phonebookengines_old/contactsmodel/tsrc/t_iccmultiplephonebook.cpp
branchGCC_SURGE
changeset 41 d11de32a5e6f
parent 40 b46a585f6909
equal deleted inserted replaced
38:11319788d38f 41:d11de32a5e6f
       
     1 // Copyright (c) 2001-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 <cntdb.h>
       
    18 #include <cntitem.h>
       
    19 #include <cntfield.h>
       
    20 #include <cntfldst.h>
       
    21 #include <phbksync.h>
       
    22 
       
    23 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    24 #include "cntsyncecom.h"
       
    25 #endif
       
    26 
       
    27 // include templates for CleanupResetAndDestroyPushL(T)
       
    28 #include "cntviewprivate.h"
       
    29 
       
    30 #include "T_UTILS.H"
       
    31 #include "cntsyncchecker.h"
       
    32 
       
    33 _LIT(KTestName,"CContactICCEntry tests with multiple phonebooks");
       
    34 _LIT(KDatabaseFileName,"C:T_ICCMULTIPLEPHONEBOOK");
       
    35 _LIT(KGivenEditName,"edited name");
       
    36 _LIT(KIccName,"icc entry name");
       
    37 _LIT(KNonIccName,"non-icc name");
       
    38 _LIT(KIccNumber,"020 794 60123");
       
    39 _LIT(KNonIccNumber,"020 794 60060");
       
    40 
       
    41 _LIT(KPluginName,"phone book synchronizer Implementation");
       
    42 _LIT(KTestPluginName,"Test phone book synchronizer Implementation");
       
    43 
       
    44 CCntTest* CntTest=NULL;
       
    45 LOCAL_D RTest test(KTestName);
       
    46 
       
    47 LOCAL_D CContactSyncChecker* syncChecker;
       
    48 
       
    49 //===============================================================================================
       
    50 // SETUP & UTILITIES
       
    51 //===============================================================================================
       
    52 class TFieldEntry
       
    53 	{
       
    54 	public:
       
    55 		TFieldEntry(TFieldType aField);
       
    56 		TFieldEntry(TFieldType aField,TUid aFieldType);
       
    57 	public:
       
    58 		TFieldType iField;
       
    59 		TUid iFieldType;
       
    60 	};
       
    61 
       
    62 TFieldEntry::TFieldEntry(TFieldType aField)
       
    63 :iField(aField)
       
    64 ,iFieldType(KUidIccPhonebookNotFound)
       
    65 	{}
       
    66 
       
    67 TFieldEntry::TFieldEntry(TFieldType aField,TUid aFieldType)
       
    68 :iField(aField)
       
    69 ,iFieldType(aFieldType)
       
    70 	{}
       
    71 
       
    72 /**
       
    73  * Create a new template and add it to the database
       
    74  * @param aDb Contact database
       
    75  * @param aTemplateName Name for the template
       
    76  * @param aFieldSet Array of fields which should are added to the template
       
    77  * @return TContactItemId Id of the newly created template
       
    78  */
       
    79 TContactItemId CreatePhonebookTemplateL(CContactDatabase& aDb, const TDesC& aTemplateName, RArray<TFieldEntry>& aFieldSet)
       
    80 	{
       
    81 	CContactItem* temp = aDb.CreateContactCardTemplateLC(aTemplateName);
       
    82 	TContactItemId templateId = temp->Id();
       
    83 	CleanupStack::PopAndDestroy(temp);
       
    84 	temp=NULL;
       
    85 
       
    86 	//Remove all the unnecessary fields
       
    87 	temp = aDb.OpenContactLX(templateId);
       
    88 	CleanupStack::PushL(temp);	
       
    89 	const TInt fieldCount = temp->CardFields().Count();
       
    90 	for(TInt i=fieldCount-1;i>=0;i--)
       
    91 		temp->RemoveField(i);
       
    92 
       
    93 	// Add each of the required fields to the template
       
    94 	for (TInt j=0; j<aFieldSet.Count(); ++j)
       
    95 		{
       
    96 		TFieldEntry fieldEntry=aFieldSet[j];
       
    97 
       
    98 		CContactItemField* field = CContactItemField::NewLC(KStorageTypeText,fieldEntry.iField);
       
    99 		if (fieldEntry.iFieldType!=KNullUid)
       
   100 			field->AddFieldTypeL(fieldEntry.iFieldType);
       
   101 		temp->AddFieldL(*field);
       
   102 		CleanupStack::Pop(field);
       
   103 		}
       
   104 
       
   105 	aDb.CommitContactL(*temp);
       
   106 	CleanupStack::PopAndDestroy(2); // temp, close template
       
   107 	
       
   108 	return templateId;
       
   109 	}
       
   110 
       
   111 /**
       
   112  * Return an array of fields for the phonebook specified
       
   113  * @param aPhonebookUid The phonebook uid
       
   114  * @return RArray<TFieldEntry> Field set for this specific phonebook.  Any contact item
       
   115  * which belongs to this phonebook should contain these fields
       
   116  */
       
   117 RArray<TFieldEntry> fieldSetForPhonebook(TUid aPhonebookUid)
       
   118 	{
       
   119 	RArray<TFieldEntry> entries;
       
   120 	entries.Append(TFieldEntry(KUidContactFieldFamilyName));
       
   121 	entries.Append(TFieldEntry(KUidContactFieldGivenName));
       
   122 	entries.Append(TFieldEntry(KUidContactFieldPhoneNumber,KUidContactFieldVCardMapHOME));
       
   123 	entries.Append(TFieldEntry(KUidContactFieldICCPhonebook));
       
   124 	
       
   125 	if (aPhonebookUid==KUidUsimAppAdnPhonebook)
       
   126 		{
       
   127 		entries.Append(TFieldEntry(KUidContactFieldEMail,KUidContactFieldVCardMapHOME));
       
   128 		entries.Append(TFieldEntry(KUidContactFieldEMail,KUidContactFieldVCardMapWORK));
       
   129 		entries.Append(TFieldEntry(KUidContactFieldPhoneNumber,KUidContactFieldVCardMapHOME));
       
   130 		entries.Append(TFieldEntry(KUidContactFieldPhoneNumber,KUidContactFieldVCardMapWORK));
       
   131 		entries.Append(TFieldEntry(KUidContactFieldPhoneNumber,KUidContactFieldVCardMapCELL));
       
   132 		entries.Append(TFieldEntry(KUidContactFieldPhoneNumber,KUidContactFieldVCardMapPAGER));
       
   133 		}
       
   134 
       
   135 	return entries;
       
   136 	}
       
   137 
       
   138 void SetUpIccPhonebooksL(CContactDatabase& aDb)
       
   139 	{
       
   140 	test.Next(_L("Set up phonebooks"));
       
   141 	RArray<TUid>	phbkList;
       
   142 	CleanupClosePushL(phbkList);
       
   143 
       
   144 	phbkList.AppendL(KUidIccGlobalAdnPhonebook);
       
   145 	phbkList.AppendL(KUidIccGlobalSdnPhonebook);
       
   146 	phbkList.AppendL(KUidIccGlobalLndPhonebook);
       
   147 	phbkList.AppendL(KUidUsimAppAdnPhonebook);
       
   148 	// tell phonebook sync simulator what phonebooks to use
       
   149 	test(syncChecker->SetPhonebookListL(phbkList) == KErrNone);
       
   150 
       
   151 	// simulate synchronisation - includes creating/finding template & group
       
   152 	// also defaults all validate responses to KErrNone
       
   153 	test(syncChecker->SynchroniseIccAllPhonebooksL(aDb, KErrNone, KErrNone) == KErrNone);
       
   154 	
       
   155 	CleanupStack::PopAndDestroy(); // phbkList
       
   156 	}
       
   157 
       
   158 /**
       
   159  * Check the content of the phonebook field in the contact item
       
   160  * @param aContactItem Contact item
       
   161  * @param aPhonebookUid The phonebook uid
       
   162  * @param aFieldIsSet EFalse if the phonebook field should not contain a value, else ETrue
       
   163  */
       
   164 void CheckPhonebookField(CContactItem& aContactItem,TUid aPhonebookUid,TBool aFieldIsSet)
       
   165 	{
       
   166 	const CContactItemFieldSet& fieldset = aContactItem.CardFields();
       
   167 	const TInt pos = fieldset.Find(KUidContactFieldICCPhonebook);
       
   168 	test(pos!=KErrNotFound);
       
   169 	TPtrC phonebookField=fieldset[pos].TextStorage()->Text();
       
   170 
       
   171 	if(aFieldIsSet)
       
   172 		{
       
   173 		TLex input(phonebookField);
       
   174 		TInt phonebookFieldVal;
       
   175 		/*TInt ignore  = */ input.Val(phonebookFieldVal);
       
   176 		TUid phonebookFieldUid;
       
   177 		phonebookFieldUid.iUid=phonebookFieldVal;
       
   178 		test(phonebookFieldUid==aPhonebookUid);
       
   179 		}
       
   180 	else
       
   181 		test(phonebookField==KNullDesC);
       
   182 	}
       
   183 
       
   184 /**
       
   185  * Verify that the template id returned by CContactDatabase::ICCTemplateIdL is the
       
   186  * same as that returned directly from the plugin
       
   187  * @param aDb Contact database
       
   188  */
       
   189 void VerifyPhonebookTemplateIdsL(CContactDatabase& aDb)
       
   190 	{
       
   191 	test.Next(_L("Verify template ids"));
       
   192 	syncChecker->ResetMethodCallCountsL();
       
   193 	test(aDb.ICCTemplateIdL() == syncChecker->ICCTemplateIdL(KUidIccGlobalAdnPhonebook));
       
   194 	test(aDb.ICCTemplateIdL(KUidIccGlobalAdnPhonebook) == syncChecker->ICCTemplateIdL(KUidIccGlobalAdnPhonebook));
       
   195 	test(aDb.ICCTemplateIdL(KUidIccGlobalSdnPhonebook) == syncChecker->ICCTemplateIdL(KUidIccGlobalSdnPhonebook));
       
   196 	test(aDb.ICCTemplateIdL(KUidIccGlobalLndPhonebook) == syncChecker->ICCTemplateIdL(KUidIccGlobalLndPhonebook));
       
   197 	test(aDb.ICCTemplateIdL(KUidUsimAppAdnPhonebook) == syncChecker->ICCTemplateIdL(KUidUsimAppAdnPhonebook));
       
   198 	test(aDb.ICCTemplateIdL(KNullUid) == KNullContactId);
       
   199 	test(syncChecker->ValidateMethodCallCountL() == 6);
       
   200 	}
       
   201 
       
   202 /**
       
   203  * Set the name field of the contact with id aId to contain the name aName
       
   204  * @param aDb Contact database
       
   205  * @param aId Contact item id
       
   206  * @param aName A name
       
   207  */
       
   208 void SetNameField(CContactDatabase& aDb,TContactItemId aId,const TDesC& aName)
       
   209 	{
       
   210 	syncChecker->ResetMethodCallCountsL();
       
   211 	CContactItem* item = aDb.OpenContactLX(aId);
       
   212 	CleanupStack::PushL(item);
       
   213 	if (item->Type() == KUidContactICCEntry)
       
   214 		{
       
   215 		test(syncChecker->ValidateMethodCallCountL() == 2);
       
   216 		}
       
   217 	else
       
   218 		{
       
   219 		test(syncChecker->ValidateMethodCallCountL() == 0);
       
   220 		}
       
   221 	CContactItemFieldSet& fieldset = item->CardFields();
       
   222 	TInt pos = fieldset.Find(KUidContactFieldFamilyName);
       
   223 	test(pos!=KErrNotFound);
       
   224 	CContactItemField& field = fieldset[pos];
       
   225 	CContactTextField* textfield = field.TextStorage();
       
   226 	textfield->SetTextL(aName);
       
   227 
       
   228 	syncChecker->ResetMethodCallCountsL();
       
   229 	aDb.CommitContactL(*item);
       
   230 	if (item->Type() == KUidContactICCEntry)
       
   231 		{
       
   232 		test(syncChecker->ValidateMethodCallCountL() == 2);
       
   233 		}
       
   234 	else
       
   235 		{
       
   236 		test(syncChecker->ValidateMethodCallCountL() == 0);
       
   237 		}
       
   238 	CleanupStack::PopAndDestroy(2); // item, lock record
       
   239 	}
       
   240 
       
   241 /**
       
   242  * Set the phone number field of the contact with id aId to contain the number aNumber
       
   243  * @param aDb Contact database
       
   244  * @param aId Contact item id
       
   245  * @param aNumber A telephone number
       
   246  */
       
   247 void SetPhoneNumberField(CContactDatabase& aDb,TContactItemId aId,const TDesC& aNumber)
       
   248 	{
       
   249 	syncChecker->ResetMethodCallCountsL();
       
   250 	CContactItem* item = aDb.OpenContactLX(aId);
       
   251 	CleanupStack::PushL(item);
       
   252 	if (item->Type() == KUidContactICCEntry)
       
   253 		{
       
   254 		test(syncChecker->ValidateMethodCallCountL() == 2);
       
   255 		}
       
   256 	else
       
   257 		{
       
   258 		test(syncChecker->ValidateMethodCallCountL() == 0);
       
   259 		}
       
   260 	CContactItemFieldSet& fieldset = item->CardFields();
       
   261 	TInt pos = fieldset.Find(KUidContactFieldPhoneNumber);
       
   262 	test(pos!=KErrNotFound);
       
   263 	
       
   264 	CContactItemField& field = fieldset[pos];
       
   265 	CContactTextField* textfield = field.TextStorage();
       
   266 	textfield->SetTextL(aNumber);
       
   267 
       
   268 	syncChecker->ResetMethodCallCountsL();
       
   269 	aDb.CommitContactL(*item);
       
   270 	if (item->Type() == KUidContactICCEntry)
       
   271 		{
       
   272 		test(syncChecker->ValidateMethodCallCountL() == 2);
       
   273 		}
       
   274 	else
       
   275 		{
       
   276 		test(syncChecker->ValidateMethodCallCountL() == 0);
       
   277 		}
       
   278 	CleanupStack::PopAndDestroy(2); // item, lock record
       
   279 	}
       
   280 
       
   281 //===============================================================================================
       
   282 // ADDING entries
       
   283 //===============================================================================================
       
   284 /**
       
   285  * Create an entry based on the template for this specific phonebook, and add
       
   286  * the entry to the contact database
       
   287  * @param aDb Contact database
       
   288  * @param aPhonebookUid The phonebook uid
       
   289  * @return TContactItemId Id of the newly created icc entry
       
   290  */
       
   291 TContactItemId doAddIccEntryL(CContactDatabase& aDb,TUid aPhonebookUid)
       
   292 	{
       
   293 	syncChecker->ResetMethodCallCountsL();
       
   294 	TContactItemId templateId = aDb.ICCTemplateIdL(aPhonebookUid);
       
   295 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   296 	CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
       
   297 	CContactICCEntry* entry = CContactICCEntry::NewL(*iccTemplate);
       
   298 	CleanupStack::PopAndDestroy(iccTemplate);
       
   299 	CleanupStack::PushL(entry);
       
   300 	// Add to the database
       
   301 	CheckPhonebookField(*entry,aPhonebookUid, EFalse);
       
   302 	syncChecker->ResetMethodCallCountsL();
       
   303 	TContactItemId id = aDb.AddNewContactL(*entry); 
       
   304 	test(syncChecker->ValidateMethodCallCountL() == 3);
       
   305 	CleanupStack::PopAndDestroy(entry);
       
   306 	test(id!=KNullContactId);
       
   307 	// Check group membership
       
   308 	syncChecker->ResetMethodCallCountsL();
       
   309 	CContactICCEntry* fetchedItem = static_cast<CContactICCEntry*>(aDb.ReadContactL(id));
       
   310 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   311 	CleanupStack::PushL(fetchedItem);	
       
   312 	const CContactIdArray* owned = fetchedItem->GroupsJoined();
       
   313 	test(owned!=NULL && owned->Count() == 1);
       
   314 	test((*owned)[0]==syncChecker->GroupIdL(aPhonebookUid));
       
   315 	test(fetchedItem->Type() == KUidContactICCEntry);
       
   316 	// Verify that the phonebook field has been set
       
   317 	CheckPhonebookField(*fetchedItem,aPhonebookUid, ETrue);
       
   318 	CleanupStack::PopAndDestroy(fetchedItem);	
       
   319 
       
   320 	return id;
       
   321 	}
       
   322 
       
   323 TContactItemId AddIccEntryL(CContactDatabase& aDb,TUid aPhonebookUid)
       
   324 	{
       
   325 	syncChecker->SetValidateWriteResponseL(KErrNone);
       
   326 	return doAddIccEntryL(aDb, aPhonebookUid);
       
   327 	}
       
   328 
       
   329 void UnsuccessfulAddIccEntryL(CContactDatabase& aDb,TUid aPhonebookUid, TInt aReason)
       
   330 	{
       
   331 	syncChecker->SetValidateWriteResponseL(aReason);
       
   332 	TRAPD(err,doAddIccEntryL(aDb, aPhonebookUid));
       
   333 	test(err==aReason);
       
   334 	}
       
   335 
       
   336 void AddEntriesBasedOnEachOfTheTemplatesL(CContactDatabase& aDb)
       
   337 	{
       
   338 	test.Next(_L("Test successful adding"));
       
   339 	TInt numberOfAdnEntries=3;
       
   340 	TInt numberOfSdnEntries=2;
       
   341 	TInt numberOfLdnEntries=1;
       
   342 	TInt numberOfUsimEntries=4;
       
   343 	TInt iter=0;
       
   344 	for (iter=0; iter<numberOfAdnEntries; ++iter)
       
   345 		{
       
   346 		TContactItemId id=AddIccEntryL(aDb,KUidIccGlobalAdnPhonebook);
       
   347 		CContactGroup* group=static_cast<CContactGroup*>(aDb.ReadContactLC(syncChecker->GroupIdL(KUidIccGlobalAdnPhonebook)));
       
   348 		CContactIdArray* entries=group->ItemsContainedLC();
       
   349 		test(entries->Count() == iter+1);
       
   350 		CleanupStack::PopAndDestroy(entries);
       
   351 		test(group->ContainsItem(id));
       
   352 		CleanupStack::PopAndDestroy(group);
       
   353 		}
       
   354 	for (iter=0; iter<numberOfSdnEntries; ++iter)
       
   355 		{
       
   356 		TContactItemId id=AddIccEntryL(aDb,KUidIccGlobalSdnPhonebook);
       
   357 		CContactGroup* group=static_cast<CContactGroup*>(aDb.ReadContactLC(syncChecker->GroupIdL(KUidIccGlobalSdnPhonebook)));
       
   358 		CContactIdArray* entries=group->ItemsContainedLC();
       
   359 		test(entries->Count() == iter+1);
       
   360 		CleanupStack::PopAndDestroy(entries);
       
   361 		test(group->ContainsItem(id));
       
   362 		CleanupStack::PopAndDestroy(group);
       
   363 		}
       
   364 	for (iter=0; iter<numberOfLdnEntries; ++iter)
       
   365 		{
       
   366 		TContactItemId id=AddIccEntryL(aDb, KUidIccGlobalLndPhonebook);
       
   367 		CContactGroup* group=static_cast<CContactGroup*>(aDb.ReadContactLC(syncChecker->GroupIdL(KUidIccGlobalLndPhonebook)));
       
   368 		CContactIdArray* entries=group->ItemsContainedLC();
       
   369 		test(entries->Count() == iter+1);
       
   370 		CleanupStack::PopAndDestroy(entries);
       
   371 		test(group->ContainsItem(id));
       
   372 		CleanupStack::PopAndDestroy(group);
       
   373 		}
       
   374 	for (iter=0; iter<numberOfUsimEntries; ++iter)
       
   375 		{
       
   376 		TContactItemId id=AddIccEntryL(aDb,KUidUsimAppAdnPhonebook);
       
   377 		CContactGroup* group=static_cast<CContactGroup*>(aDb.ReadContactLC(syncChecker->GroupIdL(KUidUsimAppAdnPhonebook)));
       
   378 		CContactIdArray* entries=group->ItemsContainedLC();
       
   379 		test(entries->Count() == iter+1);
       
   380 		CleanupStack::PopAndDestroy(entries);
       
   381 		test(group->ContainsItem(id));
       
   382 		CleanupStack::PopAndDestroy(group);
       
   383 		}
       
   384 	// Add an ICC entry based on the system template, not one of the ICC templates
       
   385 	TContactItemId templateId=aDb.TemplateId();
       
   386 	CContactItem* systemTemplate = aDb.ReadContactLC(templateId);
       
   387 	CContactICCEntry* entry = CContactICCEntry::NewL(*systemTemplate);
       
   388 	CleanupStack::PopAndDestroy(systemTemplate);
       
   389 	CleanupStack::PushL(entry);
       
   390 	syncChecker->ResetMethodCallCountsL();
       
   391 	TContactItemId id = aDb.AddNewContactL(*entry); 
       
   392 	test(syncChecker->ValidateMethodCallCountL() == 3);
       
   393 
       
   394 	syncChecker->ResetMethodCallCountsL();
       
   395 	CContactItem* item=aDb.ReadContactLC(id);
       
   396 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   397 	// check the entry hasn't been added to any group
       
   398 	CContactIdArray* array=static_cast<CContactICCEntry*>(item)->GroupsJoinedLC();
       
   399 	test(array->Count() == 0);
       
   400 	CleanupStack::PopAndDestroy(3); // array, close item, item
       
   401 	}
       
   402 
       
   403 void TestUnsuccessfulAddL(CContactDatabase& aDb)
       
   404 	{
       
   405 	// Test adding entries to each of the phonebooks when the ICC is locked, unaccessible or corrupt
       
   406 	test.Next(_L("Test unsuccessful adding"));
       
   407 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalAdnPhonebook,KErrLocked);
       
   408 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalAdnPhonebook,KErrAccessDenied);
       
   409 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalAdnPhonebook,KErrCorrupt);
       
   410 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalSdnPhonebook,KErrLocked);
       
   411 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalSdnPhonebook,KErrAccessDenied);
       
   412 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalSdnPhonebook,KErrCorrupt);
       
   413 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalLndPhonebook,KErrLocked);
       
   414 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalLndPhonebook,KErrAccessDenied);
       
   415 	UnsuccessfulAddIccEntryL(aDb,KUidIccGlobalLndPhonebook,KErrCorrupt);
       
   416 	UnsuccessfulAddIccEntryL(aDb,KUidUsimAppAdnPhonebook,KErrLocked);
       
   417 	UnsuccessfulAddIccEntryL(aDb,KUidUsimAppAdnPhonebook,KErrAccessDenied);
       
   418 	UnsuccessfulAddIccEntryL(aDb,KUidUsimAppAdnPhonebook,KErrCorrupt);
       
   419 	}
       
   420 
       
   421 /** 
       
   422  * Verify that adding contact cards doesn't call the synchroniser interface
       
   423  * @param aDb Contact database
       
   424  */
       
   425 TContactItemId AddContactCardL(CContactDatabase& aDb)
       
   426 	{
       
   427 	_LIT(KTemplateName,"contact card template");
       
   428 	RArray<TFieldEntry> entries=fieldSetForPhonebook(KUidIccGlobalAdnPhonebook);
       
   429 	TContactItemId templateId=CreatePhonebookTemplateL(aDb,KTemplateName,entries);
       
   430 	entries.Close();
       
   431 	CContactItem* iccTemplate = aDb.ReadContactLC(templateId);
       
   432 	CContactCard* card = CContactCard::NewLC(iccTemplate);
       
   433 	syncChecker->ResetMethodCallCountsL();
       
   434 	TContactItemId id=aDb.AddNewContactL(*card);
       
   435 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   436 	CleanupStack::PopAndDestroy(2,iccTemplate);
       
   437 	return id;
       
   438 	}
       
   439 //===============================================================================================
       
   440 // DELETING entries
       
   441 //===============================================================================================
       
   442 /**
       
   443  * Verify that the synchroniser is called when deleting an icc entry, and that the 
       
   444  * deletion of an icc entry fails if the icc is locked.
       
   445  * @param aDb Contact database
       
   446  */
       
   447 void TestDeleteL(CContactDatabase& aDb)
       
   448 	{
       
   449 	test.Next(_L("Test delete when ICC locked"));
       
   450 	syncChecker->SetDeleteContactResponseL(KErrLocked);
       
   451 	TContactItemId iccId=AddIccEntryL(aDb,KUidIccGlobalAdnPhonebook);
       
   452 	syncChecker->ResetMethodCallCountsL();
       
   453 	TRAPD(err,aDb.DeleteContactL(iccId));
       
   454 	test(err==KErrLocked);
       
   455 	test(syncChecker->ValidateMethodCallCountL() == 2);
       
   456 	syncChecker->ResetMethodCallCountsL();
       
   457 	CContactItem* item=aDb.ReadContactLC(iccId);
       
   458 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   459 	test(item!=NULL);
       
   460 	CleanupStack::PopAndDestroy(item);
       
   461 	item=NULL;
       
   462 
       
   463 	test.Next(_L("Test successful delete of non-icc entry when ICC locked"));
       
   464 	TContactItemId nonIccId=AddContactCardL(aDb);
       
   465 	syncChecker->ResetMethodCallCountsL();
       
   466 	TRAP(err,aDb.DeleteContactL(nonIccId));
       
   467 	test(err==KErrNone);
       
   468 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   469 
       
   470 	test.Next(_L("Test successful delete"));
       
   471 	syncChecker->SetDeleteContactResponseL(KErrNone);
       
   472 	syncChecker->ResetMethodCallCountsL();
       
   473 	TRAP(err,aDb.DeleteContactL(iccId));
       
   474 	test(syncChecker->ValidateMethodCallCountL() == 2);
       
   475 	test(err==KErrNone);
       
   476 	syncChecker->ResetMethodCallCountsL();
       
   477 	TRAP(err,aDb.ReadContactLC(iccId));
       
   478 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   479 	test(err==KErrNotFound);
       
   480 	}
       
   481 
       
   482 //===============================================================================================
       
   483 // READING entries
       
   484 //===============================================================================================
       
   485 void TestReadMinimalContactL(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
       
   486 	{
       
   487 	test.Next(_L("Test ReadMinimalContactL"));
       
   488 	// Successful read of icc entry
       
   489 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   490 	syncChecker->ResetMethodCallCountsL();
       
   491 	CContactItem* item=aDb.ReadMinimalContactLC(aIccId);
       
   492 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   493 	test(item!=NULL);
       
   494 	CleanupStack::PopAndDestroy(item);
       
   495 	item=NULL;
       
   496 
       
   497 	// Unsuccessful read of icc entry because icc locked
       
   498 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrAccessDenied);
       
   499 	syncChecker->ResetMethodCallCountsL();
       
   500 	TRAPD(err,item=aDb.ReadMinimalContactLC(aIccId));
       
   501 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   502 	test(item==NULL);
       
   503 	test(err==KErrAccessDenied);
       
   504 	
       
   505 	// successful read of non-icc entry, even though icc locked
       
   506 	syncChecker->ResetMethodCallCountsL();
       
   507 	item=aDb.ReadMinimalContactLC(aNonIccId);
       
   508 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   509 	test(item!=NULL);
       
   510 	CleanupStack::PopAndDestroy(item);
       
   511 	item=NULL;
       
   512 	}
       
   513 
       
   514 void TestReadContactL(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
       
   515 	{
       
   516 	test.Next(_L("Test ReadContactL"));
       
   517 	// Successful read of icc entry
       
   518 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   519 	syncChecker->ResetMethodCallCountsL();
       
   520 	test(syncChecker->ValidateMethodCallCountL() == 0);	
       
   521 	CContactItem* item=aDb.ReadContactLC(aIccId);
       
   522 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   523 	test(item!=NULL);
       
   524 	CleanupStack::PopAndDestroy(item);
       
   525 	item=NULL;
       
   526 
       
   527 	// Unsuccessful read of icc entry because icc locked
       
   528 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrAccessDenied);
       
   529 	syncChecker->ResetMethodCallCountsL();
       
   530 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   531 	TRAPD(err,item=aDb.ReadContactL(aIccId));
       
   532 	test(item==NULL);
       
   533 	test(err==KErrAccessDenied);
       
   534 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   535 	
       
   536 	// successful read of non-icc entry, even though icc locked
       
   537 	syncChecker->ResetMethodCallCountsL();
       
   538 	test(syncChecker->ValidateMethodCallCountL() == 0);	
       
   539 	item=aDb.ReadContactLC(aNonIccId);
       
   540 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   541 	test(item!=NULL);
       
   542 	CleanupStack::PopAndDestroy(item);
       
   543 	item=NULL;
       
   544 	}
       
   545 
       
   546 void TestReadTextDefinitionL(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
       
   547 	{
       
   548 	test.Next(_L("Test ReadTextDefinitionL"));
       
   549 	// Successful read of icc entry
       
   550 	CContactTextDef* textDef=CContactTextDef::NewLC();
       
   551 	textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
       
   552 	TBuf<64> result;
       
   553 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   554 	syncChecker->ResetMethodCallCountsL();
       
   555 	aDb.ReadContactTextDefL(aIccId,result,textDef);
       
   556 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   557 	test(result==KIccName);
       
   558 	result.Zero();
       
   559 
       
   560 	// Unsuccessful read of icc entry because icc locked
       
   561 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrAccessDenied);
       
   562 	syncChecker->ResetMethodCallCountsL();
       
   563 	TRAPD(err, aDb.ReadContactTextDefL(aIccId,result,textDef));
       
   564 	test(err==KErrAccessDenied);
       
   565 	test(result.Length() == 0);
       
   566 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   567 
       
   568 	// successful read of non-icc entry, even though icc locked
       
   569 	syncChecker->ResetMethodCallCountsL();
       
   570 	TRAP(err, aDb.ReadContactTextDefL(aNonIccId,result,textDef));
       
   571 	test(err==KErrNone);
       
   572 	test(result==KNonIccName);
       
   573 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   574 	CleanupStack::PopAndDestroy(textDef);
       
   575 	}
       
   576 
       
   577 /**
       
   578  * Verify that the synchroniser is called when reading an icc entry
       
   579  * @param aDb Contact database
       
   580  */
       
   581 void TestReadL(CContactDatabase& aDb)
       
   582 	{
       
   583 	TContactItemId iccId=AddIccEntryL(aDb,KUidIccGlobalAdnPhonebook);
       
   584 	SetNameField(aDb,iccId,KIccName);
       
   585 	TContactItemId nonIccId = AddContactCardL(aDb);
       
   586 	SetNameField(aDb,nonIccId,KNonIccName);
       
   587 	TestReadMinimalContactL(aDb,iccId,nonIccId);
       
   588 	TestReadContactL(aDb,iccId,nonIccId);
       
   589 	TestReadTextDefinitionL(aDb,iccId,nonIccId);
       
   590 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   591 	syncChecker->ResetMethodCallCountsL();
       
   592 	aDb.DeleteContactL(iccId);
       
   593 	aDb.DeleteContactL(nonIccId);
       
   594 	test(syncChecker->ValidateMethodCallCountL() == 2);
       
   595 	}
       
   596 
       
   597 //===============================================================================================
       
   598 // EDITING entries
       
   599 //===============================================================================================
       
   600 /**
       
   601  * Verify that edit validation is being done for ICC entries
       
   602  * and write validation is done when Commit is called.
       
   603  * @param aDb Contact database
       
   604  * @param aId Item Id to edit
       
   605  */
       
   606 void TestSuccessfulIccEditL(CContactDatabase& aDb, TContactItemId aId)
       
   607 	{
       
   608 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   609 	syncChecker->SetValidateResponseL(MContactSynchroniser::EEdit, KErrNone);
       
   610 	syncChecker->SetValidateWriteResponseL(KErrNone);
       
   611 	syncChecker->ResetMethodCallCountsL();
       
   612 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   613 	CContactItem* item = aDb.OpenContactLX(aId);
       
   614 	CleanupStack::PushL(item);
       
   615 	test(syncChecker->ValidateMethodCallCountL() == 2);	
       
   616 
       
   617 	CContactItemFieldSet& fieldset = item->CardFields();
       
   618 	const TInt pos = fieldset.Find(KUidContactFieldFamilyName);	
       
   619 	CContactItemField& field = fieldset[pos];
       
   620 	CContactTextField* textfield = field.TextStorage();
       
   621 	textfield->SetTextL(KGivenEditName);
       
   622 
       
   623 	aDb.CommitContactL(*item);
       
   624 	test(syncChecker->ValidateMethodCallCountL() == 4);	
       
   625 	CleanupStack::PopAndDestroy(2); //item, lock record
       
   626 	}
       
   627 
       
   628 /**
       
   629  * Verify that edit of non-icc entries is successful when the icc is
       
   630  * locked, and that the synchroniser is not called
       
   631  * @param aDb Contact database
       
   632  * @param aId Item Id to edit
       
   633  */
       
   634 void TestSuccessfulNonIccEditL(CContactDatabase& aDb, TContactItemId aId)
       
   635 	{
       
   636 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrLocked);
       
   637 	syncChecker->SetValidateResponseL(MContactSynchroniser::EEdit, KErrLocked);
       
   638 	syncChecker->SetValidateWriteResponseL(KErrLocked);
       
   639 	syncChecker->ResetMethodCallCountsL();
       
   640 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   641 	CContactItem* item = aDb.OpenContactLX(aId);
       
   642 	CleanupStack::PushL(item);
       
   643 	test(syncChecker->ValidateMethodCallCountL() == 0);	
       
   644 
       
   645 	CContactItemFieldSet& fieldset = item->CardFields();
       
   646 	const TInt pos = fieldset.Find(KUidContactFieldFamilyName);	
       
   647 	CContactItemField& field = fieldset[pos];
       
   648 	CContactTextField* textfield = field.TextStorage();
       
   649 	textfield->SetTextL(KGivenEditName);
       
   650 
       
   651 	aDb.CommitContactL(*item);
       
   652 	test(syncChecker->ValidateMethodCallCountL() == 0);	
       
   653 	CleanupStack::PopAndDestroy(2); //item, lock record
       
   654 	}
       
   655 
       
   656 /**
       
   657  * Unsuccessful edit. Fail the edit validation request
       
   658  * @param aDb Contact database
       
   659  * @param aId Item Id to edit
       
   660  */
       
   661 void FailEditValidationL(CContactDatabase& aDb, TContactItemId aId)
       
   662 	{
       
   663 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   664 	syncChecker->SetValidateResponseL(MContactSynchroniser::EEdit, KErrAccessDenied);
       
   665 	syncChecker->ResetMethodCallCountsL();
       
   666 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   667 	TRAPD(err, aDb.OpenContactL(aId));
       
   668 	test(syncChecker->ValidateMethodCallCountL() == 2);	
       
   669 	test(err==KErrAccessDenied);
       
   670 	}
       
   671 
       
   672 /**
       
   673  * Unsuccessful edit. Fail the write validation request
       
   674  * @param aDb Contact database
       
   675  * @param aId Item Id to edit
       
   676  */
       
   677 void FailWriteValidationL(CContactDatabase& aDb, TContactItemId aId)
       
   678 	{
       
   679 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   680 	syncChecker->SetValidateResponseL(MContactSynchroniser::EEdit, KErrNone);
       
   681 	syncChecker->SetValidateWriteResponseL(KErrAccessDenied);
       
   682 	syncChecker->ResetMethodCallCountsL();
       
   683 
       
   684 	CContactItem* item = aDb.OpenContactLX(aId);
       
   685 	CleanupStack::PushL(item);
       
   686 	CContactItemFieldSet& fieldset = item->CardFields();
       
   687 	const TInt pos = fieldset.Find(KUidContactFieldFamilyName);	
       
   688 	CContactItemField& field = fieldset[pos];
       
   689 	CContactTextField* textfield = field.TextStorage();
       
   690 	textfield->SetTextL(KGivenEditName);
       
   691 
       
   692 	TRAPD(err, aDb.CommitContactL(*item));
       
   693 	test(syncChecker->ValidateMethodCallCountL() == 4);	
       
   694 	test(err==KErrAccessDenied);
       
   695 	CleanupStack::PopAndDestroy(2); //item, lock record
       
   696 	}
       
   697 
       
   698 /**
       
   699  * Verify that edit validation is being done for ICC entries
       
   700  * and write validation is done when Commit is called.
       
   701  * @param aDb Contact database
       
   702  */
       
   703 void TestEditL(CContactDatabase& aDb)
       
   704 	{
       
   705 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   706 	TContactItemId iccId = AddIccEntryL(aDb,KUidIccGlobalAdnPhonebook);
       
   707 	TContactItemId nonIccId = AddContactCardL(aDb);
       
   708 	test.Next(_L("Test successful edit"));
       
   709 	TestSuccessfulIccEditL(aDb,iccId);
       
   710 	TestSuccessfulNonIccEditL(aDb,nonIccId);
       
   711 	test.Next(_L("Test unsuccessful edit - fail edit"));
       
   712 	FailEditValidationL(aDb,iccId);
       
   713 	test.Next(_L("Test unsuccessful edit - fail write"));
       
   714 	FailWriteValidationL(aDb,iccId);
       
   715 	}
       
   716 //===============================================================================================
       
   717 // SEARCHING entries
       
   718 //===============================================================================================
       
   719 void TestFindLC(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
       
   720 	{
       
   721 	test.Next(_L("Test FindLC"));
       
   722 	// Successful find of icc entry
       
   723 	CContactItemFieldDef* fieldDef=new(ELeave) CContactItemFieldDef;
       
   724 	CleanupStack::PushL(fieldDef);
       
   725 	fieldDef->AppendL(KUidContactFieldFamilyName);
       
   726 	syncChecker->ResetMethodCallCountsL();
       
   727 	CContactIdArray* array = aDb.FindLC(KIccName,fieldDef);
       
   728 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   729 	test(array!=NULL);
       
   730 	test(array->Count() == 1);
       
   731 	test((*array)[0]==aIccId);
       
   732 	CleanupStack::PopAndDestroy(array);
       
   733 	array=NULL;
       
   734 
       
   735 	test.Next(_L("Test searching when ICC locked"));
       
   736 	// Unsuccessful find of icc entry because icc locked
       
   737 	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrLocked);
       
   738 	syncChecker->ResetMethodCallCountsL();
       
   739 	TRAPD(err,array = aDb.FindLC(KIccName,fieldDef));
       
   740 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   741 	test(err==KErrLocked);
       
   742 	test(array==NULL);
       
   743 
       
   744 	// successful find of non-icc entry, even though icc locked
       
   745 	syncChecker->ResetMethodCallCountsL();
       
   746 	array = aDb.FindLC(KNonIccName,fieldDef);
       
   747 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   748 	test(array!=NULL);
       
   749 	test(array->Count() == 1);
       
   750 	test((*array)[0]==aNonIccId);
       
   751 	CleanupStack::PopAndDestroy(2,fieldDef); // array, fieldDef
       
   752 	}
       
   753 
       
   754 TInt findWordSplitterL(TAny *aParams)
       
   755 	{
       
   756 	SFindInTextDefWordParser *parser=(SFindInTextDefWordParser *)aParams;
       
   757 	parser->iWordArray->AppendL(*parser->iSearchString);
       
   758 	return(KErrNone);
       
   759 	}
       
   760 
       
   761 void TestFindInTextDefLC(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
       
   762 	{
       
   763 	test.Next(_L("Test FindInTextDefLC"));
       
   764 	// Successful find of icc entry
       
   765 	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrNone);
       
   766 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   767 
       
   768 	TCallBack callBack(findWordSplitterL);
       
   769 	CContactTextDef* textDef=CContactTextDef::NewLC();
       
   770 	textDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
       
   771 	CDesCArray* desArray = new(ELeave) CDesCArrayFlat(5);
       
   772 	desArray->AppendL(_L("icc"));
       
   773 	syncChecker->ResetMethodCallCountsL();
       
   774 	CContactIdArray* array = aDb.FindInTextDefLC(*desArray,textDef,callBack);
       
   775 	//test(syncChecker->ValidateMethodCallCountL() == 3);
       
   776 	test(array!=NULL);
       
   777 	test(array->Count() == 1);
       
   778 	test((*array)[0]==aIccId);
       
   779 	CleanupStack::PopAndDestroy(array);
       
   780 	array=NULL;
       
   781 
       
   782 	test.Next(_L("Test searching when ICC locked"));
       
   783 	// Unsuccessful find of icc entry because icc locked
       
   784 	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrLocked);
       
   785 	syncChecker->ResetMethodCallCountsL();
       
   786 	TRAPD(err,array = aDb.FindInTextDefLC(*desArray,textDef,callBack));
       
   787 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   788 	test(err==KErrLocked);
       
   789 	test(array==NULL);
       
   790 	desArray->Delete(0);
       
   791 	delete desArray;
       
   792 
       
   793 	// successful find of non-icc entry, even though icc locked
       
   794 	CDesCArray* desArray2 = new(ELeave) CDesCArrayFlat(5);
       
   795 	desArray2->AppendL(_L("non-icc"));
       
   796 	syncChecker->ResetMethodCallCountsL();
       
   797 	array = aDb.FindInTextDefLC(*desArray2,textDef,callBack);
       
   798 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   799 	test(array!=NULL);
       
   800 	test(array->Count() == 1);
       
   801 	test((*array)[0]==aNonIccId);
       
   802 
       
   803 	// both the icc and non-icc entry should match the search criteria, but only the
       
   804 	// non-icc entry should be returned since icc is locked
       
   805 	SetNameField(aDb,aIccId,KNonIccName);
       
   806 	syncChecker->ResetMethodCallCountsL();
       
   807 	TRAP(err,array = aDb.FindInTextDefLC(*desArray2,textDef,callBack));
       
   808 	test(syncChecker->ValidateMethodCallCountL() == 1);
       
   809 	test(err==KErrLocked);
       
   810 	test(array!=NULL);
       
   811 	test(array->Count() == 1);
       
   812 	test((*array)[0]==aNonIccId);
       
   813 	desArray2->Delete(0);
       
   814 	delete desArray2;
       
   815 	SetNameField(aDb,aIccId,KIccName);
       
   816 	CleanupStack::PopAndDestroy(2,textDef); // array, textDef
       
   817 	}
       
   818 
       
   819 void TestMatchPhoneNumberL(CContactDatabase& aDb, TContactItemId aIccId, TContactItemId aNonIccId)
       
   820 	{
       
   821 	// The synchroniser is not called to validate the IDs at for this method because 
       
   822 	// phone number resolution needs to be as quick as possible. 
       
   823 	// Instead, validation is done when the client attempts to read the items.
       
   824 	test.Next(_L("Test MatchPhoneNumberL"));
       
   825 	// Successful find of icc entry phone number
       
   826 	syncChecker->ResetMethodCallCountsL();
       
   827 	CContactIdArray* array = aDb.MatchPhoneNumberL(KIccNumber,KMaxPhoneMatchLength);
       
   828 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   829 	test(array!=NULL);
       
   830 	test(array->Count() == 1);
       
   831 	test((*array)[0]==aIccId);
       
   832 	delete array;
       
   833 	array=NULL;
       
   834 
       
   835 	test.Next(_L("Test searching when ICC locked"));
       
   836 	// successful find when icc locked - validation done when entry read
       
   837 	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrLocked);
       
   838 	syncChecker->ResetMethodCallCountsL();
       
   839 	TRAPD(err,array = aDb.MatchPhoneNumberL(KIccNumber,KMaxPhoneMatchLength));
       
   840 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   841 	test(array!=NULL);
       
   842 	test(err==KErrNone);
       
   843 	test((*array)[0]==aIccId);
       
   844 	delete array;
       
   845 	array=NULL;
       
   846 	syncChecker->ResetMethodCallCountsL();
       
   847 	array = aDb.MatchPhoneNumberL(KNonIccNumber,KMaxPhoneMatchLength);
       
   848 	test(syncChecker->ValidateMethodCallCountL() == 0);
       
   849 	test(array!=NULL);
       
   850 	test(array->Count() == 1);
       
   851 	test((*array)[0]==aNonIccId);
       
   852 	delete array;
       
   853 	array=NULL;
       
   854 	}
       
   855 
       
   856 void TestSearchL(CContactDatabase& aDb)
       
   857 	{
       
   858 	test.Next(_L("Test searching"));
       
   859 	syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone);
       
   860 	syncChecker->SetValidateResponseL(MContactSynchroniser::ESearch,KErrNone);
       
   861 	TContactItemId iccId = AddIccEntryL(aDb,KUidIccGlobalAdnPhonebook);
       
   862 	SetNameField(aDb,iccId,KIccName);
       
   863 	SetPhoneNumberField(aDb,iccId,KIccNumber);
       
   864 	TContactItemId nonIccId = AddContactCardL(aDb);
       
   865 	SetNameField(aDb,nonIccId,KNonIccName);
       
   866 	SetPhoneNumberField(aDb,nonIccId,KNonIccNumber);
       
   867 
       
   868 	TestFindLC(aDb,iccId,nonIccId);
       
   869 	TestFindInTextDefLC(aDb,iccId,nonIccId);
       
   870 	TestMatchPhoneNumberL(aDb,iccId,nonIccId);
       
   871 	}
       
   872 
       
   873 
       
   874 void CheckForPhbkSyncPluginL()
       
   875 	{
       
   876 	test.Next(_L("Check for PhbkSync test plug-in"));
       
   877 
       
   878 	RImplInfoPtrArray	implInfoArray;
       
   879 	CleanupResetAndDestroyPushL(implInfoArray);
       
   880 	REComSession::ListImplementationsL(KUidEcomCntPhBkSyncInterface, implInfoArray);
       
   881 	//Find implementations of KUidEcomCntPhBkSyncInterface
       
   882 	TInt availCount = implInfoArray.Count(); 
       
   883 	TInt count;
       
   884 	for(count = 0; count < availCount; count++)
       
   885 		{
       
   886 		const TUid firstImplementationFound = implInfoArray[count]->ImplementationUid();
       
   887 		CImplementationInformation *info = implInfoArray[count];
       
   888 		test.Printf(_L("\n"));
       
   889 		test.Printf(_L("PhbkSync plugin #%i, Implementation UID 0x%08X version %i\n"),
       
   890 			count + 1, info->ImplementationUid(), info->Version());
       
   891 		test.Printf(_L("Plugin name = \"%S\"\n"), &(info->DisplayName()));
       
   892 		}
       
   893 
       
   894 	// is telephony's plug-in in the list?
       
   895 	for(count = 0; count < availCount; count++)
       
   896 		{
       
   897 		const TUid firstImplementationFound = implInfoArray[count]->ImplementationUid();
       
   898 		CImplementationInformation *info = implInfoArray[count];
       
   899 		if(info->DisplayName() == KTestPluginName)
       
   900 			{
       
   901 			test.Printf(_L("\n"));
       
   902 			test.Printf(_L("This test has now loaded the test plugin"));
       
   903 			test.Printf(_L("\n"));
       
   904 			availCount = 1;
       
   905 			break;
       
   906 			}		
       
   907 		
       
   908 		if(info->DisplayName() == KPluginName)
       
   909 			{
       
   910 			test.Printf(_L("\n"));
       
   911 			test.Printf(_L("This test only works with Contacts the test plugin and not the original phonebooksync plugin."));
       
   912 			test.Printf(_L("Depending on the build to removed the plugin in different ways:"));
       
   913 			test.Printf(_L("hardware - delete the line \"ECOM_PLUGIN(phbksyncplugin.dll,1020428C.rsc)\" from phbksync.iby"));
       
   914 			test.Printf(_L("winscw - delete phbksyncplugin.dll from %epocroot%/epoc32/release/winscw/udeb or similarly named directory"));
       
   915 			test.Printf(_L("\n"));
       
   916 			test(0);  // stop
       
   917 			break;
       
   918 			}
       
   919 		}
       
   920 
       
   921 	// only continue test if there is exactly one plug-in present
       
   922 	test(availCount == 1);	
       
   923 
       
   924 	CleanupStack::PopAndDestroy(&implInfoArray);
       
   925 	}
       
   926 
       
   927 	
       
   928 //===============================================================================================
       
   929 
       
   930 /** Lists tests to execute */
       
   931 
       
   932 /**
       
   933 
       
   934 @SYMTestCaseID     PIM-T-ICCMULTIPLEPHONEBOOK-0001
       
   935 
       
   936 */
       
   937 void DoTestsL()
       
   938     {
       
   939 	test.Start(_L("@SYMTestCaseID:PIM-T-ICCMULTIPLEPHONEBOOK-0001 CContactICCEntry tests with multiple phonebooks"));
       
   940 
       
   941 	CheckForPhbkSyncPluginL();
       
   942 
       
   943 	CntTest->CreateDatabaseL();	
       
   944 	CntTest->OpenDatabaseL();
       
   945 	CContactDatabase& db= *CntTest->Db();
       
   946 
       
   947 	syncChecker = CContactSyncChecker::NewL();
       
   948 	syncChecker->ResetEverythingL();
       
   949 
       
   950 	SetUpIccPhonebooksL(db);
       
   951 	VerifyPhonebookTemplateIdsL(db);
       
   952 	AddEntriesBasedOnEachOfTheTemplatesL(db);
       
   953 	TestUnsuccessfulAddL(db);
       
   954 	TestDeleteL(db);
       
   955 	TestReadL(db);
       
   956 	TestEditL(db);
       
   957 	TestSearchL(db);
       
   958 	syncChecker->ResetMethodCallCountsL();
       
   959 
       
   960 	CntTest->CloseDatabase();
       
   961 	CntTest->DeleteDatabaseL();
       
   962 
       
   963 
       
   964 	delete syncChecker;
       
   965 	syncChecker = NULL;
       
   966     }
       
   967 
       
   968 
       
   969 /** Standard E32Main method */
       
   970 GLDEF_C TInt E32Main()
       
   971 	{
       
   972     CntTest=new(ELeave) CCntTest;
       
   973 	CntTest->ConstructL(test,KDatabaseFileName);
       
   974     TRAPD(err,DoTestsL());
       
   975 	if (syncChecker)
       
   976 		{
       
   977 		delete syncChecker;
       
   978 		syncChecker = NULL;
       
   979 		}
       
   980 	CntTest->EndTestLib(err);
       
   981 	return KErrNone;
       
   982     }
       
   983