From 0d8b1b14d2d56c92b2b783798a9552eb75d77a29 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 16 Apr 2012 10:16:47 +0200 Subject: [PATCH] Add gdbus-daemon test app --- gio/tests/Makefile.am | 4 +++ gio/tests/gdbus-daemon.c | 72 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 gio/tests/gdbus-daemon.c diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am index 79878daa1..9829aa04d 100644 --- a/gio/tests/Makefile.am +++ b/gio/tests/Makefile.am @@ -119,6 +119,7 @@ SAMPLE_PROGS = \ gapplication-example-cmdline2 \ gapplication-example-cmdline3 \ gapplication-example-actions \ + gdbus-daemon \ $(NULL) if OS_UNIX @@ -264,6 +265,9 @@ gsettings_LDADD = $(progs_ldadd) gschema_compile_SOURCES = gschema-compile.c gschema_compile_LDADD = $(progs_ldadd) +gdbus_daemon_SOURCES = gdbus-daemon.c $(top_srcdir)/gio/gdbusdaemon.c $(top_srcdir)/gio/gdbus-daemon-generated.c +gdbus_daemon_LDADD = $(progs_ldadd) + if HAVE_DBUS1 TEST_PROGS += gdbus-serialization gdbus_serialization_SOURCES = gdbus-serialization.c gdbus-tests.h gdbus-tests.c diff --git a/gio/tests/gdbus-daemon.c b/gio/tests/gdbus-daemon.c new file mode 100644 index 000000000..04717082c --- /dev/null +++ b/gio/tests/gdbus-daemon.c @@ -0,0 +1,72 @@ +#include "config.h" + +#include "gdbusdaemon.h" +#include + +int +main (int argc, char *argv[]) +{ + GDBusDaemon *daemon; + GMainLoop *loop; + const char *address = NULL; + const char *config_file = NULL; + GError *error = NULL; + gboolean print_address = FALSE; + gboolean print_env = FALSE; + GOptionContext *context; + GOptionEntry entries[] = { + { "address", 0, 0, G_OPTION_ARG_STRING, &address, N_("Address to listen on"), NULL }, + { "config-file", 0, 0, G_OPTION_ARG_STRING, &config_file, N_("Ignored, for compat with GTestDbus"), NULL }, + { "print-address", 0, 0, G_OPTION_ARG_NONE, &print_address, N_("Print address"), NULL }, + { "print-env", 0, 0, G_OPTION_ARG_NONE, &print_env, N_("Print address in shell mode"), NULL }, + { NULL } + }; + + g_type_init (); + + context = g_option_context_new (""); + g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); + g_option_context_set_summary (context, + N_("Run a dbus service")); + g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); + + error = NULL; + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + g_printerr ("%s\n", error->message); + return 1; + } + + g_option_context_free (context); + + if (argc != 1) + { + g_printerr (_("Wrong args\n")); + return 1; + } + + + loop = g_main_loop_new (NULL, FALSE); + + if (argc >= 2) + address = argv[1]; + + daemon = _g_dbus_daemon_new (address, NULL, &error); + if (daemon == NULL) + { + g_printerr ("Can't init bus: %s\n", error->message); + return 1; + } + + if (print_env) + g_print ("export DBUS_SESSION_BUS_ADDRESS=\"%s\"\n", _g_dbus_daemon_get_address (daemon)); + + if (print_address) + g_print ("%s\n", _g_dbus_daemon_get_address (daemon)); + + g_main_loop_run (loop); + + g_main_loop_unref (loop); + + return 0; +}