os/ossrv/genericservices/taskscheduler/Test/Testexecute/src/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
// Example CTestStep derived implementation
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
#include <schinfo.h>
sl@0
    18
#include <schinfointernal.h>
sl@0
    19
sl@0
    20
#include "hometime_floatStep.h"
sl@0
    21
#include "Te_floating_scheduleSuiteDefs.h"
sl@0
    22
#include "Thelpers.h"
sl@0
    23
sl@0
    24
STaskSemaphore sem9;
sl@0
    25
sl@0
    26
Chometime_floatStep::~Chometime_floatStep()
sl@0
    27
/**
sl@0
    28
 * Destructor
sl@0
    29
 */
sl@0
    30
	{
sl@0
    31
	}
sl@0
    32
sl@0
    33
Chometime_floatStep::Chometime_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(Khometime_floatStep);
sl@0
    42
	}
sl@0
    43
sl@0
    44
TVerdict Chometime_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
	sem9.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, KTestKey7, 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-0285
sl@0
    75
@SYMTestCaseDesc 			Transient schedule float offset +1Hr - Hometime
sl@0
    76
@SYMTestPriority 			High
sl@0
    77
@SYMTestActions  			For time and condition based test schedule task and check it floats when scheduled in a timezone that's not GMT
sl@0
    78
@SYMTestExpectedResults		The test must not fail.
sl@0
    79
@SYMPREQ					PREQ234
sl@0
    80
*/
sl@0
    81
TVerdict Chometime_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, "Hometime Float - Time-Based");
sl@0
    92
	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
sl@0
    93
	_LIT(KTestName2, "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::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 0, 0, 0))); // 9:00 am
sl@0
   106
sl@0
   107
	// Prepare schedules describing when we want the tasks to run (3:00 pm & 3:01 pm)
sl@0
   108
	
sl@0
   109
	// Creates a time based daily transient schedule	
sl@0
   110
	TSchedulerItemRef ref1;
sl@0
   111
	// This is the time when we want the time-based schedule to fire
sl@0
   112
	TDateTime datetime1(2000, EJanuary, 1, 15, 0, 0, 0);
sl@0
   113
	TTsTime startTimeForSchedule(datetime1, EFalse); // 3:00 pm
sl@0
   114
	
sl@0
   115
	{
sl@0
   116
	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
sl@0
   117
	CleanupStack::PushL(entryList);
sl@0
   118
	TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 1, 30);
sl@0
   119
	entryList->AppendL(entry1);
sl@0
   120
	// Associate a task with the time-based schedule
sl@0
   121
	TTaskInfo taskInfo1;
sl@0
   122
	taskInfo1.iName = KTestName1;
sl@0
   123
	taskInfo1.iPriority = 2;
sl@0
   124
	taskInfo1.iRepeat = 0;
sl@0
   125
	// Create some data associated with this task	
sl@0
   126
	HBufC* taskData1 = KTaskData1().AllocLC();
sl@0
   127
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref1, *entryList));
sl@0
   128
sl@0
   129
	CleanupStack::PopAndDestroy(2); // entryList, taskData1
sl@0
   130
	}
sl@0
   131
	
sl@0
   132
	// Disable the schedule whilst we set it up
sl@0
   133
	User::LeaveIfError(TheScheduler.DisableSchedule(ref1.iHandle));
sl@0
   134
	
sl@0
   135
	
sl@0
   136
	// Creates a condition based transient schedule
sl@0
   137
	TSchedulerItemRef ref2;
sl@0
   138
	// This is the time when we want the condition-based schedule to fire
sl@0
   139
	TDateTime datetime2(2000, EJanuary, 1, 15, 1, 0, 0);
sl@0
   140
	TTsTime defaultRuntime(datetime2, EFalse); // 3:01 pm
sl@0
   141
sl@0
   142
	{
sl@0
   143
	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(1);
sl@0
   144
	CleanupStack::PushL(conditionList);
sl@0
   145
	TTaskSchedulerCondition condition1;
sl@0
   146
	condition1.iCategory = KTestUid;
sl@0
   147
	condition1.iKey		= KTestKey1;
sl@0
   148
	condition1.iState	= 10;
sl@0
   149
	condition1.iType	= TTaskSchedulerCondition::EEquals;
sl@0
   150
	conditionList->AppendL(condition1);
sl@0
   151
	// Associate a task with the condition-based schedule
sl@0
   152
	TTaskInfo taskInfo2;
sl@0
   153
	taskInfo2.iName = KTestName2;
sl@0
   154
	taskInfo2.iPriority = 2;
sl@0
   155
	taskInfo2.iRepeat = 0;
sl@0
   156
	// Create some data associated with this task
sl@0
   157
	HBufC* taskData2 = KTaskData2().AllocLC();
sl@0
   158
	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref2, *conditionList, defaultRuntime));
sl@0
   159
	
sl@0
   160
	CleanupStack::PopAndDestroy(2); // taskData2, conditionList
sl@0
   161
	}	
sl@0
   162
	
sl@0
   163
	// Disable the schedule whilst we set it up
sl@0
   164
	User::LeaveIfError(TheScheduler.DisableSchedule(ref2.iHandle));
sl@0
   165
	
sl@0
   166
	// Set UTC offset to +1Hr by moving to Europe, Paris
sl@0
   167
	tzId = CTzId::NewL(2656); //set the timezone to Europe/Paris
sl@0
   168
	tz.SetTimeZoneL(*tzId);
sl@0
   169
sl@0
   170
 	SchSvrHelpers::SetUTCTimeL(TTime(TDateTime(2000, EJanuary, 1, 13, 59, 50, 0))); // 1:59.50 pm
sl@0
   171
sl@0
   172
	User::LeaveIfError(TheScheduler.EnableSchedule(ref1.iHandle));
sl@0
   173
	User::LeaveIfError(TheScheduler.EnableSchedule(ref2.iHandle));
sl@0
   174
	
sl@0
   175
	// Now wait for the time-based schedule to fire
sl@0
   176
	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
sl@0
   177
sl@0
   178
	TTime timeNow;
sl@0
   179
	timeNow.HomeTime();
sl@0
   180
	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), startTimeForSchedule));
sl@0
   181
sl@0
   182
	// Now wait for the condition-based schedule to fire
sl@0
   183
	TESTL(STaskSemaphore::WaitL(KDefaultTimeout) == KErrNone); 
sl@0
   184
sl@0
   185
	timeNow.HomeTime();
sl@0
   186
	TESTL(SchSvrHelpers::IsTimeTheSameNoSeconds(TTsTime(timeNow, EFalse), defaultRuntime));
sl@0
   187
	
sl@0
   188
	CleanupStack::PopAndDestroy(); // timezone ID
sl@0
   189
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   190
	SetTestStepResult(EPass);	
sl@0
   191
	return TestStepResult();
sl@0
   192
	}
sl@0
   193
sl@0
   194
sl@0
   195
sl@0
   196
TVerdict Chometime_floatStep::doTestStepPostambleL()
sl@0
   197
/**
sl@0
   198
 * @return - TVerdict code
sl@0
   199
 * Override of base class virtual
sl@0
   200
 */
sl@0
   201
	{
sl@0
   202
	SetTestStepResult(EFail);
sl@0
   203
  	CTe_floating_scheduleSuiteStepBase::doTestStepPostambleL();
sl@0
   204
  	
sl@0
   205
  	sem9.Close();
sl@0
   206
	
sl@0
   207
	// Delete all schedules
sl@0
   208
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
   209
	SchSvrHelpers::Pause(2);
sl@0
   210
	
sl@0
   211
	// Delete old files
sl@0
   212
	SchSvrHelpers::DeleteScheduleFilesL();
sl@0
   213
		
sl@0
   214
	TheScheduler.Close();
sl@0
   215
  	
sl@0
   216
  	SetTestStepResult(EPass);
sl@0
   217
	return TestStepResult();
sl@0
   218
	}