2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
5 * Copyright (c) 2014 Samsung Electronics Co., 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.
23 #include "atk_suite.h"
24 #include "atk_test_util.h"
26 #define DATA_FILE TESTS_DATA_DIR"/test-accessible.xml"
29 teardown_accessible_test (gpointer fixture, gconstpointer user_data)
31 kill (child_pid, SIGTERM);
35 atk_test_accessible_get_name (gpointer fixture, gconstpointer user_data)
37 AtspiAccessible *obj = get_root_obj (DATA_FILE);
38 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
42 atk_test_accessible_get_description (gpointer fixture, gconstpointer user_data)
44 AtspiAccessible *obj = get_root_obj (DATA_FILE);
45 g_assert_cmpstr (atspi_accessible_get_description (obj, NULL), ==, "Root of the accessible tree" );
49 atk_test_accessible_get_child_count (gpointer fixture, gconstpointer user_data)
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 );
57 atk_test_accessible_get_parent (gpointer fixture, gconstpointer user_data)
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 );
66 atk_test_accessible_get_child_at_index (gpointer fixture, gconstpointer user_data)
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");
74 atk_test_accessible_get_index_in_parent (gpointer fixture, gconstpointer user_data)
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);
83 atk_test_accessible_get_relation_set_1 (gpointer fixture, gconstpointer user_data)
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);
93 atk_test_accessible_get_relation_set_2 (gpointer fixture, gconstpointer user_data)
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);
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");
110 atk_test_accessible_get_role (gpointer fixture, gconstpointer user_data)
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);
118 atk_test_accessible_get_role_name (gpointer fixture, gconstpointer user_data)
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");
126 atk_test_accessible_get_localized_role_name (gpointer fixture, gconstpointer user_data)
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");
134 atk_test_accessible_get_state_set (gpointer fixture, gconstpointer user_data)
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);
141 AtspiStateType valid_states[] = {
143 ATSPI_STATE_MULTI_LINE,
145 g_assert_cmpint (states_arr->len, ==, 2);
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));
155 atk_test_accessible_get_attributes (gpointer fixture, gconstpointer user_data)
157 AtspiAccessible *obj = get_root_obj (DATA_FILE);
158 GHashTable *attr_hash_tab = atspi_accessible_get_attributes (obj, NULL);
162 gchar *valid_keys[] = { "atspi" };
163 gchar *valid_values[] = { "test" };
165 g_hash_table_iter_init (&iter, attr_hash_tab );
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 );
175 atk_test_accessible_get_attributes_as_array (gpointer fixture, gconstpointer user_data)
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);
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));
188 atk_test_accessible_get_toolkit_name (gpointer fixture, gconstpointer user_data)
190 AtspiAccessible *obj = get_root_obj (DATA_FILE);
191 gchar *toolkit_name = atspi_accessible_get_toolkit_name (obj, NULL);
193 g_assert_cmpstr (toolkit_name, ==, "atspitesting-toolkit");
197 atk_test_accessible_get_toolkit_version (gpointer fixture, gconstpointer user_data)
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, ==, "");
206 atk_test_accessible_get_atspi_version (gpointer fixture, gconstpointer user_data)
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");
214 atk_test_accessible_get_id (gpointer fixture, gconstpointer user_data)
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);
222 atk_test_accessible_get_application (gpointer fixture, gconstpointer user_data)
224 AtspiAccessible *obj = get_root_obj (DATA_FILE);
225 AtspiAccessible *app = atspi_accessible_get_application (obj, NULL);
226 g_assert (app != NULL);
230 atk_test_accessible_get_action_iface (gpointer fixture, gconstpointer user_data)
232 AtspiAccessible *obj = get_root_obj (DATA_FILE);
233 AtspiAction *iface = atspi_accessible_get_action_iface (obj);
234 g_assert (iface == NULL);
238 atk_test_accessible_get_collection_iface (gpointer fixture, gconstpointer user_data)
240 AtspiAccessible *obj = get_root_obj (DATA_FILE);
241 AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
242 g_assert (iface != NULL);
246 atk_test_accessible_get_component_iface (gpointer fixture, gconstpointer user_data)
248 AtspiAccessible *obj = get_root_obj (DATA_FILE);
249 AtspiComponent *iface = atspi_accessible_get_component_iface (obj);
250 g_assert (iface == NULL);
254 atk_test_accessible_get_document_iface (gpointer fixture, gconstpointer user_data)
256 AtspiAccessible *obj = get_root_obj (DATA_FILE);
257 AtspiDocument *iface = atspi_accessible_get_document_iface (obj);
258 g_assert (iface == NULL);
262 atk_test_accessible_get_editable_text_iface (gpointer fixture, gconstpointer user_data)
264 AtspiAccessible *obj = get_root_obj (DATA_FILE);
265 AtspiEditableText *iface = atspi_accessible_get_editable_text_iface (obj);
266 g_assert (iface == NULL);
270 atk_test_accessible_get_hypertext_iface (gpointer fixture, gconstpointer user_data)
272 AtspiAccessible *obj = get_root_obj (DATA_FILE);
273 AtspiHypertext *iface = atspi_accessible_get_hypertext_iface (obj);
274 g_assert (iface == NULL);
278 atk_test_accessible_get_image_iface (gpointer fixture, gconstpointer user_data)
280 AtspiAccessible *obj = get_root_obj (DATA_FILE);
281 AtspiImage *iface = atspi_accessible_get_image_iface (obj);
282 g_assert (iface == NULL);
286 atk_test_accessible_get_selection_iface (gpointer fixture, gconstpointer user_data)
288 AtspiAccessible *obj = get_root_obj (DATA_FILE);
289 AtspiSelection *iface = atspi_accessible_get_selection_iface (obj);
290 g_assert (iface == NULL);
294 atk_test_accessible_get_table_iface (gpointer fixture, gconstpointer user_data)
296 AtspiAccessible *obj = get_root_obj (DATA_FILE);
297 AtspiTable *iface = atspi_accessible_get_table_iface (obj);
298 g_assert (iface == NULL);
302 atk_test_accessible_get_text_iface (gpointer fixture, gconstpointer user_data)
304 AtspiAccessible *obj = get_root_obj (DATA_FILE);
305 AtspiText *iface = atspi_accessible_get_text_iface (obj);
306 g_assert (iface == NULL);
310 atk_test_accessible_get_value_iface (gpointer fixture, gconstpointer user_data)
312 AtspiAccessible *obj = get_root_obj (DATA_FILE);
313 AtspiValue *iface = atspi_accessible_get_value_iface (obj);
314 g_assert (iface == NULL);
318 atk_test_accessible_get_interfaces (gpointer fixture, gconstpointer user_data)
320 AtspiAccessible *obj = get_root_obj (DATA_FILE);
321 gchar *valid_obj_ifaces[] = { "Accessible", "Collection" };
323 GArray *ifaces = atspi_accessible_get_interfaces (obj);
324 g_assert (ifaces->len == 2);
326 for (i = 0; i < ifaces->len; ++i)
327 g_assert_cmpstr (valid_obj_ifaces[i], ==, g_array_index (ifaces, gchar *, i));
331 atk_test_accessible_get_object_locale (gpointer fixture, gconstpointer user_data)
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));
339 atk_test_accessible_set_cache_mask (gpointer fixture, gconstpointer user_data)
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);
348 atk_test_check_cache_cleared (AtspiAccessible *obj)
350 g_assert_cmpint (obj->cached_properties, ==, ATSPI_CACHE_NONE);
351 GPtrArray *array = obj->children;
353 for (i=0; i<array->len; i++)
354 atk_test_check_cache_cleared (g_ptr_array_index (array, i));
358 atk_test_accessible_clear_cache (gpointer fixture, gconstpointer user_data)
360 AtspiAccessible *obj = get_root_obj (DATA_FILE);
361 atspi_accessible_clear_cache (obj);
362 atk_test_check_cache_cleared (obj);
366 atk_test_accessible_get_process_id (gpointer fixture, gconstpointer user_data)
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);
374 atk_test_accessible (void)
376 g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_accesible_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);