[libgdata/657539-tasks-tests: 19/19] core: WIP
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata/657539-tasks-tests: 19/19] core: WIP
- Date: Mon, 15 Sep 2014 22:58:10 +0000 (UTC)
commit 7a9b98112f08b088bee8e0d23a999e1d3959b74c
Author: Philip Withnall <philip tecnocode co uk>
Date: Mon Sep 15 23:56:05 2014 +0100
core: WIP
configure.ac | 10 ++-
gdata/gdata-service.c | 7 ++-
gdata/gdata-upload-stream.c | 1 -
gdata/tests/streams.c | 178 ++++++++++++++++++++++++++++++++-----------
4 files changed, 149 insertions(+), 47 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2c72cae..9312664 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,7 +39,7 @@ GLIB_MAX_ALLOWED='(G_ENCODE_VERSION(2, 38))'
GIO_REQS=2.17.3
SOUP_REQS=2.42.0
SOUP_MIN_REQUIRED=SOUP_VERSION_2_42
-SOUP_MAX_ALLOWED=SOUP_VERSION_2_42
+SOUP_MAX_ALLOWED=SOUP_VERSION_2_48
OAUTH_REQS=0.9.4
GTK_REQS=2.91.2
GOA_REQS=3.8
@@ -91,6 +91,14 @@ GDATA_CFLAGS="$GDATA_CFLAGS -DJSON_VERSION_MIN_REQUIRED=$JSON_GLIB_MIN_REQUIRED
AC_SUBST(GDATA_CFLAGS)
AC_SUBST(GDATA_LIBS)
+# libsoup 2.47.3 is needed for the new SoupServer API.
+PKG_CHECK_MODULES([LIBSOUP], [libsoup-2.4 >= 2.47.3],
+ [have_libsoup_2_47_3=yes], [have_libsoup_2_47_3=no])
+AS_IF([test "x$have_libsoup_2_47_3" = "xyes"], [
+ AC_DEFINE([HAVE_LIBSOUP_2_47_3], [1],
+ [Define if the new SoupServer API is available])
+])
+
# Optional dependencies
PKG_CHECK_MODULES(GDK_PIXBUF, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQS, have_gdk_pixbuf=yes, have_gdk_pixbuf=no)
if test "x$have_gdk_pixbuf" = "xyes"; then
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index 8ac96ed..afcacd0 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -652,8 +652,13 @@ _gdata_service_actually_send_message (SoupSession *session, SoupMessage *message
* sent. */
if (cancellable == NULL || g_cancellable_is_cancelled (cancellable) == FALSE)
soup_session_send_message (session, message);
- else
+ else {
+ if (cancellable != NULL) {
+ g_mutex_unlock (&data.mutex);
+ }
+
soup_message_set_status (message, SOUP_STATUS_CANCELLED);
+ }
/* Clean up the cancellation code */
if (cancellable != NULL) {
diff --git a/gdata/gdata-upload-stream.c b/gdata/gdata-upload-stream.c
index 5043e0f..ce98545 100644
--- a/gdata/gdata-upload-stream.c
+++ b/gdata/gdata-upload-stream.c
@@ -1238,7 +1238,6 @@ finished_outer:
g_mutex_unlock (&(priv->write_mutex));
g_cond_signal (&(priv->finished_cond));
- g_mutex_unlock (&(priv->response_mutex));
/* Referenced in create_network_thread(). */
g_object_unref (self);
diff --git a/gdata/tests/streams.c b/gdata/tests/streams.c
index 92554d4..d0defaf 100644
--- a/gdata/tests/streams.c
+++ b/gdata/tests/streams.c
@@ -17,6 +17,8 @@
* License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "config.h"
+
#include <glib.h>
#include <locale.h>
#include <string.h>
@@ -28,6 +30,15 @@
#include "gdata.h"
#include "common.h"
+#ifdef HAVE_LIBSOUP_2_47_3
+static gpointer
+run_server_thread (GMainLoop *loop)
+{
+ g_main_loop_run (loop);
+
+ return NULL;
+}
+#else /* if !HAVE_LIBSOUP_2_47_3 */
static gpointer
run_server_thread (SoupServer *server)
{
@@ -35,26 +46,62 @@ run_server_thread (SoupServer *server)
return NULL;
}
+#endif /* !HAVE_LIBSOUP_2_47_3 */
static GThread *
-run_server (SoupServer *server)
+run_server (SoupServer *server, GMainLoop *loop)
{
GThread *thread;
gchar *port_string;
GError *error = NULL;
+ guint16 port;
+#ifdef HAVE_LIBSOUP_2_47_3
+ thread = g_thread_try_new ("server-thread", (GThreadFunc) run_server_thread, loop, &error);
+#else /* if !HAVE_LIBSOUP_2_47_3 */
thread = g_thread_try_new ("server-thread", (GThreadFunc) run_server_thread, server, &error);
+#endif /* !HAVE_LIBSOUP_2_47_3 */
g_assert_no_error (error);
g_assert (thread != NULL);
/* Set the port so that libgdata doesn't override it. */
- port_string = g_strdup_printf ("%u", soup_server_get_port (server));
+#ifdef HAVE_LIBSOUP_2_47_3
+{
+ GSList *uris; /* owned */
+
+ uris = soup_server_get_uris (server);
+ g_assert (uris != NULL);
+ port = soup_uri_get_port (uris->data);
+
+ g_slist_free_full (uris, (GDestroyNotify) soup_uri_free);
+}
+#else /* if !HAVE_LIBSOUP_2_47_3 */
+ port = soup_server_get_port (server);
+#endif /* !HAVE_LIBSOUP_2_47_3 */
+
+ port_string = g_strdup_printf ("%u", port);
g_setenv ("LIBGDATA_HTTPS_PORT", port_string, TRUE);
g_free (port_string);
return thread;
}
+#ifdef HAVE_LIBSOUP_2_47_3
+static gboolean
+quit_server_cb (GMainLoop *loop)
+{
+ g_main_loop_quit (loop);
+
+ return FALSE;
+}
+
+static void
+stop_server (SoupServer *server, GMainLoop *loop)
+{
+ soup_add_completion (g_main_loop_get_context (loop),
+ (GSourceFunc) quit_server_cb, loop);
+}
+#else /* if !HAVE_LIBSOUP_2_47_3 */
static gboolean
quit_server_cb (SoupServer *server)
{
@@ -63,6 +110,14 @@ quit_server_cb (SoupServer *server)
return FALSE;
}
+static void
+stop_server (SoupServer *server, GMainLoop *loop)
+{
+ soup_add_completion (g_main_loop_get_context (loop),
+ (GSourceFunc) quit_server_cb, server);
+}
+#endif /* !HAVE_LIBSOUP_2_47_3 */
+
static gchar *
get_test_string (guint start_num, guint end_num)
{
@@ -97,18 +152,36 @@ test_download_stream_download_server_content_length_handler_cb (SoupServer *serv
}
static SoupServer *
-create_server (SoupServerCallback callback, gpointer user_data, GMainContext **async_context)
+create_server (SoupServerCallback callback, gpointer user_data, GMainLoop **main_loop)
{
+ GMainContext *context;
+ SoupServer *server;
+#ifdef HAVE_LIBSOUP_2_47_3
+ GError *error = NULL;
+#else /* if !HAVE_LIBSOUP_2_47_3 */
union {
struct sockaddr_in in;
struct sockaddr norm;
} sock;
SoupAddress *addr;
- SoupServer *server;
-
- g_assert (async_context != NULL);
+#endif /* HAVE_LIBSOUP_2_47_3 */
/* Create the server */
+ g_assert (main_loop != NULL);
+ context = g_main_context_new ();
+ *main_loop = g_main_loop_new (context, FALSE);
+
+#ifdef HAVE_LIBSOUP_2_47_3
+ server = soup_server_new (NULL, NULL);
+
+ g_main_context_push_thread_default (context);
+
+ soup_server_listen_local (server, 0 /* random port */,
+ 0 /* no options */, &error);
+ g_assert_no_error (error);
+
+ g_main_context_pop_thread_default (context);
+#else /* if !HAVE_LIBSOUP_2_47_3 */
memset (&sock, 0, sizeof (sock));
sock.in.sin_family = AF_INET;
sock.in.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
@@ -117,16 +190,17 @@ create_server (SoupServerCallback callback, gpointer user_data, GMainContext **a
addr = soup_address_new_from_sockaddr (&sock.norm, sizeof (sock.norm));
g_assert (addr != NULL);
- *async_context = g_main_context_new ();
-
server = soup_server_new (SOUP_SERVER_INTERFACE, addr,
- SOUP_SERVER_ASYNC_CONTEXT, *async_context,
+ SOUP_SERVER_ASYNC_CONTEXT, context,
NULL);
- soup_server_add_handler (server, NULL, callback, user_data, NULL);
g_object_unref (addr);
+#endif /* !HAVE_LIBSOUP_2_47_3 */
+
+ soup_server_add_handler (server, NULL, callback, user_data, NULL);
g_assert (server != NULL);
+ g_main_context_unref (context);
return server;
}
@@ -134,16 +208,32 @@ create_server (SoupServerCallback callback, gpointer user_data, GMainContext **a
static gchar *
build_server_uri (SoupServer *server)
{
+#ifdef HAVE_LIBSOUP_2_47_3
+ GSList *uris; /* owned */
+ gchar *retval = NULL; /* owned */
+
+ uris = soup_server_get_uris (server);
+ if (uris == NULL) {
+ return NULL;
+ }
+
+ retval = soup_uri_to_string (uris->data, FALSE);
+
+ g_slist_free_full (uris, (GDestroyNotify) soup_uri_free);
+
+ return retval;
+#else /* if !HAVE_LIBSOUP_2_47_3 */
return g_strdup_printf ("http://%s:%u/",
soup_address_get_physical (soup_socket_get_local_address
(soup_server_get_listener (server))),
soup_server_get_port (server));
+#endif /* !HAVE_LIBSOUP_2_47_3 */
}
static void
test_download_stream_download_content_length (void)
{
SoupServer *server;
- GMainContext *async_context;
+ GMainLoop *main_loop;
GThread *thread;
gchar *download_uri, *test_string;
GDataService *service;
@@ -155,8 +245,8 @@ test_download_stream_download_content_length (void)
GError *error = NULL;
/* Create and run the server */
- server = create_server ((SoupServerCallback)
test_download_stream_download_server_content_length_handler_cb, NULL, &async_context);
- thread = run_server (server);
+ server = create_server ((SoupServerCallback)
test_download_stream_download_server_content_length_handler_cb, NULL, &main_loop);
+ thread = run_server (server, main_loop);
/* Create a new download stream connected to the server */
download_uri = build_server_uri (server);
@@ -193,12 +283,12 @@ test_download_stream_download_content_length (void)
g_string_free (contents, TRUE);
/* Kill the server and wait for it to die */
- soup_add_completion (async_context, (GSourceFunc) quit_server_cb, server);
+ stop_server (server, main_loop);
g_thread_join (thread);
g_object_unref (download_stream);
g_object_unref (server);
- g_main_context_unref (async_context);
+ g_main_loop_unref (main_loop);
}
static void
@@ -221,7 +311,7 @@ static void
test_download_stream_download_seek_before_start (void)
{
SoupServer *server;
- GMainContext *async_context;
+ GMainLoop *main_loop;
GThread *thread;
gchar *download_uri, *test_string;
goffset test_string_offset = 0;
@@ -234,8 +324,8 @@ test_download_stream_download_seek_before_start (void)
GError *error = NULL;
/* Create and run the server */
- server = create_server ((SoupServerCallback) test_download_stream_download_server_seek_handler_cb,
NULL, &async_context);
- thread = run_server (server);
+ server = create_server ((SoupServerCallback) test_download_stream_download_server_seek_handler_cb,
NULL, &main_loop);
+ thread = run_server (server, main_loop);
/* Create a new download stream connected to the server */
download_uri = build_server_uri (server);
@@ -297,12 +387,12 @@ test_download_stream_download_seek_before_start (void)
g_assert (success == TRUE);
/* Kill the server and wait for it to die */
- soup_add_completion (async_context, (GSourceFunc) quit_server_cb, server);
+ stop_server (server, main_loop);
g_thread_join (thread);
g_object_unref (download_stream);
g_object_unref (server);
- g_main_context_unref (async_context);
+ g_main_loop_unref (main_loop);
}
/* Test seeking forwards after the first read */
@@ -310,7 +400,7 @@ static void
test_download_stream_download_seek_after_start_forwards (void)
{
SoupServer *server;
- GMainContext *async_context;
+ GMainLoop *main_loop;
GThread *thread;
gchar *download_uri, *test_string;
goffset test_string_offset = 0;
@@ -323,8 +413,8 @@ test_download_stream_download_seek_after_start_forwards (void)
GError *error = NULL;
/* Create and run the server */
- server = create_server ((SoupServerCallback) test_download_stream_download_server_seek_handler_cb,
NULL, &async_context);
- thread = run_server (server);
+ server = create_server ((SoupServerCallback) test_download_stream_download_server_seek_handler_cb,
NULL, &main_loop);
+ thread = run_server (server, main_loop);
/* Create a new download stream connected to the server */
download_uri = build_server_uri (server);
@@ -386,12 +476,12 @@ test_download_stream_download_seek_after_start_forwards (void)
g_assert (success == TRUE);
/* Kill the server and wait for it to die */
- soup_add_completion (async_context, (GSourceFunc) quit_server_cb, server);
+ stop_server (server, main_loop);
g_thread_join (thread);
g_object_unref (download_stream);
g_object_unref (server);
- g_main_context_unref (async_context);
+ g_main_loop_unref (main_loop);
}
/* Test seeking backwards after the first read */
@@ -399,7 +489,7 @@ static void
test_download_stream_download_seek_after_start_backwards (void)
{
SoupServer *server;
- GMainContext *async_context;
+ GMainLoop *main_loop;
GThread *thread;
gchar *download_uri, *test_string;
goffset test_string_offset = 0;
@@ -412,8 +502,8 @@ test_download_stream_download_seek_after_start_backwards (void)
GError *error = NULL;
/* Create and run the server */
- server = create_server ((SoupServerCallback) test_download_stream_download_server_seek_handler_cb,
NULL, &async_context);
- thread = run_server (server);
+ server = create_server ((SoupServerCallback) test_download_stream_download_server_seek_handler_cb,
NULL, &main_loop);
+ thread = run_server (server, main_loop);
/* Create a new download stream connected to the server */
download_uri = build_server_uri (server);
@@ -470,12 +560,12 @@ test_download_stream_download_seek_after_start_backwards (void)
g_assert (success == TRUE);
/* Kill the server and wait for it to die */
- soup_add_completion (async_context, (GSourceFunc) quit_server_cb, server);
+ stop_server (server, main_loop);
g_thread_join (thread);
g_object_unref (download_stream);
g_object_unref (server);
- g_main_context_unref (async_context);
+ g_main_loop_unref (main_loop);
}
static void
@@ -510,7 +600,7 @@ static void
test_upload_stream_upload_no_entry_content_length (void)
{
SoupServer *server;
- GMainContext *async_context;
+ GMainLoop *main_loop;
GThread *thread;
gchar *upload_uri, *test_string;
GDataService *service;
@@ -522,8 +612,8 @@ test_upload_stream_upload_no_entry_content_length (void)
GError *error = NULL;
/* Create and run the server */
- server = create_server ((SoupServerCallback)
test_upload_stream_upload_no_entry_content_length_server_handler_cb, NULL, &async_context);
- thread = run_server (server);
+ server = create_server ((SoupServerCallback)
test_upload_stream_upload_no_entry_content_length_server_handler_cb, NULL, &main_loop);
+ thread = run_server (server, main_loop);
/* Create a new upload stream uploading to the server */
upload_uri = build_server_uri (server);
@@ -556,12 +646,12 @@ test_upload_stream_upload_no_entry_content_length (void)
g_assert (success == TRUE);
/* Kill the server and wait for it to die */
- soup_add_completion (async_context, (GSourceFunc) quit_server_cb, server);
+ stop_server (server, main_loop);
g_thread_join (thread);
g_object_unref (upload_stream);
g_object_unref (server);
- g_main_context_unref (async_context);
+ g_main_loop_unref (main_loop);
}
/* Test parameters for a run of test_upload_stream_resumable(). */
@@ -772,7 +862,7 @@ error: {
return;
continuation: {
- gchar *upload_uri;
+ gchar *upload_uri, *server_uri;
/* Continuation. */
if (server_data->next_path_index == 0) {
@@ -781,12 +871,12 @@ continuation: {
soup_message_set_status (message, 308);
}
- upload_uri = g_strdup_printf ("http://%s:%u/%u",
- soup_address_get_physical (soup_socket_get_local_address
(soup_server_get_listener (server))),
- soup_server_get_port (server),
+ server_uri = build_server_uri (server);
+ upload_uri = g_strdup_printf ("%s/%u", server_uri,
++server_data->next_path_index);
soup_message_headers_replace (message->response_headers, "Location", upload_uri);
g_free (upload_uri);
+ g_free (server_uri);
}
return;
@@ -836,7 +926,7 @@ test_upload_stream_resumable (gconstpointer user_data)
UploadStreamResumableTestParams *test_params;
UploadStreamResumableServerData server_data;
SoupServer *server;
- GMainContext *async_context;
+ GMainLoop *main_loop;
GThread *thread;
gchar *upload_uri;
GDataService *service;
@@ -869,8 +959,8 @@ test_upload_stream_resumable (gconstpointer user_data)
server_data.next_path_index = 0;
server_data.test_string = test_string;
- server = create_server ((SoupServerCallback) test_upload_stream_resumable_server_handler_cb,
&server_data, &async_context);
- thread = run_server (server);
+ server = create_server ((SoupServerCallback) test_upload_stream_resumable_server_handler_cb,
&server_data, &main_loop);
+ thread = run_server (server, main_loop);
/* Create a new upload stream uploading to the server */
if (test_params->content_type == CONTENT_AND_METADATA || test_params->content_type == METADATA_ONLY) {
@@ -936,13 +1026,13 @@ test_upload_stream_resumable (gconstpointer user_data)
}
/* Kill the server and wait for it to die */
- soup_add_completion (async_context, (GSourceFunc) quit_server_cb, server);
+ stop_server (server, main_loop);
g_thread_join (thread);
g_free (test_string);
g_object_unref (upload_stream);
g_object_unref (server);
- g_main_context_unref (async_context);
+ g_main_loop_unref (main_loop);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]