// This tests tries to reproduce defect // EDNRTRN-4J5C5E "Groups in Cntmodel cannot be renamed.." // // This defect was caused because groups weren't included in the view and // MoveInSortArrayL doesn't check that the contact item will be in the // iSortedItems list (this list depends on the view chosen). // LOCAL_C void RenameDefectL() { test.Next(_L("Rename a group")); CntTest->CloseDatabase(); CntTest->DeleteDatabaseL(); CContactDatabase* db=CntTest->CreateDatabaseL(); _LIT(KCntmodelOriginalName,"Original"); _LIT(KCntmodelRevisedName,"Revised"); CContactItem* newGroup = CntTest->Db()->CreateContactGroupLC(KCntmodelOriginalName); TContactItemId groupId = newGroup->Id(); CleanupStack::PopAndDestroy(); //newGroup TContactItemId contactA=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("a")); TContactItemId contactB=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("b")); CntTest->Db()->AddContactToGroupL(contactA,groupId); CntTest->Db()->AddContactToGroupL(contactB,groupId); CntTest->Db()->SetDbViewContactType(KUidContactCard); CntTest->Db()->SortedItemsL(); // ensures theres a iSortedItems SetSortOrderL(*db,TUid::Uid(KUidContactFieldDefinedTextValue)); // required so that the comparision CContactGroup* group = static_cast<CContactGroup*>(CntTest->Db()->OpenContactL(groupId)); CleanupStack::PushL(group); group->SetGroupLabelL(KCntmodelRevisedName); CntTest->Db()->CommitContactL(*group); CntTest->Db()->CloseContactL(groupId); CleanupStack::PopAndDestroy(); //group CContactItem* revisedGroup = CntTest->Db()->ReadContactLC(groupId,*CntTest->Db()->AllFieldsView()); TPtrC testLabel = static_cast<CContactGroup*>(revisedGroup)->GetGroupLabelL(); test(testLabel==KCntmodelRevisedName); CleanupStack::PopAndDestroy(); //revisedGroup }
void CConcurrentNotifierStep::SpeedDialTestL() { INFO_PRINTF1(KTest8); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; iMyActive->Activate(); TContactItemId cid = iIterate->PreviousL();//start at last contact, so that other tests are not corrupted OpenL( cid ); TInt fieldId=iFields->Find(KUidContactFieldPhoneNumber); iSpeedPosition = 1; iContactsDatabase->SetFieldAsSpeedDialL(*iContactItem, fieldId, iSpeedPosition); CloseL( EFalse ); OpenL( cid ); iSpeedPosition2 = 2; iContactsDatabase->SetFieldAsSpeedDialL(*iContactItem, fieldId, iSpeedPosition2); CloseL( EFalse ); AddEventL( EContactDbObserverEventSpeedDialsChanged ); AddContactL( cid ); AddEventL( EContactDbObserverEventSpeedDialsChanged ); AddContactL( cid ); AddEventL( EContactDbObserverEventSpeedDialsChanged ); AddContactL( cid ); SetMessageCountL(); iStart.UniversalTime(); }
/** if in revert mode rollback transaction, otherwise commit, tell listner to expect an notifications that may be generated */ void CConcurrentNotifierStep::EndTransactionL( ) { if(iRevert) { iRevert = EFalse; iContactsDatabase->DatabaseRollback(); AddEventL( EContactDbObserverEventRollback ); AddContactL( KNullContactId ); CleanupStack::Pop(); TBool damaged = iContactsDatabase->IsDamaged(); #ifdef _DEBUG #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ //It maybe necessary to explicitly damage the database more than once //for it to be registered as damaged while( !iContactsDatabase->IsDamaged() ) { //will give consistent behaviour on debug builds iContactsDatabase->DamageDatabaseL(0x666); } if( !damaged ) { AddEventL( EContactDbObserverEventRollback ); AddContactL( KNullContactId ); } #endif #endif if( iContactsDatabase->IsDamaged() ) { iContactsDatabase->RecoverL(); AddEventL( EContactDbObserverEventRecover ); AddContactL( 0 ); if( !damaged ) { AddEventL( EContactDbObserverEventTablesClosed ); AddContactL( 0 ); } AddEventL( EContactDbObserverEventTablesOpened ); AddContactL( 0 ); } iRevert = ETrue; } else { iContactsDatabase->DatabaseCommitLP(EFalse); } iRevert = !iRevert; }
void CConcurrentNotifierStep::MultipleChangeTransactionTestL() { if( iRevert ) { INFO_PRINTF1(KTest112); } else { INFO_PRINTF1(KTest11); } SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; TContactItemId cid = iIterate->NextL(); iContactsDatabase->DatabaseBeginLC(EFalse); OpenL( cid ); CommitL( ETrue ); AddEventL(EContactDbObserverEventContactChanged); AddContactL( cid ); cid = iIterate->NextL(); ReadL( cid ); iContactsDatabase->UpdateContactLC( cid, iContactItem); CleanupStack::PopAndDestroy(); CloseL( ETrue ); AddEventL(EContactDbObserverEventContactChanged); AddContactL( cid ); CContactCard* contact = CContactCard::NewLC(iTemplate); cid = iContactsDatabase->doAddNewContactL(*contact, EFalse, ETrue); if(!iRevert) { iIterate->AddL( cid ); } CleanupStack::PopAndDestroy(contact); AddEventL(EContactDbObserverEventContactAdded); AddContactL( cid ); cid = iIterate->NextL(); DeleteContactL( cid, ETrue ); AddEventL(EContactDbObserverEventContactDeleted); AddContactL( cid ); EndTransactionL(); SetMessageCountL(); iStart.UniversalTime(); }
// Regression testcode for MAT-5B7JD4 "AddContactToGroupL()/RemoveContactFromGroupL() does not update // object passed as argument" // LOCAL_C void GroupAddRemoveTestL() { test.Next(_L("Group addition/removal defect")); CntTest->CloseDatabase(); CntTest->DeleteDatabaseL(); CContactDatabase* db=CntTest->CreateDatabaseL(); _LIT(KCntmodelGroup,"MyGroup"); CContactItem* group = db->CreateContactGroupLC(KCntmodelGroup); TContactItemId groupId = group->Id(); TContactItemId itemId=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("C")); CContactItem* item = CntTest->Db()->ReadContactLC(itemId); CntTest->Db()->AddContactToGroupL(*item,*group); // write change to database const CContactIdArray* groupsJoined = STATIC_CAST(CContactItemPlusGroup*,item)->GroupsJoined(); test(groupsJoined->Find(groupId)==0); const CContactIdArray* itemsContained = STATIC_CAST(CContactGroup*,group)->ItemsContained(); test(itemsContained->Find(itemId)==0); CntTest->Db()->RemoveContactFromGroupL(*item,*group); test(STATIC_CAST(CContactItemPlusGroup*,item)->GroupsJoined()->Find(groupId)!=0); test(STATIC_CAST(CContactGroup*,group)->ItemsContained()->Find(itemId)!=0); CleanupStack::PopAndDestroy(item); CleanupStack::PopAndDestroy(group); }
//------------------------------------------------------------------------------------------------------------ // The contacts to be duplicated are not really random void CPerfDbCreator::GenContactsL(TContactLevel aLevel, TInt aSingles, TInt aDuplicates) { TInt i, dupDiv, duplicated=0; TReal dupDivReal; TContactItemId contactItemId; CContactItem* contactItem; if (aDuplicates != 0) { Math::Round(dupDivReal, (TReal)aSingles/(TReal)aDuplicates, 0); dupDiv= (TInt) dupDivReal; } else dupDiv=0xffff; for (i=0; i < aSingles; i++) { contactItemId = AddContactL(aLevel); // duplicate every dupDiv contact, but do not exceed aDuplicates if ((duplicated<aDuplicates) && ((i % dupDiv) == 0)) { duplicated++; contactItem = iContactsDb->ReadContactL(contactItemId); iContactsDb->AddNewContactL(*contactItem); delete contactItem; } // Compact after every KCompactEvery added contact if ((i % KCompactEvery) == 0) iContactsDb->CompactL(); } }
//------------------------------------------------------------------------------------------------------------ void CPerfDbCreator::GenAllTheSameDbL(TContactLevel aLevel, TInt aCount, TBool aAddSeedPrefix, const TDesC &aFileName) { TInt i; TContactItemId contactItemId; CContactItem* contactItem; iAddSeedPrefix=aAddSeedPrefix; iSeed=KSeed; iContactsDb = CContactDatabase::ReplaceL(aFileName); // Template will be used later, to add new contacts iTemplate=static_cast<CContactTemplate*>(iContactsDb->ReadContactL(iContactsDb->TemplateId())); // Generate database contactItemId = AddContactL(aLevel); // contact 0 for (i=1; i < aCount; i++) // contacts 1,2,3... { contactItem = iContactsDb->ReadContactL(contactItemId); iContactsDb->AddNewContactL(*contactItem); delete contactItem; // Compact after every KCompactEvery added contact if ((i % KCompactEvery) == 0) iContactsDb->CompactL(); } // And clanup delete iContactsDb; iContactsDb = NULL; delete iTemplate; iTemplate = NULL; }
void CConcurrentNotifierStep::OwnCardTestL() { INFO_PRINTF1(KTest7); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; iMyActive->Activate(); CContactItem *item = iContactsDatabase->CreateOwnCardLC(); iIterate->AddL( item->Id() ); AddEventL( EContactDbObserverEventContactAdded ); AddContactL( item->Id() ); AddEventL( EContactDbObserverEventOwnCardChanged ); AddContactL( item->Id() ); CleanupStack::PopAndDestroy( item ); SetMessageCountL(); iStart.UniversalTime(); }
void CFindTest::AddContactCompactL(const TDesC& aFirstName,const TDesC& aLastName,const TDesC& aCompanyName, const TDesC& aWorkPhone,const TDesC& aHomePhone,const TDesC& aWorkMobile, const TDesC& aHomeMobile,const TDesC& aWorkEmail) { AddContactL(aFirstName,aLastName,aCompanyName,aWorkPhone,aHomePhone,aWorkMobile,aHomeMobile,aWorkEmail); iDb->CompactL(); }
TInt CPlTransMgrTest::AddAndCommitContactL() { iPersistLayer->TransactionManager().StartTransactionL(); TInt cntID = AddContactL(); iPersistLayer->TransactionManager().CommitCurrentTransactionL(0); return cntID; }
void CConcurrentNotifierStep::DeleteSpeedDialTestL() { INFO_PRINTF1(KTest15); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; iMyActive->Activate(); TBuf<200> ptr; TContactItemId cid = iContactsDatabase->GetSpeedDialFieldL(iSpeedPosition, ptr); DeleteContactL( cid, EFalse ); AddEventL( EContactDbObserverEventSpeedDialsChanged ); AddContactL( cid ); AddEventL( EContactDbObserverEventContactDeleted ); AddContactL( cid); SetMessageCountL(); iStart.UniversalTime(); }
void CNotificationStep::UnkownChangeTestL() { INFO_PRINTF1(KTest1); TContactItemId cid = iIterate->NextL(); TInt i = 0; for( ; i < KMaxNumberOfEventsInEventQueue + 10; ++i ) { OpenL( cid ); CommitL( EFalse ); } AddEventL( EContactDbObserverEventContactChanged ); AddContactL( cid ); AddEventL( EContactDbObserverEventUnknownChanges ); AddContactL( -1 ); iMyActive->iCheck = &CNotificationStep::UnkownChangeCheck; iMyActive->Activate(); iStart.UniversalTime(); CActiveScheduler::Start(); }
void CNotificationStep::PlusTransactionUnkownChangeTestL(const TBool aRevert) { INFO_PRINTF1(KTest3); TContactItemId cid = iIterate->NextL(); TInt i = 0; for( ; i < KPlusContacts; ++i ) { OpenL( cid ); CommitL( EFalse ); } TInt many = aRevert ? KPlusContacts : 1; for( i = 0; i < many; ++i ) { AddEventL( EContactDbObserverEventContactChanged ); AddContactL( cid ); } cid = iIterate->NextL(); iContactsDatabase->DatabaseBeginLC(EFalse); for( i = 0; i < KMaxNumberOfEventsInEventQueue + 1; ++i ) { OpenL( cid ); CommitL( ETrue ); } EndTransactionL( aRevert ); if( !aRevert ) { AddEventL( EContactDbObserverEventUnknownChanges ); AddContactL( -1 ); iMyActive->iCheck = &CNotificationStep::UnkownChangeCheck; } else { iMyActive->iCheck = &CNotificationStep::TransactionUnkownChangeCheck; } iMyActive->Activate(); iStart.UniversalTime(); CActiveScheduler::Start(); }
void CConcurrentNotifierStep::CloseTablesTestL() { INFO_PRINTF1(KTest6); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; iMyActive->Activate(); iContactsDatabase->CloseTables(); AddEventL( EContactDbObserverEventTablesClosed ); AddContactL( 0 ); SetMessageCountL(); iStart.UniversalTime(); }
void CConcurrentNotifierStep::DeleteTestL() { INFO_PRINTF1(KTest4); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; TContactItemId cid = iIterate->NextL(); DeleteContactL( cid, EFalse ); AddEventL(EContactDbObserverEventContactDeleted); AddContactL( cid ); SetMessageCountL(); iStart.UniversalTime(); }
/** commit or rollback transaction as necessary, recover database if damage by rollback */ void CNotificationStep::EndTransactionL(const TBool aRevert) { if(aRevert) { iContactsDatabase->DatabaseRollback(); AddEventL( EContactDbObserverEventRollback ); AddContactL( KNullContactId ); CleanupStack::Pop(); if( iContactsDatabase->IsDamaged() ) { iContactsDatabase->RecoverL(); AddEventL( EContactDbObserverEventTablesClosed ); AddContactL( 0 ); AddEventL( EContactDbObserverEventTablesOpened ); AddContactL( 0 ); } } else { iContactsDatabase->DatabaseCommitLP(EFalse); } }
void CConcurrentNotifierStep::AddTestL() { INFO_PRINTF1(KTest3); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; CContactCard* contact = CContactCard::NewLC(iTemplate); TContactItemId cid = iContactsDatabase->AddNewContactL(*contact); iIterate->AddL( cid ); CleanupStack::PopAndDestroy(contact); AddEventL(EContactDbObserverEventContactAdded); AddContactL( cid ); SetMessageCountL(); iStart.UniversalTime(); }
void CPlTransMgrTest::OutOfMemoryAddTestL() { TInt ret=KErrNoMemory; TInt failAt=0; while (ret!=KErrNone) { // Add a successful contact, guess the next contact id TInt cntID = AddAndCommitContactL(); ++cntID; iPersistLayer->TransactionManager().StartTransactionL(); failAt++; __UHEAP_SETFAIL(RHeap::EDeterministic,failAt); __UHEAP_MARK; TRAPD(err, AddContactL()); if (err==KErrNone) { TRAP(err, iPersistLayer->TransactionManager().CommitCurrentTransactionL(0)); if (err==KErrNone) { test.Next(_L("-> TEST SUCCESS - Contact committed during OOM Test")); __UHEAP_RESET; return; } } __UHEAP_RESET; if (err!=KErrNoMemory && err!=KErrNone) { test.Printf(_L("Non standard error: %d\n"),err); } if (err == KErrNoMemory) { iPersistLayer->TransactionManager().RollbackCurrentTransactionL(0); // Close the database to allow recovery iPersistLayer->ContactsFileL().Close(); iPersistLayer->ContactsFileL().RecoverL(nsPlTransMgr::KFilename); if (!IsContactInDbL(cntID)) { test.Printf(_L(" ->Correct result - Create rollback during OOM - Contact NOT Found... Step: %d \n\r"),failAt); } else { test.Printf(_L(" ->Error - Delete rollback during OOM - Contact Found... Step: %d \n\r"),failAt); User::Leave(KErrNotFound); } } } }
void CConcurrentNotifierStep::UpdateTestL() { INFO_PRINTF1(KTest1); SetSharedTextL(KSharedNextTest,KSingleCharacter , ETrue); iWaiting = ETrue; TContactItemId cid = iIterate->NextL(); ReadL( cid ); iContactsDatabase->UpdateContactLC( cid, iContactItem); CleanupStack::PopAndDestroy(); CloseL( ETrue ); AddEventL(EContactDbObserverEventContactChanged); AddContactL( cid ); SetMessageCountL(); iStart.UniversalTime(); }
void CConcurrentNotifierStep::OwnCardDeleteTestL() { INFO_PRINTF1(KTest9); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; iMyActive->Activate(); TContactItemId cid = iContactsDatabase->OwnCardId(); ReadL( cid ); CloseL( EFalse ); DeleteContactL( cid, EFalse ); AddEventL( EContactDbObserverEventOwnCardDeleted ); AddContactL( cid); SetMessageCountL(); iStart.UniversalTime(); }
void CConcurrentNotifierStep::ChangeOwnCardTestL() { INFO_PRINTF1(KTest14); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; iMyActive->Activate(); TContactItemId cid = iIterate->NextL(); OpenL( cid ); iContactsDatabase->SetOwnCardL(*iContactItem); CloseL( ETrue ); AddEventL( EContactDbObserverEventOwnCardChanged ); AddContactL( cid ); SetMessageCountL(); iStart.UniversalTime(); }
// This tests reproduces defect // BET-4YDGB3 "Contacts crashes when creating two entries" // // This was caused because the CContactTables::ContactType() method uses the // iCurrentIdInIdentityTable to determine which contact should be used to read // the type information from. This member stores the last contact ID to be read // from the identity table. However, since AddContactToGroupL() doesn't read any // information from the identity table, the value set in iCurrentIdInIdentityTable // should be set to KErrNotFound so that the correct contact from main CONTACTS table // is used. // LOCAL_C void QuartzGroupDefectL() { test.Next(_L("Quartz defect")); CntTest->CloseDatabase(); CntTest->DeleteDatabaseL(); CContactDatabase* db=CntTest->CreateDatabaseL(); _LIT(KCntmodelGroupAll,"All"); CContactItem* group = db->CreateContactGroupLC(KCntmodelGroupAll); TContactItemId groupId = group->Id(); CleanupStack::PopAndDestroy(group); CntTest->Db()->SetDbViewContactType(KUidContactCard); CntTest->Db()->SortedItemsL(); // ensures theres a iSortedItems SetSortOrderL(*db,TUid::Uid(KUidContactFieldDefinedTextValue)); // required so that the comparision TContactItemId contactB=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("B")); CntTest->Db()->AddContactToGroupL(contactB,groupId); TContactItemId contactA=AddContactL(db,KUidContactFieldFamilyName,KUidContactFieldVCardMapUnusedN,_L("A")); CntTest->Db()->AddContactToGroupL(contactA,groupId); }
void CConcurrentNotifierStep::UnkownChangeTestL() { INFO_PRINTF1(KTest13); SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; iMyActive->Activate(); TContactItemId cid = iIterate->NextL(); TInt i = 0; iContactsDatabase->DatabaseBeginLC(EFalse); for( ; i < KMaxNumberOfEventsInEventQueue + 1; ++i ) { OpenL( cid ); CommitL( EFalse ); } AddEventL( EContactDbObserverEventUnknownChanges ); AddContactL( -1 ); EndTransactionL(); SetMessageCountL(); iStart.UniversalTime(); }
void CConcurrentNotifierStep::EmptyTransactionTestL() { if( iRevert ) { INFO_PRINTF1(KTest122); } else { INFO_PRINTF1(KTest12); } SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; iContactsDatabase->DatabaseBeginLC(EFalse); AddEventL(KNullEvent); AddContactL( KNullEvent ); EndTransactionL(); SetMessageCountL(); iStart.UniversalTime(); }
void CPlTransMgrTest::RollbackAndRecoverTestL() { test.Next(_L("-> Rollback & Recover Test")); iPersistLayer->TransactionManager().StartTransactionL(); TInt cntID = AddContactL(); iPersistLayer->TransactionManager().RollbackCurrentTransactionL(0); // Close the database to allow recovery iPersistLayer->ContactsFileL().Close(); iPersistLayer->ContactsFileL().RecoverL(nsPlTransMgr::KFilename); if (!IsContactInDbL(cntID)) { test.Next(_L("-> TEST SUCCESS - Contact was NOT Found after Rollback test")); return; } test.Next(_L("-> TEST FAILED - Contact WAS Found after ROLLBACK test")); }
void CConcurrentNotifierStep::SingleCommitTransactionTestL() { if( iRevert ) { INFO_PRINTF1(KTest102); } else { INFO_PRINTF1(KTest10); } SetSharedTextL(KSharedNextTest, KSingleCharacter, ETrue); iWaiting = ETrue; TContactItemId cid = iIterate->NextL(); iContactsDatabase->DatabaseBeginLC(EFalse); OpenL( cid ); CommitL( ETrue ); AddEventL(EContactDbObserverEventContactChanged); AddContactL( cid ); EndTransactionL(); SetMessageCountL(); iStart.UniversalTime(); }