summaryrefslogtreecommitdiff
path: root/tests/atk_test_state_set.c
blob: c1de2d1bf5ef8e36fbf618b3c365b55fc5071b78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
 * AT-SPI - Assistive Technology Service Provider Interface
 * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
 *
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "atk_suite.h"
#include "atk_test_util.h"

#define DATA_FILE TESTS_DATA_DIR"/test-accessible.xml"

static void
teardown_state_set_test (gpointer fixture, gconstpointer user_data)
{
  terminate_app ();
}

static void
atk_test_accessible_get_state_set (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
  GArray *states_arr = atspi_state_set_get_states (states);

  AtspiStateType valid_states[] = {
    ATSPI_STATE_MODAL,
    ATSPI_STATE_MULTI_LINE,
  };
  g_assert_cmpint (states_arr->len, ==, 2);
  int i = 0;
  for (i = 0; i < states_arr->len; ++i) {
    g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
    g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
    g_assert (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
  }
}

static void
atk_test_state_set_new (gpointer fixture, gconstpointer user_data)
{
  GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));

  gint state = 0;
  state = 11; // ATSPI_STATE_FOCUSABLE
  g_array_append_val (states_arr, state);
  state = 12; // ATSPI_STATE_FOCUSED
  g_array_append_val (states_arr, state);

  g_assert_cmpint (states_arr->len, ==, 2);

  AtspiStateSet *ss = atspi_state_set_new (states_arr);

  AtspiStateType valid_states[] = {
    ATSPI_STATE_FOCUSABLE,
    ATSPI_STATE_FOCUSED,
  };

  g_assert (atspi_state_set_contains (ss, valid_states[0]));
  g_assert (atspi_state_set_contains (ss, valid_states[1]));
  int i = 0;
  for (i = 0; i < states_arr->len; ++i) {
    g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
  }
}

static void
atk_test_state_set_set_by_name (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
  GArray *states_arr = atspi_state_set_get_states (states);

  atspi_state_set_set_by_name (states, "modal", FALSE);

  states_arr = atspi_state_set_get_states (states);

  g_assert_cmpint (states_arr->len, ==, 1);
  g_assert (!atspi_state_set_contains (states, ATSPI_STATE_MODAL));
  g_assert (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));

  atspi_state_set_set_by_name (states, "modal", TRUE);
  g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
}

static void
atk_test_state_set_add (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);

  g_assert (!atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));

  atspi_state_set_add (states, ATSPI_STATE_FOCUSABLE);

  g_assert (atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));

}

static void
atk_test_state_set_compare (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
  GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));

  gint state = 0;
  state = 11; // ATSPI_STATE_FOCUSABLE
  g_array_append_val (states_arr, state);
  state = 12; // ATSPI_STATE_FOCUSED
  g_array_append_val (states_arr, state);

  g_assert_cmpint (states_arr->len, ==, 2);

  AtspiStateSet *ss = atspi_state_set_new (states_arr);

  AtspiStateSet *ret = atspi_state_set_compare (states, ss);

  g_assert (atspi_state_set_contains (ret, ATSPI_STATE_MODAL));
  g_assert (atspi_state_set_contains (ret, ATSPI_STATE_MULTI_LINE));
  g_assert (atspi_state_set_contains (ret, ATSPI_STATE_FOCUSED));
  g_assert (atspi_state_set_contains (ret, ATSPI_STATE_FOCUSABLE));
}

static void
atk_test_state_set_contains (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);

  g_assert (!atspi_state_set_contains (states, ATSPI_STATE_FOCUSABLE));
  g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
}

static void
atk_test_state_set_equals (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
  GArray *states_arr = g_array_new (FALSE, FALSE, sizeof (AtspiStateType));

  gint state = 0;
  state = 16; // ATSPI_STATE_MODAL
  g_array_append_val (states_arr, state);
  state = 17; // ATSPI_STATE_MULTI_LINE
  g_array_append_val (states_arr, state);

  g_assert_cmpint (states_arr->len, ==, 2);

  AtspiStateSet *ss = atspi_state_set_new (states_arr);

  g_assert (atspi_state_set_equals (states, ss));
}

static void
atk_test_state_set_get_states (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
  GArray *states_arr = atspi_state_set_get_states (states);

  AtspiStateType valid_states[] = {
    ATSPI_STATE_MODAL,
    ATSPI_STATE_MULTI_LINE,
  };
  g_assert_cmpint (states_arr->len, ==, 2);
  int i = 0;
  for (i = 0; i < states_arr->len; ++i)
    g_assert_cmpint (valid_states[i], ==, g_array_index (states_arr, AtspiStateType, i));
  g_assert (atspi_state_set_contains (states, ATSPI_STATE_MODAL));
  g_assert (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
}

static void
atk_test_state_set_is_empty (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
  AtspiStateSet *root_states = atspi_accessible_get_state_set (obj);

  g_assert (!atspi_state_set_is_empty (states));
  g_assert (atspi_state_set_is_empty (root_states));
}

static void
atk_test_state_set_remove (gpointer fixture, gconstpointer user_data)
{
  AtspiAccessible *obj = get_root_obj (DATA_FILE);
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
  AtspiStateSet *states = atspi_accessible_get_state_set (child);
  GArray *states_arr = atspi_state_set_get_states (states);

  g_assert_cmpint (states_arr->len, ==, 2);
  atspi_state_set_remove (states, ATSPI_STATE_MODAL);

  states_arr = atspi_state_set_get_states (states);

  g_assert_cmpint (states_arr->len, ==, 1);
  g_assert (!atspi_state_set_contains (states, ATSPI_STATE_MODAL));
  g_assert (atspi_state_set_contains (states, ATSPI_STATE_MULTI_LINE));
}

void
atk_test_state_set (void)
{
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_accessible_get_state_set",
                     0, NULL, NULL, atk_test_accessible_get_state_set, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_new",
                     0, NULL, NULL, atk_test_state_set_new, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_set_by_name",
                     0, NULL, NULL, atk_test_state_set_set_by_name, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_add",
                     0, NULL, NULL, atk_test_state_set_add, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_compare",
                     0, NULL, NULL, atk_test_state_set_compare, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_contains",
                     0, NULL, NULL, atk_test_state_set_contains, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_equals",
                     0, NULL, NULL, atk_test_state_set_equals, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_get_states",
                     0, NULL, NULL, atk_test_state_set_get_states, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_is_empty",
                     0, NULL, NULL, atk_test_state_set_is_empty, teardown_state_set_test);
  g_test_add_vtable (ATK_TEST_PATH_STATE_SET "/atk_test_state_set_remove",
                     0, NULL, NULL, atk_test_state_set_remove, teardown_state_set_test);
}