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