Branch data Line data Source code
1 : : #include <gio/gio.h>
2 : : #include <stdlib.h>
3 : : #include <string.h>
4 : : #include <unistd.h>
5 : :
6 : : #include "gdbus-tests.h"
7 : : #include "gdbus-sessionbus.h"
8 : :
9 : : #if 0
10 : : /* These tests are racy -- there is no guarantee about the order of data
11 : : * arriving over D-Bus.
12 : : *
13 : : * They're also a bit ridiculous -- GApplication was never meant to be
14 : : * abused in this way...
15 : : *
16 : : * We need new tests.
17 : : */
18 : : static gint outstanding_watches;
19 : : static GMainLoop *main_loop;
20 : :
21 : : typedef struct
22 : : {
23 : : gchar *expected_stdout;
24 : : gint stdout_pipe;
25 : : gchar *expected_stderr;
26 : : gint stderr_pipe;
27 : : } ChildData;
28 : :
29 : : static void
30 : : check_data (gint fd, const gchar *expected)
31 : : {
32 : : gssize len, actual;
33 : : gchar *buffer;
34 : :
35 : : len = strlen (expected);
36 : : buffer = g_alloca (len + 100);
37 : : actual = read (fd, buffer, len + 100);
38 : :
39 : : g_assert_cmpint (actual, >=, 0);
40 : :
41 : : if (actual != len ||
42 : : memcmp (buffer, expected, len) != 0)
43 : : {
44 : : buffer[MIN(len + 100, actual)] = '\0';
45 : :
46 : : g_error ("\nExpected\n-----\n%s-----\nGot (%s)\n-----\n%s-----\n",
47 : : expected,
48 : : (actual > len) ? "truncated" : "full", buffer);
49 : : }
50 : : }
51 : :
52 : : static void
53 : : child_quit (GPid pid,
54 : : gint status,
55 : : gpointer data)
56 : : {
57 : : ChildData *child = data;
58 : :
59 : : g_assert_cmpint (status, ==, 0);
60 : :
61 : : if (--outstanding_watches == 0)
62 : : g_main_loop_quit (main_loop);
63 : :
64 : : check_data (child->stdout_pipe, child->expected_stdout);
65 : : close (child->stdout_pipe);
66 : : g_free (child->expected_stdout);
67 : :
68 : : if (child->expected_stderr)
69 : : {
70 : : check_data (child->stderr_pipe, child->expected_stderr);
71 : : close (child->stderr_pipe);
72 : : g_free (child->expected_stderr);
73 : : }
74 : :
75 : : g_slice_free (ChildData, child);
76 : : }
77 : :
78 : : static void
79 : : spawn (const gchar *expected_stdout,
80 : : const gchar *expected_stderr,
81 : : const gchar *first_arg,
82 : : ...)
83 : : {
84 : : GError *error = NULL;
85 : : const gchar *arg;
86 : : GPtrArray *array;
87 : : ChildData *data;
88 : : gchar **args;
89 : : va_list ap;
90 : : GPid pid;
91 : : GPollFD fd;
92 : : gchar **env;
93 : :
94 : : va_start (ap, first_arg);
95 : : array = g_ptr_array_new ();
96 : : g_ptr_array_add (array, g_test_build_filename (G_TEST_BUILT, "basic-application", NULL));
97 : : for (arg = first_arg; arg; arg = va_arg (ap, const gchar *))
98 : : g_ptr_array_add (array, g_strdup (arg));
99 : : g_ptr_array_add (array, NULL);
100 : : args = (gchar **) g_ptr_array_free (array, FALSE);
101 : : va_end (ap);
102 : :
103 : : env = g_environ_setenv (g_get_environ (), "TEST", "1", TRUE);
104 : :
105 : : data = g_slice_new (ChildData);
106 : : data->expected_stdout = g_strdup (expected_stdout);
107 : : data->expected_stderr = g_strdup (expected_stderr);
108 : :
109 : : g_spawn_async_with_pipes (NULL, args, env,
110 : : G_SPAWN_DO_NOT_REAP_CHILD,
111 : : NULL, NULL, &pid, NULL,
112 : : &data->stdout_pipe,
113 : : expected_stderr ? &data->stderr_pipe : NULL,
114 : : &error);
115 : : g_assert_no_error (error);
116 : :
117 : : g_strfreev (env);
118 : :
119 : : g_child_watch_add (pid, child_quit, data);
120 : : outstanding_watches++;
121 : :
122 : : /* we block until the children write to stdout to make sure
123 : : * they have started, as they need to be executed in order;
124 : : * see https://bugzilla.gnome.org/show_bug.cgi?id=664627
125 : : */
126 : : fd.fd = data->stdout_pipe;
127 : : fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
128 : : g_poll (&fd, 1, -1);
129 : : }
130 : :
131 : : static void
132 : : basic (void)
133 : : {
134 : : GDBusConnection *c;
135 : :
136 : : g_assert (outstanding_watches == 0);
137 : :
138 : : session_bus_up ();
139 : : c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
140 : :
141 : : main_loop = g_main_loop_new (NULL, 0);
142 : :
143 : : /* spawn the main instance */
144 : : spawn ("activated\n"
145 : : "open file:///a file:///b\n"
146 : : "exit status: 0\n", NULL,
147 : : "./app", NULL);
148 : :
149 : : /* send it some files */
150 : : spawn ("exit status: 0\n", NULL,
151 : : "./app", "/a", "/b", NULL);
152 : :
153 : : g_main_loop_run (main_loop);
154 : :
155 : : g_object_unref (c);
156 : : session_bus_down ();
157 : :
158 : : g_main_loop_unref (main_loop);
159 : : }
160 : :
161 : : static void
162 : : test_remote_command_line (void)
163 : : {
164 : : GDBusConnection *c;
165 : : GFile *file;
166 : : gchar *replies;
167 : : gchar *cwd;
168 : :
169 : : g_assert (outstanding_watches == 0);
170 : :
171 : : session_bus_up ();
172 : : c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
173 : :
174 : : main_loop = g_main_loop_new (NULL, 0);
175 : :
176 : : file = g_file_new_for_commandline_arg ("foo");
177 : : cwd = g_get_current_dir ();
178 : :
179 : : replies = g_strconcat ("got ./cmd 0\n",
180 : : "got ./cmd 1\n",
181 : : "cmdline ./cmd echo --abc -d\n",
182 : : "environment TEST=1\n",
183 : : "getenv TEST=1\n",
184 : : "file ", g_file_get_path (file), "\n",
185 : : "properties ok\n",
186 : : "cwd ", cwd, "\n",
187 : : "busy\n",
188 : : "idle\n",
189 : : "stdin ok\n",
190 : : "exit status: 0\n",
191 : : NULL);
192 : : g_object_unref (file);
193 : :
194 : : /* spawn the main instance */
195 : : spawn (replies, NULL,
196 : : "./cmd", NULL);
197 : :
198 : : g_free (replies);
199 : :
200 : : /* send it a few commandlines */
201 : : spawn ("exit status: 0\n", NULL,
202 : : "./cmd", NULL);
203 : :
204 : : spawn ("exit status: 0\n", NULL,
205 : : "./cmd", "echo", "--abc", "-d", NULL);
206 : :
207 : : spawn ("exit status: 0\n", NULL,
208 : : "./cmd", "env", NULL);
209 : :
210 : : spawn ("exit status: 0\n", NULL,
211 : : "./cmd", "getenv", NULL);
212 : :
213 : : spawn ("print test\n"
214 : : "exit status: 0\n", NULL,
215 : : "./cmd", "print", "test", NULL);
216 : :
217 : : spawn ("exit status: 0\n", "printerr test\n",
218 : : "./cmd", "printerr", "test", NULL);
219 : :
220 : : spawn ("exit status: 0\n", NULL,
221 : : "./cmd", "file", "foo", NULL);
222 : :
223 : : spawn ("exit status: 0\n", NULL,
224 : : "./cmd", "properties", NULL);
225 : :
226 : : spawn ("exit status: 0\n", NULL,
227 : : "./cmd", "cwd", NULL);
228 : :
229 : : spawn ("exit status: 0\n", NULL,
230 : : "./cmd", "busy", NULL);
231 : :
232 : : spawn ("exit status: 0\n", NULL,
233 : : "./cmd", "idle", NULL);
234 : :
235 : : spawn ("exit status: 0\n", NULL,
236 : : "./cmd", "stdin", NULL);
237 : :
238 : : g_main_loop_run (main_loop);
239 : :
240 : : g_object_unref (c);
241 : : session_bus_down ();
242 : :
243 : : g_main_loop_unref (main_loop);
244 : : }
245 : :
246 : : static void
247 : : test_remote_actions (void)
248 : : {
249 : : GDBusConnection *c;
250 : :
251 : : g_assert (outstanding_watches == 0);
252 : :
253 : : session_bus_up ();
254 : : c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
255 : :
256 : : main_loop = g_main_loop_new (NULL, 0);
257 : :
258 : : /* spawn the main instance */
259 : : spawn ("got ./cmd 0\n"
260 : : "activate action1\n"
261 : : "change action2 1\n"
262 : : "exit status: 0\n", NULL,
263 : : "./cmd", NULL);
264 : :
265 : : spawn ("actions quit new action1 action2\n"
266 : : "exit status: 0\n", NULL,
267 : : "./actions", "list", NULL);
268 : :
269 : : spawn ("exit status: 0\n", NULL,
270 : : "./actions", "activate", NULL);
271 : :
272 : : spawn ("exit status: 0\n", NULL,
273 : : "./actions", "set-state", NULL);
274 : :
275 : : g_main_loop_run (main_loop);
276 : :
277 : : g_object_unref (c);
278 : : session_bus_down ();
279 : :
280 : : g_main_loop_unref (main_loop);
281 : : }
282 : : #endif
283 : :
284 : : #if 0
285 : : /* Now that we register non-unique apps on the bus we need to fix the
286 : : * following test not to assume that it's safe to create multiple instances
287 : : * of the same app in one process.
288 : : *
289 : : * See https://bugzilla.gnome.org/show_bug.cgi?id=647986 for the patch that
290 : : * introduced this problem.
291 : : */
292 : :
293 : : static GApplication *recently_activated;
294 : : static GMainLoop *loop;
295 : :
296 : : static void
297 : : nonunique_activate (GApplication *application)
298 : : {
299 : : recently_activated = application;
300 : :
301 : : if (loop != NULL)
302 : : g_main_loop_quit (loop);
303 : : }
304 : :
305 : : static GApplication *
306 : : make_app (gboolean non_unique)
307 : : {
308 : : GApplication *app;
309 : : gboolean ok;
310 : :
311 : : app = g_application_new ("org.gtk.Test-Application",
312 : : non_unique ? G_APPLICATION_NON_UNIQUE : 0);
313 : : g_signal_connect (app, "activate", G_CALLBACK (nonunique_activate), NULL);
314 : : ok = g_application_register (app, NULL, NULL);
315 : : if (!ok)
316 : : {
317 : : g_object_unref (app);
318 : : return NULL;
319 : : }
320 : :
321 : : g_application_activate (app);
322 : :
323 : : return app;
324 : : }
325 : :
326 : : static void
327 : : test_nonunique (void)
328 : : {
329 : : GApplication *first, *second, *third, *fourth;
330 : :
331 : : session_bus_up ();
332 : :
333 : : first = make_app (TRUE);
334 : : /* non-remote because it is non-unique */
335 : : g_assert (!g_application_get_is_remote (first));
336 : : g_assert (recently_activated == first);
337 : : recently_activated = NULL;
338 : :
339 : : second = make_app (FALSE);
340 : : /* non-remote because it is first */
341 : : g_assert (!g_application_get_is_remote (second));
342 : : g_assert (recently_activated == second);
343 : : recently_activated = NULL;
344 : :
345 : : third = make_app (TRUE);
346 : : /* non-remote because it is non-unique */
347 : : g_assert (!g_application_get_is_remote (third));
348 : : g_assert (recently_activated == third);
349 : : recently_activated = NULL;
350 : :
351 : : fourth = make_app (FALSE);
352 : : /* should have failed to register due to being
353 : : * unable to register the object paths
354 : : */
355 : : g_assert (fourth == NULL);
356 : : g_assert (recently_activated == NULL);
357 : :
358 : : g_object_unref (first);
359 : : g_object_unref (second);
360 : : g_object_unref (third);
361 : :
362 : : session_bus_down ();
363 : : }
364 : : #endif
365 : :
366 : : static void
367 : 1 : properties (void)
368 : : {
369 : : GDBusConnection *c;
370 : : GObject *app;
371 : : gchar *id;
372 : : gchar *version;
373 : : GApplicationFlags flags;
374 : : gboolean registered;
375 : : guint timeout;
376 : : gboolean remote;
377 : : gboolean ret;
378 : 1 : GError *error = NULL;
379 : :
380 : 1 : session_bus_up ();
381 : 1 : c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
382 : :
383 : 1 : app = g_object_new (G_TYPE_APPLICATION,
384 : : "application-id", "org.gtk.TestApplication",
385 : : "version", "1.0",
386 : : NULL);
387 : :
388 : 1 : g_object_get (app,
389 : : "application-id", &id,
390 : : "version", &version,
391 : : "flags", &flags,
392 : : "is-registered", ®istered,
393 : : "inactivity-timeout", &timeout,
394 : : NULL);
395 : :
396 : 1 : g_assert_cmpstr (id, ==, "org.gtk.TestApplication");
397 : 1 : g_assert_cmpstr (version, ==, "1.0");
398 : 1 : g_assert_cmpint (flags, ==, G_APPLICATION_DEFAULT_FLAGS);
399 : 1 : g_assert (!registered);
400 : 1 : g_assert_cmpint (timeout, ==, 0);
401 : :
402 : 1 : g_clear_pointer (&version, g_free);
403 : :
404 : 1 : ret = g_application_register (G_APPLICATION (app), NULL, &error);
405 : 1 : g_assert (ret);
406 : 1 : g_assert_no_error (error);
407 : :
408 : 1 : g_object_get (app,
409 : : "is-registered", ®istered,
410 : : "is-remote", &remote,
411 : : NULL);
412 : :
413 : 1 : g_assert (registered);
414 : 1 : g_assert (!remote);
415 : :
416 : 1 : g_object_set (app,
417 : : "inactivity-timeout", 1000,
418 : : NULL);
419 : :
420 : 1 : g_application_quit (G_APPLICATION (app));
421 : :
422 : 1 : g_object_unref (c);
423 : 1 : g_object_unref (app);
424 : 1 : g_free (id);
425 : :
426 : 1 : session_bus_down ();
427 : 1 : }
428 : :
429 : : static void
430 : 1 : appid (void)
431 : : {
432 : : gchar *id;
433 : :
434 : 1 : g_assert_false (g_application_id_is_valid (""));
435 : 1 : g_assert_false (g_application_id_is_valid ("."));
436 : 1 : g_assert_false (g_application_id_is_valid ("a"));
437 : 1 : g_assert_false (g_application_id_is_valid ("abc"));
438 : 1 : g_assert_false (g_application_id_is_valid (".abc"));
439 : 1 : g_assert_false (g_application_id_is_valid ("abc."));
440 : 1 : g_assert_false (g_application_id_is_valid ("a..b"));
441 : 1 : g_assert_false (g_application_id_is_valid ("a/b"));
442 : 1 : g_assert_false (g_application_id_is_valid ("a\nb"));
443 : 1 : g_assert_false (g_application_id_is_valid ("a\nb"));
444 : 1 : g_assert_false (g_application_id_is_valid ("emoji_picker"));
445 : 1 : g_assert_false (g_application_id_is_valid ("emoji-picker"));
446 : 1 : g_assert_false (g_application_id_is_valid ("emojipicker"));
447 : 1 : g_assert_false (g_application_id_is_valid ("my.Terminal.0123"));
448 : 1 : id = g_new0 (gchar, 261);
449 : 1 : memset (id, 'a', 260);
450 : 1 : id[1] = '.';
451 : 1 : id[260] = 0;
452 : 1 : g_assert_false (g_application_id_is_valid (id));
453 : 1 : g_free (id);
454 : :
455 : 1 : g_assert_true (g_application_id_is_valid ("a.b"));
456 : 1 : g_assert_true (g_application_id_is_valid ("A.B"));
457 : 1 : g_assert_true (g_application_id_is_valid ("A-.B"));
458 : 1 : g_assert_true (g_application_id_is_valid ("a_b.c-d"));
459 : 1 : g_assert_true (g_application_id_is_valid ("_a.b"));
460 : 1 : g_assert_true (g_application_id_is_valid ("-a.b"));
461 : 1 : g_assert_true (g_application_id_is_valid ("org.gnome.SessionManager"));
462 : 1 : g_assert_true (g_application_id_is_valid ("my.Terminal._0123"));
463 : 1 : g_assert_true (g_application_id_is_valid ("com.example.MyApp"));
464 : 1 : g_assert_true (g_application_id_is_valid ("com.example.internal_apps.Calculator"));
465 : 1 : g_assert_true (g_application_id_is_valid ("org._7_zip.Archiver"));
466 : 1 : }
467 : :
468 : : static gboolean nodbus_activated;
469 : :
470 : : static gboolean
471 : 3 : release_app (gpointer user_data)
472 : : {
473 : 3 : g_application_release (user_data);
474 : 3 : return G_SOURCE_REMOVE;
475 : : }
476 : :
477 : : static void
478 : 1 : nodbus_activate (GApplication *app)
479 : : {
480 : 1 : nodbus_activated = TRUE;
481 : 1 : g_application_hold (app);
482 : :
483 : 1 : g_assert (g_application_get_dbus_connection (app) == NULL);
484 : 1 : g_assert (g_application_get_dbus_object_path (app) == NULL);
485 : :
486 : 1 : g_idle_add (release_app, app);
487 : 1 : }
488 : :
489 : : static void
490 : 1 : test_nodbus (void)
491 : : {
492 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
493 : 1 : gchar *argv[] = { binpath, NULL };
494 : : GApplication *app;
495 : :
496 : 1 : app = g_application_new ("org.gtk.Unimportant", G_APPLICATION_DEFAULT_FLAGS);
497 : 1 : g_signal_connect (app, "activate", G_CALLBACK (nodbus_activate), NULL);
498 : 1 : g_application_run (app, 1, argv);
499 : 1 : g_object_unref (app);
500 : :
501 : 1 : g_assert (nodbus_activated);
502 : 1 : g_free (binpath);
503 : 1 : }
504 : :
505 : : static gboolean noappid_activated;
506 : :
507 : : static void
508 : 2 : noappid_activate (GApplication *app)
509 : : {
510 : 2 : noappid_activated = TRUE;
511 : 2 : g_application_hold (app);
512 : :
513 : 2 : g_assert (g_application_get_flags (app) & G_APPLICATION_NON_UNIQUE);
514 : :
515 : 2 : g_idle_add (release_app, app);
516 : 2 : }
517 : :
518 : : /* test that no appid -> non-unique */
519 : : static void
520 : 1 : test_noappid (void)
521 : : {
522 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
523 : 1 : gchar *argv[] = { binpath, NULL };
524 : : GApplication *app;
525 : :
526 : 1 : app = g_application_new (NULL, G_APPLICATION_DEFAULT_FLAGS);
527 : 1 : g_signal_connect (app, "activate", G_CALLBACK (noappid_activate), NULL);
528 : 1 : g_application_run (app, 1, argv);
529 : 1 : g_object_unref (app);
530 : :
531 : 1 : g_assert (noappid_activated);
532 : 1 : g_free (binpath);
533 : 1 : }
534 : :
535 : : static gboolean activated;
536 : : static gboolean quitted;
537 : :
538 : : static gboolean
539 : 1 : quit_app (gpointer user_data)
540 : : {
541 : 1 : quitted = TRUE;
542 : 1 : g_application_quit (user_data);
543 : 1 : return G_SOURCE_REMOVE;
544 : : }
545 : :
546 : : static void
547 : 1 : quit_activate (GApplication *app)
548 : : {
549 : 1 : activated = TRUE;
550 : 1 : g_application_hold (app);
551 : :
552 : 1 : g_assert (g_application_get_dbus_connection (app) != NULL);
553 : 1 : g_assert (g_application_get_dbus_object_path (app) != NULL);
554 : :
555 : 1 : g_idle_add (quit_app, app);
556 : 1 : }
557 : :
558 : : static void
559 : 1 : test_quit (void)
560 : : {
561 : : GDBusConnection *c;
562 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
563 : 1 : gchar *argv[] = { binpath, NULL };
564 : : GApplication *app;
565 : :
566 : 1 : session_bus_up ();
567 : 1 : c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
568 : :
569 : 1 : app = g_application_new ("org.gtk.Unimportant",
570 : : G_APPLICATION_DEFAULT_FLAGS);
571 : 1 : activated = FALSE;
572 : 1 : quitted = FALSE;
573 : 1 : g_signal_connect (app, "activate", G_CALLBACK (quit_activate), NULL);
574 : 1 : g_application_run (app, 1, argv);
575 : 1 : g_object_unref (app);
576 : 1 : g_object_unref (c);
577 : :
578 : 1 : g_assert (activated);
579 : 1 : g_assert (quitted);
580 : :
581 : 1 : session_bus_down ();
582 : 1 : g_free (binpath);
583 : 1 : }
584 : :
585 : : typedef struct
586 : : {
587 : : gboolean shutdown;
588 : : GParamSpec *notify_spec; /* (owned) (nullable) */
589 : : } RegisteredData;
590 : :
591 : : static void
592 : 1 : on_registered_shutdown (GApplication *app,
593 : : gpointer user_data)
594 : : {
595 : 1 : RegisteredData *registered_data = user_data;
596 : :
597 : 1 : registered_data->shutdown = TRUE;
598 : 1 : }
599 : :
600 : : static void
601 : 3 : on_registered_notify (GApplication *app,
602 : : GParamSpec *spec,
603 : : gpointer user_data)
604 : : {
605 : 3 : RegisteredData *registered_data = user_data;
606 : 3 : registered_data->notify_spec = g_param_spec_ref (spec);
607 : :
608 : 3 : if (g_application_get_is_registered (app))
609 : 2 : g_assert_false (registered_data->shutdown);
610 : : else
611 : 1 : g_assert_true (registered_data->shutdown);
612 : 3 : }
613 : :
614 : : static void
615 : 1 : test_registered (void)
616 : : {
617 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
618 : 1 : gchar *argv[] = { binpath, NULL };
619 : 1 : RegisteredData registered_data = { FALSE, NULL };
620 : : GApplication *app;
621 : :
622 : 1 : app = g_application_new (NULL, G_APPLICATION_DEFAULT_FLAGS);
623 : 1 : g_signal_connect (app, "activate", G_CALLBACK (noappid_activate), NULL);
624 : 1 : g_signal_connect (app, "shutdown", G_CALLBACK (on_registered_shutdown), ®istered_data);
625 : 1 : g_signal_connect (app, "notify::is-registered", G_CALLBACK (on_registered_notify), ®istered_data);
626 : :
627 : 1 : g_assert_null (registered_data.notify_spec);
628 : :
629 : 1 : g_assert_true (g_application_register (app, NULL, NULL));
630 : 1 : g_assert_true (g_application_get_is_registered (app));
631 : :
632 : 1 : g_assert_nonnull (registered_data.notify_spec);
633 : 1 : g_assert_cmpstr (registered_data.notify_spec->name, ==, "is-registered");
634 : 1 : g_clear_pointer (®istered_data.notify_spec, g_param_spec_unref);
635 : :
636 : 1 : g_assert_false (registered_data.shutdown);
637 : :
638 : 1 : g_application_run (app, 1, argv);
639 : :
640 : 1 : g_assert_true (registered_data.shutdown);
641 : 1 : g_assert_false (g_application_get_is_registered (app));
642 : 1 : g_assert_nonnull (registered_data.notify_spec);
643 : 1 : g_assert_cmpstr (registered_data.notify_spec->name, ==, "is-registered");
644 : 1 : g_clear_pointer (®istered_data.notify_spec, g_param_spec_unref);
645 : :
646 : : /* Register it again */
647 : 1 : registered_data.shutdown = FALSE;
648 : 1 : g_assert_true (g_application_register (app, NULL, NULL));
649 : 1 : g_assert_true (g_application_get_is_registered (app));
650 : 1 : g_assert_nonnull (registered_data.notify_spec);
651 : 1 : g_assert_cmpstr (registered_data.notify_spec->name, ==, "is-registered");
652 : 1 : g_clear_pointer (®istered_data.notify_spec, g_param_spec_unref);
653 : 1 : g_assert_false (registered_data.shutdown);
654 : :
655 : 1 : g_object_unref (app);
656 : :
657 : 1 : g_free (binpath);
658 : 1 : }
659 : :
660 : : static void
661 : 1 : on_activate (GApplication *app)
662 : : {
663 : : gchar **actions;
664 : : GAction *action;
665 : : GVariant *state;
666 : :
667 : 1 : g_assert (!g_application_get_is_remote (app));
668 : :
669 : 1 : actions = g_action_group_list_actions (G_ACTION_GROUP (app));
670 : 1 : g_assert (g_strv_length (actions) == 0);
671 : 1 : g_strfreev (actions);
672 : :
673 : 1 : action = (GAction*)g_simple_action_new_stateful ("test", G_VARIANT_TYPE_BOOLEAN, g_variant_new_boolean (FALSE));
674 : 1 : g_action_map_add_action (G_ACTION_MAP (app), action);
675 : :
676 : 1 : actions = g_action_group_list_actions (G_ACTION_GROUP (app));
677 : 1 : g_assert (g_strv_length (actions) == 1);
678 : 1 : g_strfreev (actions);
679 : :
680 : 1 : g_action_group_change_action_state (G_ACTION_GROUP (app), "test", g_variant_new_boolean (TRUE));
681 : 1 : state = g_action_group_get_action_state (G_ACTION_GROUP (app), "test");
682 : 1 : g_assert (g_variant_get_boolean (state) == TRUE);
683 : :
684 : 1 : action = g_action_map_lookup_action (G_ACTION_MAP (app), "test");
685 : 1 : g_assert (action != NULL);
686 : :
687 : 1 : g_action_map_remove_action (G_ACTION_MAP (app), "test");
688 : :
689 : 1 : actions = g_action_group_list_actions (G_ACTION_GROUP (app));
690 : 1 : g_assert (g_strv_length (actions) == 0);
691 : 1 : g_strfreev (actions);
692 : 1 : }
693 : :
694 : : static void
695 : 1 : test_local_actions (void)
696 : : {
697 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
698 : 1 : gchar *argv[] = { binpath, NULL };
699 : : GApplication *app;
700 : :
701 : 1 : app = g_application_new ("org.gtk.Unimportant",
702 : : G_APPLICATION_DEFAULT_FLAGS);
703 : 1 : g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
704 : 1 : g_application_run (app, 1, argv);
705 : 1 : g_object_unref (app);
706 : 1 : g_free (binpath);
707 : 1 : }
708 : :
709 : : typedef GApplication TestLocCmdApp;
710 : : typedef GApplicationClass TestLocCmdAppClass;
711 : :
712 : : static GType test_loc_cmd_app_get_type (void);
713 : 3 : G_DEFINE_TYPE (TestLocCmdApp, test_loc_cmd_app, G_TYPE_APPLICATION)
714 : :
715 : : static void
716 : 1 : test_loc_cmd_app_init (TestLocCmdApp *app)
717 : : {
718 : 1 : }
719 : :
720 : : static void
721 : 0 : test_loc_cmd_app_startup (GApplication *app)
722 : : {
723 : : g_assert_not_reached ();
724 : : }
725 : :
726 : : static void
727 : 0 : test_loc_cmd_app_shutdown (GApplication *app)
728 : : {
729 : : g_assert_not_reached ();
730 : : }
731 : :
732 : : static gboolean
733 : 1 : test_loc_cmd_app_local_command_line (GApplication *application,
734 : : gchar ***arguments,
735 : : gint *exit_status)
736 : : {
737 : 1 : return TRUE;
738 : : }
739 : :
740 : : static void
741 : 1 : test_loc_cmd_app_class_init (TestLocCmdAppClass *klass)
742 : : {
743 : 1 : G_APPLICATION_CLASS (klass)->startup = test_loc_cmd_app_startup;
744 : 1 : G_APPLICATION_CLASS (klass)->shutdown = test_loc_cmd_app_shutdown;
745 : 1 : G_APPLICATION_CLASS (klass)->local_command_line = test_loc_cmd_app_local_command_line;
746 : 1 : }
747 : :
748 : : static void
749 : 1 : test_local_command_line (void)
750 : : {
751 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
752 : 1 : gchar *argv[] = { binpath, "-invalid", NULL };
753 : : GApplication *app;
754 : :
755 : 1 : app = g_object_new (test_loc_cmd_app_get_type (),
756 : : "application-id", "org.gtk.Unimportant",
757 : : "flags", G_APPLICATION_DEFAULT_FLAGS,
758 : : NULL);
759 : 1 : g_application_run (app, 1, argv);
760 : 1 : g_object_unref (app);
761 : 1 : g_free (binpath);
762 : 1 : }
763 : :
764 : : static void
765 : 1 : test_resource_path (void)
766 : : {
767 : : GApplication *app;
768 : :
769 : 1 : app = g_application_new ("x.y.z", 0);
770 : 1 : g_assert_cmpstr (g_application_get_resource_base_path (app), ==, "/x/y/z");
771 : :
772 : : /* this should not change anything */
773 : 1 : g_application_set_application_id (app, "a.b.c");
774 : 1 : g_assert_cmpstr (g_application_get_resource_base_path (app), ==, "/x/y/z");
775 : :
776 : : /* but this should... */
777 : 1 : g_application_set_resource_base_path (app, "/x");
778 : 1 : g_assert_cmpstr (g_application_get_resource_base_path (app), ==, "/x");
779 : :
780 : : /* ... and this */
781 : 1 : g_application_set_resource_base_path (app, NULL);
782 : 1 : g_assert_cmpstr (g_application_get_resource_base_path (app), ==, NULL);
783 : :
784 : 1 : g_object_unref (app);
785 : :
786 : : /* Make sure that overriding at construction time works properly */
787 : 1 : app = g_object_new (G_TYPE_APPLICATION, "application-id", "x.y.z", "resource-base-path", "/a", NULL);
788 : 1 : g_assert_cmpstr (g_application_get_resource_base_path (app), ==, "/a");
789 : 1 : g_object_unref (app);
790 : :
791 : : /* ... particularly if we override to NULL */
792 : 1 : app = g_object_new (G_TYPE_APPLICATION, "application-id", "x.y.z", "resource-base-path", NULL, NULL);
793 : 1 : g_assert_cmpstr (g_application_get_resource_base_path (app), ==, NULL);
794 : 1 : g_object_unref (app);
795 : 1 : }
796 : :
797 : : static gint
798 : 0 : test_help_command_line (GApplication *app,
799 : : GApplicationCommandLine *command_line,
800 : : gpointer user_data)
801 : : {
802 : 0 : gboolean *called = user_data;
803 : :
804 : 0 : *called = TRUE;
805 : :
806 : 0 : return 0;
807 : : }
808 : :
809 : : /* Test whether --help is handled when HANDLES_COMMND_LINE is set and
810 : : * options have been added.
811 : : */
812 : : static void
813 : 2 : test_help (void)
814 : : {
815 : 2 : if (g_test_subprocess ())
816 : : {
817 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
818 : 1 : gchar *argv[] = { binpath, "--help", NULL };
819 : : GApplication *app;
820 : 1 : gboolean called = FALSE;
821 : : int status;
822 : :
823 : 1 : app = g_application_new ("org.gtk.TestApplication", G_APPLICATION_HANDLES_COMMAND_LINE);
824 : 1 : g_application_add_main_option (app, "foo", 'f', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
825 : 1 : g_signal_connect (app, "command-line", G_CALLBACK (test_help_command_line), &called);
826 : :
827 : 1 : status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
828 : 0 : g_assert (called == TRUE);
829 : 0 : g_assert_cmpint (status, ==, 0);
830 : :
831 : 0 : g_object_unref (app);
832 : 0 : g_free (binpath);
833 : 0 : return;
834 : : }
835 : :
836 : 1 : g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
837 : 1 : g_test_trap_assert_passed ();
838 : 1 : g_test_trap_assert_stdout ("*Application options*");
839 : : }
840 : :
841 : : static gint
842 : 1 : command_line_done_callback (GApplication *app,
843 : : GApplicationCommandLine *command_line,
844 : : gpointer user_data)
845 : : {
846 : 1 : gboolean *called = user_data;
847 : :
848 : 1 : *called = TRUE;
849 : :
850 : 1 : g_application_command_line_set_exit_status (command_line, 42);
851 : 1 : g_application_command_line_done (command_line);
852 : :
853 : 1 : return 0;
854 : : }
855 : :
856 : : /* Test whether 'command-line' handler return value is ignored
857 : : * after g_application_command_line_done()
858 : : */
859 : : static void
860 : 1 : test_command_line_done (void)
861 : : {
862 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
863 : 1 : const gchar *const argv[] = { binpath, "arg", NULL };
864 : : GApplication *app;
865 : 1 : gboolean called = FALSE;
866 : : int status;
867 : : gulong command_line_id;
868 : :
869 : 1 : app = g_application_new ("org.gtk.TestApplication", G_APPLICATION_HANDLES_COMMAND_LINE);
870 : 1 : command_line_id = g_signal_connect (app, "command-line", G_CALLBACK (command_line_done_callback), &called);
871 : :
872 : 1 : status = g_application_run (app, G_N_ELEMENTS (argv) - 1, (gchar **) argv);
873 : :
874 : 1 : g_signal_handler_disconnect (app, command_line_id);
875 : 1 : g_object_unref (app);
876 : 1 : g_free (binpath);
877 : :
878 : 1 : g_assert_true (called);
879 : 1 : g_assert_cmpint (status, ==, 42);
880 : 1 : }
881 : :
882 : : typedef GApplication TestCommandLineArgumentsApp;
883 : : typedef GApplicationClass TestCommandLineArgumentsAppClass;
884 : :
885 : : static GType test_command_line_arguments_app_get_type (void);
886 : 3 : G_DEFINE_TYPE (TestCommandLineArgumentsApp, test_command_line_arguments_app, G_TYPE_APPLICATION)
887 : :
888 : : static void
889 : 1 : test_command_line_arguments_app_init (TestCommandLineArgumentsApp *app)
890 : : {
891 : 1 : }
892 : :
893 : : static gboolean
894 : 1 : test_command_line_arguments_app_local_command_line (GApplication *application,
895 : : char ***arguments,
896 : : int *exit_status)
897 : : {
898 : : /* Pretend we couldn’t parse the arguments */
899 : 1 : return FALSE;
900 : : }
901 : :
902 : : static void
903 : 1 : test_command_line_arguments_app_class_init (TestCommandLineArgumentsAppClass *klass)
904 : : {
905 : 1 : G_APPLICATION_CLASS (klass)->local_command_line = test_command_line_arguments_app_local_command_line;
906 : 1 : }
907 : :
908 : : static gint
909 : 1 : command_line_arguments_callback (GApplication *app,
910 : : GApplicationCommandLine *command_line,
911 : : void *user_data)
912 : : {
913 : 1 : char ***out_args = user_data;
914 : : int argc;
915 : :
916 : 1 : *out_args = g_application_command_line_get_arguments (command_line, &argc);
917 : 1 : g_assert_cmpint (argc, ==, g_strv_length (*out_args));
918 : :
919 : 1 : return 42; /* exit status */
920 : : }
921 : :
922 : : static void
923 : 1 : test_command_line_arguments (void)
924 : : {
925 : 1 : g_test_summary ("Test HANDLES_COMMAND_LINE locally with a ->local_command_line "
926 : : "vfunc which forces g_application_run() to take a fallback error handling path");
927 : :
928 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
929 : 1 : const char *const argv[] = { binpath, "spam", "eggs", NULL };
930 : : GApplication *app;
931 : : int status;
932 : : unsigned long command_line_id;
933 : 1 : char **args = NULL;
934 : :
935 : 1 : app = g_object_new (test_command_line_arguments_app_get_type (),
936 : : "application-id", "org.gtk.TestApplication",
937 : : "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
938 : : NULL);
939 : 1 : command_line_id = g_signal_connect (app, "command-line", G_CALLBACK (command_line_arguments_callback), &args);
940 : :
941 : 1 : status = g_application_run (app, G_N_ELEMENTS (argv) - 1, (char **) argv);
942 : :
943 : 1 : g_assert_cmpint (status, ==, 42);
944 : 4 : g_assert_cmpstrv (args, argv);
945 : :
946 : 1 : g_signal_handler_disconnect (app, command_line_id);
947 : 1 : g_object_unref (app);
948 : 1 : g_free (binpath);
949 : 1 : g_strfreev (args);
950 : 1 : }
951 : :
952 : : static void
953 : 1 : test_busy (void)
954 : : {
955 : : GApplication *app;
956 : :
957 : : /* use GSimpleAction to bind to the busy state, because it's easy to
958 : : * create and has an easily modifiable boolean property */
959 : : GSimpleAction *action1;
960 : : GSimpleAction *action2;
961 : :
962 : 1 : session_bus_up ();
963 : :
964 : 1 : app = g_application_new ("org.gtk.TestApplication", G_APPLICATION_NON_UNIQUE);
965 : 1 : g_assert (g_application_register (app, NULL, NULL));
966 : :
967 : 1 : g_assert (!g_application_get_is_busy (app));
968 : 1 : g_application_mark_busy (app);
969 : 1 : g_assert (g_application_get_is_busy (app));
970 : 1 : g_application_unmark_busy (app);
971 : 1 : g_assert (!g_application_get_is_busy (app));
972 : :
973 : 1 : action1 = g_simple_action_new ("action", NULL);
974 : 1 : g_application_bind_busy_property (app, action1, "enabled");
975 : 1 : g_assert (g_application_get_is_busy (app));
976 : :
977 : 1 : g_simple_action_set_enabled (action1, FALSE);
978 : 1 : g_assert (!g_application_get_is_busy (app));
979 : :
980 : 1 : g_application_mark_busy (app);
981 : 1 : g_assert (g_application_get_is_busy (app));
982 : :
983 : 1 : action2 = g_simple_action_new ("action", NULL);
984 : 1 : g_application_bind_busy_property (app, action2, "enabled");
985 : 1 : g_assert (g_application_get_is_busy (app));
986 : :
987 : 1 : g_application_unmark_busy (app);
988 : 1 : g_assert (g_application_get_is_busy (app));
989 : :
990 : 1 : g_object_unref (action2);
991 : 1 : g_assert (!g_application_get_is_busy (app));
992 : :
993 : 1 : g_simple_action_set_enabled (action1, TRUE);
994 : 1 : g_assert (g_application_get_is_busy (app));
995 : :
996 : 1 : g_application_mark_busy (app);
997 : 1 : g_assert (g_application_get_is_busy (app));
998 : :
999 : 1 : g_application_unbind_busy_property (app, action1, "enabled");
1000 : 1 : g_assert (g_application_get_is_busy (app));
1001 : :
1002 : 1 : g_application_unmark_busy (app);
1003 : 1 : g_assert (!g_application_get_is_busy (app));
1004 : :
1005 : 1 : g_object_unref (action1);
1006 : 1 : g_object_unref (app);
1007 : :
1008 : 1 : session_bus_down ();
1009 : 1 : }
1010 : :
1011 : : /*
1012 : : * Test that handle-local-options works as expected
1013 : : */
1014 : :
1015 : : static gint
1016 : 3 : test_local_options (GApplication *app,
1017 : : GVariantDict *options,
1018 : : gpointer data)
1019 : : {
1020 : 3 : gboolean *called = data;
1021 : :
1022 : 3 : *called = TRUE;
1023 : :
1024 : 3 : if (g_variant_dict_contains (options, "success"))
1025 : 1 : return 0;
1026 : 2 : else if (g_variant_dict_contains (options, "failure"))
1027 : 1 : return 1;
1028 : : else
1029 : 1 : return -1;
1030 : : }
1031 : :
1032 : : static gint
1033 : 1 : second_handler (GApplication *app,
1034 : : GVariantDict *options,
1035 : : gpointer data)
1036 : : {
1037 : 1 : gboolean *called = data;
1038 : :
1039 : 1 : *called = TRUE;
1040 : :
1041 : 1 : return 2;
1042 : : }
1043 : :
1044 : : static void
1045 : 2 : test_handle_local_options_success (void)
1046 : : {
1047 : 2 : if (g_test_subprocess ())
1048 : : {
1049 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
1050 : 1 : gchar *argv[] = { binpath, "--success", NULL };
1051 : : GApplication *app;
1052 : 1 : gboolean called = FALSE;
1053 : 1 : gboolean called2 = FALSE;
1054 : : int status;
1055 : :
1056 : 1 : app = g_application_new ("org.gtk.TestApplication", 0);
1057 : 1 : g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
1058 : 1 : g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
1059 : 1 : g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
1060 : 1 : g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
1061 : :
1062 : 1 : status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
1063 : 1 : g_assert (called);
1064 : 1 : g_assert (!called2);
1065 : 1 : g_assert_cmpint (status, ==, 0);
1066 : :
1067 : 1 : g_object_unref (app);
1068 : 1 : g_free (binpath);
1069 : 1 : return;
1070 : : }
1071 : :
1072 : 1 : g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
1073 : 1 : g_test_trap_assert_passed ();
1074 : : }
1075 : :
1076 : : static void
1077 : 2 : test_handle_local_options_failure (void)
1078 : : {
1079 : 2 : if (g_test_subprocess ())
1080 : : {
1081 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
1082 : 1 : gchar *argv[] = { binpath, "--failure", NULL };
1083 : : GApplication *app;
1084 : 1 : gboolean called = FALSE;
1085 : 1 : gboolean called2 = FALSE;
1086 : : int status;
1087 : :
1088 : 1 : app = g_application_new ("org.gtk.TestApplication", 0);
1089 : 1 : g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
1090 : 1 : g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
1091 : 1 : g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
1092 : 1 : g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
1093 : :
1094 : 1 : status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
1095 : 1 : g_assert (called);
1096 : 1 : g_assert (!called2);
1097 : 1 : g_assert_cmpint (status, ==, 1);
1098 : :
1099 : 1 : g_object_unref (app);
1100 : 1 : g_free (binpath);
1101 : 1 : return;
1102 : : }
1103 : :
1104 : 1 : g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
1105 : 1 : g_test_trap_assert_passed ();
1106 : : }
1107 : :
1108 : : static void
1109 : 2 : test_handle_local_options_passthrough (void)
1110 : : {
1111 : 2 : if (g_test_subprocess ())
1112 : : {
1113 : 1 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
1114 : 1 : gchar *argv[] = { binpath, NULL };
1115 : : GApplication *app;
1116 : 1 : gboolean called = FALSE;
1117 : 1 : gboolean called2 = FALSE;
1118 : : int status;
1119 : :
1120 : 1 : app = g_application_new ("org.gtk.TestApplication", 0);
1121 : 1 : g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
1122 : 1 : g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
1123 : 1 : g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
1124 : 1 : g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
1125 : :
1126 : 1 : status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
1127 : 1 : g_assert (called);
1128 : 1 : g_assert (called2);
1129 : 1 : g_assert_cmpint (status, ==, 2);
1130 : :
1131 : 1 : g_object_unref (app);
1132 : 1 : g_free (binpath);
1133 : 1 : return;
1134 : : }
1135 : :
1136 : 1 : g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
1137 : 1 : g_test_trap_assert_passed ();
1138 : : }
1139 : :
1140 : : static void
1141 : 1 : test_api (void)
1142 : : {
1143 : : GApplication *app;
1144 : : GSimpleAction *action;
1145 : :
1146 : 1 : app = g_application_new ("org.gtk.TestApplication", 0);
1147 : :
1148 : : /* add an action without a name */
1149 : 1 : g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*assertion*failed*");
1150 : 1 : action = g_simple_action_new (NULL, NULL);
1151 : 1 : g_assert (action == NULL);
1152 : 1 : g_test_assert_expected_messages ();
1153 : :
1154 : : /* also, gapplication shouldn't accept actions without names */
1155 : 1 : action = g_object_new (G_TYPE_SIMPLE_ACTION, NULL);
1156 : 1 : g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*action has no name*");
1157 : 1 : g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
1158 : 1 : g_test_assert_expected_messages ();
1159 : :
1160 : 1 : g_object_unref (action);
1161 : 1 : g_object_unref (app);
1162 : 1 : }
1163 : :
1164 : : static void
1165 : 1 : test_version (void)
1166 : : {
1167 : : GApplication *app;
1168 : 1 : gchar *version = NULL;
1169 : 1 : gchar *version_orig = NULL;
1170 : :
1171 : 1 : app = g_application_new ("org.gtk.TestApplication", 0);
1172 : :
1173 : 1 : version_orig = "1.2";
1174 : 1 : g_object_set (G_OBJECT (app), "version", version_orig, NULL);
1175 : 1 : g_object_get (app, "version", &version, NULL);
1176 : 1 : g_assert_cmpstr (version, ==, version_orig);
1177 : 1 : g_free (version);
1178 : :
1179 : : /* test attempting to set the same version again */
1180 : 1 : version_orig = "1.2";
1181 : 1 : g_object_set (G_OBJECT (app), "version", version_orig, NULL);
1182 : 1 : g_object_get (app, "version", &version, NULL);
1183 : 1 : g_assert_cmpstr (version, ==, version_orig);
1184 : 1 : g_free (version);
1185 : :
1186 : 1 : version_orig = "2.4";
1187 : 1 : g_object_set (G_OBJECT (app), "version", version_orig, NULL);
1188 : 1 : g_object_get (app, "version", &version, NULL);
1189 : 1 : g_assert_cmpstr (version, ==, version_orig);
1190 : 1 : g_free (version);
1191 : :
1192 : 1 : g_object_unref (app);
1193 : 1 : }
1194 : :
1195 : : /* Check that G_APPLICATION_ALLOW_REPLACEMENT works. To do so, we launch
1196 : : * a GApplication in this process that allows replacement, and then
1197 : : * launch a subprocess with --gapplication-replace. We have to do our
1198 : : * own async version of g_test_trap_subprocess() here since we need
1199 : : * the main process to keep spinning its mainloop.
1200 : : */
1201 : :
1202 : : static gboolean
1203 : 1 : name_was_lost (GApplication *app,
1204 : : gboolean *called)
1205 : : {
1206 : 1 : *called = TRUE;
1207 : 1 : g_application_quit (app);
1208 : 1 : return TRUE;
1209 : : }
1210 : :
1211 : : static void
1212 : 1 : startup_in_subprocess (GApplication *app,
1213 : : gboolean *called)
1214 : : {
1215 : 1 : *called = TRUE;
1216 : 1 : }
1217 : :
1218 : : typedef struct
1219 : : {
1220 : : gboolean allow_replacement;
1221 : : GSubprocess *subprocess;
1222 : : GApplication *app; /* (not owned) */
1223 : : guint timeout_id;
1224 : : } TestReplaceData;
1225 : :
1226 : : static void
1227 : 2 : startup_cb (GApplication *app,
1228 : : TestReplaceData *data)
1229 : : {
1230 : 2 : const char *argv[] = { NULL, "--verbose", "--quiet", "-p", NULL, "--GTestSubprocess", NULL };
1231 : : GSubprocessLauncher *launcher;
1232 : 2 : GError *local_error = NULL;
1233 : :
1234 : 2 : g_application_hold (app);
1235 : :
1236 : 2 : argv[0] = g_get_prgname ();
1237 : :
1238 : 2 : if (data->allow_replacement)
1239 : 1 : argv[4] = "/gapplication/replace";
1240 : : else
1241 : 1 : argv[4] = "/gapplication/no-replace";
1242 : :
1243 : : /* Now that we are the primary instance, launch our replacement.
1244 : : * We inherit the environment to share the test session bus.
1245 : : */
1246 : 2 : g_test_message ("launching subprocess");
1247 : :
1248 : 2 : launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE);
1249 : 2 : g_subprocess_launcher_set_environ (launcher, NULL);
1250 : 2 : data->subprocess = g_subprocess_launcher_spawnv (launcher, argv, &local_error);
1251 : 2 : g_assert_no_error (local_error);
1252 : 2 : g_object_unref (launcher);
1253 : :
1254 : 2 : if (!data->allow_replacement)
1255 : : {
1256 : : /* make sure we exit after a bit, if the subprocess is not replacing us */
1257 : 1 : g_application_set_inactivity_timeout (app, 500);
1258 : 1 : g_application_release (app);
1259 : : }
1260 : 2 : }
1261 : :
1262 : : static void
1263 : 4 : activate (gpointer data)
1264 : : {
1265 : : /* GApplication complains if we don't connect to ::activate */
1266 : 4 : }
1267 : :
1268 : : static void
1269 : 0 : quit_already (gpointer user_data)
1270 : : {
1271 : 0 : TestReplaceData *data = user_data;
1272 : :
1273 : 0 : g_application_quit (data->app);
1274 : 0 : data->timeout_id = 0;
1275 : 0 : }
1276 : :
1277 : : static void
1278 : 4 : test_replace (gconstpointer data)
1279 : : {
1280 : 4 : gboolean allow = GPOINTER_TO_INT (data);
1281 : :
1282 : 4 : if (g_test_subprocess ())
1283 : : {
1284 : 2 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
1285 : 2 : char *argv[] = { binpath, "--gapplication-replace", NULL };
1286 : : GApplication *app;
1287 : 2 : gboolean startup = FALSE;
1288 : :
1289 : 2 : app = g_application_new ("org.gtk.TestApplication.Replace", G_APPLICATION_ALLOW_REPLACEMENT);
1290 : 2 : g_signal_connect (app, "startup", G_CALLBACK (startup_in_subprocess), &startup);
1291 : 2 : g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
1292 : :
1293 : 2 : g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
1294 : :
1295 : 2 : if (allow)
1296 : 1 : g_assert_true (startup);
1297 : : else
1298 : 1 : g_assert_false (startup);
1299 : :
1300 : 2 : g_object_unref (app);
1301 : 2 : g_free (binpath);
1302 : : }
1303 : : else
1304 : : {
1305 : 2 : char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
1306 : 2 : gchar *argv[] = { binpath, NULL };
1307 : : GApplication *app;
1308 : 2 : gboolean name_lost = FALSE;
1309 : : TestReplaceData data;
1310 : : GTestDBus *bus;
1311 : :
1312 : 2 : data.allow_replacement = allow;
1313 : 2 : data.subprocess = NULL;
1314 : 2 : data.timeout_id = 0;
1315 : :
1316 : 2 : bus = g_test_dbus_new (0);
1317 : 2 : g_test_dbus_up (bus);
1318 : :
1319 : 2 : app = data.app = g_application_new ("org.gtk.TestApplication.Replace", allow ? G_APPLICATION_ALLOW_REPLACEMENT : G_APPLICATION_DEFAULT_FLAGS);
1320 : 2 : g_application_set_inactivity_timeout (app, 500);
1321 : 2 : g_signal_connect (app, "name-lost", G_CALLBACK (name_was_lost), &name_lost);
1322 : 2 : g_signal_connect (app, "startup", G_CALLBACK (startup_cb), &data);
1323 : 2 : g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
1324 : :
1325 : 2 : if (!allow)
1326 : 1 : data.timeout_id = g_timeout_add_seconds_once (1, quit_already, &data);
1327 : :
1328 : 2 : g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
1329 : :
1330 : 2 : g_assert_nonnull (data.subprocess);
1331 : 2 : if (allow)
1332 : 1 : g_assert_true (name_lost);
1333 : : else
1334 : 1 : g_assert_false (name_lost);
1335 : :
1336 : 2 : g_clear_handle_id (&data.timeout_id, g_source_remove);
1337 : 2 : g_object_unref (app);
1338 : 2 : g_free (binpath);
1339 : :
1340 : 2 : g_subprocess_wait (data.subprocess, NULL, NULL);
1341 : 2 : g_clear_object (&data.subprocess);
1342 : :
1343 : 2 : g_test_dbus_down (bus);
1344 : 2 : g_object_unref (bus);
1345 : : }
1346 : 4 : }
1347 : :
1348 : : static void
1349 : 6 : dbus_activate_cb (GApplication *app,
1350 : : gpointer user_data)
1351 : : {
1352 : 6 : guint *n_activations = user_data;
1353 : :
1354 : 6 : *n_activations = *n_activations + 1;
1355 : 6 : g_main_context_wakeup (NULL);
1356 : 6 : }
1357 : :
1358 : : static void dbus_startup_reply_cb (GObject *source_object,
1359 : : GAsyncResult *result,
1360 : : gpointer user_data);
1361 : : static gboolean dbus_startup_reply_idle_cb (gpointer user_data);
1362 : :
1363 : : static void
1364 : 23 : dbus_startup_cb (GApplication *app,
1365 : : gpointer user_data)
1366 : : {
1367 : 23 : GDBusConnection *connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
1368 : 23 : GDBusMessage *message = G_DBUS_MESSAGE (user_data);
1369 : :
1370 : 23 : g_assert_nonnull (connection);
1371 : :
1372 : 23 : g_dbus_connection_send_message_with_reply (connection, message,
1373 : : G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1,
1374 : : NULL, NULL,
1375 : : dbus_startup_reply_cb, g_object_ref (app));
1376 : :
1377 : 23 : g_clear_object (&connection);
1378 : 23 : }
1379 : :
1380 : : static void
1381 : 23 : dbus_startup_reply_cb (GObject *source_object,
1382 : : GAsyncResult *result,
1383 : : gpointer user_data)
1384 : : {
1385 : 23 : GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
1386 : 23 : GApplication *app = G_APPLICATION (user_data);
1387 : 23 : GDBusMessage *reply = NULL;
1388 : 23 : GError *local_error = NULL;
1389 : :
1390 : 23 : reply = g_dbus_connection_send_message_with_reply_finish (connection, result, &local_error);
1391 : 23 : g_assert_no_error (local_error);
1392 : :
1393 : 23 : g_object_set_data_full (G_OBJECT (app), "dbus-command-line-reply", g_steal_pointer (&reply), g_object_unref);
1394 : :
1395 : : /* Release the app in an idle callback, so there’s time to process other
1396 : : * pending sources first. */
1397 : 23 : g_idle_add_full (G_PRIORITY_LOW, dbus_startup_reply_idle_cb, g_steal_pointer (&app), g_object_unref);
1398 : 23 : }
1399 : :
1400 : : static gboolean
1401 : 23 : dbus_startup_reply_idle_cb (gpointer user_data)
1402 : : {
1403 : 23 : GApplication *app = G_APPLICATION (user_data);
1404 : :
1405 : 23 : g_application_release (app);
1406 : :
1407 : 23 : return G_SOURCE_REMOVE;
1408 : : }
1409 : :
1410 : : static void
1411 : 1 : test_dbus_activate (void)
1412 : : {
1413 : 1 : GTestDBus *bus = NULL;
1414 : : GVariantBuilder builder;
1415 : 1 : GDBusMessage *message = NULL;
1416 : 1 : GPtrArray *messages = NULL; /* (element-type GDBusMessage) (owned) */
1417 : : gsize i;
1418 : :
1419 : 1 : g_test_summary ("Test that calling the Activate D-Bus method works");
1420 : :
1421 : : /* Try various different messages */
1422 : 1 : messages = g_ptr_array_new_with_free_func (g_object_unref);
1423 : :
1424 : : /* Via org.gtk.Application */
1425 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
1426 : : "/org/gtk/TestApplication/Activate",
1427 : : "org.gtk.Application",
1428 : : "Activate");
1429 : 1 : g_dbus_message_set_body (message, g_variant_new ("(a{sv})", NULL));
1430 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1431 : :
1432 : : /* Via org.freedesktop.Application */
1433 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
1434 : : "/org/gtk/TestApplication/Activate",
1435 : : "org.freedesktop.Application",
1436 : : "Activate");
1437 : 1 : g_dbus_message_set_body (message, g_variant_new ("(a{sv})", NULL));
1438 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1439 : :
1440 : : /* With some platform data */
1441 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("a{sv}"));
1442 : 1 : g_variant_builder_add (&builder, "{sv}", "cwd", g_variant_new_bytestring ("/home/henry"));
1443 : :
1444 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
1445 : : "/org/gtk/TestApplication/Activate",
1446 : : "org.gtk.Application",
1447 : : "Activate");
1448 : 1 : g_dbus_message_set_body (message, g_variant_new ("(a{sv})", &builder));
1449 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1450 : :
1451 : : /* Try each message */
1452 : 1 : bus = g_test_dbus_new (G_TEST_DBUS_NONE);
1453 : 1 : g_test_dbus_up (bus);
1454 : :
1455 : 4 : for (i = 0; i < messages->len; i++)
1456 : : {
1457 : 3 : GApplication *app = NULL;
1458 : : gulong activate_id, startup_id;
1459 : 3 : guint n_activations = 0;
1460 : :
1461 : 3 : g_test_message ("Message %" G_GSIZE_FORMAT, i);
1462 : :
1463 : 3 : app = g_application_new ("org.gtk.TestApplication.Activate", G_APPLICATION_DEFAULT_FLAGS);
1464 : 3 : activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_cb), &n_activations);
1465 : 3 : startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
1466 : :
1467 : 3 : g_application_hold (app);
1468 : 3 : g_application_run (app, 0, NULL);
1469 : :
1470 : : /* It’ll be activated once as normal, and once due to the D-Bus call */
1471 : 3 : g_assert_cmpuint (n_activations, ==, 2);
1472 : :
1473 : 3 : g_signal_handler_disconnect (app, startup_id);
1474 : 3 : g_signal_handler_disconnect (app, activate_id);
1475 : 3 : g_clear_object (&app);
1476 : : }
1477 : :
1478 : 1 : g_ptr_array_unref (messages);
1479 : :
1480 : 1 : g_test_dbus_down (bus);
1481 : 1 : g_clear_object (&bus);
1482 : 1 : }
1483 : :
1484 : : static void
1485 : 16 : dbus_activate_noop_cb (GApplication *app,
1486 : : gpointer user_data)
1487 : : {
1488 : : /* noop */
1489 : 16 : }
1490 : :
1491 : : static void
1492 : 4 : dbus_open_cb (GApplication *app,
1493 : : gpointer files,
1494 : : int n_files,
1495 : : char *hint,
1496 : : gpointer user_data)
1497 : : {
1498 : 4 : guint *n_opens = user_data;
1499 : :
1500 : 4 : *n_opens = *n_opens + 1;
1501 : 4 : g_main_context_wakeup (NULL);
1502 : 4 : }
1503 : :
1504 : : static void
1505 : 1 : test_dbus_open (void)
1506 : : {
1507 : 1 : GTestDBus *bus = NULL;
1508 : : GVariantBuilder builder, builder2;
1509 : 1 : GDBusMessage *message = NULL;
1510 : 1 : GPtrArray *messages = NULL; /* (element-type GDBusMessage) (owned) */
1511 : : gsize i;
1512 : :
1513 : 1 : g_test_summary ("Test that calling the Open D-Bus method works");
1514 : :
1515 : : /* Try various different messages */
1516 : 1 : messages = g_ptr_array_new_with_free_func (g_object_unref);
1517 : :
1518 : : /* Via org.gtk.Application */
1519 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("as"));
1520 : 1 : g_variant_builder_add (&builder, "s", "file:///home/henry/test");
1521 : :
1522 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
1523 : : "/org/gtk/TestApplication/Open",
1524 : : "org.gtk.Application",
1525 : : "Open");
1526 : 1 : g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", &builder, "hint", NULL));
1527 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1528 : :
1529 : : /* Via org.freedesktop.Application (which has no hint parameter) */
1530 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("as"));
1531 : 1 : g_variant_builder_add (&builder, "s", "file:///home/henry/test");
1532 : :
1533 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
1534 : : "/org/gtk/TestApplication/Open",
1535 : : "org.freedesktop.Application",
1536 : : "Open");
1537 : 1 : g_dbus_message_set_body (message, g_variant_new ("(asa{sv})", &builder, NULL));
1538 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1539 : :
1540 : : /* With some platform data and more than one file */
1541 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("as"));
1542 : 1 : g_variant_builder_add (&builder, "s", "file:///home/henry/test");
1543 : 1 : g_variant_builder_add (&builder, "s", "file:///home/henry/test2");
1544 : :
1545 : 1 : g_variant_builder_init_static (&builder2, G_VARIANT_TYPE ("a{sv}"));
1546 : 1 : g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_bytestring ("/home/henry"));
1547 : :
1548 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
1549 : : "/org/gtk/TestApplication/Open",
1550 : : "org.gtk.Application",
1551 : : "Open");
1552 : 1 : g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", &builder, "", &builder2));
1553 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1554 : :
1555 : : /* No files */
1556 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
1557 : : "/org/gtk/TestApplication/Open",
1558 : : "org.gtk.Application",
1559 : : "Open");
1560 : 1 : g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", NULL, "", NULL));
1561 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1562 : :
1563 : : /* Try each message */
1564 : 1 : bus = g_test_dbus_new (G_TEST_DBUS_NONE);
1565 : 1 : g_test_dbus_up (bus);
1566 : :
1567 : 5 : for (i = 0; i < messages->len; i++)
1568 : : {
1569 : 4 : GApplication *app = NULL;
1570 : : gulong activate_id, open_id, startup_id;
1571 : 4 : guint n_opens = 0;
1572 : :
1573 : 4 : g_test_message ("Message %" G_GSIZE_FORMAT, i);
1574 : :
1575 : 4 : app = g_application_new ("org.gtk.TestApplication.Open", G_APPLICATION_HANDLES_OPEN);
1576 : 4 : activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
1577 : 4 : open_id = g_signal_connect (app, "open", G_CALLBACK (dbus_open_cb), &n_opens);
1578 : 4 : startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
1579 : :
1580 : 4 : g_application_hold (app);
1581 : 4 : g_application_run (app, 0, NULL);
1582 : :
1583 : 4 : g_assert_cmpuint (n_opens, ==, 1);
1584 : :
1585 : 4 : g_signal_handler_disconnect (app, startup_id);
1586 : 4 : g_signal_handler_disconnect (app, open_id);
1587 : 4 : g_signal_handler_disconnect (app, activate_id);
1588 : 4 : g_clear_object (&app);
1589 : : }
1590 : :
1591 : 1 : g_ptr_array_unref (messages);
1592 : :
1593 : 1 : g_test_dbus_down (bus);
1594 : 1 : g_clear_object (&bus);
1595 : 1 : }
1596 : :
1597 : : static void
1598 : 6 : dbus_command_line_cb (GApplication *app,
1599 : : GApplicationCommandLine *command_line,
1600 : : gpointer user_data)
1601 : : {
1602 : 6 : guint *n_command_lines = user_data;
1603 : :
1604 : 6 : *n_command_lines = *n_command_lines + 1;
1605 : 6 : g_main_context_wakeup (NULL);
1606 : 6 : }
1607 : :
1608 : : static void
1609 : 1 : test_dbus_command_line (void)
1610 : : {
1611 : 1 : GTestDBus *bus = NULL;
1612 : : GVariantBuilder builder, builder2;
1613 : 1 : GDBusMessage *message = NULL;
1614 : 1 : GPtrArray *messages = NULL; /* (element-type GDBusMessage) (owned) */
1615 : : gsize i;
1616 : :
1617 : 1 : g_test_summary ("Test that calling the CommandLine D-Bus method works");
1618 : :
1619 : : /* Try various different messages */
1620 : 1 : messages = g_ptr_array_new_with_free_func (g_object_unref);
1621 : :
1622 : : /* Via org.gtk.Application */
1623 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("aay"));
1624 : 1 : g_variant_builder_add (&builder, "^ay", "test-program");
1625 : 1 : g_variant_builder_add (&builder, "^ay", "--open");
1626 : 1 : g_variant_builder_add (&builder, "^ay", "/path/to/something");
1627 : :
1628 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
1629 : : "/org/gtk/TestApplication/CommandLine",
1630 : : "org.gtk.Application",
1631 : : "CommandLine");
1632 : 1 : g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
1633 : : "/my/org/gtk/private/CommandLine",
1634 : : &builder, NULL));
1635 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1636 : :
1637 : : /* With platform data */
1638 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("aay"));
1639 : 1 : g_variant_builder_add (&builder, "^ay", "test-program");
1640 : 1 : g_variant_builder_add (&builder, "^ay", "--open");
1641 : 1 : g_variant_builder_add (&builder, "^ay", "/path/to/something");
1642 : :
1643 : 1 : g_variant_builder_init_static (&builder2, G_VARIANT_TYPE ("a{sv}"));
1644 : 1 : g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_bytestring ("/home"));
1645 : 1 : g_variant_builder_add_parsed (&builder2, "{'environ', <@aay [ b'HOME=/home/bloop', b'PATH=/blah']>}");
1646 : 1 : g_variant_builder_add_parsed (&builder2, "{'options', <{'a': <@u 32>, 'b': <'bloop'>}>}");
1647 : :
1648 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
1649 : : "/org/gtk/TestApplication/CommandLine",
1650 : : "org.gtk.Application",
1651 : : "CommandLine");
1652 : 1 : g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
1653 : : "/my/org/gtk/private/CommandLine",
1654 : : &builder, &builder2));
1655 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1656 : :
1657 : : /* With invalid typed platform data */
1658 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("aay"));
1659 : 1 : g_variant_builder_add (&builder, "^ay", "test-program");
1660 : 1 : g_variant_builder_add (&builder, "^ay", "--open");
1661 : 1 : g_variant_builder_add (&builder, "^ay", "/path/to/something");
1662 : :
1663 : 1 : g_variant_builder_init_static (&builder2, G_VARIANT_TYPE ("a{sv}"));
1664 : 1 : g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_string ("/home should be a bytestring"));
1665 : 1 : g_variant_builder_add_parsed (&builder2, "{'environ', <['HOME=should be a bytestring', 'PATH=this also']>}");
1666 : 1 : g_variant_builder_add_parsed (&builder2, "{'options', <['should be a', 'dict']>}");
1667 : :
1668 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
1669 : : "/org/gtk/TestApplication/CommandLine",
1670 : : "org.gtk.Application",
1671 : : "CommandLine");
1672 : 1 : g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
1673 : : "/my/org/gtk/private/CommandLine",
1674 : : &builder, &builder2));
1675 : 1 : g_ptr_array_add (messages, g_steal_pointer (&message));
1676 : :
1677 : : /* Try each message */
1678 : 1 : bus = g_test_dbus_new (G_TEST_DBUS_NONE);
1679 : 1 : g_test_dbus_up (bus);
1680 : :
1681 : 4 : for (i = 0; i < messages->len; i++)
1682 : : {
1683 : 3 : GApplication *app = NULL;
1684 : : gulong activate_id, command_line_id, startup_id;
1685 : 3 : guint n_command_lines = 0;
1686 : :
1687 : 3 : g_test_message ("Message %" G_GSIZE_FORMAT, i);
1688 : :
1689 : 3 : app = g_application_new ("org.gtk.TestApplication.CommandLine", G_APPLICATION_HANDLES_COMMAND_LINE);
1690 : 3 : activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
1691 : 3 : command_line_id = g_signal_connect (app, "command-line", G_CALLBACK (dbus_command_line_cb), &n_command_lines);
1692 : 3 : startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
1693 : :
1694 : 3 : g_application_hold (app);
1695 : 3 : g_application_run (app, 0, NULL);
1696 : :
1697 : : /* It’s called once for handling the local command line on startup, and again
1698 : : * for the D-Bus call */
1699 : 3 : g_assert_cmpuint (n_command_lines, ==, 2);
1700 : :
1701 : 3 : g_signal_handler_disconnect (app, startup_id);
1702 : 3 : g_signal_handler_disconnect (app, command_line_id);
1703 : 3 : g_signal_handler_disconnect (app, activate_id);
1704 : 3 : g_clear_object (&app);
1705 : : }
1706 : :
1707 : 1 : g_ptr_array_unref (messages);
1708 : :
1709 : 1 : g_test_dbus_down (bus);
1710 : 1 : g_clear_object (&bus);
1711 : 1 : }
1712 : :
1713 : : static gint
1714 : 2 : dbus_command_line_done_cb (GApplication *app,
1715 : : GApplicationCommandLine *command_line,
1716 : : gpointer user_data)
1717 : : {
1718 : 2 : guint *n_command_lines = user_data;
1719 : :
1720 : 2 : *n_command_lines = *n_command_lines + 1;
1721 : :
1722 : 2 : if (*n_command_lines == 1)
1723 : 1 : return 0;
1724 : :
1725 : 1 : g_object_set_data_full (G_OBJECT (app), "command-line", g_object_ref (command_line), g_object_unref);
1726 : :
1727 : 1 : g_application_command_line_set_exit_status (command_line, 42);
1728 : 1 : g_application_command_line_done (command_line);
1729 : :
1730 : 1 : return 1; /* ignored - after g_application_command_line_done () */
1731 : : }
1732 : :
1733 : : static void
1734 : 1 : test_dbus_command_line_done (void)
1735 : : {
1736 : 1 : GTestDBus *bus = NULL;
1737 : : GVariantBuilder builder;
1738 : 1 : GDBusMessage *message = NULL;
1739 : 1 : GDBusMessage *reply = NULL;
1740 : 1 : GApplication *app = NULL;
1741 : 1 : guint n_command_lines = 0;
1742 : : gint exit_status;
1743 : :
1744 : 1 : g_test_summary ("Test that GDBusCommandLine.done() works");
1745 : :
1746 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("aay"));
1747 : 1 : g_variant_builder_add (&builder, "^ay", "test-program");
1748 : 1 : g_variant_builder_add (&builder, "^ay", "/path/to/something");
1749 : :
1750 : 1 : message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
1751 : : "/org/gtk/TestApplication/CommandLine",
1752 : : "org.gtk.Application",
1753 : : "CommandLine");
1754 : 1 : g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
1755 : : "/my/org/gtk/private/CommandLine",
1756 : : &builder, NULL));
1757 : :
1758 : 1 : bus = g_test_dbus_new (G_TEST_DBUS_NONE);
1759 : 1 : g_test_dbus_up (bus);
1760 : :
1761 : 1 : app = g_application_new ("org.gtk.TestApplication.CommandLine", G_APPLICATION_HANDLES_COMMAND_LINE);
1762 : 1 : g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
1763 : 1 : g_signal_connect (app, "command-line", G_CALLBACK (dbus_command_line_done_cb), &n_command_lines);
1764 : 1 : g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), message);
1765 : :
1766 : 1 : g_application_hold (app);
1767 : 1 : exit_status = g_application_run (app, 0, NULL);
1768 : :
1769 : 1 : g_assert_cmpuint (n_command_lines, ==, 2);
1770 : 1 : g_assert_cmpint (exit_status, ==, 0);
1771 : :
1772 : 1 : reply = g_object_get_data (G_OBJECT (app), "dbus-command-line-reply");
1773 : 1 : g_variant_get (g_dbus_message_get_body (reply), "(i)", &exit_status);
1774 : 1 : g_assert_cmpint (exit_status, ==, 42);
1775 : :
1776 : 1 : g_signal_handlers_disconnect_by_func (app, G_CALLBACK (dbus_activate_noop_cb), NULL);
1777 : 1 : g_signal_handlers_disconnect_by_func (app, G_CALLBACK (dbus_command_line_done_cb), &n_command_lines);
1778 : 1 : g_signal_handlers_disconnect_by_func (app, G_CALLBACK (dbus_startup_cb), message);
1779 : :
1780 : 1 : g_clear_object (&app);
1781 : 1 : g_clear_object (&message);
1782 : :
1783 : 1 : g_test_dbus_down (bus);
1784 : 1 : g_clear_object (&bus);
1785 : 1 : }
1786 : :
1787 : : typedef struct _ActivationData {
1788 : : unsigned n_activations;
1789 : : GVariant *parameter;
1790 : : } ActivationData;
1791 : :
1792 : : static void
1793 : 5 : dbus_activate_action_cb (GSimpleAction *action,
1794 : : GVariant *parameter,
1795 : : gpointer user_data)
1796 : : {
1797 : 5 : ActivationData *activation_data = user_data;
1798 : :
1799 : 5 : activation_data->n_activations++;
1800 : :
1801 : 5 : if (parameter)
1802 : : {
1803 : 4 : char *parameter_str = g_variant_print (parameter, TRUE);
1804 : :
1805 : 4 : activation_data->parameter = g_variant_ref (parameter);
1806 : 4 : g_test_message ("Activating action '%s' with parameter: %s",
1807 : 4 : g_action_get_name (G_ACTION (action)), parameter_str);
1808 : 4 : g_clear_pointer (¶meter_str, g_free);
1809 : : }
1810 : : else
1811 : : {
1812 : 1 : g_test_message ("Activating action '%s' with no parameter",
1813 : 1 : g_action_get_name (G_ACTION (action)));
1814 : : }
1815 : :
1816 : 5 : g_main_context_wakeup (NULL);
1817 : 5 : }
1818 : :
1819 : : static GVariant *
1820 : 4 : get_expected_action_parameter (GVariant *parameters)
1821 : : {
1822 : 4 : GVariant *parameter = NULL;
1823 : : guint n_children;
1824 : :
1825 : 4 : g_assert_true (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("av")));
1826 : :
1827 : 4 : if ((n_children = g_variant_n_children (parameters)) > 1)
1828 : : {
1829 : : GPtrArray *children;
1830 : :
1831 : 1 : children = g_ptr_array_new_full (n_children,
1832 : : (GDestroyNotify) g_variant_unref);
1833 : :
1834 : 3 : for (guint i = 0; i < n_children; ++i)
1835 : : {
1836 : : GVariant *variant;
1837 : :
1838 : 2 : variant = g_variant_get_child_value (parameters, i);
1839 : 2 : g_ptr_array_add (children, g_variant_get_variant (variant));
1840 : 2 : g_clear_pointer (&variant, g_variant_unref);
1841 : : }
1842 : :
1843 : 1 : parameter = g_variant_new_tuple ((GVariant **) children->pdata, n_children);
1844 : 1 : g_clear_pointer (&children, g_ptr_array_unref);
1845 : : }
1846 : 3 : else if (n_children > 0)
1847 : : {
1848 : : GVariant *variant;
1849 : :
1850 : 3 : variant = g_variant_get_child_value (parameters, 0);
1851 : 3 : parameter = g_variant_get_variant (variant);
1852 : 3 : g_clear_pointer (&variant, g_variant_unref);
1853 : : }
1854 : :
1855 : 4 : return g_steal_pointer (¶meter);
1856 : : }
1857 : :
1858 : : static void
1859 : 1 : test_dbus_activate_action (void)
1860 : : {
1861 : 1 : GTestDBus *bus = NULL;
1862 : : GVariantBuilder builder;
1863 : : GVariant *parameter;
1864 : : struct
1865 : : {
1866 : : GDBusMessage *message; /* (not nullable) (owned) */
1867 : : guint n_expected_activations;
1868 : : GVariant *expected_parameter;
1869 : 1 : } messages[12] = {0};
1870 : : gsize i;
1871 : :
1872 : 1 : g_test_summary ("Test that calling the ActivateAction D-Bus method works");
1873 : :
1874 : : /* Action without parameter */
1875 : 1 : messages[0].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1876 : : "/org/gtk/TestApplication/ActivateAction",
1877 : : "org.freedesktop.Application",
1878 : : "ActivateAction");
1879 : 1 : g_dbus_message_set_body (messages[0].message, g_variant_new ("(sava{sv})", "undo", NULL, NULL));
1880 : 1 : messages[0].n_expected_activations = 1;
1881 : :
1882 : : /* Action with parameter */
1883 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
1884 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_string ("spanish"));
1885 : :
1886 : 1 : messages[1].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1887 : : "/org/gtk/TestApplication/ActivateAction",
1888 : : "org.freedesktop.Application",
1889 : : "ActivateAction");
1890 : 1 : parameter = g_variant_ref_sink (g_variant_builder_end (&builder));
1891 : 1 : g_dbus_message_set_body (messages[1].message, g_variant_new ("(s@ava{sv})", "lang", parameter, NULL));
1892 : 1 : messages[1].n_expected_activations = 1;
1893 : 1 : messages[1].expected_parameter = get_expected_action_parameter (parameter);
1894 : 1 : g_clear_pointer (¶meter, g_variant_unref);
1895 : :
1896 : : /* Action with unexpected parameter */
1897 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
1898 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_string ("should not be passed"));
1899 : :
1900 : 1 : messages[2].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1901 : : "/org/gtk/TestApplication/ActivateAction",
1902 : : "org.freedesktop.Application",
1903 : : "ActivateAction");
1904 : 1 : g_dbus_message_set_body (messages[2].message, g_variant_new ("(sava{sv})", "undo", &builder, NULL));
1905 : 1 : messages[2].n_expected_activations = 0;
1906 : 1 : messages[2].expected_parameter = NULL;
1907 : :
1908 : : /* Action without required parameter */
1909 : 1 : messages[3].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1910 : : "/org/gtk/TestApplication/ActivateAction",
1911 : : "org.freedesktop.Application",
1912 : : "ActivateAction");
1913 : 1 : g_dbus_message_set_body (messages[3].message, g_variant_new ("(sava{sv})", "lang", NULL, NULL));
1914 : 1 : messages[3].n_expected_activations = 0;
1915 : 1 : messages[3].expected_parameter = NULL;
1916 : :
1917 : : /* Action with wrong parameter type */
1918 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
1919 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_uint32 (42));
1920 : :
1921 : 1 : messages[4].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1922 : : "/org/gtk/TestApplication/ActivateAction",
1923 : : "org.freedesktop.Application",
1924 : : "ActivateAction");
1925 : 1 : g_dbus_message_set_body (messages[4].message, g_variant_new ("(sava{sv})", "lang", &builder, NULL));
1926 : 1 : messages[4].n_expected_activations = 0;
1927 : 1 : messages[4].expected_parameter = NULL;
1928 : :
1929 : : /* Nonexistent action */
1930 : 1 : messages[5].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1931 : : "/org/gtk/TestApplication/ActivateAction",
1932 : : "org.freedesktop.Application",
1933 : : "ActivateAction");
1934 : 1 : g_dbus_message_set_body (messages[5].message, g_variant_new ("(sava{sv})", "nonexistent", NULL, NULL));
1935 : 1 : messages[5].n_expected_activations = 0;
1936 : 1 : messages[5].expected_parameter = NULL;
1937 : :
1938 : : /* Action with tuple as parameter given as two items to the interface */
1939 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
1940 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_string ("first"));
1941 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_string ("second"));
1942 : :
1943 : 1 : messages[6].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1944 : : "/org/gtk/TestApplication/ActivateAction",
1945 : : "org.freedesktop.Application",
1946 : : "ActivateAction");
1947 : :
1948 : 1 : parameter = g_variant_ref_sink (g_variant_builder_end (&builder));
1949 : 1 : g_dbus_message_set_body (messages[6].message, g_variant_new ("(s@ava{sv})", "multi", parameter, NULL));
1950 : 1 : messages[6].n_expected_activations = 1;
1951 : 1 : messages[6].expected_parameter = get_expected_action_parameter (parameter);
1952 : 1 : g_clear_pointer (¶meter, g_variant_unref);
1953 : :
1954 : : /* Action with tuple as parameter given as two items to the interface but with a wrong type */
1955 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
1956 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_string ("first"));
1957 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_uint32 (42));
1958 : :
1959 : 1 : messages[7].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1960 : : "/org/gtk/TestApplication/ActivateAction",
1961 : : "org.freedesktop.Application",
1962 : : "ActivateAction");
1963 : 1 : g_dbus_message_set_body (messages[7].message, g_variant_new ("(sava{sv})", "multi", &builder, NULL));
1964 : 1 : messages[7].n_expected_activations = 0;
1965 : 1 : messages[7].expected_parameter = NULL;
1966 : :
1967 : : /* Action with tuple as parameter given as a single item to the interface */
1968 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
1969 : 1 : g_variant_builder_add (&builder, "v", g_variant_new ("(ss)", "first", "second"));
1970 : :
1971 : 1 : messages[8].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1972 : : "/org/gtk/TestApplication/ActivateAction",
1973 : : "org.freedesktop.Application",
1974 : : "ActivateAction");
1975 : 1 : parameter = g_variant_ref_sink (g_variant_builder_end (&builder));
1976 : 1 : g_dbus_message_set_body (messages[8].message, g_variant_new ("(s@ava{sv})", "multi", parameter, NULL));
1977 : 1 : messages[8].n_expected_activations = 1;
1978 : 1 : messages[8].expected_parameter = get_expected_action_parameter (parameter);
1979 : 1 : g_clear_pointer (¶meter, g_variant_unref);
1980 : :
1981 : : /* Action with tuple as parameter given as a single item to the interface but with additional items */
1982 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
1983 : 1 : g_variant_builder_add (&builder, "v", g_variant_new ("(ss)", "first", "second"));
1984 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_uint32 (42));
1985 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_uint32 (42));
1986 : :
1987 : 1 : messages[9].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
1988 : : "/org/gtk/TestApplication/ActivateAction",
1989 : : "org.freedesktop.Application",
1990 : : "ActivateAction");
1991 : 1 : g_dbus_message_set_body (messages[9].message, g_variant_new ("(sava{sv})", "multi", &builder, NULL));
1992 : 1 : messages[9].n_expected_activations = 0;
1993 : 1 : messages[9].expected_parameter = NULL;
1994 : :
1995 : : /* Action with tuple with single item as parameter */
1996 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
1997 : 1 : g_variant_builder_add (&builder, "v", g_variant_new ("(s)", "first"));
1998 : :
1999 : 1 : messages[10].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
2000 : : "/org/gtk/TestApplication/ActivateAction",
2001 : : "org.freedesktop.Application",
2002 : : "ActivateAction");
2003 : 1 : parameter = g_variant_ref_sink (g_variant_builder_end (&builder));
2004 : 1 : g_dbus_message_set_body (messages[10].message, g_variant_new ("(s@ava{sv})", "single", parameter, NULL));
2005 : 1 : messages[10].n_expected_activations = 1;
2006 : 1 : messages[10].expected_parameter = get_expected_action_parameter (parameter);
2007 : 1 : g_clear_pointer (¶meter, g_variant_unref);
2008 : :
2009 : : /* Action with tuple with single item as parameter with additional items */
2010 : 1 : g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("av"));
2011 : 1 : g_variant_builder_add (&builder, "v", g_variant_new ("(s)", "first"));
2012 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_uint32 (42));
2013 : 1 : g_variant_builder_add (&builder, "v", g_variant_new_uint32 (43));
2014 : :
2015 : 1 : messages[11].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
2016 : : "/org/gtk/TestApplication/ActivateAction",
2017 : : "org.freedesktop.Application",
2018 : : "ActivateAction");
2019 : 1 : g_dbus_message_set_body (messages[11].message, g_variant_new ("(sava{sv})", "single", &builder, NULL));
2020 : 1 : messages[11].n_expected_activations = 0;
2021 : 1 : messages[11].expected_parameter = NULL;
2022 : :
2023 : : /* Try each message */
2024 : 1 : bus = g_test_dbus_new (G_TEST_DBUS_NONE);
2025 : 1 : g_test_dbus_up (bus);
2026 : :
2027 : 13 : for (i = 0; i < G_N_ELEMENTS (messages); i++)
2028 : : {
2029 : 12 : GApplication *app = NULL;
2030 : : gulong activate_id, startup_id;
2031 : 12 : const GActionEntry entries[] =
2032 : : {
2033 : : { "undo", dbus_activate_action_cb, NULL, NULL, NULL, { 0 } },
2034 : : { "lang", dbus_activate_action_cb, "s", "'latin'", NULL, { 0 } },
2035 : : { "single", dbus_activate_action_cb, "(s)", NULL, NULL, { 0 } },
2036 : : { "multi", dbus_activate_action_cb, "(ss)", NULL, NULL, { 0 } },
2037 : : };
2038 : 12 : ActivationData activation_data = {0};
2039 : :
2040 : 12 : g_test_message ("Message %" G_GSIZE_FORMAT, i);
2041 : :
2042 : 12 : app = g_application_new ("org.gtk.TestApplication.ActivateAction", G_APPLICATION_DEFAULT_FLAGS);
2043 : 12 : activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
2044 : 12 : startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages[i].message);
2045 : :
2046 : : /* Export some actions. */
2047 : 12 : g_action_map_add_action_entries (G_ACTION_MAP (app), entries, G_N_ELEMENTS (entries), &activation_data);
2048 : :
2049 : 12 : g_application_hold (app);
2050 : 12 : g_application_run (app, 0, NULL);
2051 : :
2052 : 12 : g_assert_cmpuint (activation_data.n_activations, ==, messages[i].n_expected_activations);
2053 : :
2054 : 12 : if (messages[i].expected_parameter)
2055 : 4 : g_assert_cmpvariant (activation_data.parameter, messages[i].expected_parameter);
2056 : : else
2057 : 8 : g_assert_null (activation_data.parameter);
2058 : :
2059 : 12 : g_signal_handler_disconnect (app, startup_id);
2060 : 12 : g_signal_handler_disconnect (app, activate_id);
2061 : 12 : g_clear_object (&app);
2062 : 12 : g_clear_pointer (&activation_data.parameter, g_variant_unref);
2063 : 12 : g_clear_pointer (&messages[i].expected_parameter, g_variant_unref);
2064 : 12 : g_clear_object (&messages[i].message);
2065 : : }
2066 : :
2067 : 1 : g_test_dbus_down (bus);
2068 : 1 : g_clear_object (&bus);
2069 : 1 : }
2070 : :
2071 : : int
2072 : 7 : main (int argc, char **argv)
2073 : : {
2074 : 7 : g_setenv ("LC_ALL", "C", TRUE);
2075 : :
2076 : 7 : g_log_writer_default_set_use_stderr (TRUE);
2077 : :
2078 : 7 : g_test_init (&argc, &argv, NULL);
2079 : :
2080 : 7 : if (!g_test_subprocess ())
2081 : 1 : g_test_dbus_unset ();
2082 : :
2083 : 7 : g_test_add_func ("/gapplication/no-dbus", test_nodbus);
2084 : : /* g_test_add_func ("/gapplication/basic", basic); */
2085 : 7 : g_test_add_func ("/gapplication/no-appid", test_noappid);
2086 : : /* g_test_add_func ("/gapplication/non-unique", test_nonunique); */
2087 : 7 : g_test_add_func ("/gapplication/properties", properties);
2088 : 7 : g_test_add_func ("/gapplication/app-id", appid);
2089 : 7 : g_test_add_func ("/gapplication/quit", test_quit);
2090 : 7 : g_test_add_func ("/gapplication/registered", test_registered);
2091 : 7 : g_test_add_func ("/gapplication/local-actions", test_local_actions);
2092 : : /* g_test_add_func ("/gapplication/remote-actions", test_remote_actions); */
2093 : 7 : g_test_add_func ("/gapplication/local-command-line", test_local_command_line);
2094 : : /* g_test_add_func ("/gapplication/remote-command-line", test_remote_command_line); */
2095 : 7 : g_test_add_func ("/gapplication/resource-path", test_resource_path);
2096 : 7 : g_test_add_func ("/gapplication/test-help", test_help);
2097 : 7 : g_test_add_func ("/gapplication/command-line-done", test_command_line_done);
2098 : 7 : g_test_add_func ("/gapplication/command-line/arguments", test_command_line_arguments);
2099 : 7 : g_test_add_func ("/gapplication/test-busy", test_busy);
2100 : 7 : g_test_add_func ("/gapplication/test-handle-local-options1", test_handle_local_options_success);
2101 : 7 : g_test_add_func ("/gapplication/test-handle-local-options2", test_handle_local_options_failure);
2102 : 7 : g_test_add_func ("/gapplication/test-handle-local-options3", test_handle_local_options_passthrough);
2103 : 7 : g_test_add_func ("/gapplication/api", test_api);
2104 : 7 : g_test_add_func ("/gapplication/version", test_version);
2105 : 7 : g_test_add_data_func ("/gapplication/replace", GINT_TO_POINTER (TRUE), test_replace);
2106 : 7 : g_test_add_data_func ("/gapplication/no-replace", GINT_TO_POINTER (FALSE), test_replace);
2107 : 7 : g_test_add_func ("/gapplication/dbus/activate", test_dbus_activate);
2108 : 7 : g_test_add_func ("/gapplication/dbus/open", test_dbus_open);
2109 : 7 : g_test_add_func ("/gapplication/dbus/command-line", test_dbus_command_line);
2110 : 7 : g_test_add_func ("/gapplication/dbus/command-line-done", test_dbus_command_line_done);
2111 : 7 : g_test_add_func ("/gapplication/dbus/activate-action", test_dbus_activate_action);
2112 : :
2113 : 7 : return g_test_run ();
2114 : : }
|