2ab74a13faa5fa3fc7c03106f44c88b40fd1f337
[platform/upstream/at-spi2-atk.git] / tests / atk_test_accessible.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 "atk_suite.h"
24 #include "atk_test_util.h"
25
26 #define DATA_FILE TESTS_DATA_DIR"/test-accessible.xml"
27
28 static void
29 teardown_accessible_test (gpointer fixture, gconstpointer user_data)
30 {
31   terminate_app ();
32 }
33
34 static void
35 atk_test_accessible_get_name (gpointer fixture, gconstpointer user_data)
36 {
37   AtspiAccessible *obj = get_root_obj (DATA_FILE);
38   g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
39 }
40
41 static void
42 atk_test_accessible_get_description (gpointer fixture, gconstpointer user_data)
43 {
44   AtspiAccessible *obj = get_root_obj (DATA_FILE);
45   g_assert_cmpstr (atspi_accessible_get_description (obj, NULL), ==, "Root of the accessible tree" );
46 }
47
48 static void
49 atk_test_accessible_get_child_count (gpointer fixture, gconstpointer user_data)
50 {
51   AtspiAccessible *obj = get_root_obj (DATA_FILE);
52   gint child_c = atspi_accessible_get_child_count (obj, NULL);
53   g_assert_cmpint ( 3, ==, child_c );
54 }
55
56 static void
57 atk_test_accessible_get_parent (gpointer fixture, gconstpointer user_data)
58 {
59   AtspiAccessible *obj = get_root_obj (DATA_FILE);
60   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL );
61   AtspiAccessible *parent = atspi_accessible_get_parent (child, NULL );
62   g_assert (parent == obj );
63 }
64
65 static void
66 atk_test_accessible_get_child_at_index (gpointer fixture, gconstpointer user_data)
67 {
68   AtspiAccessible *obj = get_root_obj (DATA_FILE);
69   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL );
70   g_assert_cmpstr (atspi_accessible_get_name (child, NULL), ==, "obj2");
71 }
72
73 static void
74 atk_test_accessible_get_index_in_parent (gpointer fixture, gconstpointer user_data)
75 {
76   AtspiAccessible *obj = get_root_obj (DATA_FILE);
77   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 2, NULL);
78   int index = atspi_accessible_get_index_in_parent (child, NULL);
79   g_assert_cmpint (index, ==, 2);
80 }
81
82 static void
83 atk_test_accessible_get_relation_set_1 (gpointer fixture, gconstpointer user_data)
84 {
85   AtspiAccessible *obj = get_root_obj (DATA_FILE);
86   AtspiAccessible *child1 = atspi_accessible_get_child_at_index (obj, 1, NULL);
87   AtspiAccessible *child = atspi_accessible_get_child_at_index (child1, 0, NULL);
88   GArray *rel_set = atspi_accessible_get_relation_set (child, NULL);
89   g_assert_cmpint (rel_set->len, == , 1);
90 }
91
92 static void
93 atk_test_accessible_get_relation_set_2 (gpointer fixture, gconstpointer user_data)
94 {
95   AtspiAccessible *obj = get_root_obj (DATA_FILE);
96   AtspiAccessible *obj2 = atspi_accessible_get_child_at_index (obj, 1, NULL);
97   AtspiAccessible *obj2_1 = atspi_accessible_get_child_at_index (obj2, 0, NULL);
98   GArray *rel_set = atspi_accessible_get_relation_set (obj2_1, NULL);
99   int i=0;
100   for (i = 0; i < rel_set->len; i++) {
101     AtspiRelation *a = g_array_index (rel_set, AtspiRelation *, i);
102     g_assert_cmpint (atspi_relation_get_relation_type (a), == , ATSPI_RELATION_CONTROLLER_FOR );
103     g_assert_cmpint (atspi_relation_get_n_targets (a), ==, 1);
104     AtspiAccessible *target = atspi_relation_get_target (a, 0);
105     g_assert_cmpstr (atspi_accessible_get_name (target,NULL), == , "obj2");
106   }
107 }
108
109 static void
110 atk_test_accessible_get_role (gpointer fixture, gconstpointer user_data)
111 {
112   AtspiAccessible *obj = get_root_obj (DATA_FILE);
113   AtspiRole root_role = atspi_accessible_get_role (obj, NULL);
114   g_assert_cmpint (root_role, ==, ATSPI_ROLE_ACCELERATOR_LABEL);
115 }
116
117 static void
118 atk_test_accessible_get_role_name (gpointer fixture, gconstpointer user_data)
119 {
120   AtspiAccessible *obj = get_root_obj (DATA_FILE);
121   gchar *root_role_name = atspi_accessible_get_role_name (obj, NULL);
122   g_assert_cmpstr (root_role_name, ==, "accelerator label");
123 }
124
125 static void
126 atk_test_accessible_get_localized_role_name (gpointer fixture, gconstpointer user_data)
127 {
128   AtspiAccessible *obj = get_root_obj (DATA_FILE);
129   gchar *root_role_name = atspi_accessible_get_localized_role_name (obj, NULL);
130   g_assert_cmpstr (root_role_name, ==, "accelerator label");
131 }
132
133 static void
134 atk_test_accessible_get_state_set (gpointer fixture, gconstpointer user_data)
135 {
136   AtspiAccessible *obj = get_root_obj (DATA_FILE);
137   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
138   AtspiStateSet *states = atspi_accessible_get_state_set (child);
139   GArray *states_arr = atspi_state_set_get_states (states);
140
141   AtspiStateType valid_states[] = {
142     ATSPI_STATE_MODAL,
143     ATSPI_STATE_MULTI_LINE,
144   };
145   g_assert_cmpint (states_arr->len, ==, 2);
146   int i = 0;
147   for (i = 0; i < states_arr->len; ++i) {
148     g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
149     g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
150     g_assert (atspi_state_set_contains(states, ATSPI_STATE_MULTI_LINE));
151   }
152 }
153
154 static void
155 atk_test_accessible_get_attributes (gpointer fixture, gconstpointer user_data)
156 {
157   AtspiAccessible *obj = get_root_obj (DATA_FILE);
158   GHashTable *attr_hash_tab = atspi_accessible_get_attributes (obj, NULL);
159   GHashTableIter iter;
160   gpointer key, value;
161
162   gchar *valid_keys[] = { "atspi" };
163   gchar *valid_values[] = { "test" };
164
165   g_hash_table_iter_init (&iter, attr_hash_tab );
166   int i = 0;
167   while (g_hash_table_iter_next (&iter, &key, &value)) {
168     g_assert_cmpstr (valid_keys[i], ==, (gchar *)key );
169     g_assert_cmpstr (valid_values[i], ==, (gchar *)value );
170     ++i;
171   }
172 }
173
174 static void
175 atk_test_accessible_get_attributes_as_array (gpointer fixture, gconstpointer user_data)
176 {
177   AtspiAccessible *obj = get_root_obj (DATA_FILE);
178   gchar *valid_attr[] = { "atspi:test", NULL };
179   GArray *attr_arr = atspi_accessible_get_attributes_as_array ( obj, NULL);
180   int i = 0;
181   g_assert (attr_arr->len == (sizeof(valid_attr)/sizeof(gchar *))-1);
182   for( i = 0; i < attr_arr->len; ++i) {
183     g_assert_cmpstr (valid_attr[i], ==, g_array_index (attr_arr, gchar *, i));
184   }
185 }
186
187 static void
188 atk_test_accessible_get_toolkit_name (gpointer fixture, gconstpointer user_data)
189 {
190   AtspiAccessible *obj = get_root_obj (DATA_FILE);
191   gchar *toolkit_name = atspi_accessible_get_toolkit_name (obj, NULL);
192
193   g_assert_cmpstr (toolkit_name, ==, "atspitesting-toolkit");
194 }
195
196 static void
197 atk_test_accessible_get_toolkit_version (gpointer fixture, gconstpointer user_data)
198 {
199   AtspiAccessible *obj = get_root_obj (DATA_FILE);
200   gchar *toolkit_ver = atspi_accessible_get_toolkit_version (obj, NULL);
201   /* should be empty string, because no value is setted */
202   g_assert_cmpstr (toolkit_ver, ==, "");
203 }
204
205 static void
206 atk_test_accessible_get_atspi_version (gpointer fixture, gconstpointer user_data)
207 {
208   AtspiAccessible *obj = get_root_obj (DATA_FILE);
209   gchar *atspi_version = atspi_accessible_get_atspi_version (obj, NULL);
210   g_assert_cmpstr (atspi_version, ==, "2.1");
211 }
212
213 static void
214 atk_test_accessible_get_id (gpointer fixture, gconstpointer user_data)
215 {
216   AtspiAccessible *obj = get_root_obj (DATA_FILE);
217   gint app_id = atspi_accessible_get_id (obj, NULL);
218   g_assert_cmpint (app_id, !=, -1);
219 }
220
221 static void
222 atk_test_accessible_get_application (gpointer fixture, gconstpointer user_data)
223 {
224   AtspiAccessible *obj = get_root_obj (DATA_FILE);
225   AtspiAccessible *app = atspi_accessible_get_application (obj, NULL);
226   g_assert (app != NULL);
227 }
228
229 static void
230 atk_test_accessible_get_action_iface (gpointer fixture, gconstpointer user_data)
231 {
232   AtspiAccessible *obj = get_root_obj (DATA_FILE);
233   AtspiAction *iface = atspi_accessible_get_action_iface (obj);
234   g_assert (iface == NULL);
235 }
236
237 static void
238 atk_test_accessible_get_collection_iface (gpointer fixture, gconstpointer user_data)
239 {
240   AtspiAccessible *obj = get_root_obj (DATA_FILE);
241   AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
242   g_assert (iface != NULL);
243 }
244
245 static void
246 atk_test_accessible_get_component_iface (gpointer fixture, gconstpointer user_data)
247 {
248   AtspiAccessible *obj = get_root_obj (DATA_FILE);
249   AtspiComponent *iface = atspi_accessible_get_component_iface (obj);
250   g_assert (iface == NULL);
251 }
252
253 static void
254 atk_test_accessible_get_document_iface (gpointer fixture, gconstpointer user_data)
255 {
256   AtspiAccessible *obj = get_root_obj (DATA_FILE);
257   AtspiDocument *iface = atspi_accessible_get_document_iface (obj);
258   g_assert (iface == NULL);
259 }
260
261 static void
262 atk_test_accessible_get_editable_text_iface (gpointer fixture, gconstpointer user_data)
263 {
264   AtspiAccessible *obj = get_root_obj (DATA_FILE);
265   AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (obj);
266   g_assert (iface == NULL);
267 }
268
269 static void
270 atk_test_accessible_get_hypertext_iface (gpointer fixture, gconstpointer user_data)
271 {
272   AtspiAccessible *obj = get_root_obj (DATA_FILE);
273   AtspiHypertext *iface = atspi_accessible_get_hypertext_iface (obj);
274   g_assert (iface == NULL);
275 }
276
277 static void
278 atk_test_accessible_get_image_iface (gpointer fixture, gconstpointer user_data)
279 {
280   AtspiAccessible *obj = get_root_obj (DATA_FILE);
281   AtspiImage *iface = atspi_accessible_get_image_iface (obj);
282   g_assert (iface == NULL);
283 }
284
285 static void
286 atk_test_accessible_get_selection_iface (gpointer fixture, gconstpointer user_data)
287 {
288   AtspiAccessible *obj = get_root_obj (DATA_FILE);
289   AtspiSelection *iface = atspi_accessible_get_selection_iface (obj);
290   g_assert (iface == NULL);
291 }
292
293 static void
294 atk_test_accessible_get_table_iface (gpointer fixture, gconstpointer user_data)
295 {
296   AtspiAccessible *obj = get_root_obj (DATA_FILE);
297   AtspiTable *iface = atspi_accessible_get_table_iface (obj);
298   g_assert (iface == NULL);
299 }
300
301 static void
302 atk_test_accessible_get_text_iface (gpointer fixture, gconstpointer user_data)
303 {
304   AtspiAccessible *obj = get_root_obj (DATA_FILE);
305   AtspiText *iface = atspi_accessible_get_text_iface (obj);
306   g_assert (iface == NULL);
307 }
308
309 static void
310 atk_test_accessible_get_value_iface (gpointer fixture, gconstpointer user_data)
311 {
312   AtspiAccessible *obj = get_root_obj (DATA_FILE);
313   AtspiValue *iface = atspi_accessible_get_value_iface (obj);
314   g_assert (iface == NULL);
315 }
316
317 static void
318 atk_test_accessible_get_interfaces (gpointer fixture, gconstpointer user_data)
319 {
320   AtspiAccessible *obj = get_root_obj (DATA_FILE);
321   gchar *valid_obj_ifaces[] = { "Accessible", "Collection" };
322
323   GArray *ifaces = atspi_accessible_get_interfaces (obj);
324   g_assert (ifaces->len == 2);
325   int i = 0;
326   for (i = 0; i < ifaces->len; ++i)
327     g_assert_cmpstr (valid_obj_ifaces[i], ==, g_array_index (ifaces, gchar *, i));
328 }
329
330 static void
331 atk_test_accessible_get_object_locale (gpointer fixture, gconstpointer user_data)
332 {
333   AtspiAccessible *obj = get_root_obj (DATA_FILE);
334   const gchar *obj_locale = atspi_accessible_get_object_locale (obj, NULL);
335   g_assert_cmpstr (obj_locale, ==, setlocale (LC_MESSAGES, NULL));
336 }
337
338 static void
339 atk_test_accessible_set_cache_mask (gpointer fixture, gconstpointer user_data)
340 {
341   AtspiAccessible *obj = get_root_obj (DATA_FILE);
342   AtspiCache cache_mask = ATSPI_CACHE_ROLE;
343   atspi_accessible_set_cache_mask (obj, cache_mask);
344   g_assert_cmpint (obj->parent.app->cache, ==, cache_mask);
345 }
346
347 static void
348 atk_test_check_cache_cleared (AtspiAccessible *obj)
349 {
350   g_assert_cmpint (obj->cached_properties, ==, ATSPI_CACHE_NONE);
351   GPtrArray *array = obj->children;
352   int i;
353   for (i=0; i<array->len; i++)
354     atk_test_check_cache_cleared (g_ptr_array_index (array, i));
355 }
356
357 static void
358 atk_test_accessible_clear_cache (gpointer fixture, gconstpointer user_data)
359 {
360   AtspiAccessible *obj = get_root_obj (DATA_FILE);
361   atspi_accessible_clear_cache (obj);
362   atk_test_check_cache_cleared (obj);
363 }
364
365 static void
366 atk_test_accessible_get_process_id (gpointer fixture, gconstpointer user_data)
367 {
368   AtspiAccessible *obj = get_root_obj (DATA_FILE);
369   guint proc_id = atspi_accessible_get_process_id (obj, NULL);
370   g_assert_cmpint (proc_id, ==, child_pid);
371 }
372
373 void
374 atk_test_accessible (void)
375 {
376   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_name",
377                      0, NULL, NULL, atk_test_accessible_get_name, teardown_accessible_test);
378   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_description",
379                      0, NULL, NULL, atk_test_accessible_get_description, teardown_accessible_test);
380   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_child_count",
381                      0, NULL, NULL, atk_test_accessible_get_child_count, teardown_accessible_test);
382   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_parent",
383                      0, NULL, NULL, atk_test_accessible_get_parent, teardown_accessible_test);
384   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_child_at_index",
385                      0, NULL, NULL, atk_test_accessible_get_child_at_index, teardown_accessible_test);
386   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_index_in_parent",
387                      0, NULL, NULL, atk_test_accessible_get_index_in_parent, teardown_accessible_test);
388   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_relation_set_1",
389                      0, NULL, NULL, atk_test_accessible_get_relation_set_1, teardown_accessible_test);
390   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_relation_set_2",
391                      0, NULL, NULL, atk_test_accessible_get_relation_set_2, teardown_accessible_test);
392   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_role",
393                      0, NULL, NULL, atk_test_accessible_get_role, teardown_accessible_test);
394   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_role_name",
395                      0, NULL, NULL, atk_test_accessible_get_role_name, teardown_accessible_test);
396   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_localized_role_name",
397                      0, NULL, NULL, atk_test_accessible_get_localized_role_name, teardown_accessible_test);
398   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_state_set",
399                      0, NULL, NULL, atk_test_accessible_get_state_set, teardown_accessible_test);
400   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_attributes",
401                      0, NULL, NULL, atk_test_accessible_get_attributes, teardown_accessible_test);
402   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_attributes_as_array",
403                      0, NULL, NULL, atk_test_accessible_get_attributes_as_array, teardown_accessible_test);
404   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_toolkit_name",
405                      0, NULL, NULL, atk_test_accessible_get_toolkit_name, teardown_accessible_test);
406   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_toolkit_version",
407                      0, NULL, NULL, atk_test_accessible_get_toolkit_version, teardown_accessible_test);
408   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_atspi_version",
409                      0, NULL, NULL, atk_test_accessible_get_atspi_version, teardown_accessible_test);
410   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_id",
411                      0, NULL, NULL, atk_test_accessible_get_id, teardown_accessible_test);
412   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_application",
413                      0, NULL, NULL, atk_test_accessible_get_application, teardown_accessible_test);
414   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_action_iface",
415                      0, NULL, NULL, atk_test_accessible_get_action_iface, teardown_accessible_test);
416   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_collection_iface",
417                      0, NULL, NULL, atk_test_accessible_get_collection_iface, teardown_accessible_test);
418   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_component_iface",
419                      0, NULL, NULL, atk_test_accessible_get_component_iface, teardown_accessible_test);
420   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_document_iface",
421                      0, NULL, NULL, atk_test_accessible_get_document_iface, teardown_accessible_test);
422   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_editable_text_iface",
423                      0, NULL, NULL, atk_test_accessible_get_editable_text_iface, teardown_accessible_test);
424   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_hypertext_iface",
425                      0, NULL, NULL, atk_test_accessible_get_hypertext_iface, teardown_accessible_test);
426   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_image_iface",
427                      0, NULL, NULL, atk_test_accessible_get_image_iface, teardown_accessible_test);
428   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_selection_iface",
429                      0, NULL, NULL, atk_test_accessible_get_selection_iface, teardown_accessible_test);
430   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_table_iface",
431                      0, NULL, NULL, atk_test_accessible_get_table_iface, teardown_accessible_test);
432   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_text_iface",
433                      0, NULL, NULL, atk_test_accessible_get_text_iface, teardown_accessible_test);
434   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_value_iface",
435                      0, NULL, NULL, atk_test_accessible_get_value_iface, teardown_accessible_test);
436   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_interfaces",
437                      0, NULL, NULL, atk_test_accessible_get_interfaces, teardown_accessible_test);
438   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_object_locale",
439                      0, NULL, NULL, atk_test_accessible_get_object_locale, teardown_accessible_test);
440   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_set_cache_mask",
441                      0, NULL, NULL, atk_test_accessible_set_cache_mask, teardown_accessible_test);
442   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_clear_cache",
443                      0, NULL, NULL, atk_test_accessible_clear_cache, teardown_accessible_test);
444   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accessible_get_process_id",
445                      0, NULL, NULL, atk_test_accessible_get_process_id, teardown_accessible_test);
446 }