os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_hometimeStep.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_hometimeStep.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,242 @@
     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 <schinfo.h>
    1.22 +#include <schinfointernal.h>
    1.23 +
    1.24 +#include "persist_hometimeStep.h"
    1.25 +#include "Te_floating_scheduleSuiteDefs.h"
    1.26 +
    1.27 +STaskSemaphore sem1;
    1.28 +
    1.29 +Cpersist_hometimeStep::~Cpersist_hometimeStep()
    1.30 +/**
    1.31 + * Destructor
    1.32 + */
    1.33 +	{
    1.34 +	}
    1.35 +
    1.36 +Cpersist_hometimeStep::Cpersist_hometimeStep()
    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_hometimeStep);
    1.45 +	}
    1.46 +
    1.47 +TVerdict Cpersist_hometimeStep::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 +	sem1.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, KTestKey1, 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-0277
    1.78 +@SYMTestCaseDesc 			Persistant schedule - Hometime
    1.79 +@SYMTestPriority 			High
    1.80 +@SYMTestActions  			For time and condition based test schedule task and check it fires
    1.81 +@SYMTestExpectedResults		The test must not fail.
    1.82 +@SYMPREQ					PREQ234
    1.83 +*/
    1.84 +TVerdict Cpersist_hometimeStep::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 - Time-Based");
    1.95 +	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
    1.96 +	_LIT(KTestName2, "Persistant Hometime - 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 +	User::After(1000000);
   1.167 +	
   1.168 +	// Turn on JIT again.
   1.169 +	User::SetJustInTime(jit);
   1.170 +	
   1.171 +	// Connect to the server again
   1.172 +	TInt res = TheScheduler.Connect();
   1.173 +	TESTL(res==KErrNone);
   1.174 +
   1.175 +	// Re-register
   1.176 +	TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
   1.177 +
   1.178 +
   1.179 +	// Associate a task with the time-based schedule
   1.180 +	TTaskInfo taskInfo1;
   1.181 +	taskInfo1.iName = KTestName1;
   1.182 +	taskInfo1.iPriority = 2;
   1.183 +	taskInfo1.iRepeat = 0;
   1.184 +	// Create some data associated with this task	
   1.185 +	HBufC* taskData1 = KTaskData1().AllocLC();
   1.186 +	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
   1.187 +	CleanupStack::PopAndDestroy();	// taskData1
   1.188 +		
   1.189 +	// Associate a task with the condition-based schedule
   1.190 +	TTaskInfo taskInfo2;
   1.191 +	taskInfo2.iName = KTestName2;
   1.192 +	taskInfo2.iPriority = 2;
   1.193 +	taskInfo2.iRepeat = 0;
   1.194 +	// Create some data associated with this task
   1.195 +	HBufC* taskData2 = KTaskData2().AllocLC();
   1.196 +	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
   1.197 +	CleanupStack::PopAndDestroy(); // taskData2	
   1.198 +	
   1.199 +	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
   1.200 +
   1.201 +	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
   1.202 +	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
   1.203 +	
   1.204 +	// Now wait for the time-based schedule to fire	
   1.205 +	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   1.206 +
   1.207 +	TTime timeNow;
   1.208 +	timeNow.HomeTime();
   1.209 +	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
   1.210 +
   1.211 +	// Now wait for the condition-based schedule to fire	
   1.212 +	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   1.213 +
   1.214 +	timeNow.HomeTime();
   1.215 +	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
   1.216 +	
   1.217 +	CleanupStack::PopAndDestroy(); // timezone ID
   1.218 +	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   1.219 +	SetTestStepResult(EPass);	
   1.220 +	return TestStepResult();
   1.221 +	}
   1.222 +
   1.223 +TVerdict Cpersist_hometimeStep::doTestStepPostambleL()
   1.224 +/**
   1.225 + * @return - TVerdict code
   1.226 + * Override of base class virtual
   1.227 + */
   1.228 +	{
   1.229 +	SetTestStepResult(EFail);
   1.230 +  	CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
   1.231 +  	
   1.232 +  	sem1.Close();
   1.233 +	
   1.234 +	// Delete all schedules
   1.235 +	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   1.236 +	SchSvrHelpers::Pause(2);
   1.237 +	
   1.238 +	// Delete old files
   1.239 +	SchSvrHelpers::DeleteScheduleFilesL();
   1.240 +		
   1.241 +	TheScheduler.Close();
   1.242 +  	
   1.243 +  	SetTestStepResult(EPass);
   1.244 +	return TestStepResult();
   1.245 +	}