[gssdp] tests: Add test for getting the netmask



commit 793f6cefcf87e3997312d0ba9e80bd3bc0d08051
Author: Jens Georg <mail jensge org>
Date:   Thu Jul 2 21:47:08 2020 +0200

    tests: Add test for getting the netmask
    
    This is related to #7

 tests/test-regression.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
---
diff --git a/tests/test-regression.c b/tests/test-regression.c
index 1b3065d..c3013ab 100644
--- a/tests/test-regression.c
+++ b/tests/test-regression.c
@@ -28,6 +28,7 @@
 
 #include <gio/gio.h>
 
+#include <libgssdp/gssdp-error.h>
 #include <libgssdp/gssdp-resource-browser.h>
 #include <libgssdp/gssdp-resource-group.h>
 #include <libgssdp/gssdp-protocol.h>
@@ -413,6 +414,63 @@ static void test_ggo_1(void)
  * ============================================================================
  */
 
+/* BEGIN Regression test
+ * https://gitlab.gnome.org/GNOME/gssdp/issues/7
+ * ============================================================================
+ *  - Check that creating a GSSDPClient with interface and ip will have a set
+ *    network mask
+ */
+void test_ggo_7 () {
+        GError *error = NULL;
+
+
+
+        // Detect the name of the adapter belonging to 127.0.0.1
+        // Yes, this is awkward, but on Windows I believe the GUID is unique for
+        // the system, but not the same on every windows and *BSD is different to
+        // Linux as well (lo0 vs lo)
+        GSSDPClient *client = g_initable_new (GSSDP_TYPE_CLIENT,
+                                              NULL,
+                                              &error,
+                                              "host-ip", "127.0.0.1",
+                                              NULL);
+        g_assert_no_error (error);
+        g_assert_nonnull (client);
+
+        char *iface = g_strdup (gssdp_client_get_interface (client));
+        g_clear_object (&client);
+
+        g_debug("Found adapter %s for 127.0.0.1", iface);
+
+        // Check that trying to get a client for a non-existing interface fails
+        client = g_initable_new (GSSDP_TYPE_CLIENT,
+                                 NULL,
+                                 &error,
+                                 "host-ip", "127.0.0.1",
+                                 "interface", "ThisShouldNotExist",
+                                 NULL);
+        g_assert_error (error, GSSDP_ERROR, GSSDP_ERROR_FAILED);
+        g_assert_null (client);
+        g_clear_error (&error);
+
+        client = g_initable_new (GSSDP_TYPE_CLIENT,
+                                 NULL,
+                                 &error,
+                                 "host-ip", "127.0.0.1",
+                                 "interface", iface,
+                                 NULL);
+        g_assert_no_error (error);
+        g_assert_nonnull (client);
+        g_assert_nonnull (gssdp_client_get_address_mask (client));
+
+        g_free (iface);
+}
+
+/* END Regression test
+ * https://gitlab.gnome.org/GNOME/gssdp/issues/7
+ * ============================================================================
+ */
+
 
 int main (int argc, char *argv[])
 {
@@ -427,6 +485,7 @@ int main (int argc, char *argv[])
                g_test_add_func ("/bugs/gnome/724030", test_bgo724030);
                g_test_add_func ("/bugs/ggo/1", test_ggo_1);
         }
+        g_test_add_func ("/bugs/ggo/7", test_ggo_7);
 
         g_test_run ();
 


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