diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2010-11-11 10:47:17 +0100 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-02-22 16:29:48 +0100 |
commit | 734c62d834f566a06ca0a3943e810be7ccf5ca7e (patch) | |
tree | 9adb0966660c223cb946bb23b7d3bb55ec97a9d9 | |
parent | fc8eec75b5b0dae572a61ad70646ae9567ec14a4 (diff) | |
download | telepathy-glib-734c62d834f566a06ca0a3943e810be7ccf5ca7e.tar.gz |
test request and observe API
-rw-r--r-- | tests/dbus/account-channel-request.c | 221 |
1 files changed, 221 insertions, 0 deletions
diff --git a/tests/dbus/account-channel-request.c b/tests/dbus/account-channel-request.c index 283d0e9a3..d0520904f 100644 --- a/tests/dbus/account-channel-request.c +++ b/tests/dbus/account-channel-request.c @@ -651,6 +651,211 @@ test_forget_cancel_after_create (Test *test, g_assert_error (test->error, TP_ERRORS, TP_ERROR_CANCELLED); } +/* Request and observe tests */ +static void +create_and_observe_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) + +{ + Test *test = user_data; + + test->channel = tp_account_channel_request_create_and_observe_channel_finish ( + TP_ACCOUNT_CHANNEL_REQUEST (source), result, &test->error); + if (test->channel == NULL) + goto out; + + g_assert (TP_IS_CHANNEL (test->channel)); + tp_clear_object (&test->channel); + +out: + g_main_loop_quit (test->mainloop); +} + +static void +test_observe_create_success (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GHashTable *request; + TpAccountChannelRequest *req; + + request = create_request (); + req = tp_account_channel_request_new (test->account, request, 0); + + tp_account_channel_request_create_and_observe_channel_async (req, "Fake", + NULL, create_and_observe_cb, test); + + g_hash_table_unref (request); + g_object_unref (req); + + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); +} + +static void +ensure_and_observe_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) + +{ + Test *test = user_data; + + test->channel = tp_account_channel_request_ensure_and_observe_channel_finish ( + TP_ACCOUNT_CHANNEL_REQUEST (source), result, &test->error); + if (test->channel == NULL) + goto out; + + g_assert (TP_IS_CHANNEL (test->channel)); + tp_clear_object (&test->channel); + +out: + g_main_loop_quit (test->mainloop); +} + +/* ChannelDispatcher.CreateChannel() call fails */ +static void +test_observe_create_fail (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GHashTable *request; + TpAccountChannelRequest *req; + + request = create_request (); + + /* Ask to the CD to fail */ + tp_asv_set_boolean (request, "CreateChannelFail", TRUE); + + req = tp_account_channel_request_new (test->account, request, 0); + + tp_account_channel_request_create_and_observe_channel_async (req, "Fake", + NULL, create_and_observe_cb, test); + + g_hash_table_unref (request); + g_object_unref (req); + + g_main_loop_run (test->mainloop); + g_assert_error (test->error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT); + g_assert (test->channel == NULL); +} + +/* ChannelRequest.Proceed() call fails */ +static void +test_observe_proceed_fail (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GHashTable *request; + TpAccountChannelRequest *req; + + request = create_request (); + + /* Ask to the CD to fail */ + tp_asv_set_boolean (request, "ProceedFail", TRUE); + + req = tp_account_channel_request_new (test->account, request, 0); + + tp_account_channel_request_create_and_observe_channel_async (req, "Fake", + NULL, create_and_observe_cb, test); + + g_hash_table_unref (request); + g_object_unref (req); + + g_main_loop_run (test->mainloop); + g_assert_error (test->error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT); + g_assert (test->channel == NULL); +} + +/* ChannelRequest fire the 'Failed' signal */ +static void +test_observe_cr_failed (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GHashTable *request; + TpAccountChannelRequest *req; + + request = create_request (); + + /* Ask to the CR to fire the signal */ + tp_asv_set_boolean (request, "FireFailed", TRUE); + + req = tp_account_channel_request_new (test->account, request, 0); + + tp_account_channel_request_create_and_observe_channel_async (req, "Fake", + NULL, create_and_observe_cb, test); + + g_hash_table_unref (request); + g_object_unref (req); + + g_main_loop_run (test->mainloop); + g_assert_error (test->error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT); + g_assert (test->channel == NULL); +} + +static void +test_observe_ensure_success (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GHashTable *request; + TpAccountChannelRequest *req; + + request = create_request (); + req = tp_account_channel_request_new (test->account, request, 0); + + tp_account_channel_request_ensure_and_observe_channel_async (req, "Fake", + NULL, ensure_and_observe_cb, test); + + g_hash_table_unref (request); + g_object_unref (req); + + g_main_loop_run (test->mainloop); + g_assert_no_error (test->error); +} + +/* Cancel the operation before starting it */ +static void +test_observe_cancel_before (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GHashTable *request; + TpAccountChannelRequest *req; + + request = create_request (); + req = tp_account_channel_request_new (test->account, request, 0); + + g_cancellable_cancel (test->cancellable); + + tp_account_channel_request_create_and_observe_channel_async (req, "Fake", + test->cancellable, create_and_observe_cb, test); + + g_hash_table_unref (request); + g_object_unref (req); + + g_main_loop_run (test->mainloop); + g_assert_error (test->error, G_IO_ERROR, G_IO_ERROR_CANCELLED); +} + +static void +test_observe_cancel_after_create (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + GHashTable *request; + TpAccountChannelRequest *req; + + request = create_request (); + req = tp_account_channel_request_new (test->account, request, 0); + + tp_account_channel_request_create_and_observe_channel_async (req, "Fake", + test->cancellable, create_and_observe_cb, test); + + g_signal_connect (test->cd_service, "channel-request-created", + G_CALLBACK (channel_request_created_cb), test); + + g_hash_table_unref (request); + g_object_unref (req); + + g_main_loop_run (test->mainloop); + g_assert_error (test->error, TP_ERRORS, TP_ERROR_CANCELLED); +} + int main (int argc, char **argv) @@ -696,5 +901,21 @@ main (int argc, g_test_add ("/account-channels-request-forget/after-create", Test, NULL, setup, test_forget_cancel_after_create, teardown); + /* Request and observe tests */ + g_test_add ("/account-channels/request-observe/create-success", Test, NULL, + setup, test_observe_create_success, teardown); + g_test_add ("/account-channels/request-observe/create-fail", Test, NULL, + setup, test_observe_create_fail, teardown); + g_test_add ("/account-channels/request-observe/proceed-fail", Test, NULL, + setup, test_observe_proceed_fail, teardown); + g_test_add ("/account-channels/request-observe/cr-failed", Test, NULL, + setup, test_observe_cr_failed, teardown); + g_test_add ("/account-channels/request-observe/ensure-success", Test, NULL, + setup, test_observe_ensure_success, teardown); + g_test_add ("/account-channels/request-observe/cancel-before", Test, NULL, + setup, test_observe_cancel_before, teardown); + g_test_add ("/account-channels/request-observe/after-create", Test, NULL, + setup, test_observe_cancel_after_create, teardown); + return g_test_run (); } |