First public contribution.
1 // Copyright (c) 2003-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.
21 #include "TestUtils.h"
23 RTest TheTest(_L("TC_TSCH_YEAR2000 - UTC"));
24 LOCAL_D RFs TheFsSession;
26 LOCAL_D RScheduler TheScheduler;
28 _LIT(KMinimalTaskHandler, "MinimalTaskHandler");
30 LOCAL_D void SetTimeTo1SecBefore(TTsTime& aTime)
32 // TTsTime class can return UTC or Local time values.
33 // to ensure these are calculated based on the correct offset,
34 // use GetLocalTime() for local time based TTsTime values,
35 // and GetUtcTime() for UTC based TTsTime values.
38 TTimeIntervalSeconds secs(1);
41 // If time is UTC based, use UTC apis. If time is local time based, use local time APIs.
44 time = aTime.GetUtcTime() - secs;
45 SchSvrHelpers::SetUTCTimeL(time);
47 time.FormatL(dateString,(_L("%H%:1%T:%S %*E%*D %X%*N%Y %1 %2 %3")));
48 TheTest.Printf(_L("current UTC time: %S\n"), &dateString);
50 else // due time is local time based
52 time = aTime.GetLocalTime() - secs;
53 SchSvrHelpers::SetHomeTimeL(time);
55 time.FormatL(dateString,(_L("%H%:1%T:%S %*E%*D %X%*N%Y %1 %2 %3")));
56 TheTest.Printf(_L("current local time: %S\n"), &dateString);
60 LOCAL_D void SetTime(TDateTime& aDateTime)
62 TTime time(aDateTime);
63 SchSvrHelpers::SetHomeTimeL(time);
66 LOCAL_D TTsTime ShowDueTime(TInt aScheduleId)
68 TScheduleState2 state;
70 CArrayFixFlat<TScheduleEntryInfo2>* entries = new CArrayFixFlat<TScheduleEntryInfo2> (3);
71 CArrayFixFlat<TTaskInfo>* tasks = new CArrayFixFlat<TTaskInfo> (3);
72 TInt res = TheScheduler.GetScheduleL(aScheduleId, state, *entries, *tasks, dueTime);
79 state.DueTime().GetUtcTime().FormatL(dateString,(_L("%H%:1%T%*E%*D%X%*N%Y %1 %2 %3")));
80 TheTest.Printf(_L("due at:%S\n"), &dateString);
81 return state.DueTime();
84 LOCAL_D void AppendHourlyEntry(CArrayFixFlat<TScheduleEntryInfo2>& aEntries, TInt aInterval,TInt aYear,
85 TMonth aMonth, TInt aDay, TInt aHour, TInt aMinute)
87 TTime ttime(TDateTime(aYear, aMonth, aDay, aHour, aMinute, 0,0));
88 TTsTime startTime (ttime,ETrue);
89 TScheduleEntryInfo2 entry1 (startTime, EHourly, aInterval, 0);
90 aEntries.AppendL(entry1);
93 LOCAL_D void AppendDailyEntry(CArrayFixFlat<TScheduleEntryInfo2>& aEntries, TInt aInterval,TInt aYear,
94 TMonth aMonth, TInt aDay, TInt aHour, TInt aMinute)
96 TTime ttime(TDateTime(aYear, aMonth, aDay, aHour, aMinute, 0,0));
97 TTsTime startTime (ttime,ETrue);
98 TScheduleEntryInfo2 entry1 (startTime, EDaily, aInterval, 0);
99 aEntries.AppendL(entry1);
102 LOCAL_D void AppendMonthlyEntry(CArrayFixFlat<TScheduleEntryInfo2>& aEntries, TInt aInterval,
103 TInt aYear, TMonth aMonth, TInt aDate, TInt aHour,TInt aMinute)
105 TTime ttime(TDateTime(aYear, aMonth, aDate, aHour, aMinute, 0,0));
106 TTsTime startTime (ttime,ETrue);
107 TScheduleEntryInfo2 entry1 (startTime, EMonthly, aInterval, 0);
108 aEntries.AppendL(entry1);
111 LOCAL_D void AppendYearlyEntry(CArrayFixFlat<TScheduleEntryInfo2>& aEntries, TInt aInterval,
112 TInt aYear, TMonth aMonth,TInt aDate, TInt aHour, TInt aMinute)
114 TTime ttime(TDateTime(aYear, aMonth, aDate, aHour, aMinute, 0,0));
115 TTsTime startTime (ttime,ETrue);
116 TScheduleEntryInfo2 entry1 (startTime, EYearly, aInterval, 0);
117 aEntries.AppendL(entry1);
121 LOCAL_D TInt testCreateBoundarySchedule1(TSchedulerItemRef& aRef)
123 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
124 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
125 TName name(_L("and another off-peak"));
128 //times post-boundary (to show boundary crossed properly)
129 AppendYearlyEntry(*entryList, 10, 1999, EJanuary, 0, 0, 0);
130 AppendYearlyEntry(*entryList, 10, 1999, EFebruary, 27, 0, 0);
131 AppendYearlyEntry(*entryList, 10, 1999, EMarch, 0, 0, 0);
132 AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 0, 0, 0);
133 AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 8, 0, 0);
134 AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 9, 0, 0);
135 AppendYearlyEntry(*entryList, 10, 2000, EJanuary, 0, 0, 0);
136 AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 27, 0, 0);
137 AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 28, 0, 0);
138 AppendYearlyEntry(*entryList, 10, 2000, EMarch, 0, 0, 0);
139 AppendYearlyEntry(*entryList, 10, 2001, EJanuary, 0, 0, 0);
140 AppendYearlyEntry(*entryList, 10, 2001, EMarch, 0, 0, 0);
141 AppendYearlyEntry(*entryList, 10, 2004, EFebruary, 28, 0, 0);
142 AppendYearlyEntry(*entryList, 10, 2004, EMarch, 0, 0, 0);
144 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
145 TEST2(res, KErrNone);
146 TInt count = entryList->Count();
151 LOCAL_D TInt testCreateBoundarySchedule2(TSchedulerItemRef& aRef)
153 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
154 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
155 TName name(_L("and another off-peak"));
158 //times on pre-boundary dates(to show they're recognized as valid)
159 //commented-out lines are handled below
160 AppendYearlyEntry(*entryList, 10, 1998, EDecember, 30, 0, 0);
161 AppendYearlyEntry(*entryList, 10, 1999, EFebruary, 26, 0, 0);
162 // AppendYearlyEntry(*entryList, 10, 1999, EFebruary, 27, 0, 0);
163 AppendYearlyEntry(*entryList, 10, 1999, EAugust, 30, 0, 0);
164 AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 7, 0, 0);
165 // AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 8, 0, 0);
166 AppendYearlyEntry(*entryList, 10, 1999, EDecember, 30, 0, 0);
167 AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 26, 0, 0);
168 // AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 27, 0, 0);
169 // AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 28, 0, 0);
170 AppendYearlyEntry(*entryList, 10, 2000, EDecember, 30, 0, 0);
171 AppendYearlyEntry(*entryList, 10, 2001, EFebruary, 27, 0, 0);
172 AppendYearlyEntry(*entryList, 10, 2004, EFebruary, 27, 0, 0);
173 //AppendYearlyEntry(*entryList, 10, 2004, EFebruary, 28, 0, 0);
174 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
175 TEST2(res, KErrNone);
177 TInt count = entryList->Count();
182 LOCAL_D TInt testCreateHourlyTimeSpanSchedule1(TSchedulerItemRef& aRef)
184 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
185 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
186 TName name(_L("and another off-peak"));
189 AppendHourlyEntry(*entryList, 213*24, 1999, EJune, 0, 0, 0);
190 AppendHourlyEntry(*entryList, 214*24, 1999, EJune, 0, 0, 0);
191 AppendHourlyEntry(*entryList, 273*24, 1999, EJune, 0, 0, 0);
192 AppendHourlyEntry(*entryList, 274*24, 1999, EJune, 0, 0, 0);
193 AppendHourlyEntry(*entryList, 305*24, 1999, EJune, 0, 0, 0);
194 AppendHourlyEntry(*entryList, 366*24, 1999, EJuly, 0, 0, 0);
196 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
197 TEST2(res, KErrNone);
199 TInt count = entryList->Count();
204 LOCAL_D TInt testCreateHourlyTimeSpanSchedule2(TSchedulerItemRef& aRef)
206 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
207 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
208 TName name(_L("and another off-peak"));
211 AppendHourlyEntry(*entryList, 365*24, 2000, EAugust, 0, 0, 0);
213 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
214 TEST2(res, KErrNone);
216 TInt count = entryList->Count();
221 LOCAL_D TInt testCreateDailyTimeSpanSchedule1(TSchedulerItemRef& aRef)
223 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
224 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
225 TName name(_L("and another off-peak"));
228 AppendDailyEntry(*entryList, 213, 1999, EJune, 0, 0, 0);
229 AppendDailyEntry(*entryList, 214, 1999, EJune, 0, 0, 0);
230 AppendDailyEntry(*entryList, 273, 1999, EJune, 0, 0, 0);
231 AppendDailyEntry(*entryList, 274, 1999, EJune, 0, 0, 0);
232 AppendDailyEntry(*entryList, 305, 1999, EJune, 0, 0, 0);
233 AppendDailyEntry(*entryList, 366, 1999, EJuly, 0, 0, 0);
235 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
236 TEST2(res, KErrNone);
238 TInt count = entryList->Count();
243 LOCAL_D TInt testCreateDailyTimeSpanSchedule2(TSchedulerItemRef& aRef)
245 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
246 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
247 TName name(_L("and another off-peak"));
250 AppendDailyEntry(*entryList, 365, 2000, EAugust, 0, 0, 0);
252 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
253 TEST2(res, KErrNone);
255 TInt count = entryList->Count();
260 LOCAL_D TInt testCreateMonthlyTimeSpanSchedule1(TSchedulerItemRef& aRef)
262 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
263 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
264 TName name(_L("and another off-peak"));
267 AppendMonthlyEntry(*entryList, 7, 1999, EMay, 30, 0, 0);
268 AppendMonthlyEntry(*entryList, 7, 1999, EJune, 0, 0, 0);
269 AppendMonthlyEntry(*entryList, 8, 1999, EJune, 29, 0, 0);
270 AppendMonthlyEntry(*entryList, 8, 1999, EJuly, 0, 0, 0);
271 AppendMonthlyEntry(*entryList, 9, 1999, EJuly, 0, 0, 0);
272 AppendMonthlyEntry(*entryList, 12, 1999, EJuly, 0, 0, 0);
274 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
275 TEST2(res, KErrNone);
277 TInt count = entryList->Count();
283 LOCAL_D TInt testCreateMonthlyTimeSpanSchedule2(TSchedulerItemRef& aRef)
285 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
286 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
287 TName name(_L("and another off-peak"));
290 AppendMonthlyEntry(*entryList, 12, 2000, EAugust, 0, 0, 0);
292 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
293 TEST2(res, KErrNone);
295 TInt count = entryList->Count();
300 LOCAL_D TInt testCreateYearlyTimeSpanSchedule1(TSchedulerItemRef& aRef)
302 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
303 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
304 TName name(_L("and another off-peak"));
307 AppendYearlyEntry(*entryList, 1, 1998, EDecember, 30, 0, 0);
308 AppendYearlyEntry(*entryList, 1, 1999, EJanuary, 0, 0, 0);
309 AppendYearlyEntry(*entryList, 1, 1999, EFebruary, 27, 0, 0);
310 AppendYearlyEntry(*entryList, 1, 1999, EMarch, 0, 0, 0);
311 AppendYearlyEntry(*entryList, 1, 1999, EApril, 0, 0, 0);
312 AppendYearlyEntry(*entryList, 1, 1999, EJuly, 0, 0, 0);
314 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
315 TEST2(res, KErrNone);
317 TInt count = entryList->Count();
323 LOCAL_D TInt testCreateYearlyTimeSpanSchedule2(TSchedulerItemRef& aRef)
325 CArrayFixFlat<TScheduleEntryInfo2>* entryList;
326 entryList = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(3);
327 TName name(_L("and another off-peak"));
330 AppendYearlyEntry(*entryList, 1, 2000, EAugust, 0, 0, 0);
332 TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList);
333 TEST2(res, KErrNone);
335 TInt count = entryList->Count();
341 LOCAL_D TInt testScheduleTask(TInt aScheduleId)
343 HBufC* data = HBufC::NewL(20);
344 *data = _L("the data");
346 taskInfo.iTaskId = 0;
347 taskInfo.iName = (_L("Y2K testing"));
348 taskInfo.iPriority = 2;
349 taskInfo.iRepeat = -1;
350 TInt res = TheScheduler.ScheduleTask(taskInfo, *data, aScheduleId);
351 TEST2(res, KErrNone);
353 return taskInfo.iTaskId;
356 LOCAL_D void doTestLoopL(TInt aId, TInt aCount)
358 TTsTime time = ShowDueTime(aId);
359 for (TInt i=0;i<aCount;i++)
361 SetTimeTo1SecBefore(time);
362 //wait for exe to launch
363 TEST2(STaskSemaphore::WaitL(KDefaultTimeout), KErrNone);
364 CleanupHelpers::KillProcess(KMinimalTaskHandler);
366 if (i<(aCount-1))//i.e. if it's going to execute
367 time = ShowDueTime(aId);
373 @SYMTestCaseID SYSLIB-SCHSVR-CT-0275
374 @SYMTestCaseDesc Year2000 replicated test, boundary test - UTC
375 @SYMTestPriority High
376 @SYMTestActions Create a schedules, with one entry for each boundary pair & with a task to execute immediately after boundary set time to 5 seconds before each boundary, task should be executed in 5 seconds - also ensures all (pre-and-)post boundary times are valid, also reports the day on each of these dates
377 @SYMTestExpectedResults The test must not fail.
380 LOCAL_D void doBoundaryTestL()
382 TDateTime dateTime(1998, EAugust, 1, 17, 0, 0, 0);
384 TSchedulerItemRef ref;
385 TInt count = testCreateBoundarySchedule1(ref);
387 taskId = testScheduleTask(ref.iHandle);
388 doTestLoopL(ref.iHandle, count);
389 TInt res = TheScheduler.DeleteTask(taskId);
390 TEST2(res, KErrNone);
391 res = TheScheduler.DeleteSchedule(ref.iHandle);
392 TEST2(res, KErrNone);
395 count = testCreateBoundarySchedule2(ref);
396 taskId = testScheduleTask(ref.iHandle);
397 doTestLoopL(ref.iHandle, count);
398 TheScheduler.DeleteTask(taskId);
399 TheScheduler.DeleteSchedule(ref.iHandle);
402 LOCAL_D void doHourlyTimeSpanTestL()
404 TDateTime dateTime(1999, EAugust, 1, 17, 0, 0, 0);
406 TSchedulerItemRef ref;
407 TInt count = testCreateHourlyTimeSpanSchedule1(ref);
409 taskId = testScheduleTask(ref.iHandle);
410 doTestLoopL(ref.iHandle, count);
411 TInt res = TheScheduler.DeleteTask(taskId);
412 TEST2(res, KErrNone);
413 res = TheScheduler.DeleteSchedule(ref.iHandle);
414 TEST2(res, KErrNone);
416 TDateTime dt2(2000, EAugust,1,17,0,0,0);
418 count = testCreateHourlyTimeSpanSchedule2(ref);
419 taskId = testScheduleTask(ref.iHandle);
420 doTestLoopL(ref.iHandle, count);
421 TheScheduler.DeleteTask(taskId);
422 TheScheduler.DeleteSchedule(ref.iHandle);
425 LOCAL_D void doDailyTimeSpanTestL()
427 TDateTime dateTime(1999, EAugust, 1, 17, 0, 0, 0);
429 TSchedulerItemRef ref;
430 TInt count = testCreateDailyTimeSpanSchedule1(ref);
432 taskId = testScheduleTask(ref.iHandle);
433 doTestLoopL(ref.iHandle, count);
434 TInt res = TheScheduler.DeleteTask(taskId);
435 TEST2(res, KErrNone);
436 res = TheScheduler.DeleteSchedule(ref.iHandle);
437 TEST2(res, KErrNone);
439 TDateTime dt2(2000, EAugust,1,17,0,0,0);
441 count = testCreateDailyTimeSpanSchedule2(ref);
442 taskId = testScheduleTask(ref.iHandle);
443 doTestLoopL(ref.iHandle, count);
444 TheScheduler.DeleteTask(taskId);
445 TheScheduler.DeleteSchedule(ref.iHandle);
448 LOCAL_D void doMonthlyTimeSpanTestL()
451 TDateTime dateTime(1999, EAugust, 1, 17, 0, 0, 0);
453 TSchedulerItemRef ref;
454 TInt count = testCreateMonthlyTimeSpanSchedule1(ref);
456 taskId = testScheduleTask(ref.iHandle);
457 doTestLoopL(ref.iHandle, count);
458 TInt res = TheScheduler.DeleteTask(taskId);
459 TEST2(res, KErrNone);
460 res = TheScheduler.DeleteSchedule(ref.iHandle);
461 TEST2(res, KErrNone);
463 TDateTime dt2(2000, EAugust,1,17,0,0,0);
465 count = testCreateMonthlyTimeSpanSchedule2(ref);
466 taskId = testScheduleTask(ref.iHandle);
467 doTestLoopL(ref.iHandle, count);
468 TheScheduler.DeleteTask(taskId);
469 TheScheduler.DeleteSchedule(ref.iHandle);
472 LOCAL_D void doYearlyTimeSpanTestL()
475 TDateTime dateTime(1999, EAugust, 1, 17, 0, 0, 0);
477 TSchedulerItemRef ref;
478 TInt count = testCreateYearlyTimeSpanSchedule1(ref);
480 taskId = testScheduleTask(ref.iHandle);
481 doTestLoopL(ref.iHandle, count);
482 TInt res = TheScheduler.DeleteTask(taskId);
483 TEST2(res, KErrNone);
484 res = TheScheduler.DeleteSchedule(ref.iHandle);
485 TEST2(res, KErrNone);
487 TDateTime dt2(2000, EAugust,1,17,0,0,0);
489 count = testCreateYearlyTimeSpanSchedule2(ref);
490 taskId = testScheduleTask(ref.iHandle);
491 doTestLoopL(ref.iHandle, count);
492 TheScheduler.DeleteTask(taskId);
493 TheScheduler.DeleteSchedule(ref.iHandle);
498 @SYMTestCaseID SYSLIB-SCHSVR-CT-0276
499 @SYMTestCaseDesc Year2000 replicated test, time span test - UTC
500 @SYMTestPriority High
501 @SYMTestActions For each time-span, a set of schedules with the interval defined in terms of hours, days, weeks, months, whose interval=the time span: then set time to some time in between start of span & end: schedules should be next due at end of each respective time-span. Test time-spans measured in days & months. So, 1 schedule for each of these, including 1 entry for each span. Each entry starts at start of span, repeats at end(defined in terms of x days/weeks/months.). For each entry, set time to just before end of span, check it goes off
502 @SYMTestExpectedResults The test must not fail.
505 LOCAL_D void doTimeSpanTestL()
507 TheTest.Printf(_L("\nTesting time-spans...\n"));
508 TheTest.Printf(_L("Hourly time-spans...\n"));
509 doHourlyTimeSpanTestL();
510 TheTest.Printf(_L("Daily time-spans...\n"));
511 doDailyTimeSpanTestL();
512 TheTest.Printf(_L("Monthly time-spans...\n"));
513 doMonthlyTimeSpanTestL();
514 TheTest.Printf(_L("Yearly time-spans...\n"));
515 doYearlyTimeSpanTestL();
518 static void DoTestsL()
520 TheTest.Next(_L("Delete old files"));
521 SchSvrHelpers::DeleteScheduleFilesL();
523 TheTest.Next(_L("Connect to Scheduler"));
524 TInt res=TheScheduler.Connect();
525 TEST2(res, KErrNone);
527 TheTest.Next(_L("Registering Client"));
528 res = SchSvrHelpers::RegisterClientL(TheScheduler);
529 TEST2(res, KErrNone);
531 // Create exe Semaphore
535 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0275 Boundary/valid dates testing "));
537 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0276 Time span testing "));
540 // close exe Semaphore
543 //Tidying up so next test will be clear.
544 TheTest.Next(_L("Delete all schedules"));
545 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
546 TheScheduler.Close();
549 GLDEF_C TInt E32Main()
553 CTrapCleanup* cleanup = CTrapCleanup::New();
554 TEST(cleanup != NULL);
556 TEST2(TheFsSession.Connect(), KErrNone);
559 TheTest.Start(_L("Year 2000 - UTC"));
561 //If the previous test fails, SCHSVR.exe may stay in memory.
562 TRAPD(err,CleanupHelpers::TestCleanupL());
563 TEST2(err, KErrNone);
565 TRAP(err, DoTestsL());
567 TRAP(err,CleanupHelpers::TestCleanupL());
568 TEST2(err, KErrNone);
571 TheFsSession.Close();