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