Commit 30e7a813 authored by Simon McVittie's avatar Simon McVittie

Tests: allow dbus-glib to be replaced with use of libdbus-internal

We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.

For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.

The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852Reviewed-by: Ralf Habacker's avatarRalf Habacker <ralf.habacker@freenet.de>
parent f17fd1cc
...@@ -478,7 +478,9 @@ set(DBUS_INTERNAL_LIBRARIES dbus-internal) ...@@ -478,7 +478,9 @@ set(DBUS_INTERNAL_LIBRARIES dbus-internal)
# important note: DBUS_INTERNAL_xxxxx_DEFINITIONS must *not* be set when building dbus-1 library # important note: DBUS_INTERNAL_xxxxx_DEFINITIONS must *not* be set when building dbus-1 library
set (DBUS_INTERNAL_ADD_LIBRARY_OPTIONS STATIC) set (DBUS_INTERNAL_ADD_LIBRARY_OPTIONS STATIC)
set (DBUS_INTERNAL_LIBRARY_DEFINITIONS "-DDBUS_STATIC_BUILD") set (DBUS_INTERNAL_LIBRARY_DEFINITIONS "-DDBUS_STATIC_BUILD")
set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_STATIC_BUILD -DDBUS_COMPILATION") # For now, the CMake build system doesn't support replacing the internal
# main loop with dbus-glib
set (DBUS_INTERNAL_CLIENT_DEFINITIONS "-DDBUS_STATIC_BUILD -DDBUS_COMPILATION -DDBUS_TEST_USE_INTERNAL")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h )
......
...@@ -2,7 +2,7 @@ if (DBUS_ENABLE_EMBEDDED_TESTS) ...@@ -2,7 +2,7 @@ if (DBUS_ENABLE_EMBEDDED_TESTS)
set (NAMEtest-DIR ../../../test/name-test) set (NAMEtest-DIR ../../../test/name-test)
add_definitions(-DDBUS_COMPILATION) add_definitions(${DBUS_INTERNAL_CLIENT_DEFINITIONS})
add_executable(test-pending-call-dispatch ${NAMEtest-DIR}/test-pending-call-dispatch.c) add_executable(test-pending-call-dispatch ${NAMEtest-DIR}/test-pending-call-dispatch.c)
target_link_libraries(test-pending-call-dispatch ${DBUS_INTERNAL_LIBRARIES}) target_link_libraries(test-pending-call-dispatch ${DBUS_INTERNAL_LIBRARIES})
......
...@@ -210,7 +210,8 @@ AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [GLIB_VERSION_2_32], [Prevent post-2.32 AP ...@@ -210,7 +210,8 @@ AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [GLIB_VERSION_2_32], [Prevent post-2.32 AP
with_glib=yes with_glib=yes
if test "x$enable_modular_tests" != xno; then AS_IF([test "x$enable_modular_tests" != xno],
[
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24, gio-2.0 >= 2.24], PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24, gio-2.0 >= 2.24],
[], [],
[if test "x$enable_modular_tests" = xyes; then [if test "x$enable_modular_tests" = xyes; then
...@@ -219,16 +220,25 @@ if test "x$enable_modular_tests" != xno; then ...@@ -219,16 +220,25 @@ if test "x$enable_modular_tests" != xno; then
else # assumed to be "auto" else # assumed to be "auto"
with_glib=no with_glib=no
fi]) fi])
# If dbus-gmain.[ch] returned to libdbus then we wouldn't need this ],
PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1], [with_glib=no])
# Not required, because we can use internal APIs (but that makes the
# "installable tests" less useful as integration tests)
AC_ARG_WITH([dbus_glib],
[AS_HELP_STRING([--with-dbus-glib], [Use dbus-glib for regression tests])],
[],
[with_dbus_glib=auto])
AS_IF([test "x$with_dbus_glib" != xno],
[PKG_CHECK_MODULES([DBUS_GLIB], [dbus-glib-1],
[], [],
[if test "x$enable_modular_tests" = xyes; then [AS_IF([test "x$with_dbus_glib" = xyes],
AC_MSG_NOTICE([Full test coverage (--enable-modular-tests=yes or --enable-tests=yes) requires dbus-glib]) dnl specifically requested, but not found
AC_MSG_ERROR([$DBUS_GLIB_ERRORS]) [AC_MSG_ERROR([$DBUS_GLIB_ERRORS])],
else # assumed to be "auto" dnl else: assumed to be "auto"
with_glib=no [with_dbus_glib=no])])])
fi]) AM_CONDITIONAL([DBUS_WITH_DBUS_GLIB], [test "x$with_dbus_glib" != xno])
fi
if test "x$enable_modular_tests" != xno; then if test "x$enable_modular_tests" != xno; then
AC_DEFINE([DBUS_ENABLE_MODULAR_TESTS], [1], AC_DEFINE([DBUS_ENABLE_MODULAR_TESTS], [1],
[Define to build independent test binaries]) [Define to build independent test binaries])
...@@ -1839,6 +1849,7 @@ echo " ...@@ -1839,6 +1849,7 @@ echo "
Building embedded tests: ${enable_embedded_tests} Building embedded tests: ${enable_embedded_tests}
Building modular tests: ${enable_modular_tests} Building modular tests: ${enable_modular_tests}
- with GLib: ${with_glib} - with GLib: ${with_glib}
- with dbus-glib: ${with_dbus_glib}
Building verbose mode: ${enable_verbose_mode} Building verbose mode: ${enable_verbose_mode}
Building assertions: ${enable_asserts} Building assertions: ${enable_asserts}
Building checks: ${enable_checks} Building checks: ${enable_checks}
......
...@@ -20,19 +20,40 @@ static_cppflags = \ ...@@ -20,19 +20,40 @@ static_cppflags = \
$(AM_CPPFLAGS) \ $(AM_CPPFLAGS) \
-DDBUS_STATIC_BUILD \ -DDBUS_STATIC_BUILD \
-DDBUS_COMPILATION \ -DDBUS_COMPILATION \
-DDBUS_TEST_USE_INTERNAL \
$(NULL) $(NULL)
libdbus_testutils_la_CPPFLAGS = \ noinst_LTLIBRARIES = libdbus-testutils-internal.la
$(static_cppflags)
# You can link either libdbus-testutils, dbus-glib and libdbus-1,
# or libdbus-testutils-internal and libdbus-internal - never both in the
# same binary.
if DBUS_WITH_DBUS_GLIB
noinst_LTLIBRARIES += libdbus-testutils.la
libdbus_testutils_la_SOURCES = \ libdbus_testutils_la_SOURCES = \
test-utils.c \ test-utils.c \
test-utils.h \ test-utils.h \
$(NULL) $(NULL)
libdbus_testutils_la_LIBADD = \ libdbus_testutils_la_LIBADD = \
$(top_builddir)/dbus/libdbus-internal.la \ $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) \
$(NULL) $(NULL)
testutils_shared_if_possible = libdbus-testutils.la
else
testutils_shared_if_possible = libdbus-testutils-internal.la
endif
noinst_LTLIBRARIES = libdbus-testutils.la libdbus_testutils_internal_la_CPPFLAGS = \
$(static_cppflags) \
$(NULL)
libdbus_testutils_internal_la_SOURCES = \
test-utils.c \
test-utils.h \
$(NULL)
libdbus_testutils_internal_la_LIBADD = \
$(top_builddir)/dbus/libdbus-internal.la \
$(NULL)
if DBUS_ENABLE_EMBEDDED_TESTS if DBUS_ENABLE_EMBEDDED_TESTS
## break-loader removed for now ## break-loader removed for now
...@@ -70,15 +91,15 @@ endif !DBUS_ENABLE_EMBEDDED_TESTS ...@@ -70,15 +91,15 @@ endif !DBUS_ENABLE_EMBEDDED_TESTS
noinst_PROGRAMS= $(TEST_BINARIES) noinst_PROGRAMS= $(TEST_BINARIES)
test_service_CPPFLAGS = $(static_cppflags) test_service_CPPFLAGS = $(static_cppflags)
test_service_LDADD = libdbus-testutils.la test_service_LDADD = libdbus-testutils-internal.la
test_names_CPPFLAGS = $(static_cppflags) test_names_CPPFLAGS = $(static_cppflags)
test_names_LDADD = libdbus-testutils.la test_names_LDADD = libdbus-testutils-internal.la
## break_loader_CPPFLAGS = $(static_cppflags) ## break_loader_CPPFLAGS = $(static_cppflags)
## break_loader_LDADD = $(top_builddir)/dbus/libdbus-internal.la ## break_loader_LDADD = $(top_builddir)/dbus/libdbus-internal.la
test_shell_service_CPPFLAGS = $(static_cppflags) test_shell_service_CPPFLAGS = $(static_cppflags)
test_shell_service_LDADD = libdbus-testutils.la test_shell_service_LDADD = libdbus-testutils-internal.la
shell_test_CPPFLAGS = $(static_cppflags) shell_test_CPPFLAGS = $(static_cppflags)
shell_test_LDADD = libdbus-testutils.la shell_test_LDADD = libdbus-testutils-internal.la
spawn_test_CPPFLAGS = $(static_cppflags) spawn_test_CPPFLAGS = $(static_cppflags)
spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la
...@@ -88,11 +109,11 @@ test_printf_LDADD = $(top_builddir)/dbus/libdbus-internal.la ...@@ -88,11 +109,11 @@ test_printf_LDADD = $(top_builddir)/dbus/libdbus-internal.la
test_refs_SOURCES = internals/refs.c test_refs_SOURCES = internals/refs.c
test_refs_CPPFLAGS = $(static_cppflags) test_refs_CPPFLAGS = $(static_cppflags)
test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS) test_refs_LDADD = libdbus-testutils-internal.la $(GLIB_LIBS)
test_syslog_SOURCES = internals/syslog.c test_syslog_SOURCES = internals/syslog.c
test_syslog_CPPFLAGS = $(static_cppflags) test_syslog_CPPFLAGS = $(static_cppflags)
test_syslog_LDADD = libdbus-testutils.la $(GLIB_LIBS) test_syslog_LDADD = libdbus-testutils-internal.la $(GLIB_LIBS)
EXTRA_DIST = dbus-test-runner EXTRA_DIST = dbus-test-runner
...@@ -139,45 +160,52 @@ TESTS_ENVIRONMENT = \ ...@@ -139,45 +160,52 @@ TESTS_ENVIRONMENT = \
$(NULL) $(NULL)
manual_authz_SOURCES = manual-authz.c manual_authz_SOURCES = manual-authz.c
manual_authz_LDADD = $(top_builddir)/dbus/libdbus-1.la \ manual_authz_LDADD = \
$(testutils_shared_if_possible) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) $(NULL)
test_corrupt_SOURCES = corrupt.c test_corrupt_SOURCES = corrupt.c
test_corrupt_LDADD = $(top_builddir)/dbus/libdbus-1.la \ test_corrupt_LDADD = \
$(testutils_shared_if_possible) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) $(NULL)
test_loopback_SOURCES = loopback.c test_loopback_SOURCES = loopback.c
test_loopback_LDADD = $(top_builddir)/dbus/libdbus-1.la \ test_loopback_LDADD = \
$(testutils_shared_if_possible) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) $(NULL)
test_relay_SOURCES = relay.c test_relay_SOURCES = relay.c
test_relay_LDADD = $(top_builddir)/dbus/libdbus-1.la \ test_relay_LDADD = \
$(testutils_shared_if_possible) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) $(NULL)
test_dbus_daemon_SOURCES = dbus-daemon.c test_dbus_daemon_SOURCES = dbus-daemon.c
test_dbus_daemon_LDADD = $(top_builddir)/dbus/libdbus-1.la \ test_dbus_daemon_LDADD = \
$(testutils_shared_if_possible) \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) $(NULL)
test_dbus_daemon_eavesdrop_SOURCES = dbus-daemon-eavesdrop.c test_dbus_daemon_eavesdrop_SOURCES = dbus-daemon-eavesdrop.c
test_dbus_daemon_eavesdrop_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS) test_dbus_daemon_eavesdrop_LDADD = \
test_dbus_daemon_eavesdrop_LDFLAGS = @R_DYNAMIC_LDFLAG@ $(testutils_shared_if_possible) \
test_dbus_daemon_eavesdrop_LDADD = $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) $(NULL)
test_marshal_SOURCES = marshal.c test_marshal_SOURCES = marshal.c
test_marshal_LDADD = $(top_builddir)/dbus/libdbus-1.la \ test_marshal_LDADD = \
$(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \ $(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) $(NULL)
test_syntax_SOURCES = syntax.c test_syntax_SOURCES = syntax.c
test_syntax_LDADD = $(top_builddir)/dbus/libdbus-1.la \ test_syntax_LDADD = \
$(GLIB_LIBS) $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
$(NULL)
if DBUS_ENABLE_MODULAR_TESTS if DBUS_ENABLE_MODULAR_TESTS
TESTS += $(installable_tests) TESTS += $(installable_tests)
......
...@@ -30,10 +30,12 @@ ...@@ -30,10 +30,12 @@
#include <gio/gio.h> #include <gio/gio.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "test-utils.h"
typedef struct { typedef struct {
DBusError e; DBusError e;
TestMainContext *ctx;
DBusServer *server; DBusServer *server;
DBusConnection *server_conn; DBusConnection *server_conn;
...@@ -72,13 +74,14 @@ new_conn_cb (DBusServer *server, ...@@ -72,13 +74,14 @@ new_conn_cb (DBusServer *server,
g_assert (f->server_conn == NULL); g_assert (f->server_conn == NULL);
f->server_conn = dbus_connection_ref (server_conn); f->server_conn = dbus_connection_ref (server_conn);
dbus_connection_setup_with_g_main (server_conn, NULL); test_connection_setup (f->ctx, server_conn);
} }
static void static void
setup (Fixture *f, setup (Fixture *f,
gconstpointer addr) gconstpointer addr)
{ {
f->ctx = test_main_context_get ();
dbus_error_init (&f->e); dbus_error_init (&f->e);
g_queue_init (&f->client_messages); g_queue_init (&f->client_messages);
...@@ -88,7 +91,7 @@ setup (Fixture *f, ...@@ -88,7 +91,7 @@ setup (Fixture *f,
dbus_server_set_new_connection_function (f->server, dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL); new_conn_cb, f, NULL);
dbus_server_setup_with_g_main (f->server, NULL); test_server_setup (f->ctx, f->server);
} }
static void static void
...@@ -103,12 +106,12 @@ test_connect (Fixture *f, ...@@ -103,12 +106,12 @@ test_connect (Fixture *f,
dbus_server_get_address (f->server), &f->e); dbus_server_get_address (f->server), &f->e);
assert_no_error (&f->e); assert_no_error (&f->e);
g_assert (f->client_conn != NULL); g_assert (f->client_conn != NULL);
dbus_connection_setup_with_g_main (f->client_conn, NULL); test_connection_setup (f->ctx, f->client_conn);
while (f->server_conn == NULL) while (f->server_conn == NULL)
{ {
g_print ("."); g_print (".");
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
have_mem = dbus_connection_add_filter (f->client_conn, have_mem = dbus_connection_add_filter (f->client_conn,
...@@ -137,7 +140,7 @@ test_message (Fixture *f, ...@@ -137,7 +140,7 @@ test_message (Fixture *f,
while (g_queue_is_empty (&f->client_messages)) while (g_queue_is_empty (&f->client_messages))
{ {
g_print ("."); g_print (".");
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
g_assert_cmpuint (g_queue_get_length (&f->client_messages), ==, 1); g_assert_cmpuint (g_queue_get_length (&f->client_messages), ==, 1);
...@@ -229,7 +232,7 @@ test_corrupt (Fixture *f, ...@@ -229,7 +232,7 @@ test_corrupt (Fixture *f,
while (g_queue_is_empty (&f->client_messages)) while (g_queue_is_empty (&f->client_messages))
{ {
g_print ("."); g_print (".");
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
incoming = g_queue_pop_head (&f->client_messages); incoming = g_queue_pop_head (&f->client_messages);
...@@ -318,7 +321,7 @@ test_byte_order (Fixture *f, ...@@ -318,7 +321,7 @@ test_byte_order (Fixture *f,
while (g_queue_is_empty (&f->client_messages)) while (g_queue_is_empty (&f->client_messages))
{ {
g_print ("."); g_print (".");
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
message = g_queue_pop_head (&f->client_messages); message = g_queue_pop_head (&f->client_messages);
...@@ -368,6 +371,8 @@ teardown (Fixture *f, ...@@ -368,6 +371,8 @@ teardown (Fixture *f,
dbus_server_unref (f->server); dbus_server_unref (f->server);
f->server = NULL; f->server = NULL;
} }
test_main_context_unref (f->ctx);
} }
int int
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <glib.h> #include <glib.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <string.h> #include <string.h>
...@@ -42,6 +41,8 @@ ...@@ -42,6 +41,8 @@
# include <unistd.h> # include <unistd.h>
#endif #endif
#include "test-utils.h"
#define SENDER_NAME "test.eavesdrop.sender" #define SENDER_NAME "test.eavesdrop.sender"
#define SENDER_PATH "/test/eavesdrop/sender" #define SENDER_PATH "/test/eavesdrop/sender"
#define SENDER_IFACE SENDER_NAME #define SENDER_IFACE SENDER_NAME
...@@ -71,6 +72,7 @@ typedef enum { ...@@ -71,6 +72,7 @@ typedef enum {
} SignalDst; } SignalDst;
typedef struct { typedef struct {
TestMainContext *ctx;
DBusError e; DBusError e;
GError *ge; GError *ge;
...@@ -160,7 +162,8 @@ spawn_dbus_daemon (gchar *binary, ...@@ -160,7 +162,8 @@ spawn_dbus_daemon (gchar *binary,
} }
static DBusConnection * static DBusConnection *
connect_to_bus (const gchar *address) connect_to_bus (Fixture *f,
const gchar *address)
{ {
DBusConnection *conn; DBusConnection *conn;
DBusError error = DBUS_ERROR_INIT; DBusError error = DBUS_ERROR_INIT;
...@@ -175,7 +178,7 @@ connect_to_bus (const gchar *address) ...@@ -175,7 +178,7 @@ connect_to_bus (const gchar *address)
g_assert (ok); g_assert (ok);
g_assert (dbus_bus_get_unique_name (conn) != NULL); g_assert (dbus_bus_get_unique_name (conn) != NULL);
dbus_connection_setup_with_g_main (conn, NULL); test_connection_setup (f->ctx, conn);
return conn; return conn;
} }
...@@ -380,6 +383,8 @@ setup (Fixture *f, ...@@ -380,6 +383,8 @@ setup (Fixture *f,
gchar *config; gchar *config;
gchar *address; gchar *address;
f->ctx = test_main_context_get ();
f->ge = NULL; f->ge = NULL;
dbus_error_init (&f->e); dbus_error_init (&f->e);
...@@ -409,12 +414,12 @@ setup (Fixture *f, ...@@ -409,12 +414,12 @@ setup (Fixture *f,
g_free (dbus_daemon); g_free (dbus_daemon);
g_free (config); g_free (config);
f->sender = connect_to_bus (address); f->sender = connect_to_bus (f, address);
dbus_bus_request_name (f->sender, SENDER_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE, dbus_bus_request_name (f->sender, SENDER_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE,
&(f->e)); &(f->e));
f->receiver = connect_to_bus (address); f->receiver = connect_to_bus (f, address);
f->eavesdropper = connect_to_bus (address); f->eavesdropper = connect_to_bus (f, address);
f->politelistener = connect_to_bus (address); f->politelistener = connect_to_bus (f, address);
add_receiver_filter (f); add_receiver_filter (f);
add_politelistener_filter (f); add_politelistener_filter (f);
add_eavesdropper_filter (f); add_eavesdropper_filter (f);
...@@ -432,7 +437,7 @@ test_eavesdrop_broadcast (Fixture *f, ...@@ -432,7 +437,7 @@ test_eavesdrop_broadcast (Fixture *f,
while (!f->receiver_got_stopper || while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper || !f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper) !f->eavesdropper_got_stopper)
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
/* all the three connection can receive a broadcast */ /* all the three connection can receive a broadcast */
g_assert_cmpint (f->receiver_dst, ==, BROADCAST); g_assert_cmpint (f->receiver_dst, ==, BROADCAST);
...@@ -452,7 +457,7 @@ test_eavesdrop_unicast_to_sender (Fixture *f, ...@@ -452,7 +457,7 @@ test_eavesdrop_unicast_to_sender (Fixture *f,
while (!f->receiver_got_stopper || while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper || !f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper) !f->eavesdropper_got_stopper)
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
/* not directed to it and not broadcasted, they cannot receive it */ /* not directed to it and not broadcasted, they cannot receive it */
g_assert_cmpint (f->receiver_dst, ==, NONE_YET); g_assert_cmpint (f->receiver_dst, ==, NONE_YET);
...@@ -472,7 +477,7 @@ test_eavesdrop_unicast_to_receiver (Fixture *f, ...@@ -472,7 +477,7 @@ test_eavesdrop_unicast_to_receiver (Fixture *f,
while (!f->receiver_got_stopper || while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper || !f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper) !f->eavesdropper_got_stopper)
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
/* direct to him */ /* direct to him */
g_assert_cmpint (f->receiver_dst, ==, TO_ME); g_assert_cmpint (f->receiver_dst, ==, TO_ME);
...@@ -534,6 +539,8 @@ teardown (Fixture *f, ...@@ -534,6 +539,8 @@ teardown (Fixture *f,
#endif #endif
g_spawn_close_pid (f->daemon_pid); g_spawn_close_pid (f->daemon_pid);
test_main_context_unref (f->ctx);
} }
int int
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <glib.h> #include <glib.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <string.h> #include <string.h>
...@@ -42,9 +41,13 @@ ...@@ -42,9 +41,13 @@
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#include "test-utils.h"
typedef struct { typedef struct {
gboolean skip; gboolean skip;
TestMainContext *ctx;
DBusError e; DBusError e;
GError *ge; GError *ge;
...@@ -127,7 +130,8 @@ spawn_dbus_daemon (gchar *binary, ...@@ -127,7 +130,8 @@ spawn_dbus_daemon (gchar *binary,
} }
static DBusConnection * static DBusConnection *
connect_to_bus (const gchar *address) connect_to_bus (Fixture *f,
const gchar *address)
{ {
DBusConnection *conn; DBusConnection *conn;
DBusError error = DBUS_ERROR_INIT; DBusError error = DBUS_ERROR_INIT;
...@@ -142,7 +146,7 @@ connect_to_bus (const gchar *address) ...@@ -142,7 +146,7 @@ connect_to_bus (const gchar *address)
g_assert (ok); g_assert (ok);
g_assert (dbus_bus_get_unique_name (conn) != NULL); g_assert (dbus_bus_get_unique_name (conn) != NULL);
dbus_connection_setup_with_g_main (conn, NULL); test_connection_setup (f->ctx, conn);
return conn; return conn;
} }
...@@ -184,6 +188,7 @@ setup (Fixture *f, ...@@ -184,6 +188,7 @@ setup (Fixture *f,
gchar *arg; gchar *arg;
gchar *address; gchar *address;
f->ctx = test_main_context_get ();
f->ge = NULL; f->ge = NULL;
dbus_error_init (&f->e); dbus_error_init (&f->e);
...@@ -227,8 +232,8 @@ setup (Fixture *f, ...@@ -227,8 +232,8 @@ setup (Fixture *f,
g_free (dbus_daemon); g_free (dbus_daemon);
g_free (arg); g_free (arg);
f->left_conn = connect_to_bus (address); f->left_conn = connect_to_bus (f, address);
f->right_conn = connect_to_bus (address); f->right_conn = connect_to_bus (f, address);
g_free (address); g_free (address);
} }
...@@ -302,7 +307,7 @@ test_echo (Fixture *f, ...@@ -302,7 +307,7 @@ test_echo (Fixture *f,
} }
while (received < count) while (received < count)
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
elapsed = g_test_timer_elapsed (); elapsed = g_test_timer_elapsed ();
...@@ -361,7 +366,7 @@ test_creds (Fixture *f, ...@@ -361,7 +366,7 @@ test_creds (Fixture *f,
g_error ("OOM"); g_error ("OOM");
while (m == NULL) while (m == NULL)
g_main_context_iteration (NULL, TRUE); test_main_context_iterate (f->ctx, TRUE);
g_assert_cmpstr (dbus_message_get_signature (m), ==, "a{sv}"); g_assert_cmpstr (dbus_message_get_signature (m), ==, "a{sv}");
...@@ -473,6 +478,8 @@ teardown (Fixture *f, ...@@ -473,6 +478,8 @@ teardown (Fixture *f,
g_spawn_close_pid (f->daemon_pid); g_spawn_close_pid (f->daemon_pid);
f->daemon_pid = 0; f->daemon_pid = 0;
} }
test_main_context_unref (f->ctx);
} }
static Config limited_config = { static Config limited_config = {
......
...@@ -29,11 +29,13 @@ ...@@ -29,11 +29,13 @@
#include <glib.h> #include <glib.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <string.h> #include <string.h>
#include "test-utils.h"
typedef struct { typedef struct {
TestMainContext *ctx;
DBusError e; DBusError e;
DBusServer *server; DBusServer *server;
...@@ -74,7 +76,7 @@ new_conn_cb (DBusServer *server, ...@@ -74,7 +76,7 @@ new_conn_cb (DBusServer *server,
g_assert (f->server_conn == NULL); g_assert (f->server_conn == NULL);
f->server_conn = dbus_connection_ref (server_conn); f->server_conn = dbus_connection_ref (server_conn);
dbus_connection_setup_with_g_main (server_conn, NULL); test_connection_setup (f->ctx, server_conn);
have_mem = dbus_connection_add_filter (server_conn, have_mem = dbus_connection_add_filter (server_conn,
server_message_cb, f, NULL); server_message_cb, f, NULL);
...@@ -85,6 +87,7 @@ static void ...@@ -85,6 +87,7 @@ static void
setup (Fixture *f, setup (Fixture *f,
gconstpointer addr) gconstpointer addr)
{ {
f->ctx = test_main_context_get ();
dbus_error_init (&f->e); dbus_error_init (&f->e);
g_queue_init (&f->server_messages); g_queue_init (&f->server_messages);
...@@ -94,7 +97,7 @@ setup (Fixture *f, ...@@ -94,7 +97,7 @@ setup (Fixture *f,
dbus_server_set_new_connection_function (f->server, dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL); new_conn_cb, f, NULL);
dbus_server_setup_with_g_main (f->server, NULL); test_server_setup (f->ctx, f->server);
} }
static void static void
...@@ -107,12 +110,12 @@ test_connect (Fixture *f, ...@@ -107,12 +110,12 @@ t