From 55f0b3b1f8ac641fc29ffdbb166b9b6947d7eb03 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Sat, 7 Jul 2018 20:55:27 +0200 Subject: ssrf: add QuickTest to test libraries. QuickTest enables QML TestCase which are used for qml testing Signed-off-by: Jan Iversen --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce8571c8a..b1d3632c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,7 +226,7 @@ endif() find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network Svg Test 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) -- cgit v1.2.3-70-g09d2 From b05e4c7b5fb4e858a997086caaeb7dc680394a34 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Sat, 7 Jul 2018 18:55:24 +0200 Subject: tests: make qml test harness build a qml test runner that includes ssrf interface The qml test runner allows having qml test files. Signed-off-by: Jan Iversen --- CHANGELOG.md | 1 + CMakeLists.txt | 2 +- tests/CMakeLists.txt | 13 +++++++++++++ tests/testqml.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/tst_qPref.qml | 17 +++++++++++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 tests/testqml.cpp create mode 100644 tests/tst_qPref.qml diff --git a/CHANGELOG.md b/CHANGELOG.md index 339874373..ef39d73bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- tests: add qml test harness - Cloud storage: fix potential issue with credentials on Linux [#1346] - Mobile/iOS: fix missing translations - Dive media: support addition of videos diff --git a/CMakeLists.txt b/CMakeLists.txt index b1d3632c5..986e5632c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,7 +224,7 @@ 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 Qt5::QuickTest) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a9c65bd09..d0e82e97f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -76,6 +76,17 @@ enable_testing() add_definitions(-g) add_definitions(-DSUBSURFACE_TEST_DATA="${SUBSURFACE_TEST_DATA}") +# Build QML test runner +add_executable(TestQML testqml.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 +99,7 @@ TEST(TestPreferences testpreferences.cpp) TEST(TestPicture testpicture.cpp) TEST(TestMerge testmerge.cpp) TEST(TestTagList testtaglist.cpp) +add_test(NAME TestQML COMMAND $ ${SUBSURFACE_SOURCE}/tests) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} @@ -104,6 +116,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..fe411f0bb --- /dev/null +++ b/tests/testqml.cpp @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include + +#include "core/settings/qPref.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 + auto rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs"); + if (rc < 0) { + qDebug() << "ERROR: cannot register qPref"; + return -1; + } + + 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) + } +} -- cgit v1.2.3-70-g09d2 From 35eecaa82af4f78337ab18a5e43cc04b8459029a Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Thu, 12 Jul 2018 13:01:05 +0200 Subject: tests: add .gitignore to ignore qmlc files With Qt 5.11 the qml compiler is included and qmlc files created in the same directory as the qml file (at least for the qml test harness). ignore *.qmlc Signed-off-by: Jan Iversen --- tests/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/.gitignore diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 000000000..86950b3e9 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +*.qmlc -- cgit v1.2.3-70-g09d2 From f354592050948700f702516d8e3de20977b634fa Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Thu, 12 Jul 2018 18:22:56 +0200 Subject: ssrf: prepare subsurface_helper.cpp to be used by testqml add test for SUBSURFACE_TEST_DATA to exclude functions not used when testing Signed-off-by: Jan Iversen --- subsurface-helper.cpp | 92 +++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index b58f8b4aa..50f975611 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() @@ -38,14 +39,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); } @@ -56,45 +57,6 @@ double get_screen_dpi() return mydesk->physicalDpiX(); } -void register_qml_types() -{ - int rc; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register Prefs (class qPref), QML will not work!!"; - rc = qmlRegisterType("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("org.subsurfacedivelog.mobile", 1, 0, "QMLManager"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile"); - if (rc < 0) - qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel"); - if (rc < 0) - qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!"; -#endif - - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper"); - if (rc < 0) - qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel"); - if (rc < 0) - qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!"; - rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "MapLocation"); - if (rc < 0) - qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!"; -} - void run_ui() { register_qml_types(); @@ -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("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs"); + if (rc < 0) + qDebug() << "ERROR: Cannot register Prefs (class qPref), QML will not work!!"; + rc = qmlRegisterType("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("org.subsurfacedivelog.mobile", 1, 0, "QMLManager"); + if (rc < 0) + qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!"; + rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs"); + if (rc < 0) + qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!"; + rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile"); + if (rc < 0) + qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!"; + rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread"); + if (rc < 0) + qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!"; + rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel"); + if (rc < 0) + qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!"; +#endif // not SUBSURFACE_MOBILE + + rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper"); + if (rc < 0) + qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!"; + rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel"); + if (rc < 0) + qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!"; + rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "MapLocation"); + if (rc < 0) + qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!"; +#endif // not SUBSURFACE_TEST_DATA +} -- cgit v1.2.3-70-g09d2 From d7fed0bcb76cc1742f73577b70df048032f70a61 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Thu, 12 Jul 2018 18:24:38 +0200 Subject: tests: update testqml to use shared register_qml_types() add subsurface-helper.cpp to TestQML target remove local qmlRegisterType() and add register_qml_types() instead Signed-off-by: Jan Iversen --- tests/CMakeLists.txt | 3 ++- tests/testqml.cpp | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d0e82e97f..863e9dd8e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -77,7 +77,8 @@ add_definitions(-g) add_definitions(-DSUBSURFACE_TEST_DATA="${SUBSURFACE_TEST_DATA}") # Build QML test runner -add_executable(TestQML testqml.cpp ) +# add_executable demands relative path, therefore ../ +add_executable(TestQML testqml.cpp ../subsurface-helper.cpp ) target_link_libraries( TestQML subsurface_corelib diff --git a/tests/testqml.cpp b/tests/testqml.cpp index fe411f0bb..8ba04da90 100644 --- a/tests/testqml.cpp +++ b/tests/testqml.cpp @@ -6,7 +6,7 @@ #include #include "core/settings/qPref.h" - +#include "core/qt-gui.h" // this is the content of QUICK_TEST_MAIN amended with // registration of ssrf classes @@ -33,12 +33,9 @@ int main(int argc, char **argv) argc--; // Register types - auto rc = qmlRegisterType("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs"); - if (rc < 0) { - qDebug() << "ERROR: cannot register qPref"; - return -1; - } + register_qml_types(); + // Run all tst_*.qml files return quick_test_main(argc, argv, "TestQML", tst_dir); #else return 0; -- cgit v1.2.3-70-g09d2