1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_utcStep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,249 @@
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 "persist_utcStep.h"
1.24 +#include "Te_floating_scheduleSuiteDefs.h"
1.25 +
1.26 +STaskSemaphore sem2;
1.27 +
1.28 +Cpersist_utcStep::~Cpersist_utcStep()
1.29 +/**
1.30 + * Destructor
1.31 + */
1.32 + {
1.33 + }
1.34 +
1.35 +Cpersist_utcStep::Cpersist_utcStep()
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(Kpersist_utcStep);
1.44 + }
1.45 +
1.46 +TVerdict Cpersist_utcStep::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 + sem2.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, KTestKey2, 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-0278
1.77 +@SYMTestCaseDesc Persistant schedule - UTC
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 Cpersist_utcStep::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, "Persistant UTC - Time-Based");
1.94 + _LIT(KTaskData1, "This is some really exciting task data (number 1)");
1.95 + _LIT(KTestName2, "Persistant UTC - 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::SetUTCTimeL(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 persistant schedule
1.112 + TSchedulerItemRef ref1;
1.113 +
1.114 + // This is the time when we want the time-based schedule to fire
1.115 + TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0);
1.116 + TTsTime startTimeForSchedule(datetime1, ETrue); // 10:00 am
1.117 +
1.118 + {
1.119 + CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
1.120 + CleanupStack::PushL(entryList);
1.121 + TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
1.122 + entryList->AppendL(entry1);
1.123 +
1.124 + TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList);
1.125 + TESTL(res==KErrNone);
1.126 + CleanupStack::PopAndDestroy(); // entryList
1.127 + }
1.128 +
1.129 + // Disable the schedule whilst we set it up
1.130 + User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
1.131 +
1.132 +
1.133 + // Creates a condition based persistant schedule
1.134 + TSchedulerItemRef ref2;
1.135 +
1.136 + // This is the time when we want the condition-based schedule to fire
1.137 + TDateTime datetime2(2000, EJanuary, 1, 10, 1, 0, 0);
1.138 + TTsTime defaultRuntime(datetime2, ETrue); // 10:01 am
1.139 +
1.140 + {
1.141 + CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
1.142 + CleanupStack::PushL(conditionList);
1.143 + TTaskSchedulerCondition condition1;
1.144 + condition1.iCategory = KTestUid;
1.145 + condition1.iKey = KTestKey1;
1.146 + condition1.iState = 10;
1.147 + condition1.iType = TTaskSchedulerCondition::EEquals;
1.148 + conditionList->AppendL(condition1);
1.149 +
1.150 + TInt res = TheScheduler.CreatePersistentSchedule(ref2, *conditionList, defaultRuntime);
1.151 + TESTL(res==KErrNone);
1.152 + CleanupStack::PopAndDestroy(); // conditionList
1.153 + }
1.154 +
1.155 + // Disable the schedule whilst we set it up
1.156 + User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
1.157 +
1.158 + // Kill the server to check if persisted schedules have been stored
1.159 + // Need to turn off JIT dubugging as we are panicking server and we
1.160 + // want test to keep running.
1.161 + TBool jit = User::JustInTime();
1.162 + User::SetJustInTime(EFalse);
1.163 +
1.164 + TheScheduler.__FaultServer();
1.165 +
1.166 + // Change UTC Offset whilst server is down
1.167 + // Set UTC offset to +1Hr by moving to Europe, Paris
1.168 + tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
1.169 + tz.SetTimeZoneL(*tzId);
1.170 +
1.171 + User::After(1000000);
1.172 +
1.173 + // Turn on JIT again.
1.174 + User::SetJustInTime(jit);
1.175 +
1.176 + // Connect to the server again
1.177 + TInt res = TheScheduler.Connect();
1.178 + TESTL(res==KErrNone);
1.179 +
1.180 + // Re-register
1.181 + TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
1.182 +
1.183 +
1.184 + // Associate a task with the time-based schedule
1.185 + TTaskInfo taskInfo1;
1.186 + taskInfo1.iName = KTestName1;
1.187 + taskInfo1.iPriority = 2;
1.188 + taskInfo1.iRepeat = 0;
1.189 + // Create some data associated with this task
1.190 + HBufC* taskData1 = KTaskData1().AllocLC();
1.191 + User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
1.192 + CleanupStack::PopAndDestroy(); // taskData1
1.193 +
1.194 + // Associate a task with the condition-based schedule
1.195 + TTaskInfo taskInfo2;
1.196 + taskInfo2.iName = KTestName2;
1.197 + taskInfo2.iPriority = 2;
1.198 + taskInfo2.iRepeat = 0;
1.199 + // Create some data associated with this task
1.200 + HBufC* taskData2 = KTaskData2().AllocLC();
1.201 + User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
1.202 + CleanupStack::PopAndDestroy(); // taskData2
1.203 +
1.204 +
1.205 + SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
1.206 +
1.207 + User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
1.208 + User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
1.209 +
1.210 + // Now wait for the time-based schedule to fire
1.211 + TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
1.212 +
1.213 + TTime timeNow;
1.214 + timeNow.UniversalTime();
1.215 + TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), startTimeForSchedule));
1.216 +
1.217 + // Now wait for the condition-based schedule to fire
1.218 + TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone);
1.219 +
1.220 + timeNow.UniversalTime();
1.221 + TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), defaultRuntime));
1.222 +
1.223 + CleanupStack::PopAndDestroy(); // timezone ID
1.224 + CleanupHelpers::KillProcess(KMinimalTaskHandler);
1.225 + SetTestStepResult(EPass);
1.226 + return TestStepResult();
1.227 + }
1.228 +
1.229 +
1.230 +TVerdict Cpersist_utcStep::doTestStepPostambleL()
1.231 +/**
1.232 + * @return - TVerdict code
1.233 + * Override of base class virtual
1.234 + */
1.235 + {
1.236 + SetTestStepResult(EFail);
1.237 + CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
1.238 +
1.239 + sem2.Close();
1.240 +
1.241 + // Delete all schedules
1.242 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.243 + SchSvrHelpers::Pause(2);
1.244 +
1.245 + // Delete old files
1.246 + SchSvrHelpers::DeleteScheduleFilesL();
1.247 +
1.248 + TheScheduler.Close();
1.249 +
1.250 + SetTestStepResult(EPass);
1.251 + return TestStepResult();
1.252 + }