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: // This file contains the implementation of test classe for TScheduleState2. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #include "SCHINFO.H" sl@0: #include sl@0: sl@0: _LIT(KTestName, "TScheduleState2 Tests"); sl@0: RTest TheTest(KTestName); 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: 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: 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: /** sl@0: State accessor for the TScheduleState2 object under test. sl@0: */ sl@0: class TScheduleState2_StateAccessor sl@0: { sl@0: public : sl@0: void TestDefaultConstructor(); sl@0: void TestCopyConstructorOverloadedConstructor(); sl@0: void TestNameSetName(); sl@0: void TestDueTimeSetDueTime(); sl@0: void TestPersistsSetPersists(); sl@0: void TestEnabledSetEnabled(); sl@0: void TestOperatorEqual(); sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0224 sl@0: @SYMTestCaseDesc Check the default constructor works properly sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleState2 and check its data has been sl@0: set to default values. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleState2_StateAccessor::TestDefaultConstructor() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0224 ")); sl@0: TScheduleState2 state; sl@0: sl@0: //name should be "" sl@0: TEST(state.iName == _L("")); sl@0: sl@0: //iDueTime UTC, O sl@0: TEST(state.iDueTime.GetUtcTime() == TTime(0)); sl@0: sl@0: //iFlags should be 0 sl@0: TEST(state.iFlags == 0); sl@0: sl@0: //iReserved 0 sl@0: TEST(state.iReserved == 0); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0225 sl@0: @SYMTestCaseDesc Checks the copy constructor and the overloaded constructor sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleState2 using the overloaded constructor sl@0: and another instance of TScheduleState2 using the copy constructor, then compares sl@0: their data and makes sure they are equal. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleState2_StateAccessor::TestCopyConstructorOverloadedConstructor() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0225 Test constructors ")); sl@0: const TName name(_L("test_state")); sl@0: TDateTime date(2005, EMay, 15, 8, 55, 0, 0); sl@0: TTime time(date); sl@0: TTsTime dueTime(time, EFalse); //TTsTime is Home time sl@0: sl@0: TScheduleState2 state1(name, dueTime, ETrue, ETrue); sl@0: TScheduleState2 state2(state1); sl@0: sl@0: TEST(state1.iName == state2.iName); sl@0: TEST(state1.iDueTime.GetLocalTime() == state2.iDueTime.GetLocalTime()); sl@0: TEST(state1.iFlags == state2.iFlags); sl@0: TEST(state1.iReserved == state2.iReserved); sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0226 sl@0: @SYMTestCaseDesc Checks SetName() and Name() functions of TScheduleState2 sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleState2, calls SetName() and Name() sl@0: and Name() returns 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 TScheduleState2_StateAccessor::TestNameSetName() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0226 ")); sl@0: TScheduleState2 state; sl@0: const TName name(_L("name")); sl@0: state.SetName(name); sl@0: sl@0: TEST(state.Name() == name); sl@0: sl@0: } sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0227 sl@0: @SYMTestCaseDesc Checks SetDueTime() and DueTime() sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleState2, sets its due time and checks sl@0: the returned time is equel to one set initially. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleState2_StateAccessor::TestDueTimeSetDueTime() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0227 Test set and get due time APIs ")); sl@0: sl@0: TScheduleState2 state; sl@0: sl@0: TDateTime date(2005, EMay, 15, 8, 55, 0, 0); sl@0: TTime time(date); sl@0: TTsTime dueTime(time, EFalse); //TTsTime is Home time sl@0: sl@0: state.SetDueTime(dueTime); sl@0: TEST(time == state.DueTime().GetLocalTime()); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0228 sl@0: @SYMTestCaseDesc Checks SetPersists() and Persists() functions sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleState2, calls SetPersists then Persists sl@0: and checks the returned value is equal to the one set initially. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleState2_StateAccessor::TestPersistsSetPersists() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0228 ")); sl@0: TScheduleState2 state; sl@0: sl@0: //set Persists to Etrue sl@0: state.SetPersists(ETrue); sl@0: TEST(state.Persists()); sl@0: sl@0: //set Persists to EFalse sl@0: state.SetPersists(EFalse); sl@0: TEST(!state.Persists()); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0229 sl@0: @SYMTestCaseDesc Checks Enabled() and SetEnabled() functions sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance TScheduleState2, calls SetEnabled() then Enabled() sl@0: and checks the returned value is equal to the one set initially. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleState2_StateAccessor::TestEnabledSetEnabled() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0229 ")); sl@0: TScheduleState2 state; sl@0: sl@0: //ETrue sl@0: state.SetEnabled(ETrue); sl@0: TEST(state.Enabled()); sl@0: sl@0: //EFlase sl@0: state.SetEnabled(EFalse); sl@0: TEST(!state.Enabled()); sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @SYMTestCaseID SYSLIB-SCHSVR-CT-0230 sl@0: @SYMTestCaseDesc Check the operator = works properly sl@0: @SYMTestPriority low sl@0: @SYMTestActions Creates an instance of TScheduleState2 using the overloaded constructor, sl@0: then creates another instance of TScheduleState2 and assigns it the first instance sl@0: of TScheduleState2. The tests make sure both instances are equal. sl@0: @SYMTestExpectedResults The test must not fail. sl@0: @SYMPREQ PREQ234 sl@0: */ sl@0: void TScheduleState2_StateAccessor::TestOperatorEqual() sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-SCHSVR-CT-0230 Test overloaded equals operator ")); sl@0: sl@0: const TName name(_L("name")); sl@0: //set the current utc time to 8.55am, 15 May 2005 -Daylight savings apply on this date sl@0: TDateTime date(2005, EMay, 15, 8, 55, 0, 0); sl@0: TTime time(date); sl@0: TTsTime dueTime(time, EFalse); //TTsTime is Home time sl@0: sl@0: TScheduleState2 state1(name, dueTime, ETrue, ETrue); sl@0: TScheduleState2 state2 = state1; sl@0: sl@0: TEST(state1.iName == state2.iName); sl@0: TEST(state1.iDueTime.GetLocalTime() == state2.iDueTime.GetLocalTime() ); sl@0: TEST(state1.iFlags == state2.iFlags); sl@0: TEST(state1.iReserved == state2.iReserved); 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 TScheduleState2 tests \n")); sl@0: TScheduleState2_StateAccessor* entry = new (ELeave) TScheduleState2_StateAccessor; sl@0: CleanupStack::PushL(entry); sl@0: entry->TestDefaultConstructor(); sl@0: entry->TestCopyConstructorOverloadedConstructor(); sl@0: entry->TestNameSetName(); sl@0: entry->TestDueTimeSetDueTime(); sl@0: entry->TestPersistsSetPersists(); sl@0: entry->TestEnabledSetEnabled(); sl@0: entry->TestOperatorEqual(); 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: TInt err; sl@0: TheTest.Title(); sl@0: sl@0: TRAP(err, ::RunTestsL()) sl@0: TEST2(err, KErrNone); sl@0: 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: