summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2011-07-14 12:36:40 (GMT)
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2011-07-14 12:42:14 (GMT)
commit8a0e284675a252229e38441ca6c9aa7e11eda425 (patch)
treec58ef968e1d4b169f032d50defcddf80a53c7540
parent2fa4235a4860d389fb74bfe6e2e1d5cb1737fa4a (diff)
downloaddbus-policy_refactoring.tar.gz
dbus-policy_refactoring.tar.xz
Factor out some common function and put them in testutils.lapolicy_refactoring
-rw-r--r--test/Makefile.am10
-rw-r--r--test/dbus-daemon-common.c131
-rw-r--r--test/dbus-daemon-common.h36
-rw-r--r--test/dbus-daemon-eavesdrop.c92
-rw-r--r--test/dbus-daemon.c92
5 files changed, 178 insertions, 183 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 443cf81..4650d19 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -6,7 +6,9 @@ DIST_SUBDIRS=name-test
INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS)
-libdbus_testutils_la_SOURCES = test-utils.h test-utils.c
+libdbus_testutils_la_SOURCES = test-utils.h test-utils.c \
+ dbus-daemon-common.h dbus-daemon-common.c
+libdbus_testutils_la_CFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS)
noinst_LTLIBRARIES = libdbus-testutils.la
@@ -118,14 +120,16 @@ test_relay_LDADD = $(top_builddir)/dbus/libdbus-1.la \
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 \
+test_dbus_daemon_LDADD = libdbus-testutils.la \
+ $(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 \
+test_dbus_daemon_eavesdrop_LDADD = libdbus-testutils.la \
+ $(top_builddir)/dbus/libdbus-1.la \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS)
diff --git a/test/dbus-daemon-common.c b/test/dbus-daemon-common.c
new file mode 100644
index 0000000..208e701
--- /dev/null
+++ b/test/dbus-daemon-common.c
@@ -0,0 +1,131 @@
+/* Common part for integration tests for the dbus-daemon
+ *
+ * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
+ * 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-glib-lowlevel.h>
+
+#include <string.h>
+
+#ifdef DBUS_WIN
+# include <windows.h>
+#else
+# include <signal.h>
+# include <unistd.h>
+#endif
+
+#include "dbus-daemon-common.h"
+
+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);
+}
+
+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);
+}
+
+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;
+}
diff --git a/test/dbus-daemon-common.h b/test/dbus-daemon-common.h
new file mode 100644
index 0000000..2b121ec
--- /dev/null
+++ b/test/dbus-daemon-common.h
@@ -0,0 +1,36 @@
+/* Common part for integration tests for the dbus-daemon
+ *
+ * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
+ * 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.
+ */
+
+#ifndef _DBUS_DAEMON_COMMON_H
+#define _DBUS_DAEMON_COMMON_H
+
+#define assert_no_error(e) _assert_no_error (e, __FILE__, __LINE__)
+
+void _assert_no_error (const DBusError *e, const char *file, int line);
+gchar *spawn_dbus_daemon (gchar *binary, gchar *configuration, gint *daemon_pid);
+DBusConnection * connect_to_bus (const gchar *address);
+
+#endif /* _DBUS_DAEMON_COMMON_H */
diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c
index cd4153d..08693a4 100644
--- a/test/dbus-daemon-eavesdrop.c
+++ b/test/dbus-daemon-eavesdrop.c
@@ -41,6 +41,8 @@
# include <unistd.h>
#endif
+#include "dbus-daemon-common.h"
+
#define SENDER_NAME "test.eavesdrop.sender"
#define SENDER_PATH "/test/eavesdrop/sender"
#define SENDER_IFACE SENDER_NAME
@@ -88,96 +90,6 @@ typedef struct {
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
diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c
index ed10d09..26589ee 100644
--- a/test/dbus-daemon.c
+++ b/test/dbus-daemon.c
@@ -40,6 +40,8 @@
# include <unistd.h>
#endif
+#include "dbus-daemon-common.h"
+
typedef struct {
DBusError e;
GError *ge;
@@ -52,96 +54,6 @@ typedef struct {
gboolean right_conn_echo;
} 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;
-}
-
static DBusHandlerResult
echo_filter (DBusConnection *connection,
DBusMessage *message,