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 --- tests/CMakeLists.txt | 13 +++++++++++++ tests/testqml.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/tst_qPref.qml | 17 +++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 tests/testqml.cpp create mode 100644 tests/tst_qPref.qml (limited to 'tests') 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 (limited to 'tests') 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 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(-) (limited to 'tests') 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