Update contrib.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Example CTestStep derived implementation
19 #include <schinfointernal.h>
21 #include "DEF061595_Step.h"
22 #include "Te_floating_scheduleSuiteDefs.h"
27 CDEF061595_Step::~CDEF061595_Step()
34 CDEF061595_Step::CDEF061595_Step()
39 // **MUST** call SetTestStepName in the constructor as the controlling
40 // framework uses the test step name immediately following construction to set
41 // up the step's unique logging ID.
42 SetTestStepName(KDEF061595_Step);
45 TVerdict CDEF061595_Step::doTestStepPreambleL()
47 * @return - TVerdict code
48 * Override of base class virtual
51 SetTestStepResult(EFail);
52 CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
55 SchSvrHelpers::DeleteScheduleFilesL();
59 TInt i = TheScheduler.Connect();
63 i = SchSvrHelpers::RegisterClientL(TheScheduler);
66 // create P&S variables for condition based tests
67 User::LeaveIfError(RProperty::Define(KTestUid, KTestKey8, 0));
69 SetTestStepResult(EPass);
70 return TestStepResult();
75 @SYMTestCaseID SYSLIB-SCHSVR-CIT-1368
76 @SYMTestCaseDesc DEF061595 - Schedule timers incorrectly expire when system time is changed
78 @SYMTestActions For time and condition based test schedule task and check it floats when scheduled in a timezone that's not GMT, check also that the schedule fires correctly when it is enabled before the time and offset is changed
79 @SYMTestExpectedResults The test must not fail.
82 TVerdict CDEF061595_Step::doTestStepL()
84 * @return - TVerdict code
85 * Override of base class pure virtual
86 * Our implementation only gets called if the base class doTestStepPreambleL() did
87 * not leave. That being the case, the current test result value will be EPass.
90 SetTestStepResult(EFail);
92 _LIT(KTestName1, "DEF061595 - Time-Based");
93 _LIT(KTaskData1, "This is some really exciting task data (number 1)");
94 _LIT(KTestName2, "DEF061595 - Condition-Based");
95 _LIT(KTaskData2, "This is some really exciting task data (number 2)");
97 // Tests with timezone set to Europe, London
100 CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
101 CleanupStack::PushL(tzId);
102 tz.SetTimeZoneL(*tzId);
104 // Set the time to a known value, since this makes testing much easier (and more
106 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 0, 0, 0))); // 9:00 am
108 // Prepare schedules describing when we want the tasks to run (3:00 pm & 3:01 pm)
110 // Creates a time based daily transient schedule
111 TSchedulerItemRef ref1;
112 // This is the time when we want the time-based schedule to fire
113 TDateTime datetime1(2000, EJanuary, 1, 15, 0, 0, 0);
114 TTsTime startTimeForSchedule(datetime1, EFalse); // 3:00 pm
117 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
118 CleanupStack::PushL(entryList);
119 TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
120 entryList->AppendL(entry1);
121 // Associate a task with the time-based schedule
123 taskInfo1.iName = KTestName1;
124 taskInfo1.iPriority = 2;
125 taskInfo1.iRepeat = 0;
126 // Create some data associated with this task
127 HBufC* taskData1 = KTaskData1().AllocLC();
128 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
130 CleanupStack::PopAndDestroy(2); // entryList, taskData1
133 // Disable the schedule whilst we set it up
134 User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
137 // Creates a condition based transient schedule
138 TSchedulerItemRef ref2;
139 // This is the time when we want the condition-based schedule to fire
140 TDateTime datetime2(2000, EJanuary, 1, 15, 1, 0, 0);
141 TTsTime defaultRuntime(datetime2, EFalse); // 3:01 pm
144 CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
145 CleanupStack::PushL(conditionList);
146 TTaskSchedulerCondition condition1;
147 condition1.iCategory = KTestUid;
148 condition1.iKey = KTestKey1;
149 condition1.iState = 10;
150 condition1.iType = TTaskSchedulerCondition::EEquals;
151 conditionList->AppendL(condition1);
152 // Associate a task with the condition-based schedule
154 taskInfo2.iName = KTestName2;
155 taskInfo2.iPriority = 2;
156 taskInfo2.iRepeat = 0;
157 // Create some data associated with this task
158 HBufC* taskData2 = KTaskData2().AllocLC();
159 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2, *conditionList, defaultRuntime));
161 CleanupStack::PopAndDestroy(2); // taskData2, conditionList
164 // Disable the schedule whilst we set it up
165 User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
167 // This step is identical to the hometime_floatStep except for the schedules
168 // being enabled BEFORE the time is changed in this case. As would be normal behaviour
170 User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
171 User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
173 // Set UTC offset to +1Hr by moving to Europe, Paris
174 tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
175 tz.SetTimeZoneL(*tzId);
176 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 13, 59, 50, 0))); // 1:59.50 pm
178 // Now wait for the time-based schedule to fire
179 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
183 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
185 // Now wait for the condition-based schedule to fire
186 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
189 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
191 CleanupStack::PopAndDestroy(); // timezone ID
192 CleanupHelpers::KillProcess(KMinimalTaskHandler);
193 SetTestStepResult(EPass);
194 return TestStepResult();
198 TVerdict CDEF061595_Step::doTestStepPostambleL()
200 * @return - TVerdict code
201 * Override of base class virtual
204 SetTestStepResult(EFail);
205 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
209 // Delete all schedules
210 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
211 SchSvrHelpers::Pause(2);
214 SchSvrHelpers::DeleteScheduleFilesL();
216 TheScheduler.Close();
218 SetTestStepResult(EPass);
219 return TestStepResult();