43
43
void testMatchExistingContact();
44
44
void testContactAdded();
45
45
void testContactRemoved();
46
void testSynchronousContactInfoRequest();
47
void testWatchIdentifier();
50
QContact createContact(const QString &firstName, const QString &lastName, const QStringList &phoneNumbers = QStringList(), const QStringList &extendedDetails = QStringList());
48
53
QContactManager *mContactManager;
57
62
ContactMatcher::instance(mContactManager);
59
64
// create two contacts to test
60
QContactPhoneNumber phoneNumber;
61
phoneNumber.setNumber("123456789");
62
QVERIFY(mPhoneContact.saveDetail(&phoneNumber));
63
QContactPhoneNumber phoneNumber2;
64
phoneNumber2.setNumber("7654321");
65
QVERIFY(mPhoneContact.saveDetail(&phoneNumber2));
67
name.setFirstName("Phone");
68
name.setLastName("Contact");
69
QVERIFY(mPhoneContact.saveDetail(&name));
70
QVERIFY(mContactManager->saveContact(&mPhoneContact));
72
QContactExtendedDetail extendedDetail;
73
extendedDetail.setName("x-mock-im");
74
extendedDetail.setData("123456789");
75
QVERIFY(mExtendedContact.saveDetail(&extendedDetail));
76
name.setFirstName("Extended");
77
name.setLastName("Generic Contact");
78
QVERIFY(mExtendedContact.saveDetail(&name));
79
QVERIFY(mContactManager->saveContact(&mExtendedContact));
65
mPhoneContact = createContact("Phone", "Contact", QStringList() << "123456789" << "7654321");
66
mExtendedContact = createContact("Extended", "Generic Contact", QStringList(), QStringList() << "123456789");
82
69
void ContactMatcherTest::init()
140
127
QVERIFY(!info.contains(History::FieldContactId));
142
129
// now add a contact that matches this item
144
QContactPhoneNumber phoneNumber;
145
phoneNumber.setNumber(identifier);
146
QVERIFY(contact.saveDetail(&phoneNumber));
147
QVERIFY(mContactManager->saveContact(&contact));
130
QContact contact = createContact("Added", "Contact", QStringList() << identifier);
149
131
QTRY_COMPARE(contactInfoSpy.count(), 1);
150
132
QCOMPARE(contactInfoSpy.first()[0].toString(), accountId);
151
133
QCOMPARE(contactInfoSpy.first()[1].toString(), identifier);
161
143
QCOMPARE(info[History::FieldIdentifier].toString(), identifier);
163
145
// now add a contact that matches this item
165
QContactPhoneNumber phoneNumber;
166
phoneNumber.setNumber(identifier);
167
QVERIFY(contact.saveDetail(&phoneNumber));
168
QVERIFY(mContactManager->saveContact(&contact));
146
QContact contact = createContact("Removed", "Contact", QStringList() << identifier);
169
147
QTRY_COMPARE(contactInfoSpy.count(), 1);
171
149
// now that the contact info is filled, remove the contact
177
155
QVERIFY(!contactInfoSpy.first()[2].toMap().contains(History::FieldContactId));
158
void ContactMatcherTest::testSynchronousContactInfoRequest()
160
QString identifier("77777777");
161
QString accountId("mock/ofono/account0");
163
// now add a contact that matches this item
164
QContact contact = createContact("Synchronous", "Contact", QStringList() << identifier);
166
// now that the contact info is filled, remove the contact
167
QVariantMap info = ContactMatcher::instance()->contactInfo(accountId, identifier, true);
168
QCOMPARE(info[History::FieldIdentifier].toString(), identifier);
169
QCOMPARE(info[History::FieldAccountId].toString(), accountId);
170
QVERIFY(!info[History::FieldContactId].toString().isEmpty());
172
// and remove this contact to not interfere in the other tests
173
QVERIFY(mContactManager->removeContact(contact.id()));
176
void ContactMatcherTest::testWatchIdentifier()
178
QString identifier("88888888");
179
QString accountId("mock/ofono/account0");
181
ContactMatcher::instance()->watchIdentifier(accountId, identifier);
183
// now add a contact and make sure we get the contactInfoChanged signal
184
QSignalSpy contactInfoSpy(ContactMatcher::instance(), SIGNAL(contactInfoChanged(QString,QString,QVariantMap)));
185
QContact contact = createContact("Contact", "Watched", QStringList() << identifier);
186
QTRY_COMPARE(contactInfoSpy.count(), 1);
187
QCOMPARE(contactInfoSpy.first()[0].toString(), accountId);
188
QCOMPARE(contactInfoSpy.first()[1].toString(), identifier);
189
QVariantMap info = contactInfoSpy.first()[2].toMap();
190
QCOMPARE(info[History::FieldContactId].toString(), contact.id().toString());
192
QVERIFY(mContactManager->removeContact(contact.id()));
195
QContact ContactMatcherTest::createContact(const QString &firstName, const QString &lastName, const QStringList &phoneNumbers, const QStringList &extendedDetails)
200
name.setFirstName(firstName);
201
name.setLastName(lastName);
203
if (!contact.saveDetail(&name)) {
207
Q_FOREACH(const QString &number, phoneNumbers) {
208
QContactPhoneNumber phoneNumber;
209
phoneNumber.setNumber(number);
210
if (!contact.saveDetail(&phoneNumber)) {
215
Q_FOREACH(const QString &extended, extendedDetails) {
216
QContactExtendedDetail extendedDetail;
217
extendedDetail.setName("x-mock-im");
218
extendedDetail.setData(extended);
219
if (!contact.saveDetail(&extendedDetail)) {
224
mContactManager->saveContact(&contact);
180
228
QTEST_MAIN(ContactMatcherTest)
181
229
#include "ContactMatcherTest.moc"