os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_mixedStep.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 "persist_mixedStep.h"
19 #include "Te_floating_scheduleSuiteDefs.h"
23 Cpersist_mixedStep::~Cpersist_mixedStep()
30 Cpersist_mixedStep::Cpersist_mixedStep()
35 // **MUST** call SetTestStepName in the constructor as the controlling
36 // framework uses the test step name immediately following construction to set
37 // up the step's unique logging ID.
38 SetTestStepName(Kpersist_mixedStep);
41 TVerdict Cpersist_mixedStep::doTestStepPreambleL()
43 * @return - TVerdict code
44 * Override of base class virtual
47 SetTestStepResult(EFail);
48 CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
51 SchSvrHelpers::DeleteScheduleFilesL();
55 TInt i = TheScheduler.Connect();
59 i = SchSvrHelpers::RegisterClientL(TheScheduler);
62 SetTestStepResult(EPass);
63 return TestStepResult();
68 @SYMTestCaseID SYSLIB-SCHSVR-CIT-0279
69 @SYMTestCaseDesc Persistant schedule - UTC & Hometime
71 @SYMTestActions For time and condition based test schedule task and check it fires
72 @SYMTestExpectedResults The test must not fail.
75 TVerdict Cpersist_mixedStep::doTestStepL()
77 * @return - TVerdict code
78 * Override of base class pure virtual
79 * Our implementation only gets called if the base class doTestStepPreambleL() did
80 * not leave. That being the case, the current test result value will be EPass.
83 SetTestStepResult(EFail);
85 _LIT(KTestName1, "Persistant Mixed - Hometime");
86 _LIT(KTaskData1, "This is some really exciting task data (number 1)");
87 _LIT(KTestName2, "Persistant Mixed - UTC");
88 _LIT(KTaskData2, "This is some really exciting task data (number 2)");
90 // Tests with timezone set to Europe, London
93 CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
94 CleanupStack::PushL(tzId);
95 tz.SetTimeZoneL(*tzId);
97 // Set the time to a known value, since this makes testing much easier (and more
99 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
101 // Prepare schedules describing when we want the tasks to run (10:00 am & 10.00)
103 // Creates a hometime based daily persistant schedule
104 TSchedulerItemRef ref1;
106 // This is the time when we want the Hometime time-based schedule to fire
107 TDateTime datetime1(2000, EJanuary, 1, 11, 0, 0, 0);
108 TTsTime startTimeForSchedule1(datetime1, EFalse); // 11:00 am
111 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
112 CleanupStack::PushL(entryList);
113 TScheduleEntryInfo2 entry1 (startTimeForSchedule1, EDaily, 1, 30);
114 entryList->AppendL(entry1);
116 TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList);
117 TESTL(res==KErrNone);
118 CleanupStack::PopAndDestroy(); // entryList
121 // Disable the schedule whilst we set it up
122 User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
125 // Creates a UTC based daily persistant schedule
126 TSchedulerItemRef ref2;
128 // This is the time when we want the UTC time-based schedule to fire
129 TDateTime datetime2(2000, EJanuary, 1, 10, 0, 0, 0);
130 TTsTime startTimeForSchedule2(datetime2, ETrue); // 10:00 am
133 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
134 CleanupStack::PushL(entryList);
135 TScheduleEntryInfo2 entry1 (startTimeForSchedule2, EDaily, 1, 30);
136 entryList->AppendL(entry1);
138 TInt res = TheScheduler.CreatePersistentSchedule(ref2, *entryList);
139 TESTL(res==KErrNone);
140 CleanupStack::PopAndDestroy(); // entryList
143 // Disable the schedule whilst we set it up
144 User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
146 // Kill the server to check if persisted schedules have been stored
147 // Need to turn off JIT dubugging as we are panicking server and we
148 // want test to keep running.
149 TBool jit = User::JustInTime();
150 User::SetJustInTime(EFalse);
152 TheScheduler.__FaultServer();
154 // Change UTC Offset whilst server is down
155 // Set UTC offset to +1Hr by moving to Europe, Paris
156 tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
157 tz.SetTimeZoneL(*tzId);
159 User::After(1000000);
161 // Turn on JIT again.
162 User::SetJustInTime(jit);
164 // Connect to the server again
165 TInt res = TheScheduler.Connect();
166 TESTL(res==KErrNone);
169 TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
172 // Associate a task with the time-based schedule
174 taskInfo1.iName = KTestName1;
175 taskInfo1.iPriority = 2;
176 taskInfo1.iRepeat = 0;
177 // Create some data associated with this task
178 HBufC* taskData1 = KTaskData1().AllocLC();
179 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
180 CleanupStack::PopAndDestroy(); // taskData1
182 // Associate a task with the condition-based schedule
184 taskInfo2.iName = KTestName2;
185 taskInfo2.iPriority = 2;
186 taskInfo2.iRepeat = 0;
187 // Create some data associated with this task
188 HBufC* taskData2 = KTaskData2().AllocLC();
189 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
190 CleanupStack::PopAndDestroy(); // taskData2
192 // Set the UTC time such that both schedules fire at the same time
193 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
195 User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
196 User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
198 // Now wait for the time-based schedule to fire
199 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
200 // Now wait for the condition-based schedule to fire
201 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
205 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule1));
207 timeNow.UniversalTime();
208 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), startTimeForSchedule2));
210 CleanupStack::PopAndDestroy(); // timezone ID
211 CleanupHelpers::KillProcess(KMinimalTaskHandler);
212 SetTestStepResult(EPass);
213 return TestStepResult();
217 TVerdict Cpersist_mixedStep::doTestStepPostambleL()
219 * @return - TVerdict code
220 * Override of base class virtual
223 SetTestStepResult(EFail);
224 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
228 // Delete all schedules
229 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
230 SchSvrHelpers::Pause(2);
233 SchSvrHelpers::DeleteScheduleFilesL();
235 TheScheduler.Close();
237 SetTestStepResult(EPass);
238 return TestStepResult();