summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-01 20:26:41 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-02-09 13:06:12 +0000
commitc217c8e6c43e35f4729c7a7aa5e7a6c31fbf5f75 (patch)
treea259e7a106595c62908d6914cdc65c13c3976963
parent8063df40a53ffb596b481b038716aac89f87ba00 (diff)
downloadtelepathy-glib-c217c8e6c43e35f4729c7a7aa5e7a6c31fbf5f75.tar.gz
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 <simon.mcvittie@collabora.co.uk> Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--tests/dbus/account.c70
1 files 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
@@ -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,