diff options
author | John (J5) Palmieri <johnp@redhat.com> | 2006-07-14 16:20:12 +0000 |
---|---|---|
committer | John (J5) Palmieri <johnp@redhat.com> | 2006-07-14 16:20:12 +0000 |
commit | a929c9a3b465db8b7e17b9b39936c612c2621a7c (patch) | |
tree | d1764257d1bd56f8e6a044516ccfc9bc44f7f9f5 /test/glib | |
parent | 5efe8e7f1d97931710558495a951e0b35afbfb72 (diff) |
* Remove all bindings
Diffstat (limited to 'test/glib')
-rw-r--r-- | test/glib/Makefile.am | 80 | ||||
-rw-r--r-- | test/glib/my-object-marshal.list | 2 | ||||
-rwxr-xr-x | test/glib/run-test.sh | 36 | ||||
-rw-r--r-- | test/glib/test-dbus-glib.c | 1621 | ||||
-rw-r--r-- | test/glib/test-profile.c | 1150 | ||||
-rw-r--r-- | test/glib/test-service-glib.c | 928 | ||||
-rw-r--r-- | test/glib/test-service-glib.xml | 179 | ||||
-rw-r--r-- | test/glib/test-thread-client.c | 98 | ||||
-rw-r--r-- | test/glib/test-thread-server.c | 209 | ||||
-rw-r--r-- | test/glib/test-thread.h | 1 |
10 files changed, 0 insertions, 4304 deletions
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 <dbus/dbus-glib.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "test-service-glib-bindings.h" -#include <glib/dbus-gidl.h> -#include <glib/dbus-gparser.h> -#include <glib.h> -#include <glib-object.h> -#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 <config.h> -#include <glib.h> -#include <dbus/dbus-glib-lowlevel.h> -#include <stdlib.h> -#include <unistd.h> - -#include <errno.h> -#include <fcntl.h> -#include <sys/socket.h> -#include <sys/un.h> -#include <netinet/in.h> -#include <string.h> -#include <sys/time.h> -#include <sys/stat.h> -#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 <dbus/dbus-glib.h> -/* NOTE - outside of D-BUS core this would be - * include <dbus/dbus-glib-bindings.h> - */ -#include "tools/dbus-glib-bindings.h" -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <glib/gi18n.h> -#include <glib-object.h> -#include <glib/gquark.h> -#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 @@ -<?xml version="1.0" encoding="UTF-8" ?> - -<node name="/org/freedesktop/DBus/Tests/MyTestObject"> - <interface name="org.freedesktop.DBus.Tests.MyObject"> - <method name="DoNothing"> - </method> - - <method name="Increment"> - <arg type="u" name="x" /> - <arg type="u" direction="out" /> - </method> - - <method name="IncrementRetval"> - <arg type="u" name="x" /> - <arg type="u" direction="out"> - <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> - </arg> - </method> - - <method name="IncrementRetvalError"> - <arg type="u" name="x" /> - <arg type="u" direction="out"> - <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> - </arg> - </method> - - <method name="ThrowError"> - </method> - - <method name="Uppercase"> - <arg type="s" direction="in" /> - <arg type="s" direction="out" /> - </method> - - <method name="ManyArgs"> - <arg type="u" name="x" direction="in" /> - <arg type="s" name="str" direction="in" /> - <arg type="d" name="trouble" direction="in" /> - <arg type="d" name="d_ret" direction="out" /> - <arg type="s" name="str_ret" direction="out" /> - </method> - - <method name="ManyReturn"> - <arg type="u" direction="out" /> - <arg type="s" direction="out" /> - <arg type="i" direction="out" /> - <arg type="u" direction="out" /> - <arg type="u" direction="out" /> - <arg type="s" direction="out"> - <annotation name="org.freedesktop.DBus.GLib.Const" value=""/> - </arg> - </method> - - <method name="Stringify"> - <arg type="v" name="val" direction="in"/> - <arg type="s" direction="out"/> - </method> - - <method name="Unstringify"> - <arg type="s" name="val" direction="in"/> - <arg type="v" direction="out"/> - </method> - - <method name="Recursive1"> - <arg type="au" direction="in"/> - <arg type="u" direction="out"/> - </method> - - <method name="Recursive2"> - <arg type="u" direction="in"/> - <arg type="au" direction="out"/> - </method> - - <method name="ManyUppercase"> - <arg type="as" direction="in"/> - <arg type="as" direction="out"/> - </method> - - <method name="StrHashLen"> - <arg type="a{ss}" direction="in"/> - <arg type="u" direction="out"/> - </method> - - <method name="SendCar"> - <arg type="(suv)" direction="in"/> - <arg type="(uo)" direction="out"/> - </method> - - <method name="GetHash"> - <arg type="a{ss}" direction="out"/> - </method> - - <method name="RecArrays"> - <arg type="aas" name="val" direction="in"/> - <arg type="aau" direction="out"/> - </method> - - <method name="Objpath"> - <arg type="o" direction="in"/> - <arg type="o" direction="out"> - <annotation name="org.freedesktop.DBus.GLib.Const" value=""/> - </arg> - </method> - - <method name="GetObjs"> - <arg type="ao" direction="out"/> - </method> - - <method name="IncrementVal"> - </method> - - <method name="AsyncIncrement"> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - <arg type="u" name="x" /> - <arg type="u" direction="out" /> - </method> - - <method name="AsyncThrowError"> - <annotation name="org.freedesktop.DBus.GLib.Async" value=""/> - </method> - - <method name="GetVal"> - <arg type="u" direction="out" /> - </method> - - <method name="ManyStringify"> - <arg type="a{sv}" direction="in"/> - <arg type="a{sv}" direction="out"/> - </method> - - <method name="EchoVariant"> - <arg type="v" direction="in" /> - <arg type="v" direction="out" /> - </method> - - <method name="ProcessVariantOfArrayOfInts123"> - <arg type="v" direction="in" /> - </method> - - <method name="DictOfDicts"> - <arg type="a{sa{ss}}" direction="in"/> - <arg type="a{sa{ss}}" direction="out"/> - </method> - - <method name="EmitFrobnicate"> - </method> - - <!-- Export signals --> - <signal name="Frobnicate"/> - - <method name="Terminate"> - </method> - </interface> - - <!-- Test multiple interfaces on the same object --> - - <interface name="org.freedesktop.DBus.Tests.FooObject"> - <method name="GetValue"> - <arg type="u" direction="out" /> - </method> - - <method name="EmitSignals"> - </method> - - <signal name="Sig0"/> - - <signal name="Sig1"/> - - <method name="EmitSignal2"> - </method> - - <signal name="Sig2"/> - - <method name="Terminate"> - </method> - - </interface> - -</node> 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 <glib.h> -#include <dbus/dbus-glib-lowlevel.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> - -#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 <glib.h> -#include <dbus/dbus-glib-lowlevel.h> -#include <stdio.h> -#include <string.h> - -#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 |