os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_hometime_floatStep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_hometime_floatStep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,248 @@
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 +// persist_hometimefloatStep.cpp
1.18 +// Example CTestStep derived implementation
1.19 +//
1.20 +//
1.21 +#include <schinfo.h>
1.22 +#include <schinfointernal.h>
1.23 +
1.24 +#include "persist_hometime_floatStep.h"
1.25 +#include "Te_floating_scheduleSuiteDefs.h"
1.26 +
1.27 +STaskSemaphore sem7;
1.28 +
1.29 +Cpersist_hometime_floatStep::~Cpersist_hometime_floatStep()
1.30 +/**
1.31 + * Destructor
1.32 + */
1.33 + {
1.34 + }
1.35 +
1.36 +Cpersist_hometime_floatStep::Cpersist_hometime_floatStep()
1.37 +/**
1.38 + * Constructor
1.39 + */
1.40 + {
1.41 + // **MUST** call SetTestStepName in the constructor as the controlling
1.42 + // framework uses the test step name immediately following construction to set
1.43 + // up the step's unique logging ID.
1.44 + SetTestStepName(Kpersist_hometime_floatStep);
1.45 + }
1.46 +
1.47 +TVerdict Cpersist_hometime_floatStep::doTestStepPreambleL()
1.48 +/**
1.49 + * @return - TVerdict code
1.50 + * Override of base class virtual
1.51 + */
1.52 + {
1.53 + SetTestStepResult(EFail);
1.54 + CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
1.55 +
1.56 + // Delete old files.
1.57 + SchSvrHelpers::DeleteScheduleFilesL();
1.58 +
1.59 + sem7.CreateL();
1.60 +
1.61 + TInt i = TheScheduler.Connect();
1.62 + TESTL (i==KErrNone);
1.63 +
1.64 + // Registering Client
1.65 + i = SchSvrHelpers::RegisterClientL(TheScheduler);
1.66 + TESTL (i==KErrNone);
1.67 +
1.68 + // create P&S variables for condition based tests
1.69 + User::LeaveIfError(RProperty::Define(KTestUid, KTestKey3, 0));
1.70 +
1.71 + SetTestStepResult(EPass);
1.72 + return TestStepResult();
1.73 + }
1.74 +
1.75 +/*
1.76 +@file
1.77 +@SYMTestCaseID SYSLIB-SCHSVR-CIT-0280
1.78 +@SYMTestCaseDesc Persistant schedule float - Hometime
1.79 +@SYMTestPriority High
1.80 +@SYMTestActions For time and condition based test schedule task and check it floats
1.81 +@SYMTestExpectedResults The test must not fail.
1.82 +@SYMPREQ PREQ234
1.83 +*/
1.84 +TVerdict Cpersist_hometime_floatStep::doTestStepL()
1.85 +/**
1.86 + * @return - TVerdict code
1.87 + * Override of base class pure virtual
1.88 + * Our implementation only gets called if the base class doTestStepPreambleL() did
1.89 + * not leave. That being the case, the current test result value will be EPass.
1.90 + */
1.91 + {
1.92 + SetTestStepResult(EFail);
1.93 +
1.94 + _LIT(KTestName1, "Persistant Hometime Float - Time-Based");
1.95 + _LIT(KTaskData1, "This is some really exciting task data (number 1)");
1.96 + _LIT(KTestName2, "Persistant Hometime Float - Condition-Based");
1.97 + _LIT(KTaskData2, "This is some really exciting task data (number 2)");
1.98 +
1.99 + // Tests with timezone set to Europe, London
1.100 + RTz tz;
1.101 + tz.Connect();
1.102 + CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
1.103 + CleanupStack::PushL(tzId);
1.104 + tz.SetTimeZoneL(*tzId);
1.105 +
1.106 + // Set the time to a known value, since this makes testing much easier (and more
1.107 + // repeatable).
1.108 + SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
1.109 +
1.110 + // Prepare schedules describing when we want the tasks to run (10:00 am & 10.01)
1.111 +
1.112 + // Creates a time based daily persistant schedule
1.113 + TSchedulerItemRef ref1;
1.114 +
1.115 + // This is the time when we want the time-based schedule to fire
1.116 + TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0);
1.117 + TTsTime startTimeForSchedule(datetime1, EFalse); // 10:00 am
1.118 +
1.119 + {
1.120 + CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
1.121 + CleanupStack::PushL(entryList);
1.122 + TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
1.123 + entryList->AppendL(entry1);
1.124 +
1.125 + TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList);
1.126 + TESTL(res==KErrNone);
1.127 + CleanupStack::PopAndDestroy(); // entryList
1.128 + }
1.129 +
1.130 + // Disable the schedule whilst we set it up
1.131 + User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
1.132 +
1.133 +
1.134 + // Creates a condition based persistant schedule
1.135 + TSchedulerItemRef ref2;
1.136 +
1.137 + // This is the time when we want the condition-based schedule to fire
1.138 + TDateTime datetime2(2000, EJanuary, 1, 10, 1, 0, 0);
1.139 + TTsTime defaultRuntime(datetime2, EFalse); // 10:01 am
1.140 +
1.141 + {
1.142 + CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
1.143 + CleanupStack::PushL(conditionList);
1.144 + TTaskSchedulerCondition condition1;
1.145 + condition1.iCategory = KTestUid;
1.146 + condition1.iKey = KTestKey1;
1.147 + condition1.iState = 10;
1.148 + condition1.iType = TTaskSchedulerCondition::EEquals;
1.149 + conditionList->AppendL(condition1);
1.150 +
1.151 + TInt res = TheScheduler.CreatePersistentSchedule(ref2, *conditionList, defaultRuntime);
1.152 + TESTL(res==KErrNone);
1.153 + CleanupStack::PopAndDestroy(); // conditionList
1.154 + }
1.155 +
1.156 + // Disable the schedule whilst we set it up
1.157 + User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
1.158 +
1.159 + // Kill the server to check if persisted schedules have been stored
1.160 + // Need to turn off JIT dubugging as we are panicking server and we
1.161 + // want test to keep running.
1.162 + TBool jit = User::JustInTime();
1.163 + User::SetJustInTime(EFalse);
1.164 +
1.165 + TheScheduler.__FaultServer();
1.166 +
1.167 + // Change UTC Offset whilst server is down
1.168 + // Set UTC offset to +1Hr by moving to Europe, Paris
1.169 + tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
1.170 + tz.SetTimeZoneL(*tzId);
1.171 +
1.172 + User::After(1000000);
1.173 +
1.174 + // Turn on JIT again.
1.175 + User::SetJustInTime(jit);
1.176 +
1.177 + // Connect to the server again
1.178 + TInt res = TheScheduler.Connect();
1.179 + TESTL(res==KErrNone);
1.180 +
1.181 + // Re-register
1.182 + TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
1.183 +
1.184 +
1.185 + // Associate a task with the time-based schedule
1.186 + TTaskInfo taskInfo1;
1.187 + taskInfo1.iName = KTestName1;
1.188 + taskInfo1.iPriority = 2;
1.189 + taskInfo1.iRepeat = 0;
1.190 + // Create some data associated with this task
1.191 + HBufC* taskData1 = KTaskData1().AllocLC();
1.192 + User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
1.193 + CleanupStack::PopAndDestroy(); // taskData1
1.194 +
1.195 + // Associate a task with the condition-based schedule
1.196 + TTaskInfo taskInfo2;
1.197 + taskInfo2.iName = KTestName2;
1.198 + taskInfo2.iPriority = 2;
1.199 + taskInfo2.iRepeat = 0;
1.200 + // Create some data associated with this task
1.201 + HBufC* taskData2 = KTaskData2().AllocLC();
1.202 + User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
1.203 + CleanupStack::PopAndDestroy(); // taskData2
1.204 +
1.205 + SchSvrHelpers::SetHomeTimeL(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.HomeTime();
1.215 + TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), 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.HomeTime();
1.221 + TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), 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 +TVerdict Cpersist_hometime_floatStep::doTestStepPostambleL()
1.230 +/**
1.231 + * @return - TVerdict code
1.232 + * Override of base class virtual
1.233 + */
1.234 + {
1.235 + SetTestStepResult(EFail);
1.236 + CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
1.237 +
1.238 + sem7.Close();
1.239 +
1.240 + // Delete all schedules
1.241 + SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1.242 + SchSvrHelpers::Pause(2);
1.243 +
1.244 + // Delete old files
1.245 + SchSvrHelpers::DeleteScheduleFilesL();
1.246 +
1.247 + TheScheduler.Close();
1.248 +
1.249 + SetTestStepResult(EPass);
1.250 + return TestStepResult();
1.251 + }