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

            
28
static void
29
1
atk_test_accessible_get_state_set (TestAppFixture *fixture, gconstpointer user_data)
30
{
31
1
  AtspiAccessible *obj = fixture->root_obj;
32
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
33
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
34
1
  GArray *states_arr = atspi_state_set_get_states (states);
35

            
36
1
  AtspiStateType valid_states[] = {
37
    ATSPI_STATE_MODAL,
38
    ATSPI_STATE_MULTI_LINE,
39
  };
40
1
  g_assert_cmpint (states_arr->len, ==, 2);
41
1
  int i = 0;
42
3
  for (i = 0; i < states_arr->len; ++i)
43
    {
44
2
      g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
45
2
      g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
46
2
      g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
47
    }
48
1
  g_array_free (states_arr, TRUE);
49
1
  g_object_unref (states);
50
1
  g_object_unref (child);
51
1
}
52

            
53
static void
54
1
atk_test_state_set_new (TestAppFixture *fixture, gconstpointer user_data)
55
{
56
1
  GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));
57

            
58
1
  AtspiStateType state = ATSPI_STATE_FOCUSABLE;
59
1
  g_array_append_val (states_arr, state);
60
1
  state = ATSPI_STATE_FOCUSED;
61
1
  g_array_append_val (states_arr, state);
62

            
63
1
  g_assert_cmpint (states_arr->len, ==, 2);
64

            
65
1
  AtspiStateSet *ss = atspi_state_set_new (states_arr);
66

            
67
1
  g_assert_true (atspi_state_set_contains (ss, ATSPI_STATE_FOCUSABLE));
68
1
  g_assert_true (atspi_state_set_contains (ss, ATSPI_STATE_FOCUSED));
69
1
  g_object_unref (ss);
70
1
  g_array_free (states_arr, TRUE);
71
1
}
72

            
73
static void
74
1
atk_test_state_set_set_by_name (TestAppFixture *fixture, gconstpointer user_data)
75
{
76
1
  AtspiAccessible *obj = fixture->root_obj;
77
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
78
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
79
1
  GArray *states_arr = atspi_state_set_get_states (states);
80

            
81
1
  atspi_state_set_set_by_name (states, "modal", FALSE);
82
1
  g_array_free (states_arr, TRUE);
83

            
84
1
  states_arr = atspi_state_set_get_states (states);
85

            
86
1
  g_assert_cmpint (states_arr->len, ==, 1);
87
1
  g_assert_true (!atspi_state_set_contains (states, ATSPI_STATE_MODAL));
88
1
  g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
89

            
90
1
  atspi_state_set_set_by_name (states, "modal", TRUE);
91
1
  g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
92
1
  g_array_free (states_arr, TRUE);
93
1
  g_object_unref (states);
94
1
  g_object_unref (child);
95
1
}
96

            
97
static void
98
1
atk_test_state_set_add (TestAppFixture *fixture, gconstpointer user_data)
99
{
100
1
  AtspiAccessible *obj = fixture->root_obj;
101
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
102
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
103

            
104
1
  g_assert_true (!atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));
105

            
106
1
  atspi_state_set_add (states, ATSPI_STATE_FOCUSABLE);
107

            
108
1
  g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));
109
1
  g_object_unref (states);
110
1
  g_object_unref (child);
111
1
}
112

            
113
static void
114
1
atk_test_state_set_compare (TestAppFixture *fixture, gconstpointer user_data)
115
{
116
1
  AtspiAccessible *obj = fixture->root_obj;
117
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
118
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
119
1
  GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));
120

            
121
1
  gint state = 0;
122
1
  state = 11; // ATSPI_STATE_FOCUSABLE
123
1
  g_array_append_val (states_arr, state);
124
1
  state = 12; // ATSPI_STATE_FOCUSED
125
1
  g_array_append_val (states_arr, state);
126

            
127
1
  g_assert_cmpint (states_arr->len, ==, 2);
128

            
129
1
  AtspiStateSet *ss = atspi_state_set_new (states_arr);
130

            
131
1
  AtspiStateSet *ret = atspi_state_set_compare (states, ss);
132

            
133
1
  g_assert_true (atspi_state_set_contains (ret, ATSPI_STATE_MODAL));
134
1
  g_assert_true (atspi_state_set_contains (ret, ATSPI_STATE_MULTI_LINE));
135
1
  g_assert_true (atspi_state_set_contains (ret, ATSPI_STATE_FOCUSED));
136
1
  g_assert_true (atspi_state_set_contains (ret, ATSPI_STATE_FOCUSABLE));
137
1
  g_object_unref (ret);
138
1
  g_object_unref (ss);
139
1
  g_array_free (states_arr, TRUE);
140
1
  g_object_unref (states);
141
1
  g_object_unref (child);
142
1
}
143

            
144
static void
145
1
atk_test_state_set_contains (TestAppFixture *fixture, gconstpointer user_data)
146
{
147
1
  AtspiAccessible *obj = fixture->root_obj;
148
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
149
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
150

            
151
1
  g_assert_true (!atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));
152
1
  g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
153
1
  g_object_unref (states);
154
1
  g_object_unref (child);
155
1
}
156

            
157
static void
158
1
atk_test_state_set_equals (TestAppFixture *fixture, gconstpointer user_data)
159
{
160
1
  AtspiAccessible *obj = fixture->root_obj;
161
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
162
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
163
1
  GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));
164

            
165
1
  gint state = 0;
166
1
  state = 16; // ATSPI_STATE_MODAL
167
1
  g_array_append_val (states_arr, state);
168
1
  state = 17; // ATSPI_STATE_MULTI_LINE
169
1
  g_array_append_val (states_arr, state);
170

            
171
1
  g_assert_cmpint (states_arr->len, ==, 2);
172

            
173
1
  AtspiStateSet *ss = atspi_state_set_new (states_arr);
174

            
175
1
  g_assert_true (atspi_state_set_equals (states, ss));
176
1
  g_object_unref (ss);
177
1
  g_array_free (states_arr, TRUE);
178
1
  g_object_unref (states);
179
1
  g_object_unref (child);
180
1
}
181

            
182
static void
183
1
atk_test_state_set_get_states (TestAppFixture *fixture, gconstpointer user_data)
184
{
185
1
  AtspiAccessible *obj = fixture->root_obj;
186
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
187
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
188
1
  GArray *states_arr = atspi_state_set_get_states (states);
189

            
190
1
  AtspiStateType valid_states[] = {
191
    ATSPI_STATE_MODAL,
192
    ATSPI_STATE_MULTI_LINE,
193
  };
194
1
  g_assert_cmpint (states_arr->len, ==, 2);
195
1
  int i = 0;
196
3
  for (i = 0; i < states_arr->len; ++i)
197
2
    g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
198
1
  g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
199
1
  g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
200
1
  g_array_free (states_arr, TRUE);
201
1
  g_object_unref (states);
202
1
  g_object_unref (child);
203
1
}
204

            
205
static void
206
1
atk_test_state_set_is_empty (TestAppFixture *fixture, gconstpointer user_data)
207
{
208
1
  AtspiAccessible *obj = fixture->root_obj;
209
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
210
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
211
1
  AtspiStateSet *root_states = atspi_accessible_get_state_set (obj);
212

            
213
1
  g_assert_true (!atspi_state_set_is_empty (states));
214
1
  g_assert_true (atspi_state_set_is_empty (root_states));
215
1
  g_object_unref (root_states);
216
1
  g_object_unref (states);
217
1
  g_object_unref (child);
218
1
}
219

            
220
static void
221
1
atk_test_state_set_remove (TestAppFixture *fixture, gconstpointer user_data)
222
{
223
1
  AtspiAccessible *obj = fixture->root_obj;
224
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
225
1
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
226
1
  GArray *states_arr = atspi_state_set_get_states (states);
227

            
228
1
  g_assert_cmpint (states_arr->len, ==, 2);
229
1
  atspi_state_set_remove (states, ATSPI_STATE_MODAL);
230
1
  g_array_free (states_arr, TRUE);
231

            
232
1
  states_arr = atspi_state_set_get_states (states);
233

            
234
1
  g_assert_cmpint (states_arr->len, ==, 1);
235
1
  g_assert_true (!atspi_state_set_contains (states, ATSPI_STATE_MODAL));
236
1
  g_assert_true (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
237
1
  g_array_free (states_arr, TRUE);
238
1
  g_object_unref (states);
239
1
  g_object_unref (child);
240
1
}
241

            
242
void
243
1
atk_test_state_set (void)
244
{
245
1
  g_test_add ("/state_set/atk_test_accessible_get_state_set",
246
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_accessible_get_state_set, fixture_teardown);
247
1
  g_test_add ("/state_set/atk_test_state_set_new",
248
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_new, fixture_teardown);
249
1
  g_test_add ("/state_set/atk_test_state_set_set_by_name",
250
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_set_by_name, fixture_teardown);
251
1
  g_test_add ("/state_set/atk_test_state_set_add",
252
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_add, fixture_teardown);
253
1
  g_test_add ("/state_set/atk_test_state_set_compare",
254
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_compare, fixture_teardown);
255
1
  g_test_add ("/state_set/atk_test_state_set_contains",
256
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_contains, fixture_teardown);
257
1
  g_test_add ("/state_set/atk_test_state_set_equals",
258
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_equals, fixture_teardown);
259
1
  g_test_add ("/state_set/atk_test_state_set_get_states",
260
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_get_states, fixture_teardown);
261
1
  g_test_add ("/state_set/atk_test_state_set_is_empty",
262
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_is_empty, fixture_teardown);
263
1
  g_test_add ("/state_set/atk_test_state_set_remove",
264
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_state_set_remove, fixture_teardown);
265
1
}