int fd_before;
} Fixture;
-#ifdef HAVE_UNIX_FD_PASSING
-
static void oom (const gchar *doing) G_GNUC_NORETURN;
static void
static void
test_connect (Fixture *f,
- gconstpointer data G_GNUC_UNUSED)
+ gboolean should_support_fds)
{
char *address;
test_main_context_iterate (f->ctx, TRUE);
}
+ if (!should_support_fds)
+ return;
+
if (!dbus_connection_can_send_type (f->left_client_conn,
DBUS_TYPE_UNIX_FD))
g_error ("left client connection cannot send Unix fds");
DBUS_TYPE_UNIX_FD))
g_error ("right server connection cannot send Unix fds");
}
-#endif
static void
-setup (Fixture *f,
- gconstpointer data G_GNUC_UNUSED)
+setup_common (Fixture *f,
+ const char *address)
{
-#ifdef HAVE_UNIX_FD_PASSING
- /* We assume that anything with fd-passing supports the unix: transport */
-
f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->messages);
- f->server = dbus_server_listen ("unix:tmpdir=/tmp", &f->e);
+ f->server = dbus_server_listen (address, &f->e);
assert_no_error (&f->e);
g_assert (f->server != NULL);
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
test_server_setup (f->ctx, f->server);
+}
+
+static void
+setup_unsupported (Fixture *f,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ setup_common (f, "tcp:host=127.0.0.1");
+}
+
+static void
+setup (Fixture *f,
+ gconstpointer data G_GNUC_UNUSED)
+{
+#ifdef HAVE_UNIX_FD_PASSING
+ /* We assume that anything with fd-passing supports the unix: transport */
+ setup_common (f, "unix:tmpdir=/tmp");
f->fd_before = open ("/dev/null", O_RDONLY);
}
static void
+test_unsupported (Fixture *f,
+ gconstpointer data)
+{
+ test_connect (f, FALSE);
+
+ if (dbus_connection_can_send_type (f->left_client_conn,
+ DBUS_TYPE_UNIX_FD))
+ g_error ("left client connection claims it can send Unix fds");
+
+ if (dbus_connection_can_send_type (f->left_server_conn,
+ DBUS_TYPE_UNIX_FD))
+ g_error ("left server connection claims it can send Unix fds");
+
+ if (dbus_connection_can_send_type (f->right_client_conn,
+ DBUS_TYPE_UNIX_FD))
+ g_error ("right client connection claims it can send Unix fds");
+
+ if (dbus_connection_can_send_type (f->right_server_conn,
+ DBUS_TYPE_UNIX_FD))
+ g_error ("right server connection claims it can send Unix fds");
+}
+
+static void
test_relay (Fixture *f,
gconstpointer data)
{
struct stat stat_before;
struct stat stat_after;
- test_connect (f, data);
+ test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting");
DBusMessage *outgoing, *incoming;
int i;
- test_connect (f, data);
+ test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting");
DBusMessage *outgoing;
unsigned int i;
- test_connect (f, data);
+ test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting");
}
#endif
- test_connect (f, data);
+ test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting");
DBusMessage *outgoing[SOME_MESSAGES];
dbus_uint32_t serial;
- test_connect (f, data);
+ test_connect (f, TRUE);
for (j = 0; j < SOME_MESSAGES; j++)
{
DBusMessage *outgoing;
int i;
- test_connect (f, data);
+ test_connect (f, TRUE);
dbus_connection_set_max_message_unix_fds (f->left_server_conn, 7);
dbus_connection_set_max_message_unix_fds (f->right_server_conn, 7);
teardown (Fixture *f,
gconstpointer data G_GNUC_UNUSED)
{
-#ifdef HAVE_UNIX_FD_PASSING
if (f->left_client_conn != NULL)
{
dbus_connection_close (f->left_client_conn);
f->server = NULL;
}
- test_main_context_unref (f->ctx);
+ if (f->ctx != NULL)
+ test_main_context_unref (f->ctx);
+#ifdef HAVE_UNIX_FD_PASSING
if (f->fd_before >= 0 && close (f->fd_before) < 0)
g_error ("%s", g_strerror (errno));
#endif
}
#endif
+ g_test_add ("/unsupported", Fixture, NULL, setup_unsupported,
+ test_unsupported, teardown);
+
g_test_add ("/relay", Fixture, NULL, setup,
test_relay, teardown);
g_test_add ("/limit", Fixture, NULL, setup,