sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "Thelpers.h" sl@0: #include "TestUtils.h" sl@0: sl@0: RTest TheTest(_L("TC_TSCH_YEAR2000 - hometime")); sl@0: LOCAL_D RFs TheFsSession; sl@0: sl@0: LOCAL_D RScheduler TheScheduler; sl@0: sl@0: _LIT(KMinimalTaskHandler, "MinimalTaskHandler"); sl@0: sl@0: LOCAL_D void SetTimeTo1SecBefore(TTsTime& aTime) sl@0: { sl@0: // TTsTime class can return UTC or Local time values. sl@0: // to ensure these are calculated based on the correct offset, sl@0: // use GetLocalTime() for local time based TTsTime values, sl@0: // and GetUtcTime() for UTC based TTsTime values. sl@0: sl@0: TTime time; sl@0: TTimeIntervalSeconds secs(1); sl@0: TBuf<30> dateString; sl@0: sl@0: // If time is UTC based, use UTC apis. If time is local time based, use local time APIs. sl@0: if(aTime.IsUtc()) sl@0: { sl@0: time = aTime.GetUtcTime() - secs; sl@0: SchSvrHelpers::SetUTCTimeL(time); sl@0: sl@0: time.FormatL(dateString,(_L("%H%:1%T:%S %*E%*D %X%*N%Y %1 %2 %3"))); sl@0: TheTest.Printf(_L("current UTC time: %S\n"), &dateString); sl@0: } sl@0: else // due time is local time based sl@0: { sl@0: time = aTime.GetLocalTime() - secs; sl@0: SchSvrHelpers::SetHomeTimeL(time); sl@0: sl@0: time.FormatL(dateString,(_L("%H%:1%T:%S %*E%*D %X%*N%Y %1 %2 %3"))); sl@0: TheTest.Printf(_L("current local time: %S\n"), &dateString); sl@0: } sl@0: } sl@0: sl@0: LOCAL_D void SetTime(TDateTime& aDateTime) sl@0: { sl@0: TTime time(aDateTime); sl@0: SchSvrHelpers::SetHomeTimeL(time); sl@0: } sl@0: sl@0: LOCAL_D TTsTime ShowDueTime(TInt aScheduleId) sl@0: { sl@0: TScheduleState2 state; sl@0: TTsTime dueTime; sl@0: CArrayFixFlat* entries = new CArrayFixFlat (3); sl@0: CArrayFixFlat* tasks = new CArrayFixFlat (3); sl@0: TInt res = TheScheduler.GetScheduleL(aScheduleId, state, *entries, *tasks, dueTime); sl@0: TEST2(res, KErrNone); sl@0: sl@0: delete tasks; sl@0: delete entries; sl@0: sl@0: TBuf<30> dateString; sl@0: state.DueTime().GetLocalTime().FormatL(dateString,(_L("%H%:1%T%*E%*D%X%*N%Y %1 %2 %3"))); sl@0: TheTest.Printf(_L("due at:%S\n"), &dateString); sl@0: return state.DueTime(); sl@0: } sl@0: sl@0: LOCAL_D void AppendHourlyEntry(CArrayFixFlat& aEntries, TInt aInterval,TInt aYear, sl@0: TMonth aMonth, TInt aDay, TInt aHour, TInt aMinute) sl@0: { sl@0: TTime ttime(TDateTime(aYear, aMonth, aDay, aHour, aMinute, 0,0)); sl@0: TTsTime startTime (ttime, EFalse); sl@0: TScheduleEntryInfo2 entry1 (startTime, EHourly, aInterval, 0); sl@0: aEntries.AppendL(entry1); sl@0: } sl@0: sl@0: LOCAL_D void AppendDailyEntry(CArrayFixFlat& aEntries, TInt aInterval,TInt aYear, sl@0: TMonth aMonth, TInt aDay, TInt aHour, TInt aMinute) sl@0: { sl@0: TTime ttime(TDateTime(aYear, aMonth, aDay, aHour, aMinute, 0,0)); sl@0: TTsTime startTime (ttime,EFalse); sl@0: TScheduleEntryInfo2 entry1 (startTime, EDaily, aInterval, 0); sl@0: aEntries.AppendL(entry1); sl@0: } sl@0: sl@0: LOCAL_D void AppendMonthlyEntry(CArrayFixFlat& aEntries, TInt aInterval, sl@0: TInt aYear, TMonth aMonth, TInt aDate, TInt aHour,TInt aMinute) sl@0: { sl@0: TTime ttime(TDateTime(aYear, aMonth, aDate, aHour, aMinute, 0,0)); sl@0: TTsTime startTime (ttime, EFalse); sl@0: TScheduleEntryInfo2 entry1 (startTime, EMonthly, aInterval, 0); sl@0: aEntries.AppendL(entry1); sl@0: } sl@0: sl@0: LOCAL_D void AppendYearlyEntry(CArrayFixFlat& aEntries, TInt aInterval, sl@0: TInt aYear, TMonth aMonth,TInt aDate, TInt aHour, TInt aMinute) sl@0: { sl@0: TTime ttime(TDateTime(aYear, aMonth, aDate, aHour, aMinute, 0,0)); sl@0: TTsTime startTime (ttime,EFalse); sl@0: TScheduleEntryInfo2 entry1 (startTime, EYearly, aInterval, 0); sl@0: aEntries.AppendL(entry1); sl@0: } sl@0: sl@0: sl@0: LOCAL_D TInt testCreateBoundarySchedule1(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: //times post-boundary (to show boundary crossed properly) sl@0: AppendYearlyEntry(*entryList, 10, 1999, EJanuary, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, EFebruary, 27, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, EMarch, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 8, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 9, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2000, EJanuary, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 27, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 28, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2000, EMarch, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2001, EJanuary, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2001, EMarch, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2004, EFebruary, 28, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2004, EMarch, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: LOCAL_D TInt testCreateBoundarySchedule2(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: //times on pre-boundary dates(to show they're recognized as valid) sl@0: //commented-out lines are handled below sl@0: AppendYearlyEntry(*entryList, 10, 1998, EDecember, 30, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, EFebruary, 26, 0, 0); sl@0: // AppendYearlyEntry(*entryList, 10, 1999, EFebruary, 27, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, EAugust, 30, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 7, 0, 0); sl@0: // AppendYearlyEntry(*entryList, 10, 1999, ESeptember, 8, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 1999, EDecember, 30, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 26, 0, 0); sl@0: // AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 27, 0, 0); sl@0: // AppendYearlyEntry(*entryList, 10, 2000, EFebruary, 28, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2000, EDecember, 30, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2001, EFebruary, 27, 0, 0); sl@0: AppendYearlyEntry(*entryList, 10, 2004, EFebruary, 27, 0, 0); sl@0: //AppendYearlyEntry(*entryList, 10, 2004, EFebruary, 28, 0, 0); sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: LOCAL_D TInt testCreateHourlyTimeSpanSchedule1(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: AppendHourlyEntry(*entryList, 213*24, 1999, EJune, 0, 0, 0); sl@0: AppendHourlyEntry(*entryList, 214*24, 1999, EJune, 0, 0, 0); sl@0: AppendHourlyEntry(*entryList, 273*24, 1999, EJune, 0, 0, 0); sl@0: AppendHourlyEntry(*entryList, 274*24, 1999, EJune, 0, 0, 0); sl@0: AppendHourlyEntry(*entryList, 305*24, 1999, EJune, 0, 0, 0); sl@0: AppendHourlyEntry(*entryList, 366*24, 1999, EJuly, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: LOCAL_D TInt testCreateHourlyTimeSpanSchedule2(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: AppendHourlyEntry(*entryList, 365*24, 2000, EAugust, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: LOCAL_D TInt testCreateDailyTimeSpanSchedule1(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: AppendDailyEntry(*entryList, 213, 1999, EJune, 0, 0, 0); sl@0: AppendDailyEntry(*entryList, 214, 1999, EJune, 0, 0, 0); sl@0: AppendDailyEntry(*entryList, 273, 1999, EJune, 0, 0, 0); sl@0: AppendDailyEntry(*entryList, 274, 1999, EJune, 0, 0, 0); sl@0: AppendDailyEntry(*entryList, 305, 1999, EJune, 0, 0, 0); sl@0: AppendDailyEntry(*entryList, 366, 1999, EJuly, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: LOCAL_D TInt testCreateDailyTimeSpanSchedule2(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: AppendDailyEntry(*entryList, 365, 2000, EAugust, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: LOCAL_D TInt testCreateMonthlyTimeSpanSchedule1(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: AppendMonthlyEntry(*entryList, 7, 1999, EMay, 30, 0, 0); sl@0: AppendMonthlyEntry(*entryList, 7, 1999, EJune, 0, 0, 0); sl@0: AppendMonthlyEntry(*entryList, 8, 1999, EJune, 29, 0, 0); sl@0: AppendMonthlyEntry(*entryList, 8, 1999, EJuly, 0, 0, 0); sl@0: AppendMonthlyEntry(*entryList, 9, 1999, EJuly, 0, 0, 0); sl@0: AppendMonthlyEntry(*entryList, 12, 1999, EJuly, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: sl@0: LOCAL_D TInt testCreateMonthlyTimeSpanSchedule2(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: AppendMonthlyEntry(*entryList, 12, 2000, EAugust, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: LOCAL_D TInt testCreateYearlyTimeSpanSchedule1(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: AppendYearlyEntry(*entryList, 1, 1998, EDecember, 30, 0, 0); sl@0: AppendYearlyEntry(*entryList, 1, 1999, EJanuary, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 1, 1999, EFebruary, 27, 0, 0); sl@0: AppendYearlyEntry(*entryList, 1, 1999, EMarch, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 1, 1999, EApril, 0, 0, 0); sl@0: AppendYearlyEntry(*entryList, 1, 1999, EJuly, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: sl@0: LOCAL_D TInt testCreateYearlyTimeSpanSchedule2(TSchedulerItemRef& aRef) sl@0: { sl@0: CArrayFixFlat* entryList; sl@0: entryList = new (ELeave) CArrayFixFlat(3); sl@0: TName name(_L("and another off-peak")); sl@0: aRef.iName = name; sl@0: sl@0: AppendYearlyEntry(*entryList, 1, 2000, EAugust, 0, 0, 0); sl@0: sl@0: TInt res = TheScheduler.CreatePersistentSchedule(aRef, *entryList); sl@0: TEST2(res, KErrNone); sl@0: sl@0: TInt count = entryList->Count(); sl@0: delete entryList; sl@0: return count; sl@0: } sl@0: sl@0: sl@0: LOCAL_D TInt testScheduleTask(TInt aScheduleId) sl@0: { sl@0: HBufC* data = HBufC::NewL(20); sl@0: *data = _L("the data"); sl@0: TTaskInfo taskInfo; sl@0: taskInfo.iTaskId = 0; sl@0: taskInfo.iName = (_L("Y2K testing")); sl@0: taskInfo.iPriority = 2; sl@0: taskInfo.iRepeat = -1; sl@0: TInt res = TheScheduler.ScheduleTask(taskInfo, *data, aScheduleId); sl@0: TEST2(res, KErrNone); sl@0: delete data; sl@0: return taskInfo.iTaskId; sl@0: } sl@0: sl@0: LOCAL_D void doTestLoopL(TInt aId, TInt aCount) sl@0: { sl@0: TTsTime time = ShowDueTime(aId); sl@0: for (TInt i=0;i