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()); }
void CallModelTest::deleteAllCalls() { CallModel model; watcher.setModel(&model); model.setQueryMode(EventModel::SyncQuery); QDateTime when = QDateTime::currentDateTime(); addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs( 54 ), REMOTEUID1 ); QVERIFY(watcher.waitForAdded()); QVERIFY(model.getEvents()); QVERIFY(model.rowCount() > 0); QSignalSpy eventsCommitted(&model, SIGNAL(eventsCommitted(const QList<CommHistory::Event>&, bool))); QVERIFY(model.deleteAll()); waitSignal(eventsCommitted); QCOMPARE(model.rowCount(), 0); QVERIFY(model.getEvents()); QCOMPARE(model.rowCount(), 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::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::testAddEvent() { CallModel model; watcher.setModel(&model); model.setQueryMode( EventModel::SyncQuery ); /* by contact: * ----------- * user1, missed (2) */ testGetEvents( CallModel::SortByContact, 1, testCalls ); /* by time: * -------- * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); // add 1 dialed from user1 QDateTime when = QDateTime::currentDateTime(); addTestEvent( model, Event::CallEvent, Event::Outbound, ACCOUNT1, -1, "", false, false, when.addSecs( 40 ), REMOTEUID1 ); testCalls.insert( 0, TestCallItem( REMOTEUID1, CallEvent::DialedCallType, 1 ) ); QVERIFY(watcher.waitForAdded()); /* by contact: * ----------- * user1, dialed (-1) */ testGetEvents( CallModel::SortByContact, 1, testCalls ); /* by time: * -------- * user1, dialed (1) * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); // add 5 received from user1 addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs( 45 ), REMOTEUID1 ); addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs( 50 ), REMOTEUID1 ); addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs( 55 ), REMOTEUID1 ); addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs( 60 ), REMOTEUID1 ); addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs( 65 ), REMOTEUID1 ); QVERIFY(watcher.waitForAdded(5)); testCalls.insert( 0, TestCallItem( REMOTEUID1, CallEvent::ReceivedCallType, 5 ) ); /* by contact: * ----------- * user1, received (-1) */ testGetEvents( CallModel::SortByContact, 1, testCalls ); /* by time: * -------- * user1, received (5) * user1, dialed (1) * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); // add 1 missed from user2 addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, true, when.addSecs( 70 ), REMOTEUID2 ); testCalls.insert( 0, TestCallItem( REMOTEUID2, CallEvent::MissedCallType, 1 ) ); QVERIFY(watcher.waitForAdded()); /* by contact: * ----------- * user2, missed (1) * user1, received (0) */ testGetEvents( CallModel::SortByContact, 2, testCalls ); /* by time: * -------- * user2, received (1) * user1, received (5) * user1, dialed (1) * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); // add 1 received from user1 addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs( 75 ), REMOTEUID1 ); testCalls.insert( 0, TestCallItem( REMOTEUID1, CallEvent::ReceivedCallType, 1 ) ); QVERIFY(watcher.waitForAdded()); /* by contact: ***REORDERING * ----------- * user1, received (0) * user2, missed (1) */ testGetEvents( CallModel::SortByContact, 2, testCalls ); /* by time: * -------- * user1, received (1) * user2, missed (1) * user1, received (5) * user1, dialed (1) * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); // add 1 received from user2 addTestEvent( model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs( 80 ), REMOTEUID2 ); testCalls.insert( 0, TestCallItem( REMOTEUID2, CallEvent::ReceivedCallType, 1 ) ); QVERIFY(watcher.waitForAdded()); /* by contact: * ----------- * user2, received (0) * user1, received (0) */ testGetEvents( CallModel::SortByContact, 2, testCalls ); /* by time: * -------- * user2, received (1) * user1, received (1) * user2, missed (1) * user1, received (5) * user1, dialed (1) * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); // add 1 received from hidden number addTestEvent(model, Event::CallEvent, Event::Inbound, ACCOUNT1, -1, "", false, false, when.addSecs(90), "<hidden>"); testCalls.insert(0, TestCallItem("<hidden>", CallEvent::ReceivedCallType, 1)); QVERIFY(watcher.waitForAdded()); /* by contact: * ----------- * "", received (0) * user2, received (0) * user1, received (0) */ testGetEvents( CallModel::SortByContact, 3, testCalls ); /* by time: * -------- * "", received (1) * user2, received (1) * user1, received (1) * user2, missed (1) * user1, received (5) * user1, dialed (1) * user1, missed (2) * user1, dialed (1) * user1, received (2) * user1, missed (1) * user1, dialed (2) */ testGetEvents( CallModel::SortByTime, testCalls.count(), testCalls ); }
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()); } }
void CallModelPerfTest::getEvents() { QFETCH(int, events); QFETCH(int, contacts); QDateTime startTime = QDateTime::currentDateTime(); int commitBatchSize = 75; #ifdef PERF_BATCH_SIZE commitBatchSize = PERF_BATCH_SIZE; #endif EventModel addModel; QDateTime when = QDateTime::currentDateTime(); QList<QString> remoteUids; qDebug() << __FUNCTION__ << "- Creating" << contacts << "new contacts"; int ci = 0; while(ci < contacts) { ci++; QString phoneNumber = QString().setNum(qrand() % 10000000); remoteUids << phoneNumber; addTestContact(QString("Test Contact %1").arg(ci), phoneNumber); if(ci % commitBatchSize == 0 && ci < contacts) { qDebug() << __FUNCTION__ << "- adding" << commitBatchSize << "contacts (" << ci << "/" << contacts << ")"; waitForIdle(5000); } } qDebug() << __FUNCTION__ << "- adding rest of the contacts (" << ci << "/" << contacts << ")"; waitForIdle(5000); QTest::qWait(TIMEOUT); qDebug() << __FUNCTION__ << "- Creating" << events << "new events"; QList<Event> eventList; int ei = 0; while(ei < events) { ei++; Event::EventDirection direction; bool isMissed = false; if(qrand() % 2 > 0) { direction = Event::Inbound; isMissed = (qrand() % 2 > 0); } else { direction = Event::Outbound; } Event e; e.setType(Event::CallEvent); e.setDirection(direction); e.setGroupId(-1); e.setStartTime(when.addSecs(ei)); e.setEndTime(when.addSecs(ei)); e.setLocalUid(ACCOUNT1); e.setRemoteUid(remoteUids.at(qrand() % contacts)); e.setFreeText(""); e.setIsDraft(false); e.setIsMissedCall(isMissed); eventList << e; if(ei % commitBatchSize == 0 && ei != events) { qDebug() << __FUNCTION__ << "- adding" << commitBatchSize << "events (" << ei << "/" << events << ")"; QVERIFY(addModel.addEvents(eventList, false)); eventList.clear(); waitForIdle(); } } QVERIFY(addModel.addEvents(eventList, false)); qDebug() << __FUNCTION__ << "- adding rest of the events (" << ei << "/" << events << ")"; eventList.clear(); waitForIdle(); int iterations = 10; int sum = 0; QList<int> times; #ifdef PERF_ITERATIONS iterations = PERF_ITERATIONS; #endif char *iterVar = getenv("PERF_ITERATIONS"); if (iterVar) { int iters = QString::fromAscii(iterVar).toInt(); if (iters > 0) { iterations = iters; } } QTest::qWait(TIMEOUT); qDebug() << __FUNCTION__ << "- Fetching events." << iterations << "iterations"; for(int i = 0; i < iterations; i++) { CallModel fetchModel; bool result = false; fetchModel.setQueryMode(EventModel::SyncQuery); fetchModel.setFilter(CallModel::SortByContact); QTime time; time.start(); result = fetchModel.getEvents(); int elapsed = time.elapsed(); times << elapsed; sum += elapsed; qDebug("Time elapsed: %d ms", elapsed); QVERIFY(result); QVERIFY(fetchModel.rowCount() > 0); waitForIdle(); } if(logFile) { QTextStream out(logFile); out << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") << ": " << metaObject()->className() << "::" << QTest::currentTestFunction() << "(" << QTest::currentDataTag() << ", " << iterations << " iterations)" << "\n"; for (int i = 0; i < times.size(); i++) { out << times.at(i) << " "; } out << "\n"; } qSort(times); float median = 0.0; if(iterations % 2 > 0) { median = times[(int)(iterations / 2)]; } else { median = (times[iterations / 2] + times[iterations / 2 - 1]) / 2.0f; } float mean = sum / (float)iterations; int testSecs = startTime.secsTo(QDateTime::currentDateTime()); qDebug("##### Mean: %.1f; Median: %.1f; Test time: %dsec", mean, median, testSecs); if(logFile) { QTextStream out(logFile); out << "Median average: " << (int)median << " ms. Test time: "; if (testSecs > 3600) { out << (testSecs / 3600) << "h "; } if (testSecs > 60) { out << ((testSecs % 3600) / 60) << "m "; } out << ((testSecs % 3600) % 60) << "s\n"; } }