os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_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 
    18 #include <schinfo.h>
    19 #include <schinfointernal.h>
    20 
    21 #include "persist_hometimeStep.h"
    22 #include "Te_floating_scheduleSuiteDefs.h"
    23 
    24 STaskSemaphore sem1;
    25 
    26 Cpersist_hometimeStep::~Cpersist_hometimeStep()
    27 /**
    28  * Destructor
    29  */
    30 	{
    31 	}
    32 
    33 Cpersist_hometimeStep::Cpersist_hometimeStep()
    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_hometimeStep);
    42 	}
    43 
    44 TVerdict Cpersist_hometimeStep::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 	sem1.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, KTestKey1, 0));
    67 		
    68 	SetTestStepResult(EPass);
    69 	return TestStepResult();
    70 	}
    71 
    72 /**
    73 @file
    74 @SYMTestCaseID				SYSLIB-SCHSVR-CIT-0277
    75 @SYMTestCaseDesc 			Persistant schedule - Hometime
    76 @SYMTestPriority 			High
    77 @SYMTestActions  			For time and condition based test schedule task and check it fires
    78 @SYMTestExpectedResults		The test must not fail.
    79 @SYMPREQ					PREQ234
    80 */
    81 TVerdict Cpersist_hometimeStep::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 - Time-Based");
    92 	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
    93 	_LIT(KTestName2, "Persistant Hometime - 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 	User::After(1000000);
   164 	
   165 	// Turn on JIT again.
   166 	User::SetJustInTime(jit);
   167 	
   168 	// Connect to the server again
   169 	TInt res = TheScheduler.Connect();
   170 	TESTL(res==KErrNone);
   171 
   172 	// Re-register
   173 	TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
   174 
   175 
   176 	// Associate a task with the time-based schedule
   177 	TTaskInfo taskInfo1;
   178 	taskInfo1.iName = KTestName1;
   179 	taskInfo1.iPriority = 2;
   180 	taskInfo1.iRepeat = 0;
   181 	// Create some data associated with this task	
   182 	HBufC* taskData1 = KTaskData1().AllocLC();
   183 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
   184 	CleanupStack::PopAndDestroy();	// taskData1
   185 		
   186 	// Associate a task with the condition-based schedule
   187 	TTaskInfo taskInfo2;
   188 	taskInfo2.iName = KTestName2;
   189 	taskInfo2.iPriority = 2;
   190 	taskInfo2.iRepeat = 0;
   191 	// Create some data associated with this task
   192 	HBufC* taskData2 = KTaskData2().AllocLC();
   193 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
   194 	CleanupStack::PopAndDestroy(); // taskData2	
   195 	
   196 	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
   197 
   198 	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
   199 	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
   200 	
   201 	// Now wait for the time-based schedule to fire	
   202 	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   203 
   204 	TTime timeNow;
   205 	timeNow.HomeTime();
   206 	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
   207 
   208 	// Now wait for the condition-based schedule to fire	
   209 	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
   210 
   211 	timeNow.HomeTime();
   212 	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
   213 	
   214 	CleanupStack::PopAndDestroy(); // timezone ID
   215 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   216 	SetTestStepResult(EPass);	
   217 	return TestStepResult();
   218 	}
   219 
   220 TVerdict Cpersist_hometimeStep::doTestStepPostambleL()
   221 /**
   222  * @return - TVerdict code
   223  * Override of base class virtual
   224  */
   225 	{
   226 	SetTestStepResult(EFail);
   227   	CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
   228   	
   229   	sem1.Close();
   230 	
   231 	// Delete all schedules
   232 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   233 	SchSvrHelpers::Pause(2);
   234 	
   235 	// Delete old files
   236 	SchSvrHelpers::DeleteScheduleFilesL();
   237 		
   238 	TheScheduler.Close();
   239   	
   240   	SetTestStepResult(EPass);
   241 	return TestStepResult();
   242 	}