2.34.1
[platform/upstream/at-spi2-atk.git] / tests / atk_test_hyperlink.c
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_test_util.h"
22 #include "atk_suite.h"
23
24 #define DATA_FILE TESTS_DATA_DIR"/test-hypertext.xml"
25
26 static void
27 atk_test_hyperlink_get_n_anchors (gpointer fixture, gconstpointer user_data)
28 {
29   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
30   g_assert (_obj);
31   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
32   g_assert (child);
33   AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
34   g_assert (obj1);
35   AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
36   g_assert (obj);
37   gint n = atspi_hyperlink_get_n_anchors (obj, NULL);
38   g_assert_cmpint (n, ==, 1);
39 }
40
41 static void
42 atk_test_hyperlink_get_uri (gpointer fixture, gconstpointer user_data)
43 {
44   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
45   g_assert (_obj);
46   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
47   g_assert (child);
48   AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
49   g_assert (obj1);
50   AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
51   g_assert (obj);
52   gchar *str = atspi_hyperlink_get_uri (obj, 0, NULL);
53   g_assert (str);
54   g_assert_cmpstr (str, ==, "pinkbike.com");
55 }
56
57 static void
58 atk_test_hyperlink_get_object (gpointer fixture, gconstpointer user_data)
59 {
60   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
61   g_assert (_obj);
62   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
63   g_assert (child);
64   AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
65   g_assert (obj1);
66   AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
67   g_assert (obj);
68   AtspiAccessible *acc = atspi_hyperlink_get_object (obj, 0, NULL);
69   g_assert (acc);
70   AtspiText *at = atspi_accessible_get_text_iface (acc);
71   g_assert (at);
72   gchar *text = atspi_text_get_text (at, 0, 12, NULL);
73   g_assert_cmpstr (text,==,"pinkbike.com");
74   g_free (text);
75 }
76
77 static void
78 atk_test_hyperlink_get_index_range (gpointer fixture, gconstpointer user_data)
79 {
80   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
81   g_assert (_obj);
82   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
83   g_assert (child);
84   AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
85   g_assert (obj1);
86   AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
87   g_assert (obj);
88   AtspiRange *range = atspi_hyperlink_get_index_range (obj, NULL);
89   g_assert (range);
90   /*
91     ATK do not define this function
92   */
93   g_assert_cmpint (range->start_offset, ==, -1);
94   g_assert_cmpint (range->end_offset, ==, -1);
95   g_free (range);
96 }
97
98 static void
99 atk_test_hyperlink_get_start_index (gpointer fixture, gconstpointer user_data)
100 {
101   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
102   g_assert (_obj);
103   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
104   g_assert (child);
105   AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
106   g_assert (obj1);
107   AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
108   g_assert  (obj);
109   gint n = atspi_hyperlink_get_start_index (obj, NULL);
110   g_assert_cmpint (n, ==, 69);
111 }
112
113 static void
114 atk_test_hyperlink_get_end_index (gpointer fixture, gconstpointer user_data)
115 {
116   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
117   g_assert (_obj);
118   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
119   g_assert (child);
120   AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
121   g_assert (obj1);
122   AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
123   g_assert (obj);
124   gint n = atspi_hyperlink_get_end_index (obj, NULL);
125   g_assert_cmpint (n, ==, 81);
126 }
127
128 static void
129 atk_test_hyperlink_is_valid (gpointer fixture, gconstpointer user_data)
130 {
131   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
132   g_assert (_obj);
133   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
134   g_assert (child);
135   AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
136   g_assert (obj1);
137   AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
138   g_assert (obj);
139   g_assert (atspi_hyperlink_is_valid (obj, NULL));
140 }
141
142 static void
143 teardown_hyperlink_test (gpointer fixture, gconstpointer user_data)
144 {
145   terminate_app ();
146 }
147
148 void
149 atk_test_hyperlink(void)
150 {
151   g_test_add_vtable(ATK_TEST_PATH_HYPERTEXT "/atk_test_hyperlink_get_n_anchors",
152                     0, NULL, NULL, atk_test_hyperlink_get_n_anchors, teardown_hyperlink_test );
153   g_test_add_vtable(ATK_TEST_PATH_HYPERTEXT "/atk_test_hyperlink_get_uri",
154                     0, NULL, NULL, atk_test_hyperlink_get_uri, teardown_hyperlink_test);
155   g_test_add_vtable(ATK_TEST_PATH_HYPERTEXT "/atk_test_hyperlink_get_object",
156                     0, NULL, NULL, atk_test_hyperlink_get_object, teardown_hyperlink_test);
157   g_test_add_vtable(ATK_TEST_PATH_HYPERTEXT "/atk_test_hyperlink_get_index_range",
158                     0, NULL, NULL, atk_test_hyperlink_get_index_range, teardown_hyperlink_test);
159   g_test_add_vtable(ATK_TEST_PATH_HYPERTEXT "/atk_test_hyperlink_get_start_index",
160                     0, NULL, NULL, atk_test_hyperlink_get_start_index, teardown_hyperlink_test);
161   g_test_add_vtable(ATK_TEST_PATH_HYPERTEXT "/atk_test_hyperlink_get_end_index",
162                     0, NULL, NULL, atk_test_hyperlink_get_end_index, teardown_hyperlink_test);
163   g_test_add_vtable(ATK_TEST_PATH_HYPERTEXT "/atk_test_hyperlink_is_valid",
164                     0, NULL, NULL, atk_test_hyperlink_is_valid, teardown_hyperlink_test);
165 }