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-hypertext.xml"
25

            
26
static void
27
1
atk_test_hyperlink_get_n_anchors (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
1
  AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
34
1
  g_assert_nonnull (obj1);
35
1
  AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
36
1
  g_assert_nonnull (obj);
37
1
  gint n = atspi_hyperlink_get_n_anchors (obj, NULL);
38
1
  g_assert_cmpint (n, ==, 1);
39
1
  g_object_unref (obj);
40
1
  g_object_unref (obj1);
41
1
  g_object_unref (child);
42
1
}
43

            
44
static void
45
1
atk_test_hyperlink_get_uri (TestAppFixture *fixture, gconstpointer user_data)
46
{
47
1
  AtspiAccessible *_obj = fixture->root_obj;
48
1
  g_assert_nonnull (_obj);
49
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
50
1
  g_assert_nonnull (child);
51
1
  AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
52
1
  g_assert_nonnull (obj1);
53
1
  AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
54
1
  g_assert_nonnull (obj);
55
1
  gchar *str = atspi_hyperlink_get_uri (obj, 0, NULL);
56
1
  g_assert_nonnull (str);
57
1
  g_assert_cmpstr (str, ==, "pinkbike.com");
58
1
  g_free (str);
59
1
  g_object_unref (obj);
60
1
  g_object_unref (obj1);
61
1
  g_object_unref (child);
62
1
}
63

            
64
static void
65
1
atk_test_hyperlink_get_object (TestAppFixture *fixture, gconstpointer user_data)
66
{
67
1
  AtspiAccessible *_obj = fixture->root_obj;
68
1
  g_assert_nonnull (_obj);
69
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
70
1
  g_assert_nonnull (child);
71
1
  AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
72
1
  g_assert_nonnull (obj1);
73
1
  AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
74
1
  g_assert_nonnull (obj);
75
1
  AtspiAccessible *acc = atspi_hyperlink_get_object (obj, 0, NULL);
76
1
  g_assert_nonnull (acc);
77
1
  AtspiText *at = atspi_accessible_get_text_iface (acc);
78
1
  g_assert_nonnull (at);
79
1
  gchar *text = atspi_text_get_text (at, 0, 12, NULL);
80
1
  g_assert_cmpstr (text, ==, "pinkbike.com");
81
1
  g_free (text);
82
1
  g_object_unref (at);
83
1
  g_object_unref (acc);
84
1
  g_object_unref (obj);
85
1
  g_object_unref (obj1);
86
1
  g_object_unref (child);
87
1
}
88

            
89
static void
90
1
atk_test_hyperlink_get_index_range (TestAppFixture *fixture, gconstpointer user_data)
91
{
92
1
  AtspiAccessible *_obj = fixture->root_obj;
93
1
  g_assert_nonnull (_obj);
94
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
95
1
  g_assert_nonnull (child);
96
1
  AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
97
1
  g_assert_nonnull (obj1);
98
1
  AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
99
1
  g_assert_nonnull (obj);
100
1
  AtspiRange *range = atspi_hyperlink_get_index_range (obj, NULL);
101
1
  g_assert_nonnull (range);
102
  /*
103
    ATK do not define this function
104
  */
105
1
  g_assert_cmpint (range->start_offset, ==, -1);
106
1
  g_assert_cmpint (range->end_offset, ==, -1);
107
1
  g_free (range);
108
1
  g_object_unref (obj);
109
1
  g_object_unref (obj1);
110
1
  g_object_unref (child);
111
1
}
112

            
113
static void
114
1
atk_test_hyperlink_get_start_index (TestAppFixture *fixture, gconstpointer user_data)
115
{
116
1
  AtspiAccessible *_obj = fixture->root_obj;
117
1
  g_assert_nonnull (_obj);
118
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
119
1
  g_assert_nonnull (child);
120
1
  AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
121
1
  g_assert_nonnull (obj1);
122
1
  AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
123
1
  g_assert_nonnull (obj);
124
1
  gint n = atspi_hyperlink_get_start_index (obj, NULL);
125
1
  g_assert_cmpint (n, ==, 69);
126
1
  g_object_unref (obj);
127
1
  g_object_unref (obj1);
128
1
  g_object_unref (child);
129
1
}
130

            
131
static void
132
1
atk_test_hyperlink_get_end_index (TestAppFixture *fixture, gconstpointer user_data)
133
{
134
1
  AtspiAccessible *_obj = fixture->root_obj;
135
1
  g_assert_nonnull (_obj);
136
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
137
1
  g_assert_nonnull (child);
138
1
  AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
139
1
  g_assert_nonnull (obj1);
140
1
  AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
141
1
  g_assert_nonnull (obj);
142
1
  gint n = atspi_hyperlink_get_end_index (obj, NULL);
143
1
  g_assert_cmpint (n, ==, 81);
144
1
  g_object_unref (obj);
145
1
  g_object_unref (obj1);
146
1
  g_object_unref (child);
147
1
}
148

            
149
static void
150
1
atk_test_hyperlink_is_valid (TestAppFixture *fixture, gconstpointer user_data)
151
{
152
1
  AtspiAccessible *_obj = fixture->root_obj;
153
1
  g_assert_nonnull (_obj);
154
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
155
1
  g_assert_nonnull (child);
156
1
  AtspiHypertext *obj1 = atspi_accessible_get_hypertext_iface (child);
157
1
  g_assert_nonnull (obj1);
158
1
  AtspiHyperlink *obj = atspi_hypertext_get_link (obj1, 1, NULL);
159
1
  g_assert_nonnull (obj);
160
1
  g_assert_true (atspi_hyperlink_is_valid (obj, NULL));
161
1
  g_object_unref (obj);
162
1
  g_object_unref (obj1);
163
1
  g_object_unref (child);
164
1
}
165

            
166
void
167
1
atk_test_hyperlink (void)
168
{
169
1
  g_test_add ("/hyperlink/atk_test_hyperlink_get_n_anchors",
170
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hyperlink_get_n_anchors, fixture_teardown);
171
1
  g_test_add ("/hyperlink/atk_test_hyperlink_get_uri",
172
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hyperlink_get_uri, fixture_teardown);
173
1
  g_test_add ("/hyperlink/atk_test_hyperlink_get_object",
174
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hyperlink_get_object, fixture_teardown);
175
1
  g_test_add ("/hyperlink/atk_test_hyperlink_get_index_range",
176
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hyperlink_get_index_range, fixture_teardown);
177
1
  g_test_add ("/hyperlink/atk_test_hyperlink_get_start_index",
178
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hyperlink_get_start_index, fixture_teardown);
179
1
  g_test_add ("/hyperlink/atk_test_hyperlink_get_end_index",
180
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hyperlink_get_end_index, fixture_teardown);
181
1
  g_test_add ("/hyperlink/atk_test_hyperlink_is_valid",
182
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hyperlink_is_valid, fixture_teardown);
183
1
}