41118e33dec329fa9a69a132d177a2201e5c9560
[platform/core/uifw/at-spi2-atk.git] / tests / apps / test-application.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Codethink Ltd.
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 /*
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.
31  */
32
33 #include <glib.h>
34 #include <gmodule.h>
35 #include <atk/atk.h>
36 #include <dbus/dbus.h>
37
38 /* The test module, GModule containing interface for an atk-test */
39 static GModule *test_module;
40 static gpointer test_module_get_root;
41
42 /* Test module interface */
43 /*************************/
44
45 typedef AtkObject *(*TestModuleGetRoot) (void);
46
47 /* Calls into the test module to get the root atk object */
48 static AtkObject *
49 get_root(void)
50 {
51   return ((TestModuleGetRoot) test_module_get_root)();
52 }
53
54 /*************************/
55
56 /* The AtkUtil class is called to find the root accessible and to deal
57  * with events. Its an incomplete class, its v-table needs to be filled in.
58  */
59 static void
60 setup_atk_util(void)
61 {
62   AtkUtilClass *klass;
63
64   klass = g_type_class_ref(ATK_TYPE_UTIL);
65   klass->get_root = get_root;
66   g_type_class_unref(klass);
67 }
68
69 typedef void (*GtkModuleInit) (int argc, char *argv[]);
70
71 /* AT-SPI is a gtk module that must be loaded and initialized */
72 static void
73 load_atspi_module(const char *path, int argc, char *argv[])
74 {
75   GModule *bridge;
76   gpointer init;
77
78   bridge = g_module_open(path, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY);
79   if (!bridge)
80     g_error("Couldn't load atk-bridge module : %s\n", path);
81
82   if (!g_module_symbol(bridge, "gtk_module_init", &init))
83     g_error("Couldn't load symbol \"gtk_module_init\"\n");
84
85   ((GtkModuleInit) init)(argc, argv);
86 }
87
88 typedef void (*TestModuleInit) (gchar *path);
89
90 static void
91 load_test_module(const char *path, const char *tdpath)
92 {
93   gpointer init;
94
95   test_module = g_module_open(path, G_MODULE_BIND_LOCAL|G_MODULE_BIND_LAZY);
96   if (!test_module)
97     g_error("Couldn't load test module : %s\n", path);
98
99   if (!g_module_symbol(test_module, "test_init", &init))
100     g_error("Couldn't load symbol \"test_init\"\n");
101
102   if (!g_module_symbol(test_module, "test_get_root", &test_module_get_root))
103     g_error("Couldn't load symbol \"test_get_root\"\n");
104
105   ((TestModuleInit) init)((gchar *)tdpath);
106 }
107
108 /*Command line data*/
109 static gchar *tmodule_path = NULL;
110 static gchar *amodule_path = NULL;
111 static gchar *tdata_path = NULL;
112
113 static GOptionEntry optentries[] = 
114 {
115   {"test-module", 't', 0, G_OPTION_ARG_STRING, &tmodule_path, "Module containing test scenario", NULL},
116   {"atspi-module", 'a', 0, G_OPTION_ARG_STRING, &amodule_path, "Gtk module with atk-atspi adaptor", NULL},
117   {"test-data", 'd', 0, G_OPTION_ARG_STRING, &tdata_path, "Path to directory of test data", NULL},
118   {NULL}
119 };
120
121 /* main
122  * 
123  * Entry point for all test applications.
124  */
125 main(int argc, char *argv[])
126 {
127   GMainLoop *mainloop;
128   GOptionContext *opt;
129   GError *err = NULL;
130
131   /*Parse command options*/
132   opt = g_option_context_new(NULL);
133   g_option_context_add_main_entries(opt, optentries, NULL);
134   g_option_context_set_ignore_unknown_options(opt, TRUE);
135   if (!g_option_context_parse(opt, &argc, &argv, &err))
136       g_error("Option parsing failed: %s\n", err->message);
137
138   if (tmodule_path == NULL)
139       g_error("No test module provided");
140   if (amodule_path == NULL)
141       g_error("No atspi module provided");
142
143   g_type_init();
144
145   setup_atk_util();
146   load_test_module(tmodule_path, tdata_path);
147   load_atspi_module(amodule_path, argc, argv);
148
149   mainloop = g_main_loop_new (NULL, FALSE);
150   g_main_loop_run (mainloop);
151
152   return 0;
153 }