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 #if !defined TEST_INTROSPECTION_DIRECTORY
17 #error "No introspection XML directory defined"
20 #define STRING_ONE "StringOne"
21 #define STRING_TWO "StringTwo"
26 #define NONE_REPLY_STRING "NoneMethod"
28 typedef struct _AnObject
34 static DBusConnection *bus;
35 static GMainLoop *main_loop;
36 static gboolean success = TRUE;
39 impl_null (DBusConnection *bus, DBusMessage *message, void *user_data)
43 reply = dbus_message_new_method_return (message);
48 impl_getInt (DBusConnection *bus, DBusMessage *message, void *user_data)
50 AnObject *object = (AnObject *) user_data;
54 dbus_error_init (&error);
56 reply = dbus_message_new_method_return (message);
57 dbus_message_append_args (reply, DBUS_TYPE_INT32, &(object->anint), DBUS_TYPE_INVALID);
62 impl_setInt (DBusConnection *bus, DBusMessage *message, void *user_data)
64 AnObject *object = (AnObject *) user_data;
68 dbus_error_init (&error);
70 dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &(object->anint), DBUS_TYPE_INVALID);
72 reply = dbus_message_new_method_return (message);
77 impl_getString (DBusConnection *bus, DBusMessage *message, void *user_data)
79 AnObject *object = (AnObject *) user_data;
83 dbus_error_init (&error);
85 reply = dbus_message_new_method_return (message);
86 dbus_message_append_args (reply, DBUS_TYPE_STRING, &(object->astring), DBUS_TYPE_INVALID);
91 impl_setString (DBusConnection *bus, DBusMessage *message, void *user_data)
93 AnObject *object = (AnObject *) user_data;
97 dbus_error_init (&error);
99 g_free (object->astring);
100 dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &(object->astring), DBUS_TYPE_INVALID);
102 reply = dbus_message_new_method_return (message);
107 impl_getInterfaceOne (DBusConnection *bus, DBusMessage *message, void *user_data)
111 gchar *itf = TEST_INTERFACE_ONE;
113 dbus_error_init (&error);
115 reply = dbus_message_new_method_return (message);
116 dbus_message_append_args (reply, DBUS_TYPE_STRING, &itf, DBUS_TYPE_INVALID);
121 impl_getInterfaceTwo (DBusConnection *bus, DBusMessage *message, void *user_data)
125 gchar *itf = TEST_INTERFACE_TWO;
127 dbus_error_init (&error);
129 reply = dbus_message_new_method_return (message);
130 dbus_message_append_args (reply, DBUS_TYPE_STRING, &itf, DBUS_TYPE_INVALID);
134 static DRouteMethod test_methods_one[] = {
136 {impl_getInt, "getInt"},
137 {impl_setInt, "setInt"},
138 {impl_getString, "getString"},
139 {impl_setString, "setString"},
140 {impl_getInterfaceOne, "getInterfaceOne"},
144 static DRouteMethod test_methods_two[] = {
146 {impl_getInt, "getInt"},
147 {impl_setInt, "setInt"},
148 {impl_getString, "getString"},
149 {impl_setString, "setString"},
150 {impl_getInterfaceTwo, "getInterfaceTwo"},
154 static DRouteProperty test_properties[] = {
159 do_tests_func (gpointer data)
162 const gchar *bus_name;
164 gchar *expected_string;
165 gchar *result_string;
167 dbus_error_init (&error);
168 bus_name = dbus_bus_get_unique_name (bus);
170 /* --------------------------------------------------------*/
172 dbind_method_call_reentrant (bus,
180 /* --------------------------------------------------------*/
182 expected_string = TEST_INTERFACE_ONE;
183 result_string = NULL;
184 dbind_method_call_reentrant (bus,
192 if (g_strcmp0(expected_string, result_string))
194 g_print ("Failed: reply to getInterfaceOne not as expected\n");
198 /* --------------------------------------------------------*/
201 g_main_loop_quit (main_loop);
206 int main (int argc, char **argv)
213 /* Setup some server object */
215 object = g_new0(AnObject, 1);
216 object->astring = g_strdup (STRING_ONE);
217 object->anint = INT_ONE;
219 dbus_error_init (&error);
220 main_loop = g_main_loop_new(NULL, FALSE);
221 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
222 dbus_connection_setup_with_g_main(bus, g_main_context_default());
224 cnx = droute_new (bus, TEST_INTROSPECTION_DIRECTORY);
225 path = droute_add_one (cnx, TEST_OBJECT_PATH, object);
227 droute_path_add_interface (path,
232 droute_path_add_interface (path,
237 g_idle_add (do_tests_func, NULL);
238 g_main_run(main_loop);