os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/hometime_floatStep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Example CTestStep derived implementation
    15 // 
    16 //
    17 #include <schinfo.h>
    18 #include <schinfointernal.h>
    19 
    20 #include "hometime_floatStep.h"
    21 #include "Te_floating_scheduleSuiteDefs.h"
    22 #include "Thelpers.h"
    23 
    24 STaskSemaphore sem9;
    25 
    26 Chometime_floatStep::~Chometime_floatStep()
    27 /**
    28  * Destructor
    29  */
    30 	{
    31 	}
    32 
    33 Chometime_floatStep::Chometime_floatStep()
    34 /**
    35  * Constructor
    36  */
    37 	{
    38 	// **MUST** call SetTestStepName in the constructor as the controlling
    39 	// framework uses the test step name immediately following construction to set
    40 	// up the step's unique logging ID.
    41 	SetTestStepName(Khometime_floatStep);
    42 	}
    43 
    44 TVerdict Chometime_floatStep::doTestStepPreambleL()
    45 /**
    46  * @return - TVerdict code
    47  * Override of base class virtual
    48  */
    49 	{
    50 	SetTestStepResult(EFail);
    51 	CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
    52 		
    53 	// Delete old files.
    54 	SchSvrHelpers::DeleteScheduleFilesL();
    55 
    56 	sem9.CreateL();
    57 
    58 	TInt i = TheScheduler.Connect();
    59 	TESTL (i==KErrNone);
    60 		
    61 	// Registering Client
    62 	i = SchSvrHelpers::RegisterClientL(TheScheduler);
    63 	TESTL (i==KErrNone);
    64 	
    65 	// create P&S variables for condition based tests
    66 	User::LeaveIfError(RProperty::Define(KTestUid, KTestKey7, 0));
    67 
    68 	SetTestStepResult(EPass);
    69 	return TestStepResult();
    70 	}
    71 
    72 /*
    73 @file
    74 @SYMTestCaseID				SYSLIB-SCHSVR-CIT-0285
    75 @SYMTestCaseDesc 			Transient schedule float offset +1Hr - Hometime
    76 @SYMTestPriority 			High
    77 @SYMTestActions  			For time and condition based test schedule task and check it floats when scheduled in a timezone that's not GMT
    78 @SYMTestExpectedResults		The test must not fail.
    79 @SYMPREQ					PREQ234
    80 */
    81 TVerdict Chometime_floatStep::doTestStepL()
    82 /**
    83  * @return - TVerdict code
    84  * Override of base class pure virtual
    85  * Our implementation only gets called if the base class doTestStepPreambleL() did
    86  * not leave. That being the case, the current test result value will be EPass.
    87  */
    88 	{
    89 	SetTestStepResult(EFail);
    90 	
    91 	_LIT(KTestName1, "Hometime Float - Time-Based");
    92 	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
    93 	_LIT(KTestName2, "Hometime Float - Condition-Based");
    94 	_LIT(KTaskData2, "This is some really exciting task data (number 2)");
    95 	
    96 	// Tests with timezone set to Europe, London
    97 	RTz tz;
    98 	tz.Connect();
    99 	CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
   100 	CleanupStack::PushL(tzId);
   101 	tz.SetTimeZoneL(*tzId);
   102 	
   103 	// Set the time to a known value, since this makes testing much easier (and more
   104 	// repeatable).
   105 	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 0, 0, 0))); // 9:00 am
   106 
   107 	// Prepare schedules describing when we want the tasks to run (3:00 pm & 3:01 pm)
   108 	
   109 	// Creates a time based daily transient schedule	
   110 	TSchedulerItemRef ref1;
   111 	// This is the time when we want the time-based schedule to fire
   112 	TDateTime datetime1(2000, EJanuary, 1, 15, 0, 0, 0);
   113 	TTsTime startTimeForSchedule(datetime1, EFalse); // 3:00 pm
   114 	
   115 	{
   116 	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
   117 	CleanupStack::PushL(entryList);
   118 	TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
   119 	entryList->AppendL(entry1);
   120 	// Associate a task with the time-based schedule
   121 	TTaskInfo taskInfo1;
   122 	taskInfo1.iName = KTestName1;
   123 	taskInfo1.iPriority = 2;
   124 	taskInfo1.iRepeat = 0;
   125 	// Create some data associated with this task	
   126 	HBufC* taskData1 = KTaskData1().AllocLC();
   127 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
   128 
   129 	CleanupStack::PopAndDestroy(2); // entryList, taskData1
   130 	}
   131 	
   132 	// Disable the schedule whilst we set it up
   133 	User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
   134 	
   135 	
   136 	// Creates a condition based transient schedule
   137 	TSchedulerItemRef ref2;
   138 	// This is the time when we want the condition-based schedule to fire
   139 	TDateTime datetime2(2000, EJanuary, 1, 15, 1, 0, 0);
   140 	TTsTime defaultRuntime(datetime2, EFalse); // 3:01 pm
   141 
   142 	{
   143 	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
   144 	CleanupStack::PushL(conditionList);
   145 	TTaskSchedulerCondition condition1;
   146 	condition1.iCategory = KTestUid;
   147 	condition1.iKey		= KTestKey1;
   148 	condition1.iState	= 10;
   149 	condition1.iType	= TTaskSchedulerCondition::EEquals;
   150 	conditionList->AppendL(condition1);
   151 	// Associate a task with the condition-based schedule
   152 	TTaskInfo taskInfo2;
   153 	taskInfo2.iName = KTestName2;
   154 	taskInfo2.iPriority = 2;
   155 	taskInfo2.iRepeat = 0;
   156 	// Create some data associated with this task
   157 	HBufC* taskData2 = KTaskData2().AllocLC();
   158 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2, *conditionList, defaultRuntime));
   159 	
   160 	CleanupStack::PopAndDestroy(2); // taskData2, conditionList
   161 	}	
   162 	
   163 	// Disable the schedule whilst we set it up
   164 	User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
   165 	
   166 	// Set UTC offset to +1Hr by moving to Europe, Paris
   167 	tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
   168 	tz.SetTimeZoneL(*tzId);
   169 
   170  	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 13, 59, 50, 0))); // 1:59.50 pm
   171 
   172 	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
   173 	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
   174 	
   175 	// Now wait for the time-based schedule to fire
   176 	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   177 
   178 	TTime timeNow;
   179 	timeNow.HomeTime();
   180 	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
   181 
   182 	// Now wait for the condition-based schedule to fire
   183 	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   184 
   185 	timeNow.HomeTime();
   186 	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
   187 	
   188 	CleanupStack::PopAndDestroy(); // timezone ID
   189 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   190 	SetTestStepResult(EPass);	
   191 	return TestStepResult();
   192 	}
   193 
   194 
   195 
   196 TVerdict Chometime_floatStep::doTestStepPostambleL()
   197 /**
   198  * @return - TVerdict code
   199  * Override of base class virtual
   200  */
   201 	{
   202 	SetTestStepResult(EFail);
   203   	CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
   204   	
   205   	sem9.Close();
   206 	
   207 	// Delete all schedules
   208 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   209 	SchSvrHelpers::Pause(2);
   210 	
   211 	// Delete old files
   212 	SchSvrHelpers::DeleteScheduleFilesL();
   213 		
   214 	TheScheduler.Close();
   215   	
   216   	SetTestStepResult(EPass);
   217 	return TestStepResult();
   218 	}