void CallModelTest::testLimit()
{
    QSKIP("Query limit not yet supported with SQLite");
    CallModel model;
    model.setQueryMode(EventModel::SyncQuery);
    model.setFilter(CallModel::SortByTime);

    QVERIFY(model.getEvents());
    QVERIFY(model.rowCount() > 1);

    model.setLimit(1);

    QVERIFY(model.getEvents());

    QCOMPARE(model.rowCount(), 1);
    Event e1 = model.event(model.index(0, 0));

    model.setOffset(1);

    QVERIFY(model.getEvents());

    QCOMPARE(model.rowCount(), 1);
    Event e2 = model.event(model.index(0, 0));

    QVERIFY(e1.id() != e2.id());
}
Example #2
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);
}
Example #3
0
int exportCALLS(QTextStream *outputStream)
{
    CallModel callModel;

    callModel.enableContactChanges(false);
    callModel.setQueryMode(EventModel::SyncQuery);
    callModel.setTreeMode(false);
    callModel.setFilter(CallModel::SortByTime);
    if(!callModel.getEvents())
    {
        qCritical() << "Error fetching calls";
        return 0;
    }

    int i;

    qDebug() << "# calls: " << callModel.rowCount();

    for(i = callModel.rowCount() - 1; i >= 0; i--) //we iterate backwards, because the jolla does not like to import the last call first
    {
        Event e = callModel.event(callModel.index(i, 0));
        if(e.type() != Event::CallEvent)
        {
            qDebug() << "Not a call";
        }
        else
        {

            QString direction = e.direction() == Event::Inbound ? "IN" : "OUT";
            QString missed = e.isMissedCall() ? "MISSED" : "OK";
            *outputStream << e.remoteUid() << ";" <<
                direction << ";" << 
                missed << ";" <<
                e.startTime().toString(Qt::ISODate) << ";" <<
                e.endTime().toString(Qt::ISODate) << endl;
        }
    }

    return 1;
}
void CallModelTest::testModifyEvent()
{
    Event e1, e2, e3;

    deleteAll();

    CallModel model;
    watcher.setModel(&model);

    /*
     * user1, received
     * user1, dialed
     * user2, missed
     * user1, received
     * -> displayed as
     * user1, received
     * user2, missed
     */
    QDateTime when = QDateTime::currentDateTime();
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when, REMOTEUID1);
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(1), REMOTEUID2);
    addTestEvent(model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(2), REMOTEUID1);
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs(3), REMOTEUID1);
    QVERIFY(watcher.waitForAdded(6, 4)); // always grouped by contact -> +2

    QVERIFY(model.setFilter(CallModel::SortByContact));
    QVERIFY(model.getEvents());
    QVERIFY(watcher.waitForModelReady());
    QCOMPARE(model.rowCount(), 2);
    e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.remoteUid(), REMOTEUID1);
    QCOMPARE(e1.direction(), Event::Inbound);
    e2 = model.event(model.index(1, 0));
    QCOMPARE(e2.remoteUid(), REMOTEUID2);
    QCOMPARE(e2.direction(), Event::Inbound);

    /*
     * upgrade latest user1 call to video:
     * user1, received, video
     * user1, dialed
     * user2, missed
     */
    e1.setIsVideoCall(true);
    QVERIFY(model.modifyEvent(e1));
    QVERIFY(watcher.waitForUpdated());

    e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.remoteUid(), REMOTEUID1);
    QCOMPARE(e1.direction(), Event::Inbound);
    QCOMPARE(e1.isVideoCall(), true);
    e2 = model.event(model.index(1, 0));
    QCOMPARE(e2.remoteUid(), REMOTEUID1);
    QCOMPARE(e2.direction(), Event::Outbound);
    QCOMPARE(e2.isVideoCall(), false);
    e3 = model.event(model.index(2, 0));
    QCOMPARE(e3.remoteUid(), REMOTEUID2);
    QCOMPARE(e3.direction(), Event::Inbound);
    QCOMPARE(e3.isVideoCall(), false);

    /*
     * downgrade back to audio:
     * user1, received
     * user2, missed
     */
    e1.setIsVideoCall(false);
    QVERIFY(model.modifyEvent(e1));
    QVERIFY(watcher.waitForUpdated());

    e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.remoteUid(), REMOTEUID1);
    QCOMPARE(e1.direction(), Event::Inbound);
    e2 = model.event(model.index(1, 0));
    QCOMPARE(e2.remoteUid(), REMOTEUID2);
    QCOMPARE(e2.direction(), Event::Inbound);
}
void CallModelTest::testSIPAddress()
{
    QSKIP("Contact matching is not yet supported with SQLite");
    deleteAll();

    CallModel model;
    model.setQueryMode(EventModel::SyncQuery);
    watcher.setModel(&model);

    QString account("/org/freedesktop/Telepathy/Account/ring/tel/ring");
    QString contactName("Donkey Kong");
    QString phoneNumber("012345678");
    QString sipAddress("sips:[email protected]");

    QString contactName2("Mario");
    QString sipAddress2("sips:[email protected]");

    QDateTime when = QDateTime::currentDateTime();
    int contactId = addTestContact(contactName, phoneNumber, account);
    QVERIFY(contactId != -1);
    int contactId2 = addTestContact(contactName2, sipAddress2, account);
    QVERIFY(contactId2 != -1);

    // normal phone call
    addTestEvent(model, Event::CallEvent, Event::Outbound, account, -1, "", false, false, when, phoneNumber);
    QVERIFY(watcher.waitForAdded());
    QCOMPARE(model.rowCount(), 1);
    Event e = model.event(model.index(0, 0));
    QCOMPARE(e.remoteUid(), phoneNumber);

    // SIP call to same number, should group with first event
    addTestEvent(model, Event::CallEvent, Event::Outbound, account, -1, "", false, false, when.addSecs(5), sipAddress);
    QVERIFY(watcher.waitForAdded());
    QCOMPARE(model.rowCount(), 1);
    e = model.event(model.index(0, 0));
    QCOMPARE(e.remoteUid(), sipAddress);

    // SIP call to non-numeric address
    addTestEvent(model, Event::CallEvent, Event::Outbound, account, -1, "", false, false, when.addSecs(10), sipAddress2);
    QVERIFY(watcher.waitForAdded());
    QCOMPARE(model.rowCount(), 2);
    e = model.event(model.index(0, 0));
    QCOMPARE(e.remoteUid(), sipAddress2);

    // check contact resolving for call groups
    QVERIFY(model.setFilter(CallModel::SortByContact));
    QVERIFY(model.getEvents());
    QCOMPARE(model.rowCount(), 2);
    e = model.event(model.index(0, 0));
    QCOMPARE(e.remoteUid(), sipAddress2);
    QVERIFY(!e.contacts().isEmpty());
    QCOMPARE(e.contacts().first().first, contactId2);
    QCOMPARE(e.contacts().first().second, contactName2);

    e = model.event(model.index(1, 0));
    QCOMPARE(e.remoteUid(), sipAddress);
    QVERIFY(!e.contacts().isEmpty());
    QCOMPARE(e.contacts().first().first, contactId);
    QCOMPARE(e.contacts().first().second, contactName);

    // check contact resolving when sorting by time
    QVERIFY(model.setFilter(CallModel::SortByTime));
    QVERIFY(model.getEvents());
    QCOMPARE(model.rowCount(), 2);

    e = model.event(model.index(0, 0));
    QCOMPARE(e.remoteUid(), sipAddress2);
    QVERIFY(!e.contacts().isEmpty());
    QCOMPARE(e.contacts().first().first, contactId2);
    QCOMPARE(e.contacts().first().second, contactName2);

    e = model.event(model.index(1, 0));
    QCOMPARE(e.remoteUid(), sipAddress);
    QVERIFY(!e.contacts().isEmpty());
    QCOMPARE(e.contacts().first().first, contactId);
    QCOMPARE(e.contacts().first().second, contactName);

    deleteTestContact(contactId);
    deleteTestContact(contactId2);
}
void CallModelTest::testSortByTimeUpdate()
{
    deleteAll();

    CallModel model;
    watcher.setModel(&model);

    /*
     * user1, missed   (2)
     * (user1, dialed)
     * user1, missed   (1)
     */
    QDateTime when = QDateTime::currentDateTime();
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when, REMOTEUID1);
    addTestEvent(model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(1), REMOTEUID1);
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(2), REMOTEUID1);
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(3), REMOTEUID1);
    QVERIFY(watcher.waitForAdded(4));

    QVERIFY(model.setFilter(CallModel::SortByTime, CallEvent::MissedCallType));
    QVERIFY(model.getEvents());
    QVERIFY(watcher.waitForModelReady());
    QCOMPARE(model.rowCount(), 2);

    Event e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.remoteUid(), REMOTEUID1);
    QVERIFY(e1.isMissedCall());
    QCOMPARE(e1.eventCount(), 2);

    Event e2 = model.event(model.index(1, 0));
    QCOMPARE(e2.remoteUid(), REMOTEUID1);
    QVERIFY(e2.isMissedCall());
    QVERIFY(e2.eventCount() <= 1);

    // add received call, count for top item should reset
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs(4), REMOTEUID1);
    QVERIFY(watcher.waitForAdded());
    e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.eventCount(), 1);

    CallModel model2;
    model2.setQueryMode(EventModel::SyncQuery);
    QVERIFY(model2.getEvents(CallModel::SortByTime, CallEvent::MissedCallType));
    QCOMPARE(model2.rowCount(), 2);
    QVERIFY(model2.event(model2.index(0, 0)).eventCount() <= 1);

    // add missed call, count should remain 1
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(5), REMOTEUID1);
    QVERIFY(watcher.waitForAdded());
    e1 = model.event(model.index(0, 0));
    int firstMissedId = e1.id();
    QCOMPARE(e1.eventCount(), 1);
    QCOMPARE(model2.event(model2.index(0, 0)).eventCount(), 1);

    QVERIFY(model2.getEvents(CallModel::SortByTime, CallEvent::MissedCallType));
    QCOMPARE(model2.rowCount(), 3);
    QCOMPARE(model2.event(model2.index(0, 0)).eventCount(), 1);

    // add another missed call, count should increase
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(6), REMOTEUID1);
    QVERIFY(watcher.waitForAdded());
    e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.eventCount(), 2);
    QCOMPARE(model2.event(model2.index(0, 0)).eventCount(), 2);
    QVERIFY(model2.getEvents(CallModel::SortByTime, CallEvent::MissedCallType));
    QCOMPARE(model2.rowCount(), 3);
    QCOMPARE(model2.event(model.index(0, 0)).eventCount(), 2);

    // mark latest missed call as read, the first should also be marked
    Event e = model.event(model.index(0, 0));
    e.setIsRead(true);
    QVERIFY(model.modifyEvent(e));
    QVERIFY(watcher.waitForUpdated(2));
    QVERIFY(model.databaseIO().getEvent(firstMissedId, e));
    QVERIFY(e.isRead());
}
void CallModelTest::testSortByContactUpdate()
{
    deleteAll();

    CallModel model;
    watcher.setModel(&model);

    /*
     * user1, missed   (2)
     * (user1, dialed)
     * user1, missed   (1)
     */
    QDateTime when = QDateTime::currentDateTime();
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when, REMOTEUID1);
    addTestEvent(model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(1), REMOTEUID1);
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(2), REMOTEUID1);
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(3), REMOTEUID1);
    QVERIFY(watcher.waitForAdded(4));

    QVERIFY(model.setFilter(CallModel::SortByContact));
    QVERIFY(model.getEvents());
    QVERIFY(watcher.waitForModelReady());
    QCOMPARE(model.rowCount(), 1);

    Event e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.remoteUid(), REMOTEUID1);
    QVERIFY(e1.isMissedCall());
    QCOMPARE(e1.eventCount(), 2);

    // add received call
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs(4), REMOTEUID1);
    QVERIFY(watcher.waitForAdded());
    e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.eventCount(), 1);
    QCOMPARE(e1.direction(), Event::Inbound);

    // add call to another contact
    addTestEvent(model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(5), REMOTEUID2);
    QVERIFY(watcher.waitForAdded());
    QCOMPARE(model.rowCount(), 2);
    e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.eventCount(), 1);
    QCOMPARE(e1.direction(), Event::Outbound);
    QCOMPARE(e1.remoteUid(), REMOTEUID2);

    // missed call to first contact, should reorder
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(6), REMOTEUID1);
    QVERIFY(watcher.waitForAdded());
    QCOMPARE(model.rowCount(), 2);
    e1 = model.event(model.index(0, 0));
    int firstMissedId = e1.id();
    QVERIFY(e1.isMissedCall());
    QCOMPARE(e1.remoteUid(), REMOTEUID1);
    QCOMPARE(e1.eventCount(), 1);

    // another missed call, increase event count
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(7), REMOTEUID1);
    QVERIFY(watcher.waitForAdded());
    QCOMPARE(model.rowCount(), 2);
    e1 = model.event(model.index(0, 0));
    QVERIFY(e1.isMissedCall());
    QCOMPARE(e1.remoteUid(), REMOTEUID1);
    QCOMPARE(e1.eventCount(), 2);

    // mark latest missed call as read, the first should also be marked
    Event e = model.event(model.index(0, 0));
    e.setIsRead(true);
    QVERIFY(model.modifyEvent(e));
    QVERIFY(watcher.waitForUpdated(7));
    QVERIFY(model.databaseIO().getEvent(firstMissedId, e));
    QVERIFY(e.isRead());

    // add call to the other contact...
    addTestEvent(model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(10), REMOTEUID2);
    QVERIFY(watcher.waitForAdded());
    QCOMPARE(model.rowCount(), 2);
    e1 = model.event(model.index(0, 0));
    QCOMPARE(e1.eventCount(), 2);
    QCOMPARE(e1.direction(), Event::Outbound);
    QCOMPARE(e1.remoteUid(), REMOTEUID2);

    // ...and a missed call to the first -> move to top and increase event count
    addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(15), REMOTEUID1);
    QVERIFY(watcher.waitForAdded());
    QCOMPARE(model.rowCount(), 2);
    e1 = model.event(model.index(0, 0));
    QVERIFY(e1.isMissedCall());
    QCOMPARE(e1.remoteUid(), REMOTEUID1);
    QCOMPARE(e1.eventCount(), 3);
}
void CallModelTest::testGetEventsTimeTypeFilter()
{
    QFETCH(bool, useThread);

    deleteAll();

    QThread modelThread;

    //initTestCase ==> 3 dialled calls, 2 Received calls, 3 Missed Calls already added
    CallModel model;
    watcher.setModel(&model);
    if (useThread) {
        modelThread.start();
        model.setBackgroundThread(&modelThread);
    }

    QDateTime when = QDateTime::currentDateTime();
    //3 dialled
    addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when );
    addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(5) );
    addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs(10) );
    QVERIFY(watcher.waitForAdded(3));

    //2 received
    addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when );
    addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs(5) );
    QVERIFY(watcher.waitForAdded(2));

    //3 missed
    addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when );
    addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(5) );
    addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs(10) );
    QVERIFY(watcher.waitForAdded(3));

    QDateTime time = when;
    //model.setQueryMode(EventModel::SyncQuery);
    model.setTreeMode(false);
    QVERIFY(model.setFilter(CallModel::SortByTime,  CallEvent::DialedCallType, time));
    QVERIFY(model.getEvents());
    QVERIFY(watcher.waitForModelReady());

    int numEventsRet = model.rowCount();
    QCOMPARE(numEventsRet, 3);
    Event e1 = model.event(model.index(0,0));
    Event e2 = model.event(model.index(1,0));
    Event e3 = model.event(model.index(2,0));
    QVERIFY(e1.isValid());
    QVERIFY(e2.isValid());
    QVERIFY(e3.isValid());
    QVERIFY(e1.direction() == Event::Outbound);
    QVERIFY(e2.direction() == Event::Outbound);
    QVERIFY(e3.direction() == Event::Outbound);

    QVERIFY(model.setFilter(CallModel::SortByTime, CallEvent::MissedCallType, time));
    QVERIFY(watcher.waitForModelReady());
    QVERIFY(model.rowCount() == 3);
    QVERIFY(model.setFilter(CallModel::SortByTime, CallEvent::ReceivedCallType, time));
    qDebug() << time;
    QVERIFY(watcher.waitForModelReady());
    for (int i = 0; i < model.rowCount(); i++) {
        qDebug() << model.event(model.index(i, 0)).toString();
    }
    QVERIFY(model.rowCount() == 2);

    /**
      * testing to check for adding events with wrong filters
      */
    time = when.addSecs(-60*5);
    int numEventsGot = 0;
    //adding one more received but 5 minutes before the set time filter
    addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, time );
    QVERIFY(watcher.waitForAdded());
    QVERIFY(model.rowCount() == 2); //event should not be added to model, so rowCount should remain same for received calls
    //filter is set for received call, try to add missed and dialled calls with correct time filter
    addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when );
    QVERIFY(watcher.waitForAdded());
    numEventsGot = model.rowCount();
    QVERIFY(numEventsGot == 2); //event should not be added to model, so rowCount should remain same which was for received calls
    addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when );
    QVERIFY(watcher.waitForAdded());
    numEventsGot = model.rowCount();
    QVERIFY(numEventsGot  == 2); //event should not be added to model, so rowCount should remain same which was for received calls

    /**
      ** testing to check for getting events after he time when all events addition was complete
      */
    //Trying to get events after 5 minutes after the  first event was added
    time = when.addSecs(60*5);
    QVERIFY(model.setFilter(CallModel::SortByTime, CallEvent::ReceivedCallType, time));
    QVERIFY(watcher.waitForModelReady());
    QVERIFY(model.rowCount() == 0);

    qDebug() << "wait thread";
    modelThread.quit();
    modelThread.wait(3000);
    qDebug() << "done";
}
void CallModelTest::testDeleteEvent()
{
    CallModel model;
    watcher.setModel(&model);

    // force change of sorting to SortByContact
    QVERIFY( model.setFilter( CallModel::SortByContact ) );
    QVERIFY( model.getEvents() );
    QVERIFY(watcher.waitForModelReady());

    /* by contact:
     * -----------
     * "", received (0)
     * user2, received (0)
     * user1, received (0)
     */
    // delete first event from hidden number
    Event e = model.event( model.index( 0, 0 ) );
    QVERIFY( e.isValid() );
    QCOMPARE( e.type(), Event::CallEvent );
    qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount();
    QCOMPARE( e.direction(), Event::Inbound );
    QCOMPARE( e.isMissedCall(), false );
    QCOMPARE( e.remoteUid(), QLatin1String("<hidden>") );
    // delete it
    QVERIFY( model.deleteEvent( e.id() ) );
    QVERIFY( watcher.waitForDeleted() );
    // correct test helper lists to match current situation
    QMutableListIterator<TestCallItem> i(testCalls);
    while (i.hasNext()) {
        i.next();
        if (i.value().remoteUid == QLatin1String("<hidden>"))
            i.remove();
    }
    // test if model contains what we want it does
    testGetEvents( CallModel::SortByContact, 2, testCalls );

    /* by contact:
     * -----------
     * user2, received (0)
     * user1, received (0)
     */
    // delete first group from user2
    e = model.event( model.index( 0, 0 ) );
    QVERIFY( e.isValid() );
    QCOMPARE( e.type(), Event::CallEvent );
    qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount();
    QCOMPARE( e.direction(), Event::Inbound );
    QCOMPARE( e.isMissedCall(), false );
    QCOMPARE( e.remoteUid(), REMOTEUID2 );
    // delete it
    QVERIFY( model.deleteEvent( e.id() ) );
    QVERIFY( watcher.waitForDeleted(2) );
    // correct test helper lists to match current situation
    i = QMutableListIterator<TestCallItem>(testCalls);
    while (i.hasNext()) {
        i.next();
        if (i.value().remoteUid == REMOTEUID2)
            i.remove();
    }
    // test if model contains what we want it does
    testGetEvents( CallModel::SortByContact, 1, testCalls );

    // force change of sorting to SortByTime
    QVERIFY( model.setFilter( CallModel::SortByTime ) );
    QVERIFY(watcher.waitForModelReady());

    /* by time:
     * --------
     * user1, received (6)***
     * user1, dialed   (1)
     * user1, missed   (2)
     * user1, dialed   (1)
     * user1, received (2)
     * user1, missed   (1)
     * user1, dialed   (2)
     *
     *     ||
     *     \/
     *
     * user1, dialed   (1)
     * user1, missed   (2)
     * user1, dialed   (1)
     * user1, received (2)
     * user1, missed   (1)
     * user1, dialed   (2)
     */
    // take the event
    e = model.event( model.index( 0, 0 ) );
    QVERIFY( e.isValid() );
    QCOMPARE( e.type(), Event::CallEvent );
    qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount();
    QCOMPARE( e.direction(), Event::Inbound );
    QCOMPARE( e.isMissedCall(), false );
    // delete it
    QVERIFY( model.deleteEvent( e.id() ) );
    QVERIFY( watcher.waitForDeleted(6) );
    // correct test helper lists to match current situation
    foreach (TestCallItem item, testCalls) {
        qDebug() << item.remoteUid << item.callType << item.eventCount;
    }
    testCalls.takeFirst(); testCalls.takeFirst();
    foreach (TestCallItem item, testCalls) {
        qDebug() << item.remoteUid << item.callType << item.eventCount;
    }
    // test if model contains what we want it does
    testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls );

    /* by time:
     * --------
     * user1, dialed   (1) <---\
     * user1, missed   (2)***   regrouping
     * user1, dialed   (1) <---/
     * user1, received (2)
     * user1, missed   (1)
     * user1, dialed   (2)
     *
     *     ||
     *     \/
     *
     * user1, dialed   (2)
     * user1, received (2)
     * user1, missed   (1)
     * user1, dialed   (2)
     */
    // take the event
    e = model.event( model.index( 1, 0 ) );
    QVERIFY( e.isValid() );
    QCOMPARE( e.type(), Event::CallEvent );
    qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount();
    QCOMPARE( e.direction(), Event::Inbound );
    QCOMPARE( e.isMissedCall(), true );
    // delete it
    QVERIFY( model.deleteEvent( e.id() ) );
    QVERIFY( watcher.waitForDeleted(2) );
    // correct test helper lists to match current situation
    testCalls.takeFirst(); testCalls.takeFirst(); testCalls.first().eventCount = 2;
    // test if model contains what we want it does
    testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls );


    // force change of sorting to SortByContact
    QVERIFY( model.setFilter( CallModel::SortByContact ) );
    QVERIFY(watcher.waitForModelReady());
    /* by contact:
     * -----------
     * user1, dialed (0)***
     *
     *    ||
     *    \/
     *
     * (empty)
     */
    // take the event
    e = model.event( model.index( 0, 0 ) );
    QVERIFY( e.isValid() );
    QCOMPARE( e.type(), Event::CallEvent );
    qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount();
    QCOMPARE( e.direction(), Event::Outbound );
    QCOMPARE( e.isMissedCall(), false );
    // delete it
    QVERIFY( model.deleteEvent( e.id() ) );
    QVERIFY( watcher.waitForDeleted(7) );
    // correct test helper lists to match current situation
    testCalls.clear();
    // test if model contains what we want it does
    testGetEvents( CallModel::SortByContact, 0, testCalls );
}
Example #10
0
void CallModelTest::testGetEvents( CallModel::Sorting sorting, int row_count, QList<TestCallItem> calls )
{
    CallModel model;
    model.setQueryMode(EventModel::SyncQuery);

    qDebug() << __PRETTY_FUNCTION__ << "*** Sorting by " << (int)sorting;
    model.setFilter(  sorting  );
    QVERIFY( model.getEvents() );

    qDebug() << "Top level event(s):" << row_count;
    QCOMPARE( model.rowCount(), row_count );

    QSet<QString> countedUids;
    for ( int i = 0; i < row_count; i++ )
    {
        Event e = model.event( model.index( i, 0 ) );
        qDebug() << "EVENT:" << e.id() << "|" << e.remoteUid() << "|" << e.direction() << "|" << e.isMissedCall() << "|" << e.eventCount();
        QCOMPARE( e.type(), Event::CallEvent );
        QCOMPARE( e.remoteUid(), calls.at( i ).remoteUid );

        bool addressFound = false;
        foreach (QString address, countedUids) {
            if (address == e.remoteUid()) {
                addressFound = true;
                break;
            }
        }

        switch ( calls.at( i ).callType )
        {
            case CallEvent::MissedCallType :
            {
                QCOMPARE( e.direction(), Event::Inbound );
                QCOMPARE( e.isMissedCall(), true );
                if (addressFound)
                    QVERIFY(e.eventCount() <= 1);
                else
                    QCOMPARE( e.eventCount(), calls.at( i ).eventCount );
                break;
            }
            case CallEvent::ReceivedCallType :
            {
                QCOMPARE( e.direction(), Event::Inbound );
                QCOMPARE( e.isMissedCall(), false );
                // received and missed calls have invalid event count if sorted by contact
                if (addressFound)
                    QVERIFY(e.eventCount() <= 1);
                else
                    QCOMPARE( e.eventCount(), sorting == CallModel::SortByContact ? 0 : calls.at( i ).eventCount );
                break;
            }
            case CallEvent::DialedCallType :
            {
                QCOMPARE( e.direction(), Event::Outbound );
                QCOMPARE( e.isMissedCall(), false );
                // received and missed calls have invalid event count if sorted by contact
                if (addressFound)
                    QVERIFY(e.eventCount() <= 1);
                else
                    QCOMPARE( e.eventCount(), sorting == CallModel::SortByContact ? 0 : calls.at( i ).eventCount );
                break;
            }
            default :
            {
                qCritical() << "Unknown call type!";
                return;
            }
        }

        countedUids.insert(e.remoteUid());
    }
}