[libsoup/server-api: 5/6] tests: port old tests to new SoupServer APIs, add some new tests
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/server-api: 5/6] tests: port old tests to new SoupServer APIs, add some new tests
- Date: Sun, 16 Mar 2014 02:25:39 +0000 (UTC)
commit af4a36ec5750cfb7970111a89d3705368cb9f1fa
Author: Dan Winship <danw gnome org>
Date: Sun Mar 9 10:04:36 2014 -0400
tests: port old tests to new SoupServer APIs, add some new tests
tests/auth-test.c | 16 +--
tests/cache-test.c | 3 +-
tests/chunk-io-test.c | 6 +-
tests/chunk-test.c | 8 +-
tests/coding-test.c | 5 +-
tests/connection-test.c | 13 ++-
tests/context-test.c | 10 +-
tests/continue-test.c | 47 +++++----
tests/cookies-test.c | 10 ++-
tests/forms-test.c | 24 +++--
tests/misc-test.c | 54 ++++-------
tests/multipart-test.c | 5 +-
tests/no-ssl-test.c | 18 ++--
tests/ntlm-test.c | 11 +--
tests/proxy-test.c | 5 +-
tests/range-test.c | 14 ++-
tests/redirect-test.c | 20 ++--
tests/requester-test.c | 73 ++++++++-------
tests/server-auth-test.c | 11 +--
tests/server-test.c | 176 ++++++++++++++++++++++++++++-----
tests/session-test.c | 49 +++++-----
tests/sniffing-test.c | 5 +-
tests/socket-test.c | 8 +-
tests/ssl-test.c | 23 +++--
tests/streaming-test.c | 7 +-
tests/test-utils.c | 234 +++++++++++++++++++++++++++++++++++---------
tests/test-utils.h | 14 ++-
tests/timeout-test.c | 48 +++++-----
tests/xmlrpc-server-test.c | 9 +-
29 files changed, 596 insertions(+), 330 deletions(-)
---
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 8ed5cea..f69501e 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -864,12 +864,10 @@ do_select_auth_test (void)
* side of this scenario correctly, because we test it against
* curl in server-auth-test.
*/
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL,
server_callback, NULL, NULL);
-
- uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (uri, soup_server_get_port (server));
+ uri = soup_test_server_get_uri (server, "http", NULL);
basic_auth_domain = soup_auth_domain_basic_new (
SOUP_AUTH_DOMAIN_REALM, "auth-test",
@@ -1012,12 +1010,12 @@ do_auth_close_test (void)
SoupURI *uri;
AuthCloseData acd;
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
soup_server_add_handler (server, NULL,
server_callback, NULL, NULL);
- uri = soup_uri_new ("http://127.0.0.1/close");
- soup_uri_set_port (uri, soup_server_get_port (server));
+ uri = soup_test_server_get_uri (server, "http", NULL);
+ soup_uri_set_path (uri, "/close");
basic_auth_domain = soup_auth_domain_basic_new (
SOUP_AUTH_DOMAIN_REALM, "auth-test",
@@ -1128,9 +1126,7 @@ do_disappearing_auth_test (void)
server = soup_test_server_new (FALSE);
soup_server_add_handler (server, NULL,
server_callback, NULL, NULL);
-
- uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (uri, soup_server_get_port (server));
+ uri = soup_test_server_get_uri (server, "http", NULL);
auth_domain = soup_auth_domain_basic_new (
SOUP_AUTH_DOMAIN_REALM, "auth-test",
diff --git a/tests/cache-test.c b/tests/cache-test.c
index 3478f37..ce811df 100644
--- a/tests/cache-test.c
+++ b/tests/cache-test.c
@@ -641,8 +641,7 @@ main (int argc, char **argv)
server = soup_test_server_new (TRUE);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- base_uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
g_test_add_data_func ("/cache/basics", base_uri, do_basics_test);
g_test_add_data_func ("/cache/cancellation", base_uri, do_cancel_test);
diff --git a/tests/chunk-io-test.c b/tests/chunk-io-test.c
index 1e53eef..4746ea6 100644
--- a/tests/chunk-io-test.c
+++ b/tests/chunk-io-test.c
@@ -10,7 +10,6 @@ force_io_streams_init (void)
{
SoupServer *server;
SoupSession *session;
- guint port;
SoupURI *base_uri;
SoupMessage *msg;
@@ -20,10 +19,7 @@ force_io_streams_init (void)
*/
server = soup_test_server_new (TRUE);
- port = soup_server_get_port (server);
-
- base_uri = soup_uri_new ("http://127.0.0.1");
- soup_uri_set_port (base_uri, port);
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
msg = soup_message_new_from_uri ("POST", base_uri);
diff --git a/tests/chunk-test.c b/tests/chunk-test.c
index 864f862..e1dbb88 100644
--- a/tests/chunk-test.c
+++ b/tests/chunk-test.c
@@ -427,21 +427,17 @@ main (int argc, char **argv)
{
GMainLoop *loop;
SoupServer *server;
- guint port;
int ret;
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL,
server_callback, NULL, NULL);
- port = soup_server_get_port (server);
loop = g_main_loop_new (NULL, TRUE);
- base_uri = soup_uri_new ("http://127.0.0.1");
- soup_uri_set_port (base_uri, port);
-
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
g_test_add_data_func ("/chunks/request/unstreamed", GINT_TO_POINTER (0), do_request_test);
diff --git a/tests/coding-test.c b/tests/coding-test.c
index 0445f63..de2949b 100644
--- a/tests/coding-test.c
+++ b/tests/coding-test.c
@@ -486,10 +486,9 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- base_uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
g_test_add ("/coding/message/plain", CodingTestData,
GINT_TO_POINTER (CODING_TEST_NO_DECODER),
diff --git a/tests/connection-test.c b/tests/connection-test.c
index 8f8c74b..d953a77 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -51,10 +51,12 @@ timeout_request_started (SoupServer *server, SoupMessage *msg,
SoupClientContext *client, gpointer user_data)
{
SoupSocket *sock;
- GMainContext *context = soup_server_get_async_context (server);
+ GMainContext *context = g_main_context_get_thread_default ();
guint readable;
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
sock = soup_client_context_get_socket (client);
+ G_GNUC_END_IGNORE_DEPRECATIONS;
readable = g_signal_connect (sock, "readable",
G_CALLBACK (timeout_socket), NULL);
while (soup_socket_is_connected (sock))
@@ -130,7 +132,9 @@ server_callback (SoupServer *server, SoupMessage *msg,
* the declared Content-Length. Instead, we
* forcibly close the socket at that point.
*/
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
sock = soup_client_context_get_socket (context);
+ G_GNUC_END_IGNORE_DEPRECATIONS;
g_signal_connect (msg, "wrote-chunk",
G_CALLBACK (close_socket), sock);
} else if (no_close) {
@@ -148,7 +152,9 @@ server_callback (SoupServer *server, SoupMessage *msg,
if (!strcmp (path, "/timeout-persistent")) {
SoupSocket *sock;
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
sock = soup_client_context_get_socket (context);
+ G_GNUC_END_IGNORE_DEPRECATIONS;
setup_timeout_persistent (server, sock);
}
@@ -849,10 +855,9 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
apache_init ();
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, "http", NULL);
- base_uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
g_test_add_func ("/connection/content-length-framing", do_content_length_framing_test);
g_test_add_func ("/connection/persistent-connection-timeout", do_persistent_connection_timeout_test);
diff --git a/tests/context-test.c b/tests/context-test.c
index 727c63b..d20a78d 100644
--- a/tests/context-test.c
+++ b/tests/context-test.c
@@ -65,7 +65,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
sd->server = server;
sd->msg = msg;
sd->timeout = soup_add_timeout (
- soup_server_get_async_context (server),
+ g_main_context_get_thread_default (),
200, add_body_chunk, sd);
g_signal_connect (msg, "finished",
G_CALLBACK (request_failed), sd);
@@ -329,14 +329,16 @@ int
main (int argc, char **argv)
{
SoupServer *server;
+ SoupURI *uri;
int ret;
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- base_uri = g_strdup_printf ("http://127.0.0.1:%u/",
- soup_server_get_port (server));
+ uri = soup_test_server_get_uri (server, "http", NULL);
+ base_uri = soup_uri_to_string (uri, FALSE);
+ soup_uri_free (uri);
g_test_add_data_func ("/context/blocking/explicit", GINT_TO_POINTER (FALSE), do_test1);
g_test_add_data_func ("/context/blocking/thread-default", GINT_TO_POINTER (TRUE), do_test1);
diff --git a/tests/continue-test.c b/tests/continue-test.c
index b6a5805..5e0c660 100644
--- a/tests/continue-test.c
+++ b/tests/continue-test.c
@@ -10,7 +10,7 @@
#define MAX_POST_LENGTH (sizeof (SHORT_BODY))
-static int port;
+static SoupURI *base_uri;
static GSList *events;
static void
@@ -54,17 +54,20 @@ do_message (const char *path, gboolean long_body,
SoupSession *session;
SoupMessage *msg;
const char *body;
- char *uri;
+ SoupURI *uri;
va_list ap;
const char *expected_event;
char *actual_event;
int expected_status, actual_status;
- uri = g_strdup_printf ("http://%s127.0.0.1:%d/%s",
- auth ? "user:pass@" : "",
- port, path);
- msg = soup_message_new ("POST", uri);
- g_free (uri);
+ uri = soup_uri_copy (base_uri);
+ if (auth) {
+ soup_uri_set_user (uri, "user");
+ soup_uri_set_password (uri, "pass");
+ }
+ soup_uri_set_path (uri, path);
+ msg = soup_message_new_from_uri ("POST", uri);
+ soup_uri_free (uri);
body = long_body ? LONG_BODY : SHORT_BODY;
soup_message_set_request (msg, "text/plain", SOUP_MEMORY_STATIC,
@@ -148,7 +151,7 @@ do_message (const char *path, gboolean long_body,
static void
do_test_unauth_short_noexpect_nopass (void)
{
- do_message ("unauth", FALSE, FALSE, FALSE,
+ do_message ("/unauth", FALSE, FALSE, FALSE,
"client-wrote_headers",
"client-wrote_body",
"server-got_headers",
@@ -165,7 +168,7 @@ do_test_unauth_short_noexpect_nopass (void)
static void
do_test_unauth_long_noexpect_nopass (void)
{
- do_message ("unauth", TRUE, FALSE, FALSE,
+ do_message ("/unauth", TRUE, FALSE, FALSE,
"client-wrote_headers",
"client-wrote_body",
"server-got_headers",
@@ -182,7 +185,7 @@ do_test_unauth_long_noexpect_nopass (void)
static void
do_test_unauth_short_expect_nopass (void)
{
- do_message ("unauth", FALSE, TRUE, FALSE,
+ do_message ("/unauth", FALSE, TRUE, FALSE,
"client-wrote_headers",
"server-got_headers",
"server-wrote_informational", SOUP_STATUS_CONTINUE,
@@ -201,7 +204,7 @@ do_test_unauth_short_expect_nopass (void)
static void
do_test_unauth_long_expect_nopass (void)
{
- do_message ("unauth", TRUE, TRUE, FALSE,
+ do_message ("/unauth", TRUE, TRUE, FALSE,
"client-wrote_headers",
"server-got_headers",
"server-wrote_headers", SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE,
@@ -216,7 +219,7 @@ do_test_unauth_long_expect_nopass (void)
static void
do_test_auth_short_noexpect_nopass (void)
{
- do_message ("auth", FALSE, FALSE, FALSE,
+ do_message ("/auth", FALSE, FALSE, FALSE,
"client-wrote_headers",
"client-wrote_body",
"server-got_headers",
@@ -233,7 +236,7 @@ do_test_auth_short_noexpect_nopass (void)
static void
do_test_auth_long_noexpect_nopass (void)
{
- do_message ("auth", TRUE, FALSE, FALSE,
+ do_message ("/auth", TRUE, FALSE, FALSE,
"client-wrote_headers",
"client-wrote_body",
"server-got_headers",
@@ -250,7 +253,7 @@ do_test_auth_long_noexpect_nopass (void)
static void
do_test_auth_short_expect_nopass (void)
{
- do_message ("auth", FALSE, TRUE, FALSE,
+ do_message ("/auth", FALSE, TRUE, FALSE,
"client-wrote_headers",
"server-got_headers",
"server-wrote_headers", SOUP_STATUS_UNAUTHORIZED,
@@ -265,7 +268,7 @@ do_test_auth_short_expect_nopass (void)
static void
do_test_auth_long_expect_nopass (void)
{
- do_message ("auth", TRUE, TRUE, FALSE,
+ do_message ("/auth", TRUE, TRUE, FALSE,
"client-wrote_headers",
"server-got_headers",
"server-wrote_headers", SOUP_STATUS_UNAUTHORIZED,
@@ -280,7 +283,7 @@ do_test_auth_long_expect_nopass (void)
static void
do_test_auth_short_noexpect_pass (void)
{
- do_message ("auth", FALSE, FALSE, TRUE,
+ do_message ("/auth", FALSE, FALSE, TRUE,
"client-wrote_headers",
"client-wrote_body",
"server-got_headers",
@@ -306,7 +309,7 @@ do_test_auth_short_noexpect_pass (void)
static void
do_test_auth_long_noexpect_pass (void)
{
- do_message ("auth", TRUE, FALSE, TRUE,
+ do_message ("/auth", TRUE, FALSE, TRUE,
"client-wrote_headers",
"client-wrote_body",
"server-got_headers",
@@ -332,7 +335,7 @@ do_test_auth_long_noexpect_pass (void)
static void
do_test_auth_short_expect_pass (void)
{
- do_message ("auth", FALSE, TRUE, TRUE,
+ do_message ("/auth", FALSE, TRUE, TRUE,
"client-wrote_headers",
"server-got_headers",
"server-wrote_headers", SOUP_STATUS_UNAUTHORIZED,
@@ -358,7 +361,7 @@ do_test_auth_short_expect_pass (void)
static void
do_test_auth_long_expect_pass (void)
{
- do_message ("auth", TRUE, TRUE, TRUE,
+ do_message ("/auth", TRUE, TRUE, TRUE,
"client-wrote_headers",
"server-got_headers",
"server-wrote_headers", SOUP_STATUS_UNAUTHORIZED,
@@ -452,7 +455,7 @@ setup_server (void)
SoupServer *server;
SoupAuthDomain *auth_domain;
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
g_signal_connect (server, "request-started",
G_CALLBACK (request_started), NULL);
@@ -481,7 +484,7 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
server = setup_server ();
- port = soup_server_get_port (server);
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
g_test_add_func ("/continue/unauth_short_noexpect_nopass", do_test_unauth_short_noexpect_nopass);
g_test_add_func ("/continue/unauth_long_noexpect_nopass", do_test_unauth_long_noexpect_nopass);
@@ -499,6 +502,8 @@ main (int argc, char **argv)
ret = g_test_run ();
soup_test_server_quit_unref (server);
+ soup_uri_free (base_uri);
+
test_cleanup ();
return ret;
diff --git a/tests/cookies-test.c b/tests/cookies-test.c
index 12529d8..479bcfe 100644
--- a/tests/cookies-test.c
+++ b/tests/cookies-test.c
@@ -167,16 +167,19 @@ do_cookies_parsing_test (void)
int
main (int argc, char **argv)
{
+ SoupURI *server_uri;
int ret;
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
+ server_uri = soup_test_server_get_uri (server, "http", NULL);
+
first_party_uri = soup_uri_new (first_party);
third_party_uri = soup_uri_new (third_party);
- soup_uri_set_port (first_party_uri, soup_server_get_port (server));
- soup_uri_set_port (third_party_uri, soup_server_get_port (server));
+ soup_uri_set_port (first_party_uri, server_uri->port);
+ soup_uri_set_port (third_party_uri, server_uri->port);
g_test_add_func ("/cookies/accept-policy", do_cookies_accept_policy_test);
g_test_add_func ("/cookies/parsing", do_cookies_parsing_test);
@@ -185,6 +188,7 @@ main (int argc, char **argv)
soup_uri_free (first_party_uri);
soup_uri_free (third_party_uri);
+ soup_uri_free (server_uri);
soup_test_server_quit_unref (server);
test_cleanup ();
diff --git a/tests/forms-test.c b/tests/forms-test.c
index 3915b01..349932b 100644
--- a/tests/forms-test.c
+++ b/tests/forms-test.c
@@ -420,41 +420,43 @@ main (int argc, char **argv)
{
GMainLoop *loop;
SoupServer *server;
- guint port;
- char *uri_str;
+ SoupURI *base_uri, *uri;
int ret = 0;
test_init (argc, argv, no_test_entry);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, "/hello",
hello_callback, NULL, NULL);
soup_server_add_handler (server, "/md5",
md5_callback, NULL, NULL);
- port = soup_server_get_port (server);
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
loop = g_main_loop_new (NULL, TRUE);
if (run_tests) {
- uri_str = g_strdup_printf ("http://127.0.0.1:%u/hello", port);
- g_test_add_data_func_full ("/forms/hello", uri_str, do_hello_tests, g_free);
+ uri = soup_uri_new_with_base (base_uri, "/hello");
+ g_test_add_data_func_full ("/forms/hello", soup_uri_to_string (uri, FALSE), do_hello_tests,
g_free);
+ soup_uri_free (uri);
- uri_str = g_strdup_printf ("http://127.0.0.1:%u/md5", port);
- g_test_add_data_func_full ("/forms/md5/curl", g_strdup (uri_str), do_md5_test_curl, g_free);
- g_test_add_data_func_full ("/forms/md5/libsoup", g_strdup (uri_str), do_md5_test_libsoup,
g_free);
- g_free (uri_str);
+ uri = soup_uri_new_with_base (base_uri, "/md5");
+ g_test_add_data_func_full ("/forms/md5/curl", soup_uri_to_string (uri, FALSE),
do_md5_test_curl, g_free);
+ g_test_add_data_func_full ("/forms/md5/libsoup", soup_uri_to_string (uri, FALSE),
do_md5_test_libsoup, g_free);
+ soup_uri_free (uri);
g_test_add_func ("/forms/decode", do_form_decode_test);
ret = g_test_run ();
} else {
- g_print ("Listening on port %d\n", port);
+ g_print ("Listening on port %d\n", base_uri->port);
g_main_loop_run (loop);
}
g_main_loop_unref (loop);
soup_test_server_quit_unref (server);
+ soup_uri_free (base_uri);
+
if (run_tests)
test_cleanup ();
return ret;
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 00559a0..acf42c3 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -73,7 +73,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
if (!strcmp (path, "/slow")) {
soup_server_pause_message (server, msg);
g_object_set_data (G_OBJECT (msg), "server", server);
- soup_add_timeout (soup_server_get_async_context (server),
+ soup_add_timeout (g_main_context_get_thread_default (),
1000, timeout_finish_message, msg);
}
@@ -151,35 +151,28 @@ static void
do_callback_unref_test (void)
{
SoupServer *bad_server;
- SoupAddress *addr;
SoupSession *session;
SoupMessage *one, *two;
GMainLoop *loop;
- char *bad_uri;
+ SoupURI *bad_uri;
g_test_bug ("533473");
/* Get a guaranteed-bad URI */
- addr = soup_address_new ("127.0.0.1", SOUP_ADDRESS_ANY_PORT);
- soup_address_resolve_sync (addr, NULL);
- bad_server = soup_server_new (SOUP_SERVER_INTERFACE, addr,
- NULL);
- g_object_unref (addr);
-
- bad_uri = g_strdup_printf ("http://127.0.0.1:%u/",
- soup_server_get_port (bad_server));
- g_object_unref (bad_server);
+ bad_server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
+ bad_uri = soup_test_server_get_uri (bad_server, "http", NULL);
+ soup_test_server_quit_unref (bad_server);
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
g_object_add_weak_pointer (G_OBJECT (session), (gpointer *)&session);
loop = g_main_loop_new (NULL, TRUE);
- one = soup_message_new ("GET", bad_uri);
+ one = soup_message_new_from_uri ("GET", bad_uri);
g_object_add_weak_pointer (G_OBJECT (one), (gpointer *)&one);
- two = soup_message_new ("GET", bad_uri);
+ two = soup_message_new_from_uri ("GET", bad_uri);
g_object_add_weak_pointer (G_OBJECT (two), (gpointer *)&two);
- g_free (bad_uri);
+ soup_uri_free (bad_uri);
soup_session_queue_message (session, one, cu_one_completed, loop);
soup_session_queue_message (session, two, cu_two_completed, loop);
@@ -245,22 +238,15 @@ static void
do_callback_unref_req_test (void)
{
SoupServer *bad_server;
- SoupAddress *addr;
SoupSession *session;
SoupRequest *one, *two;
GMainLoop *loop;
- char *bad_uri;
+ SoupURI *bad_uri;
/* Get a guaranteed-bad URI */
- addr = soup_address_new ("127.0.0.1", SOUP_ADDRESS_ANY_PORT);
- soup_address_resolve_sync (addr, NULL);
- bad_server = soup_server_new (SOUP_SERVER_INTERFACE, addr,
- NULL);
- g_object_unref (addr);
-
- bad_uri = g_strdup_printf ("http://127.0.0.1:%u/",
- soup_server_get_port (bad_server));
- g_object_unref (bad_server);
+ bad_server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
+ bad_uri = soup_test_server_get_uri (bad_server, "http", NULL);
+ soup_test_server_quit_unref (bad_server);
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
@@ -269,11 +255,11 @@ do_callback_unref_req_test (void)
loop = g_main_loop_new (NULL, TRUE);
- one = soup_session_request (session, bad_uri, NULL);
+ one = soup_session_request_uri (session, bad_uri, NULL);
g_object_add_weak_pointer (G_OBJECT (one), (gpointer *)&one);
- two = soup_session_request (session, bad_uri, NULL);
+ two = soup_session_request_uri (session, bad_uri, NULL);
g_object_add_weak_pointer (G_OBJECT (two), (gpointer *)&two);
- g_free (bad_uri);
+ soup_uri_free (bad_uri);
soup_request_send_async (one, NULL, cur_one_completed, session);
g_object_unref (one);
@@ -922,10 +908,9 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, "http", NULL);
- base_uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
auth_domain = soup_auth_domain_basic_new (
SOUP_AUTH_DOMAIN_REALM, "misc-test",
@@ -936,10 +921,9 @@ main (int argc, char **argv)
g_object_unref (auth_domain);
if (tls_available) {
- ssl_server = soup_test_server_new_ssl (TRUE);
+ ssl_server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (ssl_server, NULL, server_callback, "https", NULL);
- ssl_base_uri = soup_uri_new ("https://127.0.0.1/");
- soup_uri_set_port (ssl_base_uri, soup_server_get_port (ssl_server));
+ ssl_base_uri = soup_test_server_get_uri (ssl_server, "https", "127.0.0.1");
}
g_test_add_func ("/misc/host", do_host_test);
diff --git a/tests/multipart-test.c b/tests/multipart-test.c
index e057412..488865a 100644
--- a/tests/multipart-test.c
+++ b/tests/multipart-test.c
@@ -486,10 +486,9 @@ main (int argc, char **argv)
buffer = g_malloc (READ_BUFFER_SIZE);
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- base_uri = soup_uri_new ("http://127.0.0.1");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
base_uri_string = soup_uri_to_string (base_uri, FALSE);
/* FIXME: I had to raise the number of connections allowed here, otherwise I
diff --git a/tests/no-ssl-test.c b/tests/no-ssl-test.c
index 82532c7..54887f1 100644
--- a/tests/no-ssl-test.c
+++ b/tests/no-ssl-test.c
@@ -3,14 +3,14 @@
#include "test-utils.h"
static void
-do_ssl_test_for_session (SoupSession *session, const char *uri)
+do_ssl_test_for_session (SoupSession *session, SoupURI *uri)
{
SoupMessage *msg;
GTlsCertificate *cert = NULL;
GTlsCertificateFlags flags;
gboolean is_https;
- msg = soup_message_new ("GET", uri);
+ msg = soup_message_new_from_uri ("GET", uri);
soup_session_send_message (session, msg);
soup_test_assert_message_status (msg, SOUP_STATUS_SSL_FAILED);
@@ -24,8 +24,9 @@ do_ssl_test_for_session (SoupSession *session, const char *uri)
}
static void
-do_ssl_tests (gconstpointer uri)
+do_ssl_tests (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
g_test_bug ("700518");
@@ -121,7 +122,8 @@ int
main (int argc, char **argv)
{
SoupServer *server;
- char *uri;
+ SoupURI *uri;
+ guint port;
int ret;
/* Force this test to use the dummy TLS backend */
@@ -135,15 +137,17 @@ main (int argc, char **argv)
*/
server = soup_test_server_new (TRUE);
soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
- uri = g_strdup_printf ("https://127.0.0.1:%u/",
- soup_server_get_port (server));
+ uri = soup_test_server_get_uri (server, "http", NULL);
+ port = uri->port;
+ soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTPS);
+ soup_uri_set_port (uri, port);
g_test_add_func ("/no-ssl/session-properties", do_session_property_tests);
g_test_add_data_func ("/no-ssl/request-error", uri, do_ssl_tests);
ret = g_test_run ();
- g_free (uri);
+ soup_uri_free (uri);
soup_test_server_quit_unref (server);
test_cleanup ();
diff --git a/tests/ntlm-test.c b/tests/ntlm-test.c
index 24a0f2e..c6d5380 100644
--- a/tests/ntlm-test.c
+++ b/tests/ntlm-test.c
@@ -44,7 +44,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
SoupClientContext *client, gpointer data)
{
GHashTable *connections = data;
- SoupSocket *socket;
+ GSocket *socket;
const char *auth;
NTLMServerState state, required_user = 0;
gboolean auth_required, not_found = FALSE;
@@ -70,7 +70,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
if (strstr (path, "/404"))
not_found = TRUE;
- socket = soup_client_context_get_socket (client);
+ socket = soup_client_context_get_gsocket (client);
state = GPOINTER_TO_INT (g_hash_table_lookup (connections, socket));
auth = soup_message_headers_get_one (msg->request_headers,
"Authorization");
@@ -597,13 +597,12 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
connections = g_hash_table_new (NULL, NULL);
soup_server_add_handler (server, NULL,
server_callback, connections, NULL);
- uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (uri, soup_server_get_port (server));
+ uri = soup_test_server_get_uri (server, "http", NULL);
for (i = 0; i < G_N_ELEMENTS (ntlm_tests); i++)
g_test_add_data_func (ntlm_tests[i].name, &ntlm_tests[i], do_ntlm_test);
@@ -611,8 +610,6 @@ main (int argc, char **argv)
ret = g_test_run ();
- soup_uri_free (uri);
-
soup_test_server_quit_unref (server);
test_cleanup ();
g_hash_table_destroy (connections);
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index 4b6679b..e898a0b 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -338,10 +338,9 @@ main (int argc, char **argv)
g_simple_proxy_resolver_new (proxies[i], (char **) ignore_hosts);
}
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- base_uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
for (i = 0; i < ntests; i++) {
path = g_strdup_printf ("/proxy/async/%s", tests[i].explanation);
diff --git a/tests/range-test.c b/tests/range-test.c
index c23ba46..06cde77 100644
--- a/tests/range-test.c
+++ b/tests/range-test.c
@@ -361,16 +361,18 @@ do_libsoup_range_test (void)
{
SoupSession *session;
SoupServer *server;
- char *base_uri;
+ SoupURI *base_uri;
+ char *base_uri_str;
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
- base_uri = g_strdup_printf ("http://127.0.0.1:%u/",
- soup_server_get_port (server));
- do_range_test (session, base_uri, TRUE, TRUE);
- g_free (base_uri);
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
+ base_uri_str = soup_uri_to_string (base_uri, FALSE);
+ do_range_test (session, base_uri_str, TRUE, TRUE);
+ soup_uri_free (base_uri);
+ g_free (base_uri_str);
soup_test_server_quit_unref (server);
soup_test_session_abort_unref (session);
diff --git a/tests/redirect-test.c b/tests/redirect-test.c
index ad8daba..6b165e8 100644
--- a/tests/redirect-test.c
+++ b/tests/redirect-test.c
@@ -395,24 +395,24 @@ main (int argc, char **argv)
{
GMainLoop *loop;
SoupServer *server, *server2;
- guint port;
+ SoupURI *uri2;
char *path;
int n, ret;
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL,
server_callback, NULL, NULL);
- port = soup_server_get_port (server);
- base_uri = soup_uri_new ("http://127.0.0.1");
- soup_uri_set_port (base_uri, port);
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
- server2 = soup_test_server_new (TRUE);
+ server2 = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server2, NULL,
server2_callback, NULL, NULL);
- server2_uri = g_strdup_printf ("http://127.0.0.1:%d/on-server2",
- soup_server_get_port (server2));
+ uri2 = soup_test_server_get_uri (server2, "http", NULL);
+ soup_uri_set_path (uri2, "/on-server2");
+ server2_uri = soup_uri_to_string (uri2, FALSE);
+ soup_uri_free (uri2);
loop = g_main_loop_new (NULL, TRUE);
@@ -422,8 +422,8 @@ main (int argc, char **argv)
sync_session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
for (n = 0; n < n_tests; n++) {
- path = g_strdup_printf ("/redirect/async/msg/%d-%s-%d", n
- , tests[n].requests[0].method,
+ path = g_strdup_printf ("/redirect/async/msg/%d-%s-%d", n,
+ tests[n].requests[0].method,
tests[n].requests[0].status_code);
g_test_add_data_func (path, &tests[n], do_async_msg_api_test);
g_free (path);
diff --git a/tests/requester-test.c b/tests/requester-test.c
index 39b30bd..506bb7f 100644
--- a/tests/requester-test.c
+++ b/tests/requester-test.c
@@ -279,7 +279,7 @@ do_async_test (SoupSession *session, SoupURI *uri,
}
static void
-do_test_for_thread_and_context (SoupSession *session, const char *base_uri)
+do_test_for_thread_and_context (SoupSession *session, SoupURI *base_uri)
{
SoupRequester *requester;
SoupURI *uri;
@@ -292,39 +292,33 @@ do_test_for_thread_and_context (SoupSession *session, const char *base_uri)
soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER);
debug_printf (1, " basic test\n");
- uri = soup_uri_new (base_uri);
- do_async_test (session, uri, test_sent,
+ do_async_test (session, base_uri, test_sent,
SOUP_STATUS_OK, response,
TRUE, FALSE);
- soup_uri_free (uri);
debug_printf (1, " chunked test\n");
- uri = soup_uri_new (base_uri);
- soup_uri_set_path (uri, "/chunked");
+ uri = soup_uri_new_with_base (base_uri, "/chunked");
do_async_test (session, uri, test_sent,
SOUP_STATUS_OK, response,
TRUE, FALSE);
soup_uri_free (uri);
debug_printf (1, " auth test\n");
- uri = soup_uri_new (base_uri);
- soup_uri_set_path (uri, "/auth");
+ uri = soup_uri_new_with_base (base_uri, "/auth");
do_async_test (session, uri, auth_test_sent,
SOUP_STATUS_UNAUTHORIZED, auth_response,
TRUE, FALSE);
soup_uri_free (uri);
debug_printf (1, " non-persistent test\n");
- uri = soup_uri_new (base_uri);
- soup_uri_set_path (uri, "/non-persistent");
+ uri = soup_uri_new_with_base (base_uri, "/non-persistent");
do_async_test (session, uri, test_sent,
SOUP_STATUS_OK, response,
FALSE, FALSE);
soup_uri_free (uri);
debug_printf (1, " cancellation test\n");
- uri = soup_uri_new (base_uri);
- soup_uri_set_path (uri, "/");
+ uri = soup_uri_new_with_base (base_uri, "/");
do_async_test (session, uri, test_sent,
SOUP_STATUS_FORBIDDEN, NULL,
FALSE, TRUE);
@@ -332,8 +326,9 @@ do_test_for_thread_and_context (SoupSession *session, const char *base_uri)
}
static void
-do_simple_plain_test (gconstpointer uri)
+do_simple_plain_test (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
g_test_bug ("653707");
@@ -344,8 +339,9 @@ do_simple_plain_test (gconstpointer uri)
}
static void
-do_simple_async_test (gconstpointer uri)
+do_simple_async_test (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
g_test_bug ("653707");
@@ -358,7 +354,7 @@ do_simple_async_test (gconstpointer uri)
}
static void
-do_test_with_context_and_type (const char *uri, gboolean plain_session)
+do_test_with_context_and_type (SoupURI *uri, gboolean plain_session)
{
GMainContext *async_context;
SoupSession *session;
@@ -381,14 +377,18 @@ do_test_with_context_and_type (const char *uri, gboolean plain_session)
}
static void
-do_async_test_with_context (gconstpointer uri)
+do_async_test_with_context (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
+
do_test_with_context_and_type (uri, FALSE);
}
static void
-do_plain_test_with_context (gconstpointer uri)
+do_plain_test_with_context (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
+
do_test_with_context_and_type (uri, TRUE);
}
@@ -407,8 +407,9 @@ plain_test_thread (gpointer uri)
}
static void
-do_async_test_in_thread (gconstpointer uri)
+do_async_test_in_thread (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
GThread *thread;
thread = g_thread_new ("do_async_test_in_thread",
@@ -418,8 +419,9 @@ do_async_test_in_thread (gconstpointer uri)
}
static void
-do_plain_test_in_thread (gconstpointer uri)
+do_plain_test_in_thread (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
GThread *thread;
thread = g_thread_new ("do_plain_test_in_thread",
@@ -504,7 +506,7 @@ do_sync_request (SoupSession *session, SoupRequest *request,
}
static void
-do_sync_tests_for_session (SoupSession *session, const char *uri_string)
+do_sync_tests_for_session (SoupSession *session, SoupURI *base_uri)
{
SoupRequester *requester;
SoupRequest *request;
@@ -512,7 +514,7 @@ do_sync_tests_for_session (SoupSession *session, const char *uri_string)
requester = SOUP_REQUESTER (soup_session_get_feature (session, SOUP_TYPE_REQUESTER));
- uri = soup_uri_new (uri_string);
+ uri = soup_uri_copy (base_uri);
debug_printf (1, " basic test\n");
if (requester)
@@ -572,8 +574,9 @@ do_sync_tests_for_session (SoupSession *session, const char *uri_string)
}
static void
-do_plain_sync_test (gconstpointer uri)
+do_plain_sync_test (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -582,8 +585,9 @@ do_plain_sync_test (gconstpointer uri)
}
static void
-do_sync_sync_test (gconstpointer uri)
+do_sync_sync_test (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
SoupRequester *requester;
@@ -751,16 +755,16 @@ do_close_test_for_session (SoupSession *session,
}
static void
-do_async_close_test (gconstpointer uri)
+do_async_close_test (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
SoupURI *slow_uri;
g_test_bug ("695652");
g_test_bug ("711260");
- slow_uri = soup_uri_new (uri);
- soup_uri_set_path (slow_uri, "/slow");
+ slow_uri = soup_uri_new_with_base ((SoupURI *)uri, "/slow");
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
@@ -772,18 +776,17 @@ do_async_close_test (gconstpointer uri)
}
static void
-do_sync_close_test (gconstpointer uri)
+do_sync_close_test (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
SoupURI *slow_uri;
g_test_bug ("695652");
g_test_bug ("711260");
- slow_uri = soup_uri_new (uri);
- soup_uri_set_path (slow_uri, "/slow");
+ slow_uri = soup_uri_new_with_base ((SoupURI *)uri, "/slow");
- debug_printf (1, " SoupSessionSync\n");
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC,
SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
NULL);
@@ -796,7 +799,7 @@ do_sync_close_test (gconstpointer uri)
int
main (int argc, char **argv)
{
- char *uri;
+ SoupURI *uri;
int ret;
test_init (argc, argv, NULL);
@@ -806,10 +809,11 @@ main (int argc, char **argv)
AUTH_HTML_BODY,
strlen (AUTH_HTML_BODY));
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- uri = g_strdup_printf ("http://127.0.0.1:%u/foo", soup_server_get_port (server));
+ uri = soup_test_server_get_uri (server, "http", NULL);
+ soup_uri_set_path (uri, "/foo");
g_test_add_data_func ("/requester/simple/SoupSession", uri, do_simple_plain_test);
g_test_add_data_func ("/requester/simple/SoupSessionAsync", uri, do_simple_async_test);
@@ -826,7 +830,8 @@ main (int argc, char **argv)
ret = g_test_run ();
- g_free (uri);
+ soup_uri_free (uri);
+ soup_buffer_free (response);
soup_buffer_free (auth_response);
soup_test_server_quit_unref (server);
diff --git a/tests/server-auth-test.c b/tests/server-auth-test.c
index f386f52..ee3f57b 100644
--- a/tests/server-auth-test.c
+++ b/tests/server-auth-test.c
@@ -282,7 +282,7 @@ main (int argc, char **argv)
test_init (argc, argv, no_test_entry);
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
g_signal_connect (server, "request_started",
G_CALLBACK (request_started_callback), NULL);
soup_server_add_handler (server, NULL,
@@ -310,12 +310,10 @@ main (int argc, char **argv)
loop = g_main_loop_new (NULL, TRUE);
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
if (run_tests) {
int i;
- base_uri = soup_uri_new ("http://127.0.0.1");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
-
for (i = 0; i < 16; i++) {
char *path;
const char *authtypes;
@@ -344,13 +342,12 @@ main (int argc, char **argv)
}
ret = g_test_run ();
-
- soup_uri_free (base_uri);
} else {
- g_print ("Listening on port %d\n", soup_server_get_port (server));
+ g_print ("Listening on port %d\n", base_uri->port);
g_main_loop_run (loop);
ret = 0;
}
+ soup_uri_free (base_uri);
g_main_loop_unref (loop);
soup_test_server_quit_unref (server);
diff --git a/tests/server-test.c b/tests/server-test.c
index 0c98090..ca79f21 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -5,7 +5,9 @@
#include "test-utils.h"
-SoupServer *server, *ssl_server;
+#include <gio/gnetworking.h>
+
+SoupServer *server;
SoupURI *base_uri, *ssl_base_uri;
static void
@@ -220,10 +222,13 @@ ipv6_server_callback (SoupServer *server, SoupMessage *msg,
SoupClientContext *context, gpointer data)
{
const char *host;
+ GSocketAddress *addr;
char expected_host[128];
+ addr = soup_client_context_get_local_address (context);
g_snprintf (expected_host, sizeof (expected_host),
- "[::1]:%d", soup_server_get_port (server));
+ "[::1]:%d",
+ g_inet_socket_address_get_port (G_INET_SOCKET_ADDRESS (addr)));
host = soup_message_headers_get_one (msg->request_headers, "Host");
g_assert_cmpstr (host, ==, expected_host);
@@ -239,27 +244,18 @@ do_ipv6_test (void)
{
SoupServer *ipv6_server;
SoupURI *ipv6_uri;
- SoupAddress *ipv6_addr;
SoupSession *session;
SoupMessage *msg;
g_test_bug ("666399");
- ipv6_addr = soup_address_new ("::1", SOUP_ADDRESS_ANY_PORT);
- soup_address_resolve_sync (ipv6_addr, NULL);
- ipv6_server = soup_server_new (SOUP_SERVER_INTERFACE, ipv6_addr,
- NULL);
- g_object_unref (ipv6_addr);
- if (!ipv6_server) {
- debug_printf (1, " skipping due to lack of IPv6 support\n");
- return;
- }
+ /* FIXME: deal with lack of IPv6 support */
- soup_server_add_handler (ipv6_server, NULL, ipv6_server_callback, NULL, NULL);
- soup_server_run_async (ipv6_server);
+ debug_printf (1, "\nIPv6 server test\n");
- ipv6_uri = soup_uri_new ("http://[::1]/");
- soup_uri_set_port (ipv6_uri, soup_server_get_port (ipv6_server));
+ ipv6_server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
+ soup_server_add_handler (ipv6_server, NULL, ipv6_server_callback, NULL, NULL);
+ ipv6_uri = soup_test_server_get_uri (ipv6_server, "http", "::1");
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
@@ -281,6 +277,136 @@ do_ipv6_test (void)
soup_test_server_quit_unref (ipv6_server);
}
+static void
+do_gsocket_import_test (void)
+{
+ GSocket *gsock;
+ GSocketAddress *gaddr;
+ SoupServer *server;
+ GSList *listeners;
+ SoupURI *uri;
+ SoupSession *session;
+ SoupMessage *msg;
+ GError *error = NULL;
+
+ gsock = g_socket_new (G_SOCKET_FAMILY_IPV4,
+ G_SOCKET_TYPE_STREAM,
+ G_SOCKET_PROTOCOL_DEFAULT,
+ &error);
+ g_assert_no_error (error);
+
+ gaddr = g_inet_socket_address_new_from_string ("127.0.0.1", 0);
+ g_socket_bind (gsock, gaddr, TRUE, &error);
+ g_object_unref (gaddr);
+ g_assert_no_error (error);
+ g_socket_listen (gsock, &error);
+ g_assert_no_error (error);
+
+ gaddr = g_socket_get_local_address (gsock, &error);
+ g_assert_no_error (error);
+
+ server = soup_test_server_new (SOUP_TEST_SERVER_NO_DEFAULT_LISTENER);
+ soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
+
+ listeners = soup_server_get_listeners (server);
+ g_assert_cmpint (g_slist_length (listeners), ==, 0);
+ g_slist_free (listeners);
+
+ soup_server_listen_socket (server, gsock, 0, &error);
+ g_assert_no_error (error);
+ listeners = soup_server_get_listeners (server);
+ g_assert_cmpint (g_slist_length (listeners), ==, 1);
+ g_slist_free (listeners);
+
+ uri = soup_test_server_get_uri (server, "http", "127.0.0.1");
+ g_assert_nonnull (uri);
+ listeners = soup_server_get_listeners (server);
+ g_assert_cmpint (g_slist_length (listeners), ==, 1);
+ g_slist_free (listeners);
+
+ session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+ msg = soup_message_new_from_uri ("GET", uri);
+ soup_session_send_message (session, msg);
+ soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+ g_object_unref (msg);
+
+ soup_test_session_abort_unref (session);
+
+ soup_uri_free (uri);
+ soup_test_server_quit_unref (server);
+
+ g_assert_false (g_socket_is_connected (gsock));
+ g_object_unref (gsock);
+}
+
+static void
+do_fd_import_test (void)
+{
+ GSocket *gsock;
+ GSocketAddress *gaddr;
+ SoupServer *server;
+ GSList *listeners;
+ SoupURI *uri;
+ SoupSession *session;
+ SoupMessage *msg;
+ int type;
+ GError *error = NULL;
+
+ gsock = g_socket_new (G_SOCKET_FAMILY_IPV4,
+ G_SOCKET_TYPE_STREAM,
+ G_SOCKET_PROTOCOL_DEFAULT,
+ &error);
+ g_assert_no_error (error);
+
+ gaddr = g_inet_socket_address_new_from_string ("127.0.0.1", 0);
+ g_socket_bind (gsock, gaddr, TRUE, &error);
+ g_object_unref (gaddr);
+ g_assert_no_error (error);
+ g_socket_listen (gsock, &error);
+ g_assert_no_error (error);
+
+ gaddr = g_socket_get_local_address (gsock, &error);
+ g_assert_no_error (error);
+
+ server = soup_test_server_new (SOUP_TEST_SERVER_NO_DEFAULT_LISTENER);
+ soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
+
+ listeners = soup_server_get_listeners (server);
+ g_assert_cmpint (g_slist_length (listeners), ==, 0);
+ g_slist_free (listeners);
+
+ soup_server_listen_fd (server, g_socket_get_fd (gsock), 0, &error);
+ g_assert_no_error (error);
+ listeners = soup_server_get_listeners (server);
+ g_assert_cmpint (g_slist_length (listeners), ==, 1);
+ g_slist_free (listeners);
+
+ uri = soup_test_server_get_uri (server, "http", "127.0.0.1");
+ g_assert_nonnull (uri);
+ listeners = soup_server_get_listeners (server);
+ g_assert_cmpint (g_slist_length (listeners), ==, 1);
+ g_slist_free (listeners);
+
+ session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+ msg = soup_message_new_from_uri ("GET", uri);
+ soup_session_send_message (session, msg);
+ soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+ g_object_unref (msg);
+
+ soup_test_session_abort_unref (session);
+
+ soup_uri_free (uri);
+ soup_test_server_quit_unref (server);
+
+ /* @server should have closed our socket, although @gsock doesn't
+ * know this.
+ */
+ g_socket_get_option (gsock, SOL_SOCKET, SO_TYPE, &type, &error);
+ g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED);
+ g_clear_error (&error);
+ g_object_unref (gsock);
+}
+
int
main (int argc, char **argv)
{
@@ -290,21 +416,17 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- base_uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
g_object_set (G_OBJECT (server),
SOUP_SERVER_HTTP_ALIASES, http_aliases,
NULL);
if (tls_available) {
- ssl_server = soup_test_server_new_ssl (TRUE);
- soup_server_add_handler (ssl_server, NULL, server_callback, NULL, NULL);
- ssl_base_uri = soup_uri_new ("https://127.0.0.1/");
- soup_uri_set_port (ssl_base_uri, soup_server_get_port (ssl_server));
- g_object_set (G_OBJECT (ssl_server),
+ ssl_base_uri = soup_test_server_get_uri (server, "https", NULL);
+ g_object_set (G_OBJECT (server),
SOUP_SERVER_HTTPS_ALIASES, https_aliases,
NULL);
}
@@ -313,16 +435,16 @@ main (int argc, char **argv)
g_test_add_func ("/server/aliases", do_server_aliases_test);
g_test_add_func ("/server/..-in-path", do_dot_dot_test);
g_test_add_func ("/server/ipv6", do_ipv6_test);
+ g_test_add_func ("/server/import/gsocket", do_gsocket_import_test);
+ g_test_add_func ("/server/import/fd", do_fd_import_test);
ret = g_test_run ();
soup_uri_free (base_uri);
soup_test_server_quit_unref (server);
- if (tls_available) {
+ if (tls_available)
soup_uri_free (ssl_base_uri);
- soup_test_server_quit_unref (ssl_server);
- }
test_cleanup ();
return ret;
diff --git a/tests/session-test.c b/tests/session-test.c
index 1507205..84fe35b 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -25,7 +25,7 @@ server_handler (SoupServer *server,
gpointer user_data)
{
if (!strcmp (path, "/request-timeout")) {
- GMainContext *context = soup_server_get_async_context (server);
+ GMainContext *context = g_main_context_get_thread_default ();
GSource *timer;
timer = g_timeout_source_new (100);
@@ -57,8 +57,7 @@ cancel_message_cb (SoupMessage *msg, gpointer session)
}
static void
-do_test_for_session (SoupSession *session,
- const char *uri,
+do_test_for_session (SoupSession *session, SoupURI *uri,
gboolean queue_is_async,
gboolean send_is_blocking,
gboolean cancel_is_immediate)
@@ -66,17 +65,17 @@ do_test_for_session (SoupSession *session,
SoupMessage *msg;
gboolean finished, local_timeout;
guint timeout_id;
- char *timeout_uri;
+ SoupURI *timeout_uri;
debug_printf (1, " queue_message\n");
debug_printf (2, " requesting timeout\n");
- timeout_uri = g_strdup_printf ("%s/request-timeout", uri);
- msg = soup_message_new ("GET", timeout_uri);
- g_free (timeout_uri);
+ 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);
g_object_unref (msg);
- msg = soup_message_new ("GET", uri);
+ msg = soup_message_new_from_uri ("GET", uri);
server_processed_message = timeout = finished = FALSE;
soup_session_queue_message (session, msg, finished_cb, &finished);
while (!timeout)
@@ -98,7 +97,7 @@ do_test_for_session (SoupSession *session,
}
debug_printf (1, " send_message\n");
- msg = soup_message_new ("GET", 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);
@@ -120,7 +119,7 @@ do_test_for_session (SoupSession *session,
return;
debug_printf (1, " cancel_message\n");
- msg = soup_message_new ("GET", uri);
+ msg = soup_message_new_from_uri ("GET", uri);
g_object_ref (msg);
finished = FALSE;
soup_session_queue_message (session, msg, finished_cb, &finished);
@@ -146,8 +145,9 @@ do_test_for_session (SoupSession *session,
}
static void
-do_plain_tests (gconstpointer uri)
+do_plain_tests (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -156,8 +156,9 @@ do_plain_tests (gconstpointer uri)
}
static void
-do_async_tests (gconstpointer uri)
+do_async_tests (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
@@ -166,8 +167,9 @@ do_async_tests (gconstpointer uri)
}
static void
-do_sync_tests (gconstpointer uri)
+do_sync_tests (gconstpointer data)
{
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
@@ -194,7 +196,7 @@ priority_test_finished_cb (SoupSession *session, SoupMessage *msg, gpointer user
static void
do_priority_tests (gconstpointer data)
{
- const char *uri = data;
+ SoupURI *uri = (SoupURI *)data;
SoupSession *session;
int i, finished_count = 0;
SoupMessagePriority priorities[] =
@@ -212,12 +214,14 @@ do_priority_tests (gconstpointer data)
expected_priorities[2] = SOUP_MESSAGE_PRIORITY_LOW;
for (i = 0; i < 3; i++) {
- char *msg_uri;
+ SoupURI *msg_uri;
SoupMessage *msg;
+ char buf[5];
- msg_uri = g_strdup_printf ("%s/%d", uri, i);
- msg = soup_message_new ("GET", uri);
- g_free (msg_uri);
+ g_snprintf (buf, sizeof (buf), "%d", i);
+ msg_uri = soup_uri_new_with_base (uri, buf);
+ msg = soup_message_new_from_uri ("GET", msg_uri);
+ soup_uri_free (msg_uri);
soup_message_set_priority (msg, priorities[i]);
soup_session_queue_message (session, msg, priority_test_finished_cb, &finished_count);
@@ -368,16 +372,14 @@ int
main (int argc, char **argv)
{
SoupServer *server;
- char *uri, *timeout_uri;
+ SoupURI *uri;
int ret;
test_init (argc, argv, NULL);
server = soup_test_server_new (TRUE);
soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
- uri = g_strdup_printf ("http://127.0.0.1:%u",
- soup_server_get_port (server));
- timeout_uri = g_strdup_printf ("%s/request-timeout", uri);
+ uri = soup_test_server_get_uri (server, "http", NULL);
g_test_add_data_func ("/session/SoupSession", uri, do_plain_tests);
g_test_add_data_func ("/session/SoupSessionAsync", uri, do_async_tests);
@@ -387,8 +389,7 @@ main (int argc, char **argv)
ret = g_test_run ();
- g_free (uri);
- g_free (timeout_uri);
+ soup_uri_free (uri);
soup_test_server_quit_unref (server);
test_cleanup ();
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c
index 32fad9f..1e8680b 100644
--- a/tests/sniffing-test.c
+++ b/tests/sniffing-test.c
@@ -440,10 +440,9 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
- server = soup_test_server_new (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_callback, NULL, NULL);
- base_uri = soup_uri_new ("http://127.0.0.1/");
- soup_uri_set_port (base_uri, soup_server_get_port (server));
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
diff --git a/tests/socket-test.c b/tests/socket-test.c
index 821b1a2..cdeace2 100644
--- a/tests/socket-test.c
+++ b/tests/socket-test.c
@@ -114,6 +114,7 @@ static void
do_socket_from_fd_client_test (void)
{
SoupServer *server;
+ SoupURI *uri;
GSocket *gsock;
SoupSocket *sock;
SoupAddress *local, *remote;
@@ -122,7 +123,8 @@ do_socket_from_fd_client_test (void)
int type;
GError *error = NULL;
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
+ uri = soup_test_server_get_uri (server, "http", "127.0.0.1");
gsock = g_socket_new (G_SOCKET_FAMILY_IPV4,
G_SOCKET_TYPE_STREAM,
@@ -130,7 +132,7 @@ do_socket_from_fd_client_test (void)
&error);
g_assert_no_error (error);
- gaddr = g_inet_socket_address_new_from_string ("127.0.0.1", soup_server_get_port (server));
+ gaddr = g_inet_socket_address_new_from_string ("127.0.0.1", uri->port);
g_socket_connect (gsock, gaddr, NULL, &error);
g_object_unref (gaddr);
g_assert_no_error (error);
@@ -158,7 +160,7 @@ do_socket_from_fd_client_test (void)
g_assert_cmpstr (soup_address_get_physical (local), ==, "127.0.0.1");
g_assert_cmpint (soup_address_get_port (local), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
g_assert_cmpstr (soup_address_get_physical (remote), ==, "127.0.0.1");
- g_assert_cmpint (soup_address_get_port (remote), ==, soup_server_get_port (server));
+ g_assert_cmpint (soup_address_get_port (remote), ==, uri->port);
g_object_unref (local);
g_object_unref (remote);
diff --git a/tests/ssl-test.c b/tests/ssl-test.c
index e6bbb61..989c48d 100644
--- a/tests/ssl-test.c
+++ b/tests/ssl-test.c
@@ -2,16 +2,16 @@
#include "test-utils.h"
-static char *uri;
+SoupURI *uri;
static void
-do_properties_test_for_session (SoupSession *session, const char *uri)
+do_properties_test_for_session (SoupSession *session)
{
SoupMessage *msg;
GTlsCertificate *cert;
GTlsCertificateFlags flags;
- msg = soup_message_new ("GET", uri);
+ msg = soup_message_new_from_uri ("GET", uri);
soup_session_send_message (session, msg);
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
@@ -39,7 +39,7 @@ do_async_properties_tests (void)
SOUP_SESSION_SSL_CA_FILE, "/dev/null",
SOUP_SESSION_SSL_STRICT, FALSE,
NULL);
- do_properties_test_for_session (session, uri);
+ do_properties_test_for_session (session);
soup_test_session_abort_unref (session);
}
@@ -55,7 +55,7 @@ do_sync_properties_tests (void)
SOUP_SESSION_SSL_CA_FILE, "/dev/null",
SOUP_SESSION_SSL_STRICT, FALSE,
NULL);
- do_properties_test_for_session (session, uri);
+ do_properties_test_for_session (session);
soup_test_session_abort_unref (session);
}
@@ -109,7 +109,7 @@ do_strictness_test (gconstpointer data)
NULL);
}
- msg = soup_message_new ("GET", uri);
+ msg = soup_message_new_from_uri ("GET", uri);
soup_session_send_message (session, msg);
soup_test_assert_message_status (msg, test->expected_status);
@@ -127,6 +127,7 @@ do_strictness_test (gconstpointer data)
debug_printf (1, " tls error flags: 0x%x\n", flags);
g_object_unref (msg);
+
soup_test_session_abort_unref (session);
}
@@ -257,11 +258,11 @@ main (int argc, char **argv)
test_init (argc, argv, NULL);
if (tls_available) {
- server = soup_test_server_new_ssl (TRUE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
- uri = g_strdup_printf ("https://127.0.0.1:%u/",
- soup_server_get_port (server));
- }
+ uri = soup_test_server_get_uri (server, "https", "127.0.0.1");
+ } else
+ uri = NULL;
g_test_add_func ("/ssl/session-properties", do_session_property_tests);
g_test_add_func ("/ssl/message-properties/async", do_async_properties_tests);
@@ -276,7 +277,7 @@ main (int argc, char **argv)
ret = g_test_run ();
if (tls_available) {
- g_free (uri);
+ soup_uri_free (uri);
soup_test_server_quit_unref (server);
}
diff --git a/tests/streaming-test.c b/tests/streaming-test.c
index 8d8c02e..bd4a519 100644
--- a/tests/streaming-test.c
+++ b/tests/streaming-test.c
@@ -138,7 +138,6 @@ main (int argc, char **argv)
{
GMainLoop *loop;
SoupServer *server;
- guint port;
SoupURI *base_uri;
int ret;
@@ -149,15 +148,13 @@ main (int argc, char **argv)
(guchar *)full_response->data,
full_response->length);
- server = soup_test_server_new (FALSE);
+ server = soup_test_server_new (SOUP_TEST_SERVER_DEFAULT);
soup_server_add_handler (server, NULL,
server_callback, NULL, NULL);
- port = soup_server_get_port (server);
loop = g_main_loop_new (NULL, TRUE);
- base_uri = soup_uri_new ("http://127.0.0.1");
- soup_uri_set_port (base_uri, port);
+ base_uri = soup_test_server_get_uri (server, "http", NULL);
g_test_add_data_func ("/streaming/chunked", base_uri, do_chunked_test);
g_test_add_data_func ("/streaming/content-length", base_uri, do_content_length_test);
diff --git a/tests/test-utils.c b/tests/test-utils.c
index bc160ae..8fc7024 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -262,79 +262,217 @@ soup_test_session_abort_unref (SoupSession *session)
g_object_unref (session);
}
-static gpointer run_server_thread (gpointer user_data);
+static void
+server_listen (SoupServer *server)
+{
+ GError *error = NULL;
+ SoupServerListenOptions options =
+ GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (server), "listen-options"));
+
+ soup_server_listen_local (server, 0, options, &error);
+ if (error) {
+ g_printerr ("Unable to create server: %s\n", error->message);
+ exit (1);
+ }
+}
+
+static GMutex server_start_mutex;
+static GCond server_start_cond;
+
+static gpointer
+run_server_thread (gpointer user_data)
+{
+ SoupServer *server = user_data;
+ GMainContext *context;
+ GMainLoop *loop;
+
+ context = g_main_context_new ();
+ g_main_context_push_thread_default (context);
+ loop = g_main_loop_new (context, FALSE);
+ g_object_set_data (G_OBJECT (server), "GMainLoop", loop);
+
+ server_listen (server);
+
+ g_mutex_lock (&server_start_mutex);
+ g_cond_signal (&server_start_cond);
+ g_mutex_unlock (&server_start_mutex);
+
+ g_main_loop_run (loop);
+ g_main_loop_unref (loop);
-static SoupServer *
-test_server_new (gboolean in_own_thread, gboolean ssl)
+ soup_server_disconnect (server);
+
+ g_main_context_pop_thread_default (context);
+ g_main_context_unref (context);
+
+ return NULL;
+}
+
+SoupServer *
+soup_test_server_new (SoupTestServerOptions options)
{
SoupServer *server;
- GMainContext *async_context;
- char *ssl_cert_file, *ssl_key_file;
- SoupAddress *addr;
+ GTlsCertificate *cert = NULL;
+ GError *error = NULL;
- async_context = in_own_thread ? g_main_context_new () : NULL;
+ if (tls_available) {
+ char *ssl_cert_file, *ssl_key_file;
- if (ssl) {
ssl_cert_file = g_test_build_filename (G_TEST_DIST, "test-cert.pem", NULL);
ssl_key_file = g_test_build_filename (G_TEST_DIST, "test-key.pem", NULL);
- } else
- ssl_cert_file = ssl_key_file = NULL;
-
- addr = soup_address_new ("127.0.0.1", SOUP_ADDRESS_ANY_PORT);
- soup_address_resolve_sync (addr, NULL);
+ cert = g_tls_certificate_new_from_files (ssl_cert_file,
+ ssl_key_file,
+ &error);
+ g_free (ssl_cert_file);
+ g_free (ssl_key_file);
+ if (error) {
+ g_printerr ("Unable to create server: %s\n", error->message);
+ exit (1);
+ }
+ }
- server = soup_server_new (SOUP_SERVER_INTERFACE, addr,
- SOUP_SERVER_ASYNC_CONTEXT, async_context,
- SOUP_SERVER_SSL_CERT_FILE, ssl_cert_file,
- SOUP_SERVER_SSL_KEY_FILE, ssl_key_file,
+ server = soup_server_new (SOUP_SERVER_TLS_CERTIFICATE, cert,
NULL);
- g_object_unref (addr);
- if (async_context)
- g_main_context_unref (async_context);
- g_free (ssl_cert_file);
- g_free (ssl_key_file);
-
- if (!server) {
- g_printerr ("Unable to create server\n");
- exit (1);
- }
+ g_clear_object (&cert);
+
+ g_object_set_data (G_OBJECT (server), "options", GUINT_TO_POINTER (options));
- if (in_own_thread) {
+ if (options & SOUP_TEST_SERVER_IN_THREAD) {
GThread *thread;
+ g_mutex_lock (&server_start_mutex);
+
thread = g_thread_new ("server_thread", run_server_thread, server);
g_object_set_data (G_OBJECT (server), "thread", thread);
- } else
- soup_server_run_async (server);
+
+ if (!(options & SOUP_TEST_SERVER_NO_DEFAULT_LISTENER)) {
+ /* We have to call soup_server_listen() from the server's
+ * thread, but want to be sure we don't return from here
+ * until it happens, hence the locking.
+ */
+ g_cond_wait (&server_start_cond, &server_start_mutex);
+ g_mutex_unlock (&server_start_mutex);
+ }
+ } else if (!(options & SOUP_TEST_SERVER_NO_DEFAULT_LISTENER))
+ server_listen (server);
return server;
}
-SoupServer *
-soup_test_server_new (gboolean in_own_thread)
+static SoupURI *
+find_server_uri (SoupServer *server, const char *scheme, const char *host)
{
- return test_server_new (in_own_thread, FALSE);
+ GSList *uris, *u;
+ SoupURI *uri, *ret_uri = NULL;
+
+ uris = soup_server_get_uris (server);
+ for (u = uris; u; u = u->next) {
+ uri = u->data;
+
+ if (scheme && strcmp (uri->scheme, scheme) != 0)
+ continue;
+ if (host && strcmp (uri->host, host) != 0)
+ continue;
+
+ ret_uri = soup_uri_copy (uri);
+ break;
+ }
+ g_slist_free_full (uris, (GDestroyNotify)soup_uri_free);
+
+ return ret_uri;
}
-SoupServer *
-soup_test_server_new_ssl (gboolean in_own_thread)
+static SoupURI *
+add_listener (SoupServer *server, const char *scheme, const char *host)
{
- return test_server_new (in_own_thread, TRUE);
+ SoupServerListenOptions options = 0;
+ GError *error = NULL;
+
+ if (!g_strcmp0 (scheme, SOUP_URI_SCHEME_HTTPS))
+ options |= SOUP_SERVER_LISTEN_HTTPS;
+ if (!g_strcmp0 (host, "127.0.0.1"))
+ options |= SOUP_SERVER_LISTEN_IPV4_ONLY;
+ else if (!g_strcmp0 (host, "::1"))
+ options |= SOUP_SERVER_LISTEN_IPV6_ONLY;
+
+ soup_server_listen_local (server, 0, options, &error);
+ g_assert_no_error (error);
+
+ return find_server_uri (server, scheme, host);
}
-static gpointer
-run_server_thread (gpointer user_data)
+typedef struct {
+ GMutex mutex;
+ GCond cond;
+
+ SoupServer *server;
+ const char *scheme;
+ const char *host;
+
+ SoupURI *uri;
+} AddListenerData;
+
+static gboolean
+add_listener_in_thread (gpointer user_data)
{
- SoupServer *server = user_data;
+ AddListenerData *data = user_data;
- soup_server_run (server);
- return NULL;
+ data->uri = add_listener (data->server, data->scheme, data->host);
+ g_mutex_lock (&data->mutex);
+ g_cond_signal (&data->cond);
+ g_mutex_unlock (&data->mutex);
+
+ return FALSE;
+}
+
+SoupURI *
+soup_test_server_get_uri (SoupServer *server,
+ const char *scheme,
+ const char *host)
+{
+ SoupURI *uri;
+ GMainLoop *loop;
+
+ uri = find_server_uri (server, scheme, host);
+ if (uri)
+ return uri;
+
+ /* Need to add a new listener */
+ uri = soup_uri_new (NULL);
+ soup_uri_set_scheme (uri, scheme);
+ soup_uri_set_host (uri, host);
+
+ loop = g_object_get_data (G_OBJECT (server), "GMainLoop");
+ if (loop) {
+ GMainContext *context = g_main_loop_get_context (loop);
+ AddListenerData data;
+
+ g_mutex_init (&data.mutex);
+ g_cond_init (&data.cond);
+ data.server = server;
+ data.scheme = scheme;
+ data.host = host;
+ data.uri = NULL;
+
+ g_mutex_lock (&data.mutex);
+ soup_add_completion (context, add_listener_in_thread, &data);
+
+ while (!data.uri)
+ g_cond_wait (&data.cond, &data.mutex);
+
+ g_mutex_clear (&data.mutex);
+ g_cond_clear (&data.cond);
+ uri = data.uri;
+ } else
+ uri = add_listener (server, scheme, host);
+
+ return uri;
}
static gboolean
-idle_quit_server (gpointer server)
+idle_quit_server (gpointer loop)
{
- soup_server_quit (server);
+ g_main_loop_quit (loop);
return FALSE;
}
@@ -345,11 +483,15 @@ soup_test_server_quit_unref (SoupServer *server)
thread = g_object_get_data (G_OBJECT (server), "thread");
if (thread) {
- soup_add_completion (soup_server_get_async_context (server),
- idle_quit_server, server);
+ GMainLoop *loop;
+ GMainContext *context;
+
+ loop = g_object_get_data (G_OBJECT (server), "GMainLoop");
+ context = g_main_loop_get_context (loop);
+ soup_add_completion (context, idle_quit_server, loop);
g_thread_join (thread);
} else
- soup_server_quit (server);
+ soup_server_disconnect (server);
g_assert_cmpint (G_OBJECT (server)->ref_count, ==, 1);
g_object_unref (server);
diff --git a/tests/test-utils.h b/tests/test-utils.h
index 03637dc..43ef5a7 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -55,9 +55,17 @@ typedef enum {
SoupSession *soup_test_session_new (GType type, ...);
void soup_test_session_abort_unref (SoupSession *session);
-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);
+typedef enum {
+ SOUP_TEST_SERVER_DEFAULT = 0,
+ SOUP_TEST_SERVER_IN_THREAD = (1 << 0),
+ SOUP_TEST_SERVER_NO_DEFAULT_LISTENER = (1 << 1)
+} SoupTestServerOptions;
+
+SoupServer *soup_test_server_new (SoupTestServerOptions options);
+SoupURI *soup_test_server_get_uri (SoupServer *server,
+ const char *scheme,
+ const char *host);
+void soup_test_server_quit_unref (SoupServer *server);
GInputStream *soup_test_request_send (SoupRequest *req,
GCancellable *cancellable,
diff --git a/tests/timeout-test.c b/tests/timeout-test.c
index 81fb433..afb2c59 100644
--- a/tests/timeout-test.c
+++ b/tests/timeout-test.c
@@ -22,7 +22,7 @@ request_started_cb (SoupSession *session, SoupMessage *msg,
}
static void
-do_message_to_session (SoupSession *session, const char *uri,
+do_message_to_session (SoupSession *session, SoupURI *uri,
const char *comment, guint expected_status)
{
SoupMessage *msg;
@@ -30,7 +30,7 @@ do_message_to_session (SoupSession *session, const char *uri,
if (comment)
debug_printf (1, " msg %s\n", comment);
- msg = soup_message_new ("GET", uri);
+ msg = soup_message_new_from_uri ("GET", uri);
g_signal_connect (msg, "finished",
G_CALLBACK (message_finished), &finished);
@@ -51,8 +51,8 @@ static void
do_msg_tests_for_session (SoupSession *timeout_session,
SoupSession *idle_session,
SoupSession *plain_session,
- const char *fast_uri,
- const char *slow_uri)
+ SoupURI *fast_uri,
+ SoupURI *slow_uri)
{
SoupSocket *ret, *idle_first, *idle_second;
SoupSocket *plain_first, *plain_second;
@@ -100,7 +100,7 @@ do_msg_tests_for_session (SoupSession *timeout_session,
}
static void
-do_request_to_session (SoupSession *session, const char *uri,
+do_request_to_session (SoupSession *session, SoupURI *uri,
const char *comment, gboolean expect_timeout)
{
SoupRequest *req;
@@ -110,7 +110,7 @@ do_request_to_session (SoupSession *session, const char *uri,
gboolean finished = FALSE;
debug_printf (1, " req %s\n", comment);
- req = soup_session_request (session, uri, NULL);
+ req = soup_session_request_uri (session, uri, NULL);
msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
g_signal_connect (msg, "finished",
@@ -149,8 +149,8 @@ static void
do_req_tests_for_session (SoupSession *timeout_session,
SoupSession *idle_session,
SoupSession *plain_session,
- const char *fast_uri,
- const char *slow_uri)
+ SoupURI *fast_uri,
+ SoupURI *slow_uri)
{
SoupSocket *ret, *idle_first, *idle_second;
SoupSocket *plain_first, *plain_second;
@@ -201,11 +201,11 @@ static void
do_async_timeout_tests (gconstpointer data)
{
SoupSession *timeout_session, *idle_session, *plain_session;
- const char *fast_uri = data;
- const char *slow_uri = g_build_path ("/", fast_uri, "slow", NULL);
+ SoupURI *fast_uri = (SoupURI *)data;
+ SoupURI *slow_uri = soup_uri_new_with_base (fast_uri, "/slow");
gboolean extra_slow;
- if (g_str_has_prefix (fast_uri, "https")) {
+ if (fast_uri->scheme == SOUP_URI_SCHEME_HTTPS) {
SOUP_TEST_SKIP_IF_NO_TLS;
extra_slow = slow_https;
@@ -236,17 +236,19 @@ do_async_timeout_tests (gconstpointer data)
soup_test_session_abort_unref (timeout_session);
soup_test_session_abort_unref (idle_session);
soup_test_session_abort_unref (plain_session);
+
+ soup_uri_free (slow_uri);
}
static void
do_sync_timeout_tests (gconstpointer data)
{
SoupSession *timeout_session, *plain_session;
- const char *fast_uri = data;
- const char *slow_uri = g_build_path ("/", fast_uri, "slow", NULL);
+ SoupURI *fast_uri = (SoupURI *)data;
+ SoupURI *slow_uri = soup_uri_new_with_base (fast_uri, "/slow");
gboolean extra_slow;
- if (g_str_has_prefix (fast_uri, "https")) {
+ if (fast_uri->scheme == SOUP_URI_SCHEME_HTTPS) {
SOUP_TEST_SKIP_IF_NO_TLS;
extra_slow = slow_https;
@@ -290,7 +292,7 @@ server_handler (SoupServer *server,
if (!strcmp (path, "/slow")) {
soup_server_pause_message (server, msg);
g_object_set_data (G_OBJECT (msg), "server", server);
- soup_add_timeout (soup_server_get_async_context (server),
+ soup_add_timeout (g_main_context_get_thread_default (),
4000, timeout_finish_message, msg);
}
}
@@ -299,24 +301,22 @@ int
main (int argc, char **argv)
{
SoupServer *server, *https_server = NULL;
- char *uri, *https_uri = NULL;
+ SoupURI *uri, *https_uri = NULL;
int ret;
test_init (argc, argv, NULL);
server = soup_test_server_new (TRUE);
soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
- uri = g_strdup_printf ("http://127.0.0.1:%u/",
- soup_server_get_port (server));
+ uri = soup_test_server_get_uri (server, "http", NULL);
if (tls_available) {
SoupSession *test_session;
gint64 start, end;
- https_server = soup_test_server_new_ssl (TRUE);
+ https_server = soup_test_server_new (SOUP_TEST_SERVER_IN_THREAD);
soup_server_add_handler (https_server, NULL, server_handler, NULL, NULL);
- https_uri = g_strdup_printf ("https://127.0.0.1:%u/",
- soup_server_get_port (https_server));
+ https_uri = soup_test_server_get_uri (server, "https", "127.0.0.1");
/* The 1-second timeouts are too fast for some machines... */
test_session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -333,7 +333,7 @@ main (int argc, char **argv)
slow_https = FALSE;
}
} else
- https_uri = g_strdup ("https://fail.");
+ https_uri = soup_uri_new ("https://fail.");
g_test_add_data_func ("/timeout/http/async", uri, do_async_timeout_tests);
g_test_add_data_func ("/timeout/http/sync", uri, do_sync_timeout_tests);
@@ -342,8 +342,8 @@ main (int argc, char **argv)
ret = g_test_run ();
- g_free (uri);
- g_free (https_uri);
+ soup_uri_free (uri);
+ soup_uri_free (https_uri);
soup_test_server_quit_unref (server);
if (https_server)
soup_test_server_quit_unref (https_server);
diff --git a/tests/xmlrpc-server-test.c b/tests/xmlrpc-server-test.c
index bfeb200..bd8341d 100644
--- a/tests/xmlrpc-server-test.c
+++ b/tests/xmlrpc-server-test.c
@@ -310,15 +310,17 @@ int
main (int argc, char **argv)
{
SoupServer *server;
+ SoupURI *server_uri;
int ret;
test_init (argc, argv, no_test_entry);
- server = soup_test_server_new (run_tests);
+ server = soup_test_server_new (run_tests ? SOUP_TEST_SERVER_IN_THREAD : SOUP_TEST_SERVER_DEFAULT);
soup_server_add_handler (server, "/xmlrpc-server.php",
server_callback, NULL, NULL);
- uri = g_strdup_printf ("http://127.0.0.1:%u/xmlrpc-server.php",
- soup_server_get_port (server));
+ server_uri = soup_test_server_get_uri (server, "http", NULL);
+ soup_uri_set_path (server_uri, "/xmlrpc-server.php");
+ uri = soup_uri_to_string (server_uri, FALSE);
if (run_tests) {
char *out, **tests, *path;
@@ -363,6 +365,7 @@ main (int argc, char **argv)
}
soup_test_server_quit_unref (server);
+ soup_uri_free (server_uri);
g_free (uri);
if (run_tests)
test_cleanup ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]