[librest/wip/baedert/tests: 1/27] tests/proxy: Add invoke_async cancel test



commit d81a14b4a499b322f45a34798df2c742b5d71a52
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 |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/tests/proxy.c b/tests/proxy.c
index b47360b..4cb9c32 100644
--- a/tests/proxy.c
+++ b/tests/proxy.c
@@ -357,6 +357,55 @@ 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 +416,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]