os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_utcStep.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 #include <schinfo.h>
    18 #include <schinfointernal.h>
    19 
    20 #include "persist_utcStep.h"
    21 #include "Te_floating_scheduleSuiteDefs.h"
    22 
    23 STaskSemaphore sem2;
    24 
    25 Cpersist_utcStep::~Cpersist_utcStep()
    26 /**
    27  * Destructor
    28  */
    29 	{
    30 	}
    31 
    32 Cpersist_utcStep::Cpersist_utcStep()
    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(Kpersist_utcStep);
    41 	}
    42 
    43 TVerdict Cpersist_utcStep::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 	sem2.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, KTestKey2, 0));
    66 		
    67 	SetTestStepResult(EPass);
    68 	return TestStepResult();
    69 	}
    70 
    71 /*
    72 @file
    73 @SYMTestCaseID				SYSLIB-SCHSVR-CIT-0278
    74 @SYMTestCaseDesc 			Persistant schedule - UTC
    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 Cpersist_utcStep::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, "Persistant UTC - Time-Based");
    91 	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
    92 	_LIT(KTestName2, "Persistant UTC - 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::SetUTCTimeL(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 persistant schedule	
   109 	TSchedulerItemRef ref1;
   110 
   111 	// This is the time when we want the time-based schedule to fire
   112 	TDateTime datetime1(2000, EJanuary, 1, 10, 0, 0, 0);
   113 	TTsTime startTimeForSchedule(datetime1, ETrue); // 10:00 am
   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 
   121 	TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList);
   122 	TESTL(res==KErrNone);
   123 	CleanupStack::PopAndDestroy(); // entryList
   124 	}
   125 	
   126 	// Disable the schedule whilst we set it up
   127 	User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
   128 	
   129 	
   130 	// Creates a condition based persistant schedule
   131 	TSchedulerItemRef ref2;
   132 	
   133 	// This is the time when we want the condition-based schedule to fire
   134 	TDateTime datetime2(2000, EJanuary, 1, 10, 1, 0, 0);
   135 	TTsTime defaultRuntime(datetime2, ETrue); // 10:01 am
   136 
   137 	{
   138 	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
   139 	CleanupStack::PushL(conditionList);
   140 	TTaskSchedulerCondition condition1;
   141 	condition1.iCategory = KTestUid;
   142 	condition1.iKey		= KTestKey1;
   143 	condition1.iState	= 10;
   144 	condition1.iType	= TTaskSchedulerCondition::EEquals;
   145 	conditionList->AppendL(condition1);
   146 
   147 	TInt res = TheScheduler.CreatePersistentSchedule(ref2, *conditionList, defaultRuntime);
   148 	TESTL(res==KErrNone);
   149 	CleanupStack::PopAndDestroy(); // conditionList
   150 	}	
   151 	
   152 	// Disable the schedule whilst we set it up
   153 	User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
   154 	
   155 	// Kill the server to check if persisted schedules have been stored
   156 	// Need to turn off JIT dubugging as we are panicking server and we 
   157 	// want test to keep running.
   158 	TBool jit = User::JustInTime();
   159 	User::SetJustInTime(EFalse);
   160 
   161 	TheScheduler.__FaultServer();
   162 	
   163 	// Change UTC Offset whilst server is down	
   164 	// Set UTC offset to +1Hr by moving to Europe, Paris
   165 	tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
   166 	tz.SetTimeZoneL(*tzId);
   167 	
   168 	User::After(1000000);
   169 	
   170 	// Turn on JIT again.
   171 	User::SetJustInTime(jit);
   172 	
   173 	// Connect to the server again
   174 	TInt res = TheScheduler.Connect();
   175 	TESTL(res==KErrNone);
   176 
   177 	// Re-register
   178 	TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
   179 
   180 
   181 	// Associate a task with the time-based schedule
   182 	TTaskInfo taskInfo1;
   183 	taskInfo1.iName = KTestName1;
   184 	taskInfo1.iPriority = 2;
   185 	taskInfo1.iRepeat = 0;
   186 	// Create some data associated with this task	
   187 	HBufC* taskData1 = KTaskData1().AllocLC();
   188 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
   189 	CleanupStack::PopAndDestroy();	// taskData1
   190 		
   191 	// Associate a task with the condition-based schedule
   192 	TTaskInfo taskInfo2;
   193 	taskInfo2.iName = KTestName2;
   194 	taskInfo2.iPriority = 2;
   195 	taskInfo2.iRepeat = 0;
   196 	// Create some data associated with this task
   197 	HBufC* taskData2 = KTaskData2().AllocLC();
   198 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
   199 	CleanupStack::PopAndDestroy(); // taskData2
   200 
   201 
   202 	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
   203 
   204 	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
   205 	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
   206 	
   207 	// Now wait for the time-based schedule to fire
   208 	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   209 
   210 	TTime timeNow;
   211 	timeNow.UniversalTime();
   212 	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), startTimeForSchedule));
   213 
   214 	// Now wait for the condition-based schedule to fire
   215 	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   216 
   217 	timeNow.UniversalTime();
   218 	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), defaultRuntime));
   219 	
   220 	CleanupStack::PopAndDestroy(); // timezone ID
   221 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   222 	SetTestStepResult(EPass);	
   223 	return TestStepResult();
   224 	}
   225 
   226 
   227 TVerdict Cpersist_utcStep::doTestStepPostambleL()
   228 /**
   229  * @return - TVerdict code
   230  * Override of base class virtual
   231  */
   232 	{
   233 	SetTestStepResult(EFail);
   234   	CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
   235   	
   236   	sem2.Close();
   237 	
   238 	// Delete all schedules
   239 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   240 	SchSvrHelpers::Pause(2);
   241 	
   242 	// Delete old files
   243 	SchSvrHelpers::DeleteScheduleFilesL();
   244 		
   245 	TheScheduler.Close();
   246   	
   247   	SetTestStepResult(EPass);
   248 	return TestStepResult();
   249 	}