Fix old wiki links
[platform/upstream/glib.git] / gio / tests / gdbus-connection.c
index d9447a3..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>
  */
 #include <string.h>
 
 #include <sys/types.h>
-#include <sys/wait.h>
 
 #include "gdbus-tests.h"
 
 /* all tests rely on a shared mainloop */
 static GMainLoop *loop = NULL;
 
+#if 0
+G_GNUC_UNUSED static void
+_log (const gchar *format, ...)
+{
+  GTimeVal now;
+  time_t now_time;
+  struct tm *now_tm;
+  gchar time_buf[128];
+  gchar *str;
+  va_list var_args;
+
+  va_start (var_args, format);
+  str = g_strdup_vprintf (format, var_args);
+  va_end (var_args);
+
+  g_get_current_time (&now);
+  now_time = (time_t) now.tv_sec;
+  now_tm = localtime (&now_time);
+  strftime (time_buf, sizeof time_buf, "%H:%M:%S", now_tm);
+
+  g_print ("%s.%06d: %s\n",
+           time_buf, (gint) now.tv_usec / 1000,
+           str);
+  g_free (str);
+}
+#else
+#define _log(...)
+#endif
+
 static gboolean
 test_connection_quit_mainloop (gpointer user_data)
 {
-  gboolean *quit_mainloop_fired = user_data;
+  volatile gboolean *quit_mainloop_fired = user_data;
+  _log ("quit_mainloop_fired");
   *quit_mainloop_fired = TRUE;
   g_main_loop_quit (loop);
   return TRUE;
@@ -85,37 +112,44 @@ on_name_owner_changed (GDBusConnection *connection,
 static void
 a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop (gpointer user_data)
 {
-  gboolean *val = user_data;
+  volatile gboolean *val = user_data;
   *val = TRUE;
-
+  _log ("destroynotify fired for %p", val);
   g_main_loop_quit (loop);
 }
 
 static void
-test_connection_life_cycle (void)
+test_connection_bus_failure (void)
 {
-  gboolean ret;
   GDBusConnection *c;
-  GDBusConnection *c2;
-  GError *error;
-  gboolean on_signal_registration_freed_called;
-  gboolean on_filter_freed_called;
-  gboolean on_register_object_freed_called;
-  gboolean quit_mainloop_fired;
-  guint quit_mainloop_id;
-  guint registration_id;
-
-  error = NULL;
+  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_domain (error, G_IO_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;
+  GDBusConnection *c;
+  GDBusConnection *c2;
+  GError *error;
+  volatile gboolean on_signal_registration_freed_called;
+  volatile gboolean on_filter_freed_called;
+  volatile gboolean on_register_object_freed_called;
+  volatile gboolean quit_mainloop_fired;
+  guint quit_mainloop_id;
+  guint registration_id;
+
+  error = NULL;
 
   /*
    *  Check for correct behavior when a bus is present
@@ -182,13 +216,13 @@ test_connection_life_cycle (void)
                                       NULL,                   /* arg0 */
                                       G_DBUS_SIGNAL_FLAGS_NONE,
                                       on_name_owner_changed,
-                                      &on_signal_registration_freed_called,
+                                      (gpointer) &on_signal_registration_freed_called,
                                       a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop);
   /* filter func */
   on_filter_freed_called = FALSE;
   g_dbus_connection_add_filter (c2,
                                 some_filter_func,
-                                &on_filter_freed_called,
+                                (gpointer) &on_filter_freed_called,
                                 a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop);
   /* object registration */
   on_register_object_freed_called = FALSE;
@@ -197,7 +231,7 @@ test_connection_life_cycle (void)
                                                        "/foo",
                                                        (GDBusInterfaceInfo *) &boo_interface_info,
                                                        &boo_vtable,
-                                                       &on_register_object_freed_called,
+                                                       (gpointer) &on_register_object_freed_called,
                                                        a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop,
                                                        &error);
   g_assert_no_error (error);
@@ -205,7 +239,14 @@ test_connection_life_cycle (void)
   /* ok, finalize the connection and check that all the GDestroyNotify functions are invoked as expected */
   g_object_unref (c2);
   quit_mainloop_fired = FALSE;
-  quit_mainloop_id = g_timeout_add (1000, test_connection_quit_mainloop, &quit_mainloop_fired);
+  quit_mainloop_id = g_timeout_add (30000, test_connection_quit_mainloop, (gpointer) &quit_mainloop_fired);
+  _log ("destroynotifies for\n"
+        " register_object %p\n"
+        " filter          %p\n"
+        " signal          %p",
+        &on_register_object_freed_called,
+        &on_filter_freed_called,
+        &on_signal_registration_freed_called);
   while (TRUE)
     {
       if (on_signal_registration_freed_called &&
@@ -214,7 +255,9 @@ test_connection_life_cycle (void)
         break;
       if (quit_mainloop_fired)
         break;
+      _log ("entering loop");
       g_main_loop_run (loop);
+      _log ("exiting loop");
     }
   g_source_remove (quit_mainloop_id);
   g_assert (on_signal_registration_freed_called);
@@ -228,13 +271,12 @@ test_connection_life_cycle (void)
    */
   g_assert (!g_dbus_connection_is_closed (c));
   g_dbus_connection_set_exit_on_close (c, FALSE);
-  session_bus_down ();
-  if (!g_dbus_connection_is_closed (c))
-    _g_assert_signal_received (c, "closed");
+  session_bus_stop ();
+  _g_assert_signal_received (c, "closed");
   g_assert (g_dbus_connection_is_closed (c));
-
-  _g_object_wait_for_single_ref (c);
   g_object_unref (c);
+
+  session_bus_down ();
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -431,7 +473,7 @@ test_connection_send (void)
    * Check that we get an error when sending to a connection that is disconnected.
    */
   g_dbus_connection_set_exit_on_close (c, FALSE);
-  session_bus_down ();
+  session_bus_stop ();
   _g_assert_signal_received (c, "closed");
   g_assert (g_dbus_connection_is_closed (c));
 
@@ -448,8 +490,9 @@ test_connection_send (void)
                           NULL);
   g_main_loop_run (loop);
 
-  _g_object_wait_for_single_ref (c);
   g_object_unref (c);
+
+  session_bus_down ();
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -494,6 +537,8 @@ test_connection_signals (void)
   GError *error;
   gboolean ret;
   GVariant *result;
+  gboolean quit_mainloop_fired;
+  guint quit_mainloop_id;
 
   error = NULL;
 
@@ -579,18 +624,6 @@ test_connection_signals (void)
   count_name_owner_changed = 0;
 
   /*
-   * Bring up two other connections
-   */
-  c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
-  g_assert (c2 != NULL);
-  g_assert (!g_dbus_connection_is_closed (c2));
-  g_assert_cmpstr (g_dbus_connection_get_unique_name (c2), ==, ":1.2");
-  c3 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
-  g_assert (c3 != NULL);
-  g_assert (!g_dbus_connection_is_closed (c3));
-  g_assert_cmpstr (g_dbus_connection_get_unique_name (c3), ==, ":1.3");
-
-  /*
    * Make c2 emit "Foo" - we should catch it twice
    *
    * Note that there is no way to be sure that the signal subscriptions
@@ -615,6 +648,19 @@ test_connection_signals (void)
   g_assert_no_error (error);
   g_assert (result != NULL);
   g_variant_unref (result);
+
+  /*
+   * Bring up two other connections
+   */
+  c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
+  g_assert (c2 != NULL);
+  g_assert (!g_dbus_connection_is_closed (c2));
+  g_assert_cmpstr (g_dbus_connection_get_unique_name (c2), ==, ":1.2");
+  c3 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
+  g_assert (c3 != NULL);
+  g_assert (!g_dbus_connection_is_closed (c3));
+  g_assert_cmpstr (g_dbus_connection_get_unique_name (c3), ==, ":1.3");
+
   /* now, emit the signal on c2 */
   ret = g_dbus_connection_emit_signal (c2,
                                        NULL, /* destination bus name */
@@ -651,10 +697,8 @@ test_connection_signals (void)
    * Also to check the total amount of NameOwnerChanged signals - use a 5 second ceiling
    * to avoid spinning forever
    */
-  gboolean quit_mainloop_fired;
-  guint quit_mainloop_id;
   quit_mainloop_fired = FALSE;
-  quit_mainloop_id = g_timeout_add (5000, test_connection_quit_mainloop, &quit_mainloop_fired);
+  quit_mainloop_id = g_timeout_add (30000, test_connection_quit_mainloop, &quit_mainloop_fired);
   while (count_name_owner_changed < 2 && !quit_mainloop_fired)
     g_main_loop_run (loop);
   g_source_remove (quit_mainloop_id);
@@ -667,10 +711,6 @@ test_connection_signals (void)
   g_dbus_connection_signal_unsubscribe (c1, s3);
   g_dbus_connection_signal_unsubscribe (c1, s1b);
 
-  _g_object_wait_for_single_ref (c1);
-  _g_object_wait_for_single_ref (c2);
-  _g_object_wait_for_single_ref (c3);
-
   g_object_unref (c1);
   g_object_unref (c2);
   g_object_unref (c3);
@@ -678,6 +718,83 @@ test_connection_signals (void)
   session_bus_down ();
 }
 
+static void
+test_match_rule (GDBusConnection  *connection,
+                 GDBusSignalFlags  flags,
+                 gchar            *arg0_rule,
+                 gchar            *arg0,
+                 gboolean          should_match)
+{
+  guint subscription_ids[2];
+  gint emissions = 0;
+  gint matches = 0;
+  GError *error = NULL;
+
+  subscription_ids[0] = g_dbus_connection_signal_subscribe (connection,
+                                                            NULL, "org.gtk.ExampleInterface", "Foo", "/",
+                                                            NULL,
+                                                            G_DBUS_SIGNAL_FLAGS_NONE,
+                                                            test_connection_signal_handler,
+                                                            &emissions, NULL);
+  subscription_ids[1] = g_dbus_connection_signal_subscribe (connection,
+                                                            NULL, "org.gtk.ExampleInterface", "Foo", "/",
+                                                            arg0_rule,
+                                                            flags,
+                                                            test_connection_signal_handler,
+                                                            &matches, NULL);
+  g_assert_cmpint (subscription_ids[0], !=, 0);
+  g_assert_cmpint (subscription_ids[1], !=, 0);
+
+  g_dbus_connection_emit_signal (connection,
+                                 NULL, "/", "org.gtk.ExampleInterface",
+                                 "Foo", g_variant_new ("(s)", arg0),
+                                 &error);
+  g_assert_no_error (error);
+
+  /* synchronously ping a non-existent method to make sure the signals are dispatched */
+  g_dbus_connection_call_sync (connection, "org.gtk.ExampleInterface", "/", "org.gtk.ExampleInterface",
+                               "Bar", g_variant_new ("()"), G_VARIANT_TYPE_UNIT, G_DBUS_CALL_FLAGS_NONE,
+                               -1, NULL, NULL);
+
+  while (g_main_context_iteration (NULL, FALSE))
+    ;
+
+  g_assert_cmpint (emissions, ==, 1);
+  g_assert_cmpint (matches, ==, should_match ? 1 : 0);
+
+  g_dbus_connection_signal_unsubscribe (connection, subscription_ids[0]);
+  g_dbus_connection_signal_unsubscribe (connection, subscription_ids[1]);
+}
+
+static void
+test_connection_signal_match_rules (void)
+{
+  GDBusConnection *con;
+
+  session_bus_up ();
+  con = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_NONE, "foo", "foo", TRUE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_NONE, "foo", "bar", FALSE);
+
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE, "org.gtk", "", FALSE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE, "org.gtk", "org", FALSE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE, "org.gtk", "org.gtk", TRUE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE, "org.gtk", "org.gtk.Example", TRUE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE, "org.gtk", "org.gtk+", FALSE);
+
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_PATH, "/", "/", TRUE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_PATH, "/", "", FALSE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_PATH, "/org/gtk/Example", "/org/gtk/Example", TRUE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_PATH, "/org/gtk/", "/org/gtk/Example", TRUE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_PATH, "/org/gtk/Example", "/org/gtk/", TRUE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_PATH, "/org/gtk/Example", "/org/gtk", FALSE);
+  test_match_rule (con, G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_PATH, "/org/gtk+", "/org/gtk", FALSE);
+
+  g_object_unref (con);
+  session_bus_down ();
+}
+
 /* ---------------------------------------------------------------------------------------------------- */
 
 typedef struct
@@ -787,7 +904,7 @@ test_connection_filter_name_owner_changed_signal_handler (GDBusConnection  *conn
 static gboolean
 test_connection_filter_on_timeout (gpointer user_data)
 {
-  g_printerr ("Timeout waiting 1000 msec on service\n");
+  g_printerr ("Timeout waiting 30 sec on service\n");
   g_assert_not_reached ();
   return FALSE;
 }
@@ -845,6 +962,18 @@ test_connection_filter (void)
 
   m2 = g_dbus_message_copy (m, &error);
   g_assert_no_error (error);
+  g_dbus_message_set_serial (m2, data.serial);
+  /* lock the message to test PRESERVE_SERIAL flag. */
+  g_dbus_message_lock (m2);
+  g_dbus_connection_send_message (c, m2, G_DBUS_SEND_MESSAGE_FLAGS_PRESERVE_SERIAL, &data.serial, &error);
+  g_object_unref (m2);
+  g_assert_no_error (error);
+
+  while (data.num_handled == 2)
+    g_thread_yield ();
+
+  m2 = g_dbus_message_copy (m, &error);
+  g_assert_no_error (error);
   r = g_dbus_connection_send_message_with_reply_sync (c,
                                                       m2,
                                                       G_DBUS_SEND_MESSAGE_FLAGS_NONE,
@@ -856,7 +985,7 @@ test_connection_filter (void)
   g_assert_no_error (error);
   g_assert (r != NULL);
   g_object_unref (r);
-  g_assert_cmpint (data.num_handled, ==, 3);
+  g_assert_cmpint (data.num_handled, ==, 4);
 
   g_dbus_connection_remove_filter (c, filter_id);
 
@@ -873,11 +1002,9 @@ test_connection_filter (void)
   g_assert_no_error (error);
   g_assert (r != NULL);
   g_object_unref (r);
-  g_assert_cmpint (data.num_handled, ==, 3);
-  g_assert_cmpint (data.num_outgoing, ==, 3);
+  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 */
-  g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
   /* wait for service to be available */
   signal_handler_id = g_dbus_connection_signal_subscribe (c,
                                                           "org.freedesktop.DBus", /* sender */
@@ -890,7 +1017,11 @@ test_connection_filter (void)
                                                           NULL,
                                                           NULL);
   g_assert_cmpint (signal_handler_id, !=, 0);
-  timeout_mainloop_id = g_timeout_add (1000, test_connection_filter_on_timeout, NULL);
+
+  /* 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);
   g_dbus_connection_signal_unsubscribe (c, signal_handler_id);
@@ -942,7 +1073,6 @@ test_connection_filter (void)
 
   g_dbus_connection_remove_filter (c, filter_id);
 
-  _g_object_wait_for_single_ref (c);
   g_object_unref (c);
   g_object_unref (m);
 
@@ -951,83 +1081,91 @@ test_connection_filter (void)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+#define NUM_THREADS 50
+
 static void
-test_connection_flush_signal_handler (GDBusConnection  *connection,
-                                      const gchar      *sender_name,
-                                      const gchar      *object_path,
-                                      const gchar      *interface_name,
-                                      const gchar      *signal_name,
-                                      GVariant         *parameters,
-                                      gpointer         user_data)
+send_bogus_message (GDBusConnection *c, guint32 *out_serial)
 {
-  g_main_loop_quit (loop);
+  GDBusMessage *m;
+  GError *error;
+
+  m = g_dbus_message_new_method_call ("org.freedesktop.DBus", /* name */
+                                      "/org/freedesktop/DBus", /* path */
+                                      "org.freedesktop.DBus", /* interface */
+                                      "GetNameOwner");
+  g_dbus_message_set_body (m, g_variant_new ("(s)", "org.freedesktop.DBus"));
+  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 gboolean
-test_connection_flush_on_timeout (gpointer user_data)
+static gpointer
+serials_thread_func (GDBusConnection *c)
 {
-  guint iteration = GPOINTER_TO_UINT (user_data);
-  g_printerr ("Timeout waiting 1000 msec on iteration %d\n", iteration);
-  g_assert_not_reached ();
-  return FALSE;
+  guint32 message_serial;
+
+  /* No calls on this thread yet */
+  g_assert_cmpint (g_dbus_connection_get_last_serial(c), ==, 0);
+
+  /* Send a bogus message and store its serial */
+  message_serial = 0;
+  send_bogus_message (c, &message_serial);
+
+  /* Give it some time to actually send the message out */
+  g_usleep (250000);
+
+  g_assert_cmpint (g_dbus_connection_get_last_serial(c), !=, 0);
+  g_assert_cmpint (g_dbus_connection_get_last_serial(c), ==, message_serial);
+
+  return NULL;
 }
 
 static void
-test_connection_flush (void)
+test_connection_serials (void)
 {
-  GDBusConnection *connection;
+  GDBusConnection *c;
   GError *error;
-  guint n;
-  guint signal_handler_id;
+  GThread *pool[NUM_THREADS];
+  int i;
 
   session_bus_up ();
 
   error = NULL;
-  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+  c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
   g_assert_no_error (error);
-  g_assert (connection != NULL);
+  g_assert (c != NULL);
 
-  signal_handler_id = g_dbus_connection_signal_subscribe (connection,
-                                                          NULL, /* sender */
-                                                          "org.gtk.GDBus.FlushInterface",
-                                                          "SomeSignal",
-                                                          "/org/gtk/GDBus/FlushObject",
-                                                          NULL,
-                                                          G_DBUS_SIGNAL_FLAGS_NONE,
-                                                          test_connection_flush_signal_handler,
-                                                          NULL,
-                                                          NULL);
-  g_assert_cmpint (signal_handler_id, !=, 0);
+  /* Status after initialization */
+  g_assert_cmpint (g_dbus_connection_get_last_serial (c), ==, 1);
 
-  for (n = 0; n < 50; n++)
-    {
-      gboolean ret;
-      gint exit_status;
-      guint timeout_mainloop_id;
-
-      error = NULL;
-      ret = g_spawn_command_line_sync ("./gdbus-connection-flush-helper",
-                                       NULL, /* stdout */
-                                       NULL, /* stderr */
-                                       &exit_status,
-                                       &error);
-      g_assert_no_error (error);
-      g_assert (WIFEXITED (exit_status));
-      g_assert_cmpint (WEXITSTATUS (exit_status), ==, 0);
-      g_assert (ret);
+  /* Send a bogus message */
+  send_bogus_message (c, NULL);
+  g_assert_cmpint (g_dbus_connection_get_last_serial (c), ==, 2);
 
-      timeout_mainloop_id = g_timeout_add (1000, test_connection_flush_on_timeout, GUINT_TO_POINTER (n));
-      g_main_loop_run (loop);
-      g_source_remove (timeout_mainloop_id);
-    }
+  /* Start the threads */
+  for (i = 0; i < NUM_THREADS; i++)
+    pool[i] = g_thread_new (NULL, (GThreadFunc) serials_thread_func, c);
 
-  g_dbus_connection_signal_unsubscribe (connection, signal_handler_id);
-  _g_object_wait_for_single_ref (connection);
-  g_object_unref (connection);
+  /* Wait until threads are finished */
+  for (i = 0; i < NUM_THREADS; i++)
+      g_thread_join (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);
+
+  send_bogus_message (c, NULL);
+
+  /* All above calls + calls in threads */
+  g_assert_cmpint (g_dbus_connection_get_last_serial (c), ==, 3 + NUM_THREADS);
+
+  g_object_unref (c);
 
   session_bus_down ();
 }
 
+/* ---------------------------------------------------------------------------------------------------- */
+
 static void
 test_connection_basic (void)
 {
@@ -1075,7 +1213,6 @@ test_connection_basic (void)
   g_free (name);
   g_free (guid);
 
-  _g_object_wait_for_single_ref (connection);
   g_object_unref (connection);
 
   session_bus_down ();
@@ -1083,107 +1220,30 @@ test_connection_basic (void)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-/* Message size > 20MiB ... should be enough to make sure the message
- * is fragmented when shoved across any transport
- */
-#define LARGE_MESSAGE_STRING_LENGTH (20*1024*1024)
-
-static void
-large_message_on_name_appeared (GDBusConnection *connection,
-                                const gchar *name,
-                                const gchar *name_owner,
-                                gpointer user_data)
-{
-  GError *error;
-  gchar *request;
-  const gchar *reply;
-  GVariant *result;
-  guint n;
-
-  request = g_new (gchar, LARGE_MESSAGE_STRING_LENGTH + 1);
-  for (n = 0; n < LARGE_MESSAGE_STRING_LENGTH; n++)
-    request[n] = '0' + (n%10);
-  request[n] = '\0';
-
-  error = NULL;
-  result = g_dbus_connection_call_sync (connection,
-                                        "com.example.TestService",      /* bus name */
-                                        "/com/example/TestObject",      /* object path */
-                                        "com.example.Frob",             /* interface name */
-                                        "HelloWorld",                   /* method name */
-                                        g_variant_new ("(s)", request), /* parameters */
-                                        G_VARIANT_TYPE ("(s)"),         /* return type */
-                                        G_DBUS_CALL_FLAGS_NONE,
-                                        -1,
-                                        NULL,
-                                        &error);
-  g_assert_no_error (error);
-  g_assert (result != NULL);
-  g_variant_get (result, "(&s)", &reply);
-  g_assert_cmpint (strlen (reply), >, LARGE_MESSAGE_STRING_LENGTH);
-  g_assert (g_str_has_prefix (reply, "You greeted me with '01234567890123456789012"));
-  g_assert (g_str_has_suffix (reply, "6789'. Thanks!"));
-  g_variant_unref (result);
-
-  g_free (request);
-
-  g_main_loop_quit (loop);
-}
-
-static void
-large_message_on_name_vanished (GDBusConnection *connection,
-                                const gchar *name,
-                                gpointer user_data)
-{
-}
-
-static void
-test_connection_large_message (void)
-{
-  guint watcher_id;
-
-  session_bus_up ();
-
-  /* this is safe; testserver will exit once the bus goes away */
-  g_assert (g_spawn_command_line_async (SRCDIR "/gdbus-testserver.py", NULL));
-
-  watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
-                                 "com.example.TestService",
-                                 G_BUS_NAME_WATCHER_FLAGS_NONE,
-                                 large_message_on_name_appeared,
-                                 large_message_on_name_vanished,
-                                 NULL,  /* user_data */
-                                 NULL); /* GDestroyNotify */
-  g_main_loop_run (loop);
-  g_bus_unwatch_name (watcher_id);
-
-  session_bus_down ();
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
 int
 main (int   argc,
       char *argv[])
 {
-  g_type_init ();
+  int ret;
   g_test_init (&argc, &argv, NULL);
 
   /* all the tests rely on a shared main loop */
   loop = g_main_loop_new (NULL, FALSE);
 
-  /* all the tests use a session bus with a well-known address that we can bring up and down
-   * using session_bus_up() and session_bus_down().
-   */
-  g_unsetenv ("DISPLAY");
-  g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
+  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);
   g_test_add_func ("/gdbus/connection/signals", test_connection_signals);
+  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/flush", test_connection_flush);
-  g_test_add_func ("/gdbus/connection/large_message", test_connection_large_message);
-  return g_test_run();
+  g_test_add_func ("/gdbus/connection/serials", test_connection_serials);
+  ret = g_test_run();
+
+  g_main_loop_unref (loop);
+  return ret;
 }