6 #include "gdbus-tests.h"
7 #include "gdbus-sessionbus.h"
10 /* These tests are racy -- there is no guarantee about the order of data
11 * arriving over D-Bus.
13 * They're also a bit ridiculous -- GApplication was never meant to be
14 * abused in this way...
18 static gint outstanding_watches
;
19 static GMainLoop
*main_loop
;
23 gchar
*expected_stdout
;
25 gchar
*expected_stderr
;
30 check_data (gint fd
, const gchar
*expected
)
35 len
= strlen (expected
);
36 buffer
= g_alloca (len
+ 100);
37 actual
= read (fd
, buffer
, len
+ 100);
39 g_assert_cmpint (actual
, >=, 0);
42 memcmp (buffer
, expected
, len
) != 0)
44 buffer
[MIN(len
+ 100, actual
)] = '\0';
46 g_error ("\nExpected\n-----\n%s-----\nGot (%s)\n-----\n%s-----\n",
48 (actual
> len
) ? "truncated" : "full", buffer
);
57 ChildData
*child
= data
;
59 g_assert_cmpint (status
, ==, 0);
61 if (--outstanding_watches
== 0)
62 g_main_loop_quit (main_loop
);
64 check_data (child
->stdout_pipe
, child
->expected_stdout
);
65 close (child
->stdout_pipe
);
66 g_free (child
->expected_stdout
);
68 if (child
->expected_stderr
)
70 check_data (child
->stderr_pipe
, child
->expected_stderr
);
71 close (child
->stderr_pipe
);
72 g_free (child
->expected_stderr
);
75 g_slice_free (ChildData
, child
);
79 spawn (const gchar
*expected_stdout
,
80 const gchar
*expected_stderr
,
81 const gchar
*first_arg
,
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
);
103 env
= g_environ_setenv (g_get_environ (), "TEST", "1", TRUE
);
105 data
= g_slice_new (ChildData
);
106 data
->expected_stdout
= g_strdup (expected_stdout
);
107 data
->expected_stderr
= g_strdup (expected_stderr
);
109 g_spawn_async_with_pipes (NULL
, args
, env
,
110 G_SPAWN_DO_NOT_REAP_CHILD
,
111 NULL
, NULL
, &pid
, NULL
,
113 expected_stderr
? &data
->stderr_pipe
: NULL
,
115 g_assert_no_error (error
);
119 g_child_watch_add (pid
, child_quit
, data
);
120 outstanding_watches
++;
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
126 fd
.fd
= data
->stdout_pipe
;
127 fd
.events
= G_IO_IN
| G_IO_HUP
| G_IO_ERR
;
136 g_assert (outstanding_watches
== 0);
139 c
= g_bus_get_sync (G_BUS_TYPE_SESSION
, NULL
, NULL
);
141 main_loop
= g_main_loop_new (NULL
, 0);
143 /* spawn the master */
145 "open file:///a file:///b\n"
146 "exit status: 0\n", NULL
,
149 /* send it some files */
150 spawn ("exit status: 0\n", NULL
,
151 "./app", "/a", "/b", NULL
);
153 g_main_loop_run (main_loop
);
158 g_main_loop_unref (main_loop
);
162 test_remote_command_line (void)
169 g_assert (outstanding_watches
== 0);
172 c
= g_bus_get_sync (G_BUS_TYPE_SESSION
, NULL
, NULL
);
174 main_loop
= g_main_loop_new (NULL
, 0);
176 file
= g_file_new_for_commandline_arg ("foo");
177 cwd
= g_get_current_dir ();
179 replies
= g_strconcat ("got ./cmd 0\n",
181 "cmdline ./cmd echo --abc -d\n",
182 "environment TEST=1\n",
184 "file ", g_file_get_path (file
), "\n",
192 g_object_unref (file
);
194 /* spawn the master */
195 spawn (replies
, NULL
,
200 /* send it a few commandlines */
201 spawn ("exit status: 0\n", NULL
,
204 spawn ("exit status: 0\n", NULL
,
205 "./cmd", "echo", "--abc", "-d", NULL
);
207 spawn ("exit status: 0\n", NULL
,
208 "./cmd", "env", NULL
);
210 spawn ("exit status: 0\n", NULL
,
211 "./cmd", "getenv", NULL
);
213 spawn ("print test\n"
214 "exit status: 0\n", NULL
,
215 "./cmd", "print", "test", NULL
);
217 spawn ("exit status: 0\n", "printerr test\n",
218 "./cmd", "printerr", "test", NULL
);
220 spawn ("exit status: 0\n", NULL
,
221 "./cmd", "file", "foo", NULL
);
223 spawn ("exit status: 0\n", NULL
,
224 "./cmd", "properties", NULL
);
226 spawn ("exit status: 0\n", NULL
,
227 "./cmd", "cwd", NULL
);
229 spawn ("exit status: 0\n", NULL
,
230 "./cmd", "busy", NULL
);
232 spawn ("exit status: 0\n", NULL
,
233 "./cmd", "idle", NULL
);
235 spawn ("exit status: 0\n", NULL
,
236 "./cmd", "stdin", NULL
);
238 g_main_loop_run (main_loop
);
243 g_main_loop_unref (main_loop
);
247 test_remote_actions (void)
251 g_assert (outstanding_watches
== 0);
254 c
= g_bus_get_sync (G_BUS_TYPE_SESSION
, NULL
, NULL
);
256 main_loop
= g_main_loop_new (NULL
, 0);
258 /* spawn the master */
259 spawn ("got ./cmd 0\n"
262 "exit status: 0\n", NULL
,
265 spawn ("actions quit new action1 action2\n"
266 "exit status: 0\n", NULL
,
267 "./actions", "list", NULL
);
269 spawn ("exit status: 0\n", NULL
,
270 "./actions", "activate", NULL
);
272 spawn ("exit status: 0\n", NULL
,
273 "./actions", "set-state", NULL
);
275 g_main_loop_run (main_loop
);
280 g_main_loop_unref (main_loop
);
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.
289 * See https://bugzilla.gnome.org/show_bug.cgi?id=647986 for the patch that
290 * introduced this problem.
293 static GApplication
*recently_activated
;
294 static GMainLoop
*loop
;
297 nonunique_activate (GApplication
*application
)
299 recently_activated
= application
;
302 g_main_loop_quit (loop
);
305 static GApplication
*
306 make_app (gboolean non_unique
)
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
);
317 g_object_unref (app
);
321 g_application_activate (app
);
327 test_nonunique (void)
329 GApplication
*first
, *second
, *third
, *fourth
;
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
;
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
;
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
;
351 fourth
= make_app (FALSE
);
352 /* should have failed to register due to being
353 * unable to register the object paths
355 g_assert (fourth
== NULL
);
356 g_assert (recently_activated
== NULL
);
358 g_object_unref (first
);
359 g_object_unref (second
);
360 g_object_unref (third
);
372 GApplicationFlags flags
;
377 GError
*error
= NULL
;
380 c
= g_bus_get_sync (G_BUS_TYPE_SESSION
, NULL
, NULL
);
382 app
= g_object_new (G_TYPE_APPLICATION
,
383 "application-id", "org.gtk.TestApplication",
387 "application-id", &id
,
389 "is-registered", ®istered
,
390 "inactivity-timeout", &timeout
,
393 g_assert_cmpstr (id
, ==, "org.gtk.TestApplication");
394 g_assert_cmpint (flags
, ==, G_APPLICATION_FLAGS_NONE
);
395 g_assert (!registered
);
396 g_assert_cmpint (timeout
, ==, 0);
398 ret
= g_application_register (G_APPLICATION (app
), NULL
, &error
);
400 g_assert_no_error (error
);
403 "is-registered", ®istered
,
404 "is-remote", &remote
,
407 g_assert (registered
);
411 "inactivity-timeout", 1000,
414 g_application_quit (G_APPLICATION (app
));
417 g_object_unref (app
);
428 g_assert_false (g_application_id_is_valid (""));
429 g_assert_false (g_application_id_is_valid ("."));
430 g_assert_false (g_application_id_is_valid ("a"));
431 g_assert_false (g_application_id_is_valid ("abc"));
432 g_assert_false (g_application_id_is_valid (".abc"));
433 g_assert_false (g_application_id_is_valid ("abc."));
434 g_assert_false (g_application_id_is_valid ("a..b"));
435 g_assert_false (g_application_id_is_valid ("a/b"));
436 g_assert_false (g_application_id_is_valid ("a\nb"));
437 g_assert_false (g_application_id_is_valid ("a\nb"));
438 g_assert_false (g_application_id_is_valid ("emoji_picker"));
439 g_assert_false (g_application_id_is_valid ("emoji-picker"));
440 g_assert_false (g_application_id_is_valid ("emojipicker"));
441 g_assert_false (g_application_id_is_valid ("my.Terminal.0123"));
442 id
= g_new0 (gchar
, 261);
443 memset (id
, 'a', 260);
446 g_assert_false (g_application_id_is_valid (id
));
449 g_assert_true (g_application_id_is_valid ("a.b"));
450 g_assert_true (g_application_id_is_valid ("A.B"));
451 g_assert_true (g_application_id_is_valid ("A-.B"));
452 g_assert_true (g_application_id_is_valid ("a_b.c-d"));
453 g_assert_true (g_application_id_is_valid ("_a.b"));
454 g_assert_true (g_application_id_is_valid ("-a.b"));
455 g_assert_true (g_application_id_is_valid ("org.gnome.SessionManager"));
456 g_assert_true (g_application_id_is_valid ("my.Terminal._0123"));
457 g_assert_true (g_application_id_is_valid ("com.example.MyApp"));
458 g_assert_true (g_application_id_is_valid ("com.example.internal_apps.Calculator"));
459 g_assert_true (g_application_id_is_valid ("org._7_zip.Archiver"));
462 static gboolean nodbus_activated
;
465 release_app (gpointer user_data
)
467 g_application_release (user_data
);
468 return G_SOURCE_REMOVE
;
472 nodbus_activate (GApplication
*app
)
474 nodbus_activated
= TRUE
;
475 g_application_hold (app
);
477 g_assert (g_application_get_dbus_connection (app
) == NULL
);
478 g_assert (g_application_get_dbus_object_path (app
) == NULL
);
480 g_idle_add (release_app
, app
);
486 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
487 gchar
*argv
[] = { binpath
, NULL
};
490 app
= g_application_new ("org.gtk.Unimportant", G_APPLICATION_FLAGS_NONE
);
491 g_signal_connect (app
, "activate", G_CALLBACK (nodbus_activate
), NULL
);
492 g_application_run (app
, 1, argv
);
493 g_object_unref (app
);
495 g_assert (nodbus_activated
);
499 static gboolean noappid_activated
;
502 noappid_activate (GApplication
*app
)
504 noappid_activated
= TRUE
;
505 g_application_hold (app
);
507 g_assert (g_application_get_flags (app
) & G_APPLICATION_NON_UNIQUE
);
509 g_idle_add (release_app
, app
);
512 /* test that no appid -> non-unique */
516 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
517 gchar
*argv
[] = { binpath
, NULL
};
520 app
= g_application_new (NULL
, G_APPLICATION_FLAGS_NONE
);
521 g_signal_connect (app
, "activate", G_CALLBACK (noappid_activate
), NULL
);
522 g_application_run (app
, 1, argv
);
523 g_object_unref (app
);
525 g_assert (noappid_activated
);
529 static gboolean activated
;
530 static gboolean quitted
;
533 quit_app (gpointer user_data
)
536 g_application_quit (user_data
);
537 return G_SOURCE_REMOVE
;
541 quit_activate (GApplication
*app
)
544 g_application_hold (app
);
546 g_assert (g_application_get_dbus_connection (app
) != NULL
);
547 g_assert (g_application_get_dbus_object_path (app
) != NULL
);
549 g_idle_add (quit_app
, app
);
556 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
557 gchar
*argv
[] = { binpath
, NULL
};
561 c
= g_bus_get_sync (G_BUS_TYPE_SESSION
, NULL
, NULL
);
563 app
= g_application_new ("org.gtk.Unimportant",
564 G_APPLICATION_FLAGS_NONE
);
567 g_signal_connect (app
, "activate", G_CALLBACK (quit_activate
), NULL
);
568 g_application_run (app
, 1, argv
);
569 g_object_unref (app
);
572 g_assert (activated
);
580 on_activate (GApplication
*app
)
586 g_assert (!g_application_get_is_remote (app
));
588 actions
= g_action_group_list_actions (G_ACTION_GROUP (app
));
589 g_assert (g_strv_length (actions
) == 0);
590 g_strfreev (actions
);
592 action
= (GAction
*)g_simple_action_new_stateful ("test", G_VARIANT_TYPE_BOOLEAN
, g_variant_new_boolean (FALSE
));
593 g_action_map_add_action (G_ACTION_MAP (app
), action
);
595 actions
= g_action_group_list_actions (G_ACTION_GROUP (app
));
596 g_assert (g_strv_length (actions
) == 1);
597 g_strfreev (actions
);
599 g_action_group_change_action_state (G_ACTION_GROUP (app
), "test", g_variant_new_boolean (TRUE
));
600 state
= g_action_group_get_action_state (G_ACTION_GROUP (app
), "test");
601 g_assert (g_variant_get_boolean (state
) == TRUE
);
603 action
= g_action_map_lookup_action (G_ACTION_MAP (app
), "test");
604 g_assert (action
!= NULL
);
606 g_action_map_remove_action (G_ACTION_MAP (app
), "test");
608 actions
= g_action_group_list_actions (G_ACTION_GROUP (app
));
609 g_assert (g_strv_length (actions
) == 0);
610 g_strfreev (actions
);
614 test_local_actions (void)
616 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
617 gchar
*argv
[] = { binpath
, NULL
};
620 app
= g_application_new ("org.gtk.Unimportant",
621 G_APPLICATION_FLAGS_NONE
);
622 g_signal_connect (app
, "activate", G_CALLBACK (on_activate
), NULL
);
623 g_application_run (app
, 1, argv
);
624 g_object_unref (app
);
628 typedef GApplication TestLocCmdApp
;
629 typedef GApplicationClass TestLocCmdAppClass
;
631 static GType
test_loc_cmd_app_get_type (void);
632 G_DEFINE_TYPE (TestLocCmdApp
, test_loc_cmd_app
, G_TYPE_APPLICATION
)
635 test_loc_cmd_app_init (TestLocCmdApp
*app
)
640 test_loc_cmd_app_startup (GApplication
*app
)
642 g_assert_not_reached ();
646 test_loc_cmd_app_shutdown (GApplication
*app
)
648 g_assert_not_reached ();
652 test_loc_cmd_app_local_command_line (GApplication
*application
,
660 test_loc_cmd_app_class_init (TestLocCmdAppClass
*klass
)
662 G_APPLICATION_CLASS (klass
)->startup
= test_loc_cmd_app_startup
;
663 G_APPLICATION_CLASS (klass
)->shutdown
= test_loc_cmd_app_shutdown
;
664 G_APPLICATION_CLASS (klass
)->local_command_line
= test_loc_cmd_app_local_command_line
;
668 test_local_command_line (void)
670 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
671 gchar
*argv
[] = { binpath
, "-invalid", NULL
};
674 app
= g_object_new (test_loc_cmd_app_get_type (),
675 "application-id", "org.gtk.Unimportant",
676 "flags", G_APPLICATION_FLAGS_NONE
,
678 g_application_run (app
, 1, argv
);
679 g_object_unref (app
);
684 test_resource_path (void)
688 app
= g_application_new ("x.y.z", 0);
689 g_assert_cmpstr (g_application_get_resource_base_path (app
), ==, "/x/y/z");
691 /* this should not change anything */
692 g_application_set_application_id (app
, "a.b.c");
693 g_assert_cmpstr (g_application_get_resource_base_path (app
), ==, "/x/y/z");
695 /* but this should... */
696 g_application_set_resource_base_path (app
, "/x");
697 g_assert_cmpstr (g_application_get_resource_base_path (app
), ==, "/x");
700 g_application_set_resource_base_path (app
, NULL
);
701 g_assert_cmpstr (g_application_get_resource_base_path (app
), ==, NULL
);
703 g_object_unref (app
);
705 /* Make sure that overriding at construction time works properly */
706 app
= g_object_new (G_TYPE_APPLICATION
, "application-id", "x.y.z", "resource-base-path", "/a", NULL
);
707 g_assert_cmpstr (g_application_get_resource_base_path (app
), ==, "/a");
708 g_object_unref (app
);
710 /* ... particularly if we override to NULL */
711 app
= g_object_new (G_TYPE_APPLICATION
, "application-id", "x.y.z", "resource-base-path", NULL
, NULL
);
712 g_assert_cmpstr (g_application_get_resource_base_path (app
), ==, NULL
);
713 g_object_unref (app
);
717 test_help_command_line (GApplication
*app
,
718 GApplicationCommandLine
*command_line
,
721 gboolean
*called
= user_data
;
728 /* Test whether --help is handled when HANDLES_COMMND_LINE is set and
729 * options have been added.
734 if (g_test_subprocess ())
736 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
737 gchar
*argv
[] = { binpath
, "--help", NULL
};
739 gboolean called
= FALSE
;
742 app
= g_application_new ("org.gtk.TestApplication", G_APPLICATION_HANDLES_COMMAND_LINE
);
743 g_application_add_main_option (app
, "foo", 'f', G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, "", "");
744 g_signal_connect (app
, "command-line", G_CALLBACK (test_help_command_line
), &called
);
746 status
= g_application_run (app
, G_N_ELEMENTS (argv
) -1, argv
);
747 g_assert (called
== TRUE
);
748 g_assert_cmpint (status
, ==, 0);
750 g_object_unref (app
);
755 g_test_trap_subprocess (NULL
, 0, 0);
756 g_test_trap_assert_passed ();
757 g_test_trap_assert_stdout ("*Application options*");
765 /* use GSimpleAction to bind to the busy state, because it's easy to
766 * create and has an easily modifiable boolean property */
767 GSimpleAction
*action1
;
768 GSimpleAction
*action2
;
772 app
= g_application_new ("org.gtk.TestApplication", G_APPLICATION_NON_UNIQUE
);
773 g_assert (g_application_register (app
, NULL
, NULL
));
775 g_assert (!g_application_get_is_busy (app
));
776 g_application_mark_busy (app
);
777 g_assert (g_application_get_is_busy (app
));
778 g_application_unmark_busy (app
);
779 g_assert (!g_application_get_is_busy (app
));
781 action1
= g_simple_action_new ("action", NULL
);
782 g_application_bind_busy_property (app
, action1
, "enabled");
783 g_assert (g_application_get_is_busy (app
));
785 g_simple_action_set_enabled (action1
, FALSE
);
786 g_assert (!g_application_get_is_busy (app
));
788 g_application_mark_busy (app
);
789 g_assert (g_application_get_is_busy (app
));
791 action2
= g_simple_action_new ("action", NULL
);
792 g_application_bind_busy_property (app
, action2
, "enabled");
793 g_assert (g_application_get_is_busy (app
));
795 g_application_unmark_busy (app
);
796 g_assert (g_application_get_is_busy (app
));
798 g_object_unref (action2
);
799 g_assert (!g_application_get_is_busy (app
));
801 g_simple_action_set_enabled (action1
, TRUE
);
802 g_assert (g_application_get_is_busy (app
));
804 g_application_mark_busy (app
);
805 g_assert (g_application_get_is_busy (app
));
807 g_application_unbind_busy_property (app
, action1
, "enabled");
808 g_assert (g_application_get_is_busy (app
));
810 g_application_unmark_busy (app
);
811 g_assert (!g_application_get_is_busy (app
));
813 g_object_unref (action1
);
814 g_object_unref (app
);
820 * Test that handle-local-options works as expected
824 test_local_options (GApplication
*app
,
825 GVariantDict
*options
,
828 gboolean
*called
= data
;
832 if (g_variant_dict_contains (options
, "success"))
834 else if (g_variant_dict_contains (options
, "failure"))
841 second_handler (GApplication
*app
,
842 GVariantDict
*options
,
845 gboolean
*called
= data
;
853 test_handle_local_options_success (void)
855 if (g_test_subprocess ())
857 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
858 gchar
*argv
[] = { binpath
, "--success", NULL
};
860 gboolean called
= FALSE
;
861 gboolean called2
= FALSE
;
864 app
= g_application_new ("org.gtk.TestApplication", 0);
865 g_application_add_main_option (app
, "success", 0, G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, "", "");
866 g_application_add_main_option (app
, "failure", 0, G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, "", "");
867 g_signal_connect (app
, "handle-local-options", G_CALLBACK (test_local_options
), &called
);
868 g_signal_connect (app
, "handle-local-options", G_CALLBACK (second_handler
), &called2
);
870 status
= g_application_run (app
, G_N_ELEMENTS (argv
) -1, argv
);
873 g_assert_cmpint (status
, ==, 0);
875 g_object_unref (app
);
880 g_test_trap_subprocess (NULL
, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT
| G_TEST_SUBPROCESS_INHERIT_STDERR
);
881 g_test_trap_assert_passed ();
885 test_handle_local_options_failure (void)
887 if (g_test_subprocess ())
889 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
890 gchar
*argv
[] = { binpath
, "--failure", NULL
};
892 gboolean called
= FALSE
;
893 gboolean called2
= FALSE
;
896 app
= g_application_new ("org.gtk.TestApplication", 0);
897 g_application_add_main_option (app
, "success", 0, G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, "", "");
898 g_application_add_main_option (app
, "failure", 0, G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, "", "");
899 g_signal_connect (app
, "handle-local-options", G_CALLBACK (test_local_options
), &called
);
900 g_signal_connect (app
, "handle-local-options", G_CALLBACK (second_handler
), &called2
);
902 status
= g_application_run (app
, G_N_ELEMENTS (argv
) -1, argv
);
905 g_assert_cmpint (status
, ==, 1);
907 g_object_unref (app
);
912 g_test_trap_subprocess (NULL
, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT
| G_TEST_SUBPROCESS_INHERIT_STDERR
);
913 g_test_trap_assert_passed ();
917 test_handle_local_options_passthrough (void)
919 if (g_test_subprocess ())
921 char *binpath
= g_test_build_filename (G_TEST_BUILT
, "unimportant", NULL
);
922 gchar
*argv
[] = { binpath
, NULL
};
924 gboolean called
= FALSE
;
925 gboolean called2
= FALSE
;
928 app
= g_application_new ("org.gtk.TestApplication", 0);
929 g_application_add_main_option (app
, "success", 0, G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, "", "");
930 g_application_add_main_option (app
, "failure", 0, G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, "", "");
931 g_signal_connect (app
, "handle-local-options", G_CALLBACK (test_local_options
), &called
);
932 g_signal_connect (app
, "handle-local-options", G_CALLBACK (second_handler
), &called2
);
934 status
= g_application_run (app
, G_N_ELEMENTS (argv
) -1, argv
);
937 g_assert_cmpint (status
, ==, 2);
939 g_object_unref (app
);
944 g_test_trap_subprocess (NULL
, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT
| G_TEST_SUBPROCESS_INHERIT_STDERR
);
945 g_test_trap_assert_passed ();
952 GSimpleAction
*action
;
954 app
= g_application_new ("org.gtk.TestApplication", 0);
956 /* add an action without a name */
957 g_test_expect_message (G_LOG_DOMAIN
, G_LOG_LEVEL_CRITICAL
, "*assertion*failed*");
958 action
= g_simple_action_new (NULL
, NULL
);
959 g_assert (action
== NULL
);
960 g_test_assert_expected_messages ();
962 /* also, gapplication shouldn't accept actions without names */
963 action
= g_object_new (G_TYPE_SIMPLE_ACTION
, NULL
);
964 g_test_expect_message (G_LOG_DOMAIN
, G_LOG_LEVEL_CRITICAL
, "*action has no name*");
965 g_action_map_add_action (G_ACTION_MAP (app
), G_ACTION (action
));
966 g_test_assert_expected_messages ();
968 g_object_unref (action
);
969 g_object_unref (app
);
973 main (int argc
, char **argv
)
975 g_setenv ("LC_ALL", "C", TRUE
);
977 g_test_init (&argc
, &argv
, NULL
);
979 g_test_dbus_unset ();
981 g_test_add_func ("/gapplication/no-dbus", test_nodbus
);
982 /* g_test_add_func ("/gapplication/basic", basic); */
983 g_test_add_func ("/gapplication/no-appid", test_noappid
);
984 /* g_test_add_func ("/gapplication/non-unique", test_nonunique); */
985 g_test_add_func ("/gapplication/properties", properties
);
986 g_test_add_func ("/gapplication/app-id", appid
);
987 g_test_add_func ("/gapplication/quit", test_quit
);
988 g_test_add_func ("/gapplication/local-actions", test_local_actions
);
989 /* g_test_add_func ("/gapplication/remote-actions", test_remote_actions); */
990 g_test_add_func ("/gapplication/local-command-line", test_local_command_line
);
991 /* g_test_add_func ("/gapplication/remote-command-line", test_remote_command_line); */
992 g_test_add_func ("/gapplication/resource-path", test_resource_path
);
993 g_test_add_func ("/gapplication/test-help", test_help
);
994 g_test_add_func ("/gapplication/test-busy", test_busy
);
995 g_test_add_func ("/gapplication/test-handle-local-options1", test_handle_local_options_success
);
996 g_test_add_func ("/gapplication/test-handle-local-options2", test_handle_local_options_failure
);
997 g_test_add_func ("/gapplication/test-handle-local-options3", test_handle_local_options_passthrough
);
998 g_test_add_func ("/gapplication/api", test_api
);
1000 return g_test_run ();