diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2022-02-01 07:57:21 +0100 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2022-02-01 07:57:21 +0100 |
commit | 7f5119f81fdfa2cc97df91785dcce4798b0700cf (patch) | |
tree | 26d301d9f49c963a9456077d159ac595ba7ef17d /tests/client | |
parent | cc2c2d9a64b28cd0a73fad3d11f1e3ab2cb5aefa (diff) | |
parent | 03a23b0138dd660dcc1fe71f5bfca100016b97f7 (diff) | |
download | qmenumodel-7f5119f81fdfa2cc97df91785dcce4798b0700cf.tar.gz qmenumodel-7f5119f81fdfa2cc97df91785dcce4798b0700cf.tar.bz2 qmenumodel-7f5119f81fdfa2cc97df91785dcce4798b0700cf.zip |
Merge branch 'correct-1-0'
Attributes GH PR #18: https://github.com/AyatanaIndicators/qmenumodel/pull/18
Diffstat (limited to 'tests/client')
-rw-r--r-- | tests/client/importtest.qml (renamed from tests/client/loadmodel2.qml) | 21 | ||||
-rw-r--r-- | tests/client/loadmodel.qml | 52 | ||||
-rw-r--r-- | tests/client/qmlfiles.h.in | 7 | ||||
-rw-r--r-- | tests/client/qmltest.cpp | 61 |
4 files changed, 23 insertions, 118 deletions
diff --git a/tests/client/loadmodel2.qml b/tests/client/importtest.qml index 4e283bb..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,27 +16,11 @@ * * Authors: * Renato Araujo Oliveira Filho <renato@canonical.com> + * Dalton Durst <dalton@ubports.com> */ import QtQuick 2.0 -import QMenuModel 0.1 +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 fcdb4ba..0000000 --- a/tests/client/loadmodel.qml +++ /dev/null @@ -1,52 +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 0.1 - -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 0.1; 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"); } }; |