summaryrefslogtreecommitdiff
path: root/tests/test-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-utils.c')
-rw-r--r--tests/test-utils.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test-utils.c b/tests/test-utils.c
index f2a3bd69..f040b738 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -353,3 +353,62 @@ soup_test_server_quit_unref (SoupServer *server)
(gpointer *)&server);
}
}
+
+typedef struct {
+ GMainLoop *loop;
+ GAsyncResult *result;
+} AsyncAsSyncData;
+
+static void
+async_as_sync_callback (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ AsyncAsSyncData *data = user_data;
+
+ data->result = g_object_ref (result);
+ g_main_loop_quit (data->loop);
+}
+
+GInputStream *
+soup_test_request_send_async_as_sync (SoupRequest *req,
+ GCancellable *cancellable,
+ GError **error)
+{
+ AsyncAsSyncData data;
+ GInputStream *stream;
+
+ data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
+
+ soup_request_send_async (req, cancellable, async_as_sync_callback, &data);
+ g_main_loop_run (data.loop);
+
+ stream = soup_request_send_finish (req, data.result, error);
+
+ g_main_loop_unref (data.loop);
+ g_object_unref (data.result);
+
+ return stream;
+}
+
+gboolean
+soup_test_stream_close_async_as_sync (GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error)
+{
+ AsyncAsSyncData data;
+ gboolean ok;
+
+ data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
+
+ g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, cancellable,
+ async_as_sync_callback, &data);
+ g_main_loop_run (data.loop);
+
+ ok = g_input_stream_close_finish (stream, data.result, error);
+
+ g_main_loop_unref (data.loop);
+ g_object_unref (data.result);
+
+ return ok;
+}