summaryrefslogtreecommitdiffstats
path: root/test/glib/test-dbus-glib.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2005-06-17 14:29:48 +0000
committerColin Walters <walters@verbum.org>2005-06-17 14:29:48 +0000
commit949436ffac9e46649398e1bc9f0ddf567c88dd1c (patch)
treed8bad3f3ffa5813a7e99726b66bba3de8aafc319 /test/glib/test-dbus-glib.c
parent679018f00c7277ecd6272cb1be5dfdedf134c422 (diff)
2005-06-17 Colin Walters <walters@verbum.org>
* glib/dbus-gproxy.c (dbus_g_proxy_emit_remote_signal): Don't spew warnings if we get malformed remote signals. * glib/dbus-gobject.c (propsig_iterate): New function. (lookup_object_info): New function, extracted from lookup_object_and_method. (introspect_properties, introspect_signals): Delete; these are merged into write_interface. (write_interface): Write out signals and properties here; dump the org.gtk.object stuff and use the interface given in the introspection data blob. Also fix up property XML. (lookup_values): New function. (introspect_interfaces): Gather a mapping from interface to a list of its methods, signals, and properties, then write out each interface. (lookup_object_and_method): Use lookup_object_info. (struct DBusGSignalClosure): Add interface. (dbus_g_signal_closure_new): Add interface. Don't dup signame; we can just use the constant data. (dbus_g_signal_closure_finalize): Don't free signal name. (signal_emitter_marshaller): Use interface from signal closure. (export_signals): Only export signals mentioned in introspection blob. (dbus_g_connection_register_g_object): Warn if we have no introspection data for an object. (funcsig_equal): Remove unused variable. (dbus_g_object_register_marshaller): Take varargs instead of list. (dbus_g_object_register_marshaller_array): New function, extracted from old dbus_g_object_register_marshaller. * glib/dbus-binding-tool-glib.c (struct DBusBindingToolCData): Add signals and property data. (write_quoted_string): New function, extracted from generate_glue. (generate_glue): Write signals and properties to introspection blob. * dbus/dbus-glib.h (struct DBusGObjectInfo): Include exported_signals and exported_properties. (dbus_g_object_register_marshaller): Update prototype. (dbus_g_object_register_marshaller_array): Prototype. * test/glib/test-dbus-glib.c: Extend testing to cover new signals. * test/glib/test-service-glib.c: Add new test signals and method to emit them. * test/glib/test-service-glib.xml: Add some test signals. * test/glib/Makefile.am (BUILT_SOURCES): Add my-object-marshal.c and my-object-marshal.h (test_service_glib_SOURCES, test_dbus_glib_SOURCES): Add my-object-marshal.c. (my-object-marshal.c, my-object-marshal.h): Implement. * test/glib/.cvsignore: Update. * doc/TODO: Remove two GLib TODO items fixed by this patch.
Diffstat (limited to 'test/glib/test-dbus-glib.c')
-rw-r--r--test/glib/test-dbus-glib.c128
1 files changed, 115 insertions, 13 deletions
diff --git a/test/glib/test-dbus-glib.c b/test/glib/test-dbus-glib.c
index 2fc8665b..1f979a27 100644
--- a/test/glib/test-dbus-glib.c
+++ b/test/glib/test-dbus-glib.c
@@ -7,10 +7,14 @@
#include <glib/dbus-gidl.h>
#include <glib/dbus-gparser.h>
#include <glib-object.h>
+#include "my-object-marshal.h"
static GMainLoop *loop = NULL;
static int n_times_foo_received = 0;
static int n_times_frobnicate_received = 0;
+static int n_times_sig0_received = 0;
+static int n_times_sig1_received = 0;
+static guint exit_timeout = 0;
static gboolean
timed_exit (gpointer loop)
@@ -27,6 +31,7 @@ foo_signal_handler (DBusGProxy *proxy,
n_times_foo_received += 1;
g_main_loop_quit (loop);
+ g_source_remove (exit_timeout);
}
static void
@@ -39,6 +44,44 @@ frobnicate_signal_handler (DBusGProxy *proxy,
g_assert (val == 42);
g_main_loop_quit (loop);
+ g_source_remove (exit_timeout);
+}
+
+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_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_main_loop_quit (loop);
+ g_source_remove (exit_timeout);
}
static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
@@ -216,9 +259,7 @@ main (int argc, char **argv)
G_TYPE_INVALID);
dbus_g_connection_flush (connection);
-
- g_timeout_add (5000, timed_exit, loop);
-
+ exit_timeout = g_timeout_add (5000, timed_exit, loop);
g_main_loop_run (loop);
if (n_times_foo_received != 1)
@@ -643,16 +684,81 @@ main (int argc, char **argv)
dbus_g_connection_flush (connection);
-
-#if 0
- g_timeout_add (5000, timed_exit, loop);
-
+ 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);
-#endif
+ if (!dbus_g_proxy_invoke (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));
+
+ 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);
+
+ 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_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);
+
+ 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);
+
g_object_unref (G_OBJECT (proxy));
proxy = dbus_g_proxy_new_for_name_owner (connection,
@@ -680,7 +786,6 @@ main (int argc, char **argv)
gboolean found_properties;
gboolean found_myobject;
gboolean found_fooobject;
- gboolean found_gtk_myobject;
node = description_load_from_string (v_STRING_2, strlen (v_STRING_2), &error);
if (!node)
@@ -688,7 +793,6 @@ main (int argc, char **argv)
found_introspectable = FALSE;
found_properties = FALSE;
- found_gtk_myobject = FALSE;
found_myobject = FALSE;
found_fooobject = FALSE;
for (elt = node_info_get_interfaces (node); elt ; elt = elt->next)
@@ -699,8 +803,6 @@ main (int argc, char **argv)
found_introspectable = TRUE;
else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0)
found_properties = TRUE;
- else if (strcmp (interface_info_get_name (iface), "org.gtk.objects.MyObject") == 0)
- found_gtk_myobject = TRUE;
else if (!found_myobject && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Tests.MyObject") == 0)
{
GSList *elt;
@@ -729,7 +831,7 @@ main (int argc, char **argv)
lose ("Unexpected or duplicate interface %s", interface_info_get_name (iface));
}
- if (!(found_introspectable && found_gtk_myobject && found_myobject && found_properties))
+ if (!(found_introspectable && found_myobject && found_properties))
lose ("Missing interface");
}
g_free (v_STRING_2);