on xenial help sign in
Fixed QMenuModel mocking
commit8301d36dcbb825cab4ed392e91a3e8af32ea899f authorNick Dedekind <nicholas.dedekind@gmail.com> dateFri 11 Oct 2013, 18:16 (13 years ago) parent025c8a6
9 files changed+78−14
tests/mocks/QMenuModel/CMakeLists.txt+6−1 tests/mocks/QMenuModel/UnityMenuAction.qml+11 tests/mocks/QMenuModel/UnityMenuModel.qml → tests/mocks/QMenuModel/actionstateparser.cpp+3−10 tests/mocks/QMenuModel/actionstateparser.h+35 tests/mocks/QMenuModel/plugin.cpp+2 tests/mocks/QMenuModel/qmldir+2−1 tests/mocks/QMenuModel/unitymenumodel.h+1−1 tests/qmltests/CMakeLists.txt+2−1 tests/qmltests/Greeter/tst_Clock.qml+16
tests/mocks/QMenuModel/CMakeLists.txt+6−1
@@ -16,14 +16,19 @@ include_directories(
1616)
1717
1818set(QMenuModelQml_SOURCES
19+ actionstateparser.cpp
1920 plugin.cpp
2021 unitymenumodel.cpp
2122)
2223
23−add_library(QMenuModelQml MODULE ${QMenuModelQml_SOURCES})
24+add_library(QMenuModelQml SHARED ${QMenuModelQml_SOURCES})
2425target_link_libraries(QMenuModelQml
2526 ${Qt5Core_LIBRARIES}
2627 ${Qt5Quick_LIBRARIES}
2728)
2829
2930qt5_use_modules(QMenuModelQml Core Quick)
31+
32+set_target_properties(QMenuModelQml PROPERTIES
33+ OUTPUT_NAME qmenumodel
34+ VERSION 0)
tests/mocks/QMenuModel/UnityMenuAction.qmlnew file+11
@@ -0,0 +1,11 @@
1+import QtQuick 2.0
2+import QMenuModel 0.1
3+
4+QtObject {
5+ property string name
6+ property UnityMenuModel model
7+ property int index
8+
9+ readonly property var state: undefined
10+ readonly property bool valid: false
11+}
tests/mocks/QMenuModel/UnityMenuModel.qml → tests/mocks/QMenuModel/actionstateparser.cpprenamed+3−10
@@ -1,9 +1,6 @@
11/*
22 * Copyright (C) 2013 Canonical, Ltd.
33 *
4− * Authors:
5− * Mirco Müller <mirco.mueller@canonical.com>
6− *
74 * This program is free software; you can redistribute it and/or modify
85 * it under the terms of the GNU General Public License as published by
96 * the Free Software Foundation; version 3.
@@ -15,12 +12,8 @@
1512 *
1613 * You should have received a copy of the GNU General Public License
1714 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors: Nick Dedekind <nick.dedekind@canonical.com>
1817 */
1918
20−import QtQuick 2.0
21−
22−QtObject {
23− property variant busName
24− property variant actions
25− property variant menuObjectPath
26−}
19+#include "actionstateparser.h"
tests/mocks/QMenuModel/actionstateparser.hnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors: Nick Dedekind <nick.dedekind@canonical.com>
17+ */
18+
19+#ifndef MOCK_ACTIONSTATEPARSER_H
20+#define MOCK_ACTIONSTATEPARSER_H
21+
22+#include <QObject>
23+#include <QVariant>
24+
25+typedef struct _GVariant GVariant;
26+
27+class Q_DECL_EXPORT ActionStateParser : public QObject
28+{
29+ Q_OBJECT
30+public:
31+ ActionStateParser(QObject* parent = 0):QObject(parent) {}
32+ virtual QVariant toQVariant(GVariant*) const { return QVariant(); }
33+};
34+
35+#endif // MOCK_ACTIONSTATEPARSER_H
tests/mocks/QMenuModel/plugin.cpp+2
@@ -18,6 +18,7 @@
1818
1919#include "plugin.h"
2020#include "unitymenumodel.h"
21+#include "actionstateparser.h"
2122
2223#include <QtQml>
2324
@@ -25,4 +26,5 @@ void QMenuModelPlugin::registerTypes(const char *uri)
2526{
2627 Q_ASSERT(uri == QLatin1String("QMenuModel"));
2728 qmlRegisterType<UnityMenuModel>(uri, 0, 1, "UnityMenuModel");
29+ qmlRegisterType<ActionStateParser>(uri, 0, 1, "ActionStateParser");
2830}
tests/mocks/QMenuModel/qmldir+2−1
@@ -1,5 +1,6 @@
11module QMenuModel
2−plugin QMenuModelQml
2+plugin qmenumodel
33
44QDBusActionGroup 0.1 QDBusActionGroup.qml
5+UnityMenuAction 0.1 UnityMenuAction.qml
56UnityMenuModel 0.1 UnityMenuModel.qml
tests/mocks/QMenuModel/unitymenumodel.h+1−1
@@ -24,7 +24,7 @@ class QQmlComponent;
2424class UnityMenuAction;
2525class ActionStateParser;
2626
27−class UnityMenuModel : public QAbstractListModel
27+class Q_DECL_EXPORT UnityMenuModel : public QAbstractListModel
2828{
2929 Q_OBJECT
3030 Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
tests/qmltests/CMakeLists.txt+2−1
@@ -17,7 +17,8 @@ add_qml_test(Components MathLocal)
1717add_qml_test(Components OpenEffect)
1818add_qml_test(Components RatingStars)
1919add_qml_test(Components TimeLocal)
20−add_qml_test(Greeter Clock IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)
20+add_qml_test(Greeter Clock IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins
21+ ENVIRONMENT "QT_QPA_PLATFORM=minimal" "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/tests/mocks/QMenuModel")
2122add_qml_test(Panel IndicatorItem)
2223add_qml_test(utils/Unity/Test UnityTest)
2324
tests/qmltests/Greeter/tst_Clock.qml+16
@@ -19,6 +19,7 @@ import QtTest 1.0
1919import ".."
2020import "../../../Greeter"
2121import Ubuntu.Components 0.1
22+import QMenuModel 0.1
2223import Unity.Test 0.1 as UT
2324
2425Rectangle {
@@ -35,9 +36,24 @@ Rectangle {
3536 }
3637 }
3738
39+ UnityMenuModel {
40+ id: menuModel
41+ modelData: [{
42+ "rowData": {
43+ "actionState": { "label": Qt.formatTime(new Date("October 13, 1975 11:13:00")) }
44+ }
45+ }]
46+ }
47+
3848 UT.UnityTestCase {
3949 name: "Clock"
4050
51+ function init() {
52+ var cachedModel = findChild(clock, "timeModel");
53+ verify(cachedModel !== undefined);
54+ cachedModel.model = menuModel;
55+ }
56+
4157 function test_customDate() {
4258 var dateObj = new Date("October 13, 1975 11:13:00")
4359 var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)