diff options
| author | Carlos Garcia Campos <cgarcia@igalia.com> | 2020-09-18 14:07:45 +0200 |
|---|---|---|
| committer | Carlos Garcia Campos <cgarcia@igalia.com> | 2020-09-30 07:17:27 +0200 |
| commit | c61e2615f4fcfaed134cd9a2cd11ab2572b26551 (patch) | |
| tree | b748933051c3b123a2533050b6759f4967c7b314 | |
| parent | d1987bd1d2f72da183d0ca0985f40178466e3dfb (diff) | |
| download | libsoup-c61e2615f4fcfaed134cd9a2cd11ab2572b26551.tar.gz | |
tests: stop using soup_session_send_message in tests
Except for a few tests that seem to be testing the old API that we will
remove once the old api is gone.
| -rw-r--r-- | tests/auth-test.c | 20 | ||||
| -rw-r--r-- | tests/chunk-io-test.c | 2 | ||||
| -rw-r--r-- | tests/coding-test.c | 90 | ||||
| -rw-r--r-- | tests/connection-test.c | 36 | ||||
| -rw-r--r-- | tests/context-test.c | 4 | ||||
| -rw-r--r-- | tests/cookies-test.c | 12 | ||||
| -rw-r--r-- | tests/forms-test.c | 6 | ||||
| -rw-r--r-- | tests/hsts-db-test.c | 4 | ||||
| -rw-r--r-- | tests/hsts-test.c | 4 | ||||
| -rw-r--r-- | tests/misc-test.c | 33 | ||||
| -rw-r--r-- | tests/no-ssl-test.c | 2 | ||||
| -rw-r--r-- | tests/ntlm-test.c | 11 | ||||
| -rw-r--r-- | tests/proxy-test.c | 6 | ||||
| -rw-r--r-- | tests/pull-api-test.c | 4 | ||||
| -rw-r--r-- | tests/redirect-test.c | 7 | ||||
| -rw-r--r-- | tests/server-test.c | 47 | ||||
| -rw-r--r-- | tests/session-test.c | 7 | ||||
| -rw-r--r-- | tests/ssl-test.c | 2 | ||||
| -rw-r--r-- | tests/test-utils.c | 40 | ||||
| -rw-r--r-- | tests/test-utils.h | 6 |
20 files changed, 220 insertions, 123 deletions
diff --git a/tests/auth-test.c b/tests/auth-test.c index 75e70510..9f7720ab 100644 --- a/tests/auth-test.c +++ b/tests/auth-test.c @@ -438,7 +438,7 @@ do_digest_nonce_test (SoupSession *session, G_CALLBACK (digest_nonce_unauthorized), &got_401); got_401 = FALSE; - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert (got_401 == expect_401, "%s request %s a 401 Unauthorized!\n", nth, got_401 ? "got" : "did not get"); @@ -585,7 +585,7 @@ do_async_auth_good_password_test (void) msg2 = soup_message_new ("GET", uri); g_object_set_data (G_OBJECT (msg2), "id", GINT_TO_POINTER (2)); - soup_session_send_message (session, msg2); + soup_test_session_send_message (session, msg2); soup_test_assert_message_status (msg2, SOUP_STATUS_UNAUTHORIZED); @@ -809,7 +809,7 @@ select_auth_test_one (SoupURI *uri, sad.password = password; msg = soup_message_new_from_uri ("GET", uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert (strcmp (sad.round[0].headers, first_headers) == 0, "Header order wrong: expected %s, got %s", @@ -1099,7 +1099,7 @@ do_infinite_auth_test (void) timeout = g_timeout_add (500, infinite_cancel, session); g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING, "*stuck in infinite loop*"); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); g_test_assert_expected_messages (); soup_test_assert (msg->status_code != SOUP_STATUS_CANCELLED, @@ -1270,7 +1270,7 @@ do_batch_tests (gconstpointer data) signal = g_signal_connect (session, "authenticate", G_CALLBACK (authenticate), (gpointer)¤t_tests[i]); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); g_signal_handler_disconnect (session, signal); soup_test_assert_message_status (msg, current_tests[i].final_status); @@ -1341,7 +1341,7 @@ do_message_do_not_use_auth_cache_test (void) msg = soup_message_new_from_uri (SOUP_METHOD_GET, soup_uri); flags = soup_message_get_flags (msg); soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); g_object_unref (msg); soup_uri_free (soup_uri); @@ -1361,7 +1361,7 @@ do_message_do_not_use_auth_cache_test (void) msg = soup_message_new (SOUP_METHOD_GET, uri); flags = soup_message_get_flags (msg); soup_message_set_flags (msg, flags | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED); g_object_unref (msg); g_free (uri); @@ -1468,7 +1468,7 @@ do_message_has_authorization_header_test (void) msg = soup_message_new ("GET", uri); auth_id = g_signal_connect (session, "authenticate", G_CALLBACK (has_authorization_header_authenticate), &auth); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); soup_test_assert (SOUP_IS_AUTH (auth), "Expected a SoupAuth"); token = soup_auth_get_authorization (auth, msg); @@ -1484,7 +1484,7 @@ do_message_has_authorization_header_test (void) auth_id = g_signal_connect (session, "authenticate", G_CALLBACK (has_authorization_header_authenticate_assert), NULL); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); g_object_unref (msg); @@ -1493,7 +1493,7 @@ do_message_has_authorization_header_test (void) msg = soup_message_new ("GET", uri); soup_message_headers_replace (msg->request_headers, "Authorization", token); soup_message_set_flags (msg, soup_message_get_flags (msg) | SOUP_MESSAGE_DO_NOT_USE_AUTH_CACHE); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); g_object_unref (msg); g_free (token); diff --git a/tests/chunk-io-test.c b/tests/chunk-io-test.c index 8c1423bf..8fd1928f 100644 --- a/tests/chunk-io-test.c +++ b/tests/chunk-io-test.c @@ -23,7 +23,7 @@ force_io_streams_init (void) session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); msg = soup_message_new_from_uri ("POST", base_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); g_object_unref (msg); soup_test_session_abort_unref (session); diff --git a/tests/coding-test.c b/tests/coding-test.c index e8a33508..696f46f5 100644 --- a/tests/coding-test.c +++ b/tests/coding-test.c @@ -160,14 +160,7 @@ check_response (CodingTestData *data, type = soup_message_headers_get_one (data->msg->response_headers, "Content-Type"); g_assert_cmpstr (type, ==, expected_content_type); - if (body) { - g_assert_true (g_bytes_equal (body, data->response)); - } else { - soup_assert_cmpmem (data->msg->response_body->data, - data->msg->response_body->length, - g_bytes_get_data (data->response, NULL), - g_bytes_get_size (data->response)); - } + g_assert_true (g_bytes_equal (body, data->response)); } static void @@ -186,9 +179,7 @@ setup_coding_test (CodingTestData *data, gconstpointer test_data) data->response = g_bytes_new_static (NULL, 0); else { msg = soup_message_new_from_uri ("GET", uri); - soup_session_send_message (data->session, msg); - - data->response = soup_message_body_flatten (msg->response_body); + data->response = soup_test_session_send (data->session, msg, NULL, NULL); g_object_unref (msg); } @@ -204,7 +195,6 @@ setup_coding_test (CodingTestData *data, gconstpointer test_data) if (test_type & CODING_TEST_NO_DECODER) soup_session_remove_feature_by_type (data->session, SOUP_TYPE_CONTENT_DECODER); - } static void @@ -221,102 +211,124 @@ teardown_coding_test (CodingTestData *data, gconstpointer test_data) static void do_coding_test_plain (CodingTestData *data, gconstpointer test_data) { - soup_session_send_message (data->session, data->msg); - check_response (data, NULL, "text/plain", EXPECT_NOT_DECODED, NULL); + GBytes *body; + + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, NULL, "text/plain", EXPECT_NOT_DECODED, body); + g_bytes_unref (body); } static void do_coding_test_gzip (CodingTestData *data, gconstpointer test_data) { - soup_session_send_message (data->session, data->msg); - check_response (data, "gzip", "text/plain", EXPECT_DECODED, NULL); + GBytes *body; + + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, "gzip", "text/plain", EXPECT_DECODED, body); + g_bytes_unref (body); } static void do_coding_test_gzip_with_junk (CodingTestData *data, gconstpointer test_data) { + GBytes *body; + g_test_bug ("606352"); g_test_bug ("676477"); soup_message_headers_append (data->msg->request_headers, "X-Test-Options", "trailing-junk"); - soup_session_send_message (data->session, data->msg); - check_response (data, "gzip", "text/plain", EXPECT_DECODED, NULL); + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, "gzip", "text/plain", EXPECT_DECODED, body); + g_bytes_unref (body); } static void do_coding_test_gzip_bad_server (CodingTestData *data, gconstpointer test_data) { + GBytes *body; + g_test_bug ("613361"); soup_message_headers_append (data->msg->request_headers, "X-Test-Options", "force-encode"); - soup_session_send_message (data->session, data->msg); + body = soup_test_session_send (data->session, data->msg, NULL, NULL); /* Failed content-decoding should have left the body untouched * from what the server sent... which happens to be the * uncompressed data. */ - check_response (data, "gzip", "text/plain", EXPECT_NOT_DECODED, NULL); + check_response (data, "gzip", "text/plain", EXPECT_NOT_DECODED, body); + g_bytes_unref (body); } static void do_coding_test_deflate (CodingTestData *data, gconstpointer test_data) { + GBytes *body; + soup_message_headers_append (data->msg->request_headers, "X-Test-Options", "prefer-deflate-zlib"); - soup_session_send_message (data->session, data->msg); - - check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL); + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, "deflate", "text/plain", EXPECT_DECODED, body); + g_bytes_unref (body); } static void do_coding_test_deflate_with_junk (CodingTestData *data, gconstpointer test_data) { + GBytes *body; + g_test_bug ("606352"); g_test_bug ("676477"); soup_message_headers_append (data->msg->request_headers, "X-Test-Options", "prefer-deflate-zlib, trailing-junk"); - soup_session_send_message (data->session, data->msg); - - check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL); + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, "deflate", "text/plain", EXPECT_DECODED, body); + g_bytes_unref (body); } static void do_coding_test_deflate_bad_server (CodingTestData *data, gconstpointer test_data) { + GBytes *body; + g_test_bug ("613361"); soup_message_headers_append (data->msg->request_headers, "X-Test-Options", "force-encode, prefer-deflate-zlib"); - soup_session_send_message (data->session, data->msg); - - check_response (data, "deflate", "text/plain", EXPECT_NOT_DECODED, NULL); + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, "deflate", "text/plain", EXPECT_NOT_DECODED, body); + g_bytes_unref (body); } static void do_coding_test_deflate_raw (CodingTestData *data, gconstpointer test_data) { + GBytes *body; + soup_message_headers_append (data->msg->request_headers, "X-Test-Options", "prefer-deflate-raw"); - soup_session_send_message (data->session, data->msg); - - check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL); + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, "deflate", "text/plain", EXPECT_DECODED, body); + g_bytes_unref (body); } static void do_coding_test_deflate_raw_bad_server (CodingTestData *data, gconstpointer test_data) { + GBytes *body; + g_test_bug ("613361"); soup_message_headers_append (data->msg->request_headers, "X-Test-Options", "force-encode, prefer-deflate-raw"); - soup_session_send_message (data->session, data->msg); - - check_response (data, "deflate", "text/plain", EXPECT_NOT_DECODED, NULL); + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, "deflate", "text/plain", EXPECT_NOT_DECODED, body); + g_bytes_unref (body); } static void @@ -459,13 +471,15 @@ do_coding_req_test_deflate_raw_bad_server (CodingTestData *data, gconstpointer t static void do_coding_msg_empty_test (CodingTestData *data, gconstpointer test_data) { + GBytes *body; + g_test_bug ("697527"); soup_message_headers_append (data->msg->request_headers, "X-Test-Options", "empty"); - soup_session_send_message (data->session, data->msg); - - check_response (data, "gzip", "text/plain", EXPECT_NOT_DECODED, NULL); + body = soup_test_session_send (data->session, data->msg, NULL, NULL); + check_response (data, "gzip", "text/plain", EXPECT_NOT_DECODED, body); + g_bytes_unref (body); } static void diff --git a/tests/connection-test.c b/tests/connection-test.c index 61012e0f..d267c3ec 100644 --- a/tests/connection-test.c +++ b/tests/connection-test.c @@ -175,6 +175,7 @@ do_content_length_framing_test (void) SoupMessage *msg; SoupURI *request_uri; goffset declared_length; + GBytes *body; g_test_bug ("611481"); @@ -183,29 +184,31 @@ do_content_length_framing_test (void) debug_printf (1, " Content-Length larger than message body length\n"); request_uri = soup_uri_new_with_base (base_uri, "/content-length/long"); msg = soup_message_new_from_uri ("GET", request_uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); declared_length = soup_message_headers_get_content_length (msg->response_headers); debug_printf (2, " Content-Length: %lu, body: %s\n", - (gulong)declared_length, msg->response_body->data); - g_assert_cmpint (msg->response_body->length, <, declared_length); + (gulong)declared_length, (char *)g_bytes_get_data (body, NULL)); + g_assert_cmpint (g_bytes_get_size (body), <, declared_length); soup_uri_free (request_uri); + g_bytes_unref (body); g_object_unref (msg); debug_printf (1, " Server claims 'Connection: close' but doesn't\n"); request_uri = soup_uri_new_with_base (base_uri, "/content-length/noclose"); msg = soup_message_new_from_uri ("GET", request_uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); declared_length = soup_message_headers_get_content_length (msg->response_headers); - g_assert_cmpint (msg->response_body->length, ==, declared_length); + g_assert_cmpint (g_bytes_get_size (body), ==, declared_length); soup_uri_free (request_uri); + g_bytes_unref (body); g_object_unref (msg); soup_test_session_abort_unref (session); @@ -243,6 +246,7 @@ do_timeout_test_for_session (SoupSession *session) SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL }; SoupURI *timeout_uri; int i; + GBytes *body; g_signal_connect (session, "request-started", G_CALLBACK (request_started_socket_collector), @@ -252,13 +256,14 @@ do_timeout_test_for_session (SoupSession *session) timeout_uri = soup_uri_new_with_base (base_uri, "/timeout-persistent"); msg = soup_message_new_from_uri ("GET", timeout_uri); soup_uri_free (timeout_uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); if (sockets[1]) { soup_test_assert (sockets[1] == NULL, "Message was retried"); sockets[1] = sockets[2] = sockets[3] = NULL; } + g_bytes_unref (body); g_object_unref (msg); /* The server will grab server_mutex before returning the response, @@ -269,7 +274,7 @@ do_timeout_test_for_session (SoupSession *session) debug_printf (1, " Second message\n"); msg = soup_message_new_from_uri ("GET", base_uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); soup_test_assert (sockets[1] == sockets[0], @@ -280,6 +285,7 @@ do_timeout_test_for_session (SoupSession *session) "Message was retried on closed connection"); soup_test_assert (sockets[3] == NULL, "Message was retried again"); + g_bytes_unref (body); g_object_unref (msg); for (i = 0; sockets[i]; i++) @@ -677,6 +683,7 @@ do_non_idempotent_test_for_session (SoupSession *session) SoupMessage *msg; SoupSocket *sockets[4] = { NULL, NULL, NULL, NULL }; int i; + GBytes *body; g_signal_connect (session, "request-started", G_CALLBACK (request_started_socket_collector), @@ -684,23 +691,24 @@ do_non_idempotent_test_for_session (SoupSession *session) debug_printf (2, " GET\n"); msg = soup_message_new_from_uri ("GET", base_uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); if (sockets[1]) { soup_test_assert (sockets[1] == NULL, "Message was retried"); sockets[1] = sockets[2] = sockets[3] = NULL; } + g_bytes_unref (body); g_object_unref (msg); debug_printf (2, " POST\n"); msg = soup_message_new_from_uri ("POST", base_uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); soup_test_assert (sockets[1] != sockets[0], "Message was sent on existing connection"); soup_test_assert (sockets[2] == NULL, "Too many connections used"); - + g_bytes_unref (body); g_object_unref (msg); for (i = 0; sockets[i]; i++) @@ -770,10 +778,12 @@ static void do_one_connection_state_test (SoupSession *session, const char *uri) { SoupMessage *msg; + GBytes *body; msg = soup_message_new ("GET", uri); - soup_session_send_message (session, msg); + body = soup_test_session_async_send (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); + g_bytes_unref (body); g_object_unref (msg); soup_session_abort (session); } @@ -902,12 +912,13 @@ do_one_connection_event_test (SoupSession *session, const char *uri, const char *events) { SoupMessage *msg; + GBytes *body; msg = soup_message_new ("GET", uri); g_signal_connect (msg, "network-event", G_CALLBACK (network_event), &events); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); while (*events) { soup_test_assert (!*events, @@ -916,6 +927,7 @@ do_one_connection_event_test (SoupSession *session, const char *uri, events++; } + g_bytes_unref (body); g_object_unref (msg); soup_session_abort (session); } diff --git a/tests/context-test.c b/tests/context-test.c index c81b5131..a38f090f 100644 --- a/tests/context-test.c +++ b/tests/context-test.c @@ -130,6 +130,7 @@ test1_thread (gpointer user_data) GMainContext *async_context; char *uri; SoupMessage *msg; + GInputStream *stream; GMainLoop *loop; /* Wait for main thread to be waiting on test1_cond */ @@ -146,8 +147,9 @@ test1_thread (gpointer user_data) debug_printf (1, " send_message\n"); msg = soup_message_new ("GET", uri); - soup_session_send_message (session, msg); + stream = soup_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); + g_object_unref (stream); g_object_unref (msg); debug_printf (1, " queue_message\n"); diff --git a/tests/cookies-test.c b/tests/cookies-test.c index 38455a3b..63c9e711 100644 --- a/tests/cookies-test.c +++ b/tests/cookies-test.c @@ -72,14 +72,14 @@ do_cookies_accept_policy_test (void) uri = soup_uri_new_with_base (first_party_uri, "/foo.jpg"); msg = soup_message_new_from_uri ("GET", uri); soup_message_set_first_party (msg, third_party_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_uri_free (uri); g_object_unref (msg); uri = soup_uri_new_with_base (first_party_uri, "/index.html"); msg = soup_message_new_from_uri ("GET", uri); soup_message_set_first_party (msg, first_party_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_uri_free (uri); g_object_unref (msg); @@ -87,7 +87,7 @@ do_cookies_accept_policy_test (void) uri = soup_uri_new_with_base (first_party_uri, "/foo.jpg"); msg = soup_message_new_from_uri ("GET", uri); soup_message_set_first_party (msg, third_party_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_uri_free (uri); g_object_unref (msg); } @@ -302,19 +302,19 @@ do_cookies_parsing_test (void) msg = soup_message_new_from_uri ("GET", first_party_uri); soup_message_headers_append (msg->request_headers, "Echo-Set-Cookie", "one=1; httponly; max-age=100"); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); g_object_unref (msg); msg = soup_message_new_from_uri ("GET", first_party_uri); soup_message_headers_append (msg->request_headers, "Echo-Set-Cookie", "two=2; HttpOnly; max-age=100; SameSite=Invalid"); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); g_object_unref (msg); msg = soup_message_new_from_uri ("GET", first_party_uri); soup_message_headers_append (msg->request_headers, "Echo-Set-Cookie", "three=3; httpONLY=Wednesday; max-age=100; SameSite=Lax"); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); g_object_unref (msg); cookies = soup_cookie_jar_get_cookie_list (jar, first_party_uri, TRUE); diff --git a/tests/forms-test.c b/tests/forms-test.c index 1ad1c84a..1a07fa00 100644 --- a/tests/forms-test.c +++ b/tests/forms-test.c @@ -187,6 +187,7 @@ do_md5_test_libsoup (gconstpointer data) GBytes *buffer; SoupMessage *msg; SoupSession *session; + GBytes *body; g_test_bug ("601640"); @@ -207,11 +208,12 @@ do_md5_test_libsoup (gconstpointer data) soup_multipart_free (multipart); session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); - g_assert_cmpstr (msg->response_body->data, ==, md5); + g_assert_cmpmem (md5, strlen (md5), g_bytes_get_data (body, NULL), g_bytes_get_size (body)); + g_bytes_unref (body); g_object_unref (msg); soup_test_session_abort_unref (session); diff --git a/tests/hsts-db-test.c b/tests/hsts-db-test.c index c01cf045..f45e355d 100644 --- a/tests/hsts-db-test.c +++ b/tests/hsts-db-test.c @@ -59,11 +59,13 @@ static void session_get_uri (SoupSession *session, const char *uri, SoupStatus expected_status) { SoupMessage *msg; + GBytes *body; msg = soup_message_new ("GET", uri); soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, expected_status); + g_bytes_unref (body); g_object_unref (msg); } diff --git a/tests/hsts-test.c b/tests/hsts-test.c index 2d2257ca..e8c7d877 100644 --- a/tests/hsts-test.c +++ b/tests/hsts-test.c @@ -105,11 +105,13 @@ static void session_get_uri (SoupSession *session, const char *uri, SoupStatus expected_status) { SoupMessage *msg; + GBytes *body; msg = soup_message_new ("GET", uri); soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, expected_status); + g_bytes_unref (body); g_object_unref (msg); } diff --git a/tests/misc-test.c b/tests/misc-test.c index 62184e35..412a5754 100644 --- a/tests/misc-test.c +++ b/tests/misc-test.c @@ -99,6 +99,7 @@ do_host_test (void) { SoupSession *session; SoupMessage *one, *two; + GBytes *body_one, *body_two; g_test_bug ("539803"); @@ -108,17 +109,19 @@ do_host_test (void) two = soup_message_new_from_uri ("GET", base_uri); soup_message_headers_replace (two->request_headers, "Host", "foo"); - soup_session_send_message (session, one); - soup_session_send_message (session, two); + body_one = soup_test_session_send (session, one, NULL, NULL); + body_two = soup_test_session_send (session, two, NULL, NULL); soup_test_session_abort_unref (session); soup_test_assert_message_status (one, SOUP_STATUS_OK); - g_assert_cmpstr (one->response_body->data, ==, "index"); + g_assert_cmpstr (g_bytes_get_data (body_one, NULL), ==, "index"); + g_bytes_unref (body_one); g_object_unref (one); soup_test_assert_message_status (two, SOUP_STATUS_OK); - g_assert_cmpstr (two->response_body->data, ==, "foo-index"); + g_assert_cmpstr (g_bytes_get_data (body_two, NULL), ==, "foo-index"); + g_bytes_unref (body_two); g_object_unref (two); } @@ -131,6 +134,8 @@ do_host_big_header (void) SoupMessage *msg; SoupSession *session; int i; + GInputStream *stream; + GError *error = NULL; g_test_bug ("792173"); @@ -145,12 +150,12 @@ do_host_big_header (void) g_free (key); } - soup_session_send_message (session, msg); + stream = soup_session_send (session, msg, NULL, &error); + g_assert_null (stream); + g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_CLOSED); soup_test_session_abort_unref (session); - soup_test_assert_message_status (msg, SOUP_STATUS_IO_ERROR); - g_object_unref (msg); } @@ -376,14 +381,14 @@ do_msg_reuse_test (void) debug_printf (1, " First message\n"); msg = soup_message_new_from_uri ("GET", base_uri); - soup_session_send_message (session, msg); + soup_test_session_async_send (session, msg); ensure_no_signal_handlers (msg, signal_ids, n_signal_ids); debug_printf (1, " Redirect message\n"); uri = soup_uri_new_with_base (base_uri, "/redirect"); soup_message_set_uri (msg, uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_async_send (session, msg); g_assert_true (soup_uri_equal (soup_message_get_uri (msg), base_uri)); ensure_no_signal_handlers (msg, signal_ids, n_signal_ids); @@ -391,14 +396,14 @@ do_msg_reuse_test (void) uri = soup_uri_new_with_base (base_uri, "/auth"); soup_message_set_uri (msg, uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_async_send (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); ensure_no_signal_handlers (msg, signal_ids, n_signal_ids); /* One last try to make sure the auth stuff got cleaned up */ debug_printf (1, " Last message\n"); soup_message_set_uri (msg, base_uri); - soup_session_send_message (session, msg); + soup_test_session_async_send (session, msg); ensure_no_signal_handlers (msg, signal_ids, n_signal_ids); soup_test_session_abort_unref (session); @@ -640,7 +645,7 @@ do_one_accept_language_test (const char *language, const char *expected_header) SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE, NULL); msg = soup_message_new_from_uri ("GET", base_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_session_abort_unref (session); soup_test_assert_message_status (msg, SOUP_STATUS_OK); @@ -815,7 +820,7 @@ do_aliases_test_for_session (SoupSession *session, if (redirect_protocol) soup_message_headers_append (msg->request_headers, "X-Redirect-Protocol", redirect_protocol); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); redirected_protocol = soup_message_headers_get_one (msg->response_headers, "X-Redirected-Protocol"); @@ -1082,7 +1087,7 @@ do_stealing_test (gconstpointer data) iostream = NULL; if (sync) { - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_SWITCHING_PROTOCOLS); } else { g_signal_connect (msg, "finished", diff --git a/tests/no-ssl-test.c b/tests/no-ssl-test.c index 92253a9c..b92dd2c2 100644 --- a/tests/no-ssl-test.c +++ b/tests/no-ssl-test.c @@ -11,7 +11,7 @@ do_ssl_test_for_session (SoupSession *session, SoupURI *uri) gboolean is_https; msg = soup_message_new_from_uri ("GET", uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_SSL_FAILED); is_https = soup_message_get_https_status (msg, &cert, &flags); diff --git a/tests/ntlm-test.c b/tests/ntlm-test.c index e1ee5e95..0a980f9b 100644 --- a/tests/ntlm-test.c +++ b/tests/ntlm-test.c @@ -312,6 +312,7 @@ do_message (SoupSession *session, SoupURI *base_uri, const char *path, { SoupURI *uri; SoupMessage *msg; + GBytes *body; NTLMState state = { FALSE, FALSE, FALSE, FALSE }; uri = soup_uri_new_with_base (base_uri, path); @@ -327,7 +328,7 @@ do_message (SoupSession *session, SoupURI *base_uri, const char *path, g_signal_connect (msg, "wrote-headers", G_CALLBACK (response_check), &state); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); debug_printf (1, " %-10s -> ", path); if (state.got_ntlm_prompt) { @@ -385,6 +386,7 @@ do_message (SoupSession *session, SoupURI *base_uri, const char *path, g_assert_true (state.sent_basic_response == do_basic); soup_test_assert_message_status (msg, status_code); + g_bytes_unref (body); g_object_unref (msg); } @@ -635,6 +637,7 @@ do_retrying_test (TestServer *ts, SoupSession *session; SoupMessage *msg; SoupURI *uri; + GBytes *body; gboolean retried = FALSE; g_test_bug ("693222"); @@ -653,11 +656,12 @@ do_retrying_test (TestServer *ts, msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); g_assert_true (retried); soup_test_assert_message_status (msg, SOUP_STATUS_OK); + g_bytes_unref (body); g_object_unref (msg); soup_test_session_abort_unref (session); @@ -675,11 +679,12 @@ do_retrying_test (TestServer *ts, msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); g_assert_true (retried); soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED); + g_bytes_unref (body); g_object_unref (msg); soup_test_session_abort_unref (session); diff --git a/tests/proxy-test.c b/tests/proxy-test.c index d21b857f..a17671d4 100644 --- a/tests/proxy-test.c +++ b/tests/proxy-test.c @@ -112,7 +112,7 @@ test_url (const char *url, int proxy, guint expected, gboolean close) G_CALLBACK (set_close_on_connect), NULL); } - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); debug_printf (1, " %d %s\n", msg->status_code, msg->reason_phrase); soup_test_assert_message_status (msg, expected); @@ -264,7 +264,7 @@ do_proxy_fragment_test (gconstpointer data) req_uri = soup_uri_new_with_base (base_uri, "/#foo"); msg = soup_message_new_from_uri (SOUP_METHOD_GET, req_uri); soup_uri_free (req_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); @@ -293,7 +293,7 @@ do_proxy_redirect_test (void) msg = soup_message_new_from_uri (SOUP_METHOD_GET, req_uri); soup_message_headers_append (msg->request_headers, "Connection", "close"); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); new_uri = soup_message_get_uri (msg); soup_test_assert (strcmp (req_uri->path, new_uri->path) != 0, diff --git a/tests/pull-api-test.c b/tests/pull-api-test.c index 1024fea1..5f39bb3b 100644 --- a/tests/pull-api-test.c +++ b/tests/pull-api-test.c @@ -21,15 +21,13 @@ get_correct_response (const char *uri) session = soup_test_session_new (SOUP_TYPE_SESSION, NULL); msg = soup_message_new (SOUP_METHOD_GET, uri); - soup_session_send_message (session, msg); + correct_response = soup_test_session_send (session, msg, NULL, NULL); if (msg->status_code != SOUP_STATUS_OK) { g_printerr ("Could not fetch %s: %d %s\n", uri, msg->status_code, msg->reason_phrase); exit (1); } - correct_response = soup_message_body_flatten (msg->response_body); - g_object_unref (msg); soup_test_session_abort_unref (session); } diff --git a/tests/redirect-test.c b/tests/redirect-test.c index 0d6572d7..66b1a2d0 100644 --- a/tests/redirect-test.c +++ b/tests/redirect-test.c @@ -106,9 +106,8 @@ static TestCase tests[] = { { "GET", "/bad%20with%20spaces", 200 }, { NULL } }, 200, "566530" }, - /* Test behavior with irrecoverably-bad Location header */ { { { "GET", "/bad-no-host", 302 }, - { NULL } }, SOUP_STATUS_MALFORMED, "528882" }, + { NULL } }, 302, "528882" }, /* Test infinite redirection */ { { { "GET", "/bad-recursive", 302, TRUE }, @@ -163,6 +162,7 @@ do_message_api_test (SoupSession *session, TestCase *test) { SoupURI *uri; SoupMessage *msg; + GBytes *body; TestRequest *treq; if (test->bugref) @@ -185,10 +185,11 @@ do_message_api_test (SoupSession *session, TestCase *test) g_signal_connect (msg, "restarted", G_CALLBACK (restarted), &treq); - soup_session_send_message (session, msg); + body = soup_test_session_async_send (session, msg); soup_test_assert_message_status (msg, test->final_status); + g_bytes_unref (body); g_object_unref (msg); } diff --git a/tests/server-test.c b/tests/server-test.c index dfebb85f..77f4b763 100644 --- a/tests/server-test.c +++ b/tests/server-test.c @@ -130,7 +130,7 @@ do_star_test (ServerData *sd, gconstpointer test_data) debug_printf (1, " Testing with no handler\n"); msg = soup_message_new_from_uri ("OPTIONS", star_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_NOT_FOUND); handled_by = soup_message_headers_get_one (msg->response_headers, @@ -142,7 +142,7 @@ do_star_test (ServerData *sd, gconstpointer test_data) debug_printf (1, " Testing with handler\n"); msg = soup_message_new_from_uri ("OPTIONS", star_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); handled_by = soup_message_headers_get_one (msg->response_headers, @@ -271,7 +271,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); @@ -279,7 +279,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); @@ -288,7 +288,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); @@ -296,7 +296,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); @@ -304,7 +304,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); @@ -312,7 +312,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); @@ -320,7 +320,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); @@ -328,7 +328,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); @@ -336,7 +336,7 @@ do_dot_dot_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST); g_object_unref (msg); #endif @@ -993,7 +993,7 @@ do_early_stream_test (ServerData *sd, gconstpointer test_data) { SoupSession *session; SoupMessage *msg; - GBytes *index; + GBytes *index, *body; char *md5; server_add_early_handler (sd, NULL, early_stream_callback, NULL, NULL); @@ -1004,14 +1004,15 @@ do_early_stream_test (ServerData *sd, gconstpointer test_data) index = soup_test_get_index (); soup_message_body_append_bytes (msg->request_body, index); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); md5 = g_compute_checksum_for_bytes (G_CHECKSUM_MD5, index); - g_assert_cmpstr (md5, ==, msg->response_body->data); + g_assert_cmpmem (md5, strlen (md5), g_bytes_get_data (body, NULL), g_bytes_get_size (body)); g_free (md5); + g_bytes_unref (body); g_object_unref (msg); soup_test_session_abort_unref (session); } @@ -1031,6 +1032,7 @@ do_early_respond_test (ServerData *sd, gconstpointer test_data) SoupSession *session; SoupMessage *msg; SoupURI *uri2; + GBytes *body; server_add_early_handler (sd, NULL, early_respond_callback, NULL, NULL); @@ -1038,7 +1040,7 @@ do_early_respond_test (ServerData *sd, gconstpointer test_data) /* The early handler will intercept, and the normal handler will be skipped */ msg = soup_message_new_from_uri ("GET", sd->base_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_FORBIDDEN); g_assert_cmpint (msg->response_body->length, ==, 0); g_object_unref (msg); @@ -1046,9 +1048,10 @@ do_early_respond_test (ServerData *sd, gconstpointer test_data) /* The early handler will ignore this one */ uri2 = soup_uri_new_with_base (sd->base_uri, "/subdir"); msg = soup_message_new_from_uri ("GET", uri2); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); - g_assert_cmpstr (msg->response_body->data, ==, "index"); + g_assert_cmpmem ("index", sizeof ("index") - 1, g_bytes_get_data (body, NULL), g_bytes_get_size (body)); + g_bytes_unref (body); g_object_unref (msg); soup_uri_free (uri2); @@ -1069,6 +1072,7 @@ do_early_multi_test (ServerData *sd, gconstpointer test_data) SoupSession *session; SoupMessage *msg; SoupURI *uri; + GBytes *body; struct { const char *path; gboolean expect_normal, expect_early; @@ -1102,7 +1106,7 @@ do_early_multi_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); soup_uri_free (uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); /* The normal handler sets status to OK. The early handler doesn't * touch status, meaning that if it runs and the normal handler doesn't, @@ -1123,10 +1127,11 @@ do_early_multi_test (ServerData *sd, gconstpointer test_data) else g_assert_cmpstr (header, ==, NULL); if (multi_tests[i].expect_normal) - g_assert_cmpstr (msg->response_body->data, ==, "index"); + g_assert_cmpmem ("index", sizeof ("index") - 1, g_bytes_get_data (body, NULL), g_bytes_get_size (body)); else - g_assert_cmpint (msg->response_body->length, ==, 0); + g_assert_cmpint (g_bytes_get_size (body), ==, 0); + g_bytes_unref (body); g_object_unref (msg); } @@ -1376,7 +1381,7 @@ do_steal_connect_test (ServerData *sd, gconstpointer test_data) SOUP_SESSION_PROXY_RESOLVER, resolver, NULL); msg = soup_message_new_from_uri ("GET", sd->ssl_base_uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, SOUP_STATUS_OK); handled_by = soup_message_headers_get_one (msg->response_headers, "X-Handled-By"); diff --git a/tests/session-test.c b/tests/session-test.c index f26ee3b6..a3952f7d 100644 --- a/tests/session-test.c +++ b/tests/session-test.c @@ -65,13 +65,15 @@ do_test_for_session (SoupSession *session, SoupURI *uri, gboolean finished, local_timeout; guint timeout_id; SoupURI *timeout_uri; + GBytes *body; debug_printf (1, " queue_message\n"); debug_printf (2, " requesting timeout\n"); timeout_uri = soup_uri_new_with_base (uri, "/request-timeout"); msg = soup_message_new_from_uri ("GET", timeout_uri); soup_uri_free (timeout_uri); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); + g_bytes_unref (body); g_object_unref (msg); msg = soup_message_new_from_uri ("GET", uri); @@ -102,7 +104,8 @@ do_test_for_session (SoupSession *session, SoupURI *uri, msg = soup_message_new_from_uri ("GET", uri); server_processed_message = local_timeout = FALSE; timeout_id = g_idle_add_full (G_PRIORITY_HIGH, timeout_cb, &local_timeout, NULL); - soup_session_send_message (session, msg); + body = soup_test_session_send (session, msg, NULL, NULL); + g_bytes_unref (body); g_object_unref (msg); g_assert_true (server_processed_message); diff --git a/tests/ssl-test.c b/tests/ssl-test.c index 4e0f10e8..1422834a 100644 --- a/tests/ssl-test.c +++ b/tests/ssl-test.c @@ -46,7 +46,7 @@ do_strictness_test (gconstpointer data) } msg = soup_message_new_from_uri ("GET", uri); - soup_session_send_message (session, msg); + soup_test_session_send_message (session, msg); soup_test_assert_message_status (msg, test->expected_status); g_test_bug ("690176"); diff --git a/tests/test-utils.c b/tests/test-utils.c index 92560982..2819f8e7 100644 --- a/tests/test-utils.c +++ b/tests/test-utils.c @@ -381,6 +381,19 @@ soup_test_session_async_send_message (SoupSession *session, return msg->status_code; } +guint +soup_test_session_send_message (SoupSession *session, + SoupMessage *msg) +{ + GInputStream *stream; + + stream = soup_session_send (session, msg, NULL, NULL); + if (stream) + g_object_unref (stream); + + return msg->status_code; +} + static void server_listen (SoupServer *server) { @@ -798,6 +811,33 @@ soup_test_request_close_stream (SoupRequest *req, return ok; } +GBytes * +soup_test_session_send (SoupSession *session, + SoupMessage *msg, + GCancellable *cancellable, + GError **error) +{ + GInputStream *istream; + GOutputStream *ostream; + GBytes *body; + + istream = soup_session_send (session, msg, cancellable, error); + if (!istream) + return NULL; + + ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); + g_output_stream_splice (ostream, + istream, + G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, + NULL, NULL); + body = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (ostream)); + g_object_unref (ostream); + g_object_unref (istream); + + return body; +} + void soup_test_register_resources (void) { diff --git a/tests/test-utils.h b/tests/test-utils.h index 67392056..57ad54ef 100644 --- a/tests/test-utils.h +++ b/tests/test-utils.h @@ -57,6 +57,8 @@ GBytes *soup_test_session_async_send (SoupSession *session, SoupMessage *msg); guint soup_test_session_async_send_message (SoupSession *session, SoupMessage *msg); +guint soup_test_session_send_message (SoupSession *session, + SoupMessage *msg); typedef enum { SOUP_TEST_SERVER_DEFAULT = 0, @@ -82,6 +84,10 @@ gboolean soup_test_request_close_stream (SoupRequest *req, GInputStream *stream, GCancellable *cancellable, GError **error); +GBytes *soup_test_session_send (SoupSession *session, + SoupMessage *msg, + GCancellable *cancellable, + GError **error); void soup_test_register_resources (void); GBytes *soup_test_load_resource (const char *name, |
