Merge lp:~aacid/dee-qt/fixsetmodelsharedmodels into lp:dee-qt/0.2

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
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
Tiago Salem Herrmann (tiagosh) wrote :

It works fine.
I tested with unity-2d and the home lens is still working correctly.

review: Approve
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://jenkins.qa.ubuntu.com/job/automerge-dee-qt/16/console reported an error when processing this lp:~aacid/dee-qt/fixsetmodelsharedmodels branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-dee-qt/17/console reported an error when processing this lp:~aacid/dee-qt/fixsetmodelsharedmodels branch.
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
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2012-11-12 10:53:16 +0000
+++ CMakeLists.txt 2012-11-22 10:38:21 +0000
@@ -40,6 +40,7 @@
40 ${QT_INCLUDE_DIR}40 ${QT_INCLUDE_DIR}
41 ${QT_QTCORE_INCLUDE_DIR}41 ${QT_QTCORE_INCLUDE_DIR}
42 ${QT_QTDECLARATIVE_INCLUDE_DIR}42 ${QT_QTDECLARATIVE_INCLUDE_DIR}
43 ${QT_QTDBUS_INCLUDE_DIR}
43 ${DEE_INCLUDE_DIRS}44 ${DEE_INCLUDE_DIRS}
44 ${QT_QTTEST_INCLUDE_DIR}45 ${QT_QTTEST_INCLUDE_DIR}
45 )46 )
@@ -119,5 +120,15 @@
119qt4_generate_moc(conversiontest.cpp conversiontest.moc)120qt4_generate_moc(conversiontest.cpp conversiontest.moc)
120add_executable(conversiontest conversiontest.cpp conversiontest.moc)121add_executable(conversiontest conversiontest.cpp conversiontest.moc)
121target_link_libraries(conversiontest ${QT_QTTEST_LIBRARIES} QtDee)122target_link_libraries(conversiontest ${QT_QTTEST_LIBRARIES} QtDee)
122add_test(NAME conversiontest COMMAND "${CMAKE_CURRENT_BINARY_DIR}/conversiontest" "-xunitxml" "-o" "conversiontest-xunit.xml")123add_test(NAME conversiontest COMMAND "dbus-test-runner" "--task" "${CMAKE_CURRENT_BINARY_DIR}/conversiontest" "-p" "-xunitxml" "-p" "-o" "-p" "conversiontest-xunit.xml")
123set_property(TEST conversiontest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.")124set_property(TEST conversiontest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.")
125
126qt4_generate_moc(test-helper.cpp test-helper.moc)
127add_executable(test-helper test-helper.cpp test-helper.moc)
128target_link_libraries(test-helper ${QT_QTCORE_LIBRARIES} ${QT_QTDBUS_LIBRARIES} ${DEE_LDFLAGS})
129
130qt4_generate_moc(deelistmodeltest.cpp deelistmodeltest.moc)
131add_executable(deelistmodeltest deelistmodeltest.cpp deelistmodeltest.moc)
132target_link_libraries(deelistmodeltest ${QT_QTTEST_LIBRARIES} ${QT_QTDBUS_LIBRARIES} QtDee)
133add_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")
134set_property(TEST deelistmodeltest PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=.")
124135
=== modified file 'conversiontest.cpp'
--- conversiontest.cpp 2012-11-12 09:32:44 +0000
+++ conversiontest.cpp 2012-11-22 10:38:21 +0000
@@ -33,9 +33,13 @@
3333
34 void GVariantToQVariantConversionTest()34 void GVariantToQVariantConversionTest()
35 {35 {
36 DeeModel* model = dee_shared_model_new("com.dee-qt.test");36 DeeModel* model = dee_shared_model_new("com.deeqt.conversiontest");
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);
3838
39 // Doc says we need to be synchronized before doing anything
40 while(!dee_shared_model_is_synchronized(DEE_SHARED_MODEL(model)))
41 qApp->processEvents();
42
39 GVariant **tuples = g_new(GVariant *, 2);43 GVariant **tuples = g_new(GVariant *, 2);
4044
41 GVariant **t1 = g_new(GVariant *, 2);45 GVariant **t1 = g_new(GVariant *, 2);
4246
=== modified file 'debian/control'
--- debian/control 2012-11-12 10:53:16 +0000
+++ debian/control 2012-11-22 10:38:21 +0000
@@ -3,7 +3,7 @@
3Priority: optional3Priority: optional
4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>4Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
5XSBC-Original-Maintainer: Olivier Tilloy <olivier.tilloy@canonical.com>5XSBC-Original-Maintainer: Olivier Tilloy <olivier.tilloy@canonical.com>
6Build-Depends: cdbs, debhelper (>= 7), cmake, libqt4-dev (>= 4.7), libdee-dev (>= 1.0.0)6Build-Depends: cdbs, debhelper (>= 7), cmake, libqt4-dev (>= 4.7), libdee-dev (>= 1.0.0), dbus-test-runner
7Standards-Version: 3.9.17Standards-Version: 3.9.1
8Vcs-Bzr: http://bazaar.launchpad.net/~unity-2d-team/dee-qt/trunk8Vcs-Bzr: http://bazaar.launchpad.net/~unity-2d-team/dee-qt/trunk
99
1010
=== modified file 'debian/rules'
--- debian/rules 2010-12-24 02:57:22 +0000
+++ debian/rules 2012-11-22 10:38:21 +0000
@@ -1,6 +1,8 @@
1#!/usr/bin/make -f1#!/usr/bin/make -f
2# -*- makefile -*-2# -*- makefile -*-
33
4DEB_MAKE_CHECK_TARGET = test
5
4include /usr/share/cdbs/1/rules/debhelper.mk6include /usr/share/cdbs/1/rules/debhelper.mk
5include /usr/share/cdbs/1/class/cmake.mk7include /usr/share/cdbs/1/class/cmake.mk
68
79
=== modified file 'deelistmodel.cpp'
--- deelistmodel.cpp 2012-11-12 09:32:44 +0000
+++ deelistmodel.cpp 2012-11-22 10:38:21 +0000
@@ -85,6 +85,7 @@
85 void connectToDeeModel(DeeModel *model);85 void connectToDeeModel(DeeModel *model);
86 void disconnectFromDeeModel();86 void disconnectFromDeeModel();
87 void createRoles();87 void createRoles();
88 bool synchronized() const;
8889
89 /* GObject signal handlers for m_deeModel */90 /* GObject signal handlers for m_deeModel */
90 static void onSynchronizedChanged(GObject* emitter, GParamSpec *pspec, DeeListModel* model);91 static void onSynchronizedChanged(GObject* emitter, GParamSpec *pspec, DeeListModel* model);
@@ -96,10 +97,9 @@
96 DeeModel* m_deeModel;97 DeeModel* m_deeModel;
97 QString m_name;98 QString m_name;
98 int m_count;99 int m_count;
99 bool m_isLocal;
100};100};
101101
102DeeListModelPrivate::DeeListModelPrivate(DeeListModel* parent) : m_parent(parent), m_deeModel(NULL), m_count(0), m_isLocal(false)102DeeListModelPrivate::DeeListModelPrivate(DeeListModel* parent) : m_parent(parent), m_deeModel(NULL), m_count(0)
103{103{
104}104}
105105
@@ -137,7 +137,6 @@
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);
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);
139 }139 }
140 m_isLocal = false;
141}140}
142141
143void142void
@@ -149,12 +148,31 @@
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);
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);
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);
152 m_isLocal = true;151 if (synchronized())
153 createRoles();152 {
154 m_count = dee_model_get_n_rows(m_deeModel);153 createRoles();
155 m_parent->reset();154 m_count = dee_model_get_n_rows(m_deeModel);
156 Q_EMIT m_parent->countChanged();155 m_parent->reset();
156 Q_EMIT m_parent->countChanged();
157 }
158 else
159 {
160 g_signal_connect(m_deeModel, "notify::synchronized", G_CALLBACK(onSynchronizedChanged), m_parent);
161 }
162}
157163
164bool
165DeeListModelPrivate::synchronized() const
166{
167 if (m_deeModel == NULL) {
168 return false;
169 } else {
170 if (DEE_IS_SHARED_MODEL(m_deeModel)) {
171 return dee_shared_model_is_synchronized(DEE_SHARED_MODEL(m_deeModel));
172 } else {
173 return true;
174 }
175 }
158}176}
159177
160void178void
@@ -296,15 +314,7 @@
296bool314bool
297DeeListModel::synchronized() const315DeeListModel::synchronized() const
298{316{
299 if (d->m_deeModel == NULL) {317 return d->synchronized();
300 return false;
301 } else {
302 if (d->m_isLocal) {
303 return true;
304 } else {
305 return dee_shared_model_is_synchronized(DEE_SHARED_MODEL(d->m_deeModel));
306 }
307 }
308}318}
309319
310int320int
311321
=== added file 'deelistmodeltest.cpp'
--- deelistmodeltest.cpp 1970-01-01 00:00:00 +0000
+++ deelistmodeltest.cpp 2012-11-22 10:38:21 +0000
@@ -0,0 +1,115 @@
1/*
2 * Copyright (C) 2012 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
17#include <QtTest>
18#include <QObject>
19#include <QDBusInterface>
20
21#include "deelistmodel.h"
22
23#include <dee.h>
24
25static bool wait_until_test_service_appears()
26{
27 bool have_name = false;
28 bool timeout_reached = false;
29
30 auto timeout_cb = [](gpointer data) -> gboolean
31 {
32 *(bool*)data = true;
33 return FALSE;
34 };
35
36 auto callback = [](GDBusConnection * conn,
37 const char * name,
38 const char * name_owner,
39 gpointer user_data)
40 {
41 *(bool*)user_data = true;
42 };
43
44 g_bus_watch_name(G_BUS_TYPE_SESSION,
45 "com.deeqt.test.control",
46 G_BUS_NAME_WATCHER_FLAGS_NONE,
47 callback,
48 NULL,
49 &have_name,
50 NULL);
51 g_timeout_add(10000, timeout_cb, &timeout_reached);
52
53 while (!have_name && !timeout_reached)
54 g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
55
56 return (have_name && !timeout_reached);
57}
58
59static void tell_service_to_exit()
60{
61 QDBusInterface iface("com.deeqt.test.control", "/control");
62 iface.call("quit");
63}
64
65class DeeListModelTest : public QObject
66{
67 Q_OBJECT
68
69private Q_SLOTS:
70 void initTestCase()
71 {
72 g_type_init();
73
74 QVERIFY(wait_until_test_service_appears());
75 }
76
77 void synchronizedTest()
78 {
79 DeeModel* model = dee_shared_model_new("com.deeqt.test.does_not_exist");
80
81 DeeListModel model_qt;
82 QCOMPARE(model_qt.count(), 0);
83
84 model_qt.setModel(model);
85 QCOMPARE(model_qt.synchronized(), (bool)dee_shared_model_is_synchronized(DEE_SHARED_MODEL(model)));
86 }
87
88 void setExistingModelTest()
89 {
90 DeeModel* model = dee_shared_model_new("com.deeqt.test.model");
91
92 DeeListModel model_qt;
93 QCOMPARE(model_qt.count(), 0);
94
95 model_qt.setModel(model);
96 QCOMPARE(model_qt.synchronized(), false);
97
98 while(!model_qt.synchronized())
99 qApp->processEvents();
100
101 QCOMPARE(model_qt.synchronized(), true);
102 QCOMPARE(model_qt.roleNames().count(), 1);
103 QCOMPARE(model_qt.roleNames()[0], QByteArray("column_0"));
104 }
105
106 void cleanupTestCase()
107 {
108 tell_service_to_exit();
109 }
110
111};
112
113QTEST_MAIN(DeeListModelTest)
114
115#include "deelistmodeltest.moc"
0116
=== added file 'test-helper.cpp'
--- test-helper.cpp 1970-01-01 00:00:00 +0000
+++ test-helper.cpp 2012-11-22 10:38:21 +0000
@@ -0,0 +1,58 @@
1/*
2 * Copyright (C) 2012 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
17#include <QCoreApplication>
18#include <QDBusConnection>
19#include <QObject>
20
21#include <dee.h>
22
23#include <QDebug>
24class TestControl : public QObject
25{
26 Q_OBJECT
27public:
28 TestControl()
29 {
30 g_type_init();
31 DeeModel* model = dee_shared_model_new("com.deeqt.test.model");
32 dee_model_set_schema(model, "b", NULL);
33
34 // Doc says we need to be synchronized before doing anything
35 while(!dee_shared_model_is_synchronized(DEE_SHARED_MODEL(model)))
36 qApp->processEvents();
37
38 QDBusConnection::sessionBus().registerService("com.deeqt.test.control");
39 QDBusConnection::sessionBus().registerObject("/control", this, QDBusConnection::ExportAllSlots);
40 }
41
42public Q_SLOTS:
43 void quit()
44 {
45 qApp->quit();
46 }
47};
48
49int main(int argc, char *argv[])
50{
51 QCoreApplication a(argc, argv);
52
53 TestControl tc;
54
55 return a.exec();
56}
57
58#include "test-helper.moc"

Subscribers

People subscribed via source and target branches