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-collection.xml"
27

            
28
static void
29
1
atk_test_collection_get_collection_iface (TestAppFixture *fixture, gconstpointer user_data)
30
{
31
1
  AtspiAccessible *obj = fixture->root_obj;
32
1
  AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
33
1
  g_assert_nonnull (iface);
34
1
  g_object_unref (iface);
35
1
}
36

            
37
static void
38
6
check_and_unref (GArray *array, gint index, const char *expected_name)
39
{
40
6
  AtspiAccessible *accessible = g_array_index (array, AtspiAccessible *, index);
41
6
  check_name (accessible, expected_name);
42
6
  g_object_unref (accessible);
43
6
}
44

            
45
static void
46
1
atk_test_collection_get_matches (TestAppFixture *fixture, gconstpointer user_data)
47
{
48
1
  AtspiAccessible *obj = fixture->root_obj;
49
1
  AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
50
1
  g_assert_nonnull (iface);
51

            
52
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
53

            
54
1
  AtspiMatchRule *rule = NULL;
55
1
  AtspiStateSet *ss = atspi_accessible_get_state_set (child);
56

            
57
1
  rule = atspi_match_rule_new (ss,
58
                               ATSPI_Collection_MATCH_ALL,
59
                               NULL,
60
                               ATSPI_Collection_MATCH_ALL,
61
                               NULL,
62
                               ATSPI_Collection_MATCH_ALL,
63
                               NULL,
64
                               ATSPI_Collection_MATCH_ALL,
65
                               FALSE);
66
1
  g_object_unref (ss);
67
1
  GArray *ret = atspi_collection_get_matches (iface,
68
                                              rule,
69
                                              ATSPI_Collection_SORT_ORDER_CANONICAL,
70
                                              0,
71
                                              FALSE,
72
                                              NULL);
73
1
  g_assert_cmpint (2, ==, ret->len);
74

            
75
1
  check_and_unref (ret, 0, "obj1");
76
1
  check_and_unref (ret, 1, "obj3");
77
1
  g_array_free (ret, TRUE);
78
1
  g_object_unref (rule);
79
1
  g_object_unref (child);
80
1
  g_object_unref (iface);
81
1
}
82

            
83
static void
84
1
atk_test_collection_get_matches_to (TestAppFixture *fixture, gconstpointer user_data)
85
{
86
1
  AtspiAccessible *obj = fixture->root_obj;
87
1
  AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
88
1
  g_assert_nonnull (iface);
89

            
90
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
91
1
  AtspiAccessible *child1 = atspi_accessible_get_child_at_index (obj, 1, NULL);
92

            
93
1
  AtspiMatchRule *rule = NULL;
94
1
  AtspiStateSet *ss = atspi_accessible_get_state_set (child);
95

            
96
1
  rule = atspi_match_rule_new (ss,
97
                               ATSPI_Collection_MATCH_ALL,
98
                               NULL,
99
                               ATSPI_Collection_MATCH_ALL,
100
                               NULL,
101
                               ATSPI_Collection_MATCH_ALL,
102
                               NULL,
103
                               ATSPI_Collection_MATCH_ALL,
104
                               FALSE);
105
1
  g_object_unref (ss);
106
1
  GArray *ret = atspi_collection_get_matches_to (iface,
107
                                                 child1,
108
                                                 rule,
109
                                                 ATSPI_Collection_SORT_ORDER_CANONICAL,
110
                                                 ATSPI_Collection_TREE_INORDER,
111
                                                 TRUE,
112
                                                 0,
113
                                                 FALSE,
114
                                                 NULL);
115
1
  g_assert_cmpint (1, ==, ret->len);
116
1
  check_and_unref (ret, 0, "obj1");
117
1
  g_array_free (ret, TRUE);
118
1
  g_object_unref (rule);
119
1
  g_object_unref (child1);
120
1
  g_object_unref (child);
121
1
  g_object_unref (iface);
122
1
}
123

            
124
static void
125
1
atk_test_collection_get_matches_from (TestAppFixture *fixture, gconstpointer user_data)
126
{
127
1
  AtspiAccessible *obj = fixture->root_obj;
128
1
  AtspiCollection *iface = atspi_accessible_get_collection_iface (obj);
129
  GHashTable *attributes;
130
  GArray *array;
131
  AtspiRole role;
132

            
133
1
  g_assert_nonnull (iface);
134

            
135
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
136
1
  AtspiAccessible *child1 = atspi_accessible_get_child_at_index (obj, 1, NULL);
137

            
138
1
  AtspiMatchRule *rule = NULL;
139
1
  AtspiStateSet *ss = atspi_accessible_get_state_set (child);
140

            
141
1
  rule = atspi_match_rule_new (ss,
142
                               ATSPI_Collection_MATCH_ALL,
143
                               NULL,
144
                               ATSPI_Collection_MATCH_ALL,
145
                               NULL,
146
                               ATSPI_Collection_MATCH_ALL,
147
                               NULL,
148
                               ATSPI_Collection_MATCH_ALL,
149
                               FALSE);
150
1
  GArray *ret = atspi_collection_get_matches_from (iface,
151
                                                   child1,
152
                                                   rule,
153
                                                   ATSPI_Collection_SORT_ORDER_CANONICAL,
154
                                                   ATSPI_Collection_TREE_INORDER,
155
                                                   0,
156
                                                   FALSE,
157
                                                   NULL);
158
1
  g_object_unref (ss);
159
1
  g_assert_cmpint (3, ==, ret->len);
160
1
  check_and_unref (ret, 0, "obj2/1");
161
1
  check_and_unref (ret, 1, "obj3");
162
1
  check_and_unref (ret, 2, "obj3");
163
1
  g_array_free (ret, TRUE);
164
1
  g_object_unref (rule);
165

            
166
1
  attributes = g_hash_table_new (g_str_hash, g_str_equal);
167
1
  g_hash_table_insert (attributes, "layout-guess", "true");
168
1
  rule = atspi_match_rule_new (NULL,
169
                               ATSPI_Collection_MATCH_ALL,
170
                               attributes,
171
                               ATSPI_Collection_MATCH_NONE,
172
                               NULL,
173
                               ATSPI_Collection_MATCH_ALL,
174
                               NULL,
175
                               ATSPI_Collection_MATCH_ALL,
176
                               FALSE);
177
1
  ret = atspi_collection_get_matches_from (iface,
178
                                           child1,
179
                                           rule,
180
                                           ATSPI_Collection_SORT_ORDER_CANONICAL,
181
                                           ATSPI_Collection_TREE_INORDER,
182
                                           0,
183
                                           FALSE,
184
                                           NULL);
185
1
  g_hash_table_unref (attributes);
186
1
  g_assert_cmpint (7, ==, ret->len);
187
1
  g_array_free (ret, TRUE);
188
1
  g_object_unref (rule);
189

            
190
1
  array = g_array_new (FALSE, FALSE, sizeof (AtspiRole));
191
1
  role = ATSPI_ROLE_LINK;
192
1
  g_array_insert_val (array, 0, role);
193
1
  rule = atspi_match_rule_new (NULL,
194
                               ATSPI_Collection_MATCH_ALL,
195
                               NULL,
196
                               ATSPI_Collection_MATCH_ALL,
197
                               array,
198
                               ATSPI_Collection_MATCH_NONE,
199
                               NULL,
200
                               ATSPI_Collection_MATCH_ALL,
201
                               FALSE);
202
1
  ret = atspi_collection_get_matches_from (iface,
203
                                           child1,
204
                                           rule,
205
                                           ATSPI_Collection_SORT_ORDER_CANONICAL,
206
                                           ATSPI_Collection_TREE_INORDER,
207
                                           0,
208
                                           FALSE,
209
                                           NULL);
210
1
  g_assert_cmpint (6, ==, ret->len);
211
1
  g_array_free (array, TRUE);
212
1
  g_array_free (ret, TRUE);
213
1
  g_object_unref (rule);
214

            
215
1
  g_object_unref (child1);
216
1
  g_object_unref (child);
217
1
  g_object_unref (iface);
218
1
}
219

            
220
void
221
1
atk_test_collection (void)
222
{
223
1
  g_test_add ("/collection/atk_test_collection_get_collection_iface",
224
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_collection_get_collection_iface, fixture_teardown);
225
1
  g_test_add ("/collection/atk_test_collection_get_matches",
226
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_collection_get_matches, fixture_teardown);
227
1
  g_test_add ("/collection/atk_test_collection_get_matches_to",
228
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_collection_get_matches_to, fixture_teardown);
229
1
  g_test_add ("/collection/atk_test_collection_get_matches_from",
230
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_collection_get_matches_from, fixture_teardown);
231
1
}