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