|
|
@ -36,6 +36,7 @@ private slots: |
|
|
|
void testIsNewDb(); |
|
|
|
void testIsNewDb(); |
|
|
|
void test0to1(); |
|
|
|
void test0to1(); |
|
|
|
void test1to2(); |
|
|
|
void test1to2(); |
|
|
|
|
|
|
|
void test2to3(); |
|
|
|
void cleanupTestCase(); |
|
|
|
void cleanupTestCase(); |
|
|
|
private: |
|
|
|
private: |
|
|
|
bool initSucess{false}; |
|
|
|
bool initSucess{false}; |
|
|
@ -48,7 +49,8 @@ const QString testFileList[] = { |
|
|
|
"testIsNewDbTrue.db", |
|
|
|
"testIsNewDbTrue.db", |
|
|
|
"testIsNewDbFalse.db", |
|
|
|
"testIsNewDbFalse.db", |
|
|
|
"test0to1.db", |
|
|
|
"test0to1.db", |
|
|
|
"test1to2.db" |
|
|
|
"test1to2.db", |
|
|
|
|
|
|
|
"test2to3.db" |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const QMap<QString, QString> schema0 { |
|
|
|
const QMap<QString, QString> schema0 { |
|
|
@ -77,6 +79,9 @@ const QMap<QString, QString> schema2 { |
|
|
|
{"broken_messages", "CREATE TABLE broken_messages (id INTEGER PRIMARY KEY)"} |
|
|
|
{"broken_messages", "CREATE TABLE broken_messages (id INTEGER PRIMARY KEY)"} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// move stuck 0-length action messages to the existing "broken_messages" table. Not a real schema upgrade.
|
|
|
|
|
|
|
|
const auto schema3 = schema2; |
|
|
|
|
|
|
|
|
|
|
|
void TestDbSchema::initTestCase() |
|
|
|
void TestDbSchema::initTestCase() |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (const auto& path : testFileList) { |
|
|
|
for (const auto& path : testFileList) { |
|
|
@ -127,7 +132,7 @@ void TestDbSchema::testCreation() |
|
|
|
QVector<RawDatabase::Query> queries; |
|
|
|
QVector<RawDatabase::Query> queries; |
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{"testCreation.db", {}, {}}}; |
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{"testCreation.db", {}, {}}}; |
|
|
|
QVERIFY(createCurrentSchema(*db)); |
|
|
|
QVERIFY(createCurrentSchema(*db)); |
|
|
|
verifyDb(db, schema2); |
|
|
|
verifyDb(db, schema3); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TestDbSchema::testIsNewDb() |
|
|
|
void TestDbSchema::testIsNewDb() |
|
|
@ -247,5 +252,67 @@ void TestDbSchema::test1to2() |
|
|
|
QVERIFY(totalHisoryCount == 6); // all messages should still be in history.
|
|
|
|
QVERIFY(totalHisoryCount == 6); // all messages should still be in history.
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TestDbSchema::test2to3() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto db = std::shared_ptr<RawDatabase>{new RawDatabase{"test2to3.db", {}, {}}}; |
|
|
|
|
|
|
|
createSchemaAtVersion(db, schema2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// since we don't enforce foreign key contraints in the db, we can stick in IDs to other tables
|
|
|
|
|
|
|
|
// to avoid generating proper entries for peers and aliases tables, since they aren't actually
|
|
|
|
|
|
|
|
// relevant for the test.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QVector<RawDatabase::Query> queries; |
|
|
|
|
|
|
|
// pending message, should be moved out
|
|
|
|
|
|
|
|
queries += RawDatabase::Query{ |
|
|
|
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (1, 1, 0, ?, 0)", |
|
|
|
|
|
|
|
{"/me "}}; |
|
|
|
|
|
|
|
queries += {"INSERT INTO faux_offline_pending (id) VALUES (" |
|
|
|
|
|
|
|
" last_insert_rowid()" |
|
|
|
|
|
|
|
");"}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// non pending message with the content "/me ". Maybe it was sent by a friend using a different client.
|
|
|
|
|
|
|
|
queries += RawDatabase::Query{ |
|
|
|
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (2, 2, 0, ?, 2)", |
|
|
|
|
|
|
|
{"/me "}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// non pending message sent by us
|
|
|
|
|
|
|
|
queries += RawDatabase::Query{ |
|
|
|
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (3, 3, 0, ?, 1)", |
|
|
|
|
|
|
|
{"a normal message"}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// pending normal message sent by us
|
|
|
|
|
|
|
|
queries += RawDatabase::Query{ |
|
|
|
|
|
|
|
"INSERT INTO history (id, timestamp, chat_id, message, sender_alias) VALUES (4, 3, 0, ?, 1)", |
|
|
|
|
|
|
|
{"a normal faux offline message"}}; |
|
|
|
|
|
|
|
queries += {"INSERT INTO faux_offline_pending (id) VALUES (" |
|
|
|
|
|
|
|
" last_insert_rowid()" |
|
|
|
|
|
|
|
");"}; |
|
|
|
|
|
|
|
QVERIFY(db->execNow(queries)); |
|
|
|
|
|
|
|
QVERIFY(dbSchema2to3(*db)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long brokenCount = -1; |
|
|
|
|
|
|
|
RawDatabase::Query brokenCountQuery = {"SELECT COUNT(*) FROM broken_messages;", [&](const QVector<QVariant>& row) { |
|
|
|
|
|
|
|
brokenCount = row[0].toLongLong(); |
|
|
|
|
|
|
|
}}; |
|
|
|
|
|
|
|
QVERIFY(db->execNow(brokenCountQuery)); |
|
|
|
|
|
|
|
QVERIFY(brokenCount == 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int fauxOfflineCount = -1; |
|
|
|
|
|
|
|
RawDatabase::Query fauxOfflineCountQuery = {"SELECT COUNT(*) FROM faux_offline_pending;", [&](const QVector<QVariant>& row) { |
|
|
|
|
|
|
|
fauxOfflineCount = row[0].toLongLong(); |
|
|
|
|
|
|
|
}}; |
|
|
|
|
|
|
|
QVERIFY(db->execNow(fauxOfflineCountQuery)); |
|
|
|
|
|
|
|
QVERIFY(fauxOfflineCount == 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int totalHisoryCount = -1; |
|
|
|
|
|
|
|
RawDatabase::Query totalHistoryCountQuery = {"SELECT COUNT(*) FROM history;", [&](const QVector<QVariant>& row) { |
|
|
|
|
|
|
|
totalHisoryCount = row[0].toLongLong(); |
|
|
|
|
|
|
|
}}; |
|
|
|
|
|
|
|
QVERIFY(db->execNow(totalHistoryCountQuery)); |
|
|
|
|
|
|
|
QVERIFY(totalHisoryCount == 4); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verifyDb(db, schema3); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestDbSchema) |
|
|
|
QTEST_GUILESS_MAIN(TestDbSchema) |
|
|
|
#include "dbschema_test.moc" |
|
|
|
#include "dbschema_test.moc" |
|
|
|