os/ossrv/genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING2_UTC.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 - UTC");
    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::UtcTimeBasedOnOffset(10, 0), ETrue); // 0m:10s from "now"
   130 	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
   131 	entryList->AppendL(entry1);
   132 	}
   133 	{
   134 	TTsTime startTime2(SchSvrHelpers::UtcTimeBasedOnOffset(20, 1), ETrue); // 0m:20s from "now"
   135 	TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 20);
   136 	entryList->AppendL(entry2);
   137 	}
   138 	{
   139 	TTsTime startTime3(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, -1), ETrue); // -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::UtcTimeBasedOnOffset(30, 2), ETrue); // 2m:30s from "now"
   159 	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
   160 	entryList->AppendL(entry1);
   161 	}
   162 	{
   163 	TTsTime startTime2(SchSvrHelpers::UtcTimeBasedOnOffset(0, 5), ETrue);  // 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), ETrue); // 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), ETrue); // 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-0265
   222 @SYMTestCaseDesc 			Replicated test for for defect (EDNAWIR-4FQJ6A) - UTC
   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-0265 TheTest1: Registering with the tasks scheduler without disconnecting "));
   231 	
   232 	__UHEAP_MARK;
   233 	TheTest.Next(_L("Connect to Scheduler"));
   234 	TInt res = TheScheduler.Connect();
   235 	TEST2(res, KErrNone);
   236 
   237 	TheTest.Next(_L("Registering Client"));
   238 	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
   239 
   240 	TheScheduler.Close();
   241 	__UHEAP_MARKEND;
   242 
   243 	__UHEAP_MARK;
   244 	TheTest.Next(_L("Connect to Scheduler again"));
   245 	res = TheScheduler.Connect();
   246 	TEST2(res, KErrNone);
   247 
   248 	TheTest.Next(_L("Registering client again"));
   249 	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
   250 	TheScheduler.__DbgMarkHeap();
   251 
   252 	TheTest.Next(_L("Register when already registered"));
   253 	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
   254 
   255 	TheTest.Next(_L("Cancel registering client and check for memory leak"));
   256 	TheScheduler.__DbgMarkEnd(0);
   257 	TheScheduler.Close();
   258 	__UHEAP_MARKEND;
   259 	}
   260 
   261 
   262 //***********************************************************************************
   263 
   264 /**
   265 @file
   266 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0266
   267 @SYMTestCaseDesc 			Replicated test for for defect (EDNHLJT-4TRAAE) - UTC
   268 @SYMTestPriority 			High
   269 @SYMTestActions  			Create schedule, kill server (simulate re-boot), and make sure task still completes
   270 @SYMTestExpectedResults		The test must not fail.
   271 @SYMPREQ					PREQ234
   272 */
   273 static void Test2L()
   274 	{
   275 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0266 TheTest2: Resend after hard reset (simulation) "));
   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.UniversalTime();
   288 	time += TTimeIntervalSeconds(5); //Task to go off five seconds from now
   289 	TTsTime time2 (time, ETrue);
   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 5 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-0267
   345 @SYMTestCaseDesc 			Replicated test for CR (AALR-4EDG75) - UTC
   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 
   372 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0267 Test change request AALR-4EDG75 implementation"));
   373 	
   374 	TheTest.Next(_L("Connect to Scheduler"));
   375 	TInt res = TheScheduler.Connect();
   376 	TEST2(res, KErrNone);
   377 
   378 	TheTest.Next(_L("Registering Client"));
   379 	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
   380 
   381 	const TDateTime KTimeToStartTask(2000, EJanuary, 10, 15, 30, 0, 0);
   382 
   383 	TSchedulerItemRef schedulerItemReference;
   384 	CSchEntryInfoArray* entryArray = new(ELeave) CSchEntryInfoArray(1);
   385 	CleanupStack::PushL(entryArray);
   386 	
   387 	HBufC* taskData = _L("This is some dummy task data created for testing").AllocL();
   388 	CleanupStack::PushL(taskData);
   389 	
   390 	// Prepare the task info - this describes the tasks that are contained within the task
   391 	// entry array
   392 	TTaskInfo taskInfo = SchSvrHelpers::TaskInfo(_L("A transient test task"), 100);
   393 		
   394 	// Create a schedule entry and append it to the entry array
   395 	{
   396 	TScheduleEntryInfo2 scheduleEntry = SchSvrHelpers::ScheduleEntryInfo(EDaily, TTsTime(TTime(KTimeToStartTask), ETrue), 7, 2);
   397 	entryArray->AppendL(scheduleEntry);
   398 	}
   399 
   400 	// Create the transient task
   401 	TInt ret = TheScheduler.ScheduleTask(taskInfo, *taskData, schedulerItemReference, *entryArray);
   402 	TEST2(ret, KErrNone);
   403 
   404 	// Check that the task Id after scheduling the event is not 
   405 	// the same as it was prior to the requesting the service
   406 	TEST(taskInfo.iTaskId != -1);
   407 
   408 	//
   409 	// Now obtain info about the scheduled transient task...
   410 	//
   411 	TScheduleState2 scheduleState;
   412 	TTsTime nextTaskDueTime;
   413 
   414 	// Reset the schedule entry info array as the server now has copies of this and it is
   415 	// no longer required client-side
   416 	entryArray->Reset();
   417 	CTaskInfoArray* taskInfoArray = new(ELeave) CTaskInfoArray(4);
   418 	CleanupStack::PushL(taskInfoArray);
   419 
   420 	// Request task schedule information from the server
   421 	ret = TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime);
   422 	TEST2(ret, KErrNone);
   423 
   424 	// Because this is a daily task which is scheduled to occur at a specific time (but the date
   425 	// cannot necessarily be established, we can perform a simple check to ensure that the
   426 	// time when the task is next scheduled to run falls within the 15:30 - 17:30 bracket.
   427 	TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), ETrue)) == (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, ETrue);
   441 	TSchedulerItemRef schedulerRefFromServer;
   442 	TEST2(TheScheduler.GetTaskInfoL(taskInfo.iTaskId, taskFromServer, pTaskDataFromServer, schedulerRefFromServer, nextDueTimeFromServer), KErrNone);
   443 	TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), ETrue)) == (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.SetUtcTime(Time::NullTTime());
   457 	TEST2(TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime), KErrNone);
   458 	TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), ETrue)) == (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-0268
   477 @SYMTestCaseDesc 			Replicated test for defect (EDNAALR-4JKEFC) - UTC
   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-0268 \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), ETrue); // 1m:01s from "now"
   503 	TScheduleEntryInfo2 entry1 (startTime1, EHourly, 1, 20);
   504 	entries->AppendL(entry1);
   505 
   506 	TTsTime startTime2 (SchSvrHelpers::TimeBasedOnOffset(5, 5), ETrue); // 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(), ETrue);
   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-0269
   577 @SYMTestCaseDesc 			Persistant schedule test - UTC
   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-0269 ===== Starting test 1 ====="));
   587 	
   588 	__UHEAP_MARK;
   589 	
   590 	TSchedulerItemRef ref1;
   591 	TSchedulerItemRef ref2;
   592 	TSchedulerItemRef ref3;
   593 
   594 	// Remove all existing schedules before starting the test
   595 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   596 	
   597 	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   598 	TEST(scheduleCount == 0); // check that no schedules are present.
   599 	
   600 	TheTest.Printf(_L("Create some schedules\n"));
   601 	res = CreateSchedule1L(ref1, TheScheduler); // +10sec, +20sec, -1year
   602 	TEST2(res, KErrNone);	
   603 	res = CreateSchedule2L(ref2, TheScheduler); // +2min 30sec, +5min
   604 	TEST2(res, KErrNone);
   605 	res = CreateSchedule3L(ref3, TheScheduler); // +20day 9min, +20day 11min
   606 	TEST2(res, KErrNone);
   607 
   608 	TSchedulerItemRef ref4;
   609 	TSchedulerItemRef ref5;
   610 	res = CreateSchedule2L(ref4, TheScheduler); // +2min 30sec, 5min
   611 	TEST2(res, KErrNone);
   612 	res = CreateSchedule3L(ref5, TheScheduler); // +20day 9min, +20day 11min
   613 	TEST2(res, KErrNone);
   614 
   615 	TInt task1 = 0;
   616 	TInt task2 = 0;
   617 	TInt task3 = 0;
   618 	TInt task4 = 0;
   619 	TName name1 = (_L("web subscription"));
   620 	TName name2 = (_L("another web subscription"));
   621 	TName name3 = (_L("third web subscription"));
   622 
   623 	TheTest.Printf(_L("Schedule some tasks\n"));
   624 
   625 	// NOTE: have to put repeats here of > 0 otherwise the task will run immediately
   626 	// (because it's schedule specifies a date of 1 year in the past!) and be
   627 	// removed (by the server) before we have a chance to delete it....
   628 	res = SchedulePersistentTaskL(name1, task1, ref1.iHandle, 3, TheScheduler);
   629 	TEST2(res, KErrNone);
   630 	res = SchedulePersistentTaskL(name2, task2, ref2.iHandle, 3, TheScheduler);
   631 	TEST2(res, KErrNone);
   632 	res = SchedulePersistentTaskL(name3, task3, ref3.iHandle, 3, TheScheduler);
   633 	TEST2(res, KErrNone);
   634 	res = SchedulePersistentTaskL(name3, task4, ref3.iHandle, 3, TheScheduler);
   635 	TEST2(res, KErrNone);
   636 
   637 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   638 	TEST(scheduleCount == 5); // 5 persistant
   639 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   640 
   641 	TheTest.Printf(_L("Deleting task with id %d\n"), task1);
   642 	res = TheScheduler.DeleteTask(task1);
   643 	TEST2(res, KErrNone);
   644 	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
   645 	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   646 	TEST2(res, KErrNone);
   647 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   648 	// 4 persistant expected as we have deleted one
   649 	TEST(scheduleCount == 4); 
   650 
   651 	TheTest.Printf(_L("Deleting task with id %d\n"), task2);
   652 	res = TheScheduler.DeleteTask(task2);
   653 	TEST2(res, KErrNone);
   654 	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref2.iHandle);
   655 	res = TheScheduler.DeleteSchedule(ref2.iHandle);
   656 	TEST2(res, KErrNone);
   657 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   658 	// 3 persistant  expected as we have deleted one
   659 	TEST(scheduleCount == 3); 
   660 
   661 	TheTest.Printf(_L("Deleting task with id %d\n"), task3);
   662 	res = TheScheduler.DeleteTask(task3);
   663 	TEST2(res, KErrNone);
   664 	TheTest.Printf(_L("Deleting task with id %d\n"), task4);
   665 	res = TheScheduler.DeleteTask(task4);
   666 	TEST2(res, KErrNone);
   667 	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref3.iHandle);
   668 	res = TheScheduler.DeleteSchedule(ref3.iHandle);
   669 	TEST2(res, KErrNone);
   670 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   671 	// 2 persistant  expected as we have deleted one
   672 	TEST(scheduleCount == 2); 
   673 
   674 	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref4.iHandle);
   675 	res = TheScheduler.DeleteSchedule(ref4.iHandle);
   676 	TEST2(res, KErrNone);
   677 	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref5.iHandle);
   678 	res = TheScheduler.DeleteSchedule(ref5.iHandle);
   679 	TEST2(res, KErrNone);
   680 
   681 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   682 	TEST(scheduleCount == 0); 
   683 	
   684 	SchSvrHelpers::Pause(TheTest,1);
   685 	__UHEAP_MARKEND;
   686 	}
   687 
   688 
   689 //***********************************************************************************
   690 
   691 /**
   692 @file
   693 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0270
   694 @SYMTestCaseDesc 			Transient schedule test - UTC
   695 @SYMTestPriority 			High
   696 @SYMTestActions  			Create transient schedule with non-repeating task
   697 @SYMTestExpectedResults		The test must not fail.
   698 @SYMPREQ					PREQ234
   699 */
   700 static void Test6L()
   701 	{
   702 	// Heap testing removed because this is a flakey bit of code.
   703 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0270 Transient, non-repeating - waits for schedule to activate "));
   704 	
   705 	// Remove all existing schedules before starting the test
   706 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   707 
   708 	// Create transient schedule
   709 	TheTest.Printf(_L("Create transient schedule with non-repeating task\n"));
   710 	TSchedulerItemRef ref;
   711 	CSchEntryInfoArray* entryList = new(ELeave) CSchEntryInfoArray(1);
   712 	CleanupStack::PushL(entryList);
   713 	ref.iName = _L("A Transient Schedule");
   714 	
   715 	// CREATE SCHEDULE ENTRY:
   716 	// starttime 5 secs in the future, hometime based
   717 	TTsTime startTime(SchSvrHelpers::TimeBasedOnOffset(5), EFalse);
   718 	// constructor takes: starttime, interval type, interval, validity period
   719 	TScheduleEntryInfo2 entry(startTime, EDaily, 1, 20);
   720 	entryList->AppendL(entry);
   721 	 
   722 	// CREATE SCHEDULE TASK:
   723 	TTaskInfo taskInfo;
   724 	taskInfo.iName = _L("mail");
   725 	taskInfo.iTaskId = 0;
   726 	taskInfo.iRepeat = 1;
   727 	taskInfo.iPriority = 2;
   728 	HBufC* data = _L("This is the data for the task").AllocLC();
   729 	
   730 	// Schedule the item
   731 	TInt res = TheScheduler.ScheduleTask(taskInfo, *data, ref, *entryList);
   732 	TEST2(res, KErrNone);
   733 
   734 	CleanupStack::PopAndDestroy(2, entryList); // data, entryList
   735 	
   736 	// Should be one item
   737 	TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 1);
   738 
   739 	// Waiting for entry to complete
   740 	TheTest.Next(_L("Waiting for task to complete"));
   741 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);	
   742 
   743 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   744 	
   745 	// Should be no items as schedule deletes itself after task has completed
   746 	TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 0);
   747 
   748 	SchSvrHelpers::Pause(TheTest,1);
   749 	}
   750 
   751 
   752 //***********************************************************************************
   753 
   754 /**
   755 @file
   756 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0271
   757 @SYMTestCaseDesc 			Persistant schedule test with repeating task - UTC
   758 @SYMTestPriority 			High
   759 @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, 
   760 @SYMTestExpectedResults		The test must not fail.
   761 @SYMPREQ					PREQ234
   762 */
   763 static void Test7L()
   764 	{
   765 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0271 Test persistent scheduling, repeating and non-repeating task schedules"));
   766 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   767 
   768 	// Transient
   769 	TSchedulerItemRef ref;
   770 
   771 	// We shouldn't have any outstanding schedules registered with the server
   772 	TInt count = CountScheduledItemsL(EAllSchedules, TheScheduler);
   773 	TEST(count == 0);
   774 
   775 	// This creates 3 schedule entries, each with a validity period of 20 minutes, and are
   776 	// due to run in 10s, 20s, and over a year ago (a year in the past)
   777 	TheTest.Printf(_L("Create Persistent schedule\n"));
   778 	TInt res = CreateSchedule1L(ref, TheScheduler);
   779 	TEST2(res, KErrNone);
   780 
   781 	// We should now have one registered schedule
   782 	count = CountScheduledItemsL(EAllSchedules, TheScheduler);
   783 	TEST(count == 1);
   784 
   785 	//
   786 	TheTest.Printf(_L("\nSchedule two tasks: one repeating....\n"));
   787 	//
   788 	TInt task1 = 0;
   789 	TName name1 = (_L("web subscription(rpts)"));
   790 	// -1 indicates repeating schedule
   791 	res = SchedulePersistentTaskL(name1, task1, ref.iHandle, -1, TheScheduler); // -1 indicates repeat until explicitly deleted
   792 	TEST2(res, KErrNone);
   793 
   794 	// List those schedules that are pending
   795 	count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
   796 	TEST(count == 1);
   797 
   798 	//
   799 	TheTest.Printf(_L("\n... and one non-repeating\n"));
   800 	//
   801 	TInt task2 = 0;
   802 	TName name2 = (_L("non-repeating"));
   803 	res = SchedulePersistentTaskL(name2, task2, ref.iHandle, 1, TheScheduler); // only runs once
   804 	TEST2(res, KErrNone);
   805 
   806 	TheTest.Printf(_L("Waiting for tasks to run\n"));
   807 	// Wait for notification that schedule has executed.	
   808 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
   809 
   810 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   811 
   812 	TheTest.Printf(_L("...and wait again for repeating one to execute again\n"));
   813 	// Wait for notification that schedule has executed.
   814 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
   815 
   816 	CleanupHelpers::KillProcess
   817 	(KMinimalTaskHandler);
   818 
   819 	TheTest.Printf(_L("Delete the repeating task, and the schedule \n"));
   820 	res = TheScheduler.DeleteTask(task1);
   821 	TEST2(res, KErrNone);
   822 	res = TheScheduler.DeleteTask(task2);
   823 	TEST2(res, KErrNotFound); //Should be not found since its only executed once.
   824 	res = TheScheduler.DeleteSchedule(ref.iHandle);
   825 	TEST2(res, KErrNone);
   826 
   827 	count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
   828 	TEST(count == 0);
   829 	SchSvrHelpers::Pause(TheTest,1);
   830 	}
   831 
   832 
   833 static CSchEntryInfoArray* CreateSchEntryInfoArrayLC(TInt aGranularity)
   834 	{
   835 	CSchEntryInfoArray*	scheduleEntries	= new (ELeave) CSchEntryInfoArray(aGranularity);
   836 	CleanupStack::PushL(scheduleEntries);
   837 	return scheduleEntries;
   838 	}
   839 
   840 static CArrayFixFlat<TTaskInfo>* CreateTaskInfoLC(TInt aGranularity)
   841 	{
   842 	CArrayFixFlat<TTaskInfo>* taskInfos	= new (ELeave) CArrayFixFlat<TTaskInfo>(aGranularity);
   843 	CleanupStack::PushL(taskInfos);
   844 	return taskInfos;
   845 	}
   846 
   847 static CSchItemRefArray* CreateScheduleRefsLC(TInt aGranularity)
   848 	{
   849 	CSchItemRefArray* scheduleReferences = new (ELeave) CSchItemRefArray(aGranularity);
   850 	CleanupStack::PushL(scheduleReferences);
   851 	return scheduleReferences;
   852 	}
   853 
   854 static void CreateTransientScheduledTasksL(TInt aNumScheduleEntries,
   855 										   TInt aNumSchedules,
   856 										   CSchEntryInfoArray* aScheduleEntries,
   857 										   CArrayFixFlat<TTaskInfo>* aTaskInfos,
   858 										   CSchItemRefArray* aScheduleReferences)
   859 	{
   860 	const TTimeIntervalMicroSeconds timeToAdd = 10000000; //10 seconds
   861 	const TTimeIntervalMicroSeconds timeLimit = 5000000; // 5 seconds
   862 	_LIT(KTaskDataPrefix, "Task Data Entry: ");
   863 	// Prepare keys required
   864 	TKeyArrayFix KTaskInfoSortKey(_FOFF(TTaskInfo, iTaskId), ECmpTInt);
   865 
   866 	for(TInt i=0;i<aNumSchedules;i++)
   867 		{	
   868 		// Remove any existing schedule entry info's
   869 		aScheduleEntries->Reset();
   870 		//
   871 		// Populate the schedule entry array with a varying list of 
   872 		// start-times, intervals, etc for this particular task
   873 		//
   874 		for(TInt j=0; j<aNumScheduleEntries; ++j)
   875 			{
   876 			TScheduleEntryInfo2 scheduleEntry = SchSvrHelpers::RandomScheduleEntryInfoUtc(TheSeed);
   877 			TTime now;
   878 			now.HomeTime(); // sets now to home time
   879 			TTime sTime = scheduleEntry.StartTime().GetUtcTime();
   880 			//if scheduleEntry.StartTime() is set lower then 5 sec into the future, postpone StartTime 10 sec into the future
   881 			if(sTime < now + timeLimit) 
   882 				{
   883 				TTsTime newTime (now + timeToAdd, ETrue);
   884 				scheduleEntry.SetStartTime(newTime); 					
   885 				}
   886 			aScheduleEntries->AppendL(scheduleEntry);
   887 			}
   888 		//
   889 		// Create some dummy task data
   890 		//
   891 		HBufC* taskData = HBufC::NewLC(KTaskDataPrefix().Length()+4);
   892 		taskData->Des().Copy(KTaskDataPrefix());
   893 		taskData->Des().AppendNum(i);
   894 		//
   895 		// Munge the task name
   896 		//
   897 		TTaskInfo taskInfo;
   898 		taskInfo.iName = *taskData;
   899 		taskInfo.iRepeat = 1;
   900 		taskInfo.iPriority = 1;
   901 		// Schedule the transient task
   902 		TSchedulerItemRef scheduleReference;
   903 		TInt result = TheScheduler.ScheduleTask(taskInfo, 
   904 												*taskData, 
   905 												scheduleReference, 
   906 												*aScheduleEntries);
   907 		TEST2(result, KErrNone);
   908 		TheTest.Printf(_L("TaskId: %d => TaskName: %S\n"), taskInfo.iTaskId, &taskInfo.iName);
   909 		CleanupStack::PopAndDestroy(taskData);
   910 		//
   911 		// Save the taskInfo so we can check it later - this inserts the taskinfo into
   912 		// the array (preserves sorted order by TTaskInfo.iTaskId) but also has the
   913 		// added bonus of preventing duplicate task ids...
   914 		//
   915 		aTaskInfos->InsertIsqL(taskInfo, KTaskInfoSortKey);
   916 		// Disable all schedules once added, just to stop them going off
   917 		// and therefore being deleted when we are trying to compare them 
   918 		result = TheScheduler.DisableSchedule(scheduleReference.iHandle);
   919 		TEST2(result, KErrNone);
   920 		// Save the sever generated schedule reference and taskId for checking later
   921 		aScheduleReferences->AppendL(scheduleReference);
   922 		}
   923 	}
   924 
   925 static void CheckScheduledRefs(TInt aNumSchedules)
   926 	{
   927 	CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
   928 	CleanupStack::PushL(refs);
   929 	TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules); 
   930 	TEST2(res, KErrNone);
   931 	TInt count = refs->Count();
   932 	TEST(count == aNumSchedules);
   933 	CleanupStack::PopAndDestroy(refs);
   934 	}
   935 
   936 static void TestScheduledTasksL(TInt aNumSchedules,
   937 								CArrayFixFlat<TTaskInfo>* aTaskInfos)
   938 	{
   939 	for(TInt n=0; n<aNumSchedules; ++n)
   940 		{
   941 		const TTaskInfo& taskInfo = aTaskInfos->At(n);
   942 
   943 		// First retrieve the task size
   944 		TInt taskSize;
   945 		TInt result = TheScheduler.GetTaskDataSize(taskInfo.iTaskId, taskSize);
   946 		TEST2(result, KErrNone);
   947 		TEST(taskSize > 0);
   948 
   949 		// Next retrieve the task info associated with a particular task Id
   950 		HBufC* taskData = HBufC::NewLC(taskSize);
   951 		TPtr pTaskData = taskData->Des();
   952 
   953 		TTsTime scheduleNextDueTime;
   954 		TTaskInfo taskFromServer;
   955 		TSchedulerItemRef scheduleReference;
   956 
   957 		result = TheScheduler.GetTaskInfoL(taskInfo.iTaskId,
   958 										   taskFromServer, 
   959 										   pTaskData, 
   960 										   scheduleReference, 
   961 										   scheduleNextDueTime);
   962 		TEST2(result, KErrNone);
   963 		TEST(taskData->Length() == taskSize);
   964 
   965 		// Now check that the task returned by the server matches that held locallly....
   966 		TBool bbb = SchSvrHelpers::IsTaskInfoTheSame(taskFromServer, taskInfo);
   967 		if(!bbb)
   968 			{
   969 			RDebug::Print(_L("TaskInfo1. repeat=%x, id=%d, name=%S, priority=%x\n"),
   970 				taskFromServer.iRepeat, taskFromServer.iTaskId, &taskFromServer.iName, taskFromServer.iPriority);
   971 			RDebug::Print(_L("TaskInfo2. repeat=%x, id=%d, name=%S, priority=%x\n"),
   972 				taskInfo.iRepeat, taskInfo.iTaskId, &taskInfo.iName, taskInfo.iPriority);
   973 			}
   974 		TEST(bbb);
   975 		
   976 		// Check taskData is the same (was originally held in the TTaskInfo.iName field)
   977 		const TDesC& des1 = taskInfo.iName;
   978 		TDes& des2 = pTaskData;
   979 		TEST(des1 == des2);
   980 		CleanupStack::PopAndDestroy(taskData);
   981 		}
   982 	}
   983 
   984 //***********************************************************************************
   985 
   986 /**
   987 @file
   988 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0272
   989 @SYMTestCaseDesc 			Large number of tasks test - UTC
   990 @SYMTestPriority 			High
   991 @SYMTestActions  			Create a large number of tasks, test retrieval of task data and task info
   992 @SYMTestExpectedResults		The test must not fail.
   993 @SYMPREQ					PREQ234
   994 */
   995 static void Test8L()
   996 	{
   997 	// Test title
   998 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0272 Create a large number of tasks, test retrieval of task data and task info"));
   999 	
  1000 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
  1001 
  1002 	// Constants used in this function
  1003 	const TInt KNumberOfSchedulesToCreate		= 20;
  1004 	const TInt KNumberOfScheduleEntriesToCreate = 5;
  1005 
  1006 	// Prepare arrays required for the tests below
  1007 	CSchEntryInfoArray* scheduleEntries = ::CreateSchEntryInfoArrayLC(KNumberOfScheduleEntriesToCreate);
  1008 	CArrayFixFlat<TTaskInfo>* taskInfos = ::CreateTaskInfoLC(KNumberOfSchedulesToCreate);
  1009 	CSchItemRefArray* scheduleReferences = ::CreateScheduleRefsLC(KNumberOfSchedulesToCreate);
  1010 
  1011 	//
  1012 	// Create a large number of transient scheduled tasks 
  1013 	// to test Id generation
  1014 	//
  1015 	::CreateTransientScheduledTasksL(KNumberOfScheduleEntriesToCreate,
  1016 									 KNumberOfSchedulesToCreate,
  1017 									 scheduleEntries,
  1018 									 taskInfos,
  1019 									 scheduleReferences);
  1020 
  1021 
  1022 	::CheckScheduledRefs(KNumberOfSchedulesToCreate);
  1023 
  1024 	// Test tasks for a given taskid is the same
  1025 	::TestScheduledTasksL(KNumberOfSchedulesToCreate, taskInfos);
  1026 
  1027 	// Test reference can be retrieved for a given handle.
  1028 	CleanupStack::PopAndDestroy(scheduleReferences);
  1029 	CleanupStack::PopAndDestroy(taskInfos);
  1030 	CleanupStack::PopAndDestroy(scheduleEntries);
  1031 
  1032 	// now delete all schedules
  1033 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
  1034 	TInt ccc = CountScheduledItemsL(EAllSchedules, TheScheduler);
  1035 	TEST(ccc == 0);
  1036 
  1037 	SchSvrHelpers::Pause(TheTest,1);
  1038 	}
  1039 
  1040 //***********************************************************************************
  1041 static TInt RunTestsL()
  1042 	{
  1043 	TheTest.Next(_L("Delete old files"));
  1044 	SchSvrHelpers::DeleteScheduleFilesL();
  1045 	
  1046 	TheTest.Next(_L("Create Task notification semaphore"));
  1047 	//initialise task notification semaphore
  1048 	STaskSemaphore sem;
  1049 	sem.CreateL();
  1050 
  1051 	// Prepare random number seed
  1052 	TheTest.Next(_L("Prepare random number"));
  1053 	TTime now;
  1054 	now.UniversalTime();
  1055 	TheSeed = now.Int64();
  1056 
  1057 	// Connect to the server
  1058 	TheTest.Next(_L("===== Connect to Scheduler ====="));
  1059 	TInt res = TheScheduler.Connect();
  1060 	TEST2(res, KErrNone);
  1061 	
  1062 	// Register a client with the server
  1063 	TheTest.Next(_L("===== Registering Client ====="));
  1064 	res = SchSvrHelpers::RegisterClientL(TheScheduler);
  1065 	TEST2(res, KErrNone);
  1066 
  1067 	TheTest.Next(_L("Start tests"));
  1068 	Test1L();
  1069 	Test2L();
  1070 	Test3L();
  1071 	Test4L();
  1072 	Test5L();
  1073 	Test6L();
  1074 	Test7L();
  1075 	Test8L();
  1076 	
  1077 	TheTest.Next(_L("Tidying up"));
  1078 	//Tidying up so next test will be clear.
  1079 	TheTest.Next(_L("Delete all schedules"));
  1080 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
  1081 	SchSvrHelpers::Pause(TheTest, 2);
  1082 	TheTest.Next(_L("Delete old files\n"));
  1083 	SchSvrHelpers::DeleteScheduleFilesL();
  1084 
  1085 	TheScheduler.Close();
  1086 	
  1087 	//close handle to semaphore
  1088 	sem.Close();
  1089 
  1090 	return KErrNone;
  1091 	}
  1092 
  1093 //***********************************************************************************
  1094 GLDEF_C TInt E32Main()
  1095 //	
  1096 // TheTest the scheduler
  1097 //
  1098     {
  1099 	__UHEAP_MARK;
  1100 	TheTest.Start(_L("TC_TSCH_SCHEDULING2 - UTC"));
  1101 	TheTest.Title();
  1102 
  1103 	TheCleanup = CTrapCleanup::New();
  1104 	//If the previous test fails, SCHSVR.exe may stay in memory.
  1105 	TRAPD(error,CleanupHelpers::TestCleanupL());
  1106 	TEST2(error, KErrNone);
  1107 	
  1108 	TTime now;
  1109 	now.HomeTime();
  1110 	// Used to Set the system UTC time and UTC offset
  1111 	// so that correct UTC Time values are returned while using time based APIs.
  1112 	SchSvrHelpers::SetHomeTimeL(now);
  1113 
  1114 	TEST2(TheFsSession.Connect(), KErrNone);;
  1115 	TRAP(error, RunTestsL());	
  1116 	TRAP(error,CleanupHelpers::TestCleanupL());
  1117 	TEST2(error, KErrNone);
  1118 	delete TheCleanup;
  1119 	
  1120 	TheFsSession.Close();
  1121 	TheTest.End();
  1122 	TheTest.Close();
  1123 	__UHEAP_MARKEND;
  1124 	return(KErrNone);
  1125 	}