summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2021-06-08 17:44:04 +0200
committerGünther Wagner <info@gunibert.de>2021-11-04 21:39:51 +0100
commitf014c22bbb1e5dd857d6e47c5acf5f58fc28cecf (patch)
tree586b94fb13ac152e717ae454bdb841c10a87a830 /tests
parente55578092e347a4fce887d5a278dc007204fa5cd (diff)
downloadlibrest-f014c22bbb1e5dd857d6e47c5acf5f58fc28cecf.tar.gz
Port to libsoup3
Diffstat (limited to 'tests')
-rw-r--r--tests/custom-serialize.c18
-rw-r--r--tests/proxy-continuous.c37
-rw-r--r--tests/proxy.c63
-rw-r--r--tests/threaded.c17
4 files changed, 128 insertions, 7 deletions
diff --git a/tests/custom-serialize.c b/tests/custom-serialize.c
index c92018b..6782897 100644
--- a/tests/custom-serialize.c
+++ b/tests/custom-serialize.c
@@ -88,22 +88,40 @@ custom_proxy_call_init (CustomProxyCall *self)
}
static void
+#ifdef WITH_SOUP_2
server_callback (SoupServer *server, SoupMessage *msg,
const char *path, GHashTable *query,
SoupClientContext *client, gpointer user_data)
+#else
+server_callback (SoupServer *server, SoupServerMessage *msg,
+ const char *path, GHashTable *query, gpointer user_data)
+#endif
{
if (g_str_equal (path, "/ping")) {
const char *content_type = NULL;
+#ifdef WITH_SOUP_2
SoupMessageHeaders *headers = msg->request_headers;
SoupMessageBody *body = msg->request_body;
+#else
+ SoupMessageHeaders *headers = soup_server_message_get_request_headers (msg);
+ SoupMessageBody *body = soup_server_message_get_request_body (msg);
+#endif
content_type = soup_message_headers_get_content_type (headers, NULL);
g_assert_cmpstr (content_type, ==, "application/json");
g_assert_cmpstr (body->data, ==, "{}");
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_OK);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#endif
} else {
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED, NULL);
+#endif
}
}
diff --git a/tests/proxy-continuous.c b/tests/proxy-continuous.c
index 54c1bb6..efc3de1 100644
--- a/tests/proxy-continuous.c
+++ b/tests/proxy-continuous.c
@@ -39,9 +39,15 @@ static SoupServer *server;
static gboolean
send_chunks (gpointer user_data)
{
- SoupMessage *msg = SOUP_MESSAGE (user_data);
guint i;
guint8 data[SIZE_CHUNK];
+#ifdef WITH_SOUP_2
+ SoupMessage *msg = SOUP_MESSAGE (user_data);
+ SoupMessageBody *response_body = msg->response_body;
+#else
+ SoupServerMessage *msg = SOUP_SERVER_MESSAGE (user_data);
+ SoupMessageBody *response_body = soup_server_message_get_response_body (msg);
+#endif
for (i = 0; i < SIZE_CHUNK; i++)
{
@@ -49,12 +55,12 @@ send_chunks (gpointer user_data)
server_count++;
}
- soup_message_body_append (msg->response_body, SOUP_MEMORY_COPY, data, SIZE_CHUNK);
+ soup_message_body_append (response_body, SOUP_MEMORY_COPY, data, SIZE_CHUNK);
soup_server_unpause_message (server, msg);
if (server_count == NUM_CHUNKS * SIZE_CHUNK)
{
- soup_message_body_complete (msg->response_body);
+ soup_message_body_complete (response_body);
return FALSE;
} else {
return TRUE;
@@ -62,13 +68,28 @@ send_chunks (gpointer user_data)
}
static void
+#ifdef WITH_SOUP_2
server_callback (SoupServer *server, SoupMessage *msg,
const char *path, GHashTable *query,
SoupClientContext *client, gpointer user_data)
+#else
+server_callback (SoupServer *server, SoupServerMessage *msg,
+ const char *path, GHashTable *query, gpointer user_data)
+#endif
{
+#ifdef WITH_SOUP_2
+ SoupMessageHeaders *response_headers = msg->response_headers;
+#else
+ SoupMessageHeaders *response_headers = soup_server_message_get_response_headers (msg);
+#endif
+
g_assert_cmpstr (path, ==, "/stream");
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_OK);
- soup_message_headers_set_encoding (msg->response_headers,
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#endif
+ soup_message_headers_set_encoding (response_headers,
SOUP_ENCODING_CHUNKED);
soup_server_pause_message (server, msg);
@@ -142,13 +163,21 @@ continuous ()
uris = soup_server_get_uris (server);
g_assert (g_slist_length (uris) > 0);
+#ifdef WITH_SOUP_2
url = soup_uri_to_string (uris->data, FALSE);
+#else
+ url = g_uri_to_string (uris->data);
+#endif
loop = g_main_loop_new (NULL, FALSE);
proxy = rest_proxy_new (url, FALSE);
stream_test (proxy);
+#ifdef WITH_SOUP_2
g_slist_free_full (uris, (GDestroyNotify)soup_uri_free);
+#else
+ g_slist_free_full (uris, (GDestroyNotify)g_uri_unref);
+#endif
g_main_loop_run (loop);
g_free (url);
diff --git a/tests/proxy.c b/tests/proxy.c
index 89a9325..652c600 100644
--- a/tests/proxy.c
+++ b/tests/proxy.c
@@ -49,20 +49,35 @@ SoupServer *server;
GMainLoop *server_loop;
static void
+#ifdef WITH_SOUP_2
server_callback (SoupServer *server, SoupMessage *msg,
const char *path, GHashTable *query,
SoupClientContext *client, gpointer user_data)
+#else
+server_callback (SoupServer *server, SoupServerMessage *msg,
+ const char *path, GHashTable *query, gpointer user_data)
+#endif
{
if (g_str_equal (path, "/ping")) {
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_OK);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#endif
}
else if (g_str_equal (path, "/echo")) {
const char *value;
value = g_hash_table_lookup (query, "value");
+#ifdef WITH_SOUP_2
soup_message_set_response (msg, "text/plain", SOUP_MEMORY_COPY,
value, strlen (value));
soup_message_set_status (msg, SOUP_STATUS_OK);
+#else
+ soup_server_message_set_response (msg, "text/plain", SOUP_MEMORY_COPY,
+ value, strlen (value));
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#endif
}
else if (g_str_equal (path, "/reverse")) {
char *value;
@@ -70,9 +85,15 @@ server_callback (SoupServer *server, SoupMessage *msg,
value = g_strdup (g_hash_table_lookup (query, "value"));
g_strreverse (value);
+#ifdef WITH_SOUP_2
soup_message_set_response (msg, "text/plain", SOUP_MEMORY_TAKE,
value, strlen (value));
soup_message_set_status (msg, SOUP_STATUS_OK);
+#else
+ soup_server_message_set_response (msg, "text/plain", SOUP_MEMORY_TAKE,
+ value, strlen (value));
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#endif
}
else if (g_str_equal (path, "/status")) {
const char *value;
@@ -81,25 +102,61 @@ server_callback (SoupServer *server, SoupMessage *msg,
value = g_hash_table_lookup (query, "status");
if (value) {
status = atoi (value);
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, status ?: SOUP_STATUS_INTERNAL_SERVER_ERROR);
+#else
+ soup_server_message_set_status (msg, status ?: SOUP_STATUS_INTERNAL_SERVER_ERROR, NULL);
+#endif
} else {
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, NULL);
+#endif
}
}
else if (g_str_equal (path, "/useragent/none")) {
- if (soup_message_headers_get (msg->request_headers, "User-Agent") == NULL) {
+#ifdef WITH_SOUP_2
+ SoupMessageHeaders *request_headers = msg->request_headers;
+#else
+ SoupMessageHeaders *request_headers = soup_server_message_get_request_headers (msg);
+#endif
+
+ if (soup_message_headers_get (request_headers, "User-Agent") == NULL) {
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_OK);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#endif
} else {
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_EXPECTATION_FAILED);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_EXPECTATION_FAILED, NULL);
+#endif
}
}
else if (g_str_equal (path, "/useragent/testsuite")) {
+#ifdef WITH_SOUP_2
+ SoupMessageHeaders *request_headers = msg->request_headers;
+#else
+ SoupMessageHeaders *request_headers = soup_server_message_get_request_headers (msg);
+#endif
const char *value;
- value = soup_message_headers_get (msg->request_headers, "User-Agent");
+ value = soup_message_headers_get (request_headers, "User-Agent");
if (g_strcmp0 (value, "TestSuite-1.0") == 0) {
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_OK);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#endif
} else {
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_EXPECTATION_FAILED);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_EXPECTATION_FAILED, NULL);
+#endif
+
}
}
}
@@ -325,7 +382,7 @@ main (int argc, char **argv)
char *url;
RestProxy *proxy;
- server = soup_server_new ("", NULL);
+ server = soup_server_new (NULL);
g_thread_new ("Server Thread", server_thread_func, NULL);
url = g_strdup_printf ("http://127.0.0.1:%d/", PORT);
diff --git a/tests/threaded.c b/tests/threaded.c
index a251900..411361c 100644
--- a/tests/threaded.c
+++ b/tests/threaded.c
@@ -36,13 +36,22 @@ GMainLoop *main_loop;
SoupServer *server;
static void
+#ifdef WITH_SOUP_2
server_callback (SoupServer *server, SoupMessage *msg,
const char *path, GHashTable *query,
SoupClientContext *client, gpointer user_data)
+#else
+server_callback (SoupServer *server, SoupServerMessage *msg,
+ const char *path, GHashTable *query, gpointer user_data)
+#endif
{
g_assert_cmpstr (path, ==, "/ping");
+#ifdef WITH_SOUP_2
soup_message_set_status (msg, SOUP_STATUS_OK);
+#else
+ soup_server_message_set_status (msg, SOUP_STATUS_OK, NULL);
+#endif
g_atomic_int_add (&threads_done, 1);
if (threads_done == N_THREADS) {
@@ -96,7 +105,11 @@ static void ping ()
uris = soup_server_get_uris (server);
g_assert (g_slist_length (uris) > 0);
+#ifdef WITH_SOUP_2
url = soup_uri_to_string (uris->data, FALSE);
+#else
+ url = g_uri_to_string (uris->data);
+#endif
main_loop = g_main_loop_new (NULL, TRUE);
@@ -109,7 +122,11 @@ static void ping ()
g_main_loop_run (main_loop);
g_free (url);
+#ifdef WITH_SOUP_2
g_slist_free_full (uris, (GDestroyNotify)soup_uri_free);
+#else
+ g_slist_free_full (uris, (GDestroyNotify)g_uri_unref);
+#endif
g_object_unref (server);
g_main_loop_unref (main_loop);
}