os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_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 // persist_hometimefloatStep.cpp
15 // Example CTestStep derived implementation
19 #include <schinfointernal.h>
21 #include "persist_hometime_floatStep.h"
22 #include "Te_floating_scheduleSuiteDefs.h"
26 Cpersist_hometime_floatStep::~Cpersist_hometime_floatStep()
33 Cpersist_hometime_floatStep::Cpersist_hometime_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(Kpersist_hometime_floatStep);
44 TVerdict Cpersist_hometime_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, KTestKey3, 0));
68 SetTestStepResult(EPass);
69 return TestStepResult();
74 @SYMTestCaseID SYSLIB-SCHSVR-CIT-0280
75 @SYMTestCaseDesc Persistant schedule float - Hometime
77 @SYMTestActions For time and condition based test schedule task and check it floats
78 @SYMTestExpectedResults The test must not fail.
81 TVerdict Cpersist_hometime_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, "Persistant Hometime Float - Time-Based");
92 _LIT(KTaskData1, "This is some really exciting task data (number 1)");
93 _LIT(KTestName2, "Persistant 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::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
107 // Prepare schedules describing when we want the tasks to run (10:00 am & 10.01)
109 // Creates a time based daily persistant schedule
110 TSchedulerItemRef ref1;
112 // This is the time when we want the time-based schedule to fire
113 TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0);
114 TTsTime startTimeForSchedule(datetime1, EFalse); // 10:00 am
117 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
118 CleanupStack::PushL(entryList);
119 TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
120 entryList->AppendL(entry1);
122 TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList);
123 TESTL(res==KErrNone);
124 CleanupStack::PopAndDestroy(); // entryList
127 // Disable the schedule whilst we set it up
128 User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
131 // Creates a condition based persistant schedule
132 TSchedulerItemRef ref2;
134 // This is the time when we want the condition-based schedule to fire
135 TDateTime datetime2(2000, EJanuary, 1, 10, 1, 0, 0);
136 TTsTime defaultRuntime(datetime2, EFalse); // 10:01 am
139 CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
140 CleanupStack::PushL(conditionList);
141 TTaskSchedulerCondition condition1;
142 condition1.iCategory = KTestUid;
143 condition1.iKey = KTestKey1;
144 condition1.iState = 10;
145 condition1.iType = TTaskSchedulerCondition::EEquals;
146 conditionList->AppendL(condition1);
148 TInt res = TheScheduler.CreatePersistentSchedule(ref2, *conditionList, defaultRuntime);
149 TESTL(res==KErrNone);
150 CleanupStack::PopAndDestroy(); // conditionList
153 // Disable the schedule whilst we set it up
154 User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
156 // Kill the server to check if persisted schedules have been stored
157 // Need to turn off JIT dubugging as we are panicking server and we
158 // want test to keep running.
159 TBool jit = User::JustInTime();
160 User::SetJustInTime(EFalse);
162 TheScheduler.__FaultServer();
164 // Change UTC Offset whilst server is down
165 // Set UTC offset to +1Hr by moving to Europe, Paris
166 tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
167 tz.SetTimeZoneL(*tzId);
169 User::After(1000000);
171 // Turn on JIT again.
172 User::SetJustInTime(jit);
174 // Connect to the server again
175 TInt res = TheScheduler.Connect();
176 TESTL(res==KErrNone);
179 TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
182 // Associate a task with the time-based schedule
184 taskInfo1.iName = KTestName1;
185 taskInfo1.iPriority = 2;
186 taskInfo1.iRepeat = 0;
187 // Create some data associated with this task
188 HBufC* taskData1 = KTaskData1().AllocLC();
189 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
190 CleanupStack::PopAndDestroy(); // taskData1
192 // Associate a task with the condition-based schedule
194 taskInfo2.iName = KTestName2;
195 taskInfo2.iPriority = 2;
196 taskInfo2.iRepeat = 0;
197 // Create some data associated with this task
198 HBufC* taskData2 = KTaskData2().AllocLC();
199 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
200 CleanupStack::PopAndDestroy(); // taskData2
202 SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
204 User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
205 User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
207 // Now wait for the time-based schedule to fire
208 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
212 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
214 // Now wait for the condition-based schedule to fire
215 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
218 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
220 CleanupStack::PopAndDestroy(); // timezone ID
221 CleanupHelpers::KillProcess(KMinimalTaskHandler);
222 SetTestStepResult(EPass);
223 return TestStepResult();
226 TVerdict Cpersist_hometime_floatStep::doTestStepPostambleL()
228 * @return - TVerdict code
229 * Override of base class virtual
232 SetTestStepResult(EFail);
233 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
237 // Delete all schedules
238 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
239 SchSvrHelpers::Pause(2);
242 SchSvrHelpers::DeleteScheduleFilesL();
244 TheScheduler.Close();
246 SetTestStepResult(EPass);
247 return TestStepResult();