[glib/gdbus-daemon2: 5/8] Add gdbus-daemon test app



commit 2515a69e2e133871cf7769a8a89244212bf5deaf
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Apr 16 10:16:47 2012 +0200

    Add gdbus-daemon test app

 gio/tests/Makefile.am    |    4 ++
 gio/tests/gdbus-daemon.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 79878da..9829aa0 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 0000000..0471708
--- /dev/null
+++ b/gio/tests/gdbus-daemon.c
@@ -0,0 +1,72 @@
+#include "config.h"
+
+#include "gdbusdaemon.h"
+#include <glib/gi18n.h>
+
+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;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]