sl@0: // Copyright (c) 2004-2010 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: // test code for INC045441 - Log Engine does not return events in sequence order sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "t_logutil2.h" sl@0: sl@0: RTest TheTest(_L("t_logorderbyid")); sl@0: sl@0: _LIT( KTestNumber1, "11111" ); sl@0: _LIT( KTestNumber2, "22222" ); sl@0: _LIT( KTestNumber3, "33333" ); sl@0: sl@0: /** sl@0: Add an event to the log engine database. sl@0: The event ID assigned by logengine is store in gTheId sl@0: sl@0: @param aClient sl@0: @param aNumber The number that the event should contain sl@0: @return The index for the event added. sl@0: sl@0: */ sl@0: LOCAL_C TInt AddEventL( CLogClient& aClient, CLogEvent& aEvent, CTestActive& aActive, TInt aIndex ) sl@0: { sl@0: TInt returnId = KLogNullId; sl@0: sl@0: // Reset sl@0: TTime now; sl@0: now.UniversalTime(); sl@0: sl@0: aEvent.SetContact( aIndex ); sl@0: sl@0: // load the event with test values sl@0: switch (aIndex) sl@0: { sl@0: case 1: sl@0: aEvent.SetNumber( KTestNumber1 ); sl@0: break; sl@0: case 2: sl@0: aEvent.SetNumber( KTestNumber2 ); sl@0: break; sl@0: case 3: sl@0: aEvent.SetNumber( KTestNumber3 ); sl@0: break; sl@0: } sl@0: sl@0: // add the event to the logeng database sl@0: aActive.StartL(); sl@0: aClient.AddEvent( aEvent, aActive.iStatus ); sl@0: CActiveScheduler::Start(); sl@0: TEST2(aActive.iStatus.Int(), KErrNone); sl@0: sl@0: // check that an ID has been assigned sl@0: returnId = aEvent.Id(); sl@0: TEST( returnId != KLogNullId ); sl@0: TEST( aEvent.Time() >= now ); sl@0: sl@0: // return the event id which has been assigned by the sl@0: // log engine sl@0: return returnId; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Get the event from the log engine database. sl@0: sl@0: @param aClient sl@0: @param aTheId Unique id for the event to be fetch sl@0: @param aNumber The number that the event should contain sl@0: */ sl@0: LOCAL_C void TestGetEventL( CLogClient& aClient, TInt aTheId, TInt aIndex ) sl@0: sl@0: { sl@0: CTestActive* active = new( ELeave )CTestActive(); sl@0: CleanupStack::PushL( active ); sl@0: sl@0: CLogEvent* event = CLogEvent::NewL(); sl@0: CleanupStack::PushL( event ); sl@0: sl@0: event->SetId( aTheId ); sl@0: sl@0: active->StartL(); sl@0: aClient.GetEvent( *event, active->iStatus ); sl@0: CActiveScheduler::Start(); sl@0: TEST2(active->iStatus.Int(), KErrNone); sl@0: sl@0: // check we got the right one back sl@0: TEST( event->Contact() == aIndex ); sl@0: sl@0: TPtrC eventNumber = event->Number(); sl@0: sl@0: TBuf<30> dateString; sl@0: _LIT( KDateString5, "%-B%:0%J%:1%T%:2%S%:3%+B" ); sl@0: event->Time().FormatL( dateString, KDateString5 ); sl@0: TPtrC eventDate = dateString.Ptr(); sl@0: TheTest.Printf( _L( "Id:%d No:%S Time:%S \n" ), event->Id(), &eventNumber, &eventDate ); sl@0: sl@0: CleanupStack::PopAndDestroy( 2 ); // event, active sl@0: } sl@0: sl@0: /** sl@0: Test code for INC045441 - Log Engine does not return events in sequence order sl@0: sl@0: @SYMTestCaseID SYSLIB-LOGENG-CT-1020 sl@0: @SYMTestCaseDesc Tests for checking the sequence order on events returned by log engine sl@0: @SYMTestPriority High sl@0: @SYMTestActions Test for getting the event in order as they were added to the log sl@0: Check for memory and no error sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: LOCAL_C void TestRecentViewOrderingL( CLogClient& aClient ) sl@0: // sl@0: // sl@0: // sl@0: { sl@0: TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1020 ")); sl@0: CLogEvent* event = CLogEvent::NewL(); sl@0: CleanupStack::PushL(event); sl@0: sl@0: CTestActive* active = new( ELeave )CTestActive(); sl@0: CleanupStack::PushL( active ); sl@0: sl@0: CLogViewRecent* view = CLogViewRecent::NewL( aClient ); sl@0: CleanupStack::PushL( view ); sl@0: sl@0: TBuf buf; sl@0: aClient.GetString(buf, R_LOG_DIR_MISSED); sl@0: sl@0: event->SetEventType( KLogCallEventTypeUid ); sl@0: event->SetDirection( buf ); sl@0: sl@0: TEST( !view->SetRecentListL( KLogRecentMissedCalls, active->iStatus ) ); sl@0: TEST( view->CountL() == 0 ); sl@0: sl@0: TTime time; sl@0: TheTest.Next( _L( "add new event 1" ) ); sl@0: TInt eventId1 = AddEventL( aClient, *event, *active, 1 ); sl@0: TestGetEventL( aClient, eventId1, 1 ); sl@0: sl@0: TheTest.Next( _L( "time plus 10 mins - add new event 2" ) ); sl@0: time.HomeTime(); sl@0: TTimeIntervalMinutes timeTravelForward( 10 ); sl@0: time += timeTravelForward; sl@0: User::SetHomeTime( time ); sl@0: TInt eventId2 = AddEventL( aClient, *event, *active, 2 ); sl@0: TestGetEventL( aClient, eventId2, 2 ); sl@0: sl@0: TheTest.Next( _L( "time minus 5 mins - add new event 3" ) ); sl@0: time.HomeTime(); sl@0: TTimeIntervalMinutes timeTravelBackward( 5 ); sl@0: time -= timeTravelBackward; sl@0: User::SetHomeTime( time ); sl@0: TInt eventId3 = AddEventL( aClient, *event, *active, 3 ); sl@0: TestGetEventL( aClient, eventId3, 3 ); sl@0: sl@0: TEST( view->CountL() == 3 ); sl@0: sl@0: active->StartL(); sl@0: // Get most recent sl@0: TEST( view->FirstL( active->iStatus ) ); sl@0: CActiveScheduler::Start(); sl@0: TEST2(active->iStatus.Int(), KErrNone); sl@0: sl@0: TInt id3 = view->Event().Id(); sl@0: // Get the one before that sl@0: active->StartL(); sl@0: TEST( view->NextL( active->iStatus ) ); sl@0: CActiveScheduler::Start(); sl@0: TEST2(active->iStatus.Int(), KErrNone); sl@0: TInt id2 = view->Event().Id(); sl@0: sl@0: // Get the one before that sl@0: active->StartL(); sl@0: TEST( view->NextL( active->iStatus ) ); sl@0: CActiveScheduler::Start(); sl@0: TEST2(active->iStatus.Int(), KErrNone); sl@0: TInt id1 = view->Event().Id(); sl@0: sl@0: TEST( id1 == eventId1 ); sl@0: TEST( id2 == eventId2 ); sl@0: TEST( id3 == eventId3 ); sl@0: sl@0: CleanupStack::PopAndDestroy( 3 ); // view, active, event sl@0: theLog.Write( _L8( "Test 1.1 OK\n" ) ); sl@0: } sl@0: sl@0: sl@0: sl@0: void doTestsL() sl@0: { sl@0: TestUtils::Initialize(_L("t_logorderbyid")); sl@0: TestUtils::DeleteDatabaseL(); sl@0: sl@0: CLogClient* client = CLogClient::NewL( theFs ); sl@0: CleanupStack::PushL( client ); sl@0: sl@0: CLogChangeNotifier* notifier = CLogChangeNotifier::NewL(); sl@0: CleanupStack::PushL( notifier ); sl@0: sl@0: TheTest.Start( _L( "Recent view sorts by Id not ETime" ) ); sl@0: TestRecentViewOrderingL( *client ); sl@0: theLog.Write( _L8( "Test 1 OK\n" ) ); sl@0: sl@0: CleanupStack::PopAndDestroy( 2 ); // notifier, client; sl@0: }