/** * Create phonebook group * @param aDb Contact database */ TContactItemId CreatePhonebookGroupL(CContactDatabase& aDb) { _LIT(KPhbkGroup,"ADN Phonebook"); CContactItem* group = aDb.CreateContactGroupLC(KPhbkGroup); TContactItemId groupId = group->Id(); CleanupStack::PopAndDestroy(group); return groupId; }
void CTestResources::CreateTestContactsL() { const TInt KContacts = 4; TInt i; iContacts = CContactIdArray::NewL(); // Create contacts for (i=1; i <= KContacts; ++i) { CContactCard* card = CContactCard::NewLC(); CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName); TBuf<30> name; name.Format(_L("Contact%02d"), i); field->TextStorage()->SetTextL(name); card->AddFieldL(*field); CleanupStack::Pop(field); const TContactItemId contactId = iDb->AddNewContactL(*card); iContacts->AddL(contactId); CleanupStack::PopAndDestroy(card); // Eat away contact db events TContactDbObserverEvent event; test(iDbEventQueue->ListenForEvent(10,event)); } // Create a group CContactItem* group = iDb->CreateContactGroupLC(_L("TestGroup")); iGroupId = group->Id(); CleanupStack::PopAndDestroy(group); // Connect half of the contacts to the group for (i=0; i < iContacts->Count(); ++i) { if (i%2 == 0) { iDb->AddContactToGroupL((*iContacts)[i], iGroupId); } } }
void CRemoteViewTestResources::CreateTestGroupsL() { test.Next(_L("Test for creating a remote view and validating that queued events are received in the correct order.")); TContactViewEvent event; // Create A then "unnanmed", then rename "unnamed" to B test.Next(_L("Test for Create group A, then create group B")); CContactItem* group1 = iDb->CreateContactGroupLC(_L("A")); iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EItemAdded, 0, group1->Id()); CContactItem* group0 = iDb->CreateContactGroupLC(_L("")); iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EItemAdded, 1, group0->Id()); CContactItem *group00 = iDb->OpenContactL(group0->Id()); static_cast<CContactGroup*> (group00)->SetGroupLabelL(_L("B")); iDb->CommitContactL(*group00); // Received 3 events, grp changed, removed and added iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EGroupChanged, 0, group00->Id()); iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EItemRemoved, 1, group00->Id()); iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EItemAdded, 1, group00->Id()); // Create D then "unnamed", then rename "unnamed" to C test.Next(_L("Test for Create group D, then create group C")); CContactItem* group2 = iDb->CreateContactGroupLC(_L("D")); iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EItemAdded, 2, group2->Id()); CContactItem* group3 = iDb->CreateContactGroupLC(_L("")); iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EItemAdded, 3, group3->Id()); CContactItem *group4 = iDb->OpenContactL(group3->Id()); static_cast<CContactGroup*> (group4)->SetGroupLabelL(_L("C")); iDb->CommitContactL(*group4); // Received 3 events, grp changed, removed and added iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EGroupChanged, 0, group4->Id()); iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EItemRemoved, 3, group4->Id()); iViewEventQueue->ListenForEvent(2,event); CheckEvent(event, TContactViewEvent::EItemAdded, 2, group4->Id()); // More complex set of add and deletes. test.Next(_L("Test-Addgroup E, Addgroup F, Addgroup G , RemoveGroup G Addgroup H RenameGroup H as EA")); CContactItem* group5 = iDb->CreateContactGroupLC(_L("E")); CContactItem* group6 = iDb->CreateContactGroupLC(_L("F")); CContactItem* group7 = iDb->CreateContactGroupLC(_L("G")); iDb->DeleteContactL(group7->Id()); CContactItem* group8 = iDb->CreateContactGroupLC(_L("H")); CContactItem *group01 = iDb->OpenContactL(group8->Id()); static_cast<CContactGroup*> (group01)->SetGroupLabelL(_L("EA")); iDb->CommitContactL(*group01); // Should receive events for operations above, order is not important // Should receive events as add for E F EA(H) - In the order E EA(H) F // (none for G as add, then remove) iViewEventQueue->ListenForEvent( 2, event ); CheckEvent( event, TContactViewEvent::EItemAdded, 4, group5->Id() ); iViewEventQueue->ListenForEvent( 2, event ); CheckEvent( event, TContactViewEvent::EItemAdded, 5, group6->Id() ); iViewEventQueue->ListenForEvent( 2, event ); CheckEvent( event, TContactViewEvent::EItemAdded, 6, group8->Id() ); iViewEventQueue->ListenForEvent( 2, event ); CheckEvent( event, TContactViewEvent::EItemAdded, 7, group7->Id() ); iViewEventQueue->ListenForEvent( 2, event ); CheckEvent( event, TContactViewEvent::EItemRemoved, 7, group7->Id() ); iViewEventQueue->ListenForEvent( 2, event ); CheckEvent( event, TContactViewEvent::EGroupChanged, 0, group8->Id() ); // Cleanup delete group01; delete group00; delete group4; CleanupStack::PopAndDestroy(group8); CleanupStack::PopAndDestroy(group7); CleanupStack::PopAndDestroy(group6); CleanupStack::PopAndDestroy(group5); CleanupStack::PopAndDestroy(group3); CleanupStack::PopAndDestroy(group2); CleanupStack::PopAndDestroy(group0); CleanupStack::PopAndDestroy(group1); }