New tests for last interfaces
[platform/upstream/at-spi2-atk.git] / tests / atk_test_document.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
4  *
5  * Copyright (c) 2014 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 Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 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  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "atk_suite.h"
24 #include "atk_test_util.h"
25
26 #define DATA_FILE TESTS_DATA_DIR"/test-document.xml"
27
28 static void
29 teardown_document_test (gpointer fixture, gconstpointer user_data)
30 {
31   kill (child_pid, SIGTERM);
32 }
33
34 static void
35 atk_test_document_get_document_iface (gpointer fixture, gconstpointer user_data)
36 {
37   AtspiAccessible *obj = get_root_obj (DATA_FILE);
38   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
39   AtspiDocument *iface = atspi_accessible_get_document_iface (child);
40   g_assert (iface != NULL);
41 }
42
43 static void
44 atk_test_document_get_locale (gpointer fixture, gconstpointer user_data)
45 {
46   AtspiAccessible *obj = get_root_obj (DATA_FILE);
47   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
48   AtspiDocument *iface = atspi_accessible_get_document_iface (child);
49   g_assert (iface != NULL);
50
51   g_assert_cmpstr (atspi_document_get_locale (iface, NULL), ==, "document_locale");
52 }
53
54 static void
55 atk_test_document_get_attribute_value (gpointer fixture, gconstpointer user_data)
56 {
57   AtspiAccessible *obj = get_root_obj (DATA_FILE);
58   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
59   AtspiDocument *iface = atspi_accessible_get_document_iface (child);
60   g_assert (iface != NULL);
61
62   g_assert_cmpstr (atspi_document_get_document_attribute_value (iface, "atspi1", NULL), ==, "test1");
63   g_assert_cmpstr (atspi_document_get_document_attribute_value (iface, "atspi2", NULL), ==, "test2");
64 }
65
66 static void
67 atk_test_document_get_attributes (gpointer fixture, gconstpointer user_data)
68 {
69   AtspiAccessible *obj = get_root_obj (DATA_FILE);
70   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
71   AtspiDocument *iface = atspi_accessible_get_document_iface (child);
72   g_assert (iface != NULL);
73
74   GHashTable *attr = atspi_document_get_document_attributes (iface, NULL);
75   GHashTableIter iter;
76   gpointer key, value;
77   g_hash_table_iter_init (&iter, attr);
78
79   gchar *valid_keys[] = {"atspi1", "atspi2"};
80   gchar *valid_values[] = {"test1", "test2"};
81
82   int i=0;
83   while (g_hash_table_iter_next (&iter, &key, &value)) {
84     g_assert_cmpstr (valid_keys[i], ==, (gchar *)key);
85     g_assert_cmpstr (valid_values[i], ==, (gchar *)value);
86     ++i;
87   }
88 }
89
90 void
91 atk_test_document(void )
92 {
93   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_document_get_document_iface",
94                      0, NULL, NULL, atk_test_document_get_document_iface, teardown_document_test);
95   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_document_get_locale",
96                      0, NULL, NULL, atk_test_document_get_locale, teardown_document_test);
97   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_document_get_attribute_value",
98                      0, NULL, NULL, atk_test_document_get_attribute_value, teardown_document_test);
99   g_test_add_vtable (ATK_TEST_PATH_ACCESSIBLE "/atk_test_document_get_attributes",
100                      0, NULL, NULL, atk_test_document_get_attributes, teardown_document_test );
101 }