Fix old wiki links
[platform/upstream/glib.git] / gio / tests / gdbus-connection.c
index 43c6d28..8d0b0df 100644 (file)
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: David Zeuthen <davidz@redhat.com>
  */
@@ -28,9 +26,6 @@
 
 #include "gdbus-tests.h"
 
-const gchar *srcdir;
-const gchar *builddir;
-
 /* all tests rely on a shared mainloop */
 static GMainLoop *loop = NULL;
 
@@ -124,6 +119,23 @@ a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop (gpointer user_data
 }
 
 static void
+test_connection_bus_failure (void)
+{
+  GDBusConnection *c;
+  GError *error = NULL;
+
+  /*
+   * Check for correct behavior when no bus is present
+   *
+   */
+  c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+  g_assert (error != NULL);
+  g_assert (!g_dbus_error_is_remote_error (error));
+  g_assert (c == NULL);
+  g_error_free (error);
+}
+
+static void
 test_connection_life_cycle (void)
 {
   gboolean ret;
@@ -140,16 +152,6 @@ test_connection_life_cycle (void)
   error = NULL;
 
   /*
-   * Check for correct behavior when no bus is present
-   *
-   */
-  c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
-  g_assert (error != NULL);
-  g_assert (!g_dbus_error_is_remote_error (error));
-  g_assert (c == NULL);
-  g_error_free (error);
-
-  /*
    *  Check for correct behavior when a bus is present
    */
   session_bus_up ();
@@ -922,7 +924,6 @@ test_connection_filter (void)
   FilterEffects effects;
   GVariant *result;
   const gchar *s;
-  gchar *path;
 
   memset (&data, '\0', sizeof (FilterData));
 
@@ -1004,11 +1005,6 @@ test_connection_filter (void)
   g_assert_cmpint (data.num_handled, ==, 4);
   g_assert_cmpint (data.num_outgoing, ==, 4);
 
-  /* this is safe; testserver will exit once the bus goes away */
-  path = g_build_filename (builddir, "gdbus-testserver", NULL);
-  g_assert (g_spawn_command_line_async (path, NULL));
-  g_free (path);
-
   /* wait for service to be available */
   signal_handler_id = g_dbus_connection_signal_subscribe (c,
                                                           "org.freedesktop.DBus", /* sender */
@@ -1021,6 +1017,10 @@ test_connection_filter (void)
                                                           NULL,
                                                           NULL);
   g_assert_cmpint (signal_handler_id, !=, 0);
+
+  /* this is safe; testserver will exit once the bus goes away */
+  g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
+
   timeout_mainloop_id = g_timeout_add (30000, test_connection_filter_on_timeout, NULL);
   g_main_loop_run (loop);
   g_source_remove (timeout_mainloop_id);
@@ -1097,6 +1097,7 @@ send_bogus_message (GDBusConnection *c, guint32 *out_serial)
   error = NULL;
   g_dbus_connection_send_message (c, m, G_DBUS_SEND_MESSAGE_FLAGS_NONE, out_serial, &error);
   g_assert_no_error (error);
+  g_object_unref (m);
 }
 
 static gpointer
@@ -1148,10 +1149,7 @@ test_connection_serials (void)
 
   /* Wait until threads are finished */
   for (i = 0; i < NUM_THREADS; i++)
-    {
       g_thread_join (pool[i]);
-      g_thread_unref (pool[i]);
-    }
 
   /* No calls in between on this thread, should be the last value */
   g_assert_cmpint (g_dbus_connection_get_last_serial (c), ==, 2);
@@ -1226,21 +1224,17 @@ int
 main (int   argc,
       char *argv[])
 {
+  int ret;
   g_test_init (&argc, &argv, NULL);
 
-  if (g_getenv ("G_TEST_DATA"))
-    srcdir = builddir = g_getenv ("G_TEST_DATA");
-  else
-    {
-      srcdir = SRCDIR;
-      builddir = ".";
-    }
-
   /* all the tests rely on a shared main loop */
   loop = g_main_loop_new (NULL, FALSE);
 
   g_test_dbus_unset ();
 
+  /* gdbus cleanup is pretty racy due to worker threads, so always do this test first */
+  g_test_add_func ("/gdbus/connection/bus-failure", test_connection_bus_failure);
+
   g_test_add_func ("/gdbus/connection/basic", test_connection_basic);
   g_test_add_func ("/gdbus/connection/life-cycle", test_connection_life_cycle);
   g_test_add_func ("/gdbus/connection/send", test_connection_send);
@@ -1248,5 +1242,8 @@ main (int   argc,
   g_test_add_func ("/gdbus/connection/signal-match-rules", test_connection_signal_match_rules);
   g_test_add_func ("/gdbus/connection/filter", test_connection_filter);
   g_test_add_func ("/gdbus/connection/serials", test_connection_serials);
-  return g_test_run();
+  ret = g_test_run();
+
+  g_main_loop_unref (loop);
+  return ret;
 }