os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/transient_hometimeStep.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 "transient_hometimeStep.h"
    21 #include "Te_floating_scheduleSuiteDefs.h"
    22 
    23 STaskSemaphore sem4;
    24 
    25 Ctransient_hometimeStep::~Ctransient_hometimeStep()
    26 /**
    27  * Destructor
    28  */
    29 	{
    30 	}
    31 
    32 Ctransient_hometimeStep::Ctransient_hometimeStep()
    33 /**
    34  * Constructor
    35  */
    36 	{
    37 	// **MUST** call SetTestStepName in the constructor as the controlling
    38 	// framework uses the test step name immediately following construction to set
    39 	// up the step's unique logging ID.
    40 	SetTestStepName(Ktransient_hometimeStep);
    41 	}
    42 
    43 TVerdict Ctransient_hometimeStep::doTestStepPreambleL()
    44 /**
    45  * @return - TVerdict code
    46  * Override of base class virtual
    47  */
    48 	{
    49 	SetTestStepResult(EFail);
    50 	CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
    51 		
    52 	// Delete old files.
    53 	SchSvrHelpers::DeleteScheduleFilesL();
    54 
    55 	sem4.CreateL();
    56 
    57 	TInt i = TheScheduler.Connect();
    58 	TESTL (i==KErrNone);
    59 		
    60 	// Registering Client
    61 	i = SchSvrHelpers::RegisterClientL(TheScheduler);
    62 	TESTL (i==KErrNone);
    63 	
    64 	// create P&S variables for condition based tests
    65 	User::LeaveIfError(RProperty::Define(KTestUid, KTestKey4, 0));
    66 
    67 	SetTestStepResult(EPass);
    68 	return TestStepResult();
    69 	}
    70 
    71 /*
    72 @file
    73 @SYMTestCaseID				SYSLIB-SCHSVR-CIT-0281
    74 @SYMTestCaseDesc 			Transient schedule - Hometime
    75 @SYMTestPriority 			High
    76 @SYMTestActions  			For time and condition based test schedule task and check it fires
    77 @SYMTestExpectedResults		The test must not fail.
    78 @SYMPREQ					PREQ234
    79 */
    80 TVerdict Ctransient_hometimeStep::doTestStepL()
    81 /**
    82  * @return - TVerdict code
    83  * Override of base class pure virtual
    84  * Our implementation only gets called if the base class doTestStepPreambleL() did
    85  * not leave. That being the case, the current test result value will be EPass.
    86  */
    87 	{
    88 	SetTestStepResult(EFail);
    89 	
    90 	_LIT(KTestName1, "Transient Hometime - Time-Based");
    91 	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
    92 	_LIT(KTestName2, "Transient Hometime - Condition-Based");
    93 	_LIT(KTaskData2, "This is some really exciting task data (number 2)");
    94 	
    95 	// Tests with timezone set to Europe, London
    96 	RTz tz;
    97 	tz.Connect();
    98 	CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
    99 	CleanupStack::PushL(tzId);
   100 	tz.SetTimeZoneL(*tzId);
   101 	
   102 	// Set the time to a known value, since this makes testing much easier (and more
   103 	// repeatable).	
   104 	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
   105 
   106 	// Prepare schedules describing when we want the tasks to run (10:00 am & 10.01)
   107 	
   108 	// Creates a time based daily transient schedule	
   109 	TSchedulerItemRef ref1;
   110 	// This is the time when we want the time-based schedule to fire
   111 	TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0);
   112 	TTsTime startTimeForSchedule(datetime1, EFalse); // 10:00 am
   113 	
   114 	{
   115 	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
   116 	CleanupStack::PushL(entryList);
   117 	TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
   118 	entryList->AppendL(entry1);
   119 	// Associate a task with the time-based schedule
   120 	TTaskInfo taskInfo1;
   121 	taskInfo1.iName = KTestName1;
   122 	taskInfo1.iPriority = 2;
   123 	taskInfo1.iRepeat = 0;
   124 	// Create some data associated with this task	
   125 	HBufC* taskData1 = KTaskData1().AllocLC();
   126 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
   127 
   128 	CleanupStack::PopAndDestroy(2); // entryList, taskData1
   129 	}
   130 	
   131 	// Disable the schedule whilst we set it up
   132 	User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
   133 	
   134 	
   135 	// Creates a condition based transient schedule
   136 	TSchedulerItemRef ref2;
   137 	// This is the time when we want the condition-based schedule to fire
   138 	TDateTime datetime2(2000, EJanuary, 1, 10, 1, 0, 0);
   139 	TTsTime defaultRuntime(datetime2, EFalse); // 10:01 am
   140 
   141 	{
   142 	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
   143 	CleanupStack::PushL(conditionList);
   144 	TTaskSchedulerCondition condition1;
   145 	condition1.iCategory = KTestUid;
   146 	condition1.iKey		= KTestKey1;
   147 	condition1.iState	= 10;
   148 	condition1.iType	= TTaskSchedulerCondition::EEquals;
   149 	conditionList->AppendL(condition1);
   150 	// Associate a task with the condition-based schedule
   151 	TTaskInfo taskInfo2;
   152 	taskInfo2.iName = KTestName2;
   153 	taskInfo2.iPriority = 2;
   154 	taskInfo2.iRepeat = 0;
   155 	// Create some data associated with this task
   156 	HBufC* taskData2 = KTaskData2().AllocLC();
   157 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2, *conditionList, defaultRuntime));
   158 	
   159 	CleanupStack::PopAndDestroy(2); // taskData2, conditionList
   160 	}	
   161 	
   162 	// Disable the schedule whilst we set it up
   163 	User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
   164 	
   165 	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
   166 
   167 	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
   168 	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
   169 	
   170 	// Now wait for the time-based schedule to fire
   171 	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   172 
   173 	TTime timeNow;
   174 	timeNow.HomeTime();
   175 	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
   176 
   177 	// Now wait for the condition-based schedule to fire
   178 	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   179 
   180 	timeNow.HomeTime();
   181 	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
   182 	
   183 	CleanupStack::PopAndDestroy(); // timezone ID
   184 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   185 	SetTestStepResult(EPass);	
   186 	return TestStepResult();
   187 	}
   188 
   189 
   190 
   191 TVerdict Ctransient_hometimeStep::doTestStepPostambleL()
   192 /**
   193  * @return - TVerdict code
   194  * Override of base class virtual
   195  */
   196 	{
   197 	SetTestStepResult(EFail);
   198   	CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
   199   	
   200   	sem4.Close();
   201 	
   202 	// Delete all schedules
   203 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   204 	SchSvrHelpers::Pause(2);
   205 	
   206 	// Delete old files
   207 	SchSvrHelpers::DeleteScheduleFilesL();
   208 		
   209 	TheScheduler.Close();
   210   	
   211   	SetTestStepResult(EPass);
   212 	return TestStepResult();
   213 	}