os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/DEF061595_Step.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/DEF061595_Step.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,220 @@
     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 "DEF061595_Step.h"
    1.25 +#include "Te_floating_scheduleSuiteDefs.h"
    1.26 +#include "Thelpers.h"
    1.27 +
    1.28 +STaskSemaphore sem10;
    1.29 +
    1.30 +CDEF061595_Step::~CDEF061595_Step()
    1.31 +/**
    1.32 + * Destructor
    1.33 + */
    1.34 +	{
    1.35 +	}
    1.36 +
    1.37 +CDEF061595_Step::CDEF061595_Step()
    1.38 +/**
    1.39 + * Constructor
    1.40 + */
    1.41 +	{
    1.42 +	// **MUST** call SetTestStepName in the constructor as the controlling
    1.43 +	// framework uses the test step name immediately following construction to set
    1.44 +	// up the step's unique logging ID.
    1.45 +	SetTestStepName(KDEF061595_Step);
    1.46 +	}
    1.47 +
    1.48 +TVerdict CDEF061595_Step::doTestStepPreambleL()
    1.49 +/**
    1.50 + * @return - TVerdict code
    1.51 + * Override of base class virtual
    1.52 + */
    1.53 +	{
    1.54 +	SetTestStepResult(EFail);
    1.55 +	CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
    1.56 +		
    1.57 +	// Delete old files.
    1.58 +	SchSvrHelpers::DeleteScheduleFilesL();
    1.59 +
    1.60 +	sem10.CreateL();
    1.61 +
    1.62 +	TInt i = TheScheduler.Connect();
    1.63 +	TESTL (i==KErrNone);
    1.64 +		
    1.65 +	// Registering Client
    1.66 +	i = SchSvrHelpers::RegisterClientL(TheScheduler);
    1.67 +	TESTL (i==KErrNone);
    1.68 +	
    1.69 +	// create P&S variables for condition based tests
    1.70 +	User::LeaveIfError(RProperty::Define(KTestUid, KTestKey8, 0));
    1.71 +
    1.72 +	SetTestStepResult(EPass);
    1.73 +	return TestStepResult();
    1.74 +	}
    1.75 +
    1.76 +/*
    1.77 +@file
    1.78 +@SYMTestCaseID				SYSLIB-SCHSVR-CIT-1368
    1.79 +@SYMTestCaseDesc 			DEF061595 - Schedule timers incorrectly expire when system time is changed
    1.80 +@SYMTestPriority 			High
    1.81 +@SYMTestActions  			For time and condition based test schedule task and check it floats when scheduled in a timezone that's not GMT, check also that the schedule fires correctly when it is enabled before the time and offset is changed
    1.82 +@SYMTestExpectedResults		The test must not fail.
    1.83 +@SYMDEF						DEF061595
    1.84 +*/
    1.85 +TVerdict CDEF061595_Step::doTestStepL()
    1.86 +/**
    1.87 + * @return - TVerdict code
    1.88 + * Override of base class pure virtual
    1.89 + * Our implementation only gets called if the base class doTestStepPreambleL() did
    1.90 + * not leave. That being the case, the current test result value will be EPass.
    1.91 + */
    1.92 +	{
    1.93 +	SetTestStepResult(EFail);
    1.94 +	
    1.95 +	_LIT(KTestName1, "DEF061595 - Time-Based");
    1.96 +	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
    1.97 +	_LIT(KTestName2, "DEF061595 - Condition-Based");
    1.98 +	_LIT(KTaskData2, "This is some really exciting task data (number 2)");
    1.99 +	
   1.100 +	// Tests with timezone set to Europe, London
   1.101 +	RTz tz;
   1.102 +	tz.Connect();
   1.103 +	CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
   1.104 +	CleanupStack::PushL(tzId);
   1.105 +	tz.SetTimeZoneL(*tzId);
   1.106 +	
   1.107 +	// Set the time to a known value, since this makes testing much easier (and more
   1.108 +	// repeatable).
   1.109 +	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 0, 0, 0))); // 9:00 am
   1.110 +
   1.111 +	// Prepare schedules describing when we want the tasks to run (3:00 pm & 3:01 pm)
   1.112 +	
   1.113 +	// Creates a time based daily transient schedule	
   1.114 +	TSchedulerItemRef ref1;
   1.115 +	// This is the time when we want the time-based schedule to fire
   1.116 +	TDateTime datetime1(2000, EJanuary, 1, 15, 0, 0, 0);
   1.117 +	TTsTime startTimeForSchedule(datetime1, EFalse); // 3:00 pm
   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 +	// Associate a task with the time-based schedule
   1.125 +	TTaskInfo taskInfo1;
   1.126 +	taskInfo1.iName = KTestName1;
   1.127 +	taskInfo1.iPriority = 2;
   1.128 +	taskInfo1.iRepeat = 0;
   1.129 +	// Create some data associated with this task	
   1.130 +	HBufC* taskData1 = KTaskData1().AllocLC();
   1.131 +	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
   1.132 +
   1.133 +	CleanupStack::PopAndDestroy(2); // entryList, taskData1
   1.134 +	}
   1.135 +	
   1.136 +	// Disable the schedule whilst we set it up
   1.137 +	User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
   1.138 +	
   1.139 +	
   1.140 +	// Creates a condition based transient schedule
   1.141 +	TSchedulerItemRef ref2;
   1.142 +	// This is the time when we want the condition-based schedule to fire
   1.143 +	TDateTime datetime2(2000, EJanuary, 1, 15, 1, 0, 0);
   1.144 +	TTsTime defaultRuntime(datetime2, EFalse); // 3:01 pm
   1.145 +
   1.146 +	{
   1.147 +	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
   1.148 +	CleanupStack::PushL(conditionList);
   1.149 +	TTaskSchedulerCondition condition1;
   1.150 +	condition1.iCategory = KTestUid;
   1.151 +	condition1.iKey		= KTestKey1;
   1.152 +	condition1.iState	= 10;
   1.153 +	condition1.iType	= TTaskSchedulerCondition::EEquals;
   1.154 +	conditionList->AppendL(condition1);
   1.155 +	// Associate a task with the condition-based schedule
   1.156 +	TTaskInfo taskInfo2;
   1.157 +	taskInfo2.iName = KTestName2;
   1.158 +	taskInfo2.iPriority = 2;
   1.159 +	taskInfo2.iRepeat = 0;
   1.160 +	// Create some data associated with this task
   1.161 +	HBufC* taskData2 = KTaskData2().AllocLC();
   1.162 +	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2, *conditionList, defaultRuntime));
   1.163 +	
   1.164 +	CleanupStack::PopAndDestroy(2); // taskData2, conditionList
   1.165 +	}	
   1.166 +	
   1.167 +	// Disable the schedule whilst we set it up
   1.168 +	User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
   1.169 +
   1.170 +	// This step is identical to the hometime_floatStep except for the schedules
   1.171 +	// being enabled BEFORE the time is changed in this case. As would be normal behaviour
   1.172 +
   1.173 +	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
   1.174 +	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
   1.175 +	
   1.176 +	// Set UTC offset to +1Hr by moving to Europe, Paris
   1.177 +	tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
   1.178 +	tz.SetTimeZoneL(*tzId);
   1.179 +	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 13, 59, 50, 0))); // 1:59.50 pm
   1.180 +
   1.181 +	// Now wait for the time-based schedule to fire
   1.182 +	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   1.183 +
   1.184 +	TTime timeNow;
   1.185 +	timeNow.HomeTime();
   1.186 +	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
   1.187 +
   1.188 +	// Now wait for the condition-based schedule to fire
   1.189 +	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   1.190 +
   1.191 +	timeNow.HomeTime();
   1.192 +	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
   1.193 +	
   1.194 +	CleanupStack::PopAndDestroy(); // timezone ID
   1.195 +	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   1.196 +	SetTestStepResult(EPass);	
   1.197 +	return TestStepResult();
   1.198 +	}
   1.199 +
   1.200 +
   1.201 +TVerdict CDEF061595_Step::doTestStepPostambleL()
   1.202 +/**
   1.203 + * @return - TVerdict code
   1.204 + * Override of base class virtual
   1.205 + */
   1.206 +	{
   1.207 +	SetTestStepResult(EFail);
   1.208 +  	CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
   1.209 +  	
   1.210 +  	sem10.Close();
   1.211 +	
   1.212 +	// Delete all schedules
   1.213 +	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   1.214 +	SchSvrHelpers::Pause(2);
   1.215 +	
   1.216 +	// Delete old files
   1.217 +	SchSvrHelpers::DeleteScheduleFilesL();
   1.218 +		
   1.219 +	TheScheduler.Close();
   1.220 +  	
   1.221 +  	SetTestStepResult(EPass);
   1.222 +	return TestStepResult();
   1.223 +	}