summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-09-08 18:18:16 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-11 17:22:58 -0700
commitd5bbfac6a33c30020255a10c82305276d95d5ab6 (patch)
tree8500e021aabce1b2f5f82a58c9b0d4a7ac686b88 /tests
parentd0edc296360e7653a4c8b672cfb136581c4a10f0 (diff)
downloadsubsurface-d5bbfac6a33c30020255a10c82305276d95d5ab6.tar.gz
tests: change testqml to allow direct register of C++ objects
Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/testqml.cpp54
-rw-r--r--tests/testqml.h19
3 files changed, 38 insertions, 37 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 252d0d3d8..b4bdc6610 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -115,7 +115,7 @@ TEST(TestQPrefProxy testqPrefProxy.cpp)
TEST(TestQPrefTechnicalDetails testqPrefTechnicalDetails.cpp)
TEST(TestQPrefUnits testqPrefUnits.cpp)
TEST(TestQPrefUpdateManager testqPrefUpdateManager.cpp)
-add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> ${SUBSURFACE_SOURCE}/tests)
+add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> -input ${SUBSURFACE_SOURCE}/tests)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
diff --git a/tests/testqml.cpp b/tests/testqml.cpp
index 14aa0bf5c..fcea8dfb1 100644
--- a/tests/testqml.cpp
+++ b/tests/testqml.cpp
@@ -1,47 +1,29 @@
// SPDX-License-Identifier: GPL-2.0
-#include <QApplication>
-#include <QQmlContext>
-#include <QQmlEngine>
-#include <QtQuickTest>
-#include <QtTest>
-
-#include "core/qt-gui.h"
+#include "testqml.h"
#include "core/settings/qPref.h"
-// this is the content of QUICK_TEST_MAIN amended with
-// registration of ssrf classes
+#include <QtQuickTest>
+
+// main loosely copied from QUICK_TEST_MAIN_WITH_SETUP macro
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)
+#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
+ return 0;
+#else
QTEST_ADD_GPU_BLACKLIST_SUPPORT
QTEST_SET_MAIN_SOURCE_PATH
+ QMLTestSetup setup;
- // 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 C++ types and classes (but not objects)
qPref::instance()->registerQML(NULL);
- // Run all tst_*.qml files
- return quick_test_main(argc, argv, "TestQML", tst_dir);
-#else
- return 0;
-#endif
+ return quick_test_main_with_setup(argc, argv, "TestQML", nullptr, &setup);
+#endif //QT_VERSION
}
+
+void QMLTestSetup::qmlEngineAvailable(QQmlEngine *engine)
+{
+ // register C++ objects (but not types and classes)
+ qPref::instance()->registerQML(engine);
+};
+
diff --git a/tests/testqml.h b/tests/testqml.h
new file mode 100644
index 000000000..5c4bf0c16
--- /dev/null
+++ b/tests/testqml.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TESTQML_H
+#define TESTQML_H
+#include <QtQuickTest>
+#include <QQmlEngine>
+#include <QQmlContext>
+#include <QObject>
+
+class QMLTestSetup : public QObject {
+ Q_OBJECT
+
+public:
+ QMLTestSetup() {}
+
+public slots:
+ void qmlEngineAvailable(QQmlEngine *engine);
+};
+
+#endif // TESTQML_H