os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/transient_hometime_floatStep.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 <schinfointernal.h>
20 #include "transient_hometime_floatStep.h"
21 #include "Te_floating_scheduleSuiteDefs.h"
25 Ctransient_hometime_floatStep::~Ctransient_hometime_floatStep()
32 Ctransient_hometime_floatStep::Ctransient_hometime_floatStep()
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(Ktransient_hometime_floatStep);
43 TVerdict Ctransient_hometime_floatStep::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, KTestKey6, 0));
67 SetTestStepResult(EPass);
68 return TestStepResult();
73 @SYMTestCaseID SYSLIB-SCHSVR-CIT-0284
74 @SYMTestCaseDesc Transient schedule float - Hometime
76 @SYMTestActions For time and condition based test schedule task and check it floats
77 @SYMTestExpectedResults The test must not fail.
80 TVerdict Ctransient_hometime_floatStep::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, "Transient Hometime Float - Time-Based");
91 _LIT(KTaskData1, "This is some really exciting task data (number 1)");
92 _LIT(KTestName2, "Transient Hometime Float - 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::SetHomeTimeL(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 transient schedule
109 TSchedulerItemRef ref1;
110 // This is the time when we want the time-based schedule to fire
111 TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0);
112 TTsTime startTimeForSchedule(datetime1, EFalse); // 10:00 am
115 CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
116 CleanupStack::PushL(entryList);
117 TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
118 entryList->AppendL(entry1);
119 // Associate a task with the time-based schedule
121 taskInfo1.iName = KTestName1;
122 taskInfo1.iPriority = 2;
123 taskInfo1.iRepeat = 0;
124 // Create some data associated with this task
125 HBufC* taskData1 = KTaskData1().AllocLC();
126 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
128 CleanupStack::PopAndDestroy(2); // entryList, taskData1
131 // Disable the schedule whilst we set it up
132 User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
135 // Creates a condition based transient schedule
136 TSchedulerItemRef ref2;
137 // This is the time when we want the condition-based schedule to fire
138 TDateTime datetime2(2000, EJanuary, 1, 10, 1, 0, 0);
139 TTsTime defaultRuntime(datetime2, EFalse); // 10:01 am
142 CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
143 CleanupStack::PushL(conditionList);
144 TTaskSchedulerCondition condition1;
145 condition1.iCategory = KTestUid;
146 condition1.iKey = KTestKey1;
147 condition1.iState = 10;
148 condition1.iType = TTaskSchedulerCondition::EEquals;
149 conditionList->AppendL(condition1);
150 // Associate a task with the condition-based schedule
152 taskInfo2.iName = KTestName2;
153 taskInfo2.iPriority = 2;
154 taskInfo2.iRepeat = 0;
155 // Create some data associated with this task
156 HBufC* taskData2 = KTaskData2().AllocLC();
157 User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2, *conditionList, defaultRuntime));
159 CleanupStack::PopAndDestroy(2); // taskData2, conditionList
162 // Disable the schedule whilst we set it up
163 User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
165 // Set UTC offset to +1Hr by moving to Europe, Paris
166 tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
167 tz.SetTimeZoneL(*tzId);
169 SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
171 User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
172 User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
174 // Now wait for the time-based schedule to fire
175 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
179 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
181 // Now wait for the condition-based schedule to fire
182 TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
185 TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
187 CleanupStack::PopAndDestroy(); // timezone ID
188 CleanupHelpers::KillProcess(KMinimalTaskHandler);
189 SetTestStepResult(EPass);
190 return TestStepResult();
195 TVerdict Ctransient_hometime_floatStep::doTestStepPostambleL()
197 * @return - TVerdict code
198 * Override of base class virtual
201 SetTestStepResult(EFail);
202 CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
206 // Delete all schedules
207 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
208 SchSvrHelpers::Pause(2);
211 SchSvrHelpers::DeleteScheduleFilesL();
213 TheScheduler.Close();
215 SetTestStepResult(EPass);
216 return TestStepResult();