From 20abd076ce7c1a6d1dee53018c979d67e1aefd80 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 1 Feb 2012 20:26:41 +0000 Subject: [PATCH 3/7] 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. --- tests/dbus/account.c | 70 ++++++++++++++++++++++++++++++++----------------- 1 files changed, 46 insertions(+), 24 deletions(-) diff --git a/tests/dbus/account.c b/tests/dbus/account.c index ccad46a..79cbc4f 100644 --- a/tests/dbus/account.c +++ b/tests/dbus/account.c @@ -417,33 +417,13 @@ test_prepare_success (Test *test, } 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 @@ -545,6 +537,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, -- 1.7.9