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