sl@0: // Copyright (c) 2004-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: // T_ScheduleEntryInfo2.cpp sl@0: // This file contains the implementation of test classe for TScheduleEntryInfo2. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "Thelpers.h" sl@0: sl@0: #include "SCHINFO.H" sl@0: sl@0: _LIT(KTestName, "TScheduleEntryInfo2 Tests"); sl@0: RTest TheTest(KTestName); sl@0: sl@0: static RFs TheFsSession; sl@0: _LIT(KFileName,"_:\\tscheduleinfo2.dat"); sl@0: static TBuf<32> fileName; sl@0: sl@0: // sl@0: // sl@0: //Test macroses and functions sl@0: sl@0: static void Check(TInt aValue, TInt aLine) sl@0: { sl@0: if(!aValue) sl@0: { sl@0: (void)TheFsSession.Delete(fileName); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: static void Check(TInt aValue, TInt aExpected, TInt aLine) sl@0: { sl@0: if(aValue != aExpected) sl@0: { sl@0: RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); sl@0: (void)TheFsSession.Delete(fileName); sl@0: TheTest(EFalse, aLine); sl@0: } sl@0: } sl@0: #define TEST(arg) ::Check((arg), __LINE__) sl@0: #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) sl@0: sl@0: sl@0: /** sl@0: State accessor for the TScheduleEntryInfo2 object under test. sl@0: */ sl@0: class TScheduleEntryInfo2_StateAccessor sl@0: { sl@0: sl@0: public: sl@0: void TestDefaultConstructor(); sl@0: void TestCopyConstructorOverloadedConstructor(); sl@0: sl@0: //utility Get and Set methods sl@0: void TestIntervalTypeSetIntervalType(); sl@0: void TestStartTimeSetStartTime(); sl@0: void TestIntervalSetInterval(); sl@0: void TestValidityPeriodSetValidityPeriod(); sl@0: void TestNonExportedConstructor(); sl@0: void TestExternalizeInternalizeL(); sl@0: }; sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0231 sl@0: @SYMTestCaseDesc Check the default constructor sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor sl@0: anc checks that the data has been properly initialised sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleEntryInfo2_StateAccessor::TestDefaultConstructor() sl@0: { sl@0: //Default constructor called sl@0: //Sets Start Time to 0 UTC time sl@0: //the interval type to 0, sl@0: //the interval to 0, sl@0: //the validityPeriod to 0 sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0231 Test default constructor ")); sl@0: TScheduleEntryInfo2 entry; sl@0: sl@0: TEST(entry.iIntervalType==0); sl@0: TEST(entry.iStartTime.GetUtcTime() == TTime(0)); sl@0: TEST(entry.iInterval == 0); sl@0: TEST(entry.iValidityPeriod == TTimeIntervalMinutes(0)); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0232 sl@0: @SYMTestCaseDesc Check the copy constructor and the overloaded constructor sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the overloaded sl@0: constructor and another instance of TScheduleEntryInfo2 using the copy constructor. sl@0: Then checks that data of both instances are equal. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleEntryInfo2_StateAccessor::TestCopyConstructorOverloadedConstructor() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0232 Text contructors ")); sl@0: sl@0: TDateTime date(2005, EMay, 15, 8, 55, 0, 0); sl@0: TTime time(date); sl@0: TTsTime startTime(time, EFalse); sl@0: TIntervalType intervalType(EHourly); sl@0: TInt interval(1); sl@0: TTimeIntervalMinutes validityPeriod(60); sl@0: sl@0: TScheduleEntryInfo2 entry1(startTime, intervalType, interval, validityPeriod); sl@0: sl@0: TScheduleEntryInfo2 entry2(entry1); sl@0: sl@0: //Test entry1 == entry2 sl@0: TEST(entry1.StartTime().GetLocalTime() == entry2.StartTime().GetLocalTime()); sl@0: TEST(entry1.ValidityPeriod() == entry2.ValidityPeriod()); sl@0: TEST(entry1.Interval() == entry2.Interval()); sl@0: sl@0: } sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0233 sl@0: @SYMTestCaseDesc Check SetIntervalType and IntervalType. sl@0: @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor. sl@0: Sets its interval type and checks that the returned value of IntervalType() sl@0: is equal to the one set initially. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleEntryInfo2_StateAccessor::TestIntervalTypeSetIntervalType() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0233 Test set and get for Interval Type ")); sl@0: sl@0: TScheduleEntryInfo2 scheduleEntryInfo; sl@0: sl@0: scheduleEntryInfo.SetIntervalType(TIntervalType(EHourly)); sl@0: TIntervalType intervalType = scheduleEntryInfo.IntervalType(); sl@0: TEST(intervalType == EHourly); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0234 sl@0: @SYMTestCaseDesc Check SetStartTime() and StartTime() sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor sl@0: Sets its start time using SetStartTime() and compares StartTime() returned value sl@0: to the one set initially. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleEntryInfo2_StateAccessor::TestStartTimeSetStartTime() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0234 Test start time set and get methods ")); sl@0: sl@0: TScheduleEntryInfo2 scheduleEntryInfo; sl@0: sl@0: TDateTime date(2005, EMay, 15, 8, 55, 0, 0); sl@0: TTime time(date); sl@0: TTsTime startTime(time, EFalse); sl@0: sl@0: scheduleEntryInfo.SetStartTime(startTime); sl@0: sl@0: TEST(scheduleEntryInfo.StartTime().GetLocalTime() == startTime.GetLocalTime()); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0235 sl@0: @SYMTestCaseDesc Check SetInterval() and Intervale() sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor sl@0: Sets its Interval using SetInterval() and compares the returned value of sl@0: Interval() to the one set initially. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleEntryInfo2_StateAccessor::TestIntervalSetInterval() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0235 Test set and get for Interval ")); sl@0: sl@0: TScheduleEntryInfo2 scheduleEntryInfo; sl@0: scheduleEntryInfo.SetInterval(1); sl@0: TEST(scheduleEntryInfo.Interval() == TInt(1)); sl@0: } sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0236 sl@0: @SYMTestCaseDesc Check SetValidityPeriod() and ValidityPeriod() sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the default constructor sl@0: Sets its validty period using SetValidityPeriod() and checks that ValidityPeriod() returns sl@0: the same value as the one set initially. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleEntryInfo2_StateAccessor::TestValidityPeriodSetValidityPeriod() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0236 Set and get for validity period ")); sl@0: TScheduleEntryInfo2 scheduleEntryInfo; sl@0: sl@0: scheduleEntryInfo.SetValidityPeriod(60); sl@0: TTimeIntervalMinutes retValidityPeriod = scheduleEntryInfo.ValidityPeriod(); sl@0: sl@0: TEST(retValidityPeriod == TTimeIntervalMinutes(60)); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0237 sl@0: @SYMTestCaseDesc Check non exported constructor provided for use with the deprecated APIs sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleEntryInfo using the default constructor, sets its member data, sl@0: and creates an instance of TScheduleEntryInfo2 using the provied constructor for use with deprecated APIs. sl@0: Then checks that TScheduleEntryInfo2 date is equal to TScheduleEntryInfo data. sl@0: sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleEntryInfo2_StateAccessor::TestNonExportedConstructor() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0237 Test non exported constructor ")); sl@0: sl@0: TScheduleEntryInfo entry1; sl@0: entry1.iIntervalType = EHourly; sl@0: entry1.iStartTime = SchSvrHelpers::TimeBasedOnOffset(1); sl@0: sl@0: entry1.iInterval = 1; sl@0: entry1.iValidityPeriod = 20; sl@0: sl@0: TScheduleEntryInfo2 entry2(entry1); sl@0: sl@0: //test that scheduleEntryInfo2 startTime is local time sl@0: TEST(!entry2.iStartTime.IsUtc()); sl@0: sl@0: //test intervalType sl@0: TEST(entry2.iIntervalType == entry1.iIntervalType); sl@0: sl@0: //test interval sl@0: TEST(entry2.iInterval == entry1.iInterval); sl@0: sl@0: //test validity period sl@0: TEST(entry2.iValidityPeriod == entry1.iValidityPeriod); sl@0: } sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0238 sl@0: @SYMTestCaseDesc Check Exetrnalize and Internalize methods sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleEntryInfo2 using the overloaded operator, externalizes it sl@0: to a file and then internalizes into another instance of TScheduleEntryInfo2. sl@0: Checks the externalized data is the same as the internalized one. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleEntryInfo2_StateAccessor::TestExternalizeInternalizeL() sl@0: { sl@0: sl@0: // Test externalise sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0238 \n=== Test TScheduleEntryInfo2::ExternalizeL\n")); sl@0: RFile file; sl@0: sl@0: sl@0: TFileName testFileName(fileName); sl@0: TEST2(file.Replace(TheFsSession,testFileName,EFileWrite|EFileRead), KErrNone); sl@0: RFileBuf buf; sl@0: CleanupClosePushL(buf); sl@0: buf.Attach(file); sl@0: RWriteStream stream(&buf); sl@0: sl@0: TTsTime ttime(SchSvrHelpers::TimeBasedOnOffset(1), EFalse); sl@0: TScheduleEntryInfo2 entry1(ttime, EHourly, 1, 20); sl@0: stream << entry1; //externalize TScheduleEntryInfo2 sl@0: buf.SynchL(); sl@0: CleanupStack::PopAndDestroy(&buf); sl@0: sl@0: sl@0: // Test internalise sl@0: TheTest.Next(_L("\n=== Test TScheduleEntryInfo2::InternalizeL\n")); sl@0: TScheduleEntryInfo2 entry2; sl@0: TInt err = file.Open(TheFsSession,testFileName,EFileRead); sl@0: TEST2(err, KErrNone); sl@0: RFileBuf buf2; sl@0: CleanupClosePushL(buf2); sl@0: buf2.Attach(file); sl@0: RReadStream stream2(&buf2); sl@0: sl@0: stream2 >> entry2; //internalize TScheduleEntryInfo2 sl@0: sl@0: //check iIntervalType sl@0: TEST(entry1.iIntervalType == entry2.iIntervalType); sl@0: sl@0: //check iStartTime sl@0: TEST(entry1.iStartTime.GetUtcTime() == entry2.iStartTime.GetUtcTime()); sl@0: sl@0: //check iInterval sl@0: TEST(entry1.iInterval == entry2.iInterval); sl@0: sl@0: //check iValidityPeriod sl@0: TEST(entry1.iValidityPeriod == entry2.iValidityPeriod); sl@0: sl@0: CleanupStack::PopAndDestroy(&buf2); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-3368 sl@0: @SYMTestCaseDesc Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup. sl@0: @SYMTestPriority High sl@0: @SYMTestActions This test does not have any capability. It tries to create persistent sl@0: time/ conduction schedule, it fail to create schedule sl@0: So return code will be KErrPermissionDenied sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMDEF PDEF098080: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup. sl@0: */ sl@0: LOCAL_D void CreatePersistentScheduleCapabilityTest() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-3368 \nPDEF098080: Task Scheduler: Persistent Schedules not ReScheduled on Device Bootup\n")); sl@0: sl@0: RScheduler TheScheduler; sl@0: TheTest(TheScheduler.Connect() == KErrNone);; sl@0: sl@0: //Create persistent time based schedule sl@0: CArrayFixFlat* entryList = new(ELeave) CArrayFixFlat(1); sl@0: CleanupStack::PushL(entryList); sl@0: TSchedulerItemRef ref; sl@0: sl@0: TTime ttime(SchSvrHelpers::TimeBasedOnOffset(0)); sl@0: TTsTime startTime1(ttime, EFalse); sl@0: sl@0: TScheduleEntryInfo2 entry1 (startTime1, EDaily, 1, 20); sl@0: entryList->AppendL(entry1); sl@0: sl@0: // Create the time base schedule and check capability policing is working . sl@0: TEST2(TheScheduler.CreatePersistentSchedule(ref, *entryList),KErrPermissionDenied); sl@0: sl@0: CleanupStack::PopAndDestroy(entryList); sl@0: sl@0: //Create persistent Condition based schedule sl@0: CArrayFixFlat* conditionList = new(ELeave) CArrayFixFlat(1); sl@0: CleanupStack::PushL(conditionList); sl@0: TSchedulerItemRef ref1; sl@0: sl@0: TTaskSchedulerCondition condition1; sl@0: const TUid KTestUid = TUid::Uid(0x01234566); sl@0: condition1.iCategory = KTestUid; sl@0: condition1.iKey = 10; sl@0: condition1.iState = 10; sl@0: condition1.iType = TTaskSchedulerCondition::EEquals; sl@0: conditionList->AppendL(condition1); sl@0: sl@0: // Create the condition base schedule and check capability policing is working . sl@0: TEST2(TheScheduler.CreatePersistentSchedule(ref1, *conditionList,startTime1),KErrPermissionDenied); sl@0: sl@0: CleanupStack::PopAndDestroy(conditionList); sl@0: TheScheduler.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Runs all the tests. sl@0: */ sl@0: static void RunTestsL() sl@0: { sl@0: TheTest.Start(_L("=== Start TScheduleEntryInfo2 tests \n")); sl@0: sl@0: CreatePersistentScheduleCapabilityTest(); sl@0: sl@0: TScheduleEntryInfo2_StateAccessor* scheduleStateAccessor = new (ELeave) TScheduleEntryInfo2_StateAccessor; sl@0: sl@0: CleanupStack::PushL(scheduleStateAccessor); sl@0: sl@0: scheduleStateAccessor->TestDefaultConstructor(); sl@0: scheduleStateAccessor->TestCopyConstructorOverloadedConstructor(); sl@0: sl@0: //utility Get and Set methods sl@0: scheduleStateAccessor->TestIntervalTypeSetIntervalType(); sl@0: scheduleStateAccessor->TestStartTimeSetStartTime(); sl@0: scheduleStateAccessor->TestIntervalSetInterval(); sl@0: scheduleStateAccessor->TestValidityPeriodSetValidityPeriod(); sl@0: scheduleStateAccessor->TestNonExportedConstructor(); sl@0: sl@0: //utility externalize internalize sl@0: scheduleStateAccessor->TestExternalizeInternalizeL(); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: sl@0: sl@0: //*********************************************************************************** sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: CTrapCleanup* tc = CTrapCleanup::New(); sl@0: TEST(tc != NULL); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: fileName.Copy(KFileName); sl@0: fileName[0] = RFs::GetSystemDriveChar(); sl@0: sl@0: TInt err = TheFsSession.Connect(); sl@0: TEST2(err, KErrNone); sl@0: sl@0: TheTest.Title(); sl@0: sl@0: TRAP(err, ::RunTestsL()) sl@0: TEST2(err, KErrNone); sl@0: sl@0: (void)TheFsSession.Delete(fileName); sl@0: TheFsSession.Close(); sl@0: TheTest.End(); sl@0: TheTest.Close(); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: delete tc; sl@0: sl@0: return(KErrNone); sl@0: sl@0: } sl@0: sl@0: sl@0: