summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2008-05-30 17:11:15 -0400
committerColin Walters <walters@verbum.org>2008-05-30 17:11:15 -0400
commit5e359834f28b0580e7b79a057614d4e3592709ac (patch)
tree7fcf7e5f72aa49783544010917f2d9f185415a8e /test
parenta73a79a155e97a3bd0d3ce5001ca6b9db803eeeb (diff)
Add "PrivServer" test which exercises DBusServer and dbus_shutdown
* test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in: New service file for PrivServer. * configure.in: Generate it. * test/name-test/Makefile.am: Build test-privserver and test-privserver-client. * test/name-test/test-privserver.c: Use DBusServer to serve a private connection. * test/name-test/test-privserver-client.c: Connect via session bus and get address of private server, exercise dbus_shutdown(). * test/name-test/run-test.sh: Run it.
Diffstat (limited to 'test')
-rw-r--r--test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in4
-rw-r--r--test/name-test/Makefile.am16
-rwxr-xr-xtest/name-test/run-test.sh8
-rw-r--r--test/name-test/test-privserver-client.c102
-rw-r--r--test/name-test/test-privserver.c118
5 files changed, 247 insertions, 1 deletions
diff --git a/test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in b/test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in
new file mode 100644
index 00000000..2cbdaa8b
--- /dev/null
+++ b/test/data/valid-service-files/org.freedesktop.DBus.TestSuite.PrivServer.service.in
@@ -0,0 +1,4 @@
+[D-BUS Service]
+Name=org.freedesktop.DBus.TestSuite.PrivServer
+Exec=@TEST_PRIVSERVER_BINARY@
+
diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am
index 37a56335..17e05bec 100644
--- a/test/name-test/Makefile.am
+++ b/test/name-test/Makefile.am
@@ -16,7 +16,7 @@ if DBUS_BUILD_TESTS
## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we
## build even when not doing "make check"
-noinst_PROGRAMS=test-names test-pending-call-dispatch test-threads-init test-ids test-shutdown
+noinst_PROGRAMS=test-names test-pending-call-dispatch test-threads-init test-ids test-shutdown test-privserver test-privserver-client
test_names_SOURCES= \
test-names.c
@@ -49,4 +49,18 @@ test_shutdown_CFLAGS=
test_shutdown_LDADD=$(top_builddir)/dbus/libdbus-convenience.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
test_shutdown_LDFLAGS=@R_DYNAMIC_LDFLAG@
+test_privserver_SOURCES = \
+ test-privserver.c
+
+test_privserver_CFLAGS=
+test_privserver_LDADD=$(top_builddir)/dbus/libdbus-convenience.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
+test_privserver_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+test_privserver_client_SOURCES = \
+ test-privserver-client.c
+
+test_privserver_client_CFLAGS=
+test_privserver_client_LDADD=$(top_builddir)/dbus/libdbus-convenience.la ../libdbus-testutils.la $(DBUS_TEST_LIBS)
+test_privserver_client_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
endif
diff --git a/test/name-test/run-test.sh b/test/name-test/run-test.sh
index d466b815..3699bc9a 100755
--- a/test/name-test/run-test.sh
+++ b/test/name-test/run-test.sh
@@ -25,6 +25,11 @@ if test -z "$DBUS_TEST_NAME_IN_RUN_TEST"; then
export DBUS_TEST_NAME_IN_RUN_TEST
exec $DBUS_TOP_SRCDIR/tools/run-with-tmp-session-bus.sh $SCRIPTNAME $MODE
fi
+
+if test -n "$DBUS_TEST_MONITOR"; then
+ dbus-monitor --session &
+fi
+
echo "running test-ids"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-ids || die "test-ids failed"
@@ -37,5 +42,8 @@ ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-
echo "running test-threads-init"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-threads-init || die "test-threads-init failed"
+echo "running test-privserver-client"
+${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-privserver-client || die "test-privserver-client failed"
+
echo "running test-shutdown"
${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-shutdown || die "test-shutdown failed"
diff --git a/test/name-test/test-privserver-client.c b/test/name-test/test-privserver-client.c
new file mode 100644
index 00000000..9a1eae87
--- /dev/null
+++ b/test/name-test/test-privserver-client.c
@@ -0,0 +1,102 @@
+#include "../test-utils.h"
+
+static void
+die (const char *message, ...)
+{
+ va_list args;
+ va_start (args, message);
+ vfprintf (stderr, message, args);
+ va_end (args);
+ exit (1);
+}
+
+static DBusHandlerResult
+filter_private_message (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ if (dbus_message_is_signal (message,
+ DBUS_INTERFACE_LOCAL,
+ "Disconnected"))
+ {
+ DBusLoop *loop = user_data;
+ _dbus_loop_quit (loop);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void
+open_shutdown_private_connection ()
+{
+ DBusError error;
+ DBusLoop *loop;
+ DBusConnection *session;
+ DBusMessage *msg;
+ DBusMessage *reply;
+ DBusConnection *privconn;
+ const char *addr;
+
+ dbus_error_init (&error);
+
+ loop = _dbus_loop_new ();
+
+ session = dbus_bus_get (DBUS_BUS_SESSION, &error);
+ if (!session)
+ die ("couldn't access session bus\n");
+ dbus_connection_set_exit_on_disconnect (session, FALSE);
+ msg = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuite.TestServer",
+ "/",
+ "org.freedesktop.DBus.TestSuite.TestServer",
+ "GetPrivateAddress");
+ if (!(reply = dbus_connection_send_with_reply_and_block (session, msg, -1, &error)))
+ die ("couldn't send message: %s\n", error.message);
+ dbus_message_unref (msg);
+ if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID))
+ die ("couldn't parse message replym\n");
+ printf ("got private temp address %s\n", addr);
+
+ privconn = dbus_connection_open (addr, &error);
+ if (!privconn)
+ die ("couldn't connect to server direct connection: %s\n", error.message);
+ dbus_message_unref (reply);
+
+ dbus_connection_set_exit_on_disconnect (privconn, FALSE);
+ dbus_connection_add_filter (privconn, filter_private_message, loop, NULL);
+ test_connection_setup (loop, privconn);
+
+ msg = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuite.TestServer",
+ "/",
+ "org.freedesktop.DBus.TestSuite.TestServer",
+ "Quit");
+ if (!dbus_connection_send (session, msg, NULL))
+ die ("couldn't send Quit message\n");
+ dbus_message_unref (msg);
+
+ _dbus_loop_run (loop);
+
+ test_connection_shutdown (loop, session);
+ dbus_connection_unref (session);
+
+ test_connection_shutdown (loop, privconn);
+ dbus_connection_remove_filter (privconn, filter_private_message, loop);
+ dbus_connection_unref (privconn);
+
+ _dbus_loop_unref (loop);
+}
+
+int
+main (int argc, char *argv[])
+{
+ open_shutdown_private_connection ();
+
+ dbus_shutdown ();
+
+ /*
+ open_shutdown_private_connection ();
+
+ dbus_shutdown ();
+ */
+
+ return 0;
+}
diff --git a/test/name-test/test-privserver.c b/test/name-test/test-privserver.c
new file mode 100644
index 00000000..8a6efc4e
--- /dev/null
+++ b/test/name-test/test-privserver.c
@@ -0,0 +1,118 @@
+#include "../test-utils.h"
+
+static void
+die (const char *message, ...)
+{
+ va_list args;
+ va_start (args, message);
+ vfprintf (stderr, message, args);
+ va_end (args);
+ exit (1);
+}
+
+typedef struct TestServiceData TestServiceData;
+
+struct TestServiceData
+{
+ DBusLoop *loop;
+ char *private_addr;
+};
+
+static void
+new_connection_callback (DBusServer *server,
+ DBusConnection *new_connection,
+ void *data)
+{
+ TestServiceData *testdata = data;
+
+ if (!test_connection_setup (testdata->loop, new_connection))
+ dbus_connection_close (new_connection);
+}
+
+static DBusHandlerResult
+filter_session_message (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ TestServiceData *testdata = user_data;
+
+ if (dbus_message_is_method_call (message,
+ "org.freedesktop.DBus.TestSuite.TestServer",
+ "GetPrivateAddress"))
+ {
+ DBusMessage *reply;
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_STRING,
+ &(testdata->private_addr), DBUS_TYPE_INVALID);
+ dbus_connection_send (connection, reply, NULL);
+ dbus_message_unref (reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ else if (dbus_message_is_method_call (message,
+ "org.freedesktop.DBus.TestSuite.TestServer",
+ "Quit"))
+ {
+ fprintf (stderr, "server exiting loop\n");
+ _dbus_loop_quit (testdata->loop);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+int
+main (int argc, char *argv[])
+{
+ DBusServer *server;
+ DBusError error;
+ DBusLoop *loop;
+ DBusConnection *session;
+ TestServiceData *testdata;
+
+ dbus_error_init (&error);
+
+ loop = _dbus_loop_new ();
+
+ testdata = dbus_new (TestServiceData, 1);
+ testdata->loop = loop;
+
+ session = dbus_bus_get (DBUS_BUS_SESSION, &error);
+ if (!session)
+ die ("couldn't access session bus");
+
+ test_connection_setup (loop, session);
+
+ dbus_bus_request_name (session, "org.freedesktop.DBus.TestSuite.TestServer", 0, &error);
+ if (dbus_error_is_set (&error))
+ die ("couldn't request name: %s", error.message);
+
+ if (!dbus_connection_add_filter (session, filter_session_message, testdata, NULL))
+ die ("couldn't add filter");
+
+ server = dbus_server_listen ("unix:tmpdir=/tmp", &error);
+ if (!server)
+ die (error.message);
+ testdata->private_addr = dbus_server_get_address (server);
+ printf ("test server listening on %s\n", testdata->private_addr);
+
+ dbus_server_set_new_connection_function (server, new_connection_callback,
+ testdata, NULL);
+
+ if (!test_server_setup (loop, server))
+ die ("server setup failed");
+
+ fprintf (stderr, "server running mainloop\n");
+ _dbus_loop_run (loop);
+ fprintf (stderr, "server mainloop quit\n");
+
+ test_server_shutdown (loop, server);
+
+ test_connection_shutdown (loop, session);
+
+ dbus_connection_unref (session);
+
+ _dbus_loop_unref (loop);
+
+ dbus_free (testdata);
+
+ return 0;
+}