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/qmltest.cpp | 61 +++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) (limited to 'tests/client/qmltest.cpp') 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