os/ossrv/genericservices/taskscheduler/Test/Conditions/TC_TSCH_CONDITION_UTC.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 #include <e32property.h>
    24 #include <schinfointernal.h>
    25 #include "TestUtils.h"
    26 
    27 _LIT(KTestName,	"Task Scheduler Condition Scheduling Test - UTC");
    28 
    29 RTest	TheTest(KTestName);
    30 
    31 typedef CArrayFixFlat<TTaskInfo>			CTaskInfoArray;
    32 typedef CArrayFixFlat<TSchedulerItemRef>    CSchItemRefArray;
    33 typedef CArrayFixFlat<TTaskSchedulerCondition>	CSchConditionArray;
    34 
    35 static RScheduler	TheScheduler;
    36 static CTrapCleanup*	TheCleanup;
    37 static RFs			TheFsSession;
    38 
    39 const TInt KTestKey1 = 1;
    40 const TInt KTestKey2 = 2;
    41 const TInt KTestKey3 = 3;
    42 
    43 _LIT(KMinimalTaskHandler, "MinimalTaskHandler");
    44 _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
    45 
    46 // This function launches the TPropertyDefine process which
    47 //	has WriteDeviceData Capabilities enabling it to create the P&S 
    48 //	variables used by this test.
    49 static void LaunchHelperL(TUid aCategory, TInt aKey, TInt aAttr)
    50 	{
    51 	_LIT(KConditionHelper, "TPropertyDefine");
    52 	TRequestStatus stat;
    53 	RProcess p;
    54 	TBuf<32> args;
    55 	args.AppendNum(aCategory.iUid);
    56 	args.Append(KSeparator);
    57 	args.AppendNum(aKey);
    58 	args.Append(KSeparator);
    59 	args.AppendNum(aAttr);
    60 	User::LeaveIfError(p.Create(KConditionHelper, args,EOwnerProcess));
    61 	
    62 	// Asynchronous logon: completes when process terminates with process exit code
    63 	p.Logon(stat);
    64 	p.Resume();
    65 
    66 	User::WaitForRequest(stat);
    67 	TInt exitReason = p.ExitReason();
    68 	p.Close();
    69 	User::LeaveIfError(exitReason);
    70 	}
    71 static void CreateTestVariables()
    72 	{
    73 	LaunchHelperL(KUidSystemCategory, KTestKey1,RProperty::EInt);
    74 	LaunchHelperL(KUidSystemCategory, KTestKey2,RProperty::EInt);
    75 	LaunchHelperL(KUidSystemCategory, KTestKey3,RProperty::EInt);	
    76 	}
    77 	
    78 static void ResetVariablesL(TInt aKey1Val,
    79 							TInt aKey2Val,
    80 							TInt aKey3Val)
    81 	{
    82 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,aKey1Val));
    83 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,aKey2Val));
    84 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,aKey3Val));		
    85 	}
    86 	
    87 static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
    88 						TInt aScheduleId)
    89 	// Extract schedule references from the schedule server based on a filter. If
    90 	{
    91 	aTaskInfoArray.Reset();
    92 	TTsTime defaultTime;
    93 	TScheduleState2 state;
    94 	CSchConditionArray* conditionList 
    95 		= new (ELeave) CSchConditionArray(3);
    96 	CleanupStack::PushL(conditionList);
    97 	TInt res = TheScheduler.GetScheduleL(aScheduleId, 
    98 										state, 
    99 										*conditionList, 
   100 										defaultTime,
   101 										aTaskInfoArray);
   102 	TEST2(res, KErrNone);
   103 	CleanupStack::PopAndDestroy(conditionList);
   104 	}
   105 
   106 static TInt CountTasksL(TInt aScheduleId)	
   107 	{
   108 	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
   109 	CleanupStack::PushL(tasks);
   110 	GetTaskInfoL(*tasks, aScheduleId);
   111 	TInt ret = tasks->Count();
   112 	CleanupStack::PopAndDestroy(tasks);
   113 	return ret;
   114 	}
   115 	
   116 
   117 static TInt CountScheduledItemsL(TScheduleFilter aFilter, 
   118 								RScheduler& aScheduler)
   119 	// Extract schedule references from the schedule server based on a filter. If
   120 	{
   121 	CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
   122 	CleanupStack::PushL(refs);
   123 
   124 	TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
   125 	TEST2(res, KErrNone);
   126 
   127 	TInt count = refs->Count();
   128 	CleanupStack::PopAndDestroy(); // refs
   129 	return count;
   130 	}
   131 
   132 static CSchConditionArray* CreateSingleConditionLC(const TUid& aConditionUID,
   133 									TUint aConditionUInt)
   134 	{
   135 	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
   136 	CleanupStack::PushL(conditionList);
   137 
   138 	{
   139 	TTaskSchedulerCondition condition1;
   140 	condition1.iCategory = aConditionUID;
   141 	condition1.iKey		= aConditionUInt;
   142 	condition1.iState	= 10;
   143 	condition1.iType	= TTaskSchedulerCondition::EEquals;
   144 	conditionList->AppendL(condition1);
   145 	}
   146 	return conditionList;			
   147 	}
   148 
   149 static CSchConditionArray* CreateMultipleConditionsLC()
   150 	{
   151 	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
   152 	CleanupStack::PushL(conditionList);
   153 	{
   154 	TTaskSchedulerCondition condition1;
   155 	condition1.iCategory = KUidSystemCategory;
   156 	condition1.iKey		= KTestKey1;
   157 	condition1.iState	= 10;
   158 	condition1.iType	= TTaskSchedulerCondition::EEquals;
   159 	conditionList->AppendL(condition1);
   160 	}
   161 	{
   162 	TTaskSchedulerCondition condition2;
   163 	condition2.iCategory = KUidSystemCategory;
   164 	condition2.iKey		= KTestKey2;
   165 	condition2.iState	= 10;
   166 	condition2.iType	= TTaskSchedulerCondition::ENotEquals;
   167 	conditionList->AppendL(condition2);
   168 	}
   169 	{
   170 	TTaskSchedulerCondition condition3;
   171 	condition3.iCategory = KUidSystemCategory;
   172 	condition3.iKey		= KTestKey3;
   173 	condition3.iState	= 10;
   174 	condition3.iType	= TTaskSchedulerCondition::ELessThan;
   175 	conditionList->AppendL(condition3);
   176 	}
   177 	return conditionList;		
   178 	}
   179 	
   180 // single condition with default time set to 1 year in the future
   181 // As this is a valid time a CTimer object actually gets set unlike 
   182 // if Time::TTimeMax() is used, hence we need to test for both cases.
   183 static TInt CreateScheduleSingle1L(TSchedulerItemRef& aRef, 
   184 									RScheduler& aScheduler,
   185 									const TUid& aConditionUID,
   186 									TUint aConditionUInt)
   187 	{
   188 	aRef.iName = _L("Schedule created using CreateScheduleSingle");
   189 
   190 	CSchConditionArray* conditionList 
   191 		= CreateSingleConditionLC(aConditionUID, aConditionUInt);
   192 		
   193 	TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
   194 	TTsTime time(ttime, ETrue); //1 year in the future
   195 	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   196 	CleanupStack::PopAndDestroy(); // conditionList
   197 	return res;
   198 	}
   199 
   200 // single condition with default time set to Time::MaxTTime()
   201 static TInt CreateScheduleSingle2L(TSchedulerItemRef& aRef, 
   202 									RScheduler& aScheduler,
   203 									const TUid& aConditionUID,
   204 									TUint aConditionUInt)
   205 	{
   206 	aRef.iName = _L("Schedule created using CreateScheduleSingle");
   207 
   208 	CSchConditionArray* conditionList 
   209 		= CreateSingleConditionLC(aConditionUID, aConditionUInt);
   210 	TTime ttime(Time::MaxTTime());
   211 	TTsTime time(ttime, ETrue);
   212 	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   213 	CleanupStack::PopAndDestroy(); // conditionList
   214 	return res;
   215 	}
   216 
   217 // An empty schedule list.
   218 static TInt CreateScheduleEmpty3L(TSchedulerItemRef& aRef, 
   219 									RScheduler& aScheduler,
   220 									const TUid&,
   221 									TUint )
   222 	{
   223 	aRef.iName = _L("Empty Schedule list created");
   224 
   225 	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
   226 	CleanupStack::PushL(conditionList);
   227 	TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
   228 	TTsTime time(ttime, ETrue); //1 year in the future
   229 	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   230 	CleanupStack::PopAndDestroy(); // conditionList
   231 	
   232 	return res;
   233 	}
   234 
   235 // A null schedule.
   236 static TInt CreateScheduleSingleNull4L(TSchedulerItemRef& aRef, 
   237 									RScheduler& aScheduler,
   238 									const TUid&,
   239 									TUint )
   240 	{
   241 	aRef.iName = _L("One schedule in the list with a NULL uid");
   242 	
   243 	CSchConditionArray* conditionList 
   244 		= CreateSingleConditionLC(KNullUid, 0);
   245 	TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
   246 	TTsTime time(ttime, ETrue); //1 year in the future
   247 	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   248 	CleanupStack::PopAndDestroy(); // conditionList
   249 
   250 	return res;
   251 	}
   252 
   253 static TInt CreateScheduleMultipleL(TSchedulerItemRef& aRef, RScheduler& aScheduler)
   254 	{
   255 	aRef.iName = _L("Schedule created using CreateScheduleMultiple");
   256 	
   257 	CSchConditionArray* conditionList = CreateMultipleConditionsLC();
   258 	TTime ttime(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, 1));
   259 	TTsTime time(ttime, ETrue); //1 year in the future
   260 	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   261 	CleanupStack::PopAndDestroy(); // conditionList
   262 	return res;
   263 	}
   264 
   265 static TInt SchedulePersistentTaskL(const TDesC& aName, 
   266 									TInt& aNewId, 
   267 									TInt aScheduleId, 
   268 									RScheduler& aScheduler)
   269 	{
   270 	TTaskInfo taskInfo;
   271 	taskInfo.iTaskId = aNewId;
   272 	taskInfo.iName = aName;
   273 	taskInfo.iPriority = 2;
   274 	taskInfo.iRepeat = 0;
   275 	HBufC* data = _L("the data").AllocLC();
   276 	TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
   277 	aNewId = taskInfo.iTaskId;
   278 
   279 	CleanupStack::PopAndDestroy(); // data
   280 	return res;
   281 	}
   282 
   283 /**
   284 @file
   285 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0244
   286 @SYMTestCaseDesc 			Single condition based test - UTC
   287 @SYMTestPriority 			High
   288 @SYMTestActions  			Create a condition based schedule & check schedule auto deletes
   289 @SYMTestExpectedResults		The test must not fail.
   290 @SYMPREQ					PREQ234
   291 */
   292 static void DoTest1L()
   293 	{
   294 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0244 "));
   295 	// create a simple condition based schedule, and see if it runs.
   296 	TInt res = KErrNone;
   297 	TheTest.Next(_L("single condition based test"));
   298 	__UHEAP_MARK;
   299 	
   300 	//reset the p&s variables before creating the schedule
   301 	ResetVariablesL(0,0,0);
   302 	TSchedulerItemRef ref1;
   303 	TheTest.Printf(_L("Create a schedule\n"));
   304 	res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   305 	TEST2(res, KErrNone);
   306 	
   307 	TInt task1 = 0;
   308 	_LIT(KName1, "toothpaste");
   309 	TheTest.Printf(_L("Schedule some tasks\n"));
   310 
   311 	res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
   312 	TEST2(res, KErrNone);
   313 	
   314 	res = TheScheduler.__DbgMarkHeap();
   315 	User::LeaveIfError(res); //#1
   316 	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   317 	TEST(scheduleCount == 1); 
   318 	
   319 	// Check that schedule is of condition type
   320 	TScheduleType scheduleType;
   321 	res = TheScheduler.GetScheduleTypeL(ref1.iHandle, scheduleType);
   322 	TEST2(res, KErrNone);
   323 	TEST(scheduleType == EConditionSchedule );	
   324 
   325 	res = TheScheduler.__DbgMarkEnd(0);
   326 	User::LeaveIfError(res); //#1
   327 	
   328 	TheScheduler.Close();
   329 	SchSvrHelpers::Pause(TheTest);
   330 
   331 	// wait for condition to be satisfied
   332 	res = RProperty::Set(KUidSystemCategory, KTestKey1,10);
   333 	User::LeaveIfError(res);
   334 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   335 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   336 	
   337 	res = TheScheduler.Connect();
   338 	TEST2(res, KErrNone);
   339 	// Register a client with the server
   340 	TheTest.Next(_L("===== Registering Client ====="));
   341 	res = SchSvrHelpers::RegisterClientL(TheScheduler);
   342 	TEST2(res, KErrNone);
   343 
   344 	// can't check scheduler to see if any tasks left because it's been
   345 	// deleted as last task has completed
   346 	
   347 	//Check that persistent schedule has auto-deleted
   348 
   349 	TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n"));
   350 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   351 	TEST(scheduleCount == 0);
   352 	
   353 	// Attempt to delete auto-deleted schedule, should fail
   354 	 
   355 	TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
   356 	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   357 	TEST2(res, KErrNotFound);
   358 	
   359 	// now repeat process with singleschedule2
   360 	ResetVariablesL(0,0,0);
   361 
   362 	TheTest.Printf(_L("Create another schedule\n"));
   363 	res = CreateScheduleSingle2L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   364 	TEST2(res, KErrNone);	
   365 
   366 	TheTest.Printf(_L("Create an empty schedule list\n"));
   367 	res = CreateScheduleEmpty3L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   368 	TEST2(res, KErrArgument);	
   369 
   370 	TheTest.Printf(_L("Create an empty schedule list\n"));
   371 	res = CreateScheduleSingleNull4L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   372 	TEST2(res, KErrArgument);	
   373 
   374 	res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
   375 	TEST2(res, KErrNone);
   376 	SchSvrHelpers::Pause(TheTest);
   377 
   378 	// we should have one outstanding task (without the check in
   379 	// schtimer.cpp specifically for Time::MaxTTime() the timer would have
   380 	// gone off immediately in the past.)
   381 	TEST(CountTasksL(ref1.iHandle) == 1);
   382 
   383 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   384 	TEST(scheduleCount == 1); 
   385 	// wait for condition to be satisfied
   386 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));
   387 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   388 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   389 	
   390 	// can't check scheduler to see if any tasks left because it's been
   391 	// deleted as last task has completed
   392 
   393 	TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n"));
   394 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   395 	TEST(scheduleCount == 0); 
   396 	
   397 	// Attempt to delete auto-deleted schedule, should fail
   398 	 
   399 	TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
   400 	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   401 	TEST2(res, KErrNotFound);
   402 		
   403 	SchSvrHelpers::Pause(TheTest);
   404 	__UHEAP_MARKEND;
   405 	}
   406 
   407 /**
   408 @file
   409 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0245
   410 @SYMTestCaseDesc 			Multiple condition based test - UTC
   411 @SYMTestPriority 			High
   412 @SYMTestActions  	    	Create a condition based schedule with multiple entries, and see if it runs.
   413                         	Try auto deleting the last schedule and test for not found error. 
   414 @SYMTestExpectedResults		The test must not fail.
   415 @SYMPREQ					PREQ234
   416 */
   417 static void DoTest2L()
   418 	{
   419 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0245 "));
   420 	// create a condition based schedule with multiple entries, and see if it runs.
   421 	TInt res = KErrNone;
   422 	TheTest.Next(_L("multiple condition based test"));
   423 	__UHEAP_MARK;
   424 	
   425 	//reset the p&s variables before creating the schedule
   426 	ResetVariablesL(0,10,20);
   427 	TSchedulerItemRef ref1;
   428 	TheTest.Printf(_L("Create a schedule\n"));
   429 	res = CreateScheduleMultipleL(ref1, TheScheduler);
   430 	TEST2(res, KErrNone);	
   431 
   432 	TInt task1 = 0;
   433 	_LIT(KName1, "web subscription");
   434 	TheTest.Printf(_L("Schedule some tasks\n"));
   435 	res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
   436 	TEST2(res, KErrNone);
   437 
   438 	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   439 	TEST(scheduleCount == 1); 
   440 
   441 	// we should have one task scheduled to run
   442 	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
   443 	CleanupStack::PushL(tasks);
   444 	GetTaskInfoL(*tasks, ref1.iHandle);
   445 	TEST(tasks->Count() == 1);
   446 	tasks->Reset();
   447 	
   448 	// wait for conditions to be satisfied
   449 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));//"=="
   450 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,1234));//"!="
   451 	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,9));//"<"
   452 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   453 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   454 
   455 	// Can't check schedule for task info because it's gone
   456 
   457 	
   458 	// we should have no schedule, it has auto-deleted
   459 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   460 	TEST(scheduleCount == 0); 
   461 			
   462 	// Reset variables
   463 	TheTest.Printf(_L("Reseting variables"));
   464 	ResetVariablesL(0,10,20);
   465 
   466 	TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
   467 	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   468 	TEST2(res, KErrNotFound);
   469 	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   470 	TEST(scheduleCount == 0); 
   471 	
   472 	CleanupStack::PopAndDestroy(tasks);
   473 	
   474 	SchSvrHelpers::Pause(TheTest);
   475 	__UHEAP_MARKEND;
   476 	}
   477 	
   478 /**
   479 @file
   480 @SYMTestCaseID				SYSLIB-SCHSVR-CT-0246
   481 @SYMTestCaseDesc 			Error checking test - UTC
   482 @SYMTestPriority 			High
   483 @SYMTestActions  			Create a schedule with a P&S variables that doesnt exist & create a schedule with a P&S variable that isnt an integer.
   484 @SYMTestExpectedResults		The test must not fail.
   485 @SYMPREQ					PREQ234
   486 */	
   487 static void DoTest3L()	
   488 	{
   489 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0246 "));
   490 	// create a simple condition based schedule, and see if it runs.
   491 	TInt res = KErrNone;
   492 	TheTest.Next(_L("error checking test"));
   493 	__UHEAP_MARK;
   494 	
   495 	//reset the p&s variables before creating the schedule
   496 	ResetVariablesL(0,0,0);
   497 	TSchedulerItemRef ref1;
   498 	_LIT(KName1, "toothpaste");
   499 
   500 	TheTest.Printf(_L("Create a schedule with a P&S variables that doesnt exist\n"));
   501 	{
   502 	const TUid KNonexistentUid = TUid::Uid(0x01234566);
   503 	res = CreateScheduleSingle1L(ref1, TheScheduler, KNonexistentUid, KTestKey1);
   504 	TEST2(res, KErrNone);
   505 	TheTest.Printf(_L("Schedule some tasks - error should be returned\n"));
   506 
   507 	TTaskInfo taskInfo;
   508 	taskInfo.iName = KName1;
   509 	taskInfo.iPriority = 2;
   510 	taskInfo.iRepeat = 0;
   511 	HBufC* data = _L("the data").AllocLC();
   512 	res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
   513 	// since we have created the schedule using a UID which doesn't exist
   514 	//we should get an error
   515 	TEST2(res, KErrArgument);
   516 	CleanupStack::PopAndDestroy(); // data
   517 	
   518 	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
   519 	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   520 	TEST2(res, KErrNone);
   521 	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   522 	TEST(scheduleCount == 0); 
   523 	}
   524 
   525 	TheTest.Printf(_L("Create a schedule\n"));
   526 	res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   527 	TEST2(res, KErrNone);	
   528 	TheTest.Printf(_L("Schedule some tasks\n"));
   529 	{
   530 	TTaskInfo taskInfo;
   531 	taskInfo.iName = KName1;
   532 	taskInfo.iPriority = 2;
   533 	taskInfo.iRepeat = 1;
   534 	HBufC* data = _L("the data").AllocLC();
   535 	User::LeaveIfError(TheScheduler.__DbgMarkHeap());
   536 	res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
   537 	// since we have set repeat to something other than 0, we should get an error
   538 	TEST2(res, KErrArgument);
   539 	User::LeaveIfError(TheScheduler.__DbgMarkEnd(0));
   540 	CleanupStack::PopAndDestroy(); // data
   541 	}
   542 	
   543 	SchSvrHelpers::Pause(TheTest);
   544 	__UHEAP_MARKEND;
   545 	}
   546 	
   547 /**
   548 @SYMTestCaseID          SYSLIB-SCHSVR-CT-3245
   549 @SYMTestCaseDesc	    Persistent condition based schedule test
   550 @SYMTestPriority 	    High
   551 @SYMTestActions  	    Create a single persistent condition based schedule and then 
   552 						terminate the task scheduler.
   553 						Set the condition and then launch the task scheduler with the 
   554 						condition satisfied.  Check that the schedule is executed.
   555 @SYMTestExpectedResults Schedule must be executed and test must not panic or fail
   556 @SYMREQ                 REQ0000
   557 */
   558 static void DoTest4L()
   559 	{
   560 	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3245 "));
   561 	// create a persistent condition based schedule
   562 	TInt res = KErrNone;
   563 	TheTest.Next(_L("single condition based test"));
   564 	__UHEAP_MARK;
   565 	
   566 	//reset the p&s variables before creating the schedule
   567 	ResetVariablesL(0,0,0);
   568 	TSchedulerItemRef ref1;
   569 	TheTest.Printf(_L("Create a test schedule\n"));
   570 	res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   571 	TEST2(res, KErrNone);
   572 	
   573 	TInt task1 = 0;
   574 	_LIT(KName1, "shutdown task 1");
   575 	TheTest.Printf(_L("Schedule a persistant task\n"));
   576 
   577 	res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
   578 	TEST2(res, KErrNone);
   579 
   580 	//Fault the server to force it to shut down
   581  	TheScheduler.__FaultServer();
   582 
   583 	//close the Scheduler handle
   584 	TheScheduler.Close();
   585 
   586 	SchSvrHelpers::Pause(TheTest);
   587 		
   588 	// set condition
   589 	res = RProperty::Set(KUidSystemCategory, KTestKey1,10);
   590 	TEST2(res, KErrNone);
   591 	
   592 	//Restart the scheduler with the condition for this persistant task
   593 	//satisfied
   594 	res = TheScheduler.Connect();
   595 	TEST2(res, KErrNone);	
   596 	
   597 	//wait for task to be executed
   598 	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   599 	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   600 	
   601 	SchSvrHelpers::Pause(TheTest);
   602 
   603 	__UHEAP_MARKEND;
   604 	
   605 	}
   606 
   607 static TInt RunTestsL()
   608 	{
   609 	TheTest.Next(_L("Delete old files"));
   610 	SchSvrHelpers::DeleteScheduleFilesL();
   611 
   612 	TheTest.Next(_L("Create Task notification semaphore"));
   613 	//initialise task notification semaphore
   614 	STaskSemaphore sem;
   615 	sem.CreateL();
   616 
   617 	// Connect to the server
   618 	TheTest.Next(_L("===== Connect to Scheduler ====="));
   619 	TInt res = TheScheduler.Connect();
   620 	TEST2(res, KErrNone);
   621 	// Register a client with the server
   622 	TheTest.Next(_L("===== Registering Client ====="));
   623 	res = SchSvrHelpers::RegisterClientL(TheScheduler);
   624 	TEST2(res, KErrNone);
   625 	
   626 	// Launch helper process to create P&S variables
   627 	CreateTestVariables();
   628 	
   629 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
   630 	CleanupStack::PushL(scheduler);
   631 	CActiveScheduler::Install(scheduler);
   632 	
   633 	TheTest.Next(_L("Start tests"));
   634  	DoTest1L();
   635 	DoTest2L();
   636 	DoTest3L();
   637 	DoTest4L();
   638 
   639 	TheTest.Next(_L("Tidying up"));
   640 	CleanupStack::PopAndDestroy(scheduler);
   641 	//close handle to semaphore
   642 	sem.Close();
   643 	
   644 	//Tidying up so next test will be clear.
   645 	TheTest.Next(_L("Delete all schedules"));
   646 	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   647 	SchSvrHelpers::Pause(TheTest, 2);
   648 	TheTest.Next(_L("Delete old files\n"));
   649 	SchSvrHelpers::DeleteScheduleFilesL();
   650 
   651 	TheScheduler.Close();
   652 	return KErrNone;
   653 	}
   654 
   655 GLDEF_C TInt E32Main()
   656     {
   657 	__UHEAP_MARK;
   658 	TheTest.Start(_L("TC_TSCH_CONDITION_UTC"));
   659 	TheTest.Title();
   660 	TheCleanup = CTrapCleanup::New();
   661 
   662 	//If the previous test fails, SCHSVR.exe may stay in memory.
   663 	TRAPD(error,CleanupHelpers::TestCleanupL());
   664 	TEST2(error, KErrNone);
   665 	TheTest(TheFsSession.Connect() == KErrNone);;
   666 	TRAP(error, RunTestsL());
   667 	TEST2(error, KErrNone);	
   668 	TRAP(error,CleanupHelpers::TestCleanupL());
   669 	TEST2(error, KErrNone);
   670 	delete TheCleanup;
   671 	
   672 	TheFsSession.Close();
   673 	TheTest.End();
   674 	TheTest.Close();
   675 	__UHEAP_MARKEND;
   676 
   677 	return KErrNone;
   678 	}