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

            
28
static void
29
1
atk_test_selection_sample_get_interface (TestAppFixture *fixture, gconstpointer user_data)
30
{
31
1
  AtspiAccessible *obj = fixture->root_obj;
32
1
  check_name (obj, "root_object");
33
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
34
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
35
1
  g_assert_nonnull (iface);
36
1
  g_object_unref (iface);
37
1
  g_object_unref (child);
38
1
}
39

            
40
static void
41
1
atk_test_selection_get_n_selected_children (TestAppFixture *fixture, gconstpointer user_data)
42
{
43
1
  AtspiAccessible *obj = fixture->root_obj;
44
1
  check_name (obj, "root_object");
45
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
46
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
47
1
  g_assert_nonnull (iface);
48

            
49
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
50
1
  g_object_unref (iface);
51
1
  g_object_unref (child);
52
1
}
53

            
54
static void
55
1
atk_test_selection_get_selected_child (TestAppFixture *fixture, gconstpointer user_data)
56
{
57
1
  AtspiAccessible *obj = fixture->root_obj;
58
1
  check_name (obj, "root_object");
59
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
60
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
61
1
  g_assert_nonnull (iface);
62
1
  gchar *valid_names[] = { "obj2/1", "obj2/2", "obj3/1" };
63

            
64
1
  AtspiAccessible *o = NULL;
65
1
  int i = 0;
66
1
  int selected_count = atspi_selection_get_n_selected_children (iface, NULL);
67
1
  g_assert_cmpint (selected_count, ==, 3);
68
4
  for (i = 0; i < selected_count; i++)
69
    {
70
3
      o = atspi_selection_get_selected_child (iface, i, NULL);
71
3
      check_name (o, valid_names[i]);
72
3
      g_object_unref (o);
73
    }
74
1
  g_object_unref (iface);
75
1
  g_object_unref (child);
76
1
}
77

            
78
static void
79
1
atk_test_selection_select_child (TestAppFixture *fixture, gconstpointer user_data)
80
{
81
1
  AtspiAccessible *obj = fixture->root_obj;
82
1
  check_name (obj, "root_object");
83
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
84
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
85
1
  g_assert_nonnull (iface);
86

            
87
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
88

            
89
1
  atspi_selection_select_child (iface, 2, NULL);
90
1
  atspi_selection_select_child (iface, 3, NULL);
91
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 5);
92
1
  g_object_unref (iface);
93
1
  g_object_unref (child);
94
1
}
95

            
96
static void
97
1
atk_test_selection_deselect_selected (TestAppFixture *fixture, gconstpointer user_data)
98
{
99
1
  AtspiAccessible *obj = fixture->root_obj;
100
1
  check_name (obj, "root_object");
101
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
102
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
103
1
  g_assert_nonnull (iface);
104

            
105
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
106

            
107
1
  atspi_selection_select_child (iface, 2, NULL);
108
1
  atspi_selection_select_child (iface, 3, NULL);
109
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 5);
110

            
111
1
  atspi_selection_deselect_selected_child (iface, 2, NULL);
112
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 4);
113
1
  g_object_unref (iface);
114
1
  g_object_unref (child);
115
1
}
116

            
117
static void
118
1
atk_test_selection_deselect_child (TestAppFixture *fixture, gconstpointer user_data)
119
{
120
1
  AtspiAccessible *obj = fixture->root_obj;
121
1
  check_name (obj, "root_object");
122
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
123
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
124
1
  g_assert_nonnull (iface);
125

            
126
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
127

            
128
1
  atspi_selection_select_child (iface, 2, NULL);
129
1
  atspi_selection_select_child (iface, 3, NULL);
130
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 5);
131

            
132
1
  atspi_selection_deselect_child (iface, 2, NULL);
133
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 4);
134
1
  g_object_unref (iface);
135
1
  g_object_unref (child);
136
1
}
137

            
138
static void
139
1
atk_test_selection_is_child_selected (TestAppFixture *fixture, gconstpointer user_data)
140
{
141
1
  AtspiAccessible *obj = fixture->root_obj;
142
1
  check_name (obj, "root_object");
143
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
144
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
145
1
  g_assert_nonnull (iface);
146

            
147
1
  g_assert_true (atspi_selection_is_child_selected (iface, 0, NULL));
148
1
  g_assert_true (atspi_selection_is_child_selected (iface, 1, NULL));
149
1
  g_assert_true (atspi_selection_is_child_selected (iface, 4, NULL));
150
1
  g_assert_true (!atspi_selection_is_child_selected (iface, 2, NULL));
151
1
  g_assert_true (!atspi_selection_is_child_selected (iface, 3, NULL));
152
1
  g_object_unref (iface);
153
1
  g_object_unref (child);
154
1
}
155

            
156
static void
157
1
atk_test_selection_select_all (TestAppFixture *fixture, gconstpointer user_data)
158
{
159
1
  AtspiAccessible *obj = fixture->root_obj;
160
1
  check_name (obj, "root_object");
161
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
162
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
163
1
  g_assert_nonnull (iface);
164

            
165
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
166
1
  atspi_selection_select_all (iface, NULL);
167
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 5);
168
1
  g_object_unref (iface);
169
1
  g_object_unref (child);
170
1
}
171

            
172
static void
173
1
atk_test_selection_clear_selection (TestAppFixture *fixture, gconstpointer user_data)
174
{
175
1
  AtspiAccessible *obj = fixture->root_obj;
176
1
  check_name (obj, "root_object");
177
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 0, NULL);
178
1
  AtspiSelection *iface = atspi_accessible_get_selection_iface (child);
179
1
  g_assert_nonnull (iface);
180

            
181
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 3);
182
1
  atspi_selection_clear_selection (iface, NULL);
183
1
  g_assert_cmpint (atspi_selection_get_n_selected_children (iface, NULL), ==, 0);
184
1
  g_object_unref (iface);
185
1
  g_object_unref (child);
186
1
}
187

            
188
void
189
1
atk_test_selection (void)
190
{
191
1
  g_test_add ("/selection/atk_test_selection_sample_get_interface",
192
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_sample_get_interface, fixture_teardown);
193
1
  g_test_add ("/selection/atk_test_selection_get_n_selected_children",
194
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_get_n_selected_children, fixture_teardown);
195
1
  g_test_add ("/selection/atk_test_selection_get_selected_child",
196
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_get_selected_child, fixture_teardown);
197
1
  g_test_add ("/selection/atk_test_selection_select_child",
198
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_select_child, fixture_teardown);
199
1
  g_test_add ("/selection/atk_test_selection_deselect_selected",
200
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_deselect_selected, fixture_teardown);
201
1
  g_test_add ("/selection/atk_test_selection_deselect_child",
202
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_deselect_child, fixture_teardown);
203
1
  g_test_add ("/selection/atk_test_selection_is_child_selected",
204
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_is_child_selected, fixture_teardown);
205
1
  g_test_add ("/selection/atk_test_selection_select_all",
206
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_select_all, fixture_teardown);
207
1
  g_test_add ("/selection/atk_test_selection_clear_selection",
208
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_selection_clear_selection, fixture_teardown);
209
1
}