Example #1
0
// Make sure that phone numbers resolve to the right contacts even if they
// minimize to the same number.
void CallModelTest::testMinimizedPhone()
{
    QSKIP("Contact matching is not yet supported with SQLite");
    deleteAll();

    const QString phone00("0011112222");
    const QString phone99("9911112222");
    // Precondition for the test:
    QCOMPARE(minimizePhoneNumber(phone00), minimizePhoneNumber(phone99)); // enum { DefaultMaximumPhoneNumberCharacters = 8 }

    const QString user00("User00");
    const QString user99("User99");

    int user00id = addTestContact(user00, phone00, RING_ACCOUNT);
    int user99id = addTestContact(user99, phone99, RING_ACCOUNT);

    CallModel model;
    watcher.setModel(&model);

    QDateTime when = QDateTime::currentDateTime();
    addTestEvent(model, Event::CallEvent, Event::Inbound, RING_ACCOUNT, -1, "", false, false, when, phone00);
    addTestEvent(model, Event::CallEvent, Event::Inbound, RING_ACCOUNT, -1, "", false, false, when.addSecs(10), phone99);
    addTestEvent(model, Event::CallEvent, Event::Inbound, RING_ACCOUNT, -1, "", false, false, when.addSecs(20), phone00);
    QVERIFY(watcher.waitForAdded(3));

    model.setResolveContacts(true);
    QVERIFY(model.getEvents());
    QVERIFY(watcher.waitForModelReady());

    Event e;
    e = model.event(model.index(0, 0));
    QCOMPARE(e.contacts(), QList<ContactDetails>() << qMakePair(user00id, user00));
    QCOMPARE(e.remoteUid(), phone00);

    e = model.event(model.index(1, 0));
    QCOMPARE(e.contacts(), QList<ContactDetails>() << qMakePair(user99id, user99));
    QCOMPARE(e.remoteUid(), phone99);

    e = model.event(model.index(2, 0));
    QCOMPARE(e.contacts(), QList<ContactDetails>() << qMakePair(user00id, user00));
    QCOMPARE(e.remoteUid(), phone00);
}