summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/CMakeLists.txt17
-rw-r--r--tests/testpreferences.cpp22
-rw-r--r--tests/testqPrefAnimations.cpp81
-rw-r--r--tests/testqPrefAnimations.h19
-rw-r--r--tests/testqPrefDisplay.cpp133
-rw-r--r--tests/testqPrefDisplay.h19
-rw-r--r--tests/testqml.cpp48
-rw-r--r--tests/tst_qPref.qml17
-rw-r--r--tests/tst_qPrefAnimations.qml19
-rw-r--r--tests/tst_qPrefDisplay.qml31
11 files changed, 385 insertions, 22 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 000000000..86950b3e9
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1 @@
+*.qmlc
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a9c65bd09..0f30bfecb 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -76,6 +76,18 @@ enable_testing()
add_definitions(-g)
add_definitions(-DSUBSURFACE_TEST_DATA="${SUBSURFACE_TEST_DATA}")
+# Build QML test runner
+# add_executable demands relative path, therefore ../
+add_executable(TestQML testqml.cpp ../subsurface-helper.cpp )
+target_link_libraries(
+ TestQML
+ subsurface_corelib
+ RESOURCE_LIBRARY
+ ${QT_TEST_LIBRARIES}
+ ${SUBSURFACE_LINK_LIBRARIES}
+)
+
+# SSRF test cases (TBD, convert to standard qTest setup)
TEST(TestUnitConversion testunitconversion.cpp)
TEST(TestProfile testprofile.cpp)
TEST(TestGpsCoords testgpscoords.cpp)
@@ -85,9 +97,12 @@ TEST(TestDiveSiteDuplication testdivesiteduplication.cpp)
TEST(TestRenumber testrenumber.cpp)
TEST(TestGitStorage testgitstorage.cpp)
TEST(TestPreferences testpreferences.cpp)
+TEST(TestQPrefDisplay testqPrefDisplay.cpp)
+TEST(TestQPrefAnimations testqPrefAnimations.cpp)
TEST(TestPicture testpicture.cpp)
TEST(TestMerge testmerge.cpp)
TEST(TestTagList testtaglist.cpp)
+add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> ${SUBSURFACE_SOURCE}/tests)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
@@ -99,11 +114,13 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestGitStorage
TestPlan
TestDiveSiteDuplication
+ TestQPrefDisplay
TestPreferences
TestRenumber
TestPicture
TestMerge
TestTagList
+ TestQML
)
# useful for debugging CMake issues
diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index 585044fd0..d950c49f9 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");
@@ -499,11 +482,6 @@ void TestPreferences::testPreferences()
TEST(language->dateFormatOverride(),true);
TEST(language->useSystemLanguage(), true);
- pref->animation_settings->setAnimationSpeed(20);
- TEST(pref->animation_settings->animationSpeed(), 20);
- pref->animation_settings->setAnimationSpeed(30);
- TEST(pref->animation_settings->animationSpeed(), 30);
-
auto location = pref->location_settings;
location->setTimeThreshold(10);
location->setDistanceThreshold(20);
diff --git a/tests/testqPrefAnimations.cpp b/tests/testqPrefAnimations.cpp
new file mode 100644
index 000000000..db0e31218
--- /dev/null
+++ b/tests/testqPrefAnimations.cpp
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "testqPrefAnimations.h"
+
+#include "core/settings/qPrefAnimations.h"
+#include "core/pref.h"
+#include "core/qthelper.h"
+
+#include <QDate>
+
+void TestQPrefAnimations::initTestCase()
+{
+ QCoreApplication::setOrganizationName("Subsurface");
+ QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
+ QCoreApplication::setApplicationName("SubsurfaceTestQPrefAnimations");
+}
+
+void TestQPrefAnimations::test_struct_get()
+{
+ // Test struct pref -> get func.
+
+ auto tst = qPrefAnimations::instance();
+
+ prefs.animation_speed = 17;
+
+ QCOMPARE(tst->animation_speed(), prefs.animation_speed);
+}
+
+void TestQPrefAnimations::test_set_struct()
+{
+ // Test set func -> struct pref
+
+ auto tst = qPrefAnimations::instance();
+
+ tst->set_animation_speed(27);
+
+ QCOMPARE(prefs.animation_speed, 27);
+}
+
+void TestQPrefAnimations::test_set_load_struct()
+{
+ // test set func -> load -> struct pref
+
+ auto tst = qPrefAnimations::instance();
+
+ tst->set_animation_speed(33);
+
+ prefs.animation_speed = 17;
+
+ tst->load();
+ QCOMPARE(prefs.animation_speed, 33);
+}
+
+void TestQPrefAnimations::test_struct_disk()
+{
+ // test struct prefs -> disk
+
+ auto tst = qPrefAnimations::instance();
+
+ prefs.animation_speed = 27;
+
+ tst->sync();
+ prefs.animation_speed = 35;
+
+ tst->load();
+ QCOMPARE(prefs.animation_speed, 27);
+}
+
+void TestQPrefAnimations::test_multiple()
+{
+ // test multiple instances have the same information
+
+ prefs.animation_speed = 37;
+ auto tst_direct = new qPrefAnimations;
+
+ prefs.animation_speed = 25;
+ auto tst = qPrefAnimations::instance();
+
+ QCOMPARE(tst->animation_speed(), tst_direct->animation_speed());
+}
+
+QTEST_MAIN(TestQPrefAnimations)
diff --git a/tests/testqPrefAnimations.h b/tests/testqPrefAnimations.h
new file mode 100644
index 000000000..162baf8fd
--- /dev/null
+++ b/tests/testqPrefAnimations.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TESTQPREFANIMATIONS_H
+#define TESTQPREFANIMATIONS_H
+
+#include <QtTest>
+
+class TestQPrefAnimations : 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 // TESTQPREFANIMATIONS_H
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
new file mode 100644
index 000000000..0b75d8d48
--- /dev/null
+++ b/tests/testqml.cpp
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <QQmlEngine>
+#include <QtQuickTest>
+#include <QtTest>
+#include <QQmlEngine>
+#include <QQmlContext>
+#include <QApplication>
+
+#include "core/settings/qPref.h"
+#include "core/qt-gui.h"
+
+// this is the content of QUICK_TEST_MAIN amended with
+// registration of ssrf classes
+int main(int argc, char **argv)
+{
+ // QML testing is not supported in the oldest Qt versions we support
+ // if running with Qt version less than 5.10 then skip test
+#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
+ QTEST_ADD_GPU_BLACKLIST_SUPPORT
+ QTEST_SET_MAIN_SOURCE_PATH
+
+ // 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) {
+ qDebug() << "ERROR: missing tst_* directory";
+ return -1;
+ }
+ // save tst_dir and pass rest to Qt
+ const char *tst_dir = argv[1];
+ for (int i = 1; i < argc; i++)
+ argv[i] = argv[i+1];
+ argc--;
+
+ // Register types
+ register_qml_types();
+
+ // Run all tst_*.qml files
+ return quick_test_main(argc, argv, "TestQML", tst_dir);
+#else
+ return 0;
+#endif
+}
diff --git a/tests/tst_qPref.qml b/tests/tst_qPref.qml
new file mode 100644
index 000000000..99b798423
--- /dev/null
+++ b/tests/tst_qPref.qml
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+import QtQuick 2.6
+import QtTest 1.2
+import org.subsurfacedivelog.mobile 1.0
+
+TestCase {
+ name: "qPref"
+
+ SsrfPrefs {
+ id: prefs
+ }
+
+ function test_register() {
+ var x = prefs.mobile_version
+ compare(x, prefs.mobile_version)
+ }
+}
diff --git a/tests/tst_qPrefAnimations.qml b/tests/tst_qPrefAnimations.qml
new file mode 100644
index 000000000..01e59fa42
--- /dev/null
+++ b/tests/tst_qPrefAnimations.qml
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+import QtQuick 2.6
+import QtTest 1.2
+import org.subsurfacedivelog.mobile 1.0
+
+TestCase {
+ name: "qPrefAnimations"
+
+ SsrfAnimationsPrefs {
+ id: tst
+ }
+
+ function test_variables() {
+ var x1 = tst.animation_speed;
+ tst.animation_speed = 37
+ compare(tst.animation_speed, 37)
+ }
+
+}
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")
+ }
+
+}