summaryrefslogtreecommitdiff
path: root/gio/tests/gapplication.c
diff options
context:
space:
mode:
Diffstat (limited to 'gio/tests/gapplication.c')
-rw-r--r--gio/tests/gapplication.c528
1 files changed, 512 insertions, 16 deletions
diff --git a/gio/tests/gapplication.c b/gio/tests/gapplication.c
index 6f1a27e0f..b0584eb5f 100644
--- a/gio/tests/gapplication.c
+++ b/gio/tests/gapplication.c
@@ -391,7 +391,7 @@ properties (void)
NULL);
g_assert_cmpstr (id, ==, "org.gtk.TestApplication");
- g_assert_cmpint (flags, ==, G_APPLICATION_FLAGS_NONE);
+ g_assert_cmpint (flags, ==, G_APPLICATION_DEFAULT_FLAGS);
g_assert (!registered);
g_assert_cmpint (timeout, ==, 0);
@@ -487,7 +487,7 @@ test_nodbus (void)
gchar *argv[] = { binpath, NULL };
GApplication *app;
- app = g_application_new ("org.gtk.Unimportant", G_APPLICATION_FLAGS_NONE);
+ app = g_application_new ("org.gtk.Unimportant", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (nodbus_activate), NULL);
g_application_run (app, 1, argv);
g_object_unref (app);
@@ -517,7 +517,7 @@ test_noappid (void)
gchar *argv[] = { binpath, NULL };
GApplication *app;
- app = g_application_new (NULL, G_APPLICATION_FLAGS_NONE);
+ app = g_application_new (NULL, G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (noappid_activate), NULL);
g_application_run (app, 1, argv);
g_object_unref (app);
@@ -561,7 +561,7 @@ test_quit (void)
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
app = g_application_new ("org.gtk.Unimportant",
- G_APPLICATION_FLAGS_NONE);
+ G_APPLICATION_DEFAULT_FLAGS);
activated = FALSE;
quitted = FALSE;
g_signal_connect (app, "activate", G_CALLBACK (quit_activate), NULL);
@@ -613,7 +613,7 @@ test_registered (void)
RegisteredData registered_data = { FALSE, NULL };
GApplication *app;
- app = g_application_new (NULL, G_APPLICATION_FLAGS_NONE);
+ app = g_application_new (NULL, G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (noappid_activate), NULL);
g_signal_connect (app, "shutdown", G_CALLBACK (on_registered_shutdown), &registered_data);
g_signal_connect (app, "notify::is-registered", G_CALLBACK (on_registered_notify), &registered_data);
@@ -693,7 +693,7 @@ test_local_actions (void)
GApplication *app;
app = g_application_new ("org.gtk.Unimportant",
- G_APPLICATION_FLAGS_NONE);
+ G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
g_application_run (app, 1, argv);
g_object_unref (app);
@@ -748,7 +748,7 @@ test_local_command_line (void)
app = g_object_new (test_loc_cmd_app_get_type (),
"application-id", "org.gtk.Unimportant",
- "flags", G_APPLICATION_FLAGS_NONE,
+ "flags", G_APPLICATION_DEFAULT_FLAGS,
NULL);
g_application_run (app, 1, argv);
g_object_unref (app);
@@ -827,7 +827,7 @@ test_help (void)
return;
}
- g_test_trap_subprocess (NULL, 0, 0);
+ g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_DEFAULT);
g_test_trap_assert_passed ();
g_test_trap_assert_stdout ("*Application options*");
}
@@ -1071,6 +1071,8 @@ typedef struct
{
gboolean allow_replacement;
GSubprocess *subprocess;
+ GApplication *app; /* (not owned) */
+ guint timeout_id;
} TestReplaceData;
static void
@@ -1115,14 +1117,13 @@ activate (gpointer data)
/* GApplication complains if we don't connect to ::activate */
}
-static gboolean
-quit_already (gpointer data)
+static void
+quit_already (gpointer user_data)
{
- GApplication *app = data;
-
- g_application_quit (app);
+ TestReplaceData *data = user_data;
- return G_SOURCE_REMOVE;
+ g_application_quit (data->app);
+ data->timeout_id = 0;
}
static void
@@ -1162,18 +1163,19 @@ test_replace (gconstpointer data)
data.allow_replacement = allow;
data.subprocess = NULL;
+ data.timeout_id = 0;
bus = g_test_dbus_new (0);
g_test_dbus_up (bus);
- app = g_application_new ("org.gtk.TestApplication.Replace", allow ? G_APPLICATION_ALLOW_REPLACEMENT : G_APPLICATION_FLAGS_NONE);
+ app = data.app = g_application_new ("org.gtk.TestApplication.Replace", allow ? G_APPLICATION_ALLOW_REPLACEMENT : G_APPLICATION_DEFAULT_FLAGS);
g_application_set_inactivity_timeout (app, 500);
g_signal_connect (app, "name-lost", G_CALLBACK (name_was_lost), &name_lost);
g_signal_connect (app, "startup", G_CALLBACK (startup_cb), &data);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
if (!allow)
- g_timeout_add_seconds (1, quit_already, app);
+ data.timeout_id = g_timeout_add_seconds_once (1, quit_already, &data);
g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
@@ -1183,6 +1185,7 @@ test_replace (gconstpointer data)
else
g_assert_false (name_lost);
+ g_clear_handle_id (&data.timeout_id, g_source_remove);
g_object_unref (app);
g_free (binpath);
@@ -1194,11 +1197,500 @@ test_replace (gconstpointer data)
}
}
+static void
+dbus_activate_cb (GApplication *app,
+ gpointer user_data)
+{
+ guint *n_activations = user_data;
+
+ *n_activations = *n_activations + 1;
+ g_main_context_wakeup (NULL);
+}
+
+static void dbus_startup_reply_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data);
+static gboolean dbus_startup_reply_idle_cb (gpointer user_data);
+
+static void
+dbus_startup_cb (GApplication *app,
+ gpointer user_data)
+{
+ GDBusConnection *connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ GDBusMessage *message = G_DBUS_MESSAGE (user_data);
+
+ g_assert_nonnull (connection);
+
+ g_dbus_connection_send_message_with_reply (connection, message,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1,
+ NULL, NULL,
+ dbus_startup_reply_cb, g_object_ref (app));
+
+ g_clear_object (&connection);
+}
+
+static void
+dbus_startup_reply_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
+ GApplication *app = G_APPLICATION (user_data);
+ GDBusMessage *reply = NULL;
+ GError *local_error = NULL;
+
+ reply = g_dbus_connection_send_message_with_reply_finish (connection, result, &local_error);
+ g_assert_no_error (local_error);
+
+ /* Nothing to check on the reply for now. */
+ g_clear_object (&reply);
+
+ /* Release the app in an idle callback, so there’s time to process other
+ * pending sources first. */
+ g_idle_add_full (G_PRIORITY_LOW, dbus_startup_reply_idle_cb, g_steal_pointer (&app), g_object_unref);
+}
+
+static gboolean
+dbus_startup_reply_idle_cb (gpointer user_data)
+{
+ GApplication *app = G_APPLICATION (user_data);
+
+ g_application_release (app);
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+test_dbus_activate (void)
+{
+ GTestDBus *bus = NULL;
+ GVariantBuilder builder;
+ GDBusMessage *message = NULL;
+ GPtrArray *messages = NULL; /* (element-type GDBusMessage) (owned) */
+ gsize i;
+
+ g_test_summary ("Test that calling the Activate D-Bus method works");
+
+ /* Try various different messages */
+ messages = g_ptr_array_new_with_free_func (g_object_unref);
+
+ /* Via org.gtk.Application */
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
+ "/org/gtk/TestApplication/Activate",
+ "org.gtk.Application",
+ "Activate");
+ g_dbus_message_set_body (message, g_variant_new ("(a{sv})", NULL));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* Via org.freedesktop.Application */
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
+ "/org/gtk/TestApplication/Activate",
+ "org.freedesktop.Application",
+ "Activate");
+ g_dbus_message_set_body (message, g_variant_new ("(a{sv})", NULL));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* With some platform data */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_add (&builder, "{sv}", "cwd", g_variant_new_bytestring ("/home/henry"));
+
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Activate",
+ "/org/gtk/TestApplication/Activate",
+ "org.gtk.Application",
+ "Activate");
+ g_dbus_message_set_body (message, g_variant_new ("(a{sv})", &builder));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* Try each message */
+ bus = g_test_dbus_new (G_TEST_DBUS_NONE);
+ g_test_dbus_up (bus);
+
+ for (i = 0; i < messages->len; i++)
+ {
+ GApplication *app = NULL;
+ gulong activate_id, startup_id;
+ guint n_activations = 0;
+
+ g_test_message ("Message %" G_GSIZE_FORMAT, i);
+
+ app = g_application_new ("org.gtk.TestApplication.Activate", G_APPLICATION_DEFAULT_FLAGS);
+ activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_cb), &n_activations);
+ startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
+
+ g_application_hold (app);
+ g_application_run (app, 0, NULL);
+
+ /* It’ll be activated once as normal, and once due to the D-Bus call */
+ g_assert_cmpuint (n_activations, ==, 2);
+
+ g_signal_handler_disconnect (app, startup_id);
+ g_signal_handler_disconnect (app, activate_id);
+ g_clear_object (&app);
+ }
+
+ g_ptr_array_unref (messages);
+
+ g_test_dbus_down (bus);
+ g_clear_object (&bus);
+}
+
+static void
+dbus_activate_noop_cb (GApplication *app,
+ gpointer user_data)
+{
+ /* noop */
+}
+
+static void
+dbus_open_cb (GApplication *app,
+ gpointer files,
+ int n_files,
+ char *hint,
+ gpointer user_data)
+{
+ guint *n_opens = user_data;
+
+ *n_opens = *n_opens + 1;
+ g_main_context_wakeup (NULL);
+}
+
+static void
+test_dbus_open (void)
+{
+ GTestDBus *bus = NULL;
+ GVariantBuilder builder, builder2;
+ GDBusMessage *message = NULL;
+ GPtrArray *messages = NULL; /* (element-type GDBusMessage) (owned) */
+ gsize i;
+
+ g_test_summary ("Test that calling the Open D-Bus method works");
+
+ /* Try various different messages */
+ messages = g_ptr_array_new_with_free_func (g_object_unref);
+
+ /* Via org.gtk.Application */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
+ g_variant_builder_add (&builder, "s", "file:///home/henry/test");
+
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
+ "/org/gtk/TestApplication/Open",
+ "org.gtk.Application",
+ "Open");
+ g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", &builder, "hint", NULL));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* Via org.freedesktop.Application (which has no hint parameter) */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
+ g_variant_builder_add (&builder, "s", "file:///home/henry/test");
+
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
+ "/org/gtk/TestApplication/Open",
+ "org.freedesktop.Application",
+ "Open");
+ g_dbus_message_set_body (message, g_variant_new ("(asa{sv})", &builder, NULL));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* With some platform data and more than one file */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
+ g_variant_builder_add (&builder, "s", "file:///home/henry/test");
+ g_variant_builder_add (&builder, "s", "file:///home/henry/test2");
+
+ g_variant_builder_init (&builder2, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_bytestring ("/home/henry"));
+
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
+ "/org/gtk/TestApplication/Open",
+ "org.gtk.Application",
+ "Open");
+ g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", &builder, "", &builder2));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* No files */
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.Open",
+ "/org/gtk/TestApplication/Open",
+ "org.gtk.Application",
+ "Open");
+ g_dbus_message_set_body (message, g_variant_new ("(assa{sv})", NULL, "", NULL));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* Try each message */
+ bus = g_test_dbus_new (G_TEST_DBUS_NONE);
+ g_test_dbus_up (bus);
+
+ for (i = 0; i < messages->len; i++)
+ {
+ GApplication *app = NULL;
+ gulong activate_id, open_id, startup_id;
+ guint n_opens = 0;
+
+ g_test_message ("Message %" G_GSIZE_FORMAT, i);
+
+ app = g_application_new ("org.gtk.TestApplication.Open", G_APPLICATION_HANDLES_OPEN);
+ activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
+ open_id = g_signal_connect (app, "open", G_CALLBACK (dbus_open_cb), &n_opens);
+ startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
+
+ g_application_hold (app);
+ g_application_run (app, 0, NULL);
+
+ g_assert_cmpuint (n_opens, ==, 1);
+
+ g_signal_handler_disconnect (app, startup_id);
+ g_signal_handler_disconnect (app, open_id);
+ g_signal_handler_disconnect (app, activate_id);
+ g_clear_object (&app);
+ }
+
+ g_ptr_array_unref (messages);
+
+ g_test_dbus_down (bus);
+ g_clear_object (&bus);
+}
+
+static void
+dbus_command_line_cb (GApplication *app,
+ GApplicationCommandLine *command_line,
+ gpointer user_data)
+{
+ guint *n_command_lines = user_data;
+
+ *n_command_lines = *n_command_lines + 1;
+ g_main_context_wakeup (NULL);
+}
+
+static void
+test_dbus_command_line (void)
+{
+ GTestDBus *bus = NULL;
+ GVariantBuilder builder, builder2;
+ GDBusMessage *message = NULL;
+ GPtrArray *messages = NULL; /* (element-type GDBusMessage) (owned) */
+ gsize i;
+
+ g_test_summary ("Test that calling the CommandLine D-Bus method works");
+
+ /* Try various different messages */
+ messages = g_ptr_array_new_with_free_func (g_object_unref);
+
+ /* Via org.gtk.Application */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
+ g_variant_builder_add (&builder, "^ay", "test-program");
+ g_variant_builder_add (&builder, "^ay", "--open");
+ g_variant_builder_add (&builder, "^ay", "/path/to/something");
+
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
+ "/org/gtk/TestApplication/CommandLine",
+ "org.gtk.Application",
+ "CommandLine");
+ g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
+ "/my/org/gtk/private/CommandLine",
+ &builder, NULL));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* With platform data */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
+ g_variant_builder_add (&builder, "^ay", "test-program");
+ g_variant_builder_add (&builder, "^ay", "--open");
+ g_variant_builder_add (&builder, "^ay", "/path/to/something");
+
+ g_variant_builder_init (&builder2, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_bytestring ("/home"));
+ g_variant_builder_add_parsed (&builder2, "{'environ', <@aay [ b'HOME=/home/bloop', b'PATH=/blah']>}");
+ g_variant_builder_add_parsed (&builder2, "{'options', <{'a': <@u 32>, 'b': <'bloop'>}>}");
+
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
+ "/org/gtk/TestApplication/CommandLine",
+ "org.gtk.Application",
+ "CommandLine");
+ g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
+ "/my/org/gtk/private/CommandLine",
+ &builder, &builder2));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* With invalid typed platform data */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
+ g_variant_builder_add (&builder, "^ay", "test-program");
+ g_variant_builder_add (&builder, "^ay", "--open");
+ g_variant_builder_add (&builder, "^ay", "/path/to/something");
+
+ g_variant_builder_init (&builder2, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_add (&builder2, "{sv}", "cwd", g_variant_new_string ("/home should be a bytestring"));
+ g_variant_builder_add_parsed (&builder2, "{'environ', <['HOME=should be a bytestring', 'PATH=this also']>}");
+ g_variant_builder_add_parsed (&builder2, "{'options', <['should be a', 'dict']>}");
+
+ message = g_dbus_message_new_method_call ("org.gtk.TestApplication.CommandLine",
+ "/org/gtk/TestApplication/CommandLine",
+ "org.gtk.Application",
+ "CommandLine");
+ g_dbus_message_set_body (message, g_variant_new ("(oaaya{sv})",
+ "/my/org/gtk/private/CommandLine",
+ &builder, &builder2));
+ g_ptr_array_add (messages, g_steal_pointer (&message));
+
+ /* Try each message */
+ bus = g_test_dbus_new (G_TEST_DBUS_NONE);
+ g_test_dbus_up (bus);
+
+ for (i = 0; i < messages->len; i++)
+ {
+ GApplication *app = NULL;
+ gulong activate_id, command_line_id, startup_id;
+ guint n_command_lines = 0;
+
+ g_test_message ("Message %" G_GSIZE_FORMAT, i);
+
+ app = g_application_new ("org.gtk.TestApplication.CommandLine", G_APPLICATION_HANDLES_COMMAND_LINE);
+ activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
+ command_line_id = g_signal_connect (app, "command-line", G_CALLBACK (dbus_command_line_cb), &n_command_lines);
+ startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages->pdata[i]);
+
+ g_application_hold (app);
+ g_application_run (app, 0, NULL);
+
+ /* It’s called once for handling the local command line on startup, and again
+ * for the D-Bus call */
+ g_assert_cmpuint (n_command_lines, ==, 2);
+
+ g_signal_handler_disconnect (app, startup_id);
+ g_signal_handler_disconnect (app, command_line_id);
+ g_signal_handler_disconnect (app, activate_id);
+ g_clear_object (&app);
+ }
+
+ g_ptr_array_unref (messages);
+
+ g_test_dbus_down (bus);
+ g_clear_object (&bus);
+}
+
+static void
+dbus_activate_action_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ guint *n_activations = user_data;
+
+ *n_activations = *n_activations + 1;
+ g_main_context_wakeup (NULL);
+}
+
+static void
+test_dbus_activate_action (void)
+{
+ GTestDBus *bus = NULL;
+ GVariantBuilder builder;
+ struct
+ {
+ GDBusMessage *message; /* (not nullable) (owned) */
+ guint n_expected_activations;
+ } messages[6];
+ gsize i;
+
+ g_test_summary ("Test that calling the ActivateAction D-Bus method works");
+
+ /* Action without parameter */
+ messages[0].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
+ "/org/gtk/TestApplication/ActivateAction",
+ "org.freedesktop.Application",
+ "ActivateAction");
+ g_dbus_message_set_body (messages[0].message, g_variant_new ("(sava{sv})", "undo", NULL, NULL));
+ messages[0].n_expected_activations = 1;
+
+ /* Action with parameter */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
+ g_variant_builder_add (&builder, "v", g_variant_new_string ("spanish"));
+
+ messages[1].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
+ "/org/gtk/TestApplication/ActivateAction",
+ "org.freedesktop.Application",
+ "ActivateAction");
+ g_dbus_message_set_body (messages[1].message, g_variant_new ("(sava{sv})", "lang", &builder, NULL));
+ messages[1].n_expected_activations = 1;
+
+ /* Action with unexpected parameter */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
+ g_variant_builder_add (&builder, "v", g_variant_new_string ("should not be passed"));
+
+ messages[2].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
+ "/org/gtk/TestApplication/ActivateAction",
+ "org.freedesktop.Application",
+ "ActivateAction");
+ g_dbus_message_set_body (messages[2].message, g_variant_new ("(sava{sv})", "undo", &builder, NULL));
+ messages[2].n_expected_activations = 0;
+
+ /* Action without required parameter */
+ messages[3].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
+ "/org/gtk/TestApplication/ActivateAction",
+ "org.freedesktop.Application",
+ "ActivateAction");
+ g_dbus_message_set_body (messages[3].message, g_variant_new ("(sava{sv})", "lang", NULL, NULL));
+ messages[3].n_expected_activations = 0;
+
+ /* Action with wrong parameter type */
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
+ g_variant_builder_add (&builder, "v", g_variant_new_uint32 (42));
+
+ messages[4].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
+ "/org/gtk/TestApplication/ActivateAction",
+ "org.freedesktop.Application",
+ "ActivateAction");
+ g_dbus_message_set_body (messages[4].message, g_variant_new ("(sava{sv})", "lang", &builder, NULL));
+ messages[4].n_expected_activations = 0;
+
+ /* Nonexistent action */
+ messages[5].message = g_dbus_message_new_method_call ("org.gtk.TestApplication.ActivateAction",
+ "/org/gtk/TestApplication/ActivateAction",
+ "org.freedesktop.Application",
+ "ActivateAction");
+ g_dbus_message_set_body (messages[5].message, g_variant_new ("(sava{sv})", "nonexistent", NULL, NULL));
+ messages[5].n_expected_activations = 0;
+
+ /* Try each message */
+ bus = g_test_dbus_new (G_TEST_DBUS_NONE);
+ g_test_dbus_up (bus);
+
+ for (i = 0; i < G_N_ELEMENTS (messages); i++)
+ {
+ GApplication *app = NULL;
+ gulong activate_id, startup_id;
+ const GActionEntry entries[] =
+ {
+ { "undo", dbus_activate_action_cb, NULL, NULL, NULL, { 0 } },
+ { "lang", dbus_activate_action_cb, "s", "'latin'", NULL, { 0 } },
+ };
+ guint n_activations = 0;
+
+ g_test_message ("Message %" G_GSIZE_FORMAT, i);
+
+ app = g_application_new ("org.gtk.TestApplication.ActivateAction", G_APPLICATION_DEFAULT_FLAGS);
+ activate_id = g_signal_connect (app, "activate", G_CALLBACK (dbus_activate_noop_cb), NULL);
+ startup_id = g_signal_connect (app, "startup", G_CALLBACK (dbus_startup_cb), messages[i].message);
+
+ /* Export some actions. */
+ g_action_map_add_action_entries (G_ACTION_MAP (app), entries, G_N_ELEMENTS (entries), &n_activations);
+
+ g_application_hold (app);
+ g_application_run (app, 0, NULL);
+
+ g_assert_cmpuint (n_activations, ==, messages[i].n_expected_activations);
+
+ g_signal_handler_disconnect (app, startup_id);
+ g_signal_handler_disconnect (app, activate_id);
+ g_clear_object (&app);
+ g_clear_object (&messages[i].message);
+ }
+
+ g_test_dbus_down (bus);
+ g_clear_object (&bus);
+}
+
int
main (int argc, char **argv)
{
g_setenv ("LC_ALL", "C", TRUE);
+ g_log_writer_default_set_use_stderr (TRUE);
+
g_test_init (&argc, &argv, NULL);
if (!g_test_subprocess ())
@@ -1225,6 +1717,10 @@ main (int argc, char **argv)
g_test_add_func ("/gapplication/api", test_api);
g_test_add_data_func ("/gapplication/replace", GINT_TO_POINTER (TRUE), test_replace);
g_test_add_data_func ("/gapplication/no-replace", GINT_TO_POINTER (FALSE), test_replace);
+ g_test_add_func ("/gapplication/dbus/activate", test_dbus_activate);
+ g_test_add_func ("/gapplication/dbus/open", test_dbus_open);
+ g_test_add_func ("/gapplication/dbus/command-line", test_dbus_command_line);
+ g_test_add_func ("/gapplication/dbus/activate-action", test_dbus_activate_action);
return g_test_run ();
}