summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/testqPrefUpdateManager.cpp123
-rw-r--r--tests/testqPrefUpdateManager.h19
3 files changed, 144 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 19dba2862..bfda4383d 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -109,6 +109,7 @@ TEST(TestQPrefDivePlanner testqPrefDivePlanner.cpp)
TEST(TestQPrefFacebook testqPrefFacebook.cpp)
TEST(TestQPrefProxy testqPrefProxy.cpp)
TEST(TestQPrefUnits testqPrefUnits.cpp)
+TEST(TestQPrefUpdateManager testqPrefUpdateManager.cpp)
add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> ${SUBSURFACE_SOURCE}/tests)
@@ -135,6 +136,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestQPrefFacebook
TestQPrefProxy
TestQPrefUnits
+ TestQPrefUpdateManager
TestQML
)
diff --git a/tests/testqPrefUpdateManager.cpp b/tests/testqPrefUpdateManager.cpp
new file mode 100644
index 000000000..63757eaab
--- /dev/null
+++ b/tests/testqPrefUpdateManager.cpp
@@ -0,0 +1,123 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "testqPrefUpdateManager.h"
+
+#include "core/pref.h"
+#include "core/qthelper.h"
+#include "core/settings/qPref.h"
+
+#include <QTest>
+
+void TestQPrefUpdateManager::initTestCase()
+{
+ QCoreApplication::setOrganizationName("Subsurface");
+ QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
+ QCoreApplication::setApplicationName("SubsurfaceTestQPrefUpdateManager");
+}
+
+void TestQPrefUpdateManager::test_struct_get()
+{
+ // Test struct pref -> get func.
+
+ auto tst = qPrefUpdateManager::instance();
+
+ prefs.update_manager.dont_check_for_updates = true;
+ prefs.update_manager.dont_check_exists = true;
+ prefs.update_manager.last_version_used = copy_qstring("last_version");
+ prefs.update_manager.next_check = copy_qstring(QString("11/09/1957"));
+
+ QCOMPARE(tst->dont_check_for_updates(), true);
+ QCOMPARE(tst->dont_check_exists(), true);
+ QCOMPARE(tst->last_version_used(), QString("last_version"));
+ QCOMPARE(tst->next_check(), QDate::fromString("11/09/1957", "dd/MM/yyyy"));
+}
+
+void TestQPrefUpdateManager::test_set_struct()
+{
+ // Test set func -> struct pref
+
+ auto tst = qPrefUpdateManager::instance();
+
+ tst->set_dont_check_for_updates(false);
+ tst->set_dont_check_exists(false);
+ tst->set_last_version_used("last_version2");
+ prefs.update_manager.next_check = copy_qstring(QString("11/09/1957"));
+
+ QCOMPARE(prefs.update_manager.dont_check_for_updates, false);
+ QCOMPARE(prefs.update_manager.dont_check_exists, false);
+ QCOMPARE(QString(prefs.update_manager.last_version_used), QString("last_version2"));
+ QCOMPARE(QDate::fromString(QString(prefs.update_manager.next_check), "dd/MM/yyyy"), QDate::fromString("11/09/1957", "dd/MM/yyyy"));
+}
+
+void TestQPrefUpdateManager::test_set_load_struct()
+{
+ // test set func -> load -> struct pref
+
+ auto tst = qPrefUpdateManager::instance();
+
+ // secure set_ stores on disk
+ prefs.update_manager.dont_check_for_updates = true;
+ prefs.update_manager.dont_check_exists = true;
+ prefs.update_manager.next_check = copy_qstring(QString("value1"));
+
+ tst->set_dont_check_for_updates(false);
+ tst->set_dont_check_exists(false);
+ tst->set_last_version_used("last_version2");
+ tst->set_next_check(QDate::fromString("11/09/1957", "dd/MM/yyyy"));
+
+ prefs.update_manager.dont_check_for_updates = true;
+ prefs.update_manager.dont_check_exists = true;
+ prefs.update_manager.last_version_used = copy_qstring("last_version");
+ prefs.update_manager.next_check = copy_qstring(QString("01/01/2018"));
+
+ tst->load();
+ QCOMPARE(prefs.update_manager.dont_check_for_updates, false);
+ QCOMPARE(QString(prefs.update_manager.last_version_used), QString("last_version2"));
+ QCOMPARE(QDate::fromString(QString(prefs.update_manager.next_check),"dd/MM/yyyy"), QDate::fromString("11/09/1957", "dd/MM/yyyy"));
+
+ // dont_check_exists is NOT stored on disk
+ QCOMPARE(prefs.update_manager.dont_check_exists, true);
+}
+
+void TestQPrefUpdateManager::test_struct_disk()
+{
+ // test struct prefs -> disk
+
+ auto tst = qPrefUpdateManager::instance();
+
+ prefs.update_manager.dont_check_for_updates = true;
+ prefs.update_manager.dont_check_exists = true;
+ prefs.update_manager.last_version_used = copy_qstring("last_version");
+ prefs.update_manager.next_check = copy_qstring("11/09/1957");
+
+ tst->sync();
+ prefs.update_manager.dont_check_for_updates = false;
+ prefs.update_manager.dont_check_exists = false;
+ prefs.update_manager.last_version_used = copy_qstring("");
+ prefs.update_manager.next_check = copy_qstring("01/09/2057");
+
+ tst->load();
+ QCOMPARE(tst->dont_check_for_updates(), true);
+ QCOMPARE(tst->last_version_used(), QString("last_version"));
+ QCOMPARE(tst->next_check(), QDate::fromString("11/09/1957", "dd/MM/yyyy"));
+
+ // dont_check_exists is NOT stored on disk
+ QCOMPARE(tst->dont_check_exists(), false);
+}
+
+void TestQPrefUpdateManager::test_multiple()
+{
+ // test multiple instances have the same information
+
+ prefs.update_manager.dont_check_for_updates = false;
+ auto tst_direct = new qPrefUpdateManager;
+
+ prefs.update_manager.dont_check_exists = false;
+ auto tst = qPrefUpdateManager::instance();
+
+ QCOMPARE(tst->dont_check_for_updates(), tst_direct->dont_check_for_updates());
+ QCOMPARE(tst->dont_check_for_updates(), false);
+ QCOMPARE(tst->dont_check_exists(), tst_direct->dont_check_exists());
+ QCOMPARE(tst_direct->dont_check_exists(), false);
+}
+
+QTEST_MAIN(TestQPrefUpdateManager)
diff --git a/tests/testqPrefUpdateManager.h b/tests/testqPrefUpdateManager.h
new file mode 100644
index 000000000..6c8f04dbf
--- /dev/null
+++ b/tests/testqPrefUpdateManager.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TESTQPREFUPDATEMANAGER_H
+#define TESTQPREFUPDATEMANAGER_H
+
+#include <QObject>
+
+class TestQPrefUpdateManager : public QObject {
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void test_struct_get();
+ void test_set_struct();
+ void test_set_load_struct();
+ void test_struct_disk();
+ void test_multiple();
+};
+
+#endif // TESTQPREFUPDATEMANAGER_H