summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/testpreferences.cpp17
-rw-r--r--tests/testqPrefDisplay.cpp133
-rw-r--r--tests/testqPrefDisplay.h19
-rw-r--r--tests/testqml.cpp9
-rw-r--r--tests/tst_qPrefDisplay.qml31
6 files changed, 192 insertions, 19 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 863e9dd8e..771504794 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -97,6 +97,7 @@ TEST(TestDiveSiteDuplication testdivesiteduplication.cpp)
TEST(TestRenumber testrenumber.cpp)
TEST(TestGitStorage testgitstorage.cpp)
TEST(TestPreferences testpreferences.cpp)
+TEST(TestQPrefDisplay testqPrefDisplay.cpp)
TEST(TestPicture testpicture.cpp)
TEST(TestMerge testmerge.cpp)
TEST(TestTagList testtaglist.cpp)
@@ -112,6 +113,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestGitStorage
TestPlan
TestDiveSiteDuplication
+ TestQPrefDisplay
TestPreferences
TestRenumber
TestPicture
diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index 585044fd0..7a0fa64fd 100644
--- a/tests/testpreferences.cpp
+++ b/tests/testpreferences.cpp
@@ -445,23 +445,6 @@ void TestPreferences::testPreferences()
TEST(general->pscrRatio(), 1);
TEST(general->useDefaultFile(), false);
- auto display = pref->display_settings;
- display->setDivelistFont("comic");
- display->setFontSize(10.0);
- display->setDisplayInvalidDives(true);
-
- TEST(display->divelistFont(),QStringLiteral("comic"));
- TEST(display->fontSize(), 10.0);
- TEST(display->displayInvalidDives(), true);
-
- display->setDivelistFont("helvetica");
- display->setFontSize(14.0);
- display->setDisplayInvalidDives(false);
-
- TEST(display->divelistFont(),QStringLiteral("helvetica"));
- TEST(display->fontSize(), 14.0);
- TEST(display->displayInvalidDives(), false);
-
auto language = pref->language_settings;
language->setLangLocale ("en_US");
language->setLanguage ("en");
diff --git a/tests/testqPrefDisplay.cpp b/tests/testqPrefDisplay.cpp
new file mode 100644
index 000000000..5d510fe21
--- /dev/null
+++ b/tests/testqPrefDisplay.cpp
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "testqPrefDisplay.h"
+
+#include "core/settings/qPrefDisplay.h"
+#include "core/pref.h"
+#include "core/qthelper.h"
+
+#include <QDate>
+
+void TestQPrefDisplay::initTestCase()
+{
+ QCoreApplication::setOrganizationName("Subsurface");
+ QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
+ QCoreApplication::setApplicationName("SubsurfaceTestQPrefDisplay");
+}
+
+void TestQPrefDisplay::test_struct_get()
+{
+ // Test struct pref -> get func.
+
+ auto display = qPrefDisplay::instance();
+
+ prefs.display_invalid_dives = true;
+ prefs.divelist_font = copy_qstring("comic");
+ prefs.font_size = 12.0;
+ prefs.show_developer = false;
+ prefs.theme = copy_qstring("myTheme");
+
+ QCOMPARE(display->display_invalid_dives(), prefs.display_invalid_dives);
+ QCOMPARE(display->divelist_font(), QString(prefs.divelist_font));
+ QCOMPARE(display->font_size(), prefs.font_size);
+ QCOMPARE(display->show_developer(), prefs.show_developer);
+ QCOMPARE(display->theme(), QString(prefs.theme));
+}
+
+void TestQPrefDisplay::test_set_struct()
+{
+ // Test set func -> struct pref
+
+ auto display = qPrefDisplay::instance();
+
+ display->set_display_invalid_dives(true);
+ display->set_divelist_font("comic");
+ display->set_font_size(12.0);
+ display->set_show_developer(false);
+ display->set_theme("myTheme");
+
+ QCOMPARE(prefs.display_invalid_dives, true);
+ QCOMPARE(prefs.divelist_font, "comic");
+ QCOMPARE(prefs.font_size, 12.0);
+ QCOMPARE(prefs.show_developer, false);
+ QCOMPARE(prefs.theme, "myTheme");
+}
+
+void TestQPrefDisplay::test_set_load_struct()
+{
+ // test set func -> load -> struct pref
+
+ auto display = qPrefDisplay::instance();
+
+ display->set_display_invalid_dives(false);
+ display->set_divelist_font("helvitica");
+ display->set_font_size(15.0);
+ display->set_show_developer(true);
+ display->set_theme("myTheme2");
+
+ prefs.display_invalid_dives = true;
+ prefs.divelist_font = copy_qstring("comic");
+ prefs.font_size = 12.0;
+ prefs.show_developer = false;
+ prefs.theme = copy_qstring("myTheme");
+
+ display->load();
+ QCOMPARE(prefs.display_invalid_dives, false);
+ QCOMPARE(prefs.divelist_font, "helvitica");
+ QCOMPARE(prefs.font_size, 15.0);
+ QCOMPARE(prefs.show_developer, true);
+ QCOMPARE(prefs.theme, "myTheme2");
+}
+
+void TestQPrefDisplay::test_struct_disk()
+{
+ // test struct prefs -> disk
+
+ auto display = qPrefDisplay::instance();
+
+ prefs.display_invalid_dives = true;
+ prefs.divelist_font = copy_qstring("helvitica");
+ prefs.font_size = 17.0;
+ prefs.show_developer = false;
+ prefs.theme = copy_qstring("myTheme3");
+
+ display->sync();
+ prefs.display_invalid_dives = false;
+ prefs.divelist_font = copy_qstring("comic");
+ prefs.font_size = 11.0;
+ prefs.show_developer = true;
+ prefs.theme = copy_qstring("myTheme");
+
+ display->load();
+ QCOMPARE(prefs.display_invalid_dives, true);
+ QCOMPARE(prefs.divelist_font, "helvitica");
+ QCOMPARE(prefs.font_size, 17.0);
+ QCOMPARE(prefs.show_developer, false);
+ QCOMPARE(prefs.theme, "myTheme3");
+}
+
+void TestQPrefDisplay::test_multiple()
+{
+ // test multiple instances have the same information
+
+ prefs.display_invalid_dives = false;
+ prefs.divelist_font = copy_qstring("comic");
+ prefs.font_size = 11.0;
+ prefs.show_developer = true;
+ prefs.theme = copy_qstring("myTheme");
+ auto display_direct = new qPrefDisplay;
+
+ prefs.display_invalid_dives = true;
+ prefs.divelist_font = copy_qstring("helvetica");
+ prefs.font_size = 15.0;
+ prefs.show_developer = false;
+ prefs.theme = copy_qstring("myTheme8");
+ auto display = qPrefDisplay::instance();
+
+ QCOMPARE(display->display_invalid_dives(), display_direct->display_invalid_dives());
+ QCOMPARE(display->divelist_font(), display_direct->divelist_font());
+ QCOMPARE(display->font_size(), display_direct->font_size());
+ QCOMPARE(display->show_developer(), display_direct->show_developer());
+ QCOMPARE(display->theme(), display_direct->theme());
+}
+
+QTEST_MAIN(TestQPrefDisplay)
diff --git a/tests/testqPrefDisplay.h b/tests/testqPrefDisplay.h
new file mode 100644
index 000000000..6af2d2be5
--- /dev/null
+++ b/tests/testqPrefDisplay.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TESTQPREFDISPLAY_H
+#define TESTQPREFDISPLAY_H
+
+#include <QtTest>
+
+class TestQPrefDisplay : 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 // TESTQPREFDISPLAY_H
diff --git a/tests/testqml.cpp b/tests/testqml.cpp
index 8ba04da90..0b75d8d48 100644
--- a/tests/testqml.cpp
+++ b/tests/testqml.cpp
@@ -4,6 +4,7 @@
#include <QtTest>
#include <QQmlEngine>
#include <QQmlContext>
+#include <QApplication>
#include "core/settings/qPref.h"
#include "core/qt-gui.h"
@@ -18,8 +19,12 @@ int main(int argc, char **argv)
QTEST_ADD_GPU_BLACKLIST_SUPPORT
QTEST_SET_MAIN_SOURCE_PATH
- // check that qPref exists
- new qPref;
+ // check that qPref classes exists
+ qPref::instance();
+ qPrefDisplay::instance();
+
+ // prepare Qt application
+ new QApplication(argc, argv);
// check that we have a directory
if (argc < 2) {
diff --git a/tests/tst_qPrefDisplay.qml b/tests/tst_qPrefDisplay.qml
new file mode 100644
index 000000000..eafcadee1
--- /dev/null
+++ b/tests/tst_qPrefDisplay.qml
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+import QtQuick 2.6
+import QtTest 1.2
+import org.subsurfacedivelog.mobile 1.0
+
+TestCase {
+ name: "qPref"
+
+ SsrfDisplayPrefs {
+ id: display
+ }
+
+ function test_variables() {
+ var x1 = display.divelist_font
+ display.divelist_font = "helvitica"
+ compare(display.divelist_font, "helvitica")
+ var x2 = display.font_size
+ display.font_size = 12.0
+ compare(display.font_size, 12.0)
+ var x3 = display.display_invalid_dives
+ display.display_invalid_dives = !x3
+ compare(display.display_invalid_dives, !x3)
+ var x4 = display.show_developer
+ display.show_developer = !x4
+ compare(display.show_developer, !x4)
+ var x5 = display.theme
+ display.theme = "myColor"
+ compare(display.theme, "myColor")
+ }
+
+}