5 #include <droute/droute.h>
7 #include "atspi/atspi.h"
9 #define TEST_OBJECT_PATH "/test/object"
10 #define TEST_INTERFACE_ONE "test.interface.One"
11 #define TEST_INTERFACE_TWO "test.interface.Two"
13 #define OBJECT_ONE "ObjectOne";
14 #define OBJECT_TWO "ObjectTwo";
16 #define STRING_ONE "StringOne"
17 #define STRING_TWO "StringTwo"
22 #define NONE_REPLY_STRING "NoneMethod"
24 const gchar *test_interface_One = \
25 "<interface name=\"test.interface.One\">"
26 " <method name=\"null\"/>"
27 " <method name=\"getInt\">"
28 " <arg direction=\"out\" type=\"o\"/>"
30 " <method name=\"setInt\">"
31 " <arg direction=\"in\" type=\"o\"/>"
33 " <method name=\"getString\">"
34 " <arg direction=\"out\" type=\"s\"/>"
36 " <method name=\"setString\">"
37 " <arg direction=\"in\" type=\"s\"/>"
41 const gchar *test_interface_Two = \
42 "<interface name=\"test.interface.One\">"
43 " <method name=\"null\"/>"
44 " <method name=\"getInt\">"
45 " <arg direction=\"out\" type=\"o\"/>"
47 " <method name=\"setInt\">"
48 " <arg direction=\"in\" type=\"o\"/>"
50 " <method name=\"getString\">"
51 " <arg direction=\"out\" type=\"s\"/>"
53 " <method name=\"setString\">"
54 " <arg direction=\"in\" type=\"s\"/>"
58 typedef struct _AnObject
64 static DBusConnection *bus;
65 static GMainLoop *main_loop;
66 static gboolean success = TRUE;
69 impl_null (DBusConnection *bus, DBusMessage *message, void *user_data)
73 reply = dbus_message_new_method_return (message);
78 impl_getInt (DBusConnection *bus, DBusMessage *message, void *user_data)
80 AnObject *object = (AnObject *) user_data;
84 dbus_error_init (&error);
86 reply = dbus_message_new_method_return (message);
87 dbus_message_append_args (reply, DBUS_TYPE_INT32, &(object->anint), DBUS_TYPE_INVALID);
92 impl_setInt (DBusConnection *bus, DBusMessage *message, void *user_data)
94 AnObject *object = (AnObject *) user_data;
98 dbus_error_init (&error);
100 dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &(object->anint), DBUS_TYPE_INVALID);
102 reply = dbus_message_new_method_return (message);
107 impl_getString (DBusConnection *bus, DBusMessage *message, void *user_data)
109 AnObject *object = (AnObject *) user_data;
113 dbus_error_init (&error);
115 reply = dbus_message_new_method_return (message);
116 dbus_message_append_args (reply, DBUS_TYPE_STRING, &(object->astring), DBUS_TYPE_INVALID);
121 impl_setString (DBusConnection *bus, DBusMessage *message, void *user_data)
123 AnObject *object = (AnObject *) user_data;
127 dbus_error_init (&error);
129 g_free (object->astring);
130 dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &(object->astring), DBUS_TYPE_INVALID);
132 reply = dbus_message_new_method_return (message);
137 impl_getInterfaceOne (DBusConnection *bus, DBusMessage *message, void *user_data)
141 gchar *itf = TEST_INTERFACE_ONE;
143 dbus_error_init (&error);
145 reply = dbus_message_new_method_return (message);
146 dbus_message_append_args (reply, DBUS_TYPE_STRING, &itf, DBUS_TYPE_INVALID);
151 impl_getInterfaceTwo (DBusConnection *bus, DBusMessage *message, void *user_data)
155 gchar *itf = TEST_INTERFACE_TWO;
157 dbus_error_init (&error);
159 reply = dbus_message_new_method_return (message);
160 dbus_message_append_args (reply, DBUS_TYPE_STRING, &itf, DBUS_TYPE_INVALID);
164 static DRouteMethod test_methods_one[] = {
166 {impl_getInt, "getInt"},
167 {impl_setInt, "setInt"},
168 {impl_getString, "getString"},
169 {impl_setString, "setString"},
170 {impl_getInterfaceOne, "getInterfaceOne"},
174 static DRouteMethod test_methods_two[] = {
176 {impl_getInt, "getInt"},
177 {impl_setInt, "setInt"},
178 {impl_getString, "getString"},
179 {impl_setString, "setString"},
180 {impl_getInterfaceTwo, "getInterfaceTwo"},
184 static DRouteProperty test_properties[] = {
189 set_reply (DBusPendingCall *pending, void *user_data)
191 void **replyptr = (void **)user_data;
193 *replyptr = dbus_pending_call_steal_reply (pending);
197 send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, DBusError *error)
199 DBusPendingCall *pending;
200 DBusMessage *reply = NULL;
202 if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
206 dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
209 if (!dbus_connection_read_write_dispatch (bus, -1))
216 do_tests_func (gpointer data)
219 const gchar *bus_name;
220 DBusMessage *message, *reply;
222 gchar *expected_string;
223 gchar *result_string;
225 dbus_error_init (&error);
226 bus_name = dbus_bus_get_unique_name (bus);
228 /* --------------------------------------------------------*/
230 message = dbus_message_new_method_call (bus_name,
234 reply = send_and_allow_reentry (bus, message, NULL);
235 dbus_message_unref (message);
237 dbus_message_unref (reply);
239 /* --------------------------------------------------------*/
241 expected_string = TEST_INTERFACE_ONE;
242 result_string = NULL;
243 message = dbus_message_new_method_call (bus_name,
247 reply = send_and_allow_reentry (bus, message, NULL);
248 dbus_message_unref (message);
249 dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &result_string,
251 dbus_message_unref (reply);
252 if (g_strcmp0(expected_string, result_string))
254 g_print ("Failed: reply to getInterfaceOne was %s; expected %s\n",
255 result_string, expected_string);
259 /* --------------------------------------------------------*/
262 g_main_loop_quit (main_loop);
267 int main (int argc, char **argv)
274 /* Setup some server object */
276 object = g_new0(AnObject, 1);
277 object->astring = g_strdup (STRING_ONE);
278 object->anint = INT_ONE;
280 dbus_error_init (&error);
281 main_loop = g_main_loop_new(NULL, FALSE);
282 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
283 atspi_dbus_connection_setup_with_g_main(bus, g_main_context_default());
286 path = droute_add_one (cnx, TEST_OBJECT_PATH, object);
288 droute_path_add_interface (path,
294 droute_path_add_interface (path,
300 droute_path_register (path, bus);
302 g_idle_add (do_tests_func, NULL);
303 g_main_loop_run(main_loop);