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_hypertext_get_n_links (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 *obj = atspi_accessible_get_hypertext_iface (child);
34
1
  g_assert_nonnull (obj);
35
1
  gint cnt = atspi_hypertext_get_n_links (obj, NULL);
36
1
  g_assert_cmpint (cnt, ==, 2);
37
1
  g_object_unref (obj);
38
1
  g_object_unref (child);
39
1
}
40

            
41
static void
42
1
atk_test_hypertext_get_link (TestAppFixture *fixture, gconstpointer user_data)
43
{
44
1
  AtspiAccessible *_obj = fixture->root_obj;
45
1
  g_assert_nonnull (_obj);
46
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
47
1
  g_assert_nonnull (child);
48
1
  AtspiHypertext *obj = atspi_accessible_get_hypertext_iface (child);
49
1
  g_assert_nonnull (obj);
50
1
  AtspiHyperlink *link = atspi_hypertext_get_link (obj, 1, NULL);
51
1
  g_assert_nonnull (link);
52
1
  gchar *str = atspi_hyperlink_get_uri (link, 0, NULL);
53
1
  g_assert_nonnull (str);
54
1
  g_assert_cmpstr (str, ==, "pinkbike.com");
55

            
56
1
  g_free (str);
57
1
  g_object_unref (link);
58

            
59
1
  link = atspi_hypertext_get_link (obj, 0, NULL);
60
1
  str = atspi_hyperlink_get_uri (link, 0, NULL);
61
1
  g_assert_cmpstr (str, ==, "dh-zone.com");
62

            
63
1
  g_free (str);
64
1
  g_object_unref (link);
65
1
  g_object_unref (obj);
66
1
  g_object_unref (child);
67
1
}
68

            
69
static void
70
1
atk_test_hypertext_get_link_index (TestAppFixture *fixture, gconstpointer user_data)
71
{
72
1
  AtspiAccessible *_obj = fixture->root_obj;
73
1
  g_assert_nonnull (_obj);
74
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
75
1
  g_assert_nonnull (child);
76
1
  AtspiHypertext *obj = atspi_accessible_get_hypertext_iface (child);
77
1
  g_assert_nonnull (obj);
78
1
  gint cnt = atspi_hypertext_get_link_index (obj, 15, NULL);
79
1
  g_assert_cmpint (cnt, ==, -1);
80
1
  cnt = atspi_hypertext_get_link_index (obj, 55, NULL);
81
1
  g_assert_cmpint (cnt, ==, 0);
82
1
  cnt = atspi_hypertext_get_link_index (obj, 70, NULL);
83
1
  g_assert_cmpint (cnt, ==, 1);
84
1
  g_object_unref (obj);
85
1
  g_object_unref (child);
86
1
}
87

            
88
void
89
1
atk_test_hypertext (void)
90
{
91
1
  g_test_add ("/hypertext/atk_test_hypertext_get_n_links",
92
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hypertext_get_n_links, fixture_teardown);
93
1
  g_test_add ("/hypertext/atk_test_hypertext_get_links",
94
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hypertext_get_link, fixture_teardown);
95
1
  g_test_add ("/hypertext/atk_test_hypertext_get_link_index",
96
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_hypertext_get_link_index, fixture_teardown);
97
1
}