diff options
author | Havoc Pennington <hp@redhat.com> | 2003-09-04 00:21:36 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-09-04 00:21:36 +0000 |
commit | 636be6f92d4d8effd392ad1f894738849ec7af76 (patch) | |
tree | 963e3d848ca3c3f78e07d1d92aaa3288558eb496 /test/glib/test-thread-client.c | |
parent | 0453b2be603d4a8fcd12be3097b7eadc25838018 (diff) |
2003-09-03 Havoc Pennington <hp@pobox.com>
* test/glib/Makefile.am: add this with random glib-linked test
programs
* glib/Makefile.am: remove the random test programs from here,
leave only the unit tests
* glib/dbus-gobject.c (_dbus_gobject_test): add test for
uscore/javacaps conversion, and fix
(get_object_property, set_object_property): change to .NET
convention for mapping props to methods, set_FooBar/get_FooBar,
since one language has such a convention we may as well copy it.
Plus real methods in either getFooBar or get_foo_bar style won't
collide with this convention.
Diffstat (limited to 'test/glib/test-thread-client.c')
-rw-r--r-- | test/glib/test-thread-client.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/test/glib/test-thread-client.c b/test/glib/test-thread-client.c new file mode 100644 index 00000000..d51d4e6a --- /dev/null +++ b/test/glib/test-thread-client.c @@ -0,0 +1,98 @@ +#include <glib.h> +#include "dbus-glib.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_append_iter_init (message, &iter); + + if (!dbus_message_iter_append_int32 (&iter, threadnr)) + { + g_print ("thread %d: append threadnr failed\n", threadnr); + } + + if (!dbus_message_iter_append_uint32 (&iter, 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_string (&iter, 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_gthread_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; +} + |