From c217c8e6c43e35f4729c7a7aa5e7a6c31fbf5f75 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 1 Feb 2012 20:26:41 +0000 Subject: account test: deliberately keep async results after the callback This is valid usage, and often (as in this case!) uncovers bugs. It also makes the flow of the code more obvious. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=45554 Signed-off-by: Simon McVittie Reviewed-by: Jonny Lamb --- tests/dbus/account.c | 70 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/tests/dbus/account.c b/tests/dbus/account.c index ccad46a8e..79cbc4ffe 100644 --- a/tests/dbus/account.c +++ b/tests/dbus/account.c @@ -416,34 +416,14 @@ test_prepare_success (Test *test, "bob.mcbadgers@example.com"); } -static void -get_storage_specific_info_cb (GObject *account, - GAsyncResult *result, - gpointer user_data) -{ - Test *test = user_data; - GHashTable *info; - GError *error = NULL; - - info = tp_account_get_storage_specific_information_finish ( - TP_ACCOUNT (account), result, &error); - g_assert_no_error (error); - - g_assert_cmpuint (g_hash_table_size (info), ==, 3); - - g_assert_cmpint (tp_asv_get_int32 (info, "one", NULL), ==, 1); - g_assert_cmpuint (tp_asv_get_uint32 (info, "two", NULL), ==, 2); - g_assert_cmpstr (tp_asv_get_string (info, "marco"), ==, "polo"); - - g_main_loop_quit (test->mainloop); -} - static void test_storage (Test *test, gconstpointer mode) { GQuark account_features[] = { TP_ACCOUNT_FEATURE_STORAGE, 0 }; GValue *gvalue; + GHashTable *info; + GError *error = NULL; test->account = tp_account_new (test->dbus, ACCOUNT_PATH, NULL); g_assert (test->account != NULL); @@ -494,8 +474,20 @@ test_storage (Test *test, /* request the StorageSpecificProperties hash */ tp_account_get_storage_specific_information_async (test->account, - get_storage_specific_info_cb, test); - g_main_loop_run (test->mainloop); + tp_tests_result_ready_cb, &test->result); + tp_tests_run_until_result (&test->result); + + info = tp_account_get_storage_specific_information_finish ( + test->account, test->result, &error); + g_assert_no_error (error); + + g_assert_cmpuint (g_hash_table_size (info), ==, 3); + + g_assert_cmpint (tp_asv_get_int32 (info, "one", NULL), ==, 1); + g_assert_cmpuint (tp_asv_get_uint32 (info, "two", NULL), ==, 2); + g_assert_cmpstr (tp_asv_get_string (info, "marco"), ==, "polo"); + + tp_clear_object (&test->result); } static void @@ -544,6 +536,33 @@ test_addressing (Test *test, } +static void +test_avatar (Test *test, + gconstpointer mode) +{ + const GArray *blob; + GError *error = NULL; + + test->account = tp_account_new (test->dbus, ACCOUNT_PATH, NULL); + g_assert (test->account != NULL); + + tp_proxy_prepare_async (test->account, NULL, account_prepare_cb, test); + g_main_loop_run (test->mainloop); + + tp_account_get_avatar_async (test->account, + tp_tests_result_ready_cb, &test->result); + tp_tests_run_until_result (&test->result); + + blob = tp_account_get_avatar_finish ( + test->account, test->result, &error); + g_assert_no_error (error); + + g_assert_cmpuint (blob->len, ==, 4); + g_assert_cmpstr (((char *) blob->data), ==, ":-)"); + + tp_clear_object (&test->result); +} + static void test_connection (Test *test, gconstpointer data G_GNUC_UNUSED) @@ -770,6 +789,9 @@ main (int argc, g_test_add ("/account/storage", Test, "later", setup_service, test_storage, teardown_service); + g_test_add ("/account/avatar", Test, NULL, setup_service, test_avatar, + teardown_service); + g_test_add ("/account/addressing", Test, "first", setup_service, test_addressing, teardown_service); g_test_add ("/account/addressing", Test, "later", setup_service, -- cgit v1.2.1