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
=== modified file 'tests/vala/Makefile.am'
--- tests/vala/Makefile.am 2013-01-09 18:48:28 +0000
+++ tests/vala/Makefile.am 2013-01-17 09:19:21 +0000
@@ -34,14 +34,14 @@
34 dbusmock.vala \34 dbusmock.vala \
35 test-utils.vala \35 test-utils.vala \
36 test-service.vala \36 test-service.vala \
37 test-vala.vala 37 test-vala.vala
3838
39TESTS = test-runner39TESTS = test-runner
4040
41test-runner: test-vala Makefile.am41test-runner: test-vala Makefile.am
42 @echo "#!/bin/sh" > $@42 @echo "#!/bin/sh" > $@
43 @echo export G_DEBUG=fatal_criticals >> $@43 @echo export G_DEBUG=fatal_criticals >> $@
44 @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 >> $@44 @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 >> $@
45 @chmod +x $@45 @chmod +x $@
4646
47CLEANFILES = \47CLEANFILES = \
4848
=== modified file 'tests/vala/dbusmock.vala'
--- tests/vala/dbusmock.vala 2013-01-08 21:43:40 +0000
+++ tests/vala/dbusmock.vala 2013-01-17 09:19:21 +0000
@@ -17,9 +17,21 @@
17 * Authored by Ken VaDine <ken.vandine@canonical.com>17 * Authored by Ken VaDine <ken.vandine@canonical.com>
18 */18 */
1919
20/**
21 * This struct represents a particular call to a mocked method. The
22 * DBus type string corresponding to this struct is 'a(tsav)'.
23 */
24public struct CallSignature {
25 public uint64 timestamp;
26 public string method_name;
27 public Variant[] call_args;
28}
29
20[DBus (name = "org.freedesktop.DBus.Mock")]30[DBus (name = "org.freedesktop.DBus.Mock")]
21private interface DBusMockInterface : GLib.Object {31private interface DBusMockInterface : GLib.Object {
22 public abstract void AddMethod (string iface, string method, string in_s, string out_s, string params) throws IOError;32 public abstract void AddMethod (string iface, string method, string in_s, string out_s, string params) throws IOError;
33 public abstract CallSignature[] GetCalls () throws IOError;
34 public abstract void ClearCalls () throws IOError;
23}35}
2436
25namespace Friends.Test37namespace Friends.Test
@@ -54,5 +66,25 @@
54 warning (e.message);66 warning (e.message);
55 }67 }
56 }68 }
69
70 public CallSignature[] get_calls()
71 {
72 CallSignature[] calls = null;
73 try {
74 calls = dbusmock.GetCalls();
75 } catch (GLib.IOError e) {
76 warning (e.message);
77 }
78 return calls;
79 }
80
81 public void clear_calls()
82 {
83 try {
84 dbusmock.ClearCalls();
85 } catch (GLib.IOError e) {
86 warning (e.message);
87 }
88 }
57 }89 }
58}90}
5991
=== modified file 'tests/vala/test-service.vala'
--- tests/vala/test-service.vala 2013-01-14 18:06:20 +0000
+++ tests/vala/test-service.vala 2013-01-17 09:19:21 +0000
@@ -23,9 +23,11 @@
23{23{
24 public class ServiceSuite24 public class ServiceSuite
25 {25 {
26 public static DBusMock dbusmock;
27
26 public ServiceSuite ()28 public ServiceSuite ()
27 {29 {
28 var dbusmock = new DBusMock ();30 dbusmock = new DBusMock ();
29 /* Add mock methods to the dbus interface for testing31 /* Add mock methods to the dbus interface for testing
30 * python-dbusmock docs can be found at32 * python-dbusmock docs can be found at
31 * http://bazaar.launchpad.net/~pitti/python-dbusmock/trunk/view/head:/README.rst33 * http://bazaar.launchpad.net/~pitti/python-dbusmock/trunk/view/head:/README.rst
@@ -63,6 +65,7 @@
6365
64 static Friends.Service? get_service ()66 static Friends.Service? get_service ()
65 {67 {
68 dbusmock.clear_calls ();
66 Friends.Service service = null;69 Friends.Service service = null;
67 try {70 try {
68 service = new Friends.Service ();71 service = new Friends.Service ();
@@ -74,40 +77,45 @@
7477
75 internal static void test_refresh ()78 internal static void test_refresh ()
76 {79 {
80 dbusmock.clear_calls ();
77 var service = get_service ();81 var service = get_service ();
78 bool success = false;
79 try82 try
80 {83 {
81 service.refresh ();84 service.refresh ();
82 success = true;
83 }85 }
84 catch (GLib.IOError e)86 catch (GLib.IOError e)
85 {87 {
86 warning ("Failed to refresh - %s", e.message);88 warning ("Failed to refresh - %s", e.message);
87 }89 }
88 assert (success == true);90 CallSignature[] calls = dbusmock.get_calls();
8991 assert (calls.length == 1);
92 assert (calls[0].timestamp > 10000);
93 assert (calls[0].method_name == "Refresh");
94 assert (calls[0].call_args.length == 0);
90 }95 }
9196
92 internal static void test_quit ()97 internal static void test_quit ()
93 {98 {
99 dbusmock.clear_calls ();
94 var service = get_service ();100 var service = get_service ();
95 bool success = false;
96 try101 try
97 {102 {
98 service.quit ();103 service.quit ();
99 success = true;
100 }104 }
101 catch (GLib.IOError e)105 catch (GLib.IOError e)
102 {106 {
103 warning ("Failed to shutdown - %s", e.message);107 warning ("Failed to shutdown - %s", e.message);
104 }108 }
105 assert (success == true);109 CallSignature[] calls = dbusmock.get_calls();
106110 assert (calls.length == 1);
111 assert (calls[0].timestamp > 10000);
112 assert (calls[0].method_name == "Quit");
113 assert (calls[0].call_args.length == 0);
107 }114 }
108115
109 internal static void test_features ()116 internal static void test_features ()
110 {117 {
118 dbusmock.clear_calls ();
111 var service = get_service ();119 var service = get_service ();
112 string[] features = null;120 string[] features = null;
113 try121 try
@@ -120,10 +128,17 @@
120 }128 }
121 assert (features != null);129 assert (features != null);
122 assert ("send" in features);130 assert ("send" in features);
131 CallSignature[] calls = dbusmock.get_calls();
132 assert (calls.length == 1);
133 assert (calls[0].timestamp > 10000);
134 assert (calls[0].method_name == "GetFeatures");
135 assert (calls[0].call_args.length == 1);
136 assert (calls[0].call_args[0].get_string() == "twitter");
123 }137 }
124138
125 internal static void test_upload ()139 internal static void test_upload ()
126 {140 {
141 dbusmock.clear_calls ();
127 var service = get_service ();142 var service = get_service ();
128 uint acct = 1;143 uint acct = 1;
129 string uri = "file:///tmp/foo.png";144 string uri = "file:///tmp/foo.png";
@@ -141,77 +156,97 @@
141156
142 internal static void test_send_message ()157 internal static void test_send_message ()
143 {158 {
159 dbusmock.clear_calls ();
144 var service = get_service ();160 var service = get_service ();
145 uint? acct = null;161 uint? acct = null;
146 string msg = "A message";162 string msg = "A message";
147 bool success = false;
148 try163 try
149 {164 {
150 service.send_message (acct, msg);165 service.send_message (acct, msg);
151 success = true;
152 }166 }
153 catch (GLib.IOError e)167 catch (GLib.IOError e)
154 {168 {
155 warning ("Failed to SendMessage - %s", e.message);169 warning ("Failed to SendMessage - %s", e.message);
156 }170 }
157 assert (success == true);171 CallSignature[] calls = dbusmock.get_calls();
172 assert (calls.length == 1);
173 assert (calls[0].timestamp > 10000);
174 assert (calls[0].method_name == "SendMessage");
175 assert (calls[0].call_args.length == 1);
176 assert (calls[0].call_args[0].get_string() == "A message");
158 }177 }
159178
160 internal static void test_send_message_with_account ()179 internal static void test_send_message_with_account ()
161 {180 {
181 dbusmock.clear_calls ();
162 var service = get_service ();182 var service = get_service ();
163 uint acct = 1;183 uint acct = 1;
164 string msg = "A message";184 string msg = "A message";
165 bool success = false;
166 try185 try
167 {186 {
168 service.send_message (acct, msg);187 service.send_message (acct, msg);
169 success = true;
170 }188 }
171 catch (GLib.IOError e)189 catch (GLib.IOError e)
172 {190 {
173 warning ("Failed to SendMessage - %s", e.message);191 warning ("Failed to SendMessage - %s", e.message);
174 }192 }
175 assert (success == true);193 CallSignature[] calls = dbusmock.get_calls();
194 assert (calls.length == 1);
195 assert (calls[0].timestamp > 10000);
196 assert (calls[0].method_name == "Do");
197 assert (calls[0].call_args.length == 3);
198 assert (calls[0].call_args[0].get_string() == "send");
199 assert (calls[0].call_args[1].get_string() == "1");
200 assert (calls[0].call_args[2].get_string() == "A message");
176 }201 }
177202
178 internal static void test_send_reply ()203 internal static void test_send_reply ()
179 {204 {
205 dbusmock.clear_calls ();
180 var service = get_service ();206 var service = get_service ();
181 uint acct = 1;207 uint acct = 1;
182 string msg = "A message";208 string msg = "A message";
183 string msg_id = "100";209 string msg_id = "100";
184 bool success = false;
185 try210 try
186 {211 {
187 service.send_reply (acct, msg_id, msg);212 service.send_reply (acct, msg_id, msg);
188 success = true;
189 }213 }
190 catch (GLib.IOError e)214 catch (GLib.IOError e)
191 {215 {
192 warning ("Failed to SendReply - %s", e.message);216 warning ("Failed to SendReply - %s", e.message);
193 }217 }
194 assert (success == true);218 CallSignature[] calls = dbusmock.get_calls();
219 assert (calls.length == 1);
220 assert (calls[0].timestamp > 10000);
221 assert (calls[0].method_name == "SendReply");
222 assert (calls[0].call_args.length == 3);
223 assert (calls[0].call_args[0].get_string() == "A message");
224 assert (calls[0].call_args[1].get_string() == "1");
225 assert (calls[0].call_args[2].get_string() == "100");
195 }226 }
196227
197 internal static void test_clear_indicators ()228 internal static void test_clear_indicators ()
198 {229 {
230 dbusmock.clear_calls ();
199 var service = get_service ();231 var service = get_service ();
200 bool success = false;
201 try232 try
202 {233 {
203 service.messaging_menu_clear ();234 service.messaging_menu_clear ();
204 success = true;
205 }235 }
206 catch (GLib.IOError e)236 catch (GLib.IOError e)
207 {237 {
208 warning ("Failed to clear indicators - %s", e.message);238 warning ("Failed to clear indicators - %s", e.message);
209 }239 }
210 assert (success == true);240 CallSignature[] calls = dbusmock.get_calls();
241 assert (calls.length == 1);
242 assert (calls[0].timestamp > 10000);
243 assert (calls[0].method_name == "ClearIndicators");
244 assert (calls[0].call_args.length == 0);
211 }245 }
212246
213 internal static void test_url_shorten ()247 internal static void test_url_shorten ()
214 {248 {
249 dbusmock.clear_calls ();
215 var service = get_service ();250 var service = get_service ();
216 string result = "";251 string result = "";
217 try252 try
@@ -223,6 +258,13 @@
223 warning ("Failed to shorten URL - %s", e.message);258 warning ("Failed to shorten URL - %s", e.message);
224 }259 }
225 assert (result == "http://is.gd/short");260 assert (result == "http://is.gd/short");
261 CallSignature[] calls = dbusmock.get_calls();
262 assert (calls.length == 1);
263 assert (calls[0].timestamp > 10000);
264 assert (calls[0].method_name == "URLShorten");
265 assert (calls[0].call_args.length == 1);
266 assert (calls[0].call_args[0].get_string() ==
267 "http://example.com/really/really/long");
226 }268 }
227 }269 }
228}270}

Subscribers

People subscribed via source and target branches