sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "Thelpers.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "TestUtils.h" sl@0: sl@0: _LIT(KTestName, "Task Scheduler Condition Scheduling Test"); sl@0: sl@0: RTest TheTest(KTestName); sl@0: sl@0: typedef CArrayFixFlat CTaskInfoArray; sl@0: typedef CArrayFixFlat CSchItemRefArray; sl@0: typedef CArrayFixFlat CSchConditionArray; sl@0: sl@0: static RScheduler TheScheduler; sl@0: static CTrapCleanup* TheCleanup; sl@0: static RFs TheFsSession; sl@0: sl@0: const TInt KTestKey1 = 1; sl@0: const TInt KTestKey2 = 2; sl@0: const TInt KTestKey3 = 3; sl@0: sl@0: _LIT(KMinimalTaskHandler, "MinimalTaskHandler"); sl@0: _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames sl@0: sl@0: // This function launches the TPropertyDefine process which sl@0: // has WriteDeviceData Capabilities enabling it to create the P&S sl@0: // variables used by this test. sl@0: static void LaunchHelperL(TUid aCategory, TInt aKey, TInt aAttr) sl@0: { sl@0: _LIT(KConditionHelper, "TPropertyDefine"); sl@0: TRequestStatus stat; sl@0: RProcess p; sl@0: sl@0: TBuf<32> args; sl@0: args.AppendNum(aCategory.iUid); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aKey); sl@0: args.Append(KSeparator); sl@0: args.AppendNum(aAttr); sl@0: sl@0: User::LeaveIfError(p.Create(KConditionHelper, args,EOwnerProcess)); sl@0: sl@0: // Asynchronous logon: completes when process terminates with process exit code sl@0: p.Logon(stat); sl@0: p.Resume(); sl@0: sl@0: User::WaitForRequest(stat); sl@0: TInt exitReason = p.ExitReason(); sl@0: p.Close(); sl@0: User::LeaveIfError(exitReason); sl@0: } sl@0: sl@0: sl@0: static void CreateTestVariables() sl@0: { sl@0: LaunchHelperL(KUidSystemCategory, KTestKey1,RProperty::EInt); sl@0: LaunchHelperL(KUidSystemCategory, KTestKey2,RProperty::EInt); sl@0: LaunchHelperL(KUidSystemCategory, KTestKey3,RProperty::EInt); sl@0: } sl@0: sl@0: static void ResetVariablesL(TInt aKey1Val, sl@0: TInt aKey2Val, sl@0: TInt aKey3Val) sl@0: { sl@0: User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,aKey1Val)); sl@0: User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,aKey2Val)); sl@0: User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,aKey3Val)); sl@0: } sl@0: sl@0: static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray, sl@0: TInt aScheduleId) sl@0: // Extract schedule references from the schedule server based on a filter. If sl@0: { sl@0: aTaskInfoArray.Reset(); sl@0: TTime defaultTime; sl@0: TScheduleState state; sl@0: CSchConditionArray* conditionList sl@0: = new (ELeave) CSchConditionArray(3); sl@0: CleanupStack::PushL(conditionList); sl@0: TInt res = TheScheduler.GetScheduleL(aScheduleId, sl@0: state, sl@0: *conditionList, sl@0: defaultTime, sl@0: aTaskInfoArray); sl@0: TEST2(res, KErrNone); sl@0: CleanupStack::PopAndDestroy(conditionList); sl@0: } sl@0: sl@0: static TInt CountTasksL(TInt aScheduleId) sl@0: { sl@0: CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3); sl@0: CleanupStack::PushL(tasks); sl@0: GetTaskInfoL(*tasks, aScheduleId); sl@0: TInt ret = tasks->Count(); sl@0: CleanupStack::PopAndDestroy(tasks); sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: static TInt CountScheduledItemsL(TScheduleFilter aFilter, sl@0: RScheduler& aScheduler) sl@0: // Extract schedule references from the schedule server based on a filter. If sl@0: { sl@0: CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3); sl@0: CleanupStack::PushL(refs); sl@0: sl@0: TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = refs->Count(); sl@0: CleanupStack::PopAndDestroy(); // refs sl@0: return count; sl@0: } sl@0: sl@0: static CSchConditionArray* CreateSingleConditionLC(const TUid& aConditionUID, sl@0: TUint aConditionUInt) sl@0: { sl@0: CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3); sl@0: CleanupStack::PushL(conditionList); sl@0: sl@0: { sl@0: TTaskSchedulerCondition condition1; sl@0: condition1.iCategory = aConditionUID; sl@0: condition1.iKey = aConditionUInt; sl@0: condition1.iState = 10; sl@0: condition1.iType = TTaskSchedulerCondition::EEquals; sl@0: conditionList->AppendL(condition1); sl@0: } sl@0: return conditionList; sl@0: } sl@0: sl@0: static CSchConditionArray* CreateMultipleConditionsLC() sl@0: { sl@0: CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3); sl@0: CleanupStack::PushL(conditionList); sl@0: { sl@0: TTaskSchedulerCondition condition1; sl@0: condition1.iCategory = KUidSystemCategory; sl@0: condition1.iKey = KTestKey1; sl@0: condition1.iState = 10; sl@0: condition1.iType = TTaskSchedulerCondition::EEquals; sl@0: conditionList->AppendL(condition1); sl@0: } sl@0: { sl@0: TTaskSchedulerCondition condition2; sl@0: condition2.iCategory = KUidSystemCategory; sl@0: condition2.iKey = KTestKey2; sl@0: condition2.iState = 10; sl@0: condition2.iType = TTaskSchedulerCondition::ENotEquals; sl@0: conditionList->AppendL(condition2); sl@0: } sl@0: { sl@0: TTaskSchedulerCondition condition3; sl@0: condition3.iCategory = KUidSystemCategory; sl@0: condition3.iKey = KTestKey3; sl@0: condition3.iState = 10; sl@0: condition3.iType = TTaskSchedulerCondition::ELessThan; sl@0: conditionList->AppendL(condition3); sl@0: } sl@0: return conditionList; sl@0: } sl@0: sl@0: // single condition with default time set to 1 year in the future sl@0: // As this is a valid time a CTimer object actually gets set unlike sl@0: // if Time::TTimeMax() is used, hence we need to test for both cases. sl@0: static TInt CreateScheduleSingle1L(TSchedulerItemRef& aRef, sl@0: RScheduler& aScheduler, sl@0: const TUid& aConditionUID, sl@0: TUint aConditionUInt) sl@0: { sl@0: aRef.iName = _L("Schedule created using CreateScheduleSingle"); sl@0: sl@0: CSchConditionArray* conditionList sl@0: = CreateSingleConditionLC(aConditionUID, aConditionUInt); sl@0: TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future sl@0: TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time); sl@0: CleanupStack::PopAndDestroy(); // conditionList sl@0: return res; sl@0: } sl@0: sl@0: // single condition with default time set to Time::MaxTTime() sl@0: static TInt CreateScheduleSingle2L(TSchedulerItemRef& aRef, sl@0: RScheduler& aScheduler, sl@0: const TUid& aConditionUID, sl@0: TUint aConditionUInt) sl@0: { sl@0: aRef.iName = _L("Schedule created using CreateScheduleSingle"); sl@0: sl@0: CSchConditionArray* conditionList sl@0: = CreateSingleConditionLC(aConditionUID, aConditionUInt); sl@0: TTime time = Time::MaxTTime(); sl@0: TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time); sl@0: CleanupStack::PopAndDestroy(); // conditionList sl@0: return res; sl@0: } sl@0: sl@0: // An empty schedule list. sl@0: static TInt CreateScheduleEmpty3L(TSchedulerItemRef& aRef, sl@0: RScheduler& aScheduler, sl@0: const TUid&, sl@0: TUint ) sl@0: { sl@0: aRef.iName = _L("Empty Schedule list created"); sl@0: sl@0: CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3); sl@0: CleanupStack::PushL(conditionList); sl@0: sl@0: TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future sl@0: TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time); sl@0: CleanupStack::PopAndDestroy(); // conditionList sl@0: sl@0: return res; sl@0: } sl@0: sl@0: // A null schedule. sl@0: static TInt CreateScheduleSingleNull4L(TSchedulerItemRef& aRef, sl@0: RScheduler& aScheduler, sl@0: const TUid&, sl@0: TUint ) sl@0: { sl@0: aRef.iName = _L("One schedule in the list with a NULL uid"); sl@0: sl@0: CSchConditionArray* conditionList sl@0: = CreateSingleConditionLC(KNullUid, 0); sl@0: sl@0: TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future sl@0: TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time); sl@0: CleanupStack::PopAndDestroy(); // conditionList sl@0: sl@0: return res; sl@0: } sl@0: sl@0: static TInt CreateScheduleMultipleL(TSchedulerItemRef& aRef, RScheduler& aScheduler) sl@0: { sl@0: aRef.iName = _L("Schedule created using CreateScheduleMultiple"); sl@0: sl@0: CSchConditionArray* conditionList = CreateMultipleConditionsLC(); sl@0: TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future sl@0: TInt res = aScheduler.CreatePersistentSchedule(aRef, *conditionList, time); sl@0: CleanupStack::PopAndDestroy(); // conditionList sl@0: return res; sl@0: } sl@0: sl@0: static TInt SchedulePersistentTaskL(const TDesC& aName, sl@0: TInt& aNewId, sl@0: TInt aScheduleId, sl@0: RScheduler& aScheduler) sl@0: { sl@0: TTaskInfo taskInfo; sl@0: taskInfo.iTaskId = aNewId; sl@0: taskInfo.iName = aName; sl@0: taskInfo.iPriority = 2; sl@0: taskInfo.iRepeat = 0; sl@0: HBufC* data = _L("the data").AllocLC(); sl@0: TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId); sl@0: aNewId = taskInfo.iTaskId; sl@0: sl@0: CleanupStack::PopAndDestroy(); // data sl@0: return res; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-1024 sl@0: @SYMTestCaseDesc Single condition based test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Create a single schedule,check that schedule is of condition type.Wait for the condition to be satisfied sl@0: Check that persistent schedule has auto-deleted.Repeat the process with another schedule with time set to sl@0: Time::MaxTTime().Try auto deleting the last schedule and test for not found error. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: static void DoTest1L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1024 ")); sl@0: // create a simple condition based schedule, and see if it runs. sl@0: TInt res = KErrNone; sl@0: TheTest.Next(_L("single condition based test")); sl@0: __UHEAP_MARK; sl@0: sl@0: //reset the p&s variables before creating the schedule sl@0: ResetVariablesL(0,0,0); sl@0: TSchedulerItemRef ref1; sl@0: TheTest.Printf(_L("Create a schedule\n")); sl@0: res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt task1 = 0; sl@0: _LIT(KName1, "toothpaste"); sl@0: TheTest.Printf(_L("Schedule some tasks\n")); sl@0: sl@0: res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler); sl@0: TEST2(res, KErrNone); sl@0: sl@0: res = TheScheduler.__DbgMarkHeap(); sl@0: User::LeaveIfError(res); //#1 sl@0: TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); sl@0: TEST(scheduleCount == 1); sl@0: sl@0: // Check that schedule is of condition type sl@0: TScheduleType scheduleType; sl@0: res = TheScheduler.GetScheduleTypeL(ref1.iHandle, scheduleType); sl@0: TEST2(res, KErrNone); sl@0: TEST(scheduleType == EConditionSchedule ); sl@0: sl@0: res = TheScheduler.__DbgMarkEnd(0); sl@0: User::LeaveIfError(res); //#1 sl@0: sl@0: TheScheduler.Close(); sl@0: SchSvrHelpers::Pause(TheTest); sl@0: sl@0: // wait for condition to be satisfied sl@0: res = RProperty::Set(KUidSystemCategory, KTestKey1,10); sl@0: User::LeaveIfError(res); sl@0: TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); sl@0: CleanupHelpers::KillProcess(KMinimalTaskHandler); sl@0: sl@0: res = TheScheduler.Connect(); sl@0: TEST2(res, KErrNone); sl@0: // Register a client with the server sl@0: TheTest.Next(_L("===== Registering Client =====")); sl@0: res = SchSvrHelpers::RegisterClientL(TheScheduler); sl@0: TEST2(res, KErrNone); sl@0: sl@0: // can't check scheduler to see if any tasks left because it's been sl@0: // deleted as last task has completed sl@0: sl@0: //Check that persistent schedule has auto-deleted sl@0: sl@0: TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n")); sl@0: scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); sl@0: TEST(scheduleCount == 0); sl@0: sl@0: // Attempt to delete auto-deleted schedule, should fail sl@0: sl@0: TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle); sl@0: res = TheScheduler.DeleteSchedule(ref1.iHandle); sl@0: TEST2(res, KErrNotFound); sl@0: sl@0: // now repeat process with singleschedule2 sl@0: ResetVariablesL(0,0,0); sl@0: sl@0: TheTest.Printf(_L("Create another schedule\n")); sl@0: res = CreateScheduleSingle2L(ref1, TheScheduler, KUidSystemCategory, KTestKey1); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TheTest.Printf(_L("Create an empty schedule list\n")); sl@0: res = CreateScheduleEmpty3L(ref1, TheScheduler, KUidSystemCategory, KTestKey1); sl@0: TEST2(res, KErrArgument); sl@0: sl@0: TheTest.Printf(_L("Create an empty schedule in a list\n")); sl@0: res = CreateScheduleSingleNull4L(ref1, TheScheduler, KUidSystemCategory, KTestKey1); sl@0: TEST2(res, KErrArgument); sl@0: sl@0: res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler); sl@0: TEST2(res, KErrNone); sl@0: SchSvrHelpers::Pause(TheTest); sl@0: sl@0: // we should have one outstanding task (without the check in sl@0: // schtimer.cpp specifically for Time::MaxTTime() the timer would have sl@0: // gone off immediately in the past.) sl@0: TEST(CountTasksL(ref1.iHandle) == 1); sl@0: sl@0: scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); sl@0: TEST(scheduleCount == 1); sl@0: // wait for condition to be satisfied sl@0: User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10)); sl@0: TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); sl@0: CleanupHelpers::KillProcess(KMinimalTaskHandler); sl@0: sl@0: // can't check scheduler to see if any tasks left because it's been sl@0: // deleted as last task has completed sl@0: sl@0: TheTest.Printf(_L("DEF46200 - Check schedule has auto deleted\n")); sl@0: scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); sl@0: TEST(scheduleCount == 0); sl@0: sl@0: // Attempt to delete auto-deleted schedule, should fail sl@0: sl@0: TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle); sl@0: res = TheScheduler.DeleteSchedule(ref1.iHandle); sl@0: TEST2(res, KErrNotFound); sl@0: sl@0: SchSvrHelpers::Pause(TheTest); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-1025 sl@0: @SYMTestCaseDesc Multiple conditions based tests sl@0: @SYMTestPriority High sl@0: @SYMTestActions Create a condition based schedule with multiple entries, and see if it runs. sl@0: Try auto deleting the last schedule and test for not found error. sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: static void DoTest2L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1025 ")); sl@0: // create a condition based schedule with multiple entries, and see if it runs. sl@0: TInt res = KErrNone; sl@0: TheTest.Next(_L("multiple condition based test")); sl@0: __UHEAP_MARK; sl@0: sl@0: //reset the p&s variables before creating the schedule sl@0: ResetVariablesL(0,10,20); sl@0: TSchedulerItemRef ref1; sl@0: TheTest.Printf(_L("Create a schedule\n")); sl@0: res = CreateScheduleMultipleL(ref1, TheScheduler); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt task1 = 0; sl@0: _LIT(KName1, "web subscription"); sl@0: TheTest.Printf(_L("Schedule some tasks\n")); sl@0: res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); sl@0: TEST(scheduleCount == 1); sl@0: sl@0: // we should have one task scheduled to run sl@0: CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3); sl@0: CleanupStack::PushL(tasks); sl@0: GetTaskInfoL(*tasks, ref1.iHandle); sl@0: TEST(tasks->Count() == 1); sl@0: tasks->Reset(); sl@0: sl@0: // wait for conditions to be satisfied sl@0: User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey1,10));//"==" sl@0: User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey2,1234));//"!=" sl@0: User::LeaveIfError(RProperty::Set(KUidSystemCategory, KTestKey3,9));//"<" sl@0: TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); sl@0: CleanupHelpers::KillProcess(KMinimalTaskHandler); sl@0: sl@0: // Can't check schedule for task info because it's gone sl@0: sl@0: sl@0: // we should have no schedule, it has auto-deleted sl@0: scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); sl@0: TEST(scheduleCount == 0); sl@0: sl@0: // Reset variables sl@0: TheTest.Printf(_L("Reseting variables")); sl@0: ResetVariablesL(0,10,20); sl@0: sl@0: TheTest.Printf(_L("DEF46200 - Attempting to delete schedule with id %d\n"), ref1.iHandle); sl@0: res = TheScheduler.DeleteSchedule(ref1.iHandle); sl@0: TEST2(res, KErrNotFound); sl@0: scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); sl@0: TEST(scheduleCount == 0); sl@0: sl@0: CleanupStack::PopAndDestroy(tasks); sl@0: sl@0: SchSvrHelpers::Pause(TheTest); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: /** sl@0: Test 3 does a lot of error checking sl@0: sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-1026 sl@0: @SYMTestCaseDesc Tests for error conditions checking on task scheduler sl@0: @SYMTestPriority High sl@0: @SYMTestActions Create invalid P&S variable's and schedule a task,check for no argument error sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: static void DoTest3L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1026 ")); sl@0: // create a simple condition based schedule, and see if it runs. sl@0: TInt res = KErrNone; sl@0: TheTest.Next(_L("error checking test")); sl@0: __UHEAP_MARK; sl@0: sl@0: //reset the p&s variables before creating the schedule sl@0: ResetVariablesL(0,0,0); sl@0: TSchedulerItemRef ref1; sl@0: _LIT(KName1, "toothpaste"); sl@0: sl@0: TheTest.Printf(_L("Create a schedule with a P&S variables that doesnt exist\n")); sl@0: { sl@0: const TUid KNonexistentUid = TUid::Uid(0x01234566); sl@0: res = CreateScheduleSingle1L(ref1, TheScheduler, KNonexistentUid, KTestKey1); sl@0: TEST2(res, KErrNone); sl@0: TheTest.Printf(_L("Schedule some tasks - error should be returned\n")); sl@0: sl@0: TTaskInfo taskInfo; sl@0: taskInfo.iName = KName1; sl@0: taskInfo.iPriority = 2; sl@0: taskInfo.iRepeat = 0; sl@0: HBufC* data = _L("the data").AllocLC(); sl@0: res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle); sl@0: // since we have created the schedule using a UID which doesn't exist sl@0: //we should get an error sl@0: TEST2(res, KErrArgument); sl@0: CleanupStack::PopAndDestroy(); // data sl@0: sl@0: TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle); sl@0: res = TheScheduler.DeleteSchedule(ref1.iHandle); sl@0: TEST2(res, KErrNone); sl@0: TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); sl@0: TEST(scheduleCount == 0); sl@0: } sl@0: sl@0: TheTest.Printf(_L("Create a schedule\n")); sl@0: res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1); sl@0: TEST2(res, KErrNone); sl@0: TheTest.Printf(_L("Schedule some tasks\n")); sl@0: { sl@0: TTaskInfo taskInfo; sl@0: taskInfo.iName = KName1; sl@0: taskInfo.iPriority = 2; sl@0: taskInfo.iRepeat = 1; sl@0: HBufC* data = _L("the data").AllocLC(); sl@0: User::LeaveIfError(TheScheduler.__DbgMarkHeap()); sl@0: res = TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle); sl@0: // since we have set repeat to something other than 0, we should get an error sl@0: TEST2(res, KErrArgument); sl@0: User::LeaveIfError(TheScheduler.__DbgMarkEnd(0)); sl@0: CleanupStack::PopAndDestroy(); // data sl@0: } sl@0: sl@0: SchSvrHelpers::Pause(TheTest); sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-3227 sl@0: @SYMTestCaseDesc Persistent condition based schedule test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Create a single persistent condition based schedule and then sl@0: terminate the task scheduler. sl@0: Set the condition and then launch the task scheduler with the sl@0: condition satisfied. Check that the schedule is executed. sl@0: @SYMTestExpectedResults Schedule must be executed and test must not panic or fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: static void DoTest4L() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3227 ")); sl@0: // create a persistent condition based schedule sl@0: TInt res = KErrNone; sl@0: TheTest.Next(_L("single condition based test")); sl@0: __UHEAP_MARK; sl@0: sl@0: //reset the p&s variables before creating the schedule sl@0: ResetVariablesL(0,0,0); sl@0: TSchedulerItemRef ref1; sl@0: TheTest.Printf(_L("Create a test schedule\n")); sl@0: res = CreateScheduleSingle1L(ref1, TheScheduler, KUidSystemCategory, KTestKey1); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt task1 = 0; sl@0: _LIT(KName1, "shutdown task 1"); sl@0: TheTest.Printf(_L("Schedule a persistant task\n")); sl@0: sl@0: res = SchedulePersistentTaskL(KName1, task1, ref1.iHandle, TheScheduler); sl@0: TEST2(res, KErrNone); sl@0: sl@0: //Fault the server to force it to shut down sl@0: TheScheduler.__FaultServer(); sl@0: sl@0: //close the Scheduler handle sl@0: TheScheduler.Close(); sl@0: sl@0: SchSvrHelpers::Pause(TheTest); sl@0: sl@0: // set condition sl@0: res = RProperty::Set(KUidSystemCategory, KTestKey1,10); sl@0: TEST2(res, KErrNone); sl@0: sl@0: //Restart the scheduler with the condition for this persistant task sl@0: //satisfied sl@0: res = TheScheduler.Connect(); sl@0: TEST2(res, KErrNone); sl@0: sl@0: //wait for task to be executed sl@0: TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone); sl@0: CleanupHelpers::KillProcess(KMinimalTaskHandler); sl@0: sl@0: SchSvrHelpers::Pause(TheTest); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: } sl@0: sl@0: static TInt RunTestsL() sl@0: { sl@0: TheTest.Next(_L("Delete old files")); sl@0: SchSvrHelpers::DeleteScheduleFilesL(); sl@0: sl@0: TheTest.Next(_L("Create Task notification semaphore")); sl@0: //initialise task notification semaphore sl@0: STaskSemaphore sem; sl@0: sem.CreateL(); sl@0: sl@0: // Connect to the server sl@0: TheTest.Next(_L("===== Connect to Scheduler =====")); sl@0: TInt res = TheScheduler.Connect(); sl@0: TEST2(res, KErrNone); sl@0: // Register a client with the server sl@0: TheTest.Next(_L("===== Registering Client =====")); sl@0: res = SchSvrHelpers::RegisterClientL(TheScheduler); sl@0: TEST2(res, KErrNone); sl@0: sl@0: // Launch helper process to create P&S variables sl@0: CreateTestVariables(); sl@0: sl@0: CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); sl@0: CleanupStack::PushL(scheduler); sl@0: CActiveScheduler::Install(scheduler); sl@0: sl@0: TheTest.Next(_L("Start tests")); sl@0: DoTest1L(); sl@0: DoTest2L(); sl@0: DoTest3L(); sl@0: DoTest4L(); sl@0: sl@0: TheTest.Next(_L("Tidying up")); sl@0: CleanupStack::PopAndDestroy(scheduler); sl@0: //close handle to semaphore sl@0: sem.Close(); sl@0: sl@0: //Tidying up so next test will be clear. sl@0: TheTest.Next(_L("Delete all schedules")); sl@0: SchSvrHelpers::DeleteAllSchedulesL(TheScheduler); sl@0: SchSvrHelpers::Pause(TheTest, 2); sl@0: TheTest.Next(_L("Delete old files\n")); sl@0: SchSvrHelpers::DeleteScheduleFilesL(); sl@0: sl@0: TheScheduler.Close(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: TheTest.Start(_L("TC_TSCH_CONDITION")); sl@0: TheTest.Title(); sl@0: TheCleanup = CTrapCleanup::New(); sl@0: sl@0: //If the previous test fails, SCHSVR.exe may stay in memory. sl@0: TRAPD(error,CleanupHelpers::TestCleanupL()); sl@0: TEST2(error, KErrNone); sl@0: TheTest(TheFsSession.Connect() == KErrNone);; sl@0: TRAP(error, RunTestsL()); sl@0: TEST2(error, KErrNone); sl@0: TRAP(error,CleanupHelpers::TestCleanupL()); sl@0: TEST2(error, KErrNone); sl@0: delete TheCleanup; sl@0: sl@0: TheFsSession.Close(); sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: __UHEAP_MARKEND; sl@0: sl@0: return KErrNone; sl@0: }