250
250
// clear the database
251
251
SQLiteDatabase::instance()->reopen();
252
QSqlQuery query(SQLiteDatabase::instance()->database());
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());
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);
266
264
void SqlitePluginTest::testRollback()
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();
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());
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);
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();
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);
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);
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",