4 #include <droute/droute.h>
5 #include <dbind/dbind.h>
7 #include "dbus/dbus-glib-lowlevel.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 do_tests_func (gpointer data)
192 const gchar *bus_name;
194 gchar *expected_string;
195 gchar *result_string;
197 dbus_error_init (&error);
198 bus_name = dbus_bus_get_unique_name (bus);
200 /* --------------------------------------------------------*/
202 dbind_method_call_reentrant (bus,
210 /* --------------------------------------------------------*/
212 expected_string = TEST_INTERFACE_ONE;
213 result_string = NULL;
214 dbind_method_call_reentrant (bus,
222 if (g_strcmp0(expected_string, result_string))
224 g_print ("Failed: reply to getInterfaceOne not as expected\n");
228 /* --------------------------------------------------------*/
231 g_main_loop_quit (main_loop);
236 int main (int argc, char **argv)
243 /* Setup some server object */
245 object = g_new0(AnObject, 1);
246 object->astring = g_strdup (STRING_ONE);
247 object->anint = INT_ONE;
249 dbus_error_init (&error);
250 main_loop = g_main_loop_new(NULL, FALSE);
251 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
252 dbus_connection_setup_with_g_main(bus, g_main_context_default());
254 cnx = droute_new (bus);
255 path = droute_add_one (cnx, TEST_OBJECT_PATH, object);
257 droute_path_add_interface (path,
263 droute_path_add_interface (path,
269 g_idle_add (do_tests_func, NULL);
270 g_main_run(main_loop);