TContactItemId CTestResources::CreateTestContactL (const TDesC& aFamilyName, TBool aWithPhoneNumber) { // Create a contact card CContactCard* card = CContactCard::NewLC(); // Create a name field CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName); field->TextStorage()->SetTextL(aFamilyName); card->AddFieldL(*field); CleanupStack::Pop(field); // Create a phone number field if (aWithPhoneNumber) { // Create a phone number field CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPhoneNumber); field->TextStorage()->SetTextL(_L("555")); card->AddFieldL(*field); CleanupStack::Pop(field); } // Add the contact to the DB const TContactItemId contactId = iDb->AddNewContactL(*card); CleanupStack::PopAndDestroy(card); // Eat away contact db events TContactDbObserverEvent event; while (iDbEventQueue->ListenForEvent(10,event) && (event.iType != EContactDbObserverEventContactAdded || event.iContactId != contactId)) { } iTestContactId = contactId; return contactId; }
void CGroupViewTester::CreateGroupTestDataL() { TInt loop; iGroupOne = STATIC_CAST(CContactGroup*,iDb.CreateContactGroupL(KGroupOneName)); for (loop = 1;loop <= KNumContactsInGroupOne;++loop) { iDb.AddContactToGroupL(loop,iGroupOne->Id()); } iGroupOneId = iGroupOne->Id(); delete iGroupOne; iGroupOne = NULL; iGroupOne = STATIC_CAST(CContactGroup*,iDb.ReadContactL(iGroupOneId)); iIdsInGroupViewOne = iGroupOne->ItemsContainedLC(); CleanupStack::Pop();//iIdsInGroupViewOne:( // consume any outstanding database events before creating // the views to stop these events later being sent to them. CContactDbEventQueue* dbEventQueue = CContactDbEventQueue::NewL(&iDb, KNumMaxEventRequests); TContactDbObserverEvent dbEvent; TBool expectingEvent = ETrue; const TInt KTimeOutInSeconds = 5; for(loop = 0; expectingEvent; ++loop) { expectingEvent = dbEventQueue->ListenForEvent(KTimeOutInSeconds, dbEvent); if (expectingEvent) // meaning if we've just received one { test.Printf(_L("Consumed db event #%d: %d\n"), loop, dbEvent.iType); } } delete dbEventQueue; }
void CTestConductor::AddContactsL() { iTotalContacts = 0; TInt loop; for (loop = 0;loop < KNumContacts; ++loop) { iRandomGenerator->AddTypicalRandomContactL(); ++iTotalContacts; test.Printf(_L("Adding %d "),loop); } // consume any outstanding database events before creating // the views to stop these events later being sent to them. CContactDbEventQueue* dbEventQueue = CContactDbEventQueue::NewL(iDb, KNumMaxEventRequests); TContactDbObserverEvent dbEvent; TBool expectingEvent = ETrue; const TInt KTimeOutInSeconds = 5; for(loop = 0; expectingEvent; ++loop) { expectingEvent = dbEventQueue->ListenForEvent(KTimeOutInSeconds, dbEvent); if (expectingEvent) // meaning if we've just received one { test.Printf(_L("Consumed db event #%d: %d\n"), loop, dbEvent.iType); } } delete dbEventQueue; }
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); } } }