TInt CContactTestSynchroniser::ValidateWriteContact(CContactICCEntry& aContactItem) { TRAPD(err, iContactSyncChecker->ValidateMethodCalledL() ); __ASSERT_ALWAYS(err == KErrNone, User::Invariant() ); TBool verboseLoggingEnabled(EFalse); TRAP(err, verboseLoggingEnabled = iContactSyncChecker->VerboseLoggingEnabledL() ); __ASSERT_ALWAYS(err == KErrNone, User::Invariant() ); if (verboseLoggingEnabled) { User::InfoPrint(_L("ValidateWriteContact")); } // Set the phonebook field, if the field doesn't exist, it should be added CContactItemFieldSet& fieldset = aContactItem.CardFields(); TInt n = fieldset.Find(KUidContactFieldICCPhonebook); if(n == KErrNotFound) { CContactItemField* field(NULL); TRAP_IGNORE(field = CContactItemField::NewL(KStorageTypeText, KUidContactFieldICCPhonebook) ); TRAP(err, aContactItem.AddFieldL(*field) ); CContactItemFieldSet& fieldset = aContactItem.CardFields(); n = fieldset.Find(KUidContactFieldICCPhonebook); __ASSERT_ALWAYS(err == KErrNone && n != KErrNotFound, User::Invariant() ); } CContactItemField& field = fieldset[n]; CContactTextField* textField = field.TextStorage(); TUid phonebookUid(TUid::Null() ); TRAP(err, phonebookUid = iContactSyncChecker->PhonebookUidL(aContactItem.TemplateRefId() ) ); __ASSERT_ALWAYS(err == KErrNone, User::Invariant() ); TBuf<128> buf; if(phonebookUid != KUidIccPhonebookNotFound) { TInt phonebookUidNum = phonebookUid.iUid; buf.AppendNum(phonebookUidNum); TRAP(err, textField->SetTextL(buf)); __ASSERT_ALWAYS(err == KErrNone, User::Invariant() ); } TBool validateWriteResponse(EFalse); TRAP(err, validateWriteResponse = iContactSyncChecker->ValidateWriteResponseL() ); __ASSERT_ALWAYS(err == KErrNone, User::Invariant() ); return validateWriteResponse; }
/** * Test successful addition to database. * @param aDb Contact database */ void TestSuccessfulAddL(CContactDatabase& aDb) { //Create group TContactItemId groupId = CreatePhonebookGroupL(aDb); test(KErrNone == syncChecker->UpdatePhonebookGroupIdL(KUidIccGlobalAdnPhonebook, groupId)); //Create item and add fields TContactItemId templateId = aDb.ICCTemplateIdL(KUidIccGlobalAdnPhonebook); CContactItem* iccTemplate = aDb.ReadContactLC(templateId); CContactICCEntry* entry = CContactICCEntry::NewL(*iccTemplate); CleanupStack::PopAndDestroy(iccTemplate); CleanupStack::PushL(entry); SetNameL(*entry,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,KGivenName,EFalse); SetNameL(*entry,KUidContactFieldPhoneNumber,KUidContactFieldVCardMapTEL,KTelephoneNum,EFalse); //Add to database syncChecker->ResetMethodCallCountsL(); syncChecker->SetValidateWriteResponseL(KErrNone); syncChecker->SetValidateResponseL(MContactSynchroniser::ERead,KErrNone); test(syncChecker->ValidateMethodCallCountL() == 0); TContactItemId id = aDb.AddNewContactL(*entry); CleanupStack::PopAndDestroy(entry); test(syncChecker->ValidateMethodCallCountL() == 3); test(id!=KNullContactId); CContactICCEntry* fetchedItem = static_cast<CContactICCEntry*>(aDb.ReadContactL(id)); CleanupStack::PushL(fetchedItem); //Check group membership const CContactIdArray* owned = fetchedItem->GroupsJoined(); test(owned!=NULL && owned->Count() == 1); test((*owned)[0]==groupId); //Check number of fields and content CContactItemFieldSet& fieldset = fetchedItem->CardFields(); TInt pos = fieldset.Find(KUidContactFieldTemplateLabel); test(pos==KErrNotFound); // test(fieldset.Count() == 3); /* for (TInt i=0; i<fieldset.Count(); i++) { CContactItemField& field = fieldset[i]; TInt count = field.ContentType().FieldTypeCount(); for (TInt j=0; j<count; j++) { TFieldType ft= field.ContentType().FieldType(j); } TUid mapping = field.ContentType().Mapping(); } */ CheckFieldContentL(fieldset,KUidContactFieldFamilyName,KGivenName); // CheckFieldContentL(fieldset,KUidContactFieldPhoneNumber,KTelephoneNum); CleanupStack::PopAndDestroy(fetchedItem); }