summaryrefslogtreecommitdiff
path: root/tests/proxy-test.c
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2012-07-09 13:44:42 -0400
committerDan Winship <danw@gnome.org>2012-07-13 16:26:55 -0400
commitce65958b63582548675aa598d5126be798e1e866 (patch)
tree83fc61403411b8d5e5084c6e909b9176d7f7e836 /tests/proxy-test.c
parentda4f5b9e2b83771b23dbcfde62499425fe066e93 (diff)
downloadlibsoup-ce65958b63582548675aa598d5126be798e1e866.tar.gz
Add some test-utils helpers for async SoupRequest usage
Diffstat (limited to 'tests/proxy-test.c')
-rw-r--r--tests/proxy-test.c55
1 files changed, 20 insertions, 35 deletions
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index cebc8390..85aac9f5 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -124,27 +124,6 @@ test_url (const char *url, int proxy, guint expected,
soup_test_session_abort_unref (session);
}
-static GMainLoop *loop;
-
-static void
-request_completed (GObject *source, GAsyncResult *result, gpointer user_data)
-{
- SoupRequest *req = SOUP_REQUEST (source);
- GInputStream **stream_p = user_data;
- GError *error = NULL;
-
- debug_printf (2, " Request completed\n");
- *stream_p = soup_request_send_finish (req, result, &error);
- if (!*stream_p) {
- debug_printf (1, " Unexpected error on Request: %s\n",
- error->message);
- errors++;
- g_error_free (error);
- }
-
- g_main_loop_quit (loop);
-}
-
static void
test_url_new_api (const char *url, int proxy, guint expected,
gboolean sync, gboolean close)
@@ -155,6 +134,7 @@ test_url_new_api (const char *url, int proxy, guint expected,
SoupRequester *requester;
SoupRequest *request;
GInputStream *stream;
+ GError *error = NULL;
if (!tls_available && g_str_has_prefix (url, "https:"))
return;
@@ -186,26 +166,31 @@ test_url_new_api (const char *url, int proxy, guint expected,
request = soup_requester_request (requester, url, NULL);
msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
- if (sync) {
- GError *error = NULL;
-
+ if (sync)
stream = soup_request_send (request, NULL, &error);
- if (!stream) {
- debug_printf (1, " Unexpected error on Request: %s\n",
+ else
+ stream = soup_test_request_send_async_as_sync (request, NULL, &error);
+
+ if (!stream) {
+ debug_printf (1, " Unexpected error on Request: %s\n",
+ error->message);
+ errors++;
+ g_clear_error (&error);
+ }
+
+ if (stream) {
+ if (sync)
+ g_input_stream_close (stream, NULL, NULL);
+ else
+ soup_test_stream_close_async_as_sync (stream, NULL, NULL);
+ if (error) {
+ debug_printf (1, " Unexpected error on close: %s\n",
error->message);
errors++;
- g_error_free (error);
+ g_clear_error (&error);
}
- } else {
- loop = g_main_loop_new (NULL, TRUE);
- soup_request_send_async (request, NULL, request_completed, &stream);
- g_main_loop_run (loop);
- g_main_loop_unref (loop);
}
- if (stream)
- g_input_stream_close (stream, NULL, NULL);
-
debug_printf (1, " %d %s\n", msg->status_code, msg->reason_phrase);
if (msg->status_code != expected) {
debug_printf (1, " EXPECTED %d!\n", expected);