[glib] Fix GApplication tests to run without a session bus



commit 6720596544112a40e8133aea86672197edb46eed
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 9 23:44:13 2010 -0400

    Fix GApplication tests to run without a session bus
    
    We reuse code from the GDBus tests here to launch a session bus.

 gio/tests/Makefile.am   |    4 ++--
 gio/tests/application.c |   15 ++++++++++++++-
 gio/tests/testapps.c    |   15 ++++++++++++++-
 3 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index 87a6a84..99d2db5 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -253,7 +253,7 @@ gdbus_example_proxy_subclass_LDADD   = $(progs_ldadd)
 gdbus_example_export_SOURCES = gdbus-example-export.c
 gdbus_example_export_LDADD   = $(progs_ldadd)
 
-application_SOURCES = application.c
+application_SOURCES = application.c gdbus-sessionbus.c gdbus-sessionbus.h
 application_LDADD   = $(progs_ldadd)
 
 appinfo_SOURCES = appinfo.c
@@ -265,7 +265,7 @@ appinfo_test_LDADD   = $(progs_ldadd)
 testapp_SOURCES = testapp.c
 testapp_LDADD   = $(progs_ldadd)
 
-testapps_SOURCES = testapps.c
+testapps_SOURCES = testapps.c gdbus-sessionbus.c gdbus-sessionbus.h
 testapps_LDADD   = $(progs_ldadd)
 
 EXTRA_DIST += \
diff --git a/gio/tests/application.c b/gio/tests/application.c
index 5dba027..d8a1a63 100644
--- a/gio/tests/application.c
+++ b/gio/tests/application.c
@@ -2,6 +2,8 @@
 #include <gio.h>
 #include <gstdio.h>
 
+#include "gdbus-sessionbus.h"
+
 enum
 {
   INVOKE_ACTION,
@@ -125,10 +127,21 @@ test_basic (void)
 int
 main (int argc, char *argv[])
 {
+  gint ret;
+
   g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
+  g_unsetenv ("DISPLAY");
+  g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+
+  session_bus_up ();
+
   g_test_add_func ("/application/basic", test_basic);
 
-  return g_test_run ();
+  ret = g_test_run ();
+
+  session_bus_down ();
+
+  return ret;
 }
diff --git a/gio/tests/testapps.c b/gio/tests/testapps.c
index 51db0b8..423e808 100644
--- a/gio/tests/testapps.c
+++ b/gio/tests/testapps.c
@@ -3,6 +3,8 @@
 #include <sys/wait.h>
 #include <signal.h>
 
+#include "gdbus-sessionbus.h"
+
 static gint appeared;
 static gint disappeared;
 static gint changed;
@@ -518,9 +520,16 @@ test_change_action (void)
 int
 main (int argc, char *argv[])
 {
+  gint ret;
+
   g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
+  g_unsetenv ("DISPLAY");
+  g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+
+  session_bus_up ();
+
   g_test_add_func ("/application/unique", test_unique);
   g_test_add_func ("/application/quit", test_quit);
   g_test_add_func ("/application/list-actions", test_list_actions);
@@ -528,6 +537,10 @@ main (int argc, char *argv[])
   g_test_add_func ("/application/remote", test_remote);
   g_test_add_func ("/application/change-action", test_change_action);
 
-  return g_test_run ();
+  ret = g_test_run ();
+
+  session_bus_down ();
+
+  return ret;
 }
 



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