os/ossrv/genericservices/taskscheduler/Test/Conditions/TC_TSCH_CONDITION.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/taskscheduler/Test/Conditions/TC_TSCH_CONDITION.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,681 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <csch_cli.h>
    1.20 +#include "Thelpers.h"
    1.21 +
    1.22 +#include <e32base.h>
    1.23 +#include <e32test.h>
    1.24 +#include <f32file.h>
    1.25 +#include <s32file.h>
    1.26 +#include <e32property.h>
    1.27 +#include <schinfointernal.h>
    1.28 +
    1.29 +#include "TestUtils.h"
    1.30 +
    1.31 +_LIT(KTestName,	"Task Scheduler Condition Scheduling Test");
    1.32 +
    1.33 +RTest	TheTest(KTestName);
    1.34 +
    1.35 +typedef CArrayFixFlat<TTaskInfo>			CTaskInfoArray;
    1.36 +typedef CArrayFixFlat<TSchedulerItemRef>    CSchItemRefArray;
    1.37 +typedef CArrayFixFlat<TTaskSchedulerCondition>	CSchConditionArray;
    1.38 +
    1.39 +static RScheduler	TheScheduler;
    1.40 +static CTrapCleanup*	TheCleanup;
    1.41 +static RFs			TheFsSession;
    1.42 +
    1.43 +const TInt KTestKey1 = 1;
    1.44 +const TInt KTestKey2 = 2;
    1.45 +const TInt KTestKey3 = 3;
    1.46 +
    1.47 +_LIT(KMinimalTaskHandler, "MinimalTaskHandler");
    1.48 +_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
    1.49 +
    1.50 +// This function launches the TPropertyDefine process which
    1.51 +//	has WriteDeviceData Capabilities enabling it to create the P&S 
    1.52 +//	variables used by this test.
    1.53 +static void LaunchHelperL(TUid aCategory, TInt aKey, TInt aAttr)
    1.54 +	{
    1.55 +	_LIT(KConditionHelper, "TPropertyDefine");
    1.56 +	TRequestStatus stat;
    1.57 +	RProcess p;
    1.58 +	
    1.59 +	TBuf<32> args;
    1.60 +	args.AppendNum(aCategory.iUid);
    1.61 +	args.Append(KSeparator);
    1.62 +	args.AppendNum(aKey);
    1.63 +	args.Append(KSeparator);
    1.64 +	args.AppendNum(aAttr);
    1.65 +	
    1.66 +	User::LeaveIfError(p.Create(KConditionHelper, args,EOwnerProcess));
    1.67 +	
    1.68 +	// Asynchronous logon: completes when process terminates with process exit code
    1.69 +	p.Logon(stat);
    1.70 +	p.Resume();
    1.71 +
    1.72 +	User::WaitForRequest(stat);
    1.73 +	TInt exitReason = p.ExitReason();
    1.74 +	p.Close();
    1.75 +	User::LeaveIfError(exitReason);
    1.76 +	}
    1.77 +	
    1.78 +	
    1.79 +static void CreateTestVariables()
    1.80 +	{
    1.81 +	LaunchHelperL(KUidSystemCategory, KTestKey1,RProperty::EInt);
    1.82 +	LaunchHelperL(KUidSystemCategory, KTestKey2,RProperty::EInt);
    1.83 +	LaunchHelperL(KUidSystemCategory, KTestKey3,RProperty::EInt);	
    1.84 +	}	
    1.85 +
    1.86 +static void ResetVariablesL(TInt aKey1Val,
    1.87 +							TInt aKey2Val,
    1.88 +							TInt aKey3Val)
    1.89 +	{
    1.90 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,aKey1Val));
    1.91 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,aKey2Val));
    1.92 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,aKey3Val));		
    1.93 +	}
    1.94 +	
    1.95 +static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
    1.96 +						TInt aScheduleId)
    1.97 +	// Extract schedule references from the schedule server based on a filter. If
    1.98 +	{
    1.99 +	aTaskInfoArray.Reset();
   1.100 +	TTime defaultTime;
   1.101 +	TScheduleState state;
   1.102 +	CSchConditionArray* conditionList 
   1.103 +		= new (ELeave) CSchConditionArray(3);
   1.104 +	CleanupStack::PushL(conditionList);
   1.105 +	TInt res = TheScheduler.GetScheduleL(aScheduleId, 
   1.106 +										state, 
   1.107 +										*conditionList, 
   1.108 +										defaultTime,
   1.109 +										aTaskInfoArray);
   1.110 +	TEST2(res, KErrNone);
   1.111 +	CleanupStack::PopAndDestroy(conditionList);
   1.112 +	}
   1.113 +
   1.114 +static TInt CountTasksL(TInt aScheduleId)	
   1.115 +	{
   1.116 +	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
   1.117 +	CleanupStack::PushL(tasks);
   1.118 +	GetTaskInfoL(*tasks, aScheduleId);
   1.119 +	TInt ret = tasks->Count();
   1.120 +	CleanupStack::PopAndDestroy(tasks);
   1.121 +	return ret;
   1.122 +	}
   1.123 +	
   1.124 +
   1.125 +static TInt CountScheduledItemsL(TScheduleFilter aFilter, 
   1.126 +								RScheduler& aScheduler)
   1.127 +	// Extract schedule references from the schedule server based on a filter. If
   1.128 +	{
   1.129 +	CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
   1.130 +	CleanupStack::PushL(refs);
   1.131 +
   1.132 +	TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
   1.133 +	TEST2(res, KErrNone);
   1.134 +
   1.135 +	TInt count = refs->Count();
   1.136 +	CleanupStack::PopAndDestroy(); // refs
   1.137 +	return count;
   1.138 +	}
   1.139 +
   1.140 +static CSchConditionArray* CreateSingleConditionLC(const TUid& aConditionUID,
   1.141 +									TUint aConditionUInt)
   1.142 +	{
   1.143 +	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
   1.144 +	CleanupStack::PushL(conditionList);
   1.145 +
   1.146 +	{
   1.147 +	TTaskSchedulerCondition condition1;
   1.148 +	condition1.iCategory = aConditionUID;
   1.149 +	condition1.iKey		= aConditionUInt;
   1.150 +	condition1.iState	= 10;
   1.151 +	condition1.iType	= TTaskSchedulerCondition::EEquals;
   1.152 +	conditionList->AppendL(condition1);
   1.153 +	}
   1.154 +	return conditionList;
   1.155 +	}
   1.156 +	
   1.157 +static CSchConditionArray* CreateMultipleConditionsLC()
   1.158 +	{
   1.159 +	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
   1.160 +	CleanupStack::PushL(conditionList);
   1.161 +	{
   1.162 +	TTaskSchedulerCondition condition1;
   1.163 +	condition1.iCategory = KUidSystemCategory;
   1.164 +	condition1.iKey		= KTestKey1;
   1.165 +	condition1.iState	= 10;
   1.166 +	condition1.iType	= TTaskSchedulerCondition::EEquals;
   1.167 +	conditionList->AppendL(condition1);
   1.168 +	}
   1.169 +	{
   1.170 +	TTaskSchedulerCondition condition2;
   1.171 +	condition2.iCategory = KUidSystemCategory;
   1.172 +	condition2.iKey		= KTestKey2;
   1.173 +	condition2.iState	= 10;
   1.174 +	condition2.iType	= TTaskSchedulerCondition::ENotEquals;
   1.175 +	conditionList->AppendL(condition2);
   1.176 +	}
   1.177 +	{
   1.178 +	TTaskSchedulerCondition condition3;
   1.179 +	condition3.iCategory = KUidSystemCategory;
   1.180 +	condition3.iKey		= KTestKey3;
   1.181 +	condition3.iState	= 10;
   1.182 +	condition3.iType	= TTaskSchedulerCondition::ELessThan;
   1.183 +	conditionList->AppendL(condition3);
   1.184 +	}
   1.185 +	return conditionList;		
   1.186 +	}
   1.187 +	
   1.188 +// single condition with default time set to 1 year in the future
   1.189 +// As this is a valid time a CTimer object actually gets set unlike 
   1.190 +// if Time::TTimeMax() is used, hence we need to test for both cases.
   1.191 +static TInt CreateScheduleSingle1L(TSchedulerItemRef& aRef, 
   1.192 +									RScheduler& aScheduler,
   1.193 +									const TUid& aConditionUID,
   1.194 +									TUint aConditionUInt)
   1.195 +	{
   1.196 +	aRef.iName = _L("Schedule created using CreateScheduleSingle");
   1.197 +
   1.198 +	CSchConditionArray* conditionList 
   1.199 +		= CreateSingleConditionLC(aConditionUID, aConditionUInt);
   1.200 +	TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
   1.201 +	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   1.202 +	CleanupStack::PopAndDestroy(); // conditionList
   1.203 +	return res;
   1.204 +	}
   1.205 +
   1.206 +// single condition with default time set to Time::MaxTTime()
   1.207 +static TInt CreateScheduleSingle2L(TSchedulerItemRef& aRef, 
   1.208 +									RScheduler& aScheduler,
   1.209 +									const TUid& aConditionUID,
   1.210 +									TUint aConditionUInt)
   1.211 +	{
   1.212 +	aRef.iName = _L("Schedule created using CreateScheduleSingle");
   1.213 +
   1.214 +	CSchConditionArray* conditionList 
   1.215 +		= CreateSingleConditionLC(aConditionUID, aConditionUInt);
   1.216 +	TTime time = Time::MaxTTime();
   1.217 +	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   1.218 +	CleanupStack::PopAndDestroy(); // conditionList
   1.219 +	return res;
   1.220 +	}
   1.221 +
   1.222 +// An empty schedule list.
   1.223 +static TInt CreateScheduleEmpty3L(TSchedulerItemRef& aRef, 
   1.224 +									RScheduler& aScheduler,
   1.225 +									const TUid&,
   1.226 +									TUint )
   1.227 +	{
   1.228 +	aRef.iName = _L("Empty Schedule list created");
   1.229 +
   1.230 +	CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
   1.231 +	CleanupStack::PushL(conditionList);
   1.232 +
   1.233 +	TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
   1.234 +	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   1.235 +	CleanupStack::PopAndDestroy(); // conditionList
   1.236 +	
   1.237 +	return res;
   1.238 +	}
   1.239 +
   1.240 +// A null schedule.
   1.241 +static TInt CreateScheduleSingleNull4L(TSchedulerItemRef& aRef, 
   1.242 +									RScheduler& aScheduler,
   1.243 +									const TUid&,
   1.244 +									TUint )
   1.245 +	{
   1.246 +	aRef.iName = _L("One schedule in the list with a NULL uid");
   1.247 +	
   1.248 +	CSchConditionArray* conditionList 
   1.249 +		= CreateSingleConditionLC(KNullUid, 0);
   1.250 +		
   1.251 +	TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
   1.252 +	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   1.253 +	CleanupStack::PopAndDestroy(); // conditionList
   1.254 +
   1.255 +	return res;
   1.256 +	}
   1.257 +
   1.258 +static TInt CreateScheduleMultipleL(TSchedulerItemRef& aRef, RScheduler& aScheduler)
   1.259 +	{
   1.260 +	aRef.iName = _L("Schedule created using CreateScheduleMultiple");
   1.261 +	
   1.262 +	CSchConditionArray* conditionList = CreateMultipleConditionsLC();
   1.263 +	TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
   1.264 +	TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time);
   1.265 +	CleanupStack::PopAndDestroy(); // conditionList
   1.266 +	return res;
   1.267 +	}
   1.268 +
   1.269 +static TInt SchedulePersistentTaskL(const TDesC& aName, 
   1.270 +									TInt& aNewId, 
   1.271 +									TInt aScheduleId, 
   1.272 +									RScheduler& aScheduler)
   1.273 +	{
   1.274 +	TTaskInfo taskInfo;
   1.275 +	taskInfo.iTaskId = aNewId;
   1.276 +	taskInfo.iName = aName;
   1.277 +	taskInfo.iPriority = 2;
   1.278 +	taskInfo.iRepeat = 0;
   1.279 +	HBufC* data = _L("the data").AllocLC();
   1.280 +	TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
   1.281 +	aNewId = taskInfo.iTaskId;
   1.282 +
   1.283 +	CleanupStack::PopAndDestroy(); // data
   1.284 +	return res;
   1.285 +	}
   1.286 +
   1.287 +/**
   1.288 +@SYMTestCaseID          SYSLIB-SCHSVR-CT-1024
   1.289 +@SYMTestCaseDesc	    Single condition based test
   1.290 +@SYMTestPriority 	    High
   1.291 +@SYMTestActions  	    Create a single schedule,check that schedule is of condition type.Wait for the condition to be satisfied
   1.292 +                        Check that persistent schedule has auto-deleted.Repeat the process with another schedule with time set to 
   1.293 +                        Time::MaxTTime().Try auto deleting the last schedule and test for not found error. 
   1.294 +@SYMTestExpectedResults Test must not fail
   1.295 +@SYMREQ                 REQ0000
   1.296 +*/
   1.297 +static void DoTest1L()
   1.298 +	{
   1.299 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1024 "));
   1.300 +	// create a simple condition based schedule, and see if it runs.
   1.301 +	TInt res = KErrNone;
   1.302 +	TheTest.Next(_L("single condition based test"));
   1.303 +	__UHEAP_MARK;
   1.304 +	
   1.305 +	//reset the p&s variables before creating the schedule
   1.306 +	ResetVariablesL(0,0,0);
   1.307 +	TSchedulerItemRef ref1;
   1.308 +	TheTest.Printf(_L("Create a schedule\n"));
   1.309 +	res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   1.310 +	TEST2(res, KErrNone);
   1.311 +	
   1.312 +	TInt task1 = 0;
   1.313 +	_LIT(KName1, "toothpaste");
   1.314 +	TheTest.Printf(_L("Schedule some tasks\n"));
   1.315 +
   1.316 +	res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
   1.317 +	TEST2(res, KErrNone);
   1.318 +	
   1.319 +	res = TheScheduler.__DbgMarkHeap();
   1.320 +	User::LeaveIfError(res); //#1
   1.321 +	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   1.322 +	TEST(scheduleCount == 1); 
   1.323 +	
   1.324 +	// Check that schedule is of condition type
   1.325 +	TScheduleType scheduleType;
   1.326 +	res = TheScheduler.GetScheduleTypeL(ref1.iHandle, scheduleType);
   1.327 +	TEST2(res, KErrNone);
   1.328 +	TEST(scheduleType == EConditionSchedule );	
   1.329 +
   1.330 +	res = TheScheduler.__DbgMarkEnd(0);
   1.331 +	User::LeaveIfError(res); //#1
   1.332 +	
   1.333 +	TheScheduler.Close();
   1.334 +	SchSvrHelpers::Pause(TheTest);
   1.335 +
   1.336 +	// wait for condition to be satisfied
   1.337 +	res = RProperty::Set(KUidSystemCategory, KTestKey1,10);
   1.338 +	User::LeaveIfError(res);	
   1.339 +	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   1.340 +	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   1.341 +	
   1.342 +	res = TheScheduler.Connect();
   1.343 +	TEST2(res, KErrNone);
   1.344 +	// Register a client with the server
   1.345 +	TheTest.Next(_L("===== Registering Client ====="));
   1.346 +	res = SchSvrHelpers::RegisterClientL(TheScheduler);
   1.347 +	TEST2(res, KErrNone);
   1.348 +
   1.349 +	// can't check scheduler to see if any tasks left because it's been
   1.350 +	// deleted as last task has completed
   1.351 +	
   1.352 +	//Check that persistent schedule has auto-deleted
   1.353 +
   1.354 +	TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n"));
   1.355 +	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   1.356 +	TEST(scheduleCount == 0);
   1.357 +	
   1.358 +	// Attempt to delete auto-deleted schedule, should fail
   1.359 +	 
   1.360 +	TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
   1.361 +	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   1.362 +	TEST2(res, KErrNotFound);
   1.363 +	
   1.364 +	// now repeat process with singleschedule2
   1.365 +	ResetVariablesL(0,0,0);
   1.366 +
   1.367 +	TheTest.Printf(_L("Create another schedule\n"));
   1.368 +	res = CreateScheduleSingle2L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   1.369 +	TEST2(res, KErrNone);	
   1.370 +
   1.371 +	TheTest.Printf(_L("Create an empty schedule list\n"));
   1.372 +	res = CreateScheduleEmpty3L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   1.373 +	TEST2(res, KErrArgument);	
   1.374 +
   1.375 +	TheTest.Printf(_L("Create an empty schedule in a list\n"));
   1.376 +	res = CreateScheduleSingleNull4L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   1.377 +	TEST2(res, KErrArgument);	
   1.378 +
   1.379 +	res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
   1.380 +	TEST2(res, KErrNone);
   1.381 +	SchSvrHelpers::Pause(TheTest);
   1.382 +
   1.383 +	// we should have one outstanding task (without the check in
   1.384 +	// schtimer.cpp specifically for Time::MaxTTime() the timer would have
   1.385 +	// gone off immediately in the past.)
   1.386 +	TEST(CountTasksL(ref1.iHandle) == 1);
   1.387 +
   1.388 +	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   1.389 +	TEST(scheduleCount == 1); 
   1.390 +	// wait for condition to be satisfied
   1.391 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));	
   1.392 +	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   1.393 +	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   1.394 +	
   1.395 +	// can't check scheduler to see if any tasks left because it's been
   1.396 +	// deleted as last task has completed
   1.397 +
   1.398 +	TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n"));
   1.399 +	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   1.400 +	TEST(scheduleCount == 0); 
   1.401 +	
   1.402 +	// Attempt to delete auto-deleted schedule, should fail
   1.403 +	 
   1.404 +	TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
   1.405 +	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   1.406 +	TEST2(res, KErrNotFound);
   1.407 +		
   1.408 +	SchSvrHelpers::Pause(TheTest);
   1.409 +	__UHEAP_MARKEND;
   1.410 +	}
   1.411 +
   1.412 +/**
   1.413 +@SYMTestCaseID          SYSLIB-SCHSVR-CT-1025
   1.414 +@SYMTestCaseDesc	    Multiple conditions based tests
   1.415 +@SYMTestPriority 	    High
   1.416 +@SYMTestActions  	    Create a condition based schedule with multiple entries, and see if it runs.
   1.417 +                        Try auto deleting the last schedule and test for not found error. 
   1.418 +@SYMTestExpectedResults Test must not fail
   1.419 +@SYMREQ                 REQ0000
   1.420 +*/
   1.421 +static void DoTest2L()
   1.422 +	{
   1.423 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1025 "));
   1.424 +	// create a condition based schedule with multiple entries, and see if it runs.
   1.425 +	TInt res = KErrNone;
   1.426 +	TheTest.Next(_L("multiple condition based test"));
   1.427 +	__UHEAP_MARK;
   1.428 +	
   1.429 +	//reset the p&s variables before creating the schedule
   1.430 +	ResetVariablesL(0,10,20);
   1.431 +	TSchedulerItemRef ref1;
   1.432 +	TheTest.Printf(_L("Create a schedule\n"));
   1.433 +	res = CreateScheduleMultipleL(ref1, TheScheduler);
   1.434 +	TEST2(res, KErrNone);	
   1.435 +
   1.436 +	TInt task1 = 0;
   1.437 +	_LIT(KName1, "web subscription");
   1.438 +	TheTest.Printf(_L("Schedule some tasks\n"));
   1.439 +	res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
   1.440 +	TEST2(res, KErrNone);
   1.441 +
   1.442 +	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   1.443 +	TEST(scheduleCount == 1); 
   1.444 +
   1.445 +	// we should have one task scheduled to run
   1.446 +	CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
   1.447 +	CleanupStack::PushL(tasks);
   1.448 +	GetTaskInfoL(*tasks, ref1.iHandle);
   1.449 +	TEST(tasks->Count() == 1);
   1.450 +	tasks->Reset();
   1.451 +	
   1.452 +	// wait for conditions to be satisfied
   1.453 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));//"=="
   1.454 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,1234));//"!="
   1.455 +	User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,9));//"<"	
   1.456 +	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   1.457 +	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   1.458 +
   1.459 +	// Can't check schedule for task info because it's gone
   1.460 +
   1.461 +	
   1.462 +	// we should have no schedule, it has auto-deleted
   1.463 +	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   1.464 +	TEST(scheduleCount == 0); 
   1.465 +			
   1.466 +	// Reset variables
   1.467 +	TheTest.Printf(_L("Reseting variables"));
   1.468 +	ResetVariablesL(0,10,20);
   1.469 +
   1.470 +	TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle);
   1.471 +	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   1.472 +	TEST2(res, KErrNotFound);
   1.473 +	scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   1.474 +	TEST(scheduleCount == 0); 
   1.475 +	
   1.476 +	CleanupStack::PopAndDestroy(tasks);
   1.477 +	
   1.478 +	SchSvrHelpers::Pause(TheTest);
   1.479 +	__UHEAP_MARKEND;
   1.480 +	}
   1.481 +
   1.482 +/**
   1.483 +Test 3 does a lot of error checking	
   1.484 +
   1.485 +@SYMTestCaseID          SYSLIB-SCHSVR-CT-1026
   1.486 +@SYMTestCaseDesc	    Tests for error conditions checking on task scheduler
   1.487 +@SYMTestPriority 	    High
   1.488 +@SYMTestActions  	    Create invalid P&S variable's and schedule a task,check for no argument error
   1.489 +@SYMTestExpectedResults Test must not fail
   1.490 +@SYMREQ                 REQ0000
   1.491 +*/	
   1.492 +static void DoTest3L()	
   1.493 +	{
   1.494 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1026 "));
   1.495 +	// create a simple condition based schedule, and see if it runs.
   1.496 +	TInt res = KErrNone;
   1.497 +	TheTest.Next(_L("error checking test"));
   1.498 +	__UHEAP_MARK;
   1.499 +	
   1.500 +	//reset the p&s variables before creating the schedule
   1.501 +	ResetVariablesL(0,0,0);
   1.502 +	TSchedulerItemRef ref1;
   1.503 +	_LIT(KName1, "toothpaste");
   1.504 +
   1.505 +	TheTest.Printf(_L("Create a schedule with a P&S variables that doesnt exist\n"));
   1.506 +	{
   1.507 +	const TUid KNonexistentUid = TUid::Uid(0x01234566);
   1.508 +	res = CreateScheduleSingle1L(ref1, TheScheduler, KNonexistentUid, KTestKey1);
   1.509 +	TEST2(res, KErrNone);
   1.510 +	TheTest.Printf(_L("Schedule some tasks - error should be returned\n"));
   1.511 +
   1.512 +	TTaskInfo taskInfo;
   1.513 +	taskInfo.iName = KName1;
   1.514 +	taskInfo.iPriority = 2;
   1.515 +	taskInfo.iRepeat = 0;
   1.516 +	HBufC* data = _L("the data").AllocLC();
   1.517 +	res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
   1.518 +	// since we have created the schedule using a UID which doesn't exist
   1.519 +	//we should get an error
   1.520 +	TEST2(res, KErrArgument);
   1.521 +	CleanupStack::PopAndDestroy(); // data
   1.522 +	
   1.523 +	TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
   1.524 +	res = TheScheduler.DeleteSchedule(ref1.iHandle);
   1.525 +	TEST2(res, KErrNone);
   1.526 +	TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
   1.527 +	TEST(scheduleCount == 0); 
   1.528 +	}
   1.529 +	
   1.530 +	TheTest.Printf(_L("Create a schedule\n"));
   1.531 +	res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   1.532 +	TEST2(res, KErrNone);	
   1.533 +	TheTest.Printf(_L("Schedule some tasks\n"));
   1.534 +	{
   1.535 +	TTaskInfo taskInfo;
   1.536 +	taskInfo.iName = KName1;
   1.537 +	taskInfo.iPriority = 2;
   1.538 +	taskInfo.iRepeat = 1;
   1.539 +	HBufC* data = _L("the data").AllocLC();
   1.540 +	User::LeaveIfError(TheScheduler.__DbgMarkHeap());
   1.541 +	res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle);
   1.542 +	// since we have set repeat to something other than 0, we should get an error
   1.543 +	TEST2(res, KErrArgument);
   1.544 +	User::LeaveIfError(TheScheduler.__DbgMarkEnd(0));
   1.545 +	CleanupStack::PopAndDestroy(); // data
   1.546 +	}
   1.547 +	
   1.548 +	SchSvrHelpers::Pause(TheTest);
   1.549 +	__UHEAP_MARKEND;
   1.550 +	}
   1.551 +	
   1.552 +
   1.553 +/**
   1.554 +@SYMTestCaseID          SYSLIB-SCHSVR-CT-3227
   1.555 +@SYMTestCaseDesc	    Persistent condition based schedule test
   1.556 +@SYMTestPriority 	    High
   1.557 +@SYMTestActions  	    Create a single persistent condition based schedule and then 
   1.558 +						terminate the task scheduler.
   1.559 +						Set the condition and then launch the task scheduler with the 
   1.560 +						condition satisfied.  Check that the schedule is executed.
   1.561 +@SYMTestExpectedResults Schedule must be executed and test must not panic or fail
   1.562 +@SYMREQ                 REQ0000
   1.563 +*/
   1.564 +static void DoTest4L()
   1.565 +	{
   1.566 +	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3227 "));
   1.567 +	// create a persistent condition based schedule
   1.568 +	TInt res = KErrNone;
   1.569 +	TheTest.Next(_L("single condition based test"));
   1.570 +	__UHEAP_MARK;
   1.571 +	
   1.572 +	//reset the p&s variables before creating the schedule
   1.573 +	ResetVariablesL(0,0,0);
   1.574 +	TSchedulerItemRef ref1;
   1.575 +	TheTest.Printf(_L("Create a test schedule\n"));
   1.576 +	res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1);
   1.577 +	TEST2(res, KErrNone);
   1.578 +	
   1.579 +	TInt task1 = 0;
   1.580 +	_LIT(KName1, "shutdown task 1");
   1.581 +	TheTest.Printf(_L("Schedule a persistant task\n"));
   1.582 +
   1.583 +	res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler);
   1.584 +	TEST2(res, KErrNone);
   1.585 +
   1.586 +	//Fault the server to force it to shut down
   1.587 + 	TheScheduler.__FaultServer();
   1.588 +
   1.589 +	//close the Scheduler handle
   1.590 +	TheScheduler.Close();
   1.591 +	
   1.592 +	SchSvrHelpers::Pause(TheTest);
   1.593 +		
   1.594 +	// set condition
   1.595 +	res = RProperty::Set(KUidSystemCategory, KTestKey1,10);
   1.596 +	TEST2(res, KErrNone);
   1.597 +	
   1.598 +	//Restart the scheduler with the condition for this persistant task
   1.599 +	//satisfied
   1.600 +	res = TheScheduler.Connect();
   1.601 +	TEST2(res, KErrNone);	
   1.602 +	
   1.603 +	//wait for task to be executed
   1.604 +	TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); 
   1.605 +	CleanupHelpers::KillProcess(KMinimalTaskHandler);
   1.606 +	
   1.607 +	SchSvrHelpers::Pause(TheTest);
   1.608 +
   1.609 +	__UHEAP_MARKEND;
   1.610 +	
   1.611 +	}
   1.612 +
   1.613 +static TInt RunTestsL()
   1.614 +	{
   1.615 +	TheTest.Next(_L("Delete old files"));
   1.616 +	SchSvrHelpers::DeleteScheduleFilesL();
   1.617 +
   1.618 +	TheTest.Next(_L("Create Task notification semaphore"));
   1.619 +	//initialise task notification semaphore
   1.620 +	STaskSemaphore sem;
   1.621 +	sem.CreateL();
   1.622 +
   1.623 +	// Connect to the server
   1.624 +	TheTest.Next(_L("===== Connect to Scheduler ====="));
   1.625 +	TInt res = TheScheduler.Connect();
   1.626 +	TEST2(res, KErrNone);
   1.627 +	// Register a client with the server
   1.628 +	TheTest.Next(_L("===== Registering Client ====="));
   1.629 +	res = SchSvrHelpers::RegisterClientL(TheScheduler);
   1.630 +	TEST2(res, KErrNone);
   1.631 +	
   1.632 +	// Launch helper process to create P&S variables
   1.633 +	CreateTestVariables();
   1.634 +	
   1.635 +	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
   1.636 +	CleanupStack::PushL(scheduler);
   1.637 +	CActiveScheduler::Install(scheduler);
   1.638 +	
   1.639 +	TheTest.Next(_L("Start tests"));
   1.640 + 	DoTest1L();
   1.641 +	DoTest2L();
   1.642 +	DoTest3L();
   1.643 +	DoTest4L();
   1.644 +
   1.645 +	TheTest.Next(_L("Tidying up"));
   1.646 +	CleanupStack::PopAndDestroy(scheduler);
   1.647 +	//close handle to semaphore
   1.648 +	sem.Close();
   1.649 +	
   1.650 +	//Tidying up so next test will be clear.
   1.651 +	TheTest.Next(_L("Delete all schedules"));
   1.652 +	SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
   1.653 +	SchSvrHelpers::Pause(TheTest, 2);
   1.654 +	TheTest.Next(_L("Delete old files\n"));
   1.655 +	SchSvrHelpers::DeleteScheduleFilesL();
   1.656 +
   1.657 +	TheScheduler.Close();
   1.658 +	return KErrNone;
   1.659 +	}
   1.660 +
   1.661 +GLDEF_C TInt E32Main()
   1.662 +    {
   1.663 +	__UHEAP_MARK;
   1.664 +	TheTest.Start(_L("TC_TSCH_CONDITION"));
   1.665 +	TheTest.Title();
   1.666 +	TheCleanup = CTrapCleanup::New();
   1.667 +
   1.668 +	//If the previous test fails, SCHSVR.exe may stay in memory.
   1.669 +	TRAPD(error,CleanupHelpers::TestCleanupL());
   1.670 +	TEST2(error, KErrNone);
   1.671 +	TheTest(TheFsSession.Connect() == KErrNone);;
   1.672 +	TRAP(error, RunTestsL());
   1.673 +	TEST2(error, KErrNone);	
   1.674 +	TRAP(error,CleanupHelpers::TestCleanupL());
   1.675 +	TEST2(error, KErrNone);
   1.676 +	delete TheCleanup;	
   1.677 +	
   1.678 +	TheFsSession.Close();
   1.679 +	TheTest.End();
   1.680 +	TheTest.Close();
   1.681 +	__UHEAP_MARKEND;
   1.682 +
   1.683 +	return KErrNone;
   1.684 +	}