1 /*
2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
4 *
5 * Copyright (c) 2015 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-selection.xml"
27
28 static void
teardown_selection_test(gpointer fixture,gconstpointer user_data)29 teardown_selection_test (gpointer fixture, gconstpointer user_data)
30 {
31 terminate_app ();
32 }
33
34 static void
atk_test_selection_sample_get_interface(gpointer fixture,gconstpointer user_data)35 atk_test_selection_sample_get_interface (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 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
40 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
41 g_assert (iface != NULL);
42 }
43
44 static void
atk_test_selection_get_n_selected_children(gpointer fixture,gconstpointer user_data)45 atk_test_selection_get_n_selected_children (gpointer fixture, gconstpointer user_data)
46 {
47 AtspiAccessible *obj = get_root_obj (DATA_FILE);
48 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
49 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
50 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
51 g_assert (iface != NULL);
52
53 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
54 }
55
56 static void
atk_test_selection_get_selected_child(gpointer fixture,gconstpointer user_data)57 atk_test_selection_get_selected_child (gpointer fixture, gconstpointer user_data)
58 {
59 AtspiAccessible *obj = get_root_obj (DATA_FILE);
60 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
61 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
62 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
63 g_assert (iface != NULL);
64 gchar* valid_names[] = { "obj2/1", "obj2/2", "obj3/1"};
65
66 AtspiAccessible *o = NULL;
67 int i=0;
68 int selected_count = atspi_selection_get_n_selected_children (iface, NULL);
69 for (i=0; i<selected_count; i++) {
70 o = atspi_selection_get_selected_child (iface, i, NULL);
71 g_assert_cmpstr (atspi_accessible_get_name (o, NULL), ==, valid_names[i]);
72 }
73 }
74
75 static void
atk_test_selection_select_child(gpointer fixture,gconstpointer user_data)76 atk_test_selection_select_child (gpointer fixture, gconstpointer user_data)
77 {
78 AtspiAccessible *obj = get_root_obj (DATA_FILE);
79 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
80 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
81 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
82 g_assert (iface != NULL);
83
84 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
85
86 atspi_selection_select_child (iface, 2, NULL);
87 atspi_selection_select_child (iface, 3, NULL);
88 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 5);
89 }
90
91 static void
atk_test_selection_deselect_selected(gpointer fixture,gconstpointer user_data)92 atk_test_selection_deselect_selected (gpointer fixture, gconstpointer user_data)
93 {
94 AtspiAccessible *obj = get_root_obj (DATA_FILE);
95 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
96 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
97 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
98 g_assert (iface != NULL);
99
100 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
101
102 atspi_selection_select_child (iface, 2, NULL);
103 atspi_selection_select_child (iface, 3, NULL);
104 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 5);
105
106 atspi_selection_deselect_selected_child (iface, 2, NULL);
107 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 4);
108 }
109
110 static void
atk_test_selection_deselect_child(gpointer fixture,gconstpointer user_data)111 atk_test_selection_deselect_child (gpointer fixture, gconstpointer user_data)
112 {
113 AtspiAccessible *obj = get_root_obj (DATA_FILE);
114 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
115 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
116 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
117 g_assert (iface != NULL);
118
119 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
120
121 atspi_selection_select_child (iface, 2, NULL);
122 atspi_selection_select_child (iface, 3, NULL);
123 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 5);
124
125 atspi_selection_deselect_child (iface, 2, NULL);
126 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 4);
127 }
128
129 static void
atk_test_selection_is_child_selected(gpointer fixture,gconstpointer user_data)130 atk_test_selection_is_child_selected (gpointer fixture, gconstpointer user_data)
131 {
132 AtspiAccessible *obj = get_root_obj (DATA_FILE);
133 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
134 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
135 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
136 g_assert (iface != NULL);
137
138 g_assert (atspi_selection_is_child_selected (iface, 0, NULL));
139 g_assert (atspi_selection_is_child_selected (iface, 1, NULL));
140 g_assert (atspi_selection_is_child_selected (iface, 4, NULL));
141 g_assert (!atspi_selection_is_child_selected (iface, 2, NULL));
142 g_assert (!atspi_selection_is_child_selected (iface, 3, NULL));
143 }
144
145 static void
atk_test_selection_select_all(gpointer fixture,gconstpointer user_data)146 atk_test_selection_select_all (gpointer fixture, gconstpointer user_data)
147 {
148 AtspiAccessible *obj = get_root_obj (DATA_FILE);
149 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
150 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
151 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
152 g_assert (iface != NULL);
153
154 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
155 atspi_selection_select_all (iface, NULL);
156 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 5);
157 }
158
159 static void
atk_test_selection_clear_selection(gpointer fixture,gconstpointer user_data)160 atk_test_selection_clear_selection (gpointer fixture, gconstpointer user_data)
161 {
162 AtspiAccessible *obj = get_root_obj (DATA_FILE);
163 g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
164 AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
165 AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
166 g_assert (iface != NULL);
167
168 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
169 atspi_selection_clear_selection (iface, NULL);
170 g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 0);
171 }
172
173 void
atk_test_selection(void)174 atk_test_selection (void)
175 {
176 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_sample_get_interface",
177 0, NULL, NULL, atk_test_selection_sample_get_interface, teardown_selection_test);
178 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_get_n_selected_children",
179 0, NULL, NULL, atk_test_selection_get_n_selected_children, teardown_selection_test);
180 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_get_selected_child",
181 0, NULL, NULL, atk_test_selection_get_selected_child, teardown_selection_test);
182 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_select_child",
183 0, NULL, NULL, atk_test_selection_select_child, teardown_selection_test);
184 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_deselect_selected",
185 0, NULL, NULL, atk_test_selection_deselect_selected, teardown_selection_test);
186 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_deselect_child",
187 0, NULL, NULL, atk_test_selection_deselect_child, teardown_selection_test);
188 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_is_child_selected",
189 0, NULL, NULL, atk_test_selection_is_child_selected, teardown_selection_test);
190 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_select_all",
191 0, NULL, NULL, atk_test_selection_select_all, teardown_selection_test);
192 g_test_add_vtable (ATK_TEST_PATH_SELECTION "/atk_test_selection_clear_selection",
193 0, NULL, NULL, atk_test_selection_clear_selection, teardown_selection_test);
194
195 }
196