void CContactsRamTest::AddContactsL(const TInt aNumber) /** Add number of contacts to db, using the system template. @return None @param aNumber number of contacts to be added @pre None @post database now contains aNumber of empty contacts */ { //viewdef that loads all fields CContactItemViewDef *viewAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields); viewAll->AddL(KUidContactFieldMatchAll); CContactTemplate *ttemplate = static_cast< CContactTemplate* >( iContactsDatabase->ReadContactLC( iContactsDatabase->TemplateId(), *viewAll ) ); CContactCard* contact = CContactCard::NewLC(ttemplate); SetManyFieldsL(KFieldValue, KManyFields, contact->CardFields()); for(TInt k = 0; k<aNumber; k++) { iContactsDatabase->AddNewContactL(*contact); } CleanupStack::PopAndDestroy(contact); CleanupStack::PopAndDestroy(ttemplate); CleanupStack::PopAndDestroy(viewAll); }
void TestCreationL(CContactDatabase& aDb) { _LIT(KTestCreation,"Create CContactICCEntry item"); test.Start(_L("@SYMTESTCaseID:PIM-T-ICCENTRY-0001 Create CContactICCEntry item")); //System Template TContactItemId systemTemplateId = aDb.TemplateId(); CContactItem* systemTemplate = aDb.ReadContactLC(systemTemplateId); CContactICCEntry* entry = CContactICCEntry::NewL(*systemTemplate); CleanupStack::PopAndDestroy(systemTemplate); CleanupStack::PushL(entry); //Test CContactICCEntry items can be identified from normal contact cards test(entry->Type() == KUidContactICCEntry); test(entry->TemplateRefId() == systemTemplateId); CleanupStack::PopAndDestroy(entry); //Create user defined template for ICC contacts test.Next(_L("CContactDatabase::ICCTemplateL()")); TContactItemId templateId = CreateICCTemplateL(aDb); test(KErrNone == syncChecker->UpdatePhonebookEntryL(KUidIccGlobalAdnPhonebook, templateId, KNullContactId)); //Check that contacts model calls the plug-in when asked for the //template ID. TInt callCount = syncChecker->ValidateMethodCallCountL(); test(callCount==0); TContactItemId templateIdFromCntmodel; templateIdFromCntmodel = aDb.ICCTemplateIdL(KUidIccGlobalAdnPhonebook); test(syncChecker->ValidateMethodCallCountL() == 1); test(templateId == templateIdFromCntmodel); CContactItem* iccTemplate = aDb.ReadContactLC(templateId); CheckTemplateL(*iccTemplate); //create ICC contact CContactICCEntry* iccentry = CContactICCEntry::NewL(*iccTemplate); CleanupStack::PopAndDestroy(iccTemplate); CleanupStack::PushL(iccentry); test(iccentry->Type() == KUidContactICCEntry); test(iccentry->TemplateRefId() == templateId); CleanupStack::PopAndDestroy(iccentry); test.End(); }
void AddEntriesBasedOnEachOfTheTemplatesL(CContactDatabase& aDb) { test.Next(_L("Test successful adding")); TInt numberOfAdnEntries=3; TInt numberOfSdnEntries=2; TInt numberOfLdnEntries=1; TInt numberOfUsimEntries=4; TInt iter=0; for (iter=0; iter<numberOfAdnEntries; ++iter) { TContactItemId id=AddIccEntryL(aDb,KUidIccGlobalAdnPhonebook); CContactGroup* group=static_cast<CContactGroup*>(aDb.ReadContactLC(syncChecker->GroupIdL(KUidIccGlobalAdnPhonebook))); CContactIdArray* entries=group->ItemsContainedLC(); test(entries->Count() == iter+1); CleanupStack::PopAndDestroy(entries); test(group->ContainsItem(id)); CleanupStack::PopAndDestroy(group); } for (iter=0; iter<numberOfSdnEntries; ++iter) { TContactItemId id=AddIccEntryL(aDb,KUidIccGlobalSdnPhonebook); CContactGroup* group=static_cast<CContactGroup*>(aDb.ReadContactLC(syncChecker->GroupIdL(KUidIccGlobalSdnPhonebook))); CContactIdArray* entries=group->ItemsContainedLC(); test(entries->Count() == iter+1); CleanupStack::PopAndDestroy(entries); test(group->ContainsItem(id)); CleanupStack::PopAndDestroy(group); } for (iter=0; iter<numberOfLdnEntries; ++iter) { TContactItemId id=AddIccEntryL(aDb, KUidIccGlobalLndPhonebook); CContactGroup* group=static_cast<CContactGroup*>(aDb.ReadContactLC(syncChecker->GroupIdL(KUidIccGlobalLndPhonebook))); CContactIdArray* entries=group->ItemsContainedLC(); test(entries->Count() == iter+1); CleanupStack::PopAndDestroy(entries); test(group->ContainsItem(id)); CleanupStack::PopAndDestroy(group); } for (iter=0; iter<numberOfUsimEntries; ++iter) { TContactItemId id=AddIccEntryL(aDb,KUidUsimAppAdnPhonebook); CContactGroup* group=static_cast<CContactGroup*>(aDb.ReadContactLC(syncChecker->GroupIdL(KUidUsimAppAdnPhonebook))); CContactIdArray* entries=group->ItemsContainedLC(); test(entries->Count() == iter+1); CleanupStack::PopAndDestroy(entries); test(group->ContainsItem(id)); CleanupStack::PopAndDestroy(group); } // Add an ICC entry based on the system template, not one of the ICC templates TContactItemId templateId=aDb.TemplateId(); CContactItem* systemTemplate = aDb.ReadContactLC(templateId); CContactICCEntry* entry = CContactICCEntry::NewL(*systemTemplate); CleanupStack::PopAndDestroy(systemTemplate); CleanupStack::PushL(entry); syncChecker->ResetMethodCallCountsL(); TContactItemId id = aDb.AddNewContactL(*entry); test(syncChecker->ValidateMethodCallCountL() == 3); syncChecker->ResetMethodCallCountsL(); CContactItem* item=aDb.ReadContactLC(id); test(syncChecker->ValidateMethodCallCountL() == 1); // check the entry hasn't been added to any group CContactIdArray* array=static_cast<CContactICCEntry*>(item)->GroupsJoinedLC(); test(array->Count() == 0); CleanupStack::PopAndDestroy(3); // array, close item, item }
/** @SYMTestCaseID PIM-T-TEMPL-INC100029-0001 @SYMTestType UT @SYMTestPriority Critical @SYMDEF INC100029 @SYMTestCaseDesc Tests that if an attempt is made to commit the System template with a field which contains data that the commit leaves with KErrNotSupported. @SYMTestActions 1. Open the System template. 2. Add data to the field KUidContactFieldGivenName. 3. Commit the System template. 4. Check that step 3 leaves with error KErrNotSupported. @SYMTestExpectedResults As per Test Action 4. */ LOCAL_C void TestTemplateFieldModificationL() { test.Next( _L("@SYMTestCaseID:PIM-T-TEMPL-INC100029-0001 Validate template field modification") ); CContactDatabase* db = CntTest->OpenDatabaseL(); // // 1. Open the System template. // CContactTemplate* contactTemplate = static_cast<CContactTemplate*>( db->OpenContactLX( db->TemplateId() ) ); CleanupStack::PushL( contactTemplate ); // // 2. Add data to the field KUidContactFieldGivenName. // SetNameL(*contactTemplate, KUidContactFieldGivenName, _L("Invalid"), EFalse ); // // 3. Commit the System template. // TRAPD( err, db->CommitContactL( *contactTemplate ) ); // // 4. Check that step 3 leaves with error KErrNotSupported. // test( err == KErrNotSupported ); CleanupStack::PopAndDestroy(2); // contactTemplate and lock. CntTest->CloseDatabase(); }