os/ossrv/genericservices/taskscheduler/Test/Scheduling/TC_TSCH_SCHEDULING2_UTC.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 - UTC");
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::UtcTimeBasedOnOffset(10, 0), ETrue); // 0m:10s from "now"
130 TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
131 entryList->AppendL(entry1);
134 TTsTime startTime2(SchSvrHelpers::UtcTimeBasedOnOffset(20, 1), ETrue); // 0m:20s from "now"
135 TScheduleEntryInfo2 entry2 (startTime2, EDaily, 1, 20);
136 entryList->AppendL(entry2);
139 TTsTime startTime3(SchSvrHelpers::UtcTimeBasedOnOffset(0, 0, 0, 0, 0, -1), ETrue); // -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::UtcTimeBasedOnOffset(30, 2), ETrue); // 2m:30s from "now"
159 TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20);
160 entryList->AppendL(entry1);
163 TTsTime startTime2(SchSvrHelpers::UtcTimeBasedOnOffset(0, 5), ETrue); // 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), ETrue); // 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), ETrue); // 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-0265
222 @SYMTestCaseDesc Replicated test for for defect (EDNAWIR-4FQJ6A) - UTC
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-0265 TheTest1: Registering with the tasks scheduler without disconnecting "));
233 TheTest.Next(_L("Connect to Scheduler"));
234 TInt res = TheScheduler.Connect();
235 TEST2(res, KErrNone);
237 TheTest.Next(_L("Registering Client"));
238 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
240 TheScheduler.Close();
244 TheTest.Next(_L("Connect to Scheduler again"));
245 res = TheScheduler.Connect();
246 TEST2(res, KErrNone);
248 TheTest.Next(_L("Registering client again"));
249 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
250 TheScheduler.__DbgMarkHeap();
252 TheTest.Next(_L("Register when already registered"));
253 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
255 TheTest.Next(_L("Cancel registering client and check for memory leak"));
256 TheScheduler.__DbgMarkEnd(0);
257 TheScheduler.Close();
262 //***********************************************************************************
266 @SYMTestCaseID SYSLIB-SCHSVR-CT-0266
267 @SYMTestCaseDesc Replicated test for for defect (EDNHLJT-4TRAAE) - UTC
268 @SYMTestPriority High
269 @SYMTestActions Create schedule, kill server (simulate re-boot), and make sure task still completes
270 @SYMTestExpectedResults The test must not fail.
275 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0266 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;
287 time.UniversalTime();
288 time += TTimeIntervalSeconds(5); //Task to go off five seconds from now
289 TTsTime time2 (time, ETrue);
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 5 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-0267
345 @SYMTestCaseDesc Replicated test for CR (AALR-4EDG75) - UTC
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.
372 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0267 Test change request AALR-4EDG75 implementation"));
374 TheTest.Next(_L("Connect to Scheduler"));
375 TInt res = TheScheduler.Connect();
376 TEST2(res, KErrNone);
378 TheTest.Next(_L("Registering Client"));
379 TEST2(SchSvrHelpers::RegisterClientL(TheScheduler), KErrNone);
381 const TDateTime KTimeToStartTask(2000, EJanuary, 10, 15, 30, 0, 0);
383 TSchedulerItemRef schedulerItemReference;
384 CSchEntryInfoArray* entryArray = new(ELeave) CSchEntryInfoArray(1);
385 CleanupStack::PushL(entryArray);
387 HBufC* taskData = _L("This is some dummy task data created for testing").AllocL();
388 CleanupStack::PushL(taskData);
390 // Prepare the task info - this describes the tasks that are contained within the task
392 TTaskInfo taskInfo = SchSvrHelpers::TaskInfo(_L("A transient test task"), 100);
394 // Create a schedule entry and append it to the entry array
396 TScheduleEntryInfo2 scheduleEntry = SchSvrHelpers::ScheduleEntryInfo(EDaily, TTsTime(TTime(KTimeToStartTask), ETrue), 7, 2);
397 entryArray->AppendL(scheduleEntry);
400 // Create the transient task
401 TInt ret = TheScheduler.ScheduleTask(taskInfo, *taskData, schedulerItemReference, *entryArray);
402 TEST2(ret, KErrNone);
404 // Check that the task Id after scheduling the event is not
405 // the same as it was prior to the requesting the service
406 TEST(taskInfo.iTaskId != -1);
409 // Now obtain info about the scheduled transient task...
411 TScheduleState2 scheduleState;
412 TTsTime nextTaskDueTime;
414 // Reset the schedule entry info array as the server now has copies of this and it is
415 // no longer required client-side
417 CTaskInfoArray* taskInfoArray = new(ELeave) CTaskInfoArray(4);
418 CleanupStack::PushL(taskInfoArray);
420 // Request task schedule information from the server
421 ret = TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime);
422 TEST2(ret, KErrNone);
424 // Because this is a daily task which is scheduled to occur at a specific time (but the date
425 // cannot necessarily be established, we can perform a simple check to ensure that the
426 // 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), ETrue)) == (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, ETrue);
441 TSchedulerItemRef schedulerRefFromServer;
442 TEST2(TheScheduler.GetTaskInfoL(taskInfo.iTaskId, taskFromServer, pTaskDataFromServer, schedulerRefFromServer, nextDueTimeFromServer), KErrNone);
443 TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), ETrue)) == (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.SetUtcTime(Time::NullTTime());
457 TEST2(TheScheduler.GetScheduleL(schedulerItemReference.iHandle, scheduleState, *entryArray, *taskInfoArray, nextTaskDueTime), KErrNone);
458 TEST(SchSvrHelpers::IsTimeTheSame(nextTaskDueTime, TTsTime(TTime(KTimeToStartTask), ETrue)) == (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-0268
477 @SYMTestCaseDesc Replicated test for defect (EDNAALR-4JKEFC) - UTC
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-0268 \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), ETrue); // 1m:01s from "now"
503 TScheduleEntryInfo2 entry1 (startTime1, EHourly, 1, 20);
504 entries->AppendL(entry1);
506 TTsTime startTime2 (SchSvrHelpers::TimeBasedOnOffset(5, 5), ETrue); // 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(), ETrue);
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-0269
577 @SYMTestCaseDesc Persistant schedule test - UTC
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-0269 ===== Starting test 1 ====="));
590 TSchedulerItemRef ref1;
591 TSchedulerItemRef ref2;
592 TSchedulerItemRef ref3;
594 // Remove all existing schedules before starting the test
595 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
597 TInt scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
598 TEST(scheduleCount == 0); // check that no schedules are present.
600 TheTest.Printf(_L("Create some schedules\n"));
601 res = CreateSchedule1L(ref1, TheScheduler); // +10sec, +20sec, -1year
602 TEST2(res, KErrNone);
603 res = CreateSchedule2L(ref2, TheScheduler); // +2min 30sec, +5min
604 TEST2(res, KErrNone);
605 res = CreateSchedule3L(ref3, TheScheduler); // +20day 9min, +20day 11min
606 TEST2(res, KErrNone);
608 TSchedulerItemRef ref4;
609 TSchedulerItemRef ref5;
610 res = CreateSchedule2L(ref4, TheScheduler); // +2min 30sec, 5min
611 TEST2(res, KErrNone);
612 res = CreateSchedule3L(ref5, TheScheduler); // +20day 9min, +20day 11min
613 TEST2(res, KErrNone);
619 TName name1 = (_L("web subscription"));
620 TName name2 = (_L("another web subscription"));
621 TName name3 = (_L("third web subscription"));
623 TheTest.Printf(_L("Schedule some tasks\n"));
625 // NOTE: have to put repeats here of > 0 otherwise the task will run immediately
626 // (because it's schedule specifies a date of 1 year in the past!) and be
627 // removed (by the server) before we have a chance to delete it....
628 res = SchedulePersistentTaskL(name1, task1, ref1.iHandle, 3, TheScheduler);
629 TEST2(res, KErrNone);
630 res = SchedulePersistentTaskL(name2, task2, ref2.iHandle, 3, TheScheduler);
631 TEST2(res, KErrNone);
632 res = SchedulePersistentTaskL(name3, task3, ref3.iHandle, 3, TheScheduler);
633 TEST2(res, KErrNone);
634 res = SchedulePersistentTaskL(name3, task4, ref3.iHandle, 3, TheScheduler);
635 TEST2(res, KErrNone);
637 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
638 TEST(scheduleCount == 5); // 5 persistant
639 CleanupHelpers::KillProcess(KMinimalTaskHandler);
641 TheTest.Printf(_L("Deleting task with id %d\n"), task1);
642 res = TheScheduler.DeleteTask(task1);
643 TEST2(res, KErrNone);
644 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref1.iHandle);
645 res = TheScheduler.DeleteSchedule(ref1.iHandle);
646 TEST2(res, KErrNone);
647 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
648 // 4 persistant expected as we have deleted one
649 TEST(scheduleCount == 4);
651 TheTest.Printf(_L("Deleting task with id %d\n"), task2);
652 res = TheScheduler.DeleteTask(task2);
653 TEST2(res, KErrNone);
654 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref2.iHandle);
655 res = TheScheduler.DeleteSchedule(ref2.iHandle);
656 TEST2(res, KErrNone);
657 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
658 // 3 persistant expected as we have deleted one
659 TEST(scheduleCount == 3);
661 TheTest.Printf(_L("Deleting task with id %d\n"), task3);
662 res = TheScheduler.DeleteTask(task3);
663 TEST2(res, KErrNone);
664 TheTest.Printf(_L("Deleting task with id %d\n"), task4);
665 res = TheScheduler.DeleteTask(task4);
666 TEST2(res, KErrNone);
667 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref3.iHandle);
668 res = TheScheduler.DeleteSchedule(ref3.iHandle);
669 TEST2(res, KErrNone);
670 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
671 // 2 persistant expected as we have deleted one
672 TEST(scheduleCount == 2);
674 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref4.iHandle);
675 res = TheScheduler.DeleteSchedule(ref4.iHandle);
676 TEST2(res, KErrNone);
677 TheTest.Printf(_L("Deleting schedule with id %d\n"), ref5.iHandle);
678 res = TheScheduler.DeleteSchedule(ref5.iHandle);
679 TEST2(res, KErrNone);
681 scheduleCount = CountScheduledItemsL(EAllSchedules, TheScheduler);
682 TEST(scheduleCount == 0);
684 SchSvrHelpers::Pause(TheTest,1);
689 //***********************************************************************************
693 @SYMTestCaseID SYSLIB-SCHSVR-CT-0270
694 @SYMTestCaseDesc Transient schedule test - UTC
695 @SYMTestPriority High
696 @SYMTestActions Create transient schedule with non-repeating task
697 @SYMTestExpectedResults The test must not fail.
702 // Heap testing removed because this is a flakey bit of code.
703 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0270 Transient, non-repeating - waits for schedule to activate "));
705 // Remove all existing schedules before starting the test
706 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
708 // Create transient schedule
709 TheTest.Printf(_L("Create transient schedule with non-repeating task\n"));
710 TSchedulerItemRef ref;
711 CSchEntryInfoArray* entryList = new(ELeave) CSchEntryInfoArray(1);
712 CleanupStack::PushL(entryList);
713 ref.iName = _L("A Transient Schedule");
715 // CREATE SCHEDULE ENTRY:
716 // starttime 5 secs in the future, hometime based
717 TTsTime startTime(SchSvrHelpers::TimeBasedOnOffset(5), EFalse);
718 // constructor takes: starttime, interval type, interval, validity period
719 TScheduleEntryInfo2 entry(startTime, EDaily, 1, 20);
720 entryList->AppendL(entry);
722 // CREATE SCHEDULE TASK:
724 taskInfo.iName = _L("mail");
725 taskInfo.iTaskId = 0;
726 taskInfo.iRepeat = 1;
727 taskInfo.iPriority = 2;
728 HBufC* data = _L("This is the data for the task").AllocLC();
731 TInt res = TheScheduler.ScheduleTask(taskInfo, *data, ref, *entryList);
732 TEST2(res, KErrNone);
734 CleanupStack::PopAndDestroy(2, entryList); // data, entryList
736 // Should be one item
737 TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 1);
739 // Waiting for entry to complete
740 TheTest.Next(_L("Waiting for task to complete"));
741 TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
743 CleanupHelpers::KillProcess(KMinimalTaskHandler);
745 // Should be no items as schedule deletes itself after task has completed
746 TEST(CountScheduledItemsL(EAllSchedules, TheScheduler) == 0);
748 SchSvrHelpers::Pause(TheTest,1);
752 //***********************************************************************************
756 @SYMTestCaseID SYSLIB-SCHSVR-CT-0271
757 @SYMTestCaseDesc Persistant schedule test with repeating task - UTC
758 @SYMTestPriority High
759 @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,
760 @SYMTestExpectedResults The test must not fail.
765 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0271 Test persistent scheduling, repeating and non-repeating task schedules"));
766 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
769 TSchedulerItemRef ref;
771 // We shouldn't have any outstanding schedules registered with the server
772 TInt count = CountScheduledItemsL(EAllSchedules, TheScheduler);
775 // This creates 3 schedule entries, each with a validity period of 20 minutes, and are
776 // due to run in 10s, 20s, and over a year ago (a year in the past)
777 TheTest.Printf(_L("Create Persistent schedule\n"));
778 TInt res = CreateSchedule1L(ref, TheScheduler);
779 TEST2(res, KErrNone);
781 // We should now have one registered schedule
782 count = CountScheduledItemsL(EAllSchedules, TheScheduler);
786 TheTest.Printf(_L("\nSchedule two tasks: one repeating....\n"));
789 TName name1 = (_L("web subscription(rpts)"));
790 // -1 indicates repeating schedule
791 res = SchedulePersistentTaskL(name1, task1, ref.iHandle, -1, TheScheduler); // -1 indicates repeat until explicitly deleted
792 TEST2(res, KErrNone);
794 // List those schedules that are pending
795 count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
799 TheTest.Printf(_L("\n... and one non-repeating\n"));
802 TName name2 = (_L("non-repeating"));
803 res = SchedulePersistentTaskL(name2, task2, ref.iHandle, 1, TheScheduler); // only runs once
804 TEST2(res, KErrNone);
806 TheTest.Printf(_L("Waiting for tasks to run\n"));
807 // Wait for notification that schedule has executed.
808 TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
810 CleanupHelpers::KillProcess(KMinimalTaskHandler);
812 TheTest.Printf(_L("...and wait again for repeating one to execute again\n"));
813 // Wait for notification that schedule has executed.
814 TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
816 CleanupHelpers::KillProcess
817 (KMinimalTaskHandler);
819 TheTest.Printf(_L("Delete the repeating task, and the schedule \n"));
820 res = TheScheduler.DeleteTask(task1);
821 TEST2(res, KErrNone);
822 res = TheScheduler.DeleteTask(task2);
823 TEST2(res, KErrNotFound); //Should be not found since its only executed once.
824 res = TheScheduler.DeleteSchedule(ref.iHandle);
825 TEST2(res, KErrNone);
827 count = CountScheduledItemsL(EPendingSchedules, TheScheduler);
829 SchSvrHelpers::Pause(TheTest,1);
833 static CSchEntryInfoArray* CreateSchEntryInfoArrayLC(TInt aGranularity)
835 CSchEntryInfoArray* scheduleEntries = new (ELeave) CSchEntryInfoArray(aGranularity);
836 CleanupStack::PushL(scheduleEntries);
837 return scheduleEntries;
840 static CArrayFixFlat<TTaskInfo>* CreateTaskInfoLC(TInt aGranularity)
842 CArrayFixFlat<TTaskInfo>* taskInfos = new (ELeave) CArrayFixFlat<TTaskInfo>(aGranularity);
843 CleanupStack::PushL(taskInfos);
847 static CSchItemRefArray* CreateScheduleRefsLC(TInt aGranularity)
849 CSchItemRefArray* scheduleReferences = new (ELeave) CSchItemRefArray(aGranularity);
850 CleanupStack::PushL(scheduleReferences);
851 return scheduleReferences;
854 static void CreateTransientScheduledTasksL(TInt aNumScheduleEntries,
856 CSchEntryInfoArray* aScheduleEntries,
857 CArrayFixFlat<TTaskInfo>* aTaskInfos,
858 CSchItemRefArray* aScheduleReferences)
860 const TTimeIntervalMicroSeconds timeToAdd = 10000000; //10 seconds
861 const TTimeIntervalMicroSeconds timeLimit = 5000000; // 5 seconds
862 _LIT(KTaskDataPrefix, "Task Data Entry: ");
863 // Prepare keys required
864 TKeyArrayFix KTaskInfoSortKey(_FOFF(TTaskInfo, iTaskId), ECmpTInt);
866 for(TInt i=0;i<aNumSchedules;i++)
868 // Remove any existing schedule entry info's
869 aScheduleEntries->Reset();
871 // Populate the schedule entry array with a varying list of
872 // start-times, intervals, etc for this particular task
874 for(TInt j=0; j<aNumScheduleEntries; ++j)
876 TScheduleEntryInfo2 scheduleEntry = SchSvrHelpers::RandomScheduleEntryInfoUtc(TheSeed);
878 now.HomeTime(); // sets now to home time
879 TTime sTime = scheduleEntry.StartTime().GetUtcTime();
880 //if scheduleEntry.StartTime() is set lower then 5 sec into the future, postpone StartTime 10 sec into the future
881 if(sTime < now + timeLimit)
883 TTsTime newTime (now + timeToAdd, ETrue);
884 scheduleEntry.SetStartTime(newTime);
886 aScheduleEntries->AppendL(scheduleEntry);
889 // Create some dummy task data
891 HBufC* taskData = HBufC::NewLC(KTaskDataPrefix().Length()+4);
892 taskData->Des().Copy(KTaskDataPrefix());
893 taskData->Des().AppendNum(i);
895 // Munge the task name
898 taskInfo.iName = *taskData;
899 taskInfo.iRepeat = 1;
900 taskInfo.iPriority = 1;
901 // Schedule the transient task
902 TSchedulerItemRef scheduleReference;
903 TInt result = TheScheduler.ScheduleTask(taskInfo,
907 TEST2(result, KErrNone);
908 TheTest.Printf(_L("TaskId: %d => TaskName: %S\n"), taskInfo.iTaskId, &taskInfo.iName);
909 CleanupStack::PopAndDestroy(taskData);
911 // Save the taskInfo so we can check it later - this inserts the taskinfo into
912 // the array (preserves sorted order by TTaskInfo.iTaskId) but also has the
913 // added bonus of preventing duplicate task ids...
915 aTaskInfos->InsertIsqL(taskInfo, KTaskInfoSortKey);
916 // Disable all schedules once added, just to stop them going off
917 // and therefore being deleted when we are trying to compare them
918 result = TheScheduler.DisableSchedule(scheduleReference.iHandle);
919 TEST2(result, KErrNone);
920 // Save the sever generated schedule reference and taskId for checking later
921 aScheduleReferences->AppendL(scheduleReference);
925 static void CheckScheduledRefs(TInt aNumSchedules)
927 CSchItemRefArray* refs = new (ELeave) CSchItemRefArray(3);
928 CleanupStack::PushL(refs);
929 TInt res = TheScheduler.GetScheduleRefsL(*refs, EAllSchedules);
930 TEST2(res, KErrNone);
931 TInt count = refs->Count();
932 TEST(count == aNumSchedules);
933 CleanupStack::PopAndDestroy(refs);
936 static void TestScheduledTasksL(TInt aNumSchedules,
937 CArrayFixFlat<TTaskInfo>* aTaskInfos)
939 for(TInt n=0; n<aNumSchedules; ++n)
941 const TTaskInfo& taskInfo = aTaskInfos->At(n);
943 // First retrieve the task size
945 TInt result = TheScheduler.GetTaskDataSize(taskInfo.iTaskId, taskSize);
946 TEST2(result, KErrNone);
949 // Next retrieve the task info associated with a particular task Id
950 HBufC* taskData = HBufC::NewLC(taskSize);
951 TPtr pTaskData = taskData->Des();
953 TTsTime scheduleNextDueTime;
954 TTaskInfo taskFromServer;
955 TSchedulerItemRef scheduleReference;
957 result = TheScheduler.GetTaskInfoL(taskInfo.iTaskId,
961 scheduleNextDueTime);
962 TEST2(result, KErrNone);
963 TEST(taskData->Length() == taskSize);
965 // Now check that the task returned by the server matches that held locallly....
966 TBool bbb = SchSvrHelpers::IsTaskInfoTheSame(taskFromServer, taskInfo);
969 RDebug::Print(_L("TaskInfo1. repeat=%x, id=%d, name=%S, priority=%x\n"),
970 taskFromServer.iRepeat, taskFromServer.iTaskId, &taskFromServer.iName, taskFromServer.iPriority);
971 RDebug::Print(_L("TaskInfo2. repeat=%x, id=%d, name=%S, priority=%x\n"),
972 taskInfo.iRepeat, taskInfo.iTaskId, &taskInfo.iName, taskInfo.iPriority);
976 // Check taskData is the same (was originally held in the TTaskInfo.iName field)
977 const TDesC& des1 = taskInfo.iName;
978 TDes& des2 = pTaskData;
980 CleanupStack::PopAndDestroy(taskData);
984 //***********************************************************************************
988 @SYMTestCaseID SYSLIB-SCHSVR-CT-0272
989 @SYMTestCaseDesc Large number of tasks test - UTC
990 @SYMTestPriority High
991 @SYMTestActions Create a large number of tasks, test retrieval of task data and task info
992 @SYMTestExpectedResults The test must not fail.
998 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0272 Create a large number of tasks, test retrieval of task data and task info"));
1000 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1002 // Constants used in this function
1003 const TInt KNumberOfSchedulesToCreate = 20;
1004 const TInt KNumberOfScheduleEntriesToCreate = 5;
1006 // Prepare arrays required for the tests below
1007 CSchEntryInfoArray* scheduleEntries = ::CreateSchEntryInfoArrayLC(KNumberOfScheduleEntriesToCreate);
1008 CArrayFixFlat<TTaskInfo>* taskInfos = ::CreateTaskInfoLC(KNumberOfSchedulesToCreate);
1009 CSchItemRefArray* scheduleReferences = ::CreateScheduleRefsLC(KNumberOfSchedulesToCreate);
1012 // Create a large number of transient scheduled tasks
1013 // to test Id generation
1015 ::CreateTransientScheduledTasksL(KNumberOfScheduleEntriesToCreate,
1016 KNumberOfSchedulesToCreate,
1019 scheduleReferences);
1022 ::CheckScheduledRefs(KNumberOfSchedulesToCreate);
1024 // Test tasks for a given taskid is the same
1025 ::TestScheduledTasksL(KNumberOfSchedulesToCreate, taskInfos);
1027 // Test reference can be retrieved for a given handle.
1028 CleanupStack::PopAndDestroy(scheduleReferences);
1029 CleanupStack::PopAndDestroy(taskInfos);
1030 CleanupStack::PopAndDestroy(scheduleEntries);
1032 // now delete all schedules
1033 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1034 TInt ccc = CountScheduledItemsL(EAllSchedules, TheScheduler);
1037 SchSvrHelpers::Pause(TheTest,1);
1040 //***********************************************************************************
1041 static TInt RunTestsL()
1043 TheTest.Next(_L("Delete old files"));
1044 SchSvrHelpers::DeleteScheduleFilesL();
1046 TheTest.Next(_L("Create Task notification semaphore"));
1047 //initialise task notification semaphore
1051 // Prepare random number seed
1052 TheTest.Next(_L("Prepare random number"));
1054 now.UniversalTime();
1055 TheSeed = now.Int64();
1057 // Connect to the server
1058 TheTest.Next(_L("===== Connect to Scheduler ====="));
1059 TInt res = TheScheduler.Connect();
1060 TEST2(res, KErrNone);
1062 // Register a client with the server
1063 TheTest.Next(_L("===== Registering Client ====="));
1064 res = SchSvrHelpers::RegisterClientL(TheScheduler);
1065 TEST2(res, KErrNone);
1067 TheTest.Next(_L("Start tests"));
1077 TheTest.Next(_L("Tidying up"));
1078 //Tidying up so next test will be clear.
1079 TheTest.Next(_L("Delete all schedules"));
1080 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
1081 SchSvrHelpers::Pause(TheTest, 2);
1082 TheTest.Next(_L("Delete old files\n"));
1083 SchSvrHelpers::DeleteScheduleFilesL();
1085 TheScheduler.Close();
1087 //close handle to semaphore
1093 //***********************************************************************************
1094 GLDEF_C TInt E32Main()
1096 // TheTest the scheduler
1100 TheTest.Start(_L("TC_TSCH_SCHEDULING2 - UTC"));
1103 TheCleanup = CTrapCleanup::New();
1104 //If the previous test fails, SCHSVR.exe may stay in memory.
1105 TRAPD(error,CleanupHelpers::TestCleanupL());
1106 TEST2(error, KErrNone);
1110 // Used to Set the system UTC time and UTC offset
1111 // so that correct UTC Time values are returned while using time based APIs.
1112 SchSvrHelpers::SetHomeTimeL(now);
1114 TEST2(TheFsSession.Connect(), KErrNone);;
1115 TRAP(error, RunTestsL());
1116 TRAP(error,CleanupHelpers::TestCleanupL());
1117 TEST2(error, KErrNone);
1120 TheFsSession.Close();