14ea216b833ccf3a276a29722d6cc5e77caad30f
[platform/upstream/at-spi2-atk.git] / tests / atk_suite.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 #include <stdlib.h>
24 #include <stdio.h>
25 #include <glib.h>
26 #include <string.h>
27 #include <sys/wait.h>
28 #include <unistd.h>
29 #include "atk_suite.h"
30 #include "atk_test_util.h"
31
32 static gchar *tdata_list = NULL;
33 static gchar *one_test = NULL;
34
35 typedef struct _Atk_Test_Case Atk_Test_Case;
36
37 struct _Atk_Test_Case {
38   const char *test_case;
39   void (*build)( void);
40 };
41
42 static const Atk_Test_Case atc[] = {
43   { ATK_TEST_PATH_ACCESSIBLE, atk_test_accessible },
44   { ATK_TEST_PATH_ACTION, atk_test_action },
45   { ATK_TEST_PATH_COMP, atk_test_component },
46   { ATK_TEST_PATH_COLLECTION, atk_test_collection },
47   { ATK_TEST_PATH_DOC, atk_test_document },
48   { ATK_TEST_PATH_EDIT_TEXT, atk_test_editable_text },
49   { ATK_TEST_PATH_HYPERLINK, atk_test_hyperlink },
50   { ATK_TEST_PATH_HYPERTEXT, atk_test_hypertext },
51   { ATK_TEST_PATH_IMAGE, atk_test_image },
52   { ATK_TEST_PATH_SELECTION, atk_test_selection },
53   { ATK_TEST_PATH_STATE_SET, atk_test_state_set },
54   { ATK_TEST_PATH_TABLE, atk_test_table },
55   { ATK_TEST_PATH_TABLE_CELL, atk_test_table_cell },
56   { ATK_TEST_PATH_TEXT, atk_test_text },
57   { ATK_TEST_PATH_VALUE, atk_test_value },
58   { NULL, NULL}
59 };
60
61 static void
62 _list_tests (void)
63 {
64   const Atk_Test_Case *itr;
65
66   itr = atc;
67   g_print ("Available Test Cases:\n");
68   for (; itr->test_case; itr++)
69     g_print ("\t%s\n", itr->test_case);
70 }
71
72 static void
73 atk_suite_build (int argc, char **argv )
74 {
75   g_test_init (&argc, &argv, NULL);
76   atk_test_accessible ();
77   atk_test_action ();
78   atk_test_component ();
79   atk_test_collection ();
80   atk_test_document ();
81
82   atk_test_editable_text ();
83   atk_test_hyperlink ();
84   atk_test_hypertext ();
85   atk_test_image ();
86   atk_test_selection ();
87   atk_test_state_set ();
88   atk_test_table ();
89   atk_test_table_cell ();
90   atk_test_text ();
91   atk_test_value ();
92 }
93
94 static GOptionEntry optentries[] = {
95   {"list", 'l', 0, G_OPTION_ARG_NONE, &tdata_list, "Display all available test cases", NULL},
96   {"separate", 0, 0, G_OPTION_ARG_STRING, &one_test, "Run only NAME test", "NAME"},
97   {NULL}
98 };
99
100 int
101 main(int argc, char **argv)
102 {
103   int test_result;
104   GOptionContext *opt;
105   opt = g_option_context_new (NULL);
106   g_option_context_add_main_entries (opt, optentries, NULL);
107   g_option_context_set_help_enabled (opt, TRUE);
108   g_option_context_set_ignore_unknown_options (opt, TRUE);
109
110   if (!g_option_context_parse (opt, &argc, &argv, NULL))
111     return EXIT_FAILURE;
112
113   if (tdata_list) {
114     _list_tests();
115     return EXIT_SUCCESS;
116   }
117
118   clean_exit_on_fail ();
119
120   if (one_test) {
121     if (!g_strcmp0 (one_test, "Accessible")) {
122       g_test_init (&argc, &argv, NULL);
123       atk_test_accessible ();
124       test_result = g_test_run ();
125       return (test_result == 0 ) ? 0 : 255;
126     }
127     if (!g_strcmp0 (one_test, "Action")) {
128       g_test_init (&argc, &argv, NULL);
129       atk_test_action ();
130       test_result = g_test_run ();
131       return (test_result == 0 ) ? 0 : 255;
132     }
133     if (!g_strcmp0 (one_test, "Component")) {
134       g_test_init (&argc, &argv, NULL);
135       atk_test_component ();
136       test_result = g_test_run ();
137       return ( test_result == 0 ) ? 0 : 255;
138     }
139     if (!g_strcmp0 (one_test, "Collection")) {
140       g_test_init (&argc, &argv, NULL);
141       atk_test_collection ();
142       test_result = g_test_run ();
143       return ( test_result == 0 ) ? 0 : 255;
144     }
145     if (!g_strcmp0 (one_test, "Document")) {
146       g_test_init (&argc, &argv, NULL);
147       atk_test_document ();
148       test_result = g_test_run ();
149       return ( test_result == 0 ) ? 0 : 255;
150     }
151     if (!g_strcmp0 (one_test, "Editable_Text")) {
152       g_test_init (&argc, &argv, NULL);
153       atk_test_editable_text ();
154       test_result = g_test_run ();
155       return ( test_result == 0 ) ? 0 : 255;
156     }
157     if (!g_strcmp0 (one_test, "Hyperlink")) {
158       g_test_init (&argc, &argv, NULL);
159       atk_test_hyperlink ();
160       test_result = g_test_run ();
161       return ( test_result == 0 ) ? 0 : 255;
162     }
163     if (!g_strcmp0 (one_test, "Hypertext")) {
164       g_test_init (&argc, &argv, NULL);
165       atk_test_hypertext ();
166       test_result = g_test_run ();
167       return ( test_result == 0 ) ? 0 : 255;
168     }
169     if (!g_strcmp0 (one_test, "Image")) {
170       g_test_init (&argc, &argv, NULL);
171       atk_test_image ();
172       test_result = g_test_run ();
173       return ( test_result == 0 ) ? 0 : 255;
174     }
175     if (!g_strcmp0 (one_test, "Selection")) {
176       g_test_init (&argc, &argv, NULL);
177       atk_test_selection ();
178       test_result = g_test_run ();
179       return ( test_result == 0 ) ? 0 : 255;
180     }
181     if (!g_strcmp0 (one_test, "State_Set")) {
182       g_test_init (&argc, &argv, NULL);
183       atk_test_state_set ();
184       test_result = g_test_run ();
185       return ( test_result == 0 ) ? 0 : 255;
186     }
187     if (!g_strcmp0 (one_test, "Table")) {
188       g_test_init (&argc, &argv, NULL);
189       atk_test_table ();
190       test_result = g_test_run ();
191       return ( test_result == 0 ) ? 0 : 255;
192     }
193     if (!g_strcmp0 (one_test, "Table_Cell")) {
194       g_test_init (&argc, &argv, NULL);
195       atk_test_table_cell ();
196       test_result = g_test_run ();
197       return ( test_result == 0 ) ? 0 : 255;
198     }
199     if (!g_strcmp0 (one_test, "Text")) {
200       g_test_init (&argc, &argv, NULL);
201       atk_test_text ();
202       test_result = g_test_run ();
203       return ( test_result == 0 ) ? 0 : 255;
204     }
205     if (!g_strcmp0 (one_test, "Value")) {
206       g_test_init (&argc, &argv, NULL);
207       atk_test_value ();
208       test_result = g_test_run ();
209       return ( test_result == 0 ) ? 0 : 255;
210     }
211     g_print ("Unknown test name\n");
212     _list_tests ();
213     return EXIT_SUCCESS;
214   }
215   atk_suite_build (argc, argv);
216   test_result = g_test_run ();
217
218   return (test_result == 0 ) ? 0 : 255;
219
220 }