on xenial help sign in
removed dbus in favour of mocking
ef3201dNick Dedekind
plugins/Unity/Indicators/unitymenumodelstack.cpp+4−5
@@ -52,7 +52,7 @@ private Q_SLOTS:
52 {
52 {
53 int delta = end-start + 1;
53 int delta = end-start + 1;
54 if (start <= m_index) {
54 if (start <= m_index) {
55− if (start + delta >= m_index) {
55+ if (start + delta > m_index) {
56 // in the range removed
56 // in the range removed
57 Q_EMIT remove();
57 Q_EMIT remove();
58 disconnect(m_parentModel, 0, this, 0);
58 disconnect(m_parentModel, 0, this, 0);
@@ -62,16 +62,15 @@ private Q_SLOTS:
62 }
62 }
63 }
63 }
64
64
65−Q_SIGNALS:
66− void remove();
67−
68−private Q_SLOTS:
69 void onModelReset()
65 void onModelReset()
70 {
66 {
71 Q_EMIT remove();
67 Q_EMIT remove();
72 disconnect(m_parentModel, 0, this, 0);
68 disconnect(m_parentModel, 0, this, 0);
73 }
69 }
74
70
71+Q_SIGNALS:
72+ void remove();
73+
75private:
74private:
76 UnityMenuModel* m_model;
75 UnityMenuModel* m_model;
77 UnityMenuModel* m_parentModel;
76 UnityMenuModel* m_parentModel;
tests/mocks/QMenuModel/CMakeLists.txt+18
@@ -9,3 +9,21 @@ add_custom_target(QMenuModelQmlFiles ALL
9 COMMAND cp ${QMLFILES} ${CMAKE_CURRENT_BINARY_DIR}
9 COMMAND cp ${QMLFILES} ${CMAKE_CURRENT_BINARY_DIR}
10 DEPENDS ${QMLFILES}
10 DEPENDS ${QMLFILES}
11)
11)
12+
13+include_directories(
14+ ${Qt5Core_INCLUDE_DIRS}
15+ ${Qt5Quick_INCLUDE_DIRS}
16+)
17+
18+set(QMenuModelQml_SOURCES
19+ plugin.cpp
20+ unitymenumodel.cpp
21+)
22+
23+add_library(QMenuModelQml MODULE ${QMenuModelQml_SOURCES})
24+target_link_libraries(QMenuModelQml
25+ ${Qt5Core_LIBRARIES}
26+ ${Qt5Quick_LIBRARIES}
27+)
28+
29+qt5_use_modules(QMenuModelQml Core Quick)
tests/mocks/QMenuModel/plugin.cppnew file+28
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2012,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+#include "plugin.h"
20+#include "unitymenumodel.h"
21+
22+#include <QtQml>
23+
24+void QMenuModelPlugin::registerTypes(const char *uri)
25+{
26+ Q_ASSERT(uri == QLatin1String("QMenuModel"));
27+ qmlRegisterType<UnityMenuModel>(uri, 0, 1, "UnityMenuModel");
28+}
tests/mocks/QMenuModel/plugin.hnew file+34
@@ -0,0 +1,34 @@
1+/*
2+ * Copyright (C) 2012,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_QMENUMODEL_PLUGIN_H
20+#define MOCK_QMENUMODEL_PLUGIN_H
21+
22+#include <QQmlEngine>
23+#include <QQmlExtensionPlugin>
24+
25+class QMenuModelPlugin : public QQmlExtensionPlugin
26+{
27+ Q_OBJECT
28+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29+
30+public:
31+ void registerTypes(const char *uri);
32+};
33+
34+#endif
tests/mocks/QMenuModel/qmldir+2
@@ -1,2 +1,4 @@
1module QMenuModel
1module QMenuModel
2+plugin QMenuModelQml
3+
2QDBusActionGroup 0.1 QDBusActionGroup.qml
4QDBusActionGroup 0.1 QDBusActionGroup.qml
tests/mocks/QMenuModel/unitymenumodel.cppnew file+243
@@ -0,0 +1,243 @@
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+#include "unitymenumodel.h"
20+#include <QDebug>
21+
22+enum MenuRoles {
23+ LabelRole = Qt::DisplayRole + 1,
24+ SensitiveRole,
25+ IsSeparatorRole,
26+ IconRole,
27+ TypeRole,
28+ ExtendedAttributesRole,
29+ ActionRole,
30+ ActionStateRole,
31+ IsCheckRole,
32+ IsRadioRole,
33+ IsToggledRole
34+};
35+
36+UnityMenuModel::UnityMenuModel(QObject *parent)
37+: QAbstractListModel(parent)
38+{
39+}
40+
41+UnityMenuModel::UnityMenuModel(const QVariant& data, QObject *parent)
42+: QAbstractListModel(parent)
43+{
44+ QVariantList li = data.toList();
45+ m_modelData = li;
46+}
47+
48+QVariant UnityMenuModel::modelData() const
49+{
50+ return m_modelData;
51+}
52+
53+void UnityMenuModel::setModelData(const QVariant& data)
54+{
55+ beginResetModel();
56+
57+ m_modelData.clear();
58+ m_modelData = data.toList();
59+
60+ endResetModel();
61+}
62+
63+
64+void UnityMenuModel::insertRow(int row, const QVariant& data)
65+{
66+ row = qMin(row, rowCount());
67+
68+ beginInsertRows(QModelIndex(), row, row);
69+
70+ m_modelData.insert(row, data);
71+
72+ endInsertRows();
73+}
74+
75+void UnityMenuModel::appendRow(const QVariant& data)
76+{
77+ insertRow(rowCount(), data);
78+}
79+
80+void UnityMenuModel::removeRow(int row)
81+{
82+ if (row < 0 || rowCount() <= row) {
83+ return;
84+ }
85+
86+ beginRemoveRows(QModelIndex(), row, row);
87+
88+ m_modelData.removeAt(row);
89+
90+ endRemoveRows();
91+}
92+
93+UnityMenuModel::~UnityMenuModel()
94+{
95+}
96+
97+QByteArray UnityMenuModel::busName() const
98+{
99+ return m_busName;
100+}
101+
102+void UnityMenuModel::setBusName(const QByteArray &busName)
103+{
104+ this->m_busName = busName;
105+}
106+
107+QVariantMap UnityMenuModel::actions() const
108+{
109+ return m_actions;
110+}
111+
112+void UnityMenuModel::setActions(const QVariantMap &actions)
113+{
114+ this->m_actions = actions;
115+}
116+
117+QByteArray UnityMenuModel::menuObjectPath() const
118+{
119+ return m_menuObjectPath;
120+}
121+
122+void UnityMenuModel::setMenuObjectPath(const QByteArray &path)
123+{
124+ this->m_menuObjectPath = path;
125+}
126+
127+ActionStateParser* UnityMenuModel::actionStateParser() const
128+{
129+ return NULL;
130+}
131+
132+void UnityMenuModel::setActionStateParser(ActionStateParser*)
133+{
134+}
135+
136+int UnityMenuModel::rowCount(const QModelIndex&) const
137+{
138+ return m_modelData.count();
139+}
140+
141+int UnityMenuModel::columnCount(const QModelIndex&) const
142+{
143+ return 1;
144+}
145+
146+QVariant UnityMenuModel::data(const QModelIndex &index, int role) const
147+{
148+ return rowData(index.row())[roleNames()[role]];
149+}
150+
151+QVariantMap UnityMenuModel::rowData(int row) const
152+{
153+ return m_modelData[row].toMap()["rowData"].toMap();
154+}
155+
156+QVariant UnityMenuModel::subMenuData(int row) const
157+{
158+ return m_modelData[row].toMap()["submenu"];
159+}
160+
161+QModelIndex UnityMenuModel::index(int row, int column, const QModelIndex&) const
162+{
163+ return createIndex(row, column);
164+}
165+
166+QModelIndex UnityMenuModel::parent(const QModelIndex &) const
167+{
168+ return QModelIndex();
169+}
170+
171+QHash<int, QByteArray> UnityMenuModel::roleNames() const
172+{
173+ QHash<int, QByteArray> names;
174+
175+ names[LabelRole] = "label";
176+ names[SensitiveRole] = "sensitive";
177+ names[IsSeparatorRole] = "isSeparator";
178+ names[IconRole] = "icon";
179+ names[TypeRole] = "type";
180+ names[ExtendedAttributesRole] = "ext";
181+ names[ActionRole] = "action";
182+ names[ActionStateRole] = "actionState";
183+ names[IsCheckRole] = "isCheck";
184+ names[IsRadioRole] = "isRadio";
185+ names[IsToggledRole] = "isToggled";
186+
187+ return names;
188+}
189+
190+QObject * UnityMenuModel::submenu(int position, QQmlComponent*)
191+{
192+ if (position < 0 || m_modelData.count() < position) {
193+ return NULL;
194+ }
195+
196+ while (submenus.count() <= position) {
197+ submenus.append(NULL);
198+ }
199+
200+ QVariant submenuData = subMenuData(position);
201+ if (submenuData.type() == (int)QMetaType::QVariantList) {
202+ UnityMenuModel*& model = submenus[position];
203+ if (!model) {
204+ model = new UnityMenuModel(submenuData, this);
205+ return model;
206+ }
207+ }
208+
209+ return NULL;
210+}
211+
212+bool UnityMenuModel::loadExtendedAttributes(int, const QVariantMap &)
213+{
214+ return false;
215+}
216+
217+QVariant UnityMenuModel::get(int row, const QByteArray &role)
218+{
219+ static QHash<QByteArray, int> roles;
220+ if (roles.isEmpty()) {
221+ QHash<int, QByteArray> names = roleNames();
222+ Q_FOREACH (int role, names.keys())
223+ roles.insert(names[role], role);
224+ }
225+
226+ return this->data(this->index(row, 0), roles[role]);
227+}
228+
229+void UnityMenuModel::activate(int, const QVariant&)
230+{
231+}
232+
233+void UnityMenuModel::changeState(int, const QVariant&)
234+{
235+}
236+
237+void UnityMenuModel::registerAction(UnityMenuAction*)
238+{
239+}
240+
241+void UnityMenuModel::unregisterAction(UnityMenuAction*)
242+{
243+}
tests/mocks/QMenuModel/unitymenumodel.hnew file+98
@@ -0,0 +1,98 @@
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_UNITYMENUMODEL_H
20+#define MOCK_UNITYMENUMODEL_H
21+
22+#include <QAbstractListModel>
23+class QQmlComponent;
24+class UnityMenuAction;
25+class ActionStateParser;
26+
27+class UnityMenuModel : public QAbstractListModel
28+{
29+ Q_OBJECT
30+ Q_PROPERTY(QVariant modelData READ modelData WRITE setModelData NOTIFY modelDataChanged)
31+ Q_PROPERTY(QByteArray busName READ busName WRITE setBusName NOTIFY busNameChanged)
32+ Q_PROPERTY(QVariantMap actions READ actions WRITE setActions NOTIFY actionsChanged)
33+ Q_PROPERTY(QByteArray menuObjectPath READ menuObjectPath WRITE setMenuObjectPath NOTIFY menuObjectPathChanged)
34+ Q_PROPERTY(ActionStateParser* actionStateParser READ actionStateParser WRITE setActionStateParser NOTIFY actionStateParserChanged)
35+
36+public:
37+ UnityMenuModel(QObject *parent = NULL);
38+ virtual ~UnityMenuModel();
39+
40+ Q_INVOKABLE void insertRow(int row, const QVariant& data);
41+ Q_INVOKABLE void appendRow(const QVariant& data);
42+ Q_INVOKABLE void removeRow(int row);
43+
44+ QVariant modelData() const;
45+ void setModelData(const QVariant& data);
46+
47+ QByteArray busName() const;
48+ void setBusName(const QByteArray &busName);
49+
50+ QVariantMap actions() const;
51+ void setActions(const QVariantMap &actions);
52+
53+ QByteArray menuObjectPath() const;
54+ void setMenuObjectPath(const QByteArray &path);
55+
56+ ActionStateParser* actionStateParser() const;
57+ void setActionStateParser(ActionStateParser* actionStateParser);
58+
59+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
60+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
61+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
62+ QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
63+ QModelIndex parent(const QModelIndex &index) const;
64+ QHash<int, QByteArray> roleNames() const;
65+
66+ Q_INVOKABLE QObject * submenu(int position, QQmlComponent* actionStateParser = NULL);
67+ Q_INVOKABLE bool loadExtendedAttributes(int position, const QVariantMap &schema);
68+ Q_INVOKABLE QVariant get(int row, const QByteArray &role);
69+
70+ Q_INVOKABLE void activate(int index, const QVariant& parameter = QVariant());
71+ Q_INVOKABLE void changeState(int index, const QVariant& parameter);
72+
73+ void registerAction(UnityMenuAction* action);
74+ void unregisterAction(UnityMenuAction* action);
75+
76+Q_SIGNALS:
77+ void busNameChanged();
78+ void actionsChanged();
79+ void menuObjectPathChanged();
80+ void actionStateParserChanged();
81+ void modelDataChanged();
82+
83+private:
84+ UnityMenuModel(const QVariant& data, QObject *parent = NULL);
85+
86+ QVariantMap rowData(int row) const;
87+ QVariant subMenuData(int row) const;
88+
89+ class Row;
90+ QVariantList m_modelData;
91+ QList<UnityMenuModel*> submenus;
92+
93+ QByteArray m_busName;
94+ QVariantMap m_actions;
95+ QByteArray m_menuObjectPath;
96+};
97+
98+#endif // MOCK_UNITYMENUMODEL_H
tests/plugins/Unity/Indicators/CMakeLists.txt+29−29
@@ -1,39 +1,39 @@
1pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
1pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32)
2pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
2pkg_check_modules(GIO REQUIRED gio-2.0>=2.32)
3−pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
3+
4+set(INDICATORS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../plugins/Unity/Indicators)
5+set(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
4
6
5include_directories(
7include_directories(
6 ${CMAKE_CURRENT_BINARY_DIR}
8 ${CMAKE_CURRENT_BINARY_DIR}
7− ${CMAKE_CURRENT_SOURCE_DIR}/../../../../plugins/Unity/Indicators
9+ ${INDICATORS_DIR}
10+ ${TEST_DIR}/mocks/QMenuModel
8 ${GLIB_INCLUDE_DIRS}
11 ${GLIB_INCLUDE_DIRS}
9 ${GIO_INCLUDE_DIRS}
12 ${GIO_INCLUDE_DIRS}
10− ${QMENUMODEL_INCLUDE_DIRS}
11 )
13 )
12
14
13−macro(run_tests)
15+macro(indicator_test TEST)
14− set(_test_list "")
16+ set(multi_value_keywords ADDITIONAL_CPPS ADDITIONAL_LIBS)
15− foreach(_test ${ARGN})
17+ cmake_parse_arguments(test "" "" "${multi_value_keywords}" ${ARGN})
16− set(testCommand ${CMAKE_CURRENT_BINARY_DIR}/${_test}Exec
17− -o ${CMAKE_BINARY_DIR}/${_test}.xml,xunitxml
18− -o -,txt)
19− add_test(NAME ${_test} COMMAND ${testCommand})
20− add_custom_target(${_test} ${testCommand})
21− add_executable(${_test}Exec ${_test}.cpp
22− )
23− qt5_use_modules(${_test}Exec Test Core Qml)
24− target_link_libraries(${_test}Exec
25− IndicatorsQml
26− ${GLIB_LIBRARIES}
27− ${GIO_LIBRARIES}
28− ${QMENUMODEL_LDFLAGS}
29− )
30− set(_test_list "${_test_list};${_test}")
31− endforeach()
32−endmacro(run_tests)
33
18
34−run_tests(
19+ set(testCommand ${CMAKE_CURRENT_BINARY_DIR}/${TEST}Exec
20+ -o ${CMAKE_BINARY_DIR}/${TEST}.xml,xunitxml
21+ -o -,txt)
22+ add_test(NAME ${TEST} COMMAND ${testCommand})
23+ add_custom_target(${TEST} ${testCommand})
24+ add_executable(${TEST}Exec
25+ ${TEST}.cpp
26+ ${test_ADDITIONAL_CPPS}
27+ )
28+ qt5_use_modules(${TEST}Exec Test Core Qml)
29+ target_link_libraries(${TEST}Exec
30+ ${test_ADDITIONAL_LIBS}
31+ ${GLIB_LIBRARIES}
32+ ${GIO_LIBRARIES}
33+ )
34+endmacro(indicator_test)
35+
35− indicatorsmanagertest
36+indicator_test(indicatorsmanagertest ADDITIONAL_LIBS IndicatorsQml)
36− indicatorsmodeltest
37+indicator_test(indicatorsmodeltest ADDITIONAL_LIBS IndicatorsQml)
37− menucontentactivatortest
38+indicator_test(menucontentactivatortest ADDITIONAL_CPPS ${INDICATORS_DIR}/menucontentactivator.cpp)
38− unitymenumodelstacktest
39+indicator_test(unitymenumodelstacktest ADDITIONAL_CPPS ${TEST_DIR}/mocks/QMenuModel/unitymenumodel.cpp ${INDICATORS_DIR}/unitymenumodelstack.cpp)
39− )
tests/plugins/Unity/Indicators/unitymenumodelstacktest.cpp+21−98
@@ -23,19 +23,8 @@
23
23
24#include <QtTest>
24#include <QtTest>
25#include <QDebug>
25#include <QDebug>
26−
27−#include <glib.h>
28−#include <gio/gio.h>
29#include <unitymenumodel.h>
26#include <unitymenumodel.h>
30
27
31− #define BUS_NAME "com.canonical.unity8.unitymenumodelstacktest"
32− #define OBJECT_PATH "/com/canonical/unity8/unitymenumodelstack"
33−
34−static void on_bus_acquired (GDBusConnection *bus, const gchar *name, gpointer user_data);
35−static void on_name_aquired (GDBusConnection *bus, const gchar *name, gpointer user_data);
36−static void on_name_lost (GDBusConnection *bus, const gchar *name, gpointer user_data);
37−
38−
39class UnityMenuModelStackTest : public QObject
28class UnityMenuModelStackTest : public QObject
40{
29{
41 Q_OBJECT
30 Q_OBJECT
@@ -43,25 +32,10 @@ private Q_SLOTS:
43
32
44 void initTestCase()
33 void initTestCase()
45 {
34 {
46− m_menuUid = 0;
47− m_connection = NULL;
48− m_connected = NULL;
49− m_failed = false;
50− m_menu = NULL;
51−
52− GBusNameOwnerFlags flags;
53− flags = (GBusNameOwnerFlags) (G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | G_BUS_NAME_OWNER_FLAGS_REPLACE);
54−
55− g_bus_own_name (G_BUS_TYPE_SESSION, BUS_NAME, flags,
56− on_bus_acquired, on_name_aquired, on_name_lost, this, NULL);
57 }
35 }
58
36
59 void cleanupTestCase()
37 void cleanupTestCase()
60 {
38 {
61− if (m_connection) {
62− g_object_unref(m_connection);
63− m_connection = NULL;
64− }
65 }
39 }
66
40
67 void init()
41 void init()
@@ -70,30 +44,11 @@ private Q_SLOTS:
70 QFETCH(int, menuDepth);
44 QFETCH(int, menuDepth);
71 QFETCH(int, subMenuCount);
45 QFETCH(int, subMenuCount);
72
46
73− waitFor([this]() { return this->m_connected || this->m_failed; }, 500);
47+ m_model = new UnityMenuModel();
74− QVERIFY(m_connected);
48+ m_model->setModelData(recuseAddMenu(subMenuCount, menuDepth));
75−
76− const QString& path = QString(OBJECT_PATH) + "/" + test;
77−
78− m_menuUid = exportMenuModel(&m_menu, m_connection, path, subMenuCount, menuDepth);
79−
80− m_model = new UnityMenuModel;
81− m_model->setBusName(BUS_NAME);
82− m_model->setMenuObjectPath(path.toUtf8());
83 }
49 }
84
50
85 void cleanup() {
51 void cleanup() {
86− if (m_model) {
87− delete m_model;
88− m_model = NULL;
89− }
90− if (m_menuUid != 0) {
91− g_dbus_connection_unexport_menu_model(m_connection, m_menuUid);
92− m_menuUid = 0;
93− }
94− if (m_menu) {
95− g_object_unref(m_menu);
96− }
97 }
52 }
98
53
99
54
@@ -177,7 +132,8 @@ private Q_SLOTS:
177 }
132 }
178
133
179 QCOMPARE(stack.count(), menuDepth+1);
134 QCOMPARE(stack.count(), menuDepth+1);
180− g_menu_remove(m_menu, removeIndex);
135+
136+ m_model->removeRow(removeIndex);
181
137
182 waitFor([&stack, resultCount]() { return stack.count() == resultCount; }, 1000);
138 waitFor([&stack, resultCount]() { return stack.count() == resultCount; }, 1000);
183 QCOMPARE(stack.count(), resultCount);
139 QCOMPARE(stack.count(), resultCount);
@@ -191,65 +147,32 @@ private:
191 while(!functor() && timer.elapsed() < ms) { QTest::qWait(10); }
147 while(!functor() && timer.elapsed() < ms) { QTest::qWait(10); }
192 return functor();
148 return functor();
193 }
149 }
194− guint exportMenuModel(GMenu** menu, GDBusConnection* connection, const QString& object_path, int submenuCount, int depth);
195−
196−public:
197− GDBusConnection* m_connection;
198− bool m_failed;
199− bool m_connected;
200− guint m_menuUid;
201− GMenu* m_menu;
202− UnityMenuModel* m_model;
203−};
204−
205−void recuseAddMenu(GMenu* menu, int subMenuCount, int depth_remaining)
206−{
207− for (int i = 0; i < subMenuCount; i ++) {
208− GMenuItem* item = g_menu_item_new("", NULL);
209
150
210− if (depth_remaining > 0) {
211− GMenu* submenu = g_menu_new ();
212− recuseAddMenu(submenu, subMenuCount, depth_remaining-1);
151+ QVariant recuseAddMenu(int subMenuCount, int depth_remaining)
213− g_menu_item_set_submenu (item, G_MENU_MODEL (submenu));
152+ {
214− }
153+ QVariantList rows;
215
154
216− g_menu_append_item (menu, item);
155+ for (int i = 0; i < subMenuCount; i ++) {
217− }
156+ QVariantMap row;
218−}
157+ QVariantMap rowData;
219
158
220−guint UnityMenuModelStackTest::exportMenuModel(GMenu** menu, GDBusConnection* connection, const QString& object_path, int submenuCount, int depth)
159+ if (depth_remaining > 0) {
221−{
160+ row["submenu"] = recuseAddMenu(subMenuCount, depth_remaining-1);
222− *menu=g_menu_new();
161+ }
223− recuseAddMenu(*menu, submenuCount, depth);
224
162
225− QByteArray path = object_path.toUtf8();
163+ row["rowData"] = rowData;
226
164
227− return g_dbus_connection_export_menu_model (connection, path.constData(), G_MENU_MODEL (*menu), NULL);
165+ rows << row;
228−}
166+ }
229
167
230−static void
168+ return rows;
231−on_bus_acquired (GDBusConnection *bus, const gchar *, gpointer user_data)
232−{
233− UnityMenuModelStackTest* test = (UnityMenuModelStackTest*)user_data;
234− test->m_connection = bus;
235−}
169+ }
236
170
237−static void
171+public:
238−on_name_aquired (GDBusConnection*, const gchar*, gpointer user_data)
172+ UnityMenuModel* m_model;
239−{
240− UnityMenuModelStackTest* test = (UnityMenuModelStackTest*)user_data;
241− test->m_connected = true;
242− test->m_failed = false;
243−}
173+};
244
174
245
175
246−static void
247−on_name_lost (GDBusConnection*, const gchar*, gpointer user_data)
248−{
249− UnityMenuModelStackTest* test = (UnityMenuModelStackTest*)user_data;
250− test->m_connected = false;
251− test->m_failed = true;
252−}
253
176
254QTEST_GUILESS_MAIN(UnityMenuModelStackTest)
177QTEST_GUILESS_MAIN(UnityMenuModelStackTest)
255#include "unitymenumodelstacktest.moc"
178#include "unitymenumodelstacktest.moc"