2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
5 * Copyright (c) 2015 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_state_set_test (gpointer fixture, gconstpointer user_data)
31 kill (child_pid, SIGTERM);
35 atk_test_accessible_get_state_set (gpointer fixture, gconstpointer user_data)
37 AtspiAccessible *obj = get_root_obj (DATA_FILE);
38 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
39 AtspiStateSet *states = atspi_accessible_get_state_set (child);
40 GArray *states_arr = atspi_state_set_get_states (states);
42 AtspiStateType valid_states[] = {
44 ATSPI_STATE_MULTI_LINE,
46 g_assert_cmpint (states_arr->len, ==, 2);
48 for (i = 0; i < states_arr->len; ++i) {
49 g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
50 g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
51 g_assert (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
56 atk_test_state_set_new (gpointer fixture, gconstpointer user_data)
58 GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));
61 state = 11; // ATSPI_STATE_FOCUSABLE
62 g_array_append_val (states_arr, state);
63 state = 12; // ATSPI_STATE_FOCUSED
64 g_array_append_val (states_arr, state);
66 g_assert_cmpint (states_arr->len, ==, 2);
68 AtspiStateSet *ss = atspi_state_set_new (states_arr);
70 AtspiStateType valid_states[] = {
71 ATSPI_STATE_FOCUSABLE,
75 g_assert (atspi_state_set_contains (ss, valid_states[0]));
76 g_assert (atspi_state_set_contains (ss, valid_states[1]));
78 for (i = 0; i < states_arr->len; ++i) {
79 g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
84 atk_test_state_set_set_by_name (gpointer fixture, gconstpointer user_data)
86 AtspiAccessible *obj = get_root_obj (DATA_FILE);
87 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
88 AtspiStateSet *states = atspi_accessible_get_state_set (child);
89 GArray *states_arr = atspi_state_set_get_states (states);
91 atspi_state_set_set_by_name (states, "modal", FALSE);
93 states_arr = atspi_state_set_get_states (states);
95 g_assert_cmpint (states_arr->len, ==, 1);
96 g_assert (!atspi_state_set_contains (states, ATSPI_STATE_MODAL));
97 g_assert (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
99 atspi_state_set_set_by_name (states, "modal", TRUE);
100 g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
104 atk_test_state_set_add (gpointer fixture, gconstpointer user_data)
106 AtspiAccessible *obj = get_root_obj (DATA_FILE);
107 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
108 AtspiStateSet *states = atspi_accessible_get_state_set (child);
110 g_assert (!atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));
112 atspi_state_set_add (states, ATSPI_STATE_FOCUSABLE);
114 g_assert (atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));
119 atk_test_state_set_compare (gpointer fixture, gconstpointer user_data)
121 AtspiAccessible *obj = get_root_obj (DATA_FILE);
122 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
123 AtspiStateSet *states = atspi_accessible_get_state_set (child);
124 GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));
127 state = 11; // ATSPI_STATE_FOCUSABLE
128 g_array_append_val (states_arr, state);
129 state = 12; // ATSPI_STATE_FOCUSED
130 g_array_append_val (states_arr, state);
132 g_assert_cmpint (states_arr->len, ==, 2);
134 AtspiStateSet *ss = atspi_state_set_new (states_arr);
136 AtspiStateSet *ret = atspi_state_set_compare (states, ss);
138 g_assert (atspi_state_set_contains (ret, ATSPI_STATE_MODAL));
139 g_assert (atspi_state_set_contains (ret, ATSPI_STATE_MULTI_LINE));
140 g_assert (atspi_state_set_contains (ret, ATSPI_STATE_FOCUSED));
141 g_assert (atspi_state_set_contains (ret, ATSPI_STATE_FOCUSABLE));
145 atk_test_state_set_contains (gpointer fixture, gconstpointer user_data)
147 AtspiAccessible *obj = get_root_obj (DATA_FILE);
148 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
149 AtspiStateSet *states = atspi_accessible_get_state_set (child);
151 g_assert (!atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));
152 g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
156 atk_test_state_set_equals (gpointer fixture, gconstpointer user_data)
158 AtspiAccessible *obj = get_root_obj (DATA_FILE);
159 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
160 AtspiStateSet *states = atspi_accessible_get_state_set (child);
161 GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));
164 state = 16; // ATSPI_STATE_MODAL
165 g_array_append_val (states_arr, state);
166 state = 17; // ATSPI_STATE_MULTI_LINE
167 g_array_append_val (states_arr, state);
169 g_assert_cmpint (states_arr->len, ==, 2);
171 AtspiStateSet *ss = atspi_state_set_new (states_arr);
173 g_assert (atspi_state_set_equals (states, ss));
177 atk_test_state_set_get_states (gpointer fixture, gconstpointer user_data)
179 AtspiAccessible *obj = get_root_obj (DATA_FILE);
180 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
181 AtspiStateSet *states = atspi_accessible_get_state_set (child);
182 GArray *states_arr = atspi_state_set_get_states (states);
184 AtspiStateType valid_states[] = {
186 ATSPI_STATE_MULTI_LINE,
188 g_assert_cmpint (states_arr->len, ==, 2);
190 for (i = 0; i < states_arr->len; ++i)
191 g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
192 g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
193 g_assert (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
197 atk_test_state_set_is_empty (gpointer fixture, gconstpointer user_data)
199 AtspiAccessible *obj = get_root_obj (DATA_FILE);
200 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
201 AtspiStateSet *states = atspi_accessible_get_state_set (child);
202 AtspiStateSet *root_states = atspi_accessible_get_state_set (obj);
204 g_assert (!atspi_state_set_is_empty (states));
205 g_assert (atspi_state_set_is_empty (root_states));
209 atk_test_state_set_remove (gpointer fixture, gconstpointer user_data)
211 AtspiAccessible *obj = get_root_obj (DATA_FILE);
212 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
213 AtspiStateSet *states = atspi_accessible_get_state_set (child);
214 GArray *states_arr = atspi_state_set_get_states (states);
216 g_assert_cmpint (states_arr->len, ==, 2);
217 atspi_state_set_remove (states, ATSPI_STATE_MODAL);
219 states_arr = atspi_state_set_get_states (states);
221 g_assert_cmpint (states_arr->len, ==, 1);
222 g_assert (!atspi_state_set_contains (states, ATSPI_STATE_MODAL));
223 g_assert (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
227 atk_test_state_set (void)
229 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_accessible_get_state_set",
230 0, NULL, NULL, atk_test_accessible_get_state_set, teardown_state_set_test);
231 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_new",
232 0, NULL, NULL, atk_test_state_set_new, teardown_state_set_test);
233 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_set_by_name",
234 0, NULL, NULL, atk_test_state_set_set_by_name, teardown_state_set_test);
235 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_add",
236 0, NULL, NULL, atk_test_state_set_add, teardown_state_set_test);
237 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_compare",
238 0, NULL, NULL, atk_test_state_set_compare, teardown_state_set_test);
239 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_contains",
240 0, NULL, NULL, atk_test_state_set_contains, teardown_state_set_test);
241 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_equals",
242 0, NULL, NULL, atk_test_state_set_equals, teardown_state_set_test);
243 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_get_states",
244 0, NULL, NULL, atk_test_state_set_get_states, teardown_state_set_test);
245 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_is_empty",
246 0, NULL, NULL, atk_test_state_set_is_empty, teardown_state_set_test);
247 g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_remove",
248 0, NULL, NULL, atk_test_state_set_remove, teardown_state_set_test);