[glib] Add tests for GApplication::handle-local-options
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add tests for GApplication::handle-local-options
- Date: Mon, 27 Jul 2015 01:41:28 +0000 (UTC)
commit c885d42751e35ac8210f889d80e4b059a08d86ae
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jul 26 21:39:53 2015 -0400
Add tests for GApplication::handle-local-options
gio/tests/gapplication.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 132 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/gapplication.c b/gio/tests/gapplication.c
index 39e1ff4..42f76af 100644
--- a/gio/tests/gapplication.c
+++ b/gio/tests/gapplication.c
@@ -808,6 +808,135 @@ test_busy (void)
session_bus_down ();
}
+/*
+ * Test that handle-local-options works as expected
+ */
+
+static gint
+test_local_options (GApplication *app,
+ GVariantDict *options,
+ gpointer data)
+{
+ gboolean *called = data;
+
+ *called = TRUE;
+
+ if (g_variant_dict_contains (options, "success"))
+ return 0;
+ else if (g_variant_dict_contains (options, "failure"))
+ return 1;
+ else
+ return -1;
+}
+
+static gint
+second_handler (GApplication *app,
+ GVariantDict *options,
+ gpointer data)
+{
+ gboolean *called = data;
+
+ *called = TRUE;
+
+ return 2;
+}
+
+static void
+test_handle_local_options_success (void)
+{
+ if (g_test_subprocess ())
+ {
+ char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
+ gchar *argv[] = { binpath, "--success", NULL };
+ GApplication *app;
+ gboolean called = FALSE;
+ gboolean called2 = FALSE;
+ int status;
+
+ app = g_application_new ("org.gtk.TestApplication", 0);
+ g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
+ g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
+ g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
+ g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
+
+ status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
+ g_assert (called);
+ g_assert (!called2);
+ g_assert_cmpint (status, ==, 0);
+
+ g_object_unref (app);
+ g_free (binpath);
+ return;
+ }
+
+ g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
+ g_test_trap_assert_passed ();
+}
+
+static void
+test_handle_local_options_failure (void)
+{
+ if (g_test_subprocess ())
+ {
+ char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
+ gchar *argv[] = { binpath, "--failure", NULL };
+ GApplication *app;
+ gboolean called = FALSE;
+ gboolean called2 = FALSE;
+ int status;
+
+ app = g_application_new ("org.gtk.TestApplication", 0);
+ g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
+ g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
+ g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
+ g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
+
+ status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
+ g_assert (called);
+ g_assert (!called2);
+ g_assert_cmpint (status, ==, 1);
+
+ g_object_unref (app);
+ g_free (binpath);
+ return;
+ }
+
+ g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
+ g_test_trap_assert_passed ();
+}
+
+static void
+test_handle_local_options_passthrough (void)
+{
+ if (g_test_subprocess ())
+ {
+ char *binpath = g_test_build_filename (G_TEST_BUILT, "unimportant", NULL);
+ gchar *argv[] = { binpath, NULL };
+ GApplication *app;
+ gboolean called = FALSE;
+ gboolean called2 = FALSE;
+ int status;
+
+ app = g_application_new ("org.gtk.TestApplication", 0);
+ g_application_add_main_option (app, "success", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
+ g_application_add_main_option (app, "failure", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, "", "");
+ g_signal_connect (app, "handle-local-options", G_CALLBACK (test_local_options), &called);
+ g_signal_connect (app, "handle-local-options", G_CALLBACK (second_handler), &called2);
+
+ status = g_application_run (app, G_N_ELEMENTS (argv) -1, argv);
+ g_assert (called);
+ g_assert (called2);
+ g_assert_cmpint (status, ==, 2);
+
+ g_object_unref (app);
+ g_free (binpath);
+ return;
+ }
+
+ g_test_trap_subprocess (NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDOUT | G_TEST_SUBPROCESS_INHERIT_STDERR);
+ g_test_trap_assert_passed ();
+}
+
int
main (int argc, char **argv)
{
@@ -829,6 +958,9 @@ main (int argc, char **argv)
g_test_add_func ("/gapplication/resource-path", test_resource_path);
g_test_add_func ("/gapplication/test-help", test_help);
g_test_add_func ("/gapplication/test-busy", test_busy);
+ g_test_add_func ("/gapplication/test-handle-local-options1", test_handle_local_options_success);
+ g_test_add_func ("/gapplication/test-handle-local-options2", test_handle_local_options_failure);
+ g_test_add_func ("/gapplication/test-handle-local-options3", test_handle_local_options_passthrough);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]