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 - hometime"));
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().GetLocalTime().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, EFalse);
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,EFalse);
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, EFalse);
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,EFalse);
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-0273
374 @SYMTestCaseDesc Year2000 replicated test, boundary test - Hometime
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 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0273 "));
383 TDateTime dateTime(1998, EAugust, 1, 17, 0, 0, 0);
385 TSchedulerItemRef ref;
386 TInt count = testCreateBoundarySchedule1(ref);
388 taskId = testScheduleTask(ref.iHandle);
389 doTestLoopL(ref.iHandle, count);
390 TInt res = TheScheduler.DeleteTask(taskId);
391 TEST2(res, KErrNone);
392 res = TheScheduler.DeleteSchedule(ref.iHandle);
393 TEST2(res, KErrNone);
396 count = testCreateBoundarySchedule2(ref);
397 taskId = testScheduleTask(ref.iHandle);
398 doTestLoopL(ref.iHandle, count);
399 TheScheduler.DeleteTask(taskId);
400 TheScheduler.DeleteSchedule(ref.iHandle);
403 LOCAL_D void doHourlyTimeSpanTestL()
405 TDateTime dateTime(1999, EAugust, 1, 17, 0, 0, 0);
407 TSchedulerItemRef ref;
408 TInt count = testCreateHourlyTimeSpanSchedule1(ref);
410 taskId = testScheduleTask(ref.iHandle);
411 doTestLoopL(ref.iHandle, count);
412 TInt res = TheScheduler.DeleteTask(taskId);
413 TEST2(res, KErrNone);
414 res = TheScheduler.DeleteSchedule(ref.iHandle);
415 TEST2(res, KErrNone);
417 TDateTime dt2(2000, EAugust,1,17,0,0,0);
419 count = testCreateHourlyTimeSpanSchedule2(ref);
420 taskId = testScheduleTask(ref.iHandle);
421 doTestLoopL(ref.iHandle, count);
422 TheScheduler.DeleteTask(taskId);
423 TheScheduler.DeleteSchedule(ref.iHandle);
426 LOCAL_D void doDailyTimeSpanTestL()
428 TDateTime dateTime(1999, EAugust, 1, 17, 0, 0, 0);
430 TSchedulerItemRef ref;
431 TInt count = testCreateDailyTimeSpanSchedule1(ref);
433 taskId = testScheduleTask(ref.iHandle);
434 doTestLoopL(ref.iHandle, count);
435 TInt res = TheScheduler.DeleteTask(taskId);
436 TEST2(res, KErrNone);
437 res = TheScheduler.DeleteSchedule(ref.iHandle);
438 TEST2(res, KErrNone);
440 TDateTime dt2(2000, EAugust,1,17,0,0,0);
442 count = testCreateDailyTimeSpanSchedule2(ref);
443 taskId = testScheduleTask(ref.iHandle);
444 doTestLoopL(ref.iHandle, count);
445 TheScheduler.DeleteTask(taskId);
446 TheScheduler.DeleteSchedule(ref.iHandle);
449 LOCAL_D void doMonthlyTimeSpanTestL()
452 TDateTime dateTime(1999, EAugust, 1, 17, 0, 0, 0);
454 TSchedulerItemRef ref;
455 TInt count = testCreateMonthlyTimeSpanSchedule1(ref);
457 taskId = testScheduleTask(ref.iHandle);
458 doTestLoopL(ref.iHandle, count);
459 TInt res = TheScheduler.DeleteTask(taskId);
460 TEST2(res, KErrNone);
461 res = TheScheduler.DeleteSchedule(ref.iHandle);
462 TEST2(res, KErrNone);
464 TDateTime dt2(2000, EAugust,1,17,0,0,0);
466 count = testCreateMonthlyTimeSpanSchedule2(ref);
467 taskId = testScheduleTask(ref.iHandle);
468 doTestLoopL(ref.iHandle, count);
469 TheScheduler.DeleteTask(taskId);
470 TheScheduler.DeleteSchedule(ref.iHandle);
473 LOCAL_D void doYearlyTimeSpanTestL()
476 TDateTime dateTime(1999, EAugust, 1, 17, 0, 0, 0);
478 TSchedulerItemRef ref;
479 TInt count = testCreateYearlyTimeSpanSchedule1(ref);
481 taskId = testScheduleTask(ref.iHandle);
482 doTestLoopL(ref.iHandle, count);
483 TInt res = TheScheduler.DeleteTask(taskId);
484 TEST2(res, KErrNone);
485 res = TheScheduler.DeleteSchedule(ref.iHandle);
486 TEST2(res, KErrNone);
488 TDateTime dt2(2000, EAugust,1,17,0,0,0);
490 count = testCreateYearlyTimeSpanSchedule2(ref);
491 taskId = testScheduleTask(ref.iHandle);
492 doTestLoopL(ref.iHandle, count);
493 TheScheduler.DeleteTask(taskId);
494 TheScheduler.DeleteSchedule(ref.iHandle);
499 @SYMTestCaseID SYSLIB-SCHSVR-CT-0274
500 @SYMTestCaseDesc Year2000 replicated test, time span test - Hometime
501 @SYMTestPriority High
502 @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
503 @SYMTestExpectedResults The test must not fail.
506 LOCAL_D void doTimeSpanTestL()
509 TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0274 "));
510 TheTest.Printf(_L("\nTesting time-spans...\n"));
511 TheTest.Printf(_L("Hourly time-spans...\n"));
512 doHourlyTimeSpanTestL();
513 TheTest.Printf(_L("Daily time-spans...\n"));
514 doDailyTimeSpanTestL();
515 TheTest.Printf(_L("Monthly time-spans...\n"));
516 doMonthlyTimeSpanTestL();
517 TheTest.Printf(_L("Yearly time-spans...\n"));
518 doYearlyTimeSpanTestL();
521 static void DoTestsL()
523 TheTest.Next(_L("Delete old files"));
524 SchSvrHelpers::DeleteScheduleFilesL();
526 TheTest.Next(_L("Connect to Scheduler"));
527 TInt res=TheScheduler.Connect();
528 TEST2(res, KErrNone);
530 TheTest.Next(_L("Registering Client"));
531 res = SchSvrHelpers::RegisterClientL(TheScheduler);
532 TEST2(res, KErrNone);
534 // Create exe Semaphore
538 TheTest.Next(_L("Boundary/valid dates testing"));
540 TheTest.Next(_L("Time span testing"));
543 // close exe Semaphore
546 //Tidying up so next test will be clear.
547 TheTest.Next(_L("Delete all schedules"));
548 SchSvrHelpers::DeleteAllSchedulesL(TheScheduler);
549 TheScheduler.Close();
552 GLDEF_C TInt E32Main()
556 CTrapCleanup* cleanup = CTrapCleanup::New();
557 TEST(cleanup != NULL);
559 TEST2(TheFsSession.Connect(), KErrNone);
562 TheTest.Start(_L("Year 2000 - hometime"));
564 //If the previous test fails, SCHSVR.exe may stay in memory.
565 TRAPD(err,CleanupHelpers::TestCleanupL());
566 TEST2(err, KErrNone);
568 TRAP(err, DoTestsL());
570 TRAP(err,CleanupHelpers::TestCleanupL());
571 TEST2(err, KErrNone);
574 TheFsSession.Close();