New tests for last interfaces
[platform/upstream/at-spi2-atk.git] / tests / atk_test_hypertext.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 Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 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  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, 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_hypertext_get_n_links (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 *obj = atspi_accessible_get_hypertext_iface (child);
34   g_assert (obj);
35   gint cnt = atspi_hypertext_get_n_links (obj, NULL);
36   g_assert_cmpint (cnt, ==, 2);
37 }
38
39 static void
40 atk_test_hypertext_get_link (gpointer fixture, gconstpointer user_data)
41 {
42   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
43   g_assert (_obj);
44   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
45   g_assert (child);
46   AtspiHypertext *obj = atspi_accessible_get_hypertext_iface (child);
47   g_assert (obj);
48   AtspiHyperlink *link = atspi_hypertext_get_link (obj, 1, NULL);
49   g_assert (link);
50   gchar *str = atspi_hyperlink_get_uri (link, 0, NULL);
51   g_assert (str);
52   g_assert_cmpstr (str, ==, "pinkbike.com");
53
54   g_free (str);
55
56   link = atspi_hypertext_get_link (obj, 0, NULL);
57   str = atspi_hyperlink_get_uri (link, 0, NULL);
58   g_assert_cmpstr (str, ==, "dh-zone.com");
59
60   g_free (str);
61 }
62
63 static void
64 atk_test_hypertext_get_link_index (gpointer fixture, gconstpointer user_data)
65 {
66   AtspiAccessible *_obj = get_root_obj (DATA_FILE);
67   g_assert (_obj);
68   AtspiAccessible *child = atspi_accessible_get_child_at_index (_obj, 0, NULL);
69   g_assert (child);
70   AtspiHypertext *obj = atspi_accessible_get_hypertext_iface (child);
71   g_assert (obj);
72   gint cnt = atspi_hypertext_get_link_index (obj, 15, NULL);
73   g_assert_cmpint (cnt, ==, -1);
74   cnt = atspi_hypertext_get_link_index (obj, 55, NULL);
75   g_assert_cmpint (cnt, ==, 0);
76   cnt = atspi_hypertext_get_link_index (obj, 70, NULL);
77   g_assert_cmpint (cnt, ==, 1);
78 }
79
80 static void
81 teardown_hypertext_test (gpointer fixture, gconstpointer user_data)
82 {
83   kill (child_pid, SIGTERM);
84 }
85
86 void
87 atk_test_hypertext (void)
88 {
89   g_test_add_vtable (ATK_TEST_PATH_HYPERTEXT "/atk_test_hypertext_get_n_links",
90                      0, NULL, NULL, atk_test_hypertext_get_n_links, teardown_hypertext_test );
91   g_test_add_vtable (ATK_TEST_PATH_HYPERTEXT "/atk_test_hypertext_get_links",
92                      0, NULL, NULL, atk_test_hypertext_get_link, teardown_hypertext_test );
93   g_test_add_vtable (ATK_TEST_PATH_HYPERTEXT "/atk_test_hypertext_get_link_index",
94                      0, NULL, NULL, atk_test_hypertext_get_link_index, teardown_hypertext_test );
95 }