diff options
author | Jens Georg <mail@jensge.org> | 2021-12-06 13:40:22 +0100 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2021-12-30 10:10:21 +0100 |
commit | 3cc9ff3f21538ddd981288fdf9d3dffe2acc8ef0 (patch) | |
tree | d4fdcd7942cc655af2b2754c7e3aeb86521eeb96 | |
parent | 0c73fddf0af66f2341ae3199669e232c956108a8 (diff) | |
download | gupnp-3cc9ff3f21538ddd981288fdf9d3dffe2acc8ef0.tar.gz |
tests: Make sure the session is cleaned properly
-rw-r--r-- | libgupnp/gupnp-context.c | 2 | ||||
-rw-r--r-- | tests/test-context.c | 11 | ||||
-rw-r--r-- | tests/test-service.c | 44 |
3 files changed, 38 insertions, 19 deletions
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c index 8f935f9..b5b9325 100644 --- a/libgupnp/gupnp-context.c +++ b/libgupnp/gupnp-context.c @@ -186,7 +186,7 @@ gupnp_context_initable_init (GInitable *initable, priv->session = soup_session_new (); user_agent = g_strdup_printf ("%s GUPnP/" VERSION " DLNADOC/1.50", - g_get_prgname ()? : ""); + g_get_prgname()? : ""); soup_session_set_user_agent (priv->session, user_agent); g_free (user_agent); diff --git a/tests/test-context.c b/tests/test-context.c index 61a1ae9..42311c7 100644 --- a/tests/test-context.c +++ b/tests/test-context.c @@ -63,7 +63,7 @@ request_range_and_compare (GMappedFile *file, soup_message_headers_set_range (request_headers, want_start, want_end); - /* interpretation according to SoupRange documentation */ + // interpretation according to SoupRange documentation if (want_end == -1) { if (want_start < 0) { want_length = -want_start; @@ -209,7 +209,12 @@ test_gupnp_context_http_ranged_requests (void) g_free (uri); g_object_unref (context); + + // Make sure the source teardown handlers get run so we don't confuse valgrind + g_timeout_add (500, g_main_loop_quit, loop); + g_main_loop_run (loop); g_main_loop_unref (loop); + g_object_unref (session); g_mapped_file_unref (file); } @@ -239,9 +244,13 @@ test_gupnp_context_error_when_bound () port, NULL); + g_slist_free_full (uris, (GDestroyNotify) g_uri_unref); + g_object_unref (server); + g_test_assert_expected_messages (); g_assert_error (error, GUPNP_SERVER_ERROR, GUPNP_SERVER_ERROR_OTHER); g_assert_null (context); + g_clear_error (&error); } int main (int argc, char *argv[]) { diff --git a/tests/test-service.c b/tests/test-service.c index c69910c..0cf57e5 100644 --- a/tests/test-service.c +++ b/tests/test-service.c @@ -16,7 +16,7 @@ create_context (guint16 port, GError **error) error, "host-ip", "127.0.0.1", - "msearch-port", + "port", port, NULL)); } @@ -63,9 +63,34 @@ on_finished (SoupServerMessage *msg, TestServiceNotificationCancelledData *data) g_main_loop_quit (data->loop); } +static SoupMessage * +prepare_subscribe_message (const char *subscription_uri, SoupServer *server) +{ + SoupMessage *msg = soup_message_new ("SUBSCRIBE", subscription_uri); + + GSList *uris = soup_server_get_uris (server); + GUri *subscription = + soup_uri_copy (uris->data, SOUP_URI_PATH, "/Notify", NULL); + char *uri_string = g_uri_to_string (subscription); + char *callback = g_strdup_printf ("<%s>", uri_string); + g_free (uri_string); + g_slist_free_full (uris, (GDestroyNotify) g_uri_unref); + g_uri_unref (subscription); + + SoupMessageHeaders *h = soup_message_get_request_headers (msg); + soup_message_headers_append (h, "Callback", callback); + g_free (callback); + + soup_message_headers_append (h, "NT", "upnp:event"); + + return msg; +} + static void test_service_notification_cancelled () { + // Check that the notification message is cancelled correctly if the service is + // Shut down during sending GUPnPContext *context = NULL; GError *error = NULL; GUPnPRootDevice *rd; @@ -100,23 +125,8 @@ test_service_notification_cancelled () GUPNP_DEVICE_INFO (rd), "urn:test-gupnp-org:service:TestService:1"); char *url = gupnp_service_info_get_event_subscription_url (info); - SoupMessage *msg = soup_message_new ("SUBSCRIBE", url); - g_free (url); - - GSList *uris = soup_server_get_uris (server); - GUri *subscription = - soup_uri_copy (uris->data, SOUP_URI_PATH, "/Notify", NULL); - char *uri_string = g_uri_to_string (subscription); - char *callback = g_strdup_printf ("<%s>", uri_string); - g_free (uri_string); - g_slist_free_full (uris, (GDestroyNotify) g_uri_unref); - g_uri_unref (subscription); - - SoupMessageHeaders *h = soup_message_get_request_headers (msg); - soup_message_headers_append (h, "Callback", callback); - g_free (callback); - soup_message_headers_append (h, "NT", "upnp:event"); + SoupMessage *msg = prepare_subscribe_message (url, server); SoupSession *session = soup_session_new (); // FIXME: Add timeout header soup_session_send_and_read_async (session, |