on xenial help sign in
Fixed QMenuModel mocking
8301d36Nick Dedekind
tests/mocks/QMenuModel/CMakeLists.txt+6−1
@@ -16,14 +16,19 @@ include_directories(
16)
16)
17
17
18set(QMenuModelQml_SOURCES
18set(QMenuModelQml_SOURCES
19+ actionstateparser.cpp
19 plugin.cpp
20 plugin.cpp
20 unitymenumodel.cpp
21 unitymenumodel.cpp
21)
22)
22
23
23−add_library(QMenuModelQml MODULE ${QMenuModelQml_SOURCES})
24+add_library(QMenuModelQml SHARED ${QMenuModelQml_SOURCES})
24target_link_libraries(QMenuModelQml
25target_link_libraries(QMenuModelQml
25 ${Qt5Core_LIBRARIES}
26 ${Qt5Core_LIBRARIES}
26 ${Qt5Quick_LIBRARIES}
27 ${Qt5Quick_LIBRARIES}
27)
28)
28
29
29qt5_use_modules(QMenuModelQml Core Quick)
30qt5_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 @@
1/*
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
3 *
4− * Authors:
5− * Mirco Müller <mirco.mueller@canonical.com>
6− *
7 * This program is free software; you can redistribute it and/or modify
4 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
5 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
6 * the Free Software Foundation; version 3.
@@ -15,12 +12,8 @@
15 *
12 *
16 * You should have received a copy of the GNU General Public License
13 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors: Nick Dedekind <nick.dedekind@canonical.com>
18 */
17 */
19
18
20−import QtQuick 2.0
19+#include "actionstateparser.h"
21−
22−QtObject {
23− property variant busName
24− property variant actions
25− property variant menuObjectPath
26−}
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 @@
18
18
19#include "plugin.h"
19#include "plugin.h"
20#include "unitymenumodel.h"
20#include "unitymenumodel.h"
21+#include "actionstateparser.h"
21
22
22#include <QtQml>
23#include <QtQml>
23
24
@@ -25,4 +26,5 @@ void QMenuModelPlugin::registerTypes(const char *uri)
25{
26{
26 Q_ASSERT(uri == QLatin1String("QMenuModel"));
27 Q_ASSERT(uri == QLatin1String("QMenuModel"));
27 qmlRegisterType<UnityMenuModel>(uri, 0, 1, "UnityMenuModel");
28 qmlRegisterType<UnityMenuModel>(uri, 0, 1, "UnityMenuModel");
29+ qmlRegisterType<ActionStateParser>(uri, 0, 1, "ActionStateParser");
28}
30}
tests/mocks/QMenuModel/qmldir+2−1
@@ -1,5 +1,6 @@
1module QMenuModel
1module QMenuModel
2−plugin QMenuModelQml
2+plugin qmenumodel
3
3
4QDBusActionGroup 0.1 QDBusActionGroup.qml
4QDBusActionGroup 0.1 QDBusActionGroup.qml
5+UnityMenuAction 0.1 UnityMenuAction.qml
5UnityMenuModel 0.1 UnityMenuModel.qml
6UnityMenuModel 0.1 UnityMenuModel.qml
tests/mocks/QMenuModel/unitymenumodel.h+1−1
@@ -24,7 +24,7 @@ class QQmlComponent;
24class UnityMenuAction;
24class UnityMenuAction;
25class ActionStateParser;
25class ActionStateParser;
26
26
27−class UnityMenuModel : public QAbstractListModel
27+class Q_DECL_EXPORT UnityMenuModel : public QAbstractListModel
28{
28{
29 Q_OBJECT
29 Q_OBJECT
30 Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
30 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)
17add_qml_test(Components OpenEffect)
17add_qml_test(Components OpenEffect)
18add_qml_test(Components RatingStars)
18add_qml_test(Components RatingStars)
19add_qml_test(Components TimeLocal)
19add_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")
21add_qml_test(Panel IndicatorItem)
22add_qml_test(Panel IndicatorItem)
22add_qml_test(utils/Unity/Test UnityTest)
23add_qml_test(utils/Unity/Test UnityTest)
23
24
tests/qmltests/Greeter/tst_Clock.qml+16
@@ -19,6 +19,7 @@ import QtTest 1.0
19import ".."
19import ".."
20import "../../../Greeter"
20import "../../../Greeter"
21import Ubuntu.Components 0.1
21import Ubuntu.Components 0.1
22+import QMenuModel 0.1
22import Unity.Test 0.1 as UT
23import Unity.Test 0.1 as UT
23
24
24Rectangle {
25Rectangle {
@@ -35,9 +36,24 @@ Rectangle {
35 }
36 }
36 }
37 }
37
38
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+
38 UT.UnityTestCase {
48 UT.UnityTestCase {
39 name: "Clock"
49 name: "Clock"
40
50
51+ function init() {
52+ var cachedModel = findChild(clock, "timeModel");
53+ verify(cachedModel !== undefined);
54+ cachedModel.model = menuModel;
55+ }
56+
41 function test_customDate() {
57 function test_customDate() {
42 var dateObj = new Date("October 13, 1975 11:13:00")
58 var dateObj = new Date("October 13, 1975 11:13:00")
43 var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
59 var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)