6ce7439e8474c7cff2f64ad8f362aa051c4004f9
[platform/upstream/at-spi2-atk.git] / tests / atk_test_component.c
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 teardown_component_test (gpointer fixture, gconstpointer user_data)
30 {
31   terminate_app ();
32 }
33
34 static void
35 atk_test_component_sample (gpointer fixture, gconstpointer user_data)
36 {
37   AtspiAccessible *obj = get_root_obj (DATA_FILE);
38   g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
39   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
40   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
41   g_assert (iface != NULL);
42 }
43
44 static void
45 atk_test_component_contains (gpointer fixture, gconstpointer user_data)
46 {
47   AtspiAccessible *obj = get_root_obj (DATA_FILE);
48   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
49   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
50   g_assert (iface != NULL);
51
52   gboolean ret = atspi_component_contains (iface, 400, 300, ATSPI_COORD_TYPE_SCREEN, NULL);
53   g_assert (ret != FALSE);
54 }
55
56 static void
57 atk_test_component_get_accessible_at_point (gpointer fixture, gconstpointer user_data)
58 {
59   AtspiAccessible *obj = get_root_obj (DATA_FILE);
60   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
61   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
62   g_assert (iface != NULL);
63
64   AtspiAccessible *r = atspi_component_get_accessible_at_point (iface,
65                        400,
66                        300,
67                        ATSPI_COORD_TYPE_SCREEN,
68                        NULL);
69   g_assert (r != NULL);
70 }
71
72 static void
73 atk_test_component_get_extents (gpointer fixture, gconstpointer user_data)
74 {
75   AtspiAccessible *obj = get_root_obj (DATA_FILE);
76   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
77   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
78   g_assert (iface != NULL);
79
80   AtspiRect *r = atspi_component_get_extents (iface, ATSPI_COORD_TYPE_SCREEN, NULL);
81   g_assert_cmpint (r->x, ==, 350);
82   g_assert_cmpint (r->y, ==, 200);
83   g_assert_cmpint (r->width, ==, 250);
84   g_assert_cmpint (r->height, ==, 250);
85   g_free (r);
86 }
87
88 static void
89 atk_test_component_get_layer (gpointer fixture, gconstpointer user_data)
90 {
91   AtspiAccessible *obj = get_root_obj (DATA_FILE);
92   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
93   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
94   g_assert (iface != NULL);
95
96   AtspiComponentLayer layer = atspi_component_get_layer (iface, NULL);
97   g_assert_cmpint (layer, ==, ATSPI_LAYER_WIDGET);
98 }
99
100 static void
101 atk_test_component_get_mdi_z_order (gpointer fixture, gconstpointer user_data)
102 {
103   AtspiAccessible *obj = get_root_obj (DATA_FILE);
104   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
105   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
106   g_assert (iface != NULL);
107
108   gshort ret = atspi_component_get_mdi_z_order (iface, NULL);
109   g_assert_cmpint (ret, ==, 2);
110 }
111
112 static void
113 atk_test_component_grab_focus (gpointer fixture, gconstpointer user_data)
114 {
115   AtspiAccessible *obj = get_root_obj (DATA_FILE);
116   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
117   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
118   g_assert (iface != NULL);
119
120   gboolean ret = atspi_component_grab_focus (iface, NULL);
121   g_assert (ret != FALSE);
122 }
123
124 static void
125 atk_test_component_get_alpha (gpointer fixture, gconstpointer user_data)
126 {
127   AtspiAccessible *obj = get_root_obj (DATA_FILE);
128   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
129   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
130   g_assert (iface != NULL);
131
132   gdouble ret = atspi_component_get_alpha (iface, NULL);
133   g_assert_cmpint (ret, ==, 2.5);
134 }
135
136 static void
137 atk_test_component_set_extents (gpointer fixture, gconstpointer user_data)
138 {
139   AtspiAccessible *obj = get_root_obj (DATA_FILE);
140   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
141   AtspiComponent *iface = atspi_accessible_get_component_iface (child);
142   g_assert (iface != NULL);
143
144   AtspiRect *r = atspi_component_get_extents (iface, ATSPI_COORD_TYPE_SCREEN, NULL);
145   g_assert_cmpint (r->x, ==, 350);
146   g_assert_cmpint (r->y, ==, 200);
147   g_assert_cmpint (r->width, ==, 250);
148   g_assert_cmpint (r->height, ==, 250);
149   g_free (r);
150
151   gboolean ret = atspi_component_set_extents (iface, 100, 100, 100, 100, ATSPI_COORD_TYPE_SCREEN, NULL);
152   g_assert (ret != FALSE);
153
154   r = atspi_component_get_extents (iface, ATSPI_COORD_TYPE_SCREEN, NULL);
155   g_assert_cmpint (r->x, ==, 100);
156   g_assert_cmpint (r->y, ==, 100);
157   g_assert_cmpint (r->width, ==, 100);
158   g_assert_cmpint (r->height, ==, 100);
159   g_free (r);
160 }
161
162 void
163 atk_test_component (void)
164 {
165   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_sample",
166                      0, NULL, NULL, atk_test_component_sample, teardown_component_test);
167   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_contains",
168                      0, NULL, NULL, atk_test_component_contains, teardown_component_test);
169   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_get_accessible_at_point",
170                      0, NULL, NULL, atk_test_component_get_accessible_at_point, teardown_component_test);
171   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_get_extents",
172                      0, NULL, NULL, atk_test_component_get_extents, teardown_component_test);
173   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_get_layer",
174                      0, NULL, NULL, atk_test_component_get_layer, teardown_component_test);
175   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_get_mdi_z_order",
176                      0, NULL, NULL, atk_test_component_get_mdi_z_order, teardown_component_test);
177   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_grab_focus",
178                      0, NULL, NULL, atk_test_component_grab_focus, teardown_component_test);
179   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_get_alpha",
180                      0, NULL, NULL, atk_test_component_get_alpha, teardown_component_test);
181   g_test_add_vtable (ATK_TEST_PATH_COMP "/atk_test_component_set_extents",
182                      0, NULL, NULL, atk_test_component_set_extents, teardown_component_test);
183 }