From c9f5612c3aa681e8eb67f82dcb88df56af0db69b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 16 Apr 2012 16:52:50 +0100 Subject: [PATCH 04/14] tp_tests_connection_run_until_contact_by_id: add --- tests/lib/util.c | 38 ++++++++++++++++++++++++++++++++++++++ tests/lib/util.h | 6 ++++++ 2 files changed, 44 insertions(+) diff --git a/tests/lib/util.c b/tests/lib/util.c index f758b4f..5cb6d23 100644 --- a/tests/lib/util.c +++ b/tests/lib/util.c @@ -471,3 +471,41 @@ tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection) g_assert (ok); g_object_unref (result); } + +static void +one_contact_cb (TpConnection *connection, + guint n_contacts, + TpContact * const *contacts, + const gchar * const *good_ids, + GHashTable *bad_ids, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + TpContact **contact_loc = user_data; + + g_assert_no_error (error); + g_assert_cmpuint (g_hash_table_size (bad_ids), ==, 0); + g_assert_cmpuint (n_contacts, ==, 1); + g_assert_cmpstr (good_ids[0], !=, NULL); + g_assert (contacts[0] != NULL); + + *contact_loc = g_object_ref (contacts[0]); +} + +TpContact * +tp_tests_connection_run_until_contact_by_id (TpConnection *connection, + const gchar *id, + guint n_features, + const TpContactFeature *features) +{ + TpContact *contact = NULL; + + tp_connection_get_contacts_by_id (connection, 1, &id, n_features, features, + one_contact_cb, &contact, NULL, NULL); + + while (contact == NULL) + g_main_context_iteration (NULL, TRUE); + + return contact; +} diff --git a/tests/lib/util.h b/tests/lib/util.h index d0428ac..3fccc4c 100644 --- a/tests/lib/util.h +++ b/tests/lib/util.h @@ -73,4 +73,10 @@ void _tp_destroy_socket_control_list (gpointer data); void tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection); +TpContact *tp_tests_connection_run_until_contact_by_id ( + TpConnection *connection, + const gchar *id, + guint n_features, + const TpContactFeature *features); + #endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */ -- 1.7.10