From ae5a098159b40b741ab5030f880225249672384d Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Tue, 10 Feb 2009 17:24:23 +0000 Subject: Test user-agent handling --- tests/proxy.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/proxy.c b/tests/proxy.c index dbc6c01..cd3edd8 100644 --- a/tests/proxy.c +++ b/tests/proxy.c @@ -24,7 +24,6 @@ * TODO: * - port to gtest * - decide if status 3xx is success or failure - * - test user agent handling * - test query params * - test request headers * - test response headers @@ -77,6 +76,22 @@ server_callback (SoupServer *server, SoupMessage *msg, soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR); } } + else if (g_str_equal (path, "/useragent/none")) { + if (soup_message_headers_get (msg->request_headers, "User-Agent") == NULL) { + soup_message_set_status (msg, SOUP_STATUS_OK); + } else { + soup_message_set_status (msg, SOUP_STATUS_EXPECTATION_FAILED); + } + } + else if (g_str_equal (path, "/useragent/testsuite")) { + const char *value; + value = soup_message_headers_get (msg->request_headers, "User-Agent"); + if (g_strcmp0 (value, "TestSuite-1.0") == 0) { + soup_message_set_status (msg, SOUP_STATUS_OK); + } else { + soup_message_set_status (msg, SOUP_STATUS_EXPECTATION_FAILED); + } + } } static void @@ -234,6 +249,32 @@ status_error_test (RestProxy *proxy, int status) g_object_unref (call); } +static void +test_status_ok (RestProxy *proxy, const char *function) +{ + RestProxyCall *call; + GError *error = NULL; + + call = rest_proxy_new_call (proxy); + rest_proxy_call_set_function (call, function); + + if (!rest_proxy_call_run (call, NULL, &error)) { + g_printerr ("%s call failed: %s\n", function, error->message); + g_error_free (error); + errors++; + g_object_unref (call); + return; + } + + if (rest_proxy_call_get_status_code (call) != SOUP_STATUS_OK) { + g_printerr ("wrong response code, got %d\n", rest_proxy_call_get_status_code (call)); + errors++; + return; + } + + g_object_unref (call); +} + int main (int argc, char **argv) { @@ -264,5 +305,9 @@ main (int argc, char **argv) status_error_test (proxy, SOUP_STATUS_BAD_REQUEST); status_error_test (proxy, SOUP_STATUS_NOT_IMPLEMENTED); + test_status_ok (proxy, "useragent/none"); + rest_proxy_set_user_agent (proxy, "TestSuite-1.0"); + test_status_ok (proxy, "useragent/testsuite"); + return errors != 0; } -- cgit v1.2.1