genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING1_UTC.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 1997-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 <e32base.h>
       
    17 #include <e32test.h>
       
    18 #include <csch_cli.h>
       
    19 #include <f32file.h>
       
    20 #include "Thelpers.h"
       
    21 
       
    22 #include "TestUtils.h"
       
    23 
       
    24 // Globals
       
    25 RTest					TheTest(_L("TC_TSCH_SCHEDULING1 - UTC"));
       
    26 static RScheduler		TheScheduler;
       
    27 static RFs				TheFsSession;
       
    28 
       
    29 typedef CArrayFixFlat<TScheduleEntryInfo2>	CScheduleEntryInfoArray;
       
    30 typedef CArrayFixFlat<TTaskInfo>			CTaskInfoArray;
       
    31 typedef CArrayFixFlat<TSchedulerItemRef>    CSchItemRefArray;
       
    32 
       
    33 _LIT(KMinimalTaskHandler, "MinimalTaskHandler");
       
    34 
       
    35 _LIT(KTimeFormatString,						"%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B");
       
    36 _LIT(KCurrentDateTimeChanged,				"Date & Time changed to: [%S]\n");
       
    37 
       
    38 //***********************************************************************************
       
    39 
       
    40 // Sets time to before specified time by aTimeBeforeInSeconds
       
    41 static void SetTimeBeforeL(RTest& aTest, TTsTime& aTime, TInt aTimeBeforeInSeconds)
       
    42 	{
       
    43 	TTimeIntervalSeconds secs(aTimeBeforeInSeconds);
       
    44 	TTime time = aTime.GetLocalTime()-secs;
       
    45 	SchSvrHelpers::SetHomeTimeL(time);
       
    46 	TBuf<30> dateString;
       
    47 	time.FormatL(dateString, KTimeFormatString);
       
    48 	aTest.Printf(KCurrentDateTimeChanged, &dateString);
       
    49 	}
       
    50 
       
    51 // gets the due time for this schedule
       
    52 static TTsTime GetDueTimeL(TInt aScheduleId)
       
    53 	{
       
    54 	TTsTime nextTimeScheduleIsDue;
       
    55 	TScheduleState2 state;
       
    56 	CScheduleEntryInfoArray* entries 
       
    57 		= new (ELeave) CScheduleEntryInfoArray(3);
       
    58 	CleanupStack::PushL(entries);
       
    59 	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
       
    60 	CleanupStack::PushL(tasks);
       
    61 
       
    62 	TInt res = TheScheduler.GetScheduleL(aScheduleId, state, *entries, *tasks, nextTimeScheduleIsDue);
       
    63 	TEST2(res, KErrNone);
       
    64 
       
    65 	CleanupStack::PopAndDestroy(2); // entries, tasks
       
    66 	
       
    67 	return state.DueTime();
       
    68 	}
       
    69 	
       
    70 // Forces the task to be exectued aCount times.
       
    71 static void ForceTaskExecutionForSpecifiedIdL(TInt aId, TInt aCount)
       
    72 	{
       
    73 	TheTest.Printf(_L("Executing %d times\n"), aCount);
       
    74 	TTsTime time;
       
    75 	for (TInt i=0; i<aCount; ++i)
       
    76 		{
       
    77 		TheTest.Printf(_L("Execution %d\n"), i+1);
       
    78 		time = GetDueTimeL(aId);		
       
    79 		
       
    80 		SetTimeBeforeL(TheTest, time, 5 /*seconds*/);		
       
    81 		
       
    82 		// Wait for notification that schedule has executed.
       
    83 		TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
       
    84 		CleanupHelpers::KillProcess(KMinimalTaskHandler);
       
    85 		}
       
    86 	}
       
    87 
       
    88 //creates a daily schedule with StartTime of aStartTime
       
    89 static TInt CreateScheduleL(TSchedulerItemRef& aRef, 
       
    90 							RScheduler& aScheduler, 
       
    91 							const TTsTime& aStartTime)
       
    92 	{
       
    93 	CScheduleEntryInfoArray* entryList 
       
    94 		= new (ELeave) CScheduleEntryInfoArray(1);
       
    95 	CleanupStack::PushL(entryList);
       
    96 
       
    97 	TScheduleEntryInfo2 entry1 (aStartTime, EDaily, 1, 30);
       
    98 	entryList->AppendL(entry1);
       
    99 	TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
       
   100 	CleanupStack::PopAndDestroy(); // entryList
       
   101 	return res;
       
   102 	}
       
   103 
       
   104 // counts the number of scheduled items based on the supplied filter.
       
   105 static TInt CountScheduledItemsL(TScheduleFilter aFilter, 
       
   106 								RScheduler& aScheduler)
       
   107 	// Extract schedule references from the schedule server based on a filter. If
       
   108 	{
       
   109 	CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
       
   110 	CleanupStack::PushL(refs);
       
   111 
       
   112 	TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
       
   113 	TEST2(res, KErrNone);
       
   114 
       
   115 	TInt count = refs->Count();
       
   116 	CleanupStack::PopAndDestroy(); // refs
       
   117 	return count;
       
   118 	}	
       
   119 
       
   120 // Extract task references from the schedule server based on a ID
       
   121 static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
       
   122 						TInt aScheduleId)
       
   123 	{
       
   124 	aTaskInfoArray.Reset();
       
   125 	TTsTime nextTimeScheduleIsDue;
       
   126 	TScheduleState2 state;
       
   127 	CScheduleEntryInfoArray* entries 
       
   128 		= new (ELeave) CScheduleEntryInfoArray(3);
       
   129 	CleanupStack::PushL(entries);
       
   130 	TInt res = TheScheduler.GetScheduleL(aScheduleId, 
       
   131 										state, 
       
   132 										*entries, 
       
   133 										aTaskInfoArray, 
       
   134 										nextTimeScheduleIsDue);
       
   135 	TEST2(res, KErrNone);
       
   136 	CleanupStack::PopAndDestroy(entries);
       
   137 	}
       
   138 
       
   139 // schedules a transient task	
       
   140 static TInt ScheduleTransientTaskL(TInt& aTaskId, 
       
   141 								TSchedulerItemRef& aRef, 
       
   142 								TInt aRepeat, 
       
   143 								RScheduler& aScheduler)
       
   144 	{
       
   145 	CScheduleEntryInfoArray* entryList = new(ELeave) CScheduleEntryInfoArray(3);
       
   146 	CleanupStack::PushL(entryList);
       
   147 
       
   148 	aRef.iName = _L("transient one");
       
   149 
       
   150 	// SCHEDULES
       
   151 	TTime ttime1(SchSvrHelpers::UtcTimeBasedOnOffset(0, 1));
       
   152 	TTsTime startTime1 (ttime1,ETrue); // 1 min in the future
       
   153 	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
       
   154 	entryList->AppendL(entry1);
       
   155 	TTime ttime2(SchSvrHelpers::UtcTimeBasedOnOffset(0, 2));
       
   156 	TTsTime startTime2 (ttime2,ETrue); // 2 min in the future
       
   157 	TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 500);
       
   158 	entryList->AppendL(entry2);
       
   159 
       
   160 	TTime ttime3(SchSvrHelpers::UtcTimeBasedOnOffset(0, 3));
       
   161 	TTsTime startTime3 (ttime3,ETrue); // 3 min in the future
       
   162 	TScheduleEntryInfo2 entry3 (startTime3, EDaily, 1, 5);
       
   163 	entryList->AppendL(entry3);
       
   164 
       
   165 	// TASK
       
   166 	TTaskInfo taskInfo;
       
   167 	taskInfo.iName = _L("mail");
       
   168 	taskInfo.iTaskId = aTaskId;
       
   169 	taskInfo.iRepeat = aRepeat;
       
   170 	taskInfo.iPriority = 2;
       
   171 	HBufC* data = _L("the data, some strange new name ").AllocLC();
       
   172 
       
   173 	// Schedule the item
       
   174 	TInt res = aScheduler.ScheduleTask(taskInfo, *data, aRef, *entryList);
       
   175 	CleanupStack::PopAndDestroy(2); // data, entryList
       
   176 
       
   177 	aTaskId = taskInfo.iTaskId;
       
   178 	return res;
       
   179 	}
       
   180 
       
   181 
       
   182 //***********************************************************************************
       
   183 
       
   184 /**
       
   185 @file
       
   186 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0254
       
   187 @SYMTestCaseDesc 			Replicated test for for defect (EDNEMHE-4Q69BG) - UTC
       
   188 @SYMTestPriority 			High
       
   189 @SYMTestActions  			Create time based schedules and then jump to a time after the due time but within the validity period and check it schedule still fires
       
   190 @SYMTestExpectedResults		The test must not fail.
       
   191 @SYMPREQ					PREQ234
       
   192 */
       
   193 static void Test1L()
       
   194 	{
       
   195 	_LIT(KTaskData1, "This is some really exciting task data (number 1)");
       
   196 	_LIT(KTaskData2, "This is some really exciting task data (number 2)");
       
   197 	_LIT(KTestName,	"SmsTest");
       
   198 
       
   199 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0254 TheTest3: SMS:Sending to multiple recipients "));
       
   200 	
       
   201 	TheTest.Next(_L("Connect to Scheduler"));
       
   202 	TInt res = TheScheduler.Connect();
       
   203 	TEST2(res, KErrNone);
       
   204 
       
   205 	TheTest.Next(_L("Registering Client"));
       
   206 	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
       
   207 
       
   208 	// Set the time to a known value, since this makes testing much easier (and more
       
   209 	// repeatable).	
       
   210 	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
       
   211 
       
   212 	// This is the time when we want the schedule to fire
       
   213 	TDateTime datetime(2000, EJanuary, 1, 10, 0, 0, 0);
       
   214 	TTsTime startTimeForSchedule(datetime, ETrue); // 10:00 am
       
   215 
       
   216 
       
   217 	// Prepare a schedule describing when we want the tasks to run (10:00 am)
       
   218 	TSchedulerItemRef ref;
       
   219 	User::LeaveIfError(CreateScheduleL(ref, TheScheduler, startTimeForSchedule));
       
   220 
       
   221 	// Disable the schedule whilst we set it up
       
   222 	User::LeaveIfError(TheScheduler.DisableSchedule(ref.iHandle));
       
   223 
       
   224 	// Associate a task with the schedule
       
   225 	TTaskInfo taskInfo1;
       
   226 	taskInfo1.iRepeat = 0;
       
   227 	taskInfo1.iName = KTestName;
       
   228 	taskInfo1.iPriority = 2;
       
   229 
       
   230 	// Create some data associated with this task
       
   231 	HBufC* taskData1 = KTaskData1().AllocLC();
       
   232 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo1, *taskData1, ref.iHandle));
       
   233 	CleanupStack::PopAndDestroy(); // taskData1
       
   234 
       
   235 	// Associate a task (2) with the schedule
       
   236 	TTaskInfo taskInfo2;
       
   237 	taskInfo2.iRepeat = 0;
       
   238 	taskInfo2.iName = KTestName;
       
   239 	taskInfo2.iPriority = 2;
       
   240 
       
   241 	// Create some data associated with this task
       
   242 	HBufC* taskData2 = KTaskData2().AllocLC();
       
   243 	User::LeaveIfError(TheScheduler.ScheduleTask(taskInfo2, *taskData2, ref.iHandle));
       
   244 	CleanupStack::PopAndDestroy(); // taskData2
       
   245 
       
   246 	// We should now have two tasks scheduled at exactly the same time...
       
   247 	User::LeaveIfError(TheScheduler.EnableSchedule(ref.iHandle));
       
   248 
       
   249 	// Set the time to 5 minutes *AFTER* the schedule was due to run (10:05am). In this instance,
       
   250 	// based on the new fixed Schedule Server, the schedule should still execute since 
       
   251 	// it falls within the validity period (30 mins), however, in the old scheme of things,
       
   252 	// the schedule would not be valid again until tomorrow (2/1/2000) at 10:00am and hence
       
   253 	// would not execute until then.	
       
   254 	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 10, 5, 0, 0))); // 10:05 am
       
   255 
       
   256 	// Now wait for something to happen...
       
   257 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
       
   258 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
       
   259 	}
       
   260 
       
   261 //***********************************************************************************
       
   262 
       
   263 /**
       
   264 @file
       
   265 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0255
       
   266 @SYMTestCaseDesc 			Replicated test for for defect (EDNEMHE-4Q69BG) - UTC
       
   267 @SYMTestPriority 			High
       
   268 @SYMTestActions  			Create time based schedules and then jump to a time after the due time but within the validity period and check it schedule still fires
       
   269 @SYMTestExpectedResults		The test must not fail.
       
   270 @SYMPREQ					PREQ234
       
   271 */
       
   272 static void Test2L()
       
   273 	{
       
   274 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0255 Testing creation of transient schedule with task repeating 5 times "));	
       
   275 	TInt tTask = 0;
       
   276 	TSchedulerItemRef ref;
       
   277 	// schedule has 3 entries - +1min, +2min and +3min
       
   278 	TInt res = ScheduleTransientTaskL(tTask, ref, 5, TheScheduler);//5 repeats
       
   279 	TEST2(res, KErrNone);
       
   280 	
       
   281 	TheTest.Printf(_L("Get Task count and repeat count\n"));
       
   282 
       
   283 	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
       
   284 	CleanupStack::PushL(tasks);
       
   285 	GetTaskInfoL(*tasks, ref.iHandle);
       
   286 	TEST(tasks->Count() == 1);
       
   287 	TTaskInfo info = tasks->At(0);
       
   288 	TEST(info.iRepeat == 5);
       
   289 	ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 3);
       
   290 	GetTaskInfoL(*tasks, ref.iHandle);
       
   291 	TEST(tasks->Count() == 1);
       
   292 	info = tasks->At(0);
       
   293 	TEST(info.iRepeat == 2); // still 2 repeats to go.
       
   294 	ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 2);
       
   295 
       
   296 	CleanupStack::PopAndDestroy(tasks);
       
   297 	
       
   298 	TInt scheduleCount = CountScheduledItemsL(EPendingSchedules, TheScheduler);
       
   299 	// There should be no schedules as its a transient one and last schedule
       
   300 	// should have deleted itself.
       
   301 	TEST(scheduleCount == 0); 
       
   302 	SchSvrHelpers::Pause(TheTest);
       
   303 	}
       
   304 
       
   305 //***********************************************************************************
       
   306 
       
   307 /**
       
   308 @file
       
   309 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0256
       
   310 @SYMTestCaseDesc 			Replicated test for for defect (DEF055586L) - UTC
       
   311 @SYMTestPriority 			High
       
   312 @SYMTestActions  			Create a time-based schedule check that there are 0 entries in the scehule after it fires
       
   313 @SYMTestExpectedResults		The test must not fail.
       
   314 @SYMPREQ					PREQ234
       
   315 */
       
   316 static void DEF055586L()
       
   317 	{
       
   318 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0256 DEF055586 - Last element in array missed by loop "));
       
   319 	TheTest.Next(_L("Connect to Scheduler"));
       
   320 	TInt res = TheScheduler.Connect();
       
   321 	TEST2(res, KErrNone);
       
   322 
       
   323 	TheTest.Next(_L("Registering Client"));
       
   324 	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
       
   325 
       
   326 	// Set the time to a known value, since this makes testing much easier (and more
       
   327 	// repeatable).	
       
   328 	SchSvrHelpers::SetHomeTimeL(TTime(TDateTime(2000, EJanuary, 1, 9, 55, 0, 0))); // 9:55 am
       
   329 
       
   330 	// This is the time when we want the schedule to fire
       
   331 	TDateTime datetime(2000, EJanuary, 1, 10, 0, 0, 0);
       
   332 	TTsTime startTimeForSchedule(datetime, ETrue); // 10:00 am
       
   333 
       
   334 	// Prepare a schedule describing when we want the tasks to run (10:00 am)
       
   335 	TSchedulerItemRef ref;
       
   336 
       
   337 	CScheduleEntryInfoArray* entryList = new (ELeave) CScheduleEntryInfoArray(1);
       
   338 	CleanupStack::PushL(entryList);
       
   339 
       
   340 	TScheduleEntryInfo2 entry1 (startTimeForSchedule, EDaily, 0, 30); // TTimeIntervalDays: set to 0 to induce an error
       
   341 	entryList->AppendL(entry1);
       
   342 	TInt err = TheScheduler.CreatePersistentSchedule(ref, *entryList);
       
   343 
       
   344 	TEST2(err, KErrArgument);
       
   345 
       
   346 	TheTest.Next(_L("DEF055586 - Now checking 0 entries in schedule"));
       
   347 	entryList->Reset();
       
   348 	
       
   349 	err = TheScheduler.CreatePersistentSchedule(ref, *entryList);
       
   350 	
       
   351 	TEST2(err, KErrArgument);
       
   352 	
       
   353 	CleanupStack::PopAndDestroy(); // entryList
       
   354 	}
       
   355 	
       
   356 //DEF061595  Schedule timers incorrectly expire when system time is changed 	
       
   357 //The test will create and submit one schedule which execution time is one year later.
       
   358 //Then the test will change the system time to be current time + 1 day.
       
   359 //Although the schedule time is set to be current time + 1 year, the schedule task(s) will
       
   360 //be executed immediately because the schedule timer expires when the system time changes.
       
   361 void DEF061595L()
       
   362 	{
       
   363 	TheTest.Next(_L("DEF061595  Schedule timers incorrectly expire when system time is changed"));
       
   364 	//Get current time in currTime variable
       
   365 	TTime currTime;		
       
   366 	currTime.HomeTime();
       
   367 	//Prepare the task time (in taskTime variable) to be currTime + 1 year.
       
   368 	TTime taskTime(currTime + TTimeIntervalYears(1));		
       
   369 	TInt taskYear = taskTime.DateTime().Year();
       
   370 	//Connect to the Task Scheduler Server	
       
   371 	RScheduler	scheduler;
       
   372 	CleanupClosePushL(scheduler);
       
   373 	TInt res = scheduler.Connect();
       
   374 	TEST2(res, KErrNone);
       
   375 	TEST2(SchSvrHelpers::RegisterClientL(scheduler), KErrNone);
       
   376 	//Create new schedule. The new schedule task will run 1 year later.
       
   377 	TTsTime taskTsTime(taskTime, EFalse);
       
   378 	TSchedulerItemRef ref;
       
   379 	TEST2(::CreateScheduleL(ref, scheduler, taskTsTime), KErrNone);
       
   380 	// Disable the schedule whilst we set it up
       
   381 	TEST2(scheduler.DisableSchedule(ref.iHandle), KErrNone);
       
   382 	// Associate a task with the schedule
       
   383 	_LIT(KTaskInfo, "DEF061595");
       
   384 	TTaskInfo taskInfo;
       
   385 	taskInfo.iRepeat = 0;
       
   386 	taskInfo.iName = KTaskInfo;
       
   387 	taskInfo.iPriority = 2;
       
   388 	const TInt KTaskDataLen = 1;
       
   389 	HBufC* taskData = HBufC::NewLC(KTaskDataLen);
       
   390 	TEST2(scheduler.ScheduleTask(taskInfo, *taskData, ref.iHandle), KErrNone);
       
   391 	//We should now have one tasks scheduled to be executed after 1 year.
       
   392 	//Enable schedule.
       
   393 	TEST2(scheduler.EnableSchedule(ref.iHandle), KErrNone);
       
   394 	//Get the scheduled task info. The task year should be the same as it was set in the schedule.
       
   395 	TTime nextTime;	
       
   396 	TPtr pTaskData = taskData->Des();
       
   397 	TEST2(scheduler.GetTaskInfoL(taskInfo.iTaskId, taskInfo, pTaskData, ref, nextTime), KErrNone);
       
   398 	TInt nextTaskYear = nextTime.DateTime().Year();	
       
   399 	TEST(nextTaskYear == taskYear);
       
   400 	//Change the system time to be current time + 1 day	
       
   401 	TEST2(SchSvrHelpers::SetUTCTimeL(currTime + TTimeIntervalDays(1)), KErrNone);
       
   402 	//Get the scheduled task info again. If the defect is not fixed, the call will fail
       
   403 	//with KErrNotFound (because SchSvrHelpers::SetUTCTimeL() call will make the schedule timer to expire)
       
   404 	TInt err = scheduler.GetTaskInfoL(taskInfo.iTaskId, taskInfo, pTaskData, ref, nextTime);
       
   405 //TODO	TEST2(err, KErrNone);
       
   406 //TODO	nextTaskYear = nextTime.DateTime().Year();
       
   407 //TODO	TEST(nextTaskYear == taskYear);
       
   408 	
       
   409 	CleanupStack::PopAndDestroy(taskData);
       
   410 	CleanupStack::PopAndDestroy(&scheduler);
       
   411 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
       
   412 	}
       
   413 
       
   414 /**
       
   415 @SYMTestCaseID          SYSLIB-SCHSVR-CT-1655
       
   416 @SYMTestCaseDesc	    Tests for defect number DEF079983
       
   417 @SYMTestPriority 	    High
       
   418 @SYMTestActions  	    Check to ensure all task files have been cleaned up
       
   419 						after scheduled tasks completed
       
   420 @SYMTestExpectedResults Test must not fail
       
   421 @SYMDEF 				DEF079983
       
   422 */		
       
   423 static void DEF079983L()
       
   424 	{
       
   425 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1655 DEF079983: Private directory of schsvr flooded with files "));
       
   426 	// A dummy scheduled task:
       
   427 	// Create some transient schedule task and repeat 5 times
       
   428 	TheTest.Printf(_L("DEF079983: Create a dummy scheduled task"));
       
   429 	TInt tTask = 0;
       
   430 	TSchedulerItemRef ref;
       
   431 	// 5 repeats
       
   432 	TInt res = ScheduleTransientTaskL(tTask, ref, 5, TheScheduler);
       
   433 	TEST2(res, KErrNone);
       
   434 	ForceTaskExecutionForSpecifiedIdL(ref.iHandle, 5);
       
   435 	
       
   436 	// Check for left task files after scheduled tasks completed
       
   437 	// To access private data cage, uses SchSvrHelplers::CheckTaskFilesL()
       
   438 	TheTest.Next(_L("DEF079983: Now checking no files left when tasks completed"));
       
   439 	TInt err = SchSvrHelpers::CheckTaskFilesL();
       
   440 	// If there's any task files left, test fails with error code KErrGeneral
       
   441 	TEST(err == KErrNone);
       
   442 	}		
       
   443 
       
   444 /**
       
   445 @SYMTestCaseID          SYSLIB-SCHSVR-CT-3362
       
   446 @SYMTestCaseDesc	    Replicated test for for defect (INC098909) - UTC   
       
   447 @SYMTestPriority 	    High
       
   448 @SYMTestActions  	    Mark heap of Scheduler then create a schedule & task wait for its 
       
   449 						execution then check heap again for memory leaks
       
   450 @SYMTestExpectedResults Test must not fail (i.e. No memory leaks)
       
   451 @SYMDEF                INC098909: Process !TaskScheluder leaks memory in mail polls.
       
   452 */
       
   453 static void INC098909()
       
   454 	{
       
   455 	const TInt KTimeToWait = 10*1000*1000; 
       
   456 	SchSvrHelpers::DeleteScheduleFilesL();
       
   457 	
       
   458 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3362 INC098909: Process !TaskScheluder leaks memory in mail polls "));
       
   459 	TheTest.Next(_L("Connect to Scheduler"));
       
   460 	TEST2(TheScheduler.Connect(),KErrNone);
       
   461 
       
   462 	TheTest.Next(_L("Registering Client"));
       
   463 	TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
       
   464 	
       
   465 	User::LeaveIfError(TheScheduler.__DbgMarkHeap());
       
   466 
       
   467 	//Create Schedule
       
   468 	CArrayFixFlat<TScheduleEntryInfo2>* entryList = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
       
   469 	CleanupStack::PushL(entryList);
       
   470 	TSchedulerItemRef ref;
       
   471 	
       
   472 	TTsTime startTime1(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0), ETrue); // 0m:0s from "now"
       
   473 
       
   474 	TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
       
   475 	entryList->AppendL(entry1);
       
   476 	
       
   477 	// Create the schedule for the task...
       
   478 	TEST2(TheScheduler.CreatePersistentSchedule(ref, *entryList),KErrNone);
       
   479 	
       
   480 	//Create Task
       
   481 	TTaskInfo task;
       
   482 	task.iRepeat	= 1; // repeat once
       
   483 	task.iName		= _L("Test ");
       
   484 	task.iPriority	= 100;
       
   485 	
       
   486 	HBufC* taskData = HBufC::NewLC(1);
       
   487 	TEST2(TheScheduler.ScheduleTask(task, *taskData,ref.iHandle), KErrNone);
       
   488 	
       
   489 	CleanupStack::PopAndDestroy(taskData);
       
   490 	CleanupStack::PopAndDestroy(entryList);	
       
   491 	
       
   492 	//Wait schedule to complete
       
   493 	User::After(KTimeToWait);
       
   494 
       
   495 	User::LeaveIfError(TheScheduler.__DbgMarkEnd(0));
       
   496 	
       
   497 	TheScheduler.Close();
       
   498 	// really clean out the scheduler (get rid of all the files and process)
       
   499 	SchSvrHelpers::DeleteScheduleFilesL();
       
   500 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
       
   501 	// Now wait for something to happen...
       
   502 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);	
       
   503 	}
       
   504 
       
   505 GLDEF_C TInt DoTheTestsL()
       
   506 	{
       
   507 	//Delete old files.
       
   508 	SchSvrHelpers::DeleteScheduleFilesL();
       
   509 	
       
   510 	STaskSemaphore sem;
       
   511 	sem.CreateL();
       
   512 
       
   513 	TheTest.Next(_L("Start tests"));
       
   514 	// Add tests here:-
       
   515 	Test1L();
       
   516 	Test2L();
       
   517 	INC098909();
       
   518 	DEF055586L();
       
   519 	DEF061595L();
       
   520 	DEF079983L();	// task file check test
       
   521 	
       
   522 	sem.Close();
       
   523 	
       
   524 	//Tidying up so next test will be clear.
       
   525 	TheTest.Next(_L("Delete all schedules"));
       
   526 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
       
   527 	SchSvrHelpers::Pause(TheTest, 2);
       
   528 	TheTest.Next(_L("Delete old files\n"));
       
   529 	SchSvrHelpers::DeleteScheduleFilesL();
       
   530 
       
   531 	TheScheduler.Close();
       
   532 
       
   533 	return KErrNone;
       
   534 	}
       
   535 
       
   536 //***********************************************************************************
       
   537 GLDEF_C TInt E32Main()
       
   538     {
       
   539 	__UHEAP_MARK;
       
   540 	TheTest.Title();
       
   541 	TheTest.Start(_L("TC_TSCH_SCHEDULING1 - UTC"));
       
   542 
       
   543 	TInt error = KErrNone;
       
   544 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   545 	if	(!cleanup)
       
   546 		return KErrNoMemory;
       
   547 	//If the previous test fails, SCHSVR.exe may stay in memory.
       
   548 	TRAP(error,CleanupHelpers::TestCleanupL());
       
   549 	TEST2(error, KErrNone);
       
   550 
       
   551 	TTime now;
       
   552 	now.HomeTime();
       
   553 	// Used to Set the system UTC time and UTC offset
       
   554 	// so that correct UTC Time values are returned while using time based APIs.
       
   555 	SchSvrHelpers::SetHomeTimeL(now);
       
   556 
       
   557 	TEST2(TheFsSession.Connect(), KErrNone);
       
   558 	TheTest.Next(_L("Do the tests"));
       
   559 	TRAP(error, DoTheTestsL());
       
   560 	TEST2(error,KErrNone);
       
   561 	TheFsSession.Close();
       
   562 	TRAP(error,CleanupHelpers::TestCleanupL());
       
   563 	TEST2(error, KErrNone);
       
   564 	delete cleanup;	
       
   565 
       
   566 	TheTest.End();
       
   567 	TheTest.Close();
       
   568 	__UHEAP_MARKEND;
       
   569 	return KErrNone;
       
   570 	}