summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am98
-rw-r--r--test/break-loader.c2
-rw-r--r--test/data/valid-config-files/incoming-limit.conf18
-rw-r--r--test/dbus-daemon-eavesdrop.c558
-rw-r--r--test/dbus-daemon.c77
-rw-r--r--test/marshal.c1
-rw-r--r--test/name-test/Makefile.am69
-rw-r--r--test/name-test/test-privserver-client.c1
-rw-r--r--test/test-service.c9
-rw-r--r--test/test-shell-service.c7
-rw-r--r--test/test-utils.c64
11 files changed, 717 insertions, 187 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index e5fd756b..971299a9 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,9 +4,22 @@
SUBDIRS= . name-test
DIST_SUBDIRS=name-test
-INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS)
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ $(GLIB_CFLAGS) \
+ $(DBUS_GLIB_CFLAGS) \
+ $(NULL)
-libdbus_testutils_la_SOURCES = test-utils.h test-utils.c
+# improve backtraces from test stuff
+AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
+
+libdbus_testutils_la_SOURCES = \
+ test-utils.c \
+ test-utils.h \
+ $(NULL)
+libdbus_testutils_la_LIBADD = \
+ $(top_builddir)/dbus/libdbus-internal.la \
+ $(NULL)
noinst_LTLIBRARIES = libdbus-testutils.la
@@ -52,54 +65,27 @@ endif !DBUS_BUILD_TESTS
noinst_PROGRAMS= $(TEST_BINARIES)
-test_service_SOURCES= \
- test-service.c
-
-test_names_SOURCES= \
- test-names.c
-
-##break_loader_SOURCES= \
-## break-loader.c
-
-test_shell_service_SOURCES = \
- test-shell-service.c
-
-shell_test_SOURCES= \
- shell-test.c
-
-spawn_test_SOURCES= \
- spawn-test.c
-
-test_exit_SOURCES = \
- test-exit.c
-
-test_segfault_SOURCES = \
- test-segfault.c
-
-test_sleep_forever_SOURCES = \
- test-sleep-forever.c
-
-# This assumes that most tests will be linked to libdbus-internal;
-# tests linked to only the public libdbus have their own CPPFLAGS.
-AM_CPPFLAGS=-DDBUS_STATIC_BUILD
-TEST_LIBS=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
+static_cppflags = \
+ $(AM_CPPFLAGS) \
+ -DDBUS_STATIC_BUILD \
+ $(NULL)
-test_service_LDADD=libdbus-testutils.la $(TEST_LIBS)
-test_service_LDFLAGS=@R_DYNAMIC_LDFLAG@
-test_names_LDADD=libdbus-testutils.la $(TEST_LIBS)
-test_names_LDFLAGS=@R_DYNAMIC_LDFLAG@
-## break_loader_LDADD= $(TEST_LIBS)
-## break_loader_LDFLAGS=@R_DYNAMIC_LDFLAG@
-test_shell_service_LDADD=libdbus-testutils.la $(TEST_LIBS)
-test_shell_service_LDFLAGS=@R_DYNAMIC_LDFLAG@
-shell_test_LDADD=libdbus-testutils.la $(TEST_LIBS)
-shell_test_LDFLAGS=@R_DYNAMIC_LDFLAG@
-spawn_test_LDADD=$(TEST_LIBS)
-spawn_test_LDFLAGS=@R_DYNAMIC_LDFLAG@
+test_service_CPPFLAGS = $(static_cppflags)
+test_service_LDADD = libdbus-testutils.la
+test_names_CPPFLAGS = $(static_cppflags)
+test_names_LDADD = libdbus-testutils.la
+## break_loader_CPPFLAGS = $(static_cppflags)
+## break_loader_LDADD = $(top_builddir)/dbus/libdbus-internal.la
+test_shell_service_CPPFLAGS = $(static_cppflags)
+test_shell_service_LDADD = libdbus-testutils.la
+shell_test_CPPFLAGS = $(static_cppflags)
+shell_test_LDADD = libdbus-testutils.la
+spawn_test_CPPFLAGS = $(static_cppflags)
+spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la
test_refs_SOURCES = internals/refs.c
-test_refs_CPPFLAGS = -DDBUS_STATIC_BUILD $(GLIB_CFLAGS)
-test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS) $(TEST_LIBS)
+test_refs_CPPFLAGS = $(static_cppflags)
+test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS)
EXTRA_DIST = dbus-test-runner
@@ -110,6 +96,7 @@ testexec_PROGRAMS =
installable_tests = \
test-corrupt \
test-dbus-daemon \
+ test-dbus-daemon-eavesdrop \
test-loopback \
test-marshal \
test-refs \
@@ -130,36 +117,33 @@ TESTS_ENVIRONMENT = \
$(NULL)
test_corrupt_SOURCES = corrupt.c
-test_corrupt_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
-test_corrupt_LDFLAGS = @R_DYNAMIC_LDFLAG@
test_corrupt_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS)
test_loopback_SOURCES = loopback.c
-test_loopback_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
-test_loopback_LDFLAGS = @R_DYNAMIC_LDFLAG@
test_loopback_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS)
test_relay_SOURCES = relay.c
-test_relay_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
-test_relay_LDFLAGS = @R_DYNAMIC_LDFLAG@
test_relay_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS)
test_dbus_daemon_SOURCES = dbus-daemon.c
-test_dbus_daemon_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
-test_dbus_daemon_LDFLAGS = @R_DYNAMIC_LDFLAG@
test_dbus_daemon_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS)
+test_dbus_daemon_eavesdrop_SOURCES = dbus-daemon-eavesdrop.c
+test_dbus_daemon_eavesdrop_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
+test_dbus_daemon_eavesdrop_LDFLAGS = @R_DYNAMIC_LDFLAG@
+test_dbus_daemon_eavesdrop_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+ $(GLIB_LIBS) \
+ $(DBUS_GLIB_LIBS)
+
test_marshal_SOURCES = marshal.c
-test_marshal_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
-test_marshal_LDFLAGS = @R_DYNAMIC_LDFLAG@
test_marshal_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS)
diff --git a/test/break-loader.c b/test/break-loader.c
index 7bfa7227..542f36ff 100644
--- a/test/break-loader.c
+++ b/test/break-loader.c
@@ -446,7 +446,7 @@ randomly_change_one_type (const DBusString *orig_data,
{
int b;
b = _dbus_string_get_byte (mutated, i);
- if (_dbus_type_is_valid (b))
+ if (dbus_type_is_valid (b))
{
_dbus_string_set_byte (mutated, i, random_type ());
return;
diff --git a/test/data/valid-config-files/incoming-limit.conf b/test/data/valid-config-files/incoming-limit.conf
new file mode 100644
index 00000000..abfab3f7
--- /dev/null
+++ b/test/data/valid-config-files/incoming-limit.conf
@@ -0,0 +1,18 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+ <!-- Our well-known bus type, don't change this -->
+ <type>session</type>
+ <listen>unix:tmpdir=/tmp</listen>
+
+ <policy context="default">
+ <!-- Allow everything to be sent -->
+ <allow send_destination="*" eavesdrop="true"/>
+ <!-- Allow everything to be received -->
+ <allow eavesdrop="true"/>
+ <!-- Allow anyone to own anything -->
+ <allow own="*"/>
+ </policy>
+
+ <limit name="max_incoming_bytes">1</limit>
+</busconfig>
diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c
new file mode 100644
index 00000000..6819ec13
--- /dev/null
+++ b/test/dbus-daemon-eavesdrop.c
@@ -0,0 +1,558 @@
+/* Integration tests for the eavesdrop=true|false keyword in DBusMatchRule
+ *
+ * Author: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
+ * Based on: tests/dbus-daemon.c by Simon McVittie
+ * Copyright © 2010-2011 Nokia Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <glib.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include <string.h>
+
+#ifdef DBUS_WIN
+# include <windows.h>
+#else
+# include <signal.h>
+# include <unistd.h>
+#endif
+
+#define SENDER_NAME "test.eavesdrop.sender"
+#define SENDER_PATH "/test/eavesdrop/sender"
+#define SENDER_IFACE SENDER_NAME
+#define SENDER_SIGNAL_NAME "Signal"
+#define SENDER_STOPPER_NAME "Stopper"
+
+/* This rule is equivalent to the one added to a proxy connecting to
+ * SENDER_NAME+SENDER_IFACE, plus restricting on signal name.
+ * Being more restrictive, if the connection receives what we need, for sure
+ * the original proxy rule will match it */
+#define RECEIVER_RULE "sender='" SENDER_NAME "'," \
+ "interface='" SENDER_IFACE "'," \
+ "type='signal'," \
+ "member='" SENDER_SIGNAL_NAME "'"
+#define POLITELISTENER_RULE RECEIVER_RULE
+#define EAVESDROPPER_RULE RECEIVER_RULE ",eavesdrop=true"
+
+#define STOPPER_RULE "sender='" SENDER_NAME \
+ "',interface='" SENDER_IFACE "',type='signal',member='" SENDER_STOPPER_NAME "'"
+
+/* a connection received a signal to whom? */
+typedef enum {
+ NONE_YET = 0,
+ TO_ME,
+ TO_OTHER,
+ BROADCAST,
+} SignalDst;
+
+typedef struct {
+ DBusError e;
+ GError *ge;
+
+ gint daemon_pid;
+
+ /* eavedrop keyword tests */
+ DBusConnection *sender;
+ DBusConnection *receiver;
+ SignalDst receiver_dst;
+ dbus_bool_t receiver_got_stopper;
+ DBusConnection *eavesdropper;
+ SignalDst eavesdropper_dst;
+ dbus_bool_t eavesdropper_got_stopper;
+ DBusConnection *politelistener;
+ SignalDst politelistener_dst;
+ dbus_bool_t politelistener_got_stopper;
+} Fixture;
+
+#define assert_no_error(e) _assert_no_error (e, __FILE__, __LINE__)
+static void
+_assert_no_error (const DBusError *e,
+ const char *file,
+ int line)
+{
+ if (G_UNLIKELY (dbus_error_is_set (e)))
+ g_error ("%s:%d: expected success but got error: %s: %s",
+ file, line, e->name, e->message);
+}
+
+static gchar *
+spawn_dbus_daemon (gchar *binary,
+ gchar *configuration,
+ gint *daemon_pid)
+{
+ GError *error = NULL;
+ GString *address;
+ gint address_fd;
+ gchar *argv[] = {
+ binary,
+ configuration,
+ "--nofork",
+ "--print-address=1", /* stdout */
+ NULL
+ };
+
+ g_spawn_async_with_pipes (NULL, /* working directory */
+ argv,
+ NULL, /* envp */
+ G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
+ NULL, /* child_setup */
+ NULL, /* user data */
+ daemon_pid,
+ NULL, /* child's stdin = /dev/null */
+ &address_fd,
+ NULL, /* child's stderr = our stderr */
+ &error);
+ g_assert_no_error (error);
+
+ address = g_string_new (NULL);
+
+ /* polling until the dbus-daemon writes out its address is a bit stupid,
+ * but at least it's simple, unlike dbus-launch... in principle we could
+ * use select() here, but life's too short */
+ while (1)
+ {
+ gssize bytes;
+ gchar buf[4096];
+ gchar *newline;
+
+ bytes = read (address_fd, buf, sizeof (buf));
+
+ if (bytes > 0)
+ g_string_append_len (address, buf, bytes);
+
+ newline = strchr (address->str, '\n');
+
+ if (newline != NULL)
+ {
+ g_string_truncate (address, newline - address->str);
+ break;
+ }
+
+ g_usleep (G_USEC_PER_SEC / 10);
+ }
+
+ return g_string_free (address, FALSE);
+}
+
+static DBusConnection *
+connect_to_bus (const gchar *address)
+{
+ DBusConnection *conn;
+ DBusError error = DBUS_ERROR_INIT;
+ dbus_bool_t ok;
+
+ conn = dbus_connection_open_private (address, &error);
+ assert_no_error (&error);
+ g_assert (conn != NULL);
+
+ ok = dbus_bus_register (conn, &error);
+ assert_no_error (&error);
+ g_assert (ok);
+ g_assert (dbus_bus_get_unique_name (conn) != NULL);
+
+ dbus_connection_setup_with_g_main (conn, NULL);
+ return conn;
+}
+
+/* send a unicast signal to <self> to ensure that no other connection
+ * listening is the actual recipient for the signal */
+static DBusHandlerResult
+sender_send_unicast_to_sender (Fixture *f)
+{
+ DBusError error = DBUS_ERROR_INIT;
+ DBusMessage *signal;
+
+ signal = dbus_message_new_signal (SENDER_PATH, SENDER_IFACE,
+ SENDER_SIGNAL_NAME);
+ dbus_message_set_destination (signal, dbus_bus_get_unique_name (f->sender));
+
+ if (signal == NULL)
+ g_error ("OOM");
+
+ if (!dbus_connection_send (f->sender, signal, NULL))
+ g_error ("OOM");
+
+ dbus_message_unref (signal);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+/* send a unicast signal to <receiver>, making <politelistener> and
+ * <eavesdropper> not a actual recipient for it */
+static DBusHandlerResult
+sender_send_unicast_to_receiver (Fixture *f)
+{
+ DBusError error = DBUS_ERROR_INIT;
+ DBusMessage *signal;
+
+ signal = dbus_message_new_signal (SENDER_PATH, SENDER_IFACE, SENDER_SIGNAL_NAME);
+ dbus_message_set_destination (signal, dbus_bus_get_unique_name (f->receiver));
+
+ if (signal == NULL)
+ g_error ("OOM");
+
+ if (!dbus_connection_send (f->sender, signal, NULL))
+ g_error ("OOM");
+
+ dbus_message_unref (signal);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult
+sender_send_broadcast (Fixture *f)
+{
+ DBusError error = DBUS_ERROR_INIT;
+ DBusMessage *signal;
+
+ signal = dbus_message_new_signal (SENDER_PATH, SENDER_IFACE, SENDER_SIGNAL_NAME);
+ dbus_message_set_destination (signal, NULL);
+
+ if (signal == NULL)
+ g_error ("OOM");
+
+ if (!dbus_connection_send (f->sender, signal, NULL))
+ g_error ("OOM");
+
+ dbus_message_unref (signal);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+/* Send special broadcast signal to indicate that the connections can "stop"
+ * listening and check their results.
+ * DBus does not re-order messages, so when the three connections have received
+ * this signal, we are sure that any message sent before it has also been
+ * dispatched. */
+static DBusHandlerResult
+sender_send_stopper (Fixture *f)
+{
+ DBusError error = DBUS_ERROR_INIT;
+ DBusMessage *signal;
+
+ signal = dbus_message_new_signal (SENDER_PATH, SENDER_IFACE, SENDER_STOPPER_NAME);
+ dbus_message_set_destination (signal, NULL);
+
+ if (signal == NULL)
+ g_error ("OOM");
+
+ if (!dbus_connection_send (f->sender, signal, NULL))
+ g_error ("OOM");
+
+ dbus_message_unref (signal);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+/* Ignore NameAcquired, then depending on the signal received:
+ * - updates f-><conn>_dst based on the destination of the message
+ * - asserts that <conn> received the stop signal
+ */
+static DBusHandlerResult
+signal_filter (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ Fixture *f = user_data;
+ SignalDst *dst = NULL;
+ DBusConnection **conn;
+ dbus_bool_t *got_stopper;
+
+ if (0 == strcmp (dbus_message_get_member (message), "NameAcquired"))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (connection == f->receiver)
+ {
+ dst = &(f->receiver_dst);
+ conn = &(f->receiver);
+ got_stopper = &(f->receiver_got_stopper);
+ }
+ else if (connection == f->eavesdropper)
+ {
+ dst = &(f->eavesdropper_dst);
+ conn = &(f->eavesdropper);
+ got_stopper = &(f->eavesdropper_got_stopper);
+ }
+ else if (connection == f->politelistener)
+ {
+ dst = &(f->politelistener_dst);
+ conn = &(f->politelistener);
+ got_stopper = &(f->politelistener_got_stopper);
+ }
+ else
+ {
+ g_error ("connection not matching");
+ }
+
+ if (0 == strcmp (dbus_message_get_member (message), SENDER_SIGNAL_NAME))
+ {
+ if (dbus_message_get_destination (message) == NULL)
+ *dst = BROADCAST;
+ else if (0 == strcmp (dbus_message_get_destination (message), dbus_bus_get_unique_name (*conn)))
+ *dst = TO_ME;
+ else /* if (dbus_message_get_destination (message) != NULL) */
+ *dst = TO_OTHER;
+ }
+ else if (0 == strcmp (dbus_message_get_member (message), SENDER_STOPPER_NAME))
+ {
+ *got_stopper = TRUE;
+ }
+ else
+ {
+ g_error ("got unknown member from message: %s",
+ dbus_message_get_member (message));
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void
+add_receiver_filter (Fixture *f)
+{
+ DBusError e = DBUS_ERROR_INIT;
+
+ dbus_bus_add_match (f->receiver, RECEIVER_RULE, &e);
+ assert_no_error (&e);
+ dbus_bus_add_match (f->receiver, STOPPER_RULE, &e);
+ assert_no_error (&e);
+
+ if (!dbus_connection_add_filter (f->receiver,
+ signal_filter, f, NULL))
+ g_error ("OOM");
+}
+
+static void
+add_eavesdropper_filter (Fixture *f)
+{
+ DBusError e = DBUS_ERROR_INIT;
+
+ dbus_bus_add_match (f->eavesdropper, EAVESDROPPER_RULE, &e);
+ assert_no_error (&e);
+ dbus_bus_add_match (f->eavesdropper, STOPPER_RULE, &e);
+ assert_no_error (&e);
+
+ if (!dbus_connection_add_filter (f->eavesdropper,
+ signal_filter, f, NULL))
+ g_error ("OOM");
+}
+
+static void
+add_politelistener_filter (Fixture *f)
+{
+ DBusError e = DBUS_ERROR_INIT;
+
+ dbus_bus_add_match (f->politelistener, POLITELISTENER_RULE, &e);
+ assert_no_error (&e);
+ dbus_bus_add_match (f->politelistener, STOPPER_RULE, &e);
+ assert_no_error (&e);
+
+ if (!dbus_connection_add_filter (f->politelistener,
+ signal_filter, f, NULL))
+ g_error ("OOM");
+}
+
+static void
+setup (Fixture *f,
+ gconstpointer context G_GNUC_UNUSED)
+{
+ gchar *dbus_daemon;
+ gchar *config;
+ gchar *address;
+
+ f->ge = NULL;
+ dbus_error_init (&f->e);
+
+ dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
+
+ if (dbus_daemon == NULL)
+ dbus_daemon = g_strdup ("dbus-daemon");
+
+ if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL)
+ {
+ config = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
+ g_getenv ("DBUS_TEST_SYSCONFDIR"));
+ }
+ else if (g_getenv ("DBUS_TEST_DATA") != NULL)
+ {
+ config = g_strdup_printf (
+ "--config-file=%s/valid-config-files/session.conf",
+ g_getenv ("DBUS_TEST_DATA"));
+ }
+ else
+ {
+ config = g_strdup ("--session");
+ }
+
+ address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid);
+
+ g_free (dbus_daemon);
+ g_free (config);
+
+ f->sender = connect_to_bus (address);
+ dbus_bus_request_name (f->sender, SENDER_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE,
+ &(f->e));
+ f->receiver = connect_to_bus (address);
+ f->eavesdropper = connect_to_bus (address);
+ f->politelistener = connect_to_bus (address);
+ add_receiver_filter (f);
+ add_politelistener_filter (f);
+ add_eavesdropper_filter (f);
+
+ g_free (address);
+}
+
+static void
+test_eavesdrop_broadcast (Fixture *f,
+ gconstpointer context G_GNUC_UNUSED)
+{
+ sender_send_broadcast (f);
+ sender_send_stopper (f);
+
+ while (!f->receiver_got_stopper ||
+ !f->politelistener_got_stopper ||
+ !f->eavesdropper_got_stopper)
+ g_main_context_iteration (NULL, TRUE);
+
+ /* all the three connection can receive a broadcast */
+ g_assert_cmpint (f->receiver_dst, ==, BROADCAST);
+ g_assert_cmpint (f->politelistener_dst, ==, BROADCAST);
+ g_assert_cmpint (f->eavesdropper_dst, ==, BROADCAST);
+}
+
+/* a way to say that none of the listening connection are destination of the
+ * signal */
+static void
+test_eavesdrop_unicast_to_sender (Fixture *f,
+ gconstpointer context G_GNUC_UNUSED)
+{
+ sender_send_unicast_to_sender (f);
+ sender_send_stopper (f);
+
+ while (!f->receiver_got_stopper ||
+ !f->politelistener_got_stopper ||
+ !f->eavesdropper_got_stopper)
+ g_main_context_iteration (NULL, TRUE);
+
+ /* not directed to it and not broadcasted, they cannot receive it */
+ g_assert_cmpint (f->receiver_dst, ==, NONE_YET);
+ g_assert_cmpint (f->politelistener_dst, ==, NONE_YET);
+ /* eavesdrop=true, it will receive the signal even though it's not directed
+ * to it */
+ g_assert_cmpint (f->eavesdropper_dst, ==, TO_OTHER);
+}
+
+static void
+test_eavesdrop_unicast_to_receiver (Fixture *f,
+ gconstpointer context G_GNUC_UNUSED)
+{
+ sender_send_unicast_to_receiver (f);
+ sender_send_stopper (f);
+
+ while (!f->receiver_got_stopper ||
+ !f->politelistener_got_stopper ||
+ !f->eavesdropper_got_stopper)
+ g_main_context_iteration (NULL, TRUE);
+
+ /* direct to him */
+ g_assert_cmpint (f->receiver_dst, ==, TO_ME);
+ /* not directed to it and not broadcasted, it cannot receive it */
+ g_assert_cmpint (f->politelistener_dst, ==, NONE_YET);
+ /* eavesdrop=true, it will receive the signal even though it's not directed
+ * to it */
+ g_assert_cmpint (f->eavesdropper_dst, ==, TO_OTHER);
+}
+
+static void
+teardown (Fixture *f,
+ gconstpointer context G_GNUC_UNUSED)
+{
+ dbus_error_free (&f->e);
+ g_clear_error (&f->ge);
+
+ if (f->sender != NULL)
+ {
+ dbus_connection_close (f->sender);
+ dbus_connection_unref (f->sender);
+ f->sender = NULL;
+ }
+
+ if (f->receiver != NULL)
+ {
+ dbus_connection_remove_filter (f->receiver,
+ signal_filter, f);
+
+ dbus_connection_close (f->receiver);
+ dbus_connection_unref (f->receiver);
+ f->receiver = NULL;
+ }
+
+ if (f->politelistener != NULL)
+ {
+ dbus_connection_remove_filter (f->politelistener,
+ signal_filter, f);
+
+ dbus_connection_close (f->politelistener);
+ dbus_connection_unref (f->politelistener);
+ f->politelistener = NULL;
+ }
+
+ if (f->eavesdropper != NULL)
+ {
+ dbus_connection_remove_filter (f->eavesdropper,
+ signal_filter, f);
+
+ dbus_connection_close (f->eavesdropper);
+ dbus_connection_unref (f->eavesdropper);
+ f->eavesdropper = NULL;
+ }
+
+#ifdef DBUS_WIN
+ TerminateProcess (f->daemon_pid, 1);
+#else
+ kill (f->daemon_pid, SIGTERM);
+#endif
+
+ g_spawn_close_pid (f->daemon_pid);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
+
+ g_test_add ("/eavedrop/match_keyword/broadcast", Fixture, NULL,
+ setup, test_eavesdrop_broadcast, teardown);
+ g_test_add ("/eavedrop/match_keyword/unicast_to_receiver", Fixture, NULL,
+ setup, test_eavesdrop_unicast_to_receiver,
+ teardown);
+ g_test_add ("/eavedrop/match_keyword/unicast_to_sender", Fixture, NULL,
+ setup, test_eavesdrop_unicast_to_sender, teardown);
+
+ return g_test_run ();
+}
diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c
index e192c68f..cc871530 100644
--- a/test/dbus-daemon.c
+++ b/test/dbus-daemon.c
@@ -42,6 +42,8 @@
#endif
typedef struct {
+ gboolean skip;
+
DBusError e;
GError *ge;
@@ -149,8 +151,6 @@ echo_filter (DBusConnection *connection,
void *user_data)
{
DBusMessage *reply;
- DBusError error = DBUS_ERROR_INIT;
- int *sleep_ms = user_data;
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -168,42 +168,63 @@ echo_filter (DBusConnection *connection,
return DBUS_HANDLER_RESULT_HANDLED;
}
+typedef struct {
+ const char *bug_ref;
+ guint min_messages;
+ const char *config_file;
+} Config;
+
static void
setup (Fixture *f,
- gconstpointer context G_GNUC_UNUSED)
+ gconstpointer context)
{
+ const Config *config = context;
gchar *dbus_daemon;
- gchar *config;
+ gchar *arg;
gchar *address;
f->ge = NULL;
dbus_error_init (&f->e);
- dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
-
- if (dbus_daemon == NULL)
- dbus_daemon = g_strdup ("dbus-daemon");
+ if (config != NULL && config->config_file != NULL)
+ {
+ if (g_getenv ("DBUS_TEST_DATA") == NULL)
+ {
+ g_message ("SKIP: set DBUS_TEST_DATA to a directory containing %s",
+ config->config_file);
+ f->skip = TRUE;
+ return;
+ }
- if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL)
+ arg = g_strdup_printf (
+ "--config-file=%s/%s",
+ g_getenv ("DBUS_TEST_DATA"), config->config_file);
+ }
+ else if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL)
{
- config = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
+ arg = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
g_getenv ("DBUS_TEST_SYSCONFDIR"));
}
else if (g_getenv ("DBUS_TEST_DATA") != NULL)
{
- config = g_strdup_printf (
+ arg = g_strdup_printf (
"--config-file=%s/valid-config-files/session.conf",
g_getenv ("DBUS_TEST_DATA"));
}
else
{
- config = g_strdup ("--session");
+ arg = g_strdup ("--session");
}
- address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid);
+ dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
+
+ if (dbus_daemon == NULL)
+ dbus_daemon = g_strdup ("dbus-daemon");
+
+ address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid);
g_free (dbus_daemon);
- g_free (config);
+ g_free (arg);
f->left_conn = connect_to_bus (address);
f->right_conn = connect_to_bus (address);
@@ -230,16 +251,26 @@ pc_count (DBusPendingCall *pc,
static void
test_echo (Fixture *f,
- gconstpointer context G_GNUC_UNUSED)
+ gconstpointer context)
{
+ const Config *config = context;
guint count = 2000;
guint sent;
guint received = 0;
double elapsed;
+ if (f->skip)
+ return;
+
+ if (config != NULL && config->bug_ref != NULL)
+ g_test_bug (config->bug_ref);
+
if (g_test_perf ())
count = 100000;
+ if (config != NULL)
+ count = MAX (config->min_messages, count);
+
add_echo_filter (f);
g_test_timer_start ();
@@ -305,15 +336,23 @@ teardown (Fixture *f,
f->right_conn = NULL;
}
+ if (f->daemon_pid != 0)
+ {
#ifdef DBUS_WIN
- TerminateProcess (f->daemon_pid, 1);
+ TerminateProcess (f->daemon_pid, 1);
#else
- kill (f->daemon_pid, SIGTERM);
+ kill (f->daemon_pid, SIGTERM);
#endif
- g_spawn_close_pid (f->daemon_pid);
+ g_spawn_close_pid (f->daemon_pid);
+ f->daemon_pid = 0;
+ }
}
+static Config limited_config = {
+ "34393", 10000, "valid-config-files/incoming-limit.conf"
+};
+
int
main (int argc,
char **argv)
@@ -322,6 +361,8 @@ main (int argc,
g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add ("/echo/session", Fixture, NULL, setup, test_echo, teardown);
+ g_test_add ("/echo/limited", Fixture, &limited_config,
+ setup, test_echo, teardown);
return g_test_run ();
}
diff --git a/test/marshal.c b/test/marshal.c
index 4cee9412..e9ac7e30 100644
--- a/test/marshal.c
+++ b/test/marshal.c
@@ -146,7 +146,6 @@ test_endian (Fixture *f,
gconstpointer arg)
{
const gchar *blob = arg;
- const gchar *native_blob;
char *output;
DBusMessage *m;
int len;
diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am
index 5f11f0be..68fc33ec 100644
--- a/test/name-test/Makefile.am
+++ b/test/name-test/Makefile.am
@@ -1,4 +1,12 @@
-INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) $(DBUS_TEST_CFLAGS) -DDBUS_COMPILATION
+# Everything in this directory is statically-linked to libdbus-internal
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -DDBUS_COMPILATION \
+ -DDBUS_STATIC_BUILD \
+ $(NULL)
+
+# if assertions are enabled, improve backtraces
+AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
## note that TESTS has special meaning (stuff to use in make check)
## so if adding tests not to be run in make check, don't add them to
@@ -18,57 +26,14 @@ if DBUS_BUILD_TESTS
## build even when not doing "make check"
noinst_PROGRAMS=test-pending-call-dispatch test-pending-call-timeout test-threads-init test-ids test-shutdown test-privserver test-privserver-client test-autolaunch
-AM_CPPFLAGS = -DDBUS_STATIC_BUILD
-test_pending_call_dispatch_SOURCES = \
- test-pending-call-dispatch.c
-
-test_pending_call_dispatch_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
-test_pending_call_dispatch_LDFLAGS=@R_DYNAMIC_LDFLAG@
-
-test_pending_call_timeout_SOURCES = \
- test-pending-call-timeout.c
-
-test_pending_call_timeout_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
-test_pending_call_timeout_LDFLAGS=@R_DYNAMIC_LDFLAG@
-
-test_threads_init_SOURCES = \
- test-threads-init.c
-
-test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
-test_threads_init_LDFLAGS=@R_DYNAMIC_LDFLAG@
-
-test_ids_SOURCES = \
- test-ids.c
-
-test_ids_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_TEST_LIBS)
-test_ids_LDFLAGS=@R_DYNAMIC_LDFLAG@
-
-test_shutdown_SOURCES = \
- test-shutdown.c
-
-test_shutdown_CFLAGS=
-test_shutdown_LDADD=$(top_builddir)/dbus/libdbus-internal.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
-test_shutdown_LDFLAGS=@R_DYNAMIC_LDFLAG@
-
-test_privserver_SOURCES = \
- test-privserver.c
-
-test_privserver_CFLAGS=
-test_privserver_LDADD=$(top_builddir)/dbus/libdbus-internal.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
-test_privserver_LDFLAGS=@R_DYNAMIC_LDFLAG@
-
-test_privserver_client_SOURCES = \
- test-privserver-client.c
-
-test_privserver_client_CFLAGS=
-test_privserver_client_LDADD=$(top_builddir)/dbus/libdbus-internal.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
-test_privserver_client_LDFLAGS=@R_DYNAMIC_LDFLAG@
-
-test_autolaunch_SOURCES = \
- test-autolaunch.c
+test_pending_call_dispatch_LDADD=$(top_builddir)/dbus/libdbus-internal.la
+test_pending_call_timeout_LDADD=$(top_builddir)/dbus/libdbus-internal.la
+test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-internal.la
+test_ids_LDADD=$(top_builddir)/dbus/libdbus-internal.la
-test_autolaunch_CFLAGS=
-test_autolaunch_LDADD=$(top_builddir)/dbus/libdbus-internal.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
-test_autolaunch_LDFLAGS=@R_DYNAMIC_LDFLAG@
+test_shutdown_LDADD=../libdbus-testutils.la
+test_privserver_LDADD=../libdbus-testutils.la
+test_privserver_client_LDADD=../libdbus-testutils.la
+test_autolaunch_LDADD=../libdbus-testutils.la
endif
diff --git a/test/name-test/test-privserver-client.c b/test/name-test/test-privserver-client.c
index 1c43faee..e7f48960 100644
--- a/test/name-test/test-privserver-client.c
+++ b/test/name-test/test-privserver-client.c
@@ -71,7 +71,6 @@ open_shutdown_private_connection (dbus_bool_t use_guid)
DBusMessage *reply;
DBusConnection *privconn;
char *addr;
- char *comma;
dbus_bool_t service_died;
dbus_bool_t private_conn_lost;
diff --git a/test/test-service.c b/test/test-service.c
index 6627ea75..7181fa38 100644
--- a/test/test-service.c
+++ b/test/test-service.c
@@ -477,7 +477,14 @@ main (int argc,
dbus_error_free (&error);
exit (1);
}
-
+
+ if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+ {
+ fprintf (stderr, "Unable to acquire service: code %d\n", result);
+ _dbus_verbose ("*** Failed to acquire service: %d\n", result);
+ exit (1);
+ }
+
_dbus_verbose ("*** Test service entering main loop\n");
_dbus_loop_run (loop);
diff --git a/test/test-shell-service.c b/test/test-shell-service.c
index 57c16123..32a88329 100644
--- a/test/test-shell-service.c
+++ b/test/test-shell-service.c
@@ -176,6 +176,13 @@ main (int argc,
exit (1);
}
+ if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+ {
+ fprintf (stderr, "Unable to acquire service: code %d\n", result);
+ _dbus_verbose ("*** Failed to acquire service: %d\n", result);
+ exit (1);
+ }
+
_dbus_verbose ("*** Test service entering main loop\n");
_dbus_loop_run (loop);
diff --git a/test/test-utils.c b/test/test-utils.c
index 05cd7535..4fd84fe8 100644
--- a/test/test-utils.c
+++ b/test/test-utils.c
@@ -9,23 +9,12 @@ typedef struct
} CData;
static dbus_bool_t
-connection_watch_callback (DBusWatch *watch,
- unsigned int condition,
- void *data)
-{
- return dbus_watch_handle (watch, condition);
-}
-
-static dbus_bool_t
add_watch (DBusWatch *watch,
void *data)
{
CData *cd = data;
- return _dbus_loop_add_watch (cd->loop,
- watch,
- connection_watch_callback,
- cd, NULL);
+ return _dbus_loop_add_watch (cd->loop, watch);
}
static void
@@ -34,16 +23,7 @@ remove_watch (DBusWatch *watch,
{
CData *cd = data;
- _dbus_loop_remove_watch (cd->loop,
- watch, connection_watch_callback, cd);
-}
-
-static void
-connection_timeout_callback (DBusTimeout *timeout,
- void *data)
-{
- /* Can return FALSE on OOM but we just let it fire again later */
- dbus_timeout_handle (timeout);
+ _dbus_loop_remove_watch (cd->loop, watch);
}
static dbus_bool_t
@@ -52,8 +32,7 @@ add_timeout (DBusTimeout *timeout,
{
CData *cd = data;
- return _dbus_loop_add_timeout (cd->loop,
- timeout, connection_timeout_callback, cd, NULL);
+ return _dbus_loop_add_timeout (cd->loop, timeout);
}
static void
@@ -62,8 +41,7 @@ remove_timeout (DBusTimeout *timeout,
{
CData *cd = data;
- _dbus_loop_remove_timeout (cd->loop,
- timeout, connection_timeout_callback, cd);
+ _dbus_loop_remove_timeout (cd->loop, timeout);
}
static void
@@ -226,27 +204,12 @@ serverdata_new (DBusLoop *loop,
}
static dbus_bool_t
-server_watch_callback (DBusWatch *watch,
- unsigned int condition,
- void *data)
-{
- /* FIXME this can be done in dbus-mainloop.c
- * if the code in activation.c for the babysitter
- * watch handler is fixed.
- */
-
- return dbus_watch_handle (watch, condition);
-}
-
-static dbus_bool_t
add_server_watch (DBusWatch *watch,
void *data)
{
ServerData *context = data;
- return _dbus_loop_add_watch (context->loop,
- watch, server_watch_callback, context,
- NULL);
+ return _dbus_loop_add_watch (context->loop, watch);
}
static void
@@ -255,16 +218,7 @@ remove_server_watch (DBusWatch *watch,
{
ServerData *context = data;
- _dbus_loop_remove_watch (context->loop,
- watch, server_watch_callback, context);
-}
-
-static void
-server_timeout_callback (DBusTimeout *timeout,
- void *data)
-{
- /* can return FALSE on OOM but we just let it fire again later */
- dbus_timeout_handle (timeout);
+ _dbus_loop_remove_watch (context->loop, watch);
}
static dbus_bool_t
@@ -273,8 +227,7 @@ add_server_timeout (DBusTimeout *timeout,
{
ServerData *context = data;
- return _dbus_loop_add_timeout (context->loop,
- timeout, server_timeout_callback, context, NULL);
+ return _dbus_loop_add_timeout (context->loop, timeout);
}
static void
@@ -283,8 +236,7 @@ remove_server_timeout (DBusTimeout *timeout,
{
ServerData *context = data;
- _dbus_loop_remove_timeout (context->loop,
- timeout, server_timeout_callback, context);
+ _dbus_loop_remove_timeout (context->loop, timeout);
}
dbus_bool_t