[libsoup] test-utils: simplify the SoupRequest test utils a bit
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] test-utils: simplify the SoupRequest test utils a bit
- Date: Wed, 25 Jul 2012 12:54:28 +0000 (UTC)
commit 6cddb7cdd31fbee94ec424993e99e0b7f7bdb90b
Author: Dan Winship <danw gnome org>
Date: Wed Jul 25 08:54:11 2012 -0400
test-utils: simplify the SoupRequest test utils a bit
tests/coding-test.c | 4 +-
tests/connection-test.c | 22 +++------------
tests/misc-test.c | 4 +-
tests/proxy-test.c | 11 +------
tests/redirect-test.c | 10 +-----
tests/test-utils.c | 67 ++++++++++++++++++++++++++---------------------
tests/test-utils.h | 13 +++++----
tests/timeout-test.c | 10 +-----
8 files changed, 58 insertions(+), 83 deletions(-)
---
diff --git a/tests/coding-test.c b/tests/coding-test.c
index cda4b89..02ec23a 100644
--- a/tests/coding-test.c
+++ b/tests/coding-test.c
@@ -338,7 +338,7 @@ do_single_coding_req_test (SoupRequest *req,
msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
- stream = soup_test_request_send_async_as_sync (req, NULL, &error);
+ stream = soup_test_request_send (req, NULL, &error);
if (error) {
debug_printf (1, " Error sending request: %s\n",
error->message);
@@ -359,7 +359,7 @@ do_single_coding_req_test (SoupRequest *req,
g_byte_array_append (data, buf, nread);
} while (nread > 0);
- soup_test_stream_close_async_as_sync (stream, NULL, &error);
+ soup_test_request_close_stream (req, stream, NULL, &error);
if (error) {
debug_printf (1, " error closing stream: %s\n",
error->message);
diff --git a/tests/connection-test.c b/tests/connection-test.c
index ddf0c98..6ddc89c 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -321,21 +321,14 @@ do_timeout_req_test_for_session (SoupSession *session)
req = soup_requester_request_uri (requester, timeout_uri, NULL);
soup_uri_free (timeout_uri);
- if (SOUP_IS_SESSION_SYNC (session))
- stream = soup_request_send (req, NULL, &error);
- else
- stream = soup_test_request_send_async_as_sync (req, NULL, &error);
-
+ stream = soup_test_request_send (req, NULL, &error);
if (!stream) {
debug_printf (1, " Unexpected error on send: %s\n",
error->message);
errors++;
g_clear_error (&error);
} else {
- if (SOUP_IS_SESSION_SYNC (session))
- g_input_stream_close (stream, NULL, &error);
- else
- soup_test_stream_close_async_as_sync (stream, NULL, &error);
+ soup_test_request_close_stream (req, stream, NULL, &error);
if (error) {
debug_printf (1, " Unexpected error on close: %s\n",
error->message);
@@ -354,21 +347,14 @@ do_timeout_req_test_for_session (SoupSession *session)
debug_printf (1, " Second request\n");
req = soup_requester_request_uri (requester, base_uri, NULL);
- if (SOUP_IS_SESSION_SYNC (session))
- stream = soup_request_send (req, NULL, &error);
- else
- stream = soup_test_request_send_async_as_sync (req, NULL, &error);
-
+ stream = soup_test_request_send (req, NULL, &error);
if (!stream) {
debug_printf (1, " Unexpected error on send: %s\n",
error->message);
errors++;
g_clear_error (&error);
} else {
- if (SOUP_IS_SESSION_SYNC (session))
- g_input_stream_close (stream, NULL, &error);
- else
- soup_test_stream_close_async_as_sync (stream, NULL, &error);
+ soup_test_request_close_stream (req, stream, NULL, &error);
if (error) {
debug_printf (1, " Unexpected error on close: %s\n",
error->message);
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 605fa21..a71d4aa 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -947,12 +947,12 @@ do_cancel_while_reading_req_test_for_session (SoupRequester *requester)
if (SOUP_IS_SESSION_ASYNC (soup_request_get_session (req))) {
g_timeout_add (100, cancel_request_timeout, cancellable);
- soup_test_request_send_async_as_sync (req, cancellable, &error);
+ soup_test_request_send (req, cancellable, &error);
} else {
GThread *thread;
thread = g_thread_new ("cancel_request_thread", cancel_request_thread, cancellable);
- soup_request_send (req, cancellable, &error);
+ soup_test_request_send (req, cancellable, &error);
g_thread_unref (thread);
}
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index 85aac9f..35c9d84 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -166,11 +166,7 @@ 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)
- stream = soup_request_send (request, NULL, &error);
- else
- stream = soup_test_request_send_async_as_sync (request, NULL, &error);
-
+ stream = soup_test_request_send (request, NULL, &error);
if (!stream) {
debug_printf (1, " Unexpected error on Request: %s\n",
error->message);
@@ -179,10 +175,7 @@ test_url_new_api (const char *url, int proxy, guint expected,
}
if (stream) {
- if (sync)
- g_input_stream_close (stream, NULL, NULL);
- else
- soup_test_stream_close_async_as_sync (stream, NULL, NULL);
+ soup_test_request_close_stream (request, stream, NULL, NULL);
if (error) {
debug_printf (1, " Unexpected error on close: %s\n",
error->message);
diff --git a/tests/redirect-test.c b/tests/redirect-test.c
index 59a2f07..401eda2 100644
--- a/tests/redirect-test.c
+++ b/tests/redirect-test.c
@@ -255,10 +255,7 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
g_signal_connect (msg, "restarted",
G_CALLBACK (restarted), &treq);
- if (SOUP_IS_SESSION_SYNC (session))
- stream = soup_request_send (req, NULL, &error);
- else
- stream = soup_test_request_send_async_as_sync (req, NULL, &error);
+ stream = soup_test_request_send (req, NULL, &error);
if (SOUP_STATUS_IS_TRANSPORT_ERROR (final_status)) {
if (stream) {
@@ -289,10 +286,7 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
return;
}
- if (SOUP_IS_SESSION_SYNC (session))
- g_input_stream_close (stream, NULL, &error);
- else
- soup_test_stream_close_async_as_sync (stream, NULL, &error);
+ soup_test_request_close_stream (req, stream, NULL, &error);
if (error) {
debug_printf (1, " could not close stream: %s\n",
error->message);
diff --git a/tests/test-utils.c b/tests/test-utils.c
index f040b73..606de32 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -355,8 +355,8 @@ soup_test_server_quit_unref (SoupServer *server)
}
typedef struct {
- GMainLoop *loop;
- GAsyncResult *result;
+ GMainLoop *loop;
+ GAsyncResult *result;
} AsyncAsSyncData;
static void
@@ -364,51 +364,58 @@ async_as_sync_callback (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- AsyncAsSyncData *data = user_data;
+ AsyncAsSyncData *data = user_data;
- data->result = g_object_ref (result);
- g_main_loop_quit (data->loop);
+ 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)
+soup_test_request_send (SoupRequest *req,
+ GCancellable *cancellable,
+ GError **error)
{
- AsyncAsSyncData data;
- GInputStream *stream;
+ AsyncAsSyncData data;
+ GInputStream *stream;
- data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
+ if (SOUP_IS_SESSION_SYNC (soup_request_get_session (req)))
+ return soup_request_send (req, cancellable, error);
- soup_request_send_async (req, cancellable, async_as_sync_callback, &data);
- g_main_loop_run (data.loop);
+ data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
- stream = soup_request_send_finish (req, data.result, error);
+ soup_request_send_async (req, cancellable, async_as_sync_callback, &data);
+ g_main_loop_run (data.loop);
- g_main_loop_unref (data.loop);
- g_object_unref (data.result);
+ stream = soup_request_send_finish (req, data.result, error);
- return stream;
+ 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)
+soup_test_request_close_stream (SoupRequest *req,
+ GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error)
{
- AsyncAsSyncData data;
- gboolean ok;
+ AsyncAsSyncData data;
+ gboolean ok;
- data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
+ if (SOUP_IS_SESSION_SYNC (soup_request_get_session (req)))
+ return g_input_stream_close (stream, cancellable, error);
- g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, cancellable,
- async_as_sync_callback, &data);
- g_main_loop_run (data.loop);
+ data.loop = g_main_loop_new (g_main_context_get_thread_default (), FALSE);
- ok = g_input_stream_close_finish (stream, data.result, error);
+ g_input_stream_close_async (stream, G_PRIORITY_DEFAULT, cancellable,
+ async_as_sync_callback, &data);
+ g_main_loop_run (data.loop);
- g_main_loop_unref (data.loop);
- g_object_unref (data.result);
+ ok = g_input_stream_close_finish (stream, data.result, error);
- return ok;
+ g_main_loop_unref (data.loop);
+ g_object_unref (data.result);
+
+ return ok;
}
diff --git a/tests/test-utils.h b/tests/test-utils.h
index 9e96903..5c244f3 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -32,9 +32,10 @@ SoupServer *soup_test_server_new (gboolean in_own_thread);
SoupServer *soup_test_server_new_ssl (gboolean in_own_thread);
void soup_test_server_quit_unref (SoupServer *server);
-GInputStream *soup_test_request_send_async_as_sync (SoupRequest *req,
- GCancellable *cancellable,
- GError **error);
-gboolean soup_test_stream_close_async_as_sync (GInputStream *stream,
- GCancellable *cancellable,
- GError **error);
+GInputStream *soup_test_request_send (SoupRequest *req,
+ GCancellable *cancellable,
+ GError **error);
+gboolean soup_test_request_close_stream (SoupRequest *req,
+ GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error);
diff --git a/tests/timeout-test.c b/tests/timeout-test.c
index aad2c3d..5c9d6a8 100644
--- a/tests/timeout-test.c
+++ b/tests/timeout-test.c
@@ -127,10 +127,7 @@ do_request_to_session (SoupRequester *requester, const char *uri,
g_signal_connect (msg, "finished",
G_CALLBACK (message_finished), &finished);
- if (SOUP_IS_SESSION_SYNC (soup_request_get_session (req)))
- stream = soup_request_send (req, NULL, &error);
- else
- stream = soup_test_request_send_async_as_sync (req, NULL, &error);
+ stream = soup_test_request_send (req, NULL, &error);
if (expect_timeout && !error) {
debug_printf (1, " FAILED: request did not time out\n");
@@ -148,10 +145,7 @@ do_request_to_session (SoupRequester *requester, const char *uri,
g_clear_error (&error);
if (stream) {
- if (SOUP_IS_SESSION_SYNC (soup_request_get_session (req)))
- g_input_stream_close (stream, NULL, &error);
- else
- soup_test_stream_close_async_as_sync (stream, NULL, &error);
+ soup_test_request_close_stream (req, stream, NULL, &error);
if (error) {
debug_printf (1, " ERROR closing string: %s",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]