From c0530e75dd94bd4d7dba1a1aa6d366356b452aa0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 16 Apr 2012 12:10:37 +0100 Subject: [PATCH 1/2] Add a utility function to tear down a private connection in tests --- configure.ac | 1 + test/Makefile.am | 4 +-- test/core/Makefile.am | 4 ++- test/interfaces/Makefile.am | 4 ++- test/lib/Makefile.am | 19 ++++++++++++ test/lib/util.c | 69 +++++++++++++++++++++++++++++++++++++++++++ test/lib/util.h | 32 ++++++++++++++++++++ 7 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 test/lib/Makefile.am create mode 100644 test/lib/util.c create mode 100644 test/lib/util.h diff --git a/configure.ac b/configure.ac index caa65a0..16dc7e1 100644 --- a/configure.ac +++ b/configure.ac @@ -450,6 +450,7 @@ test/interfaces/Makefile test/data/valid-service-files/debug-glib.service test/data/valid-service-files/debug-echo.service test/data/valid-service-files/interfaces-test.service +test/lib/Makefile test/manual/Makefile tools/Makefile dbus-glib-1.pc diff --git a/test/Makefile.am b/test/Makefile.am index e0531f6..1ffd63e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = . core interfaces manual -DIST_SUBDIRS = core interfaces manual +SUBDIRS = lib . core interfaces manual +DIST_SUBDIRS = lib core interfaces manual INCLUDES = \ -I$(top_srcdir) \ diff --git a/test/core/Makefile.am b/test/core/Makefile.am index e1d3502..8641215 100644 --- a/test/core/Makefile.am +++ b/test/core/Makefile.am @@ -11,7 +11,9 @@ LDADD = \ $(DBUS_GLIB_THREADS_LIBS) \ $(DBUS_GLIB_LIBS) \ $(DBUS_LIBS) \ - $(top_builddir)/dbus/libdbus-glib-1.la + $(top_builddir)/dbus/libdbus-glib-1.la \ + $(top_builddir)/test/lib/libtest.la \ + $(NULL) tool_ldadd = \ $(LDADD) \ diff --git a/test/interfaces/Makefile.am b/test/interfaces/Makefile.am index 3cb2c39..3e83482 100644 --- a/test/interfaces/Makefile.am +++ b/test/interfaces/Makefile.am @@ -8,7 +8,9 @@ INCLUDES = \ LDADD = $(DBUS_GLIB_LIBS) \ $(top_builddir)/dbus/libdbus-glib-1.la \ - $(top_builddir)/dbus/libdbus-gtool.la + $(top_builddir)/dbus/libdbus-gtool.la \ + $(top_builddir)/test/lib/libtest.la \ + $(NULL) ## 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 diff --git a/test/lib/Makefile.am b/test/lib/Makefile.am new file mode 100644 index 0000000..8a2670b --- /dev/null +++ b/test/lib/Makefile.am @@ -0,0 +1,19 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + $(DBUS_CFLAGS) \ + $(DBUS_GLIB_CFLAGS) \ + $(NULL) + +noinst_LTLIBRARIES = libtest.la + +libtest_la_SOURCES = \ + util.c \ + util.h \ + $(NULL) + +libtest_la_LIBADD = \ + $(top_builddir)/dbus/libdbus-glib-1.la \ + $(DBUS_LIBS) \ + $(DBUS_GLIB_LIBS) \ + $(NULL) diff --git a/test/lib/util.c b/test/lib/util.c new file mode 100644 index 0000000..ec879b5 --- /dev/null +++ b/test/lib/util.c @@ -0,0 +1,69 @@ +/* Regression test utilities + * + * Copyright © 2009 Collabora Ltd. + * Copyright © 2009-2011 Nokia Corporation + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include + +#include "util.h" + +static void +destroy_cb (DBusGProxy *proxy G_GNUC_UNUSED, + gpointer user_data) +{ + gboolean *disconnected = user_data; + + *disconnected = TRUE; +} + +void +test_run_until_disconnected (DBusGConnection *connection, + GMainContext *context) +{ + gboolean disconnected = FALSE; + DBusGProxy *proxy; + + g_printerr ("Disconnecting... "); + + dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), + FALSE); + + /* low-level tests might not have called this yet */ + g_type_init (); + + proxy = dbus_g_proxy_new_for_peer (connection, "/", + "org.freedesktop.DBus.Peer"); + g_signal_connect (G_OBJECT (proxy), "destroy", G_CALLBACK (destroy_cb), + &disconnected); + + dbus_connection_close (dbus_g_connection_get_connection (connection)); + + while (!disconnected) + { + g_printerr ("."); + g_main_context_iteration (context, TRUE); + } + + g_signal_handlers_disconnect_by_func (proxy, destroy_cb, &disconnected); + g_object_unref (proxy); + + g_printerr (" disconnected\n"); +} diff --git a/test/lib/util.h b/test/lib/util.h new file mode 100644 index 0000000..bc6fa60 --- /dev/null +++ b/test/lib/util.h @@ -0,0 +1,32 @@ +/* Regression test utilities + * + * Copyright © 2009 Collabora Ltd. + * Copyright © 2009-2011 Nokia Corporation + * + * Licensed under the Academic Free License version 2.1 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#ifndef DBUS_GLIB_TEST_UTIL_H + +#include +#include + +void test_run_until_disconnected (DBusGConnection *connection, + GMainContext *context); + +#endif -- 1.7.10