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: // tschsvrsclient1.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include "Thelpers.h" sl@0: #include "TestUtils.h" sl@0: sl@0: _LIT(KTestName, "Client with different UID test"); sl@0: RTest TheTest(KTestName); sl@0: static RScheduler TheScheduler; sl@0: sl@0: sl@0: typedef CArrayFixFlat CSchEntryInfoArray; sl@0: typedef CArrayFixFlat CTaskInfoArray; sl@0: typedef CArrayFixFlat CSchItemRefArray; sl@0: typedef CArrayFixFlat CSchConditionArray; sl@0: sl@0: sl@0: static CSchEntryInfoArray* CreateScheduleArrayLC() sl@0: { sl@0: CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3); sl@0: CleanupStack::PushL(entryList); sl@0: sl@0: TScheduleEntryInfo entry1; sl@0: entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 20); // 20m from "now" sl@0: entry1.iInterval = 1; sl@0: entry1.iIntervalType = EDaily; sl@0: entry1.iValidityPeriod = 20; sl@0: entryList->AppendL(entry1); sl@0: sl@0: return entryList; sl@0: } sl@0: sl@0: static CSchConditionArray* CreateSingleConditionLC() sl@0: { sl@0: CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3); sl@0: CleanupStack::PushL(conditionList); sl@0: sl@0: const TUid KTestUid = TUid::Uid(0x12345678); sl@0: sl@0: TTaskSchedulerCondition condition1; sl@0: condition1.iCategory = KTestUid; sl@0: condition1.iKey = 1; 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: @SYMTestCaseID SYSLIB-SCHSVR-CT-1343 sl@0: @SYMTestCaseDesc Client with different UID test sl@0: @SYMTestPriority High sl@0: @SYMTestActions Connect to Scheduler, sl@0: Tests RScheduler::EditSchedule(),RScheduler::DisableSchedule(),RScheduler::EnableSchedule() sl@0: RScheduler::ScheduleTask(),RScheduler::GetScheduleRefsL(),RScheduler::GetScheduleL(), sl@0: RScheduler::GetTaskRefsL(),RScheduler::GetTaskDataSize(),RScheduler::GetTaskInfoL(), sl@0: RScheduler::GetScheduleTypeL(),RScheduler::DeleteTask(),RScheduler::DeleteSchedule() functions sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void DoExecuteL(TInt aScheduleHandle, sl@0: TInt aTaskHandle, sl@0: TInt aExpectedError, sl@0: TInt aExpectedScheduleCount, sl@0: TInt aExpectedTaskCount) sl@0: { sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1343 Connect to Scheduler ")); sl@0: TInt res = TheScheduler.Connect(); sl@0: TEST2(res, KErrNone); sl@0: TheTest.Next(_L("Registering Client")); sl@0: TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone); sl@0: sl@0: //Edit Schedule sl@0: TheTest.Next(_L("Testing EditSchedule")); sl@0: CSchEntryInfoArray* scheduleArray = CreateScheduleArrayLC(); sl@0: res = TheScheduler.EditSchedule(aScheduleHandle, *scheduleArray); sl@0: CleanupStack::PopAndDestroy(); //scheduleArray sl@0: TEST2(res, aExpectedError); sl@0: //condition API - only check if we are expecting an error sl@0: if(aExpectedError != KErrNone) sl@0: { sl@0: CSchConditionArray* conditionList = CreateSingleConditionLC(); sl@0: TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future sl@0: res = TheScheduler.EditSchedule(aScheduleHandle, *conditionList, time); sl@0: CleanupStack::PopAndDestroy(); // conditionList sl@0: TEST2(res, aExpectedError); sl@0: } sl@0: //Disable/Enable Schedule sl@0: TheTest.Next(_L("Testing DisableSchedule and EnableSchedule")); sl@0: res = TheScheduler.DisableSchedule(aScheduleHandle); sl@0: TEST2(res, aExpectedError); sl@0: res = TheScheduler.EnableSchedule(aScheduleHandle); sl@0: TEST2(res, aExpectedError); sl@0: sl@0: //ScheduleTask sl@0: TheTest.Next(_L("Testing ScheduleTask")); sl@0: TTaskInfo taskInfo; sl@0: taskInfo.iName = _L("MyTask"); sl@0: taskInfo.iPriority = 2; sl@0: taskInfo.iTaskId = 0; sl@0: taskInfo.iRepeat = 1; sl@0: HBufC* data = _L("Task Data I cant schedule").AllocLC(); sl@0: res = TheScheduler.ScheduleTask(taskInfo, *data, aScheduleHandle); sl@0: TEST2(res, aExpectedError); sl@0: CleanupStack::PopAndDestroy(); // data sl@0: sl@0: if(res == KErrNone) sl@0: { sl@0: res = TheScheduler.DeleteTask(taskInfo.iTaskId); sl@0: TEST2(res, KErrNone); sl@0: } sl@0: sl@0: //GetScheduleRefs sl@0: TheTest.Next(_L("Testing GetScheduleRefsL")); sl@0: CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3); sl@0: CleanupStack::PushL(refs); sl@0: res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules); sl@0: TEST2(res, KErrNone); sl@0: TInt count = refs->Count(); sl@0: TEST2(count, aExpectedScheduleCount); sl@0: sl@0: //GetSchedule sl@0: TheTest.Next(_L("Testing GetScheduleL")); sl@0: CSchEntryInfoArray* entries = new (ELeave) CSchEntryInfoArray(3); sl@0: CleanupStack::PushL(entries); sl@0: CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3); sl@0: CleanupStack::PushL(tasks); sl@0: sl@0: TTime nextTimeScheduleIsDue; sl@0: TScheduleState state; sl@0: res = TheScheduler.GetScheduleL(aScheduleHandle, sl@0: state, sl@0: *entries, sl@0: *tasks, sl@0: nextTimeScheduleIsDue); sl@0: TEST2(res, aExpectedError); sl@0: //condition API - only check if we are expecting an error sl@0: if(aExpectedError != KErrNone) sl@0: { sl@0: CSchConditionArray* conditions = new (ELeave) CSchConditionArray(3); sl@0: CleanupStack::PushL(conditions); sl@0: res = TheScheduler.GetScheduleL(aScheduleHandle, sl@0: state, sl@0: *conditions, sl@0: nextTimeScheduleIsDue, sl@0: *tasks); sl@0: CleanupStack::PopAndDestroy(conditions); sl@0: TEST2(res, aExpectedError); sl@0: } sl@0: sl@0: //GetTaskRefs sl@0: TheTest.Next(_L("Testing GetScheduleL")); sl@0: res = TheScheduler.GetTaskRefsL(*refs, EAllSchedules, EAllTasks); sl@0: TEST2(res, KErrNone); sl@0: count = refs->Count(); sl@0: TEST2(count, aExpectedTaskCount); sl@0: sl@0: // TaskDataSize sl@0: TheTest.Next(_L("Testing GetTaskDataSize")); sl@0: TInt taskSize = 0; sl@0: res = TheScheduler.GetTaskDataSize(aTaskHandle, taskSize); sl@0: TEST2(res, aExpectedError); sl@0: sl@0: // GetTaskInfo sl@0: TheTest.Next(_L("Testing GetTaskInfoL")); sl@0: if(aExpectedError != KErrNone) sl@0: //use dummy size for task as we actually didnt get it from above sl@0: // if we were expected as error sl@0: taskSize = 10; sl@0: HBufC* taskData = HBufC::NewLC(taskSize); sl@0: TPtr pTaskData = taskData->Des(); sl@0: sl@0: TTime scheduleNextDueTime; sl@0: TTaskInfo taskFromServer; sl@0: TSchedulerItemRef scheduleReference; sl@0: sl@0: res = TheScheduler.GetTaskInfoL(aTaskHandle, sl@0: taskFromServer, sl@0: pTaskData, sl@0: scheduleReference, sl@0: scheduleNextDueTime); sl@0: CleanupStack::PopAndDestroy(taskData); sl@0: TEST2(res, aExpectedError); sl@0: sl@0: TScheduleType scheduleType; sl@0: res = TheScheduler.GetScheduleTypeL(aScheduleHandle, scheduleType); sl@0: TEST2(res, aExpectedError); sl@0: sl@0: //DeleteTask sl@0: TheTest.Next(_L("Testing TaskSchedule")); sl@0: res = TheScheduler.DeleteTask(aTaskHandle); sl@0: TEST2(res, aExpectedError); sl@0: sl@0: //Delete Schedule sl@0: TheTest.Next(_L("Testing DeleteSchedule")); sl@0: res = TheScheduler.DeleteSchedule(aScheduleHandle); sl@0: TEST2(res, aExpectedError); sl@0: sl@0: CleanupStack::PopAndDestroy(tasks); sl@0: CleanupStack::PopAndDestroy(entries); sl@0: CleanupStack::PopAndDestroy(refs); sl@0: sl@0: TheScheduler.Close(); sl@0: sl@0: } sl@0: sl@0: LOCAL_D TInt Execute(TInt aScheduleHandle, sl@0: TInt aTaskHandle, sl@0: TInt aExpectedError, sl@0: TInt aExpectedScheduleCount, sl@0: TInt aExpectedTaskCount) sl@0: { sl@0: TInt err = KErrNoMemory; sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail sl@0: if (cleanup) sl@0: { sl@0: sl@0: TheTest.Start(_L("TSchSvrClient")); sl@0: TheTest.Title(); sl@0: err = KErrNone; sl@0: TRAP(err, DoExecuteL(aScheduleHandle, sl@0: aTaskHandle, sl@0: aExpectedError, sl@0: aExpectedScheduleCount, sl@0: aExpectedTaskCount)) sl@0: delete cleanup; sl@0: sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: sl@0: //*********************************************************************************** sl@0: static TInt Str2Int(const TDesC& aStr) sl@0: { sl@0: TLex16 lex(aStr); sl@0: TInt val = 0; sl@0: lex.Val(val); sl@0: return val; sl@0: } sl@0: sl@0: static TBuf<20> ExtractInt(const TDesC& aBuf, TInt& aExtractedInt) sl@0: { sl@0: TBuf<20> buf = aBuf.Right(aBuf.Length() - aBuf.Locate(':')-1); sl@0: TBuf<5> handle; sl@0: handle.FillZ(); sl@0: handle = buf.Left(buf.Locate(':')); sl@0: aExtractedInt = Str2Int(handle); sl@0: return buf; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: TBuf<30> cmd; sl@0: User::CommandLine(cmd); sl@0: // schedule Handle is first sl@0: TInt scheduleHandle=0, taskHandle=0, errCode=0, schCount=0, taskCount=0; sl@0: cmd = ExtractInt(cmd, scheduleHandle); sl@0: // task Handle is second sl@0: cmd = ExtractInt(cmd, taskHandle); sl@0: // expected error code is third sl@0: cmd = ExtractInt(cmd, errCode); sl@0: // expected schedule count (based on this exe UID/Capability is fourth sl@0: cmd = ExtractInt(cmd, schCount); sl@0: // expected task count (based on this exe UID/Capability is fourth sl@0: cmd = ExtractInt(cmd, taskCount); sl@0: sl@0: return Execute(scheduleHandle, taskHandle, errCode, schCount, taskCount); sl@0: } sl@0: sl@0: