Merge lp:~attente/indicator-keyboard/fix-tests-gdk-display-error into lp:indicator-keyboard
- fix-tests-gdk-display-error
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Lars Karlitski |
Approved revision: | 241 |
Merged at revision: | 251 |
Proposed branch: | lp:~attente/indicator-keyboard/fix-tests-gdk-display-error |
Merge into: | lp:indicator-keyboard |
Diff against target: |
1427 lines (+723/-668) 3 files modified
tests/Makefile.am (+2/-1) tests/fixture.vala (+125/-0) tests/main.vala (+596/-667) |
To merge this branch: | bzr merge lp:~attente/indicator-keyboard/fix-tests-gdk-display-error |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Lars Karlitski (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+202152@code.launchpad.net |
Commit message
Fix tests by restoring DISPLAY's value.
Description of the change
Fix tests by restoring DISPLAY's value.
PS Jenkins bot (ps-jenkins) wrote : | # |
Lars Karlitski (larsu) wrote : | # |
I think you could have just removed the Source.remove() lines in r238. Or can something other than the timeouts quit the loop?
Why does re-setting DISPLAY fix the error? Is it unset by one of the tests?
- 240. By William Hua
-
Add fixture class from libunity.
- 241. By William Hua
-
Use fixture class.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:241
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'tests/Makefile.am' |
2 | --- tests/Makefile.am 2013-07-23 17:16:26 +0000 |
3 | +++ tests/Makefile.am 2014-01-29 16:00:28 +0000 |
4 | @@ -8,7 +8,8 @@ |
5 | AM_VALAFLAGS = --metadatadir $(top_srcdir)/deps \ |
6 | --vapidir $(top_srcdir)/deps |
7 | |
8 | -indicator_keyboard_tests_SOURCES = main.vala \ |
9 | +indicator_keyboard_tests_SOURCES = main.vala \ |
10 | + fixture.vala \ |
11 | config.vala |
12 | indicator_keyboard_tests_VALAFLAGS = $(AM_VALAFLAGS) \ |
13 | --pkg gio-2.0 |
14 | |
15 | === added file 'tests/fixture.vala' |
16 | --- tests/fixture.vala 1970-01-01 00:00:00 +0000 |
17 | +++ tests/fixture.vala 2014-01-29 16:00:28 +0000 |
18 | @@ -0,0 +1,125 @@ |
19 | +/* |
20 | + * Copyright (C) 2014 Canonical Ltd. |
21 | + * |
22 | + * This program is free software: you can redistribute it and/or modify |
23 | + * it under the terms of the GNU General Public License version 3 as |
24 | + * published by the Free Software Foundation. |
25 | + * |
26 | + * This program is distributed in the hope that it will be useful, |
27 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
28 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
29 | + * GNU General Public License for more details. |
30 | + * |
31 | + * You should have received a copy of the GNU General Public License |
32 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
33 | + * |
34 | + * Authored by Michal Hruby <michal.hruby@canonical.com> |
35 | + * |
36 | + * This file is taken from libunity. |
37 | + */ |
38 | + |
39 | +/* A bit of magic to get proper-ish fixture support */ |
40 | +public interface Fixture : Object |
41 | +{ |
42 | + class DelegateWrapper |
43 | + { |
44 | + TestDataFunc func; |
45 | + public DelegateWrapper (owned TestDataFunc f) { func = (owned) f; } |
46 | + } |
47 | + |
48 | + public virtual void setup () {} |
49 | + public virtual void teardown () {} |
50 | + |
51 | + [CCode (has_target = false)] |
52 | + public delegate void Callback<T> (T ptr); |
53 | + |
54 | + private static List<DelegateWrapper> _tests; |
55 | + |
56 | + public static unowned TestDataFunc create<F> (Callback<void*> cb) |
57 | + requires (typeof (F).is_a (typeof (Fixture))) |
58 | + { |
59 | + TestDataFunc functor = () => |
60 | + { |
61 | + var type = typeof (F); |
62 | + var instance = Object.new (type) as Fixture; |
63 | + instance.setup (); |
64 | + cb (instance); |
65 | + instance.teardown (); |
66 | + }; |
67 | + unowned TestDataFunc copy = functor; |
68 | + _tests.append (new DelegateWrapper ((owned) functor)); |
69 | + return copy; |
70 | + } |
71 | + public static unowned TestDataFunc create_static<F> (Callback<F> cb) |
72 | + { |
73 | + return create<F> ((Callback<void*>) cb); |
74 | + } |
75 | +} |
76 | + |
77 | +public static bool run_with_timeout (MainLoop ml, uint timeout_ms = 5000) |
78 | +{ |
79 | + bool timeout_reached = false; |
80 | + var t_id = Timeout.add (timeout_ms, () => |
81 | + { |
82 | + timeout_reached = true; |
83 | + debug ("Timeout reached"); |
84 | + ml.quit (); |
85 | + return false; |
86 | + }); |
87 | + |
88 | + ml.run (); |
89 | + |
90 | + if (!timeout_reached) Source.remove (t_id); |
91 | + |
92 | + return !timeout_reached; |
93 | +} |
94 | + |
95 | +/* calling this will ensure that the object was destroyed, but note that |
96 | + * it needs to be called with the (owned) modifier */ |
97 | +public static void ensure_destruction (owned Object obj) |
98 | +{ |
99 | + var ml = new MainLoop (); |
100 | + bool destroyed = false; |
101 | + obj.weak_ref (() => { destroyed = true; ml.quit (); }); |
102 | + |
103 | + obj = null; |
104 | + if (!destroyed) |
105 | + { |
106 | + // wait a bit if there were async operations |
107 | + assert (run_with_timeout (ml)); |
108 | + } |
109 | +} |
110 | + |
111 | +public class ErrorHandler |
112 | +{ |
113 | + public ErrorHandler () |
114 | + { |
115 | + GLib.Test.log_set_fatal_handler (handle_fatal_func); |
116 | + } |
117 | + |
118 | + private bool handle_fatal_func (string? log_domain, LogLevelFlags flags, |
119 | + string message) |
120 | + { |
121 | + return false; |
122 | + } |
123 | + |
124 | + private uint[] handler_ids; |
125 | + private GenericArray<string?> handler_domains; |
126 | + |
127 | + public void ignore_message (string? domain, LogLevelFlags flags) |
128 | + { |
129 | + handler_ids += Log.set_handler (domain, flags | LogLevelFlags.FLAG_FATAL, |
130 | + () => {}); |
131 | + if (handler_domains == null) |
132 | + { |
133 | + handler_domains = new GenericArray<string?> (); |
134 | + } |
135 | + handler_domains.add (domain); |
136 | + } |
137 | + |
138 | + ~ErrorHandler () |
139 | + { |
140 | + for(uint i = 0; i < handler_ids.length; i++) |
141 | + Log.remove_handler (handler_domains[i], handler_ids[i]); |
142 | + } |
143 | +} |
144 | |
145 | === modified file 'tests/main.vala' |
146 | --- tests/main.vala 2013-08-21 04:46:54 +0000 |
147 | +++ tests/main.vala 2014-01-29 16:00:28 +0000 |
148 | @@ -20,6 +20,8 @@ |
149 | const int TIMEOUT_MS = 1000; |
150 | const int LONG_TIMEOUT_S = 10; |
151 | |
152 | +static string display; |
153 | + |
154 | [DBus (name = "com.canonical.indicator.keyboard.test")] |
155 | public class Service : Object { |
156 | |
157 | @@ -42,676 +44,603 @@ |
158 | } |
159 | } |
160 | |
161 | -struct Fixture { |
162 | - TestDBus? bus; |
163 | - uint service_name; |
164 | - DBusConnection? connection; |
165 | - Service? service; |
166 | - uint object_name; |
167 | -} |
168 | - |
169 | -static void start_service (Fixture *fixture) { |
170 | - if (fixture.connection != null) { |
171 | - try { |
172 | - fixture.service = new Service (); |
173 | - fixture.object_name = ((!) fixture.connection).register_object ("/com/canonical/indicator/keyboard/test", fixture.service); |
174 | - } catch (IOError error) { |
175 | - fixture.connection = null; |
176 | - fixture.service = null; |
177 | - fixture.object_name = 0; |
178 | - |
179 | - Test.message ("error: %s", error.message); |
180 | - Test.fail (); |
181 | - } |
182 | - } |
183 | -} |
184 | - |
185 | -static void begin_test (void *data) { |
186 | - var fixture = (Fixture *) data; |
187 | - |
188 | - fixture.bus = new TestDBus (TestDBusFlags.NONE); |
189 | - ((!) fixture.bus).add_service_dir (SERVICE_DIR); |
190 | - ((!) fixture.bus).up (); |
191 | - |
192 | - var loop = new MainLoop (null, false); |
193 | - |
194 | - fixture.service_name = Bus.own_name (BusType.SESSION, |
195 | - "com.canonical.indicator.keyboard.test", |
196 | - BusNameOwnerFlags.ALLOW_REPLACEMENT | BusNameOwnerFlags.REPLACE, |
197 | - (connection, name) => { |
198 | - if (loop.is_running ()) { |
199 | - fixture.connection = connection; |
200 | - |
201 | - start_service (fixture); |
202 | - |
203 | - loop.quit (); |
204 | - } |
205 | - }, |
206 | - null, |
207 | - (connection, name) => { |
208 | - if (loop.is_running ()) { |
209 | - fixture.connection = null; |
210 | - fixture.service = null; |
211 | - fixture.object_name = 0; |
212 | - |
213 | - loop.quit (); |
214 | - } |
215 | - }); |
216 | - |
217 | - loop.run (); |
218 | - |
219 | - if (fixture.connection == null) { |
220 | - Test.message ("error: Unable to connect to com.canonical.indicator.keyboard.test."); |
221 | - Test.fail (); |
222 | - } |
223 | -} |
224 | - |
225 | -static void end_test (void *data) { |
226 | - var fixture = (Fixture *) data; |
227 | - |
228 | - if (fixture.object_name != 0) { |
229 | - ((!) fixture.connection).unregister_object (fixture.object_name); |
230 | - fixture.object_name = 0; |
231 | - } |
232 | - |
233 | - if (fixture.service_name != 0) { |
234 | - Bus.unown_name (fixture.service_name); |
235 | - fixture.service_name = 0; |
236 | - } |
237 | - |
238 | - fixture.service = null; |
239 | - fixture.connection = null; |
240 | - |
241 | - if (fixture.bus != null) { |
242 | - ((!) fixture.bus).down (); |
243 | - fixture.bus = null; |
244 | - } |
245 | -} |
246 | - |
247 | -static void test_activate_input_source (void *data) { |
248 | - var fixture = (Fixture *) data; |
249 | - |
250 | - if (fixture.object_name == 0) { |
251 | - Test.message ("error: Test fixture not initialized."); |
252 | - Test.fail (); |
253 | - return; |
254 | - } |
255 | - |
256 | - try { |
257 | - var current = 0; |
258 | - var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]"; |
259 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
260 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
261 | - } catch (SpawnError error) { |
262 | - Test.message ("error: %s", error.message); |
263 | - Test.fail (); |
264 | - return; |
265 | - } |
266 | - |
267 | - var action_group = DBusActionGroup.get ((!) fixture.connection, |
268 | - "com.canonical.indicator.keyboard", |
269 | - "/com/canonical/indicator/keyboard"); |
270 | - action_group.list_actions (); |
271 | - action_group.activate_action ("current", new Variant.uint32 (2)); |
272 | - |
273 | - var loop = new MainLoop (null, false); |
274 | - Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
275 | - loop.run (); |
276 | - |
277 | - var state = action_group.get_action_state ("current"); |
278 | - var current = state.get_uint32 (); |
279 | - stderr.printf ("current = %u\n", current); |
280 | - assert (current == 2); |
281 | - |
282 | - try { |
283 | - string output; |
284 | - Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources current", out output); |
285 | - stderr.printf ("output = \"%s\"\n", output); |
286 | - assert (strcmp (output, "uint32 2\n") == 0); |
287 | - } catch (SpawnError error) { |
288 | - Test.message ("error: %s", error.message); |
289 | - Test.fail (); |
290 | - return; |
291 | - } |
292 | -} |
293 | - |
294 | -static void test_activate_character_map (void *data) { |
295 | - var fixture = (Fixture *) data; |
296 | - |
297 | - if (fixture.object_name == 0) { |
298 | - Test.message ("error: Test fixture not initialized."); |
299 | - Test.fail (); |
300 | - return; |
301 | - } |
302 | - |
303 | - var action_group = DBusActionGroup.get ((!) fixture.connection, |
304 | - "com.canonical.indicator.keyboard", |
305 | - "/com/canonical/indicator/keyboard"); |
306 | - var loop = new MainLoop (null, false); |
307 | - var signal_name = ((!) fixture.service).notify["command"].connect ((pspec) => { |
308 | - loop.quit (); |
309 | - }); |
310 | - |
311 | - action_group.activate_action ("map", null); |
312 | - |
313 | - var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return false; }); |
314 | - loop.run (); |
315 | - Source.remove (source); |
316 | - ((!) fixture.service).disconnect (signal_name); |
317 | - |
318 | - stderr.printf ("fixture.service.command = \"%s\"\n", (!) ((!) fixture.service).command); |
319 | - assert (strcmp ((!) ((!) fixture.service).command, "'gucharmap '") == 0); |
320 | -} |
321 | - |
322 | -static void test_activate_keyboard_layout_chart (void *data) { |
323 | - var fixture = (Fixture *) data; |
324 | - |
325 | - if (fixture.object_name == 0) { |
326 | - Test.message ("error: Test fixture not initialized."); |
327 | - Test.fail (); |
328 | - return; |
329 | - } |
330 | - |
331 | - try { |
332 | - var current = 1; |
333 | - var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]"; |
334 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
335 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
336 | - } catch (SpawnError error) { |
337 | - Test.message ("error: %s", error.message); |
338 | - Test.fail (); |
339 | - return; |
340 | - } |
341 | - |
342 | - var action_group = DBusActionGroup.get ((!) fixture.connection, |
343 | - "com.canonical.indicator.keyboard", |
344 | - "/com/canonical/indicator/keyboard"); |
345 | - var loop = new MainLoop (null, false); |
346 | - var signal_name = ((!) fixture.service).notify["command"].connect ((pspec) => { |
347 | - loop.quit (); |
348 | - }); |
349 | - |
350 | - action_group.activate_action ("chart", null); |
351 | - |
352 | - var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return false; }); |
353 | - loop.run (); |
354 | - Source.remove (source); |
355 | - ((!) fixture.service).disconnect (signal_name); |
356 | - |
357 | - stderr.printf ("fixture.service.command = \"%s\"\n", (!) ((!) fixture.service).command); |
358 | - assert (strcmp ((!) ((!) fixture.service).command, "'gkbd-keyboard-display -l ca\teng'") == 0); |
359 | -} |
360 | - |
361 | -static void test_activate_text_entry_settings (void *data) { |
362 | - var fixture = (Fixture *) data; |
363 | - |
364 | - if (fixture.object_name == 0) { |
365 | - Test.message ("error: Test fixture not initialized."); |
366 | - Test.fail (); |
367 | - return; |
368 | - } |
369 | - |
370 | - var action_group = DBusActionGroup.get ((!) fixture.connection, |
371 | - "com.canonical.indicator.keyboard", |
372 | - "/com/canonical/indicator/keyboard"); |
373 | - var loop = new MainLoop (null, false); |
374 | - var signal_name = ((!) fixture.service).notify["command"].connect ((pspec) => { |
375 | - loop.quit (); |
376 | - }); |
377 | - |
378 | - action_group.activate_action ("settings", null); |
379 | - |
380 | - var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return false; }); |
381 | - loop.run (); |
382 | - Source.remove (source); |
383 | - ((!) fixture.service).disconnect (signal_name); |
384 | - |
385 | - stderr.printf ("fixture.service.command = \"%s\"\n", (!) ((!) fixture.service).command); |
386 | - assert (strcmp ((!) ((!) fixture.service).command, "'gnome-control-center region layouts'") == 0); |
387 | -} |
388 | - |
389 | -static void test_migration (void *data) { |
390 | - var fixture = (Fixture *) data; |
391 | - |
392 | - if (fixture.object_name == 0) { |
393 | - Test.message ("error: Test fixture not initialized."); |
394 | - Test.fail (); |
395 | - return; |
396 | - } |
397 | - |
398 | - try { |
399 | - var migrated = false; |
400 | - var sources = "[('xkb', 'us')]"; |
401 | - var layouts = "['us', 'ca\teng', 'epo']"; |
402 | - Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard migrated $migrated"); |
403 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
404 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.libgnomekbd.keyboard layouts \"$layouts\""); |
405 | - } catch (SpawnError error) { |
406 | - Test.message ("error: %s", error.message); |
407 | - Test.fail (); |
408 | - return; |
409 | - } |
410 | - |
411 | - try { |
412 | - var cancellable = new Cancellable (); |
413 | - |
414 | - var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { cancellable.cancel (); return false; }); |
415 | - |
416 | - var dbus_proxy = new DBusProxy.sync ((!) fixture.connection, |
417 | - DBusProxyFlags.NONE, |
418 | - null, |
419 | - "org.freedesktop.DBus", |
420 | - "/", |
421 | - "org.freedesktop.DBus", |
422 | - cancellable); |
423 | - |
424 | - Source.remove (source); |
425 | - |
426 | - if (cancellable.is_cancelled ()) { |
427 | - Test.message ("error: Unable to connect to org.freedesktop.DBus."); |
428 | - Test.fail (); |
429 | - return; |
430 | - } |
431 | - |
432 | - dbus_proxy.call_sync ("StartServiceByName", new Variant ("(su)", "com.canonical.indicator.keyboard", 0), DBusCallFlags.NONE, TIMEOUT_MS); |
433 | - } catch (Error error) { |
434 | - Test.message ("error: %s", error.message); |
435 | - Test.fail (); |
436 | - return; |
437 | - } |
438 | - |
439 | - var loop = new MainLoop (null, false); |
440 | - Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
441 | - loop.run (); |
442 | - |
443 | - try { |
444 | - string sources; |
445 | - Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources sources", out sources); |
446 | - stderr.printf ("sources = \"%s\"\n", sources); |
447 | - assert (strcmp (sources, "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo')]\n") == 0); |
448 | - } catch (SpawnError error) { |
449 | - Test.message ("error: %s", error.message); |
450 | - Test.fail (); |
451 | - return; |
452 | - } |
453 | -} |
454 | - |
455 | -static void test_no_migration (void *data) { |
456 | - var fixture = (Fixture *) data; |
457 | - |
458 | - if (fixture.object_name == 0) { |
459 | - Test.message ("error: Test fixture not initialized."); |
460 | - Test.fail (); |
461 | - return; |
462 | - } |
463 | - |
464 | - try { |
465 | - var migrated = true; |
466 | - var sources = "[('xkb', 'us')]"; |
467 | - var layouts = "['us', 'ca\teng', 'epo']"; |
468 | - Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard migrated $migrated"); |
469 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
470 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.libgnomekbd.keyboard layouts \"$layouts\""); |
471 | - } catch (SpawnError error) { |
472 | - Test.message ("error: %s", error.message); |
473 | - Test.fail (); |
474 | - return; |
475 | - } |
476 | - |
477 | - try { |
478 | - var cancellable = new Cancellable (); |
479 | - |
480 | - var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { cancellable.cancel (); return false; }); |
481 | - |
482 | - var dbus_proxy = new DBusProxy.sync ((!) fixture.connection, |
483 | - DBusProxyFlags.NONE, |
484 | - null, |
485 | - "org.freedesktop.DBus", |
486 | - "/", |
487 | - "org.freedesktop.DBus", |
488 | - cancellable); |
489 | - |
490 | - Source.remove (source); |
491 | - |
492 | - if (cancellable.is_cancelled ()) { |
493 | - Test.message ("error: Unable to connect to org.freedesktop.DBus."); |
494 | - Test.fail (); |
495 | - return; |
496 | - } |
497 | - |
498 | - dbus_proxy.call_sync ("StartServiceByName", new Variant ("(su)", "com.canonical.indicator.keyboard", 0), DBusCallFlags.NONE, TIMEOUT_MS); |
499 | - } catch (Error error) { |
500 | - Test.message ("error: %s", error.message); |
501 | - Test.fail (); |
502 | - return; |
503 | - } |
504 | - |
505 | - var loop = new MainLoop (null, false); |
506 | - Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
507 | - loop.run (); |
508 | - |
509 | - try { |
510 | - string sources; |
511 | - Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources sources", out sources); |
512 | - stderr.printf ("sources = \"%s\"\n", sources); |
513 | - assert (strcmp (sources, "[('xkb', 'us')]\n") == 0); |
514 | - } catch (SpawnError error) { |
515 | - Test.message ("error: %s", error.message); |
516 | - Test.fail (); |
517 | - return; |
518 | - } |
519 | -} |
520 | - |
521 | -static void test_update_visible (void *data) { |
522 | - var fixture = (Fixture *) data; |
523 | - |
524 | - if (fixture.object_name == 0) { |
525 | - Test.message ("error: Test fixture not initialized."); |
526 | - Test.fail (); |
527 | - return; |
528 | - } |
529 | - |
530 | - bool visible; |
531 | - |
532 | - try { |
533 | - visible = true; |
534 | - Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible"); |
535 | - } catch (SpawnError error) { |
536 | - Test.message ("error: %s", error.message); |
537 | - Test.fail (); |
538 | - return; |
539 | - } |
540 | - |
541 | - var action_group = DBusActionGroup.get ((!) fixture.connection, |
542 | - "com.canonical.indicator.keyboard", |
543 | - "/com/canonical/indicator/keyboard"); |
544 | - var loop = new MainLoop (null, false); |
545 | - var signal_name = action_group.action_added["indicator"].connect ((action) => { |
546 | - loop.quit (); |
547 | - }); |
548 | - |
549 | - action_group.list_actions (); |
550 | - |
551 | - var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return false; }); |
552 | - loop.run (); |
553 | - Source.remove (source); |
554 | - action_group.disconnect (signal_name); |
555 | - |
556 | - var state = action_group.get_action_state ("indicator"); |
557 | - assert (state.lookup ("visible", "b", out visible)); |
558 | - stderr.printf ("visible = %s\n", visible ? "true" : "false"); |
559 | - assert (visible); |
560 | - |
561 | - loop = new MainLoop (null, false); |
562 | - signal_name = action_group.action_state_changed["indicator"].connect ((action, state) => { |
563 | - loop.quit (); |
564 | - }); |
565 | - |
566 | - try { |
567 | - visible = false; |
568 | - Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible"); |
569 | - } catch (SpawnError error) { |
570 | - Test.message ("error: %s", error.message); |
571 | - Test.fail (); |
572 | - return; |
573 | - } |
574 | - |
575 | - source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return false; }); |
576 | - loop.run (); |
577 | - Source.remove (source); |
578 | - action_group.disconnect (signal_name); |
579 | - |
580 | - state = action_group.get_action_state ("indicator"); |
581 | - assert (state.lookup ("visible", "b", out visible)); |
582 | - stderr.printf ("visible = %s\n", visible ? "true" : "false"); |
583 | - assert (!visible); |
584 | - |
585 | - loop = new MainLoop (null, false); |
586 | - signal_name = action_group.action_state_changed["indicator"].connect ((action, state) => { |
587 | - loop.quit (); |
588 | - }); |
589 | - |
590 | - try { |
591 | - visible = true; |
592 | - Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible"); |
593 | - } catch (SpawnError error) { |
594 | - Test.message ("error: %s", error.message); |
595 | - Test.fail (); |
596 | - return; |
597 | - } |
598 | - |
599 | - source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return false; }); |
600 | - loop.run (); |
601 | - Source.remove (source); |
602 | - action_group.disconnect (signal_name); |
603 | - |
604 | - state = action_group.get_action_state ("indicator"); |
605 | - assert (state.lookup ("visible", "b", out visible)); |
606 | - stderr.printf ("visible = %s\n", visible ? "true" : "false"); |
607 | - assert (visible); |
608 | -} |
609 | - |
610 | -static void test_update_input_source (void *data) { |
611 | - var fixture = (Fixture *) data; |
612 | - |
613 | - if (fixture.object_name == 0) { |
614 | - Test.message ("error: Test fixture not initialized."); |
615 | - Test.fail (); |
616 | - return; |
617 | - } |
618 | - |
619 | - try { |
620 | - var current = 0; |
621 | - var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]"; |
622 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
623 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
624 | - } catch (SpawnError error) { |
625 | - Test.message ("error: %s", error.message); |
626 | - Test.fail (); |
627 | - return; |
628 | - } |
629 | - |
630 | - var action_group = DBusActionGroup.get ((!) fixture.connection, |
631 | - "com.canonical.indicator.keyboard", |
632 | - "/com/canonical/indicator/keyboard"); |
633 | - var loop = new MainLoop (null, false); |
634 | - var signal_name = action_group.action_state_changed["current"].connect ((action, state) => { |
635 | - loop.quit (); |
636 | - }); |
637 | - |
638 | - action_group.list_actions (); |
639 | - |
640 | - try { |
641 | - var current = 1; |
642 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
643 | - } catch (SpawnError error) { |
644 | - Test.message ("error: %s", error.message); |
645 | - Test.fail (); |
646 | - return; |
647 | - } |
648 | - |
649 | - var source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
650 | - loop.run (); |
651 | - Source.remove (source); |
652 | - action_group.disconnect (signal_name); |
653 | - |
654 | - var state = action_group.get_action_state ("current"); |
655 | - var current = state.get_uint32 (); |
656 | - stderr.printf ("current = %u\n", current); |
657 | - assert (current == 1); |
658 | - |
659 | - try { |
660 | - string output; |
661 | - Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources current", out output); |
662 | - stderr.printf ("output = \"%s\"\n", output); |
663 | - assert (strcmp (output, "uint32 1\n") == 0); |
664 | - } catch (SpawnError error) { |
665 | - Test.message ("error: %s", error.message); |
666 | - Test.fail (); |
667 | - return; |
668 | - } |
669 | - |
670 | - loop = new MainLoop (null, false); |
671 | - signal_name = action_group.action_state_changed["current"].connect ((action, state) => { |
672 | - loop.quit (); |
673 | - }); |
674 | - |
675 | - try { |
676 | - current = 0; |
677 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
678 | - } catch (SpawnError error) { |
679 | - Test.message ("error: %s", error.message); |
680 | - Test.fail (); |
681 | - return; |
682 | - } |
683 | - |
684 | - source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return false; }); |
685 | - loop.run (); |
686 | - Source.remove (source); |
687 | - action_group.disconnect (signal_name); |
688 | - |
689 | - state = action_group.get_action_state ("current"); |
690 | - current = state.get_uint32 (); |
691 | - stderr.printf ("current = %u\n", current); |
692 | - assert (current == 0); |
693 | - |
694 | - try { |
695 | - string output; |
696 | - Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources current", out output); |
697 | - stderr.printf ("output = \"%s\"\n", output); |
698 | - assert (strcmp (output, "uint32 0\n") == 0); |
699 | - } catch (SpawnError error) { |
700 | - Test.message ("error: %s", error.message); |
701 | - Test.fail (); |
702 | - return; |
703 | - } |
704 | -} |
705 | - |
706 | -static void test_update_input_sources (void *data) { |
707 | - var fixture = (Fixture *) data; |
708 | - |
709 | - if (fixture.object_name == 0) { |
710 | - Test.message ("error: Test fixture not initialized."); |
711 | - Test.fail (); |
712 | - return; |
713 | - } |
714 | - |
715 | - try { |
716 | - var current = 0; |
717 | - var sources = "[('xkb', 'us')]"; |
718 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
719 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
720 | - } catch (SpawnError error) { |
721 | - Test.message ("error: %s", error.message); |
722 | - Test.fail (); |
723 | - return; |
724 | - } |
725 | - |
726 | - var menu_model = DBusMenuModel.get ((!) fixture.connection, |
727 | - "com.canonical.indicator.keyboard", |
728 | - "/com/canonical/indicator/keyboard/desktop"); |
729 | - var loop = new MainLoop (null, false); |
730 | - var signal_name = menu_model.items_changed.connect ((position, removed, added) => { |
731 | - loop.quit (); |
732 | - }); |
733 | - |
734 | - menu_model.get_n_items (); |
735 | - |
736 | - var source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
737 | - loop.run (); |
738 | - Source.remove (source); |
739 | - menu_model.disconnect (signal_name); |
740 | - |
741 | - var menu = menu_model.get_item_link (0, Menu.LINK_SUBMENU); |
742 | - loop = new MainLoop (null, false); |
743 | - signal_name = menu.items_changed.connect ((position, removed, added) => { |
744 | - loop.quit (); |
745 | - }); |
746 | - |
747 | - menu.get_n_items (); |
748 | - |
749 | - source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
750 | - loop.run (); |
751 | - Source.remove (source); |
752 | - menu.disconnect (signal_name); |
753 | - |
754 | - var section = menu.get_item_link (0, Menu.LINK_SECTION); |
755 | - loop = new MainLoop (null, false); |
756 | - signal_name = section.items_changed.connect ((position, removed, added) => { |
757 | - loop.quit (); |
758 | - }); |
759 | - |
760 | - section.get_n_items (); |
761 | - |
762 | - source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
763 | - loop.run (); |
764 | - Source.remove (source); |
765 | - section.disconnect (signal_name); |
766 | - |
767 | - string label; |
768 | - |
769 | - stderr.printf ("section.get_n_items () = %d\n", section.get_n_items ()); |
770 | - assert (section.get_n_items () == 1); |
771 | - section.get_item_attribute (0, Menu.ATTRIBUTE_LABEL, "s", out label); |
772 | - stderr.printf ("label = \"%s\"\n", label); |
773 | - assert (strcmp (label, "English (US)") == 0); |
774 | - |
775 | - loop = new MainLoop (null, false); |
776 | - signal_name = section.items_changed.connect ((position, removed, added) => { |
777 | - if (section.get_n_items () == 4) { |
778 | - loop.quit (); |
779 | - } |
780 | - }); |
781 | - |
782 | - try { |
783 | - var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]"; |
784 | - Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
785 | - } catch (SpawnError error) { |
786 | - Test.message ("error: %s", error.message); |
787 | - Test.fail (); |
788 | - return; |
789 | - } |
790 | - |
791 | - source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return false; }); |
792 | - loop.run (); |
793 | - Source.remove (source); |
794 | - section.disconnect (signal_name); |
795 | - |
796 | - stderr.printf ("section.get_n_items () = %d\n", section.get_n_items ()); |
797 | - assert (section.get_n_items () == 4); |
798 | - section.get_item_attribute (0, Menu.ATTRIBUTE_LABEL, "s", out label); |
799 | - stderr.printf ("label = \"%s\"\n", label); |
800 | - assert (strcmp (label, "English (US)") == 0); |
801 | - section.get_item_attribute (1, Menu.ATTRIBUTE_LABEL, "s", out label); |
802 | - stderr.printf ("label = \"%s\"\n", label); |
803 | - assert (strcmp (label, "English (Canada)") == 0); |
804 | - section.get_item_attribute (2, Menu.ATTRIBUTE_LABEL, "s", out label); |
805 | - stderr.printf ("label = \"%s\"\n", label); |
806 | - assert (strcmp (label, "Esperanto") == 0); |
807 | - section.get_item_attribute (3, Menu.ATTRIBUTE_LABEL, "s", out label); |
808 | - stderr.printf ("label = \"%s\"\n", label); |
809 | - assert (label.ascii_casecmp ("Pinyin") == 0); |
810 | +public class Tests : Object, Fixture { |
811 | + |
812 | + private TestDBus? _bus; |
813 | + private uint _service_name; |
814 | + private DBusConnection? _connection; |
815 | + private Service? _service; |
816 | + private uint _object_name; |
817 | + |
818 | + public void start_service () { |
819 | + if (_connection != null) { |
820 | + try { |
821 | + _service = new Service (); |
822 | + _object_name = ((!) _connection).register_object ("/com/canonical/indicator/keyboard/test", _service); |
823 | + } catch (IOError error) { |
824 | + _connection = null; |
825 | + _service = null; |
826 | + _object_name = 0; |
827 | + |
828 | + Test.message ("error: %s", error.message); |
829 | + Test.fail (); |
830 | + } |
831 | + } |
832 | + } |
833 | + |
834 | + public void setup () { |
835 | + Environment.set_variable ("DCONF_PROFILE", DCONF_PROFILE, true); |
836 | + Environment.set_variable ("DISPLAY", display, true); |
837 | + Environment.set_variable ("LC_ALL", "C", true); |
838 | + |
839 | + _bus = new TestDBus (TestDBusFlags.NONE); |
840 | + ((!) _bus).add_service_dir (SERVICE_DIR); |
841 | + ((!) _bus).up (); |
842 | + |
843 | + var loop = new MainLoop (null, false); |
844 | + |
845 | + _service_name = Bus.own_name (BusType.SESSION, |
846 | + "com.canonical.indicator.keyboard.test", |
847 | + BusNameOwnerFlags.ALLOW_REPLACEMENT | BusNameOwnerFlags.REPLACE, |
848 | + (connection, name) => { |
849 | + if (loop.is_running ()) { |
850 | + _connection = connection; |
851 | + start_service (); |
852 | + loop.quit (); |
853 | + } |
854 | + }, |
855 | + null, |
856 | + (connection, name) => { |
857 | + if (loop.is_running ()) { |
858 | + _connection = null; |
859 | + _service = null; |
860 | + _object_name = 0; |
861 | + loop.quit (); |
862 | + } |
863 | + }); |
864 | + |
865 | + loop.run (); |
866 | + |
867 | + if (_connection == null) { |
868 | + Test.message ("error: Unable to connect to com.canonical.indicator.keyboard.test."); |
869 | + Test.fail (); |
870 | + } |
871 | + |
872 | + if (_object_name == 0) { |
873 | + Test.message ("error: Test fixture not initialized."); |
874 | + Test.fail (); |
875 | + return; |
876 | + } |
877 | + } |
878 | + |
879 | + public void teardown () { |
880 | + if (_object_name != 0) { |
881 | + ((!) _connection).unregister_object (_object_name); |
882 | + _object_name = 0; |
883 | + } |
884 | + |
885 | + if (_service_name != 0) { |
886 | + Bus.unown_name (_service_name); |
887 | + _service_name = 0; |
888 | + } |
889 | + |
890 | + _service = null; |
891 | + _connection = null; |
892 | + |
893 | + if (_bus != null) { |
894 | + ((!) _bus).down (); |
895 | + _bus = null; |
896 | + } |
897 | + } |
898 | + |
899 | + public void test_activate_input_source () { |
900 | + try { |
901 | + var current = 0; |
902 | + var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]"; |
903 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
904 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
905 | + } catch (SpawnError error) { |
906 | + Test.message ("error: %s", error.message); |
907 | + Test.fail (); |
908 | + return; |
909 | + } |
910 | + |
911 | + var action_group = DBusActionGroup.get ((!) _connection, |
912 | + "com.canonical.indicator.keyboard", |
913 | + "/com/canonical/indicator/keyboard"); |
914 | + action_group.list_actions (); |
915 | + action_group.activate_action ("current", new Variant.uint32 (2)); |
916 | + |
917 | + var loop = new MainLoop (null, false); |
918 | + Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
919 | + loop.run (); |
920 | + |
921 | + var state = action_group.get_action_state ("current"); |
922 | + var current = state.get_uint32 (); |
923 | + stderr.printf ("current = %u\n", current); |
924 | + assert (current == 2); |
925 | + |
926 | + try { |
927 | + string output; |
928 | + Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources current", out output); |
929 | + stderr.printf ("output = \"%s\"\n", output); |
930 | + assert (strcmp (output, "uint32 2\n") == 0); |
931 | + } catch (SpawnError error) { |
932 | + Test.message ("error: %s", error.message); |
933 | + Test.fail (); |
934 | + return; |
935 | + } |
936 | + } |
937 | + |
938 | + public void test_activate_character_map () { |
939 | + var action_group = DBusActionGroup.get ((!) _connection, |
940 | + "com.canonical.indicator.keyboard", |
941 | + "/com/canonical/indicator/keyboard"); |
942 | + var loop = new MainLoop (null, false); |
943 | + var signal_name = ((!) _service).notify["command"].connect ((pspec) => { |
944 | + loop.quit (); |
945 | + }); |
946 | + |
947 | + action_group.activate_action ("map", null); |
948 | + |
949 | + var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return true; }); |
950 | + loop.run (); |
951 | + Source.remove (source); |
952 | + ((!) _service).disconnect (signal_name); |
953 | + |
954 | + stderr.printf ("_service.command = \"%s\"\n", (!) ((!) _service).command); |
955 | + assert (strcmp ((!) ((!) _service).command, "'gucharmap '") == 0); |
956 | + } |
957 | + |
958 | + public void test_activate_keyboard_layout_chart () { |
959 | + try { |
960 | + var current = 1; |
961 | + var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]"; |
962 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
963 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
964 | + } catch (SpawnError error) { |
965 | + Test.message ("error: %s", error.message); |
966 | + Test.fail (); |
967 | + return; |
968 | + } |
969 | + |
970 | + var action_group = DBusActionGroup.get ((!) _connection, |
971 | + "com.canonical.indicator.keyboard", |
972 | + "/com/canonical/indicator/keyboard"); |
973 | + var loop = new MainLoop (null, false); |
974 | + var signal_name = ((!) _service).notify["command"].connect ((pspec) => { |
975 | + loop.quit (); |
976 | + }); |
977 | + |
978 | + action_group.activate_action ("chart", null); |
979 | + |
980 | + var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return true; }); |
981 | + loop.run (); |
982 | + Source.remove (source); |
983 | + ((!) _service).disconnect (signal_name); |
984 | + |
985 | + stderr.printf ("_service.command = \"%s\"\n", (!) ((!) _service).command); |
986 | + assert (strcmp ((!) ((!) _service).command, "'gkbd-keyboard-display -l ca\teng'") == 0); |
987 | + } |
988 | + |
989 | + public void test_activate_text_entry_settings () { |
990 | + var action_group = DBusActionGroup.get ((!) _connection, |
991 | + "com.canonical.indicator.keyboard", |
992 | + "/com/canonical/indicator/keyboard"); |
993 | + var loop = new MainLoop (null, false); |
994 | + var signal_name = ((!) _service).notify["command"].connect ((pspec) => { |
995 | + loop.quit (); |
996 | + }); |
997 | + |
998 | + action_group.activate_action ("settings", null); |
999 | + |
1000 | + var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return true; }); |
1001 | + loop.run (); |
1002 | + Source.remove (source); |
1003 | + ((!) _service).disconnect (signal_name); |
1004 | + |
1005 | + stderr.printf ("_service.command = \"%s\"\n", (!) ((!) _service).command); |
1006 | + assert (strcmp ((!) ((!) _service).command, "'gnome-control-center region layouts'") == 0); |
1007 | + } |
1008 | + |
1009 | + public void test_migration () { |
1010 | + try { |
1011 | + var migrated = false; |
1012 | + var sources = "[('xkb', 'us')]"; |
1013 | + var layouts = "['us', 'ca\teng', 'epo']"; |
1014 | + Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard migrated $migrated"); |
1015 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
1016 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.libgnomekbd.keyboard layouts \"$layouts\""); |
1017 | + } catch (SpawnError error) { |
1018 | + Test.message ("error: %s", error.message); |
1019 | + Test.fail (); |
1020 | + return; |
1021 | + } |
1022 | + |
1023 | + try { |
1024 | + var cancellable = new Cancellable (); |
1025 | + |
1026 | + var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { cancellable.cancel (); return true; }); |
1027 | + |
1028 | + var dbus_proxy = new DBusProxy.sync ((!) _connection, |
1029 | + DBusProxyFlags.NONE, |
1030 | + null, |
1031 | + "org.freedesktop.DBus", |
1032 | + "/", |
1033 | + "org.freedesktop.DBus", |
1034 | + cancellable); |
1035 | + |
1036 | + Source.remove (source); |
1037 | + |
1038 | + if (cancellable.is_cancelled ()) { |
1039 | + Test.message ("error: Unable to connect to org.freedesktop.DBus."); |
1040 | + Test.fail (); |
1041 | + return; |
1042 | + } |
1043 | + |
1044 | + dbus_proxy.call_sync ("StartServiceByName", new Variant ("(su)", "com.canonical.indicator.keyboard", 0), DBusCallFlags.NONE, TIMEOUT_MS); |
1045 | + } catch (Error error) { |
1046 | + Test.message ("error: %s", error.message); |
1047 | + Test.fail (); |
1048 | + return; |
1049 | + } |
1050 | + |
1051 | + var loop = new MainLoop (null, false); |
1052 | + Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
1053 | + loop.run (); |
1054 | + |
1055 | + try { |
1056 | + string sources; |
1057 | + Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources sources", out sources); |
1058 | + stderr.printf ("sources = \"%s\"\n", sources); |
1059 | + assert (strcmp (sources, "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo')]\n") == 0); |
1060 | + } catch (SpawnError error) { |
1061 | + Test.message ("error: %s", error.message); |
1062 | + Test.fail (); |
1063 | + return; |
1064 | + } |
1065 | + } |
1066 | + |
1067 | + public void test_no_migration () { |
1068 | + try { |
1069 | + var migrated = true; |
1070 | + var sources = "[('xkb', 'us')]"; |
1071 | + var layouts = "['us', 'ca\teng', 'epo']"; |
1072 | + Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard migrated $migrated"); |
1073 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
1074 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.libgnomekbd.keyboard layouts \"$layouts\""); |
1075 | + } catch (SpawnError error) { |
1076 | + Test.message ("error: %s", error.message); |
1077 | + Test.fail (); |
1078 | + return; |
1079 | + } |
1080 | + |
1081 | + try { |
1082 | + var cancellable = new Cancellable (); |
1083 | + |
1084 | + var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { cancellable.cancel (); return true; }); |
1085 | + |
1086 | + var dbus_proxy = new DBusProxy.sync ((!) _connection, |
1087 | + DBusProxyFlags.NONE, |
1088 | + null, |
1089 | + "org.freedesktop.DBus", |
1090 | + "/", |
1091 | + "org.freedesktop.DBus", |
1092 | + cancellable); |
1093 | + |
1094 | + Source.remove (source); |
1095 | + |
1096 | + if (cancellable.is_cancelled ()) { |
1097 | + Test.message ("error: Unable to connect to org.freedesktop.DBus."); |
1098 | + Test.fail (); |
1099 | + return; |
1100 | + } |
1101 | + |
1102 | + dbus_proxy.call_sync ("StartServiceByName", new Variant ("(su)", "com.canonical.indicator.keyboard", 0), DBusCallFlags.NONE, TIMEOUT_MS); |
1103 | + } catch (Error error) { |
1104 | + Test.message ("error: %s", error.message); |
1105 | + Test.fail (); |
1106 | + return; |
1107 | + } |
1108 | + |
1109 | + var loop = new MainLoop (null, false); |
1110 | + Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return false; }); |
1111 | + loop.run (); |
1112 | + |
1113 | + try { |
1114 | + string sources; |
1115 | + Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources sources", out sources); |
1116 | + stderr.printf ("sources = \"%s\"\n", sources); |
1117 | + assert (strcmp (sources, "[('xkb', 'us')]\n") == 0); |
1118 | + } catch (SpawnError error) { |
1119 | + Test.message ("error: %s", error.message); |
1120 | + Test.fail (); |
1121 | + return; |
1122 | + } |
1123 | + } |
1124 | + |
1125 | + public void test_update_visible () { |
1126 | + bool visible; |
1127 | + |
1128 | + try { |
1129 | + visible = true; |
1130 | + Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible"); |
1131 | + } catch (SpawnError error) { |
1132 | + Test.message ("error: %s", error.message); |
1133 | + Test.fail (); |
1134 | + return; |
1135 | + } |
1136 | + |
1137 | + var action_group = DBusActionGroup.get ((!) _connection, |
1138 | + "com.canonical.indicator.keyboard", |
1139 | + "/com/canonical/indicator/keyboard"); |
1140 | + var loop = new MainLoop (null, false); |
1141 | + var signal_name = action_group.action_added["indicator"].connect ((action) => { |
1142 | + loop.quit (); |
1143 | + }); |
1144 | + |
1145 | + action_group.list_actions (); |
1146 | + |
1147 | + var source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return true; }); |
1148 | + loop.run (); |
1149 | + Source.remove (source); |
1150 | + action_group.disconnect (signal_name); |
1151 | + |
1152 | + var state = action_group.get_action_state ("indicator"); |
1153 | + assert (state.lookup ("visible", "b", out visible)); |
1154 | + stderr.printf ("visible = %s\n", visible ? "true" : "false"); |
1155 | + assert (visible); |
1156 | + |
1157 | + loop = new MainLoop (null, false); |
1158 | + signal_name = action_group.action_state_changed["indicator"].connect ((action, state) => { |
1159 | + loop.quit (); |
1160 | + }); |
1161 | + |
1162 | + try { |
1163 | + visible = false; |
1164 | + Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible"); |
1165 | + } catch (SpawnError error) { |
1166 | + Test.message ("error: %s", error.message); |
1167 | + Test.fail (); |
1168 | + return; |
1169 | + } |
1170 | + |
1171 | + source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return true; }); |
1172 | + loop.run (); |
1173 | + Source.remove (source); |
1174 | + action_group.disconnect (signal_name); |
1175 | + |
1176 | + state = action_group.get_action_state ("indicator"); |
1177 | + assert (state.lookup ("visible", "b", out visible)); |
1178 | + stderr.printf ("visible = %s\n", visible ? "true" : "false"); |
1179 | + assert (!visible); |
1180 | + |
1181 | + loop = new MainLoop (null, false); |
1182 | + signal_name = action_group.action_state_changed["indicator"].connect ((action, state) => { |
1183 | + loop.quit (); |
1184 | + }); |
1185 | + |
1186 | + try { |
1187 | + visible = true; |
1188 | + Process.spawn_command_line_sync (@"gsettings set com.canonical.indicator.keyboard visible $visible"); |
1189 | + } catch (SpawnError error) { |
1190 | + Test.message ("error: %s", error.message); |
1191 | + Test.fail (); |
1192 | + return; |
1193 | + } |
1194 | + |
1195 | + source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return true; }); |
1196 | + loop.run (); |
1197 | + Source.remove (source); |
1198 | + action_group.disconnect (signal_name); |
1199 | + |
1200 | + state = action_group.get_action_state ("indicator"); |
1201 | + assert (state.lookup ("visible", "b", out visible)); |
1202 | + stderr.printf ("visible = %s\n", visible ? "true" : "false"); |
1203 | + assert (visible); |
1204 | + } |
1205 | + |
1206 | + public void test_update_input_source () { |
1207 | + try { |
1208 | + var current = 0; |
1209 | + var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]"; |
1210 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
1211 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
1212 | + } catch (SpawnError error) { |
1213 | + Test.message ("error: %s", error.message); |
1214 | + Test.fail (); |
1215 | + return; |
1216 | + } |
1217 | + |
1218 | + var action_group = DBusActionGroup.get ((!) _connection, |
1219 | + "com.canonical.indicator.keyboard", |
1220 | + "/com/canonical/indicator/keyboard"); |
1221 | + var loop = new MainLoop (null, false); |
1222 | + var signal_name = action_group.action_state_changed["current"].connect ((action, state) => { |
1223 | + loop.quit (); |
1224 | + }); |
1225 | + |
1226 | + action_group.list_actions (); |
1227 | + |
1228 | + try { |
1229 | + var current = 1; |
1230 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
1231 | + } catch (SpawnError error) { |
1232 | + Test.message ("error: %s", error.message); |
1233 | + Test.fail (); |
1234 | + return; |
1235 | + } |
1236 | + |
1237 | + var source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return true; }); |
1238 | + loop.run (); |
1239 | + Source.remove (source); |
1240 | + action_group.disconnect (signal_name); |
1241 | + |
1242 | + var state = action_group.get_action_state ("current"); |
1243 | + var current = state.get_uint32 (); |
1244 | + stderr.printf ("current = %u\n", current); |
1245 | + assert (current == 1); |
1246 | + |
1247 | + try { |
1248 | + string output; |
1249 | + Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources current", out output); |
1250 | + stderr.printf ("output = \"%s\"\n", output); |
1251 | + assert (strcmp (output, "uint32 1\n") == 0); |
1252 | + } catch (SpawnError error) { |
1253 | + Test.message ("error: %s", error.message); |
1254 | + Test.fail (); |
1255 | + return; |
1256 | + } |
1257 | + |
1258 | + loop = new MainLoop (null, false); |
1259 | + signal_name = action_group.action_state_changed["current"].connect ((action, state) => { |
1260 | + loop.quit (); |
1261 | + }); |
1262 | + |
1263 | + try { |
1264 | + current = 0; |
1265 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
1266 | + } catch (SpawnError error) { |
1267 | + Test.message ("error: %s", error.message); |
1268 | + Test.fail (); |
1269 | + return; |
1270 | + } |
1271 | + |
1272 | + source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return true; }); |
1273 | + loop.run (); |
1274 | + Source.remove (source); |
1275 | + action_group.disconnect (signal_name); |
1276 | + |
1277 | + state = action_group.get_action_state ("current"); |
1278 | + current = state.get_uint32 (); |
1279 | + stderr.printf ("current = %u\n", current); |
1280 | + assert (current == 0); |
1281 | + |
1282 | + try { |
1283 | + string output; |
1284 | + Process.spawn_command_line_sync ("gsettings get org.gnome.desktop.input-sources current", out output); |
1285 | + stderr.printf ("output = \"%s\"\n", output); |
1286 | + assert (strcmp (output, "uint32 0\n") == 0); |
1287 | + } catch (SpawnError error) { |
1288 | + Test.message ("error: %s", error.message); |
1289 | + Test.fail (); |
1290 | + return; |
1291 | + } |
1292 | + } |
1293 | + |
1294 | + public void test_update_input_sources () { |
1295 | + try { |
1296 | + var current = 0; |
1297 | + var sources = "[('xkb', 'us')]"; |
1298 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources current $current"); |
1299 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
1300 | + } catch (SpawnError error) { |
1301 | + Test.message ("error: %s", error.message); |
1302 | + Test.fail (); |
1303 | + return; |
1304 | + } |
1305 | + |
1306 | + var menu_model = DBusMenuModel.get ((!) _connection, |
1307 | + "com.canonical.indicator.keyboard", |
1308 | + "/com/canonical/indicator/keyboard/desktop"); |
1309 | + var loop = new MainLoop (null, false); |
1310 | + var signal_name = menu_model.items_changed.connect ((position, removed, added) => { |
1311 | + loop.quit (); |
1312 | + }); |
1313 | + |
1314 | + menu_model.get_n_items (); |
1315 | + |
1316 | + var source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return true; }); |
1317 | + loop.run (); |
1318 | + Source.remove (source); |
1319 | + menu_model.disconnect (signal_name); |
1320 | + |
1321 | + var menu = menu_model.get_item_link (0, Menu.LINK_SUBMENU); |
1322 | + loop = new MainLoop (null, false); |
1323 | + signal_name = menu.items_changed.connect ((position, removed, added) => { |
1324 | + loop.quit (); |
1325 | + }); |
1326 | + |
1327 | + menu.get_n_items (); |
1328 | + |
1329 | + source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return true; }); |
1330 | + loop.run (); |
1331 | + Source.remove (source); |
1332 | + menu.disconnect (signal_name); |
1333 | + |
1334 | + var section = menu.get_item_link (0, Menu.LINK_SECTION); |
1335 | + loop = new MainLoop (null, false); |
1336 | + signal_name = section.items_changed.connect ((position, removed, added) => { |
1337 | + loop.quit (); |
1338 | + }); |
1339 | + |
1340 | + section.get_n_items (); |
1341 | + |
1342 | + source = Timeout.add_seconds (TIMEOUT_S, () => { loop.quit (); return true; }); |
1343 | + loop.run (); |
1344 | + Source.remove (source); |
1345 | + section.disconnect (signal_name); |
1346 | + |
1347 | + string label; |
1348 | + |
1349 | + stderr.printf ("section.get_n_items () = %d\n", section.get_n_items ()); |
1350 | + assert (section.get_n_items () == 1); |
1351 | + section.get_item_attribute (0, Menu.ATTRIBUTE_LABEL, "s", out label); |
1352 | + stderr.printf ("label = \"%s\"\n", label); |
1353 | + assert (strcmp (label, "English (US)") == 0); |
1354 | + |
1355 | + loop = new MainLoop (null, false); |
1356 | + signal_name = section.items_changed.connect ((position, removed, added) => { |
1357 | + if (section.get_n_items () == 4) { |
1358 | + loop.quit (); |
1359 | + } |
1360 | + }); |
1361 | + |
1362 | + try { |
1363 | + var sources = "[('xkb', 'us'), ('xkb', 'ca+eng'), ('xkb', 'epo'), ('ibus', 'pinyin')]"; |
1364 | + Process.spawn_command_line_sync (@"gsettings set org.gnome.desktop.input-sources sources \"$sources\""); |
1365 | + } catch (SpawnError error) { |
1366 | + Test.message ("error: %s", error.message); |
1367 | + Test.fail (); |
1368 | + return; |
1369 | + } |
1370 | + |
1371 | + source = Timeout.add_seconds (LONG_TIMEOUT_S, () => { loop.quit (); return true; }); |
1372 | + loop.run (); |
1373 | + Source.remove (source); |
1374 | + section.disconnect (signal_name); |
1375 | + |
1376 | + stderr.printf ("section.get_n_items () = %d\n", section.get_n_items ()); |
1377 | + assert (section.get_n_items () == 4); |
1378 | + section.get_item_attribute (0, Menu.ATTRIBUTE_LABEL, "s", out label); |
1379 | + stderr.printf ("label = \"%s\"\n", label); |
1380 | + assert (strcmp (label, "English (US)") == 0); |
1381 | + section.get_item_attribute (1, Menu.ATTRIBUTE_LABEL, "s", out label); |
1382 | + stderr.printf ("label = \"%s\"\n", label); |
1383 | + assert (strcmp (label, "English (Canada)") == 0); |
1384 | + section.get_item_attribute (2, Menu.ATTRIBUTE_LABEL, "s", out label); |
1385 | + stderr.printf ("label = \"%s\"\n", label); |
1386 | + assert (strcmp (label, "Esperanto") == 0); |
1387 | + section.get_item_attribute (3, Menu.ATTRIBUTE_LABEL, "s", out label); |
1388 | + stderr.printf ("label = \"%s\"\n", label); |
1389 | + assert (label.ascii_casecmp ("Pinyin") == 0); |
1390 | + } |
1391 | } |
1392 | |
1393 | public int main (string[] args) { |
1394 | - Environment.set_variable ("DCONF_PROFILE", DCONF_PROFILE, true); |
1395 | - Environment.set_variable ("LC_ALL", "C", true); |
1396 | - |
1397 | - Test.init (ref args, null); |
1398 | - |
1399 | - var suite = new TestSuite ("indicator-keyboard"); |
1400 | - |
1401 | - suite.add (new TestCase ("activate-input-source", begin_test, test_activate_input_source, end_test, sizeof (Fixture))); |
1402 | - suite.add (new TestCase ("activate-character-map", begin_test, test_activate_character_map, end_test, sizeof (Fixture))); |
1403 | - suite.add (new TestCase ("activate-keyboard-layout-chart", begin_test, test_activate_keyboard_layout_chart, end_test, sizeof (Fixture))); |
1404 | - suite.add (new TestCase ("activate-text-entry-settings", begin_test, test_activate_text_entry_settings, end_test, sizeof (Fixture))); |
1405 | - suite.add (new TestCase ("migration", begin_test, test_migration, end_test, sizeof (Fixture))); |
1406 | - suite.add (new TestCase ("no-migration", begin_test, test_no_migration, end_test, sizeof (Fixture))); |
1407 | - suite.add (new TestCase ("update-visible", begin_test, test_update_visible, end_test, sizeof (Fixture))); |
1408 | - suite.add (new TestCase ("update-input-source", begin_test, test_update_input_source, end_test, sizeof (Fixture))); |
1409 | - suite.add (new TestCase ("update-input-sources", begin_test, test_update_input_sources, end_test, sizeof (Fixture))); |
1410 | - |
1411 | - TestSuite.get_root ().add_suite (suite); |
1412 | + display = Environment.get_variable ("DISPLAY"); |
1413 | + |
1414 | + Test.init (ref args); |
1415 | + |
1416 | + Test.add_data_func ("/indicator-keyboard-service/activate-input-source", Fixture.create<Tests> (Tests.test_activate_input_source)); |
1417 | + Test.add_data_func ("/indicator-keyboard-service/activate-character-map", Fixture.create<Tests> (Tests.test_activate_character_map)); |
1418 | + Test.add_data_func ("/indicator-keyboard-service/activate-keyboard-layout-chart", Fixture.create<Tests> (Tests.test_activate_keyboard_layout_chart)); |
1419 | + Test.add_data_func ("/indicator-keyboard-service/activate-text-entry-settings", Fixture.create<Tests> (Tests.test_activate_text_entry_settings)); |
1420 | + Test.add_data_func ("/indicator-keyboard-service/migration", Fixture.create<Tests> (Tests.test_migration)); |
1421 | + Test.add_data_func ("/indicator-keyboard-service/no-migration", Fixture.create<Tests> (Tests.test_no_migration)); |
1422 | + Test.add_data_func ("/indicator-keyboard-service/update-visible", Fixture.create<Tests> (Tests.test_update_visible)); |
1423 | + Test.add_data_func ("/indicator-keyboard-service/update-input-source", Fixture.create<Tests> (Tests.test_update_input_source)); |
1424 | + Test.add_data_func ("/indicator-keyboard-service/update-input-sources", Fixture.create<Tests> (Tests.test_update_input_sources)); |
1425 | |
1426 | return Test.run (); |
1427 | } |
PASSED: Continuous integration, rev:239 jenkins. qa.ubuntu. com/job/ indicator- keyboard- ci/39/ jenkins. qa.ubuntu. com/job/ indicator- keyboard- trusty- amd64-ci/ 6 jenkins. qa.ubuntu. com/job/ indicator- keyboard- trusty- armhf-ci/ 6 jenkins. qa.ubuntu. com/job/ indicator- keyboard- trusty- armhf-ci/ 6/artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/indicator- keyboard- ci/39/rebuild
http://