os/persistentdata/loggingservices/eventlogger/test/src/t_logcntmatch.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2006-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
//
sl@0
    15
#include "LOGREPDEFS.H"
sl@0
    16
#include "t_logutil2.h"
sl@0
    17
#include "t_logutil3.h"
sl@0
    18
#include "t_logcntmatchplugin.h"
sl@0
    19
sl@0
    20
RTest TheTest(_L("t_logcntmatch"));
sl@0
    21
sl@0
    22
#ifdef SYSLIBS_TEST
sl@0
    23
sl@0
    24
TBool TheMatchingIsEnabled = EFalse;
sl@0
    25
//TheContactNameFmt variable must be initialized before tests. 
sl@0
    26
//It gives an information what is the contact name format in the logs.
sl@0
    27
TLogContactNameFormat TheContactNameFmt = KLogContactNameFormat;
sl@0
    28
sl@0
    29
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
    30
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
sl@0
    31
sl@0
    32
//This function checks the logged name is the same as the event name.
sl@0
    33
//Contact name logging format is taken into account.
sl@0
    34
static void CheckContactName(CLogEvent& aEvent, const TDesC& aGivenName, const TDesC& aFamilyName)
sl@0
    35
	{
sl@0
    36
	TBuf<128> fullname;
sl@0
    37
	if(TheContactNameFmt == ELogWesternFormat)
sl@0
    38
		{
sl@0
    39
		fullname.Format(_L("%S %S"), &aGivenName, &aFamilyName);
sl@0
    40
		}
sl@0
    41
	else //ELogChineseFormat
sl@0
    42
		{
sl@0
    43
		fullname.Format(_L("%S %S"), &aFamilyName, &aGivenName);
sl@0
    44
		}
sl@0
    45
	TEST(aEvent.RemoteParty() == fullname);
sl@0
    46
	}
sl@0
    47
sl@0
    48
/**
sl@0
    49
Check normal operation
sl@0
    50
sl@0
    51
@SYMTestCaseID          SYSLIB-LOGENG-CT-1016
sl@0
    52
@SYMTestCaseDesc	    Tests for normal operations of CContactItem class
sl@0
    53
@SYMTestPriority 	    High
sl@0
    54
@SYMTestActions  	    The test adds 3 events and checks that the retrieved contact details are correct.
sl@0
    55
@SYMTestExpectedResults Test must not fail
sl@0
    56
@SYMREQ                 REQ0000
sl@0
    57
*/
sl@0
    58
static void TestContactMatch1L(CLogClient& aClient)
sl@0
    59
	{
sl@0
    60
	CTestActive* active = new(ELeave)CTestActive();
sl@0
    61
	CleanupStack::PushL(active);
sl@0
    62
sl@0
    63
	CLogEvent* event = CLogEvent::NewL();
sl@0
    64
	CleanupStack::PushL(event);
sl@0
    65
	event->SetEventType(KLogCallEventTypeUid);
sl@0
    66
	event->SetNumber(KNumber1);
sl@0
    67
sl@0
    68
	// Add event. Expected contact to be found: {KFirstName1, KLastName1}.
sl@0
    69
	active->StartL();
sl@0
    70
	aClient.AddEvent(*event, active->iStatus);
sl@0
    71
	CActiveScheduler::Start();
sl@0
    72
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
    73
sl@0
    74
	// Check result
sl@0
    75
	TLogContactItemId id1 = event->Contact(); 
sl@0
    76
	TEST(id1 != KLogNullContactId);
sl@0
    77
	::CheckContactName(*event, KFirstName1, KLastName1);
sl@0
    78
	TEST(event->Flags() & KLogEventContactSearched);
sl@0
    79
sl@0
    80
	// Create new event
sl@0
    81
	CleanupStack::PopAndDestroy(event);
sl@0
    82
	event = CLogEvent::NewL();
sl@0
    83
	CleanupStack::PushL(event);
sl@0
    84
	event->SetEventType(KLogCallEventTypeUid);
sl@0
    85
	event->SetNumber(KNumber2);
sl@0
    86
sl@0
    87
	// Add event. Expected contact to be found: {KFirstName2, KLastName2}.
sl@0
    88
	active->StartL();
sl@0
    89
	aClient.AddEvent(*event, active->iStatus);
sl@0
    90
	CActiveScheduler::Start();
sl@0
    91
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
    92
sl@0
    93
	// Check result
sl@0
    94
    TLogContactItemId id2 = event->Contact(); 
sl@0
    95
	TEST(id2 != KLogNullContactId && id2 != id1);
sl@0
    96
	::CheckContactName(*event, KFirstName2, KLastName2);
sl@0
    97
	TEST(event->Flags() & KLogEventContactSearched);
sl@0
    98
sl@0
    99
	// Create new event
sl@0
   100
	CleanupStack::PopAndDestroy(event);
sl@0
   101
	event = CLogEvent::NewL();
sl@0
   102
	CleanupStack::PushL(event);
sl@0
   103
	event->SetEventType(KLogCallEventTypeUid);
sl@0
   104
	event->SetNumber(KNumber3);
sl@0
   105
sl@0
   106
	// Add event. Expected contact to be found: {KFirstName3, KLastName3}.
sl@0
   107
	active->StartL();
sl@0
   108
	aClient.AddEvent(*event, active->iStatus);
sl@0
   109
	CActiveScheduler::Start();
sl@0
   110
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   111
sl@0
   112
	// Check result
sl@0
   113
    TLogContactItemId id3 = event->Contact(); 
sl@0
   114
    TEST(id3 != KLogNullContactId && id3 != id2);
sl@0
   115
	::CheckContactName(*event, KFirstName3, KLastName3);
sl@0
   116
	TEST(event->Flags() & KLogEventContactSearched);
sl@0
   117
	
sl@0
   118
	CleanupStack::PopAndDestroy(2); // event, active
sl@0
   119
	}
sl@0
   120
sl@0
   121
/**
sl@0
   122
Check special cases
sl@0
   123
sl@0
   124
@SYMTestCaseID          SYSLIB-LOGENG-CT-1017
sl@0
   125
@SYMTestCaseDesc	    Tests for special cases on CContactItem class
sl@0
   126
@SYMTestPriority 	    High
sl@0
   127
@SYMTestActions  	    The test adds couple events and checks that the retrieved contact details are correct.
sl@0
   128
@SYMTestExpectedResults Test must not fail
sl@0
   129
@SYMREQ                 REQ0000
sl@0
   130
*/
sl@0
   131
static void TestContactMatch2L(CLogClient& aClient)
sl@0
   132
	{
sl@0
   133
	CTestActive* active = new(ELeave)CTestActive();
sl@0
   134
	CleanupStack::PushL(active);
sl@0
   135
sl@0
   136
	CLogEvent* event = CLogEvent::NewL();
sl@0
   137
	CleanupStack::PushL(event);
sl@0
   138
	event->SetEventType(KLogCallEventTypeUid);
sl@0
   139
sl@0
   140
	const TLogContactItemId KIdInvalid = 77711;
sl@0
   141
	event->SetNumber(KNumber3);
sl@0
   142
	event->SetContact(KIdInvalid);
sl@0
   143
sl@0
   144
	// Add event. There is a contacts record with phone number KNumber3, but the contact id is not KIdInvalid. 
sl@0
   145
	active->StartL();
sl@0
   146
	aClient.AddEvent(*event, active->iStatus);
sl@0
   147
	CActiveScheduler::Start();
sl@0
   148
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   149
sl@0
   150
	// Check result - details should be unchanged
sl@0
   151
    TLogContactItemId id1 = event->Contact(); 
sl@0
   152
	TEST(id1 == KIdInvalid);
sl@0
   153
	TEST(event->RemoteParty().Length() == 0);
sl@0
   154
	TEST(!(event->Flags() & KLogEventContactSearched));
sl@0
   155
sl@0
   156
	// Set remote party. The contact id is still KIdInvalid.
sl@0
   157
	// The remote part of the contacts record with phone number KNumber3 is KFirstName3.
sl@0
   158
	event->SetRemoteParty(KFirstName5);
sl@0
   159
sl@0
   160
	// Add event 
sl@0
   161
	active->StartL();
sl@0
   162
	aClient.AddEvent(*event, active->iStatus);
sl@0
   163
	CActiveScheduler::Start();
sl@0
   164
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   165
sl@0
   166
	// Check result - details should be unchanged
sl@0
   167
    id1 = event->Contact(); 
sl@0
   168
	TEST(id1 == KIdInvalid);
sl@0
   169
	TEST(event->RemoteParty() == KFirstName5);
sl@0
   170
	TEST(!(event->Flags() & KLogEventContactSearched));
sl@0
   171
sl@0
   172
	// Create new event. The contact id is not set.
sl@0
   173
    // The phone number is set to be the same as the phone number of the contacts record.
sl@0
   174
	// The remote party is set but is different in the contacts record.
sl@0
   175
	CleanupStack::PopAndDestroy(event);
sl@0
   176
	event = CLogEvent::NewL();
sl@0
   177
	CleanupStack::PushL(event);
sl@0
   178
	event->SetEventType(KLogCallEventTypeUid);
sl@0
   179
	event->SetNumber(KNumber3);
sl@0
   180
	event->SetRemoteParty(KFirstName5);
sl@0
   181
	
sl@0
   182
	// Add event
sl@0
   183
	active->StartL();
sl@0
   184
	aClient.AddEvent(*event, active->iStatus);
sl@0
   185
	CActiveScheduler::Start();
sl@0
   186
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   187
sl@0
   188
	// Check result - Remote party should be unchanged. But the contact id should be set and valid.
sl@0
   189
    TLogContactItemId id2 = event->Contact(); 
sl@0
   190
	TEST(id2 != KLogNullContactId && id2 != id1);
sl@0
   191
	TEST(event->RemoteParty() == KFirstName5);
sl@0
   192
	TEST(event->Flags() & KLogEventContactSearched);
sl@0
   193
sl@0
   194
	// Create new event
sl@0
   195
	CleanupStack::PopAndDestroy(event);
sl@0
   196
	event = CLogEvent::NewL();
sl@0
   197
	CleanupStack::PushL(event);
sl@0
   198
	event->SetEventType(KLogCallEventTypeUid);
sl@0
   199
	event->SetNumber(KNumber4);//There are 2 contacts records with phone number = KNumber4.
sl@0
   200
sl@0
   201
	// Add event
sl@0
   202
	active->StartL();
sl@0
   203
	aClient.AddEvent(*event, active->iStatus);
sl@0
   204
	CActiveScheduler::Start();
sl@0
   205
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   206
sl@0
   207
	// Check result - Details should not be set, because more than one contact found
sl@0
   208
	TEST(event->Contact() == KLogNullContactId);
sl@0
   209
	TEST(event->RemoteParty().Length() == 0);
sl@0
   210
	TEST(event->Flags() & KLogEventContactSearched);
sl@0
   211
sl@0
   212
	// Create new event
sl@0
   213
	CleanupStack::PopAndDestroy(event);
sl@0
   214
	event = CLogEvent::NewL();
sl@0
   215
	CleanupStack::PushL(event);
sl@0
   216
	event->SetEventType(KLogCallEventTypeUid);
sl@0
   217
sl@0
   218
	TInt count = KNumber6().Length();
sl@0
   219
	while(count--)
sl@0
   220
		{
sl@0
   221
		TPtrC num = KNumber6().Right(KNumber6().Length() - count);
sl@0
   222
		event->SetNumber(num);
sl@0
   223
sl@0
   224
		// Add event
sl@0
   225
		active->StartL();
sl@0
   226
		aClient.AddEvent(*event, active->iStatus);
sl@0
   227
		CActiveScheduler::Start();
sl@0
   228
		TEST2(active->iStatus.Int(), KErrNone);
sl@0
   229
sl@0
   230
	    TLogContactItemId id3 = event->Contact();
sl@0
   231
		
sl@0
   232
		// Shouldn't perform a contacts match if number isn't big enough
sl@0
   233
		if (num.Length() < 7)
sl@0
   234
			{
sl@0
   235
			// Check result - contact should not be set
sl@0
   236
			TEST(id3 == KLogNullContactId);
sl@0
   237
			TEST(event->RemoteParty().Length() == 0);
sl@0
   238
			}
sl@0
   239
		else
sl@0
   240
			{
sl@0
   241
			// Check result - Details should be set now
sl@0
   242
            TEST(id3 != KLogNullContactId);
sl@0
   243
			::CheckContactName(*event, KFirstName6, KLastName6);
sl@0
   244
			}
sl@0
   245
		TEST(event->Flags() & KLogEventContactSearched);
sl@0
   246
		}
sl@0
   247
		
sl@0
   248
	CleanupStack::PopAndDestroy(2); // event, active
sl@0
   249
	}
sl@0
   250
	
sl@0
   251
/**
sl@0
   252
@SYMTestCaseID          SYSLIB-LOGENG-CT-1392
sl@0
   253
@SYMTestCaseDesc	    Test for DEF068087 fix - "Chinese names don't display in Chinese name format."
sl@0
   254
@SYMTestPriority 	    Medium
sl@0
   255
@SYMTestActions  	    Checks that added {given_name,family_name} strings pair
sl@0
   256
                        is stored in the logs using the correct order (degtermined 
sl@0
   257
                        by r_log_contact_name_format resource value).
sl@0
   258
@SYMTestExpectedResults Test must not fail
sl@0
   259
@SYMREQ                 REQ0000
sl@0
   260
*/
sl@0
   261
void DEF068087L(CLogClient& aClient)
sl@0
   262
	{
sl@0
   263
	CTestActive* active = new (ELeave) CTestActive();
sl@0
   264
	CleanupStack::PushL(active);
sl@0
   265
	
sl@0
   266
	//Add "phone call" event using one of the existing contacts
sl@0
   267
	CLogEvent* event = CLogEvent::NewL();
sl@0
   268
	CleanupStack::PushL(event);
sl@0
   269
	event->SetEventType(KLogCallEventTypeUid);
sl@0
   270
	event->SetNumber(KNumber7);
sl@0
   271
	active->StartL();
sl@0
   272
	aClient.AddEvent(*event, active->iStatus);
sl@0
   273
	CActiveScheduler::Start();
sl@0
   274
	TEST2(active->iStatus.Int(), KErrNone);
sl@0
   275
	TInt eventId = event->Id();
sl@0
   276
	TEST(eventId != KLogNullId);
sl@0
   277
sl@0
   278
	//Check result
sl@0
   279
	TEST(event->Contact() != KLogNullContactId);
sl@0
   280
	::CheckContactName(*event, KFirstName7, KLastName7);
sl@0
   281
	TEST(event->Flags() & KLogEventContactSearched);
sl@0
   282
	
sl@0
   283
	//Cleanup
sl@0
   284
	CleanupStack::PopAndDestroy(event);
sl@0
   285
	CleanupStack::PopAndDestroy(active);
sl@0
   286
	}
sl@0
   287
sl@0
   288
void doTestsL()
sl@0
   289
	{
sl@0
   290
	TestUtils::Initialize(_L("t_logcntmatch"));
sl@0
   291
sl@0
   292
	TheTest.Start(_L("Prepare the test environment"));
sl@0
   293
sl@0
   294
	TheMatchingIsEnabled = TestUtils::MatchingEnabledL();
sl@0
   295
sl@0
   296
	if (!TheMatchingIsEnabled)
sl@0
   297
		{
sl@0
   298
		TheTest.Printf(_L("Contacts matching not enabled. Contacts matching tests NOT run\n"));
sl@0
   299
		return;
sl@0
   300
		}
sl@0
   301
sl@0
   302
	TInt contactMatchCount = 0;
sl@0
   303
	LogGetContactmatchCountAndNameFormatL(contactMatchCount, TheContactNameFmt);
sl@0
   304
	TheTest.Printf(_L("Contact match count = %d, TheContactNameFmt = %d\r\n"), contactMatchCount, (TInt)TheContactNameFmt);
sl@0
   305
sl@0
   306
	TestUtils::DeleteDatabaseL();
sl@0
   307
sl@0
   308
	CLogClient* client = CLogClient::NewL(theFs);
sl@0
   309
	CleanupStack::PushL(client);
sl@0
   310
	
sl@0
   311
	//All tests bellow are likely to fail if:
sl@0
   312
	// 101f401d.txt file exists in CentralRepository private data cage and the contact mach count is set to 0 in that file.
sl@0
   313
    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1392: DEF068087: Chinese names don't display in Chinese name format"));
sl@0
   314
	::DEF068087L(*client);
sl@0
   315
    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1016: Contacts matching - test1"));
sl@0
   316
	TestContactMatch1L(*client);
sl@0
   317
    TheTest.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1017: Contacts matching - test2"));
sl@0
   318
	TestContactMatch2L(*client);
sl@0
   319
sl@0
   320
	TestUtils::DeleteDatabaseL();
sl@0
   321
sl@0
   322
	CleanupStack::PopAndDestroy(client);
sl@0
   323
	}
sl@0
   324
sl@0
   325
#else //SYSLIBS_TEST
sl@0
   326
sl@0
   327
void doTestsL()
sl@0
   328
	{
sl@0
   329
	TheTest.Start(_L("This test can be run only when built with SYSLIBS_TEST macro defined!"));
sl@0
   330
	}
sl@0
   331
sl@0
   332
#endif //SYSLIBS_TEST