[gupnp/wip/phako/libsoup3] tests: Check context creation fails



commit 0c73fddf0af66f2341ae3199669e232c956108a8
Author: Jens Georg <mail jensge org>
Date:   Sun Nov 21 16:29:26 2021 +0100

    tests: Check context creation fails
    
    If we cannot listen on our internal server port, fail the GInitable
    creation

 libgupnp/gupnp-context.c |  3 +++
 tests/test-context.c     | 35 +++++++++++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)
---
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index b8214a1..8f935f9 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -22,6 +22,9 @@
  */
 
 #include <config.h>
+
+#define G_LOG_DOMAIN "gupnp-context"
+
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
diff --git a/tests/test-context.c b/tests/test-context.c
index 2733512..61a1ae9 100644
--- a/tests/test-context.c
+++ b/tests/test-context.c
@@ -6,9 +6,7 @@
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
 #include <string.h>
 
@@ -215,11 +213,44 @@ test_gupnp_context_http_ranged_requests (void)
         g_mapped_file_unref (file);
 }
 
+static void
+test_gupnp_context_error_when_bound ()
+{
+        GError *error = NULL;
+        SoupServer *server = soup_server_new (NULL, NULL);
+        soup_server_listen_local (server, 0, 0, &error);
+        g_assert_no_error (error);
+
+        GSList *uris = soup_server_get_uris (server);
+
+        const char *address = g_uri_get_host (uris->data);
+        int port = g_uri_get_port (uris->data);
+
+        g_test_expect_message (
+                "gupnp-context",
+                G_LOG_LEVEL_WARNING,
+                "*Unable to listen*Could not listen*Address already in use*");
+        GUPnPContext *context = g_initable_new (GUPNP_TYPE_CONTEXT,
+                                                NULL,
+                                                &error,
+                                                "host-ip",
+                                                address,
+                                                "port",
+                                                port,
+                                                NULL);
+
+        g_test_assert_expected_messages ();
+        g_assert_error (error, GUPNP_SERVER_ERROR, GUPNP_SERVER_ERROR_OTHER);
+        g_assert_null (context);
+}
+
 int main (int argc, char *argv[]) {
         g_test_init (&argc, &argv, NULL);
         g_test_add_func ("/context/http/ranged-requests",
                          test_gupnp_context_http_ranged_requests);
 
+        g_test_add_func ("/context/creation/error-when-bound", test_gupnp_context_error_when_bound);
+
         g_test_run ();
 
         return 0;


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