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

            
28
static void
29
1
atk_test_component_sample (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, 1, NULL);
34
1
  AtspiComponent *iface = atspi_accessible_get_component_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_component_contains (TestAppFixture *fixture, gconstpointer user_data)
42
{
43
1
  AtspiAccessible *obj = fixture->root_obj;
44
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
45
1
  AtspiComponent *iface = atspi_accessible_get_component_iface (child);
46
1
  g_assert_nonnull (iface);
47

            
48
1
  gboolean ret = atspi_component_contains (iface, 400, 300, ATSPI_COORD_TYPE_SCREEN, NULL);
49
1
  g_assert_true (ret);
50
1
  g_object_unref (iface);
51
1
  g_object_unref (child);
52
1
}
53

            
54
static void
55
1
atk_test_component_get_accessible_at_point (TestAppFixture *fixture, gconstpointer user_data)
56
{
57
1
  AtspiAccessible *obj = fixture->root_obj;
58
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
59
1
  AtspiComponent *iface = atspi_accessible_get_component_iface (child);
60
1
  g_assert_nonnull (iface);
61

            
62
1
  AtspiAccessible *r = atspi_component_get_accessible_at_point (iface,
63
                                                                400,
64
                                                                300,
65
                                                                ATSPI_COORD_TYPE_SCREEN,
66
                                                                NULL);
67
1
  g_assert_nonnull (r);
68
1
  g_object_unref (r);
69
1
  g_object_unref (iface);
70
1
  g_object_unref (child);
71
1
}
72

            
73
static void
74
1
atk_test_component_get_extents (TestAppFixture *fixture, gconstpointer user_data)
75
{
76
1
  AtspiAccessible *obj = fixture->root_obj;
77
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
78
1
  AtspiComponent *iface = atspi_accessible_get_component_iface (child);
79
1
  g_assert_nonnull (iface);
80

            
81
1
  AtspiRect *r = atspi_component_get_extents (iface, ATSPI_COORD_TYPE_SCREEN, NULL);
82
1
  g_assert_cmpint (r->x, ==, 350);
83
1
  g_assert_cmpint (r->y, ==, 200);
84
1
  g_assert_cmpint (r->width, ==, 250);
85
1
  g_assert_cmpint (r->height, ==, 250);
86
1
  g_free (r);
87
1
  g_object_unref (iface);
88
1
  g_object_unref (child);
89
1
}
90

            
91
static void
92
1
atk_test_component_get_layer (TestAppFixture *fixture, gconstpointer user_data)
93
{
94
1
  AtspiAccessible *obj = fixture->root_obj;
95
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
96
1
  AtspiComponent *iface = atspi_accessible_get_component_iface (child);
97
1
  g_assert_nonnull (iface);
98

            
99
1
  AtspiComponentLayer layer = atspi_component_get_layer (iface, NULL);
100
1
  g_assert_cmpint (layer, ==, ATSPI_LAYER_WIDGET);
101
1
  g_object_unref (iface);
102
1
  g_object_unref (child);
103
1
}
104

            
105
static void
106
1
atk_test_component_get_mdi_z_order (TestAppFixture *fixture, gconstpointer user_data)
107
{
108
1
  AtspiAccessible *obj = fixture->root_obj;
109
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
110
1
  AtspiComponent *iface = atspi_accessible_get_component_iface (child);
111
1
  g_assert_nonnull (iface);
112

            
113
1
  gshort ret = atspi_component_get_mdi_z_order (iface, NULL);
114
1
  g_assert_cmpint (ret, ==, 2);
115
1
  g_object_unref (iface);
116
1
  g_object_unref (child);
117
1
}
118

            
119
static void
120
1
atk_test_component_grab_focus (TestAppFixture *fixture, gconstpointer user_data)
121
{
122
1
  AtspiAccessible *obj = fixture->root_obj;
123
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
124
1
  AtspiComponent *iface = atspi_accessible_get_component_iface (child);
125
1
  g_assert_nonnull (iface);
126

            
127
1
  gboolean ret = atspi_component_grab_focus (iface, NULL);
128
1
  g_assert_true (ret);
129
1
  g_object_unref (iface);
130
1
  g_object_unref (child);
131
1
}
132

            
133
static void
134
1
atk_test_component_get_alpha (TestAppFixture *fixture, gconstpointer user_data)
135
{
136
1
  AtspiAccessible *obj = fixture->root_obj;
137
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
138
1
  AtspiComponent *iface = atspi_accessible_get_component_iface (child);
139
1
  g_assert_nonnull (iface);
140

            
141
1
  gdouble ret = atspi_component_get_alpha (iface, NULL);
142
1
  g_assert_cmpfloat (ret, ==, 2.5);
143
1
  g_object_unref (iface);
144
1
  g_object_unref (child);
145
1
}
146

            
147
static void
148
1
atk_test_component_set_extents (TestAppFixture *fixture, gconstpointer user_data)
149
{
150
1
  AtspiAccessible *obj = fixture->root_obj;
151
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
152
1
  AtspiComponent *iface = atspi_accessible_get_component_iface (child);
153
1
  g_assert_nonnull (iface);
154

            
155
1
  AtspiRect *r = atspi_component_get_extents (iface, ATSPI_COORD_TYPE_SCREEN, NULL);
156
1
  g_assert_cmpint (r->x, ==, 350);
157
1
  g_assert_cmpint (r->y, ==, 200);
158
1
  g_assert_cmpint (r->width, ==, 250);
159
1
  g_assert_cmpint (r->height, ==, 250);
160
1
  g_free (r);
161

            
162
1
  gboolean ret = atspi_component_set_extents (iface, 100, 100, 100, 100, ATSPI_COORD_TYPE_SCREEN, NULL);
163
1
  g_assert_true (ret);
164

            
165
1
  r = atspi_component_get_extents (iface, ATSPI_COORD_TYPE_SCREEN, NULL);
166
1
  g_assert_cmpint (r->x, ==, 100);
167
1
  g_assert_cmpint (r->y, ==, 100);
168
1
  g_assert_cmpint (r->width, ==, 100);
169
1
  g_assert_cmpint (r->height, ==, 100);
170
1
  g_free (r);
171
1
  g_object_unref (iface);
172
1
  g_object_unref (child);
173
1
}
174

            
175
void
176
1
atk_test_component (void)
177
{
178
1
  g_test_add ("/component/atk_test_component_sample",
179
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_sample, fixture_teardown);
180
1
  g_test_add ("/component/atk_test_component_contains",
181
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_contains, fixture_teardown);
182
1
  g_test_add ("/component/atk_test_component_get_accessible_at_point",
183
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_get_accessible_at_point, fixture_teardown);
184
1
  g_test_add ("/component/atk_test_component_get_extents",
185
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_get_extents, fixture_teardown);
186
1
  g_test_add ("/component/atk_test_component_get_layer",
187
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_get_layer, fixture_teardown);
188
1
  g_test_add ("/component/atk_test_component_get_mdi_z_order",
189
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_get_mdi_z_order, fixture_teardown);
190
1
  g_test_add ("/component/atk_test_component_grab_focus",
191
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_grab_focus, fixture_teardown);
192
1
  g_test_add ("/component/atk_test_component_get_alpha",
193
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_get_alpha, fixture_teardown);
194
1
  g_test_add ("/component/atk_test_component_set_extents",
195
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_component_set_extents, fixture_teardown);
196
1
}