From 9bf14725a2333ca9535e734e2d6f3d7168a090d4 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Thu, 11 Oct 2012 16:15:17 -0300 Subject: Created unit test for crash during model destruction. --- tests/client/loadmodel2.qml | 22 ++++++++++++++++++++++ tests/client/qmlfiles.h.in | 1 + tests/client/qmltest.cpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tests/client/loadmodel2.qml (limited to 'tests') diff --git a/tests/client/loadmodel2.qml b/tests/client/loadmodel2.qml new file mode 100644 index 0000000..dfe265d --- /dev/null +++ b/tests/client/loadmodel2.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 +import QMenuModel 0.1 + +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 ebb534c..876b78f 100644 --- a/tests/client/qmlfiles.h.in +++ b/tests/client/qmlfiles.h.in @@ -1,2 +1,3 @@ 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"; diff --git a/tests/client/qmltest.cpp b/tests/client/qmltest.cpp index e9db4ac..4e6f288 100644 --- a/tests/client/qmltest.cpp +++ b/tests/client/qmltest.cpp @@ -84,6 +84,35 @@ private Q_SLOTS: QTest::qWait(500); } + /* + * Test the menu model disappearing from the bus and reappearing + * while the QML application is running. + */ + void testServiceDisappear() + { + 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)); + view->show(); + QTest::qWait(500); + + m_script.unpublishMenu(); + QTest::qWait(500); + + m_script.publishMenu(); + m_script.run(); + QTest::qWait(500); + + delete view; + QTest::qWait(1000); + } }; QTEST_MAIN(QMLTest) -- cgit v1.2.3