os/ossrv/genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING2_HOMETIME.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) 2004-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
//
sl@0
    15
sl@0
    16
#include <csch_cli.h>
sl@0
    17
#include "Thelpers.h"
sl@0
    18
sl@0
    19
#include <e32base.h>
sl@0
    20
#include <e32test.h>
sl@0
    21
#include <f32file.h>
sl@0
    22
#include <s32file.h>
sl@0
    23
sl@0
    24
#include "TestUtils.h"
sl@0
    25
sl@0
    26
sl@0
    27
//If suddenly all SCHSVR tests begin failing, the OOM conditions might be the reason.
sl@0
    28
//TScheduling test tries to create KNumberOfSchedulesToCreate tasks, loading enormously 
sl@0
    29
//the task scheduling server. The task scheduling server fails and stays loaded in memory
sl@0
    30
//with many scheduling tasks holding large amounts of allocated memory in this way.
sl@0
    31
//The next SCHSVR tests may fail because of OOM.
sl@0
    32
//KNumberOfSchedulesToCreate value was 100 originally. Now it is 20.
sl@0
    33
sl@0
    34
//
sl@0
    35
// Literal constants
sl@0
    36
//
sl@0
    37
_LIT(KTestName,								"TC_TSCH_SCHEDULING2 - Hometime");
sl@0
    38
sl@0
    39
//
sl@0
    40
// Type definitions
sl@0
    41
//
sl@0
    42
typedef CArrayFixFlat<TScheduleEntryInfo2>	CSchEntryInfoArray;
sl@0
    43
typedef CArrayFixFlat<TTaskInfo>			CTaskInfoArray;
sl@0
    44
typedef CArrayFixFlat<TSchedulerItemRef>    CSchItemRefArray;
sl@0
    45
sl@0
    46
//
sl@0
    47
// Global data
sl@0
    48
//
sl@0
    49
RTest										TheTest(KTestName);
sl@0
    50
static TInt64								TheSeed;
sl@0
    51
static RScheduler							TheScheduler;
sl@0
    52
static CTrapCleanup*						TheCleanup;
sl@0
    53
static RFs									TheFsSession;
sl@0
    54
sl@0
    55
_LIT(KMinimalTaskHandler, "MinimalTaskHandler");
sl@0
    56
sl@0
    57
sl@0
    58
//***********************************************************************************
sl@0
    59
// Extract task info from the schedule server based on a schedule ID
sl@0
    60
static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
sl@0
    61
						TInt aScheduleId)
sl@0
    62
	{
sl@0
    63
	aTaskInfoArray.Reset();
sl@0
    64
	TTsTime nextTimeScheduleIsDue;
sl@0
    65
	TScheduleState2 state;
sl@0
    66
	CSchEntryInfoArray* entries 
sl@0
    67
		= new (ELeave) CSchEntryInfoArray(3);
sl@0
    68
	CleanupStack::PushL(entries);
sl@0
    69
	TInt res = TheScheduler.GetScheduleL(aScheduleId, 
sl@0
    70
										state, 
sl@0
    71
										*entries, 
sl@0
    72
										aTaskInfoArray, 
sl@0
    73
										nextTimeScheduleIsDue);
sl@0
    74
	TEST2(res, KErrNone);
sl@0
    75
	CleanupStack::PopAndDestroy(entries);
sl@0
    76
	}
sl@0
    77
sl@0
    78
// count the number of tasks associated with this schedule
sl@0
    79
static TInt CountTasksL(TInt aScheduleId)	
sl@0
    80
	{
sl@0
    81
	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
sl@0
    82
	CleanupStack::PushL(tasks);
sl@0
    83
	GetTaskInfoL(*tasks, aScheduleId);
sl@0
    84
	TInt ret = tasks->Count();
sl@0
    85
	CleanupStack::PopAndDestroy(tasks);
sl@0
    86
	return ret;
sl@0
    87
	}
sl@0
    88
sl@0
    89
// count the number of schedules based on a filter.
sl@0
    90
static TInt CountScheduledItemsL(TScheduleFilter aFilter, 
sl@0
    91
								RScheduler& aScheduler)
sl@0
    92
	{
sl@0
    93
	CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
sl@0
    94
	CleanupStack::PushL(refs);
sl@0
    95
sl@0
    96
	TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
sl@0
    97
	TEST2(res, KErrNone);
sl@0
    98
sl@0
    99
	TInt count = refs->Count();
sl@0
   100
	CleanupStack::PopAndDestroy(); // refs
sl@0
   101
	return count;
sl@0
   102
	}
sl@0
   103
sl@0
   104
//creates a daily schedule with StartTime of aStartTime
sl@0
   105
static TInt CreateScheduleL(TSchedulerItemRef& aRef, 
sl@0
   106
							RScheduler& aScheduler, 
sl@0
   107
							const TTsTime& aStartTime)
sl@0
   108
	{
sl@0
   109
	CSchEntryInfoArray* entryList 
sl@0
   110
		= new (ELeave) CSchEntryInfoArray(1);
sl@0
   111
	CleanupStack::PushL(entryList);
sl@0
   112
sl@0
   113
	TScheduleEntryInfo2 entry1 (aStartTime, EDaily, 1, 30);
sl@0
   114
	entryList->AppendL(entry1);
sl@0
   115
	TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
sl@0
   116
	CleanupStack::PopAndDestroy(); // entryList
sl@0
   117
	return res;
sl@0
   118
	}
sl@0
   119
	
sl@0
   120
// creates a schedule with numerous entries	
sl@0
   121
static TInt CreateSchedule1L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
sl@0
   122
	{
sl@0
   123
	aRef.iName = _L("Schedule created using \"CreateSchedule1L\"");
sl@0
   124
sl@0
   125
	CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
sl@0
   126
	CleanupStack::PushL(entryList);
sl@0
   127
sl@0
   128
	{
sl@0
   129
	TTsTime startTime1(SchSvrHelpers::TimeBasedOnOffset(10, 0), EFalse); // 0m:10s from "now"
sl@0
   130
	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
sl@0
   131
	entryList->AppendL(entry1);
sl@0
   132
	}
sl@0
   133
	{
sl@0
   134
	TTsTime startTime2(SchSvrHelpers::TimeBasedOnOffset(20, 0), EFalse); // 0m:20s from "now"
sl@0
   135
	TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 20);
sl@0
   136
	entryList->AppendL(entry2);
sl@0
   137
	}
sl@0
   138
	{
sl@0
   139
	TTsTime startTime3(SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, -1), EFalse); // -1 year from "now"
sl@0
   140
	TScheduleEntryInfo2 entry3 (startTime3, EDaily, 1, 20);
sl@0
   141
	entryList->AppendL(entry3);
sl@0
   142
	}
sl@0
   143
sl@0
   144
	TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
sl@0
   145
	CleanupStack::PopAndDestroy(); // entryList
sl@0
   146
	return res;
sl@0
   147
	}
sl@0
   148
sl@0
   149
// creates a schedule with numerous entries	
sl@0
   150
static TInt CreateSchedule2L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
sl@0
   151
	{
sl@0
   152
	CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
sl@0
   153
	CleanupStack::PushL(entryList);
sl@0
   154
sl@0
   155
	aRef.iName = _L("Schedule created using \"CreateSchedule2L\"");
sl@0
   156
sl@0
   157
	{
sl@0
   158
	TTsTime startTime1(SchSvrHelpers::TimeBasedOnOffset(30, 2), EFalse); // 2m:30s from "now"
sl@0
   159
	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
sl@0
   160
	entryList->AppendL(entry1);
sl@0
   161
	}
sl@0
   162
	{
sl@0
   163
	TTsTime startTime2(SchSvrHelpers::TimeBasedOnOffset(0, 5), EFalse);  // 5m:00s from "now"
sl@0
   164
	TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 20);
sl@0
   165
	entryList->AppendL(entry2);
sl@0
   166
	}
sl@0
   167
sl@0
   168
	TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
sl@0
   169
	CleanupStack::PopAndDestroy(); // entryList
sl@0
   170
	return res;
sl@0
   171
	}
sl@0
   172
sl@0
   173
// creates a schedule with numerous entries	
sl@0
   174
static TInt CreateSchedule3L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
sl@0
   175
	{
sl@0
   176
	CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
sl@0
   177
	CleanupStack::PushL(entryList);
sl@0
   178
sl@0
   179
	aRef.iName = _L("Schedule created using \"CreateSchedule3L\"");
sl@0
   180
sl@0
   181
	{
sl@0
   182
	TTsTime startTime1(SchSvrHelpers::TimeBasedOnOffset(0, 9, 0, 20), EFalse); // 9mins and 20days in the future
sl@0
   183
	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 5); // repeat every day and valid for only 5 minutes 
sl@0
   184
	entryList->AppendL(entry1);
sl@0
   185
	}
sl@0
   186
	
sl@0
   187
	{
sl@0
   188
	TTsTime startTime2(SchSvrHelpers::TimeBasedOnOffset(0, 11, 0, 20), EFalse); // 11mins and 20days in the future
sl@0
   189
	TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 5);
sl@0
   190
	entryList->AppendL(entry2);
sl@0
   191
	}
sl@0
   192
sl@0
   193
	TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
sl@0
   194
	CleanupStack::PopAndDestroy(); // entryList
sl@0
   195
sl@0
   196
	return res;
sl@0
   197
	}
sl@0
   198
sl@0
   199
// schedules a persistent task associated with the supplied schedule ID
sl@0
   200
static TInt SchedulePersistentTaskL(const TName& aName, 
sl@0
   201
									TInt& aNewId, 
sl@0
   202
									TInt aScheduleId, 
sl@0
   203
									TInt aRepeat, 
sl@0
   204
									RScheduler& aScheduler)
sl@0
   205
	{
sl@0
   206
	TTaskInfo taskInfo;
sl@0
   207
	taskInfo.iTaskId = aNewId;
sl@0
   208
	taskInfo.iName = aName;
sl@0
   209
	taskInfo.iPriority = 2;
sl@0
   210
	taskInfo.iRepeat = aRepeat;
sl@0
   211
	HBufC* data = _L("the data").AllocLC();
sl@0
   212
	TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
sl@0
   213
	aNewId = taskInfo.iTaskId;
sl@0
   214
sl@0
   215
	CleanupStack::PopAndDestroy(); // data
sl@0
   216
	return res;
sl@0
   217
	}
sl@0
   218
sl@0
   219
/**
sl@0
   220
@file
sl@0
   221
@SYMTestCaseID				SYSLIB-SCHSVR-CT-0257
sl@0
   222
@SYMTestCaseDesc 			Replicated test for for defect (EDNAWIR-4FQJ6A) - Hometime
sl@0
   223
@SYMTestPriority 			High
sl@0
   224
@SYMTestActions  			Register twice with SchSvr and check that there are no memery leaks
sl@0
   225
@SYMTestExpectedResults		The test must not fail.
sl@0
   226
@SYMPREQ					PREQ234
sl@0
   227
*/
sl@0
   228
static void Test1L()
sl@0
   229
	{
sl@0
   230
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0257 TheTest1: Registering with the tasks scheduler without disconnecting "));    
sl@0
   231
	__UHEAP_MARK;
sl@0
   232
	TheTest.Next(_L("Connect to Scheduler"));
sl@0
   233
	TInt res = TheScheduler.Connect();
sl@0
   234
	TEST2(res, KErrNone);
sl@0
   235
sl@0
   236
	TheTest.Next(_L("Registering Client"));
sl@0
   237
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   238
sl@0
   239
	TheScheduler.Close();
sl@0
   240
	__UHEAP_MARKEND;
sl@0
   241
sl@0
   242
	__UHEAP_MARK;
sl@0
   243
	TheTest.Next(_L("Connect to Scheduler again"));
sl@0
   244
	res = TheScheduler.Connect();
sl@0
   245
	TEST2(res, KErrNone);
sl@0
   246
sl@0
   247
	TheTest.Next(_L("Registering client again"));
sl@0
   248
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   249
	TheScheduler.__DbgMarkHeap();
sl@0
   250
sl@0
   251
	TheTest.Next(_L("Register when already registered"));
sl@0
   252
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   253
sl@0
   254
	TheTest.Next(_L("Cancel registering client and check for memory leak"));
sl@0
   255
	TheScheduler.__DbgMarkEnd(0);
sl@0
   256
	TheScheduler.Close();
sl@0
   257
	__UHEAP_MARKEND;
sl@0
   258
	}
sl@0
   259
sl@0
   260
sl@0
   261
//***********************************************************************************
sl@0
   262
sl@0
   263
/**
sl@0
   264
@file
sl@0
   265
@SYMTestCaseID				SYSLIB-SCHSVR-CT-0258
sl@0
   266
@SYMTestCaseDesc 			Replicated test for for defect (EDNHLJT-4TRAAE) - Hometime
sl@0
   267
@SYMTestPriority 			High
sl@0
   268
@SYMTestActions  			Create schedule, kill server (simulate re-boot), and make sure task still completes
sl@0
   269
@SYMTestExpectedResults		The test must not fail.
sl@0
   270
@SYMPREQ					PREQ234
sl@0
   271
*/
sl@0
   272
static void Test2L()
sl@0
   273
	{
sl@0
   274
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0258 TheTest2: Resend after hard reset (simulation) "));
sl@0
   275
    
sl@0
   276
	TheTest.Next(_L("Connect to Scheduler"));
sl@0
   277
	TInt res = TheScheduler.Connect();
sl@0
   278
	TEST2(res, KErrNone);
sl@0
   279
sl@0
   280
	TheTest.Next(_L("Registering Client"));
sl@0
   281
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   282
sl@0
   283
	// Create a schedule
sl@0
   284
	TheTest.Next(_L("Creating schedule"));
sl@0
   285
	TSchedulerItemRef scheduleHandle;
sl@0
   286
	TTime time;
sl@0
   287
	time.HomeTime();
sl@0
   288
	time += TTimeIntervalSeconds(2); //Task to go off two seconds from now
sl@0
   289
	TTsTime time2 (time, EFalse);
sl@0
   290
	User::LeaveIfError(CreateScheduleL(scheduleHandle, TheScheduler, time2));  
sl@0
   291
sl@0
   292
	// Add a task to the schedule
sl@0
   293
	TheTest.Next(_L("Creating task for schedule"));
sl@0
   294
	{
sl@0
   295
	TTaskInfo taskInfo;
sl@0
   296
	taskInfo.iName = _L("MyTaskName");
sl@0
   297
	taskInfo.iPriority = 2;
sl@0
   298
	taskInfo.iTaskId = 0;
sl@0
   299
	taskInfo.iRepeat = 1;
sl@0
   300
	HBufC* data = _L("Task Data").AllocLC();
sl@0
   301
	TInt res = TheScheduler.ScheduleTask(taskInfo, *data, scheduleHandle.iHandle);
sl@0
   302
	CleanupStack::PopAndDestroy(); // data
sl@0
   303
	TEST2(res, KErrNone);
sl@0
   304
	}
sl@0
   305
sl@0
   306
	// Kill the server !!
sl@0
   307
	TheTest.Next(_L("Killing server"));
sl@0
   308
	// Need to turn off JIT dubugging as we are panicking server and we 
sl@0
   309
	// want test to keep running.
sl@0
   310
	TBool jit = User::JustInTime();
sl@0
   311
	User::SetJustInTime(EFalse);
sl@0
   312
sl@0
   313
	TheScheduler.__FaultServer();
sl@0
   314
	User::After(100000);
sl@0
   315
	
sl@0
   316
	// Turn on JIT again.
sl@0
   317
	User::SetJustInTime(jit);
sl@0
   318
	
sl@0
   319
	// Connect to the server again
sl@0
   320
	TheTest.Next(_L("Re-connect to Scheduler"));
sl@0
   321
	res = TheScheduler.Connect();
sl@0
   322
	TEST2(res, KErrNone);
sl@0
   323
sl@0
   324
	// Re-register
sl@0
   325
	TheTest.Next(_L("Re-register Client"));
sl@0
   326
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   327
sl@0
   328
	TheTest.Next(_L("Check schedule count and task count"));
sl@0
   329
	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   330
	TEST(scheduleCount == 1);
sl@0
   331
	TInt taskCount = CountTasksL(scheduleHandle.iHandle);
sl@0
   332
	TEST(taskCount == 1);
sl@0
   333
	
sl@0
   334
	// Wait for task to fire... It should happen in about 2 seconds
sl@0
   335
	TheTest.Next(_L("Waiting for task to complete"));
sl@0
   336
	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
sl@0
   337
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   338
	}
sl@0
   339
sl@0
   340
//***********************************************************************************
sl@0
   341
sl@0
   342
/**
sl@0
   343
@file
sl@0
   344
@SYMTestCaseID				SYSLIB-SCHSVR-CT-0259
sl@0
   345
@SYMTestCaseDesc 			Replicated test for CR (AALR-4EDG75) - Hometime
sl@0
   346
@SYMTestPriority 			High
sl@0
   347
@SYMTestActions  			Test changes to Schedule Server API
sl@0
   348
@SYMTestExpectedResults		The test must not fail.
sl@0
   349
@SYMPREQ					PREQ234
sl@0
   350
*/
sl@0
   351
static void Test3L()
sl@0
   352
	{
sl@0
   353
	//
sl@0
   354
	//
sl@0
   355
	// Test changes to Schedule Server API as of Change Request document AALR-4EDG75
sl@0
   356
	// (GT change requests database)
sl@0
   357
	//
sl@0
   358
	//
sl@0
   359
	//
sl@0
   360
	// This test establishes that the change to...
sl@0
   361
	//
sl@0
   362
	//	RScheduler::GetScheduleL(const TInt aScheduleHandle,
sl@0
   363
	//								 TScheduleState& aState,
sl@0
   364
	//								 CArrayFixFlat<TScheduleEntryInfo>& aEntries,
sl@0
   365
	//								 CArrayFixFlat<TTaskInfo>& aTasks,
sl@0
   366
	//								 TTime& aNextDue)
sl@0
   367
	//
sl@0
   368
	// ...is functionally correct.
sl@0
   369
	// 
sl@0
   370
	//
sl@0
   371
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0259 Test change request AALR-4EDG75 implementation "));
sl@0
   372
	
sl@0
   373
	TheTest.Next(_L("Connect to Scheduler"));
sl@0
   374
	TInt res = TheScheduler.Connect();
sl@0
   375
	TEST2(res, KErrNone);
sl@0
   376
sl@0
   377
	TheTest.Next(_L("Registering Client"));
sl@0
   378
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   379
sl@0
   380
	const TDateTime KTimeToStartTask(2000, EJanuary, 10, 15, 30, 0, 0);
sl@0
   381
sl@0
   382
	TSchedulerItemRef schedulerItemReference;
sl@0
   383
	CSchEntryInfoArray* entryArray = new(ELeave) CSchEntryInfoArray(1);
sl@0
   384
	CleanupStack::PushL(entryArray);
sl@0
   385
	
sl@0
   386
	HBufC* taskData = _L("This is some dummy task data created for testing").AllocL();
sl@0
   387
	CleanupStack::PushL(taskData);
sl@0
   388
	
sl@0
   389
	// Prepare the task info - this describes the tasks that are contained within the task
sl@0
   390
	// entry array
sl@0
   391
	TTaskInfo taskInfo = SchSvrHelpers::TaskInfo(_L("A transient test task"), 100);
sl@0
   392
		
sl@0
   393
	// Create a schedule entry and append it to the entry array
sl@0
   394
	{
sl@0
   395
	TScheduleEntryInfo2 scheduleEntry = SchSvrHelpers::ScheduleEntryInfo(EDaily, TTsTime(TTime(KTimeToStartTask), EFalse), 7, 2);
sl@0
   396
	entryArray->AppendL(scheduleEntry);
sl@0
   397
	}
sl@0
   398
sl@0
   399
	// Create the transient task
sl@0
   400
	TInt ret = TheScheduler.ScheduleTask(taskInfo, *taskData, schedulerItemReference, *entryArray);
sl@0
   401
	TEST2(ret, KErrNone);
sl@0
   402
sl@0
   403
	// Check that the task Id after scheduling the event is not 
sl@0
   404
	// the same as it was prior to the requesting the service
sl@0
   405
	TEST(taskInfo.iTaskId != -1);
sl@0
   406
sl@0
   407
	//
sl@0
   408
	// Now obtain info about the scheduled transient task...
sl@0
   409
	//
sl@0
   410
	TScheduleState2 scheduleState;
sl@0
   411
	TTsTime nextTaskDueTime;
sl@0
   412
sl@0
   413
	// Reset the schedule entry info array as the server now has copies of this and it is
sl@0
   414
	// no longer required client-side
sl@0
   415
	entryArray->Reset();
sl@0
   416
	CTaskInfoArray* taskInfoArray = new(ELeave) CTaskInfoArray(4);
sl@0
   417
	CleanupStack::PushL(taskInfoArray);
sl@0
   418
sl@0
   419
	// Request task schedule information from the server
sl@0
   420
	ret = TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime);
sl@0
   421
	TEST2(ret, KErrNone);
sl@0
   422
sl@0
   423
	// Because this is a daily task which is scheduled to occur at a specific time (but the date
sl@0
   424
	// cannot necessarily be established, we can perform a simple check to ensure that the
sl@0
   425
	// time when the task is next scheduled to run falls within the 15:30 - 17:30 bracket.
sl@0
   426
	
sl@0
   427
	TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), EFalse)) == (TInt) ETrue);
sl@0
   428
sl@0
   429
	// Establish and test the size of the task data for the specified task object
sl@0
   430
	TInt sizeOfTaskData = 0;
sl@0
   431
	TEST2(TheScheduler.GetTaskDataSize(taskInfo.iTaskId, sizeOfTaskData), KErrNone);
sl@0
   432
	TEST(sizeOfTaskData == taskData->Length());
sl@0
   433
sl@0
   434
	// Now check the information return from the server pertaining to a specific task...
sl@0
   435
	{
sl@0
   436
	TTaskInfo taskFromServer;
sl@0
   437
	HBufC* taskDataFromServer					= HBufC::NewLC(sizeOfTaskData);
sl@0
   438
	TPtr pTaskDataFromServer					= taskDataFromServer->Des();
sl@0
   439
	TTime nullTime								= Time::NullTTime();
sl@0
   440
	TTsTime nextDueTimeFromServer (nullTime, EFalse);
sl@0
   441
	TSchedulerItemRef schedulerRefFromServer;
sl@0
   442
	TEST2(TheScheduler.GetTaskInfoL(taskInfo.iTaskId, taskFromServer, pTaskDataFromServer, schedulerRefFromServer, nextDueTimeFromServer), KErrNone);
sl@0
   443
	TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), EFalse)) == (TInt) ETrue);
sl@0
   444
	
sl@0
   445
	TEST(SchSvrHelpers::IsTaskInfoTheSame(taskFromServer, taskInfo) == (TInt) ETrue);
sl@0
   446
	TEST(SchSvrHelpers::IsItemRefTheSame(schedulerRefFromServer, schedulerItemReference) == (TInt) ETrue);
sl@0
   447
	CleanupStack::PopAndDestroy(); // taskDataFromServer
sl@0
   448
	}
sl@0
   449
sl@0
   450
	// Disable the schedule and check when it is next schedule to run
sl@0
   451
	TEST2(TheScheduler.DisableSchedule(schedulerItemReference.iHandle), KErrNone);
sl@0
   452
sl@0
   453
	// Get the new schedule info - check that the nextDueTime is still reported even
sl@0
   454
	// though the schedule has been disabled
sl@0
   455
	
sl@0
   456
	nextTaskDueTime.SetLocalTime(Time::NullTTime());
sl@0
   457
	TEST2(TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime), KErrNone);
sl@0
   458
	TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), EFalse)) == (TInt) ETrue);
sl@0
   459
	TEST(SchSvrHelpers::IsTaskInfoTheSame(taskInfoArray->At(0), taskInfo) == (TInt) ETrue);
sl@0
   460
sl@0
   461
	// Re-enable the schedule
sl@0
   462
	TEST2(TheScheduler.EnableSchedule(schedulerItemReference.iHandle), KErrNone);
sl@0
   463
sl@0
   464
	// Delete the only task (relating to this test) from the server
sl@0
   465
	TEST2(TheScheduler.DeleteTask(taskInfo.iTaskId), KErrNone);
sl@0
   466
	ret = TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime);
sl@0
   467
	TEST2(ret, KErrNotFound); // there is no longer any tasks associated with this schedule
sl@0
   468
sl@0
   469
	CleanupStack::PopAndDestroy(3); // taskInfoArray, entryArray, taskData
sl@0
   470
	}
sl@0
   471
sl@0
   472
//***********************************************************************************
sl@0
   473
sl@0
   474
/**
sl@0
   475
@file
sl@0
   476
@SYMTestCaseID				SYSLIB-SCHSVR-CT-0260
sl@0
   477
@SYMTestCaseDesc 			Replicated test for defect (EDNAALR-4JKEFC) - Hometime
sl@0
   478
@SYMTestPriority 			High
sl@0
   479
@SYMTestActions  			Create 2 schedules with repeating tasks, kill server and check that tasks complete
sl@0
   480
@SYMTestExpectedResults		The test must not fail.
sl@0
   481
@SYMPREQ					PREQ234
sl@0
   482
*/
sl@0
   483
static void Test4L()
sl@0
   484
	{
sl@0
   485
	// Test title
sl@0
   486
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0260 \nTest for defect EDNAALR-4JKEFC "));
sl@0
   487
	
sl@0
   488
	TheTest.Next(_L("Connect to Scheduler"));
sl@0
   489
	TInt res = TheScheduler.Connect();
sl@0
   490
	TEST2(res, KErrNone);
sl@0
   491
sl@0
   492
	TheTest.Next(_L("Registering Client"));
sl@0
   493
	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
sl@0
   494
sl@0
   495
	// Constants / vars used in this function
sl@0
   496
	TSchedulerItemRef itemRef;
sl@0
   497
sl@0
   498
	// Create some scheduling entries
sl@0
   499
	CArrayFixFlat<TScheduleEntryInfo2>* entries = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2>(10);
sl@0
   500
	CleanupStack::PushL(entries);
sl@0
   501
sl@0
   502
	TTsTime startTime1 (SchSvrHelpers::TimeBasedOnOffset(1, 1), EFalse); // 1m:01s from "now"
sl@0
   503
	TScheduleEntryInfo2 entry1 (startTime1, EHourly, 1, 20);
sl@0
   504
	entries->AppendL(entry1);
sl@0
   505
sl@0
   506
	TTsTime startTime2 (SchSvrHelpers::TimeBasedOnOffset(5, 5), EFalse); // 5m:05s from "now"
sl@0
   507
	TScheduleEntryInfo2 entry2 (startTime2, EHourly, 1, 20);
sl@0
   508
	entries->AppendL(entry2);
sl@0
   509
sl@0
   510
	// Create the schedule for the task...
sl@0
   511
	res = TheScheduler.CreatePersistentSchedule(itemRef, *entries);
sl@0
   512
	TEST2(res, KErrNone);
sl@0
   513
sl@0
   514
	// Create the tasks themselves..
sl@0
   515
	TTaskInfo task;
sl@0
   516
	task.iRepeat	= 10; // repeat once
sl@0
   517
	task.iName		= _L("Test Task For Defect Verification");
sl@0
   518
	task.iPriority	= 100;
sl@0
   519
	HBufC* taskData = task.iName.AllocLC();
sl@0
   520
	res = TheScheduler.ScheduleTask(task, *taskData, itemRef.iHandle);
sl@0
   521
	CleanupStack::PopAndDestroy(); // taskData
sl@0
   522
sl@0
   523
	{
sl@0
   524
	CArrayFixFlat<TSchedulerItemRef>* refs = new CArrayFixFlat<TSchedulerItemRef>(3);
sl@0
   525
	CleanupStack::PushL(refs);
sl@0
   526
	TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules); 
sl@0
   527
	TEST2(res, KErrNone);
sl@0
   528
	CleanupStack::PopAndDestroy(); // refs
sl@0
   529
	}
sl@0
   530
sl@0
   531
	// Re-register theclient with the server
sl@0
   532
	for(TInt i=0; i<5; i++)
sl@0
   533
		{
sl@0
   534
		// Log off from the task scheduler
sl@0
   535
		TheScheduler.Close();
sl@0
   536
		res = TheScheduler.Connect();
sl@0
   537
		TEST2(res, KErrNone);
sl@0
   538
sl@0
   539
		User::After(1000000);
sl@0
   540
sl@0
   541
		TheTest.Next(_L("===== Re-registering Client (wait a second) ====="));
sl@0
   542
		res = SchSvrHelpers::RegisterClientL(TheScheduler);
sl@0
   543
		TEST2(res, KErrNone);
sl@0
   544
			{
sl@0
   545
			CArrayFixFlat<TSchedulerItemRef>* refs = new CArrayFixFlat<TSchedulerItemRef>(3);
sl@0
   546
			CleanupStack::PushL(refs);
sl@0
   547
			TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
sl@0
   548
			TEST2(res, 0);
sl@0
   549
			CleanupStack::PopAndDestroy(); // refs
sl@0
   550
			}
sl@0
   551
sl@0
   552
		// Check the information that the scheduler knows about...
sl@0
   553
		TInt taskDataSize = 0;
sl@0
   554
		res = TheScheduler.GetTaskDataSize(task.iTaskId, taskDataSize);
sl@0
   555
		TEST2(res, KErrNone);
sl@0
   556
		TEST(taskDataSize == task.iName.Length());
sl@0
   557
		TTaskInfo taskInfoFromServer;
sl@0
   558
		taskData = HBufC::NewLC(taskDataSize);
sl@0
   559
		TPtr pTaskData = taskData->Des();
sl@0
   560
sl@0
   561
		TTsTime nextDueTime(Time::NullTTime(), EFalse);
sl@0
   562
		res = TheScheduler.GetTaskInfoL(task.iTaskId, taskInfoFromServer, pTaskData, itemRef, nextDueTime);
sl@0
   563
		TEST2(res, KErrNone);
sl@0
   564
		TEST(pTaskData == task.iName);
sl@0
   565
		CleanupStack::PopAndDestroy(); // taskData
sl@0
   566
		}
sl@0
   567
sl@0
   568
	CleanupStack::PopAndDestroy(); // entries
sl@0
   569
sl@0
   570
	}
sl@0
   571
sl@0
   572
//***********************************************************************************
sl@0
   573
sl@0
   574
/**
sl@0
   575
@file
sl@0
   576
@SYMTestCaseID				SYSLIB-SCHSVR-CT-0261
sl@0
   577
@SYMTestCaseDesc 			Persistant schedule test - Hometime
sl@0
   578
@SYMTestPriority 			High
sl@0
   579
@SYMTestActions  			Mark heap, create persistent schedules, schedule tasks, transient schedules, delete tasks, delete remaing schedules, check heap
sl@0
   580
@SYMTestExpectedResults		The test must not fail.
sl@0
   581
@SYMPREQ					PREQ234
sl@0
   582
*/
sl@0
   583
static void Test5L()
sl@0
   584
	{
sl@0
   585
	TInt res = KErrNone;
sl@0
   586
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0261 ===== Starting test 1 ===== "));	
sl@0
   587
	__UHEAP_MARK;
sl@0
   588
	
sl@0
   589
	TSchedulerItemRef ref1;
sl@0
   590
	TSchedulerItemRef ref2;
sl@0
   591
	TSchedulerItemRef ref3;
sl@0
   592
sl@0
   593
	// Remove all existing schedules before starting the test
sl@0
   594
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
   595
	
sl@0
   596
	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   597
	TEST(scheduleCount == 0); // check that no schedules are present.
sl@0
   598
	
sl@0
   599
	TheTest.Printf(_L("Create some schedules\n"));
sl@0
   600
	res = CreateSchedule1L(ref1, TheScheduler); // +10sec, +20sec, -1year
sl@0
   601
	TEST2(res, KErrNone);	
sl@0
   602
	res = CreateSchedule2L(ref2, TheScheduler); // +2min 30sec, +5min
sl@0
   603
	TEST2(res, KErrNone);
sl@0
   604
	res = CreateSchedule3L(ref3, TheScheduler); // +20day 9min, +20day 11min
sl@0
   605
	TEST2(res, KErrNone);
sl@0
   606
sl@0
   607
	TSchedulerItemRef ref4;
sl@0
   608
	TSchedulerItemRef ref5;
sl@0
   609
	res = CreateSchedule2L(ref4, TheScheduler); // +2min 30sec, 5min
sl@0
   610
	TEST2(res, KErrNone);
sl@0
   611
	res = CreateSchedule3L(ref5, TheScheduler); // +20day 9min, +20day 11min
sl@0
   612
	TEST2(res, KErrNone);
sl@0
   613
sl@0
   614
	TInt task1 = 0;
sl@0
   615
	TInt task2 = 0;
sl@0
   616
	TInt task3 = 0;
sl@0
   617
	TInt task4 = 0;
sl@0
   618
	TName name1 = (_L("web subscription"));
sl@0
   619
	TName name2 = (_L("another web subscription"));
sl@0
   620
	TName name3 = (_L("third web subscription"));
sl@0
   621
sl@0
   622
	TheTest.Printf(_L("Schedule some tasks\n"));
sl@0
   623
sl@0
   624
	// NOTE: have to put repeats here of > 0 otherwise the task will run immediately
sl@0
   625
	// (because it's schedule specifies a date of 1 year in the past!) and be
sl@0
   626
	// removed (by the server) before we have a chance to delete it....
sl@0
   627
	res = SchedulePersistentTaskL(name1, task1, ref1.iHandle, 3, TheScheduler);
sl@0
   628
	TEST2(res, KErrNone);
sl@0
   629
	res = SchedulePersistentTaskL(name2, task2, ref2.iHandle, 3, TheScheduler);
sl@0
   630
	TEST2(res, KErrNone);
sl@0
   631
	res = SchedulePersistentTaskL(name3, task3, ref3.iHandle, 3, TheScheduler);
sl@0
   632
	TEST2(res, KErrNone);
sl@0
   633
	res = SchedulePersistentTaskL(name3, task4, ref3.iHandle, 3, TheScheduler);
sl@0
   634
	TEST2(res, KErrNone);
sl@0
   635
sl@0
   636
	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   637
	TEST(scheduleCount == 5); // 5 persistant
sl@0
   638
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   639
sl@0
   640
	TheTest.Printf(_L("Deleting task with id %d\n"), task1);
sl@0
   641
	res = TheScheduler.DeleteTask(task1);
sl@0
   642
	TEST2(res, KErrNone);
sl@0
   643
	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
sl@0
   644
	res = TheScheduler.DeleteSchedule(ref1.iHandle);
sl@0
   645
	TEST2(res, KErrNone);
sl@0
   646
	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   647
	// 4 persistant expected as we have deleted one
sl@0
   648
	TEST(scheduleCount == 4); 
sl@0
   649
sl@0
   650
	TheTest.Printf(_L("Deleting task with id %d\n"), task2);
sl@0
   651
	res = TheScheduler.DeleteTask(task2);
sl@0
   652
	TEST2(res, KErrNone);
sl@0
   653
	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref2.iHandle);
sl@0
   654
	res = TheScheduler.DeleteSchedule(ref2.iHandle);
sl@0
   655
	TEST2(res, KErrNone);
sl@0
   656
	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   657
	// 3 persistant  expected as we have deleted one
sl@0
   658
	TEST(scheduleCount == 3); 
sl@0
   659
sl@0
   660
	TheTest.Printf(_L("Deleting task with id %d\n"), task3);
sl@0
   661
	res = TheScheduler.DeleteTask(task3);
sl@0
   662
	TEST2(res, KErrNone);
sl@0
   663
	TheTest.Printf(_L("Deleting task with id %d\n"), task4);
sl@0
   664
	res = TheScheduler.DeleteTask(task4);
sl@0
   665
	TEST2(res, KErrNone);
sl@0
   666
	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref3.iHandle);
sl@0
   667
	res = TheScheduler.DeleteSchedule(ref3.iHandle);
sl@0
   668
	TEST2(res, KErrNone);
sl@0
   669
	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   670
	// 2 persistant  expected as we have deleted one
sl@0
   671
	TEST(scheduleCount == 2); 
sl@0
   672
sl@0
   673
	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref4.iHandle);
sl@0
   674
	res = TheScheduler.DeleteSchedule(ref4.iHandle);
sl@0
   675
	TEST2(res, KErrNone);
sl@0
   676
	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref5.iHandle);
sl@0
   677
	res = TheScheduler.DeleteSchedule(ref5.iHandle);
sl@0
   678
	TEST2(res, KErrNone);
sl@0
   679
sl@0
   680
	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   681
	TEST(scheduleCount == 0); 
sl@0
   682
	
sl@0
   683
	SchSvrHelpers::Pause(TheTest,1);
sl@0
   684
	__UHEAP_MARKEND;
sl@0
   685
	}
sl@0
   686
sl@0
   687
sl@0
   688
//***********************************************************************************
sl@0
   689
sl@0
   690
/**
sl@0
   691
@file
sl@0
   692
@SYMTestCaseID				SYSLIB-SCHSVR-CT-0262
sl@0
   693
@SYMTestCaseDesc 			Transient schedule test - Hometime
sl@0
   694
@SYMTestPriority 			High
sl@0
   695
@SYMTestActions  			Create transient schedule with non-repeating task
sl@0
   696
@SYMTestExpectedResults		The test must not fail.
sl@0
   697
@SYMPREQ					PREQ234
sl@0
   698
*/
sl@0
   699
static void Test6L()
sl@0
   700
	{
sl@0
   701
	// Heap testing removed because this is a flakey bit of code.
sl@0
   702
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0262 Transient, non-repeating - waits for schedule to activate "));
sl@0
   703
	
sl@0
   704
	// Remove all existing schedules before starting the test
sl@0
   705
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
   706
sl@0
   707
	// Create transient schedule
sl@0
   708
	TheTest.Printf(_L("Create transient schedule with non-repeating task\n"));
sl@0
   709
	TSchedulerItemRef ref;
sl@0
   710
	CSchEntryInfoArray* entryList = new(ELeave) CSchEntryInfoArray(1);
sl@0
   711
	CleanupStack::PushL(entryList);
sl@0
   712
	ref.iName = _L("A Transient Schedule");
sl@0
   713
sl@0
   714
	// CREATE SCHEDULE ENTRY:
sl@0
   715
	// starttime 5 secs in the future, hometime based
sl@0
   716
	TTsTime startTime(SchSvrHelpers::TimeBasedOnOffset(5), EFalse);
sl@0
   717
	// constructor takes: starttime, interval type, interval, validity period
sl@0
   718
	TScheduleEntryInfo2 entry(startTime, EDaily, 1, 20);
sl@0
   719
	entryList->AppendL(entry);
sl@0
   720
sl@0
   721
	// CREATE SCHEDULE TASK:
sl@0
   722
	TTaskInfo taskInfo;
sl@0
   723
	taskInfo.iName = _L("mail");
sl@0
   724
	taskInfo.iTaskId = 0;
sl@0
   725
	taskInfo.iRepeat = 1;
sl@0
   726
	taskInfo.iPriority = 2;
sl@0
   727
	HBufC* data = _L("This is the data for the task").AllocLC();
sl@0
   728
sl@0
   729
	// Schedule the item
sl@0
   730
	TInt res = TheScheduler.ScheduleTask(taskInfo, *data, ref, *entryList);
sl@0
   731
	TEST2(res, KErrNone);
sl@0
   732
	CleanupStack::PopAndDestroy(2, entryList); // data, entryList
sl@0
   733
	
sl@0
   734
	// Should be one item
sl@0
   735
	TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 1);
sl@0
   736
sl@0
   737
	// Waiting for entry to complete
sl@0
   738
	TheTest.Next(_L("Waiting for for task to complete"));
sl@0
   739
	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
sl@0
   740
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   741
	// Should be no items as schedule deletes itself after task has completed
sl@0
   742
	TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 0);
sl@0
   743
sl@0
   744
	SchSvrHelpers::Pause(TheTest,1);
sl@0
   745
	}
sl@0
   746
sl@0
   747
sl@0
   748
//***********************************************************************************
sl@0
   749
sl@0
   750
/**
sl@0
   751
@file
sl@0
   752
@SYMTestCaseID				SYSLIB-SCHSVR-CT-0263
sl@0
   753
@SYMTestCaseDesc 			Persistant schedule test with repeating task - Hometime
sl@0
   754
@SYMTestPriority 			High
sl@0
   755
@SYMTestActions  			Persistent schedule, repeating task, non-repeating task, go off, check task's still there, go off again, check it's still there, delete task, delete schedule, 
sl@0
   756
@SYMTestExpectedResults		The test must not fail.
sl@0
   757
@SYMPREQ					PREQ234
sl@0
   758
*/
sl@0
   759
static void Test7L()
sl@0
   760
	{
sl@0
   761
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0263 Test persistent scheduling, repeating and non-repeating task schedules "));
sl@0
   762
	
sl@0
   763
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
   764
sl@0
   765
	// Transient
sl@0
   766
	TSchedulerItemRef ref;
sl@0
   767
sl@0
   768
	// We shouldn't have any outstanding schedules registered with the server
sl@0
   769
	TInt count = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   770
	TEST(count == 0);
sl@0
   771
sl@0
   772
	// This creates 3 schedule entries, each with a validity period of 20 minutes, and are
sl@0
   773
	// due to run in 10s, 20s, and over a year ago (a year in the past)
sl@0
   774
	TheTest.Printf(_L("Create Persistent schedule\n"));
sl@0
   775
	TInt res = CreateSchedule1L(ref, TheScheduler);
sl@0
   776
	TEST2(res, KErrNone);
sl@0
   777
sl@0
   778
	// We should now have one registered schedule
sl@0
   779
	count = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
   780
	TEST(count == 1);
sl@0
   781
sl@0
   782
	//
sl@0
   783
	TheTest.Printf(_L("\nSchedule two tasks: one repeating....\n"));
sl@0
   784
	//
sl@0
   785
	TInt task1 = 0;
sl@0
   786
	TName name1 = (_L("web subscription(rpts)"));
sl@0
   787
	// -1 indicates repeating schedule
sl@0
   788
	res = SchedulePersistentTaskL(name1, task1, ref.iHandle, -1, TheScheduler); // -1 indicates repeat until explicitly deleted
sl@0
   789
	TEST2(res, KErrNone);
sl@0
   790
sl@0
   791
	// List those schedules that are pending
sl@0
   792
	count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
sl@0
   793
	TEST(count == 1);
sl@0
   794
sl@0
   795
	//
sl@0
   796
	TheTest.Printf(_L("\n... and one non-repeating\n"));
sl@0
   797
	//
sl@0
   798
	TInt task2 = 0;
sl@0
   799
	TName name2 = (_L("non-repeating"));
sl@0
   800
	res = SchedulePersistentTaskL(name2, task2, ref.iHandle, 1, TheScheduler); // only runs once
sl@0
   801
	TEST2(res, KErrNone);
sl@0
   802
sl@0
   803
	TheTest.Printf(_L("Waiting for tasks to run\n"));
sl@0
   804
	// Wait for notification that schedule has executed.
sl@0
   805
	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
sl@0
   806
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   807
sl@0
   808
	TheTest.Printf(_L("...and wait again for repeating one to execute again\n"));
sl@0
   809
	// Wait for notification that schedule has executed.
sl@0
   810
	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
sl@0
   811
	CleanupHelpers::KillProcess(KMinimalTaskHandler);
sl@0
   812
sl@0
   813
	TheTest.Printf(_L("Delete the repeating task, and the schedule \n"));
sl@0
   814
	res = TheScheduler.DeleteTask(task1);
sl@0
   815
	TEST2(res, KErrNone);
sl@0
   816
	res = TheScheduler.DeleteTask(task2);
sl@0
   817
	TEST2(res, KErrNotFound); //Should be not found since its only executed once.
sl@0
   818
	res = TheScheduler.DeleteSchedule(ref.iHandle);
sl@0
   819
	TEST2(res, KErrNone);
sl@0
   820
sl@0
   821
	count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
sl@0
   822
	TEST(count == 0);
sl@0
   823
	SchSvrHelpers::Pause(TheTest, 1);
sl@0
   824
	}
sl@0
   825
sl@0
   826
sl@0
   827
static CSchEntryInfoArray* CreateSchEntryInfoArrayLC(TInt aGranularity)
sl@0
   828
	{
sl@0
   829
	CSchEntryInfoArray*	scheduleEntries	= new (ELeave) CSchEntryInfoArray(aGranularity);
sl@0
   830
	CleanupStack::PushL(scheduleEntries);
sl@0
   831
	return scheduleEntries;
sl@0
   832
	}
sl@0
   833
sl@0
   834
static CArrayFixFlat<TTaskInfo>* CreateTaskInfoLC(TInt aGranularity)
sl@0
   835
	{
sl@0
   836
	CArrayFixFlat<TTaskInfo>* taskInfos	= new (ELeave) CArrayFixFlat<TTaskInfo>(aGranularity);
sl@0
   837
	CleanupStack::PushL(taskInfos);
sl@0
   838
	return taskInfos;
sl@0
   839
	}
sl@0
   840
sl@0
   841
static CSchItemRefArray* CreateScheduleRefsLC(TInt aGranularity)
sl@0
   842
	{
sl@0
   843
	CSchItemRefArray* scheduleReferences = new (ELeave) CSchItemRefArray(aGranularity);
sl@0
   844
	CleanupStack::PushL(scheduleReferences);
sl@0
   845
	return scheduleReferences;
sl@0
   846
	}
sl@0
   847
sl@0
   848
static void CreateTransientScheduledTasksL(TInt aNumScheduleEntries,
sl@0
   849
										   TInt aNumSchedules,
sl@0
   850
										   CSchEntryInfoArray* aScheduleEntries,
sl@0
   851
										   CArrayFixFlat<TTaskInfo>* aTaskInfos,
sl@0
   852
										   CSchItemRefArray* aScheduleReferences)
sl@0
   853
	{
sl@0
   854
	const TTimeIntervalMicroSeconds timeToAdd = 10000000; //10 seconds
sl@0
   855
	const TTimeIntervalMicroSeconds timeLimit = 5000000; // 5 seconds
sl@0
   856
	_LIT(KTaskDataPrefix, "Task Data Entry: ");
sl@0
   857
	// Prepare keys required
sl@0
   858
	TKeyArrayFix KTaskInfoSortKey(_FOFF(TTaskInfo, iTaskId), ECmpTInt);
sl@0
   859
sl@0
   860
	for(TInt i=0;i<aNumSchedules;i++)
sl@0
   861
		{	
sl@0
   862
		// Remove any existing schedule entry info's
sl@0
   863
		aScheduleEntries->Reset();
sl@0
   864
		//
sl@0
   865
		// Populate the schedule entry array with a varying list of 
sl@0
   866
		// start-times, intervals, etc for this particular task
sl@0
   867
		//
sl@0
   868
		for(TInt j=0; j<aNumScheduleEntries; ++j)
sl@0
   869
			{
sl@0
   870
			TScheduleEntryInfo2 scheduleEntry = SchSvrHelpers::RandomScheduleEntryInfoHometime(TheSeed);
sl@0
   871
			TTime now;
sl@0
   872
			now.HomeTime(); // sets now to home time
sl@0
   873
			TTime sTime = scheduleEntry.StartTime().GetLocalTime();
sl@0
   874
			//if scheduleEntry.StartTime() is set lower then 5 sec into the future, postpone StartTime 10 sec into the future
sl@0
   875
			if(sTime < now + timeLimit) 
sl@0
   876
				{
sl@0
   877
				TTsTime newTime (now + timeToAdd, EFalse);
sl@0
   878
				scheduleEntry.SetStartTime(newTime); 					
sl@0
   879
				}
sl@0
   880
			aScheduleEntries->AppendL(scheduleEntry);
sl@0
   881
			}
sl@0
   882
		//
sl@0
   883
		// Create some dummy task data
sl@0
   884
		//
sl@0
   885
		HBufC* taskData = HBufC::NewLC(KTaskDataPrefix().Length()+4);
sl@0
   886
		taskData->Des().Copy(KTaskDataPrefix());
sl@0
   887
		taskData->Des().AppendNum(i);
sl@0
   888
		//
sl@0
   889
		// Munge the task name
sl@0
   890
		//
sl@0
   891
		TTaskInfo taskInfo;
sl@0
   892
		taskInfo.iName = *taskData;
sl@0
   893
		taskInfo.iRepeat = 1;
sl@0
   894
		taskInfo.iPriority = 1;
sl@0
   895
		// Schedule the transient task
sl@0
   896
		TSchedulerItemRef scheduleReference;
sl@0
   897
		TInt result = TheScheduler.ScheduleTask(taskInfo, 
sl@0
   898
												*taskData, 
sl@0
   899
												scheduleReference, 
sl@0
   900
												*aScheduleEntries);
sl@0
   901
		TEST2(result, KErrNone);
sl@0
   902
		TheTest.Printf(_L("TaskId: %d => TaskName: %S\n"), taskInfo.iTaskId, &taskInfo.iName);
sl@0
   903
		CleanupStack::PopAndDestroy(taskData);
sl@0
   904
		//
sl@0
   905
		// Save the taskInfo so we can check it later - this inserts the taskinfo into
sl@0
   906
		// the array (preserves sorted order by TTaskInfo.iTaskId) but also has the
sl@0
   907
		// added bonus of preventing duplicate task ids...
sl@0
   908
		//
sl@0
   909
		aTaskInfos->InsertIsqL(taskInfo, KTaskInfoSortKey);
sl@0
   910
		// Disable all schedules once added, just to stop them going off
sl@0
   911
		// and therefore being deleted when we are trying to compare them 
sl@0
   912
		result = TheScheduler.DisableSchedule(scheduleReference.iHandle);
sl@0
   913
		TEST2(result, KErrNone);
sl@0
   914
		// Save the sever generated schedule reference and taskId for checking later
sl@0
   915
		aScheduleReferences->AppendL(scheduleReference);
sl@0
   916
		}
sl@0
   917
	}
sl@0
   918
sl@0
   919
static void CheckScheduledRefs(TInt aNumSchedules)
sl@0
   920
	{
sl@0
   921
	CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
sl@0
   922
	CleanupStack::PushL(refs);
sl@0
   923
	TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules); 
sl@0
   924
	TEST2(res, KErrNone);
sl@0
   925
	TInt count = refs->Count();
sl@0
   926
	TEST(count == aNumSchedules);
sl@0
   927
	CleanupStack::PopAndDestroy(refs);
sl@0
   928
	}
sl@0
   929
sl@0
   930
static void TestScheduledTasksL(TInt aNumSchedules,
sl@0
   931
								CArrayFixFlat<TTaskInfo>* aTaskInfos)
sl@0
   932
	{
sl@0
   933
	for(TInt n=0; n<aNumSchedules; ++n)
sl@0
   934
		{
sl@0
   935
		const TTaskInfo& taskInfo = aTaskInfos->At(n);
sl@0
   936
sl@0
   937
		// First retrieve the task size
sl@0
   938
		TInt taskSize;
sl@0
   939
		TInt result = TheScheduler.GetTaskDataSize(taskInfo.iTaskId, taskSize);
sl@0
   940
		TEST2(result, KErrNone);
sl@0
   941
		TEST(taskSize > 0);
sl@0
   942
sl@0
   943
		// Next retrieve the task info associated with a particular task Id
sl@0
   944
		HBufC* taskData = HBufC::NewLC(taskSize);
sl@0
   945
		TPtr pTaskData = taskData->Des();
sl@0
   946
sl@0
   947
		TTsTime scheduleNextDueTime;
sl@0
   948
		TTaskInfo taskFromServer;
sl@0
   949
		TSchedulerItemRef scheduleReference;
sl@0
   950
sl@0
   951
		result = TheScheduler.GetTaskInfoL(taskInfo.iTaskId,
sl@0
   952
										   taskFromServer, 
sl@0
   953
										   pTaskData, 
sl@0
   954
										   scheduleReference, 
sl@0
   955
										   scheduleNextDueTime);
sl@0
   956
		TEST2(result, KErrNone);
sl@0
   957
		TEST(taskData->Length() == taskSize);
sl@0
   958
sl@0
   959
		// Now check that the task returned by the server matches that held locallly....
sl@0
   960
		TBool bbb = SchSvrHelpers::IsTaskInfoTheSame(taskFromServer, taskInfo);
sl@0
   961
		if(!bbb)
sl@0
   962
			{
sl@0
   963
			RDebug::Print(_L("TaskInfo1. repeat=%x, id=%d, name=%S, priority=%x\n"),
sl@0
   964
				taskFromServer.iRepeat, taskFromServer.iTaskId, &taskFromServer.iName, taskFromServer.iPriority);
sl@0
   965
			RDebug::Print(_L("TaskInfo2. repeat=%x, id=%d, name=%S, priority=%x\n"),
sl@0
   966
				taskInfo.iRepeat, taskInfo.iTaskId, &taskInfo.iName, taskInfo.iPriority);
sl@0
   967
			}
sl@0
   968
		TEST(bbb);
sl@0
   969
		
sl@0
   970
		// Check taskData is the same (was originally held in the TTaskInfo.iName field)
sl@0
   971
		const TDesC& des1 = taskInfo.iName;
sl@0
   972
		TDes& des2 = pTaskData;
sl@0
   973
		TEST(des1 == des2);
sl@0
   974
		CleanupStack::PopAndDestroy(taskData);
sl@0
   975
		}
sl@0
   976
	}
sl@0
   977
sl@0
   978
//***********************************************************************************
sl@0
   979
sl@0
   980
/**
sl@0
   981
@file
sl@0
   982
@SYMTestCaseID				SYSLIB-SCHSVR-CT-0264
sl@0
   983
@SYMTestCaseDesc 			Large number of tasks test - Hometime
sl@0
   984
@SYMTestPriority 			High
sl@0
   985
@SYMTestActions  			Create a large number of tasks, test retrieval of task data and task info
sl@0
   986
@SYMTestExpectedResults		The test must not fail.
sl@0
   987
@SYMPREQ					PREQ234
sl@0
   988
*/
sl@0
   989
static void Test8L()
sl@0
   990
	{
sl@0
   991
	// Test title
sl@0
   992
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0264 Create a large number of tasks, test retrieval of task data and task info "));
sl@0
   993
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
   994
sl@0
   995
	// Constants used in this function
sl@0
   996
	const TInt KNumberOfSchedulesToCreate		= 20;
sl@0
   997
	const TInt KNumberOfScheduleEntriesToCreate = 5;
sl@0
   998
sl@0
   999
	// Prepare arrays required for the tests below
sl@0
  1000
	CSchEntryInfoArray* scheduleEntries = ::CreateSchEntryInfoArrayLC(KNumberOfScheduleEntriesToCreate);
sl@0
  1001
	CArrayFixFlat<TTaskInfo>* taskInfos = ::CreateTaskInfoLC(KNumberOfSchedulesToCreate);
sl@0
  1002
	CSchItemRefArray* scheduleReferences = ::CreateScheduleRefsLC(KNumberOfSchedulesToCreate);
sl@0
  1003
sl@0
  1004
	//
sl@0
  1005
	// Create a large number of transient scheduled tasks 
sl@0
  1006
	// to test Id generation
sl@0
  1007
	//
sl@0
  1008
	::CreateTransientScheduledTasksL(KNumberOfScheduleEntriesToCreate,
sl@0
  1009
									 KNumberOfSchedulesToCreate,
sl@0
  1010
									 scheduleEntries,
sl@0
  1011
									 taskInfos,
sl@0
  1012
									 scheduleReferences);
sl@0
  1013
sl@0
  1014
sl@0
  1015
	::CheckScheduledRefs(KNumberOfSchedulesToCreate);
sl@0
  1016
sl@0
  1017
	// Test tasks for a given taskid is the same
sl@0
  1018
	::TestScheduledTasksL(KNumberOfSchedulesToCreate, taskInfos);
sl@0
  1019
sl@0
  1020
	// Test reference can be retrieved for a given handle.
sl@0
  1021
	CleanupStack::PopAndDestroy(scheduleReferences);
sl@0
  1022
	CleanupStack::PopAndDestroy(taskInfos);
sl@0
  1023
	CleanupStack::PopAndDestroy(scheduleEntries);
sl@0
  1024
sl@0
  1025
	// now delete all schedules
sl@0
  1026
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
  1027
	TInt ccc = CountScheduledItemsL(EAllSchedules, TheScheduler);
sl@0
  1028
	TEST(ccc == 0);
sl@0
  1029
sl@0
  1030
	SchSvrHelpers::Pause(TheTest,1 );
sl@0
  1031
	}
sl@0
  1032
sl@0
  1033
//***********************************************************************************
sl@0
  1034
static TInt RunTestsL()
sl@0
  1035
	{
sl@0
  1036
	TheTest.Next(_L("Delete old files"));
sl@0
  1037
	SchSvrHelpers::DeleteScheduleFilesL();
sl@0
  1038
	
sl@0
  1039
	TheTest.Next(_L("Create Task notification semaphore"));
sl@0
  1040
	//initialise task notification semaphore
sl@0
  1041
	STaskSemaphore sem;
sl@0
  1042
	sem.CreateL();
sl@0
  1043
sl@0
  1044
	// Prepare random number seed
sl@0
  1045
	TheTest.Next(_L("Prepare random number"));
sl@0
  1046
	TTime now;
sl@0
  1047
	now.UniversalTime();
sl@0
  1048
	TheSeed = now.Int64();
sl@0
  1049
sl@0
  1050
	// Connect to the server
sl@0
  1051
	TheTest.Next(_L("===== Connect to Scheduler ====="));
sl@0
  1052
	TInt res = TheScheduler.Connect();
sl@0
  1053
	TEST2(res, KErrNone);
sl@0
  1054
	
sl@0
  1055
	// Register a client with the server
sl@0
  1056
	TheTest.Next(_L("===== Registering Client ====="));
sl@0
  1057
	res = SchSvrHelpers::RegisterClientL(TheScheduler);
sl@0
  1058
	TEST2(res, KErrNone);
sl@0
  1059
sl@0
  1060
	TheTest.Next(_L("Start tests"));
sl@0
  1061
	Test1L();
sl@0
  1062
	Test2L();
sl@0
  1063
	Test3L();
sl@0
  1064
	Test4L();
sl@0
  1065
	Test5L();
sl@0
  1066
	Test6L();
sl@0
  1067
	Test7L();
sl@0
  1068
	Test8L();
sl@0
  1069
sl@0
  1070
	TheTest.Next(_L("Tidying up"));
sl@0
  1071
	//Tidying up so next test will be clear.
sl@0
  1072
	TheTest.Next(_L("Delete all schedules"));
sl@0
  1073
	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
sl@0
  1074
	SchSvrHelpers::Pause(TheTest, 2);
sl@0
  1075
	TheTest.Next(_L("Delete old files\n"));
sl@0
  1076
	SchSvrHelpers::DeleteScheduleFilesL();
sl@0
  1077
sl@0
  1078
	TheScheduler.Close();
sl@0
  1079
	
sl@0
  1080
	//close handle to semaphore
sl@0
  1081
	sem.Close();
sl@0
  1082
sl@0
  1083
	return KErrNone;
sl@0
  1084
	}
sl@0
  1085
sl@0
  1086
//***********************************************************************************
sl@0
  1087
GLDEF_C TInt E32Main()
sl@0
  1088
//	
sl@0
  1089
// TheTest the scheduler
sl@0
  1090
//
sl@0
  1091
    {
sl@0
  1092
	__UHEAP_MARK;
sl@0
  1093
	TheTest.Start(_L("TC_TSCH_SCHEDULING2 - Hometime"));
sl@0
  1094
	TheTest.Title();
sl@0
  1095
	TheCleanup = CTrapCleanup::New();
sl@0
  1096
	//If the previous test fails, SCHSVR.exe may stay in memory.
sl@0
  1097
	TRAPD(error,CleanupHelpers::TestCleanupL());
sl@0
  1098
	TEST2(error, KErrNone);
sl@0
  1099
sl@0
  1100
	TEST2(TheFsSession.Connect(), KErrNone);;
sl@0
  1101
	TRAP(error, RunTestsL());	
sl@0
  1102
	TRAP(error,CleanupHelpers::TestCleanupL());
sl@0
  1103
	TEST2(error, KErrNone);
sl@0
  1104
	delete TheCleanup;
sl@0
  1105
	
sl@0
  1106
	TheFsSession.Close();
sl@0
  1107
	TheTest.End();
sl@0
  1108
	TheTest.Close();
sl@0
  1109
	__UHEAP_MARKEND;
sl@0
  1110
	return(KErrNone);
sl@0
  1111
	}