[librest/wip/baedert/tests: 2/10] tests/proxy: Add invoke_async cancel test
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librest/wip/baedert/tests: 2/10] tests/proxy: Add invoke_async cancel test
- Date: Fri, 22 Jul 2016 08:03:53 +0000 (UTC)
commit 9cae82d3a32f4d9dc7c0497927a46bf06a424eb0
Author: Timm Bäder <mail baedert org>
Date: Thu Jul 21 14:27:30 2016 +0200
tests/proxy: Add invoke_async cancel test
tests/proxy.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 52 insertions(+), 0 deletions(-)
---
diff --git a/tests/proxy.c b/tests/proxy.c
index b47360b..9984a69 100644
--- a/tests/proxy.c
+++ b/tests/proxy.c
@@ -357,6 +357,57 @@ useragent ()
test_server_stop (server);
}
+static void
+cancel_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ RestProxyCall *call = REST_PROXY_CALL (source_object);
+ GMainLoop *main_loop = user_data;
+ GError *error = NULL;
+ gboolean success;
+
+ /* This call has been cancelled and should have failed */
+ success= rest_proxy_call_invoke_finish (call, result, &error);
+ g_assert (!success);
+ g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
+
+ g_error_free (error);
+ g_main_loop_quit (main_loop);
+}
+
+static void
+cancel ()
+{
+ TestServer *server = create_server ();
+ RestProxy *proxy = rest_proxy_new (server->url, FALSE);
+ RestProxyCall *call;
+ GMainLoop *main_loop;
+ GCancellable *cancellable;
+
+ test_server_run (server);
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+ cancellable = g_cancellable_new ();
+ call = rest_proxy_new_call (proxy);
+ rest_proxy_call_set_function (call, "useragent/none");
+
+ rest_proxy_call_invoke_async (call,
+ cancellable,
+ cancel_cb,
+ main_loop);
+
+ g_cancellable_cancel (cancellable);
+ g_main_loop_run (main_loop);
+
+
+
+ g_main_loop_unref (main_loop);
+ g_object_unref (proxy);
+ g_object_unref (call);
+ test_server_stop (server);
+}
+
int
main (int argc, char **argv)
{
@@ -367,6 +418,7 @@ main (int argc, char **argv)
g_test_add_func ("/proxy/params", params);
g_test_add_func ("/proxy/fail", fail);
g_test_add_func ("/proxy/useragent", useragent);
+ g_test_add_func ("/proxy/cancel", cancel);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]