Merge lp:~robru/libfriends/dbusmock into lp:libfriends

Proposed by Robert Bruce Park
Status: Merged
Approved by: Ken VanDine
Approved revision: 54
Merged at revision: 52
Proposed branch: lp:~robru/libfriends/dbusmock
Merge into: lp:libfriends
Diff against target: 293 lines (+97/-23)
3 files modified
tests/vala/Makefile.am (+2/-2)
tests/vala/dbusmock.vala (+32/-0)
tests/vala/test-service.vala (+63/-21)
To merge this branch: bzr merge lp:~robru/libfriends/dbusmock
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Review via email: mp+143649@code.launchpad.net

Description of the change

Begin using the new ClearCalls/GetCalls dbusmock API in the libfriends testsuite.

Note that this commit introduces a hard dep on python-dbusmock 0.4.0, which is not yet released, but has been backported as the python-dbusmock package in the super-friends/daily PPA.

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks and works great

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/vala/Makefile.am'
2--- tests/vala/Makefile.am 2013-01-09 18:48:28 +0000
3+++ tests/vala/Makefile.am 2013-01-17 09:19:21 +0000
4@@ -34,14 +34,14 @@
5 dbusmock.vala \
6 test-utils.vala \
7 test-service.vala \
8- test-vala.vala
9+ test-vala.vala
10
11 TESTS = test-runner
12
13 test-runner: test-vala Makefile.am
14 @echo "#!/bin/sh" > $@
15 @echo export G_DEBUG=fatal_criticals >> $@
16- @echo xvfb-run $(DBUS_RUNNER) --task python3 -p -m -p dbusmock -p com.canonical.Friends.Service -p /com/canonical/friends/Service -p com.canonical.Friends.Service --task-name DBusService --ignore-return --task ./test-vala --wait-for com.canonical.Friends.Service --task-name Service >> $@
17+ @echo xvfb-run $(DBUS_RUNNER) --task python3 -p -m -p dbusmock -p com.canonical.Friends.Service -p /com/canonical/friends/Service -p com.canonical.Friends.Service -p --logfile -p /dev/null --task-name DBusService --ignore-return --task ./test-vala --wait-for com.canonical.Friends.Service --task-name Service >> $@
18 @chmod +x $@
19
20 CLEANFILES = \
21
22=== modified file 'tests/vala/dbusmock.vala'
23--- tests/vala/dbusmock.vala 2013-01-08 21:43:40 +0000
24+++ tests/vala/dbusmock.vala 2013-01-17 09:19:21 +0000
25@@ -17,9 +17,21 @@
26 * Authored by Ken VaDine <ken.vandine@canonical.com>
27 */
28
29+/**
30+ * This struct represents a particular call to a mocked method. The
31+ * DBus type string corresponding to this struct is 'a(tsav)'.
32+ */
33+public struct CallSignature {
34+ public uint64 timestamp;
35+ public string method_name;
36+ public Variant[] call_args;
37+}
38+
39 [DBus (name = "org.freedesktop.DBus.Mock")]
40 private interface DBusMockInterface : GLib.Object {
41 public abstract void AddMethod (string iface, string method, string in_s, string out_s, string params) throws IOError;
42+ public abstract CallSignature[] GetCalls () throws IOError;
43+ public abstract void ClearCalls () throws IOError;
44 }
45
46 namespace Friends.Test
47@@ -54,5 +66,25 @@
48 warning (e.message);
49 }
50 }
51+
52+ public CallSignature[] get_calls()
53+ {
54+ CallSignature[] calls = null;
55+ try {
56+ calls = dbusmock.GetCalls();
57+ } catch (GLib.IOError e) {
58+ warning (e.message);
59+ }
60+ return calls;
61+ }
62+
63+ public void clear_calls()
64+ {
65+ try {
66+ dbusmock.ClearCalls();
67+ } catch (GLib.IOError e) {
68+ warning (e.message);
69+ }
70+ }
71 }
72 }
73
74=== modified file 'tests/vala/test-service.vala'
75--- tests/vala/test-service.vala 2013-01-14 18:06:20 +0000
76+++ tests/vala/test-service.vala 2013-01-17 09:19:21 +0000
77@@ -23,9 +23,11 @@
78 {
79 public class ServiceSuite
80 {
81+ public static DBusMock dbusmock;
82+
83 public ServiceSuite ()
84 {
85- var dbusmock = new DBusMock ();
86+ dbusmock = new DBusMock ();
87 /* Add mock methods to the dbus interface for testing
88 * python-dbusmock docs can be found at
89 * http://bazaar.launchpad.net/~pitti/python-dbusmock/trunk/view/head:/README.rst
90@@ -63,6 +65,7 @@
91
92 static Friends.Service? get_service ()
93 {
94+ dbusmock.clear_calls ();
95 Friends.Service service = null;
96 try {
97 service = new Friends.Service ();
98@@ -74,40 +77,45 @@
99
100 internal static void test_refresh ()
101 {
102+ dbusmock.clear_calls ();
103 var service = get_service ();
104- bool success = false;
105 try
106 {
107 service.refresh ();
108- success = true;
109 }
110 catch (GLib.IOError e)
111 {
112 warning ("Failed to refresh - %s", e.message);
113 }
114- assert (success == true);
115-
116+ CallSignature[] calls = dbusmock.get_calls();
117+ assert (calls.length == 1);
118+ assert (calls[0].timestamp > 10000);
119+ assert (calls[0].method_name == "Refresh");
120+ assert (calls[0].call_args.length == 0);
121 }
122
123 internal static void test_quit ()
124 {
125+ dbusmock.clear_calls ();
126 var service = get_service ();
127- bool success = false;
128 try
129 {
130 service.quit ();
131- success = true;
132 }
133 catch (GLib.IOError e)
134 {
135 warning ("Failed to shutdown - %s", e.message);
136 }
137- assert (success == true);
138-
139+ CallSignature[] calls = dbusmock.get_calls();
140+ assert (calls.length == 1);
141+ assert (calls[0].timestamp > 10000);
142+ assert (calls[0].method_name == "Quit");
143+ assert (calls[0].call_args.length == 0);
144 }
145
146 internal static void test_features ()
147 {
148+ dbusmock.clear_calls ();
149 var service = get_service ();
150 string[] features = null;
151 try
152@@ -120,10 +128,17 @@
153 }
154 assert (features != null);
155 assert ("send" in features);
156+ CallSignature[] calls = dbusmock.get_calls();
157+ assert (calls.length == 1);
158+ assert (calls[0].timestamp > 10000);
159+ assert (calls[0].method_name == "GetFeatures");
160+ assert (calls[0].call_args.length == 1);
161+ assert (calls[0].call_args[0].get_string() == "twitter");
162 }
163
164 internal static void test_upload ()
165 {
166+ dbusmock.clear_calls ();
167 var service = get_service ();
168 uint acct = 1;
169 string uri = "file:///tmp/foo.png";
170@@ -141,77 +156,97 @@
171
172 internal static void test_send_message ()
173 {
174+ dbusmock.clear_calls ();
175 var service = get_service ();
176 uint? acct = null;
177 string msg = "A message";
178- bool success = false;
179 try
180 {
181 service.send_message (acct, msg);
182- success = true;
183 }
184 catch (GLib.IOError e)
185 {
186 warning ("Failed to SendMessage - %s", e.message);
187 }
188- assert (success == true);
189+ CallSignature[] calls = dbusmock.get_calls();
190+ assert (calls.length == 1);
191+ assert (calls[0].timestamp > 10000);
192+ assert (calls[0].method_name == "SendMessage");
193+ assert (calls[0].call_args.length == 1);
194+ assert (calls[0].call_args[0].get_string() == "A message");
195 }
196
197 internal static void test_send_message_with_account ()
198 {
199+ dbusmock.clear_calls ();
200 var service = get_service ();
201 uint acct = 1;
202 string msg = "A message";
203- bool success = false;
204 try
205 {
206 service.send_message (acct, msg);
207- success = true;
208 }
209 catch (GLib.IOError e)
210 {
211 warning ("Failed to SendMessage - %s", e.message);
212 }
213- assert (success == true);
214+ CallSignature[] calls = dbusmock.get_calls();
215+ assert (calls.length == 1);
216+ assert (calls[0].timestamp > 10000);
217+ assert (calls[0].method_name == "Do");
218+ assert (calls[0].call_args.length == 3);
219+ assert (calls[0].call_args[0].get_string() == "send");
220+ assert (calls[0].call_args[1].get_string() == "1");
221+ assert (calls[0].call_args[2].get_string() == "A message");
222 }
223
224 internal static void test_send_reply ()
225 {
226+ dbusmock.clear_calls ();
227 var service = get_service ();
228 uint acct = 1;
229 string msg = "A message";
230 string msg_id = "100";
231- bool success = false;
232 try
233 {
234 service.send_reply (acct, msg_id, msg);
235- success = true;
236 }
237 catch (GLib.IOError e)
238 {
239 warning ("Failed to SendReply - %s", e.message);
240 }
241- assert (success == true);
242+ CallSignature[] calls = dbusmock.get_calls();
243+ assert (calls.length == 1);
244+ assert (calls[0].timestamp > 10000);
245+ assert (calls[0].method_name == "SendReply");
246+ assert (calls[0].call_args.length == 3);
247+ assert (calls[0].call_args[0].get_string() == "A message");
248+ assert (calls[0].call_args[1].get_string() == "1");
249+ assert (calls[0].call_args[2].get_string() == "100");
250 }
251
252 internal static void test_clear_indicators ()
253 {
254+ dbusmock.clear_calls ();
255 var service = get_service ();
256- bool success = false;
257 try
258 {
259 service.messaging_menu_clear ();
260- success = true;
261 }
262 catch (GLib.IOError e)
263 {
264 warning ("Failed to clear indicators - %s", e.message);
265 }
266- assert (success == true);
267+ CallSignature[] calls = dbusmock.get_calls();
268+ assert (calls.length == 1);
269+ assert (calls[0].timestamp > 10000);
270+ assert (calls[0].method_name == "ClearIndicators");
271+ assert (calls[0].call_args.length == 0);
272 }
273
274 internal static void test_url_shorten ()
275 {
276+ dbusmock.clear_calls ();
277 var service = get_service ();
278 string result = "";
279 try
280@@ -223,6 +258,13 @@
281 warning ("Failed to shorten URL - %s", e.message);
282 }
283 assert (result == "http://is.gd/short");
284+ CallSignature[] calls = dbusmock.get_calls();
285+ assert (calls.length == 1);
286+ assert (calls[0].timestamp > 10000);
287+ assert (calls[0].method_name == "URLShorten");
288+ assert (calls[0].call_args.length == 1);
289+ assert (calls[0].call_args[0].get_string() ==
290+ "http://example.com/really/really/long");
291 }
292 }
293 }

Subscribers

People subscribed via source and target branches