os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/transient_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 "transient_mixedStep.h"
19 #include "Te_floating_scheduleSuiteDefs.h"
23 Ctransient_mixedStep::~Ctransient_mixedStep()
30 Ctransient_mixedStep::Ctransient_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(Ktransient_mixedStep);
41 TVerdict Ctransient_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-0283
69 @SYMTestCaseDesc Transient schedule - Hometime & UTC
71 @SYMTestActions For time and condition based test schedule task and check it fires
72 @SYMTestExpectedResults The test must not fail.
75 TVerdict Ctransient_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, "Transient Mixed - Hometime");
86 _LIT(KTaskData1, "This is some really exciting task data (number 1)");
87 _LIT(KTestName2, "Transient Mixed - UTC");
88 _LIT(KTaskData2, "This is some really exciting task data (number 2)");
90 // Tests with timezone set to Europe, Paris
93 CTzId* tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
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.01)
103 // Creates a hometime based daily transient schedule
104 TSchedulerItemRef ref1;
105 // This is the time when we want the Hometime time-based schedule to fire
106 TDateTime datetime1(2000, EJanuary, 1, 11, 0, 0, 0);
107 TTsTime startTimeForSchedule1(datetime1, EFalse); // 11:00 am
110 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
111 CleanupStack::PushL(entryList);
112 TScheduleEntryInfo2 entry1 (startTimeForSchedule1, EDaily, 1, 30);
113 entryList->AppendL(entry1);
114 // Associate a task with the time-based schedule
116 taskInfo1.iName = KTestName1;
117 taskInfo1.iPriority = 2;
118 taskInfo1.iRepeat = 0;
119 // Create some data associated with this task
120 HBufC* taskData1 = KTaskData1().AllocLC();
121 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
123 CleanupStack::PopAndDestroy(2); // entryList, taskData1
126 // Disable the schedule whilst we set it up
127 User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
130 // Creates a UTC based daily transient schedule
131 TSchedulerItemRef ref2;
132 // This is the time when we want the UTC time-based schedule to fire
133 TDateTime datetime2(2000, EJanuary, 1, 10, 0, 0, 0);
134 TTsTime startTimeForSchedule2(datetime2, ETrue); // 10:00 am
137 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
138 CleanupStack::PushL(entryList);
139 TScheduleEntryInfo2 entry1 (startTimeForSchedule2, EDaily, 1, 30);
140 entryList->AppendL(entry1);
141 // Associate a task with the time-based schedule
143 taskInfo1.iName = KTestName2;
144 taskInfo1.iPriority = 2;
145 taskInfo1.iRepeat = 0;
146 // Create some data associated with this task
147 HBufC* taskData2 = KTaskData2().AllocLC();
148 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData2, ref2, *entryList));
150 CleanupStack::PopAndDestroy(2); // entryList, taskData1
153 // Disable the schedule whilst we set it up
154 User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
156 // Set the UTC time such that both schedules fire at the same time
157 SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
159 User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
160 User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
162 // Now wait for the time-based schedule to fire
163 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
167 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule1));
169 // Now wait for the condition-based schedule to fire
170 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
172 timeNow.UniversalTime();
173 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), startTimeForSchedule2));
175 CleanupStack::PopAndDestroy(); // timezone ID
176 CleanupHelpers::KillProcess(KMinimalTaskHandler);
177 SetTestStepResult(EPass);
178 return TestStepResult();
183 TVerdict Ctransient_mixedStep::doTestStepPostambleL()
185 * @return - TVerdict code
186 * Override of base class virtual
189 SetTestStepResult(EFail);
190 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
194 // Delete all schedules
195 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
196 SchSvrHelpers::Pause(2);
199 SchSvrHelpers::DeleteScheduleFilesL();
201 TheScheduler.Close();
203 SetTestStepResult(EPass);
204 return TestStepResult();