os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_hometimeStep.cpp
First public contribution.
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
19 #include <schinfointernal.h>
21 #include "persist_hometimeStep.h"
22 #include "Te_floating_scheduleSuiteDefs.h"
26 Cpersist_hometimeStep::~Cpersist_hometimeStep()
33 Cpersist_hometimeStep::Cpersist_hometimeStep()
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_hometimeStep);
44 TVerdict Cpersist_hometimeStep::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, KTestKey1, 0));
68 SetTestStepResult(EPass);
69 return TestStepResult();
74 @SYMTestCaseID SYSLIB-SCHSVR-CIT-0277
75 @SYMTestCaseDesc Persistant schedule - Hometime
77 @SYMTestActions For time and condition based test schedule task and check it fires
78 @SYMTestExpectedResults The test must not fail.
81 TVerdict Cpersist_hometimeStep::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 - Time-Based");
92 _LIT(KTaskData1, "This is some really exciting task data (number 1)");
93 _LIT(KTestName2, "Persistant Hometime - 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();
163 User::After(1000000);
165 // Turn on JIT again.
166 User::SetJustInTime(jit);
168 // Connect to the server again
169 TInt res = TheScheduler.Connect();
170 TESTL(res==KErrNone);
173 TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
176 // Associate a task with the time-based schedule
178 taskInfo1.iName = KTestName1;
179 taskInfo1.iPriority = 2;
180 taskInfo1.iRepeat = 0;
181 // Create some data associated with this task
182 HBufC* taskData1 = KTaskData1().AllocLC();
183 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
184 CleanupStack::PopAndDestroy(); // taskData1
186 // Associate a task with the condition-based schedule
188 taskInfo2.iName = KTestName2;
189 taskInfo2.iPriority = 2;
190 taskInfo2.iRepeat = 0;
191 // Create some data associated with this task
192 HBufC* taskData2 = KTaskData2().AllocLC();
193 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
194 CleanupStack::PopAndDestroy(); // taskData2
196 SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
198 User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
199 User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
201 // Now wait for the time-based schedule to fire
202 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
206 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
208 // Now wait for the condition-based schedule to fire
209 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
212 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
214 CleanupStack::PopAndDestroy(); // timezone ID
215 CleanupHelpers::KillProcess(KMinimalTaskHandler);
216 SetTestStepResult(EPass);
217 return TestStepResult();
220 TVerdict Cpersist_hometimeStep::doTestStepPostambleL()
222 * @return - TVerdict code
223 * Override of base class virtual
226 SetTestStepResult(EFail);
227 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
231 // Delete all schedules
232 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
233 SchSvrHelpers::Pause(2);
236 SchSvrHelpers::DeleteScheduleFilesL();
238 TheScheduler.Close();
240 SetTestStepResult(EPass);
241 return TestStepResult();