From 231423c40b639bf0c1eadc49234a961aa227efc9 Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Sun, 20 Nov 2022 18:27:38 +0100 Subject: context: Fix getting port if port was random Fixed #81 --- libgupnp/gupnp-context.c | 5 +++-- tests/test-bugs.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ tests/test-context.c | 3 +++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c index 1df57c5..c486282 100644 --- a/libgupnp/gupnp-context.c +++ b/libgupnp/gupnp-context.c @@ -88,13 +88,14 @@ G_DEFINE_TYPE_EXTENDED (GUPnPContext, (G_TYPE_INITABLE, gupnp_context_initable_iface_init)) -enum { +enum +{ PROP_0, PROP_SERVER, PROP_SESSION, PROP_SUBSCRIPTION_TIMEOUT, PROP_DEFAULT_LANGUAGE, - PROP_ACL + PROP_ACL, }; typedef struct { diff --git a/tests/test-bugs.c b/tests/test-bugs.c index d77b37e..5f4d85a 100644 --- a/tests/test-bugs.c +++ b/tests/test-bugs.c @@ -859,6 +859,52 @@ test_ggo_60_no_crash () g_main_loop_unref (data.loop); } +void +test_ggo_81 () +{ + GInetAddress *address = + g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4); + GError *error = NULL; + + GUPnPContext *context = + gupnp_context_new_for_address (address, + 4711, + GSSDP_UDA_VERSION_1_0, + &error); + g_assert_nonnull (context); + g_assert_no_error (error); + g_assert_cmpint (4711, ==, gupnp_context_get_port (context)); + g_assert_cmpint (4711, + ==, + gssdp_client_get_port (GSSDP_CLIENT (context))); + + guint port = 0; + g_object_get (context, "port", &port, NULL); + g_assert_cmpint (4711, ==, port); + + g_object_unref (context); + + context = gupnp_context_new_for_address (address, + 0, + GSSDP_UDA_VERSION_1_0, + &error); + + g_assert_nonnull (context); + g_assert_no_error (error); + port = gupnp_context_get_port (context); + g_assert_cmpint (0, !=, port); + + guint port2 = 0; + g_object_get (context, "port", &port2, NULL); + g_assert_cmpint (port, ==, port2); + + g_assert_cmpint (port2, + ==, + gssdp_client_get_port (GSSDP_CLIENT (context))); + + g_object_unref (context); + g_object_unref (address); +} int main (int argc, char *argv[]) { g_test_init (&argc, &argv, NULL); @@ -871,6 +917,7 @@ main (int argc, char *argv[]) { g_test_add_func ("/bugs/ggo/42", test_ggo_42); g_test_add_func ("/bugs/ggo/63", test_ggo_63); g_test_add_func ("/bugs/ggo/60", test_ggo_60_no_crash); + g_test_add_func ("/bugs/ggo/81", test_ggo_81); return g_test_run (); } diff --git a/tests/test-context.c b/tests/test-context.c index 12a9914..e781455 100644 --- a/tests/test-context.c +++ b/tests/test-context.c @@ -1098,6 +1098,8 @@ test_gupnp_context_host_path_invalid_methods (ContextTestFixture *tf, } g_free (rewritten_uri); } + + int main (int argc, char *argv[]) { @@ -1268,6 +1270,7 @@ main (int argc, char *argv[]) test_fixture_setup, test_gupnp_context_host_path_invalid_methods, test_fixture_teardown); + g_free (name); it++; } -- cgit v1.2.1