summaryrefslogtreecommitdiffstats
path: root/test/name-test
diff options
context:
space:
mode:
Diffstat (limited to 'test/name-test')
-rw-r--r--test/name-test/Makefile.am26
-rwxr-xr-xtest/name-test/run-test.sh11
-rw-r--r--test/name-test/test-privserver-client.c116
-rw-r--r--test/name-test/test-privserver.c118
-rw-r--r--test/name-test/test-shutdown.c67
5 files changed, 335 insertions, 3 deletions
diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am
index fbc80c42..17e05bec 100644
--- a/test/name-test/Makefile.am
+++ b/test/name-test/Makefile.am
@@ -1,4 +1,4 @@
-INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) -DDBUS_COMPILATION
+INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_CFLAGS) $(DBUS_TEST_CFLAGS) -DDBUS_COMPILATION
## 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
@@ -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
+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
@@ -42,5 +42,25 @@ test_ids_SOURCES = \
test_ids_LDADD=$(top_builddir)/dbus/libdbus-convenience.la $(DBUS_TEST_LIBS)
test_ids_LDFLAGS=@R_DYNAMIC_LDFLAG@
-endif
+test_shutdown_SOURCES = \
+ test-shutdown.c
+
+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 5d9c584a..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"
@@ -36,3 +41,9 @@ ${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..239b7bdf
--- /dev/null
+++ b/test/name-test/test-privserver-client.c
@@ -0,0 +1,116 @@
+#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 (dbus_bool_t use_guid)
+{
+ DBusError error;
+ DBusLoop *loop;
+ DBusConnection *session;
+ DBusMessage *msg;
+ DBusMessage *reply;
+ DBusConnection *privconn;
+ char *addr;
+ char *comma;
+
+ 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);
+ addr = strdup (addr);
+ if (!use_guid)
+ {
+ char *comma = strrchr (addr, ',');
+ if (comma)
+ *comma = '\0';
+ }
+ privconn = dbus_connection_open (addr, &error);
+ free (addr);
+ 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 (TRUE);
+
+ dbus_shutdown ();
+
+ open_shutdown_private_connection (TRUE);
+
+ dbus_shutdown ();
+
+ open_shutdown_private_connection (FALSE);
+
+ dbus_shutdown ();
+
+ open_shutdown_private_connection (FALSE);
+
+ 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;
+}
diff --git a/test/name-test/test-shutdown.c b/test/name-test/test-shutdown.c
new file mode 100644
index 00000000..c50ef4b6
--- /dev/null
+++ b/test/name-test/test-shutdown.c
@@ -0,0 +1,67 @@
+
+#include "../test-utils.h"
+
+static DBusLoop *loop;
+
+static void
+die (const char *message)
+{
+ fprintf (stderr, "*** test-shutdown: %s", message);
+ exit (1);
+}
+
+static void
+open_destroy_shared_session_bus_connection ()
+{
+ DBusError error;
+ DBusConnection *connection;
+ char *session_addr_no_guid;
+ char *comma;
+
+ dbus_error_init (&error);
+
+ session_addr_no_guid = strdup (getenv ("DBUS_SESSION_BUS_ADDRESS"));
+ comma = strchr (session_addr_no_guid, ',');
+ if (comma == NULL)
+ die ("Couldn't find GUID in session bus address");
+ *comma = '\0';
+
+ connection = dbus_connection_open (session_addr_no_guid, &error);
+ free (session_addr_no_guid);
+ if (connection == NULL)
+ die ("Failed to open connection to temp session bus\n");
+
+ loop = _dbus_loop_new ();
+ if (loop == NULL)
+ die ("No memory\n");
+
+ if (!test_connection_setup (loop, connection))
+ die ("No memory\n");
+
+ test_connection_shutdown (loop, connection);
+
+ _dbus_loop_unref (loop);
+
+ dbus_connection_unref (connection);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ open_destroy_shared_session_bus_connection ();
+
+ dbus_shutdown ();
+
+ open_destroy_shared_session_bus_connection ();
+
+ dbus_shutdown ();
+
+ open_destroy_shared_session_bus_connection ();
+
+ dbus_shutdown ();
+
+ _dbus_verbose ("*** Test shutdown exiting\n");
+
+ return 0;
+}