|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Example CTestStep derived implementation |
|
15 // |
|
16 // |
|
17 |
|
18 #include "persist_mixedStep.h" |
|
19 #include "Te_floating_scheduleSuiteDefs.h" |
|
20 |
|
21 STaskSemaphore sem3; |
|
22 |
|
23 Cpersist_mixedStep::~Cpersist_mixedStep() |
|
24 /** |
|
25 * Destructor |
|
26 */ |
|
27 { |
|
28 } |
|
29 |
|
30 Cpersist_mixedStep::Cpersist_mixedStep() |
|
31 /** |
|
32 * Constructor |
|
33 */ |
|
34 { |
|
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); |
|
39 } |
|
40 |
|
41 TVerdict Cpersist_mixedStep::doTestStepPreambleL() |
|
42 /** |
|
43 * @return - TVerdict code |
|
44 * Override of base class virtual |
|
45 */ |
|
46 { |
|
47 SetTestStepResult(EFail); |
|
48 CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL(); |
|
49 |
|
50 // Delete old files. |
|
51 SchSvrHelpers::DeleteScheduleFilesL(); |
|
52 |
|
53 sem3.CreateL(); |
|
54 |
|
55 TInt i = TheScheduler.Connect(); |
|
56 TESTL (i==KErrNone); |
|
57 |
|
58 // Registering Client |
|
59 i = SchSvrHelpers::RegisterClientL(TheScheduler); |
|
60 TESTL (i==KErrNone); |
|
61 |
|
62 SetTestStepResult(EPass); |
|
63 return TestStepResult(); |
|
64 } |
|
65 |
|
66 /* |
|
67 @file |
|
68 @SYMTestCaseID SYSLIB-SCHSVR-CIT-0279 |
|
69 @SYMTestCaseDesc Persistant schedule - UTC & Hometime |
|
70 @SYMTestPriority High |
|
71 @SYMTestActions For time and condition based test schedule task and check it fires |
|
72 @SYMTestExpectedResults The test must not fail. |
|
73 @SYMPREQ PREQ234 |
|
74 */ |
|
75 TVerdict Cpersist_mixedStep::doTestStepL() |
|
76 /** |
|
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. |
|
81 */ |
|
82 { |
|
83 SetTestStepResult(EFail); |
|
84 |
|
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)"); |
|
89 |
|
90 // Tests with timezone set to Europe, London |
|
91 RTz tz; |
|
92 tz.Connect(); |
|
93 CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London |
|
94 CleanupStack::PushL(tzId); |
|
95 tz.SetTimeZoneL(*tzId); |
|
96 |
|
97 // Set the time to a known value, since this makes testing much easier (and more |
|
98 // repeatable). |
|
99 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am |
|
100 |
|
101 // Prepare schedules describing when we want the tasks to run (10:00 am & 10.00) |
|
102 |
|
103 // Creates a hometime based daily persistant schedule |
|
104 TSchedulerItemRef ref1; |
|
105 |
|
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 |
|
109 |
|
110 { |
|
111 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1); |
|
112 CleanupStack::PushL(entryList); |
|
113 TScheduleEntryInfo2 entry1 (startTimeForSchedule1, EDaily, 1, 30); |
|
114 entryList->AppendL(entry1); |
|
115 |
|
116 TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList); |
|
117 TESTL(res==KErrNone); |
|
118 CleanupStack::PopAndDestroy(); // entryList |
|
119 } |
|
120 |
|
121 // Disable the schedule whilst we set it up |
|
122 User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle)); |
|
123 |
|
124 |
|
125 // Creates a UTC based daily persistant schedule |
|
126 TSchedulerItemRef ref2; |
|
127 |
|
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 |
|
131 |
|
132 { |
|
133 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1); |
|
134 CleanupStack::PushL(entryList); |
|
135 TScheduleEntryInfo2 entry1 (startTimeForSchedule2, EDaily, 1, 30); |
|
136 entryList->AppendL(entry1); |
|
137 |
|
138 TInt res = TheScheduler.CreatePersistentSchedule(ref2, *entryList); |
|
139 TESTL(res==KErrNone); |
|
140 CleanupStack::PopAndDestroy(); // entryList |
|
141 } |
|
142 |
|
143 // Disable the schedule whilst we set it up |
|
144 User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle)); |
|
145 |
|
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); |
|
151 |
|
152 TheScheduler.__FaultServer(); |
|
153 |
|
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); |
|
158 |
|
159 User::After(1000000); |
|
160 |
|
161 // Turn on JIT again. |
|
162 User::SetJustInTime(jit); |
|
163 |
|
164 // Connect to the server again |
|
165 TInt res = TheScheduler.Connect(); |
|
166 TESTL(res==KErrNone); |
|
167 |
|
168 // Re-register |
|
169 TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone); |
|
170 |
|
171 |
|
172 // Associate a task with the time-based schedule |
|
173 TTaskInfo taskInfo1; |
|
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 |
|
181 |
|
182 // Associate a task with the condition-based schedule |
|
183 TTaskInfo taskInfo2; |
|
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 |
|
191 |
|
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 |
|
194 |
|
195 User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle)); |
|
196 User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle)); |
|
197 |
|
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); |
|
202 |
|
203 TTime timeNow; |
|
204 timeNow.HomeTime(); |
|
205 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule1)); |
|
206 |
|
207 timeNow.UniversalTime(); |
|
208 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), startTimeForSchedule2)); |
|
209 |
|
210 CleanupStack::PopAndDestroy(); // timezone ID |
|
211 CleanupHelpers::KillProcess(KMinimalTaskHandler); |
|
212 SetTestStepResult(EPass); |
|
213 return TestStepResult(); |
|
214 } |
|
215 |
|
216 |
|
217 TVerdict Cpersist_mixedStep::doTestStepPostambleL() |
|
218 /** |
|
219 * @return - TVerdict code |
|
220 * Override of base class virtual |
|
221 */ |
|
222 { |
|
223 SetTestStepResult(EFail); |
|
224 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL(); |
|
225 |
|
226 sem3.Close(); |
|
227 |
|
228 // Delete all schedules |
|
229 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler); |
|
230 SchSvrHelpers::Pause(2); |
|
231 |
|
232 // Delete old files |
|
233 SchSvrHelpers::DeleteScheduleFilesL(); |
|
234 |
|
235 TheScheduler.Close(); |
|
236 |
|
237 SetTestStepResult(EPass); |
|
238 return TestStepResult(); |
|
239 } |