|
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 // |
|
15 |
|
16 #include <csch_cli.h> |
|
17 #include "Thelpers.h" |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32test.h> |
|
21 #include <f32file.h> |
|
22 #include <s32file.h> |
|
23 #include <e32property.h> |
|
24 #include <schinfointernal.h> |
|
25 #include "TestUtils.h" |
|
26 |
|
27 // |
|
28 // Literal constants |
|
29 // |
|
30 _LIT(KTestName, "TC_TSCH_SCHSVR_OOM_HOMETIME"); |
|
31 |
|
32 |
|
33 // |
|
34 // Type definitions |
|
35 // |
|
36 typedef CArrayFixFlat<TScheduleEntryInfo2> CSchEntryInfoArray; |
|
37 typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray; |
|
38 typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray; |
|
39 typedef CArrayFixFlat<TTaskSchedulerCondition> CSchConditionArray; |
|
40 |
|
41 // |
|
42 // Global data |
|
43 // |
|
44 RTest TheTest(KTestName); |
|
45 static RScheduler TheScheduler; |
|
46 static CTrapCleanup* TheCleanup; |
|
47 static RFs TheFsSession; |
|
48 |
|
49 const TUid KTestUid = TUid::Uid(0x12345678); |
|
50 const TInt KTestKey1 = 1; |
|
51 |
|
52 |
|
53 //*********************************************************************************** |
|
54 static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray, |
|
55 TInt aScheduleId) |
|
56 // Extract schedule references from the schedule server based on a filter. If |
|
57 { |
|
58 aTaskInfoArray.Reset(); |
|
59 TTsTime nextTimeScheduleIsDue; |
|
60 TScheduleState2 state; |
|
61 CSchEntryInfoArray* entries |
|
62 = new (ELeave) CSchEntryInfoArray(3); |
|
63 CleanupStack::PushL(entries); |
|
64 TInt res = TheScheduler.GetScheduleL(aScheduleId, |
|
65 state, |
|
66 *entries, |
|
67 aTaskInfoArray, |
|
68 nextTimeScheduleIsDue); |
|
69 TEST2(res, KErrNone); |
|
70 CleanupStack::PopAndDestroy(entries); |
|
71 } |
|
72 |
|
73 //*********************************************************************************** |
|
74 static TInt CountTasksL(TInt aScheduleId) |
|
75 { |
|
76 CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3); |
|
77 CleanupStack::PushL(tasks); |
|
78 GetTaskInfoL(*tasks, aScheduleId); |
|
79 TInt ret = tasks->Count(); |
|
80 CleanupStack::PopAndDestroy(tasks); |
|
81 return ret; |
|
82 } |
|
83 |
|
84 //*********************************************************************************** |
|
85 static TInt CountScheduledItemsL(TScheduleFilter aFilter, |
|
86 RScheduler& aScheduler) |
|
87 // Extract schedule references from the schedule server based on a filter. If |
|
88 { |
|
89 CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3); |
|
90 CleanupStack::PushL(refs); |
|
91 |
|
92 TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter); |
|
93 TEST2(res, KErrNone); |
|
94 |
|
95 TInt count = refs->Count(); |
|
96 CleanupStack::PopAndDestroy(); // refs |
|
97 return count; |
|
98 } |
|
99 |
|
100 |
|
101 //*********************************************************************************** |
|
102 static CSchEntryInfoArray* CreateScheduleArrayLC() |
|
103 { |
|
104 CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3); |
|
105 CleanupStack::PushL(entryList); |
|
106 |
|
107 TTime ttime(SchSvrHelpers::TimeBasedOnOffset(0, 20)); |
|
108 TTsTime startTime (ttime, EFalse); |
|
109 TScheduleEntryInfo2 entry1 (startTime, EDaily, 1, 20); // 20m from "now" |
|
110 entryList->AppendL(entry1); |
|
111 |
|
112 return entryList; |
|
113 } |
|
114 |
|
115 //*********************************************************************************** |
|
116 static CSchConditionArray* CreateConditionArrayLC() |
|
117 { |
|
118 CSchConditionArray* conditionList = new (ELeave) CSchConditionArray(3); |
|
119 CleanupStack::PushL(conditionList); |
|
120 |
|
121 TTaskSchedulerCondition condition1; |
|
122 condition1.iCategory = KTestUid; |
|
123 condition1.iKey = KTestKey1; |
|
124 condition1.iState = 10; |
|
125 condition1.iType = TTaskSchedulerCondition::EEquals; |
|
126 conditionList->AppendL(condition1); |
|
127 |
|
128 return conditionList; |
|
129 } |
|
130 |
|
131 //*********************************************************************************** |
|
132 |
|
133 /** |
|
134 @file |
|
135 @SYMTestCaseID SYSLIB-SCHSVR-CT-0247 |
|
136 @SYMTestCaseDesc OOM test for time-based schedules - Hometime |
|
137 @SYMTestPriority High |
|
138 @SYMTestActions OOM test for time-based schedules |
|
139 @SYMTestExpectedResults The test must not fail. |
|
140 @SYMPREQ PREQ234 |
|
141 */ |
|
142 static void DoTest1L() |
|
143 // Time based API's |
|
144 { |
|
145 |
|
146 TInt err = KErrNone; |
|
147 TInt tryCount = 0; |
|
148 |
|
149 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0247 ===== Starting OOM test =====")); |
|
150 |
|
151 CSchEntryInfoArray* scheduleArray = CreateScheduleArrayLC(); |
|
152 TSchedulerItemRef ref1; |
|
153 |
|
154 TheTest.Next(_L("===== Testing create persistent schedule =====")); |
|
155 for (tryCount = 0; ;++tryCount) |
|
156 { |
|
157 // These allocations are ignored because they cause corruptness |
|
158 // of the persistent store. Its a bit rubbish. |
|
159 if(tryCount < 7 || tryCount >8 ) |
|
160 { |
|
161 TheScheduler.__DbgFailNext(tryCount); |
|
162 TheScheduler.__DbgMarkHeap(); |
|
163 err = TheScheduler.CreatePersistentSchedule(ref1, *scheduleArray); |
|
164 if (err==KErrNone) |
|
165 { |
|
166 TheScheduler.__DbgResetHeap(); |
|
167 break; |
|
168 } |
|
169 TEST2(err, KErrNoMemory); |
|
170 // reset server side heap for next iteration. |
|
171 TheScheduler.__DbgMarkEnd(0); |
|
172 } |
|
173 } |
|
174 // Check schedule count |
|
175 TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
176 TEST(scheduleCount == 1); |
|
177 |
|
178 // OK, now we have a persistent schedule |
|
179 TheTest.Next(_L("===== Testing disable schedule =====")); |
|
180 for (tryCount = 0; ;++tryCount) |
|
181 { |
|
182 TheScheduler.__DbgFailNext(tryCount); |
|
183 TheScheduler.__DbgMarkHeap(); |
|
184 err = TheScheduler.DisableSchedule(ref1.iHandle); |
|
185 if (err==KErrNone) |
|
186 { |
|
187 TheScheduler.__DbgResetHeap(); |
|
188 break; |
|
189 } |
|
190 TEST2(err, KErrNoMemory); |
|
191 // reset server side heap for next iteration. |
|
192 TheScheduler.__DbgMarkEnd(0); |
|
193 } |
|
194 // Check schedule count |
|
195 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
196 TEST(scheduleCount == 1); |
|
197 |
|
198 TheTest.Next(_L("===== Testing enable schedule =====")); |
|
199 for (tryCount = 0; ;++tryCount) |
|
200 { |
|
201 TheScheduler.__DbgFailNext(tryCount); |
|
202 TheScheduler.__DbgMarkHeap(); |
|
203 err = TheScheduler.EnableSchedule(ref1.iHandle); |
|
204 if (err==KErrNone) |
|
205 { |
|
206 TheScheduler.__DbgResetHeap(); |
|
207 break; |
|
208 } |
|
209 TEST2(err, KErrNoMemory); |
|
210 // reset server side heap for next iteration. |
|
211 TheScheduler.__DbgMarkEnd(0); |
|
212 } |
|
213 // Check schedule count |
|
214 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
215 TEST(scheduleCount == 1); |
|
216 |
|
217 TheTest.Next(_L("===== Testing edit schedule =====")); |
|
218 for (tryCount = 0; ;++tryCount) |
|
219 { |
|
220 TheScheduler.__DbgFailNext(tryCount); |
|
221 TheScheduler.__DbgMarkHeap(); |
|
222 // Even though we use the same array as before, the task scheduler |
|
223 // code is not smart enough to just return but actually replaces |
|
224 // the existing one, hence we are actually testing this method fully. |
|
225 err = TheScheduler.EditSchedule(ref1.iHandle, *scheduleArray); |
|
226 if (err==KErrNone) |
|
227 { |
|
228 TheScheduler.__DbgResetHeap(); |
|
229 break; |
|
230 } |
|
231 TEST2(err, KErrNoMemory); |
|
232 // reset server side heap for next iteration. |
|
233 TheScheduler.__DbgMarkEnd(0); |
|
234 } |
|
235 // Check schedule count |
|
236 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
237 TEST(scheduleCount == 1); |
|
238 |
|
239 TheTest.Next(_L("===== Testing delete schedule =====")); |
|
240 for (tryCount = 0; ;++tryCount) |
|
241 { |
|
242 TheScheduler.__DbgFailNext(tryCount); |
|
243 TheScheduler.__DbgMarkHeap(); |
|
244 err = TheScheduler.DeleteSchedule(ref1.iHandle); |
|
245 if (err==KErrNone) |
|
246 { |
|
247 TheScheduler.__DbgResetHeap(); |
|
248 break; |
|
249 } |
|
250 TEST2(err, KErrNoMemory); |
|
251 // reset server side heap for next iteration. |
|
252 TheScheduler.__DbgMarkEnd(0); |
|
253 } |
|
254 // Check schedule count |
|
255 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
256 TEST(scheduleCount == 0); |
|
257 |
|
258 // delete old files. |
|
259 // We need to do this because we have actually corrupted the store, |
|
260 // even though its empty. Without deleting it we get problems below. |
|
261 // This is a bit rubbish having to do this but what else can be done?? |
|
262 TheTest.Next(_L("Delete old files")); |
|
263 SchSvrHelpers::DeleteScheduleFilesL(); |
|
264 |
|
265 // OK now add back schedule in preparation for adding tasks. |
|
266 err = TheScheduler.CreatePersistentSchedule(ref1, *scheduleArray); |
|
267 TEST2(err, KErrNone); |
|
268 |
|
269 TheTest.Next(_L("===== Testing ScheduleTask =====")); |
|
270 |
|
271 _LIT(KTaskName, "TheTaskName"); |
|
272 TName name = KTaskName(); |
|
273 TTaskInfo taskInfo(0, name, 2, 0); |
|
274 |
|
275 HBufC* data = _L("the data").AllocLC(); |
|
276 // cant test ScheduleTask API using OOM loop as it does dodgy things to |
|
277 // the store which cause allocation problems. Need to investigate this |
|
278 // later at some stage. |
|
279 TEST2(TheScheduler.ScheduleTask(taskInfo, *data, ref1.iHandle), KErrNone); |
|
280 |
|
281 // Check schedule and task count |
|
282 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
283 TEST(scheduleCount == 1); |
|
284 TInt taskCount = CountTasksL(ref1.iHandle); |
|
285 TEST(taskCount = 1); |
|
286 |
|
287 TheTest.Next(_L("===== Testing GetScheduleRefsL =====")); |
|
288 |
|
289 CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3); |
|
290 CleanupStack::PushL(refs); |
|
291 for (tryCount = 0; ;++tryCount) |
|
292 { |
|
293 TheScheduler.__DbgFailNext(tryCount); |
|
294 TheScheduler.__DbgMarkHeap(); |
|
295 err = TheScheduler.GetScheduleRefsL(*refs, EPendingSchedules); |
|
296 if (err==KErrNone) |
|
297 { |
|
298 TheScheduler.__DbgResetHeap(); |
|
299 break; |
|
300 } |
|
301 TEST2(err, KErrNoMemory); |
|
302 // reset server side heap for next iteration. |
|
303 TheScheduler.__DbgMarkEnd(0); |
|
304 } |
|
305 // Check schedule and task count |
|
306 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
307 TEST(scheduleCount == 1); |
|
308 taskCount = CountTasksL(ref1.iHandle); |
|
309 TEST(taskCount = 1); |
|
310 |
|
311 TheTest.Next(_L("===== Testing GetScheduleL =====")); |
|
312 |
|
313 CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3); |
|
314 CleanupStack::PushL(tasks); |
|
315 TScheduleState2 state; |
|
316 TTsTime time; |
|
317 CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3); |
|
318 CleanupStack::PushL(entryList); |
|
319 for (tryCount = 0; ;++tryCount) |
|
320 { |
|
321 TheScheduler.__DbgFailNext(tryCount); |
|
322 TheScheduler.__DbgMarkHeap(); |
|
323 err = TheScheduler.GetScheduleL(ref1.iHandle, |
|
324 state, |
|
325 *entryList, |
|
326 *tasks, time); |
|
327 if (err==KErrNone) |
|
328 { |
|
329 TheScheduler.__DbgResetHeap(); |
|
330 break; |
|
331 } |
|
332 TEST2(err, KErrNoMemory); |
|
333 // reset server side heap for next iteration. |
|
334 TheScheduler.__DbgMarkEnd(0); |
|
335 } |
|
336 // Check schedule and task count |
|
337 TEST(entryList->Count() == 1); |
|
338 TEST(tasks->Count() == 1); |
|
339 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
340 TEST(scheduleCount == 1); |
|
341 taskCount = CountTasksL(ref1.iHandle); |
|
342 TEST(taskCount = 1); |
|
343 |
|
344 CleanupStack::PopAndDestroy(entryList); |
|
345 CleanupStack::PopAndDestroy(tasks); |
|
346 |
|
347 TheTest.Next(_L("===== Testing GetTaskRefsL =====")); |
|
348 |
|
349 for (tryCount = 0; ;++tryCount) |
|
350 { |
|
351 TheScheduler.__DbgFailNext(tryCount); |
|
352 TheScheduler.__DbgMarkHeap(); |
|
353 err = TheScheduler.GetTaskRefsL(*refs, |
|
354 EAllSchedules, |
|
355 EAllTasks); |
|
356 if (err==KErrNone) |
|
357 { |
|
358 TheScheduler.__DbgResetHeap(); |
|
359 break; |
|
360 } |
|
361 TEST2(err, KErrNoMemory); |
|
362 // reset server side heap for next iteration. |
|
363 TheScheduler.__DbgMarkEnd(0); |
|
364 } |
|
365 CleanupStack::PopAndDestroy(refs); |
|
366 |
|
367 TheTest.Next(_L("===== Testing GetTaskDataSize =====")); |
|
368 |
|
369 TInt size; |
|
370 for (tryCount = 0; ;++tryCount) |
|
371 { |
|
372 TheScheduler.__DbgFailNext(tryCount); |
|
373 TheScheduler.__DbgMarkHeap(); |
|
374 err = TheScheduler.GetTaskDataSize(ref1.iHandle, |
|
375 size); |
|
376 if (err==KErrNone) |
|
377 { |
|
378 TheScheduler.__DbgResetHeap(); |
|
379 break; |
|
380 } |
|
381 TEST2(err, KErrNoMemory); |
|
382 // reset server side heap for next iteration. |
|
383 TheScheduler.__DbgMarkEnd(0); |
|
384 } |
|
385 |
|
386 TheTest.Next(_L("===== Testing GetTaskInfoL =====")); |
|
387 |
|
388 HBufC* newData = HBufC::NewLC(size); |
|
389 TPtr pTaskData = newData->Des(); |
|
390 |
|
391 TTaskInfo newTaskInfo; |
|
392 for (tryCount = 0; ;++tryCount) |
|
393 { |
|
394 TheScheduler.__DbgFailNext(tryCount); |
|
395 TheScheduler.__DbgMarkHeap(); |
|
396 err = TheScheduler.GetTaskInfoL(taskInfo.iTaskId, |
|
397 newTaskInfo, |
|
398 pTaskData, |
|
399 ref1, |
|
400 time); |
|
401 if (err==KErrNone) |
|
402 { |
|
403 TheScheduler.__DbgResetHeap(); |
|
404 break; |
|
405 } |
|
406 TEST2(err, KErrNoMemory); |
|
407 // reset server side heap for next iteration. |
|
408 TheScheduler.__DbgMarkEnd(0); |
|
409 } |
|
410 TEST(newData->MatchF(*data) == 0); |
|
411 |
|
412 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
413 TEST(scheduleCount == 1); |
|
414 taskCount = CountTasksL(ref1.iHandle); |
|
415 TEST(taskCount = 1); |
|
416 |
|
417 CleanupStack::PopAndDestroy(newData); |
|
418 CleanupStack::PopAndDestroy(data); |
|
419 |
|
420 TheTest.Next(_L("===== Testing GetScheduleTypeL =====")); |
|
421 |
|
422 TScheduleType type; |
|
423 for (tryCount = 0; ;++tryCount) |
|
424 { |
|
425 TheScheduler.__DbgFailNext(tryCount); |
|
426 TheScheduler.__DbgMarkHeap(); |
|
427 err = TheScheduler.GetScheduleTypeL(ref1.iHandle, type); |
|
428 if (err==KErrNone) |
|
429 { |
|
430 TheScheduler.__DbgResetHeap(); |
|
431 break; |
|
432 } |
|
433 TEST2(err, KErrNoMemory); |
|
434 // reset server side heap for next iteration. |
|
435 TheScheduler.__DbgMarkEnd(0); |
|
436 } |
|
437 TEST(type == ETimeSchedule); |
|
438 |
|
439 CleanupStack::PopAndDestroy(scheduleArray); |
|
440 |
|
441 TheTest.Next(_L("===== Testing DeleteTask =====")); |
|
442 |
|
443 for (tryCount = 0; ;++tryCount) |
|
444 { |
|
445 TheScheduler.__DbgFailNext(tryCount); |
|
446 TheScheduler.__DbgMarkHeap(); |
|
447 err = TheScheduler.DeleteTask(taskInfo.iTaskId); |
|
448 //include test for KErrNotFound here as task is actually deleted and |
|
449 // then store is updated (which causes mem failure). Problems |
|
450 // will still occur if you add a new task again and try and access store |
|
451 // as store is likely to still be corrupt. Investigate this?? |
|
452 if (err==KErrNone || err==KErrNotFound) |
|
453 { |
|
454 TheScheduler.__DbgResetHeap(); |
|
455 break; |
|
456 } |
|
457 TEST2(err, KErrNoMemory); |
|
458 // reset server side heap for next iteration. |
|
459 TheScheduler.__DbgMarkEnd(0); |
|
460 } |
|
461 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
462 TEST(scheduleCount == 1); |
|
463 taskCount = CountTasksL(ref1.iHandle); |
|
464 TEST(taskCount == 0); |
|
465 |
|
466 //Now delete schedule to setup for next test |
|
467 TEST2(TheScheduler.DeleteSchedule(ref1.iHandle), KErrNone); |
|
468 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
469 TEST(scheduleCount == 0); |
|
470 |
|
471 SchSvrHelpers::Pause(TheTest); |
|
472 } |
|
473 |
|
474 |
|
475 //*********************************************************************************** |
|
476 |
|
477 /** |
|
478 @file |
|
479 @SYMTestCaseID SYSLIB-SCHSVR-CT-0248 |
|
480 @SYMTestCaseDesc OOM test for condition-based schedules - Hometime |
|
481 @SYMTestPriority High |
|
482 @SYMTestActions OOM test for condition-based schedules |
|
483 @SYMTestExpectedResults The test must not fail. |
|
484 @SYMPREQ PREQ234 |
|
485 */ |
|
486 static void DoTest2L() |
|
487 // Condition based API's |
|
488 { |
|
489 |
|
490 TInt err = KErrNone; |
|
491 TInt tryCount = 0; |
|
492 |
|
493 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0248 ===== Starting Condition OOM test ===== ")); |
|
494 |
|
495 // delete old files. |
|
496 // We need to do this because we have actually corrupted the store, |
|
497 // with the DeleteTask call. Without deleting it we get problems below. |
|
498 // This is a bit rubbish having to do this but what else can be done?? |
|
499 TheTest.Next(_L("Delete old files")); |
|
500 SchSvrHelpers::DeleteScheduleFilesL(); |
|
501 |
|
502 //Ensure P&S variables are defined. |
|
503 err = RProperty::Define(KTestUid, KTestKey1, RProperty::EInt); |
|
504 TEST(err == KErrNone || err == KErrAlreadyExists); |
|
505 TEST2(RProperty::Set(KTestUid, KTestKey1,1), KErrNone); |
|
506 |
|
507 CSchConditionArray* conditionArray = CreateConditionArrayLC(); |
|
508 TSchedulerItemRef ref1; |
|
509 |
|
510 TheTest.Next(_L("===== Testing create persistent schedule =====")); |
|
511 for (tryCount = 0; ;++tryCount) |
|
512 { |
|
513 TheScheduler.__DbgFailNext(tryCount); |
|
514 TheScheduler.__DbgMarkHeap(); |
|
515 err = TheScheduler.CreatePersistentSchedule(ref1, *conditionArray, Time::MaxTTime()); |
|
516 if (err==KErrNone) |
|
517 { |
|
518 TheScheduler.__DbgResetHeap(); |
|
519 break; |
|
520 } |
|
521 TEST2(err, KErrNoMemory); |
|
522 // reset server side heap for next iteration. |
|
523 TheScheduler.__DbgMarkEnd(0); |
|
524 } |
|
525 // Check schedule count |
|
526 TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
527 TEST(scheduleCount == 1); |
|
528 |
|
529 // This test code causes problems when EditSchedule fails, it deletes the entries |
|
530 // but doenst delete the actual CSchedule object. We can't do this really as the |
|
531 // schedule may have oustanding tasks. Need to clean up data in a consistent manner. |
|
532 // Fix this! Same applied for time based EditSchedule |
|
533 /* TheTest.Next(_L("===== Testing edit schedule =====")); |
|
534 for (tryCount = 0; ;++tryCount) |
|
535 { |
|
536 TheScheduler.__DbgFailNext(tryCount); |
|
537 TheScheduler.__DbgMarkHeap(); |
|
538 // Even though we use the same array as before, the task scheduler |
|
539 // code is not smart enough to just return but actually replaces |
|
540 // the existing one, hence we are actually testing this method fully. |
|
541 err = TheScheduler.EditSchedule(ref1.iHandle, *conditionArray, |
|
542 SchSvrHelpers::TimeBasedOnOffset(0, 20)); |
|
543 if (err==KErrNone) |
|
544 { |
|
545 TheScheduler.__DbgResetHeap(); |
|
546 break; |
|
547 } |
|
548 TEST2(err, KErrNoMemory); |
|
549 // reset server side heap for next iteration. |
|
550 TheScheduler.__DbgMarkEnd(0); |
|
551 } |
|
552 // Check schedule count |
|
553 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
554 TEST(scheduleCount == 1); |
|
555 */ |
|
556 TheTest.Next(_L("===== Testing GetScheduleL =====")); |
|
557 |
|
558 CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3); |
|
559 CleanupStack::PushL(tasks); |
|
560 TScheduleState2 state; |
|
561 TTsTime time; |
|
562 CSchConditionArray* entryList = new (ELeave) CSchConditionArray(3); |
|
563 CleanupStack::PushL(entryList); |
|
564 for (tryCount = 0; ;++tryCount) |
|
565 { |
|
566 TheScheduler.__DbgFailNext(tryCount); |
|
567 TheScheduler.__DbgMarkHeap(); |
|
568 err = TheScheduler.GetScheduleL(ref1.iHandle, |
|
569 state, |
|
570 *entryList, |
|
571 time, *tasks); |
|
572 if (err==KErrNone) |
|
573 { |
|
574 TheScheduler.__DbgResetHeap(); |
|
575 break; |
|
576 } |
|
577 TEST2(err, KErrNoMemory); |
|
578 // reset server side heap for next iteration. |
|
579 TheScheduler.__DbgMarkEnd(0); |
|
580 } |
|
581 CleanupStack::PopAndDestroy(entryList); |
|
582 CleanupStack::PopAndDestroy(tasks); |
|
583 |
|
584 TheTest.Next(_L("===== Testing delete schedule =====")); |
|
585 for (tryCount = 0; ;++tryCount) |
|
586 { |
|
587 TheScheduler.__DbgFailNext(tryCount); |
|
588 TheScheduler.__DbgMarkHeap(); |
|
589 err = TheScheduler.DeleteSchedule(ref1.iHandle); |
|
590 if (err==KErrNone) |
|
591 { |
|
592 TheScheduler.__DbgResetHeap(); |
|
593 break; |
|
594 } |
|
595 TEST2(err, KErrNoMemory); |
|
596 // reset server side heap for next iteration. |
|
597 TheScheduler.__DbgMarkEnd(0); |
|
598 } |
|
599 // Check schedule count |
|
600 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler); |
|
601 TEST(scheduleCount == 0); |
|
602 |
|
603 CleanupStack::PopAndDestroy(conditionArray); |
|
604 |
|
605 SchSvrHelpers::Pause(TheTest); |
|
606 } |
|
607 |
|
608 //*********************************************************************************** |
|
609 static TInt RunTestsL() |
|
610 { |
|
611 TheTest.Next(_L("Delete old files")); |
|
612 SchSvrHelpers::DeleteScheduleFilesL(); |
|
613 |
|
614 TheTest.Next(_L("Create Task notification semaphore")); |
|
615 //initialise task notification semaphore |
|
616 STaskSemaphore sem; |
|
617 sem.CreateL(); |
|
618 |
|
619 // Connect to the server |
|
620 TheTest.Next(_L("===== Connect to Scheduler =====")); |
|
621 TInt res = TheScheduler.Connect(); |
|
622 TEST2(res, KErrNone); |
|
623 // Register a client with the server |
|
624 TheTest.Next(_L("===== Registering Client =====")); |
|
625 res = SchSvrHelpers::RegisterClientL(TheScheduler); |
|
626 TEST2(res, KErrNone); |
|
627 |
|
628 TheTest.Next(_L("Start tests")); |
|
629 DoTest1L(); |
|
630 DoTest2L(); |
|
631 |
|
632 // Need to add OOM tests for when a task is executed |
|
633 // to clarify behaviour. This will be tricky!!! |
|
634 |
|
635 TheTest.Next(_L("Tidying up")); |
|
636 //Tidying up so next test will be clear. |
|
637 TheTest.Next(_L("Delete all schedules")); |
|
638 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler); |
|
639 SchSvrHelpers::Pause(TheTest, 2); |
|
640 TheTest.Next(_L("Delete old files\n")); |
|
641 SchSvrHelpers::DeleteScheduleFilesL(); |
|
642 |
|
643 TheScheduler.Close(); |
|
644 |
|
645 //close handle to semaphore |
|
646 sem.Close(); |
|
647 |
|
648 return KErrNone; |
|
649 } |
|
650 |
|
651 //*********************************************************************************** |
|
652 GLDEF_C TInt E32Main() |
|
653 // |
|
654 // TheTest the scheduler |
|
655 // |
|
656 { |
|
657 __UHEAP_MARK; |
|
658 TheTest.Start(_L("OOM testing - hometime")); |
|
659 TheTest.Title(); |
|
660 TheCleanup = CTrapCleanup::New(); |
|
661 |
|
662 //If the previous test fails, SCHSVR.exe may stay in memory. |
|
663 TRAPD(error,CleanupHelpers::TestCleanupL()); |
|
664 TEST2(error, KErrNone); |
|
665 |
|
666 TheTest(TheFsSession.Connect() == KErrNone);; |
|
667 TRAP(error, RunTestsL()); |
|
668 TEST2(error,KErrNone); |
|
669 TRAP(error,CleanupHelpers::TestCleanupL()); |
|
670 TEST2(error, KErrNone); |
|
671 delete TheCleanup; |
|
672 |
|
673 TheFsSession.Close(); |
|
674 TheTest.End(); |
|
675 TheTest.Close(); |
|
676 __UHEAP_MARKEND; |
|
677 return KErrNone; |
|
678 } |