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