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