diff options
author | Simon McVittie <smcv@collabora.com> | 2017-06-28 18:52:12 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2017-06-29 14:03:36 +0100 |
commit | 063c505efb656be44d6fe02bf2c10492b57b0695 (patch) | |
tree | a9a61c20cef10b8c2f693ce7d4b2c682bb9ab52b | |
parent | fe19134bb6194ea2bc2d23da4d5f608cb7c8b702 (diff) | |
download | dbus-063c505efb656be44d6fe02bf2c10492b57b0695.tar.gz |
test/loopback: Assert that the connectable address makes sense
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
-rw-r--r-- | test/loopback.c | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/test/loopback.c b/test/loopback.c index 46e9758d..0d94e1b7 100644 --- a/test/loopback.c +++ b/test/loopback.c @@ -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); |