|
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 // tschsvrsclient1.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <e32debug.h> |
|
20 |
|
21 #include <csch_cli.h> |
|
22 #include <schinfointernal.h> |
|
23 #include "Thelpers.h" |
|
24 #include "TestUtils.h" |
|
25 |
|
26 _LIT(KTestName, "Client with different UID test"); |
|
27 RTest TheTest(KTestName); |
|
28 static RScheduler TheScheduler; |
|
29 |
|
30 |
|
31 typedef CArrayFixFlat<TScheduleEntryInfo> CSchEntryInfoArray; |
|
32 typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray; |
|
33 typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray; |
|
34 typedef CArrayFixFlat<TTaskSchedulerCondition> CSchConditionArray; |
|
35 |
|
36 |
|
37 static CSchEntryInfoArray* CreateScheduleArrayLC() |
|
38 { |
|
39 CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3); |
|
40 CleanupStack::PushL(entryList); |
|
41 |
|
42 TScheduleEntryInfo entry1; |
|
43 entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(0, 20); // 20m from "now" |
|
44 entry1.iInterval = 1; |
|
45 entry1.iIntervalType = EDaily; |
|
46 entry1.iValidityPeriod = 20; |
|
47 entryList->AppendL(entry1); |
|
48 |
|
49 return entryList; |
|
50 } |
|
51 |
|
52 static CSchConditionArray* CreateSingleConditionLC() |
|
53 { |
|
54 CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3); |
|
55 CleanupStack::PushL(conditionList); |
|
56 |
|
57 const TUid KTestUid = TUid::Uid(0x12345678); |
|
58 |
|
59 TTaskSchedulerCondition condition1; |
|
60 condition1.iCategory = KTestUid; |
|
61 condition1.iKey = 1; |
|
62 condition1.iState = 10; |
|
63 condition1.iType = TTaskSchedulerCondition::EEquals; |
|
64 conditionList->AppendL(condition1); |
|
65 |
|
66 return conditionList; |
|
67 } |
|
68 /** |
|
69 @SYMTestCaseID SYSLIB-SCHSVR-CT-1343 |
|
70 @SYMTestCaseDesc Client with different UID test |
|
71 @SYMTestPriority High |
|
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 |
|
78 @SYMREQ REQ0000 |
|
79 */ |
|
80 void DoExecuteL(TInt aScheduleHandle, |
|
81 TInt aTaskHandle, |
|
82 TInt aExpectedError, |
|
83 TInt aExpectedScheduleCount, |
|
84 TInt aExpectedTaskCount) |
|
85 { |
|
86 |
|
87 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-1343 Connect to Scheduler ")); |
|
88 TInt res = TheScheduler.Connect(); |
|
89 TEST2(res, KErrNone); |
|
90 TheTest.Next(_L("Registering Client")); |
|
91 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone); |
|
92 |
|
93 //Edit Schedule |
|
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) |
|
101 { |
|
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); |
|
107 } |
|
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); |
|
114 |
|
115 //ScheduleTask |
|
116 TheTest.Next(_L("Testing ScheduleTask")); |
|
117 TTaskInfo taskInfo; |
|
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 |
|
126 |
|
127 if(res == KErrNone) |
|
128 { |
|
129 res = TheScheduler.DeleteTask(taskInfo.iTaskId); |
|
130 TEST2(res, KErrNone); |
|
131 } |
|
132 |
|
133 //GetScheduleRefs |
|
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); |
|
141 |
|
142 //GetSchedule |
|
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); |
|
148 |
|
149 TTime nextTimeScheduleIsDue; |
|
150 TScheduleState state; |
|
151 res = TheScheduler.GetScheduleL(aScheduleHandle, |
|
152 state, |
|
153 *entries, |
|
154 *tasks, |
|
155 nextTimeScheduleIsDue); |
|
156 TEST2(res, aExpectedError); |
|
157 //condition API - only check if we are expecting an error |
|
158 if(aExpectedError != KErrNone) |
|
159 { |
|
160 CSchConditionArray* conditions = new (ELeave) CSchConditionArray(3); |
|
161 CleanupStack::PushL(conditions); |
|
162 res = TheScheduler.GetScheduleL(aScheduleHandle, |
|
163 state, |
|
164 *conditions, |
|
165 nextTimeScheduleIsDue, |
|
166 *tasks); |
|
167 CleanupStack::PopAndDestroy(conditions); |
|
168 TEST2(res, aExpectedError); |
|
169 } |
|
170 |
|
171 //GetTaskRefs |
|
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); |
|
177 |
|
178 // TaskDataSize |
|
179 TheTest.Next(_L("Testing GetTaskDataSize")); |
|
180 TInt taskSize = 0; |
|
181 res = TheScheduler.GetTaskDataSize(aTaskHandle, taskSize); |
|
182 TEST2(res, aExpectedError); |
|
183 |
|
184 // GetTaskInfo |
|
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 |
|
189 taskSize = 10; |
|
190 HBufC* taskData = HBufC::NewLC(taskSize); |
|
191 TPtr pTaskData = taskData->Des(); |
|
192 |
|
193 TTime scheduleNextDueTime; |
|
194 TTaskInfo taskFromServer; |
|
195 TSchedulerItemRef scheduleReference; |
|
196 |
|
197 res = TheScheduler.GetTaskInfoL(aTaskHandle, |
|
198 taskFromServer, |
|
199 pTaskData, |
|
200 scheduleReference, |
|
201 scheduleNextDueTime); |
|
202 CleanupStack::PopAndDestroy(taskData); |
|
203 TEST2(res, aExpectedError); |
|
204 |
|
205 TScheduleType scheduleType; |
|
206 res = TheScheduler.GetScheduleTypeL(aScheduleHandle, scheduleType); |
|
207 TEST2(res, aExpectedError); |
|
208 |
|
209 //DeleteTask |
|
210 TheTest.Next(_L("Testing TaskSchedule")); |
|
211 res = TheScheduler.DeleteTask(aTaskHandle); |
|
212 TEST2(res, aExpectedError); |
|
213 |
|
214 //Delete Schedule |
|
215 TheTest.Next(_L("Testing DeleteSchedule")); |
|
216 res = TheScheduler.DeleteSchedule(aScheduleHandle); |
|
217 TEST2(res, aExpectedError); |
|
218 |
|
219 CleanupStack::PopAndDestroy(tasks); |
|
220 CleanupStack::PopAndDestroy(entries); |
|
221 CleanupStack::PopAndDestroy(refs); |
|
222 |
|
223 TheScheduler.Close(); |
|
224 |
|
225 } |
|
226 |
|
227 LOCAL_D TInt Execute(TInt aScheduleHandle, |
|
228 TInt aTaskHandle, |
|
229 TInt aExpectedError, |
|
230 TInt aExpectedScheduleCount, |
|
231 TInt aExpectedTaskCount) |
|
232 { |
|
233 TInt err = KErrNoMemory; |
|
234 CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail |
|
235 if (cleanup) |
|
236 { |
|
237 |
|
238 TheTest.Start(_L("TSchSvrClient")); |
|
239 TheTest.Title(); |
|
240 err = KErrNone; |
|
241 TRAP(err, DoExecuteL(aScheduleHandle, |
|
242 aTaskHandle, |
|
243 aExpectedError, |
|
244 aExpectedScheduleCount, |
|
245 aExpectedTaskCount)) |
|
246 delete cleanup; |
|
247 |
|
248 TheTest.End(); |
|
249 TheTest.Close(); |
|
250 |
|
251 } |
|
252 return err; |
|
253 } |
|
254 |
|
255 |
|
256 //*********************************************************************************** |
|
257 static TInt Str2Int(const TDesC& aStr) |
|
258 { |
|
259 TLex16 lex(aStr); |
|
260 TInt val = 0; |
|
261 lex.Val(val); |
|
262 return val; |
|
263 } |
|
264 |
|
265 static TBuf<20> ExtractInt(const TDesC& aBuf, TInt& aExtractedInt) |
|
266 { |
|
267 TBuf<20> buf = aBuf.Right(aBuf.Length() - aBuf.Locate(':')-1); |
|
268 TBuf<5> handle; |
|
269 handle.FillZ(); |
|
270 handle = buf.Left(buf.Locate(':')); |
|
271 aExtractedInt = Str2Int(handle); |
|
272 return buf; |
|
273 } |
|
274 |
|
275 GLDEF_C TInt E32Main() |
|
276 { |
|
277 TBuf<30> cmd; |
|
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); |
|
290 |
|
291 return Execute(scheduleHandle, taskHandle, errCode, schCount, taskCount); |
|
292 } |
|
293 |
|
294 |