2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008 Codethink Ltd.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Testing AT-SPI requires both a test application and AT client.
25 * Test applications are built using the Dummy ATK implementation: MyAtk.
26 * This file contains the entry point for all test applications.
27 * Each test is built as a GModule, and this program loads the
28 * test module, as well as the AT-SPI module. The test module will
29 * provide its own implementation of atk_get_root, and as such provide
30 * all the application state for the test.
37 #include <dbus/dbus.h>
39 /* The test module, GModule containing interface for an atk-test */
40 static GModule *test_module;
41 static gpointer test_module_get_root;
42 static gpointer test_module_next;
43 static gpointer test_module_finished;
45 static DBusConnection *dbus_bus;
46 static GMainLoop *mainloop;
48 /* Test module interface */
49 /*************************/
51 typedef AtkObject *(*TestModuleGetRoot) (void);
53 /* Calls into the test module to get the root atk object */
57 return ((TestModuleGetRoot) test_module_get_root)();
60 typedef void (*VoidVoid) (void);
62 /* Called to move to next stage of test.*/
66 ((VoidVoid) test_module_next)();
70 /*************************/
72 /* The AtkUtil class is called to find the root accessible and to deal
73 * with events. Its an incomplete class, its v-table needs to be filled in.
80 klass = g_type_class_ref(ATK_TYPE_UTIL);
81 klass->get_root = get_root;
82 g_type_class_unref(klass);
85 typedef void (*GtkModuleInit) (int *argc, char **argv[]);
87 /* AT-SPI is a gtk module that must be loaded and initialized */
89 load_atspi_module(const char *path, int *argc, char **argv[])
94 bridge = g_module_open(path, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY);
96 g_error("Couldn't load atk-bridge module : %s\n", g_module_error());
98 if (!g_module_symbol(bridge, "gtk_module_init", &init))
99 g_error("Couldn't load symbol \"gtk_module_init\"\n");
101 ((GtkModuleInit) init)(argc, argv);
104 typedef void (*TestModuleInit) (gchar *path);
107 load_test_module(const char *path, const char *tdpath)
111 test_module = g_module_open(path, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY);
113 g_error("Couldn't load test module : %s\n", path);
115 if (!g_module_symbol(test_module, "test_init", &init))
116 g_error("Couldn't load symbol \"test_init\"\n");
118 if (!g_module_symbol(test_module, "test_get_root", &test_module_get_root))
119 g_error("Couldn't load symbol \"test_get_root\"\n");
121 if (!g_module_symbol(test_module, "test_next", &test_module_next))
122 g_error("Couldn't load symbol \"test_next\"\n");
124 if (!g_module_symbol(test_module, "test_finished", &test_module_finished))
125 g_error("Couldn't load symbol \"test_finished\"\n");
127 ((TestModuleInit) init)((gchar *)tdpath);
130 static const char* introspection_string =
131 "<node name=\"/org/codethink/atspi/test\">"
132 " <interface name=\"org.codethink.atspi.test\">"
133 " <method name=\"next\"/>"
134 " <method name=\"finish\"/>"
135 " <signal name=\"started\"/>"
139 static DBusHandlerResult
140 message_handler (DBusConnection *bus, DBusMessage *message, void *user_data)
142 const char *iface = dbus_message_get_interface (message);
143 const char *member = dbus_message_get_member (message);
144 DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
145 gboolean exit = FALSE;
147 DBusMessage *reply = NULL;
149 g_return_val_if_fail(iface != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
151 if (!strcmp(iface, "org.codethink.atspi.test"))
153 if (!strcmp(member, "next"))
156 reply = dbus_message_new_method_return (message);
157 g_assert(reply != NULL);
158 result = DBUS_HANDLER_RESULT_HANDLED;
161 if (!strcmp(member, "finish"))
163 ((VoidVoid) test_module_finished)();
164 reply = dbus_message_new_method_return (message);
165 g_assert(reply != NULL);
166 result = DBUS_HANDLER_RESULT_HANDLED;
171 if (!strcmp(iface, "org.freedesktop.DBus.Introspectable"))
173 if (!strcmp(member, "Introspect"))
175 reply = dbus_message_new_method_return (message);
176 g_assert(reply != NULL);
177 dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection_string,
179 result = DBUS_HANDLER_RESULT_HANDLED;
185 dbus_connection_send (bus, reply, NULL);
186 dbus_message_unref (reply);
191 dbus_connection_flush(bus);
192 dbus_connection_unref(bus);
193 g_main_loop_quit(mainloop);
198 static DBusObjectPathVTable test_vtable =
202 NULL, NULL, NULL, NULL
206 init_dbus_interface(void)
210 dbus_error_init(&error);
211 dbus_bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
212 g_print("\nUnique D-Bus name is: %s\n", dbus_bus_get_unique_name(dbus_bus));
215 g_error("Couldn't get the session bus - %s\n", error.message);
217 g_assert(dbus_connection_register_object_path(dbus_bus,
218 "/org/codethink/atspi/test",
222 dbus_connection_setup_with_g_main(dbus_bus, g_main_context_default());
226 send_started_signal(void)
229 DBusMessageIter args;
231 sig = dbus_message_new_signal("/org/codethink/atspi/test", "org.codethink.atspi.test", "started");
232 g_assert(sig != NULL);
233 if (!dbus_connection_send(dbus_bus, sig, NULL))
234 g_error("Out of memory");
235 dbus_connection_flush(dbus_bus);
236 dbus_message_unref(sig);
239 /*Command line data*/
240 static gchar *tmodule_path = NULL;
241 static gchar *amodule_path = NULL;
242 static gchar *tdata_path = NULL;
244 static GOptionEntry optentries[] =
246 {"test-module", 0, 0, G_OPTION_ARG_STRING, &tmodule_path, "Module containing test scenario", NULL},
247 {"test-atspi-library", 0, 0, G_OPTION_ARG_STRING, &amodule_path, "Gtk module with atk-atspi adaptor", NULL},
248 {"test-data-directory", 0, 0, G_OPTION_ARG_STRING, &tdata_path, "Path to directory of test data", NULL},
254 * Entry point for all test applications.
256 main(int argc, char *argv[])
261 /*Parse command options*/
262 opt = g_option_context_new(NULL);
263 g_option_context_add_main_entries(opt, optentries, NULL);
264 g_option_context_set_ignore_unknown_options(opt, TRUE);
266 if (!g_option_context_parse(opt, &argc, &argv, &err))
267 g_error("Option parsing failed: %s\n", err->message);
269 if (tmodule_path == NULL)
270 g_error("No test module provided");
271 if (amodule_path == NULL)
272 g_error("No atspi module provided");
277 load_test_module(tmodule_path, tdata_path);
278 load_atspi_module(amodule_path, &argc, &argv);
279 init_dbus_interface();
280 send_started_signal();
282 mainloop = g_main_loop_new (NULL, FALSE);
283 g_main_loop_run (mainloop);