test/loopback: Assert that the connectable address makes sense
authorSimon McVittie <smcv@collabora.com>
Wed, 28 Jun 2017 17:52:12 +0000 (18:52 +0100)
committerSimon McVittie <smcv@collabora.com>
Thu, 29 Jun 2017 13:03:36 +0000 (14:03 +0100)
When we listen on a tcp: address we should get a connectable tcp:
address, and so on.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101567

test/loopback.c

index 46e9758..0d94e1b 100644 (file)
@@ -158,13 +158,86 @@ setup_no_runtime (Fixture *f,
 
 static void
 test_connect (Fixture *f,
-    gconstpointer addr G_GNUC_UNUSED)
+    gconstpointer addr)
 {
+  const char *listening_address = addr;
   char *address;
+  DBusAddressEntry **entries;
+  int n_entries;
+  dbus_bool_t ok;
+
   g_assert (f->server_conn == NULL);
 
   address = dbus_server_get_address (f->server);
   g_test_message ("listening at %s", address);
+
+  ok = dbus_parse_address (address, &entries, &n_entries, &f->e);
+  assert_no_error (&f->e);
+  g_assert_true (ok);
+  g_assert_cmpint (n_entries, ==, 1);
+
+  g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "guid"), !=,
+                   NULL);
+
+  if (g_strcmp0 (listening_address, "tcp:host=127.0.0.1") == 0)
+    {
+      g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "tcp");
+      g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "host"), ==,
+                       "127.0.0.1");
+      g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "port"), !=,
+                       NULL);
+      g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "noncefile"),
+                       ==, NULL);
+    }
+  else if (g_strcmp0 (listening_address, "nonce-tcp:host=127.0.0.1") == 0)
+    {
+      g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==,
+                       "nonce-tcp");
+      g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "host"), ==,
+                       "127.0.0.1");
+      g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "port"), !=,
+                       NULL);
+      g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "noncefile"),
+                       !=, NULL);
+    }
+#ifdef DBUS_UNIX
+  else if (g_strcmp0 (listening_address, "unix:tmpdir=/tmp") == 0)
+    {
+      g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "unix");
+
+      if (dbus_address_entry_get_value (entries[0], "abstract") != NULL)
+        {
+          const char *abstract = dbus_address_entry_get_value (entries[0],
+                                                               "abstract");
+
+          g_assert_true (g_str_has_prefix (abstract, "/tmp/dbus-"));
+          g_assert_cmpstr (dbus_address_entry_get_value (entries[0], "path"),
+                                                         ==, NULL);
+        }
+      else
+        {
+          const char *path = dbus_address_entry_get_value (entries[0],
+                                                           "path");
+
+          g_assert_nonnull (path);
+          g_assert_true (g_str_has_prefix (path, "/tmp/dbus-"));
+        }
+    }
+  else if (g_strcmp0 (listening_address,
+                      "unix:runtime=yes;unix:tmpdir=/tmp") == 0)
+    {
+      g_assert_cmpstr (dbus_address_entry_get_method (entries[0]), ==, "unix");
+      /* No particular statement about the path here: for that see
+       * setup_runtime() and setup_no_runtime() */
+    }
+#endif
+  else
+    {
+      g_assert_not_reached ();
+    }
+
+  dbus_address_entries_free (entries);
+
   f->client_conn = dbus_connection_open_private (address, &f->e);
   assert_no_error (&f->e);
   g_assert (f->client_conn != NULL);