summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2010-09-10 14:24:53 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2010-09-10 14:29:41 +0100
commita54835b7454dbc99014349bebaf32bf52410664c (patch)
treeddecb38e44eafabd28be14e6bb03a5b5a272bc7e
parent42110a1be5f6b6eb126f56a46cf8dddeb57e159a (diff)
downloadtelepathy-glib-a54835b7454dbc99014349bebaf32bf52410664c.tar.gz
tests: add tp_tests_run_until_result, tp_tests_result_ready_cb
-rw-r--r--tests/lib/util.c25
-rw-r--r--tests/lib/util.h4
2 files changed, 22 insertions, 7 deletions
diff --git a/tests/lib/util.c b/tests/lib/util.c
index 4b3fd4fd2..6b6d5d0bc 100644
--- a/tests/lib/util.c
+++ b/tests/lib/util.c
@@ -20,8 +20,10 @@ tp_tests_proxy_run_until_prepared (gpointer proxy,
g_assert_no_error (error);
}
-static void
-prepared_cb (GObject *object,
+/* A GAsyncReadyCallback whose user_data is a GAsyncResult **. It writes a
+ * reference to the result into that pointer. */
+void
+tp_tests_result_ready_cb (GObject *object,
GAsyncResult *res,
gpointer user_data)
{
@@ -30,6 +32,18 @@ prepared_cb (GObject *object,
*result = g_object_ref (res);
}
+/* Run until *result contains a result. Intended to be used with a pending
+ * async call that uses tp_tests_result_ready_cb. */
+void
+tp_tests_run_until_result (GAsyncResult **result)
+{
+ /* not synchronous */
+ g_assert (*result == NULL);
+
+ while (*result == NULL)
+ g_main_context_iteration (NULL, TRUE);
+}
+
gboolean
tp_tests_proxy_run_until_prepared_or_failed (gpointer proxy,
const GQuark *features,
@@ -38,12 +52,9 @@ tp_tests_proxy_run_until_prepared_or_failed (gpointer proxy,
GAsyncResult *result = NULL;
gboolean r;
- tp_proxy_prepare_async (proxy, features, prepared_cb, &result);
- /* not synchronous */
- g_assert (result == NULL);
+ tp_proxy_prepare_async (proxy, features, tp_tests_result_ready_cb, &result);
- while (result == NULL)
- g_main_context_iteration (NULL, TRUE);
+ tp_tests_run_until_result (&result);
r = tp_proxy_prepare_finish (proxy, result, error);
g_object_unref (result);
diff --git a/tests/lib/util.h b/tests/lib/util.h
index d3433ccf9..bc150d6af 100644
--- a/tests/lib/util.h
+++ b/tests/lib/util.h
@@ -48,4 +48,8 @@ void tp_tests_create_and_connect_conn (GType conn_type,
gpointer tp_tests_object_new_static_class (GType type,
...) G_GNUC_NULL_TERMINATED;
+void tp_tests_run_until_result (GAsyncResult **result);
+void tp_tests_result_ready_cb (GObject *object,
+ GAsyncResult *res, gpointer user_data);
+
#endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */