Merge lp:~pete-woods/libqtdbusmock/first-test into lp:libqtdbusmock

Proposed by Pete Woods
Status: Merged
Merged at revision: 19
Proposed branch: lp:~pete-woods/libqtdbusmock/first-test
Merge into: lp:libqtdbusmock
Diff against target: 211 lines (+92/-72)
4 files modified
src/libqtdbusmock/DBusMock.cpp (+4/-4)
tests/CMakeLists.txt (+1/-0)
tests/data/valgrind.suppression (+0/-68)
tests/libqtdbusmock/TestDBusMock.cpp (+87/-0)
To merge this branch: bzr merge lp:~pete-woods/libqtdbusmock/first-test
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Unity Team Pending
Review via email: mp+178938@code.launchpad.net

Commit message

Add a test case

Description of the change

Add a test case

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/libqtdbusmock/DBusMock.cpp'
2--- src/libqtdbusmock/DBusMock.cpp 2013-08-05 12:09:47 +0000
3+++ src/libqtdbusmock/DBusMock.cpp 2013-08-07 14:57:33 +0000
4@@ -54,7 +54,7 @@
5 void DBusMock::registerNetworkManager() {
6 d->m_testRunner.registerService(
7 DBusServicePtr(
8- new QProcessDBusService(NM_DBUS_INTERFACE,
9+ new QProcessDBusService(NM_DBUS_SERVICE,
10 QDBusConnection::SystemBus, "python3",
11 QStringList() << "-m" << "dbusmock" << "--template"
12 << "networkmanager")));
13@@ -63,14 +63,14 @@
14 void DBusMock::registerCustomMock(const QString &name, const QString &path,
15 const QString &interface, QDBusConnection::BusType busType) {
16 QStringList args;
17+ args << "-m" << "dbusmock";
18 if (busType == QDBusConnection::SystemBus) {
19 args << "-s";
20 }
21- args << "-m" << "dbusmock" << name << path << interface;
22+ args << name << path << interface;
23 d->m_testRunner.registerService(
24 DBusServicePtr(
25- new QProcessDBusService(interface, busType, "python3",
26- args)));
27+ new QProcessDBusService(name, busType, "python3", args)));
28 }
29
30 NetworkManagerMockInterface & DBusMock::networkManagerInterface() {
31
32=== modified file 'tests/CMakeLists.txt'
33--- tests/CMakeLists.txt 2013-08-05 11:38:16 +0000
34+++ tests/CMakeLists.txt 2013-08-07 14:57:33 +0000
35@@ -12,6 +12,7 @@
36 set(
37 UNIT_TESTS_SRC
38 main.cpp
39+ libqtdbusmock/TestDBusMock.cpp
40 )
41
42 add_executable(
43
44=== modified file 'tests/data/valgrind.suppression'
45--- tests/data/valgrind.suppression 2013-08-01 15:17:32 +0000
46+++ tests/data/valgrind.suppression 2013-08-07 14:57:33 +0000
47@@ -25,71 +25,3 @@
48 ...
49 fun:g_main_context_new
50 }
51-
52-###############################
53-# GObject rules
54-###############################
55-
56-{
57- <insert_a_suppression_name_here>
58- Memcheck:Leak
59- ...
60- fun:g_type_register_static
61-}
62-
63-{
64- <insert_a_suppression_name_here>
65- Memcheck:Leak
66- ...
67- fun:g_type_register_fundamental
68-}
69-
70-{
71- <insert_a_suppression_name_here>
72- Memcheck:Leak
73- ...
74- fun:type_node_fundamental_new_W
75-}
76-
77-{
78- <insert_a_suppression_name_here>
79- Memcheck:Leak
80- ...
81- fun:type_data_make_W
82-}
83-
84-{
85- <insert_a_suppression_name_here>
86- Memcheck:Leak
87- ...
88- fun:g_type_add_interface_static
89-}
90-
91-{
92- <insert_a_suppression_name_here>
93- Memcheck:Leak
94- ...
95- fun:type_iface_vtable_base_init_Wm
96-}
97-
98-{
99- <insert_a_suppression_name_here>
100- Memcheck:Leak
101- ...
102- fun:g_dbus_interface_skeleton_class_intern_init
103-}
104-
105-{
106- <insert_a_suppression_name_here>
107- Memcheck:Leak
108- ...
109- fun:g_signal_type_cclosure_new
110-}
111-
112-{
113- <insert_a_suppression_name_here>
114- Memcheck:Leak
115- fun:calloc
116- fun:g_malloc0
117- fun:g_type_class_ref
118-}
119
120=== added directory 'tests/libqtdbusmock'
121=== added file 'tests/libqtdbusmock/TestDBusMock.cpp'
122--- tests/libqtdbusmock/TestDBusMock.cpp 1970-01-01 00:00:00 +0000
123+++ tests/libqtdbusmock/TestDBusMock.cpp 2013-08-07 14:57:33 +0000
124@@ -0,0 +1,87 @@
125+/*
126+ * Copyright (C) 2013 Canonical, Ltd.
127+ *
128+ * This program is free software: you can redistribute it and/or modify it
129+ * under the terms of the GNU General Public License version 3, as published
130+ * by the Free Software Foundation.
131+ *
132+ * This program is distributed in the hope that it will be useful, but
133+ * WITHOUT ANY WARRANTY; without even the implied warranties of
134+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
135+ * PURPOSE. See the GNU General Public License for more details.
136+ *
137+ * You should have received a copy of the GNU General Public License along
138+ * with this program. If not, see <http://www.gnu.org/licenses/>.
139+ *
140+ * Author: Pete Woods <pete.woods@canonical.com>
141+ */
142+
143+#include <libqtdbusmock/DBusMock.h>
144+#include <QCoreApplication>
145+
146+#include <gmock/gmock.h>
147+#include <gtest/gtest.h>
148+
149+using namespace std;
150+using namespace testing;
151+using namespace QtDBusTest;
152+using namespace QtDBusMock;
153+
154+namespace {
155+
156+class TestDBusMock: public Test {
157+protected:
158+ TestDBusMock() :
159+ dbusMock(dbusTestRunner) {
160+ }
161+
162+ virtual ~TestDBusMock() {
163+ }
164+
165+ bool processListContains(const char *str) {
166+ QProcess pgrep;
167+ pgrep.start("ps",
168+ QStringList() << "--no-headers" << "--ppid"
169+ << QString::number(QCoreApplication::applicationPid())
170+ << "-o" << "args");
171+ pgrep.waitForFinished();
172+ pgrep.waitForReadyRead();
173+
174+ return pgrep.readAll().contains(str);
175+ }
176+
177+ DBusTestRunner dbusTestRunner;
178+
179+ DBusMock dbusMock;
180+};
181+
182+TEST_F(TestDBusMock, StartsDBusMockSession) {
183+ dbusMock.registerCustomMock("test.name", "/test/object", "test.Interface",
184+ QDBusConnection::SessionBus);
185+ dbusTestRunner.startServices();
186+
187+ EXPECT_TRUE(
188+ processListContains(
189+ "python3 -m dbusmock test.name /test/object test.Interface"));
190+}
191+
192+TEST_F(TestDBusMock, StartsDBusMockSystem) {
193+ dbusMock.registerCustomMock("test.name2", "/test/object2",
194+ "test.Interface2", QDBusConnection::SystemBus);
195+ dbusTestRunner.startServices();
196+
197+ EXPECT_TRUE(
198+ processListContains(
199+ "python3 -m dbusmock -s test.name2 /test/object2 test.Interface2"));
200+}
201+
202+TEST_F(TestDBusMock, StartsDBusMockWithTemplate) {
203+ dbusMock.registerNetworkManager();
204+ dbusTestRunner.startServices();
205+
206+ EXPECT_TRUE(
207+ processListContains(
208+ "python3 -m dbusmock --template networkmanager"));
209+}
210+
211+} // namespace

Subscribers

People subscribed via source and target branches

to all changes: