/** add agent field to contact b. set value of agent to contact a. export contacts a & b. check access count for a & b(should be 0), check value of agent(should equal b) open contact b, delete all fields. commit. import contacts a and b. check that agent field is not imported. */ void CAccessCountTests::AgentExportImportAccessTestL() { const TContactItemId KFirstContactId = iIterate->NextL();//contact a const TContactItemId KSecondContactId = iIterate->NextL();//contact b //open contact a and populate all fields OpenL(KFirstContactId, *iViewAll); SetContactFieldsL(*iContactItem); CommitL(); //open contact b OpenL(KSecondContactId,*iViewAll); //populate all fields SetContactFieldsL(*iContactItem); //add contact a id as an agent field value AddAgentFieldL(KFirstContactId); CommitL(); CContactIdArray *ArrayOfExportedContactIds = CContactIdArray::NewLC(); //set contact a and b to be export ArrayOfExportedContactIds->AddL(KFirstContactId); ArrayOfExportedContactIds->AddL(KSecondContactId); //export contact a & b ExportVcardL(*ArrayOfExportedContactIds); const TInt KFirstContactAccessCountAfterExport = GetAccessCountL(KFirstContactId); const TInt KSecondContactAccessCountAfterExport = GetAccessCountL(KSecondContactId); const TInt KSecondContactAgentFieldAfterExport = GetAgentFieldL(KSecondContactId); CleanupStack::PopAndDestroy(ArrayOfExportedContactIds); //delete all fields from contact b OpenL(KSecondContactId,*iViewAll); iFields->Reset(); CommitL(); //import exported contacts ImportVcardL(); const TInt KFirstContactAccessCountAfterImport = GetAccessCountL(KFirstContactId); const TInt KSecondContactAccessCountAfterImport = GetAccessCountL(KSecondContactId); const TContactItemId KSecondContactAgentFieldAfterImport = GetAgentFieldL(KSecondContactId); //importing & exporting contacts should not affect the access count INTCOMPARE( KFirstContactAccessCountAfterExport , ==, 0, 0, 0 ); INTCOMPARE( KSecondContactAccessCountAfterExport , ==, 0, 0, 0 ); INTCOMPARE( KFirstContactAccessCountAfterExport , ==, KFirstContactAccessCountAfterImport, 0, 0 ); INTCOMPARE( KSecondContactAccessCountAfterExport , ==, KSecondContactAccessCountAfterImport, 0, 0 ); //agent field values should not be exported/imported INTCOMPARE( KFirstContactId , ==, KSecondContactAgentFieldAfterImport, 0, 0 ); //exporting contacts should not affect the internal state of the contacts agent field INTCOMPARE( KSecondContactAgentFieldAfterExport , ==, KFirstContactId, 0, 0 ); iParent->Fs().Delete(KVcardFile);//cleanup of exported vcard file }
/** opens contact item, and changes the label of each field to a custom label, then checks if label was stored correctly */ void CCustomLabelUid::TestCustomLabelsL( const TContactItemId aCid ) { //open contact item CContactItem *contactItem = NULL; contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); CleanupStack::PushL(contactItem); //setlabels of contact field to custom values SetContactLabelsL(*contactItem); //populate cotnact fields and update SetContactFieldsL(*contactItem); iContactsDatabase->CommitContactL(*contactItem); CleanupStack::PopAndDestroy(contactItem); CleanupStack::Pop();//lock record //read contact contactItem = NULL; contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); //check that contact field labels were updated correctly SINGLECOMPARE( CheckContactLabelsL(*contactItem),0,0 ); //check that fields updated correctly SINGLECOMPARE( CheckContactFieldsL(*contactItem),0,0 ); CleanupStack::PopAndDestroy(contactItem); }
/** Test: opens contact item, and adds a custom uid to each field, then checks if uid was stored correctly */ void CCustomLabelUid::TestCustomUidsL( const TContactItemId aCid ) { //open contact CContactItem *contactItem = NULL; contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); CleanupStack::PushL(contactItem); CContactItemFieldSet *ContactFields = &(contactItem->CardFields()); //add an extra (custom) uid to each fieldtype of this contact AddUIDsL(*ContactFields,TestConstants::KInitialUID); //populate contact fields SetContactFieldsL(*contactItem); //update contact iContactsDatabase->CommitContactL(*contactItem); CleanupStack::PopAndDestroy(contactItem); CleanupStack::Pop();//lock contactItem = NULL; //read contact item contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); ContactFields = &(contactItem->CardFields()); //check that contact field uids updated correctly SINGLECOMPARE( CheckUIDsL(*ContactFields,TestConstants::KInitialUID), 0 ,0 ); //check that contact fields updated correctly SINGLECOMPARE( CheckContactFieldsL(*contactItem), 0, 0 ); CleanupStack::PopAndDestroy(contactItem); }
/** open acid, increase access count to 1, attempt to delete contact, check that it has not been deleted, set access count to 0, delete, and check that it has been deleted. */ void CAccessCountTests::AccessCountTestL(const TContactItemId aCid) { TInt err = KErrNone; static const TInt KAccessCount = 1;//increase access count of contact by 1, TInt i = 0; OpenL(aCid,*iViewAll); SetContactFieldsL(*iContactItem); for(i = 0; i < KAccessCount; ++i ) { iContactItem->IncAccessCount(); } CommitL(); ReadL(aCid, *iViewAll); const TInt KInitialAccessCount = iContactItem->AccessCount();//facount const TInt KInitialFieldCount = iFields->Count(); //fcount const TInt KInitialEmptyFields = CountEmpty(*iFields);//fhcount Close(); INTCOMPARE( KInitialEmptyFields , ==, 0 , 0, 0 ); INTCOMPARE( KInitialFieldCount , >, 0 , 0, 0 ); for(i = 0; i < KAccessCount; ++i ) { iContactsDatabase->DeleteContactL(aCid); } ReadL(aCid,*iViewAll); const TInt KModifiedAccessCount = iContactItem->AccessCount();//dacount const TInt KModifiedFieldCount = iFields->Count();//dcount const TInt KModifiedEmptyFields = CountEmpty(*iFields);//dHcount Close(); /* check that deleting a contact doesnt modify its access count check that deleting a contact with access count > 1, deletes all fields associated with contact but not the contact item itself */ INTCOMPARE( KModifiedAccessCount , ==, KInitialAccessCount , 0, 0 ); INTCOMPARE( KInitialFieldCount , ==, KModifiedFieldCount , 0, 0 ); INTCOMPARE( KModifiedEmptyFields , ==, KInitialFieldCount , 0, 0 ); INTCOMPARE( KModifiedFieldCount , ==, KModifiedEmptyFields , 0, 0 ); OpenL(aCid,*iViewAll); for(i = 0; i < KAccessCount; ++i ) { iContactItem->DecAccessCount(); } const TInt lAcount = iContactItem->AccessCount(); CommitL(); INTCOMPARE( lAcount , ==, 0, 0, 0 ); TRAP( err, ReadL(aCid, *iViewAll) ); Close(); INTCOMPARE( err , ==, KErrNotFound , 0, 0 ); }
/** attempt to load aCid with viewdef containing multiple identical uids, this test will panic in debug mode as CContactItemViewDef does not allow multiple identical uids */ void CViewDefAnyFieldsTest::doIdenticalUidsTestL(const TContactItemId &aCid) { OpenL(aCid,*iViewAll, EFalse);// ETrue); SetContactFieldsL(*iContactItem); CommitL(); //multiple identical uids SINGLECOMPARE( FieldCountCompL(aCid, *iViewII, EFalse, EFalse, EFalse, ETrue), 0 , 0 ); }
/** this function encompasses two tests Test1(!aNewFields) opens contact item, and adds a custom uid to each field, changes lable to custom label then checks if uid and label were stored correctly Test2(aNewFields) opens contact item and adds ten new fields, and adds a custom uid to each field(new and old), changes lable to custom label then checks if uid and label were stored correctly. also checks both uids of new fields */ void CCustomLabelUid::TestCustomUidLabelsL( const TContactItemId aCid, const TBool aNewFields ) { CContactItem *contactItem = NULL; //open contact contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); CleanupStack::PushL(contactItem); CContactItemFieldSet *ContactFields = &(contactItem->CardFields()); if(aNewFields) { TInt length = 10;//add 10 new custom fields for(TInt i = 0, uids = TestConstants::KAltUID; i < length; i++, uids++) { AddNewFieldL( *ContactFields, TestConstants::KShortString, TFieldType::Uid(uids) ); } } //set custom labels for contact fields SetContactLabelsL(*contactItem); //set custom uids for contact fields AddUIDsL(*ContactFields,TestConstants::KInitialUID); //populate contact fields and update SetContactFieldsL(*contactItem); iContactsDatabase->CommitContactL(*contactItem); CleanupStack::PopAndDestroy(contactItem); CleanupStack::Pop();//lock //read contact contactItem = NULL; contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); ContactFields = &(contactItem->CardFields()); //check uids were update correctly SINGLECOMPARE( CheckUIDsL(*ContactFields,TestConstants::KInitialUID),0,0 ); //check labels were update correctly SINGLECOMPARE( CheckContactLabelsL(*contactItem),0,0 ); //check fields were populated correctly SINGLECOMPARE( CheckContactFieldsL(*contactItem),0,0 ); if(aNewFields) { //check that new fields contain the correct uids(2), initial and updated custom values TInt length = ContactFields->Count(); TInt i = ContactFields->Find( TFieldType::Uid(TestConstants::KAltUID) ); for(TInt uids = TestConstants::KAltUID; i < length; i++, uids++) { SINGLECOMPARE( CheckNewFieldL( *ContactFields, i, TFieldType::Uid(uids) ), i, 0); } } CleanupStack::PopAndDestroy(contactItem); }
/** tests loading aCid with different viewdefs, it is tested with all possible uids for each viewdef, check to see that expected fields are excluded/included */ void CViewDefAnyFieldsTest::doAnyFieldsTestL(const TContactItemId &aCid) { OpenL(aCid,*iViewAll, EFalse);//ETrue); SetContactFieldsL(*iContactItem); CommitL(); /*viewdefs ignore primary mappings stored as mapping in contenttype rather than within the array*/ SINGLECOMPARE( FieldCountCompL(aCid, *iViewII, EFalse, EFalse), 0, 0); //hidden is reversed SINGLECOMPARE( FieldCountCompL(aCid, *iViewMI, ETrue, ETrue), 0, 0 ); //"all" hidden fields are excluded SINGLECOMPARE( FieldCountCompL(aCid, *iViewIM, EFalse, ETrue, ETrue), 0, 0 ); //"all" hidden fields are excluded SINGLECOMPARE( FieldCountCompL(aCid, *iViewMM, ETrue, ETrue, ETrue), 0, 0 ); }
/**opens and read contct aCid using the default viewdefs. then it reads and minimally reads aCid using aView, it stores the number relevant fields after each read/open, then checks that the values match the expected resluts as constrained by aZeroN/H, aZeroN == all normal fields should be excluded, aZeroH == all hidden fields should be excluded*/ TBool CViewDefAllFieldsTest::FieldCountCompL( const TContactItemId aCid, const CContactItemViewDef &aView, const TBool aDefault, const TBool aZeroN, const TBool aZeroH) { TBool SingleCheck = EFalse; TBool OverallResult = ETrue; TInt counti = 0; TInt countr = 0; TInt countrv = 0; TInt countrAll = 0; TInt countrAllv = 0; TInt countrm = 0; TInt hcounti = 0; TInt hcountr = 0; TInt hcountrv = 0; TInt hcountrm = 0; OpenL(aCid,aView, ETrue); SetContactFieldsL(*iContactItem); counti = iFields->Count(); hcounti = CountHiddenFields(*iFields); CommitL(); ReadL(aCid,*iViewAll,EFalse); countrv = CountEmpty(*iFields); countrAllv = iFields->Count(); hcountrv = CountHiddenFields(*iFields); Close(); ReadL(aCid,aView,aDefault); countr = CountEmpty(*iFields); countrAll = iFields->Count(); hcountr = CountHiddenFields(*iFields); Close(); ReadMinimalL(aCid, aView, *iDefView, aDefault); countrm = iFields->Count(); hcountrm = CountHiddenFields(*iFields); Close(); SingleCheck = INTCOMPARE( countrAllv, ==, counti, 0, 0 ); OverallResult = OverallResult && SingleCheck; SingleCheck = INTCOMPARE(hcounti , ==, hcountrv, 0, 0 ); OverallResult = OverallResult && SingleCheck; SingleCheck = INTCOMPARE(countrv , ==, 0, 0, 0 ); OverallResult = OverallResult && SingleCheck; SingleCheck = INTCOMPARE( ( countrAll - countr) , ==, countrm , 0, 0 ); OverallResult = OverallResult && SingleCheck; if(aZeroN) { SingleCheck = INTCOMPARE( ( countr - hcountr ) , ==, ( counti - hcounti ) , 0, 0 ); OverallResult = OverallResult && SingleCheck; SingleCheck = INTCOMPARE( ( countrm - hcountrm ) , ==, 0 , 0, 0 ); OverallResult = OverallResult && SingleCheck; } else {
/** Add new contact Add new uid to each field that doesnt already contain that uid (EUniqueUids) Add new uid to each field that already contains that uid (EDuplicateUids) populate contact set custom labels check that all fields contain the additional uid (EUniqueUids) check that contact was populated correctly check that field lables were updated correctly */ void CCustomLabelUid::ExistingUidsTestL( const TUidTypeTest aTestType ) { /* Limitations (exceptions) to Test It is not possible to add Uids to all fields and expect to store and re-read them. This is because: i) Template matching (CContactItemFieldSet::MatchTemplateField) means that if a field matches a template field, the additional Uids are lost ii) Fast access fields must be text fields iii) Other curious combinations of Uids seem to never have been supported (e.g. Unused Name and Additional Name) */ const TUid KFastAccessFieldUids[] = { KUidContactFieldGivenNameValue, KUidContactFieldFamilyNameValue, KUidContactFieldCompanyNameValue, KUidContactFieldGivenNamePronunciationValue, KUidContactFieldFamilyNamePronunciationValue, KUidContactFieldCompanyNamePronunciationValue }; const TInt KUidsCount = iExistingUidsArray->Count(); CContactCard* contact = CContactCard::NewLC(iTemplate); for(TInt i = 0; i < KUidsCount; ++i ) { const TFieldType KFieldType = TFieldType::Uid( (*iExistingUidsArray)[i] ); TBool found = EFalse; for (TInt nameFieldNum = 0; nameFieldNum < sizeof(KFastAccessFieldUids) / sizeof(TInt); ++nameFieldNum) { if (KFieldType == (KFastAccessFieldUids[nameFieldNum])) { found = ETrue; } } found = found || KFieldType == KUidContactFieldVCardMapSIPID; found = found || KFieldType == KUidContactFieldTemplateLabel; found = found || KFieldType == KUidContactFieldVCardMapUnusedN; found = found || KFieldType == KUidContactFieldVCardMapTEL; if (found) { continue; } TContactItemId contactId = KNullContactId; contactId = iContactsDatabase->AddNewContactL( *contact ); //open contact CContactItem *contactItem = NULL; contactItem = iContactsDatabase->OpenContactLX(contactId,*iViewAll); CleanupStack::PushL(contactItem); CContactItemFieldSet &contactFields = contactItem->CardFields(); const TInt KFieldsCount = contactFields.Count(); for( TInt j = 0; j < KFieldsCount; ++j ) { const CContentType &KContentType = contactFields[j].ContentType(); // don't add phone/email/SIP UIDs to non-text fields if ((KFieldType == KUidContactFieldEMail || KFieldType == KUidContactFieldPhoneNumber || KFieldType == KUidContactFieldFax || KFieldType == KUidContactFieldSms) && contactFields[j].StorageType() != KStorageTypeText) { continue; } //if testing duplicate uids and uid is present in contact field add uid // if testing unique uids and uid is not presnt in contact field add uid if( (aTestType == EDuplicateUids) && KContentType.ContainsFieldType( KFieldType ) ) { contactFields[j].AddFieldTypeL( KFieldType ); } else if( (aTestType == EUniqueUids) && !KContentType.ContainsFieldType( KFieldType ) ) { contactFields[j].AddFieldTypeL( KFieldType ); } } //populate contact fields SetContactFieldsL(*contactItem); //setlabels of contact field to custom values SetContactLabelsL(*contactItem); iContactsDatabase->CommitContactL(*contactItem); CleanupStack::PopAndDestroy(contactItem); CleanupStack::Pop();//lock //read contact item contactItem = iContactsDatabase->ReadContactLC(contactId,*iViewAll); CContactItemFieldSet &readContactFields = contactItem->CardFields(); //check that contact field uids updated correctly const TInt KReadFieldsCount = readContactFields.Count(); INTCOMPARE( KReadFieldsCount, >, 0, i, 0 ); if( (aTestType == EUniqueUids) ) { //check that each fields contains at least one instance of the existing uid // (except the fast access fields) for( TInt k = 0; k < KReadFieldsCount; ++k ) { TBool found = EFalse; const CContentType &KContentType = readContactFields[k].ContentType(); for (TInt nameFieldNum = 0; nameFieldNum < sizeof(KFastAccessFieldUids) / sizeof(TInt); ++nameFieldNum) { if (KContentType.ContainsFieldType(KFastAccessFieldUids[nameFieldNum])) { found = ETrue; } } if (found) { continue; } // The behaviour of CContactItemFieldSet::MatchTemplateField has changed // add an extra UID in this case to avoid a template match (and loss of the added UID) if (KContentType.ContainsFieldType(KUidContactFieldVCardMapSIPID)) { continue; } if (KContentType.ContainsFieldType(KUidContactFieldVCardMapTEL)) { continue; } // some combinations of UID to Field Type are not supported if (KContentType.ContainsFieldType(KUidContactFieldVCardMapUnusedN) && (KFieldType == KUidContactFieldAdditionalName || KFieldType == KUidContactFieldSuffixName || KFieldType == KUidContactFieldPrefixName)) { continue; } // don't check phone/email/SIP UIDs to non-text fields if ((KFieldType == KUidContactFieldEMail || KFieldType == KUidContactFieldPhoneNumber || KFieldType == KUidContactFieldFax || KFieldType == KUidContactFieldSms) && contactFields[k].StorageType() != KStorageTypeText) { continue; } SINGLECOMPARE( KContentType.ContainsFieldType( KFieldType ), i, k ); } } //check that contact fields updated correctly SINGLECOMPARE( CheckContactFieldsL(*contactItem),i,0 ); //check that contact field labels were updated correctly SINGLECOMPARE( CheckContactLabelsL(*contactItem),i,0 ); CleanupStack::PopAndDestroy(contactItem); iContactsDatabase->DeleteContactL( contactId ); } CleanupStack::PopAndDestroy( contact ); }
/** Test: opens contact item, add two identical uids to each field, alternating between custom and existing uids, then checks if uids were stored correctly */ void CCustomLabelUid::DuplicateUidsTestL( const TContactItemId aCid ) { //open contact CContactItem *contactItem = NULL; contactItem = iContactsDatabase->OpenContactLX(aCid,*iViewAll); CleanupStack::PushL(contactItem); CContactItemFieldSet *contactFields = &(contactItem->CardFields()); //add two identical uids to each field, alternating between custom and existing uids const TInt KFieldsCount = contactFields->Count(); TInt error = KErrNone; //add duplicate custom uids CContactItemField *contactField1 = CContactItemField::NewL(KStorageTypeText); CleanupStack::PushL(contactField1); contactField1->SetTemplateField(EFalse); TRAP( error, contactField1->AddFieldTypeL( TFieldType::Uid(TestConstants::KInitialUID) )); INTCOMPARE( KErrNone, ==, error, 0, 0 ); TRAP( error, contactField1->AddFieldTypeL( TFieldType::Uid(TestConstants::KInitialUID) )); INTCOMPARE( KErrNone, ==, error, 0, 0 ); contactItem->AddFieldL(*contactField1); CleanupStack::Pop(contactField1); //add duplicate existing uids CContactItemField *contactField2 = CContactItemField::NewL(KStorageTypeText); CleanupStack::PushL(contactField2); contactField2->SetTemplateField(EFalse); TRAP( error, contactField2->AddFieldTypeL(KUidContactFieldAdditionalName)); INTCOMPARE( KErrNone, ==, error, 1, 0 ); TRAP( error, contactField2->AddFieldTypeL(KUidContactFieldAdditionalName)); INTCOMPARE( KErrNone, ==, error, 1, 0 ); contactItem->AddFieldL(*contactField2); CleanupStack::Pop(contactField2); //populate contact fields SetContactFieldsL(*contactItem); //update contact iContactsDatabase->CommitContactL(*contactItem); CleanupStack::PopAndDestroy(contactItem); CleanupStack::Pop();//lock contactItem = NULL; //read contact item contactItem = iContactsDatabase->ReadContactLC(aCid,*iViewAll); contactFields = &(contactItem->CardFields()); //check that contact field uids updated correctly const TInt KReadFieldsCount = contactFields->Count(); const CContentType *KContentType = NULL; INTCOMPARE( KReadFieldsCount, >, 0, 0, 0 ); KContentType = &(*contactFields)[KFieldsCount].ContentType(); SINGLECOMPARE( KContentType->ContainsFieldType( TFieldType::Uid(TestConstants::KInitialUID) ), KFieldsCount,0 ); KContentType = &(*contactFields)[KFieldsCount+1].ContentType(); SINGLECOMPARE( KContentType->ContainsFieldType(KUidContactFieldAdditionalName), KFieldsCount+1,0 ); //check that contact fields updated correctly SINGLECOMPARE( CheckContactFieldsL(*contactItem), 0, 0 ); CleanupStack::PopAndDestroy(contactItem); }