aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/client/importtest.qml (renamed from tests/client/loadmodel2.qml)21
-rw-r--r--tests/client/loadmodel.qml52
-rw-r--r--tests/client/qmlfiles.h.in7
-rw-r--r--tests/client/qmltest.cpp61
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");
}
};