Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // tschsvrsclient1.cpp
22 #include <schinfointernal.h>
24 #include "TestUtils.h"
26 _LIT(KTestName, "Client with different UID test");
27 RTest TheTest(KTestName);
28 static RScheduler TheScheduler;
31 typedef CArrayFixFlat<TScheduleEntryInfo> CSchEntryInfoArray;
32 typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
33 typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
34 typedef CArrayFixFlat<TTaskSchedulerCondition> CSchConditionArray;
37 static CSchEntryInfoArray* CreateScheduleArrayLC()
39 CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
40 CleanupStack::PushL(entryList);
42 TScheduleEntryInfo entry1;
43 entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 20); // 20m from "now"
45 entry1.iIntervalType = EDaily;
46 entry1.iValidityPeriod = 20;
47 entryList->AppendL(entry1);
52 static CSchConditionArray* CreateSingleConditionLC()
54 CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3);
55 CleanupStack::PushL(conditionList);
57 const TUid KTestUid = TUid::Uid(0x12345678);
59 TTaskSchedulerCondition condition1;
60 condition1.iCategory = KTestUid;
62 condition1.iState = 10;
63 condition1.iType = TTaskSchedulerCondition::EEquals;
64 conditionList->AppendL(condition1);
69 @SYMTestCaseID SYSLIB-SCHSVR-CT-1343
70 @SYMTestCaseDesc Client with different UID test
72 @SYMTestActions Connect to Scheduler,
73 Tests RScheduler::EditSchedule(),RScheduler::DisableSchedule(),RScheduler::EnableSchedule()
74 RScheduler::ScheduleTask(),RScheduler::GetScheduleRefsL(),RScheduler::GetScheduleL(),
75 RScheduler::GetTaskRefsL(),RScheduler::GetTaskDataSize(),RScheduler::GetTaskInfoL(),
76 RScheduler::GetScheduleTypeL(),RScheduler::DeleteTask(),RScheduler::DeleteSchedule() functions
77 @SYMTestExpectedResults Test must not fail
80 void DoExecuteL(TInt aScheduleHandle,
83 TInt aExpectedScheduleCount,
84 TInt aExpectedTaskCount)
87 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1343 Connect to Scheduler "));
88 TInt res = TheScheduler.Connect();
90 TheTest.Next(_L("Registering Client"));
91 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
94 TheTest.Next(_L("Testing EditSchedule"));
95 CSchEntryInfoArray* scheduleArray = CreateScheduleArrayLC();
96 res = TheScheduler.EditSchedule(aScheduleHandle, *scheduleArray);
97 CleanupStack::PopAndDestroy(); //scheduleArray
98 TEST2(res, aExpectedError);
99 //condition API - only check if we are expecting an error
100 if(aExpectedError != KErrNone)
102 CSchConditionArray* conditionList = CreateSingleConditionLC();
103 TTime time = SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, 1); //1 year in the future
104 res = TheScheduler.EditSchedule(aScheduleHandle, *conditionList, time);
105 CleanupStack::PopAndDestroy(); // conditionList
106 TEST2(res, aExpectedError);
108 //Disable/Enable Schedule
109 TheTest.Next(_L("Testing DisableSchedule and EnableSchedule"));
110 res = TheScheduler.DisableSchedule(aScheduleHandle);
111 TEST2(res, aExpectedError);
112 res = TheScheduler.EnableSchedule(aScheduleHandle);
113 TEST2(res, aExpectedError);
116 TheTest.Next(_L("Testing ScheduleTask"));
118 taskInfo.iName = _L("MyTask");
119 taskInfo.iPriority = 2;
120 taskInfo.iTaskId = 0;
121 taskInfo.iRepeat = 1;
122 HBufC* data = _L("Task Data I cant schedule").AllocLC();
123 res = TheScheduler.ScheduleTask(taskInfo, *data, aScheduleHandle);
124 TEST2(res, aExpectedError);
125 CleanupStack::PopAndDestroy(); // data
129 res = TheScheduler.DeleteTask(taskInfo.iTaskId);
130 TEST2(res, KErrNone);
134 TheTest.Next(_L("Testing GetScheduleRefsL"));
135 CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
136 CleanupStack::PushL(refs);
137 res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
138 TEST2(res, KErrNone);
139 TInt count = refs->Count();
140 TEST2(count, aExpectedScheduleCount);
143 TheTest.Next(_L("Testing GetScheduleL"));
144 CSchEntryInfoArray* entries = new (ELeave) CSchEntryInfoArray(3);
145 CleanupStack::PushL(entries);
146 CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
147 CleanupStack::PushL(tasks);
149 TTime nextTimeScheduleIsDue;
150 TScheduleState state;
151 res = TheScheduler.GetScheduleL(aScheduleHandle,
155 nextTimeScheduleIsDue);
156 TEST2(res, aExpectedError);
157 //condition API - only check if we are expecting an error
158 if(aExpectedError != KErrNone)
160 CSchConditionArray* conditions = new (ELeave) CSchConditionArray(3);
161 CleanupStack::PushL(conditions);
162 res = TheScheduler.GetScheduleL(aScheduleHandle,
165 nextTimeScheduleIsDue,
167 CleanupStack::PopAndDestroy(conditions);
168 TEST2(res, aExpectedError);
172 TheTest.Next(_L("Testing GetScheduleL"));
173 res = TheScheduler.GetTaskRefsL(*refs, EAllSchedules, EAllTasks);
174 TEST2(res, KErrNone);
175 count = refs->Count();
176 TEST2(count, aExpectedTaskCount);
179 TheTest.Next(_L("Testing GetTaskDataSize"));
181 res = TheScheduler.GetTaskDataSize(aTaskHandle, taskSize);
182 TEST2(res, aExpectedError);
185 TheTest.Next(_L("Testing GetTaskInfoL"));
186 if(aExpectedError != KErrNone)
187 //use dummy size for task as we actually didnt get it from above
188 // if we were expected as error
190 HBufC* taskData = HBufC::NewLC(taskSize);
191 TPtr pTaskData = taskData->Des();
193 TTime scheduleNextDueTime;
194 TTaskInfo taskFromServer;
195 TSchedulerItemRef scheduleReference;
197 res = TheScheduler.GetTaskInfoL(aTaskHandle,
201 scheduleNextDueTime);
202 CleanupStack::PopAndDestroy(taskData);
203 TEST2(res, aExpectedError);
205 TScheduleType scheduleType;
206 res = TheScheduler.GetScheduleTypeL(aScheduleHandle, scheduleType);
207 TEST2(res, aExpectedError);
210 TheTest.Next(_L("Testing TaskSchedule"));
211 res = TheScheduler.DeleteTask(aTaskHandle);
212 TEST2(res, aExpectedError);
215 TheTest.Next(_L("Testing DeleteSchedule"));
216 res = TheScheduler.DeleteSchedule(aScheduleHandle);
217 TEST2(res, aExpectedError);
219 CleanupStack::PopAndDestroy(tasks);
220 CleanupStack::PopAndDestroy(entries);
221 CleanupStack::PopAndDestroy(refs);
223 TheScheduler.Close();
227 LOCAL_D TInt Execute(TInt aScheduleHandle,
230 TInt aExpectedScheduleCount,
231 TInt aExpectedTaskCount)
233 TInt err = KErrNoMemory;
234 CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail
238 TheTest.Start(_L("TSchSvrClient"));
241 TRAP(err, DoExecuteL(aScheduleHandle,
244 aExpectedScheduleCount,
256 //***********************************************************************************
257 static TInt Str2Int(const TDesC& aStr)
265 static TBuf<20> ExtractInt(const TDesC& aBuf, TInt& aExtractedInt)
267 TBuf<20> buf = aBuf.Right(aBuf.Length() - aBuf.Locate(':')-1);
270 handle = buf.Left(buf.Locate(':'));
271 aExtractedInt = Str2Int(handle);
275 GLDEF_C TInt E32Main()
278 User::CommandLine(cmd);
279 // schedule Handle is first
280 TInt scheduleHandle=0, taskHandle=0, errCode=0, schCount=0, taskCount=0;
281 cmd = ExtractInt(cmd, scheduleHandle);
282 // task Handle is second
283 cmd = ExtractInt(cmd, taskHandle);
284 // expected error code is third
285 cmd = ExtractInt(cmd, errCode);
286 // expected schedule count (based on this exe UID/Capability is fourth
287 cmd = ExtractInt(cmd, schCount);
288 // expected task count (based on this exe UID/Capability is fourth
289 cmd = ExtractInt(cmd, taskCount);
291 return Execute(scheduleHandle, taskHandle, errCode, schCount, taskCount);