gdbus-auth: Fix leaks in tests
[platform/upstream/glib.git] / gio / tests / gdbus-addresses.c
index 568c775..c5a237d 100644 (file)
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static void
+test_empty_address (void)
+{
+  GError *error;
+  error = NULL;
+  g_dbus_address_get_stream_sync ("",
+                                  NULL,
+                                  NULL,
+                                  &error);
+  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
+  g_error_free (error);
+}
+
 #ifdef G_OS_UNIX
 static void
 test_unix_address (void)
@@ -61,17 +74,73 @@ test_nonce_tcp_address (void)
   g_assert (!g_dbus_is_supported_address ("nonce-tcp:host=,port=420000,noncefile=/foo/bar,family=ipv4", NULL));
 }
 
+static void
+test_tcp_address (void)
+{
+  g_assert (g_dbus_is_supported_address ("tcp:host=localhost", NULL));
+  g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,noncefile=/tmp/foo", NULL));
+  g_assert (g_dbus_is_supported_address ("tcp:host=localhost,port=42", NULL));
+  g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=-1", NULL));
+  g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=420000", NULL));
+  g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=42x", NULL));
+  g_assert (g_dbus_is_supported_address ("tcp:host=localhost,port=42,family=ipv4", NULL));
+  g_assert (g_dbus_is_supported_address ("tcp:host=localhost,port=42,family=ipv6", NULL));
+  g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=42,family=sopranos", NULL));
+}
+
+static void
+test_autolaunch_address (void)
+{
+  g_assert (g_dbus_is_supported_address ("autolaunch:", NULL));
+}
+
+static void
+test_mixed_address (void)
+{
+  g_assert (g_dbus_is_supported_address ("unix:path=/tmp/dbus1;unix:path=/tmp/dbus2", NULL));
+  g_assert (g_dbus_is_supported_address ("tcp:host=localhost,port=42;autolaunch:", NULL));
+  g_assert (!g_dbus_is_supported_address ("tcp:host=localhost,port=42;tcp:family=bla", NULL));
+}
+
+static const struct { const char *before; const char *after; } escaping[] = {
+      { "foo", "foo" },
+      { "/.\\-_", "/.\\-_" },
+      { "<=>", "%3C%3D%3E" },
+      { "/foo~1", "/foo%7E1" },
+      { "\xe2\x98\xad\xff", "%E2%98%AD%FF" },
+      { NULL, NULL }
+};
+
+static void
+test_escape_address (void)
+{
+  gsize i;
+
+  for (i = 0; escaping[i].before != NULL; i++)
+    {
+      gchar *s = g_dbus_address_escape_value (escaping[i].before);
+
+      g_assert_cmpstr (s, ==, escaping[i].after);
+      g_free (s);
+    }
+}
+
 int
 main (int   argc,
       char *argv[])
 {
-  g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
+  g_test_add_func ("/gdbus/empty-address", test_empty_address);
 #ifdef G_OS_UNIX
   g_test_add_func ("/gdbus/unix-address", test_unix_address);
 #endif
   g_test_add_func ("/gdbus/nonce-tcp-address", test_nonce_tcp_address);
+  g_test_add_func ("/gdbus/tcp-address", test_tcp_address);
+  g_test_add_func ("/gdbus/autolaunch-address", test_autolaunch_address);
+  g_test_add_func ("/gdbus/mixed-address", test_mixed_address);
+  g_test_add_func ("/gdbus/escape-address", test_escape_address);
+
   return g_test_run();
 }