os/persistentdata/loggingservices/eventlogger/test/src/t_logorderbyid.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// test code for INC045441 - Log Engine does not return events in sequence order
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <s32file.h>
sl@0
    19
#include <e32math.h>
sl@0
    20
#include <logview.h>
sl@0
    21
#include "t_logutil2.h"
sl@0
    22
sl@0
    23
RTest TheTest(_L("t_logorderbyid"));
sl@0
    24
sl@0
    25
_LIT( KTestNumber1, "11111" );
sl@0
    26
_LIT( KTestNumber2, "22222" );
sl@0
    27
_LIT( KTestNumber3, "33333" );
sl@0
    28
sl@0
    29
/**
sl@0
    30
Add an event to the log engine database.
sl@0
    31
The event ID assigned by logengine is store in gTheId 
sl@0
    32
sl@0
    33
@param  aClient 
sl@0
    34
@param  aNumber The number that the event should contain
sl@0
    35
@return The index for the event added.
sl@0
    36
  
sl@0
    37
*/
sl@0
    38
LOCAL_C TInt AddEventL( CLogClient& aClient, CLogEvent& aEvent, CTestActive& aActive, TInt aIndex )
sl@0
    39
	{
sl@0
    40
	TInt returnId = KLogNullId;
sl@0
    41
sl@0
    42
	// Reset
sl@0
    43
	TTime now;
sl@0
    44
	now.UniversalTime();
sl@0
    45
sl@0
    46
	aEvent.SetContact( aIndex );
sl@0
    47
sl@0
    48
	// load the event with test values
sl@0
    49
	switch (aIndex)
sl@0
    50
		{
sl@0
    51
	case 1:
sl@0
    52
		aEvent.SetNumber( KTestNumber1 );
sl@0
    53
		break;
sl@0
    54
	case 2:
sl@0
    55
		aEvent.SetNumber( KTestNumber2 );
sl@0
    56
		break;
sl@0
    57
	case 3:
sl@0
    58
		aEvent.SetNumber( KTestNumber3 );
sl@0
    59
		break;
sl@0
    60
		}
sl@0
    61
sl@0
    62
	// add the event to the logeng database
sl@0
    63
	aActive.StartL();
sl@0
    64
	aClient.AddEvent( aEvent, aActive.iStatus );
sl@0
    65
	CActiveScheduler::Start();
sl@0
    66
	TEST2(aActive.iStatus.Int(), KErrNone);
sl@0
    67
sl@0
    68
	// check that an ID has been assigned
sl@0
    69
	returnId = aEvent.Id();
sl@0
    70
	TEST( returnId != KLogNullId );
sl@0
    71
	TEST( aEvent.Time() >= now );
sl@0
    72
	
sl@0
    73
	// return the event id which has been assigned by the 
sl@0
    74
	// log engine
sl@0
    75
	return returnId;
sl@0
    76
	}
sl@0
    77
sl@0
    78
sl@0
    79
/**
sl@0
    80
Get the event from the log engine database.
sl@0
    81
 
sl@0
    82
@param aClient 
sl@0
    83
@param aTheId Unique id for the event to be fetch
sl@0
    84
@param aNumber The number that the event should contain
sl@0
    85
*/
sl@0
    86
LOCAL_C void TestGetEventL( CLogClient& aClient, TInt aTheId, TInt aIndex )
sl@0
    87
sl@0
    88
	{
sl@0
    89
	CTestActive* active = new( ELeave )CTestActive();
sl@0
    90
	CleanupStack::PushL( active );
sl@0
    91
sl@0
    92
	CLogEvent* event = CLogEvent::NewL();
sl@0
    93
	CleanupStack::PushL( event );
sl@0
    94
sl@0
    95
	event->SetId( aTheId );
sl@0
    96
sl@0
    97
	active->StartL();
sl@0
    98
	aClient.GetEvent( *event, active->iStatus );
sl@0
    99
	CActiveScheduler::Start();
sl@0
   100
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   101
sl@0
   102
	// check we got the right one back
sl@0
   103
	TEST( event->Contact() == aIndex );
sl@0
   104
sl@0
   105
	TPtrC eventNumber = event->Number();
sl@0
   106
sl@0
   107
	TBuf<30> dateString;
sl@0
   108
	_LIT( KDateString5, "%-B%:0%J%:1%T%:2%S%:3%+B" );
sl@0
   109
	event->Time().FormatL( dateString, KDateString5 );
sl@0
   110
	TPtrC eventDate = dateString.Ptr();
sl@0
   111
	TheTest.Printf( _L( "Id:%d No:%S Time:%S \n" ), event->Id(), &eventNumber, &eventDate );
sl@0
   112
	
sl@0
   113
	CleanupStack::PopAndDestroy( 2 ); // event, active
sl@0
   114
	}
sl@0
   115
sl@0
   116
/**
sl@0
   117
Test code for INC045441 - Log Engine does not return events in sequence order
sl@0
   118
sl@0
   119
@SYMTestCaseID          SYSLIB-LOGENG-CT-1020
sl@0
   120
@SYMTestCaseDesc	    Tests for checking the sequence order on events returned by log engine
sl@0
   121
@SYMTestPriority 	    High
sl@0
   122
@SYMTestActions  	    Test for getting the event in order as they were added to the log
sl@0
   123
                        Check for memory and no error
sl@0
   124
@SYMTestExpectedResults Test must not fail
sl@0
   125
@SYMREQ                 REQ0000
sl@0
   126
*/	
sl@0
   127
LOCAL_C void TestRecentViewOrderingL( CLogClient& aClient )
sl@0
   128
//
sl@0
   129
//
sl@0
   130
//
sl@0
   131
	{
sl@0
   132
	TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1020 "));
sl@0
   133
	CLogEvent* event = CLogEvent::NewL();
sl@0
   134
	CleanupStack::PushL(event);
sl@0
   135
sl@0
   136
	CTestActive* active = new( ELeave )CTestActive();
sl@0
   137
	CleanupStack::PushL( active );
sl@0
   138
sl@0
   139
	CLogViewRecent* view = CLogViewRecent::NewL( aClient );
sl@0
   140
	CleanupStack::PushL( view );
sl@0
   141
sl@0
   142
	TBuf<KLogMaxDirectionLength> buf;
sl@0
   143
	aClient.GetString(buf, R_LOG_DIR_MISSED);
sl@0
   144
sl@0
   145
	event->SetEventType( KLogCallEventTypeUid );
sl@0
   146
	event->SetDirection( buf );
sl@0
   147
sl@0
   148
	TEST( !view->SetRecentListL( KLogRecentMissedCalls, active->iStatus ) );
sl@0
   149
	TEST( view->CountL() == 0 );
sl@0
   150
sl@0
   151
	TTime time;
sl@0
   152
	TheTest.Next( _L( "add new event 1" ) );
sl@0
   153
	TInt eventId1 = AddEventL( aClient, *event, *active, 1 );
sl@0
   154
	TestGetEventL( aClient, eventId1, 1 );
sl@0
   155
sl@0
   156
	TheTest.Next( _L( "time plus 10 mins - add new event 2" ) );
sl@0
   157
	time.HomeTime();
sl@0
   158
	TTimeIntervalMinutes timeTravelForward( 10 );
sl@0
   159
	time += timeTravelForward;
sl@0
   160
	User::SetHomeTime( time );
sl@0
   161
	TInt eventId2 = AddEventL( aClient, *event, *active, 2 );
sl@0
   162
	TestGetEventL( aClient, eventId2, 2 );
sl@0
   163
sl@0
   164
	TheTest.Next( _L( "time minus 5 mins - add new event 3" ) );
sl@0
   165
	time.HomeTime();
sl@0
   166
	TTimeIntervalMinutes timeTravelBackward( 5 );
sl@0
   167
	time -= timeTravelBackward;
sl@0
   168
	User::SetHomeTime( time );
sl@0
   169
	TInt eventId3 = AddEventL( aClient, *event, *active, 3 );
sl@0
   170
	TestGetEventL( aClient, eventId3, 3 );
sl@0
   171
sl@0
   172
	TEST( view->CountL() == 3 );
sl@0
   173
sl@0
   174
	active->StartL();
sl@0
   175
	// Get most recent
sl@0
   176
	TEST( view->FirstL( active->iStatus ) );
sl@0
   177
	CActiveScheduler::Start();
sl@0
   178
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   179
sl@0
   180
	TInt id3 = view->Event().Id();
sl@0
   181
	// Get the one before that
sl@0
   182
	active->StartL();
sl@0
   183
	TEST( view->NextL( active->iStatus ) );
sl@0
   184
	CActiveScheduler::Start();
sl@0
   185
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   186
	TInt id2 = view->Event().Id();
sl@0
   187
sl@0
   188
	// Get the one before that
sl@0
   189
	active->StartL();
sl@0
   190
	TEST( view->NextL( active->iStatus ) );
sl@0
   191
	CActiveScheduler::Start();
sl@0
   192
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   193
	TInt id1 = view->Event().Id();
sl@0
   194
sl@0
   195
	TEST( id1 == eventId1 );
sl@0
   196
	TEST( id2 == eventId2 );
sl@0
   197
	TEST( id3 == eventId3 );
sl@0
   198
sl@0
   199
	CleanupStack::PopAndDestroy( 3 ); // view, active, event
sl@0
   200
	theLog.Write( _L8( "Test 1.1 OK\n" ) );
sl@0
   201
	}
sl@0
   202
sl@0
   203
	
sl@0
   204
	
sl@0
   205
void doTestsL()
sl@0
   206
	{
sl@0
   207
	TestUtils::Initialize(_L("t_logorderbyid"));
sl@0
   208
	TestUtils::DeleteDatabaseL();
sl@0
   209
sl@0
   210
	CLogClient* client = CLogClient::NewL( theFs );
sl@0
   211
	CleanupStack::PushL( client );
sl@0
   212
sl@0
   213
	CLogChangeNotifier* notifier = CLogChangeNotifier::NewL();
sl@0
   214
	CleanupStack::PushL( notifier );
sl@0
   215
sl@0
   216
	TheTest.Start( _L( "Recent view sorts by Id not ETime" ) );
sl@0
   217
	TestRecentViewOrderingL( *client );
sl@0
   218
	theLog.Write( _L8( "Test 1 OK\n" ) );
sl@0
   219
sl@0
   220
	CleanupStack::PopAndDestroy( 2 ); // notifier, client;
sl@0
   221
	}