summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-04-16 12:10:37 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-06-25 17:18:36 +0100
commit82d45d15088d206f1e1f024215e95301fa04e92c (patch)
tree9b64cfa3d15f482abd641aa14a7a4e59adb1f5a3
parent403c5bf4d98fcba83caa94aee96da27128bbf9c8 (diff)
downloaddbus-glib-82d45d15088d206f1e1f024215e95301fa04e92c.tar.gz
Add a utility function to tear down a private connection in tests
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41126 Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
-rw-r--r--configure.ac1
-rw-r--r--test/Makefile.am4
-rw-r--r--test/core/Makefile.am4
-rw-r--r--test/interfaces/Makefile.am4
-rw-r--r--test/lib/Makefile.am19
-rw-r--r--test/lib/util.c69
-rw-r--r--test/lib/util.h32
7 files changed, 129 insertions, 4 deletions
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. <http://www.collabora.co.uk/>
+ * 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 <config.h>
+
+#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. <http://www.collabora.co.uk/>
+ * 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 <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+void test_run_until_disconnected (DBusGConnection *connection,
+ GMainContext *context);
+
+#endif