diff options
author | Dalton Durst <dalton@ubports.com> | 2021-12-23 17:30:01 -0600 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2022-02-01 07:56:48 +0100 |
commit | 03a23b0138dd660dcc1fe71f5bfca100016b97f7 (patch) | |
tree | 26d301d9f49c963a9456077d159ac595ba7ef17d | |
parent | fbb94cd8e14c1e8f4342249fb414b466eb60186f (diff) | |
download | qmenumodel-correct-1-0.tar.gz qmenumodel-correct-1-0.tar.bz2 qmenumodel-correct-1-0.zip |
Make the qmltests test imports, at leastcorrect-1-0
The loadmodule.qml and loadmodule2.qml files never actually loaded in
their views but the test case was still passing.
I wasn't able to discern what the tests were actually supposed to do
when they were working. Therefore, I removed the majority of the tests
and just made sure the import for qmenumodel is working.
At least it does *something* now, I guess.
-rw-r--r-- | tests/client/importtest.qml (renamed from tests/client/loadmodel2.qml) | 18 | ||||
-rw-r--r-- | tests/client/loadmodel.qml | 51 | ||||
-rw-r--r-- | tests/client/qmlfiles.h.in | 7 | ||||
-rw-r--r-- | tests/client/qmltest.cpp | 61 |
4 files changed, 22 insertions, 115 deletions
diff --git a/tests/client/loadmodel2.qml b/tests/client/importtest.qml index 5d1f43b..1560bbd 100644 --- a/tests/client/loadmodel2.qml +++ b/tests/client/importtest.qml @@ -1,5 +1,6 @@ /* * Copyright 2012 Canonical Ltd. + * Copyright 2021 UBports Foundation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -15,26 +16,11 @@ * * Authors: * Renato Araujo Oliveira Filho <renato@canonical.com> + * Dalton Durst <dalton@ubports.com> */ import QtQuick 2.0 import QMenuModel 1.0 Item { - width: 100 - height: 100 - - QDBusMenuModel { - id: menuModel - busType: globalBusType - busName: globalBusName - objectPath: globalObjectPath - } - - ListView { - model: menuModel - delegate: Item {} - } - - Component.onCompleted: menuModel.start() } diff --git a/tests/client/loadmodel.qml b/tests/client/loadmodel.qml deleted file mode 100644 index f51a183..0000000 --- a/tests/client/loadmodel.qml +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Renato Araujo Oliveira Filho <renato@canonical.com> - */ - -import QtQuick 2.0 -import QMenuModel 1.0 - -Item { - id: root - width: 100 - height: 100 - - property bool reset: resetModel - - onResetChanged: { - if (reset) { - // destroy the current model and check if it will not crash the QML engine - view.model.destroy(); - } - } - - ListView { - id: view - anchors.fill: parent - delegate: Text { - text: label - } - } - - Component.onCompleted: { - // dynamically create the model to destroy it later - var model = Qt.createQmlObject("import QMenuModel 1.0; QDBusMenuModel { id: menuModel; busType: globalBusType; busName: globalBusName; objectPath: globalObjectPath; }", view, ""); - model.start(); - view.model = model; - } -} diff --git a/tests/client/qmlfiles.h.in b/tests/client/qmlfiles.h.in index 876b78f..631390b 100644 --- a/tests/client/qmlfiles.h.in +++ b/tests/client/qmlfiles.h.in @@ -1,3 +1,4 @@ -const char* QML_BASE_DIR = "@libqmenumodel_BINARY_DIR@"; -const char* LOADMODEL_QML = "@CMAKE_CURRENT_SOURCE_DIR@/loadmodel.qml"; -const char* LOADMODEL2_QML = "@CMAKE_CURRENT_SOURCE_DIR@/loadmodel2.qml"; +#include <QString> + +const QString QML_BASE_DIR = QStringLiteral("@libqmenumodel_BINARY_DIR@"); +const QString IMPORTTEST_QML = QStringLiteral("@CMAKE_CURRENT_SOURCE_DIR@/importtest.qml"); diff --git a/tests/client/qmltest.cpp b/tests/client/qmltest.cpp index 94080df..b47c88e 100644 --- a/tests/client/qmltest.cpp +++ b/tests/client/qmltest.cpp @@ -1,5 +1,6 @@ /* * Copyright 2012 Canonical Ltd. + * Copyright 2021 UBports Foundation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -15,8 +16,11 @@ * * Authors: * Renato Araujo Oliveira Filho <renato@canonical.com> + * Dalton Durst <dalton@ubports.com> */ +#include <memory> + #include <glib-object.h> #include "qdbusmenumodel.h" @@ -27,6 +31,7 @@ #include <QSignalSpy> #include <QtTest> #include <QDebug> +#include <QString> #include <QQmlContext> #include <QQmlEngine> @@ -38,6 +43,13 @@ class QMLTest : public QObject Q_OBJECT private: DBusMenuScript m_script; + std::shared_ptr<QQuickView> loadView(const QString baseDir, const QString fileLocation) + { + std::shared_ptr<QQuickView> view = std::make_shared<QQuickView>(); + view->engine()->addImportPath(baseDir); + view->setSource(QUrl::fromLocalFile(fileLocation)); + return view; + } private Q_SLOTS: void initTestCase() @@ -60,53 +72,12 @@ private Q_SLOTS: } /* - * Test if model is destroyed without crash - */ - void destroyModel() - { - m_script.publishMenu(); - m_script.run(); - QTest::qWait(500); - - QQuickView *view = new QQuickView; - view->engine()->addImportPath(QML_BASE_DIR); - view->engine()->rootContext()->setContextProperty("resetModel", QVariant(false)); - view->engine()->rootContext()->setContextProperty("globalBusType", DBusEnums::SessionBus); - view->engine()->rootContext()->setContextProperty("globalBusName", MENU_SERVICE_NAME); - view->engine()->rootContext()->setContextProperty("globalObjectPath", MENU_OBJECT_PATH); - view->setSource(QUrl::fromLocalFile(LOADMODEL_QML)); - QTest::qWait(500); - view->engine()->rootContext()->setContextProperty("resetModel", true); - QTest::qWait(500); - } - - /* - * Test the menu model disappearing from the bus and reappearing - * while the QML application is running. + * Test if importtest.qml can be loaded successfully */ - void testServiceDisappear() + void importtest() { - m_script.publishMenu(); - m_script.run(); - QTest::qWait(500); - - QQuickView *view = new QQuickView; - view->engine()->addImportPath(QML_BASE_DIR); - view->engine()->rootContext()->setContextProperty("globalBusType", DBusEnums::SessionBus); - view->engine()->rootContext()->setContextProperty("globalBusName", MENU_SERVICE_NAME); - view->engine()->rootContext()->setContextProperty("globalObjectPath", MENU_OBJECT_PATH); - view->setSource(QUrl::fromLocalFile(LOADMODEL2_QML)); - QTest::qWait(500); - - m_script.unpublishMenu(); - QTest::qWait(500); - - m_script.publishMenu(); - m_script.run(); - QTest::qWait(500); - - delete view; - QTest::qWait(1000); + std::shared_ptr<QQuickView> view = loadView(QML_BASE_DIR, IMPORTTEST_QML); + QTRY_VERIFY2((view->status() == QQuickView::Ready), "loadmodel.qml view never became ready"); } }; |