From a929c9a3b465db8b7e17b9b39936c612c2621a7c Mon Sep 17 00:00:00 2001 From: "John (J5) Palmieri" Date: Fri, 14 Jul 2006 16:20:12 +0000 Subject: * Remove all bindings --- test/Makefile.am | 15 +- .../data/valid-service-files/debug-glib.service.in | 3 - .../valid-service-files/debug-python.service.in | 3 - test/glib/Makefile.am | 80 - test/glib/my-object-marshal.list | 2 - test/glib/run-test.sh | 36 - test/glib/test-dbus-glib.c | 1621 -------------------- test/glib/test-profile.c | 1150 -------------- test/glib/test-service-glib.c | 928 ----------- test/glib/test-service-glib.xml | 179 --- test/glib/test-thread-client.c | 98 -- test/glib/test-thread-server.c | 209 --- test/glib/test-thread.h | 1 - test/python/.cvsignore | 3 - test/python/Makefile.am | 11 - test/python/run-test.sh | 42 - test/python/test-client.py | 306 ---- test/python/test-service.py | 141 -- test/qt/.cvsignore | 11 - test/qt/Makefile.am | 38 - test/qt/common.h | 264 ---- test/qt/qpong.cpp | 38 - test/qt/tst_hal.cpp | 80 - test/qt/tst_headertest.cpp | 16 - test/qt/tst_qdbusabstractadaptor.cpp | 989 ------------ test/qt/tst_qdbusconnection.cpp | 257 ---- test/qt/tst_qdbusinterface.cpp | 295 ---- test/qt/tst_qdbusmarshall.cpp | 342 ----- test/qt/tst_qdbusxmlparser.cpp | 578 ------- 29 files changed, 2 insertions(+), 7734 deletions(-) delete mode 100644 test/data/valid-service-files/debug-glib.service.in delete mode 100644 test/data/valid-service-files/debug-python.service.in delete mode 100644 test/glib/Makefile.am delete mode 100644 test/glib/my-object-marshal.list delete mode 100755 test/glib/run-test.sh delete mode 100644 test/glib/test-dbus-glib.c delete mode 100644 test/glib/test-profile.c delete mode 100644 test/glib/test-service-glib.c delete mode 100644 test/glib/test-service-glib.xml delete mode 100644 test/glib/test-thread-client.c delete mode 100644 test/glib/test-thread-server.c delete mode 100644 test/glib/test-thread.h delete mode 100644 test/python/.cvsignore delete mode 100644 test/python/Makefile.am delete mode 100755 test/python/run-test.sh delete mode 100755 test/python/test-client.py delete mode 100755 test/python/test-service.py delete mode 100644 test/qt/.cvsignore delete mode 100644 test/qt/Makefile.am delete mode 100644 test/qt/common.h delete mode 100644 test/qt/qpong.cpp delete mode 100644 test/qt/tst_hal.cpp delete mode 100644 test/qt/tst_headertest.cpp delete mode 100644 test/qt/tst_qdbusabstractadaptor.cpp delete mode 100644 test/qt/tst_qdbusconnection.cpp delete mode 100644 test/qt/tst_qdbusinterface.cpp delete mode 100644 test/qt/tst_qdbusmarshall.cpp delete mode 100644 test/qt/tst_qdbusxmlparser.cpp (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index e419fb8c..b4863c7a 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,16 +1,5 @@ - -if HAVE_GLIB - GLIB_SUBDIR=glib -endif -if HAVE_PYTHON - PYTHON_SUBDIR=python -endif -if HAVE_QTESTLIB - QT_SUBDIR=qt -endif - -SUBDIRS=name-test $(GLIB_SUBDIR) $(PYTHON_SUBDIR) $(QT_SUBDIR) -DIST_SUBDIRS=glib python qt name-test +SUBDIRS=name-test +DIST_SUBDIRS=name-test INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS) diff --git a/test/data/valid-service-files/debug-glib.service.in b/test/data/valid-service-files/debug-glib.service.in deleted file mode 100644 index 199fd808..00000000 --- a/test/data/valid-service-files/debug-glib.service.in +++ /dev/null @@ -1,3 +0,0 @@ -[D-BUS Service] -Name=org.freedesktop.DBus.TestSuiteGLibService -Exec=@TEST_GLIB_SERVICE_BINARY@ diff --git a/test/data/valid-service-files/debug-python.service.in b/test/data/valid-service-files/debug-python.service.in deleted file mode 100644 index 9dca726b..00000000 --- a/test/data/valid-service-files/debug-python.service.in +++ /dev/null @@ -1,3 +0,0 @@ -[D-BUS Service] -Name=org.freedesktop.DBus.TestSuitePythonService -Exec=@TEST_PYTHON_SERVICE_BINARY@ diff --git a/test/glib/Makefile.am b/test/glib/Makefile.am deleted file mode 100644 index aebaf37c..00000000 --- a/test/glib/Makefile.am +++ /dev/null @@ -1,80 +0,0 @@ -INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_GLIB_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 -## TESTS -if DBUS_BUILD_TESTS -TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=$(ABSOLUTE_TOP_BUILDDIR) -TESTS=run-test.sh -else -TESTS= -endif - -EXTRA_DIST=run-test.sh test-service-glib.xml my-object-marshal.list test-service-glib.xml - -if DBUS_BUILD_TESTS - -if HAVE_GLIB_THREADS -THREAD_APPS=test-thread-server test-thread-client test-profile - -test_thread_server_SOURCES= \ - test-thread-server.c \ - test-thread.h - -test_thread_server_LDADD= $(DBUS_GLIB_THREADS_LIBS) $(top_builddir)/glib/libdbus-glib-1.la - -test_thread_client_SOURCES= \ - test-thread-client.c \ - test-thread.h - -test_thread_client_LDADD= $(DBUS_GLIB_THREADS_LIBS) $(top_builddir)/glib/libdbus-glib-1.la -endif - -## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we -## build even when not doing "make check" -noinst_PROGRAMS= test-dbus-glib test-service-glib $(THREAD_APPS) - -test_dbus_glib_SOURCES= \ - my-object-marshal.c \ - test-dbus-glib.c - -test_dbus_glib_LDADD= $(DBUS_GLIB_TOOL_LIBS) $(top_builddir)/glib/libdbus-glib-1.la $(top_builddir)/glib/libdbus-gtool.la - -BUILT_SOURCES = test-service-glib-glue.h test-service-glib-bindings.h my-object-marshal.c my-object-marshal.h - -test_service_glib_SOURCES= \ - my-object-marshal.c \ - test-service-glib.c - -test-service-glib-glue.h: test-service-glib.xml $(top_builddir)/glib/dbus-binding-tool - $(top_builddir)/glib/dbus-binding-tool --prefix=my_object --mode=glib-server --output=test-service-glib-glue.h $(srcdir)/test-service-glib.xml - -test-service-glib-bindings.h: test-service-glib.xml $(top_builddir)/glib/dbus-binding-tool - $(top_builddir)/glib/dbus-binding-tool --prefix=my_object --mode=glib-client --output=test-service-glib-bindings.h $(srcdir)/test-service-glib.xml - -my-object-marshal.c: Makefile my-object-marshal.list - @GLIB_GENMARSHAL@ --prefix=my_object_marshal $(srcdir)/my-object-marshal.list --header --body > my-object-marshal.c - -my-object-marshal.h: Makefile my-object-marshal.list - @GLIB_GENMARSHAL@ --prefix=my_object_marshal $(srcdir)/my-object-marshal.list --header > my-object-marshal.h - - -CLEANFILES = $(BUILT_SOURCES) - -test_service_glib_LDADD= $(top_builddir)/glib/libdbus-glib-1.la $(DBUS_GLIB_THREADS_LIBS) - -else -### not building tests - -if HAVE_GLIB_THREADS -noinst_PROGRAMS=test-profile -endif - -endif - -if HAVE_GLIB_THREADS -test_profile_SOURCES= \ - test-profile.c - -test_profile_LDADD= $(DBUS_GLIB_THREADS_LIBS) $(top_builddir)/glib/libdbus-glib-1.la -endif diff --git a/test/glib/my-object-marshal.list b/test/glib/my-object-marshal.list deleted file mode 100644 index 48cbfad4..00000000 --- a/test/glib/my-object-marshal.list +++ /dev/null @@ -1,2 +0,0 @@ -NONE:STRING,INT,STRING -NONE:STRING,BOXED diff --git a/test/glib/run-test.sh b/test/glib/run-test.sh deleted file mode 100755 index 86f1aee8..00000000 --- a/test/glib/run-test.sh +++ /dev/null @@ -1,36 +0,0 @@ -#! /bin/bash - -SCRIPTNAME=$0 -MODE=$1 - -## so the tests can complain if you fail to use the script to launch them -export DBUS_TEST_GLIB_RUN_TEST_SCRIPT=1 - -# Rerun ourselves with tmp session bus if we're not already -if test -z "$DBUS_TEST_GLIB_IN_RUN_TEST"; then - DBUS_TEST_GLIB_IN_RUN_TEST=1 - export DBUS_TEST_GLIB_IN_RUN_TEST - exec $DBUS_TOP_BUILDDIR/tools/run-with-tmp-session-bus.sh $SCRIPTNAME $MODE -fi - -if test x$MODE = xprofile ; then - echo "profiling type $PROFILE_TYPE" - sleep 2 ## this lets the bus get started so its startup time doesn't affect the profile too much - if test x$PROFILE_TYPE = x ; then - PROFILE_TYPE=all - fi - libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/glib/test-profile $PROFILE_TYPE || die "test-profile failed" -elif test x$MODE = xviewer ; then - echo "Launching dbus-viewer" - ARGS= - if test x$DEBUG = x ; then - ARGS="--services org.freedesktop.DBus org.freedesktop.DBus.TestSuiteGLibService" - fi - libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/tools/dbus-viewer $ARGS || die "could not run dbus-viewer" -elif test x$MODE = xwait ; then - echo "Waiting DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" - sleep 86400 -else - echo "running test-dbus-glib" - libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/glib/test-dbus-glib || die "test-dbus-glib failed" -fi diff --git a/test/glib/test-dbus-glib.c b/test/glib/test-dbus-glib.c deleted file mode 100644 index ebcfaeaa..00000000 --- a/test/glib/test-dbus-glib.c +++ /dev/null @@ -1,1621 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -#include -#include -#include -#include -#include "test-service-glib-bindings.h" -#include -#include -#include -#include -#include "my-object-marshal.h" - -static GMainLoop *loop = NULL; -static const char *await_terminating_service = NULL; -static int n_times_foo_received = 0; -static int n_times_frobnicate_received = 0; -static int n_times_frobnicate_received_2 = 0; -static int n_times_sig0_received = 0; -static int n_times_sig1_received = 0; -static int n_times_sig2_received = 0; -static guint exit_timeout = 0; -static gboolean proxy_destroyed = FALSE; -static gboolean proxy_destroy_and_nameowner = FALSE; -static gboolean proxy_destroy_and_nameowner_complete = FALSE; - -static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2); -static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN; - -static void -unset_and_free_gvalue (gpointer val) -{ - g_value_unset (val); - g_free (val); -} - -static gboolean -timed_exit (gpointer loop) -{ - g_print ("timed exit!\n"); - g_main_loop_quit (loop); - return TRUE; -} - -static void -proxy_destroyed_cb (DBusGProxy *proxy, gpointer user_data) -{ - proxy_destroyed = TRUE; - if (proxy_destroy_and_nameowner && !proxy_destroy_and_nameowner_complete && await_terminating_service == NULL) - { - g_source_remove (exit_timeout); - g_main_loop_quit (loop); - proxy_destroy_and_nameowner_complete = TRUE; - } -} - -static void -name_owner_changed (DBusGProxy *proxy, - const char *name, - const char *prev_owner, - const char *new_owner, - gpointer user_data) -{ - g_print ("(signal NameOwnerChanged) name owner changed for %s from %s to %s\n", - name, prev_owner, new_owner); - if (await_terminating_service && - !strcmp (name, await_terminating_service) - && !strcmp ("", new_owner)) - { - g_print ("Caught expected ownership loss for %s\n", name); - await_terminating_service = NULL; - if (proxy_destroy_and_nameowner && !proxy_destroy_and_nameowner_complete && proxy_destroyed) - { - g_source_remove (exit_timeout); - g_main_loop_quit (loop); - proxy_destroy_and_nameowner_complete = TRUE; - } - else if (!proxy_destroy_and_nameowner) - { - g_source_remove (exit_timeout); - g_main_loop_quit (loop); - } - } -} - -static void -foo_signal_handler (DBusGProxy *proxy, - double d, - void *user_data) -{ - n_times_foo_received += 1; - - g_print ("Got Foo signal\n"); - - g_main_loop_quit (loop); - g_source_remove (exit_timeout); -} - -static void -frobnicate_signal_handler (DBusGProxy *proxy, - int val, - void *user_data) -{ - n_times_frobnicate_received += 1; - - g_assert (val == 42); - g_print ("Got Frobnicate signal\n"); - - g_main_loop_quit (loop); - g_source_remove (exit_timeout); -} - -static void -frobnicate_signal_handler_2 (DBusGProxy *proxy, - int val, - void *user_data) -{ - n_times_frobnicate_received_2 += 1; - - g_assert (val == 42); - g_print ("Got Frobnicate signal (again)\n"); -} - -static void -sig0_signal_handler (DBusGProxy *proxy, - const char *str0, - int val, - const char *str1, - void *user_data) -{ - n_times_sig0_received += 1; - - g_assert (!strcmp (str0, "foo")); - - g_assert (val == 22); - - g_assert (!strcmp (str1, "moo")); - - g_print ("Got Sig0 signal\n"); - - g_main_loop_quit (loop); - g_source_remove (exit_timeout); -} - -static void -sig1_signal_handler (DBusGProxy *proxy, - const char *str0, - GValue *value, - void *user_data) -{ - n_times_sig1_received += 1; - - g_assert (!strcmp (str0, "baz")); - - g_assert (G_VALUE_HOLDS_STRING (value)); - - g_assert (!strcmp (g_value_get_string (value), "bar")); - - g_print ("Got Sig1 signal\n"); - - g_main_loop_quit (loop); - g_source_remove (exit_timeout); -} - -static void -sig2_signal_handler (DBusGProxy *proxy, - GHashTable *table, - void *user_data) -{ - n_times_sig2_received += 1; - - g_assert (g_hash_table_size (table) == 2); - - g_assert (g_hash_table_lookup (table, "baz") != NULL); - g_assert (!strcmp (g_hash_table_lookup (table, "baz"), "cow")); - g_assert (g_hash_table_lookup (table, "bar") != NULL); - g_assert (!strcmp (g_hash_table_lookup (table, "bar"), "foo")); - - g_print ("Got Sig2 signal\n"); - - g_main_loop_quit (loop); - g_source_remove (exit_timeout); -} - -static DBusGProxyCall *echo_call; -static guint n_times_echo_cb_entered; -static void -echo_received_cb (DBusGProxy *proxy, - DBusGProxyCall *call, - gpointer data) -{ - GError *error; - char *echo_data; - - g_assert (call == echo_call); - g_assert (data == NULL); - - error = NULL; - echo_data = NULL; - n_times_echo_cb_entered++; - - if (!dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_STRING, - &echo_data, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete async Echo", error); - g_assert (echo_data != NULL); - g_print ("Async echo gave \"%s\"\n", echo_data); - g_free (echo_data); - g_main_loop_quit (loop); - g_source_remove (exit_timeout); -} - -static void -increment_received_cb (DBusGProxy *proxy, - DBusGProxyCall *call, - gpointer data) -{ - GError *error; - guint val; - - g_assert (!strcmp (data, "moo")); - - error = NULL; - if (!dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_UINT, &val, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete (async) Increment call", error); - - if (val != 43) - lose ("Increment call returned %d, should be 43", val); - - g_print ("Async increment gave \"%d\"\n", val); - g_main_loop_quit (loop); - g_source_remove (exit_timeout); -} - -static void -increment_async_cb (DBusGProxy *proxy, guint val, GError *error, gpointer data) -{ - if (error) - lose_gerror ("Failed to complete (wrapped async) Increment call", error); - - if (data != NULL) - lose ("(wrapped async) Increment call gave unexpected data"); - if (val != 43) - lose ("(wrapped async) Increment call returned %d, should be 43", val); - - g_print ("(wrapped async) increment gave \"%d\"\n", val); - g_main_loop_quit (loop); - g_source_remove (exit_timeout); -} - - -static void -lose (const char *str, ...) -{ - va_list args; - - va_start (args, str); - - vfprintf (stderr, str, args); - fputc ('\n', stderr); - - va_end (args); - - exit (1); -} - -static void -lose_gerror (const char *prefix, GError *error) -{ - if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) - lose ("%s (%s): %s", prefix, dbus_g_error_get_name (error), - error->message); - else - lose ("%s: %s", prefix, error->message); -} - -static void -run_mainloop (void) -{ - GMainContext *ctx; - - ctx = g_main_loop_get_context (loop); - - while (g_main_context_pending (ctx)) - g_main_context_iteration (ctx, FALSE); -} - -int -main (int argc, char **argv) -{ - DBusGConnection *connection; - GError *error; - DBusGProxy *driver; - DBusGProxy *proxy; - DBusGProxy *proxy2; - char **name_list; - guint name_list_len; - guint i; - DBusGProxyCall *call; - guint32 result; - char *v_STRING_2; - guint32 v_UINT32_2; - double v_DOUBLE_2; - - g_type_init (); - - g_log_set_always_fatal (G_LOG_LEVEL_WARNING); - - loop = g_main_loop_new (NULL, FALSE); - - error = NULL; - connection = dbus_g_bus_get (DBUS_BUS_SESSION, - &error); - if (connection == NULL) - lose_gerror ("Failed to open connection to bus", error); - - /* should always get the same one */ - g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL)); - g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL)); - g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL)); - - /* Create a proxy object for the "bus driver" */ - - driver = dbus_g_proxy_new_for_name (connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); - - dbus_g_proxy_add_signal (driver, - "NameOwnerChanged", - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_INVALID); - - dbus_g_proxy_connect_signal (driver, - "NameOwnerChanged", - G_CALLBACK (name_owner_changed), - NULL, - NULL); - /* Call ListNames method */ - - error = NULL; - if (!dbus_g_proxy_call (driver, "ListNames", &error, - G_TYPE_INVALID, - G_TYPE_STRV, &name_list, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete ListNames call", error); - - g_print ("Names on the message bus:\n"); - i = 0; - name_list_len = g_strv_length (name_list); - while (i < name_list_len) - { - g_assert (name_list[i] != NULL); - g_print (" %s\n", name_list[i]); - ++i; - } - g_assert (name_list[i] == NULL); - - g_strfreev (name_list); - - g_print ("calling ThisMethodDoesNotExist\n"); - /* Test handling of unknown method */ - if (dbus_g_proxy_call (driver, "ThisMethodDoesNotExist", &error, - G_TYPE_STRING, - "blah blah blah blah blah", - G_TYPE_INT, - 10, - G_TYPE_INVALID, G_TYPE_INVALID) != FALSE) - lose ("Calling nonexistent method succeeded!"); - - g_print ("Got EXPECTED error from calling unknown method: %s\n", error->message); - g_clear_error (&error); - - run_mainloop (); - - /* Activate a service */ - g_print ("Activating echo service\n"); - if (!dbus_g_proxy_call (driver, "StartServiceByName", &error, - G_TYPE_STRING, - "org.freedesktop.DBus.TestSuiteEchoService", - G_TYPE_UINT, 0, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Activate call", error); - - g_print ("Starting echo service result = 0x%x\n", result); - - /* Activate a service again */ - g_print ("Activating echo service again\n"); - if (!dbus_g_proxy_call (driver, "StartServiceByName", &error, - G_TYPE_STRING, - "org.freedesktop.DBus.TestSuiteEchoService", - G_TYPE_UINT, - 0, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Activate call", error); - - g_print ("Duplicate start of echo service = 0x%x\n", result); - - /* Talk to the new service */ - - g_print ("Creating proxy for echo service\n"); - proxy = dbus_g_proxy_new_for_name_owner (connection, - "org.freedesktop.DBus.TestSuiteEchoService", - "/org/freedesktop/TestSuite", - "org.freedesktop.TestSuite", - &error); - - if (proxy == NULL) - lose_gerror ("Failed to create proxy for name owner", error); - - run_mainloop (); - - g_print ("Calling Echo\n"); - if (!dbus_g_proxy_call (proxy, "Echo", &error, - G_TYPE_STRING, "my string hello", - G_TYPE_INVALID, - G_TYPE_STRING, &v_STRING_2, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Echo call", error); - - g_print ("String echoed = \"%s\"\n", v_STRING_2); - g_free (v_STRING_2); - - g_print ("Calling Echo (async)\n"); - echo_call = dbus_g_proxy_begin_call (proxy, "Echo", - echo_received_cb, NULL, NULL, - G_TYPE_STRING, "my string hello", - G_TYPE_INVALID); - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - /* Test oneway call and signal handling */ - - g_print ("Testing Foo emission\n"); - dbus_g_proxy_add_signal (proxy, "Foo", G_TYPE_DOUBLE, G_TYPE_INVALID); - - dbus_g_proxy_connect_signal (proxy, "Foo", - G_CALLBACK (foo_signal_handler), - NULL, NULL); - - dbus_g_proxy_call_no_reply (proxy, "EmitFoo", - G_TYPE_INVALID); - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_foo_received != 1) - lose ("Foo signal received %d times, should have been 1", n_times_foo_received); - - /* Activate test servie */ - g_print ("Activating TestSuiteGLibService\n"); - error = NULL; - if (!dbus_g_proxy_call (driver, "StartServiceByName", &error, - G_TYPE_STRING, - "org.freedesktop.DBus.TestSuiteGLibService", - G_TYPE_UINT, - 0, - G_TYPE_INVALID, - G_TYPE_UINT, &result, - G_TYPE_INVALID)) { - lose_gerror ("Failed to complete Activate call", error); - } - - g_print ("TestSuiteGLibService activated\n"); - - if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION")) - g_usleep (8 * G_USEC_PER_SEC); - - g_object_unref (G_OBJECT (proxy)); - - run_mainloop (); - - proxy = dbus_g_proxy_new_for_name_owner (connection, - "org.freedesktop.DBus.TestSuiteGLibService", - "/org/freedesktop/DBus/Tests/MyTestObject", - "org.freedesktop.DBus.Tests.MyObject", - &error); - - if (proxy == NULL) - lose_gerror ("Failed to create proxy for name owner", error); - - g_print ("Calling DoNothing\n"); - if (!dbus_g_proxy_call (proxy, "DoNothing", &error, - G_TYPE_INVALID, G_TYPE_INVALID)) - lose_gerror ("Failed to complete DoNothing call", error); - - g_print ("Calling Increment\n"); - error = NULL; - if (!dbus_g_proxy_call (proxy, "Increment", &error, - G_TYPE_UINT, 42, - G_TYPE_INVALID, - G_TYPE_UINT, &v_UINT32_2, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Increment call", error); - if (v_UINT32_2 != 43) - lose ("Increment call returned %d, should be 43", v_UINT32_2); - - v_UINT32_2 = 0; - g_print ("Calling Increment (async)\n"); - call = dbus_g_proxy_begin_call (proxy, "Increment", - increment_received_cb, g_strdup ("moo"), g_free, - G_TYPE_UINT, 42, - G_TYPE_INVALID); - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - g_print ("Calling IncrementRetval\n"); - error = NULL; - v_UINT32_2 = 0; - if (!dbus_g_proxy_call (proxy, "IncrementRetval", &error, - G_TYPE_UINT, 42, - G_TYPE_INVALID, - G_TYPE_UINT, &v_UINT32_2, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Increment call", error); - if (v_UINT32_2 != 43) - lose ("IncrementRetval call returned %d, should be 43", v_UINT32_2); - - g_print ("Calling IncrementRetvalError\n"); - error = NULL; - v_UINT32_2 = 0; - if (!dbus_g_proxy_call (proxy, "IncrementRetvalError", &error, - G_TYPE_UINT, 5, - G_TYPE_INVALID, - G_TYPE_UINT, &v_UINT32_2, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Increment call", error); - if (v_UINT32_2 != 6) - lose ("IncrementRetval call returned %d, should be 6", v_UINT32_2); - - g_print ("Calling ThrowError\n"); - if (dbus_g_proxy_call (proxy, "ThrowError", &error, - G_TYPE_INVALID, G_TYPE_INVALID) != FALSE) - lose ("ThrowError call unexpectedly succeeded!"); - - if (!dbus_g_error_has_name (error, "org.freedesktop.DBus.Tests.MyObject.Foo")) - lose ("ThrowError call returned unexpected error \"%s\": %s", dbus_g_error_get_name (error), - error->message); - - g_print ("ThrowError failed (as expected) returned error: %s\n", error->message); - g_clear_error (&error); - - g_print ("Calling IncrementRetvalError (for error)\n"); - error = NULL; - v_UINT32_2 = 0; - if (dbus_g_proxy_call (proxy, "IncrementRetvalError", &error, - G_TYPE_UINT, 20, - G_TYPE_INVALID, - G_TYPE_UINT, &v_UINT32_2, - G_TYPE_INVALID) != FALSE) - lose ("IncrementRetvalError call unexpectedly succeeded!"); - if (!dbus_g_error_has_name (error, "org.freedesktop.DBus.Tests.MyObject.Foo")) - lose ("IncrementRetvalError call returned unexpected error \"%s\": %s", dbus_g_error_get_name (error), error->message); - g_clear_error (&error); - - error = NULL; - g_print ("Calling Uppercase\n"); - if (!dbus_g_proxy_call (proxy, "Uppercase", &error, - G_TYPE_STRING, "foobar", - G_TYPE_INVALID, - G_TYPE_STRING, &v_STRING_2, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Uppercase call", error); - if (strcmp ("FOOBAR", v_STRING_2) != 0) - lose ("Uppercase call returned unexpected string %s", v_STRING_2); - g_free (v_STRING_2); - - run_mainloop (); - - g_print ("Calling ManyArgs\n"); - if (!dbus_g_proxy_call (proxy, "ManyArgs", &error, - G_TYPE_UINT, 26, - G_TYPE_STRING, "bazwhee", - G_TYPE_DOUBLE, G_PI, - G_TYPE_INVALID, - G_TYPE_DOUBLE, &v_DOUBLE_2, - G_TYPE_STRING, &v_STRING_2, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete ManyArgs call", error); - if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56) - lose ("ManyArgs call returned unexpected double value %f", v_DOUBLE_2); - if (strcmp ("BAZWHEE", v_STRING_2) != 0) - lose ("ManyArgs call returned unexpected string %s", v_STRING_2); - g_free (v_STRING_2); - - g_print ("Calling (wrapped) do_nothing\n"); - if (!org_freedesktop_DBus_Tests_MyObject_do_nothing (proxy, &error)) - lose_gerror ("Failed to complete (wrapped) DoNothing call", error); - - g_print ("Calling (wrapped) increment\n"); - if (!org_freedesktop_DBus_Tests_MyObject_increment (proxy, 42, &v_UINT32_2, &error)) - lose_gerror ("Failed to complete (wrapped) Increment call", error); - - if (v_UINT32_2 != 43) - lose ("(wrapped) increment call returned %d, should be 43", v_UINT32_2); - - g_print ("Calling (wrapped async) increment\n"); - if (!org_freedesktop_DBus_Tests_MyObject_increment_async (proxy, 42, increment_async_cb, NULL)) - lose_gerror ("Failed to complete (wrapped) Increment call", error); - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - v_UINT32_2 = 0; - if (!org_freedesktop_DBus_Tests_MyObject_async_increment (proxy, 42, &v_UINT32_2, &error)) - lose_gerror ("Failed to complete (wrapped) AsyncIncrement call", error); - - if (v_UINT32_2 != 43) - lose ("(wrapped) async increment call returned %d, should be 43", v_UINT32_2); - - g_print ("Calling (wrapped) throw_error\n"); - if (org_freedesktop_DBus_Tests_MyObject_throw_error (proxy, &error) != FALSE) - lose ("(wrapped) ThrowError call unexpectedly succeeded!"); - - g_print ("(wrapped) ThrowError failed (as expected) returned error: %s\n", error->message); - g_clear_error (&error); - - if (org_freedesktop_DBus_Tests_MyObject_async_throw_error (proxy, &error) != FALSE) - lose ("(wrapped) AsyncThrowError call unexpectedly succeeded!"); - - g_print ("(wrapped) AsyncThrowError failed (as expected) returned error: %s\n", error->message); - g_clear_error (&error); - - g_print ("Calling (wrapped) uppercase\n"); - if (!org_freedesktop_DBus_Tests_MyObject_uppercase (proxy, "foobar", &v_STRING_2, &error)) - lose_gerror ("Failed to complete (wrapped) Uppercase call", error); - if (strcmp ("FOOBAR", v_STRING_2) != 0) - lose ("(wrapped) Uppercase call returned unexpected string %s", v_STRING_2); - g_free (v_STRING_2); - - g_print ("Calling (wrapped) many_args\n"); - if (!org_freedesktop_DBus_Tests_MyObject_many_args (proxy, 26, "bazwhee", G_PI, - &v_DOUBLE_2, &v_STRING_2, &error)) - lose_gerror ("Failed to complete (wrapped) ManyArgs call", error); - - if (v_DOUBLE_2 < 55 || v_DOUBLE_2 > 56) - - lose ("(wrapped) ManyArgs call returned unexpected double value %f", v_DOUBLE_2); - - if (strcmp ("BAZWHEE", v_STRING_2) != 0) - lose ("(wrapped) ManyArgs call returned unexpected string %s", v_STRING_2); - g_free (v_STRING_2); - - { - guint32 arg0; - char *arg1; - gint32 arg2; - guint32 arg3; - guint32 arg4; - char *arg5; - - g_print ("Calling (wrapped) many_return\n"); - if (!org_freedesktop_DBus_Tests_MyObject_many_return (proxy, &arg0, &arg1, &arg2, &arg3, &arg4, &arg5, &error)) - lose_gerror ("Failed to complete (wrapped) ManyReturn call", error); - - if (arg0 != 42) - lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg0); - - if (strcmp ("42", arg1) != 0) - lose ("(wrapped) ManyReturn call returned unexpected string %s", arg1); - g_free (arg1); - - if (arg2 != -67) - lose ("(wrapped) ManyReturn call returned unexpected gint32 value %u", arg2); - - if (arg3 != 2) - lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg3); - - if (arg4 != 26) - lose ("(wrapped) ManyReturn call returned unexpected guint32 value %u", arg4); - - if (strcmp ("hello world", arg5)) - lose ("(wrapped) ManyReturn call returned unexpected string %s", arg5); - g_free (arg5); - } - - run_mainloop (); - - { - GValue value = {0, }; - - g_value_init (&value, G_TYPE_STRING); - g_value_set_string (&value, "foo"); - - g_print ("Calling (wrapped) stringify, with string\n"); - if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy, - &value, - &v_STRING_2, - &error)) - lose_gerror ("Failed to complete (wrapped) stringify call", error); - if (strcmp ("foo", v_STRING_2) != 0) - lose ("(wrapped) stringify call returned unexpected string %s", v_STRING_2); - g_free (v_STRING_2); - - g_value_unset (&value); - g_value_init (&value, G_TYPE_INT); - g_value_set_int (&value, 42); - - g_print ("Calling (wrapped) stringify, with int\n"); - if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy, - &value, - &v_STRING_2, - &error)) - lose_gerror ("Failed to complete (wrapped) stringify call 2", error); - if (strcmp ("42", v_STRING_2) != 0) - lose ("(wrapped) stringify call 2 returned unexpected string %s", v_STRING_2); - g_value_unset (&value); - g_free (v_STRING_2); - - g_value_init (&value, G_TYPE_INT); - g_value_set_int (&value, 88); - g_print ("Calling (wrapped) stringify, with another int\n"); - if (!org_freedesktop_DBus_Tests_MyObject_stringify (proxy, - &value, - NULL, - &error)) - lose_gerror ("Failed to complete (wrapped) stringify call 3", error); - g_value_unset (&value); - - g_print ("Calling (wrapped) unstringify, for string\n"); - if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy, - "foo", - &value, - &error)) - lose_gerror ("Failed to complete (wrapped) unstringify call", error); - if (!G_VALUE_HOLDS_STRING (&value)) - lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value)); - if (strcmp (g_value_get_string (&value), "foo")) - lose ("(wrapped) unstringify call returned unexpected string %s", - g_value_get_string (&value)); - - g_value_unset (&value); - - g_print ("Calling (wrapped) unstringify, for int\n"); - if (!org_freedesktop_DBus_Tests_MyObject_unstringify (proxy, - "10", - &value, - &error)) - lose_gerror ("Failed to complete (wrapped) unstringify call", error); - if (!G_VALUE_HOLDS_INT (&value)) - lose ("(wrapped) unstringify call returned unexpected value type %d", (int) G_VALUE_TYPE (&value)); - if (g_value_get_int (&value) != 10) - lose ("(wrapped) unstringify call returned unexpected integer %d", - g_value_get_int (&value)); - - g_value_unset (&value); - } - - run_mainloop (); - - { - GArray *array; - guint32 arraylen; - - array = g_array_new (FALSE, TRUE, sizeof (guint32)); - - arraylen = 0; - g_print ("Calling (wrapped) zero-length recursive1\n"); - if (!org_freedesktop_DBus_Tests_MyObject_recursive1 (proxy, array, - &arraylen, &error)) - lose_gerror ("Failed to complete (wrapped) zero-length recursive1 call", error); - if (arraylen != 0) - lose ("(wrapped) zero-length recursive1 call returned invalid length %u", arraylen); - } - - { - GArray *array; - guint32 val; - guint32 arraylen; - - array = g_array_new (FALSE, TRUE, sizeof (guint32)); - val = 42; - g_array_append_val (array, val); - val = 69; - g_array_append_val (array, val); - val = 88; - g_array_append_val (array, val); - val = 26; - g_array_append_val (array, val); - val = 2; - g_array_append_val (array, val); - - arraylen = 0; - g_print ("Calling (wrapped) recursive1\n"); - if (!org_freedesktop_DBus_Tests_MyObject_recursive1 (proxy, array, - &arraylen, &error)) - lose_gerror ("Failed to complete (wrapped) recursive1 call", error); - if (arraylen != 5) - lose ("(wrapped) recursive1 call returned invalid length %u", arraylen); - } - - { - GArray *array = NULL; - guint32 *arrayvals; - - g_print ("Calling (wrapped) recursive2\n"); - if (!org_freedesktop_DBus_Tests_MyObject_recursive2 (proxy, 2, &array, &error)) - lose_gerror ("Failed to complete (wrapped) Recursive2 call", error); - - if (array == NULL) - lose ("(wrapped) Recursive2 call returned NULL"); - if (array->len != 5) - lose ("(wrapped) Recursive2 call returned unexpected array length %u", array->len); - - arrayvals = (guint32*) array->data; - if (arrayvals[0] != 42) - lose ("(wrapped) Recursive2 call returned unexpected value %d in position 0", arrayvals[0]); - if (arrayvals[1] != 26) - lose ("(wrapped) Recursive2 call returned unexpected value %d in position 1", arrayvals[1]); - if (arrayvals[4] != 2) - lose ("(wrapped) Recursive2 call returned unexpected value %d in position 4", arrayvals[4]); - - g_array_free (array, TRUE); - } - - run_mainloop (); - - { - char **strs; - char **strs_ret; - - strs = g_new0 (char *, 4); - strs[0] = "hello"; - strs[1] = "HellO"; - strs[2] = "HELLO"; - strs[3] = NULL; - - strs_ret = NULL; - g_print ("Calling (wrapped) many_uppercase\n"); - if (!org_freedesktop_DBus_Tests_MyObject_many_uppercase (proxy, strs, &strs_ret, &error)) - lose_gerror ("Failed to complete (wrapped) ManyUppercase call", error); - g_assert (strs_ret != NULL); - if (strcmp ("HELLO", strs_ret[0]) != 0) - lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[0]); - if (strcmp ("HELLO", strs_ret[1]) != 0) - lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[1]); - if (strcmp ("HELLO", strs_ret[2]) != 0) - lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[2]); - - g_free (strs); - g_strfreev (strs_ret); - } - - { - GHashTable *table; - guint len; - - table = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_insert (table, "moooo", "b"); - g_hash_table_insert (table, "xxx", "cow!"); - - len = 0; - g_print ("Calling (wrapped) str_hash_len\n"); - if (!org_freedesktop_DBus_Tests_MyObject_str_hash_len (proxy, table, &len, &error)) - lose_gerror ("(wrapped) StrHashLen call failed", error); - if (len != 13) - lose ("(wrapped) StrHashLen returned unexpected length %u", len); - g_hash_table_destroy (table); - } - - { - GHashTable *table; - const char *val; - - g_print ("Calling (wrapped) get_hash\n"); - if (!org_freedesktop_DBus_Tests_MyObject_get_hash (proxy, &table, &error)) - lose_gerror ("(wrapped) GetHash call failed", error); - val = g_hash_table_lookup (table, "foo"); - if (val == NULL || strcmp ("bar", val)) - lose ("(wrapped) StrHashLen returned invalid value %s for key \"foo\"", - val ? val : "(null)"); - val = g_hash_table_lookup (table, "baz"); - if (val == NULL || strcmp ("whee", val)) - lose ("(wrapped) StrHashLen returned invalid value %s for key \"whee\"", - val ? val : "(null)"); - val = g_hash_table_lookup (table, "cow"); - if (val == NULL || strcmp ("crack", val)) - lose ("(wrapped) StrHashLen returned invalid value %s for key \"cow\"", - val ? val : "(null)"); - if (g_hash_table_size (table) != 3) - lose ("(wrapped) StrHashLen returned unexpected hash size %u", - g_hash_table_size (table)); - - g_hash_table_destroy (table); - } - - run_mainloop (); - - { - GValueArray *vals; - GValueArray *vals_ret; - GValue *val; - - vals = g_value_array_new (3); - - g_value_array_append (vals, NULL); - g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_STRING); - g_value_set_string (g_value_array_get_nth (vals, 0), "foo"); - - g_value_array_append (vals, NULL); - g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_UINT); - g_value_set_uint (g_value_array_get_nth (vals, vals->n_values - 1), 42); - - g_value_array_append (vals, NULL); - g_value_init (g_value_array_get_nth (vals, vals->n_values - 1), G_TYPE_VALUE); - val = g_new0 (GValue, 1); - g_value_init (val, G_TYPE_UCHAR); - g_value_set_uchar (val, '!'); - g_value_set_boxed (g_value_array_get_nth (vals, vals->n_values - 1), val); - - vals_ret = NULL; - g_print ("Calling SendCar\n"); - if (!dbus_g_proxy_call (proxy, "SendCar", &error, - G_TYPE_VALUE_ARRAY, vals, - G_TYPE_INVALID, - G_TYPE_VALUE_ARRAY, &vals_ret, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete SendCar call", error); - - g_assert (vals_ret != NULL); - g_assert (vals_ret->n_values == 2); - - g_assert (G_VALUE_HOLDS_UINT (g_value_array_get_nth (vals_ret, 0))); - g_assert (g_value_get_uint (g_value_array_get_nth (vals_ret, 0)) == 43); - - g_assert (G_VALUE_TYPE (g_value_array_get_nth (vals_ret, 1)) == DBUS_TYPE_G_OBJECT_PATH); - g_assert (!strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2", - g_value_get_boxed (g_value_array_get_nth (vals_ret, 1)))); - - g_value_array_free (vals); - g_value_array_free (vals_ret); - } - - { - GValue *val; - GHashTable *table; - GHashTable *ret_table; - - table = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, unset_and_free_gvalue); - - val = g_new0 (GValue, 1); - g_value_init (val, G_TYPE_UINT); - g_value_set_uint (val, 42); - g_hash_table_insert (table, g_strdup ("foo"), val); - - val = g_new0 (GValue, 1); - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, "hello"); - g_hash_table_insert (table, g_strdup ("bar"), val); - - ret_table = NULL; - g_print ("Calling ManyStringify\n"); - if (!dbus_g_proxy_call (proxy, "ManyStringify", &error, - dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), table, - G_TYPE_INVALID, - dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &ret_table, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete ManyStringify call", error); - - g_assert (ret_table != NULL); - g_assert (g_hash_table_size (ret_table) == 2); - - val = g_hash_table_lookup (ret_table, "foo"); - g_assert (val != NULL); - g_assert (G_VALUE_HOLDS_STRING (val)); - g_assert (!strcmp ("42", g_value_get_string (val))); - - val = g_hash_table_lookup (ret_table, "bar"); - g_assert (val != NULL); - g_assert (G_VALUE_HOLDS_STRING (val)); - g_assert (!strcmp ("hello", g_value_get_string (val))); - - g_hash_table_destroy (table); - g_hash_table_destroy (ret_table); - } - - { - GPtrArray *in_array; - GPtrArray *out_array; - char **strs; - GArray *uints; - - in_array = g_ptr_array_new (); - - strs = g_new0 (char *, 3); - strs[0] = "foo"; - strs[1] = "bar"; - strs[2] = NULL; - g_ptr_array_add (in_array, strs); - - strs = g_new0 (char *, 4); - strs[0] = "baz"; - strs[1] = "whee"; - strs[2] = "moo"; - strs[3] = NULL; - g_ptr_array_add (in_array, strs); - - out_array = NULL; - g_print ("Calling RecArrays\n"); - if (!dbus_g_proxy_call (proxy, "RecArrays", &error, - dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRV), in_array, - G_TYPE_INVALID, - dbus_g_type_get_collection ("GPtrArray", - dbus_g_type_get_collection ("GPtrArray", - G_TYPE_UINT)), &out_array, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete RecArrays call", error); - g_free (g_ptr_array_index (in_array, 0)); - g_free (g_ptr_array_index (in_array, 1)); - - g_assert (out_array); - g_assert (out_array->len == 2); - uints = g_ptr_array_index (out_array, 0); - g_assert (uints); - g_assert (uints->len == 3); - g_assert (g_array_index (uints, guint, 0) == 10); - g_assert (g_array_index (uints, guint, 1) == 42); - g_assert (g_array_index (uints, guint, 2) == 27); - g_array_free (uints, TRUE); - uints = g_ptr_array_index (out_array, 1); - g_assert (uints); - g_assert (uints->len == 1); - g_assert (g_array_index (uints, guint, 0) == 30); - g_array_free (uints, TRUE); - g_ptr_array_free (out_array, TRUE); - } - - { - guint val; - char *ret_path; - DBusGProxy *ret_proxy; - - g_print ("Calling (wrapped) objpath\n"); - if (!dbus_g_proxy_call (proxy, "Objpath", &error, - DBUS_TYPE_G_PROXY, proxy, G_TYPE_INVALID, - DBUS_TYPE_G_PROXY, &ret_proxy, G_TYPE_INVALID)) - lose_gerror ("Failed to complete Objpath call", error); - if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2", - dbus_g_proxy_get_path (ret_proxy)) != 0) - lose ("(wrapped) objpath call returned unexpected proxy %s", - dbus_g_proxy_get_path (ret_proxy)); - - g_print ("Doing get/increment val tests\n"); - val = 1; - if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error)) - lose_gerror ("Failed to complete (wrapped) GetVal call", error); - if (val != 0) - lose ("(wrapped) GetVal returned invalid value %d", val); - - if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error)) - lose_gerror ("Failed to complete (wrapped) IncrementVal call", error); - - if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error)) - lose_gerror ("Failed to complete (wrapped) IncrementVal call", error); - - if (!org_freedesktop_DBus_Tests_MyObject_increment_val (ret_proxy, &error)) - lose_gerror ("Failed to complete (wrapped) IncrementVal call", error); - - if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error)) - lose_gerror ("Failed to complete (wrapped) GetVal call", error); - if (val != 3) - lose ("(wrapped) GetVal returned invalid value %d", val); - - if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error)) - lose_gerror ("Failed to complete (wrapped) GetVal call", error); - if (val != 0) - lose ("(wrapped) GetVal returned invalid value %d", val); - - if (!org_freedesktop_DBus_Tests_MyObject_increment_val (proxy, &error)) - lose_gerror ("Failed to complete (wrapped) IncrementVal call", error); - - if (!org_freedesktop_DBus_Tests_MyObject_get_val (proxy, &val, &error)) - lose_gerror ("Failed to complete (wrapped) GetVal call", error); - if (val != 1) - lose ("(wrapped) GetVal returned invalid value %d", val); - - if (!org_freedesktop_DBus_Tests_MyObject_get_val (ret_proxy, &val, &error)) - lose_gerror ("Failed to complete (wrapped) GetVal call", error); - if (val != 3) - lose ("(wrapped) GetVal returned invalid value %d", val); - - g_object_unref (G_OBJECT (ret_proxy)); - - g_print ("Calling objpath again\n"); - ret_proxy = NULL; - - if (!dbus_g_proxy_call (proxy, "Objpath", &error, - DBUS_TYPE_G_OBJECT_PATH, - dbus_g_proxy_get_path (proxy), - G_TYPE_INVALID, - DBUS_TYPE_G_OBJECT_PATH, - &ret_path, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Objpath call 2", error); - if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2", ret_path) != 0) - lose ("Objpath call 2 returned unexpected path %s", - ret_path); - - ret_proxy = dbus_g_proxy_new_for_name_owner (connection, - "org.freedesktop.DBus.TestSuiteGLibService", - ret_path, - "org.freedesktop.DBus.Tests.FooObject", - &error); - g_free (ret_path); - - val = 0; - if (!org_freedesktop_DBus_Tests_FooObject_get_value (ret_proxy, &val, &error)) - lose_gerror ("Failed to complete (wrapped) GetValue call", error); - if (val != 3) - lose ("(wrapped) GetValue returned invalid value %d", val); - } - - run_mainloop (); - - { - GPtrArray *objs; - guint i; - - g_print ("Calling GetObjs\n"); - - if (!dbus_g_proxy_call (proxy, "GetObjs", &error, G_TYPE_INVALID, - dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), - &objs, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete GetObjs call", error); - if (objs->len != 2) - lose ("GetObjs call returned unexpected number of objects %d, expected 2", - objs->len); - - if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject", - g_ptr_array_index (objs, 0)) != 0) - lose ("GetObjs call returned unexpected path \"%s\" in position 0; expected /org/freedesktop/DBus/Tests/MyTestObject", (char*) g_ptr_array_index (objs, 0)); - - if (strcmp ("/org/freedesktop/DBus/Tests/MyTestObject2", - g_ptr_array_index (objs, 1)) != 0) - lose ("GetObjs call returned unexpected path \"%s\" in position 1; expected /org/freedesktop/DBus/Tests/MyTestObject2", (char*) g_ptr_array_index (objs, 1)); - - for (i = 0; i < objs->len; i++) - g_free (g_ptr_array_index (objs, i)); - g_ptr_array_free (objs, TRUE); - } - - { - GValue *variant; - GArray *array; - gint i; - - g_print ("Calling ProcessVariantOfArrayOfInts123\n"); - - array = g_array_sized_new (FALSE, FALSE, sizeof(gint), 3); - i = 1; - g_array_append_val (array, i); - i++; - g_array_append_val (array, i); - i++; - g_array_append_val (array, i); - - variant = g_new0 (GValue, 1); - g_value_init (variant, dbus_g_type_get_collection ("GArray", G_TYPE_INT)); - g_value_set_boxed_take_ownership (variant, array); - - if (!dbus_g_proxy_call (proxy, "ProcessVariantOfArrayOfInts123", &error, - G_TYPE_VALUE, variant, - G_TYPE_INVALID, - G_TYPE_INVALID)) - lose_gerror ("Failed to send a vairant of array of ints 1, 2 and 3!", error); - - g_value_unset (variant); - } - - for (i=0; i<3; i++) - { - gchar *val; - GHashTable *table; - GHashTable *subtable; - GHashTable *ret_table; - - table = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) (g_free), - (GDestroyNotify) (g_hash_table_destroy)); - - subtable = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) (g_free), - (GDestroyNotify) (g_free)); - g_hash_table_insert (subtable, g_strdup ("foo"), g_strdup("1")); - g_hash_table_insert (subtable, g_strdup ("bar"), g_strdup("2")); - g_hash_table_insert (subtable, g_strdup ("baz"), g_strdup("3")); - - g_hash_table_insert (table, g_strdup("dict1"), subtable); - - subtable = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) (g_free), - (GDestroyNotify) (g_free)); - g_hash_table_insert (subtable, g_strdup ("foo"), g_strdup("4")); - g_hash_table_insert (subtable, g_strdup ("bar"), g_strdup("5")); - g_hash_table_insert (subtable, g_strdup ("baz"), g_strdup("6")); - - g_hash_table_insert (table, g_strdup("dict2"), subtable); - - subtable = NULL; - - ret_table = NULL; - - g_print ("Calling DictOfDicts\n"); - if (!dbus_g_proxy_call (proxy, "DictOfDicts", &error, - dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, - dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, - G_TYPE_STRING)), table, - G_TYPE_INVALID, - dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, - dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, - G_TYPE_STRING)), &ret_table, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete DictOfDicts call", error); - - g_assert (ret_table != NULL); - g_assert (g_hash_table_size (ret_table) == 2); - - subtable = g_hash_table_lookup (ret_table, "dict1"); - g_assert(subtable); - g_assert (g_hash_table_size (subtable) == 3); - - val = g_hash_table_lookup (subtable, "foo"); - g_assert (val != NULL); - g_assert (!strcmp ("dict1 1", val)); - - val = g_hash_table_lookup (subtable, "bar"); - g_assert (val != NULL); - g_assert (!strcmp ("dict1 2", val)); - - val = g_hash_table_lookup (subtable, "baz"); - g_assert (val != NULL); - g_assert (!strcmp ("dict1 3", val)); - - subtable = g_hash_table_lookup (ret_table, "dict2"); - g_assert(subtable); - g_assert (g_hash_table_size (subtable) == 3); - - val = g_hash_table_lookup (subtable, "foo"); - g_assert (val != NULL); - g_assert (!strcmp ("dict2 4", val)); - - val = g_hash_table_lookup (subtable, "bar"); - g_assert (val != NULL); - g_assert (!strcmp ("dict2 5", val)); - - val = g_hash_table_lookup (subtable, "baz"); - g_assert (val != NULL); - g_assert (!strcmp ("dict2 6", val)); - - g_hash_table_destroy (table); - g_hash_table_destroy (ret_table); - - g_mem_profile (); - } - - - - /* Signal handling tests */ - - g_print ("Testing signal handling\n"); - dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID); - - dbus_g_proxy_connect_signal (proxy, "Frobnicate", - G_CALLBACK (frobnicate_signal_handler), - NULL, NULL); - - g_print ("Calling EmitFrobnicate\n"); - if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error, - G_TYPE_INVALID, G_TYPE_INVALID)) - lose_gerror ("Failed to complete EmitFrobnicate call", error); - - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_frobnicate_received != 1) - lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received); - - g_print ("Calling EmitFrobnicate again\n"); - if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error, - G_TYPE_INVALID, G_TYPE_INVALID)) - lose_gerror ("Failed to complete EmitFrobnicate call", error); - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_frobnicate_received != 2) - lose ("Frobnicate signal received %d times, should have been 2", n_times_frobnicate_received); - - g_object_unref (G_OBJECT (proxy)); - - run_mainloop (); - - g_print ("Creating proxy for FooObject interface\n"); - proxy = dbus_g_proxy_new_for_name_owner (connection, - "org.freedesktop.DBus.TestSuiteGLibService", - "/org/freedesktop/DBus/Tests/MyTestObject", - "org.freedesktop.DBus.Tests.FooObject", - &error); - - if (proxy == NULL) - lose_gerror ("Failed to create proxy for name owner", error); - - dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_INT_STRING, - G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID); - - dbus_g_object_register_marshaller (my_object_marshal_VOID__STRING_BOXED, - G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); - - dbus_g_proxy_add_signal (proxy, "Sig0", G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_add_signal (proxy, "Sig1", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); - dbus_g_proxy_add_signal (proxy, "Sig2", DBUS_TYPE_G_STRING_STRING_HASHTABLE, G_TYPE_INVALID); - - dbus_g_proxy_connect_signal (proxy, "Sig0", - G_CALLBACK (sig0_signal_handler), - NULL, NULL); - dbus_g_proxy_connect_signal (proxy, "Sig1", - G_CALLBACK (sig1_signal_handler), - NULL, NULL); - dbus_g_proxy_connect_signal (proxy, "Sig2", - G_CALLBACK (sig2_signal_handler), - NULL, NULL); - - g_print ("Calling FooObject EmitSignals\n"); - dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID); - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_sig0_received != 1) - lose ("Sig0 signal received %d times, should have been 1", n_times_sig0_received); - if (n_times_sig1_received != 1) - lose ("Sig1 signal received %d times, should have been 1", n_times_sig1_received); - - g_print ("Calling FooObject EmitSignals and EmitSignal2\n"); - dbus_g_proxy_call_no_reply (proxy, "EmitSignal2", G_TYPE_INVALID); - dbus_g_connection_flush (connection); - - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_sig2_received != 1) - lose ("Sig2 signal received %d times, should have been 1", n_times_sig2_received); - - g_print ("Calling FooObject EmitSignals two more times\n"); - dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID); - dbus_g_proxy_call_no_reply (proxy, "EmitSignals", G_TYPE_INVALID); - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_sig0_received != 3) - lose ("Sig0 signal received %d times, should have been 3", n_times_sig0_received); - if (n_times_sig1_received != 3) - lose ("Sig1 signal received %d times, should have been 3", n_times_sig1_received); - - /* Terminate again */ - g_print ("Terminating service\n"); - await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService"; - dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID); - - proxy_destroyed = FALSE; - proxy_destroy_and_nameowner = TRUE; - proxy_destroy_and_nameowner_complete = FALSE; - - g_signal_connect (G_OBJECT (proxy), - "destroy", - G_CALLBACK (proxy_destroyed_cb), - NULL); - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (await_terminating_service != NULL) - lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\""); - if (!proxy_destroyed) - lose ("Didn't get proxy_destroyed"); - g_print ("Proxy destroyed successfully\n"); - - /* Don't need to unref, proxy was destroyed */ - - run_mainloop (); - - /* Create a new proxy for the name; should not be associated */ - proxy = dbus_g_proxy_new_for_name (connection, - "org.freedesktop.DBus.TestSuiteGLibService", - "/org/freedesktop/DBus/Tests/MyTestObject", - "org.freedesktop.DBus.Tests.MyObject"); - g_assert (proxy != NULL); - - proxy_destroyed = FALSE; - proxy_destroy_and_nameowner = FALSE; - proxy_destroy_and_nameowner_complete = FALSE; - - g_signal_connect (G_OBJECT (proxy), - "destroy", - G_CALLBACK (proxy_destroyed_cb), - NULL); - - if (!dbus_g_proxy_call (driver, "GetNameOwner", &error, - G_TYPE_STRING, - "org.freedesktop.DBus.TestSuiteGLibService", - G_TYPE_INVALID, - G_TYPE_STRING, - &v_STRING_2, - G_TYPE_INVALID)) { - if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_NAME_HAS_NO_OWNER) - g_print ("Got expected error \"org.freedesktop.DBus.Error.NameHasNoOwner\"\n"); - else - lose_gerror ("Unexpected error from GetNameOwner", error); - } else - lose ("GetNameOwner unexpectedly succeeded!"); - g_clear_error (&error); - - /* This will have the side-effect of activating the service, thus - * causing a NameOwnerChanged, which should let our name proxy - * get signals - */ - g_print ("Calling Uppercase for name proxy\n"); - if (!dbus_g_proxy_call (proxy, "Uppercase", &error, - G_TYPE_STRING, "bazwhee", - G_TYPE_INVALID, - G_TYPE_STRING, &v_STRING_2, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Uppercase call", error); - g_free (v_STRING_2); - - if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION1")) - g_usleep (8 * G_USEC_PER_SEC); - - dbus_g_proxy_add_signal (proxy, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID); - - dbus_g_proxy_connect_signal (proxy, "Frobnicate", - G_CALLBACK (frobnicate_signal_handler), - NULL, NULL); - - g_print ("Calling EmitFrobnicate\n"); - if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error, - G_TYPE_INVALID, G_TYPE_INVALID)) - lose_gerror ("Failed to complete EmitFrobnicate call", error); - - n_times_frobnicate_received = 0; - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_frobnicate_received != 1) - lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received); - - /* Now terminate the service, then start it again (implicitly) and wait for signals */ - g_print ("Terminating service (2)\n"); - await_terminating_service = "org.freedesktop.DBus.TestSuiteGLibService"; - dbus_g_proxy_call_no_reply (proxy, "Terminate", G_TYPE_INVALID); - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - if (await_terminating_service != NULL) - lose ("Didn't see name loss for \"org.freedesktop.DBus.TestSuiteGLibService\""); - - if (proxy_destroyed) - lose ("Unexpectedly got proxy_destroyed!"); - - n_times_frobnicate_received = 0; - - g_print ("Calling EmitFrobnicate (2)\n"); - if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error, - G_TYPE_INVALID, G_TYPE_INVALID)) - lose_gerror ("Failed to complete EmitFrobnicate call", error); - - if (getenv ("DBUS_GLIB_TEST_SLEEP_AFTER_ACTIVATION2")) - g_usleep (8 * G_USEC_PER_SEC); - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_frobnicate_received != 1) - lose ("Frobnicate signal received %d times, should have been 1", n_times_frobnicate_received); - - if (proxy_destroyed) - lose ("Unexpectedly got proxy_destroyed!"); - - /* Create another proxy for the name; should be associated immediately */ - proxy2 = dbus_g_proxy_new_for_name (connection, - "org.freedesktop.DBus.TestSuiteGLibService", - "/org/freedesktop/DBus/Tests/MyTestObject", - "org.freedesktop.DBus.Tests.MyObject"); - g_assert (proxy2 != NULL); - - dbus_g_proxy_add_signal (proxy2, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID); - - dbus_g_proxy_connect_signal (proxy2, "Frobnicate", - G_CALLBACK (frobnicate_signal_handler_2), - NULL, NULL); - - g_print ("Calling EmitFrobnicate (3)\n"); - if (!dbus_g_proxy_call (proxy, "EmitFrobnicate", &error, - G_TYPE_INVALID, G_TYPE_INVALID)) - lose_gerror ("Failed to complete EmitFrobnicate call", error); - - dbus_g_connection_flush (connection); - exit_timeout = g_timeout_add (5000, timed_exit, loop); - g_main_loop_run (loop); - - if (n_times_frobnicate_received != 2) - lose ("Frobnicate signal received %d times for 1st proxy, should have been 2", n_times_frobnicate_received); - if (n_times_frobnicate_received_2 != 1) - lose ("Frobnicate signal received %d times for 2nd proxy, should have been 1", n_times_frobnicate_received_2); - - g_object_unref (G_OBJECT (proxy)); - g_object_unref (G_OBJECT (proxy2)); - - run_mainloop (); - - /* Test introspection */ - proxy = dbus_g_proxy_new_for_name_owner (connection, - "org.freedesktop.DBus.TestSuiteGLibService", - "/org/freedesktop/DBus/Tests/MyTestObject", - "org.freedesktop.DBus.Introspectable", - &error); - if (proxy == NULL) - lose_gerror ("Failed to create proxy for name owner", error); - - g_print ("Testing introspect\n"); - if (!dbus_g_proxy_call (proxy, "Introspect", &error, - G_TYPE_INVALID, - G_TYPE_STRING, &v_STRING_2, - G_TYPE_INVALID)) - lose_gerror ("Failed to complete Introspect call", error); - - /* Could just do strcmp(), but that seems more fragile */ - { - NodeInfo *node; - GSList *elt; - gboolean found_introspectable; - gboolean found_properties; - gboolean found_myobject; - gboolean found_fooobject; - - node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error); - if (!node) - lose_gerror ("Failed to parse introspection data: %s", error); - - found_introspectable = FALSE; - found_properties = FALSE; - found_myobject = FALSE; - found_fooobject = FALSE; - for (elt = node_info_get_interfaces (node); elt ; elt = elt->next) - { - InterfaceInfo *iface = elt->data; - - if (!found_introspectable && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Introspectable") == 0) - found_introspectable = TRUE; - else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0) - found_properties = TRUE; - else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0) - { - GSList *elt; - gboolean found_manyargs; - - found_myobject = TRUE; - - found_manyargs = FALSE; - for (elt = interface_info_get_methods (iface); elt; elt = elt->next) - { - MethodInfo *method; - - method = elt->data; - if (strcmp (method_info_get_name (method), "ManyArgs") == 0) - { - found_manyargs = TRUE; - break; - } - } - if (!found_manyargs) - lose ("Missing method org.freedesktop.DBus.Tests.MyObject.ManyArgs"); - } - else if (!found_fooobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.FooObject") == 0) - found_fooobject = TRUE; - else - lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface)); - } - - if (!(found_introspectable && found_myobject && found_properties)) - lose ("Missing interface"); - } - g_free (v_STRING_2); - - g_object_unref (G_OBJECT (driver)); - - g_print ("Successfully completed %s\n", argv[0]); - - return 0; -} diff --git a/test/glib/test-profile.c b/test/glib/test-profile.c deleted file mode 100644 index 9f63b36b..00000000 --- a/test/glib/test-profile.c +++ /dev/null @@ -1,1150 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -/* test-profile.c Program that does basic message-response for timing; doesn't really use glib bindings - * - * Copyright (C) 2003, 2004 Red Hat Inc. - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef HAVE_SOCKLEN_T -#define socklen_t int -#endif - -#define _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object)))) -#define _DBUS_MAX_SUN_PATH_LENGTH 99 - -/* Note that if you set threads > 1 you get a bogus profile since the - * clients start blocking on the server, so the client write() will go - * higher in the profile the larger the number of threads. - */ -#define N_CLIENT_THREADS 1 -/* It seems like at least 750000 or so iterations reduces the variability to sane levels */ -#define N_ITERATIONS 2000 -#define N_PROGRESS_UPDATES 20 -/* Don't make PAYLOAD_SIZE too huge because it gets used as a static buffer size */ -#define PAYLOAD_SIZE 0 - -#define ECHO_SERVICE "org.freedesktop.EchoTestServer" -#define ECHO_PATH "/org/freedesktop/EchoTest" -#define ECHO_INTERFACE "org.freedesktop.EchoTest" -#define ECHO_PING_METHOD "Ping" - -static const char *messages_address; -static const char *plain_sockets_address; -static unsigned char *payload; -static int echo_call_size; -static int echo_return_size; - -typedef struct ProfileRunVTable ProfileRunVTable; - -typedef struct -{ - const ProfileRunVTable *vtable; - int iterations; - GMainLoop *loop; -} ClientData; - -typedef struct -{ - const ProfileRunVTable *vtable; - int handled; - GMainLoop *loop; - int n_clients; -} ServerData; - -struct ProfileRunVTable -{ - const char *name; - gboolean fake_malloc_overhead; - void* (* init_server) (ServerData *sd); - void (* stop_server) (ServerData *sd, - void *server); - void* (* client_thread_func) (void *data); /* Data has to be the vtable */ - - /* this is so different runs show up in the profiler with - * different backtrace - */ - void (* main_loop_run_func) (GMainLoop *loop); -}; - -/* Note, this is all crack-a-rific; it isn't using DBusGProxy and thus is - * a major pain - */ -static void -send_echo_method_call (DBusConnection *connection) -{ - DBusMessage *message; - const char *hello = "Hello World!"; - dbus_int32_t i32 = 123456; - - message = dbus_message_new_method_call (ECHO_SERVICE, - ECHO_PATH, - ECHO_INTERFACE, - ECHO_PING_METHOD); - dbus_message_append_args (message, - DBUS_TYPE_STRING, &hello, - DBUS_TYPE_INT32, &i32, -#if PAYLOAD_SIZE > 0 - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, - &payload, PAYLOAD_SIZE, -#endif - DBUS_TYPE_INVALID); - - dbus_connection_send (connection, message, NULL); - dbus_message_unref (message); - dbus_connection_flush (connection); -} - -static void -send_echo_method_return (DBusConnection *connection, - DBusMessage *call_message) -{ - DBusMessage *message; - - message = dbus_message_new_method_return (call_message); - - dbus_connection_send (connection, message, NULL); - dbus_message_unref (message); - dbus_connection_flush (connection); -} - -static DBusHandlerResult -with_or_without_bus_client_filter (DBusConnection *connection, - DBusMessage *message, - ClientData *cd) -{ - if (dbus_message_is_signal (message, - DBUS_INTERFACE_LOCAL, - "Disconnected")) - { - g_printerr ("Client thread disconnected\n"); - exit (1); - } - else if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_RETURN) - { - cd->iterations += 1; - if (cd->iterations >= N_ITERATIONS) - { - g_printerr ("\nCompleted %d iterations\n", N_ITERATIONS); - g_main_loop_quit (cd->loop); - } - else if (cd->iterations % (N_ITERATIONS/N_PROGRESS_UPDATES) == 0) - { - g_printerr ("%d%% ", (int) (cd->iterations/(double)N_ITERATIONS * 100.0)); - } - - send_echo_method_call (connection); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static DBusHandlerResult -no_bus_client_filter (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - ClientData *cd = user_data; - - return with_or_without_bus_client_filter (connection, message, cd); -} - -static void* -no_bus_thread_func (void *data) -{ - DBusError error; - GMainContext *context; - DBusConnection *connection; - ClientData cd; - - g_printerr ("Starting client thread %p\n", g_thread_self()); - - dbus_error_init (&error); - connection = dbus_connection_open_private (messages_address, &error); - if (connection == NULL) - { - g_printerr ("could not open connection: %s\n", error.message); - dbus_error_free (&error); - exit (1); - } - - context = g_main_context_new (); - - cd.iterations = 1; - cd.loop = g_main_loop_new (context, FALSE); - - if (!dbus_connection_add_filter (connection, - no_bus_client_filter, &cd, NULL)) - g_error ("no memory"); - - - dbus_connection_setup_with_g_main (connection, context); - - g_printerr ("Client thread sending message to prime pingpong\n"); - send_echo_method_call (connection); - g_printerr ("Client thread sent message\n"); - - g_printerr ("Client thread entering main loop\n"); - g_main_loop_run (cd.loop); - g_printerr ("Client thread %p exiting main loop\n", - g_thread_self()); - - dbus_connection_close (connection); - - g_main_loop_unref (cd.loop); - g_main_context_unref (context); - - return NULL; -} - -static DBusHandlerResult -no_bus_server_filter (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - ServerData *sd = user_data; - - if (dbus_message_is_signal (message, - DBUS_INTERFACE_LOCAL, - "Disconnected")) - { - g_printerr ("Client disconnected from server\n"); - sd->n_clients -= 1; - if (sd->n_clients == 0) - g_main_loop_quit (sd->loop); - } - else if (dbus_message_is_method_call (message, - ECHO_INTERFACE, - ECHO_PING_METHOD)) - { - sd->handled += 1; - send_echo_method_return (connection, message); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static void -no_bus_new_connection_callback (DBusServer *server, - DBusConnection *new_connection, - void *user_data) -{ - ServerData *sd = user_data; - - dbus_connection_ref (new_connection); - dbus_connection_setup_with_g_main (new_connection, NULL); - - if (!dbus_connection_add_filter (new_connection, - no_bus_server_filter, sd, NULL)) - g_error ("no memory"); - - sd->n_clients += 1; - - /* FIXME we leak the handler */ -} - -static void* -no_bus_init_server (ServerData *sd) -{ - DBusServer *server; - DBusError error; - - dbus_error_init (&error); - server = dbus_server_listen ("unix:tmpdir="DBUS_TEST_SOCKET_DIR, - &error); - if (server == NULL) - { - g_printerr ("Could not start server: %s\n", - error.message); - exit (1); - } - - messages_address = dbus_server_get_address (server); - - dbus_server_set_new_connection_function (server, - no_bus_new_connection_callback, - sd, NULL); - - dbus_server_setup_with_g_main (server, NULL); - - return server; -} - -static void -no_bus_stop_server (ServerData *sd, - void *server) -{ - dbus_server_disconnect (server); - dbus_server_unref (server); -} - -static void -no_bus_main_loop_run (GMainLoop *loop) -{ - g_main_loop_run (loop); -} - -static const ProfileRunVTable no_bus_vtable = { - "dbus direct without bus", - FALSE, - no_bus_init_server, - no_bus_stop_server, - no_bus_thread_func, - no_bus_main_loop_run -}; - -typedef struct -{ - const ProfileRunVTable *vtable; - ServerData *sd; - GHashTable *client_names; - DBusConnection *connection; -} WithBusServer; - -static DBusHandlerResult -with_bus_client_filter (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - ClientData *cd = user_data; - - return with_or_without_bus_client_filter (connection, message, cd); -} - -static void* -with_bus_thread_func (void *data) -{ - DBusError error; - DBusConnection *connection; - ClientData cd; - const char *address; - GMainContext *context; - - g_printerr ("Starting client thread %p\n", g_thread_self()); - - address = g_getenv ("DBUS_SESSION_BUS_ADDRESS"); - if (address == NULL) - { - g_printerr ("DBUS_SESSION_BUS_ADDRESS not set\n"); - exit (1); - } - - dbus_error_init (&error); - connection = dbus_connection_open_private (address, &error); - if (connection == NULL) - { - g_printerr ("could not open connection to bus: %s\n", error.message); - dbus_error_free (&error); - exit (1); - } - - if (!dbus_bus_register (connection, &error)) - { - g_printerr ("could not register with bus: %s\n", error.message); - dbus_error_free (&error); - exit (1); - } - - context = g_main_context_new (); - - cd.iterations = 1; - cd.loop = g_main_loop_new (context, FALSE); - - if (!dbus_connection_add_filter (connection, - with_bus_client_filter, &cd, NULL)) - g_error ("no memory"); - - dbus_connection_setup_with_g_main (connection, context); - - g_printerr ("Client thread sending message to prime pingpong\n"); - send_echo_method_call (connection); - g_printerr ("Client thread sent message\n"); - - g_printerr ("Client thread entering main loop\n"); - g_main_loop_run (cd.loop); - g_printerr ("Client thread %p exiting main loop\n", - g_thread_self()); - - dbus_connection_close (connection); - - g_main_loop_unref (cd.loop); - g_main_context_unref (context); - - return NULL; -} - -static DBusHandlerResult -with_bus_server_filter (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - WithBusServer *server = user_data; - - if (dbus_message_is_signal (message, - DBUS_INTERFACE_LOCAL, - "Disconnected")) - { - g_printerr ("Server disconnected from message bus\n"); - exit (1); - } - else if (dbus_message_has_sender (message, - DBUS_SERVICE_DBUS) && - dbus_message_is_signal (message, - DBUS_INTERFACE_DBUS, - "NameOwnerChanged")) - { - const char *name, *old_owner, *new_owner; - DBusError error; - - name = NULL; - old_owner = NULL; - new_owner = NULL; - - dbus_error_init (&error); - if (!dbus_message_get_args (message, - &error, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_STRING, &old_owner, - DBUS_TYPE_STRING, &new_owner, - DBUS_TYPE_INVALID)) - { - g_printerr ("dbus_message_get_args(): %s\n", error.message); - exit (1); - } - - if (g_hash_table_lookup (server->client_names, - name) && - *old_owner != '\0' && - *new_owner == '\0') - { - g_hash_table_remove (server->client_names, - name); - server->sd->n_clients -= 1; - if (server->sd->n_clients == 0) - g_main_loop_quit (server->sd->loop); - } - } - else if (dbus_message_is_method_call (message, - ECHO_INTERFACE, - ECHO_PING_METHOD)) - { - const char *sender; - - sender = dbus_message_get_sender (message); - - if (!g_hash_table_lookup (server->client_names, - sender)) - { - g_printerr ("First message from new client %s on bus\n", sender); - - g_hash_table_replace (server->client_names, - g_strdup (sender), - GINT_TO_POINTER (1)); - server->sd->n_clients += 1; - } - - server->sd->handled += 1; - send_echo_method_return (connection, message); - return DBUS_HANDLER_RESULT_HANDLED; - } - - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -static void* -with_bus_init_server (ServerData *sd) -{ - DBusGConnection *gconnection; - DBusConnection *connection; - GError *gerror; - const char *s; - WithBusServer *server; - char *rule; - - server = g_new0 (WithBusServer, 1); - - server->vtable = sd->vtable; - server->sd = sd; - - s = g_getenv ("DBUS_TEST_GLIB_RUN_TEST_SCRIPT"); - if (s == NULL || - *s != '1') - { - g_printerr ("You have to run with_bus mode with the run-test.sh script\n"); - exit (1); - } - - /* Note that we use the standard global bus connection for the - * server, and the clients open their own connections so they can - * have their own main loops and because I'm not sure "talking to - * yourself" really works yet - */ - gerror = NULL; - gconnection = dbus_g_bus_get (DBUS_BUS_SESSION, &gerror); - if (gconnection == NULL) - { - g_printerr ("could not open connection to bus: %s\n", gerror->message); - g_error_free (gerror); - exit (1); - } - - server->client_names = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - - connection = dbus_g_connection_get_connection (gconnection); - - dbus_bus_request_name (connection, - ECHO_SERVICE, - 0, NULL); /* ignore errors because we suck */ - - rule = g_strdup_printf ("type='signal',sender='%s',member='%s'", - DBUS_SERVICE_DBUS, - "NameOwnerChanged"); - - /* ignore errors because we suck */ - dbus_bus_add_match (connection, rule, NULL); - - g_free (rule); - - if (!dbus_connection_add_filter (connection, - with_bus_server_filter, server, NULL)) - g_error ("no memory"); - - server->connection = connection; - server->client_names = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, NULL); - - return server; -} - -static void -with_bus_stop_server (ServerData *sd, - void *serverv) -{ - WithBusServer *server = serverv; - - dbus_connection_remove_filter (server->connection, - with_bus_server_filter, server); - - g_hash_table_destroy (server->client_names); - dbus_connection_unref (server->connection); - - g_free (server); -} - -static void -with_bus_main_loop_run (GMainLoop *loop) -{ - g_main_loop_run (loop); -} - -static const ProfileRunVTable with_bus_vtable = { - "routing via a bus", - FALSE, - with_bus_init_server, - with_bus_stop_server, - with_bus_thread_func, - with_bus_main_loop_run -}; - - -typedef struct -{ - const ProfileRunVTable *vtable; - int listen_fd; - ServerData *sd; - unsigned int source_id; -} PlainSocketServer; - -static void -read_and_drop_on_floor (int fd, - int count, - gboolean fake_malloc_overhead) -{ - int bytes_read; - int val; - char *buf; - char *allocated; - char not_allocated[512+PAYLOAD_SIZE]; - - g_assert (count < (int) sizeof(not_allocated)); - - if (fake_malloc_overhead) - { - allocated = g_malloc (count); - buf = allocated; - } - else - { - allocated = NULL; - buf = not_allocated; - } - - bytes_read = 0; - - while (bytes_read < count) - { - again: - - val = read (fd, buf + bytes_read, count - bytes_read); - - if (val < 0) - { - if (errno == EINTR) - goto again; - else - { - g_printerr ("read() failed thread %p: %s\n", - g_thread_self(), strerror (errno)); - exit (1); - } - } - else - { - bytes_read += val; - } - } - - if (fake_malloc_overhead) - g_free (allocated); - -#if 0 - g_printerr ("%p read %d bytes from fd %d\n", - g_thread_self(), bytes_read, fd); -#endif -} - -static void -write_junk (int fd, - int count, - gboolean fake_malloc_overhead) -{ - int bytes_written; - int val; - char *buf; - char *allocated; - char not_allocated[512+PAYLOAD_SIZE] = { '\0', }; - - g_assert (count < (int) sizeof(not_allocated)); - - if (fake_malloc_overhead) - { - int i; - - allocated = g_malloc (count); - buf = allocated; - - /* Write some stuff into the allocated buffer to simulate - * creating some sort of data - */ - i = 0; - while (i < count) - { - allocated[i] = (char) i; - ++i; - } - } - else - { - allocated = NULL; - buf = not_allocated; - } - - bytes_written = 0; - - while (bytes_written < count) - { - again: - - val = write (fd, buf + bytes_written, count - bytes_written); - - if (val < 0) - { - if (errno == EINTR) - goto again; - else - { - g_printerr ("write() failed thread %p: %s\n", - g_thread_self(), strerror (errno)); - exit (1); - } - } - else - { - bytes_written += val; - } - } - - if (fake_malloc_overhead) - g_free (allocated); - -#if 0 - g_printerr ("%p wrote %d bytes to fd %d\n", - g_thread_self(), bytes_written, fd); -#endif -} - -static gboolean -plain_sockets_talk_to_client_watch (GIOChannel *source, - GIOCondition condition, - gpointer data) -{ - PlainSocketServer *server = data; - int client_fd = g_io_channel_unix_get_fd (source); - - if (condition & G_IO_HUP) - { - g_printerr ("Client disconnected from server\n"); - server->sd->n_clients -= 1; - if (server->sd->n_clients == 0) - g_main_loop_quit (server->sd->loop); - - return FALSE; /* remove watch */ - } - else if (condition & G_IO_IN) - { - server->sd->handled += 1; - - read_and_drop_on_floor (client_fd, echo_call_size, server->vtable->fake_malloc_overhead); - write_junk (client_fd, echo_return_size, server->vtable->fake_malloc_overhead); - } - else - { - g_printerr ("Unexpected IO condition in server thread\n"); - exit (1); - } - - return TRUE; -} - -static gboolean -plain_sockets_new_client_watch (GIOChannel *source, - GIOCondition condition, - gpointer data) -{ - int client_fd; - struct sockaddr addr; - socklen_t addrlen; - GIOChannel *channel; - PlainSocketServer *server = data; - - if (!(condition & G_IO_IN)) - { - g_printerr ("Unexpected IO condition on server socket\n"); - exit (1); - } - - addrlen = sizeof (addr); - - retry: - client_fd = accept (server->listen_fd, &addr, &addrlen); - - if (client_fd < 0) - { - if (errno == EINTR) - goto retry; - else - { - g_printerr ("Failed to accept() connection from client: %s\n", - strerror (errno)); - exit (1); - } - } - - channel = g_io_channel_unix_new (client_fd); - g_io_add_watch (channel, - G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_PRI, - plain_sockets_talk_to_client_watch, - server); - g_io_channel_unref (channel); - - server->sd->n_clients += 1; - - return TRUE; -} - -static void* -plain_sockets_init_server (ServerData *sd) -{ - PlainSocketServer *server; - struct sockaddr_un addr; - static char path[] = "/tmp/dbus-test-profile-XXXXXX"; - char *p; - GIOChannel *channel; - - server = g_new0 (PlainSocketServer, 1); - server->sd = sd; - server->vtable = sd->vtable; /* for convenience */ - - p = path; - while (*p) - { - if (*p == 'X') - *p = 'a' + (int) (26.0*rand()/(RAND_MAX+1.0)); - ++p; - } - - g_printerr ("Socket is %s\n", path); - - server->listen_fd = socket (PF_UNIX, SOCK_STREAM, 0); - - if (server->listen_fd < 0) - { - g_printerr ("Failed to create socket: %s", - strerror (errno)); - exit (1); - } - - _DBUS_ZERO (addr); - addr.sun_family = AF_UNIX; - -#ifdef HAVE_ABSTRACT_SOCKETS - /* remember that abstract names aren't nul-terminated so we rely - * on sun_path being filled in with zeroes above. - */ - addr.sun_path[0] = '\0'; /* this is what says "use abstract" */ - strncpy (&addr.sun_path[1], path, _DBUS_MAX_SUN_PATH_LENGTH - 2); - /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */ -#else /* HAVE_ABSTRACT_SOCKETS */ - { - struct stat sb; - - if (stat (path, &sb) == 0 && - S_ISSOCK (sb.st_mode)) - unlink (path); - } - - strncpy (addr.sun_path, path, _DBUS_MAX_SUN_PATH_LENGTH - 1); -#endif /* ! HAVE_ABSTRACT_SOCKETS */ - - if (bind (server->listen_fd, (struct sockaddr*) &addr, sizeof (addr)) < 0) - { - g_printerr ("Failed to bind socket \"%s\": %s", - path, strerror (errno)); - exit (1); - } - - if (listen (server->listen_fd, 30 /* backlog */) < 0) - { - g_printerr ("Failed to listen on socket \"%s\": %s", - path, strerror (errno)); - exit (1); - } - - plain_sockets_address = path; - - channel = g_io_channel_unix_new (server->listen_fd); - server->source_id = - g_io_add_watch (channel, - G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_PRI, - plain_sockets_new_client_watch, - server); - g_io_channel_unref (channel); - - return server; -} - -static void -plain_sockets_stop_server (ServerData *sd, - void *server_v) -{ - PlainSocketServer *server = server_v; - - g_source_remove (server->source_id); - - close (server->listen_fd); - g_free (server); - - { - struct stat sb; - - if (stat (plain_sockets_address, &sb) == 0 && - S_ISSOCK (sb.st_mode)) - unlink (plain_sockets_address); - } -} - -static gboolean -plain_sockets_client_side_watch (GIOChannel *source, - GIOCondition condition, - gpointer data) -{ - ClientData *cd = data; - int fd = g_io_channel_unix_get_fd (source); - - if (condition & G_IO_IN) - { - read_and_drop_on_floor (fd, echo_return_size, cd->vtable->fake_malloc_overhead); - } - else if (condition & G_IO_OUT) - { - cd->iterations += 1; - if (cd->iterations >= N_ITERATIONS) - { - g_printerr ("\nCompleted %d iterations\n", N_ITERATIONS); - g_main_loop_quit (cd->loop); - } - else if (cd->iterations % (N_ITERATIONS/N_PROGRESS_UPDATES) == 0) - { - g_printerr ("%d%% ", (int) (cd->iterations/(double)N_ITERATIONS * 100.0)); - } - - write_junk (fd, echo_call_size, cd->vtable->fake_malloc_overhead); - } - else - { - g_printerr ("Unexpected IO condition in client thread\n"); - exit (1); - } - - return TRUE; -} - -static void* -plain_sockets_thread_func (void *data) -{ - GMainContext *context; - ClientData cd; - int fd; - struct sockaddr_un addr; - GIOChannel *channel; - GSource *gsource; - - g_printerr ("Starting client thread %p\n", - g_thread_self()); - - fd = socket (PF_UNIX, SOCK_STREAM, 0); - - if (fd < 0) - { - g_printerr ("Failed to create socket: %s", - strerror (errno)); - exit (1); - } - - _DBUS_ZERO (addr); - addr.sun_family = AF_UNIX; - -#ifdef HAVE_ABSTRACT_SOCKETS - /* remember that abstract names aren't nul-terminated so we rely - * on sun_path being filled in with zeroes above. - */ - addr.sun_path[0] = '\0'; /* this is what says "use abstract" */ - strncpy (&addr.sun_path[1], plain_sockets_address, _DBUS_MAX_SUN_PATH_LENGTH - 2); - /* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */ -#else /* HAVE_ABSTRACT_SOCKETS */ - strncpy (addr.sun_path, plain_sockets_address, _DBUS_MAX_SUN_PATH_LENGTH - 1); -#endif /* ! HAVE_ABSTRACT_SOCKETS */ - - if (connect (fd, (struct sockaddr*) &addr, sizeof (addr)) < 0) - { - g_printerr ("Failed to connect to socket %s: %s", - plain_sockets_address, strerror (errno)); - exit (1); - } - - context = g_main_context_new (); - - cd.iterations = 1; - cd.loop = g_main_loop_new (context, FALSE); - cd.vtable = data; - - channel = g_io_channel_unix_new (fd); - - gsource = g_io_create_watch (channel, - G_IO_IN | G_IO_OUT | - G_IO_ERR | G_IO_HUP | G_IO_NVAL | G_IO_PRI); - - g_source_set_callback (gsource, - (GSourceFunc)plain_sockets_client_side_watch, - &cd, NULL); - - g_source_attach (gsource, context); - - g_io_channel_unref (channel); - - g_printerr ("Client thread writing to prime pingpong\n"); - write_junk (fd, echo_call_size, cd.vtable->fake_malloc_overhead); - g_printerr ("Client thread done writing primer\n"); - - g_printerr ("Client thread entering main loop\n"); - g_main_loop_run (cd.loop); - g_printerr ("Client thread %p exiting main loop\n", - g_thread_self()); - - g_source_destroy (gsource); - - close (fd); - - g_main_loop_unref (cd.loop); - g_main_context_unref (context); - - return NULL; -} - -static void -plain_sockets_main_loop_run (GMainLoop *loop) -{ - g_main_loop_run (loop); -} - -static const ProfileRunVTable plain_sockets_vtable = { - "plain sockets", - FALSE, - plain_sockets_init_server, - plain_sockets_stop_server, - plain_sockets_thread_func, - plain_sockets_main_loop_run -}; - -static const ProfileRunVTable plain_sockets_with_malloc_vtable = { - "plain sockets with malloc overhead", - TRUE, - plain_sockets_init_server, - plain_sockets_stop_server, - plain_sockets_thread_func, - plain_sockets_main_loop_run -}; - -static double -do_profile_run (const ProfileRunVTable *vtable) -{ - GTimer *timer; - int i; - double secs; - ServerData sd; - void *server; - - g_printerr ("Profiling %s\n", vtable->name); - - sd.handled = 0; - sd.n_clients = 0; - sd.loop = g_main_loop_new (NULL, FALSE); - sd.vtable = vtable; - - server = (* vtable->init_server) (&sd); - - for (i = 0; i < N_CLIENT_THREADS; i++) - { - g_thread_create (vtable->client_thread_func, (void*) vtable, FALSE, NULL); - } - - timer = g_timer_new (); - - g_printerr ("Server thread %p entering main loop\n", - g_thread_self()); - (* vtable->main_loop_run_func) (sd.loop); - g_printerr ("Server thread %p exiting main loop\n", - g_thread_self()); - - secs = g_timer_elapsed (timer, NULL); - g_timer_destroy (timer); - - g_printerr ("%s: %g seconds, %d round trips, %f seconds per pingpong\n", - vtable->name, secs, sd.handled, secs/sd.handled); - - (* vtable->stop_server) (&sd, server); - - g_main_loop_unref (sd.loop); - - return secs; -} - -static void -print_result (const ProfileRunVTable *vtable, - double seconds, - double baseline) -{ - g_printerr (" %g times slower for %s (%g seconds, %f per iteration)\n", - seconds/baseline, vtable->name, - seconds, seconds / N_ITERATIONS); -} - -int -main (int argc, char *argv[]) -{ - g_thread_init (NULL); - dbus_g_thread_init (); - -#ifndef DBUS_DISABLE_ASSERT - g_printerr ("You should probably --disable-asserts before you profile as they have noticeable overhead\n"); -#endif - -#if DBUS_ENABLE_VERBOSE_MODE - g_printerr ("You should probably --disable-verbose-mode before you profile as verbose has noticeable overhead\n"); -#endif - - payload = g_malloc (PAYLOAD_SIZE); - - /* The actual size of the DBusMessage on the wire, as of Nov 23 2004, - * without the payload - */ - echo_call_size = 140 + PAYLOAD_SIZE; - echo_return_size = 32; - - if (argc > 1 && strcmp (argv[1], "plain_sockets") == 0) - do_profile_run (&plain_sockets_vtable); - else if (argc > 1 && strcmp (argv[1], "plain_sockets_with_malloc") == 0) - do_profile_run (&plain_sockets_with_malloc_vtable); - else if (argc > 1 && strcmp (argv[1], "no_bus") == 0) - do_profile_run (&no_bus_vtable); - else if (argc > 1 && strcmp (argv[1], "with_bus") == 0) - do_profile_run (&with_bus_vtable); - else if (argc > 1 && strcmp (argv[1], "all") == 0) - { - double e1, e2, e3, e4; - - e1 = do_profile_run (&plain_sockets_vtable); - e2 = do_profile_run (&plain_sockets_with_malloc_vtable); - e3 = do_profile_run (&no_bus_vtable); - e4 = do_profile_run (&with_bus_vtable); - - g_printerr ("Baseline plain sockets time %g seconds for %d iterations\n", - e1, N_ITERATIONS); - print_result (&plain_sockets_vtable, e1, e1); - print_result (&plain_sockets_with_malloc_vtable, e2, e1); - print_result (&no_bus_vtable, e3, e1); - print_result (&with_bus_vtable, e4, e1); - } - else - { - g_printerr ("Specify profile type plain_sockets, plain_sockets_with_malloc, no_bus, with_bus, all\n"); - exit (1); - } - - /* Make valgrind happy */ - dbus_shutdown (); - - return 0; -} diff --git a/test/glib/test-service-glib.c b/test/glib/test-service-glib.c deleted file mode 100644 index 829cb57d..00000000 --- a/test/glib/test-service-glib.c +++ /dev/null @@ -1,928 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ -#include -/* NOTE - outside of D-BUS core this would be - * include - */ -#include "tools/dbus-glib-bindings.h" -#include -#include -#include -#include -#include -#include -#include "my-object-marshal.h" - -typedef struct MyObject MyObject; -typedef struct MyObjectClass MyObjectClass; - -GType my_object_get_type (void); - -struct MyObject -{ - GObject parent; - char *this_is_a_string; - guint val; -}; - -struct MyObjectClass -{ - GObjectClass parent; -}; - -#define MY_TYPE_OBJECT (my_object_get_type ()) -#define MY_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MY_TYPE_OBJECT, MyObject)) -#define MY_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MY_TYPE_OBJECT, MyObjectClass)) -#define MY_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MY_TYPE_OBJECT)) -#define MY_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MY_TYPE_OBJECT)) -#define MY_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MY_TYPE_OBJECT, MyObjectClass)) - -G_DEFINE_TYPE(MyObject, my_object, G_TYPE_OBJECT) - -typedef enum -{ - MY_OBJECT_ERROR_FOO, - MY_OBJECT_ERROR_BAR -} MyObjectError; - -#define MY_OBJECT_ERROR (my_object_error_quark ()) - -#define MY_TYPE_ERROR (my_object_error_get_type ()) - -gboolean my_object_do_nothing (MyObject *obj, GError **error); - -gboolean my_object_increment (MyObject *obj, gint32 x, gint32 *ret, GError **error); - -gint32 my_object_increment_retval (MyObject *obj, gint32 x); - -gint32 my_object_increment_retval_error (MyObject *obj, gint32 x, GError **error); - -gboolean my_object_throw_error (MyObject *obj, GError **error); - -gboolean my_object_uppercase (MyObject *obj, const char *str, char **ret, GError **error); - -gboolean my_object_many_args (MyObject *obj, guint32 x, const char *str, double trouble, double *d_ret, char **str_ret, GError **error); - -gboolean my_object_many_return (MyObject *obj, guint32 *arg0, char **arg1, gint32 *arg2, guint32 *arg3, guint32 *arg4, const char **arg5, GError **error); - -gboolean my_object_recursive1 (MyObject *obj, GArray *array, guint32 *len_ret, GError **error); -gboolean my_object_recursive2 (MyObject *obj, guint32 reqlen, GArray **array, GError **error); - -gboolean my_object_many_stringify (MyObject *obj, GHashTable *vals, GHashTable **ret, GError **error); - -gboolean my_object_rec_arrays (MyObject *obj, GPtrArray *in, GPtrArray **ret, GError **error); - -gboolean my_object_objpath (MyObject *obj, const char *in, const char **arg1, GError **error); - -gboolean my_object_get_objs (MyObject *obj, GPtrArray **objs, GError **error); - -gboolean my_object_stringify (MyObject *obj, GValue *value, char **ret, GError **error); -gboolean my_object_unstringify (MyObject *obj, const char *str, GValue *value, GError **error); - -gboolean my_object_many_uppercase (MyObject *obj, const char * const *in, char ***out, GError **error); - -gboolean my_object_str_hash_len (MyObject *obj, GHashTable *table, guint *len, GError **error); - -gboolean my_object_send_car (MyObject *obj, GValueArray *invals, GValueArray **outvals, GError **error); - -gboolean my_object_get_hash (MyObject *obj, GHashTable **table, GError **error); - -gboolean my_object_increment_val (MyObject *obj, GError **error); - -gboolean my_object_get_val (MyObject *obj, guint *ret, GError **error); - -gboolean my_object_get_value (MyObject *obj, guint *ret, GError **error); - -gboolean my_object_emit_signals (MyObject *obj, GError **error); -gboolean my_object_emit_signal2 (MyObject *obj, GError **error); - -gboolean my_object_emit_frobnicate (MyObject *obj, GError **error); - -gboolean my_object_echo_variant (MyObject *obj, GValue *variant, GValue *ret, GError **error); - -gboolean my_object_process_variant_of_array_of_ints123 (MyObject *obj, GValue *variant, GError **error); - -gboolean my_object_dict_of_dicts (MyObject *obj, GHashTable *dict, GHashTable **ret, GError **error); - -gboolean my_object_terminate (MyObject *obj, GError **error); - -void my_object_async_increment (MyObject *obj, gint32 x, DBusGMethodInvocation *context); - -void my_object_async_throw_error (MyObject *obj, DBusGMethodInvocation *context); - -#include "test-service-glib-glue.h" - -GQuark my_object_error_quark (void); - -GType my_object_error_get_type (void); - -/* Properties */ -enum -{ - PROP_0, - PROP_THIS_IS_A_STRING -}; - -enum -{ - FROBNICATE, - SIG0, - SIG1, - SIG2, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -static void -my_object_finalize (GObject *object) -{ - MyObject *mobject = MY_OBJECT (object); - - g_free (mobject->this_is_a_string); - - (G_OBJECT_CLASS (my_object_parent_class)->finalize) (object); -} - -static void -my_object_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MyObject *mobject; - - mobject = MY_OBJECT (object); - - switch (prop_id) - { - case PROP_THIS_IS_A_STRING: - g_free (mobject->this_is_a_string); - mobject->this_is_a_string = g_value_dup_string (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -my_object_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MyObject *mobject; - - mobject = MY_OBJECT (object); - - switch (prop_id) - { - case PROP_THIS_IS_A_STRING: - g_value_set_string (value, mobject->this_is_a_string); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -my_object_init (MyObject *obj) -{ - obj->val = 0; -} - -static void -my_object_class_init (MyObjectClass *mobject_class) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (mobject_class); - - gobject_class->finalize = my_object_finalize; - gobject_class->set_property = my_object_set_property; - gobject_class->get_property = my_object_get_property; - - g_object_class_install_property (gobject_class, - PROP_THIS_IS_A_STRING, - g_param_spec_string ("this_is_a_string", - _("Sample string"), - _("Example of a string property"), - "default value", - G_PARAM_READWRITE)); - signals[FROBNICATE] = - g_signal_new ("frobnicate", - G_OBJECT_CLASS_TYPE (mobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); - - signals[SIG0] = - g_signal_new ("sig0", - G_OBJECT_CLASS_TYPE (mobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, - 0, - NULL, NULL, - my_object_marshal_VOID__STRING_INT_STRING, - G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING); - - signals[SIG1] = - g_signal_new ("sig1", - G_OBJECT_CLASS_TYPE (mobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, - 0, - NULL, NULL, - my_object_marshal_VOID__STRING_BOXED, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_VALUE); - - signals[SIG2] = - g_signal_new ("sig2", - G_OBJECT_CLASS_TYPE (mobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, 1, DBUS_TYPE_G_STRING_STRING_HASHTABLE); -} - -GQuark -my_object_error_quark (void) -{ - static GQuark quark = 0; - if (!quark) - quark = g_quark_from_static_string ("my_object_error"); - - return quark; -} - -/* This should really be standard. */ -#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } - -GType -my_object_error_get_type (void) -{ - static GType etype = 0; - - if (etype == 0) - { - static const GEnumValue values[] = - { - - ENUM_ENTRY (MY_OBJECT_ERROR_FOO, "Foo"), - ENUM_ENTRY (MY_OBJECT_ERROR_BAR, "Bar"), - { 0, 0, 0 } - }; - - etype = g_enum_register_static ("MyObjectError", values); - } - - return etype; -} - -static GObject *obj; -static GObject *obj2; - -gboolean -my_object_do_nothing (MyObject *obj, GError **error) -{ - return TRUE; -} - -gboolean -my_object_increment (MyObject *obj, gint32 x, gint32 *ret, GError **error) -{ - *ret = x +1; - return TRUE; -} - -gint32 -my_object_increment_retval (MyObject *obj, gint32 x) -{ - return x + 1; -} - -gint32 -my_object_increment_retval_error (MyObject *obj, gint32 x, GError **error) -{ - if (x + 1 > 10) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "%s", - "x is bigger than 9"); - return FALSE; - } - return x + 1; -} - -gboolean -my_object_throw_error (MyObject *obj, GError **error) -{ - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "%s", - "this method always loses"); - return FALSE; -} - -gboolean -my_object_uppercase (MyObject *obj, const char *str, char **ret, GError **error) -{ - *ret = g_ascii_strup (str, -1); - return TRUE; -} - -gboolean -my_object_many_args (MyObject *obj, guint32 x, const char *str, double trouble, double *d_ret, char **str_ret, GError **error) -{ - *d_ret = trouble + (x * 2); - *str_ret = g_ascii_strup (str, -1); - return TRUE; -} - -gboolean -my_object_many_return (MyObject *obj, guint32 *arg0, char **arg1, gint32 *arg2, guint32 *arg3, guint32 *arg4, const char **arg5, GError **error) -{ - *arg0 = 42; - *arg1 = g_strdup ("42"); - *arg2 = -67; - *arg3 = 2; - *arg4 = 26; - *arg5 = "hello world"; /* Annotation specifies as const */ - return TRUE; -} - -gboolean -my_object_stringify (MyObject *obj, GValue *value, char **ret, GError **error) -{ - GValue valstr = {0, }; - - g_value_init (&valstr, G_TYPE_STRING); - if (!g_value_transform (value, &valstr)) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "couldn't transform value"); - return FALSE; - } - *ret = g_value_dup_string (&valstr); - g_value_unset (&valstr); - return TRUE; -} - -gboolean -my_object_unstringify (MyObject *obj, const char *str, GValue *value, GError **error) -{ - if (str[0] == '\0' || !g_ascii_isdigit (str[0])) { - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, str); - } else { - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, (int) g_ascii_strtoull (str, NULL, 10)); - } - return TRUE; -} - -gboolean -my_object_recursive1 (MyObject *obj, GArray *array, guint32 *len_ret, GError **error) -{ - *len_ret = array->len; - return TRUE; -} - -gboolean -my_object_recursive2 (MyObject *obj, guint32 reqlen, GArray **ret, GError **error) -{ - guint32 val; - GArray *array; - - array = g_array_new (FALSE, TRUE, sizeof (guint32)); - - while (reqlen > 0) { - val = 42; - g_array_append_val (array, val); - val = 26; - g_array_append_val (array, val); - reqlen--; - } - val = 2; - g_array_append_val (array, val); - *ret = array; - return TRUE; -} - -gboolean -my_object_many_uppercase (MyObject *obj, const char * const *in, char ***out, GError **error) -{ - int len; - int i; - - len = g_strv_length ((char**) in); - - *out = g_new0 (char *, len + 1); - for (i = 0; i < len; i++) - { - (*out)[i] = g_ascii_strup (in[i], -1); - } - (*out)[i] = NULL; - - return TRUE; -} - -static void -hash_foreach_stringify (gpointer key, gpointer val, gpointer user_data) -{ - const char *keystr = key; - const GValue *value = val; - GValue *sval; - GHashTable *ret = user_data; - - sval = g_new0 (GValue, 1); - g_value_init (sval, G_TYPE_STRING); - if (!g_value_transform (value, sval)) - g_assert_not_reached (); - - g_hash_table_insert (ret, g_strdup (keystr), sval); -} - -static void -unset_and_free_gvalue (gpointer val) -{ - g_value_unset (val); - g_free (val); -} - -gboolean -my_object_many_stringify (MyObject *obj, GHashTable /* char * -> GValue * */ *vals, GHashTable /* char * -> GValue * */ **ret, GError **error) -{ - *ret = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, unset_and_free_gvalue); - g_hash_table_foreach (vals, hash_foreach_stringify, *ret); - return TRUE; -} - -gboolean -my_object_rec_arrays (MyObject *obj, GPtrArray *in, GPtrArray **ret, GError **error) -{ - char **strs; - GArray *ints; - guint v_UINT; - - if (in->len != 2) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid array len"); - return FALSE; - } - - strs = g_ptr_array_index (in, 0); - if (!*strs || strcmp (*strs, "foo")) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid string 0"); - return FALSE; - } - strs++; - if (!*strs || strcmp (*strs, "bar")) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid string 1"); - return FALSE; - } - strs++; - if (*strs) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid string array len in pos 0"); - return FALSE; - } - strs = g_ptr_array_index (in, 1); - if (!*strs || strcmp (*strs, "baz")) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid string 0"); - return FALSE; - } - strs++; - if (!*strs || strcmp (*strs, "whee")) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid string 1"); - return FALSE; - } - strs++; - if (!*strs || strcmp (*strs, "moo")) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid string 2"); - return FALSE; - } - strs++; - if (*strs) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid string array len in pos 1"); - return FALSE; - } - - *ret = g_ptr_array_new (); - - ints = g_array_new (TRUE, TRUE, sizeof (guint)); - v_UINT = 10; - g_array_append_val (ints, v_UINT); - v_UINT = 42; - g_array_append_val (ints, v_UINT); - v_UINT = 27; - g_array_append_val (ints, v_UINT); - g_ptr_array_add (*ret, ints); - - ints = g_array_new (TRUE, TRUE, sizeof (guint)); - v_UINT = 30; - g_array_append_val (ints, v_UINT); - g_ptr_array_add (*ret, ints); - return TRUE; -} - -gboolean -my_object_objpath (MyObject *obj, const char *incoming, const char **outgoing, GError **error) -{ - if (strcmp (incoming, "/org/freedesktop/DBus/Tests/MyTestObject")) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid incoming object"); - return FALSE; - } - *outgoing = "/org/freedesktop/DBus/Tests/MyTestObject2"; - return TRUE; -} - -gboolean -my_object_get_objs (MyObject *obj, GPtrArray **objs, GError **error) -{ - *objs = g_ptr_array_new (); - - g_ptr_array_add (*objs, g_strdup ("/org/freedesktop/DBus/Tests/MyTestObject")); - g_ptr_array_add (*objs, g_strdup ("/org/freedesktop/DBus/Tests/MyTestObject2")); - - return TRUE; -} - -static void -hash_foreach (gpointer key, gpointer val, gpointer user_data) -{ - const char *keystr = key; - const char *valstr = val; - guint *count = user_data; - - *count += (strlen (keystr) + strlen (valstr)); - g_print ("%s -> %s\n", keystr, valstr); -} - -gboolean -my_object_str_hash_len (MyObject *obj, GHashTable *table, guint *len, GError **error) -{ - *len = 0; - g_hash_table_foreach (table, hash_foreach, len); - return TRUE; -} - -gboolean -my_object_send_car (MyObject *obj, GValueArray *invals, GValueArray **outvals, GError **error) -{ - if (invals->n_values != 3 - || G_VALUE_TYPE (g_value_array_get_nth (invals, 0)) != G_TYPE_STRING - || G_VALUE_TYPE (g_value_array_get_nth (invals, 1)) != G_TYPE_UINT - || G_VALUE_TYPE (g_value_array_get_nth (invals, 2)) != G_TYPE_VALUE) - { - g_set_error (error, - MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "invalid incoming values"); - return FALSE; - } - *outvals = g_value_array_new (2); - g_value_array_append (*outvals, NULL); - g_value_init (g_value_array_get_nth (*outvals, (*outvals)->n_values - 1), G_TYPE_UINT); - g_value_set_uint (g_value_array_get_nth (*outvals, (*outvals)->n_values - 1), - g_value_get_uint (g_value_array_get_nth (invals, 1)) + 1); - g_value_array_append (*outvals, NULL); - g_value_init (g_value_array_get_nth (*outvals, (*outvals)->n_values - 1), DBUS_TYPE_G_OBJECT_PATH); - g_value_set_boxed (g_value_array_get_nth (*outvals, (*outvals)->n_values - 1), - g_strdup ("/org/freedesktop/DBus/Tests/MyTestObject2")); - return TRUE; -} - -gboolean -my_object_get_hash (MyObject *obj, GHashTable **ret, GError **error) -{ - GHashTable *table; - - table = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_insert (table, "foo", "bar"); - g_hash_table_insert (table, "baz", "whee"); - g_hash_table_insert (table, "cow", "crack"); - *ret = table; - return TRUE; -} - -gboolean -my_object_increment_val (MyObject *obj, GError **error) -{ - obj->val++; - return TRUE; -} - -gboolean -my_object_get_val (MyObject *obj, guint *ret, GError **error) -{ - *ret = obj->val; - return TRUE; -} - -gboolean -my_object_get_value (MyObject *obj, guint *ret, GError **error) -{ - *ret = obj->val; - return TRUE; -} - -gboolean -my_object_echo_variant (MyObject *obj, GValue *variant, GValue *ret, GError **error) -{ - GType t; - t = G_VALUE_TYPE(variant); - g_value_init (ret, t); - g_value_copy (variant, ret); - - return TRUE; -} - -gboolean -my_object_process_variant_of_array_of_ints123 (MyObject *obj, GValue *variant, GError **error) -{ - GArray *array; - int i; - int j; - - j = 0; - - array = (GArray *)g_value_get_boxed (variant); - - for (i = 0; i <= 2; i++) - { - j = g_array_index (array, int, i); - if (j != i + 1) - goto error; - } - - return TRUE; - -error: - *error = g_error_new (MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "Error decoding a variant of type ai (i + 1 = %i, j = %i)", - i, j + 1); - return FALSE; -} - - -typedef struct _HashAndString HashAndString; - -struct _HashAndString -{ - GHashTable *hash; - gchar* string; -}; - -static void -hash_foreach_prepend_string (gpointer key, gpointer val, gpointer user_data) -{ - HashAndString *data = (HashAndString*) user_data; - gchar *in = (gchar*) val; - g_hash_table_insert (data->hash, g_strdup ((gchar*) key), - g_strjoin (" ", data->string, in, NULL)); -} - - -static void -hash_foreach_mangle_dict_of_strings (gpointer key, gpointer val, gpointer user_data) -{ - GHashTable *out = (GHashTable*) user_data; - GHashTable *in_dict = (GHashTable *) val; - HashAndString *data = g_new0 (HashAndString, 1); - - data->string = (gchar*) key; - data->hash = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, g_free); - g_hash_table_foreach (in_dict, hash_foreach_prepend_string, data); - - g_hash_table_insert(out, g_strdup ((gchar*) key), data->hash); -} - -gboolean -my_object_dict_of_dicts (MyObject *obj, GHashTable *in, - GHashTable **out, GError **error) -{ - *out = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_hash_table_destroy); - g_hash_table_foreach (in, hash_foreach_mangle_dict_of_strings, *out); - return TRUE; -} - -gboolean -my_object_emit_frobnicate (MyObject *obj, GError **error) -{ - g_signal_emit (obj, signals[FROBNICATE], 0, 42); - return TRUE; -} - -gboolean -my_object_emit_signals (MyObject *obj, GError **error) -{ - GValue val = {0, }; - - g_signal_emit (obj, signals[SIG0], 0, "foo", 22, "moo"); - - g_value_init (&val, G_TYPE_STRING); - g_value_set_string (&val, "bar"); - g_signal_emit (obj, signals[SIG1], 0, "baz", &val); - g_value_unset (&val); - - return TRUE; -} - -gboolean -my_object_emit_signal2 (MyObject *obj, GError **error) -{ - GHashTable *table; - - table = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_insert (table, "baz", "cow"); - g_hash_table_insert (table, "bar", "foo"); - g_signal_emit (obj, signals[SIG2], 0, table); - g_hash_table_destroy (table); - return TRUE; -} - -typedef struct { - gint32 x; - DBusGMethodInvocation *context; -} IncrementData; - -static gboolean -do_async_increment (IncrementData *data) -{ - gint32 newx = data->x + 1; - dbus_g_method_return (data->context, newx); - g_free (data); - return FALSE; -} - -void -my_object_async_increment (MyObject *obj, gint32 x, DBusGMethodInvocation *context) -{ - IncrementData *data = g_new0 (IncrementData, 1); - data->x = x; - data->context = context; - g_idle_add ((GSourceFunc)do_async_increment, data); -} - -static gboolean -do_async_error (IncrementData *data) -{ - GError *error; - error = g_error_new (MY_OBJECT_ERROR, - MY_OBJECT_ERROR_FOO, - "%s", - "this method always loses"); - dbus_g_method_return_error (data->context, error); - g_free (data); - return FALSE; -} - -void -my_object_async_throw_error (MyObject *obj, DBusGMethodInvocation *context) -{ - IncrementData *data = g_new0(IncrementData, 1); - data->context = context; - g_idle_add ((GSourceFunc)do_async_error, data); -} - - -static GMainLoop *loop; - -gboolean -my_object_terminate (MyObject *obj, GError **error) -{ - g_main_loop_quit (loop); - return TRUE; -} - -#define TEST_SERVICE_NAME "org.freedesktop.DBus.TestSuiteGLibService" - -int -main (int argc, char **argv) -{ - DBusGConnection *connection; - GError *error; - DBusGProxy *driver_proxy; - guint32 request_name_ret; - - g_type_init (); - g_thread_init (NULL); dbus_g_thread_init (); - - dbus_g_object_type_install_info (MY_TYPE_OBJECT, - &dbus_glib_my_object_object_info); - - dbus_g_error_domain_register (MY_OBJECT_ERROR, - NULL, - MY_TYPE_ERROR); - - g_printerr ("Launching test-service-glib\n"); - - loop = g_main_loop_new (NULL, FALSE); - - { - GLogLevelFlags fatal_mask; - - fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); - fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; - g_log_set_always_fatal (fatal_mask); - } - - error = NULL; - connection = dbus_g_bus_get (DBUS_BUS_STARTER, - &error); - if (connection == NULL) - { - g_printerr ("Failed to open connection to bus: %s\n", - error->message); - g_error_free (error); - exit (1); - } - - obj = g_object_new (MY_TYPE_OBJECT, NULL); - obj2 = g_object_new (MY_TYPE_OBJECT, NULL); - - dbus_g_connection_register_g_object (connection, - "/org/freedesktop/DBus/Tests/MyTestObject", - obj); - dbus_g_connection_register_g_object (connection, - "/org/freedesktop/DBus/Tests/MyTestObject2", - obj2); - - driver_proxy = dbus_g_proxy_new_for_name (connection, - DBUS_SERVICE_DBUS, - DBUS_PATH_DBUS, - DBUS_INTERFACE_DBUS); - - if (!org_freedesktop_DBus_request_name (driver_proxy, - TEST_SERVICE_NAME, - 0, &request_name_ret, &error)) - { - g_assert (error != NULL); - g_printerr ("Failed to get name: %s\n", - error->message); - g_clear_error (&error); - exit (1); - } - - if (!(request_name_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)) - { - g_printerr ("Got result code %u from requesting name\n", request_name_ret); - exit (1); - } - - g_printerr ("GLib test service has name '%s'\n", TEST_SERVICE_NAME); - g_printerr ("GLib test service entering main loop\n"); - - g_main_loop_run (loop); - - g_printerr ("Successfully completed %s\n", argv[0]); - - return 0; -} diff --git a/test/glib/test-service-glib.xml b/test/glib/test-service-glib.xml deleted file mode 100644 index 91f1fe9c..00000000 --- a/test/glib/test-service-glib.xml +++ /dev/null @@ -1,179 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/glib/test-thread-client.c b/test/glib/test-thread-client.c deleted file mode 100644 index f63866fc..00000000 --- a/test/glib/test-thread-client.c +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include -#include -#include - -#include "test-thread.h" - -DBusConnection *connection; - -static gpointer -thread_func (gpointer data) -{ - gint32 threadnr = GPOINTER_TO_INT (data); - guint32 counter = 0; - DBusMessageIter iter; - DBusMessage *message; - char *str; - - while (1) - { - message = dbus_message_new_method_call (NULL, - "/org/freedesktop/ThreadTest", - "org.freedesktop.ThreadTest", - "TestMethod"); - - dbus_message_iter_init_append (message, &iter); - - if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &threadnr)) - { - g_print ("thread %d: append threadnr failed\n", threadnr); - } - - if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &counter)) - { - g_print ("thread %d: append counter (%d) failed\n", threadnr, counter); - } - - str = g_strdup_printf ("Thread %d-%d\n", threadnr, counter); - if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &str)) - { - g_print ("thread %d: append string (%s) failed\n", threadnr, str); - } - g_free (str); - - if (!dbus_connection_send (connection, - message, - NULL)) - { - g_print ("thread %d: send message failed\n", threadnr); - } - - dbus_message_unref (message); - - counter ++; - } - - return NULL; -} - -int -main (int argc, char *argv[]) -{ - GMainLoop *loop; - DBusError error; - int i; - - g_thread_init (NULL); - dbus_g_thread_init (); - - if(argc < 2) - { - g_error("Need an address as argv[1]\n"); - return 1; - } - - dbus_error_init (&error); - connection = dbus_connection_open (argv[1], &error); - if (connection == NULL) - { - g_printerr ("could not open connection: %s\n", error.message); - dbus_error_free (&error); - return 1; - } - - dbus_connection_setup_with_g_main (connection, NULL); - - for (i = 0; i < N_TEST_THREADS; i++) - { - g_thread_create (thread_func, GINT_TO_POINTER (i), FALSE, NULL); - } - - loop = g_main_loop_new (NULL, FALSE); - g_main_run (loop); - - return 0; -} - diff --git a/test/glib/test-thread-server.c b/test/glib/test-thread-server.c deleted file mode 100644 index 9b683983..00000000 --- a/test/glib/test-thread-server.c +++ /dev/null @@ -1,209 +0,0 @@ -#include -#include -#include -#include - -#include "test-thread.h" - -typedef struct { - guint32 counters[N_TEST_THREADS]; -} ThreadTestData; - -static ThreadTestData * -thread_test_data_new (void) -{ - ThreadTestData *data; - - data = g_new0 (ThreadTestData, 1); - - return data; -} - -static void -thread_test_data_free (ThreadTestData *data) -{ - g_free (data); -} - -static DBusHandlerResult -filter_test_message (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - ThreadTestData *data = user_data; - DBusMessageIter iter; - gint32 threadnr; - guint32 counter; - const char *str; - char *expected_str; - GString *counter_str; - int i; - - if (!dbus_message_is_method_call (message, "org.freedesktop.ThreadTest", - "TestMethod")) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_message_iter_init (message, &iter); - - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32) - { - g_print ("First arg not right type\n"); - goto out; - } - dbus_message_iter_get_basic (&iter, &threadnr); - if (threadnr < 0 || threadnr >= N_TEST_THREADS) - { - g_print ("Invalid thread nr\n"); - goto out; - } - - if (! dbus_message_iter_next (&iter)) - { - g_print ("Couldn't get second arg\n"); - goto out; - } - - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_UINT32) - { - g_print ("Second arg not right type\n"); - goto out; - } - - dbus_message_iter_get_basic (&iter, &counter); - - if (counter != data->counters[threadnr]) - { - g_print ("Thread %d, counter %d, expected %d\n", threadnr, counter, data->counters[threadnr]); - goto out; - } - data->counters[threadnr]++; - - if (! dbus_message_iter_next (&iter)) - { - g_print ("Couldn't get third arg\n"); - goto out; - } - - if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) - { - g_print ("Third arg not right type\n"); - goto out; - } - - dbus_message_iter_get_basic (&iter, &str); - - if (str == NULL) - { - g_print ("No third arg\n"); - goto out; - } - - expected_str = g_strdup_printf ("Thread %d-%d\n", threadnr, counter); - if (strcmp (expected_str, str) != 0) - { - g_print ("Wrong string '%s', expected '%s'\n", str, expected_str); - goto out; - } - g_free (expected_str); - - if (dbus_message_iter_next (&iter)) - { - g_print ("Extra args on end of message\n"); - goto out; - } - - dbus_connection_flush (connection); - - counter_str = g_string_new (""); - for (i = 0; i < N_TEST_THREADS; i++) - { - g_string_append_printf (counter_str, "%d ", data->counters[i]); - } - g_print ("%s\r", counter_str->str); - g_string_free (counter_str, TRUE); - - out: - return DBUS_HANDLER_RESULT_HANDLED; -} - -static DBusHandlerResult -filter_disconnect (DBusConnection *connection, - DBusMessage *message, - void *user_data) -{ - if (!dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, - "Disconnected")) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - g_print ("connection disconnected\n"); - dbus_connection_unref (connection); - - return DBUS_HANDLER_RESULT_HANDLED; -} - -static void -new_connection_callback (DBusServer *server, - DBusConnection *new_connection, - void *user_data) -{ - ThreadTestData * data; - - g_print ("new_connection_callback\n"); - - dbus_connection_ref (new_connection); - dbus_connection_setup_with_g_main (new_connection, NULL); - - data = thread_test_data_new (); - - if (!dbus_connection_add_filter (new_connection, - filter_test_message, data, - (DBusFreeFunction) thread_test_data_free)) - goto nomem; - - if (!dbus_connection_add_filter (new_connection, - filter_disconnect, NULL, NULL)) - goto nomem; - - return; - - nomem: - g_error ("no memory to setup new connection"); -} - -int -main (int argc, char *argv[]) -{ - GMainLoop *loop; - DBusServer *server; - DBusError error; - - g_thread_init (NULL); - dbus_g_thread_init (); - - if (argc < 2) - { - fprintf (stderr, "Give the server address as an argument\n"); - return 1; - } - - dbus_error_init (&error); - server = dbus_server_listen (argv[1], &error); - if (server == NULL) - { - fprintf (stderr, "Failed to start server on %s: %s\n", - argv[1], error.message); - dbus_error_free (&error); - return 1; - } - - dbus_server_set_new_connection_function (server, - new_connection_callback, - NULL, NULL); - - dbus_server_setup_with_g_main (server, NULL); - - loop = g_main_loop_new (NULL, FALSE); - g_main_run (loop); - - return 0; -} diff --git a/test/glib/test-thread.h b/test/glib/test-thread.h deleted file mode 100644 index 8c78fba2..00000000 --- a/test/glib/test-thread.h +++ /dev/null @@ -1 +0,0 @@ -#define N_TEST_THREADS 5 diff --git a/test/python/.cvsignore b/test/python/.cvsignore deleted file mode 100644 index f5e130db..00000000 --- a/test/python/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Makefile -Makefile.in -run-with-tmp-session-bus.conf diff --git a/test/python/Makefile.am b/test/python/Makefile.am deleted file mode 100644 index 5e4da980..00000000 --- a/test/python/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -## 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 -## TESTS -if DBUS_BUILD_TESTS -TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=$(ABSOLUTE_TOP_BUILDDIR) -TESTS=run-test.sh -else -TESTS= -endif - -EXTRA_DIST=run-test.sh test-service.py test-client.py diff --git a/test/python/run-test.sh b/test/python/run-test.sh deleted file mode 100755 index a50a5f48..00000000 --- a/test/python/run-test.sh +++ /dev/null @@ -1,42 +0,0 @@ -#! /bin/bash - -function die() -{ - if ! test -z "$DBUS_SESSION_BUS_PID" ; then - echo "killing message bus "$DBUS_SESSION_BUS_PID >&2 - kill -9 $DBUS_SESSION_BUS_PID - fi - echo $SCRIPTNAME: $* >&2 - - rm $DBUS_TOP_BUILDDIR/python/dbus - - exit 1 -} - - -SCRIPTNAME=$0 -MODE=$1 - -## so the tests can complain if you fail to use the script to launch them -export DBUS_TEST_PYTHON_RUN_TEST_SCRIPT=1 - -# Rerun ourselves with tmp session bus if we're not already -if test -z "$DBUS_TEST_PYTHON_IN_RUN_TEST"; then - DBUS_TEST_PYTHON_IN_RUN_TEST=1 - export DBUS_TEST_PYTHON_IN_RUN_TEST - exec $DBUS_TOP_BUILDDIR/tools/run-with-tmp-session-bus.sh $SCRIPTNAME $MODE -fi - -ln -s $DBUS_TOP_BUILDDIR/python $DBUS_TOP_BUILDDIR/python/dbus -echo "running test-client.py" -#uncomment this if you need to see the output from the service for debugging -#otherwise keep it commented so we can test activation -#libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/python/test-service.py & -#libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/glib/test-service-glib & -#sleep 1 -#ps -#sleep 9 - -libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/python/test-client.py || die "test-client.py failed" -rm $DBUS_TOP_BUILDDIR/python/dbus - diff --git a/test/python/test-client.py b/test/python/test-client.py deleted file mode 100755 index f6ef12ba..00000000 --- a/test/python/test-client.py +++ /dev/null @@ -1,306 +0,0 @@ -#!/usr/bin/env python -import sys -import os -import unittest -import time - -builddir = os.environ["DBUS_TOP_BUILDDIR"] -pydir = builddir + "/python" - -sys.path.insert(0, pydir) -sys.path.insert(0, pydir + "/.libs") - -import dbus -import dbus_bindings -import gobject -import dbus.glib -import dbus.service - -if not dbus.__file__.startswith(pydir): - raise Exception("DBus modules are not being picked up from the package") - -if not dbus_bindings.__file__.startswith(pydir): - raise Exception("DBus modules are not being picked up from the package") - -test_types_vals = [1, 12323231, 3.14159265, 99999999.99, - "dude", "123", "What is all the fuss about?", "gob@gob.com", - u'\\u310c\\u310e\\u3114', u'\\u0413\\u0414\\u0415', - u'\\u2200software \\u2203crack', u'\\xf4\\xe5\\xe8', - [1,2,3], ["how", "are", "you"], [1.23,2.3], [1], ["Hello"], - (1,2,3), (1,), (1,"2",3), ("2", "what"), ("you", 1.2), - {1:"a", 2:"b"}, {"a":1, "b":2}, #{"a":(1,"B")}, - {1:1.1, 2:2.2}, [[1,2,3],[2,3,4]], [["a","b"],["c","d"]], - True, False, - dbus.Int16(-10), dbus.UInt16(10), - #([1,2,3],"c", 1.2, ["a","b","c"], {"a": (1,"v"), "b": (2,"d")}) - ] - -class TestDBusBindings(unittest.TestCase): - def setUp(self): - self.bus = dbus.SessionBus() - self.remote_object = self.bus.get_object("org.freedesktop.DBus.TestSuitePythonService", "/org/freedesktop/DBus/TestSuitePythonObject") - self.iface = dbus.Interface(self.remote_object, "org.freedesktop.DBus.TestSuiteInterface") - - def testInterfaceKeyword(self): - #test dbus_interface parameter - print self.remote_object.Echo("dbus_interface on Proxy test Passed", dbus_interface = "org.freedesktop.DBus.TestSuiteInterface") - print self.iface.Echo("dbus_interface on Interface test Passed", dbus_interface = "org.freedesktop.DBus.TestSuiteInterface") - self.assert_(True) - - def testIntrospection(self): - #test introspection - print "\n********* Introspection Test ************" - print self.remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable") - print "Introspection test passed" - self.assert_(True) - - def testPythonTypes(self): - #test sending python types and getting them back - print "\n********* Testing Python Types ***********" - - for send_val in test_types_vals: - print "Testing %s"% str(send_val) - recv_val = self.iface.Echo(send_val) - self.assertEquals(send_val, recv_val) - - def testBenchmarkIntrospect(self): - print "\n********* Benchmark Introspect ************" - a = time.time() - print a - print self.iface.GetComplexArray() - b = time.time() - print b - print "Delta: %f" % (b - a) - self.assert_(True) - - def testAsyncCalls(self): - #test sending python types and getting them back async - print "\n********* Testing Async Calls ***********" - - - main_loop = gobject.MainLoop() - class async_check: - def __init__(self, test_controler, expected_result, do_exit): - self.expected_result = expected_result - self.do_exit = do_exit - self.test_controler = test_controler - - def callback(self, val): - try: - if self.do_exit: - main_loop.quit() - - self.test_controler.assertEquals(val, self.expected_result) - except Exception, e: - print "%s:\n%s" % (e.__class__, e) - - def error_handler(self, error): - print error - if self.do_exit: - main_loop.quit() - - self.test_controler.assert_(val, False) - - last_type = test_types_vals[-1] - for send_val in test_types_vals: - print "Testing %s"% str(send_val) - check = async_check(self, send_val, last_type == send_val) - recv_val = self.iface.Echo(send_val, - reply_handler = check.callback, - error_handler = check.error_handler) - - main_loop.run() - - def testStrictMarshalling(self): - print "\n********* Testing strict return & signal marshalling ***********" - - # these values are the same as in the server, and the - # methods should only succeed when they are called with - # the right value number, because they have out_signature - # decorations, and return an unmatching type when called - # with a different number - values = ["", ("",""), ("","",""), [], {}, ["",""], ["","",""]] - methods = [ - (self.iface.ReturnOneString, 'SignalOneString', set([0]), set([0])), - (self.iface.ReturnTwoStrings, 'SignalTwoStrings', set([1, 5]), set([5])), - (self.iface.ReturnStruct, 'SignalStruct', set([1, 5]), set([1])), - # all of our test values are sequences so will marshall correctly into an array :P - (self.iface.ReturnArray, 'SignalArray', set(range(len(values))), set([3, 5, 6])), - (self.iface.ReturnDict, 'SignalDict', set([0, 3, 4]), set([4])) - ] - - for (method, signal, success_values, return_values) in methods: - print "\nTrying correct behaviour of", method._method_name - for value in range(len(values)): - try: - ret = method(value) - except Exception, e: - print "%s(%r) raised %s" % (method._method_name, values[value], e.__class__) - - # should fail if it tried to marshal the wrong type - self.assert_(value not in success_values, "%s should succeed when we ask it to return %r\n%s\n%s" % (method._method_name, values[value], e.__class__, e)) - else: - print "%s(%r) returned %r" % (method._method_name, values[value], ret) - - # should only succeed if it's the right return type - self.assert_(value in success_values, "%s should fail when we ask it to return %r" % (method._method_name, values[value])) - - # check the value is right too :D - returns = map(lambda n: values[n], return_values) - self.assert_(ret in returns, "%s should return one of %r" % (method._method_name, returns)) - - print "\nTrying correct emission of", signal - for value in range(len(values)): - try: - self.iface.EmitSignal(signal, value) - except Exception, e: - print "EmitSignal(%s, %r) raised %s" % (signal, values[value], e.__class__) - - # should fail if it tried to marshal the wrong type - self.assert_(value not in success_values, "EmitSignal(%s) should succeed when we ask it to return %r\n%s\n%s" % (signal, values[value], e.__class__, e)) - else: - print "EmitSignal(%s, %r) appeared to succeed" % (signal, values[value]) - - # should only succeed if it's the right return type - self.assert_(value in success_values, "EmitSignal(%s) should fail when we ask it to return %r" % (signal, values[value])) - - # FIXME: wait for the signal here - - print - - def testInheritance(self): - print "\n********* Testing inheritance from dbus.method.Interface ***********" - ret = self.iface.CheckInheritance() - print "CheckInheritance returned %s" % ret - self.assert_(ret, "overriding CheckInheritance from TestInterface failed") - - def testAsyncMethods(self): - print "\n********* Testing asynchronous method implementation *******" - for (async, fail) in ((False, False), (False, True), (True, False), (True, True)): - try: - val = ('a', 1, False, [1,2], {1:2}) - print "calling AsynchronousMethod with %s %s %s" % (async, fail, val) - ret = self.iface.AsynchronousMethod(async, fail, val) - except Exception, e: - print "%s:\n%s" % (e.__class__, e) - self.assert_(fail) - else: - self.assert_(not fail) - print val, ret - self.assert_(val == ret) - - def testBusInstanceCaching(self): - print "\n********* Testing dbus.Bus instance sharing *********" - - # unfortunately we can't test the system bus here - # but the codepaths are the same - for (cls, type, func) in ((dbus.SessionBus, dbus.Bus.TYPE_SESSION, dbus.Bus.get_session), (dbus.StarterBus, dbus.Bus.TYPE_STARTER, dbus.Bus.get_starter)): - print "\nTesting %s:" % cls.__name__ - - share_cls = cls() - share_type = dbus.Bus(bus_type=type) - share_func = func() - - private_cls = cls(private=True) - private_type = dbus.Bus(bus_type=type, private=True) - private_func = func(private=True) - - print " - checking shared instances are the same..." - self.assert_(share_cls == share_type, '%s should equal %s' % (share_cls, share_type)) - self.assert_(share_type == share_func, '%s should equal %s' % (share_type, share_func)) - - print " - checking private instances are distinct from the shared instance..." - self.assert_(share_cls != private_cls, '%s should not equal %s' % (share_cls, private_cls)) - self.assert_(share_type != private_type, '%s should not equal %s' % (share_type, private_type)) - self.assert_(share_func != private_func, '%s should not equal %s' % (share_func, private_func)) - - print " - checking private instances are distinct from each other..." - self.assert_(private_cls != private_type, '%s should not equal %s' % (private_cls, private_type)) - self.assert_(private_type != private_func, '%s should not equal %s' % (private_type, private_func)) - self.assert_(private_func != private_cls, '%s should not equal %s' % (private_func, private_cls)) - - def testSenderName(self): - print '\n******** Testing sender name keyword ********' - myself = self.iface.WhoAmI() - print "I am", myself - - def testBusNameCreation(self): - print '\n******** Testing BusName creation ********' - test = [('org.freedesktop.DBus.Python.TestName', True), - ('org.freedesktop.DBus.Python.TestName', True), - ('org.freedesktop.DBus.Python.InvalidName&^*%$', False)] - # Do some more intelligent handling/testing of queueing vs success? - # ('org.freedesktop.DBus.TestSuitePythonService', False)] - # For some reason this actually succeeds - # ('org.freedesktop.DBus', False)] - - # make a method call to ensure the test service is active - self.iface.Echo("foo") - - names = {} - for (name, succeed) in test: - try: - print "requesting %s" % name - busname = dbus.service.BusName(name) - except Exception, e: - print "%s:\n%s" % (e.__class__, e) - self.assert_(not succeed, 'did not expect registering bus name %s to fail' % name) - else: - print busname - self.assert_(succeed, 'expected registering bus name %s to fail'% name) - if name in names: - self.assert_(names[name] == busname, 'got a new instance for same name %s' % name) - print "instance of %s re-used, good!" % name - else: - names[name] = busname - - del busname - - print - - del names - - bus = dbus.Bus() - ret = dbus.dbus_bindings.bus_name_has_owner(bus._connection, 'org.freedesktop.DBus.Python.TestName') - self.assert_(not ret, 'deleting reference failed to release BusName org.freedesktop.DBus.Python.TestName') - - -class TestDBusPythonToGLibBindings(unittest.TestCase): - def setUp(self): - self.bus = dbus.SessionBus() - self.remote_object = self.bus.get_object("org.freedesktop.DBus.TestSuiteGLibService", "/org/freedesktop/DBus/Tests/MyTestObject") - self.iface = dbus.Interface(self.remote_object, "org.freedesktop.DBus.Tests.MyObject") - - def testIntrospection(self): - #test introspection - print "\n********* Introspection Test ************" - print self.remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable") - print "Introspection test passed" - self.assert_(True) - - def testCalls(self): - print "\n********* Call Test ************" - result = self.iface.ManyArgs(1000, 'Hello GLib', 2) - print result - self.assert_(result == [2002.0, 'HELLO GLIB']) - - arg0 = {"Dude": 1, "john": "palmieri", "python": 2.4} - result = self.iface.ManyStringify(arg0) - print result - - print "Call test passed" - self.assert_(True) - - def testPythonTypes(self): - print "\n********* Testing Python Types ***********" - - for send_val in test_types_vals: - print "Testing %s"% str(send_val) - recv_val = self.iface.EchoVariant(send_val) - self.assertEquals(send_val, recv_val) - -if __name__ == '__main__': - gobject.threads_init() - dbus.glib.init_threads() - - unittest.main() diff --git a/test/python/test-service.py b/test/python/test-service.py deleted file mode 100755 index e8213805..00000000 --- a/test/python/test-service.py +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env python -import sys -import os - -builddir = os.environ["DBUS_TOP_BUILDDIR"] -pydir = builddir + "/python" - -sys.path.insert(0, pydir) -sys.path.insert(0, pydir + '/.libs') - -import dbus - -if not dbus.__file__.startswith(pydir): - raise Exception("DBus modules are not being picked up from the package") - -import dbus.service -import dbus.glib -import gobject -import random - -class TestInterface(dbus.service.Interface): - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='', out_signature='b') - def CheckInheritance(self): - return False - -class TestObject(dbus.service.Object, TestInterface): - def __init__(self, bus_name, object_path="/org/freedesktop/DBus/TestSuitePythonObject"): - dbus.service.Object.__init__(self, bus_name, object_path) - - """ Echo whatever is sent - """ - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface") - def Echo(self, arg): - return arg - - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface") - def GetComplexArray(self): - ret = [] - for i in range(0,100): - ret.append((random.randint(0,100), random.randint(0,100), str(random.randint(0,100)))) - - return dbus.Array(ret, signature="(uus)") - - def returnValue(self, test): - if test == 0: - return "" - elif test == 1: - return "","" - elif test == 2: - return "","","" - elif test == 3: - return [] - elif test == 4: - return {} - elif test == 5: - return ["",""] - elif test == 6: - return ["","",""] - - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='s') - def ReturnOneString(self, test): - return self.returnValue(test) - - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='ss') - def ReturnTwoStrings(self, test): - return self.returnValue(test) - - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='(ss)') - def ReturnStruct(self, test): - return self.returnValue(test) - - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='as') - def ReturnArray(self, test): - return self.returnValue(test) - - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='a{ss}') - def ReturnDict(self, test): - return self.returnValue(test) - - @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='s') - def SignalOneString(self, test): - pass - - @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='ss') - def SignalTwoStrings(self, test, test2): - pass - - @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='(ss)') - def SignalStruct(self, test): - pass - - @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='as') - def SignalArray(self, test): - pass - - @dbus.service.signal("org.freedesktop.DBus.TestSuiteInterface", signature='a{ss}') - def SignalDict(self, test): - pass - - @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='su', out_signature='') - def EmitSignal(self, signal, value): - sig = getattr(self, signal, None) - assert(sig != None) - - val = self.returnValue(value) - # make two string case work by passing arguments in by tuple - if (signal == 'SignalTwoStrings' and (value == 1 or value == 5)): - val = tuple(val) - else: - val = tuple([val]) - - sig(*val) - - def CheckInheritance(self): - return True - - @dbus.service.method('org.freedesktop.DBus.TestSuiteInterface', in_signature='bbv', out_signature='v', async_callbacks=('return_cb', 'error_cb')) - def AsynchronousMethod(self, async, fail, variant, return_cb, error_cb): - try: - if async: - gobject.timeout_add(500, self.AsynchronousMethod, False, fail, variant, return_cb, error_cb) - return - else: - if fail: - raise RuntimeError - else: - return_cb(variant) - - return False # do not run again - except Exception, e: - error_cb(e) - - @dbus.service.method('org.freedesktop.DBus.TestSuiteInterface', in_signature='', out_signature='s', sender_keyword='sender') - def WhoAmI(self, sender): - return sender - -session_bus = dbus.SessionBus() -name = dbus.service.BusName("org.freedesktop.DBus.TestSuitePythonService", bus=session_bus) -object = TestObject(name) -loop = gobject.MainLoop() -loop.run() diff --git a/test/qt/.cvsignore b/test/qt/.cvsignore deleted file mode 100644 index f6454f28..00000000 --- a/test/qt/.cvsignore +++ /dev/null @@ -1,11 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la -*.bb -*.bbg -*.da -*.gcov -*.moc diff --git a/test/qt/Makefile.am b/test/qt/Makefile.am deleted file mode 100644 index 8ebd3323..00000000 --- a/test/qt/Makefile.am +++ /dev/null @@ -1,38 +0,0 @@ -INCLUDES=-I$(top_srcdir) -I$(top_srcdir)/qt $(DBUS_CLIENT_CFLAGS) $(DBUS_QT_CFLAGS) $(DBUS_QTESTLIB_CFLAGS) -DDBUS_COMPILATION - -if DBUS_BUILD_TESTS -TEST_BINARIES = tst_headertest tst_qdbusxmlparser tst_qdbusconnection qpong tst_qdbusmarshall tst_qdbusinterface tst_qdbusabstractadaptor tst_hal -TESTS= -else -TEST_BINARIES= -TESTS= -endif - -noinst_PROGRAMS= $(TEST_BINARIES) - -qpong_SOURCES= qpong.cpp -tst_headertest_SOURCES = tst_headertest.cpp -tst_qdbusconnection_SOURCES = tst_qdbusconnection.cpp -tst_qdbusxmlparser_SOURCES = tst_qdbusxmlparser.cpp -tst_qdbusmarshall_SOURCES = tst_qdbusmarshall.cpp -tst_qdbusinterface_SOURCES = tst_qdbusinterface.cpp -tst_qdbusabstractadaptor_SOURCES = tst_qdbusabstractadaptor.cpp common.h -tst_hal_SOURCES = tst_hal.cpp - -qpong.o: qpong.moc -tst_qdbusxmlparser.o: tst_qdbusxmlparser.moc -tst_qdbusmarshall.o: tst_qdbusmarshall.moc -tst_qdbusconnection.o: tst_qdbusconnection.moc -tst_qdbusinterface.o: tst_qdbusinterface.moc -tst_qdbusabstractadaptor.o: tst_qdbusabstractadaptor.moc -tst_hal.o: tst_hal.moc - -%.moc: %.cpp - $(QT_MOC) $< > $@ - -TEST_LIBS=$(DBUS_QTESTLIB_LIBS) $(top_builddir)/qt/src/libdbus-qt4-1.la - -LDADD=$(TEST_LIBS) - -clean-local: - -rm *.moc diff --git a/test/qt/common.h b/test/qt/common.h deleted file mode 100644 index 58beae4e..00000000 --- a/test/qt/common.h +++ /dev/null @@ -1,264 +0,0 @@ -#include // isnan - -Q_DECLARE_METATYPE(QVariant) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QList) -Q_DECLARE_METATYPE(QList) -#ifdef USE_PRIVATE_CODE -#include "../../qt/src/qdbusintrospection_p.h" - -// just to make it easier: -typedef QDBusIntrospection::Interfaces InterfaceMap; -typedef QDBusIntrospection::Objects ObjectMap; -typedef QDBusIntrospection::Arguments ArgumentList; -typedef QDBusIntrospection::Annotations AnnotationsMap; -typedef QDBusIntrospection::Methods MethodMap; -typedef QDBusIntrospection::Signals SignalMap; -typedef QDBusIntrospection::Properties PropertyMap; - -Q_DECLARE_METATYPE(QDBusIntrospection::Method) -Q_DECLARE_METATYPE(QDBusIntrospection::Signal) -Q_DECLARE_METATYPE(QDBusIntrospection::Property) -Q_DECLARE_METATYPE(MethodMap) -Q_DECLARE_METATYPE(SignalMap) -Q_DECLARE_METATYPE(PropertyMap) - -inline QDBusIntrospection::Argument arg(const char* type, const char *name = 0) -{ - QDBusIntrospection::Argument retval; - retval.type = QLatin1String(type); - retval.name = QLatin1String(name); - return retval; -} - -template -inline QMap& operator<<(QMap& map, const T& m) -{ map.insertMulti(m.name, m); return map; } - -inline const char* mapName(const MethodMap&) -{ return "MethodMap"; } - -inline const char* mapName(const SignalMap&) -{ return "SignalMap"; } - -inline const char* mapName(const PropertyMap&) -{ return "PropertyMap"; } - -QString printable(const QDBusIntrospection::Method& m) -{ - QString result = "method " + m.name + "("; - foreach (QDBusIntrospection::Argument arg, m.inputArgs) - result += QString("in %1 %2, ") - .arg(arg.type, arg.name); - foreach (QDBusIntrospection::Argument arg, m.outputArgs) - result += QString("out %1 %2, ") - .arg(arg.type, arg.name); - AnnotationsMap::const_iterator it = m.annotations.begin(); - for ( ; it != m.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); - - result += ")"; - return result; -} - -QString printable(const QDBusIntrospection::Signal& s) -{ - QString result = "signal " + s.name + "("; - foreach (QDBusIntrospection::Argument arg, s.outputArgs) - result += QString("out %1 %2, ") - .arg(arg.type, arg.name); - AnnotationsMap::const_iterator it = s.annotations.begin(); - for ( ; it != s.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); - - result += ")"; - return result; -} - -QString printable(const QDBusIntrospection::Property& p) -{ - QString result; - if (p.access == QDBusIntrospection::Property::Read) - result = "property read %1 %2, "; - else if (p.access == QDBusIntrospection::Property::Write) - result = "property write %1 %2, "; - else - result = "property readwrite %1 %2, "; - result = result.arg(p.type, p.name); - - AnnotationsMap::const_iterator it = p.annotations.begin(); - for ( ; it != p.annotations.end(); ++it) - result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); - - return result; -} - -template -char* printableMap(const QMap& map) -{ - QString contents = "\n"; - typename QMap::const_iterator it = map.begin(); - for ( ; it != map.end(); ++it) { - if (it.key() != it.value().name) - contents += it.value().name + ":"; - contents += printable(it.value()); - contents += ";\n"; - } - - QString result("%1(size = %2): {%3}"); - return qstrdup(qPrintable(result - .arg(mapName(map)) - .arg(map.size()) - .arg(contents))); -} - -namespace QTest { - template<> - inline char* toString(const MethodMap& map) - { - return printableMap(map); - } - - template<> - inline char* toString(const SignalMap& map) - { - return printableMap(map); - } - - template<> - inline char* toString(const PropertyMap& map) - { - return printableMap(map); - } -} -#endif -bool compare(const QVariantList &l1, const QVariantList &l2); -bool compare(const QVariantMap &m1, const QVariantMap &m2); -bool compare(const QVariant &v1, const QVariant &v2); - -bool compare(const QList &l1, const QList &l2) -{ - if (l1.count() != l2.count()) - return false; - - QList::ConstIterator it1 = l1.constBegin(); - QList::ConstIterator it2 = l2.constBegin(); - QList::ConstIterator end = l1.constEnd(); - for ( ; it1 != end; ++it1, ++it2) - if (isnan(*it1) && isnan(*it2)) - continue; - else if (*it1 != *it2) - return false; - return true; -} - -bool compare(const QString &s1, const QString &s2) -{ - if (s1.isEmpty() && s2.isEmpty()) - return true; // regardless of whether one of them is null - return s1 == s2; -} - -bool compare(const QByteArray &ba1, const QByteArray &ba2) -{ - if (ba1.isEmpty() && ba2.isEmpty()) - return true; // regardless of whether one of them is null - return ba1 == ba2; -} - -bool compare(const QVariant &v1, const QVariant &v2) -{ - if (v1.userType() != v2.userType()) - return false; - - int id = v1.userType(); - if (id == QVariant::List) - return compare(v1.toList(), v2.toList()); - - else if (id == QVariant::Map) - return compare(v1.toMap(), v2.toMap()); - - else if (id == QVariant::String) - return compare(v1.toString(), v2.toString()); - - else if (id == QVariant::ByteArray) - return compare(v1.toByteArray(), v2.toByteArray()); - - else if (id < int(QVariant::UserType)) // yes, v1.type() - // QVariant can compare - return v1 == v2; - - else if (id == QMetaType::UChar) - return qvariant_cast(v1) == qvariant_cast(v2); - - else if (id == QMetaType::Short) - return qvariant_cast(v1) == qvariant_cast(v2); - - else if (id == QMetaType::UShort) - return qvariant_cast(v1) == qvariant_cast(v2); - - else if (id == qMetaTypeId()) - return compare(qvariant_cast(v1), qvariant_cast(v2)); - - else if (id == qMetaTypeId >()) - return qvariant_cast >(v1) == qvariant_cast >(v2); - - else if (id == qMetaTypeId >()) - return qvariant_cast >(v1) == qvariant_cast >(v2); - - else if (id == qMetaTypeId >()) - return qvariant_cast >(v1) == qvariant_cast >(v2); - - else if (id == qMetaTypeId >()) - return qvariant_cast >(v1) == qvariant_cast >(v2); - - else if (id == qMetaTypeId >()) - return qvariant_cast >(v1) == qvariant_cast >(v2); - - else if (id == qMetaTypeId >()) - return qvariant_cast >(v1) == qvariant_cast >(v2); - - else if (id == qMetaTypeId >()) - return qvariant_cast >(v2) == qvariant_cast >(v2); - - else if (id == qMetaTypeId >()) - return compare(qvariant_cast >(v1), qvariant_cast >(v2)); - - else - return false; // unknown type -} - -bool compare(const QVariantList &l1, const QVariantList &l2) -{ - if (l1.count() != l2.size()) - return false; - QVariantList::ConstIterator i1 = l1.constBegin(); - QVariantList::ConstIterator i2 = l2.constBegin(); - QVariantList::ConstIterator end = l1.constEnd(); - for ( ; i1 != end; ++i1, ++i2) { - if (!compare(*i1, *i2)) - return false; - } - return true; -} - -bool compare(const QVariantMap &m1, const QVariantMap &m2) -{ - if (m1.count() != m2.size()) - return false; - QVariantMap::ConstIterator i1 = m1.constBegin(); - QVariantMap::ConstIterator end = m1.constEnd(); - for ( ; i1 != end; ++i1) { - QVariantMap::ConstIterator i2 = m2.find(i1.key()); - if (i2 == m2.constEnd()) - return false; - if (!compare(*i1, *i2)) - return false; - } - return true; -} diff --git a/test/qt/qpong.cpp b/test/qt/qpong.cpp deleted file mode 100644 index cad04eb6..00000000 --- a/test/qt/qpong.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include - -class Pong: public QObject -{ - Q_OBJECT -public slots: - - void ping(const QDBusMessage &msg) - { - QDBusMessage reply = QDBusMessage::methodReply(msg); - reply << static_cast >(msg); - reply.setSignature(msg.signature()); - if (!msg.connection().send(reply)) - exit(1); - } -}; - -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - - QDBusConnection &con = QDBus::sessionBus(); - if (!con.isConnected()) - exit(1); - - if (con.busService()->requestName("org.kde.selftest", QDBusBusService::DoNotQueueName).isError()) - exit(2); - - Pong pong; - con.registerObject("/org/kde/selftest", &pong, QDBusConnection::ExportSlots); - - printf("ready.\n"); - - return app.exec(); -} - -#include "qpong.moc" diff --git a/test/qt/tst_hal.cpp b/test/qt/tst_hal.cpp deleted file mode 100644 index a69daf2f..00000000 --- a/test/qt/tst_hal.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include - -#include -#include - -class tst_Hal: public QObject -{ - Q_OBJECT - -private slots: - void getDevices(); - void lock(); -}; - -class Spy: public QObject -{ - Q_OBJECT -public: - int count; - QDBusConnection &conn; - - Spy(QDBusConnection &c) : count(0), conn(c) - { } - -public slots: - void spySlot(int, const QVariantList&) - { - ++count; - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.Hal", - "/org/freedesktop/Hal/devices/acpi_CPU0", - "org.freedesktop.Hal.Device", "GetProperty"); - msg << "info.locked"; - - QDBusMessage reply = conn.sendWithReply(msg); - QVERIFY(!reply.isEmpty()); - } -}; - - -void tst_Hal::getDevices() -{ - QDBusConnection &con = QDBus::systemBus(); - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.Hal", - "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal.Manager", - "GetAllDevices"); - - QDBusMessage reply = con.sendWithReply(msg); - QVERIFY(!reply.isEmpty()); - QVERIFY(reply.type() == QDBusMessage::ReplyMessage); - //qDebug() << reply; -} - -void tst_Hal::lock() -{ - QDBusConnection &con = QDBus::systemBus(); - QVERIFY(con.isConnected()); - - Spy spy( con ); - - con.connect("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/acpi_CPU0", - "org.freedesktop.Hal.Device", "PropertyModified", - &spy, SLOT(spySlot(int, QVariantList))); - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.Hal", - "/org/freedesktop/Hal/devices/acpi_CPU0", "org.freedesktop.Hal.Device", - "Lock"); - msg << "No reason..."; - - QDBusMessage reply = con.sendWithReply(msg); - //QTest::qWait(200); - //qDebug() << reply; - QCOMPARE(spy.count, 3); - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); -} - -QTEST_MAIN(tst_Hal) - -#include "tst_hal.moc" diff --git a/test/qt/tst_headertest.cpp b/test/qt/tst_headertest.cpp deleted file mode 100644 index eb90c555..00000000 --- a/test/qt/tst_headertest.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#define QT_NO_KEYWORDS -#define signals Choke! -#define slots Choke! -#define emit Choke! -#define foreach Choke! -#define forever Choke! - -#define QT_NO_CAST_FROM_ASCII -#define QT_NO_CAST_TO_ASCII - -#include - -int main(int, char **) -{ - return 0; -} diff --git a/test/qt/tst_qdbusabstractadaptor.cpp b/test/qt/tst_qdbusabstractadaptor.cpp deleted file mode 100644 index d47c5436..00000000 --- a/test/qt/tst_qdbusabstractadaptor.cpp +++ /dev/null @@ -1,989 +0,0 @@ -#include -#include - -#include - -#include - -#include "common.h" - -#ifdef Q_CC_MSVC -#define __PRETTY_FUNCTION__ __FUNCDNAME__ -#endif - -const char *slotSpy; -QString valueSpy; - -namespace QTest { - char *toString(QDBusMessage::MessageType t) - { - switch (t) - { - case QDBusMessage::InvalidMessage: - return qstrdup("InvalidMessage"); - case QDBusMessage::MethodCallMessage: - return qstrdup("MethodCallMessage"); - case QDBusMessage::ReplyMessage: - return qstrdup("ReplyMessage"); - case QDBusMessage::ErrorMessage: - return qstrdup("ErrorMessage"); - case QDBusMessage::SignalMessage: - return qstrdup("SignalMessage"); - default: - return 0; - } - } -} - -class tst_QDBusAbstractAdaptor: public QObject -{ - Q_OBJECT - -private slots: - void methodCalls_data(); - void methodCalls(); - void signalEmissions_data(); - void signalEmissions(); - void sameSignalDifferentPaths(); - void overloadedSignalEmission_data(); - void overloadedSignalEmission(); - void readProperties(); - void writeProperties(); - - void typeMatching_data(); - void typeMatching(); -}; - -class QDBusSignalSpy: public QObject -{ - Q_OBJECT - -public slots: - void slot(const QDBusMessage &msg) - { - ++count; - interface = msg.interface(); - name = msg.name(); - signature = msg.signature(); - value.clear(); - if (msg.count()) - value = msg.at(0); - } - -public: - QDBusSignalSpy() : count(0) { } - - int count; - QString interface; - QString name; - QString signature; - QVariant value; -}; - -class Interface1: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "local.Interface1") -public: - Interface1(QObject *parent) : QDBusAbstractAdaptor(parent) - { } -}; - -class Interface2: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "local.Interface2") - Q_PROPERTY(QString prop1 READ prop1) - Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2) -public: - Interface2(QObject *parent) : QDBusAbstractAdaptor(parent) - { setAutoRelaySignals(true); } - - QString prop1() const - { return __PRETTY_FUNCTION__; } - - QString prop2() const - { return __PRETTY_FUNCTION__; } - - void setProp2(const QString &value) - { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; } - - void emitSignal(const QString &, const QVariant &) - { emit signal(); } - -public slots: - void method() { slotSpy = __PRETTY_FUNCTION__; } - -signals: - void signal(); -}; - -class Interface3: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "local.Interface3") - Q_PROPERTY(QString prop1 READ prop1) - Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2) -public: - Interface3(QObject *parent) : QDBusAbstractAdaptor(parent) - { setAutoRelaySignals(true); } - - QString prop1() const - { return __PRETTY_FUNCTION__; } - - QString prop2() const - { return __PRETTY_FUNCTION__; } - - void setProp2(const QString &value) - { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; } - - void emitSignal(const QString &name, const QVariant &value) - { - if (name == "signalVoid") - emit signalVoid(); - else if (name == "signalInt") - emit signalInt(value.toInt()); - else if (name == "signalString") - emit signalString(value.toString()); - } - -public slots: - void methodVoid() { slotSpy = __PRETTY_FUNCTION__; } - void methodInt(int) { slotSpy = __PRETTY_FUNCTION__; } - void methodString(QString) { slotSpy = __PRETTY_FUNCTION__; } - -signals: - void signalVoid(); - void signalInt(int); - void signalString(const QString &); -}; - -class Interface4: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "local.Interface4") - Q_PROPERTY(QString prop1 READ prop1) - Q_PROPERTY(QString prop2 READ prop2 WRITE setProp2) -public: - Interface4(QObject *parent) : QDBusAbstractAdaptor(parent) - { setAutoRelaySignals(true); } - - QString prop1() const - { return __PRETTY_FUNCTION__; } - - QString prop2() const - { return __PRETTY_FUNCTION__; } - - void setProp2(const QString &value) - { slotSpy = __PRETTY_FUNCTION__; valueSpy = value; } - - void emitSignal(const QString &, const QVariant &value) - { - switch (value.type()) - { - case QVariant::Invalid: - emit signal(); - break; - case QVariant::Int: - emit signal(value.toInt()); - break; - case QVariant::String: - emit signal(value.toString()); - break; - default: - break; - } - } - -public slots: - void method() { slotSpy = __PRETTY_FUNCTION__; } - void method(int) { slotSpy = __PRETTY_FUNCTION__; } - void method(QString) { slotSpy = __PRETTY_FUNCTION__; } - -signals: - void signal(); - void signal(int); - void signal(const QString &); -}; - -class MyObject: public QObject -{ - Q_OBJECT -public: - Interface1 *if1; - Interface2 *if2; - Interface3 *if3; - Interface4 *if4; - - MyObject(int n = 4) - : if1(0), if2(0), if3(0), if4(0) - { - switch (n) - { - case 4: - if4 = new Interface4(this); - case 3: - if3 = new Interface3(this); - case 2: - if2 = new Interface2(this); - case 1: - if1 = new Interface1(this); - } - } -}; - -class TypesInterface: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "local.TypesInterface") -public: - TypesInterface(QObject *parent) - : QDBusAbstractAdaptor(parent) - { } - - union - { - bool b; - uchar uc; - short s; - ushort us; - int i; - uint ui; - qlonglong ll; - qulonglong ull; - double d; - } dataSpy; - QVariant variantSpy; - QString stringSpy; - QVariantList listSpy; - QStringList stringlistSpy; - QByteArray bytearraySpy; - QVariantMap mapSpy; - -public slots: - void methodBool(bool b) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.b = b; - } - - void methodUChar(uchar uc) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.uc = uc; - } - - void methodShort(short s) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.s = s; - } - - void methodUShort(ushort us) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.us = us; - } - - void methodInt(int i) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.i = i; - } - - void methodUInt(uint ui) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.ui = ui; - } - - void methodLongLong(qlonglong ll) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.ll = ll; - } - - void methodULongLong(qulonglong ull) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.ull = ull; - } - - void methodDouble(double d) - { - slotSpy = __PRETTY_FUNCTION__; - dataSpy.d = d; - } - - void methodString(const QString &s) - { - slotSpy = __PRETTY_FUNCTION__; - stringSpy = s; - } - - void methodVariant(const QVariant &v) - { - slotSpy = __PRETTY_FUNCTION__; - variantSpy = v; - } - - void methodList(const QVariantList &l) - { - slotSpy = __PRETTY_FUNCTION__; - listSpy = l; - } - - void methodStringList(const QStringList &sl) - { - slotSpy = __PRETTY_FUNCTION__; - stringlistSpy = sl; - } - - void methodByteArray(const QByteArray &ba) - { - slotSpy = __PRETTY_FUNCTION__; - bytearraySpy = ba; - } - - void methodMap(const QVariantMap &m) - { - slotSpy = __PRETTY_FUNCTION__; - mapSpy = m; - } - - bool retrieveBool() - { - return dataSpy.b; - } - - uchar retrieveUChar() - { - return dataSpy.uc; - } - - short retrieveShort() - { - return dataSpy.s; - } - - ushort retrieveUShort() - { - return dataSpy.us; - } - - int retrieveInt() - { - return dataSpy.i; - } - - uint retrieveUInt() - { - return dataSpy.ui; - } - - qlonglong retrieveLongLong() - { - return dataSpy.ll; - } - - qulonglong retrieveULongLong() - { - return dataSpy.ull; - } - - double retrieveDouble() - { - return dataSpy.d; - } - - QString retrieveString() - { - return stringSpy; - } - - QVariant retrieveVariant() - { - return variantSpy; - } - - QVariantList retrieveList() - { - return listSpy; - } - - QStringList retrieveStringList() - { - return stringlistSpy; - } - - QByteArray retrieveByteArray() - { - return bytearraySpy; - } - - QVariantMap retrieveMap() - { - return mapSpy; - } -}; - -void tst_QDBusAbstractAdaptor::methodCalls_data() -{ - QTest::addColumn("nInterfaces"); - QTest::newRow("0") << 0; - QTest::newRow("1") << 1; - QTest::newRow("2") << 2; - QTest::newRow("3") << 3; - QTest::newRow("4") << 4; -} - -void tst_QDBusAbstractAdaptor::methodCalls() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - //QDBusInterface *empty = con.findInterface(con.baseService(), "/", QString()); - QDBusInterface *if1 = con.findInterface(con.baseService(), "/", "local.Interface1"); - QDBusInterface *if2 = con.findInterface(con.baseService(), "/", "local.Interface2"); - QDBusInterface *if3 = con.findInterface(con.baseService(), "/", "local.Interface3"); - QDBusInterface *if4 = con.findInterface(con.baseService(), "/", "local.Interface4"); - - QObject deleter; - if1->setParent(&deleter); - if2->setParent(&deleter); - if3->setParent(&deleter); - if4->setParent(&deleter); - - // must fail: no object - //QCOMPARE(empty->call("method").type(), QDBusMessage::ErrorMessage); - QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ErrorMessage); - - QFETCH(int, nInterfaces); - MyObject obj(nInterfaces); - con.registerObject("/", &obj); - - // must fail: no such method - QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ErrorMessage); - if (!nInterfaces--) - return; - if (!nInterfaces--) - return; - - // simple call: one such method exists - QCOMPARE(if2->call(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface2::method()"); - if (!nInterfaces--) - return; - - // multiple methods in multiple interfaces, no name overlap - QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "methodVoid").type(), QDBusMessage::ErrorMessage); - QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "methodInt").type(), QDBusMessage::ErrorMessage); - QCOMPARE(if1->call(QDBusInterface::UseEventLoop, "methodString").type(), QDBusMessage::ErrorMessage); - QCOMPARE(if2->call(QDBusInterface::UseEventLoop, "methodVoid").type(), QDBusMessage::ErrorMessage); - QCOMPARE(if2->call(QDBusInterface::UseEventLoop, "methodInt").type(), QDBusMessage::ErrorMessage); - QCOMPARE(if2->call(QDBusInterface::UseEventLoop, "methodString").type(), QDBusMessage::ErrorMessage); - - QCOMPARE(if3->call(QDBusInterface::UseEventLoop, "methodVoid").type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface3::methodVoid()"); - QCOMPARE(if3->call(QDBusInterface::UseEventLoop, "methodInt", 42).type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface3::methodInt(int)"); - QCOMPARE(if3->call(QDBusInterface::UseEventLoop, "methodString", QString("")).type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface3::methodString(QString)"); - - if (!nInterfaces--) - return; - - // method overloading: different interfaces - QCOMPARE(if4->call(QDBusInterface::UseEventLoop, "method").type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface4::method()"); - - // method overloading: different parameters - QCOMPARE(if4->call(QDBusInterface::UseEventLoop, "method.i", 42).type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface4::method(int)"); - QCOMPARE(if4->call(QDBusInterface::UseEventLoop, "method.s", QString()).type(), QDBusMessage::ReplyMessage); - QCOMPARE(slotSpy, "void Interface4::method(QString)"); - -} - -static void emitSignal(MyObject *obj, const QString &iface, const QString &name, - const QVariant ¶meter) -{ - if (iface.endsWith('2')) - obj->if2->emitSignal(name, parameter); - else if (iface.endsWith('3')) - obj->if3->emitSignal(name, parameter); - else if (iface.endsWith('4')) - obj->if4->emitSignal(name, parameter); - - QTest::qWait(200); -} - -void tst_QDBusAbstractAdaptor::signalEmissions_data() -{ - QTest::addColumn("interface"); - QTest::addColumn("name"); - QTest::addColumn("signature"); - QTest::addColumn("parameter"); - - QTest::newRow("Interface2.signal") << "local.Interface2" << "signal" << QString() << QVariant(); - QTest::newRow("Interface3.signalVoid") << "local.Interface3" << "signalVoid" << QString() << QVariant(); - QTest::newRow("Interface3.signalInt") << "local.Interface3" << "signalInt" << "i" << QVariant(1); - QTest::newRow("Interface3.signalString") << "local.Interface3" << "signalString" << "s" << QVariant("foo"); -} - -void tst_QDBusAbstractAdaptor::signalEmissions() -{ - QFETCH(QString, interface); - QFETCH(QString, name); - QFETCH(QVariant, parameter); - - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - MyObject obj(3); - con.registerObject("/", &obj); - - //QDBusInterface empty = con.findInterface(con.baseService(), "/", QString()); - QDBusInterface *if2 = con.findInterface(con.baseService(), "/", "local.Interface2"); - QDBusInterface *if3 = con.findInterface(con.baseService(), "/", "local.Interface3"); - QObject deleter; - if2->setParent(&deleter); - if3->setParent(&deleter); - - // connect all signals and emit only one - { - QDBusSignalSpy spy; - con.connect(con.baseService(), "/", "local.Interface2", "signal", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface3", "signalVoid", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface3", "signalInt", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface3", "signalString", - &spy, SLOT(slot(QDBusMessage))); - - emitSignal(&obj, interface, name, parameter); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, interface); - QCOMPARE(spy.name, name); - QTEST(spy.signature, "signature"); - QCOMPARE(spy.value, parameter); - } - - // connect one signal and emit them all - { - QDBusSignalSpy spy; - con.connect(con.baseService(), "/", interface, name, &spy, SLOT(slot(QDBusMessage))); - emitSignal(&obj, "local.Interface2", "signal", QVariant()); - emitSignal(&obj, "local.Interface3", "signalVoid", QVariant()); - emitSignal(&obj, "local.Interface3", "signalInt", QVariant(1)); - emitSignal(&obj, "local.Interface3", "signalString", QVariant("foo")); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, interface); - QCOMPARE(spy.name, name); - QTEST(spy.signature, "signature"); - QCOMPARE(spy.value, parameter); - } -} - -void tst_QDBusAbstractAdaptor::sameSignalDifferentPaths() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - MyObject obj(2); - - con.registerObject("/p1",&obj); - con.registerObject("/p2",&obj); - - QDBusSignalSpy spy; - con.connect(con.baseService(), "/p1", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage))); - obj.if2->emitSignal(QString(), QVariant()); - QTest::qWait(200); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, QString("local.Interface2")); - QCOMPARE(spy.name, QString("signal")); - QVERIFY(spy.signature.isEmpty()); - - // now connect the other one - spy.count = 0; - con.connect(con.baseService(), "/p2", "local.Interface2", "signal", &spy, SLOT(slot(QDBusMessage))); - obj.if2->emitSignal(QString(), QVariant()); - QTest::qWait(200); - - QCOMPARE(spy.count, 2); -} - -void tst_QDBusAbstractAdaptor::overloadedSignalEmission_data() -{ - QTest::addColumn("signature"); - QTest::addColumn("parameter"); - QTest::newRow("void") << QString("") << QVariant(); - QTest::newRow("int") << "i" << QVariant(1); - QTest::newRow("string") << "s" << QVariant("foo"); -} - -void tst_QDBusAbstractAdaptor::overloadedSignalEmission() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - MyObject obj; - con.registerObject("/", &obj); - - QString interface = "local.Interface4"; - QString name = "signal"; - QFETCH(QVariant, parameter); - //QDBusInterface *if4 = con.findInterface(con.baseService(), "/", interface); - - // connect all signals and emit only one - { - QDBusSignalSpy spy; - con.connect(con.baseService(), "/", "local.Interface4", "signal", "", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface4", "signal", "i", - &spy, SLOT(slot(QDBusMessage))); - con.connect(con.baseService(), "/", "local.Interface4", "signal", "s", - &spy, SLOT(slot(QDBusMessage))); - - emitSignal(&obj, interface, name, parameter); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, interface); - QCOMPARE(spy.name, name); - QTEST(spy.signature, "signature"); - QCOMPARE(spy.value, parameter); - } - - QFETCH(QString, signature); - // connect one signal and emit them all - { - QDBusSignalSpy spy; - con.connect(con.baseService(), "/", interface, name, signature, &spy, SLOT(slot(QDBusMessage))); - emitSignal(&obj, "local.Interface4", "signal", QVariant()); - emitSignal(&obj, "local.Interface4", "signal", QVariant(1)); - emitSignal(&obj, "local.Interface4", "signal", QVariant("foo")); - - QCOMPARE(spy.count, 1); - QCOMPARE(spy.interface, interface); - QCOMPARE(spy.name, name); - QTEST(spy.signature, "signature"); - QCOMPARE(spy.value, parameter); - } -} - -void tst_QDBusAbstractAdaptor::readProperties() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - MyObject obj; - con.registerObject("/", &obj); - - QDBusInterfacePtr properties(con, con.baseService(), "/", "org.freedesktop.DBus.Properties"); - for (int i = 2; i <= 4; ++i) { - QString name = QString("Interface%1").arg(i); - - for (int j = 1; j <= 2; ++j) { - QString propname = QString("prop%1").arg(j); - QDBusReply reply = - properties->call(QDBusInterface::UseEventLoop, "Get", "local." + name, propname); - QVariant value = reply; - - QCOMPARE(value.userType(), int(QVariant::String)); - QCOMPARE(value.toString(), QString("QString %1::%2() const").arg(name, propname)); - } - } -} - -void tst_QDBusAbstractAdaptor::writeProperties() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - MyObject obj; - con.registerObject("/", &obj); - - QDBusInterfacePtr properties(con, con.baseService(), "/", "org.freedesktop.DBus.Properties"); - for (int i = 2; i <= 4; ++i) { - QString name = QString("Interface%1").arg(i); - - QVariant value(name); - - valueSpy.clear(); - properties->call(QDBusInterface::UseEventLoop, "Set", "local." + name, QString("prop1"), - value); - QVERIFY(valueSpy.isEmpty()); // call mustn't have succeeded - - properties->call(QDBusInterface::UseEventLoop, "Set", "local." + name, QString("prop2"), - value); - QCOMPARE(valueSpy, name); - QCOMPARE(QString(slotSpy), QString("void %1::setProp2(const QString&)").arg(name)); - } -} - -#if 0 -void tst_QDBusAbstractAdaptor::adaptorIntrospection_data() -{ - methodCalls_data(); -} - -void tst_QDBusAbstractAdaptor::adaptorIntrospection() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - QObject obj; - con.registerObject("/", &obj); - - QFETCH(int, nInterfaces); - switch (nInterfaces) - { - case 4: - new Interface4(&obj); - case 3: - new Interface3(&obj); - case 2: - new Interface2(&obj); - case 1: - new Interface1(&obj); - } - - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QVERIFY(dobj.isValid()); - - QString xml = dobj.introspect(); - QVERIFY(!xml.isEmpty()); - - QStringList interfaces = dobj.interfaces(); - QCOMPARE(interfaces.count(), nInterfaces + 2); - switch (nInterfaces) - { - case 4: { - QVERIFY(interfaces.contains("local.Interface4")); - QDBusInterface iface(dobj, "local.Interface4"); - QCOMPARE(iface.methodData(), Interface4::methodData); - QCOMPARE(iface.signalData(), Interface4::signalData); - QCOMPARE(iface.propertyData(), Interface4::propertyData); - } - case 3: { - QVERIFY(interfaces.contains("local.Interface3")); - QDBusInterface iface(dobj, "local.Interface3"); - QCOMPARE(iface.methodData(), Interface3::methodData); - QCOMPARE(iface.signalData(), Interface3::signalData); - QCOMPARE(iface.propertyData(), Interface3::propertyData); - } - case 2: { - QVERIFY(interfaces.contains("local.Interface2")); - QDBusInterface iface(dobj, "local.Interface2"); - QCOMPARE(iface.methodData(), Interface2::methodData); - QCOMPARE(iface.signalData(), Interface2::signalData); - QCOMPARE(iface.propertyData(), Interface2::propertyData); - } - case 1: { - QVERIFY(interfaces.contains("local.Interface1")); - QDBusInterface iface(dobj, "local.Interface1"); - QCOMPARE(iface.methodData(), Interface1::methodData); - QCOMPARE(iface.signalData(), Interface1::signalData); - QCOMPARE(iface.propertyData(), Interface1::propertyData); - } - } -} - -void tst_QDBusAbstractAdaptor::objectTreeIntrospection() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.isEmpty()); - } - - QObject root; - con.registerObject("/", &root); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.isEmpty()); - } - - QObject p1; - con.registerObject("/p1", &p1); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("p1")); - } - - con.unregisterObject("/"); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("p1")); - } - - con.registerObject("/p1/q/r", &root); - { - QDBusObject dobj = con.findObject(con.baseService(), "/p1"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("q")); - } - { - QDBusObject dobj = con.findObject(con.baseService(), "/p1/q"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("r")); - } - - con.unregisterObject("/p1", QDBusConnection::UnregisterTree); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.isEmpty()); - } - - QObject p2; - con.registerObject("/p2", &p2, QDBusConnection::ExportChildObjects); - { - QDBusObject dobj = con.findObject(con.baseService(), "/"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(!tree.childObjects.contains("p1")); - QVERIFY(tree.childObjects.contains("p2")); - } - - QObject q; - q.setParent(&p2); - { - QDBusObject dobj = con.findObject(con.baseService(), "/p2"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(!tree.childObjects.contains("q")); - } - - q.setObjectName("q"); - { - QDBusObject dobj = con.findObject(con.baseService(), "/p2"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(tree.childObjects.contains("q")); - } - - q.setParent(0); - { - QDBusObject dobj = con.findObject(con.baseService(), "/p2"); - QString xml = dobj.introspect(); - - QDBusIntrospection::Object tree = - QDBusIntrospection::parseObject(xml); - QVERIFY(!tree.childObjects.contains("q")); - } -} -#endif - -static inline QVariant nest(const QVariant& v) -{ - QVariant ret; - qVariantSetValue(ret, v); - return ret; -} - -void tst_QDBusAbstractAdaptor::typeMatching_data() -{ - QTest::addColumn("basename"); - QTest::addColumn("signature"); - QTest::addColumn("value"); - - QTest::newRow("bool") << "Bool" << "b" << QVariant(true); - QTest::newRow("byte") << "UChar" << "y" << qVariantFromValue(uchar(42)); - QTest::newRow("short") << "Short" << "n" << qVariantFromValue(short(-43)); - QTest::newRow("ushort") << "UShort" << "q" << qVariantFromValue(ushort(44)); - QTest::newRow("int") << "Int" << "i" << QVariant(42); - QTest::newRow("uint") << "UInt" << "u" << QVariant(42U); - QTest::newRow("qlonglong") << "LongLong" << "x" << QVariant(Q_INT64_C(42)); - QTest::newRow("qulonglong") << "ULongLong" << "t" << QVariant(Q_UINT64_C(42)); - QTest::newRow("double") << "Double" << "d" << QVariant(2.5); - QTest::newRow("string") << "String" << "s" << QVariant("Hello, World!"); - - QTest::newRow("variant") << "Variant" << "v" << nest(QVariant("Hello again!")); - QTest::newRow("list") << "List" << "av" << QVariant(QVariantList() - << nest(42) - << nest(QString("foo")) - << nest(QByteArray("bar")) - << nest(nest(QString("baz")))); - QTest::newRow("stringlist") << "StringList" << "as" << QVariant(QStringList() << "Hello" << "world"); - QTest::newRow("bytearray") << "ByteArray" << "ay" << QVariant(QByteArray("foo")); - - QVariantMap map; - map["one"] = nest(1); // int - map["The answer to life, the Universe and everything"] = nest(42u); // uint - map["In the beginning..."] = nest(QString("There was nothing")); // string - map["but Unix came and said"] = nest(QByteArray("\"Hello, World\"")); // bytearray - map["two"] = nest(qVariantFromValue(short(2))); // short - QTest::newRow("map") << "Map" << "a{sv}" << QVariant(map); -} - -void tst_QDBusAbstractAdaptor::typeMatching() -{ - QObject obj; - new TypesInterface(&obj); - - QDBusConnection &con = QDBus::sessionBus(); - con.registerObject("/types", &obj); - - QFETCH(QString, basename); - QFETCH(QString, signature); - QFETCH(QVariant, value); - - QDBusMessage reply; - QDBusInterface *iface = con.findInterface(con.baseService(), "/types", "local.TypesInterface"); - - reply = iface->callWithArgs("method" + basename + '.' + signature, QVariantList() << value, - QDBusInterface::UseEventLoop); - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - - reply = iface->call(QDBusInterface::UseEventLoop, "retrieve" + basename); - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - QCOMPARE(reply.count(), 1); - - const QVariant &retval = reply.at(0); - QCOMPARE(retval.userType(), value.userType()); - QVERIFY(compare(retval, value)); - - iface->deleteLater(); -} - -QTEST_MAIN(tst_QDBusAbstractAdaptor) - -#include "tst_qdbusabstractadaptor.moc" diff --git a/test/qt/tst_qdbusconnection.cpp b/test/qt/tst_qdbusconnection.cpp deleted file mode 100644 index a887cd93..00000000 --- a/test/qt/tst_qdbusconnection.cpp +++ /dev/null @@ -1,257 +0,0 @@ -#include -#include - -#include - -#include - -class MyObject: public QObject -{ - Q_OBJECT -public slots: - void method(const QDBusMessage &msg) { serial = msg.serialNumber(); path = msg.path(); } - -public: - int serial; - QString path; - MyObject() : serial(0) { } -}; - -class tst_QDBusConnection: public QObject -{ - Q_OBJECT - -private slots: - void addConnection(); - void connect(); - void send(); - void sendAsync(); - void sendSignal(); - - void registerObject(); - -public: - bool callMethod(const QDBusConnection &conn, const QString &path); -}; - -class QDBusSpy: public QObject -{ - Q_OBJECT -public slots: - void handlePing(const QString &str) { args.clear(); args << str; } - void asyncReply(const QDBusMessage &msg) { args << msg; serial = msg.replySerialNumber(); } - -public: - QList args; - int serial; -}; - -void tst_QDBusConnection::sendSignal() -{ - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::signal("/org/kde/selftest", "org.kde.selftest", - "Ping"); - msg << QLatin1String("ping"); - - QVERIFY(con.send(msg)); - - QTest::qWait(1000); -} - -void tst_QDBusConnection::send() -{ - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.DBus", - "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames"); - - QDBusMessage reply = con.sendWithReply(msg); - - QCOMPARE(reply.count(), 1); - QCOMPARE(reply.at(0).typeName(), "QStringList"); - QVERIFY(reply.at(0).toStringList().contains(con.baseService())); -} - -void tst_QDBusConnection::sendAsync() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - QDBusSpy spy; - - QDBusMessage msg = QDBusMessage::methodCall("org.freedesktop.DBus", - "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListNames"); - int msgId = con.sendWithReplyAsync(msg, &spy, SLOT(asyncReply(QDBusMessage))); - QVERIFY(msgId != 0); - - QTest::qWait(1000); - - QCOMPARE(spy.args.value(0).typeName(), "QStringList"); - QVERIFY(spy.args.at(0).toStringList().contains(con.baseService())); - QCOMPARE(spy.serial, msgId); -} - -void tst_QDBusConnection::connect() -{ - QDBusSpy spy; - - QDBusConnection &con = QDBus::sessionBus(); - - con.connect(con.baseService(), "/org/kde/selftest", "org.kde.selftest", "ping", &spy, - SLOT(handlePing(QString))); - - QDBusMessage msg = QDBusMessage::signal("/org/kde/selftest", "org.kde.selftest", - "ping"); - msg << QLatin1String("ping"); - - QVERIFY(con.send(msg)); - - QTest::qWait(1000); - - QCOMPARE(spy.args.count(), 1); - QCOMPARE(spy.args.at(0).toString(), QString("ping")); -} - -void tst_QDBusConnection::addConnection() -{ - { - QDBusConnection con = QDBusConnection::addConnection( - QDBusConnection::SessionBus, "bubu"); - - QVERIFY(con.isConnected()); - QVERIFY(!con.lastError().isValid()); - - QDBusConnection con2("foo"); - QVERIFY(!con2.isConnected()); - QVERIFY(!con2.lastError().isValid()); - - con2 = con; - QVERIFY(con.isConnected()); - QVERIFY(con2.isConnected()); - QVERIFY(!con.lastError().isValid()); - QVERIFY(!con2.lastError().isValid()); - } - - { - QDBusConnection con("bubu"); - QVERIFY(con.isConnected()); - QVERIFY(!con.lastError().isValid()); - } - - QDBusConnection::closeConnection("bubu"); - - { - QDBusConnection con("bubu"); - QVERIFY(!con.isConnected()); - QVERIFY(!con.lastError().isValid()); - } -} - -void tst_QDBusConnection::registerObject() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - // make sure nothing is using our paths: - QVERIFY(!callMethod(con, "/")); - QVERIFY(!callMethod(con, "/p1")); - QVERIFY(!callMethod(con, "/p2")); - QVERIFY(!callMethod(con, "/p1/q")); - QVERIFY(!callMethod(con, "/p1/q/r")); - - { - // register one object at root: - MyObject obj; - QVERIFY(con.registerObject("/", &obj, QDBusConnection::ExportSlots)); - QVERIFY(callMethod(con, "/")); - QCOMPARE(obj.path, QString("/")); - } - // make sure it's gone - QVERIFY(!callMethod(con, "/")); - - { - // register one at an element: - MyObject obj; - QVERIFY(con.registerObject("/p1", &obj, QDBusConnection::ExportSlots)); - QVERIFY(!callMethod(con, "/")); - QVERIFY(callMethod(con, "/p1")); - QCOMPARE(obj.path, QString("/p1")); - - // re-register it somewhere else - QVERIFY(con.registerObject("/p2", &obj, QDBusConnection::ExportSlots)); - QVERIFY(callMethod(con, "/p1")); - QCOMPARE(obj.path, QString("/p1")); - QVERIFY(callMethod(con, "/p2")); - QCOMPARE(obj.path, QString("/p2")); - } - // make sure it's gone - QVERIFY(!callMethod(con, "/p1")); - QVERIFY(!callMethod(con, "/p2")); - - { - // register at a deep path - MyObject obj; - QVERIFY(con.registerObject("/p1/q/r", &obj, QDBusConnection::ExportSlots)); - QVERIFY(!callMethod(con, "/")); - QVERIFY(!callMethod(con, "/p1")); - QVERIFY(!callMethod(con, "/p1/q")); - QVERIFY(callMethod(con, "/p1/q/r")); - QCOMPARE(obj.path, QString("/p1/q/r")); - } - // make sure it's gone - QVERIFY(!callMethod(con, "/p1/q/r")); - - { - MyObject obj; - QVERIFY(con.registerObject("/p1/q2", &obj, QDBusConnection::ExportSlots)); - QVERIFY(callMethod(con, "/p1/q2")); - QCOMPARE(obj.path, QString("/p1/q2")); - - // try unregistering - con.unregisterObject("/p1/q2"); - QVERIFY(!callMethod(con, "/p1/q2")); - - // register it again - QVERIFY(con.registerObject("/p1/q2", &obj, QDBusConnection::ExportSlots)); - QVERIFY(callMethod(con, "/p1/q2")); - QCOMPARE(obj.path, QString("/p1/q2")); - - // now try removing things around it: - con.unregisterObject("/p2"); - QVERIFY(callMethod(con, "/p1/q2")); // unrelated object shouldn't affect - - con.unregisterObject("/p1"); - QVERIFY(callMethod(con, "/p1/q2")); // unregistering just the parent shouldn't affect it - - con.unregisterObject("/p1/q2/r"); - QVERIFY(callMethod(con, "/p1/q2")); // unregistering non-existing child shouldn't affect it either - - con.unregisterObject("/p1/q"); - QVERIFY(callMethod(con, "/p1/q2")); // unregistering sibling (before) shouldn't affect - - con.unregisterObject("/p1/r"); - QVERIFY(callMethod(con, "/p1/q2")); // unregistering sibling (after) shouldn't affect - - // now remove it: - con.unregisterObject("/p1", QDBusConnection::UnregisterTree); - QVERIFY(!callMethod(con, "/p1/q2")); // we removed the full tree - } -} - -bool tst_QDBusConnection::callMethod(const QDBusConnection &conn, const QString &path) -{ - QDBusMessage msg = QDBusMessage::methodCall(conn.baseService(), path, "local.any", "method"); - QDBusMessage reply = conn.sendWithReply(msg, QDBusConnection::UseEventLoop); - - return reply.type() == QDBusMessage::ReplyMessage; -} - -QTEST_MAIN(tst_QDBusConnection) - -#include "tst_qdbusconnection.moc" - diff --git a/test/qt/tst_qdbusinterface.cpp b/test/qt/tst_qdbusinterface.cpp deleted file mode 100644 index a63b8e0b..00000000 --- a/test/qt/tst_qdbusinterface.cpp +++ /dev/null @@ -1,295 +0,0 @@ -/* -*- C++ -*- - * - * Copyright (C) 2006 Trolltech AS. All rights reserved. - * Author: Thiago Macieira - * - * 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 -#include - -#include -#include - -#include "common.h" - -Q_DECLARE_METATYPE(QVariantList) - -#define TEST_INTERFACE_NAME "com.trolltech.QtDBus.MyObject" -#define TEST_SIGNAL_NAME "somethingHappened" - -class MyObject: public QObject -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "com.trolltech.QtDBus.MyObject") - Q_CLASSINFO("D-Bus Introspection", "" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" - "") -public: - MyObject() - { - QObject *subObject = new QObject(this); - subObject->setObjectName("subObject"); - } - -public slots: - - void ping(const QDBusMessage &msg) - { - QDBusMessage reply = QDBusMessage::methodReply(msg); - reply << static_cast >(msg); - if (!msg.connection().send(reply)) - exit(1); - } -}; - -class Spy: public QObject -{ - Q_OBJECT -public: - QString received; - int count; - - Spy() : count(0) - { } - -public slots: - void spySlot(const QString& arg) - { - received = arg; - ++count; - } -}; - -// helper function -void emitSignal(const QString &interface, const QString &name, const QString &arg) -{ - QDBusMessage msg = QDBusMessage::signal("/", interface, name); - msg << arg; - QDBus::sessionBus().send(msg); - - QTest::qWait(200); -} - -class tst_QDBusInterface: public QObject -{ - Q_OBJECT - MyObject obj; -private slots: - void initTestCase(); - - void call_data(); - void call(); - - void introspect(); - - void signal(); -}; - -void tst_QDBusInterface::initTestCase() -{ - QDBusConnection &con = QDBus::sessionBus(); - QVERIFY(con.isConnected()); - - con.registerObject("/", &obj, QDBusConnection::ExportAdaptors | QDBusConnection::ExportSlots | - QDBusConnection::ExportChildObjects); -} - -void tst_QDBusInterface::call_data() -{ - QTest::addColumn("method"); - QTest::addColumn("input"); - QTest::addColumn("output"); - - QVariantList input; - QTest::newRow("empty") << "ping" << input << input; - - input << qVariantFromValue(1); - QTest::newRow("int") << "ping" << input << input; - QTest::newRow("int-int") << "ping.i" << input << input; - QTest::newRow("int-int16") << "ping.n" << input << (QVariantList() << qVariantFromValue(short(1))); - - // try doing some conversions - QVariantList output; - output << qVariantFromValue(1U); - QTest::newRow("int-uint") << "ping.u" << input << output; - -#if QT_VERSION >= 0x040200 - output.clear(); - output << qVariantFromValue(ushort(1)); - QTest::newRow("int-uint16") << "ping.q" << input << output; -#endif - - QTest::newRow("int-int64") << "ping.x" << input << (QVariantList() << qVariantFromValue(Q_INT64_C(1))); - QTest::newRow("int-uint64") << "ping.t" << input << (QVariantList() << qVariantFromValue(Q_UINT64_C(1))); - QTest::newRow("int-double") << "ping.d" << input << (QVariantList() << qVariantFromValue(1.0)); - - output.clear(); - output << QString("1"); - QTest::newRow("int-string") << "ping.s" << input << output; - - // try from string now - input = output; - QTest::newRow("string") << "ping" << input << output; - QTest::newRow("string-string") << "ping.s" << input << output; - - output.clear(); - output << qVariantFromValue(1); - QTest::newRow("string-int") << "ping.i" << input << output; - -#if QT_VERSION >= 0x040200 - output.clear(); - output << qVariantFromValue(short(1)); - QTest::newRow("string-int16") << "ping.n" << input << input; -#endif - - output.clear(); - output << qVariantFromValue(1U); - QTest::newRow("string-uint") << "ping.u" << input << output; - -#if QT_VERSION >= 0x040200 - output.clear(); - output << qVariantFromValue(ushort(1)); - QTest::newRow("string-uint16") << "ping.q" << input << output; -#endif - - QTest::newRow("string-int64") << "ping.x" << input << (QVariantList() << qVariantFromValue(1LL)); - QTest::newRow("string-uint64") << "ping.t" << input << (QVariantList() << qVariantFromValue(1ULL)); - QTest::newRow("string-double") << "ping.d" << input << (QVariantList() << qVariantFromValue(1.0)); - - // two args (must be strings!) - input.clear(); - input << QString("Hello") << QString("World"); - output = input; - QTest::newRow("two-strings") << "ping" << input << output; - QTest::newRow("two-strings") << "ping.ss" << input << output; - - // this should drop one of the arguments - output.removeLast(); - QTest::newRow("last-dropped") << "ping.s" << input << output; -} - -void tst_QDBusInterface::call() -{ - QDBusConnection &con = QDBus::sessionBus(); - QDBusInterface *iface = con.findInterface(con.baseService(), QLatin1String("/"), - TEST_INTERFACE_NAME); - - QFETCH(QString, method); - QFETCH(QVariantList, input); - QFETCH(QVariantList, output); - - QDBusMessage reply; - // try first callWithArgs: - reply = iface->callWithArgs(method, input, QDBusInterface::UseEventLoop); - - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - if (!output.isEmpty()) { - QCOMPARE(reply.count(), output.count()); - QVERIFY(compare(reply, output)); - } - - // try the template methods - if (input.isEmpty()) - reply = iface->call(QDBusInterface::UseEventLoop, method); - else if (input.count() == 1) - switch (input.at(0).type()) - { - case QVariant::Int: - reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toInt()); - break; - - case QVariant::UInt: - reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toUInt()); - break; - - case QVariant::String: - reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toString()); - break; - - default: - QFAIL("Unknown type. Please update the test case"); - break; - } - else - reply = iface->call(QDBusInterface::UseEventLoop, method, input.at(0).toString(), input.at(1).toString()); - - QCOMPARE(reply.type(), QDBusMessage::ReplyMessage); - if (!output.isEmpty()) { - QCOMPARE(reply.count(), output.count()); - QVERIFY(compare(reply, output)); - } -} - -void tst_QDBusInterface::introspect() -{ - QDBusConnection &con = QDBus::sessionBus(); - QDBusInterface *iface = con.findInterface(QDBus::sessionBus().baseService(), QLatin1String("/"), - TEST_INTERFACE_NAME); - - const QMetaObject *mo = iface->metaObject(); - - qDebug("Improve to a better testcase of QDBusMetaObject"); - QCOMPARE(mo->methodCount() - mo->methodOffset(), 3); - QVERIFY(mo->indexOfSignal(TEST_SIGNAL_NAME "(QString)") != -1); - - QCOMPARE(mo->propertyCount() - mo->propertyOffset(), 1); - QVERIFY(mo->indexOfProperty("prop1") != -1); - - iface->deleteLater(); -} - -void tst_QDBusInterface::signal() -{ - QDBusConnection &con = QDBus::sessionBus(); - QDBusInterface *iface = con.findInterface(con.baseService(), QLatin1String("/"), - TEST_INTERFACE_NAME); - - QString arg = "So long and thanks for all the fish"; - { - Spy spy; - spy.connect(iface, SIGNAL(somethingHappened(QString)), SLOT(spySlot(QString))); - - emitSignal(TEST_INTERFACE_NAME, TEST_SIGNAL_NAME, arg); - QCOMPARE(spy.count, 1); - QCOMPARE(spy.received, arg); - } - - iface->deleteLater(); -} - -QTEST_MAIN(tst_QDBusInterface) - -#include "tst_qdbusinterface.moc" - diff --git a/test/qt/tst_qdbusmarshall.cpp b/test/qt/tst_qdbusmarshall.cpp deleted file mode 100644 index 306f7b6a..00000000 --- a/test/qt/tst_qdbusmarshall.cpp +++ /dev/null @@ -1,342 +0,0 @@ -#include -#include -#include - -#include "common.h" -#include - -class tst_QDBusMarshall: public QObject -{ - Q_OBJECT - -public slots: - void initTestCase(); - void cleanupTestCase(); - -private slots: - void sendBasic_data(); - void sendBasic(); - - void sendVariant_data(); - void sendVariant(); - - void sendArrays_data(); - void sendArrays(); - - void sendArrayOfArrays_data(); - void sendArrayOfArrays(); - - void sendStringMap_data(); - void sendStringMap(); - - void sendStringMapOfMap_data(); - void sendStringMapOfMap(); - -private: - QProcess proc; -}; - -void tst_QDBusMarshall::initTestCase() -{ - proc.start("./qpong"); - QVERIFY(proc.waitForStarted()); - QTest::qWait(2000); -} - -void tst_QDBusMarshall::cleanupTestCase() -{ - proc.close(); - proc.kill(); -} - -void tst_QDBusMarshall::sendBasic_data() -{ - QTest::addColumn("value"); - QTest::addColumn("sig"); - - // basic types: - QTest::newRow("bool") << QVariant(false) << "b"; - QTest::newRow("bool2") << QVariant(true) << "b"; - QTest::newRow("byte") << qVariantFromValue(uchar(1)) << "y"; - QTest::newRow("int16") << qVariantFromValue(short(2)) << "n"; - QTest::newRow("uint16") << qVariantFromValue(ushort(3)) << "q"; - QTest::newRow("int") << QVariant(1) << "i"; - QTest::newRow("uint") << QVariant(2U) << "u"; - QTest::newRow("int64") << QVariant(Q_INT64_C(3)) << "x"; - QTest::newRow("uint64") << QVariant(Q_UINT64_C(4)) << "t"; - QTest::newRow("double") << QVariant(42.5) << "d"; - QTest::newRow("string") << QVariant("ping") << "s"; - QTest::newRow("emptystring") << QVariant("") << "s"; - QTest::newRow("nullstring") << QVariant(QString()) << "s"; -} - -void tst_QDBusMarshall::sendVariant_data() -{ - sendBasic_data(); - - // add a few more: - QVariant nested(1); - QTest::newRow("variant") << nested << "v"; - - QVariant nested2; - qVariantSetValue(nested2, nested); - QTest::newRow("variant-variant") << nested2 << "v"; -} - -void tst_QDBusMarshall::sendArrays_data() -{ - QTest::addColumn("value"); - QTest::addColumn("sig"); - - // arrays: - QStringList strings; - QTest::newRow("emptystringlist") << QVariant(strings) << "as"; - strings << "hello" << "world"; - QTest::newRow("stringlist") << QVariant(strings) << "as"; - - strings.clear(); - strings << "" << "" << ""; - QTest::newRow("list-of-emptystrings") << QVariant(strings) << "as"; - - strings.clear(); - strings << QString() << QString() << QString() << QString(); - QTest::newRow("list-of-nullstrings") << QVariant(strings) << "as"; - - QByteArray bytearray; - QTest::newRow("nullbytearray") << QVariant(bytearray) << "ay"; - bytearray = ""; // empty, not null - QTest::newRow("emptybytearray") << QVariant(bytearray) << "ay"; - bytearray = "foo"; - QTest::newRow("bytearray") << QVariant(bytearray) << "ay"; - bytearray.clear(); - for (int i = 0; i < 4096; ++i) - bytearray += QByteArray(1024, char(i)); - QTest::newRow("hugebytearray") << QVariant(bytearray) << "ay"; - - QList bools; - QTest::newRow("emptyboollist") << qVariantFromValue(bools) << "ab"; - bools << false << true << false; - QTest::newRow("boollist") << qVariantFromValue(bools) << "ab"; - - QList shorts; - QTest::newRow("emptyshortlist") << qVariantFromValue(shorts) << "an"; - shorts << 42 << -43 << 44 << 45 << -32768 << 32767; - QTest::newRow("shortlist") << qVariantFromValue(shorts) << "an"; - - QList ushorts; - QTest::newRow("emptyushortlist") << qVariantFromValue(ushorts) << "aq"; - ushorts << 12u << 13u << 14u << 15 << 65535; - QTest::newRow("ushortlist") << qVariantFromValue(ushorts) << "aq"; - - QList ints; - QTest::newRow("emptyintlist") << qVariantFromValue(ints) << "ai"; - ints << 42 << -43 << 44 << 45 << 2147483647 << -2147483647-1; - QTest::newRow("intlist") << qVariantFromValue(ints) << "ai"; - - QList uints; - QTest::newRow("emptyuintlist") << qVariantFromValue(uints) << "au"; - uints << uint(12) << uint(13) << uint(14) << 4294967295U; - QTest::newRow("uintlist") << qVariantFromValue(uints) << "au"; - - QList llints; - QTest::newRow("emptyllintlist") << qVariantFromValue(llints) << "ax"; - llints << Q_INT64_C(99) << Q_INT64_C(-100) - << Q_INT64_C(-9223372036854775807)-1 << Q_INT64_C(9223372036854775807); - QTest::newRow("llintlist") << qVariantFromValue(llints) << "ax"; - - QList ullints; - QTest::newRow("emptyullintlist") << qVariantFromValue(ullints) << "at"; - ullints << Q_UINT64_C(66) << Q_UINT64_C(67) - << Q_UINT64_C(18446744073709551615); - QTest::newRow("ullintlist") << qVariantFromValue(ullints) << "at"; - - QList doubles; - QTest::newRow("emptydoublelist") << qVariantFromValue(doubles) << "ad"; - doubles << 1.2 << 2.2 << 4.4 - << -std::numeric_limits::infinity() - << std::numeric_limits::infinity() - << std::numeric_limits::quiet_NaN(); - QTest::newRow("doublelist") << qVariantFromValue(doubles) << "ad"; - - QVariantList variants; - QTest::newRow("emptyvariantlist") << QVariant(variants) << "av"; - variants << QString("Hello") << QByteArray("World") << 42 << -43.0 << 44U << Q_INT64_C(-45) - << Q_UINT64_C(46) << true << qVariantFromValue(short(-47)); - for (int i = 0; i < variants.count(); ++i) { - QVariant tmp = variants.at(i); - qVariantSetValue(variants[i], tmp); - } - QTest::newRow("variantlist") << QVariant(variants) << "av"; -} - -void tst_QDBusMarshall::sendArrayOfArrays_data() -{ - sendArrays_data(); -} - -void tst_QDBusMarshall::sendStringMap_data() -{ - sendBasic_data(); - - QVariant nested; - qVariantSetValue(nested, QVariant(1)); - QTest::newRow("variant") << nested << "v"; - - QVariant nested2; - qVariantSetValue(nested2, nested); - QTest::newRow("variant-variant") << nested2 << "v"; - - sendArrays_data(); -} - -void tst_QDBusMarshall::sendStringMapOfMap_data() -{ - sendStringMap_data(); -} - -void tst_QDBusMarshall::sendBasic() -{ - QFETCH(QVariant, value); - - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest", - "/org/kde/selftest", "org.kde.selftest", "ping"); - msg << value; - - QDBusMessage reply = con.sendWithReply(msg); - // qDebug() << reply; - - QCOMPARE(reply.count(), msg.count()); - QTEST(reply.signature(), "sig"); - for (int i = 0; i < reply.count(); ++i) - QVERIFY(compare(reply.at(i), msg.at(i))); -} - -void tst_QDBusMarshall::sendVariant() -{ - QFETCH(QVariant, value); - QVariant tmp = value; - qVariantSetValue(value, tmp); - - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest", - "/org/kde/selftest", "org.kde.selftest", "ping"); - msg << value; - - QDBusMessage reply = con.sendWithReply(msg); - // qDebug() << reply; - - QCOMPARE(reply.count(), msg.count()); - QCOMPARE(reply.signature(), QString("v")); - for (int i = 0; i < reply.count(); ++i) - QVERIFY(compare(reply.at(i), msg.at(i))); -} - -void tst_QDBusMarshall::sendArrays() -{ - QFETCH(QVariant, value); - - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest", - "/org/kde/selftest", "org.kde.selftest", "ping"); - msg << value; - - QDBusMessage reply = con.sendWithReply(msg); - // qDebug() << reply; - - QCOMPARE(reply.count(), msg.count()); - QTEST(reply.signature(), "sig"); - for (int i = 0; i < reply.count(); ++i) - QVERIFY(compare(reply.at(i), msg.at(i))); -} - -void tst_QDBusMarshall::sendArrayOfArrays() -{ - QFETCH(QVariant, value); - - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest", - "/org/kde/selftest", "org.kde.selftest", "ping"); - msg << QVariant(QVariantList() << value << value); - - QDBusMessage reply = con.sendWithReply(msg); - // qDebug() << reply; - - QCOMPARE(reply.count(), msg.count()); - QFETCH(QString, sig); - QCOMPARE(reply.signature(), "a" + sig); - for (int i = 0; i < reply.count(); ++i) - QVERIFY(compare(reply.at(i), msg.at(i))); -} - -void tst_QDBusMarshall::sendStringMap() -{ - QFETCH(QVariant, value); - - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest", - "/org/kde/selftest", "org.kde.selftest", "ping"); - - QVariantMap map; - map["foo"] = value; - map["bar"] = value; - msg << QVariant(map); - - QDBusMessage reply = con.sendWithReply(msg); - // qDebug() << reply; - - QCOMPARE(reply.count(), msg.count()); - QFETCH(QString, sig); - QCOMPARE(reply.signature(), "a{s" + sig + "}"); - for (int i = 0; i < reply.count(); ++i) - QVERIFY(compare(reply.at(i), msg.at(i))); -} - -void tst_QDBusMarshall::sendStringMapOfMap() -{ - QFETCH(QVariant, value); - - QDBusConnection &con = QDBus::sessionBus(); - - QVERIFY(con.isConnected()); - - QDBusMessage msg = QDBusMessage::methodCall("org.kde.selftest", - "/org/kde/selftest", "org.kde.selftest", "ping"); - - QVariantMap map; - map["foo"] = value; - map["bar"] = value; - - QVariantMap map2; - map2["foo"] = map; - msg << QVariant(map2); - - QDBusMessage reply = con.sendWithReply(msg); - // qDebug() << reply; - - QCOMPARE(reply.count(), msg.count()); - QFETCH(QString, sig); - QCOMPARE(reply.signature(), "a{sa{s" + sig + "}}"); - - for (int i = 0; i < reply.count(); ++i) - QVERIFY(compare(reply.at(i), msg.at(i))); -} - - -QTEST_MAIN(tst_QDBusMarshall) -#include "tst_qdbusmarshall.moc" diff --git a/test/qt/tst_qdbusxmlparser.cpp b/test/qt/tst_qdbusxmlparser.cpp deleted file mode 100644 index bf1ddec5..00000000 --- a/test/qt/tst_qdbusxmlparser.cpp +++ /dev/null @@ -1,578 +0,0 @@ -/* -*- C++ -*- - * - * Copyright (C) 2006 Trolltech AS. All rights reserved. - * Author: Thiago Macieira - * - * 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 -#include - -#include - -#define USE_PRIVATE_CODE -#include "common.h" - -class tst_QDBusXmlParser: public QObject -{ - Q_OBJECT - -private: - void parsing_common(const QString&); - -private slots: - void parsing_data(); - void parsing(); - void parsingWithDoctype_data(); - void parsingWithDoctype(); - - void objectWithContent_data(); - void objectWithContent(); - - void methods_data(); - void methods(); - void signals__data(); - void signals_(); - void properties_data(); - void properties(); -}; - -void tst_QDBusXmlParser::parsing_data() -{ - QTest::addColumn("xmlData"); - QTest::addColumn("interfaceCount"); - QTest::addColumn("objectCount"); - - QTest::newRow("null") << QString() << 0 << 0; - QTest::newRow("empty") << QString("") << 0 << 0; - - QTest::newRow("junk") << "" << 0 << 0; - QTest::newRow("interface-inside-junk") << "" - << 0 << 0; - QTest::newRow("object-inside-junk") << "" - << 0 << 0; - - QTest::newRow("zero-interfaces") << "" << 0 << 0; - QTest::newRow("one-interface") << "" << 1 << 0; - - - QTest::newRow("two-interfaces") << "" - "" - << 2 << 0; - - - QTest::newRow("one-object") << "" << 0 << 1; - QTest::newRow("two-objects") << "" << 0 << 2; - - QTest::newRow("i1o1") << "" << 1 << 1; - -} - -void tst_QDBusXmlParser::parsing_common(const QString &xmlData) -{ - QDBusIntrospection::ObjectTree obj = - QDBusIntrospection::parseObjectTree(xmlData, "local.testing", "/"); - QFETCH(int, interfaceCount); - QFETCH(int, objectCount); - QCOMPARE(obj.interfaces.count(), interfaceCount); - QCOMPARE(obj.childObjects.count(), objectCount); - - // also verify the naming - int i = 0; - foreach (QString name, obj.interfaces) - QCOMPARE(name, QString("iface.iface%1").arg(++i)); - - i = 0; - foreach (QString name, obj.childObjects) - QCOMPARE(name, QString("obj%1").arg(++i)); -} - -void tst_QDBusXmlParser::parsing() -{ - QFETCH(QString, xmlData); - - parsing_common(xmlData); -} - -void tst_QDBusXmlParser::parsingWithDoctype_data() -{ - parsing_data(); -} - -void tst_QDBusXmlParser::parsingWithDoctype() -{ - QString docType = "\n"; - QFETCH(QString, xmlData); - - parsing_common(docType + xmlData); -} - -void tst_QDBusXmlParser::objectWithContent_data() -{ - QTest::addColumn("xmlData"); - QTest::addColumn("probedObject"); - QTest::addColumn("interfaceCount"); - QTest::addColumn("objectCount"); - - QTest::newRow("zero") << "" << "obj" << 0 << 0; - - QString xmlData = "" - "" - ""; - QTest::newRow("one-interface") << xmlData << "obj" << 1 << 0; - QTest::newRow("one-interface2") << xmlData << "obj2" << 0 << 0; - - xmlData = "" - "" - "" - ""; - QTest::newRow("two-interfaces") << xmlData << "obj" << 2 << 0; - QTest::newRow("two-interfaces2") << xmlData << "obj2" << 0 << 0; - - xmlData = "" - "" - "" - "" - "" - ""; - QTest::newRow("two-nodes-two-interfaces") << xmlData << "obj" << 2 << 0; - QTest::newRow("two-nodes-one-interface") << xmlData << "obj2" << 1 << 0; - - xmlData = "" - "" - ""; - QTest::newRow("one-object") << xmlData << "obj" << 0 << 1; - QTest::newRow("one-object2") << xmlData << "obj2" << 0 << 0; - - xmlData = "" - "" - "" - ""; - QTest::newRow("two-objects") << xmlData << "obj" << 0 << 2; - QTest::newRow("two-objects2") << xmlData << "obj2" << 0 << 0; - - xmlData = "" - "" - "" - "" - "" - ""; - QTest::newRow("two-nodes-two-objects") << xmlData << "obj" << 0 << 2; - QTest::newRow("two-nodes-one-object") << xmlData << "obj2" << 0 << 1; -} - -void tst_QDBusXmlParser::objectWithContent() -{ - QFETCH(QString, xmlData); - QFETCH(QString, probedObject); - - QDBusIntrospection::ObjectTree tree = - QDBusIntrospection::parseObjectTree(xmlData, "local.testing", "/"); - - const ObjectMap &om = tree.childObjectData; - - if (om.contains(probedObject)) { - const QSharedDataPointer& obj = om.value(probedObject); - QVERIFY(obj != 0); - - QFETCH(int, interfaceCount); - QFETCH(int, objectCount); - - QCOMPARE(obj->interfaces.count(), interfaceCount); - QCOMPARE(obj->childObjects.count(), objectCount); - - // verify the object names - int i = 0; - foreach (QString name, obj->interfaces) - QCOMPARE(name, QString("iface.iface%1").arg(++i)); - - i = 0; - foreach (QString name, obj->childObjects) - QCOMPARE(name, QString("obj%1").arg(++i)); - } -} - -void tst_QDBusXmlParser::methods_data() -{ - QTest::addColumn("xmlDataFragment"); - QTest::addColumn("methodMap"); - - MethodMap map; - QTest::newRow("no-methods") << QString() << map; - - // one method without arguments - QDBusIntrospection::Method method; - method.name = "Foo"; - map << method; - QTest::newRow("one-method") << "" << map; - - // add another method without arguments - method.name = "Bar"; - map << method; - QTest::newRow("two-methods") << "" - "" - << map; - - // invert the order of the XML declaration - QTest::newRow("two-methods-inverse") << "" - "" - << map; - - // add a third, with annotations - method.name = "Baz"; - method.annotations.insert("foo.testing", "nothing to see here"); - map << method; - QTest::newRow("method-with-annotation") << - "" - "" - "" - << map; - - // arguments - map.clear(); - method.annotations.clear(); - - method.name = "Method"; - method.inputArgs << arg("s"); - map << method; - QTest::newRow("one-in") << - "" - "" - "" << map; - - // two arguments - method.inputArgs << arg("v"); - map.clear(); - map << method; - QTest::newRow("two-in") << - "" - "" - "" - "" << map; - - // one invalid arg - QTest::newRow("two-in-one-invalid") << - "" - "" - "" // this line should be ignored - "" - "" << map; - - // one out argument - method.inputArgs.clear(); - method.outputArgs << arg("s"); - map.clear(); - map << method; - QTest::newRow("one-out") << - "" - "" - "" << map; - - // two in and one out - method.inputArgs << arg("s") << arg("v"); - map.clear(); - map << method; - QTest::newRow("two-in-one-out") << - "" - "" - "" - "" - "" << map; - - // let's try an arg with name - method.outputArgs.clear(); - method.inputArgs.clear(); - method.inputArgs << arg("s", "foo"); - map.clear(); - map << method; - QTest::newRow("one-in-with-name") << - "" - "" - "" << map; - - // two args with name - method.inputArgs << arg("i", "bar"); - map.clear(); - map << method; - QTest::newRow("two-in-with-name") << - "" - "" - "" - "" << map; - - // one complex - map.clear(); - method = QDBusIntrospection::Method(); - - // Method1(in STRING arg1, in BYTE arg2, out ARRAY of STRING) - method.inputArgs << arg("s", "arg1") << arg("y", "arg2"); - method.outputArgs << arg("as"); - method.name = "Method1"; - map << method; - - // Method2(in ARRAY of DICT_ENTRY of (STRING,VARIANT) variantMap, in UINT32 index, - // out STRING key, out VARIANT value) - // with annotation "foo.equivalent":"QVariantMap" - method = QDBusIntrospection::Method(); - method.inputArgs << arg("a{sv}", "variantMap") << arg("u", "index"); - method.outputArgs << arg("s", "key") << arg("v", "value"); - method.annotations.insert("foo.equivalent", "QVariantMap"); - method.name = "Method2"; - map << method; - - QTest::newRow("complex") << - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" << map; -} - -void tst_QDBusXmlParser::methods() -{ - QString xmlHeader = "" - "", - xmlFooter = "" - ""; - - QFETCH(QString, xmlDataFragment); - - QDBusIntrospection::Interface iface = - QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); - - QCOMPARE(iface.name, QString("iface.iface1")); - - QFETCH(MethodMap, methodMap); - MethodMap parsedMap = iface.methods; - - QCOMPARE(methodMap.count(), parsedMap.count()); - QCOMPARE(methodMap, parsedMap); -} - -void tst_QDBusXmlParser::signals__data() -{ - QTest::addColumn("xmlDataFragment"); - QTest::addColumn("signalMap"); - - SignalMap map; - QTest::newRow("no-signals") << QString() << map; - - // one signal without arguments - QDBusIntrospection::Signal signal; - signal.name = "Foo"; - map << signal; - QTest::newRow("one-signal") << "" << map; - - // add another signal without arguments - signal.name = "Bar"; - map << signal; - QTest::newRow("two-signals") << "" - "" - << map; - - // invert the order of the XML declaration - QTest::newRow("two-signals-inverse") << "" - "" - << map; - - // add a third, with annotations - signal.name = "Baz"; - signal.annotations.insert("foo.testing", "nothing to see here"); - map << signal; - QTest::newRow("signal-with-annotation") << - "" - "" - "" - << map; - - // one out argument - map.clear(); - signal.annotations.clear(); - signal.outputArgs << arg("s"); - signal.name = "Signal"; - map.clear(); - map << signal; - QTest::newRow("one-out") << - "" - "" - "" << map; - - // without saying which direction it is - QTest::newRow("one-out-no-direction") << - "" - "" - "" << map; - - // two args with name - signal.outputArgs << arg("i", "bar"); - map.clear(); - map << signal; - QTest::newRow("two-out-with-name") << - "" - "" - "" - "" << map; - - // one complex - map.clear(); - signal = QDBusIntrospection::Signal(); - - // Signal1(out ARRAY of STRING) - signal.outputArgs << arg("as"); - signal.name = "Signal1"; - map << signal; - - // Signal2(out STRING key, out VARIANT value) - // with annotation "foo.equivalent":"QVariantMap" - signal = QDBusIntrospection::Signal(); - signal.outputArgs << arg("s", "key") << arg("v", "value"); - signal.annotations.insert("foo.equivalent", "QVariantMap"); - signal.name = "Signal2"; - map << signal; - - QTest::newRow("complex") << - "" - "" - "" - "" - "" - "" - "" - "" << map; -} - -void tst_QDBusXmlParser::signals_() -{ - QString xmlHeader = "" - "", - xmlFooter = "" - ""; - - QFETCH(QString, xmlDataFragment); - - QDBusIntrospection::Interface iface = - QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); - - QCOMPARE(iface.name, QString("iface.iface1")); - - QFETCH(SignalMap, signalMap); - SignalMap parsedMap = iface.signals_; - - QCOMPARE(signalMap.count(), parsedMap.count()); - QCOMPARE(signalMap, parsedMap); -} - -void tst_QDBusXmlParser::properties_data() -{ - QTest::addColumn("xmlDataFragment"); - QTest::addColumn("propertyMap"); - - PropertyMap map; - QTest::newRow("no-signals") << QString() << map; - - // one readable signal - QDBusIntrospection::Property prop; - prop.name = "foo"; - prop.type = "s"; - prop.access = QDBusIntrospection::Property::Read; - map << prop; - QTest::newRow("one-readable") << "" << map; - - // one writable signal - prop.access = QDBusIntrospection::Property::Write; - map.clear(); - map << prop; - QTest::newRow("one-writable") << "" << map; - - // one read- & writable signal - prop.access = QDBusIntrospection::Property::ReadWrite; - map.clear(); - map << prop; - QTest::newRow("one-read-writable") << "" - << map; - - // two, mixed properties - prop.name = "bar"; - prop.type = "i"; - prop.access = QDBusIntrospection::Property::Read; - map << prop; - QTest::newRow("two") << - "" - "" << map; - - // invert the order of the declaration - QTest::newRow("two") << - "" - "" << map; - - // add a third with annotations - prop.name = "baz"; - prop.type = "as"; - prop.access = QDBusIntrospection::Property::Write; - prop.annotations.insert("foo.annotation", "Hello, World"); - prop.annotations.insert("foo.annotation2", "Goodbye, World"); - map << prop; - QTest::newRow("complex") << - "" - "" - "" - "" - "" << map; - - // and now change the order - QTest::newRow("complex2") << - "" - "" - "" - "" - "" << map; -} - -void tst_QDBusXmlParser::properties() -{ - QString xmlHeader = "" - "", - xmlFooter = "" - ""; - - QFETCH(QString, xmlDataFragment); - - QDBusIntrospection::Interface iface = - QDBusIntrospection::parseInterface(xmlHeader + xmlDataFragment + xmlFooter); - - QCOMPARE(iface.name, QString("iface.iface1")); - - QFETCH(PropertyMap, propertyMap); - PropertyMap parsedMap = iface.properties; - - QCOMPARE(propertyMap.count(), parsedMap.count()); - QCOMPARE(propertyMap, parsedMap); -} - -QTEST_MAIN(tst_QDBusXmlParser) - -#include "tst_qdbusxmlparser.moc" -- cgit