From 02c973a4dc7d9980a0ea5a2993cb0ba08cb35857 Mon Sep 17 00:00:00 2001 From: Dalton Durst Date: Thu, 23 Dec 2021 16:20:35 -0600 Subject: Fix versioning in examples and tests --- examples/ayatanaqmlmenumodel.qml | 2 +- examples/render-menumodel.qml | 3 +-- tests/client/loadmodel.qml | 5 ++--- tests/client/loadmodel2.qml | 3 +-- 4 files changed, 5 insertions(+), 8 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/tests/client/loadmodel.qml b/tests/client/loadmodel.qml index fcdb4ba..f51a183 100644 --- a/tests/client/loadmodel.qml +++ b/tests/client/loadmodel.qml @@ -18,7 +18,7 @@ */ import QtQuick 2.0 -import QMenuModel 0.1 +import QMenuModel 1.0 Item { id: root @@ -44,9 +44,8 @@ Item { 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, ""); + 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/loadmodel2.qml b/tests/client/loadmodel2.qml index 4e283bb..5d1f43b 100644 --- a/tests/client/loadmodel2.qml +++ b/tests/client/loadmodel2.qml @@ -18,7 +18,7 @@ */ import QtQuick 2.0 -import QMenuModel 0.1 +import QMenuModel 1.0 Item { width: 100 @@ -38,4 +38,3 @@ Item { Component.onCompleted: menuModel.start() } - -- cgit v1.2.3 From 0333149b68b2d1ea164a96a2b43cfdd3f8f9c945 Mon Sep 17 00:00:00 2001 From: Dalton Durst Date: Thu, 23 Dec 2021 16:23:03 -0600 Subject: Fix naming of AyatanaMenuModel qml type --- libqmenumodel/QMenuModel/plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(uri, 1, 0, "QDBusMenuModel"); qmlRegisterType(uri, 1, 0, "QDBusActionGroup"); - qmlRegisterType(uri, 1, 0, "AyatanaMenuAction"); + qmlRegisterType(uri, 1, 0, "AyatanaMenuModel"); qmlRegisterType(uri, 1, 0, "AyatanaMenuAction"); } -- cgit v1.2.3 From fbb94cd8e14c1e8f4342249fb414b466eb60186f Mon Sep 17 00:00:00 2001 From: Dalton Durst Date: Thu, 23 Dec 2021 16:28:37 -0600 Subject: Fix build warning regarding qchar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The warning was: format ‘%s’ expects argument of type ‘char*’, but argument 5 has type ‘const QChar*’ --- libqmenumodel/src/ayatanamenumodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } -- cgit v1.2.3 From 03a23b0138dd660dcc1fe71f5bfca100016b97f7 Mon Sep 17 00:00:00 2001 From: Dalton Durst Date: Thu, 23 Dec 2021 17:30:01 -0600 Subject: Make the qmltests test imports, at least 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. --- tests/client/importtest.qml | 26 +++++++++++++++++++ tests/client/loadmodel.qml | 51 ------------------------------------- tests/client/loadmodel2.qml | 40 ----------------------------- tests/client/qmlfiles.h.in | 7 +++--- tests/client/qmltest.cpp | 61 ++++++++++++--------------------------------- 5 files changed, 46 insertions(+), 139 deletions(-) create mode 100644 tests/client/importtest.qml delete mode 100644 tests/client/loadmodel.qml delete mode 100644 tests/client/loadmodel2.qml diff --git a/tests/client/importtest.qml b/tests/client/importtest.qml new file mode 100644 index 0000000..1560bbd --- /dev/null +++ b/tests/client/importtest.qml @@ -0,0 +1,26 @@ +/* + * 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 + * 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 . + * + * Authors: + * Renato Araujo Oliveira Filho + * Dalton Durst + */ + +import QtQuick 2.0 +import QMenuModel 1.0 + +Item { +} 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 . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -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/loadmodel2.qml b/tests/client/loadmodel2.qml deleted file mode 100644 index 5d1f43b..0000000 --- a/tests/client/loadmodel2.qml +++ /dev/null @@ -1,40 +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 . - * - * Authors: - * Renato Araujo Oliveira Filho - */ - -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/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 + +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 + * Dalton Durst */ +#include + #include #include "qdbusmenumodel.h" @@ -27,6 +31,7 @@ #include #include #include +#include #include #include @@ -38,6 +43,13 @@ class QMLTest : public QObject Q_OBJECT private: DBusMenuScript m_script; + std::shared_ptr loadView(const QString baseDir, const QString fileLocation) + { + std::shared_ptr view = std::make_shared(); + 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 view = loadView(QML_BASE_DIR, IMPORTTEST_QML); + QTRY_VERIFY2((view->status() == QQuickView::Ready), "loadmodel.qml view never became ready"); } }; -- cgit v1.2.3