[gupnp/wip/phako/libsoup3] wip



commit cb94530b3fde56245f0d905e8991cb1cb15cf4c1
Author: Jens Georg <mail jensge org>
Date:   Mon Dec 6 13:40:22 2021 +0100

    wip

 libgupnp/gupnp-context.c |  2 +-
 tests/test-context.c     | 11 ++++++++++-
 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..88a263b 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_application_name()? : "");
 
         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,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]