summaryrefslogtreecommitdiff
path: root/tests/coding-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/coding-test.c')
-rw-r--r--tests/coding-test.c690
1 files changed, 337 insertions, 353 deletions
diff --git a/tests/coding-test.c b/tests/coding-test.c
index 30417b47..0445f632 100644
--- a/tests/coding-test.c
+++ b/tests/coding-test.c
@@ -16,8 +16,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
{
const char *accept_encoding, *options;
GSList *codings;
- char *file = NULL, *contents;
- gsize length;
+ SoupBuffer *response = NULL;
options = soup_message_headers_get_one (msg->request_headers,
"X-Test-Options");
@@ -33,7 +32,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
if (codings) {
gboolean claim_deflate, claim_gzip;
- const char *file_path = NULL, *encoding = NULL;
+ const char *extension = NULL, *encoding = NULL;
claim_deflate = g_slist_find_custom (codings, "deflate", (GCompareFunc)g_ascii_strcasecmp) != NULL;
claim_gzip = g_slist_find_custom (codings, "gzip", (GCompareFunc)g_ascii_strcasecmp) != NULL;
@@ -41,44 +40,44 @@ server_callback (SoupServer *server, SoupMessage *msg,
if (claim_gzip && (!claim_deflate ||
(!soup_header_contains (options, "prefer-deflate-zlib") &&
!soup_header_contains (options, "prefer-deflate-raw")))) {
- file_path = SRCDIR "/resources%s.gz";
+ extension = "gz";
encoding = "gzip";
} else if (claim_deflate) {
if (soup_header_contains (options, "prefer-deflate-raw")) {
- file_path = SRCDIR "/resources%s.raw";
+ extension = "raw";
encoding = "deflate";
} else {
- file_path = SRCDIR "/resources%s.zlib";
+ extension = "zlib";
encoding = "deflate";
}
}
- if (file_path && encoding) {
- file = g_strdup_printf (file_path, path);
- if (g_file_test (file, G_FILE_TEST_EXISTS)) {
+ if (extension && encoding) {
+ char *resource;
+
+ resource = g_strdup_printf ("%s.%s", path, extension);
+ response = soup_test_load_resource (resource, NULL);
+
+ if (response) {
soup_message_headers_append (msg->response_headers,
"Content-Encoding",
encoding);
- } else {
- g_free (file);
- file = NULL;
}
+ g_free (resource);
}
}
soup_header_free_list (codings);
- if (!file)
- file = g_strdup_printf (SRCDIR "/resources%s", path);
- if (!g_file_get_contents (file, &contents, &length, NULL)) {
+ if (!response)
+ response = soup_test_load_resource (path, NULL);
+ if (!response) {
/* If path.gz exists but can't be read, we'll send back
* the error with "Content-Encoding: gzip" but there's
* no body, so, eh.
*/
- g_free (file);
soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
return;
}
- g_free (file);
if (soup_header_contains (options, "force-encode")) {
const gchar *encoding = "gzip";
@@ -106,11 +105,9 @@ server_callback (SoupServer *server, SoupMessage *msg,
soup_message_set_status (msg, SOUP_STATUS_OK);
soup_message_headers_set_encoding (msg->response_headers, SOUP_ENCODING_CHUNKED);
- if (!soup_header_contains (options, "empty")) {
- soup_message_body_append (msg->response_body,
- SOUP_MEMORY_TAKE, contents, length);
- } else
- g_free (contents);
+ if (!soup_header_contains (options, "empty"))
+ soup_message_body_append_buffer (msg->response_body, response);
+ soup_buffer_free (response);
if (soup_header_contains (options, "trailing-junk")) {
soup_message_body_append (msg->response_body, SOUP_MEMORY_COPY,
@@ -119,6 +116,20 @@ server_callback (SoupServer *server, SoupMessage *msg,
soup_message_body_complete (msg->response_body);
}
+typedef struct {
+ SoupSession *session;
+ SoupMessage *msg;
+ SoupRequest *req;
+ SoupBuffer *response;
+} CodingTestData;
+
+typedef enum {
+ CODING_TEST_DEFAULT = 0,
+ CODING_TEST_NO_DECODER = (1 << 0),
+ CODING_TEST_REQUEST_API = (1 << 1),
+ CODING_TEST_EMPTY = (1 << 2)
+} CodingTestType;
+
typedef enum {
NO_CHECK,
EXPECT_DECODED,
@@ -126,184 +137,189 @@ typedef enum {
} MessageContentStatus;
static void
-check_response (SoupMessage *msg,
+check_response (CodingTestData *data,
const char *expected_encoding,
const char *expected_content_type,
- MessageContentStatus status)
+ MessageContentStatus status,
+ GByteArray *body)
{
const char *coding, *type;
- if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- debug_printf (1, " Unexpected status %d %s\n",
- msg->status_code, msg->reason_phrase);
- errors++;
- }
+ soup_test_assert_message_status (data->msg, SOUP_STATUS_OK);
- coding = soup_message_headers_get_one (msg->response_headers, "Content-Encoding");
- if (expected_encoding) {
- if (!coding || g_ascii_strcasecmp (coding, expected_encoding) != 0) {
- debug_printf (1, " Unexpected Content-Encoding: %s\n",
- coding ? coding : "(none)");
- errors++;
- }
- } else {
- if (coding) {
- debug_printf (1, " Unexpected Content-Encoding: %s\n",
- coding);
- errors++;
- }
- }
+ coding = soup_message_headers_get_one (data->msg->response_headers, "Content-Encoding");
+ g_assert_cmpstr (coding, ==, expected_encoding);
if (status != NO_CHECK) {
- if (status == EXPECT_DECODED) {
- if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_CONTENT_DECODED)) {
- debug_printf (1, " SOUP_MESSAGE_CONTENT_DECODED not set!\n");
- errors++;
- }
- } else {
- if (soup_message_get_flags (msg) & SOUP_MESSAGE_CONTENT_DECODED) {
- debug_printf (1, " SOUP_MESSAGE_CONTENT_DECODED set!\n");
- errors++;
- }
- }
+ if (status == EXPECT_DECODED)
+ g_assert_true (soup_message_get_flags (data->msg) & SOUP_MESSAGE_CONTENT_DECODED);
+ else
+ g_assert_false (soup_message_get_flags (data->msg) & SOUP_MESSAGE_CONTENT_DECODED);
}
- type = soup_message_headers_get_one (msg->response_headers, "Content-Type");
- if (!type || g_ascii_strcasecmp (type, expected_content_type) != 0) {
- debug_printf (1, " Unexpected Content-Type: %s\n",
- type ? type : "(none)");
- errors++;
+ type = soup_message_headers_get_one (data->msg->response_headers, "Content-Type");
+ g_assert_cmpstr (type, ==, expected_content_type);
+
+ if (body) {
+ soup_assert_cmpmem (body->data,
+ body->len,
+ data->response->data,
+ data->response->length);
+ } else {
+ soup_assert_cmpmem (data->msg->response_body->data,
+ data->msg->response_body->length,
+ data->response->data,
+ data->response->length);
}
}
static void
-check_msg_bodies (SoupMessage *msg1,
- SoupMessage *msg2,
- const char *msg1_type,
- const char *msg2_type)
+setup_coding_test (CodingTestData *data, gconstpointer test_data)
{
- if (msg1->response_body->length != msg2->response_body->length) {
- debug_printf (1, " Message length mismatch: %lu (%s) vs %lu (%s)\n",
- (gulong)msg1->response_body->length,
- msg1_type,
- (gulong)msg2->response_body->length,
- msg2_type);
- errors++;
- } else if (memcmp (msg1->response_body->data,
- msg2->response_body->data,
- msg1->response_body->length) != 0) {
- debug_printf (1, " Message data mismatch (%s/%s)\n",
- msg1_type, msg2_type);
- errors++;
+ CodingTestType test_type = GPOINTER_TO_INT (test_data);
+ SoupMessage *msg;
+ SoupURI *uri;
+
+ data->session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
+ SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
+ NULL);
+
+ uri = soup_uri_new_with_base (base_uri, "/mbox");
+
+ if (test_type & CODING_TEST_EMPTY)
+ data->response = soup_buffer_new (SOUP_MEMORY_STATIC, "", 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);
+ g_object_unref (msg);
}
+
+ if (test_type & CODING_TEST_REQUEST_API) {
+ SoupRequestHTTP *reqh;
+
+ reqh = soup_session_request_http_uri (data->session, "GET", uri, NULL);
+ data->req = SOUP_REQUEST (reqh);
+ data->msg = soup_request_http_get_message (reqh);
+ } else
+ data->msg = soup_message_new_from_uri ("GET", uri);
+ soup_uri_free (uri);
+
+ if (! (test_type & CODING_TEST_NO_DECODER))
+ soup_session_add_feature_by_type (data->session, SOUP_TYPE_CONTENT_DECODER);
}
static void
-do_coding_test (void)
+teardown_coding_test (CodingTestData *data, gconstpointer test_data)
{
- SoupSession *session;
- SoupMessage *msg, *msgz, *msgj, *msge, *msgzl, *msgzlj, *msgzle, *msgzlr, *msgzlre;
- SoupURI *uri;
+ soup_buffer_free (data->response);
- debug_printf (1, "SoupMessage tests\n");
+ g_clear_object (&data->req);
+ g_object_unref (data->msg);
- session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
- uri = soup_uri_new_with_base (base_uri, "/mbox");
+ soup_test_session_abort_unref (data->session);
+}
- /* Plain text data, no claim */
- debug_printf (1, " GET /mbox, plain\n");
- msg = soup_message_new_from_uri ("GET", uri);
- soup_session_send_message (session, msg);
- check_response (msg, NULL, "text/plain", EXPECT_NOT_DECODED);
-
- /* Plain text data, claim gzip */
- debug_printf (1, " GET /mbox, Accept-Encoding: gzip\n");
- soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_DECODER);
- msgz = soup_message_new_from_uri ("GET", uri);
- soup_session_send_message (session, msgz);
- check_response (msgz, "gzip", "text/plain", EXPECT_DECODED);
- check_msg_bodies (msg, msgz, "plain", "compressed");
-
- /* Plain text data, claim gzip w/ junk */
- debug_printf (1, " GET /mbox, Accept-Encoding: gzip, plus trailing junk\n");
- msgj = soup_message_new_from_uri ("GET", uri);
- soup_message_headers_append (msgj->request_headers,
+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);
+}
+
+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);
+}
+
+static void
+do_coding_test_gzip_with_junk (CodingTestData *data, gconstpointer test_data)
+{
+ 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 (session, msgj);
- check_response (msgj, "gzip", "text/plain", EXPECT_DECODED);
- check_msg_bodies (msg, msgj, "plain", "compressed w/ junk");
-
- /* Plain text data, claim gzip with server error */
- debug_printf (1, " GET /mbox, Accept-Encoding: gzip, with server error\n");
- msge = soup_message_new_from_uri ("GET", uri);
- soup_message_headers_append (msge->request_headers,
+
+ soup_session_send_message (data->session, data->msg);
+ check_response (data, "gzip", "text/plain", EXPECT_DECODED, NULL);
+}
+
+static void
+do_coding_test_gzip_bad_server (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("613361");
+
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "force-encode");
- soup_session_send_message (session, msge);
- check_response (msge, "gzip", "text/plain", EXPECT_NOT_DECODED);
+
+ soup_session_send_message (data->session, data->msg);
/* Failed content-decoding should have left the body untouched
* from what the server sent... which happens to be the
* uncompressed data.
*/
- check_msg_bodies (msg, msge, "plain", "mis-encoded");
+ check_response (data, "gzip", "text/plain", EXPECT_NOT_DECODED, NULL);
+}
- /* Plain text data, claim deflate */
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate\n");
- msgzl = soup_message_new_from_uri ("GET", uri);
- soup_message_headers_append (msgzl->request_headers,
+static void
+do_coding_test_deflate (CodingTestData *data, gconstpointer test_data)
+{
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "prefer-deflate-zlib");
- soup_session_send_message (session, msgzl);
- check_response (msgzl, "deflate", "text/plain", EXPECT_DECODED);
- check_msg_bodies (msg, msgzl, "plain", "compressed");
-
- /* Plain text data, claim deflate w/ junk */
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate, plus trailing junk\n");
- msgzlj = soup_message_new_from_uri ("GET", uri);
- soup_message_headers_append (msgzlj->request_headers,
+ soup_session_send_message (data->session, data->msg);
+
+ check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL);
+}
+
+static void
+do_coding_test_deflate_with_junk (CodingTestData *data, gconstpointer test_data)
+{
+ 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 (session, msgzlj);
- check_response (msgzlj, "deflate", "text/plain", EXPECT_DECODED);
- check_msg_bodies (msg, msgzlj, "plain", "compressed w/ junk");
-
- /* Plain text data, claim deflate with server error */
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate, with server error\n");
- msgzle = soup_message_new_from_uri ("GET", uri);
- soup_message_headers_append (msgzle->request_headers,
+ soup_session_send_message (data->session, data->msg);
+
+ check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL);
+}
+
+static void
+do_coding_test_deflate_bad_server (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("613361");
+
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "force-encode, prefer-deflate-zlib");
- soup_session_send_message (session, msgzle);
- check_response (msgzle, "deflate", "text/plain", EXPECT_NOT_DECODED);
- check_msg_bodies (msg, msgzle, "plain", "mis-encoded");
-
- /* Plain text data, claim deflate (no zlib headers)*/
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate (raw data)\n");
- msgzlr = soup_message_new_from_uri ("GET", uri);
- soup_message_headers_append (msgzlr->request_headers,
+ soup_session_send_message (data->session, data->msg);
+
+ check_response (data, "deflate", "text/plain", EXPECT_NOT_DECODED, NULL);
+}
+
+static void
+do_coding_test_deflate_raw (CodingTestData *data, gconstpointer test_data)
+{
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "prefer-deflate-raw");
- soup_session_send_message (session, msgzlr);
- check_response (msgzlr, "deflate", "text/plain", EXPECT_DECODED);
- check_msg_bodies (msg, msgzlr, "plain", "compressed");
-
- /* Plain text data, claim deflate with server error */
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate (raw data), with server error\n");
- msgzlre = soup_message_new_from_uri ("GET", uri);
- soup_message_headers_append (msgzlre->request_headers,
+ soup_session_send_message (data->session, data->msg);
+
+ check_response (data, "deflate", "text/plain", EXPECT_DECODED, NULL);
+}
+
+static void
+do_coding_test_deflate_raw_bad_server (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("613361");
+
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "force-encode, prefer-deflate-raw");
- soup_session_send_message (session, msgzlre);
- check_response (msgzlre, "deflate", "text/plain", EXPECT_NOT_DECODED);
- check_msg_bodies (msg, msgzlre, "plain", "mis-encoded");
-
- g_object_unref (msg);
- g_object_unref (msgzlre);
- g_object_unref (msgzlr);
- g_object_unref (msgzlj);
- g_object_unref (msgzle);
- g_object_unref (msgzl);
- g_object_unref (msgz);
- g_object_unref (msgj);
- g_object_unref (msge);
- soup_uri_free (uri);
+ soup_session_send_message (data->session, data->msg);
- soup_test_session_abort_unref (session);
+ check_response (data, "deflate", "text/plain", EXPECT_NOT_DECODED, NULL);
}
static void
@@ -314,36 +330,29 @@ read_finished (GObject *stream, GAsyncResult *result, gpointer user_data)
*nread = g_input_stream_read_finish (G_INPUT_STREAM (stream),
result, &error);
- if (error) {
- debug_printf (1, " Error reading: %s\n",
- error->message);
- g_error_free (error);
- errors++;
- }
+ g_assert_no_error (error);
+ g_clear_error (&error);
}
-static GByteArray *
-do_single_coding_req_test (SoupRequestHTTP *reqh,
+static void
+do_single_coding_req_test (CodingTestData *data,
const char *expected_encoding,
const char *expected_content_type,
MessageContentStatus status)
{
GInputStream *stream;
- SoupMessage *msg;
- GByteArray *data;
+ GByteArray *body;
guchar buf[1024];
gssize nread;
GError *error = NULL;
- data = g_byte_array_new ();
+ body = g_byte_array_new ();
- stream = soup_test_request_send (SOUP_REQUEST (reqh), NULL, 0, &error);
- if (error) {
- debug_printf (1, " Error sending request: %s\n",
- error->message);
+ stream = soup_test_request_send (data->req, NULL, 0, &error);
+ if (!stream) {
+ g_assert_no_error (error);
g_error_free (error);
- errors++;
- return data;
+ return;
}
do {
@@ -355,212 +364,126 @@ do_single_coding_req_test (SoupRequestHTTP *reqh,
g_main_context_iteration (NULL, TRUE);
if (nread > 0)
- g_byte_array_append (data, buf, nread);
+ g_byte_array_append (body, buf, nread);
} while (nread > 0);
- soup_test_request_close_stream (SOUP_REQUEST (reqh), stream, NULL, &error);
- if (error) {
- debug_printf (1, " error closing stream: %s\n",
- error->message);
- g_error_free (error);
- errors++;
- }
+ soup_test_request_close_stream (data->req, stream, NULL, &error);
+ g_assert_no_error (error);
+ g_clear_error (&error);
g_object_unref (stream);
- msg = soup_request_http_get_message (reqh);
- check_response (msg, expected_encoding, expected_content_type, status);
- g_object_unref (msg);
+ check_response (data, expected_encoding, expected_content_type, status, body);
+ g_byte_array_free (body, TRUE);
+}
- return data;
+static void
+do_coding_req_test_plain (CodingTestData *data, gconstpointer test_data)
+{
+ do_single_coding_req_test (data, NULL, "text/plain", EXPECT_NOT_DECODED);
}
static void
-check_req_bodies (GByteArray *body1,
- GByteArray *body2,
- const char *msg1_type,
- const char *msg2_type)
+do_coding_req_test_gzip (CodingTestData *data, gconstpointer test_data)
{
- if (body1->len != body2->len) {
- debug_printf (1, " Message length mismatch: %lu (%s) vs %lu (%s)\n",
- (gulong)body1->len, msg1_type,
- (gulong)body2->len, msg2_type);
- errors++;
- } else if (memcmp (body1->data, body2->data, body1->len) != 0) {
- debug_printf (1, " Message data mismatch (%s/%s)\n",
- msg1_type, msg2_type);
- errors++;
- }
+ do_single_coding_req_test (data, "gzip", "text/plain", EXPECT_DECODED);
}
static void
-do_coding_req_test (void)
+do_coding_req_test_gzip_with_junk (CodingTestData *data, gconstpointer test_data)
{
- SoupSession *session;
- SoupRequestHTTP *reqh;
- SoupMessage *msg;
- SoupURI *uri;
- GByteArray *plain, *cmp;
+ g_test_bug ("606352");
+ g_test_bug ("676477");
- debug_printf (1, "\nSoupRequest tests\n");
+ soup_message_headers_append (data->msg->request_headers,
+ "X-Test-Options", "trailing-junk");
- session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
- SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
- NULL);
- uri = soup_uri_new_with_base (base_uri, "/mbox");
+ do_single_coding_req_test (data, "gzip", "text/plain", EXPECT_DECODED);
+}
- /* Plain text data, no claim */
- debug_printf (1, " GET /mbox, plain\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- plain = do_single_coding_req_test (reqh, NULL, "text/plain", EXPECT_NOT_DECODED);
- g_object_unref (reqh);
-
- /* Plain text data, claim gzip */
- debug_printf (1, " GET /mbox, Accept-Encoding: gzip\n");
- soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_DECODER);
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- cmp = do_single_coding_req_test (reqh, "gzip", "text/plain", EXPECT_DECODED);
- check_req_bodies (plain, cmp, "plain", "compressed");
- g_byte_array_free (cmp, TRUE);
- g_object_unref (reqh);
-
- /* Plain text data, claim gzip w/ junk */
- debug_printf (1, " GET /mbox, Accept-Encoding: gzip, plus trailing junk\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- msg = soup_request_http_get_message (reqh);
- soup_message_headers_append (msg->request_headers,
- "X-Test-Options", "trailing-junk");
- g_object_unref (msg);
- cmp = do_single_coding_req_test (reqh, "gzip", "text/plain", EXPECT_DECODED);
- check_req_bodies (plain, cmp, "plain", "compressed w/ junk");
- g_byte_array_free (cmp, TRUE);
- g_object_unref (reqh);
-
- /* Plain text data, claim gzip with server error */
- debug_printf (1, " GET /mbox, Accept-Encoding: gzip, with server error\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- msg = soup_request_http_get_message (reqh);
- soup_message_headers_append (msg->request_headers,
+static void
+do_coding_req_test_gzip_bad_server (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("613361");
+
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "force-encode");
- g_object_unref (msg);
- cmp = do_single_coding_req_test (reqh, "gzip", "text/plain", EXPECT_NOT_DECODED);
+ do_single_coding_req_test (data, "gzip", "text/plain", EXPECT_NOT_DECODED);
+}
- /* Failed content-decoding should have left the body untouched
- * from what the server sent... which happens to be the
- * uncompressed data.
- */
- check_req_bodies (plain, cmp, "plain", "mis-encoded");
- g_byte_array_free (cmp, TRUE);
- g_object_unref (reqh);
-
- /* Plain text data, claim deflate */
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- msg = soup_request_http_get_message (reqh);
- soup_message_headers_append (msg->request_headers,
+static void
+do_coding_req_test_deflate (CodingTestData *data, gconstpointer test_data)
+{
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "prefer-deflate-zlib");
- g_object_unref (msg);
- cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_DECODED);
- check_req_bodies (plain, cmp, "plain", "compressed");
- g_byte_array_free (cmp, TRUE);
- g_object_unref (reqh);
-
- /* Plain text data, claim deflate w/ junk */
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate, plus trailing junk\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- msg = soup_request_http_get_message (reqh);
- soup_message_headers_append (msg->request_headers,
+ do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_DECODED);
+}
+
+static void
+do_coding_req_test_deflate_with_junk (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("606352");
+ g_test_bug ("676477");
+
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "prefer-deflate-zlib, trailing-junk");
- g_object_unref (msg);
- cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_DECODED);
- check_req_bodies (plain, cmp, "plain", "compressed w/ junk");
- g_byte_array_free (cmp, TRUE);
- g_object_unref (reqh);
-
- /* Plain text data, claim deflate with server error */
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate, with server error\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- msg = soup_request_http_get_message (reqh);
- soup_message_headers_append (msg->request_headers,
- "X-Test-Options", "force-encode, prefer-deflate-zlib");
- g_object_unref (msg);
- cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_NOT_DECODED);
- check_req_bodies (plain, cmp, "plain", "mis-encoded");
- g_byte_array_free (cmp, TRUE);
- g_object_unref (reqh);
-
- /* Plain text data, claim deflate (no zlib headers)*/
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate (raw data)\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- msg = soup_request_http_get_message (reqh);
- soup_message_headers_append (msg->request_headers,
- "X-Test-Options", "prefer-deflate-raw");
- g_object_unref (msg);
- cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_DECODED);
- check_req_bodies (plain, cmp, "plain", "compressed");
- g_byte_array_free (cmp, TRUE);
- g_object_unref (reqh);
-
- /* Plain text data, claim deflate with server error */
- debug_printf (1, " GET /mbox, Accept-Encoding: deflate (raw data), with server error\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- msg = soup_request_http_get_message (reqh);
- soup_message_headers_append (msg->request_headers,
- "X-Test-Options", "force-encode, prefer-deflate-raw");
- g_object_unref (msg);
- cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_NOT_DECODED);
- check_req_bodies (plain, cmp, "plain", "mis-encoded");
- g_byte_array_free (cmp, TRUE);
- g_object_unref (reqh);
+ do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_DECODED);
+}
- g_byte_array_free (plain, TRUE);
- soup_uri_free (uri);
+static void
+do_coding_req_test_deflate_bad_server (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("613361");
- soup_test_session_abort_unref (session);
+ soup_message_headers_append (data->msg->request_headers,
+ "X-Test-Options", "force-encode, prefer-deflate-zlib");
+ do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_NOT_DECODED);
}
static void
-do_coding_empty_test (void)
+do_coding_req_test_deflate_raw (CodingTestData *data, gconstpointer test_data)
{
- SoupSession *session;
- SoupMessage *msg;
- SoupURI *uri;
- SoupRequestHTTP *reqh;
- GByteArray *body;
+ soup_message_headers_append (data->msg->request_headers,
+ "X-Test-Options", "prefer-deflate-raw");
+ do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_DECODED);
+}
- debug_printf (1, "\nEmpty allegedly-encoded body test\n");
+static void
+do_coding_req_test_deflate_raw_bad_server (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("613361");
- session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
- SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
- SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
- NULL);
- uri = soup_uri_new_with_base (base_uri, "/mbox");
+ soup_message_headers_append (data->msg->request_headers,
+ "X-Test-Options", "force-encode, prefer-deflate-raw");
+ do_single_coding_req_test (data, "deflate", "text/plain", EXPECT_NOT_DECODED);
+}
- debug_printf (1, " SoupMessage\n");
- msg = soup_message_new_from_uri ("GET", uri);
- soup_message_headers_append (msg->request_headers,
- "X-Test-Options", "empty");
- soup_session_send_message (session, msg);
- check_response (msg, "gzip", "text/plain", EXPECT_NOT_DECODED);
- g_object_unref (msg);
-
- debug_printf (1, " SoupRequest\n");
- reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
- msg = soup_request_http_get_message (reqh);
- soup_message_headers_append (msg->request_headers,
+static void
+do_coding_msg_empty_test (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("697527");
+
+ soup_message_headers_append (data->msg->request_headers,
"X-Test-Options", "empty");
- g_object_unref (msg);
- body = do_single_coding_req_test (reqh, "gzip", "text/plain", EXPECT_NOT_DECODED);
- g_byte_array_free (body, TRUE);
- g_object_unref (reqh);
+ soup_session_send_message (data->session, data->msg);
- soup_uri_free (uri);
- soup_test_session_abort_unref (session);
+ check_response (data, "gzip", "text/plain", EXPECT_NOT_DECODED, NULL);
}
+static void
+do_coding_req_empty_test (CodingTestData *data, gconstpointer test_data)
+{
+ g_test_bug ("697527");
+
+ soup_message_headers_append (data->msg->request_headers,
+ "X-Test-Options", "empty");
+ do_single_coding_req_test (data, "gzip", "text/plain", EXPECT_NOT_DECODED);
+}
int
main (int argc, char **argv)
{
+ int ret;
+
test_init (argc, argv, NULL);
server = soup_test_server_new (TRUE);
@@ -568,13 +491,74 @@ main (int argc, char **argv)
base_uri = soup_uri_new ("http://127.0.0.1/");
soup_uri_set_port (base_uri, soup_server_get_port (server));
- do_coding_test ();
- do_coding_req_test ();
- do_coding_empty_test ();
+ g_test_add ("/coding/message/plain", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_NO_DECODER),
+ setup_coding_test, do_coding_test_plain, teardown_coding_test);
+ g_test_add ("/coding/message/gzip", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_DEFAULT),
+ setup_coding_test, do_coding_test_gzip, teardown_coding_test);
+ g_test_add ("/coding/message/gzip/with-junk", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_DEFAULT),
+ setup_coding_test, do_coding_test_gzip_with_junk, teardown_coding_test);
+ g_test_add ("/coding/message/gzip/bad-server", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_DEFAULT),
+ setup_coding_test, do_coding_test_gzip_bad_server, teardown_coding_test);
+ g_test_add ("/coding/message/deflate", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_DEFAULT),
+ setup_coding_test, do_coding_test_deflate, teardown_coding_test);
+ g_test_add ("/coding/message/deflate/with-junk", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_DEFAULT),
+ setup_coding_test, do_coding_test_deflate_with_junk, teardown_coding_test);
+ g_test_add ("/coding/message/deflate/bad-server", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_DEFAULT),
+ setup_coding_test, do_coding_test_deflate_bad_server, teardown_coding_test);
+ g_test_add ("/coding/message/deflate-raw", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_DEFAULT),
+ setup_coding_test, do_coding_test_deflate_raw, teardown_coding_test);
+ g_test_add ("/coding/message/deflate-raw/bad-server", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_DEFAULT),
+ setup_coding_test, do_coding_test_deflate_raw_bad_server, teardown_coding_test);
+
+ g_test_add ("/coding/request/plain", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_NO_DECODER | CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_plain, teardown_coding_test);
+ g_test_add ("/coding/request/gzip", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_gzip, teardown_coding_test);
+ g_test_add ("/coding/request/gzip/with-junk", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_gzip_with_junk, teardown_coding_test);
+ g_test_add ("/coding/request/gzip/bad-server", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_gzip_bad_server, teardown_coding_test);
+ g_test_add ("/coding/request/deflate", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_deflate, teardown_coding_test);
+ g_test_add ("/coding/request/deflate/with-junk", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_deflate_with_junk, teardown_coding_test);
+ g_test_add ("/coding/request/deflate/bad-server", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_deflate_bad_server, teardown_coding_test);
+ g_test_add ("/coding/request/deflate-raw", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_deflate_raw, teardown_coding_test);
+ g_test_add ("/coding/request/deflate-raw/bad-server", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API),
+ setup_coding_test, do_coding_req_test_deflate_raw_bad_server, teardown_coding_test);
+
+ g_test_add ("/coding/message/empty", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_EMPTY),
+ setup_coding_test, do_coding_msg_empty_test, teardown_coding_test);
+ g_test_add ("/coding/request/empty", CodingTestData,
+ GINT_TO_POINTER (CODING_TEST_REQUEST_API | CODING_TEST_EMPTY),
+ setup_coding_test, do_coding_req_empty_test, teardown_coding_test);
+
+ ret = g_test_run ();
soup_uri_free (base_uri);
soup_test_server_quit_unref (server);
test_cleanup ();
- return errors != 0;
+ return ret;
}