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 "persist_utcStep.h"
21 #include "Te_floating_scheduleSuiteDefs.h"
25 Cpersist_utcStep::~Cpersist_utcStep()
32 Cpersist_utcStep::Cpersist_utcStep()
37 // **MUST** call SetTestStepName in the constructor as the controlling
38 // framework uses the test step name immediately following construction to set
39 // up the step's unique logging ID.
40 SetTestStepName(Kpersist_utcStep);
43 TVerdict Cpersist_utcStep::doTestStepPreambleL()
45 * @return - TVerdict code
46 * Override of base class virtual
49 SetTestStepResult(EFail);
50 CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
53 SchSvrHelpers::DeleteScheduleFilesL();
57 TInt i = TheScheduler.Connect();
61 i = SchSvrHelpers::RegisterClientL(TheScheduler);
64 // create P&S variables for condition based tests
65 User::LeaveIfError(RProperty::Define(KTestUid, KTestKey2, 0));
67 SetTestStepResult(EPass);
68 return TestStepResult();
73 @SYMTestCaseID SYSLIB-SCHSVR-CIT-0278
74 @SYMTestCaseDesc Persistant schedule - UTC
76 @SYMTestActions For time and condition based test schedule task and check it fires
77 @SYMTestExpectedResults The test must not fail.
80 TVerdict Cpersist_utcStep::doTestStepL()
82 * @return - TVerdict code
83 * Override of base class pure virtual
84 * Our implementation only gets called if the base class doTestStepPreambleL() did
85 * not leave. That being the case, the current test result value will be EPass.
88 SetTestStepResult(EFail);
90 _LIT(KTestName1, "Persistant UTC - Time-Based");
91 _LIT(KTaskData1, "This is some really exciting task data (number 1)");
92 _LIT(KTestName2, "Persistant UTC - Condition-Based");
93 _LIT(KTaskData2, "This is some really exciting task data (number 2)");
95 // Tests with timezone set to Europe, London
98 CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
99 CleanupStack::PushL(tzId);
100 tz.SetTimeZoneL(*tzId);
102 // Set the time to a known value, since this makes testing much easier (and more
104 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
106 // Prepare schedules describing when we want the tasks to run (10:00 am & 10.01)
108 // Creates a time based daily persistant schedule
109 TSchedulerItemRef ref1;
111 // This is the time when we want the time-based schedule to fire
112 TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0);
113 TTsTime startTimeForSchedule(datetime1, ETrue); // 10:00 am
116 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
117 CleanupStack::PushL(entryList);
118 TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
119 entryList->AppendL(entry1);
121 TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList);
122 TESTL(res==KErrNone);
123 CleanupStack::PopAndDestroy(); // entryList
126 // Disable the schedule whilst we set it up
127 User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
130 // Creates a condition based persistant schedule
131 TSchedulerItemRef ref2;
133 // This is the time when we want the condition-based schedule to fire
134 TDateTime datetime2(2000, EJanuary, 1, 10, 1, 0, 0);
135 TTsTime defaultRuntime(datetime2, ETrue); // 10:01 am
138 CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
139 CleanupStack::PushL(conditionList);
140 TTaskSchedulerCondition condition1;
141 condition1.iCategory = KTestUid;
142 condition1.iKey = KTestKey1;
143 condition1.iState = 10;
144 condition1.iType = TTaskSchedulerCondition::EEquals;
145 conditionList->AppendL(condition1);
147 TInt res = TheScheduler.CreatePersistentSchedule(ref2, *conditionList, defaultRuntime);
148 TESTL(res==KErrNone);
149 CleanupStack::PopAndDestroy(); // conditionList
152 // Disable the schedule whilst we set it up
153 User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
155 // Kill the server to check if persisted schedules have been stored
156 // Need to turn off JIT dubugging as we are panicking server and we
157 // want test to keep running.
158 TBool jit = User::JustInTime();
159 User::SetJustInTime(EFalse);
161 TheScheduler.__FaultServer();
163 // Change UTC Offset whilst server is down
164 // Set UTC offset to +1Hr by moving to Europe, Paris
165 tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
166 tz.SetTimeZoneL(*tzId);
168 User::After(1000000);
170 // Turn on JIT again.
171 User::SetJustInTime(jit);
173 // Connect to the server again
174 TInt res = TheScheduler.Connect();
175 TESTL(res==KErrNone);
178 TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
181 // Associate a task with the time-based schedule
183 taskInfo1.iName = KTestName1;
184 taskInfo1.iPriority = 2;
185 taskInfo1.iRepeat = 0;
186 // Create some data associated with this task
187 HBufC* taskData1 = KTaskData1().AllocLC();
188 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
189 CleanupStack::PopAndDestroy(); // taskData1
191 // Associate a task with the condition-based schedule
193 taskInfo2.iName = KTestName2;
194 taskInfo2.iPriority = 2;
195 taskInfo2.iRepeat = 0;
196 // Create some data associated with this task
197 HBufC* taskData2 = KTaskData2().AllocLC();
198 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
199 CleanupStack::PopAndDestroy(); // taskData2
202 SchSvrHelpers::SetUTCTimeL(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);
211 timeNow.UniversalTime();
212 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), startTimeForSchedule));
214 // Now wait for the condition-based schedule to fire
215 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
217 timeNow.UniversalTime();
218 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), defaultRuntime));
220 CleanupStack::PopAndDestroy(); // timezone ID
221 CleanupHelpers::KillProcess(KMinimalTaskHandler);
222 SetTestStepResult(EPass);
223 return TestStepResult();
227 TVerdict Cpersist_utcStep::doTestStepPostambleL()
229 * @return - TVerdict code
230 * Override of base class virtual
233 SetTestStepResult(EFail);
234 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
238 // Delete all schedules
239 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
240 SchSvrHelpers::Pause(2);
243 SchSvrHelpers::DeleteScheduleFilesL();
245 TheScheduler.Close();
247 SetTestStepResult(EPass);
248 return TestStepResult();