aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-14 08:10:35 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-14 08:12:27 -0700
commitcf329ca13100f3b8947c33c8e0a7f4a9cedd5e2b (patch)
treeac321aa1687b73d769abc15b097a191fa15c110e
parent52cc51f9061f578932ede736ed591b36e69b8695 (diff)
parentd7fed0bcb76cc1742f73577b70df048032f70a61 (diff)
downloadsubsurface-cf329ca13100f3b8947c33c8e0a7f4a9cedd5e2b.tar.gz
Merge branch 'qml_test' of https://github.com/janiversen/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--CHANGELOG.md2
-rw-r--r--CMakeLists.txt4
-rw-r--r--subsurface-helper.cpp92
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/CMakeLists.txt14
-rw-r--r--tests/testqml.cpp43
-rw-r--r--tests/tst_qPref.qml17
7 files changed, 126 insertions, 47 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9c1e1f09..d3032bbc8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-
+- tests: add qml test harness
- Dive media: sort thumbnails by timestamp
- Dive media: don't recalculate all pictures on drag & drop
- Profile: immediately update thumbnail positions on deletion
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ce8571c8a..986e5632c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -224,9 +224,9 @@ if(BTSUPPORT)
list(APPEND QT_EXTRA_LIBRARIES Qt5::Bluetooth)
endif()
-find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network Svg Test LinguistTools Positioning Quick Location ${QT_EXTRA_COMPONENTS})
+find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network Svg Test QuickTest LinguistTools Positioning Quick Location ${QT_EXTRA_COMPONENTS})
set(QT_LIBRARIES Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network Qt5::Svg Qt5::Positioning Qt5::Quick Qt5::Location ${QT_EXTRA_LIBRARIES})
-set(QT_TEST_LIBRARIES ${QT_LIBRARIES} Qt5::Test)
+set(QT_TEST_LIBRARIES ${QT_LIBRARIES} Qt5::Test Qt5::QuickTest)
#disable bluetooth if Qt version is ancient.
if (BTSUPPORT AND Qt5Widgets_VERSION VERSION_LESS 5.4.0)
diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp
index b533e7e91..894c8a1b6 100644
--- a/subsurface-helper.cpp
+++ b/subsurface-helper.cpp
@@ -28,6 +28,7 @@
#include "core/pluginmanager.h"
#endif
+#ifndef SUBSURFACE_TEST_DATA
QObject *qqWindowObject = NULL;
void init_ui()
@@ -39,14 +40,14 @@ void init_ui()
MainWindow *window = new MainWindow();
window->setTitle();
-#endif
+#endif // SUBSURFACE_MOBILE
}
void exit_ui()
{
#ifndef SUBSURFACE_MOBILE
delete MainWindow::instance();
-#endif
+#endif // SUBSURFACE_MOBILE
delete qApp;
free((void *)existing_filename);
}
@@ -57,45 +58,6 @@ double get_screen_dpi()
return mydesk->physicalDpiX();
}
-void register_qml_types()
-{
- int rc;
- rc = qmlRegisterType<qPref>("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register Prefs (class qPref), QML will not work!!";
- rc = qmlRegisterType<qPrefDisplay>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!";
-
-#ifdef SUBSURFACE_MOBILE
- rc = qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!";
- rc = qmlRegisterType<QMLPrefs>("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!";
- rc = qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!";
- rc = qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!";
- rc = qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!";
-#endif
-
- rc = qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!";
- rc = qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!";
- rc = qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!";
-}
-
void run_ui()
{
@@ -115,7 +77,7 @@ void run_ui()
engine.addImportPath(importPath.replace("MacOS", "Frameworks"));
}
qDebug() << "QML import path" << engine.importPathList();
-#endif
+#endif // __APPLE__ not Q_OS_IOS
engine.addImportPath("qrc://imports");
DiveListModel diveListModel;
LOG_STP("run_ui diveListModel started");
@@ -167,11 +129,53 @@ void run_ui()
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
qml_window->setHeight(1200);
qml_window->setWidth(800);
-#endif
+#endif // not Q_OS_ANDROID and not Q_OS_IOS
qml_window->show();
LOG_STP("run_ui running exec");
#else
MainWindow::instance()->show();
-#endif
+#endif // SUBSURFACE_MOBILE
qApp->exec();
}
+#endif // not SUBSURFACE_TEST_DATA
+
+void register_qml_types()
+{
+ int rc;
+ rc = qmlRegisterType<qPref>("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register Prefs (class qPref), QML will not work!!";
+ rc = qmlRegisterType<qPrefDisplay>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!";
+
+#ifndef SUBSURFACE_TEST_DATA
+#ifdef SUBSURFACE_MOBILE
+ rc = qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!";
+ rc = qmlRegisterType<QMLPrefs>("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!";
+ rc = qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!";
+ rc = qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!";
+ rc = qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!";
+#endif // not SUBSURFACE_MOBILE
+
+ rc = qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!";
+ rc = qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!";
+ rc = qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!";
+#endif // not SUBSURFACE_TEST_DATA
+}
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..863e9dd8e 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)
@@ -88,6 +100,7 @@ TEST(TestPreferences testpreferences.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}
@@ -104,6 +117,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestPicture
TestMerge
TestTagList
+ TestQML
)
# useful for debugging CMake issues
diff --git a/tests/testqml.cpp b/tests/testqml.cpp
new file mode 100644
index 000000000..8ba04da90
--- /dev/null
+++ b/tests/testqml.cpp
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <QQmlEngine>
+#include <QtQuickTest>
+#include <QtTest>
+#include <QQmlEngine>
+#include <QQmlContext>
+
+#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 exists
+ new qPref;
+
+ // 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)
+ }
+}