/*! * This function will be called before the first testfunction is executed. */ void Ut_NotificationManager::initTestCase() { nm = NotificationManager::instance(); nm->m_Notifications.clear(); nm->m_pMWIListener->disconnect(nm); // Create the contacts we need QContactOnlineAccount qcoa; qcoa.setValue(QContactOnlineAccount__FieldAccountPath, DUT_ACCOUNT_PATH); qcoa.setValue(QContactOnlineAccount::FieldAccountUri, CONTACT_1_REMOTE_ID); QVERIFY(contact1.saveDetail(&qcoa)); QContactName name; name.setPrefix(CONTACT_1_REMOTE_ID); QVERIFY(contact1.saveDetail(&name)); QVERIFY(nm->contactManager()->saveContact(&contact1)); qcoa = QContactOnlineAccount(); qcoa.setValue(QContactOnlineAccount__FieldAccountPath, DUT_ACCOUNT_PATH); qcoa.setValue(QContactOnlineAccount::FieldAccountUri, CONTACT_2_REMOTE_ID); QVERIFY(contact2.saveDetail(&qcoa)); name = QContactName(); name.setPrefix(CONTACT_2_REMOTE_ID); QVERIFY(contact2.saveDetail(&name)); QVERIFY(nm->contactManager()->saveContact(&contact2)); }
int addTestContact(const QString &name, const QString &remoteUid, const QString &localUid) { QString contactUri = QString("<testcontact:%1>").arg(contactNumber++); QContact contact; QContactSyncTarget syncTarget; syncTarget.setSyncTarget(QLatin1String("commhistory-tests")); if (!contact.saveDetail(&syncTarget)) { qWarning() << "Unable to add sync target to contact:" << contactUri; return -1; } if (!localUid.isEmpty() && localUid.indexOf("/ring/tel/") == -1) { // Create a metadata detail to link the contact with the account QContactOriginMetadata metadata; metadata.setGroupId(localUid); metadata.setId(remoteUid); metadata.setEnabled(true); if (!contact.saveDetail(&metadata)) { qWarning() << "Unable to add metadata to contact:" << contactUri; return false; } } QString normal = CommHistory::normalizePhoneNumber(remoteUid); if (normal.isEmpty()) { QContactOnlineAccount qcoa; qcoa.setValue(QContactOnlineAccount__FieldAccountPath, localUid); qcoa.setAccountUri(remoteUid); if (!contact.saveDetail(&qcoa)) { qWarning() << "Unable to add online account to contact:" << contactUri; return -1; } } else { QContactPhoneNumber phoneNumberDetail; phoneNumberDetail.setNumber(remoteUid); if (!contact.saveDetail(&phoneNumberDetail)) { qWarning() << "Unable to add phone number to contact:" << contactUri; return -1; } } QContactName nameDetail; nameDetail.setLastName(name); if (!contact.saveDetail(&nameDetail)) { qWarning() << "Unable to add name to contact:" << contactUri; return -1; } if (!manager()->saveContact(&contact)) { qWarning() << "Unable to store contact:" << contactUri; return -1; } // We should return the aggregated instance of this contact QContactRelationshipFilter filter; filter.setRelatedContactRole(QContactRelationship::Second); #ifdef USING_QTPIM filter.setRelatedContact(contact); filter.setRelationshipType(QContactRelationship::Aggregates()); #else filter.setRelatedContactId(contact.id()); filter.setRelationshipType(QContactRelationship::Aggregates); #endif foreach (const ContactListener::ApiContactIdType &id, manager()->contactIds(filter)) { qDebug() << "********** contact id" << id; addedContactIds.insert(id); return ContactListener::internalContactId(id); }