summaryrefslogtreecommitdiff
path: root/droute/droute-test.c
diff options
context:
space:
mode:
authorMark Doffman <mdoff@silver-wind.(none)>2008-12-17 17:53:30 +0000
committerMark Doffman <mdoff@silver-wind.(none)>2008-12-18 12:25:38 +0000
commit95ac4886d1b6649d54daffa7191be1b2bbaf2989 (patch)
tree7321b1777cd3601007548f99ac75047f21adc910 /droute/droute-test.c
parentb37f0b74994912dea13f33d63d3f1395554944b2 (diff)
downloadat-spi2-atk-95ac4886d1b6649d54daffa7191be1b2bbaf2989.tar.gz
2008-12-17 Mark Doffman <mark.doffman@codethink.co.uk>
Mega commit that changes droute, adding an interface for creating a droute context and registering single, or multiple objects with the droute context. Modifies atk-adaptor and registryd to use the new interface. * droute/ New interface * atk-adaptor Use new droute interface * registryd Use new droute interface * pyatspi Bug fix, methods were using "null" interface.
Diffstat (limited to 'droute/droute-test.c')
-rw-r--r--droute/droute-test.c246
1 files changed, 246 insertions, 0 deletions
diff --git a/droute/droute-test.c b/droute/droute-test.c
new file mode 100644
index 0000000..1895fb6
--- /dev/null
+++ b/droute/droute-test.c
@@ -0,0 +1,246 @@
+#include <stdio.h>
+#include <glib.h>
+#include <string.h>
+#include <droute/droute.h>
+
+#include "dbus/dbus-glib-lowlevel.h"
+
+#define TEST_OBJECT_PATH "/test/object"
+#define TEST_INTERFACE_ONE "test.interface.One"
+#define TEST_INTERFACE_TWO "test.interface.Two"
+
+#define OBJECT_ONE "ObjectOne";
+#define OBJECT_TWO "ObjectTwo";
+
+#if !defined TEST_INTROSPECTION_DIRECTORY
+ #error "No introspection XML directory defined"
+#endif
+
+#define STRING_ONE "StringOne"
+#define STRING_TWO "StringTwo"
+
+#define INT_ONE 0
+#define INT_TWO 456
+
+#define NONE_REPLY_STRING "NoneMethod"
+
+typedef struct _AnObject
+{
+ gchar *astring;
+ guint *anint;
+} AnObject;
+
+static DBusConnection *bus;
+static GMainLoop *main_loop;
+static gboolean success = TRUE;
+
+static DBusMessage *
+impl_null (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ AnObject *object = (AnObject *) user_data;
+ DBusMessage *reply;
+ DBusError error;
+
+ reply = dbus_message_new_method_return (message);
+ return reply;
+}
+
+static DBusMessage *
+impl_getInt (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ AnObject *object = (AnObject *) user_data;
+ DBusMessage *reply;
+ DBusError error;
+
+ dbus_error_init (&error);
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_INT32, &(object->anint), DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_setInt (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ AnObject *object = (AnObject *) user_data;
+ DBusMessage *reply;
+ DBusError error;
+
+ dbus_error_init (&error);
+
+ dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &(object->anint), DBUS_TYPE_INVALID);
+
+ reply = dbus_message_new_method_return (message);
+ return reply;
+}
+
+static DBusMessage *
+impl_getString (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ AnObject *object = (AnObject *) user_data;
+ DBusMessage *reply;
+ DBusError error;
+
+ dbus_error_init (&error);
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_STRING, &(object->astring), DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_setString (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ AnObject *object = (AnObject *) user_data;
+ DBusMessage *reply;
+ DBusError error;
+
+ dbus_error_init (&error);
+
+ g_free (object->astring);
+ dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &(object->astring), DBUS_TYPE_INVALID);
+
+ reply = dbus_message_new_method_return (message);
+ return reply;
+}
+
+static DBusMessage *
+impl_getInterfaceOne (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ AnObject *object = (AnObject *) user_data;
+ DBusMessage *reply;
+ DBusError error;
+ gchar *itf = TEST_INTERFACE_ONE;
+
+ dbus_error_init (&error);
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_STRING, &itf, DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_getInterfaceTwo (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ AnObject *object = (AnObject *) user_data;
+ DBusMessage *reply;
+ DBusError error;
+ gchar *itf = TEST_INTERFACE_TWO;
+
+ dbus_error_init (&error);
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_STRING, &itf, DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DRouteMethod test_methods_one[] = {
+ {impl_null, "null"},
+ {impl_getInt, "getInt"},
+ {impl_setInt, "setInt"},
+ {impl_getString, "getString"},
+ {impl_setString, "setString"},
+ {impl_getInterfaceOne, "getInterfaceOne"},
+ {NULL, NULL}
+};
+
+static DRouteMethod test_methods_two[] = {
+ {impl_null, "null"},
+ {impl_getInt, "getInt"},
+ {impl_setInt, "setInt"},
+ {impl_getString, "getString"},
+ {impl_setString, "setString"},
+ {impl_getInterfaceTwo, "getInterfaceTwo"},
+ {NULL, NULL}
+};
+
+static DRouteProperty test_properties[] = {
+ {NULL, NULL, NULL}
+};
+
+gboolean
+do_tests_func (gpointer data)
+{
+ DBusError error;
+ gchar *bus_name;
+
+ gchar *expected_string;
+ gchar *result_string;
+
+ dbus_error_init (&error);
+ bus_name = dbus_bus_get_unique_name (bus);
+
+ /* --------------------------------------------------------*/
+
+ dbind_method_call_reentrant (bus,
+ bus_name,
+ TEST_OBJECT_PATH,
+ TEST_INTERFACE_ONE,
+ "null",
+ NULL,
+ "");
+
+ /* --------------------------------------------------------*/
+
+ expected_string = TEST_INTERFACE_ONE;
+ result_string = NULL;
+ dbind_method_call_reentrant (bus,
+ bus_name,
+ TEST_OBJECT_PATH,
+ TEST_INTERFACE_ONE,
+ "getInterfaceOne",
+ NULL,
+ "=>s",
+ &result_string);
+ if (g_strcmp0(expected_string, result_string))
+ {
+ g_print ("Failed: reply to getInterfaceOne not as expected\n");
+ goto out;
+ }
+
+ /* --------------------------------------------------------*/
+
+out:
+ g_main_loop_quit (main_loop);
+ return FALSE;
+}
+
+
+int main (int argc, char **argv)
+{
+ DRouteContext *cnx;
+ DRoutePath *path;
+ AnObject *object;
+ DBusError error;
+
+ /* Setup some server object */
+
+ object = g_new0(AnObject, 1);
+ object->astring = g_strdup (STRING_ONE);
+ object->anint = INT_ONE;
+
+ dbus_error_init (&error);
+ main_loop = g_main_loop_new(NULL, FALSE);
+ bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
+ dbus_connection_setup_with_g_main(bus, g_main_context_default());
+
+ cnx = droute_new (bus, TEST_INTROSPECTION_DIRECTORY);
+ path = droute_add_one (cnx, TEST_OBJECT_PATH, object);
+
+ droute_path_add_interface (path,
+ TEST_INTERFACE_ONE,
+ test_methods_one,
+ test_properties);
+
+ droute_path_add_interface (path,
+ TEST_INTERFACE_TWO,
+ test_methods_two,
+ test_properties);
+
+ g_idle_add (do_tests_func, NULL);
+ g_main_run(main_loop);
+ if (success)
+ return 0;
+ else
+ return 1;
+}