[glib] Tests: add session_bus_run() and use it where possible



commit 940fa98290812789d095d93ff1c550cd86fb2428
Author: Xavier Claessens <xavier claessens collabora co uk>
Date:   Mon Oct 28 17:18:54 2013 -0400

    Tests: add session_bus_run() and use it where possible
    
    This is to avoid having again the subtil bug in dbus-appinfo.c:
    session_bus_down() was called before g_test_run() so the test was
    running on the user's dbus session.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697348

 gio/tests/dbus-appinfo.c        |    6 +-----
 gio/tests/gdbus-export.c        |   11 +----------
 gio/tests/gdbus-introspection.c |   10 +---------
 gio/tests/gdbus-proxy.c         |    5 +----
 gio/tests/gdbus-sessionbus.c    |   11 +++++++++++
 gio/tests/gdbus-sessionbus.h    |    1 +
 gio/tests/gdbus-test-codegen.c  |   11 +----------
 7 files changed, 17 insertions(+), 38 deletions(-)
---
diff --git a/gio/tests/dbus-appinfo.c b/gio/tests/dbus-appinfo.c
index ca11e98..7698429 100644
--- a/gio/tests/dbus-appinfo.c
+++ b/gio/tests/dbus-appinfo.c
@@ -280,11 +280,7 @@ main (int argc, char **argv)
 {
   g_test_init (&argc, &argv, NULL);
 
-  session_bus_up ();
-
   g_test_add_func ("/appinfo/dbusappinfo", test_dbus_appinfo);
 
-  session_bus_down ();
-
-  return g_test_run ();
+  return session_bus_run ();
 }
diff --git a/gio/tests/gdbus-export.c b/gio/tests/gdbus-export.c
index a1a9bc4..270f3b7 100644
--- a/gio/tests/gdbus-export.c
+++ b/gio/tests/gdbus-export.c
@@ -1732,15 +1732,11 @@ int
 main (int   argc,
       char *argv[])
 {
-  gint ret;
-
   g_test_init (&argc, &argv, NULL);
 
   /* all the tests rely on a shared main loop */
   loop = g_main_loop_new (NULL, FALSE);
 
-  session_bus_up ();
-
   g_test_add_func ("/gdbus/object-registration", test_object_registration);
   g_test_add_func ("/gdbus/registered-interfaces", test_registered_interfaces);
   g_test_add_func ("/gdbus/async-properties", test_async_properties);
@@ -1748,10 +1744,5 @@ main (int   argc,
   /* TODO: check that we spit out correct introspection data */
   /* TODO: check that registering a whole subtree works */
 
-  ret = g_test_run();
-
-  /* tear down bus */
-  session_bus_down ();
-
-  return ret;
+  return session_bus_run ();
 }
diff --git a/gio/tests/gdbus-introspection.c b/gio/tests/gdbus-introspection.c
index 79daacb..627ea99 100644
--- a/gio/tests/gdbus-introspection.c
+++ b/gio/tests/gdbus-introspection.c
@@ -303,23 +303,15 @@ int
 main (int   argc,
       char *argv[])
 {
-  gint ret;
-
   g_test_init (&argc, &argv, NULL);
 
   /* all the tests rely on a shared main loop */
   loop = g_main_loop_new (NULL, FALSE);
 
-  session_bus_up ();
-
   g_test_add_func ("/gdbus/introspection-parser", test_introspection_parser);
   g_test_add_func ("/gdbus/introspection-generate", test_generate);
   g_test_add_func ("/gdbus/introspection-default-direction", test_default_direction);
   g_test_add_func ("/gdbus/introspection-extra-data", test_extra_data);
 
-  ret = g_test_run ();
-
-  session_bus_down ();
-
-  return ret;
+  return session_bus_run ();
 }
diff --git a/gio/tests/gdbus-proxy.c b/gio/tests/gdbus-proxy.c
index 2402f3d..e550b52 100644
--- a/gio/tests/gdbus-proxy.c
+++ b/gio/tests/gdbus-proxy.c
@@ -921,17 +921,14 @@ main (int   argc,
   /* all the tests rely on a shared main loop */
   loop = g_main_loop_new (NULL, FALSE);
 
-  session_bus_up ();
-
   g_test_add_func ("/gdbus/proxy", test_proxy);
   g_test_add_func ("/gdbus/proxy/no-properties", test_no_properties);
   g_test_add_func ("/gdbus/proxy/wellknown-noauto", test_wellknown_noauto);
   g_test_add_func ("/gdbus/proxy/async", test_async);
 
-  ret = g_test_run();
+  ret = session_bus_run();
 
   g_dbus_node_info_unref (introspection_data);
 
-  session_bus_down ();
   return ret;
 }
diff --git a/gio/tests/gdbus-sessionbus.c b/gio/tests/gdbus-sessionbus.c
index 68c4449..13c2edb 100644
--- a/gio/tests/gdbus-sessionbus.c
+++ b/gio/tests/gdbus-sessionbus.c
@@ -47,3 +47,14 @@ session_bus_down (void)
   g_clear_object (&singleton);
 }
 
+gint
+session_bus_run (void)
+{
+  gint ret;
+
+  session_bus_up ();
+  ret = g_test_run ();
+  session_bus_down ();
+
+  return ret;
+}
diff --git a/gio/tests/gdbus-sessionbus.h b/gio/tests/gdbus-sessionbus.h
index 7ef3abd..284cd00 100644
--- a/gio/tests/gdbus-sessionbus.h
+++ b/gio/tests/gdbus-sessionbus.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
 void session_bus_up   (void);
 void session_bus_stop (void);
 void session_bus_down (void);
+gint session_bus_run (void);
 
 G_END_DECLS
 
diff --git a/gio/tests/gdbus-test-codegen.c b/gio/tests/gdbus-test-codegen.c
index ae92431..d4d9c36 100644
--- a/gio/tests/gdbus-test-codegen.c
+++ b/gio/tests/gdbus-test-codegen.c
@@ -2352,21 +2352,12 @@ int
 main (int   argc,
       char *argv[])
 {
-  gint ret;
-
   g_test_init (&argc, &argv, NULL);
 
-  session_bus_up ();
-
   g_test_add_func ("/gdbus/codegen/annotations", test_annotations);
   g_test_add_func ("/gdbus/codegen/interface_stability", test_interface_stability);
   g_test_add_func ("/gdbus/codegen/object-manager", test_object_manager);
   g_test_add_func ("/gdbus/codegen/property-naming", test_property_naming);
 
-  ret = g_test_run();
-
-  /* tear down bus */
-  session_bus_down ();
-
-  return ret;
+  return session_bus_run ();
 }


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