# 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_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 )
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)
target_link_libraries(test-pending-call-dispatch ${DBUS_INTERNAL_LIBRARIES})
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],
[],
[if test "x$enable_modular_tests" = xyes; then
else # assumed to be "auto"
with_glib=no
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
- AC_MSG_NOTICE([Full test coverage (--enable-modular-tests=yes or --enable-tests=yes) requires dbus-glib])
- AC_MSG_ERROR([$DBUS_GLIB_ERRORS])
- else # assumed to be "auto"
- with_glib=no
- fi])
-fi
+ [AS_IF([test "x$with_dbus_glib" = xyes],
+ dnl specifically requested, but not found
+ [AC_MSG_ERROR([$DBUS_GLIB_ERRORS])],
+ dnl else: assumed to be "auto"
+ [with_dbus_glib=no])])])
+AM_CONDITIONAL([DBUS_WITH_DBUS_GLIB], [test "x$with_dbus_glib" != xno])
+
if test "x$enable_modular_tests" != xno; then
AC_DEFINE([DBUS_ENABLE_MODULAR_TESTS], [1],
[Define to build independent test binaries])
Building embedded tests: ${enable_embedded_tests}
Building modular tests: ${enable_modular_tests}
- with GLib: ${with_glib}
+ - with dbus-glib: ${with_dbus_glib}
Building verbose mode: ${enable_verbose_mode}
Building assertions: ${enable_asserts}
Building checks: ${enable_checks}
$(AM_CPPFLAGS) \
-DDBUS_STATIC_BUILD \
-DDBUS_COMPILATION \
+ -DDBUS_TEST_USE_INTERNAL \
$(NULL)
-libdbus_testutils_la_CPPFLAGS = \
- $(static_cppflags)
+noinst_LTLIBRARIES = libdbus-testutils-internal.la
+
+# 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 = \
test-utils.c \
test-utils.h \
$(NULL)
libdbus_testutils_la_LIBADD = \
- $(top_builddir)/dbus/libdbus-internal.la \
+ $(top_builddir)/dbus/libdbus-1.la \
+ $(GLIB_LIBS) \
+ $(DBUS_GLIB_LIBS) \
$(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
## break-loader removed for now
noinst_PROGRAMS= $(TEST_BINARIES)
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_LDADD = libdbus-testutils.la
+test_names_LDADD = libdbus-testutils-internal.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
+test_shell_service_LDADD = libdbus-testutils-internal.la
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_LDADD = $(top_builddir)/dbus/libdbus-internal.la
test_refs_SOURCES = internals/refs.c
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_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
$(NULL)
manual_authz_SOURCES = manual-authz.c
-manual_authz_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+manual_authz_LDADD = \
+ $(testutils_shared_if_possible) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_corrupt_SOURCES = corrupt.c
-test_corrupt_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_corrupt_LDADD = \
+ $(testutils_shared_if_possible) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_loopback_SOURCES = loopback.c
-test_loopback_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_loopback_LDADD = \
+ $(testutils_shared_if_possible) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_relay_SOURCES = relay.c
-test_relay_LDADD = $(top_builddir)/dbus/libdbus-1.la \
+test_relay_LDADD = \
+ $(testutils_shared_if_possible) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
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) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
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 \
+test_dbus_daemon_eavesdrop_LDADD = \
+ $(testutils_shared_if_possible) \
$(GLIB_LIBS) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
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) \
- $(DBUS_GLIB_LIBS)
+ $(NULL)
test_syntax_SOURCES = syntax.c
-test_syntax_LDADD = $(top_builddir)/dbus/libdbus-1.la \
- $(GLIB_LIBS)
+test_syntax_LDADD = \
+ $(top_builddir)/dbus/libdbus-1.la \
+ $(GLIB_LIBS) \
+ $(NULL)
if DBUS_ENABLE_MODULAR_TESTS
TESTS += $(installable_tests)
#include <gio/gio.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
+
+#include "test-utils.h"
typedef struct {
DBusError e;
+ TestMainContext *ctx;
DBusServer *server;
DBusConnection *server_conn;
g_assert (f->server_conn == NULL);
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
setup (Fixture *f,
gconstpointer addr)
{
+ f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->client_messages);
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->server, NULL);
+ test_server_setup (f->ctx, f->server);
}
static void
dbus_server_get_address (f->server), &f->e);
assert_no_error (&f->e);
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)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
have_mem = dbus_connection_add_filter (f->client_conn,
while (g_queue_is_empty (&f->client_messages))
{
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);
while (g_queue_is_empty (&f->client_messages))
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
incoming = g_queue_pop_head (&f->client_messages);
while (g_queue_is_empty (&f->client_messages))
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
message = g_queue_pop_head (&f->client_messages);
dbus_server_unref (f->server);
f->server = NULL;
}
+
+ test_main_context_unref (f->ctx);
}
int
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <string.h>
# include <unistd.h>
#endif
+#include "test-utils.h"
+
#define SENDER_NAME "test.eavesdrop.sender"
#define SENDER_PATH "/test/eavesdrop/sender"
#define SENDER_IFACE SENDER_NAME
} SignalDst;
typedef struct {
+ TestMainContext *ctx;
DBusError e;
GError *ge;
}
static DBusConnection *
-connect_to_bus (const gchar *address)
+connect_to_bus (Fixture *f,
+ const gchar *address)
{
DBusConnection *conn;
DBusError error = DBUS_ERROR_INIT;
g_assert (ok);
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;
}
gchar *config;
gchar *address;
+ f->ctx = test_main_context_get ();
+
f->ge = NULL;
dbus_error_init (&f->e);
g_free (dbus_daemon);
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,
&(f->e));
- f->receiver = connect_to_bus (address);
- f->eavesdropper = connect_to_bus (address);
- f->politelistener = connect_to_bus (address);
+ f->receiver = connect_to_bus (f, address);
+ f->eavesdropper = connect_to_bus (f, address);
+ f->politelistener = connect_to_bus (f, address);
add_receiver_filter (f);
add_politelistener_filter (f);
add_eavesdropper_filter (f);
while (!f->receiver_got_stopper ||
!f->politelistener_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 */
g_assert_cmpint (f->receiver_dst, ==, BROADCAST);
while (!f->receiver_got_stopper ||
!f->politelistener_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 */
g_assert_cmpint (f->receiver_dst, ==, NONE_YET);
while (!f->receiver_got_stopper ||
!f->politelistener_got_stopper ||
!f->eavesdropper_got_stopper)
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
/* direct to him */
g_assert_cmpint (f->receiver_dst, ==, TO_ME);
#endif
g_spawn_close_pid (f->daemon_pid);
+
+ test_main_context_unref (f->ctx);
}
int
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <string.h>
# include <sys/types.h>
#endif
+#include "test-utils.h"
+
typedef struct {
gboolean skip;
+ TestMainContext *ctx;
+
DBusError e;
GError *ge;
}
static DBusConnection *
-connect_to_bus (const gchar *address)
+connect_to_bus (Fixture *f,
+ const gchar *address)
{
DBusConnection *conn;
DBusError error = DBUS_ERROR_INIT;
g_assert (ok);
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;
}
gchar *arg;
gchar *address;
+ f->ctx = test_main_context_get ();
f->ge = NULL;
dbus_error_init (&f->e);
g_free (dbus_daemon);
g_free (arg);
- f->left_conn = connect_to_bus (address);
- f->right_conn = connect_to_bus (address);
+ f->left_conn = connect_to_bus (f, address);
+ f->right_conn = connect_to_bus (f, address);
g_free (address);
}
}
while (received < count)
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
elapsed = g_test_timer_elapsed ();
g_error ("OOM");
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_spawn_close_pid (f->daemon_pid);
f->daemon_pid = 0;
}
+
+ test_main_context_unref (f->ctx);
}
static Config limited_config = {
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <string.h>
+#include "test-utils.h"
+
typedef struct {
+ TestMainContext *ctx;
DBusError e;
DBusServer *server;
g_assert (f->server_conn == NULL);
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,
server_message_cb, f, NULL);
setup (Fixture *f,
gconstpointer addr)
{
+ f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->server_messages);
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->server, NULL);
+ test_server_setup (f->ctx, f->server);
}
static void
dbus_server_get_address (f->server), &f->e);
assert_no_error (&f->e);
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)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
}
f->client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
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)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
/* We get disconnected */
while (g_queue_is_empty (&f->server_messages))
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1);
while (g_queue_is_empty (&f->server_messages))
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1);
dbus_server_unref (f->server);
f->server = NULL;
}
+
+ test_main_context_unref (f->ctx);
}
int
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#ifdef G_OS_UNIX
#include <unistd.h>
#include <sys/types.h>
#endif
+#include "test-utils.h"
+
typedef struct {
DBusError e;
+ TestMainContext *ctx;
DBusServer *normal_server;
DBusServer *anon_allowed_server;
Fixture *f = data;
dbus_connection_ref (conn);
- dbus_connection_setup_with_g_main (conn, NULL);
+ test_connection_setup (f->ctx, conn);
if (!dbus_connection_add_filter (conn, server_message_cb, f, NULL))
oom ();
g_assert (f->normal_server != NULL);
dbus_server_set_new_connection_function (f->normal_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->normal_server, NULL);
+ test_server_setup (f->ctx, f->normal_server);
connect_addr = dbus_server_get_address (f->normal_server);
g_message ("Normal server:\n%s", connect_addr);
dbus_free (connect_addr);
g_assert (f->anon_allowed_server != NULL);
dbus_server_set_new_connection_function (f->anon_allowed_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->anon_allowed_server, NULL);
+ test_server_setup (f->ctx, f->anon_allowed_server);
connect_addr = dbus_server_get_address (f->anon_allowed_server);
g_message ("Anonymous-allowed server:\n%s", connect_addr);
dbus_free (connect_addr);
g_assert (f->anon_only_server != NULL);
dbus_server_set_new_connection_function (f->anon_only_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->anon_only_server, NULL);
+ test_server_setup (f->ctx, f->anon_only_server);
connect_addr = dbus_server_get_address (f->anon_only_server);
g_message ("Anonymous-only server:\n%s", connect_addr);
dbus_free (connect_addr);
dbus_server_set_auth_mechanisms (f->anon_mech_only_server, only_anon);
dbus_server_set_new_connection_function (f->anon_mech_only_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->anon_mech_only_server, NULL);
+ test_server_setup (f->ctx, f->anon_mech_only_server);
connect_addr = dbus_server_get_address (f->anon_mech_only_server);
g_message ("Anon mech only server:\n%s", connect_addr);
dbus_free (connect_addr);
dbus_server_set_auth_mechanisms (f->anon_disallowed_server, only_anon);
dbus_server_set_new_connection_function (f->anon_disallowed_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->anon_disallowed_server, NULL);
+ test_server_setup (f->ctx, f->anon_disallowed_server);
connect_addr = dbus_server_get_address (f->anon_disallowed_server);
g_message ("Anonymous-disallowed server:\n%s", connect_addr);
dbus_free (connect_addr);
g_assert (f->permissive_server != NULL);
dbus_server_set_new_connection_function (f->permissive_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->permissive_server, NULL);
+ test_server_setup (f->ctx, f->permissive_server);
connect_addr = dbus_server_get_address (f->permissive_server);
g_message ("Permissive server:\n%s", connect_addr);
dbus_free (connect_addr);
g_assert (f->unhappy_server != NULL);
dbus_server_set_new_connection_function (f->unhappy_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->unhappy_server, NULL);
+ test_server_setup (f->ctx, f->unhappy_server);
connect_addr = dbus_server_get_address (f->unhappy_server);
g_message ("Unhappy server:\n%s", connect_addr);
dbus_free (connect_addr);
g_assert (f->same_uid_server != NULL);
dbus_server_set_new_connection_function (f->same_uid_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->same_uid_server, NULL);
+ test_server_setup (f->ctx, f->same_uid_server);
connect_addr = dbus_server_get_address (f->same_uid_server);
g_message ("Same-UID server:\n%s", connect_addr);
dbus_free (connect_addr);
g_assert (f->same_uid_or_anon_server != NULL);
dbus_server_set_new_connection_function (f->same_uid_or_anon_server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->same_uid_or_anon_server, NULL);
+ test_server_setup (f->ctx, f->same_uid_or_anon_server);
connect_addr = dbus_server_get_address (f->same_uid_or_anon_server);
g_message ("Same-UID-or-anon server:\n%s", connect_addr);
dbus_free (connect_addr);
main (int argc,
char **argv)
{
- Fixture f = { DBUS_ERROR_INIT };
+ Fixture f = { DBUS_ERROR_INIT, test_main_context_get () };
if (argc >= 2)
setup (&f, argv[1]);
setup (&f, "tcp:host=127.0.0.1");
for (;;)
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f.ctx, TRUE);
+
+ /* never returns */
}
#include <string.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
typedef struct {
DBusError e;
-I$(top_srcdir) \
-DDBUS_COMPILATION \
-DDBUS_STATIC_BUILD \
+ -DDBUS_TEST_USE_INTERNAL \
$(NULL)
# if assertions are enabled, improve backtraces
test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-internal.la
test_ids_LDADD=$(top_builddir)/dbus/libdbus-internal.la
-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
+test_shutdown_LDADD=../libdbus-testutils-internal.la
+test_privserver_LDADD=../libdbus-testutils-internal.la
+test_privserver_client_LDADD=../libdbus-testutils-internal.la
+test_autolaunch_LDADD=../libdbus-testutils-internal.la
endif
#include <glib.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
+
+#include "test-utils.h"
/* This is basically a miniature dbus-daemon. We relay messages from the client
* on the left to the client on the right.
*/
typedef struct {
+ TestMainContext *ctx;
DBusError e;
DBusServer *server;
f->right_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
setup (Fixture *f,
gconstpointer data G_GNUC_UNUSED)
{
+ f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->messages);
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
- dbus_server_setup_with_g_main (f->server, NULL);
+ test_server_setup (f->ctx, f->server);
}
static void
f->left_client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
g_assert (f->left_client_conn != NULL);
- dbus_connection_setup_with_g_main (f->left_client_conn, NULL);
+ test_connection_setup (f->ctx, f->left_client_conn);
while (f->left_server_conn == NULL)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
f->right_client_conn = dbus_connection_open_private (address, &f->e);
assert_no_error (&f->e);
g_assert (f->right_client_conn != NULL);
- dbus_connection_setup_with_g_main (f->right_client_conn, NULL);
+ test_connection_setup (f->ctx, f->right_client_conn);
dbus_free (address);
while (f->right_server_conn == NULL)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
have_mem = dbus_connection_add_filter (f->right_client_conn,
while (g_queue_get_length (&f->messages) < 2)
{
g_print (".");
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 2);
/* This was an attempt to reproduce fd.o #34393. It didn't work. */
g_test_bug ("34393");
dbus_connection_set_max_received_size (f->left_server_conn, 1);
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
for (i = 0; i < MANY; i++)
{
{
while (g_queue_is_empty (&f->messages))
{
- g_main_context_iteration (NULL, TRUE);
+ test_main_context_iterate (f->ctx, TRUE);
}
while ((incoming = g_queue_pop_head (&f->messages)) != NULL)
dbus_server_unref (f->server);
f->server = NULL;
}
+
+ test_main_context_unref (f->ctx);
}
int
#include <config.h>
#include "test-utils.h"
+#ifndef DBUS_TEST_USE_INTERNAL
+# include <dbus/dbus.h>
+# include <dbus/dbus-glib-lowlevel.h>
+#endif
+
+#ifdef DBUS_TEST_USE_INTERNAL
+
typedef struct
{
DBusLoop *loop;
return cd;
}
+#endif /* DBUS_TEST_USE_INTERNAL */
+
dbus_bool_t
-test_connection_setup (DBusLoop *loop,
+test_connection_setup (TestMainContext *ctx,
DBusConnection *connection)
{
+#ifdef DBUS_TEST_USE_INTERNAL
+ DBusLoop *loop = ctx;
CData *cd;
cd = NULL;
dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
return FALSE;
+#else /* !DBUS_TEST_USE_INTERNAL */
+
+ dbus_connection_setup_with_g_main (connection, ctx);
+ return TRUE;
+
+#endif /* !DBUS_TEST_USE_INTERNAL */
+}
+
+static void
+die (const char *message)
+{
+ fprintf (stderr, "*** %s", message);
+ exit (1);
}
void
-test_connection_shutdown (DBusLoop *loop,
+test_connection_shutdown (TestMainContext *ctx,
DBusConnection *connection)
{
if (!dbus_connection_set_watch_functions (connection,
NULL,
NULL,
NULL, NULL))
- _dbus_assert_not_reached ("setting watch functions to NULL failed");
+ die ("setting watch functions to NULL failed");
if (!dbus_connection_set_timeout_functions (connection,
NULL,
NULL,
NULL,
NULL, NULL))
- _dbus_assert_not_reached ("setting timeout functions to NULL failed");
+ die ("setting timeout functions to NULL failed");
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
}
+#ifdef DBUS_TEST_USE_INTERNAL
+
typedef struct
{
DBusLoop *loop;
_dbus_loop_remove_timeout (context->loop, timeout);
}
+#endif /* DBUS_TEST_USE_INTERNAL */
+
dbus_bool_t
-test_server_setup (DBusLoop *loop,
+test_server_setup (TestMainContext *ctx,
DBusServer *server)
{
+#ifdef DBUS_TEST_USE_INTERNAL
+ DBusLoop *loop = ctx;
ServerData *sd;
sd = serverdata_new (loop, server);
test_server_shutdown (loop, server);
return FALSE;
+
+#else /* !DBUS_TEST_USE_INTERNAL */
+
+ dbus_server_setup_with_g_main (server, ctx);
+ return TRUE;
+
+#endif /* !DBUS_TEST_USE_INTERNAL */
}
void
-test_server_shutdown (DBusLoop *loop,
+test_server_shutdown (TestMainContext *ctx,
DBusServer *server)
{
dbus_server_disconnect (server);
NULL, NULL, NULL,
NULL,
NULL))
- _dbus_assert_not_reached ("setting watch functions to NULL failed");
+ die ("setting watch functions to NULL failed");
if (!dbus_server_set_timeout_functions (server,
NULL, NULL, NULL,
NULL,
NULL))
- _dbus_assert_not_reached ("setting timeout functions to NULL failed");
+ die ("setting timeout functions to NULL failed");
+}
+
+TestMainContext *
+test_main_context_get (void)
+{
+#ifdef DBUS_TEST_USE_INTERNAL
+ return _dbus_loop_new ();
+#else
+ /* I suspect dbus-glib relies the default main context in some places */
+ return g_main_context_ref (g_main_context_default ());
+#endif
+}
+
+TestMainContext *
+test_main_context_ref (TestMainContext *ctx)
+{
+#ifdef DBUS_TEST_USE_INTERNAL
+ return _dbus_loop_ref (ctx);
+#else
+ return g_main_context_ref (ctx);
+#endif
+}
+
+void test_main_context_unref (TestMainContext *ctx)
+{
+#ifdef DBUS_TEST_USE_INTERNAL
+ _dbus_loop_unref (ctx);
+#else
+ g_main_context_unref (ctx);
+#endif
+}
+
+void test_main_context_iterate (TestMainContext *ctx,
+ dbus_bool_t may_block)
+{
+#ifdef DBUS_TEST_USE_INTERNAL
+ _dbus_loop_iterate (ctx, may_block);
+#else
+ g_main_context_iteration (ctx, may_block);
+#endif
}
#ifndef TEST_UTILS_H
#define TEST_UTILS_H
-#include <dbus/dbus.h>
+
#include <stdio.h>
#include <stdlib.h>
-#include <dbus/dbus-mainloop.h>
-#include <dbus/dbus-internals.h>
-dbus_bool_t test_connection_setup (DBusLoop *loop,
+#include <dbus/dbus.h>
+
+#ifdef DBUS_TEST_USE_INTERNAL
+
+# include <dbus/dbus-mainloop.h>
+# include <dbus/dbus-internals.h>
+ typedef DBusLoop TestMainContext;
+
+#else /* !DBUS_TEST_USE_INTERNAL */
+
+# include <glib.h>
+ typedef GMainContext TestMainContext;
+
+#endif /* !DBUS_TEST_USE_INTERNAL */
+
+TestMainContext *test_main_context_get (void);
+TestMainContext *test_main_context_ref (TestMainContext *ctx);
+void test_main_context_unref (TestMainContext *ctx);
+void test_main_context_iterate (TestMainContext *ctx,
+ dbus_bool_t may_block);
+
+dbus_bool_t test_connection_setup (TestMainContext *ctx,
DBusConnection *connection);
-void test_connection_shutdown (DBusLoop *loop,
+void test_connection_shutdown (TestMainContext *ctx,
DBusConnection *connection);
-void test_connection_dispatch_all_messages (DBusConnection *connection);
-dbus_bool_t test_connection_dispatch_one_message (DBusConnection *connection);
-dbus_bool_t test_server_setup (DBusLoop *loop,
+dbus_bool_t test_server_setup (TestMainContext *ctx,
DBusServer *server);
-void test_server_shutdown (DBusLoop *loop,
+void test_server_shutdown (TestMainContext *ctx,
DBusServer *server);
#endif