1
/*
2
 * Copyright 2008 Codethink Ltd.
3
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the
17
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 * Boston, MA 02110-1301, USA.
19
 */
20

            
21
#include "atk_suite.h"
22
#include "atk_test_util.h"
23

            
24
#define DATA_FILE TESTS_DATA_DIR "/test-table.xml"
25

            
26
static void
27
1
atk_test_accessible_get_table_cell (TestAppFixture *fixture, gconstpointer user_data)
28
{
29
1
  AtspiAccessible *_obj = fixture->root_obj;
30
1
  g_assert_nonnull (_obj);
31
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
32
1
  g_assert_nonnull (child);
33

            
34
1
  AtspiAccessible *cell = atspi_accessible_get_child_at_index (child, 9, NULL);
35
1
  AtspiTableCell *obj = atspi_accessible_get_table_cell (cell);
36
1
  g_assert_nonnull (obj);
37
1
  g_object_unref (obj);
38
1
  g_object_unref (cell);
39
1
  g_object_unref (child);
40
1
}
41

            
42
static void
43
1
atk_test_table_cell_get_column_span (TestAppFixture *fixture, gconstpointer user_data)
44
{
45
1
  AtspiAccessible *_obj = fixture->root_obj;
46
1
  g_assert_nonnull (_obj);
47
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
48
1
  g_assert_nonnull (child);
49

            
50
1
  AtspiAccessible *cell = atspi_accessible_get_child_at_index (child, 10, NULL);
51
1
  AtspiTableCell *obj = atspi_accessible_get_table_cell (cell);
52
1
  g_assert_nonnull (obj);
53

            
54
1
  g_assert_cmpint (3, ==, atspi_table_cell_get_column_span (obj, NULL));
55
1
  g_object_unref (obj);
56
1
  g_object_unref (cell);
57

            
58
1
  cell = atspi_accessible_get_child_at_index (child, 11, NULL);
59
1
  obj = atspi_accessible_get_table_cell (cell);
60
1
  g_assert_nonnull (obj);
61

            
62
1
  g_assert_cmpint (1, ==, atspi_table_cell_get_column_span (obj, NULL));
63
1
  g_object_unref (obj);
64
1
  g_object_unref (cell);
65
1
  g_object_unref (child);
66
1
}
67

            
68
/*
69
static void
70
atk_test_table_cell_get_column_header_cells (TestAppFixture *fixture, gconstpointer user_data)
71
{
72
  AtspiAccessible *_obj = fixture->root_obj;
73
  g_assert_nonnull (_obj);
74
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
75
  g_assert_nonnull (child);
76

            
77
  AtspiAccessible *cell = atspi_accessible_get_child_at_index (child, 10, NULL);
78
  AtspiTableCell *obj = atspi_accessible_get_table_cell (cell);
79
  g_assert_nonnull (obj);
80

            
81
  GPtrArray *ret = atspi_table_cell_get_column_header_cells (obj, NULL);
82
  g_assert_cmpint (3, ==, ret->len);
83
  g_array_free (ret, TRUE);
84
  g_object_unref (obj);
85
  g_object_unref (cell);
86
  g_object_unref (child);
87
}
88
*/
89

            
90
static void
91
1
atk_test_table_cell_get_row_span (TestAppFixture *fixture, gconstpointer user_data)
92
{
93
1
  AtspiAccessible *_obj = fixture->root_obj;
94
1
  g_assert_nonnull (_obj);
95
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
96
1
  g_assert_nonnull (child);
97

            
98
1
  AtspiAccessible *cell = atspi_accessible_get_child_at_index (child, 9, NULL);
99
1
  AtspiTableCell *obj = atspi_accessible_get_table_cell (cell);
100
1
  g_assert_nonnull (obj);
101

            
102
1
  g_assert_cmpint (2, ==, atspi_table_cell_get_row_span (obj, NULL));
103
1
  g_object_unref (obj);
104
1
  g_object_unref (cell);
105

            
106
1
  cell = atspi_accessible_get_child_at_index (child, 11, NULL);
107
1
  obj = atspi_accessible_get_table_cell (cell);
108
1
  g_assert_nonnull (obj);
109

            
110
1
  g_assert_cmpint (1, ==, atspi_table_cell_get_column_span (obj, NULL));
111
1
  g_object_unref (obj);
112
1
  g_object_unref (cell);
113
1
  g_object_unref (child);
114
1
}
115

            
116
/*
117
static void
118
atk_test_table_cell_get_row_header_cells (TestAppFixture *fixture, gconstpointer user_data)
119
{
120
  AtspiAccessible *_obj = fixture->root_obj;
121
  g_assert_nonnull (_obj);
122
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
123
  g_assert_nonnull (child);
124

            
125
  AtspiAccessible *cell = atspi_accessible_get_child_at_index (child, 10, NULL);
126
  AtspiTableCell *obj = atspi_accessible_get_table_cell (cell);
127
  g_assert_nonnull (obj);
128

            
129
  GPtrArray *ret = atspi_table_cell_get_row_header_cells (obj, NULL);
130
  g_assert_cmpint (4, ==, ret->len);
131
  g_array_free (ret, TRUE);
132
  g_object_unref (obj);
133
  g_object_unref (cell);
134
  g_object_unref (child);
135
}
136
*/
137

            
138
static void
139
1
atk_test_table_cell_get_row_column_span (TestAppFixture *fixture, gconstpointer user_data)
140
{
141
1
  AtspiAccessible *_obj = fixture->root_obj;
142
1
  g_assert_nonnull (_obj);
143
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
144
1
  g_assert_nonnull (child);
145

            
146
1
  AtspiAccessible *cell = atspi_accessible_get_child_at_index (child, 9, NULL);
147
1
  AtspiTableCell *obj = atspi_accessible_get_table_cell (cell);
148
1
  g_assert_nonnull (obj);
149

            
150
1
  gint row = 10;
151
1
  gint column = 10;
152
1
  gint row_span = 10;
153
1
  gint column_span = 10;
154

            
155
1
  atspi_table_cell_get_row_column_span (obj, &row, &column, &row_span, &column_span, NULL);
156

            
157
1
  g_assert_cmpint (row, ==, 0);
158
1
  g_assert_cmpint (column, ==, 0);
159
1
  g_assert_cmpint (row_span, ==, 2);
160
1
  g_assert_cmpint (column_span, ==, 1);
161
1
  g_object_unref (obj);
162
1
  g_object_unref (cell);
163
1
  g_object_unref (child);
164
1
}
165

            
166
static void
167
1
atk_test_table_cell_get_position (TestAppFixture *fixture, gconstpointer user_data)
168
{
169
1
  AtspiAccessible *_obj = fixture->root_obj;
170
1
  g_assert_nonnull (_obj);
171
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
172
1
  g_assert_nonnull (child);
173

            
174
1
  AtspiAccessible *cell = atspi_accessible_get_child_at_index (child, 9, NULL);
175
1
  AtspiTableCell *obj = atspi_accessible_get_table_cell (cell);
176
1
  g_assert_nonnull (cell);
177

            
178
1
  gint row = 10;
179
1
  gint column = 10;
180

            
181
1
  atspi_table_cell_get_position (obj, &row, &column, NULL);
182

            
183
  /* TODO: not a very good test for the app to return (-1, -1) */
184
1
  g_assert_cmpint (row, ==, -1);
185
1
  g_assert_cmpint (column, ==, -1);
186
1
  g_object_unref (obj);
187
1
  g_object_unref (cell);
188
1
  g_object_unref (child);
189
1
}
190

            
191
static void
192
1
atk_test_table_cell_get_table (TestAppFixture *fixture, gconstpointer user_data)
193
{
194
1
  AtspiAccessible *_obj = fixture->root_obj;
195
1
  g_assert_nonnull (_obj);
196
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
197
1
  g_assert_nonnull (child);
198

            
199
1
  AtspiAccessible *cell = atspi_accessible_get_child_at_index (child, 9, NULL);
200
1
  AtspiTableCell *obj = atspi_accessible_get_table_cell (cell);
201
1
  g_assert_nonnull (obj);
202

            
203
1
  AtspiAccessible *tab = atspi_table_cell_get_table (obj, NULL);
204
1
  g_assert_nonnull (tab);
205
1
  g_assert_true (child == tab);
206
1
  g_object_unref (tab);
207
1
  g_object_unref (obj);
208
1
  g_object_unref (cell);
209
1
  g_object_unref (child);
210
1
}
211

            
212
void
213
1
atk_test_table_cell (void)
214
{
215
1
  g_test_add ("/table_cell/atk_test_accessible_get_table_cell",
216
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_accessible_get_table_cell, fixture_teardown);
217
1
  g_test_add ("/table_cell/atk_test_table_cell_get_column_span",
218
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_table_cell_get_column_span, fixture_teardown);
219
  /*
220
    g_test_add ("/table_cell/atk_test_table_cell_get_column_header_cells",
221
                TestAppFixture, DATA_FILE, fixture_setup, atk_test_table_cell_get_column_header_cells, fixture_teardown);
222
  */
223
1
  g_test_add ("/table_cell/atk_test_table_cell_get_row_span",
224
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_table_cell_get_row_span, fixture_teardown);
225
  /*
226
    g_test_add ("/table_cell/atk_test_table_cell_get_row_header_cells",
227
                TestAppFixture, DATA_FILE, fixture_setup, atk_test_table_cell_get_row_header_cells, fixture_teardown);
228
  */
229
1
  g_test_add ("/table_cell/atk_test_table_cell_get_row_column_span",
230
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_table_cell_get_row_column_span, fixture_teardown);
231
1
  g_test_add ("/table_cell/atk_test_table_cell_get_position",
232
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_table_cell_get_position, fixture_teardown);
233
1
  g_test_add ("/table_cell/atk_test_table_cell_get_table",
234
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_table_cell_get_table, fixture_teardown);
235
1
}