loggingservices/eventlogger/test/src/t_logcntmatch.cpp
changeset 0 08ec8eefde2f
child 6 5ffdb8f2067f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // The "contacts matching" part of the test will work only if r_log_contact_match_count 
       
    15 // resource value is not 0. See LogServ.rss file.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <bautils.h>
       
    20 #include <logserv.rsg>
       
    21 #include <barsc.h>
       
    22 #include "TEST.H"
       
    23 
       
    24 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    25 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    26 
       
    27 //The test uses a test contact database (SQLite__Contacts.cdb), part of LogEng data files.
       
    28 //The test contact database contains the follwing contacts:
       
    29 //{1, KPhoneNumber, KGivenName,  KFamilyName}
       
    30 //{2, KNumber1,     KFirstName1, KLastName1}
       
    31 //{3, KNumber2,     KFirstName2, KLastName2}
       
    32 //{4, KNumber3,     KFirstName3, KLastName3}
       
    33 //{5, KNumber4,     KFirstName4, KLastName4}
       
    34 //{6, KNumber4,     KFirstName5, KLastName5}
       
    35 //{7, KTestNum,     KFirstName6, KLastName6}
       
    36 
       
    37 //The records data
       
    38 _LIT(KFirstName1, "Barney");
       
    39 _LIT(KFirstName2, "Elma");
       
    40 _LIT(KFirstName3, "Peter");
       
    41 _LIT(KLastName1, "Rubble");
       
    42 _LIT(KLastName2, "Fudd");
       
    43 _LIT(KLastName3, "Harper");
       
    44 _LIT(KNumber1, "447700900000");
       
    45 _LIT(KNumber2, "+441632960000");
       
    46 _LIT(KNumber3, "07700 900001");
       
    47 //_LIT(KFirstName4, "Abc");
       
    48 _LIT(KFirstName5, "Rtyu");
       
    49 _LIT(KFirstName6, "Zxcvb");
       
    50 //_LIT(KLastName4,  "Lkjhgf");
       
    51 //_LIT(KLastName5,  "Poiuytqwe");
       
    52 _LIT(KLastName6,  "Mnbvcxz");
       
    53 _LIT(KNumber4, "447756900111");
       
    54 //_LIT(KNumber5, "+441987960222");
       
    55 //_LIT(KNumber6, "07700 608101");
       
    56 _LIT(KGivenName, "AAA");
       
    57 _LIT(KFamilyName, "BBB");
       
    58 _LIT(KPhoneNumber, "0123456789");
       
    59 _LIT(KTestNum, "1234567890");
       
    60 
       
    61 #undef test  //there is a "test" macro which hides "RTest test" declaration.
       
    62 
       
    63 RTest test(_L("Contact Matching Test Harness"));
       
    64 TBool TheMatchingIsEnabled = EFalse;
       
    65 //TheContactNameFmt variable must be initialized before tests. 
       
    66 //It gives an information what is the contact name format in the logs.
       
    67 TLogContactNameFormat TheContactNameFmt = ELogWesternFormat;
       
    68 
       
    69 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    70 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
    71 
       
    72 //The function opens the LogEng server resource file (logserv.rsc) and gets the value of 
       
    73 //R_LOG_CONTACT_NAME_FORMAT resource. This value will be retured as a result of the call.
       
    74 //It gives an information what is the contact name format in the logs.
       
    75 static TLogContactNameFormat GetContactNameFormatL()
       
    76 	{
       
    77 	// Get language of resource file
       
    78 	_LIT(KLogResourceFile,"z:\\private\\101f401d\\logserv.rsc");
       
    79 	TFileName fileName(KLogResourceFile);
       
    80 	BaflUtils::NearestLanguageFile(theFs, fileName);
       
    81 
       
    82 	// Open resource file
       
    83 	RResourceFile rscFile;
       
    84 	CleanupClosePushL(rscFile);
       
    85 	rscFile.OpenL(theFs, fileName);
       
    86 	HBufC8* buf = rscFile.AllocReadLC(R_LOG_CONTACT_NAME_FORMAT);
       
    87 
       
    88 	TResourceReader reader;
       
    89 	reader.SetBuffer(buf);
       
    90 
       
    91 	TLogContactNameFormat contactNameFmt = static_cast <TLogContactNameFormat> (reader.ReadInt16());
       
    92 	CleanupStack::PopAndDestroy(2, &rscFile);
       
    93 	return contactNameFmt;
       
    94 	}
       
    95 
       
    96 //This function checks the logged name is the same as the event name.
       
    97 //Contact name logging format is taken into account.
       
    98 static void CheckContactName(CLogEvent& aEvent, const TDesC& aGivenName, const TDesC& aFamilyName)
       
    99 	{
       
   100 	TBuf<128> fullname;
       
   101 	if(TheContactNameFmt == ELogWesternFormat)
       
   102 		{
       
   103 		fullname.Format(_L("%S %S"), &aGivenName, &aFamilyName);
       
   104 		}
       
   105 	else //ELogChineseFormat
       
   106 		{
       
   107 		fullname.Format(_L("%S %S"), &aFamilyName, &aGivenName);
       
   108 		}
       
   109 	TEST(aEvent.RemoteParty() == fullname);
       
   110 	}
       
   111 
       
   112 /**
       
   113 Check normal operation
       
   114 
       
   115 @SYMTestCaseID          SYSLIB-LOGENG-CT-1016
       
   116 @SYMTestCaseDesc	    Tests for normal operations of CContactItem class
       
   117 @SYMTestPriority 	    High
       
   118 @SYMTestActions  	    The test adds 3 events and checks that the retrieved contact details are correct.
       
   119 @SYMTestExpectedResults Test must not fail
       
   120 @SYMREQ                 REQ0000
       
   121 */
       
   122 static void TestContactMatch1L(CLogClient& aClient)
       
   123 	{
       
   124 	CTestActive* active = new(ELeave)CTestActive();
       
   125 	CleanupStack::PushL(active);
       
   126 
       
   127 	CLogEvent* event = CLogEvent::NewL();
       
   128 	CleanupStack::PushL(event);
       
   129 	event->SetEventType(KLogCallEventTypeUid);
       
   130 	event->SetNumber(KNumber1);
       
   131 
       
   132 	// Add event. Expected contact to be found: {KFirstName1, KLastName1}.
       
   133 	active->StartL();
       
   134 	aClient.AddEvent(*event, active->iStatus);
       
   135 	CActiveScheduler::Start();
       
   136 	TEST2(active->iStatus.Int(), KErrNone);
       
   137 
       
   138 	// Check result
       
   139 	TLogContactItemId id1 = event->Contact(); 
       
   140 	TEST(id1 != KLogNullContactId);
       
   141 	::CheckContactName(*event, KFirstName1, KLastName1);
       
   142 	TEST(event->Flags() & KLogEventContactSearched);
       
   143 
       
   144 	// Create new event
       
   145 	CleanupStack::PopAndDestroy(event);
       
   146 	event = CLogEvent::NewL();
       
   147 	CleanupStack::PushL(event);
       
   148 	event->SetEventType(KLogCallEventTypeUid);
       
   149 	event->SetNumber(KNumber2);
       
   150 
       
   151 	// Add event. Expected contact to be found: {KFirstName2, KLastName2}.
       
   152 	active->StartL();
       
   153 	aClient.AddEvent(*event, active->iStatus);
       
   154 	CActiveScheduler::Start();
       
   155 	TEST2(active->iStatus.Int(), KErrNone);
       
   156 
       
   157 	// Check result
       
   158     TLogContactItemId id2 = event->Contact(); 
       
   159 	TEST(id2 != KLogNullContactId && id2 != id1);
       
   160 	::CheckContactName(*event, KFirstName2, KLastName2);
       
   161 	TEST(event->Flags() & KLogEventContactSearched);
       
   162 
       
   163 	// Create new event
       
   164 	CleanupStack::PopAndDestroy(event);
       
   165 	event = CLogEvent::NewL();
       
   166 	CleanupStack::PushL(event);
       
   167 	event->SetEventType(KLogCallEventTypeUid);
       
   168 	event->SetNumber(KNumber3);
       
   169 
       
   170 	// Add event. Expected contact to be found: {KFirstName3, KLastName3}.
       
   171 	active->StartL();
       
   172 	aClient.AddEvent(*event, active->iStatus);
       
   173 	CActiveScheduler::Start();
       
   174 	TEST2(active->iStatus.Int(), KErrNone);
       
   175 
       
   176 	// Check result
       
   177     TLogContactItemId id3 = event->Contact(); 
       
   178     TEST(id3 != KLogNullContactId && id3 != id2);
       
   179 	::CheckContactName(*event, KFirstName3, KLastName3);
       
   180 	TEST(event->Flags() & KLogEventContactSearched);
       
   181 	
       
   182 	CleanupStack::PopAndDestroy(2); // event, active
       
   183 	}
       
   184 
       
   185 /**
       
   186 Check special cases
       
   187 
       
   188 @SYMTestCaseID          SYSLIB-LOGENG-CT-1017
       
   189 @SYMTestCaseDesc	    Tests for special cases on CContactItem class
       
   190 @SYMTestPriority 	    High
       
   191 @SYMTestActions  	    The test adds couple events and checks that the retrieved contact details are correct.
       
   192 @SYMTestExpectedResults Test must not fail
       
   193 @SYMREQ                 REQ0000
       
   194 */
       
   195 static void TestContactMatch2L(CLogClient& aClient)
       
   196 	{
       
   197 	CTestActive* active = new(ELeave)CTestActive();
       
   198 	CleanupStack::PushL(active);
       
   199 
       
   200 	CLogEvent* event = CLogEvent::NewL();
       
   201 	CleanupStack::PushL(event);
       
   202 	event->SetEventType(KLogCallEventTypeUid);
       
   203 
       
   204 	const TLogContactItemId KIdInvalid = 77711;
       
   205 	event->SetNumber(KNumber3);
       
   206 	event->SetContact(KIdInvalid);
       
   207 
       
   208 	// Add event. There is a contacts record with phone number KNumber3, but the contact id is not KIdInvalid. 
       
   209 	active->StartL();
       
   210 	aClient.AddEvent(*event, active->iStatus);
       
   211 	CActiveScheduler::Start();
       
   212 	TEST2(active->iStatus.Int(), KErrNone);
       
   213 
       
   214 	// Check result - details should be unchanged
       
   215     TLogContactItemId id1 = event->Contact(); 
       
   216 	TEST(id1 == KIdInvalid);
       
   217 	TEST(event->RemoteParty().Length() == 0);
       
   218 	TEST(!(event->Flags() & KLogEventContactSearched));
       
   219 
       
   220 	// Set remote party. The contact id is still KIdInvalid.
       
   221 	// The remote part of the contacts record with phone number KNumber3 is KFirstName3.
       
   222 	event->SetRemoteParty(KFirstName5);
       
   223 
       
   224 	// Add event 
       
   225 	active->StartL();
       
   226 	aClient.AddEvent(*event, active->iStatus);
       
   227 	CActiveScheduler::Start();
       
   228 	TEST2(active->iStatus.Int(), KErrNone);
       
   229 
       
   230 	// Check result - details should be unchanged
       
   231     id1 = event->Contact(); 
       
   232 	TEST(id1 == KIdInvalid);
       
   233 	TEST(event->RemoteParty() == KFirstName5);
       
   234 	TEST(!(event->Flags() & KLogEventContactSearched));
       
   235 
       
   236 	// Create new event. The contact id is not set.
       
   237     // The phone number is set to be the same as the phone number of the contacts record.
       
   238 	// The remote party is set but is different in the contacts record.
       
   239 	CleanupStack::PopAndDestroy(event);
       
   240 	event = CLogEvent::NewL();
       
   241 	CleanupStack::PushL(event);
       
   242 	event->SetEventType(KLogCallEventTypeUid);
       
   243 	event->SetNumber(KNumber3);
       
   244 	event->SetRemoteParty(KFirstName5);
       
   245 	
       
   246 	// Add event
       
   247 	active->StartL();
       
   248 	aClient.AddEvent(*event, active->iStatus);
       
   249 	CActiveScheduler::Start();
       
   250 	TEST2(active->iStatus.Int(), KErrNone);
       
   251 
       
   252 	// Check result - Remote party should be unchanged. But the contact id should be set and valid.
       
   253     TLogContactItemId id2 = event->Contact(); 
       
   254 	TEST(id2 != KLogNullContactId && id2 != id1);
       
   255 	TEST(event->RemoteParty() == KFirstName5);
       
   256 	TEST(event->Flags() & KLogEventContactSearched);
       
   257 
       
   258 	// Create new event
       
   259 	CleanupStack::PopAndDestroy(event);
       
   260 	event = CLogEvent::NewL();
       
   261 	CleanupStack::PushL(event);
       
   262 	event->SetEventType(KLogCallEventTypeUid);
       
   263 	event->SetNumber(KNumber4);//There are 2 contacts records with phone number = KNumber4.
       
   264 
       
   265 	// Add event
       
   266 	active->StartL();
       
   267 	aClient.AddEvent(*event, active->iStatus);
       
   268 	CActiveScheduler::Start();
       
   269 	TEST2(active->iStatus.Int(), KErrNone);
       
   270 
       
   271 	// Check result - Details should not be set, because more than one contact found
       
   272 	TEST(event->Contact() == KLogNullContactId);
       
   273 	TEST(event->RemoteParty().Length() == 0);
       
   274 	TEST(event->Flags() & KLogEventContactSearched);
       
   275 
       
   276 	// Create new event
       
   277 	CleanupStack::PopAndDestroy(event);
       
   278 	event = CLogEvent::NewL();
       
   279 	CleanupStack::PushL(event);
       
   280 	event->SetEventType(KLogCallEventTypeUid);
       
   281 
       
   282 	TInt count = KTestNum().Length();
       
   283 	while(count--)
       
   284 		{
       
   285 		TPtrC num = KTestNum().Right(KTestNum().Length() - count);
       
   286 		event->SetNumber(num);
       
   287 
       
   288 		// Add event
       
   289 		active->StartL();
       
   290 		aClient.AddEvent(*event, active->iStatus);
       
   291 		CActiveScheduler::Start();
       
   292 		TEST2(active->iStatus.Int(), KErrNone);
       
   293 
       
   294 	    TLogContactItemId id3 = event->Contact();
       
   295 		
       
   296 		// Shouldn't perform a contacts match if number isn't big enough
       
   297 		if (num.Length() < 7)
       
   298 			{
       
   299 			// Check result - contact should not be set
       
   300 			TEST(id3 == KLogNullContactId);
       
   301 			TEST(event->RemoteParty().Length() == 0);
       
   302 			}
       
   303 		else
       
   304 			{
       
   305 			// Check result - Details should be set now
       
   306             TEST(id3 != KLogNullContactId);
       
   307 			::CheckContactName(*event, KFirstName6, KLastName6);
       
   308 			}
       
   309 		TEST(event->Flags() & KLogEventContactSearched);
       
   310 		}
       
   311 		
       
   312 	CleanupStack::PopAndDestroy(2); // event, active
       
   313 	}
       
   314 	
       
   315 /**
       
   316 @SYMTestCaseID          SYSLIB-LOGENG-CT-1392
       
   317 @SYMTestCaseDesc	    Test for DEF068087 fix - "Chinese names don't display in Chinese name format."
       
   318 @SYMTestPriority 	    Medium
       
   319 @SYMTestActions  	    Checks that added {given_name,family_name} strings pair
       
   320                         is stored in the logs using the correct order (degtermined 
       
   321                         by r_log_contact_name_format resource value).
       
   322 @SYMTestExpectedResults Test must not fail
       
   323 @SYMREQ                 REQ0000
       
   324 */
       
   325 void DEF068087L(CLogClient& aClient)
       
   326 	{
       
   327 	CTestActive* active = new (ELeave) CTestActive();
       
   328 	CleanupStack::PushL(active);
       
   329 	
       
   330 	//Add "phone call" event using one of the existing contacts
       
   331 	CLogEvent* event = CLogEvent::NewL();
       
   332 	CleanupStack::PushL(event);
       
   333 	event->SetEventType(KLogCallEventTypeUid);
       
   334 	event->SetNumber(KPhoneNumber);
       
   335 	active->StartL();
       
   336 	aClient.AddEvent(*event, active->iStatus);
       
   337 	CActiveScheduler::Start();
       
   338 	TEST2(active->iStatus.Int(), KErrNone);
       
   339 	TInt eventId = event->Id();
       
   340 	TEST(eventId != KLogNullId);
       
   341 
       
   342 	//Check result
       
   343 	TEST(event->Contact() != KLogNullContactId);
       
   344 	::CheckContactName(*event, KGivenName, KFamilyName);
       
   345 	TEST(event->Flags() & KLogEventContactSearched);
       
   346 	
       
   347 	//Cleanup
       
   348 	CleanupStack::PopAndDestroy(event);
       
   349 	CleanupStack::PopAndDestroy(active);
       
   350 	}
       
   351 
       
   352 void doTestsL()
       
   353 	{
       
   354 	TestUtils::Initialize(_L("T_LOGCONTACT"));
       
   355 
       
   356 	test.Start(_L("Prepare the test environment"));
       
   357 
       
   358 	TheMatchingIsEnabled = TestUtils::MatchingEnabledL();
       
   359 
       
   360 	if (!TheMatchingIsEnabled)
       
   361 		{
       
   362 		test.Printf(_L("Contacts matching not enabled. Contacts matching tests NOT run\n"));
       
   363 		return;
       
   364 		}
       
   365 
       
   366 	TheContactNameFmt = ::GetContactNameFormatL();
       
   367 
       
   368 	TestUtils::DeleteDatabaseL();
       
   369 
       
   370 	CLogClient* client = CLogClient::NewL(theFs);
       
   371 	CleanupStack::PushL(client);
       
   372 	
       
   373     test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1392: DEF068087: Chinese names don't display in Chinese name format"));
       
   374 	::DEF068087L(*client);
       
   375     test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1016: Contacts matching - test1"));
       
   376 	TestContactMatch1L(*client);
       
   377     test.Next(_L(" @SYMTestCaseID:SYSLIB-LOGENG-CT-1017: Contacts matching - test2"));
       
   378 	TestContactMatch2L(*client);
       
   379 
       
   380 	TestUtils::DeleteDatabaseL();
       
   381 
       
   382 	CleanupStack::PopAndDestroy(client);
       
   383 	}