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