2.34.1
[platform/upstream/at-spi2-atk.git] / tests / test-application.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
4  *
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 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  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, 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  * The test will provide its own implementation of atk_get_root,
28  * and as such provide all the application state for the test.
29  */
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
34 #include <glib.h>
35 #include <atk/atk.h>
36 #include <atk-bridge.h>
37 #include "my-atk.h"
38 #include "atk-object-xml-loader.h"
39
40 static AtkObject *root_accessible;
41
42 static GMainLoop *mainloop;
43
44 static gchar *tdata_path = NULL;
45
46 void
47 test_init (gchar *path)
48 {
49   gchar *td;
50
51   if (path == NULL) {
52     g_print ("No test data file provided\n");
53     exit (EXIT_FAILURE);
54   }
55   tdata_path = path;
56
57   td = g_build_path (G_DIR_SEPARATOR_S, tdata_path, NULL, NULL);
58   root_accessible = ATK_OBJECT (atk_object_xml_parse (td));
59   g_free (td);
60 }
61
62 AtkObject *
63 test_get_root (void)
64 {
65   return root_accessible;
66 }
67
68 static AtkObject *
69 get_root (void)
70 {
71   return test_get_root ();
72 }
73
74 const gchar *
75 get_toolkit_name (void)
76 {
77   return strdup ("atspitesting-toolkit");
78 }
79
80 static void
81 setup_atk_util (void)
82 {
83   AtkUtilClass *klass;
84
85   klass = g_type_class_ref (ATK_TYPE_UTIL);
86   klass->get_root = get_root;
87   klass->get_toolkit_name = get_toolkit_name;
88   g_type_class_unref (klass);
89 }
90
91 static GOptionEntry optentries[] = {
92   {"test-data-file", 0, 0, G_OPTION_ARG_STRING, &tdata_path, "Path to file of test data", NULL},
93   {NULL}
94 };
95
96 int main (int argc, char *argv[])
97 {
98   GOptionContext *opt;
99   GError *err = NULL;
100   opt = g_option_context_new (NULL);
101   g_option_context_add_main_entries (opt, optentries, NULL);
102   g_option_context_set_ignore_unknown_options (opt, TRUE);
103
104   if (!g_option_context_parse (opt, &argc, &argv, &err))
105     g_error("Option parsing failed: %s\n", err->message);
106
107   setup_atk_util ();
108   test_init (tdata_path);
109   atk_bridge_adaptor_init (NULL, NULL);
110
111   mainloop = g_main_loop_new (NULL, FALSE);
112   g_main_loop_run (mainloop);
113
114   return 0;
115 }