Merge lp:~aacid/dee-qt/fixsetmodelsharedmodels into lp:dee-qt/0.2
- fixsetmodelsharedmodels
- Merge into trunk
Proposed by
Albert Astals Cid
Status: | Merged |
---|---|
Approved by: | Martin Mrazik |
Approved revision: | 71 |
Merged at revision: | 67 |
Proposed branch: | lp:~aacid/dee-qt/fixsetmodelsharedmodels |
Merge into: | lp:dee-qt/0.2 |
Diff against target: |
342 lines (+220/-20) 7 files modified
CMakeLists.txt (+12/-1) conversiontest.cpp (+5/-1) debian/control (+1/-1) debian/rules (+2/-0) deelistmodel.cpp (+27/-17) deelistmodeltest.cpp (+115/-0) test-helper.cpp (+58/-0) |
To merge this branch: | bzr merge lp:~aacid/dee-qt/fixsetmodelsharedmodels |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tiago Salem Herrmann (community) | Approve | ||
Review via email: mp+135396@code.launchpad.net |
Commit message
Make setModel work for shared deemodels
Removes the isLocal member, don't need it and was checking for wrong stuff anyway
Description of the change
Make setModel work for shared deemodels
Removes the isLocal member, don't need it and was checking for wrong stuff anyway
To post a comment you must log in.
Revision history for this message
Unity Merger (unity-merger) wrote : | # |
No commit message specified.
Revision history for this message
Albert Astals Cid (aacid) wrote : | # |
Reapproving, just forgot to set the commit message
Revision history for this message
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
Revision history for this message
Unity Merger (unity-merger) wrote : | # |
The Jenkins job https:/
Not merging it.
- 71. By Albert Astals Cid
-
Use dbus-test-runner and make the helper a bit better
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2012-11-12 10:53:16 +0000 | |||
3 | +++ CMakeLists.txt 2012-11-22 10:38:21 +0000 | |||
4 | @@ -40,6 +40,7 @@ | |||
5 | 40 | ${QT_INCLUDE_DIR} | 40 | ${QT_INCLUDE_DIR} |
6 | 41 | ${QT_QTCORE_INCLUDE_DIR} | 41 | ${QT_QTCORE_INCLUDE_DIR} |
7 | 42 | ${QT_QTDECLARATIVE_INCLUDE_DIR} | 42 | ${QT_QTDECLARATIVE_INCLUDE_DIR} |
8 | 43 | ${QT_QTDBUS_INCLUDE_DIR} | ||
9 | 43 | ${DEE_INCLUDE_DIRS} | 44 | ${DEE_INCLUDE_DIRS} |
10 | 44 | ${QT_QTTEST_INCLUDE_DIR} | 45 | ${QT_QTTEST_INCLUDE_DIR} |
11 | 45 | ) | 46 | ) |
12 | @@ -119,5 +120,15 @@ | |||
13 | 119 | qt4_generate_moc(conversiontest.cpp conversiontest.moc) | 120 | qt4_generate_moc(conversiontest.cpp conversiontest.moc) |
14 | 120 | add_executable(conversiontest conversiontest.cpp conversiontest.moc) | 121 | add_executable(conversiontest conversiontest.cpp conversiontest.moc) |
15 | 121 | target_link_libraries(conversiontest ${QT_QTTEST_LIBRARIES} QtDee) | 122 | target_link_libraries(conversiontest ${QT_QTTEST_LIBRARIES} QtDee) |
17 | 122 | add_test(NAME conversiontest COMMAND "${CMAKE_CURRENT_BINARY_DIR}/conversiontest" "-xunitxml" "-o" "conversiontest-xunit.xml") | 123 | add_test(NAME conversiontest COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/conversiontest" "-p" "-xunitxml" "-p" "-o" "-p" "conversiontest-xunit.xml") |
18 | 123 | set_property(TEST conversiontest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") | 124 | set_property(TEST conversiontest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") |
19 | 125 | |||
20 | 126 | qt4_generate_moc(test-helper.cpp test-helper.moc) | ||
21 | 127 | add_executable(test-helper test-helper.cpp test-helper.moc) | ||
22 | 128 | target_link_libraries(test-helper ${QT_QTCORE_LIBRARIES} ${QT_QTDBUS_LIBRARIES} ${DEE_LDFLAGS}) | ||
23 | 129 | |||
24 | 130 | qt4_generate_moc(deelistmodeltest.cpp deelistmodeltest.moc) | ||
25 | 131 | add_executable(deelistmodeltest deelistmodeltest.cpp deelistmodeltest.moc) | ||
26 | 132 | target_link_libraries(deelistmodeltest ${QT_QTTEST_LIBRARIES} ${QT_QTDBUS_LIBRARIES} QtDee) | ||
27 | 133 | add_test(NAME deelistmodeltest COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/test-helper" "--task" "${CMAKE_CURRENT_BINARY_DIR}/deelistmodeltest" "-p" "-xunitxml" "-p" "-o" "-p" "deelistmodeltest-xunit.xml") | ||
28 | 134 | set_property(TEST deelistmodeltest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.") | ||
29 | 124 | 135 | ||
30 | === modified file 'conversiontest.cpp' | |||
31 | --- conversiontest.cpp 2012-11-12 09:32:44 +0000 | |||
32 | +++ conversiontest.cpp 2012-11-22 10:38:21 +0000 | |||
33 | @@ -33,9 +33,13 @@ | |||
34 | 33 | 33 | ||
35 | 34 | void GVariantToQVariantConversionTest() | 34 | void GVariantToQVariantConversionTest() |
36 | 35 | { | 35 | { |
38 | 36 | DeeModel* model = dee_shared_model_new("com.dee-qt.test"); | 36 | DeeModel* model = dee_shared_model_new("com.deeqt.conversiontest"); |
39 | 37 | dee_model_set_schema(model, "b", "y", "n", "q", "i", "u", "x", "t", "d", "s", "a(ii)", NULL); | 37 | dee_model_set_schema(model, "b", "y", "n", "q", "i", "u", "x", "t", "d", "s", "a(ii)", NULL); |
40 | 38 | 38 | ||
41 | 39 | // Doc says we need to be synchronized before doing anything | ||
42 | 40 | while(!dee_shared_model_is_synchronized(DEE_SHARED_MODEL(model))) | ||
43 | 41 | qApp->processEvents(); | ||
44 | 42 | |||
45 | 39 | GVariant **tuples = g_new(GVariant *, 2); | 43 | GVariant **tuples = g_new(GVariant *, 2); |
46 | 40 | 44 | ||
47 | 41 | GVariant **t1 = g_new(GVariant *, 2); | 45 | GVariant **t1 = g_new(GVariant *, 2); |
48 | 42 | 46 | ||
49 | === modified file 'debian/control' | |||
50 | --- debian/control 2012-11-12 10:53:16 +0000 | |||
51 | +++ debian/control 2012-11-22 10:38:21 +0000 | |||
52 | @@ -3,7 +3,7 @@ | |||
53 | 3 | Priority: optional | 3 | Priority: optional |
54 | 4 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | 4 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
55 | 5 | XSBC-Original-Maintainer: Olivier Tilloy <olivier.tilloy@canonical.com> | 5 | XSBC-Original-Maintainer: Olivier Tilloy <olivier.tilloy@canonical.com> |
57 | 6 | Build-Depends: cdbs, debhelper (>= 7), cmake, libqt4-dev (>= 4.7), libdee-dev (>= 1.0.0) | 6 | Build-Depends: cdbs, debhelper (>= 7), cmake, libqt4-dev (>= 4.7), libdee-dev (>= 1.0.0), dbus-test-runner |
58 | 7 | Standards-Version: 3.9.1 | 7 | Standards-Version: 3.9.1 |
59 | 8 | Vcs-Bzr: http://bazaar.launchpad.net/~unity-2d-team/dee-qt/trunk | 8 | Vcs-Bzr: http://bazaar.launchpad.net/~unity-2d-team/dee-qt/trunk |
60 | 9 | 9 | ||
61 | 10 | 10 | ||
62 | === modified file 'debian/rules' | |||
63 | --- debian/rules 2010-12-24 02:57:22 +0000 | |||
64 | +++ debian/rules 2012-11-22 10:38:21 +0000 | |||
65 | @@ -1,6 +1,8 @@ | |||
66 | 1 | #!/usr/bin/make -f | 1 | #!/usr/bin/make -f |
67 | 2 | # -*- makefile -*- | 2 | # -*- makefile -*- |
68 | 3 | 3 | ||
69 | 4 | DEB_MAKE_CHECK_TARGET = test | ||
70 | 5 | |||
71 | 4 | include /usr/share/cdbs/1/rules/debhelper.mk | 6 | include /usr/share/cdbs/1/rules/debhelper.mk |
72 | 5 | include /usr/share/cdbs/1/class/cmake.mk | 7 | include /usr/share/cdbs/1/class/cmake.mk |
73 | 6 | 8 | ||
74 | 7 | 9 | ||
75 | === modified file 'deelistmodel.cpp' | |||
76 | --- deelistmodel.cpp 2012-11-12 09:32:44 +0000 | |||
77 | +++ deelistmodel.cpp 2012-11-22 10:38:21 +0000 | |||
78 | @@ -85,6 +85,7 @@ | |||
79 | 85 | void connectToDeeModel(DeeModel *model); | 85 | void connectToDeeModel(DeeModel *model); |
80 | 86 | void disconnectFromDeeModel(); | 86 | void disconnectFromDeeModel(); |
81 | 87 | void createRoles(); | 87 | void createRoles(); |
82 | 88 | bool synchronized() const; | ||
83 | 88 | 89 | ||
84 | 89 | /* GObject signal handlers for m_deeModel */ | 90 | /* GObject signal handlers for m_deeModel */ |
85 | 90 | static void onSynchronizedChanged(GObject* emitter, GParamSpec *pspec, DeeListModel* model); | 91 | static void onSynchronizedChanged(GObject* emitter, GParamSpec *pspec, DeeListModel* model); |
86 | @@ -96,10 +97,9 @@ | |||
87 | 96 | DeeModel* m_deeModel; | 97 | DeeModel* m_deeModel; |
88 | 97 | QString m_name; | 98 | QString m_name; |
89 | 98 | int m_count; | 99 | int m_count; |
90 | 99 | bool m_isLocal; | ||
91 | 100 | }; | 100 | }; |
92 | 101 | 101 | ||
94 | 102 | DeeListModelPrivate::DeeListModelPrivate(DeeListModel* parent) : m_parent(parent), m_deeModel(NULL), m_count(0), m_isLocal(false) | 102 | DeeListModelPrivate::DeeListModelPrivate(DeeListModel* parent) : m_parent(parent), m_deeModel(NULL), m_count(0) |
95 | 103 | { | 103 | { |
96 | 104 | } | 104 | } |
97 | 105 | 105 | ||
98 | @@ -137,7 +137,6 @@ | |||
99 | 137 | g_signal_connect(m_deeModel, "row-removed", G_CALLBACK(onRowRemoved), m_parent); | 137 | g_signal_connect(m_deeModel, "row-removed", G_CALLBACK(onRowRemoved), m_parent); |
100 | 138 | g_signal_connect(m_deeModel, "row-changed", G_CALLBACK(onRowChanged), m_parent); | 138 | g_signal_connect(m_deeModel, "row-changed", G_CALLBACK(onRowChanged), m_parent); |
101 | 139 | } | 139 | } |
102 | 140 | m_isLocal = false; | ||
103 | 141 | } | 140 | } |
104 | 142 | 141 | ||
105 | 143 | void | 142 | void |
106 | @@ -149,12 +148,31 @@ | |||
107 | 149 | g_signal_connect(m_deeModel, "row-added", G_CALLBACK(onRowAdded), m_parent); | 148 | g_signal_connect(m_deeModel, "row-added", G_CALLBACK(onRowAdded), m_parent); |
108 | 150 | g_signal_connect(m_deeModel, "row-removed", G_CALLBACK(onRowRemoved), m_parent); | 149 | g_signal_connect(m_deeModel, "row-removed", G_CALLBACK(onRowRemoved), m_parent); |
109 | 151 | g_signal_connect(m_deeModel, "row-changed", G_CALLBACK(onRowChanged), m_parent); | 150 | g_signal_connect(m_deeModel, "row-changed", G_CALLBACK(onRowChanged), m_parent); |
115 | 152 | m_isLocal = true; | 151 | if (synchronized()) |
116 | 153 | createRoles(); | 152 | { |
117 | 154 | m_count = dee_model_get_n_rows(m_deeModel); | 153 | createRoles(); |
118 | 155 | m_parent->reset(); | 154 | m_count = dee_model_get_n_rows(m_deeModel); |
119 | 156 | Q_EMIT m_parent->countChanged(); | 155 | m_parent->reset(); |
120 | 156 | Q_EMIT m_parent->countChanged(); | ||
121 | 157 | } | ||
122 | 158 | else | ||
123 | 159 | { | ||
124 | 160 | g_signal_connect(m_deeModel, "notify::synchronized", G_CALLBACK(onSynchronizedChanged), m_parent); | ||
125 | 161 | } | ||
126 | 162 | } | ||
127 | 157 | 163 | ||
128 | 164 | bool | ||
129 | 165 | DeeListModelPrivate::synchronized() const | ||
130 | 166 | { | ||
131 | 167 | if (m_deeModel == NULL) { | ||
132 | 168 | return false; | ||
133 | 169 | } else { | ||
134 | 170 | if (DEE_IS_SHARED_MODEL(m_deeModel)) { | ||
135 | 171 | return dee_shared_model_is_synchronized(DEE_SHARED_MODEL(m_deeModel)); | ||
136 | 172 | } else { | ||
137 | 173 | return true; | ||
138 | 174 | } | ||
139 | 175 | } | ||
140 | 158 | } | 176 | } |
141 | 159 | 177 | ||
142 | 160 | void | 178 | void |
143 | @@ -296,15 +314,7 @@ | |||
144 | 296 | bool | 314 | bool |
145 | 297 | DeeListModel::synchronized() const | 315 | DeeListModel::synchronized() const |
146 | 298 | { | 316 | { |
156 | 299 | if (d->m_deeModel == NULL) { | 317 | return d->synchronized(); |
148 | 300 | return false; | ||
149 | 301 | } else { | ||
150 | 302 | if (d->m_isLocal) { | ||
151 | 303 | return true; | ||
152 | 304 | } else { | ||
153 | 305 | return dee_shared_model_is_synchronized(DEE_SHARED_MODEL(d->m_deeModel)); | ||
154 | 306 | } | ||
155 | 307 | } | ||
157 | 308 | } | 318 | } |
158 | 309 | 319 | ||
159 | 310 | int | 320 | int |
160 | 311 | 321 | ||
161 | === added file 'deelistmodeltest.cpp' | |||
162 | --- deelistmodeltest.cpp 1970-01-01 00:00:00 +0000 | |||
163 | +++ deelistmodeltest.cpp 2012-11-22 10:38:21 +0000 | |||
164 | @@ -0,0 +1,115 @@ | |||
165 | 1 | /* | ||
166 | 2 | * Copyright (C) 2012 Canonical, Ltd. | ||
167 | 3 | * | ||
168 | 4 | * This program is free software; you can redistribute it and/or modify | ||
169 | 5 | * it under the terms of the GNU General Public License as published by | ||
170 | 6 | * the Free Software Foundation; version 3. | ||
171 | 7 | * | ||
172 | 8 | * This program is distributed in the hope that it will be useful, | ||
173 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
174 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
175 | 11 | * GNU General Public License for more details. | ||
176 | 12 | * | ||
177 | 13 | * You should have received a copy of the GNU General Public License | ||
178 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
179 | 15 | */ | ||
180 | 16 | |||
181 | 17 | #include <QtTest> | ||
182 | 18 | #include <QObject> | ||
183 | 19 | #include <QDBusInterface> | ||
184 | 20 | |||
185 | 21 | #include "deelistmodel.h" | ||
186 | 22 | |||
187 | 23 | #include <dee.h> | ||
188 | 24 | |||
189 | 25 | static bool wait_until_test_service_appears() | ||
190 | 26 | { | ||
191 | 27 | bool have_name = false; | ||
192 | 28 | bool timeout_reached = false; | ||
193 | 29 | |||
194 | 30 | auto timeout_cb = [](gpointer data) -> gboolean | ||
195 | 31 | { | ||
196 | 32 | *(bool*)data = true; | ||
197 | 33 | return FALSE; | ||
198 | 34 | }; | ||
199 | 35 | |||
200 | 36 | auto callback = [](GDBusConnection * conn, | ||
201 | 37 | const char * name, | ||
202 | 38 | const char * name_owner, | ||
203 | 39 | gpointer user_data) | ||
204 | 40 | { | ||
205 | 41 | *(bool*)user_data = true; | ||
206 | 42 | }; | ||
207 | 43 | |||
208 | 44 | g_bus_watch_name(G_BUS_TYPE_SESSION, | ||
209 | 45 | "com.deeqt.test.control", | ||
210 | 46 | G_BUS_NAME_WATCHER_FLAGS_NONE, | ||
211 | 47 | callback, | ||
212 | 48 | NULL, | ||
213 | 49 | &have_name, | ||
214 | 50 | NULL); | ||
215 | 51 | g_timeout_add(10000, timeout_cb, &timeout_reached); | ||
216 | 52 | |||
217 | 53 | while (!have_name && !timeout_reached) | ||
218 | 54 | g_main_context_iteration(g_main_context_get_thread_default(), TRUE); | ||
219 | 55 | |||
220 | 56 | return (have_name && !timeout_reached); | ||
221 | 57 | } | ||
222 | 58 | |||
223 | 59 | static void tell_service_to_exit() | ||
224 | 60 | { | ||
225 | 61 | QDBusInterface iface("com.deeqt.test.control", "/control"); | ||
226 | 62 | iface.call("quit"); | ||
227 | 63 | } | ||
228 | 64 | |||
229 | 65 | class DeeListModelTest : public QObject | ||
230 | 66 | { | ||
231 | 67 | Q_OBJECT | ||
232 | 68 | |||
233 | 69 | private Q_SLOTS: | ||
234 | 70 | void initTestCase() | ||
235 | 71 | { | ||
236 | 72 | g_type_init(); | ||
237 | 73 | |||
238 | 74 | QVERIFY(wait_until_test_service_appears()); | ||
239 | 75 | } | ||
240 | 76 | |||
241 | 77 | void synchronizedTest() | ||
242 | 78 | { | ||
243 | 79 | DeeModel* model = dee_shared_model_new("com.deeqt.test.does_not_exist"); | ||
244 | 80 | |||
245 | 81 | DeeListModel model_qt; | ||
246 | 82 | QCOMPARE(model_qt.count(), 0); | ||
247 | 83 | |||
248 | 84 | model_qt.setModel(model); | ||
249 | 85 | QCOMPARE(model_qt.synchronized(), (bool)dee_shared_model_is_synchronized(DEE_SHARED_MODEL(model))); | ||
250 | 86 | } | ||
251 | 87 | |||
252 | 88 | void setExistingModelTest() | ||
253 | 89 | { | ||
254 | 90 | DeeModel* model = dee_shared_model_new("com.deeqt.test.model"); | ||
255 | 91 | |||
256 | 92 | DeeListModel model_qt; | ||
257 | 93 | QCOMPARE(model_qt.count(), 0); | ||
258 | 94 | |||
259 | 95 | model_qt.setModel(model); | ||
260 | 96 | QCOMPARE(model_qt.synchronized(), false); | ||
261 | 97 | |||
262 | 98 | while(!model_qt.synchronized()) | ||
263 | 99 | qApp->processEvents(); | ||
264 | 100 | |||
265 | 101 | QCOMPARE(model_qt.synchronized(), true); | ||
266 | 102 | QCOMPARE(model_qt.roleNames().count(), 1); | ||
267 | 103 | QCOMPARE(model_qt.roleNames()[0], QByteArray("column_0")); | ||
268 | 104 | } | ||
269 | 105 | |||
270 | 106 | void cleanupTestCase() | ||
271 | 107 | { | ||
272 | 108 | tell_service_to_exit(); | ||
273 | 109 | } | ||
274 | 110 | |||
275 | 111 | }; | ||
276 | 112 | |||
277 | 113 | QTEST_MAIN(DeeListModelTest) | ||
278 | 114 | |||
279 | 115 | #include "deelistmodeltest.moc" | ||
280 | 0 | 116 | ||
281 | === added file 'test-helper.cpp' | |||
282 | --- test-helper.cpp 1970-01-01 00:00:00 +0000 | |||
283 | +++ test-helper.cpp 2012-11-22 10:38:21 +0000 | |||
284 | @@ -0,0 +1,58 @@ | |||
285 | 1 | /* | ||
286 | 2 | * Copyright (C) 2012 Canonical, Ltd. | ||
287 | 3 | * | ||
288 | 4 | * This program is free software; you can redistribute it and/or modify | ||
289 | 5 | * it under the terms of the GNU General Public License as published by | ||
290 | 6 | * the Free Software Foundation; version 3. | ||
291 | 7 | * | ||
292 | 8 | * This program is distributed in the hope that it will be useful, | ||
293 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
294 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
295 | 11 | * GNU General Public License for more details. | ||
296 | 12 | * | ||
297 | 13 | * You should have received a copy of the GNU General Public License | ||
298 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
299 | 15 | */ | ||
300 | 16 | |||
301 | 17 | #include <QCoreApplication> | ||
302 | 18 | #include <QDBusConnection> | ||
303 | 19 | #include <QObject> | ||
304 | 20 | |||
305 | 21 | #include <dee.h> | ||
306 | 22 | |||
307 | 23 | #include <QDebug> | ||
308 | 24 | class TestControl : public QObject | ||
309 | 25 | { | ||
310 | 26 | Q_OBJECT | ||
311 | 27 | public: | ||
312 | 28 | TestControl() | ||
313 | 29 | { | ||
314 | 30 | g_type_init(); | ||
315 | 31 | DeeModel* model = dee_shared_model_new("com.deeqt.test.model"); | ||
316 | 32 | dee_model_set_schema(model, "b", NULL); | ||
317 | 33 | |||
318 | 34 | // Doc says we need to be synchronized before doing anything | ||
319 | 35 | while(!dee_shared_model_is_synchronized(DEE_SHARED_MODEL(model))) | ||
320 | 36 | qApp->processEvents(); | ||
321 | 37 | |||
322 | 38 | QDBusConnection::sessionBus().registerService("com.deeqt.test.control"); | ||
323 | 39 | QDBusConnection::sessionBus().registerObject("/control", this, QDBusConnection::ExportAllSlots); | ||
324 | 40 | } | ||
325 | 41 | |||
326 | 42 | public Q_SLOTS: | ||
327 | 43 | void quit() | ||
328 | 44 | { | ||
329 | 45 | qApp->quit(); | ||
330 | 46 | } | ||
331 | 47 | }; | ||
332 | 48 | |||
333 | 49 | int main(int argc, char *argv[]) | ||
334 | 50 | { | ||
335 | 51 | QCoreApplication a(argc, argv); | ||
336 | 52 | |||
337 | 53 | TestControl tc; | ||
338 | 54 | |||
339 | 55 | return a.exec(); | ||
340 | 56 | } | ||
341 | 57 | |||
342 | 58 | #include "test-helper.moc" |
It works fine.
I tested with unity-2d and the home lens is still working correctly.