9ac69d7852beaaff8d16cf67a88f8699b96f3dff
[platform/upstream/at-spi2-atk.git] / tests / atk_test_collection.c
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 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.
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  * Library General Public License for more details.
16  *
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.
21  */
22
23
24 #include "atk_suite.h"
25 #include "atk_test_util.h"
26
27 #define DATA_FILE TESTS_DATA_DIR"/test-collection.xml"
28
29 static void
30 teardown_collection_test (gpointer fixture, gconstpointer user_data)
31 {
32   kill (child_pid, SIGTERM);
33 }
34
35 static void
36 atk_test_collection_get_collection_iface (gpointer fixture, gconstpointer user_data)
37 {
38   AtspiAccessible *obj = get_root_obj (DATA_FILE);
39   AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
40   g_assert (iface);
41 }
42
43 static void
44 atk_test_collection_get_matches (gpointer fixture, gconstpointer user_data)
45 {
46   AtspiAccessible *obj = get_root_obj (DATA_FILE);
47   AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
48   g_assert (iface);
49
50   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
51
52   AtspiMatchRule *rule = NULL;
53   AtspiStateSet *ss = atspi_accessible_get_state_set (child);
54
55   rule = atspi_match_rule_new (ss,
56                                ATSPI_Collection_MATCH_ALL,
57                                NULL,
58                                ATSPI_Collection_MATCH_ALL,
59                                NULL,
60                                ATSPI_Collection_MATCH_ALL,
61                                NULL,
62                                ATSPI_Collection_MATCH_ALL,
63                                FALSE);
64   GArray *ret = atspi_collection_get_matches (iface,
65                 rule,
66                 ATSPI_Collection_SORT_ORDER_CANONICAL,
67                 0,
68                 FALSE,
69                 NULL);
70   g_assert_cmpint (2, ==, ret->len);
71
72   AtspiAccessible *get = NULL;
73   get = g_array_index (ret, AtspiAccessible *, 0);
74   g_assert_cmpstr("obj1", ==, atspi_accessible_get_name (get, NULL));
75   get = g_array_index (ret, AtspiAccessible *, 1);
76   g_assert_cmpstr("obj3", ==, atspi_accessible_get_name (get, NULL));
77 }
78
79 static void
80 atk_test_collection_get_matches_to (gpointer fixture, gconstpointer user_data)
81 {
82   AtspiAccessible *obj = get_root_obj (DATA_FILE);
83   AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
84   g_assert (iface);
85
86   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
87   AtspiAccessible *child1 = atspi_accessible_get_child_at_index (obj, 1, NULL);
88
89   AtspiMatchRule *rule = NULL;
90   AtspiStateSet *ss = atspi_accessible_get_state_set (child);
91
92   rule = atspi_match_rule_new (ss,
93                                ATSPI_Collection_MATCH_ALL,
94                                NULL,
95                                ATSPI_Collection_MATCH_ALL,
96                                NULL,
97                                ATSPI_Collection_MATCH_ALL,
98                                NULL,
99                                ATSPI_Collection_MATCH_ALL,
100                                FALSE);
101   GArray *ret = atspi_collection_get_matches_to (iface,
102                 child1,
103                 rule,
104                 ATSPI_Collection_SORT_ORDER_CANONICAL,
105                 ATSPI_Collection_TREE_INORDER,
106                 TRUE,
107                 0,
108                 FALSE,
109                 NULL);
110   g_assert_cmpint (1, ==, ret->len);
111   AtspiAccessible *get = NULL;
112   get = g_array_index (ret, AtspiAccessible *, 0);
113   g_assert_cmpstr("obj1", ==, atspi_accessible_get_name (get, NULL));
114 }
115
116 static void
117 atk_test_collection_get_matches_from (gpointer fixture, gconstpointer user_data)
118 {
119   AtspiAccessible *obj = get_root_obj (DATA_FILE);
120   AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
121   g_assert (iface);
122
123   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
124   AtspiAccessible *child1 = atspi_accessible_get_child_at_index (obj, 1, NULL);
125
126   AtspiMatchRule *rule = NULL;
127   AtspiStateSet *ss = atspi_accessible_get_state_set (child);
128
129   rule = atspi_match_rule_new (ss,
130                                ATSPI_Collection_MATCH_ALL,
131                                NULL,
132                                ATSPI_Collection_MATCH_ALL,
133                                NULL,
134                                ATSPI_Collection_MATCH_ALL,
135                                NULL,
136                                ATSPI_Collection_MATCH_ALL,
137                                FALSE);
138   GArray *ret = atspi_collection_get_matches_from (iface,
139                 child1,
140                 rule,
141                 ATSPI_Collection_SORT_ORDER_CANONICAL,
142                 ATSPI_Collection_TREE_INORDER,
143                 0,
144                 FALSE,
145                 NULL);
146   g_assert_cmpint (3, ==, ret->len);
147   AtspiAccessible *get = NULL;
148   get = g_array_index (ret, AtspiAccessible *, 0);
149   g_assert_cmpstr("obj2/1", ==, atspi_accessible_get_name (get, NULL));
150   get = g_array_index (ret, AtspiAccessible *, 1);
151   g_assert_cmpstr("obj3", ==, atspi_accessible_get_name (get, NULL));
152   get = g_array_index (ret, AtspiAccessible *, 2);
153   g_assert_cmpstr("obj3", ==, atspi_accessible_get_name (get, NULL));
154 }
155
156
157 void
158 atk_test_collection (void )
159 {
160   g_test_add_vtable (ATK_TEST_PATH_COLLECTION "/atk_test_collection_get_collection_iface",
161                      0, NULL, NULL, atk_test_collection_get_collection_iface, teardown_collection_test );
162   g_test_add_vtable (ATK_TEST_PATH_COLLECTION "/atk_test_collection_get_matches",
163                      0, NULL, NULL, atk_test_collection_get_matches, teardown_collection_test );
164   g_test_add_vtable (ATK_TEST_PATH_COLLECTION "/atk_test_collection_get_matches_to",
165                      0, NULL, NULL, atk_test_collection_get_matches_to, teardown_collection_test );
166   g_test_add_vtable (ATK_TEST_PATH_COLLECTION "/atk_test_collection_get_matches_from",
167                      0, NULL, NULL, atk_test_collection_get_matches_from, teardown_collection_test );
168 }
169