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