os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/persist_mixedStep.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.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Example CTestStep derived implementation
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "persist_mixedStep.h"
sl@0
    19
#include "Te_floating_scheduleSuiteDefs.h"
sl@0
    20
sl@0
    21
STaskSemaphore sem3;
sl@0
    22
sl@0
    23
Cpersist_mixedStep::~Cpersist_mixedStep()
sl@0
    24
/**
sl@0
    25
 * Destructor
sl@0
    26
 */
sl@0
    27
	{
sl@0
    28
	}
sl@0
    29
sl@0
    30
Cpersist_mixedStep::Cpersist_mixedStep()
sl@0
    31
/**
sl@0
    32
 * Constructor
sl@0
    33
 */
sl@0
    34
	{
sl@0
    35
	// **MUST** call SetTestStepName in the constructor as the controlling
sl@0
    36
	// framework uses the test step name immediately following construction to set
sl@0
    37
	// up the step's unique logging ID.
sl@0
    38
	SetTestStepName(Kpersist_mixedStep);
sl@0
    39
	}
sl@0
    40
sl@0
    41
TVerdict Cpersist_mixedStep::doTestStepPreambleL()
sl@0
    42
/**
sl@0
    43
 * @return - TVerdict code
sl@0
    44
 * Override of base class virtual
sl@0
    45
 */
sl@0
    46
	{
sl@0
    47
	SetTestStepResult(EFail);
sl@0
    48
	CTe_floating_scheduleSuiteStepBase::doTestStepPreambleL();
sl@0
    49
		
sl@0
    50
	// Delete old files.
sl@0
    51
	SchSvrHelpers::DeleteScheduleFilesL();
sl@0
    52
sl@0
    53
	sem3.CreateL();
sl@0
    54
sl@0
    55
	TInt i = TheScheduler.Connect();
sl@0
    56
	TESTL (i==KErrNone);
sl@0
    57
		
sl@0
    58
	// Registering Client
sl@0
    59
	i = SchSvrHelpers::RegisterClientL(TheScheduler);
sl@0
    60
	TESTL (i==KErrNone);
sl@0
    61
	
sl@0
    62
	SetTestStepResult(EPass);
sl@0
    63
	return TestStepResult();
sl@0
    64
	}
sl@0
    65
sl@0
    66
/*
sl@0
    67
@file
sl@0
    68
@SYMTestCaseID				SYSLIB-SCHSVR-CIT-0279
sl@0
    69
@SYMTestCaseDesc 			Persistant schedule - UTC & Hometime
sl@0
    70
@SYMTestPriority 			High
sl@0
    71
@SYMTestActions  			For time and condition based test schedule task and check it fires
sl@0
    72
@SYMTestExpectedResults		The test must not fail.
sl@0
    73
@SYMPREQ					PREQ234
sl@0
    74
*/
sl@0
    75
TVerdict Cpersist_mixedStep::doTestStepL()
sl@0
    76
/**
sl@0
    77
 * @return - TVerdict code
sl@0
    78
 * Override of base class pure virtual
sl@0
    79
 * Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0
    80
 * not leave. That being the case, the current test result value will be EPass.
sl@0
    81
 */
sl@0
    82
	{
sl@0
    83
	SetTestStepResult(EFail);
sl@0
    84
	
sl@0
    85
	_LIT(KTestName1, "Persistant Mixed - Hometime");
sl@0
    86
	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
sl@0
    87
	_LIT(KTestName2, "Persistant Mixed - UTC");
sl@0
    88
	_LIT(KTaskData2, "This is some really exciting task data (number 2)");
sl@0
    89
	
sl@0
    90
	// Tests with timezone set to Europe, London
sl@0
    91
	RTz tz;
sl@0
    92
	tz.Connect();
sl@0
    93
	CTzId* tzId = CTzId::NewL(2592); //set the timezone to Europe/London
sl@0
    94
	CleanupStack::PushL(tzId);
sl@0
    95
	tz.SetTimeZoneL(*tzId);
sl@0
    96
	
sl@0
    97
	// Set the time to a known value, since this makes testing much easier (and more
sl@0
    98
	// repeatable).
sl@0
    99
	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
sl@0
   100
sl@0
   101
	// Prepare schedules describing when we want the tasks to run (10:00 am & 10.00)
sl@0
   102
	
sl@0
   103
	// Creates a hometime based daily persistant schedule	
sl@0
   104
	TSchedulerItemRef ref1;
sl@0
   105
sl@0
   106
	// This is the time when we want the Hometime time-based schedule to fire
sl@0
   107
	TDateTime datetime1(2000, EJanuary, 1, 11, 0, 0, 0);
sl@0
   108
	TTsTime startTimeForSchedule1(datetime1, EFalse); // 11:00 am
sl@0
   109
	
sl@0
   110
	{
sl@0
   111
	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
sl@0
   112
	CleanupStack::PushL(entryList);
sl@0
   113
	TScheduleEntryInfo2 entry1 (startTimeForSchedule1, EDaily, 1, 30);
sl@0
   114
	entryList->AppendL(entry1);
sl@0
   115
sl@0
   116
	TInt res = TheScheduler.CreatePersistentSchedule(ref1, *entryList);
sl@0
   117
	TESTL(res==KErrNone);
sl@0
   118
	CleanupStack::PopAndDestroy(); // entryList
sl@0
   119
	}
sl@0
   120
	
sl@0
   121
	// Disable the schedule whilst we set it up
sl@0
   122
	User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
sl@0
   123
	
sl@0
   124
	
sl@0
   125
	// Creates a UTC based daily persistant schedule	
sl@0
   126
	TSchedulerItemRef ref2;
sl@0
   127
sl@0
   128
	// This is the time when we want the UTC time-based schedule to fire
sl@0
   129
	TDateTime datetime2(2000, EJanuary, 1, 10, 0, 0, 0);
sl@0
   130
	TTsTime startTimeForSchedule2(datetime2, ETrue); // 10:00 am
sl@0
   131
	
sl@0
   132
	{
sl@0
   133
	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
sl@0
   134
	CleanupStack::PushL(entryList);
sl@0
   135
	TScheduleEntryInfo2 entry1 (startTimeForSchedule2, EDaily, 1, 30);
sl@0
   136
	entryList->AppendL(entry1);
sl@0
   137
sl@0
   138
	TInt res = TheScheduler.CreatePersistentSchedule(ref2, *entryList);
sl@0
   139
	TESTL(res==KErrNone);
sl@0
   140
	CleanupStack::PopAndDestroy(); // entryList
sl@0
   141
	}
sl@0
   142
	
sl@0
   143
	// Disable the schedule whilst we set it up
sl@0
   144
	User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
sl@0
   145
	
sl@0
   146
	// Kill the server to check if persisted schedules have been stored
sl@0
   147
	// Need to turn off JIT dubugging as we are panicking server and we 
sl@0
   148
	// want test to keep running.
sl@0
   149
	TBool jit = User::JustInTime();
sl@0
   150
	User::SetJustInTime(EFalse);
sl@0
   151
sl@0
   152
	TheScheduler.__FaultServer();
sl@0
   153
	
sl@0
   154
	// Change UTC Offset whilst server is down	
sl@0
   155
	// Set UTC offset to +1Hr by moving to Europe, Paris
sl@0
   156
	tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
sl@0
   157
	tz.SetTimeZoneL(*tzId);
sl@0
   158
	
sl@0
   159
	User::After(1000000);
sl@0
   160
	
sl@0
   161
	// Turn on JIT again.
sl@0
   162
	User::SetJustInTime(jit);
sl@0
   163
	
sl@0
   164
	// Connect to the server again
sl@0
   165
	TInt res = TheScheduler.Connect();
sl@0
   166
	TESTL(res==KErrNone);
sl@0
   167
sl@0
   168
	// Re-register
sl@0
   169
	TESTL(SchSvrHelpers::RegisterClientL(TheScheduler)==KErrNone);
sl@0
   170
sl@0
   171
sl@0
   172
	// Associate a task with the time-based schedule
sl@0
   173
	TTaskInfo taskInfo1;
sl@0
   174
	taskInfo1.iName = KTestName1;
sl@0
   175
	taskInfo1.iPriority = 2;
sl@0
   176
	taskInfo1.iRepeat = 0;
sl@0
   177
	// Create some data associated with this task	
sl@0
   178
	HBufC* taskData1 = KTaskData1().AllocLC();
sl@0
   179
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1.iHandle));
sl@0
   180
	CleanupStack::PopAndDestroy();	// taskData1
sl@0
   181
		
sl@0
   182
	// Associate a task with the condition-based schedule
sl@0
   183
	TTaskInfo taskInfo2;
sl@0
   184
	taskInfo2.iName = KTestName2;
sl@0
   185
	taskInfo2.iPriority = 2;
sl@0
   186
	taskInfo2.iRepeat = 0;
sl@0
   187
	// Create some data associated with this task
sl@0
   188
	HBufC* taskData2 = KTaskData2().AllocLC();
sl@0
   189
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2.iHandle));
sl@0
   190
	CleanupStack::PopAndDestroy(); // taskData2
sl@0
   191
sl@0
   192
	// Set the UTC time such that both schedules fire at the same time
sl@0
   193
	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 59, 50, 0))); // 9:59.50 am
sl@0
   194
sl@0
   195
	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
sl@0
   196
	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
sl@0
   197
	
sl@0
   198
	// Now wait for the time-based schedule to fire
sl@0
   199
	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
sl@0
   200
	// Now wait for the condition-based schedule to fire
sl@0
   201
	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
sl@0
   202
	
sl@0
   203
	TTime timeNow;
sl@0
   204
	timeNow.HomeTime();
sl@0
   205
	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule1));
sl@0
   206
sl@0
   207
	timeNow.UniversalTime();
sl@0
   208
	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, ETrue), startTimeForSchedule2));
sl@0
   209
	
sl@0
   210
	CleanupStack::PopAndDestroy(); // timezone ID
sl@0
   211
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   212
	SetTestStepResult(EPass);	
sl@0
   213
	return TestStepResult();
sl@0
   214
	}
sl@0
   215
sl@0
   216
sl@0
   217
TVerdict Cpersist_mixedStep::doTestStepPostambleL()
sl@0
   218
/**
sl@0
   219
 * @return - TVerdict code
sl@0
   220
 * Override of base class virtual
sl@0
   221
 */
sl@0
   222
	{
sl@0
   223
	SetTestStepResult(EFail);
sl@0
   224
  	CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
sl@0
   225
  	
sl@0
   226
  	sem3.Close();
sl@0
   227
	
sl@0
   228
	// Delete all schedules
sl@0
   229
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
   230
	SchSvrHelpers::Pause(2);
sl@0
   231
	
sl@0
   232
	// Delete old files
sl@0
   233
	SchSvrHelpers::DeleteScheduleFilesL();
sl@0
   234
		
sl@0
   235
	TheScheduler.Close();
sl@0
   236
  	
sl@0
   237
  	SetTestStepResult(EPass);
sl@0
   238
	return TestStepResult();
sl@0
   239
	}