[Telepathy-commits] [telepathy-glib/master] tests/lib: add a simple function to spin a main loop until queued D-Bus messages have been dealt with

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Oct 8 10:26:51 PDT 2008


---
 tests/dbus/connection-handles.c |   26 ++++----------------------
 tests/lib/Makefile.am           |    4 +++-
 tests/lib/util.c                |   17 +++++++++++++++++
 tests/lib/util.h                |   18 ++++++++++++++++++
 4 files changed, 42 insertions(+), 23 deletions(-)
 create mode 100644 tests/lib/util.c
 create mode 100644 tests/lib/util.h

diff --git a/tests/dbus/connection-handles.c b/tests/dbus/connection-handles.c
index 37a8fa9..9450f5d 100644
--- a/tests/dbus/connection-handles.c
+++ b/tests/dbus/connection-handles.c
@@ -15,6 +15,7 @@
 #include "tests/lib/debug.h"
 #include "tests/lib/myassert.h"
 #include "tests/lib/simple-conn.h"
+#include "tests/lib/util.h"
 
 static int fail = 0;
 
@@ -99,13 +100,6 @@ finish (gpointer r)
   g_main_loop_quit (result->loop);
 }
 
-static gboolean
-quit_when_idle (gpointer p)
-{
-  g_main_loop_quit (p);
-  return FALSE;
-}
-
 /*
  * Assert that RequestHandles + unref releases the handles.
  */
@@ -160,11 +154,7 @@ test_request_and_release (SimpleConnection *service_conn,
 
   tp_connection_unref_handles (client_conn, TP_HANDLE_TYPE_CONTACT,
       result.handles->len, (const TpHandle *) result.handles->data);
-
-  /* synchronize state of D-Bus connection */
-  g_idle_add_full (G_PRIORITY_LOW, quit_when_idle, result.loop, NULL);
-  g_main_loop_run (result.loop);
-  tp_cli_connection_run_get_protocol (client_conn, -1, NULL, NULL, NULL);
+  test_connection_run_until_dbus_queue_processed (client_conn);
 
   /* check that the handles have been released */
 
@@ -268,11 +258,7 @@ test_request_hold_release (SimpleConnection *service_conn,
 
   tp_connection_unref_handles (client_conn, TP_HANDLE_TYPE_CONTACT,
       result.handles->len, (const TpHandle *) result.handles->data);
-
-  /* synchronize state of D-Bus connection */
-  g_idle_add_full (G_PRIORITY_LOW, quit_when_idle, result.loop, NULL);
-  g_main_loop_run (result.loop);
-  tp_cli_connection_run_get_protocol (client_conn, -1, NULL, NULL, NULL);
+  test_connection_run_until_dbus_queue_processed (client_conn);
 
   /* check that the handles have not been released */
 
@@ -291,11 +277,7 @@ test_request_hold_release (SimpleConnection *service_conn,
 
   tp_connection_unref_handles (client_conn, TP_HANDLE_TYPE_CONTACT,
       result.handles->len, (const TpHandle *) result.handles->data);
-
-  /* synchronize state of D-Bus connection */
-  g_idle_add_full (G_PRIORITY_LOW, quit_when_idle, result.loop, NULL);
-  g_main_loop_run (result.loop);
-  tp_cli_connection_run_get_protocol (client_conn, -1, NULL, NULL, NULL);
+  test_connection_run_until_dbus_queue_processed (client_conn);
 
   /* check that the handles have been released */
 
diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am
index 7762c15..043ab66 100644
--- a/tests/lib/Makefile.am
+++ b/tests/lib/Makefile.am
@@ -12,7 +12,9 @@ libtp_glib_tests_la_SOURCES = \
     stub-object.c \
     stub-object.h \
     textchan-null.c \
-    textchan-null.h
+    textchan-null.h \
+    util.c \
+    util.h
 
 check_c_sources = *.c
 include $(top_srcdir)/tools/check-coding-style.mk
diff --git a/tests/lib/util.c b/tests/lib/util.c
new file mode 100644
index 0000000..162293d
--- /dev/null
+++ b/tests/lib/util.c
@@ -0,0 +1,17 @@
+/* Simple utility code used by the regression tests.
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#include "tests/lib/util.h"
+
+void
+test_connection_run_until_dbus_queue_processed (TpConnection *connection)
+{
+  tp_cli_connection_run_get_protocol (connection, -1, NULL, NULL, NULL);
+}
diff --git a/tests/lib/util.h b/tests/lib/util.h
new file mode 100644
index 0000000..a6be5d1
--- /dev/null
+++ b/tests/lib/util.h
@@ -0,0 +1,18 @@
+/* Simple utility code used by the regression tests.
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#ifndef TEST_LIB_UTIL_H
+#define TEST_LIB_UTIL_H
+
+#include <telepathy-glib/connection.h>
+
+void test_connection_run_until_dbus_queue_processed (TpConnection *connection);
+
+#endif
-- 
1.5.6.5




More information about the Telepathy-commits mailing list