os/ossrv/genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING2_HOMETIME.cpp
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.
24 #include "TestUtils.h"
27 //If suddenly all SCHSVR tests begin failing, the OOM conditions might be the reason.
28 //TScheduling test tries to create KNumberOfSchedulesToCreate tasks, loading enormously
29 //the task scheduling server. The task scheduling server fails and stays loaded in memory
30 //with many scheduling tasks holding large amounts of allocated memory in this way.
31 //The next SCHSVR tests may fail because of OOM.
32 //KNumberOfSchedulesToCreate value was 100 originally. Now it is 20.
37 _LIT(KTestName, "TC_TSCH_SCHEDULING2 - Hometime");
42 typedef CArrayFixFlat<TScheduleEntryInfo2> CSchEntryInfoArray;
43 typedef CArrayFixFlat<TTaskInfo> CTaskInfoArray;
44 typedef CArrayFixFlat<TSchedulerItemRef> CSchItemRefArray;
49 RTest TheTest(KTestName);
50 static TInt64 TheSeed;
51 static RScheduler TheScheduler;
52 static CTrapCleanup* TheCleanup;
53 static RFs TheFsSession;
55 _LIT(KMinimalTaskHandler, "MinimalTaskHandler");
58 //***********************************************************************************
59 // Extract task info from the schedule server based on a schedule ID
60 static void GetTaskInfoL(CTaskInfoArray& aTaskInfoArray,
63 aTaskInfoArray.Reset();
64 TTsTime nextTimeScheduleIsDue;
65 TScheduleState2 state;
66 CSchEntryInfoArray* entries
67 = new (ELeave) CSchEntryInfoArray(3);
68 CleanupStack::PushL(entries);
69 TInt res = TheScheduler.GetScheduleL(aScheduleId,
73 nextTimeScheduleIsDue);
75 CleanupStack::PopAndDestroy(entries);
78 // count the number of tasks associated with this schedule
79 static TInt CountTasksL(TInt aScheduleId)
81 CTaskInfoArray* tasks = new (ELeave) CTaskInfoArray(3);
82 CleanupStack::PushL(tasks);
83 GetTaskInfoL(*tasks, aScheduleId);
84 TInt ret = tasks->Count();
85 CleanupStack::PopAndDestroy(tasks);
89 // count the number of schedules based on a filter.
90 static TInt CountScheduledItemsL(TScheduleFilter aFilter,
91 RScheduler& aScheduler)
93 CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
94 CleanupStack::PushL(refs);
96 TInt res = aScheduler.GetScheduleRefsL(*refs, aFilter);
99 TInt count = refs->Count();
100 CleanupStack::PopAndDestroy(); // refs
104 //creates a daily schedule with StartTime of aStartTime
105 static TInt CreateScheduleL(TSchedulerItemRef& aRef,
106 RScheduler& aScheduler,
107 const TTsTime& aStartTime)
109 CSchEntryInfoArray* entryList
110 = new (ELeave) CSchEntryInfoArray(1);
111 CleanupStack::PushL(entryList);
113 TScheduleEntryInfo2 entry1 (aStartTime, EDaily, 1, 30);
114 entryList->AppendL(entry1);
115 TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
116 CleanupStack::PopAndDestroy(); // entryList
120 // creates a schedule with numerous entries
121 static TInt CreateSchedule1L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
123 aRef.iName = _L("Schedule created using \"CreateSchedule1L\"");
125 CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
126 CleanupStack::PushL(entryList);
129 TTsTime startTime1(SchSvrHelpers::TimeBasedOnOffset(10, 0), EFalse); // 0m:10s from "now"
130 TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
131 entryList->AppendL(entry1);
134 TTsTime startTime2(SchSvrHelpers::TimeBasedOnOffset(20, 0), EFalse); // 0m:20s from "now"
135 TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 20);
136 entryList->AppendL(entry2);
139 TTsTime startTime3(SchSvrHelpers::TimeBasedOnOffset(0, 0, 0, 0, 0, -1), EFalse); // -1 year from "now"
140 TScheduleEntryInfo2 entry3 (startTime3, EDaily, 1, 20);
141 entryList->AppendL(entry3);
144 TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
145 CleanupStack::PopAndDestroy(); // entryList
149 // creates a schedule with numerous entries
150 static TInt CreateSchedule2L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
152 CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
153 CleanupStack::PushL(entryList);
155 aRef.iName = _L("Schedule created using \"CreateSchedule2L\"");
158 TTsTime startTime1(SchSvrHelpers::TimeBasedOnOffset(30, 2), EFalse); // 2m:30s from "now"
159 TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
160 entryList->AppendL(entry1);
163 TTsTime startTime2(SchSvrHelpers::TimeBasedOnOffset(0, 5), EFalse); // 5m:00s from "now"
164 TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 20);
165 entryList->AppendL(entry2);
168 TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
169 CleanupStack::PopAndDestroy(); // entryList
173 // creates a schedule with numerous entries
174 static TInt CreateSchedule3L(TSchedulerItemRef& aRef, RScheduler& aScheduler)
176 CSchEntryInfoArray* entryList = new (ELeave) CSchEntryInfoArray(3);
177 CleanupStack::PushL(entryList);
179 aRef.iName = _L("Schedule created using \"CreateSchedule3L\"");
182 TTsTime startTime1(SchSvrHelpers::TimeBasedOnOffset(0, 9, 0, 20), EFalse); // 9mins and 20days in the future
183 TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 5); // repeat every day and valid for only 5 minutes
184 entryList->AppendL(entry1);
188 TTsTime startTime2(SchSvrHelpers::TimeBasedOnOffset(0, 11, 0, 20), EFalse); // 11mins and 20days in the future
189 TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 5);
190 entryList->AppendL(entry2);
193 TInt res = aScheduler.CreatePersistentSchedule(aRef, *entryList);
194 CleanupStack::PopAndDestroy(); // entryList
199 // schedules a persistent task associated with the supplied schedule ID
200 static TInt SchedulePersistentTaskL(const TName& aName,
204 RScheduler& aScheduler)
207 taskInfo.iTaskId = aNewId;
208 taskInfo.iName = aName;
209 taskInfo.iPriority = 2;
210 taskInfo.iRepeat = aRepeat;
211 HBufC* data = _L("the data").AllocLC();
212 TInt res = aScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
213 aNewId = taskInfo.iTaskId;
215 CleanupStack::PopAndDestroy(); // data
221 @SYMTestCaseID SYSLIB-SCHSVR-CT-0257
222 @SYMTestCaseDesc Replicated test for for defect (EDNAWIR-4FQJ6A) - Hometime
223 @SYMTestPriority High
224 @SYMTestActions Register twice with SchSvr and check that there are no memery leaks
225 @SYMTestExpectedResults The test must not fail.
230 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0257 TheTest1: Registering with the tasks scheduler without disconnecting "));
232 TheTest.Next(_L("Connect to Scheduler"));
233 TInt res = TheScheduler.Connect();
234 TEST2(res, KErrNone);
236 TheTest.Next(_L("Registering Client"));
237 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
239 TheScheduler.Close();
243 TheTest.Next(_L("Connect to Scheduler again"));
244 res = TheScheduler.Connect();
245 TEST2(res, KErrNone);
247 TheTest.Next(_L("Registering client again"));
248 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
249 TheScheduler.__DbgMarkHeap();
251 TheTest.Next(_L("Register when already registered"));
252 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
254 TheTest.Next(_L("Cancel registering client and check for memory leak"));
255 TheScheduler.__DbgMarkEnd(0);
256 TheScheduler.Close();
261 //***********************************************************************************
265 @SYMTestCaseID SYSLIB-SCHSVR-CT-0258
266 @SYMTestCaseDesc Replicated test for for defect (EDNHLJT-4TRAAE) - Hometime
267 @SYMTestPriority High
268 @SYMTestActions Create schedule, kill server (simulate re-boot), and make sure task still completes
269 @SYMTestExpectedResults The test must not fail.
274 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0258 TheTest2: Resend after hard reset (simulation) "));
276 TheTest.Next(_L("Connect to Scheduler"));
277 TInt res = TheScheduler.Connect();
278 TEST2(res, KErrNone);
280 TheTest.Next(_L("Registering Client"));
281 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
284 TheTest.Next(_L("Creating schedule"));
285 TSchedulerItemRef scheduleHandle;
288 time += TTimeIntervalSeconds(2); //Task to go off two seconds from now
289 TTsTime time2 (time, EFalse);
290 User::LeaveIfError(CreateScheduleL(scheduleHandle, TheScheduler, time2));
292 // Add a task to the schedule
293 TheTest.Next(_L("Creating task for schedule"));
296 taskInfo.iName = _L("MyTaskName");
297 taskInfo.iPriority = 2;
298 taskInfo.iTaskId = 0;
299 taskInfo.iRepeat = 1;
300 HBufC* data = _L("Task Data").AllocLC();
301 TInt res = TheScheduler.ScheduleTask(taskInfo, *data, scheduleHandle.iHandle);
302 CleanupStack::PopAndDestroy(); // data
303 TEST2(res, KErrNone);
306 // Kill the server !!
307 TheTest.Next(_L("Killing server"));
308 // Need to turn off JIT dubugging as we are panicking server and we
309 // want test to keep running.
310 TBool jit = User::JustInTime();
311 User::SetJustInTime(EFalse);
313 TheScheduler.__FaultServer();
316 // Turn on JIT again.
317 User::SetJustInTime(jit);
319 // Connect to the server again
320 TheTest.Next(_L("Re-connect to Scheduler"));
321 res = TheScheduler.Connect();
322 TEST2(res, KErrNone);
325 TheTest.Next(_L("Re-register Client"));
326 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
328 TheTest.Next(_L("Check schedule count and task count"));
329 TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
330 TEST(scheduleCount == 1);
331 TInt taskCount = CountTasksL(scheduleHandle.iHandle);
332 TEST(taskCount == 1);
334 // Wait for task to fire... It should happen in about 2 seconds
335 TheTest.Next(_L("Waiting for task to complete"));
336 TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
337 CleanupHelpers::KillProcess(KMinimalTaskHandler);
340 //***********************************************************************************
344 @SYMTestCaseID SYSLIB-SCHSVR-CT-0259
345 @SYMTestCaseDesc Replicated test for CR (AALR-4EDG75) - Hometime
346 @SYMTestPriority High
347 @SYMTestActions Test changes to Schedule Server API
348 @SYMTestExpectedResults The test must not fail.
355 // Test changes to Schedule Server API as of Change Request document AALR-4EDG75
356 // (GT change requests database)
360 // This test establishes that the change to...
362 // RScheduler::GetScheduleL(const TInt aScheduleHandle,
363 // TScheduleState& aState,
364 // CArrayFixFlat<TScheduleEntryInfo>& aEntries,
365 // CArrayFixFlat<TTaskInfo>& aTasks,
368 // ...is functionally correct.
371 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0259 Test change request AALR-4EDG75 implementation "));
373 TheTest.Next(_L("Connect to Scheduler"));
374 TInt res = TheScheduler.Connect();
375 TEST2(res, KErrNone);
377 TheTest.Next(_L("Registering Client"));
378 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
380 const TDateTime KTimeToStartTask(2000, EJanuary, 10, 15, 30, 0, 0);
382 TSchedulerItemRef schedulerItemReference;
383 CSchEntryInfoArray* entryArray = new(ELeave) CSchEntryInfoArray(1);
384 CleanupStack::PushL(entryArray);
386 HBufC* taskData = _L("This is some dummy task data created for testing").AllocL();
387 CleanupStack::PushL(taskData);
389 // Prepare the task info - this describes the tasks that are contained within the task
391 TTaskInfo taskInfo = SchSvrHelpers::TaskInfo(_L("A transient test task"), 100);
393 // Create a schedule entry and append it to the entry array
395 TScheduleEntryInfo2 scheduleEntry = SchSvrHelpers::ScheduleEntryInfo(EDaily, TTsTime(TTime(KTimeToStartTask), EFalse), 7, 2);
396 entryArray->AppendL(scheduleEntry);
399 // Create the transient task
400 TInt ret = TheScheduler.ScheduleTask(taskInfo, *taskData, schedulerItemReference, *entryArray);
401 TEST2(ret, KErrNone);
403 // Check that the task Id after scheduling the event is not
404 // the same as it was prior to the requesting the service
405 TEST(taskInfo.iTaskId != -1);
408 // Now obtain info about the scheduled transient task...
410 TScheduleState2 scheduleState;
411 TTsTime nextTaskDueTime;
413 // Reset the schedule entry info array as the server now has copies of this and it is
414 // no longer required client-side
416 CTaskInfoArray* taskInfoArray = new(ELeave) CTaskInfoArray(4);
417 CleanupStack::PushL(taskInfoArray);
419 // Request task schedule information from the server
420 ret = TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime);
421 TEST2(ret, KErrNone);
423 // Because this is a daily task which is scheduled to occur at a specific time (but the date
424 // cannot necessarily be established, we can perform a simple check to ensure that the
425 // time when the task is next scheduled to run falls within the 15:30 - 17:30 bracket.
427 TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), EFalse)) == (TInt) ETrue);
429 // Establish and test the size of the task data for the specified task object
430 TInt sizeOfTaskData = 0;
431 TEST2(TheScheduler.GetTaskDataSize(taskInfo.iTaskId, sizeOfTaskData), KErrNone);
432 TEST(sizeOfTaskData == taskData->Length());
434 // Now check the information return from the server pertaining to a specific task...
436 TTaskInfo taskFromServer;
437 HBufC* taskDataFromServer = HBufC::NewLC(sizeOfTaskData);
438 TPtr pTaskDataFromServer = taskDataFromServer->Des();
439 TTime nullTime = Time::NullTTime();
440 TTsTime nextDueTimeFromServer (nullTime, EFalse);
441 TSchedulerItemRef schedulerRefFromServer;
442 TEST2(TheScheduler.GetTaskInfoL(taskInfo.iTaskId, taskFromServer, pTaskDataFromServer, schedulerRefFromServer, nextDueTimeFromServer), KErrNone);
443 TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), EFalse)) == (TInt) ETrue);
445 TEST(SchSvrHelpers::IsTaskInfoTheSame(taskFromServer, taskInfo) == (TInt) ETrue);
446 TEST(SchSvrHelpers::IsItemRefTheSame(schedulerRefFromServer, schedulerItemReference) == (TInt) ETrue);
447 CleanupStack::PopAndDestroy(); // taskDataFromServer
450 // Disable the schedule and check when it is next schedule to run
451 TEST2(TheScheduler.DisableSchedule(schedulerItemReference.iHandle), KErrNone);
453 // Get the new schedule info - check that the nextDueTime is still reported even
454 // though the schedule has been disabled
456 nextTaskDueTime.SetLocalTime(Time::NullTTime());
457 TEST2(TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime), KErrNone);
458 TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), EFalse)) == (TInt) ETrue);
459 TEST(SchSvrHelpers::IsTaskInfoTheSame(taskInfoArray->At(0), taskInfo) == (TInt) ETrue);
461 // Re-enable the schedule
462 TEST2(TheScheduler.EnableSchedule(schedulerItemReference.iHandle), KErrNone);
464 // Delete the only task (relating to this test) from the server
465 TEST2(TheScheduler.DeleteTask(taskInfo.iTaskId), KErrNone);
466 ret = TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime);
467 TEST2(ret, KErrNotFound); // there is no longer any tasks associated with this schedule
469 CleanupStack::PopAndDestroy(3); // taskInfoArray, entryArray, taskData
472 //***********************************************************************************
476 @SYMTestCaseID SYSLIB-SCHSVR-CT-0260
477 @SYMTestCaseDesc Replicated test for defect (EDNAALR-4JKEFC) - Hometime
478 @SYMTestPriority High
479 @SYMTestActions Create 2 schedules with repeating tasks, kill server and check that tasks complete
480 @SYMTestExpectedResults The test must not fail.
486 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0260 \nTest for defect EDNAALR-4JKEFC "));
488 TheTest.Next(_L("Connect to Scheduler"));
489 TInt res = TheScheduler.Connect();
490 TEST2(res, KErrNone);
492 TheTest.Next(_L("Registering Client"));
493 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
495 // Constants / vars used in this function
496 TSchedulerItemRef itemRef;
498 // Create some scheduling entries
499 CArrayFixFlat<TScheduleEntryInfo2>* entries = new(ELeave) CArrayFixFlat<TScheduleEntryInfo2>(10);
500 CleanupStack::PushL(entries);
502 TTsTime startTime1 (SchSvrHelpers::TimeBasedOnOffset(1, 1), EFalse); // 1m:01s from "now"
503 TScheduleEntryInfo2 entry1 (startTime1, EHourly, 1, 20);
504 entries->AppendL(entry1);
506 TTsTime startTime2 (SchSvrHelpers::TimeBasedOnOffset(5, 5), EFalse); // 5m:05s from "now"
507 TScheduleEntryInfo2 entry2 (startTime2, EHourly, 1, 20);
508 entries->AppendL(entry2);
510 // Create the schedule for the task...
511 res = TheScheduler.CreatePersistentSchedule(itemRef, *entries);
512 TEST2(res, KErrNone);
514 // Create the tasks themselves..
516 task.iRepeat = 10; // repeat once
517 task.iName = _L("Test Task For Defect Verification");
518 task.iPriority = 100;
519 HBufC* taskData = task.iName.AllocLC();
520 res = TheScheduler.ScheduleTask(task, *taskData, itemRef.iHandle);
521 CleanupStack::PopAndDestroy(); // taskData
524 CArrayFixFlat<TSchedulerItemRef>* refs = new CArrayFixFlat<TSchedulerItemRef>(3);
525 CleanupStack::PushL(refs);
526 TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
527 TEST2(res, KErrNone);
528 CleanupStack::PopAndDestroy(); // refs
531 // Re-register theclient with the server
532 for(TInt i=0; i<5; i++)
534 // Log off from the task scheduler
535 TheScheduler.Close();
536 res = TheScheduler.Connect();
537 TEST2(res, KErrNone);
539 User::After(1000000);
541 TheTest.Next(_L("===== Re-registering Client (wait a second) ====="));
542 res = SchSvrHelpers::RegisterClientL(TheScheduler);
543 TEST2(res, KErrNone);
545 CArrayFixFlat<TSchedulerItemRef>* refs = new CArrayFixFlat<TSchedulerItemRef>(3);
546 CleanupStack::PushL(refs);
547 TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
549 CleanupStack::PopAndDestroy(); // refs
552 // Check the information that the scheduler knows about...
553 TInt taskDataSize = 0;
554 res = TheScheduler.GetTaskDataSize(task.iTaskId, taskDataSize);
555 TEST2(res, KErrNone);
556 TEST(taskDataSize == task.iName.Length());
557 TTaskInfo taskInfoFromServer;
558 taskData = HBufC::NewLC(taskDataSize);
559 TPtr pTaskData = taskData->Des();
561 TTsTime nextDueTime(Time::NullTTime(), EFalse);
562 res = TheScheduler.GetTaskInfoL(task.iTaskId, taskInfoFromServer, pTaskData, itemRef, nextDueTime);
563 TEST2(res, KErrNone);
564 TEST(pTaskData == task.iName);
565 CleanupStack::PopAndDestroy(); // taskData
568 CleanupStack::PopAndDestroy(); // entries
572 //***********************************************************************************
576 @SYMTestCaseID SYSLIB-SCHSVR-CT-0261
577 @SYMTestCaseDesc Persistant schedule test - Hometime
578 @SYMTestPriority High
579 @SYMTestActions Mark heap, create persistent schedules, schedule tasks, transient schedules, delete tasks, delete remaing schedules, check heap
580 @SYMTestExpectedResults The test must not fail.
586 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0261 ===== Starting test 1 ===== "));
589 TSchedulerItemRef ref1;
590 TSchedulerItemRef ref2;
591 TSchedulerItemRef ref3;
593 // Remove all existing schedules before starting the test
594 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
596 TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
597 TEST(scheduleCount == 0); // check that no schedules are present.
599 TheTest.Printf(_L("Create some schedules\n"));
600 res = CreateSchedule1L(ref1, TheScheduler); // +10sec, +20sec, -1year
601 TEST2(res, KErrNone);
602 res = CreateSchedule2L(ref2, TheScheduler); // +2min 30sec, +5min
603 TEST2(res, KErrNone);
604 res = CreateSchedule3L(ref3, TheScheduler); // +20day 9min, +20day 11min
605 TEST2(res, KErrNone);
607 TSchedulerItemRef ref4;
608 TSchedulerItemRef ref5;
609 res = CreateSchedule2L(ref4, TheScheduler); // +2min 30sec, 5min
610 TEST2(res, KErrNone);
611 res = CreateSchedule3L(ref5, TheScheduler); // +20day 9min, +20day 11min
612 TEST2(res, KErrNone);
618 TName name1 = (_L("web subscription"));
619 TName name2 = (_L("another web subscription"));
620 TName name3 = (_L("third web subscription"));
622 TheTest.Printf(_L("Schedule some tasks\n"));
624 // NOTE: have to put repeats here of > 0 otherwise the task will run immediately
625 // (because it's schedule specifies a date of 1 year in the past!) and be
626 // removed (by the server) before we have a chance to delete it....
627 res = SchedulePersistentTaskL(name1, task1, ref1.iHandle, 3, TheScheduler);
628 TEST2(res, KErrNone);
629 res = SchedulePersistentTaskL(name2, task2, ref2.iHandle, 3, TheScheduler);
630 TEST2(res, KErrNone);
631 res = SchedulePersistentTaskL(name3, task3, ref3.iHandle, 3, TheScheduler);
632 TEST2(res, KErrNone);
633 res = SchedulePersistentTaskL(name3, task4, ref3.iHandle, 3, TheScheduler);
634 TEST2(res, KErrNone);
636 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
637 TEST(scheduleCount == 5); // 5 persistant
638 CleanupHelpers::KillProcess(KMinimalTaskHandler);
640 TheTest.Printf(_L("Deleting task with id %d\n"), task1);
641 res = TheScheduler.DeleteTask(task1);
642 TEST2(res, KErrNone);
643 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
644 res = TheScheduler.DeleteSchedule(ref1.iHandle);
645 TEST2(res, KErrNone);
646 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
647 // 4 persistant expected as we have deleted one
648 TEST(scheduleCount == 4);
650 TheTest.Printf(_L("Deleting task with id %d\n"), task2);
651 res = TheScheduler.DeleteTask(task2);
652 TEST2(res, KErrNone);
653 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref2.iHandle);
654 res = TheScheduler.DeleteSchedule(ref2.iHandle);
655 TEST2(res, KErrNone);
656 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
657 // 3 persistant expected as we have deleted one
658 TEST(scheduleCount == 3);
660 TheTest.Printf(_L("Deleting task with id %d\n"), task3);
661 res = TheScheduler.DeleteTask(task3);
662 TEST2(res, KErrNone);
663 TheTest.Printf(_L("Deleting task with id %d\n"), task4);
664 res = TheScheduler.DeleteTask(task4);
665 TEST2(res, KErrNone);
666 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref3.iHandle);
667 res = TheScheduler.DeleteSchedule(ref3.iHandle);
668 TEST2(res, KErrNone);
669 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
670 // 2 persistant expected as we have deleted one
671 TEST(scheduleCount == 2);
673 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref4.iHandle);
674 res = TheScheduler.DeleteSchedule(ref4.iHandle);
675 TEST2(res, KErrNone);
676 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref5.iHandle);
677 res = TheScheduler.DeleteSchedule(ref5.iHandle);
678 TEST2(res, KErrNone);
680 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
681 TEST(scheduleCount == 0);
683 SchSvrHelpers::Pause(TheTest,1);
688 //***********************************************************************************
692 @SYMTestCaseID SYSLIB-SCHSVR-CT-0262
693 @SYMTestCaseDesc Transient schedule test - Hometime
694 @SYMTestPriority High
695 @SYMTestActions Create transient schedule with non-repeating task
696 @SYMTestExpectedResults The test must not fail.
701 // Heap testing removed because this is a flakey bit of code.
702 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0262 Transient, non-repeating - waits for schedule to activate "));
704 // Remove all existing schedules before starting the test
705 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
707 // Create transient schedule
708 TheTest.Printf(_L("Create transient schedule with non-repeating task\n"));
709 TSchedulerItemRef ref;
710 CSchEntryInfoArray* entryList = new(ELeave) CSchEntryInfoArray(1);
711 CleanupStack::PushL(entryList);
712 ref.iName = _L("A Transient Schedule");
714 // CREATE SCHEDULE ENTRY:
715 // starttime 5 secs in the future, hometime based
716 TTsTime startTime(SchSvrHelpers::TimeBasedOnOffset(5), EFalse);
717 // constructor takes: starttime, interval type, interval, validity period
718 TScheduleEntryInfo2 entry(startTime, EDaily, 1, 20);
719 entryList->AppendL(entry);
721 // CREATE SCHEDULE TASK:
723 taskInfo.iName = _L("mail");
724 taskInfo.iTaskId = 0;
725 taskInfo.iRepeat = 1;
726 taskInfo.iPriority = 2;
727 HBufC* data = _L("This is the data for the task").AllocLC();
730 TInt res = TheScheduler.ScheduleTask(taskInfo, *data, ref, *entryList);
731 TEST2(res, KErrNone);
732 CleanupStack::PopAndDestroy(2, entryList); // data, entryList
734 // Should be one item
735 TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 1);
737 // Waiting for entry to complete
738 TheTest.Next(_L("Waiting for for task to complete"));
739 TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
740 CleanupHelpers::KillProcess(KMinimalTaskHandler);
741 // Should be no items as schedule deletes itself after task has completed
742 TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 0);
744 SchSvrHelpers::Pause(TheTest,1);
748 //***********************************************************************************
752 @SYMTestCaseID SYSLIB-SCHSVR-CT-0263
753 @SYMTestCaseDesc Persistant schedule test with repeating task - Hometime
754 @SYMTestPriority High
755 @SYMTestActions Persistent schedule, repeating task, non-repeating task, go off, check task's still there, go off again, check it's still there, delete task, delete schedule,
756 @SYMTestExpectedResults The test must not fail.
761 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0263 Test persistent scheduling, repeating and non-repeating task schedules "));
763 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
766 TSchedulerItemRef ref;
768 // We shouldn't have any outstanding schedules registered with the server
769 TInt count = CountScheduledItemsL(EAllSchedules, TheScheduler);
772 // This creates 3 schedule entries, each with a validity period of 20 minutes, and are
773 // due to run in 10s, 20s, and over a year ago (a year in the past)
774 TheTest.Printf(_L("Create Persistent schedule\n"));
775 TInt res = CreateSchedule1L(ref, TheScheduler);
776 TEST2(res, KErrNone);
778 // We should now have one registered schedule
779 count = CountScheduledItemsL(EAllSchedules, TheScheduler);
783 TheTest.Printf(_L("\nSchedule two tasks: one repeating....\n"));
786 TName name1 = (_L("web subscription(rpts)"));
787 // -1 indicates repeating schedule
788 res = SchedulePersistentTaskL(name1, task1, ref.iHandle, -1, TheScheduler); // -1 indicates repeat until explicitly deleted
789 TEST2(res, KErrNone);
791 // List those schedules that are pending
792 count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
796 TheTest.Printf(_L("\n... and one non-repeating\n"));
799 TName name2 = (_L("non-repeating"));
800 res = SchedulePersistentTaskL(name2, task2, ref.iHandle, 1, TheScheduler); // only runs once
801 TEST2(res, KErrNone);
803 TheTest.Printf(_L("Waiting for tasks to run\n"));
804 // Wait for notification that schedule has executed.
805 TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
806 CleanupHelpers::KillProcess(KMinimalTaskHandler);
808 TheTest.Printf(_L("...and wait again for repeating one to execute again\n"));
809 // Wait for notification that schedule has executed.
810 TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
811 CleanupHelpers::KillProcess(KMinimalTaskHandler);
813 TheTest.Printf(_L("Delete the repeating task, and the schedule \n"));
814 res = TheScheduler.DeleteTask(task1);
815 TEST2(res, KErrNone);
816 res = TheScheduler.DeleteTask(task2);
817 TEST2(res, KErrNotFound); //Should be not found since its only executed once.
818 res = TheScheduler.DeleteSchedule(ref.iHandle);
819 TEST2(res, KErrNone);
821 count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
823 SchSvrHelpers::Pause(TheTest, 1);
827 static CSchEntryInfoArray* CreateSchEntryInfoArrayLC(TInt aGranularity)
829 CSchEntryInfoArray* scheduleEntries = new (ELeave) CSchEntryInfoArray(aGranularity);
830 CleanupStack::PushL(scheduleEntries);
831 return scheduleEntries;
834 static CArrayFixFlat<TTaskInfo>* CreateTaskInfoLC(TInt aGranularity)
836 CArrayFixFlat<TTaskInfo>* taskInfos = new (ELeave) CArrayFixFlat<TTaskInfo>(aGranularity);
837 CleanupStack::PushL(taskInfos);
841 static CSchItemRefArray* CreateScheduleRefsLC(TInt aGranularity)
843 CSchItemRefArray* scheduleReferences = new (ELeave) CSchItemRefArray(aGranularity);
844 CleanupStack::PushL(scheduleReferences);
845 return scheduleReferences;
848 static void CreateTransientScheduledTasksL(TInt aNumScheduleEntries,
850 CSchEntryInfoArray* aScheduleEntries,
851 CArrayFixFlat<TTaskInfo>* aTaskInfos,
852 CSchItemRefArray* aScheduleReferences)
854 const TTimeIntervalMicroSeconds timeToAdd = 10000000; //10 seconds
855 const TTimeIntervalMicroSeconds timeLimit = 5000000; // 5 seconds
856 _LIT(KTaskDataPrefix, "Task Data Entry: ");
857 // Prepare keys required
858 TKeyArrayFix KTaskInfoSortKey(_FOFF(TTaskInfo, iTaskId), ECmpTInt);
860 for(TInt i=0;i<aNumSchedules;i++)
862 // Remove any existing schedule entry info's
863 aScheduleEntries->Reset();
865 // Populate the schedule entry array with a varying list of
866 // start-times, intervals, etc for this particular task
868 for(TInt j=0; j<aNumScheduleEntries; ++j)
870 TScheduleEntryInfo2 scheduleEntry = SchSvrHelpers::RandomScheduleEntryInfoHometime(TheSeed);
872 now.HomeTime(); // sets now to home time
873 TTime sTime = scheduleEntry.StartTime().GetLocalTime();
874 //if scheduleEntry.StartTime() is set lower then 5 sec into the future, postpone StartTime 10 sec into the future
875 if(sTime < now + timeLimit)
877 TTsTime newTime (now + timeToAdd, EFalse);
878 scheduleEntry.SetStartTime(newTime);
880 aScheduleEntries->AppendL(scheduleEntry);
883 // Create some dummy task data
885 HBufC* taskData = HBufC::NewLC(KTaskDataPrefix().Length()+4);
886 taskData->Des().Copy(KTaskDataPrefix());
887 taskData->Des().AppendNum(i);
889 // Munge the task name
892 taskInfo.iName = *taskData;
893 taskInfo.iRepeat = 1;
894 taskInfo.iPriority = 1;
895 // Schedule the transient task
896 TSchedulerItemRef scheduleReference;
897 TInt result = TheScheduler.ScheduleTask(taskInfo,
901 TEST2(result, KErrNone);
902 TheTest.Printf(_L("TaskId: %d => TaskName: %S\n"), taskInfo.iTaskId, &taskInfo.iName);
903 CleanupStack::PopAndDestroy(taskData);
905 // Save the taskInfo so we can check it later - this inserts the taskinfo into
906 // the array (preserves sorted order by TTaskInfo.iTaskId) but also has the
907 // added bonus of preventing duplicate task ids...
909 aTaskInfos->InsertIsqL(taskInfo, KTaskInfoSortKey);
910 // Disable all schedules once added, just to stop them going off
911 // and therefore being deleted when we are trying to compare them
912 result = TheScheduler.DisableSchedule(scheduleReference.iHandle);
913 TEST2(result, KErrNone);
914 // Save the sever generated schedule reference and taskId for checking later
915 aScheduleReferences->AppendL(scheduleReference);
919 static void CheckScheduledRefs(TInt aNumSchedules)
921 CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
922 CleanupStack::PushL(refs);
923 TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
924 TEST2(res, KErrNone);
925 TInt count = refs->Count();
926 TEST(count == aNumSchedules);
927 CleanupStack::PopAndDestroy(refs);
930 static void TestScheduledTasksL(TInt aNumSchedules,
931 CArrayFixFlat<TTaskInfo>* aTaskInfos)
933 for(TInt n=0; n<aNumSchedules; ++n)
935 const TTaskInfo& taskInfo = aTaskInfos->At(n);
937 // First retrieve the task size
939 TInt result = TheScheduler.GetTaskDataSize(taskInfo.iTaskId, taskSize);
940 TEST2(result, KErrNone);
943 // Next retrieve the task info associated with a particular task Id
944 HBufC* taskData = HBufC::NewLC(taskSize);
945 TPtr pTaskData = taskData->Des();
947 TTsTime scheduleNextDueTime;
948 TTaskInfo taskFromServer;
949 TSchedulerItemRef scheduleReference;
951 result = TheScheduler.GetTaskInfoL(taskInfo.iTaskId,
955 scheduleNextDueTime);
956 TEST2(result, KErrNone);
957 TEST(taskData->Length() == taskSize);
959 // Now check that the task returned by the server matches that held locallly....
960 TBool bbb = SchSvrHelpers::IsTaskInfoTheSame(taskFromServer, taskInfo);
963 RDebug::Print(_L("TaskInfo1. repeat=%x, id=%d, name=%S, priority=%x\n"),
964 taskFromServer.iRepeat, taskFromServer.iTaskId, &taskFromServer.iName, taskFromServer.iPriority);
965 RDebug::Print(_L("TaskInfo2. repeat=%x, id=%d, name=%S, priority=%x\n"),
966 taskInfo.iRepeat, taskInfo.iTaskId, &taskInfo.iName, taskInfo.iPriority);
970 // Check taskData is the same (was originally held in the TTaskInfo.iName field)
971 const TDesC& des1 = taskInfo.iName;
972 TDes& des2 = pTaskData;
974 CleanupStack::PopAndDestroy(taskData);
978 //***********************************************************************************
982 @SYMTestCaseID SYSLIB-SCHSVR-CT-0264
983 @SYMTestCaseDesc Large number of tasks test - Hometime
984 @SYMTestPriority High
985 @SYMTestActions Create a large number of tasks, test retrieval of task data and task info
986 @SYMTestExpectedResults The test must not fail.
992 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0264 Create a large number of tasks, test retrieval of task data and task info "));
993 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
995 // Constants used in this function
996 const TInt KNumberOfSchedulesToCreate = 20;
997 const TInt KNumberOfScheduleEntriesToCreate = 5;
999 // Prepare arrays required for the tests below
1000 CSchEntryInfoArray* scheduleEntries = ::CreateSchEntryInfoArrayLC(KNumberOfScheduleEntriesToCreate);
1001 CArrayFixFlat<TTaskInfo>* taskInfos = ::CreateTaskInfoLC(KNumberOfSchedulesToCreate);
1002 CSchItemRefArray* scheduleReferences = ::CreateScheduleRefsLC(KNumberOfSchedulesToCreate);
1005 // Create a large number of transient scheduled tasks
1006 // to test Id generation
1008 ::CreateTransientScheduledTasksL(KNumberOfScheduleEntriesToCreate,
1009 KNumberOfSchedulesToCreate,
1012 scheduleReferences);
1015 ::CheckScheduledRefs(KNumberOfSchedulesToCreate);
1017 // Test tasks for a given taskid is the same
1018 ::TestScheduledTasksL(KNumberOfSchedulesToCreate, taskInfos);
1020 // Test reference can be retrieved for a given handle.
1021 CleanupStack::PopAndDestroy(scheduleReferences);
1022 CleanupStack::PopAndDestroy(taskInfos);
1023 CleanupStack::PopAndDestroy(scheduleEntries);
1025 // now delete all schedules
1026 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1027 TInt ccc = CountScheduledItemsL(EAllSchedules, TheScheduler);
1030 SchSvrHelpers::Pause(TheTest,1 );
1033 //***********************************************************************************
1034 static TInt RunTestsL()
1036 TheTest.Next(_L("Delete old files"));
1037 SchSvrHelpers::DeleteScheduleFilesL();
1039 TheTest.Next(_L("Create Task notification semaphore"));
1040 //initialise task notification semaphore
1044 // Prepare random number seed
1045 TheTest.Next(_L("Prepare random number"));
1047 now.UniversalTime();
1048 TheSeed = now.Int64();
1050 // Connect to the server
1051 TheTest.Next(_L("===== Connect to Scheduler ====="));
1052 TInt res = TheScheduler.Connect();
1053 TEST2(res, KErrNone);
1055 // Register a client with the server
1056 TheTest.Next(_L("===== Registering Client ====="));
1057 res = SchSvrHelpers::RegisterClientL(TheScheduler);
1058 TEST2(res, KErrNone);
1060 TheTest.Next(_L("Start tests"));
1070 TheTest.Next(_L("Tidying up"));
1071 //Tidying up so next test will be clear.
1072 TheTest.Next(_L("Delete all schedules"));
1073 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1074 SchSvrHelpers::Pause(TheTest, 2);
1075 TheTest.Next(_L("Delete old files\n"));
1076 SchSvrHelpers::DeleteScheduleFilesL();
1078 TheScheduler.Close();
1080 //close handle to semaphore
1086 //***********************************************************************************
1087 GLDEF_C TInt E32Main()
1089 // TheTest the scheduler
1093 TheTest.Start(_L("TC_TSCH_SCHEDULING2 - Hometime"));
1095 TheCleanup = CTrapCleanup::New();
1096 //If the previous test fails, SCHSVR.exe may stay in memory.
1097 TRAPD(error,CleanupHelpers::TestCleanupL());
1098 TEST2(error, KErrNone);
1100 TEST2(TheFsSession.Connect(), KErrNone);;
1101 TRAP(error, RunTestsL());
1102 TRAP(error,CleanupHelpers::TestCleanupL());
1103 TEST2(error, KErrNone);
1106 TheFsSession.Close();