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_test_util.h"
24 #include "atk_suite.h"
26 #define DATA_FILE TESTS_DATA_DIR"/test-text.xml"
28 static gboolean GHRunc_find (gpointer key, gpointer value, gpointer user_data)
30 if (!g_strcmp0 (key, user_data)) {
37 atk_test_text_get_character_count (gpointer fixture, gconstpointer user_data)
39 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
41 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
43 AtspiText *obj = atspi_accessible_get_text_iface (child);
45 gint count = atspi_text_get_character_count (obj, NULL);
46 g_assert_cmpint (count, ==, 16);
50 atk_test_text_get_text (gpointer fixture, gconstpointer user_data)
52 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
54 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
56 AtspiText *obj = atspi_accessible_get_text_iface (child);
58 gchar *text = atspi_text_get_text (obj, 9, 14, NULL);
59 g_assert_cmpstr (text, ==, "works");
64 atk_test_text_get_caret_offset (gpointer fixture, gconstpointer user_data)
66 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
68 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
70 AtspiText *obj = atspi_accessible_get_text_iface (child);
72 gint pos = atspi_text_get_caret_offset (obj, NULL);
73 g_assert_cmpint (pos,==,-1);
77 atk_test_text_set_caret_offset (gpointer fixture, gconstpointer user_data)
79 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
81 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
83 AtspiText *obj = atspi_accessible_get_text_iface (child);
85 g_assert_true (atspi_text_set_caret_offset (obj, 5, NULL));
86 g_assert_false (atspi_text_set_caret_offset (obj, -1, NULL));
87 gint pos = atspi_text_get_caret_offset (obj, NULL);
88 g_assert_cmpint (pos, ==, 5);
91 atk_test_text_get_character_at_offset (gpointer fixture, gconstpointer user_data)
93 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
95 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
97 AtspiText *obj = atspi_accessible_get_text_iface (child);
99 guint chr = atspi_text_get_character_at_offset (obj, 5, NULL);
100 g_assert_cmpint (chr, ==, 32);
104 atk_test_text_get_character_extents (gpointer fixture, gconstpointer user_data)
106 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
108 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
110 AtspiText *obj = atspi_accessible_get_text_iface (child);
112 AtspiRect *rec = atspi_text_get_character_extents (obj, 6, ATSPI_COORD_TYPE_SCREEN, NULL);
113 g_assert_cmpint (rec->x, ==, 100);
114 g_assert_cmpint (rec->y, ==, 33);
115 g_assert_cmpint (rec->width, ==, 110);
116 g_assert_cmpint (rec->height, ==, 30);
122 atk_test_text_get_range_extents (gpointer fixture, gconstpointer user_data)
124 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
126 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
128 AtspiText *obj = atspi_accessible_get_text_iface (child);
130 AtspiRect *rec = atspi_text_get_range_extents (obj, 0, 1, ATSPI_COORD_TYPE_SCREEN, NULL);
132 g_assert_cmpint (rec->x, ==, 100);
133 g_assert_cmpint (rec->y, ==, 33);
134 g_assert_cmpint (rec->width, ==, 110);
135 g_assert_cmpint (rec->height, ==, 30);
141 atk_test_text_add_selection (gpointer fixture, gconstpointer user_data)
143 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
145 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
147 AtspiText *obj = atspi_accessible_get_text_iface (child);
149 g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL));
153 atk_test_text_get_n_selections (gpointer fixture, gconstpointer user_data)
155 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
157 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
159 AtspiText *obj = atspi_accessible_get_text_iface (child);
161 gint n = atspi_text_get_n_selections (obj, NULL);
162 g_assert_cmpint (n, ==, 0);
163 g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL));
164 g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL));
165 g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL));
166 n = atspi_text_get_n_selections (obj, NULL);
167 g_assert_cmpint (n, ==, 3);
171 atk_test_text_get_selection (gpointer fixture, gconstpointer user_data)
173 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
175 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
177 AtspiText *obj = atspi_accessible_get_text_iface (child);
179 g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL));
180 g_assert_true (atspi_text_add_selection (obj, 14, 15, NULL));
182 AtspiRange *range = atspi_text_get_selection (obj, 0, NULL);
184 g_assert_cmpint (range->start_offset, ==, 9);
185 g_assert_cmpint (range->end_offset, ==, 14);
188 range = atspi_text_get_selection (obj, 1, NULL);
190 g_assert_cmpint (range->start_offset, ==, 14);
191 g_assert_cmpint (range->end_offset, ==, 15);
196 atk_test_text_set_selection (gpointer fixture, gconstpointer user_data)
198 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
200 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
202 AtspiText *obj = atspi_accessible_get_text_iface (child);
204 g_assert_true(atspi_text_add_selection (obj, 9, 14, NULL));
205 g_assert_true(atspi_text_add_selection (obj, 14, 15, NULL));
206 g_assert_true(atspi_text_set_selection (obj, 0, 1, 2, NULL));
207 g_assert_true(atspi_text_set_selection (obj, 1, 3, 4, NULL));
209 AtspiRange *range = atspi_text_get_selection (obj, 0, NULL);
211 g_assert_cmpint (range->start_offset, ==, 1);
212 g_assert_cmpint (range->end_offset, ==, 2);
215 range = atspi_text_get_selection (obj, 1, NULL);
217 g_assert_cmpint (range->start_offset, ==, 3);
218 g_assert_cmpint (range->end_offset, ==, 4);
223 atk_test_text_remove_selection (gpointer fixture, gconstpointer user_data)
225 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
227 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
229 AtspiText *obj = atspi_accessible_get_text_iface (child);
231 gint n = atspi_text_get_n_selections (obj, NULL);
232 g_assert_cmpint (n, ==, 0);
234 g_assert_true (atspi_text_add_selection (obj, 9, 14, NULL));
235 g_assert_true (atspi_text_add_selection (obj, 14, 15, NULL));
236 n = atspi_text_get_n_selections (obj, NULL);
237 g_assert_cmpint (n, ==, 2);
239 g_assert_true (atspi_text_remove_selection (obj, 1, NULL));
240 n = atspi_text_get_n_selections (obj, NULL);
241 g_assert_cmpint (n, ==, 1);
243 g_assert_true (atspi_text_remove_selection (obj, 0, NULL));
244 n = atspi_text_get_n_selections (obj, NULL);
245 g_assert_cmpint (n, ==, 0);
249 atk_test_text_get_offset_at_point (gpointer fixture, gconstpointer user_data)
251 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
253 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
255 AtspiText *obj = atspi_accessible_get_text_iface (child);
257 gint n = atspi_text_get_offset_at_point (obj, 0, 0, ATSPI_COORD_TYPE_SCREEN, NULL);
258 g_assert_cmpint (n, ==, 5);
262 atk_test_text_get_text_attribute_value (gpointer fixture, gconstpointer user_data)
264 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
266 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
268 AtspiText *obj = atspi_accessible_get_text_iface (child);
271 gchar *str = atspi_text_get_text_attribute_value (obj, 0, "text_test_attr1", &err);
273 g_print ("error msg:%s\n", err->message);
275 g_assert_cmpstr (str, ==, "on");
278 str = atspi_text_get_text_attribute_value (obj, 0, "text_test_attr2", NULL);
280 g_assert_cmpstr (str, ==, "off");
285 atk_test_text_get_attribute_run (gpointer fixture, gconstpointer user_data)
287 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
289 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
291 AtspiText *obj = atspi_accessible_get_text_iface (child);
293 gint start_offset = 0;
295 GHashTable *tab = atspi_text_get_attribute_run (obj, 0, FALSE, &start_offset, &end_offset , NULL);
299 g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "text_test_attr1"), ==, "on");
300 g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "text_test_attr2"), ==, "off");
301 g_assert_cmpint (start_offset, == , 5);
302 g_assert_cmpint (end_offset, == , 10);
303 g_hash_table_destroy (tab);
307 atk_test_text_get_defualt_attributes (gpointer fixture, gconstpointer user_data)
309 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
311 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
313 AtspiText *obj = atspi_accessible_get_text_iface (child);
315 GHashTable *tab = atspi_text_get_default_attributes (obj, NULL);
318 g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "bold_text"), ==, "on");
319 g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "underline_text"), ==, "off");
320 g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "dummy_text"), ==, "");
321 g_hash_table_destroy (tab);
325 atk_test_text_get_text_attributes (gpointer fixture, gconstpointer user_data)
327 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
329 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
331 AtspiText *obj = atspi_accessible_get_text_iface (child);
333 gint start_offset = 0;
335 GHashTable *tab = atspi_text_get_text_attributes (obj, 0, &start_offset, &end_offset, NULL);
339 g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "text_test_attr1"), ==, "on");
340 g_assert_cmpstr ((const char*) g_hash_table_find (tab, GHRunc_find, "text_test_attr2"), ==, "off");
341 g_assert_cmpint (start_offset, == , 5);
342 g_assert_cmpint (end_offset, == , 10);
343 g_hash_table_destroy (tab);
347 atk_test_text_get_string_at_offset_s1 (gpointer fixture, gconstpointer user_data)
349 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
351 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
353 AtspiText *obj = atspi_accessible_get_text_iface (child);
355 AtspiTextRange *range = atspi_text_get_string_at_offset (obj, 0, ATSPI_TEXT_GRANULARITY_CHAR, NULL);
357 g_assert_cmpint (range->start_offset, ==, 0);
358 g_assert_cmpint (range->end_offset, ==, 1);
359 g_assert_cmpstr (range->content, ==, "t");
363 range = atspi_text_get_string_at_offset (obj, 5, ATSPI_TEXT_GRANULARITY_WORD, NULL);
365 g_assert_cmpint (range->start_offset, ==, 6);
366 g_assert_cmpint (range->end_offset, ==, 7);
367 g_assert_cmpstr (range->content, ==, "it");
372 atk_test_text_get_string_at_offset_s2 (gpointer fixture, gconstpointer user_data)
374 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
376 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 1, NULL);
378 AtspiText *obj = atspi_accessible_get_text_iface (child);
380 AtspiTextRange *range = atspi_text_get_string_at_offset (obj, 20, ATSPI_TEXT_GRANULARITY_SENTENCE, NULL);
382 g_assert_cmpint (range->start_offset, ==, 18);
383 g_assert_cmpint (range->end_offset, ==, 34);
384 g_assert_cmpstr (range->content, ==, "Second sentence.");
388 range = atspi_text_get_string_at_offset (obj, 21, ATSPI_TEXT_GRANULARITY_LINE, NULL);
390 g_assert_cmpint (range->start_offset, ==, 18);
391 g_assert_cmpint (range->end_offset, ==, 34);
392 g_assert_cmpstr (range->content, ==, "Second sentence.");
396 range = atspi_text_get_string_at_offset (obj, 0, ATSPI_TEXT_GRANULARITY_PARAGRAPH, NULL);
398 g_assert_cmpint (range->start_offset, ==, 0);
399 g_assert_cmpint (range->end_offset, ==, 0);
400 g_assert_cmpstr (range->content, ==, "");
406 atk_test_text_get_bounded_ranges (gpointer fixture, gconstpointer user_data)
408 AtspiAccessible *_obj = get_root_obj (DATA_FILE);
410 AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
412 AtspiText *obj = atspi_accessible_get_text_iface (child);
414 GArray *array = atspi_text_get_bounded_ranges (obj, 15, 21, 100, 50, ATSPI_COORD_TYPE_SCREEN, ATSPI_TEXT_CLIP_MAX, ATSPI_TEXT_CLIP_MIN, NULL);
417 AtspiTextRange *range = &g_array_index (array, AtspiTextRange, 0);
418 g_assert_cmpint (g_array_get_element_size (array), ==, sizeof (AtspiTextRange));
419 g_assert_cmpint (range->start_offset, ==, 0);
420 g_assert_cmpint (range->end_offset, ==, 5);
421 g_assert_cmpstr (range->content, ==, "text0");
423 range = &g_array_index (array, AtspiTextRange, 1);
424 g_assert_cmpint (g_array_get_element_size (array), ==, sizeof (AtspiTextRange));
425 g_assert_cmpint (range->start_offset, ==, 6);
426 g_assert_cmpint (range->end_offset, ==, 10);
427 g_assert_cmpstr (range->content, ==, "it w");
429 g_array_free (array,TRUE);
433 teardown_text_test (gpointer fixture, gconstpointer user_data)
435 kill (child_pid, SIGTERM);
441 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_character_count",
442 0, NULL, NULL, atk_test_text_get_character_count, teardown_text_test);
443 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_text",
444 0, NULL, NULL, atk_test_text_get_text, teardown_text_test);
445 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_caret_offset",
446 0, NULL, NULL, atk_test_text_get_caret_offset, teardown_text_test);
447 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_text_attributes",
448 0, NULL, NULL, atk_test_text_get_text_attributes, teardown_text_test);
449 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_attribute_run",
450 0, NULL, NULL, atk_test_text_get_attribute_run, teardown_text_test);
451 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_text_attribute_value",
452 0, NULL, NULL, atk_test_text_get_text_attribute_value, teardown_text_test);
453 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_defualt_attributes",
454 0, NULL, NULL, atk_test_text_get_defualt_attributes, teardown_text_test);
455 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_set_caret_offset",
456 0, NULL, NULL, atk_test_text_set_caret_offset, teardown_text_test);
457 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_string_at_offset_s1",
458 0, NULL, NULL, atk_test_text_get_string_at_offset_s1, teardown_text_test );
459 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_string_at_offset_s2",
460 0, NULL, NULL, atk_test_text_get_string_at_offset_s2, teardown_text_test );
461 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_character_at_offset",
462 0, NULL, NULL, atk_test_text_get_character_at_offset, teardown_text_test);
463 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_character_extents",
464 0, NULL, NULL, atk_test_text_get_character_extents, teardown_text_test);
465 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_offset_at_point",
466 0, NULL, NULL, atk_test_text_get_offset_at_point, teardown_text_test);
467 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_range_extents",
468 0, NULL, NULL, atk_test_text_get_range_extents, teardown_text_test);
469 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_bounded_ranges",
470 0, NULL, NULL, atk_test_text_get_bounded_ranges, teardown_text_test);
471 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_n_selections",
472 0, NULL, NULL, atk_test_text_get_n_selections, teardown_text_test);
473 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_get_selection",
474 0, NULL, NULL, atk_test_text_get_selection, teardown_text_test);
475 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_add_selection",
476 0, NULL, NULL, atk_test_text_add_selection, teardown_text_test );
477 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_remove_selection",
478 0, NULL, NULL, atk_test_text_remove_selection, teardown_text_test );
479 g_test_add_vtable (ATK_TEST_PATH_TEXT "/atk_test_text_set_selection",
480 0, NULL, NULL, atk_test_text_set_selection, teardown_text_test);