os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/transient_hometimeStep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/transient_hometimeStep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,213 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Example CTestStep derived implementation
1.18 +//
1.19 +//
1.20 +#include <schinfo.h>
1.21 +#include <schinfointernal.h>
1.22 +
1.23 +#include "transient_hometimeStep.h"
1.24 +#include "Te_floating_scheduleSuiteDefs.h"
1.25 +
1.26 +STaskSemaphore sem4;
1.27 +
1.28 +Ctransient_hometimeStep::~Ctransient_hometimeStep()
1.29 +/**
1.30 + * Destructor
1.31 + */
1.32 + {
1.33 + }
1.34 +
1.35 +Ctransient_hometimeStep::Ctransient_hometimeStep()
1.36 +/**
1.37 + * Constructor
1.38 + */
1.39 + {
1.40 + // **MUST** call SetTestStepName in the constructor as the controlling
1.41 + // framework uses the test step name immediately following construction to set
1.42 + // up the step's unique logging ID.
1.43 + SetTestStepName(Ktransient_hometimeStep);
1.44 + }
1.45 +
1.46 +TVerdict Ctransient_hometimeStep::doTestStepPreambleL()
1.47 +/**
1.48 + * @return - TVerdict code
1.49 + * Override of base class virtual
1.50 + */
1.51 + {
1.52 + SetTestStepResult(EFail);
1.53 + CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
1.54 +
1.55 + // Delete old files.
1.56 + SchSvrHelpers::DeleteScheduleFilesL();
1.57 +
1.58 + sem4.CreateL();
1.59 +
1.60 + TInt i = TheScheduler.Connect();
1.61 + TESTL (i==KErrNone);
1.62 +
1.63 + // Registering Client
1.64 + i = SchSvrHelpers::RegisterClientL(TheScheduler);
1.65 + TESTL (i==KErrNone);
1.66 +
1.67 + // create P&S variables for condition based tests
1.68 + User::LeaveIfError(RProperty::Define(KTestUid, KTestKey4, 0));
1.69 +
1.70 + SetTestStepResult(EPass);
1.71 + return TestStepResult();
1.72 + }
1.73 +
1.74 +/*
1.75 +@file
1.76 +@SYMTestCaseID SYSLIB-SCHSVR-CIT-0281
1.77 +@SYMTestCaseDesc Transient schedule - Hometime
1.78 +@SYMTestPriority High
1.79 +@SYMTestActions For time and condition based test schedule task and check it fires
1.80 +@SYMTestExpectedResults The test must not fail.
1.81 +@SYMPREQ PREQ234
1.82 +*/
1.83 +TVerdict Ctransient_hometimeStep::doTestStepL()
1.84 +/**
1.85 + * @return - TVerdict code
1.86 + * Override of base class pure virtual
1.87 + * Our implementation only gets called if the base class doTestStepPreambleL() did
1.88 + * not leave. That being the case, the current test result value will be EPass.
1.89 + */
1.90 + {
1.91 + SetTestStepResult(EFail);
1.92 +
1.93 + _LIT(KTestName1, "Transient Hometime - Time-Based");
1.94 + _LIT(KTaskData1, "This is some really exciting task data (number 1)");
1.95 + _LIT(KTestName2, "Transient Hometime - Condition-Based");
1.96 + _LIT(KTaskData2, "This is some really exciting task data (number 2)");
1.97 +
1.98 + // Tests with timezone set to Europe, London
1.99 + RTz tz;
1.100 + tz.Connect();
1.101 + CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
1.102 + CleanupStack::PushL(tzId);
1.103 + tz.SetTimeZoneL(*tzId);
1.104 +
1.105 + // Set the time to a known value, since this makes testing much easier (and more
1.106 + // repeatable).
1.107 + SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
1.108 +
1.109 + // Prepare schedules describing when we want the tasks to run (10:00 am & 10.01)
1.110 +
1.111 + // Creates a time based daily transient schedule
1.112 + TSchedulerItemRef ref1;
1.113 + // This is the time when we want the time-based schedule to fire
1.114 + TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0);
1.115 + TTsTime startTimeForSchedule(datetime1, EFalse); // 10:00 am
1.116 +
1.117 + {
1.118 + CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
1.119 + CleanupStack::PushL(entryList);
1.120 + TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
1.121 + entryList->AppendL(entry1);
1.122 + // Associate a task with the time-based schedule
1.123 + TTaskInfo taskInfo1;
1.124 + taskInfo1.iName = KTestName1;
1.125 + taskInfo1.iPriority = 2;
1.126 + taskInfo1.iRepeat = 0;
1.127 + // Create some data associated with this task
1.128 + HBufC* taskData1 = KTaskData1().AllocLC();
1.129 + User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
1.130 +
1.131 + CleanupStack::PopAndDestroy(2); // entryList, taskData1
1.132 + }
1.133 +
1.134 + // Disable the schedule whilst we set it up
1.135 + User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
1.136 +
1.137 +
1.138 + // Creates a condition based transient schedule
1.139 + TSchedulerItemRef ref2;
1.140 + // This is the time when we want the condition-based schedule to fire
1.141 + TDateTime datetime2(2000, EJanuary, 1, 10, 1, 0, 0);
1.142 + TTsTime defaultRuntime(datetime2, EFalse); // 10:01 am
1.143 +
1.144 + {
1.145 + CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
1.146 + CleanupStack::PushL(conditionList);
1.147 + TTaskSchedulerCondition condition1;
1.148 + condition1.iCategory = KTestUid;
1.149 + condition1.iKey = KTestKey1;
1.150 + condition1.iState = 10;
1.151 + condition1.iType = TTaskSchedulerCondition::EEquals;
1.152 + conditionList->AppendL(condition1);
1.153 + // Associate a task with the condition-based schedule
1.154 + TTaskInfo taskInfo2;
1.155 + taskInfo2.iName = KTestName2;
1.156 + taskInfo2.iPriority = 2;
1.157 + taskInfo2.iRepeat = 0;
1.158 + // Create some data associated with this task
1.159 + HBufC* taskData2 = KTaskData2().AllocLC();
1.160 + User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2, *conditionList, defaultRuntime));
1.161 +
1.162 + CleanupStack::PopAndDestroy(2); // taskData2, conditionList
1.163 + }
1.164 +
1.165 + // Disable the schedule whilst we set it up
1.166 + User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
1.167 +
1.168 + SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
1.169 +
1.170 + User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
1.171 + User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
1.172 +
1.173 + // Now wait for the time-based schedule to fire
1.174 + TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
1.175 +
1.176 + TTime timeNow;
1.177 + timeNow.HomeTime();
1.178 + TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
1.179 +
1.180 + // Now wait for the condition-based schedule to fire
1.181 + TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
1.182 +
1.183 + timeNow.HomeTime();
1.184 + TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
1.185 +
1.186 + CleanupStack::PopAndDestroy(); // timezone ID
1.187 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.188 + SetTestStepResult(EPass);
1.189 + return TestStepResult();
1.190 + }
1.191 +
1.192 +
1.193 +
1.194 +TVerdict Ctransient_hometimeStep::doTestStepPostambleL()
1.195 +/**
1.196 + * @return - TVerdict code
1.197 + * Override of base class virtual
1.198 + */
1.199 + {
1.200 + SetTestStepResult(EFail);
1.201 + CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
1.202 +
1.203 + sem4.Close();
1.204 +
1.205 + // Delete all schedules
1.206 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.207 + SchSvrHelpers::Pause(2);
1.208 +
1.209 + // Delete old files
1.210 + SchSvrHelpers::DeleteScheduleFilesL();
1.211 +
1.212 + TheScheduler.Close();
1.213 +
1.214 + SetTestStepResult(EPass);
1.215 + return TestStepResult();
1.216 + }