LOCAL_C void TestUpdateContactL() { test.Next(_L("TestUpdateContactL")); SETUP; CContactItem* contact = CContactItem::NewLC(KUidContactCard); TContactItemId id = cntClient.CreateContactL(*contact); CleanupStack::PopAndDestroy(contact); // View definition to read image field CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); imageViewDef->AddL(KUidContactFieldMatchAll); contact = cntClient.OpenContactLX(imageViewDef ,id); CleanupStack::PushL(contact); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage); newField->SetMapping(KUidContactFieldVCardMapUnknown); newField->TextStorage()->SetTextL(KSrcImage()); contact->AddFieldL(*newField); // Takes ownership CleanupStack::Pop(newField); cntClient.CommitContactL(*contact, EFalse); CleanupStack::PopAndDestroy(2); // contact, imageViewDef // View definition to read image field imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); imageViewDef->AddL(KUidContactFieldCodImage); contact = cntClient.ReadContactL(imageViewDef ,id); TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown); // Test image field found test(index != KErrNotFound); CContactItemField& field = contact->CardFields()[index]; TPtrC imagePtr = field.TextStorage()->Text(); // Image should exist test(BaflUtils::FileExists(fs, imagePtr)); // Test for GUID TPtrC guid = contact->Guid(); test(imagePtr.Find(guid)); cntClient.CloseContact(id); CleanupStack::PopAndDestroy(2); // contact, imageViewDef TEAR_DOWN; }
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 CAsyncTest::TestResultL() { CContactDatabase* db = iOpenOp->TakeDatabase(); if(db == NULL) User::Leave(KErrNotFound); // Test adding a contact CContactItemViewDef* matchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields); matchAll->AddL(KUidContactFieldMatchAll); CContactItem* cntTemplate = db->ReadContactL(0, *matchAll); CleanupStack::PopAndDestroy(matchAll); CleanupStack::PushL(cntTemplate); CCntItemBuilder* cntItemBldr = CCntItemBuilder::NewLC(static_cast<CContactTemplate&>(*cntTemplate)); CContactItem* tempCntItem = cntItemBldr->GetCntItemLC(); db->AddNewContactL(*tempCntItem); CleanupStack::PopAndDestroy(tempCntItem); CleanupStack::PopAndDestroy(cntItemBldr); CleanupStack::PopAndDestroy(cntTemplate); delete iOpenOp; delete db; iOpenOp = NULL; db = NULL; iTest->Next(_L("Read data from Database\n")); }
void CPackagerTests::EmptyContactItemTestL() { CCntPackager* thePackage = CCntPackager::NewL(); CleanupStack::PushL(thePackage); test.Next(_L("EmptyContactItemTestL")); CPersistenceLayer* iPersistLayer = CPersistenceLayer::NewLC(iFs); CContactItemViewDef* cntItemVdef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); cntItemVdef->AddL(KUidContactFieldMatchAll); MLplContactsFile& cntFile = iPersistLayer->ContactsFileL(); TRAPD(err, cntFile.CreateL(KCreatePlPerform, true ? MLplContactsFile::EPlOverwrite : MLplContactsFile::EPlLeaveIfExist)); User::LeaveIfError(err); TRAP(err, while(cntFile.OpenStepL(KCreatePlPerform)){});
LOCAL_C void TestDeleteContactL() { test.Next(_L("TestDeleteContactL")); SETUP; CContactItem* contact = CContactItem::NewLC(KUidContactCard); CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage); newField->SetMapping(KUidContactFieldVCardMapUnknown); newField->TextStorage()->SetTextL(KSrcImage()); contact->AddFieldL(*newField); // Takes ownership CleanupStack::Pop(newField); TContactItemId id = cntClient.CreateContactL(*contact); CleanupStack::PopAndDestroy(contact); // View definition to read image field CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); imageViewDef->AddL(KUidContactFieldCodImage); contact = cntClient.ReadContactL(imageViewDef ,id); CleanupStack::PopAndDestroy(imageViewDef); // imageViewDef TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown); // Test image field found test(index != KErrNotFound); CContactItemField& field = contact->CardFields()[index]; TPtrC imagePtr = field.TextStorage()->Text(); test(BaflUtils::FileExists(fs, imagePtr)); cntClient.DeleteContactL(id, EDeferEvent, ETrue); test(!BaflUtils::FileExists(fs, imagePtr)); cntClient.CloseContact(id); delete contact; TEAR_DOWN; }
TBool CViewDefAnyFieldsTest::FieldCountCompL( const TContactItemId &aCid, CContactItemViewDef &aView, const TBool aExcludeN, const TBool aExcludeH, const TBool aZeroH, const TBool aMultiple) { TBool SingleTestResult = EFalse; TBool OverallTestResult = EFalse; TInt countM = 0; TInt countR = 0; TInt fieldsIV = 0; TInt emptyfsM = 0; TInt emptyfsR = 0; TInt hcountM = 0; TInt hcountR = 0; TInt hfieldsIV = 0; TInt length = 0; length = iExistingUidsArray->Count(); for(TInt i = 0, j = 0; i < length;) { OverallTestResult = EFalse; if( (*iExistingUidsArray)[i] == 0 ) { ++i; continue; } aView.AddL(TUid::Uid((*iExistingUidsArray)[i])); ReadL(aCid,*iViewAll,EFalse); FieldsInView(aView, fieldsIV, hfieldsIV); countR = iFields->Count(); hcountR = CountHiddenFields(*iFields); emptyfsR = CountEmpty(*iFields); Close(); ReadMinimalL(aCid, aView, *iDefView,EFalse); countM = iFields->Count(); hcountM = CountHiddenFields(*iFields); emptyfsM = CountEmpty(*iFields); Close(); SingleTestResult = INTCOMPARE( 0 , ==, emptyfsM, i, 0 ); OverallTestResult = SingleTestResult; SingleTestResult = INTCOMPARE( 0 , ==, emptyfsR, i, 0 ); OverallTestResult = OverallTestResult && SingleTestResult; SingleTestResult = INTCOMPARE( hcountR , >, 0 , i, 0 ); OverallTestResult = OverallTestResult && SingleTestResult; if(aExcludeN) { SingleTestResult = INTCOMPARE( ( (countR - fieldsIV) - hcountR ) , ==, (countM - hcountM) , i, 0 ); OverallTestResult = OverallTestResult && SingleTestResult; } else { SingleTestResult = INTCOMPARE( fieldsIV , ==, (countM - hcountM) , i, 0 ); OverallTestResult = OverallTestResult && SingleTestResult; } if(aExcludeH) { if( aZeroH) { SingleTestResult = INTCOMPARE( 0 , ==, hcountM, i, 0 ); OverallTestResult = OverallTestResult && SingleTestResult; } else { SingleTestResult = INTCOMPARE( ( hcountR - hfieldsIV) , ==, hcountM , i, 0 ); OverallTestResult = OverallTestResult && SingleTestResult; } }
LOCAL_C void TestCreateContactWithoutImagesFoldeL() { test.Next(_L("TestCreateContactWithoutImagesFoldeL")); SETUP; // Delete the images folder and all contents TInt drive; #ifdef __WINS__ TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultPhoneMemory, drive); #else TInt err = DriveInfo::GetDefaultDrive(DriveInfo::EDefaultMassStorage, drive); #endif // Do not leave with this error. The phone does not have to have this support if (err == KErrNone) { // Get the root path in this drive to create // to create the images directory TPath dir; User::LeaveIfError(PathInfo::GetRootPath(dir, drive)); dir.Append(KImagesFolder); CFileMan* fileMan = CFileMan::NewL(fs); err = fileMan->RmDir(dir); // err not used delete fileMan; } else { test.Printf(_L("Could not remove the images folder\n")); return; } // Create an image and store an image without the images dir available CContactItem *contact = CContactItem::NewLC(KUidContactCard); CContactItemField *newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage); newField->SetMapping(KUidContactFieldVCardMapUnknown); newField->TextStorage()->SetTextL(KSrcImage()); contact->AddFieldL(*newField); // Takes ownership CleanupStack::Pop(newField); TContactItemId id = cntClient.CreateContactL(*contact); CleanupStack::PopAndDestroy(contact); // View definition to read image field CContactItemViewDef *imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields); imageViewDef->AddL(KUidContactFieldCodImage); contact = cntClient.ReadContactL(imageViewDef ,id); CleanupStack::PopAndDestroy(imageViewDef); // imageViewDef TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown); // Test image field found test(index != KErrNotFound); CContactItemField& field = contact->CardFields()[index]; TPtrC imagePtr = field.TextStorage()->Text(); // Image path should not change test(imagePtr.Compare(KSrcImage()) == 0); cntClient.CloseContact(id); delete contact; TEAR_DOWN; }
/** Add the given contact item to the database. Forward the call to CPplTableBase based classes representing the tables in the contact database. @param aItem The contact item to be added to the database. @param aSessionId The ID of the session that issued the request. Used to prevent Phonebook Synchroniser deadlock. @return Contact item ID of the contact added to the database. */ TContactItemId CPplContactItemManager::CreateL(CContactItem& aItem, TUint aSessionId) { TBool controlTransaction = !(iTransactionManager.IsTransactionActive()); TBool compressedGuid=EFalse; // If needed generate a gui for the current contact item if (aItem.Guid() == TPtrC(KNullDesC)) { iPreferencePersistor->SetGuidL(aItem, compressedGuid); } if (compressedGuid) { aItem.SetHasCompressedGuid(compressedGuid); } if (aItem.Type() == KUidContactICCEntry) { const TInt ret = iContactProperties.ContactSynchroniserL(aSessionId).ValidateWriteContact(static_cast<CContactICCEntry&>(aItem)); User::LeaveIfError(ret); } if(controlTransaction) { StartTransactionL(aSessionId); } iContactTable->CreateInDbL(aItem); iGroupTable->CreateInDbL(aItem); iCommAddrTable->CreateInDbL(aItem); TContactItemId groupId = iIccContactStore.CreateInDbL(aItem, aSessionId); if(groupId != KNullContactId) { //Every ICC entry is added to a special group, created by the Phonebook //Synchroniser server during the initial synchronisation with the Contacts Model. CContactItemViewDef* itemDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields); itemDef->AddL(KUidContactFieldMatchAll); // Add ICC entry to the group. CContactGroup* grp = static_cast<CContactGroup*>(ReadLC(groupId, *itemDef, EPlAllInfo, aSessionId)); grp->AddContactL(aItem.Id()); UpdateL(*grp, aSessionId); CleanupStack::PopAndDestroy(2, itemDef); // grp } if(controlTransaction) { CommitTransactionL(); } // Assuming success if no leaves at this point, so update // the metadata search store for this entry //CCntMetadataOperation* op = CCntMetadataOperation::NewLC(iColSession); //TRAP_IGNORE(op->SaveContactLD(aItem)); //CleanupStack::Pop(op); // Do not destroy - called LD function return aItem.Id(); }