phonebookengines_old/contactsmodel/tsrc/t_CntFindAll.cpp
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 1999-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 /**
       
    17 @SYMTestCaseID PIM-T-CNTFINDALL-INC049017-0001
       
    18 @SYMTestPriority High
       
    19 @SYMDEF INC049017
       
    20 @SYMTestCaseDependencies cnttutil
       
    21 @SYMTestCaseDesc Tests that Identity fields are searched when FindAsyncL and FindLC are used with KUidContactFieldMatchAll.
       
    22 @SYMTestActions Create a contact database and add four contacts.
       
    23 Search the database by using identity fields: GivenName, FamilyName and CompanyName.
       
    24 Search for contacts by providing a name and using KUidContactFieldMatchAll.
       
    25 Perform the search synchronously and asynchronously.
       
    26 @SYMTestExpectedResults Contacts are found by given name, family name or company name when using KUidContactFieldMatchAll.
       
    27 */
       
    28 #include <e32std.h>
       
    29 #include <e32test.h>
       
    30 #include <e32math.h>
       
    31 #include <cntdb.h>
       
    32 #include <cntitem.h>
       
    33 #include <cntfldst.h>
       
    34 
       
    35 #include "t_utils2.h"
       
    36 #include "t_CntFindAll.h"
       
    37 
       
    38 
       
    39 // Constants.
       
    40 _LIT(KTestName,"t_CntFindAll");
       
    41 _LIT(KDbFileName,"c:contacts.cdb");
       
    42 _LIT(KLogFileName,"t_cntFindAll.log");
       
    43 _LIT(KDummyData, "Some dummy data");
       
    44 
       
    45 // CFindTest.
       
    46 CFindTest::CFindTest()
       
    47  : iTest(KTestName),
       
    48  iLogFileName(KLogFileName),
       
    49  iDbFileName(KDbFileName)
       
    50 	{
       
    51 	}
       
    52 
       
    53 CFindTest::~CFindTest()
       
    54 	{
       
    55 	delete iTemplate;
       
    56 	delete iDb;
       
    57 	delete iLog;
       
    58 	iTest.Close();
       
    59 	}
       
    60 
       
    61 void CFindTest::ConstructL()
       
    62 	{
       
    63 	iLog=CLog::NewL(iTest,iLogFileName);
       
    64 	}
       
    65 
       
    66 
       
    67 void CFindTest::DoTestsL()
       
    68 	{
       
    69 	iTest.Title(); 
       
    70 	iTest.Start(_L("@SYMTestCaseID:PIM-T-CNTFINDALL-INC049017-0001 CREATING THE DATABASE"));
       
    71 	iDb=CContactDatabase::ReplaceL(iDbFileName);
       
    72 	iTemplate=STATIC_CAST(CContactTemplate*,iDb->ReadContactL(iDb->TemplateId()));
       
    73 
       
    74 	iTest.Next(_L("ADDING COMPACT CONTACTS"));
       
    75 		{
       
    76 		iLog->LogLine(_L("Adding The Contacts."));
       
    77 	//	AddContactCompactL(aFirstName,aLastName,aCompanyName,aWorkPhone, 
       
    78 	//												aHomePhone,& aWorkMobile,aHomeMobile,aWorkEmail)											
       
    79 		AddContactCompactL(_L("TestRt"),_L("Jrtstn"),_L("Example Company"),_L("02079460100"), 
       
    80 												_L("02079460900"), _L("07700900329"),_L("07700900300"),_L("tj2@example_company.abc"));									
       
    81 		AddContactCompactL(_L("Atsta"),_L("Jrtstn"),_L("Example Company"),_L("02079460100"), 
       
    82 												_L("02079460900"), _L("07700900101"),_L("07700900301"),_L("aj2@example_company.abc"));									
       
    83 		AddContactCompactL(_L("Btest"),_L("Tester"),_L("High Test Example"),_L("02079460658"), 
       
    84 												_L("02079460901"), _L("07700900210"),_L("07700900321"),_L("btester@hightestex.abc"));									
       
    85 		AddContactCompactL(_L("Chtsts"),_L("Artestw"),_L("Testx Kick"),_L("1234567890"), 
       
    86 												_L("02079460678"), _L("07700900890"),_L("07700900891"),_L("c_Artestw@testxkick.abc"));
       
    87 		}
       
    88 
       
    89 	//start of tests for defect where identity fields were not searched when using KUidMatchInAllFields
       
    90 	iTest.Next(_L("FINDING CONTACTS BY NAME FROM GIVEN NAME FIELD."));
       
    91 		{
       
    92 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY NAME FROM GIVEN NAME FIELD."));
       
    93 		FindNameInFirstNameFieldL(_L("Chtsts"),1);
       
    94 		FindNameInFirstNameFieldL(_L("Tester"),0);
       
    95 		FindNameInFirstNameFieldL(_L("e"),2);
       
    96 		}
       
    97 
       
    98 	iTest.Next(_L("FINDING CONTACTS BY NAME FROM FAMILY NAME FIELD"));
       
    99 		{
       
   100 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY NAME FROM FAMILY NAME FIELD."));
       
   101 		FindNameInLastNameFieldL(_L("Tester"),1);
       
   102 		FindNameInLastNameFieldL(_L("Jrtstn"),2);
       
   103 		FindNameInLastNameFieldL(_L("r"),4);
       
   104 		FindNameInLastNameFieldL(_L("Chtsts"),0);
       
   105 		}
       
   106 
       
   107 	iTest.Next(_L("FINDING CONTACTS BY NAME FROM ALL FIELDS"));
       
   108 		{
       
   109 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY NAME FROM ALL FIELDS"));
       
   110 		FindInAllFieldsL(_L("Btest"),1);
       
   111 		FindInAllFieldsL(_L("Jrtstn"),2);
       
   112 		FindInAllFieldsL(_L("r"),4);
       
   113 		FindInAllFieldsL(_L("xxxxxxxxx"),0);
       
   114 		}
       
   115 
       
   116 	iTest.Next(_L("FINDING CONTACTS BY COMPANY FROM COMPANY NAME FIELD"));
       
   117 		{
       
   118 		iLog->LogLine(_L("\r\nFINDING CONTACTS COMPANY FROM COMPANY NAME FIELD"));
       
   119 		FindInCompanyFieldL(_L("Btest"),0);
       
   120 		FindInCompanyFieldL(_L("High Test Example"),1);
       
   121 		FindInCompanyFieldL(_L("Example Company"),2);
       
   122 		FindInCompanyFieldL(_L("c"),3);
       
   123 		}
       
   124 
       
   125 	iTest.Next(_L("FINDING CONTACTS BY COMPANY FROM  ALL FIELDS"));
       
   126 		{
       
   127 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY COMPANY FROM ALL FIELDS"));
       
   128 		FindInAllFieldsL(_L("Kick"),1);
       
   129 		FindInAllFieldsL(_L("High Test Example"),1);
       
   130 		FindInAllFieldsL(_L("Example Company"),2);
       
   131 		FindInAllFieldsL(_L("c"),4);
       
   132 		}
       
   133 	//end of tests for defect where identity fields were not searched when using KUidMatchInAllFields
       
   134 
       
   135 	//start of Async tests for defect where identity fields were not searched when using KUidMatchInAllFields
       
   136 	iTest.Next(_L("FINDING CONTACTS BY NAME FROM GIVEN NAME FIELD ASYNCHRONOUSLY"));
       
   137 		{
       
   138 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY NAME FROM GIVEN NAME FIELD ASYNCHRONOUSLY."));
       
   139 		FindNameInFirstNameFieldL(_L("Chtsts"),1,ETrue);
       
   140 		FindNameInFirstNameFieldL(_L("Tester"),0,ETrue);
       
   141 		FindNameInFirstNameFieldL(_L("e"),2,ETrue);
       
   142 		}
       
   143 
       
   144 	iTest.Next(_L("FINDING CONTACTS BY NAME FROM FAMILY NAME FIELD ASYNCHRONOUSLY"));
       
   145 		{
       
   146 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY NAME FROM FAMILY NAME FIELD ASYNCHRONOUSLY."));
       
   147 		FindNameInLastNameFieldL(_L("Tester"),1,ETrue);
       
   148 		FindNameInLastNameFieldL(_L("Jrtstn"),2,ETrue);
       
   149 		FindNameInLastNameFieldL(_L("r"),4,ETrue);
       
   150 		FindNameInLastNameFieldL(_L("Chtsts"),0,ETrue);
       
   151 		}
       
   152 
       
   153 	iTest.Next(_L("FINDING CONTACTS BY NAME FROM ALL FIELDS ASYNCHRONOUSLY"));
       
   154 		{
       
   155 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY NAME FROM ALL FIELDS ASYNCHRONOUSLY"));
       
   156 		FindInAllFieldsL(_L("Btest"),1,ETrue);
       
   157 		FindInAllFieldsL(_L("Jrtstn"),2,ETrue);
       
   158 		FindInAllFieldsL(_L("r"),4,ETrue);
       
   159 		FindInAllFieldsL(_L("xxxxxxxxx"),0,ETrue);
       
   160 		}
       
   161 
       
   162 	iTest.Next(_L("FINDING CONTACTS BY COMPANY FROM COMPANY NAME FIELD"));
       
   163 		{
       
   164 		iLog->LogLine(_L("\r\nFINDING CONTACTS COMPANY FROM COMPANY NAME FIELD ASYNCHRONOUSLY"));
       
   165 		FindInCompanyFieldL(_L("Btest"),0,ETrue);
       
   166 		FindInCompanyFieldL(_L("High Test Example"),1,ETrue);
       
   167 		FindInCompanyFieldL(_L("Example Company"),2,ETrue);
       
   168 		FindInCompanyFieldL(_L("s"),2,ETrue);
       
   169 		}
       
   170 
       
   171 	iTest.Next(_L("FINDING CONTACTS BY COMPANY FROM  ALL FIELDS ASYNCHRONOUSLY"));
       
   172 		{
       
   173 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY COMPANY FROM ALL FIELDS ASYNCHRONOUSLY"));
       
   174 		FindInAllFieldsL(_L("Kick"),1,ETrue);
       
   175 		FindInAllFieldsL(_L("High Test Example"),1,ETrue);
       
   176 		FindInAllFieldsL(_L("Example Company"),2,ETrue);
       
   177 		FindInAllFieldsL(_L("s"),4,ETrue);
       
   178 		}
       
   179     iTest.Next(_L("FINDING CONTACTS BY SIP ADDRESS IN ALL FIELDS ASYNCHRONOUSLY"));
       
   180         {
       
   181 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY SIP ADDRESS IN ALL FIELDS"));
       
   182 		FindInSipAddressL(_L("123@a.com"),1, ETrue);
       
   183 		}
       
   184 	//end of Async tests for defect where identity fields were not searched when using KUidMatchInAllFields
       
   185 
       
   186 	//the following tests were not part of the defect but included as regression testing
       
   187 	iTest.Next(_L("FINDING CONTACTS BY WORK PHONE NUMBER FROM   PHONE FIELD"));
       
   188 		{ 
       
   189 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY WORK PHONE NUMBER FROM   PHONE FIELD"));
       
   190 		FindPhoneNumberL(_L("02079460100"),2);
       
   191 		FindPhoneNumberL(_L("02079460658"),1);
       
   192 		FindPhoneNumberL(_L("999999999999"),0);
       
   193 		}
       
   194 	iTest.Next(_L("FINDING CONTACTS BY  HOME PHONE NUMBER FROM PHONE FIELD"));
       
   195 		{
       
   196 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY HOME PHONE NUMBER FROM   PHONE FIELD"));
       
   197 		FindPhoneNumberL(_L("02079460900"),2);
       
   198 		FindPhoneNumberL(_L("02079460678"),1);
       
   199 		FindPhoneNumberL(_L("999999999999"),0);
       
   200 		}
       
   201 	iTest.Next(_L("FINDING CONTACTS BY  WORK MOBILE  NUMBER FROM PHONE FIELD"));
       
   202 		{
       
   203 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY WORK MOBILE NUMBER FROM   PHONE FIELD"));
       
   204 		FindPhoneNumberL(_L("07700900329"),1);
       
   205 		FindPhoneNumberL(_L("07700900101"),1);
       
   206 		FindPhoneNumberL(_L("07700900210"),1);
       
   207 		FindPhoneNumberL(_L("999999999999"),0);
       
   208 		}
       
   209 	iTest.Next(_L("FINDING CONTACTS BY HOME MOBILE  NUMBER FROM  PHONE FIELD"));
       
   210 		{
       
   211 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY HOME MOBILE NUMBER FROM   PHONE FIELD"));
       
   212 		FindPhoneNumberL(_L("07700900891"),1);
       
   213 		FindPhoneNumberL(_L("07700900301"),1);
       
   214 		FindPhoneNumberL(_L("07700900300"),1);
       
   215 		FindPhoneNumberL(_L("999999999999"),0);
       
   216 		}
       
   217 	iTest.Next(_L("FINDING CONTACTS BY PHONE NUMBER FROM  ALL FIELDS"));
       
   218 		{
       
   219 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY PHONE NUMBER FROM  ALL FIELDS"));
       
   220 		FindInAllFieldsL(_L("02079460100"),2);
       
   221 		FindInAllFieldsL(_L("02079460900"),2);
       
   222 		FindInAllFieldsL(_L("02079460658"),1);
       
   223 		FindInAllFieldsL(_L("02079460678"),1);
       
   224 		FindInAllFieldsL(_L("999999999999"),0);
       
   225 		}
       
   226 	iTest.Next(_L("FINDING CONTACTS BY EMAIL FROM  EMAIL FIELD"));
       
   227 		{
       
   228 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY EMAIL FROM  EMAIL FIELD"));
       
   229 		FindEmailAddressL(_L("@@"),0);
       
   230 		FindEmailAddressL(_L("aj2@example_company.abc"),1);
       
   231 		FindEmailAddressL(_L("example_company.abc"),2);
       
   232 		FindEmailAddressL(_L("example"),2);
       
   233 		FindEmailAddressL(_L("@"),4);
       
   234 		}
       
   235 	iTest.Next(_L("FINDING CONTACTS BY EMAIL FROM  ALL FIELDS"));
       
   236 		{
       
   237 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY EMAIL FROM  ALL FIELDS"));
       
   238 		FindInAllFieldsL(_L("@@"),0);
       
   239 		FindInAllFieldsL(_L("aj2@example_company.abc"),1);
       
   240 		FindInAllFieldsL(_L("example_company.abc"),2);
       
   241 		FindInAllFieldsL(_L("example"),3);
       
   242 		FindInAllFieldsL(_L("@"),4);
       
   243 		}
       
   244 	iTest.Next(_L("FINDING CONTACTS BY NOTES FROM NOTES FIELDS"));
       
   245 		{
       
   246 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY NOTES FROM  NOTES FIELDS"));
       
   247 		FindNotesL(_L("dummy"),4);
       
   248 		FindNotesL(_L("dummy"),4, ETrue);
       
   249 		FindNotesL(_L("nonexistant"),0);
       
   250 		FindNotesL(_L("nonexistant"),0, ETrue);
       
   251 		}
       
   252 	iTest.Next(_L("FINDING CONTACTS BY SIP ADDRESS IN ALL FIELDS"));
       
   253         {
       
   254 		iLog->LogLine(_L("\r\nFINDING CONTACTS BY SIP ADDRESS IN ALL FIELDS"));
       
   255 		FindInSipAddressL(_L("123@a.com"),1);
       
   256 		}
       
   257 	iTest.Next(_L("FINDING NOTES FROM  ALL FIELDS"));
       
   258 		{
       
   259 		iLog->LogLine(_L("\r\nFINDING NOTES FROM  ALL FIELDS"));
       
   260 		FindInAllFieldsL(_L("dummy"),4);
       
   261 		FindInAllFieldsL(_L("dummy"),4, ETrue);
       
   262 		FindInAllFieldsL(_L("nonexistant"),0);
       
   263 		FindInAllFieldsL(_L("nonexistant"),0, ETrue);
       
   264 		}
       
   265 	iTest.Next(_L("FINDING All CONTACTS WITH NULL SEARCH STRING"));
       
   266 		{
       
   267 		iLog->LogLine(_L("\r\nFINDING All CONTACTS WITH NULL SEARCH STRING"));
       
   268 				
       
   269 		//Create a new database and check that there are no contacts on it.
       
   270 		delete iDb;
       
   271 		iDb=CContactDatabase::ReplaceL(iDbFileName);
       
   272 		iTest(iDb->CountL() == 0);
       
   273 
       
   274 		//Add a fixed number of contacts to the database and check if they have been added or not.
       
   275 		CRandomContactGenerator* rcg = CRandomContactGenerator::NewL();
       
   276 		CleanupStack::PushL(rcg);
       
   277 		rcg->SetDbL(*iDb);
       
   278 		const TInt KContactsCount = 50;
       
   279 		for(TInt count = 0;count < KContactsCount;++count)
       
   280 			{
       
   281 			rcg->AddTypicalRandomContactL();
       
   282 			}
       
   283 		iTest(iDb->CountL() == KContactsCount);
       
   284 		
       
   285 		//Actual Test: This should return all 50 contacts. No less, no more!
       
   286 		FindInAllFieldsL(_L(""), KContactsCount, ETrue);
       
   287 		CleanupStack::PopAndDestroy();
       
   288 		}
       
   289 	iTest.End();
       
   290 	}
       
   291 
       
   292 void CFindTest::AddContactL(const TDesC& aFirstName,const TDesC& aLastName,const TDesC& aCompanyName,
       
   293 													const TDesC& aWorkPhone,const TDesC& aHomePhone,const TDesC& aWorkMobile,
       
   294 													const TDesC& aHomeMobile,const TDesC& aWorkEmail)
       
   295 	{
       
   296 	iLog->LogLine(_L("\r\nAdding Contact "));
       
   297 	iLog->LogLine(_L("Name: %S %S"),&aFirstName,&aLastName);
       
   298 	iLog->LogLine(_L("Company: %S "),&aCompanyName);
       
   299 	iLog->LogLine(_L("WorkPhone: %S "),&aWorkPhone);
       
   300 	iLog->LogLine(_L("WorkMob: %S"),&aWorkMobile);
       
   301 	iLog->LogLine(_L("HomePhone: %S"),&aHomePhone);
       
   302 	iLog->LogLine(_L("HomeMob: %S"),&aHomeMobile);
       
   303 	iLog->LogLine(_L("Email: %S "),&aWorkEmail);
       
   304 
       
   305 	CTestContact* contact=CTestContact::NewLC(*iTemplate);
       
   306 	
       
   307 	contact->SetFirstNameL(aFirstName);
       
   308 	contact->SetLastNameL(aLastName);
       
   309 	contact->SetCompanyNameL(aCompanyName);
       
   310 	contact->SetWorkPhoneL(aWorkPhone);
       
   311 	contact->SetHomePhoneL(aHomePhone);
       
   312 	contact->SetWorkMobileL(aWorkMobile);
       
   313 	contact->SetHomeMobileL(aHomeMobile);
       
   314 	contact->SetWorkEmailAddressL(aWorkEmail);
       
   315 	contact->SetNotesL(KDummyData);	
       
   316 	iDb->AddNewContactL(contact->ContactItem());
       
   317 	CleanupStack::PopAndDestroy(1);  //contact.
       
   318 
       
   319 	}
       
   320 
       
   321 void CFindTest::AddContactCompactL(const TDesC& aFirstName,const TDesC& aLastName,const TDesC& aCompanyName,
       
   322 																	  const TDesC& aWorkPhone,const TDesC& aHomePhone,const TDesC& aWorkMobile,
       
   323 																	  const TDesC& aHomeMobile,const TDesC& aWorkEmail)
       
   324 	{
       
   325 	AddContactL(aFirstName,aLastName,aCompanyName,aWorkPhone,aHomePhone,aWorkMobile,aHomeMobile,aWorkEmail);
       
   326 	iDb->CompactL();
       
   327 	}
       
   328 
       
   329 void CFindTest::FindNameInFirstNameFieldL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync)
       
   330 	{
       
   331 	iLog->LogLine(_L("Find %S in Given name field"),&aTextToFind);	
       
   332 	CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef();
       
   333 	CleanupStack::PushL(def);
       
   334 	def->AppendL(KUidContactFieldGivenName);
       
   335 	if(!aAsync)
       
   336 		{
       
   337 		DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   338 		}
       
   339 	else
       
   340 		{
       
   341 		DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   342 		}
       
   343 	CleanupStack::PopAndDestroy(); // def.
       
   344 	}
       
   345 
       
   346 void CFindTest::FindNameInLastNameFieldL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync)
       
   347 	{
       
   348 	iLog->LogLine(_L("Find %S in Family name field"),&aTextToFind);	
       
   349 	CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef();
       
   350 	CleanupStack::PushL(def);
       
   351 	def->AppendL(KUidContactFieldFamilyName);
       
   352 	if(!aAsync)
       
   353 		{
       
   354 		DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   355 		}	
       
   356 	else
       
   357 		{
       
   358 		DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   359 		}
       
   360 	CleanupStack::PopAndDestroy(); // def.	
       
   361 	}
       
   362 
       
   363 void CFindTest::FindInSipAddressL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync)
       
   364     {
       
   365     CContactCard *contactItem = CContactCard::NewL(iTemplate); CleanupStack::PushL(contactItem);
       
   366 
       
   367     CContactItemField* itemFieldPtr = CContactItemField::NewLC( KStorageTypeText, KUidContactFieldSIPID );
       
   368     CContactTextField* textStoragePtr = itemFieldPtr->TextStorage();
       
   369     textStoragePtr->SetTextL( aTextToFind );
       
   370     contactItem->AddFieldL( *itemFieldPtr );
       
   371     CleanupStack::Pop( itemFieldPtr ); 
       
   372  
       
   373     CContactItemField* itemFieldPtr_1 = CContactItemField::NewLC( KStorageTypeStore, KUidContactFieldPicture );
       
   374     CContactStoreField* binaryStoragePtr = itemFieldPtr_1->StoreStorage();
       
   375       
       
   376     binaryStoragePtr->SetThingL(_L8("Jpeg"));
       
   377      
       
   378     contactItem->AddFieldL( *itemFieldPtr_1 ); 
       
   379     CleanupStack::Pop( itemFieldPtr_1 ); 
       
   380            
       
   381     TContactItemId id = iDb->AddNewContactL(*contactItem);
       
   382    
       
   383     CContactItemFieldDef* def = new(ELeave) CContactItemFieldDef();
       
   384     CleanupStack::PushL(def);
       
   385     def->AppendL(KUidContactFieldSIPID);
       
   386  
       
   387     if(!aAsync)
       
   388         {
       
   389         DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   390         }
       
   391     else
       
   392         {
       
   393         DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   394         }
       
   395 
       
   396     CleanupStack::PopAndDestroy(2); //def, contactItem
       
   397     
       
   398     iDb->DeleteContactL(id);
       
   399         
       
   400     contactItem = CContactCard::NewL(iTemplate); 
       
   401     CleanupStack::PushL(contactItem);
       
   402     
       
   403     itemFieldPtr = CContactItemField::NewLC( KStorageTypeText, KUidContactFieldFamilyName );
       
   404     textStoragePtr = itemFieldPtr->TextStorage();
       
   405     textStoragePtr->SetTextL( _L("A") );
       
   406     contactItem->AddFieldL( *itemFieldPtr );
       
   407     CleanupStack::Pop( itemFieldPtr ); 
       
   408     id = iDb->AddNewContactL(*contactItem);
       
   409     CleanupStack::PopAndDestroy( contactItem );
       
   410    
       
   411     // retrieve the contact add an image to it
       
   412     CContactItem *contactItem1 = iDb->OpenContactL( id );
       
   413     CleanupStack::PushL( contactItem1 );
       
   414     itemFieldPtr_1 = CContactItemField::NewLC( KStorageTypeStore, KUidContactFieldVCardMapJPEG );
       
   415     binaryStoragePtr = itemFieldPtr_1->StoreStorage();   
       
   416     binaryStoragePtr->SetThingL(_L8("Jpeg"));
       
   417    
       
   418     contactItem1->AddFieldL( *itemFieldPtr_1 ); 
       
   419     CleanupStack::Pop( itemFieldPtr_1 );
       
   420     iDb->CommitContactL(*contactItem1);
       
   421     iDb->CloseContactL( id );
       
   422     CleanupStack::PopAndDestroy( contactItem1 );
       
   423    
       
   424     //retrieve the contact and add voip to it
       
   425     CContactItem *contactItem2 = iDb->OpenContactL( id );
       
   426     CleanupStack::PushL( contactItem2 );
       
   427     CContactItemField* itemFieldPtr2 = CContactItemField::NewLC( KStorageTypeText, KUidContactFieldSIPID );
       
   428     CContactTextField* textStoragePtr2 = itemFieldPtr2->TextStorage();
       
   429     textStoragePtr2->SetTextL( aTextToFind );
       
   430     contactItem2->AddFieldL( *itemFieldPtr2 );
       
   431     CleanupStack::Pop( itemFieldPtr2 );
       
   432     iDb->CommitContactL( *contactItem2 );
       
   433     iDb->CloseContactL( id );
       
   434     CleanupStack::PopAndDestroy( contactItem2 );
       
   435   
       
   436     // find the contact with voip number
       
   437     def = new(ELeave) CContactItemFieldDef();
       
   438     CleanupStack::PushL(def);
       
   439     def->AppendL(KUidContactFieldSIPID);
       
   440     if(!aAsync)
       
   441         {
       
   442         DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   443         }
       
   444     else
       
   445         {
       
   446         DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   447         }
       
   448 
       
   449     CleanupStack::PopAndDestroy(1); 
       
   450    
       
   451     iDb->DeleteContactL(id);
       
   452     }
       
   453 
       
   454 void CFindTest::FindInAllFieldsL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync)
       
   455 	{
       
   456 	iLog->LogLine(_L("Find %S in All fields"),&aTextToFind);	
       
   457 	CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef();
       
   458 	CleanupStack::PushL(def);
       
   459 	def->AppendL(KUidContactFieldMatchAll);
       
   460 	if(!aAsync)
       
   461 		{
       
   462 		DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   463 		}
       
   464 	else
       
   465 		{
       
   466 		DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   467 		}
       
   468 	CleanupStack::PopAndDestroy(); // def.
       
   469 	}
       
   470 
       
   471 void CFindTest::FindInCompanyFieldL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync)
       
   472 	{
       
   473 	iLog->LogLine(_L("Find %S in Company name field"),&aTextToFind);	
       
   474 	CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef();
       
   475 	CleanupStack::PushL(def);
       
   476 	def->AppendL(KUidContactFieldCompanyName);
       
   477 	if(!aAsync)
       
   478 		{
       
   479 		DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   480 		}
       
   481 	else
       
   482 		{
       
   483 		DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   484 		}
       
   485 	CleanupStack::PopAndDestroy(); // def.
       
   486 	}
       
   487 
       
   488 void CFindTest::FindPhoneNumberL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync)
       
   489 	{
       
   490 	iLog->LogLine(_L("Find %S in Phone fields"),&aTextToFind);	
       
   491 	CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef();
       
   492 	CleanupStack::PushL(def);
       
   493 	def->AppendL(KUidContactFieldPhoneNumber);
       
   494 	if(!aAsync)
       
   495 		{
       
   496 		DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   497 		}
       
   498 	else
       
   499 		{
       
   500 		DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   501 		}
       
   502 	CleanupStack::PopAndDestroy(); // def.
       
   503 	}
       
   504 
       
   505 void CFindTest::FindEmailAddressL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync)
       
   506 	{
       
   507 	iLog->LogLine(_L("Find %S in Email fields"),&aTextToFind);	
       
   508 	CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef();
       
   509 	CleanupStack::PushL(def);
       
   510 	def->AppendL(KUidContactFieldEMail);
       
   511 	if(!aAsync)
       
   512 		{
       
   513 		DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   514 		}
       
   515 	else
       
   516 		{
       
   517 		DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   518 		}
       
   519 	CleanupStack::PopAndDestroy(); // def.
       
   520 	}
       
   521 	
       
   522 void CFindTest::FindNotesL(const TDesC& aTextToFind, const TInt aNumExpectedFinds,TBool aAsync)
       
   523 	{
       
   524 	iLog->LogLine(_L("Find %S in Email fields"),&aTextToFind);	
       
   525 	CContactItemFieldDef* def=new(ELeave) CContactItemFieldDef();
       
   526 	CleanupStack::PushL(def);
       
   527 	def->AppendL(KUidContactFieldNote);
       
   528 	
       
   529 	if(!aAsync)
       
   530 		{	
       
   531 	    DoFindL(aTextToFind,*def,aNumExpectedFinds);
       
   532 		}
       
   533 	else
       
   534 		{
       
   535 		DoFindAsyncL(aTextToFind,*def,aNumExpectedFinds);
       
   536 		}
       
   537 	CleanupStack::PopAndDestroy(); // def.
       
   538 	}	
       
   539 
       
   540 void CFindTest::DoFindL(const TDesC& aTextToFind,const CContactItemFieldDef& aFieldDef, const TInt aNumExpectedFinds)
       
   541 	{
       
   542 	CContactIdArray* matchList=iDb->FindLC(aTextToFind,&aFieldDef);
       
   543 
       
   544 	const TInt numIds=matchList->Count();
       
   545 	iLog->LogLine(_L("Matched %d contact(s) of %d expected"),numIds,aNumExpectedFinds);
       
   546 	if(numIds!=aNumExpectedFinds)
       
   547 		{
       
   548 		iLog->LogLine(_L("%S FAILED!"),&KTestName);
       
   549 		}
       
   550 	iTest(numIds==aNumExpectedFinds);
       
   551 	CleanupStack::PopAndDestroy(); // matchList.
       
   552 	}
       
   553 
       
   554 void CFindTest::DoFindAsyncL(const TDesC& aTextToFind,const CContactItemFieldDef& aFieldDef, const TInt aNumExpectedFinds)
       
   555 	{
       
   556 	iIdleFinder=iDb->FindAsyncL(aTextToFind,&aFieldDef,this);
       
   557 	CleanupStack::PushL(iIdleFinder); // Handle on cleanup stack because object is very temporary.
       
   558 	CActiveScheduler::Start();
       
   559 
       
   560 	CContactIdArray* matchList=iIdleFinder->TakeContactIds();
       
   561 	CleanupStack::PushL(matchList);
       
   562 	const TInt numIds=matchList->Count();
       
   563 	iLog->LogLine(_L("Matched %d contact(s) of %d expected"),numIds,aNumExpectedFinds);
       
   564 	if(numIds!=aNumExpectedFinds)
       
   565 		{
       
   566 		iLog->LogLine(_L("%S FAILED!"),&KTestName);
       
   567 		}
       
   568 	iTest(numIds==aNumExpectedFinds);
       
   569 	CleanupStack::PopAndDestroy(2); // matchList.  iIdleFinder.
       
   570 	}
       
   571 
       
   572 void CFindTest::IdleFindCallback()
       
   573 	{
       
   574 	if (iIdleFinder->IsComplete())
       
   575 		{
       
   576 		CActiveScheduler::Stop();
       
   577 		}
       
   578 	}
       
   579 
       
   580 //
       
   581 // Main.
       
   582 //
       
   583 
       
   584 GLDEF_C TInt E32Main()
       
   585 	{
       
   586 	RDebug::Print(_L("t_cntfindall started"));
       
   587 	__UHEAP_MARK;
       
   588 	
       
   589 	CActiveScheduler* sheduler=new CActiveScheduler;
       
   590 	if (sheduler)
       
   591 		{
       
   592 		CActiveScheduler::Install(sheduler);
       
   593 		CTrapCleanup* cleanup=CTrapCleanup::New();
       
   594 		if (cleanup)
       
   595 			{
       
   596 			CFindTest* findtest=new CFindTest();//::NewL();
       
   597 			if (findtest)
       
   598 				{
       
   599 				TRAPD(err, findtest->ConstructL();	findtest->DoTestsL(););
       
   600 				RDebug::Print(_L("t_cntFindAll finish with %d error"),err);
       
   601 				delete findtest;
       
   602 				}
       
   603 			delete cleanup;
       
   604 			}
       
   605 		delete sheduler;
       
   606 		}
       
   607 	__UHEAP_MARKEND;
       
   608 	return KErrNone;
       
   609     }