aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/ayatanaqmlmenumodel.qml2
-rw-r--r--examples/render-menumodel.qml3
-rw-r--r--libqmenumodel/QMenuModel/plugin.cpp2
-rw-r--r--libqmenumodel/src/ayatanamenumodel.cpp2
-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
8 files changed, 27 insertions, 123 deletions
diff --git a/examples/ayatanaqmlmenumodel.qml b/examples/ayatanaqmlmenumodel.qml
index 00984f0..fd110cc 100644
--- a/examples/ayatanaqmlmenumodel.qml
+++ b/examples/ayatanaqmlmenumodel.qml
@@ -17,7 +17,7 @@
*/
import QtQuick 2.0
-import QMenuModel 0.1
+import QMenuModel 1.0
Item {
width: 400;
diff --git a/examples/render-menumodel.qml b/examples/render-menumodel.qml
index 5458eeb..3c4309c 100644
--- a/examples/render-menumodel.qml
+++ b/examples/render-menumodel.qml
@@ -22,7 +22,7 @@
// /org/ayatana/testmenu.
import QtQuick 2.0
-import QMenuModel 0.1
+import QMenuModel 1.0
Item {
id: container
@@ -162,4 +162,3 @@ Item {
Component.onCompleted: menuModel.start()
}
-
diff --git a/libqmenumodel/QMenuModel/plugin.cpp b/libqmenumodel/QMenuModel/plugin.cpp
index 503827a..f8d6c0b 100644
--- a/libqmenumodel/QMenuModel/plugin.cpp
+++ b/libqmenumodel/QMenuModel/plugin.cpp
@@ -44,6 +44,6 @@ void QMenuModelQmlPlugin::registerTypes(const char *uri)
qmlRegisterType<QDBusMenuModel>(uri, 1, 0, "QDBusMenuModel");
qmlRegisterType<QDBusActionGroup>(uri, 1, 0, "QDBusActionGroup");
- qmlRegisterType<AyatanaMenuModel>(uri, 1, 0, "AyatanaMenuAction");
+ qmlRegisterType<AyatanaMenuModel>(uri, 1, 0, "AyatanaMenuModel");
qmlRegisterType<AyatanaMenuAction>(uri, 1, 0, "AyatanaMenuAction");
}
diff --git a/libqmenumodel/src/ayatanamenumodel.cpp b/libqmenumodel/src/ayatanamenumodel.cpp
index f535e5c..2c735e6 100644
--- a/libqmenumodel/src/ayatanamenumodel.cpp
+++ b/libqmenumodel/src/ayatanamenumodel.cpp
@@ -682,7 +682,7 @@ bool AyatanaMenuModel::loadExtendedAttributes(int position, const QVariantMap &s
extendedAttrs->insert(qtify_name (name.toUtf8()), qvalue);
else
qCWarning(ayatanamenumodel, "loadExtendedAttributes: key '%s' is of type '%s' (expected '%s')",
- name.toUtf8().constData(), g_variant_get_type_string(value), type.constData());
+ name.toUtf8().constData(), g_variant_get_type_string(value), type.toUtf8().constData());
g_variant_unref (value);
}
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");
}
};