phonebookengines/contactsmodel/tsrc/T_NOMACH.CPP
changeset 0 e686773b3f54
child 24 0ba2181d7c28
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 1997-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 //
       
    15 
       
    16 #include <e32test.h>
       
    17 #include <f32file.h>
       
    18 #include "T_UTILS.H"
       
    19 #include <coreappstest/testserver.h>
       
    20 
       
    21 _LIT(KCntTestTitle,"T_NOMACH");
       
    22 _LIT(KDatabaseFileName,"c:T_NOMACH");
       
    23 
       
    24 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ 
       
    25 _LIT(KSrcDatabaseName, "z:\\t_old_contacts_original.cdb");
       
    26 _LIT(KDatabaseName, "C:\\private\\10003A73\\t_old_contacts_in_use.cdb");
       
    27 _LIT(KDatabaseOpenName, "C:t_old_contacts_in_use.cdb");
       
    28 _LIT(KTestDbUpdate, "-- Test database update\n");
       
    29 #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__
       
    30 
       
    31 _LIT(KTestName,"Test Name No %d");
       
    32 _LIT(KTestAddress,"Test Address No %d");
       
    33 _LIT(KTestFamilyName,"Test Family Name No %d");
       
    34 _LIT(KTestEmail,"Test@Email.com No %d");
       
    35 _LIT(KTestCountry,"Test Country No %d");
       
    36 _LIT(KTestCompany,"Test Company No %d");
       
    37 _LIT(KCntName,"Firstname");
       
    38 _LIT(KCntSurname,"Surname");
       
    39 
       
    40 _LIT(KTestNoPhoneMatchLibrary,"-- Regression testcode for DUG-4ZVNBW - MatchPhoneNumberL doesn't match correctly without CNTPHONE.DLL\n");
       
    41 _LIT(KTestNewMatching,"-- Test matching; all following tests should match 1234567\n");
       
    42 _LIT(KTestFaxSMSMatching,"-- Test adding fax and SMS numbers to the phone number match list, regression for COY-567J99\n");
       
    43 _LIT(KSpeedDialSimpleTest,"-- Basic speed-dial tests.\n");
       
    44 _LIT(KTestRemovingSpeedDials,"\n-- Test removing speed-dials; add five contacts, Set two speed dials - remove one & check the other is still there.\n");
       
    45 _LIT(KTest11Digitmatching, "-- Test 11 digit matching\n");
       
    46 _LIT(KTest15Digitmatching, "-- Test 15 digit matching\n");
       
    47 _LIT(KTestEmbeddedZeroes, "-- Test Embedded Zeroes\n");
       
    48 
       
    49 const TInt KMatch6Digits = 6;
       
    50 const TInt KMatch7Digits = 7;
       
    51 const TInt KMatch8Digits = 8;
       
    52 const TInt KMatch10Digits = 10;
       
    53 const TInt KMatch11Digits = 11;
       
    54 const TInt KMatch12Digits = 12;
       
    55 const TInt KMatch13Digits = 13;
       
    56 const TInt KMatch14Digits = 14;
       
    57 const TInt KMatch15Digits = 15;
       
    58 const TInt KMatch16Digits = 16;
       
    59 
       
    60 const TInt KTestContactsNum=10;
       
    61 
       
    62 GLDEF_D CCntTest* CntTest=NULL;
       
    63 GLDEF_D RTest test(KCntTestTitle);
       
    64 
       
    65 
       
    66 LOCAL_C void SetNameL(CContactItem& aItem,TUid aType,const TDesC& aName, TBool aAddField)
       
    67 //
       
    68 // Set the contents of a text field, creating the field if required
       
    69 //
       
    70 	{
       
    71 	CContactItemFieldSet& fieldSet=aItem.CardFields();
       
    72 	const TInt pos=fieldSet.Find(aType);
       
    73 	if (!aAddField && pos!=KErrNotFound)
       
    74 		fieldSet[pos].TextStorage()->SetTextL(aName);
       
    75 	else
       
    76 		{
       
    77 		CContactItemField* field=CContactItemField::NewLC(KStorageTypeText,aType);
       
    78    		field->SetMapping(KUidContactFieldVCardMapUnusedN);
       
    79 		field->TextStorage()->SetTextL(aName);
       
    80 		aItem.AddFieldL(*field);
       
    81 		CleanupStack::Pop(field); 
       
    82 		}
       
    83 	}
       
    84 
       
    85 LOCAL_C void PopulateDatabaseL(TInt aNumberToPopulate)
       
    86 //
       
    87 // Create and populate the database
       
    88 //
       
    89 	{
       
    90 	CContactItem* templ = CntTest->Db()->ReadContactL(0);
       
    91 	CleanupStack::PushL(templ);
       
    92 	
       
    93 	for (TInt ii=0;ii<aNumberToPopulate;ii++)
       
    94 		{
       
    95 		CContactItem* item=CContactCard::NewLC(templ);
       
    96 		TBuf<20> name;
       
    97 		name.Format(KTestName,ii);
       
    98    		SetNameL(*item,KUidContactFieldGivenName,name,EFalse);
       
    99 		TBuf<20> number;
       
   100 		switch(ii%3)
       
   101 			{
       
   102 			case 0:
       
   103 				number.Format(_L("0171-%03d %04d"),(ii*9)%1000,((ii+11)*23)%10000);
       
   104 				break;
       
   105 			case 1:
       
   106 				number.Format(_L("%04d:%04d:%04d:%04d"),(ii*123)%10000,(ii*666)%10000,(ii*234)%10000);
       
   107 				break;
       
   108 			case 2:
       
   109 				number.Format(_L("+00%d-%03d %04d"),(ii*123)%100,(ii*13)%1000,((ii+13)*17)%10000);
       
   110 				break;
       
   111 			}
       
   112    		SetNameL(*item,KUidContactFieldPhoneNumber,_L("11111"),EFalse);
       
   113 		if (!(ii%2))
       
   114 			{
       
   115 			number.Format(_L("0181-%03d %04d"),(ii*8)%1000,((ii+11)*22)%10000);
       
   116 	   		SetNameL(*item,KUidContactFieldPhoneNumber,_L("111"),EFalse); 
       
   117 			number.Format(_L("01734-%06d"),(ii*123456)%1000000);
       
   118 	   		SetNameL(*item,KUidContactFieldPhoneNumber,_L("1111"),EFalse);
       
   119 			CContactItemFieldSet& itemFields = item->CardFields();
       
   120 			for (TInt ii=0;ii<itemFields.Count();ii++)
       
   121 				{
       
   122 				CContactItemField& field = (itemFields)[ii];
       
   123 				if (!itemFields[ii].Storage()->IsFull() && itemFields[ii].StorageType()==KStorageTypeText && 
       
   124 					field.ContentType().ContainsFieldType(KUidContactFieldPhoneNumber))
       
   125 					itemFields[ii].TextStorage()->SetTextL(_L("111111"));
       
   126 				}
       
   127 			}
       
   128 		TBuf<32> address;
       
   129 		address.Format(KTestAddress,ii);
       
   130 		SetNameL(*item,KUidContactFieldAddress,address,EFalse);
       
   131 //
       
   132 		TBuf<32> familyName;
       
   133 		familyName.Format(KTestFamilyName,ii);
       
   134 		SetNameL(*item,KUidContactFieldFamilyName,familyName,EFalse);
       
   135 //
       
   136 		TBuf<32> email;
       
   137 		email.Format(KTestEmail,ii);
       
   138 		SetNameL(*item,KUidContactFieldEMail,email,EFalse);
       
   139 //
       
   140 		TBuf<32> country;
       
   141 		country.Format(KTestCountry,ii);
       
   142 		SetNameL(*item,KUidContactFieldCountry,country,EFalse);
       
   143 //	
       
   144 		TBuf<32> company;
       
   145 		company.Format(KTestCompany,ii);
       
   146 		SetNameL(*item,KUidContactFieldCompanyName,company,EFalse);
       
   147 //	
       
   148 		CntTest->Db()->AddNewContactL(*item); 
       
   149 		CleanupStack::PopAndDestroy(item); 
       
   150 
       
   151 		test.Printf(_L("."));	// Just to show some life
       
   152 		}
       
   153 	CleanupStack::PopAndDestroy(templ);
       
   154 	CntTest->Db()->CompactL();
       
   155 	}
       
   156 
       
   157 
       
   158 
       
   159 
       
   160 
       
   161 
       
   162 // Delete the current contacts database and create a new one
       
   163 // 
       
   164 LOCAL_C void ResetDatabaseL()
       
   165 	{
       
   166 	// Reset all server side speed dials ;-))) 
       
   167 	CntTest->Db()->ResetServerSpeedDialsL();
       
   168 
       
   169 	CntTest->CloseDatabase();
       
   170 	CntTest->DeleteDatabaseL();
       
   171 	CntTest->CreateDatabaseL();
       
   172 	CntTest->OpenDatabaseL();	
       
   173 	}
       
   174 
       
   175 
       
   176 LOCAL_C TContactItemId CreateContactL(const TDesC& aFirstName, const TDesC& aFamilyName, const TDesC& aPhoneNo, const TDesC& aMobileNo)
       
   177 	{
       
   178 	test.Printf(_L("\tCreating contact %S %S, phone: %S mobile: %S\n"), &aFirstName, &aFamilyName, &aPhoneNo, &aMobileNo);
       
   179 	CContactItem* item=CContactCard::NewLC();
       
   180 	SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aFirstName,ETrue);
       
   181 	SetNameL(*item,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,aFamilyName,ETrue);
       
   182 	SetNameL(*item,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,aPhoneNo,ETrue);
       
   183 	SetNameL(*item,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapCELL,aMobileNo,ETrue);
       
   184 	item->SetTemplateRefId(KGoldenTemplateId);
       
   185 	TContactItemId id=CntTest->Db()->AddNewContactL(*item);
       
   186 	CleanupStack::PopAndDestroy(item); 
       
   187 	return id;
       
   188 	}
       
   189 
       
   190 LOCAL_C void CheckPhoneMatchL(const TDesC& aPhoneNumberToMatch, TInt aNumberOfMatchDigits, TInt aExpectedNumOfMatches)
       
   191 	{
       
   192 	TBuf<256> testCase;
       
   193 	_LIT(KFormat,"Checking %d matches to %S, matching %d digits");
       
   194 	testCase.Format(KFormat, aExpectedNumOfMatches, &aPhoneNumberToMatch, aNumberOfMatchDigits);
       
   195 	test.Next(_L(" "));
       
   196 
       
   197 	CContactDatabase& db = *(CntTest->Db());
       
   198 	CContactIdArray* array = db.MatchPhoneNumberL(aPhoneNumberToMatch,aNumberOfMatchDigits);
       
   199 	CleanupStack::PushL(array);
       
   200 	const TInt numberOfMatches = array->Count();
       
   201 	CleanupStack::PopAndDestroy(array);
       
   202 	
       
   203 	
       
   204 	TInt sfd = db.MachineId();
       
   205 	// OverrideMachineUniqueId
       
   206 	
       
   207 	
       
   208 	test(numberOfMatches==aExpectedNumOfMatches);
       
   209 	}
       
   210 
       
   211 /** 
       
   212 Testcode for Graham's new API
       
   213 
       
   214 These all match 1234567:
       
   215 *#42# 0201234567 p123
       
   216 *#42# +358201234567 p123
       
   217 *61 0201234567
       
   218 *61 +358201234567
       
   219 +358201234567 +3
       
   220 +358201234567 p123
       
   221 
       
   222 */
       
   223 LOCAL_C void TestNewMatchingL()
       
   224 	{
       
   225 	ResetDatabaseL();
       
   226 
       
   227 	const TInt KLastThreeDigits =3;
       
   228 	//These numbers match 1234567
       
   229 	_LIT(KCntDTMFNumber1,"*#42# 0201234567 p123");
       
   230 	_LIT(KCntDTMFNumber2,"*#42#+358401234567 p123");
       
   231 	_LIT(KCntDTMFNumber3,"*61 0201234567");
       
   232 	_LIT(KCntDTMFNumber4,"*61 +358201234567");
       
   233 	_LIT(KCntDTMFNumber5,"+358201234567 +3");
       
   234 	_LIT(KCntDTMFNumber6,"+358201234567 p123");
       
   235 	_LIT(KCntMatch1to7ExtraCharacters,"mobile 12 345-67");
       
   236 	_LIT(KCntMatch1to7Brackets,"(020) 0123-4567");
       
   237 	_LIT(KCntMatch1to7TooManyNumbers,"123456789012345678901234567");
       
   238 	//These shouldn't match 1234567
       
   239 	_LIT(KCntDTMFNumber7,"*#42# 0201234567#p123");//empty
       
   240 	_LIT(KCntDTMFNumber8,"*12345+0201234567");    //matches 12345
       
   241 	_LIT(KCntDTMFNumber9,"*+123+456+++++++++++"); //matches 123
       
   242 	//Graham's possible defects
       
   243 	_LIT(KCntPossibleDefect,"70000");
       
   244 	_LIT(KCntZeroAtEnd,"020 5632700");
       
   245 	//Match numbers
       
   246 	_LIT(KCntMatch1to7,"1234567");
       
   247 	_LIT(KCntMatch1to3,"123");
       
   248 	_LIT(KCntMatch700,"700");
       
   249 	//Spaces at the start
       
   250 	_LIT(KCntSpaceInNumber,"   0 2 0      7 9 4 6  5 6 7 8    ");
       
   251 	_LIT(KCntSpaceMatch,"02079465678");
       
   252 	_LIT(KCntSpaceInNumberIntl,"   +44 7700 900 472");
       
   253 	_LIT(KCntSpaceInNumberIntlMatch,"+447700900472");
       
   254 	_LIT(KCntSpaceWorstCase,"              ");
       
   255 	_LIT(KCntNoRealDigitsInNumber,"Lycos SMS");
       
   256 
       
   257 	_LIT(KCntShortNumber1,"789");
       
   258 	_LIT(KCntShortNumber2,"456");
       
   259 
       
   260 	_LIT(KCntEndingByShortNumber1,"+44(0)79460064789");
       
   261 	_LIT(KCntEndingByShortNumber2,"+447946008731456");
       
   262 
       
   263 	_LIT(KCntMatchShortNumber1,"789"); // must not match other number ending with 789
       
   264 	_LIT(KCntMatchShortNumber2,"456"); // must not match other number ending with 456
       
   265 
       
   266 	CreateContactL(KCntName,KCntSurname,KCntShortNumber1,KNullDesC);
       
   267 	CreateContactL(KCntName,KCntSurname,KCntShortNumber2,KNullDesC);
       
   268 	CreateContactL(KCntName,KCntSurname,KCntEndingByShortNumber1,KNullDesC);
       
   269 	CreateContactL(KCntName,KCntSurname,KCntEndingByShortNumber2,KNullDesC);
       
   270 	
       
   271 
       
   272 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber1,KNullDesC);
       
   273 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber2,KNullDesC);
       
   274 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber3,KNullDesC);
       
   275 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber4,KNullDesC);
       
   276 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber5,KNullDesC);
       
   277 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber6,KNullDesC);
       
   278 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber7,KNullDesC);
       
   279 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber8,KNullDesC);
       
   280 	CreateContactL(KCntName,KCntSurname,KCntDTMFNumber9,KNullDesC);
       
   281 	CreateContactL(KCntName,KCntSurname,KCntPossibleDefect,KNullDesC);
       
   282 	CreateContactL(KCntName,KCntSurname,KCntMatch1to7ExtraCharacters,KNullDesC);
       
   283 	CreateContactL(KCntName,KCntSurname,KCntMatch1to7Brackets,KNullDesC);
       
   284 	CreateContactL(KCntName,KCntSurname,KCntMatch1to7TooManyNumbers,KNullDesC);
       
   285 	TContactItemId id = CreateContactL(KCntName,KCntSurname,KCntZeroAtEnd,KNullDesC);
       
   286 
       
   287 	CheckPhoneMatchL(KCntMatch1to7,KMatch7Digits,9);
       
   288 	CheckPhoneMatchL(KCntMatch1to7,KLastThreeDigits,0);	// no contact with 567 as phone number  
       
   289 	CheckPhoneMatchL(KCntMatch1to7,KMatch7Digits,9);
       
   290 	CheckPhoneMatchL(KCntMatch1to7,KLastThreeDigits,0); // no contact with 567 as phone number  
       
   291 	
       
   292 	CheckPhoneMatchL(KCntMatch1to3,KMatch7Digits,1);
       
   293 	CheckPhoneMatchL(KCntMatch1to3,KMatch7Digits,1);
       
   294 
       
   295 	CheckPhoneMatchL(KCntPossibleDefect,KMatch7Digits,1);
       
   296 	CheckPhoneMatchL(KCntZeroAtEnd,KMatch7Digits,1);
       
   297 	CheckPhoneMatchL(KCntMatch700,KLastThreeDigits,0);  // no contact with 700 as phone number at this point 
       
   298 	CheckPhoneMatchL(KCntZeroAtEnd,KMatch7Digits,1);
       
   299 		
       
   300 	CheckPhoneMatchL(KCntNoRealDigitsInNumber,KMatch7Digits,0);
       
   301 	
       
   302 	CheckPhoneMatchL(KCntMatchShortNumber1,KLastThreeDigits,1); //
       
   303 	CheckPhoneMatchL(KCntMatchShortNumber2,KLastThreeDigits,1); //
       
   304 
       
   305 	// Simulate a synchronisation (increment the access count)
       
   306 	CContactItem* item = CntTest->Db()->OpenContactLX(id);
       
   307 	item->IncAccessCount();
       
   308 	CntTest->Db()->CommitContactL(*item);
       
   309 	CleanupStack::PopAndDestroy(); //lock record
       
   310 	delete item;
       
   311 	
       
   312 	// Delete the contact and verify that it has been removed from the phone match table 
       
   313 	CntTest->Db()->DeleteContactL(id);
       
   314 	CheckPhoneMatchL(KCntZeroAtEnd,KMatch7Digits,0);
       
   315 
       
   316 	CreateContactL(KCntName,KCntSurname,KCntSpaceInNumber,KNullDesC);
       
   317 	CheckPhoneMatchL(KCntSpaceMatch,KMatch7Digits,1);	
       
   318 	CreateContactL(KCntName,KCntSurname,KCntSpaceInNumberIntl,KNullDesC);
       
   319 	CheckPhoneMatchL(KCntSpaceInNumberIntlMatch,KMatch7Digits,1);	
       
   320 	CreateContactL(KCntName,KCntSurname,KCntSpaceWorstCase,KNullDesC);
       
   321 	}
       
   322 
       
   323 
       
   324 // Regression testcode for 
       
   325 // DUG-4ZVNBW "MatchPhoneNumberL doesn't match correctly without CNTPHONE.DLL"
       
   326 //
       
   327 // Remove CNTPHONE.DLL before running this test to verify
       
   328 //
       
   329 LOCAL_C void TestNoPhoneMatchLibraryL()
       
   330 	{
       
   331 	ResetDatabaseL();
       
   332 	_LIT(KCntNumberWithSpaces,"+44  020 7946 0000");
       
   333 	_LIT(KCntNumberWithoutSpaces,"02079460000");
       
   334 	CreateContactL(KCntName,KCntSurname,KCntNumberWithSpaces,KNullDesC);
       
   335 	CheckPhoneMatchL(KCntNumberWithoutSpaces,KMatch7Digits,1);
       
   336 	}
       
   337 
       
   338 
       
   339 LOCAL_C TContactItemId CreateFaxSMSContactL(const TDesC& aFirstName, const TDesC& aFamilyName, const TDesC& aFaxNo, const TDesC& aSMSNo)
       
   340 	{
       
   341 	CContactItem* item=CContactCard::NewLC();
       
   342 	SetNameL(*item,KUidContactFieldGivenName,KUidContactFieldVCardMapUnusedN,aFirstName,ETrue);
       
   343 	SetNameL(*item,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,aFamilyName,ETrue);
       
   344 	SetNameL(*item,KUidContactFieldFax,KUidContactFieldVCardMapFAX,aFaxNo,ETrue);
       
   345 	SetNameL(*item,KUidContactFieldSms,KUidContactFieldVCardMapTEL,aSMSNo,ETrue);
       
   346 	item->SetTemplateRefId(KGoldenTemplateId);
       
   347 	TContactItemId id=CntTest->Db()->AddNewContactL(*item);
       
   348 	CleanupStack::PopAndDestroy(item); 
       
   349 	return id;
       
   350 	}
       
   351 
       
   352 
       
   353 /** 
       
   354 Regression testcode for defect COY-567J99 "Phone number matching does not match Fax field"
       
   355 Testcode for adding fax and SMS numbers to the phone number match list
       
   356 */
       
   357 LOCAL_C void TestFaxSMSMatchingL()
       
   358 	{
       
   359 	ResetDatabaseL();
       
   360 
       
   361 	_LIT(KCntFaxNumber1,"020 79460585");
       
   362 	_LIT(KCntFaxNumber2,"020 79460432");
       
   363 	_LIT(KCntSMSNumber1,"+442079460432");
       
   364 	_LIT(KCntSMSNumber2,"+442079460585");
       
   365 	
       
   366 	_LIT(KCntDuplicateNumber,"0207 9460585");
       
   367 	_LIT(KCntNewSMSNumber,"020 79460696");
       
   368 	
       
   369 	TContactItemId one = CreateFaxSMSContactL(KCntName,KCntSurname,KCntFaxNumber1,KCntSMSNumber1);
       
   370 	TContactItemId two = CreateFaxSMSContactL(KCntName,KCntSurname,KCntFaxNumber2,KCntSMSNumber2);
       
   371 	
       
   372 	//check that there are only 2 matches
       
   373 	CheckPhoneMatchL(KCntDuplicateNumber,9,2);
       
   374 	
       
   375 	// delete contact one 
       
   376 	CntTest->Db()->DeleteContactL(one);
       
   377 	
       
   378 	//check that there is only 1 match now
       
   379 	CheckPhoneMatchL(KCntDuplicateNumber,9,1);
       
   380 
       
   381 	//edit item two
       
   382 	CContactItem* item = CntTest->Db()->OpenContactL(two);
       
   383 	CleanupStack::PushL(item);
       
   384 	CContactItemFieldSet& fieldSet = item->CardFields();
       
   385 	TInt fieldId=fieldSet.Find(KUidContactFieldSms);
       
   386 	CContactItemField& field = fieldSet[fieldId];
       
   387 	field.TextStorage()->SetTextL(KCntNewSMSNumber);
       
   388 	CntTest->Db()->CommitContactL(*item);
       
   389 	CleanupStack::PopAndDestroy(item);
       
   390 	
       
   391 	//check that there is no matches now
       
   392 	CheckPhoneMatchL(KCntDuplicateNumber,9,0);
       
   393 	}
       
   394 
       
   395 
       
   396 // Check that the speed dial at position aSpeedDialPosition matches the aExpectedId
       
   397 // and the contents of the field with aFieldId is the same in the speed dial.
       
   398 //
       
   399 LOCAL_C void CheckSpeedDialL(TInt aSpeedDialPosition, CContactItem& aContact, TInt aFieldId)
       
   400 	{
       
   401 	HBufC* buf=HBufC::NewLC(100);	
       
   402 	TPtr fieldContents=buf->Des();
       
   403 	
       
   404 	TContactItemId id = CntTest->Db()->GetSpeedDialFieldL(aSpeedDialPosition, fieldContents);
       
   405 	TPtrC actualContents =(aContact.CardFields()[aFieldId].TextStorage()->Text());
       
   406 	test(id==aContact.Id());
       
   407 	test(actualContents==fieldContents);
       
   408 
       
   409 	CleanupStack::PopAndDestroy(); //buf
       
   410 	}
       
   411 
       
   412 /**
       
   413  * Check that speed dials are working correctly;
       
   414  * Add first contact to speed dial 1, add second contact to speed dial 9.
       
   415  * Check speed dial 1 still matches contact 1 after adding speed dial
       
   416  * Check persistance of speed dial list
       
   417  * Check overwriting old speed dial with new contact id
       
   418  * Check deletion of contact removes all existing speed dials
       
   419  */
       
   420 LOCAL_C void SpeedDialSimpleTest()
       
   421 	{
       
   422 	ResetDatabaseL();
       
   423 	TRAP_IGNORE(PopulateDatabaseL(KTestContactsNum));
       
   424 	
       
   425 	const CContactIdArray* sortedItems = CntTest->Db()->SortedItemsL();
       
   426 
       
   427 	// first item in position 1
       
   428 	CContactItem* firstItem = CntTest->Db()->OpenContactL((*sortedItems)[0]);
       
   429 	CleanupStack::PushL(firstItem);
       
   430 	TInt fieldId=5;
       
   431 	const TInt speedDialPositionOne=1;
       
   432 	CntTest->Db()->SetFieldAsSpeedDialL(*firstItem, fieldId, speedDialPositionOne);
       
   433 	CheckSpeedDialL(speedDialPositionOne,*firstItem,fieldId);
       
   434 
       
   435 	// second item in position 2
       
   436 	CContactItem* secondItem = CntTest->Db()->OpenContactL((*sortedItems)[1]);
       
   437 	CleanupStack::PushL(secondItem);
       
   438 	fieldId=5;
       
   439 	const TInt speedDialPositionNine=9;
       
   440 	CntTest->Db()->SetFieldAsSpeedDialL(*secondItem, fieldId, speedDialPositionNine);
       
   441 	CheckSpeedDialL(speedDialPositionNine,*secondItem,fieldId);
       
   442 
       
   443 	// wrong answers..... 
       
   444 	CheckSpeedDialL(speedDialPositionOne,*firstItem,5);
       
   445 	
       
   446 	// check persistance
       
   447 	CntTest->CloseDatabase();
       
   448 	CntTest->OpenDatabaseL();
       
   449 	CheckSpeedDialL(speedDialPositionOne,*firstItem,5);
       
   450 	CheckSpeedDialL(speedDialPositionNine,*secondItem,5);
       
   451 
       
   452 	// check overwriting old speed dial (third contact, speed dial 1)
       
   453 	const CContactIdArray* newSortedItems = CntTest->Db()->SortedItemsL();
       
   454 	CContactItem* thirdItem = CntTest->Db()->OpenContactL((*newSortedItems)[2]);
       
   455 	CleanupStack::PushL(thirdItem);
       
   456 	fieldId=5;
       
   457 	CntTest->Db()->SetFieldAsSpeedDialL(*thirdItem, fieldId, speedDialPositionOne);
       
   458 	CheckSpeedDialL(speedDialPositionOne,*thirdItem,5);
       
   459 
       
   460 	// delete contact and check that speed dials have been removed
       
   461 	CntTest->Db()->DeleteContactL((*newSortedItems)[2]);
       
   462 	HBufC* temp8=HBufC::NewLC(100);	
       
   463 	TPtr testText8=temp8->Des();
       
   464 	TContactItemId eightId = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionOne, testText8);
       
   465 	test(eightId==KNullContactId);
       
   466 	test(testText8==KNullDesC);
       
   467 
       
   468 	// modify a contact with a speed dial - but do not change the relavent field.
       
   469 	CContactItem* fourthItem = CntTest->Db()->OpenContactL((*newSortedItems)[2]);
       
   470 	CleanupStack::PushL(fourthItem);
       
   471 	fieldId=5;
       
   472 	
       
   473 	CntTest->Db()->SetFieldAsSpeedDialL(*fourthItem, fieldId, speedDialPositionOne);
       
   474 	TInt fieldPosOfSpeedDial = fourthItem->CardFields().Find(KUidSpeedDialOne);
       
   475 	test(fieldPosOfSpeedDial != KErrNotFound);
       
   476   	
       
   477 	CContactItem* fifthItem = CntTest->Db()->OpenContactL(fourthItem->Id());
       
   478 	CleanupStack::PushL(fifthItem);
       
   479 
       
   480 	// remove the first field in the list.
       
   481 	fieldPosOfSpeedDial = fifthItem->CardFields().Find(KUidSpeedDialOne);
       
   482 
       
   483 	fifthItem->CardFields().Remove(1);
       
   484 	CntTest->Db()->CommitContactL(*fifthItem);
       
   485 	
       
   486 	CleanupStack::PopAndDestroy(6); // firstItem, secondItem, thirdItem, fourthItem, fifthItem, temp8
       
   487 	}
       
   488 
       
   489 
       
   490 /**
       
   491  *Add five contacts.
       
   492  * Set two speed dials - remove one & check the other is still there.
       
   493  */
       
   494 LOCAL_C void TestRemovingSpeedDialsL()
       
   495 	{
       
   496 	ResetDatabaseL();
       
   497 	PopulateDatabaseL(KTestContactsNum);
       
   498 	const CContactIdArray* sortedItems = CntTest->Db()->SortedItemsL(); //doesn't take ownership
       
   499 	const TInt speedDialPositionOne=1;
       
   500 	const TInt speedDialPositionNine=9;
       
   501 
       
   502 	
       
   503 	const TContactItemId firstId = (*sortedItems)[3];
       
   504 	const TContactItemId secondId = (*sortedItems)[5];
       
   505 
       
   506 	CContactItem* first = CntTest->Db()->OpenContactL(firstId);
       
   507 	CleanupStack::PushL(first);
       
   508 	CContactItemFieldSet& aFieldSet = first->CardFields();
       
   509 	for(TInt fieldLoop=0;fieldLoop<aFieldSet.Count();fieldLoop++)
       
   510 		{
       
   511 		CContactItemField& field = aFieldSet[fieldLoop];
       
   512 		if (field.ContentType().ContainsFieldType(KUidContactFieldPhoneNumber))
       
   513 			{
       
   514 			// change it...
       
   515 			field.TextStorage()->SetTextL(_L("956431458"));
       
   516 			}				
       
   517 		}
       
   518 	CntTest->Db()->CommitContactL(*first);
       
   519 	CleanupStack::PopAndDestroy(); //first
       
   520 
       
   521 	first = CntTest->Db()->OpenContactL(firstId);
       
   522 	CleanupStack::PushL(first);	
       
   523 	TInt fieldId=first->CardFields().Find(KUidContactFieldPhoneNumber);
       
   524 	CntTest->Db()->SetFieldAsSpeedDialL(*first, fieldId, speedDialPositionOne);
       
   525 
       
   526 	CContactItem* second = CntTest->Db()->OpenContactL(secondId);
       
   527 	CleanupStack::PushL(second);	
       
   528 	TInt fieldId2=first->CardFields().Find(KUidContactFieldPhoneNumber);
       
   529 	CntTest->Db()->SetFieldAsSpeedDialL(*second, fieldId2, speedDialPositionNine);
       
   530 
       
   531 	// check they are all established ok
       
   532 	HBufC* buf=HBufC::NewLC(100);	
       
   533 	TPtr fieldContents=buf->Des();
       
   534 	TContactItemId	id = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionOne, fieldContents);
       
   535 	test(id==firstId);
       
   536 	id = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionNine, fieldContents);
       
   537 	test(id==secondId);
       
   538 	CleanupStack::PopAndDestroy(); //buf
       
   539 
       
   540 	CntTest->Db()->RemoveSpeedDialFieldL(firstId, speedDialPositionOne);
       
   541 
       
   542 	HBufC* buf2=HBufC::NewLC(100);	
       
   543 	TPtr phoneNum=buf2->Des();
       
   544 	TContactItemId idOne = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionOne, phoneNum);
       
   545 	test(idOne==KNullContactId);
       
   546 	test(phoneNum==KNullDesC);
       
   547 	CleanupStack::PopAndDestroy(); //buf2
       
   548 
       
   549 
       
   550 	HBufC* buf3=HBufC::NewLC(100);	
       
   551 	TPtr phoneNo2=buf3->Des();
       
   552 	TContactItemId id2 = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionNine, phoneNo2);
       
   553 	test(id2==secondId);
       
   554 	CleanupStack::PopAndDestroy(); //buf
       
   555 
       
   556 	CntTest->Db()->RemoveSpeedDialFieldL(secondId, speedDialPositionNine);
       
   557 
       
   558 	HBufC* buf4=HBufC::NewLC(100);	
       
   559 	TPtr phoneNo3=buf4->Des();
       
   560 	id = CntTest->Db()->GetSpeedDialFieldL(speedDialPositionNine, phoneNo3);
       
   561 	test(id==KNullContactId);
       
   562 	test(phoneNum==KNullDesC);
       
   563 	CleanupStack::PopAndDestroy(); //buf4
       
   564 
       
   565 	CleanupStack::PopAndDestroy(2); //first, second
       
   566 	}
       
   567 
       
   568 /**
       
   569  * Verifies that matching of 11-digit phone number matching works correctly
       
   570  */
       
   571 LOCAL_C void Test11DigitMatchingL()
       
   572 	{
       
   573 	ResetDatabaseL();
       
   574 
       
   575 	_LIT(K11DigitTestNumber1,"020 7700 9001");
       
   576 	_LIT(K11DigitTestNumber2,"20 7700 90012");
       
   577 	_LIT(K11DigitTestNumber3,"020 7700 9081");
       
   578 	_LIT(K11DigitTestNumber4,"120 7700 9081");
       
   579 	_LIT(K11DigitTestNumber5,"9120 7700 9081");
       
   580 
       
   581 	CreateContactL(KCntName,KCntSurname,K11DigitTestNumber1,KNullDesC);
       
   582 	CreateContactL(KCntName,KCntSurname,K11DigitTestNumber2,KNullDesC);
       
   583 	CreateContactL(KCntName,KCntSurname,K11DigitTestNumber3,KNullDesC);
       
   584 	CreateContactL(KCntName,KCntSurname,K11DigitTestNumber4,KNullDesC);
       
   585 	CreateContactL(KCntName,KCntSurname,K11DigitTestNumber5,KNullDesC);
       
   586 
       
   587 	//Match numbers
       
   588 	_LIT(K11DigitMatch1,"020 7700 9001");
       
   589 	_LIT(K11DigitMatch2,"20 7700 90012");
       
   590 	_LIT(K11DigitMatch3,"020 7700 9081");
       
   591 	_LIT(K11DigitMatch4,"120 7700 9081");
       
   592 	_LIT(K11DigitMatch5,"9120 7700 9081");
       
   593 	_LIT(K11DigitMatch6,"20 7700 9081");
       
   594 
       
   595 	CheckPhoneMatchL(K11DigitMatch1,KMatch10Digits,1);
       
   596 	CheckPhoneMatchL(K11DigitMatch1,KMatch11Digits,1);
       
   597 
       
   598 	CheckPhoneMatchL(K11DigitMatch2,KMatch10Digits,1);
       
   599 	CheckPhoneMatchL(K11DigitMatch2,KMatch11Digits,1);
       
   600 
       
   601 	CheckPhoneMatchL(K11DigitMatch3,KMatch10Digits,3);
       
   602 	CheckPhoneMatchL(K11DigitMatch3,KMatch11Digits,1);
       
   603 
       
   604 	CheckPhoneMatchL(K11DigitMatch4,KMatch10Digits,3);
       
   605 	CheckPhoneMatchL(K11DigitMatch4,KMatch11Digits,2);
       
   606 
       
   607 	CheckPhoneMatchL(K11DigitMatch5,KMatch12Digits,1);
       
   608 	CheckPhoneMatchL(K11DigitMatch5,KMatch13Digits,1);
       
   609 
       
   610 	CheckPhoneMatchL(K11DigitMatch6,KMatch10Digits,3);
       
   611 	CheckPhoneMatchL(K11DigitMatch6,KMatch11Digits,3);
       
   612 	}
       
   613 
       
   614 /**
       
   615  * Verifies that 15 digit phone numbers are matched correctly.
       
   616  */
       
   617 LOCAL_C void Test15DigitMatchingL()
       
   618 	{
       
   619 	ResetDatabaseL();
       
   620 
       
   621 	_LIT(K15DigitTestNumber1,"0086 207 9476 0454");
       
   622 	_LIT(K15DigitTestNumber2,"8186 207 9476 0454");
       
   623 	_LIT(K15DigitTestNumber3,"8620 794 7604 5400");
       
   624 
       
   625 	CreateContactL(KCntName,KCntSurname,K15DigitTestNumber1,KNullDesC);
       
   626 	CreateContactL(KCntName,KCntSurname,K15DigitTestNumber2,KNullDesC);
       
   627 	CreateContactL(KCntName,KCntSurname,K15DigitTestNumber3,KNullDesC);
       
   628 
       
   629 	//Match numbers
       
   630 	_LIT(K15DigitMatch1,"0086 207 9476 0454");
       
   631 	_LIT(K15DigitMatch2,"86 207 9476 0454");
       
   632 	_LIT(K15DigitMatch3,"8186 207 9476 0454");
       
   633 	_LIT(K15DigitMatch4,"08186 207 9476 0454");
       
   634 
       
   635 	CheckPhoneMatchL(K15DigitMatch1,KMatch15Digits,1);
       
   636 	CheckPhoneMatchL(K15DigitMatch1,KMatch14Digits,1);
       
   637 	CheckPhoneMatchL(K15DigitMatch1,KMatch13Digits,2);
       
   638 
       
   639 	CheckPhoneMatchL(K15DigitMatch2,KMatch13Digits,2);
       
   640 
       
   641 	CheckPhoneMatchL(K15DigitMatch3,KMatch15Digits,1);
       
   642 
       
   643 	CheckPhoneMatchL(K15DigitMatch4,KMatch16Digits,0);
       
   644 	CheckPhoneMatchL(K15DigitMatch4,KMatch15Digits,1);
       
   645 	}
       
   646 
       
   647 
       
   648 /**
       
   649  * Verifies that phone numbers are matched correctly if they
       
   650  * have leading, trailing and embedded zeroes.
       
   651  */
       
   652 LOCAL_C void TestEmbeddedZeroesL()
       
   653 	{
       
   654 	ResetDatabaseL();
       
   655 
       
   656 	_LIT(KEmbeddedZeroesTestNumber1,"9999 9990 0999 999");
       
   657 	_LIT(KEmbeddedZeroesTestNumber2,"9000 0000 0000 000");
       
   658 	_LIT(KEmbeddedZeroesTestNumber3,"0000 0000 0000 000");
       
   659 	_LIT(KEmbeddedZeroesTestNumber4,"0000 0000 0000 009");
       
   660 	_LIT(KEmbeddedZeroesTestNumber5,"9 9000 000");
       
   661 	_LIT(KEmbeddedZeroesTestNumber6,"9000 000");
       
   662 
       
   663 	CreateContactL(KCntName,KCntSurname,KEmbeddedZeroesTestNumber1,KNullDesC);
       
   664 	CreateContactL(KCntName,KCntSurname,KEmbeddedZeroesTestNumber2,KNullDesC);
       
   665 	CreateContactL(KCntName,KCntSurname,KEmbeddedZeroesTestNumber3,KNullDesC);
       
   666 	CreateContactL(KCntName,KCntSurname,KEmbeddedZeroesTestNumber4,KNullDesC);
       
   667 	CreateContactL(KCntName,KCntSurname,KEmbeddedZeroesTestNumber5,KNullDesC);
       
   668 	CreateContactL(KCntName,KCntSurname,KEmbeddedZeroesTestNumber6,KNullDesC);
       
   669 
       
   670 	//Match numbers
       
   671 	_LIT(KEmbeddedZeroMatch1,"9999 9990 0999 999");
       
   672 	_LIT(KEmbeddedZeroMatch2,"9000 0000 0000 000");
       
   673 	_LIT(KEmbeddedZeroMatch3,"0000 0000 0000 000");
       
   674 	_LIT(KEmbeddedZeroMatch4,"0000 0000 0000 009");
       
   675 	_LIT(KEmbeddedZeroMatch5,"9 9000 000");
       
   676 	_LIT(KEmbeddedZeroMatch6,"9000 000");
       
   677 	_LIT(KEmbeddedZeroMatch7,"0000 000");
       
   678 
       
   679 	CheckPhoneMatchL(KEmbeddedZeroMatch1,KMatch15Digits,1);
       
   680 	CheckPhoneMatchL(KEmbeddedZeroMatch2,KMatch15Digits,1);
       
   681 	CheckPhoneMatchL(KEmbeddedZeroMatch3,KMatch15Digits,1);
       
   682 	CheckPhoneMatchL(KEmbeddedZeroMatch4,KMatch15Digits,1);
       
   683 	CheckPhoneMatchL(KEmbeddedZeroMatch5,KMatch15Digits,1);
       
   684 	CheckPhoneMatchL(KEmbeddedZeroMatch5,KMatch8Digits,1);
       
   685 	CheckPhoneMatchL(KEmbeddedZeroMatch6,KMatch7Digits,2);
       
   686 	CheckPhoneMatchL(KEmbeddedZeroMatch7,KMatch7Digits,2);
       
   687 	CheckPhoneMatchL(KEmbeddedZeroMatch6,KMatch6Digits,2);
       
   688 	}
       
   689 
       
   690 
       
   691 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ 	//we mark this since the new contact database based on SQLite 
       
   692                          		//as the porting on SQLite database allows the thorough DC break and
       
   693                          		//doesn't support the feature of database update from old database on
       
   694                          		//Symbian DBMS.
       
   695 void TestDbUpdateL()
       
   696 	{
       
   697 
       
   698     RPIMTestServer serv;
       
   699     User::LeaveIfError(serv.Connect());
       
   700     serv.CopyFileL(KSrcDatabaseName, KDatabaseName);
       
   701 
       
   702     serv.Close();
       
   703 
       
   704 	// Contact model must open and upgrade database
       
   705 	test.Printf(_L("Opening and upgrading database\n"));
       
   706 	CContactDatabase* db = NULL; 
       
   707 	db = CContactDatabase::OpenL(KDatabaseOpenName);
       
   708 
       
   709 	// Add a contact with a 15 digit phone number and match the same number
       
   710 	_LIT(K15DigitTestNumber,"0086 207 3453 1212");
       
   711 	_LIT(K15DigitMatch,"0086 207 3453 1212");
       
   712 	CreateContactL(KCntName,KCntSurname,K15DigitTestNumber,KNullDesC);
       
   713 	CheckPhoneMatchL(K15DigitMatch,KMatch15Digits,1);
       
   714 
       
   715 	delete db;
       
   716 	db = NULL;
       
   717 	}
       
   718 #endif // __SYMBIAN_CNTMODEL_USE_SQLITE__ 
       
   719 
       
   720 /**
       
   721 
       
   722 @SYMTestCaseID     PIM-T-NOMACH-0001
       
   723 
       
   724 */
       
   725 
       
   726 LOCAL_C void DoTestsL()
       
   727     {
       
   728 	test.Start(_L("@SYMTESTCaseID:PIM-T-NOMACH-0001 T_NOMACH"));
       
   729 
       
   730 
       
   731 	CTestRegister* TempFiles = CTestRegister::NewLC();
       
   732 	
       
   733 
       
   734 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   735 	TempFiles->RegisterL(KDatabaseOpenName, EFileTypeCnt);
       
   736 #endif // __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   737 	
       
   738 	TempFiles->RegisterL(KDatabaseFileName, EFileTypeCnt);
       
   739 
       
   740 	CntTest->CreateDatabaseL();
       
   741     TInt err;
       
   742     
       
   743 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ //see comments above function TestDbUpdateL 
       
   744 	test.Printf(KTestDbUpdate);
       
   745 	TRAP(err,TestDbUpdateL());
       
   746 	test(err==KErrNone);
       
   747 #endif // __SYMBIAN_CNTMODEL_USE_SQLITE__
       
   748 
       
   749 
       
   750 
       
   751      
       
   752 
       
   753 
       
   754 	test.Printf(KTest11Digitmatching);
       
   755 	TRAP(err,Test11DigitMatchingL());
       
   756 	test(err==KErrNone);
       
   757 
       
   758 	test.Printf(KTest15Digitmatching);
       
   759 	TRAP(err,Test15DigitMatchingL());
       
   760 	test(err==KErrNone);
       
   761 
       
   762 	test.Printf(KTestEmbeddedZeroes);
       
   763 	TRAP(err,TestEmbeddedZeroesL());
       
   764 	test(err==KErrNone);
       
   765 
       
   766 	test.Printf(KTestNoPhoneMatchLibrary);
       
   767 	TestNoPhoneMatchLibraryL();
       
   768 
       
   769 	test.Printf(KTestNewMatching);
       
   770 	TestNewMatchingL();
       
   771 
       
   772 
       
   773 	test.Printf(KTestFaxSMSMatching);
       
   774 	TestFaxSMSMatchingL();
       
   775 
       
   776 	test.Printf(KSpeedDialSimpleTest);
       
   777 	TRAP(err,SpeedDialSimpleTest());
       
   778 	test(err==KErrNone);
       
   779 
       
   780 	test.Printf(KTestRemovingSpeedDials);
       
   781 	TRAP(err,TestRemovingSpeedDialsL());
       
   782 	test(err==KErrNone);
       
   783 
       
   784 	CntTest->CloseDatabase();
       
   785 	CntTest->DeleteDatabaseL();
       
   786 
       
   787 	CleanupStack::PopAndDestroy(TempFiles);
       
   788 	
       
   789 	// stop efsrv.lib warning on 8.1a wins
       
   790 	TEntry dummy;
       
   791 	(void)dummy.IsTypeValid();
       
   792     }
       
   793 
       
   794 
       
   795 	
       
   796 GLDEF_C TInt E32Main()
       
   797 	{
       
   798     CntTest=new(ELeave) CCntTest;
       
   799 	CntTest->ConstructL(test,KDatabaseFileName);
       
   800     TRAPD(err,DoTestsL());
       
   801 	test.Printf(_L("\n"));
       
   802 	CntTest->EndTestLib(err);
       
   803 
       
   804 	return KErrNone;
       
   805     }