~ci-train-bot/history-service/history-service-ubuntu-zesty-2629

« back to all changes in this revision

Viewing changes to tests/plugins/sqlite/SqlitePluginTest.cpp

  • Committer: Bileto Bot
  • Author(s): Gustavo Pichorim Boiko
  • Date: 2016-11-30 15:13:58 UTC
  • mfrom: (230.2.23 staging)
  • Revision ID: ci-train-bot@canonical.com-20161130151358-jy3mqj0ir0b6ncxe
Improve group chat support.

Approved by: Roberto Mier Escandón , Tiago Salem Herrmann

Show diffs side-by-side

added added

removed removed

Lines of Context:
249
249
{
250
250
    // clear the database
251
251
    SQLiteDatabase::instance()->reopen();
 
252
    QSqlQuery query(SQLiteDatabase::instance()->database());
252
253
 
253
254
    QVERIFY(mPlugin->beginBatchOperation());
254
 
    mPlugin->createThreadForParticipants("accountOne", History::EventTypeText, QStringList() << "participantOne");
255
 
    mPlugin->createThreadForParticipants("accountTwo", History::EventTypeText, QStringList() << "participantTwo");
256
 
    mPlugin->createThreadForParticipants("accountThree", History::EventTypeText, QStringList() << "participantThree");
 
255
    QVERIFY(query.exec("UPDATE schema_version SET version=123"));
257
256
    QVERIFY(mPlugin->endBatchOperation());
258
257
 
259
258
    // check that the data was actually written
260
 
    QSqlQuery query(SQLiteDatabase::instance()->database());
261
 
    QVERIFY(query.exec("SELECT count(*) FROM threads"));
 
259
    QVERIFY(query.exec("SELECT version FROM schema_version"));
262
260
    QVERIFY(query.next());
263
 
    QCOMPARE(query.value(0).toInt(), 3);
 
261
    QCOMPARE(query.value(0).toInt(), 123);
264
262
}
265
263
 
266
264
void SqlitePluginTest::testRollback()
267
265
{
268
266
    // clear the database
269
267
    SQLiteDatabase::instance()->reopen();
 
268
    QSqlQuery query(SQLiteDatabase::instance()->database());
 
269
    QVERIFY(query.exec("SELECT version FROM schema_version"));
 
270
    QVERIFY(query.next());
 
271
    int version = query.value(0).toInt();
270
272
 
271
273
    QVERIFY(mPlugin->beginBatchOperation());
272
 
    mPlugin->createThreadForParticipants("accountOne", History::EventTypeText, QStringList() << "participantOne");
273
 
    mPlugin->createThreadForParticipants("accountTwo", History::EventTypeText, QStringList() << "participantTwo");
274
 
    mPlugin->createThreadForParticipants("accountThree", History::EventTypeText, QStringList() << "participantThree");
 
274
    QVERIFY(query.exec("UPDATE schema_version SET version=255"));
275
275
    QVERIFY(mPlugin->rollbackBatchOperation());
276
276
 
277
277
    // check that the steps were reverted
278
 
    QSqlQuery query(SQLiteDatabase::instance()->database());
279
 
    QVERIFY(query.exec("SELECT count(*) FROM threads"));
 
278
    QVERIFY(query.exec("SELECT version FROM schema_version"));
280
279
    QVERIFY(query.next());
281
 
    QCOMPARE(query.value(0).toInt(), 0);
 
280
    QCOMPARE(query.value(0).toInt(), version);
282
281
}
283
282
 
284
283
void SqlitePluginTest::testQueryThreads()
319
318
    QTest::newRow("text event with attachments") << History::TextEvent("mmsAccountId", "mmsSender", "mmsEventId", "mmsSender",
320
319
                                                                       QDateTime::currentDateTime(), false, "Hello with attachments",
321
320
                                                                       History::MessageTypeMultiPart, History::MessageStatusDelivered,
322
 
                                                                       QDateTime::currentDateTime(), "The Subject", attachments).properties();
 
321
                                                                       QDateTime::currentDateTime(), "The Subject", History::InformationTypeNone, attachments).properties();
323
322
}
324
323
 
325
324
void SqlitePluginTest::testWriteTextEvent()
406
405
                                            thread[History::FieldEventId].toString(), "theAttachmentId", "text/plain", "/file/path");
407
406
    History::TextEvent textEvent(thread[History::FieldAccountId].toString(), thread[History::FieldThreadId].toString(), "theEventId",
408
407
                                 "theParticipant", QDateTime::currentDateTime(), true, "Hi there!", History::MessageTypeMultiPart,
409
 
                                 History::MessageStatusPending, QDateTime::currentDateTime(), "theSubject",
 
408
                                 History::MessageStatusPending, QDateTime::currentDateTime(), "theSubject", History::InformationTypeNone,
410
409
                                 History::TextEventAttachments() << attachment);
411
410
    QCOMPARE(mPlugin->writeTextEvent(textEvent.properties()), History::EventWriteCreated);
412
411
 
606
605
                                     QString("textEventId%1").arg(QString::number(i)), "textParticipant",
607
606
                                     QDateTime::currentDateTime(), true, "Hello World!", History::MessageTypeMultiPart,
608
607
                                     History::MessageStatusPending, QDateTime::currentDateTime(),
609
 
                                     "theSubject", History::TextEventAttachments() << attachment);
 
608
                                     "theSubject", History::InformationTypeNone, History::TextEventAttachments() << attachment);
610
609
        QCOMPARE(mPlugin->writeTextEvent(textEvent.properties()), History::EventWriteCreated);
611
610
    }
612
611
 
659
658
    QTest::newRow("text event with attachments") << History::TextEvent("mmsAccountId", "mmsSender", "mmsEventId", "mmsSender",
660
659
                                                                       QDateTime::currentDateTime(), false, "Hello with attachments",
661
660
                                                                       History::MessageTypeMultiPart, History::MessageStatusDelivered,
662
 
                                                                       QDateTime::currentDateTime(), "The Subject", attachments).properties();
 
661
                                                                       QDateTime::currentDateTime(), "The Subject", History::InformationTypeNone, attachments).properties();
663
662
    QTest::newRow("missed call") << History::VoiceEvent("theAccountId", "theSenderId", "theEventId", "theSenderId",
664
663
                                                        QDateTime::currentDateTime(), true, true).properties();
665
664
    QTest::newRow("incoming call") << History::VoiceEvent("otherAccountId", "otherSenderId", "otherEventId", "otherSenderId",