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