From 6ad92bb63742d9bc6fff421af897a98505cde509 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sun, 8 May 2022 03:35:39 -0700 Subject: [PATCH] test(history): Add unit test for when db is newer than qTox supports --- test/persistence/dbschema_test.cpp | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/persistence/dbschema_test.cpp b/test/persistence/dbschema_test.cpp index f0ddcf826..457d401c2 100644 --- a/test/persistence/dbschema_test.cpp +++ b/test/persistence/dbschema_test.cpp @@ -22,6 +22,7 @@ #include "src/core/toxfile.h" #include "dbutility/dbutility.h" +#include "src/widget/tool/imessageboxmanager.h" #include #include @@ -70,6 +71,51 @@ bool insertFileId(RawDatabase& db, int row, bool valid) , {resumeId}); return db.execNow(upgradeQueries); } + +class MockMessageBoxManager : public IMessageBoxManager +{ +public: + ~MockMessageBoxManager() override = default; + void showInfo(const QString& title, const QString& msg) override { + std::ignore = title; + std::ignore = msg; + } + void showWarning(const QString& title, const QString& msg) override { + std::ignore = title; + std::ignore = msg; + } + void showError(const QString& title, const QString& msg) override { + std::ignore = title; + std::ignore = msg; + ++errorsShown; + } + bool askQuestion(const QString& title, const QString& msg, bool defaultAns = false, + bool warning = true, bool yesno = true) override { + std::ignore = title; + std::ignore = msg; + std::ignore = warning; + std::ignore = yesno; + return defaultAns; + } + bool askQuestion(const QString& title, const QString& msg, const QString& button1, + const QString& button2, bool defaultAns = false, bool warning = true) override { + std::ignore = title; + std::ignore = msg; + std::ignore = button1; + std::ignore = button2; + std::ignore = warning; + return defaultAns; + } + void confirmExecutableOpen(const QFileInfo& file) override { + std::ignore = file; + } + int getErrorsShown() { + return errorsShown; + } +private: + int errorsShown = 0; +}; + } // namespace class TestDbSchema : public QObject @@ -80,6 +126,7 @@ private slots: void cleanup(); void testCreation(); void testIsNewDb(); + void testNewerDb(); void test0to1(); void test1to2(); void test2to3(); @@ -133,6 +180,19 @@ void TestDbSchema::testIsNewDb() QVERIFY(newDb == false); } +void TestDbSchema::testNewerDb() +{ + auto db = std::shared_ptr{new RawDatabase{testDatabaseFile->fileName(), {}, {}}}; + createSchemaAtVersion(db, DbUtility::schema0); + int futureSchemaVersion = 1000000; + db->execNow( + RawDatabase::Query(QStringLiteral("PRAGMA user_version = %1").arg(futureSchemaVersion))); + MockMessageBoxManager messageBoxManager; + bool success = DbUpgrader::dbSchemaUpgrade(db, messageBoxManager); + QVERIFY(success == false); + QVERIFY(messageBoxManager.getErrorsShown() == 1); +} + void TestDbSchema::test0to1() { auto db = std::shared_ptr{new RawDatabase{testDatabaseFile->fileName(), {}, {}}};