os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/hometime_floatStep.cpp
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
18 #include <schinfointernal.h>
20 #include "hometime_floatStep.h"
21 #include "Te_floating_scheduleSuiteDefs.h"
26 Chometime_floatStep::~Chometime_floatStep()
33 Chometime_floatStep::Chometime_floatStep()
38 // **MUST** call SetTestStepName in the constructor as the controlling
39 // framework uses the test step name immediately following construction to set
40 // up the step's unique logging ID.
41 SetTestStepName(Khometime_floatStep);
44 TVerdict Chometime_floatStep::doTestStepPreambleL()
46 * @return - TVerdict code
47 * Override of base class virtual
50 SetTestStepResult(EFail);
51 CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
54 SchSvrHelpers::DeleteScheduleFilesL();
58 TInt i = TheScheduler.Connect();
62 i = SchSvrHelpers::RegisterClientL(TheScheduler);
65 // create P&S variables for condition based tests
66 User::LeaveIfError(RProperty::Define(KTestUid, KTestKey7, 0));
68 SetTestStepResult(EPass);
69 return TestStepResult();
74 @SYMTestCaseID SYSLIB-SCHSVR-CIT-0285
75 @SYMTestCaseDesc Transient schedule float offset +1Hr - Hometime
77 @SYMTestActions For time and condition based test schedule task and check it floats when scheduled in a timezone that's not GMT
78 @SYMTestExpectedResults The test must not fail.
81 TVerdict Chometime_floatStep::doTestStepL()
83 * @return - TVerdict code
84 * Override of base class pure virtual
85 * Our implementation only gets called if the base class doTestStepPreambleL() did
86 * not leave. That being the case, the current test result value will be EPass.
89 SetTestStepResult(EFail);
91 _LIT(KTestName1, "Hometime Float - Time-Based");
92 _LIT(KTaskData1, "This is some really exciting task data (number 1)");
93 _LIT(KTestName2, "Hometime Float - Condition-Based");
94 _LIT(KTaskData2, "This is some really exciting task data (number 2)");
96 // Tests with timezone set to Europe, London
99 CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
100 CleanupStack::PushL(tzId);
101 tz.SetTimeZoneL(*tzId);
103 // Set the time to a known value, since this makes testing much easier (and more
105 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 0, 0, 0))); // 9:00 am
107 // Prepare schedules describing when we want the tasks to run (3:00 pm & 3:01 pm)
109 // Creates a time based daily transient schedule
110 TSchedulerItemRef ref1;
111 // This is the time when we want the time-based schedule to fire
112 TDateTime datetime1(2000, EJanuary, 1, 15, 0, 0, 0);
113 TTsTime startTimeForSchedule(datetime1, EFalse); // 3:00 pm
116 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
117 CleanupStack::PushL(entryList);
118 TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
119 entryList->AppendL(entry1);
120 // Associate a task with the time-based schedule
122 taskInfo1.iName = KTestName1;
123 taskInfo1.iPriority = 2;
124 taskInfo1.iRepeat = 0;
125 // Create some data associated with this task
126 HBufC* taskData1 = KTaskData1().AllocLC();
127 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
129 CleanupStack::PopAndDestroy(2); // entryList, taskData1
132 // Disable the schedule whilst we set it up
133 User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
136 // Creates a condition based transient schedule
137 TSchedulerItemRef ref2;
138 // This is the time when we want the condition-based schedule to fire
139 TDateTime datetime2(2000, EJanuary, 1, 15, 1, 0, 0);
140 TTsTime defaultRuntime(datetime2, EFalse); // 3:01 pm
143 CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
144 CleanupStack::PushL(conditionList);
145 TTaskSchedulerCondition condition1;
146 condition1.iCategory = KTestUid;
147 condition1.iKey = KTestKey1;
148 condition1.iState = 10;
149 condition1.iType = TTaskSchedulerCondition::EEquals;
150 conditionList->AppendL(condition1);
151 // Associate a task with the condition-based schedule
153 taskInfo2.iName = KTestName2;
154 taskInfo2.iPriority = 2;
155 taskInfo2.iRepeat = 0;
156 // Create some data associated with this task
157 HBufC* taskData2 = KTaskData2().AllocLC();
158 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2, *conditionList, defaultRuntime));
160 CleanupStack::PopAndDestroy(2); // taskData2, conditionList
163 // Disable the schedule whilst we set it up
164 User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
166 // Set UTC offset to +1Hr by moving to Europe, Paris
167 tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
168 tz.SetTimeZoneL(*tzId);
170 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 13, 59, 50, 0))); // 1:59.50 pm
172 User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
173 User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
175 // Now wait for the time-based schedule to fire
176 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
180 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
182 // Now wait for the condition-based schedule to fire
183 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
186 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
188 CleanupStack::PopAndDestroy(); // timezone ID
189 CleanupHelpers::KillProcess(KMinimalTaskHandler);
190 SetTestStepResult(EPass);
191 return TestStepResult();
196 TVerdict Chometime_floatStep::doTestStepPostambleL()
198 * @return - TVerdict code
199 * Override of base class virtual
202 SetTestStepResult(EFail);
203 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
207 // Delete all schedules
208 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
209 SchSvrHelpers::Pause(2);
212 SchSvrHelpers::DeleteScheduleFilesL();
214 TheScheduler.Close();
216 SetTestStepResult(EPass);
217 return TestStepResult();