dbus/test/glib test-service-glib.xml, 1.11, 1.12 test-service-glib.c,
1.21, 1.22 test-dbus-glib.c, 1.28, 1.29
Colin Walters
walters at freedesktop.org
Mon Jul 11 08:54:21 EST 2005
Update of /cvs/dbus/dbus/test/glib
In directory gabe:/tmp/cvs-serv16516/test/glib
Modified Files:
test-service-glib.xml test-service-glib.c test-dbus-glib.c
Log Message:
2005-07-10 Colin Walters <walters at verbum.org>
* doc/TODO: Knock off some GLib items with this patch.
* glib/dbus-gvalue-utils.c (_dbus_gtype_can_signal_error)
(_dbus_gvalue_signals_error): New functions.
* glib/dbus-gvalue-utils.h: Prototype them.
* glib/dbus-gobject.c (arg_iterate): Update to handle return vals
and change to not output const/retval flags for input args. All
callers updated.
(invoke_object_method): Refactor to handle return values. Add
some more comments in various places. Remove debug g_print.
* glib/dbus-binding-tool-glib.h (DBUS_GLIB_ANNOTATION_RETURNVAL): New.
* glib/dbus-binding-tool-glib.c (dbus_g_type_get_marshal_name):
Handle G_TYPE_NONE.
(compute_gsignature): New function; refactored from code from
compute_marshaller and compute_marshaller_name. Enhance to
handle return values and async ops more cleanly. Update for
async ops returning NONE instead of BOOLEAN.
(compute_marshaller, compute_marshaller_name): Call compute_gsignature
and output appropriate string.
(generate_glue): Handle return value annotation. Also don't dump
constness flag for input arguments.
* glib/Makefile.am (DBUS_GLIB_INTERNALS): New variable; contains
files shared between installed library and utilities.
(libdbus_glib_1_la_SOURCES): Move some stuf into DBUS_GLIB_INTERNALS.
(libdbus_gtool_la_SOURCES): Suck in DBUS_GLIB_INTERNALS so the
binding tool can access gtype utility functions.
* test/glib/test-service-glib.c:
* test/glib/test-service-glib.xml:
* test/glib/test-dbus-glib.c: Add some tests for return values.
Index: test-service-glib.xml
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-service-glib.xml,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- test-service-glib.xml 9 Jul 2005 17:52:51 -0000 1.11
+++ test-service-glib.xml 10 Jul 2005 22:54:18 -0000 1.12
@@ -10,6 +10,20 @@
<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>
Index: test-service-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-service-glib.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- test-service-glib.c 9 Jul 2005 17:52:51 -0000 1.21
+++ test-service-glib.c 10 Jul 2005 22:54:18 -0000 1.22
@@ -52,6 +52,10 @@
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);
@@ -91,9 +95,9 @@
gboolean my_object_terminate (MyObject *obj, GError **error);
-gboolean my_object_async_increment (MyObject *obj, gint32 x, DBusGMethodInvocation *context);
+void my_object_async_increment (MyObject *obj, gint32 x, DBusGMethodInvocation *context);
-gboolean my_object_async_throw_error (MyObject *obj, DBusGMethodInvocation *context);
+void my_object_async_throw_error (MyObject *obj, DBusGMethodInvocation *context);
#include "test-service-glib-glue.h"
@@ -283,6 +287,27 @@
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)
{
@@ -559,14 +584,13 @@
return FALSE;
}
-gboolean
+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);
- return TRUE;
}
static gboolean
@@ -582,13 +606,12 @@
return FALSE;
}
-gboolean
+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);
- return TRUE;
}
@@ -623,11 +646,16 @@
g_printerr ("Launching test-service-glib\n");
- g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
- g_log_set_always_fatal (G_LOG_LEVEL_WARNING);
-
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);
Index: test-dbus-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/test/glib/test-dbus-glib.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- test-dbus-glib.c 9 Jul 2005 01:46:51 -0000 1.28
+++ test-dbus-glib.c 10 Jul 2005 22:54:18 -0000 1.29
@@ -504,11 +504,11 @@
G_TYPE_UINT, &v_UINT32_2,
G_TYPE_INVALID))
lose_gerror ("Failed to complete Increment call", error);
- g_assert (n_times_echo_cb_entered == 1);
-
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,
@@ -517,6 +517,30 @@
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)
@@ -529,6 +553,19 @@
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,
More information about the dbus-commit
mailing list