fa79d1e5c3f692b0eac481c140ee9d7da07e2bdc
[platform/upstream/at-spi2-atk.git] / tests / atk_test_action.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
4  *
5  * Copyright (c) 2015 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-action.xml"
27
28 static void
29 teardown_action_test (gpointer fixture, gconstpointer user_data)
30 {
31   kill (child_pid, SIGTERM);
32 }
33
34 static void
35 atk_test_action_sample_get_interface (gpointer fixture, gconstpointer user_data)
36 {
37   AtspiAccessible *obj = get_root_obj (DATA_FILE);
38   g_assert_cmpstr (atspi_accessible_get_name (obj, NULL), ==, "root_object");
39   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL);
40   AtspiAction *iface = atspi_accessible_get_action_iface (child);
41   g_assert (iface != NULL);
42 }
43
44 static void
45 atk_test_action_get_action_description (gpointer fixture, gconstpointer user_data)
46 {
47   AtspiAccessible *obj = get_root_obj (DATA_FILE);
48   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL);
49   AtspiAction *action = atspi_accessible_get_action_iface (child);
50   g_assert_cmpstr (atspi_action_get_action_description (action, 0, NULL), == ,"action1 description");
51 }
52
53 static void
54 atk_test_action_get_action_name (gpointer fixture, gconstpointer user_data)
55 {
56   AtspiAccessible *obj = get_root_obj (DATA_FILE);
57   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL);
58   AtspiAction *action = atspi_accessible_get_action_iface (child);
59   g_assert_cmpstr (atspi_action_get_action_name (action, 0, NULL), == ,"action1");
60 }
61
62 static void
63 atk_test_action_get_n_actions (gpointer fixture, gconstpointer user_data)
64 {
65   AtspiAccessible *obj = get_root_obj (DATA_FILE);
66   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL);
67   AtspiAction *action = atspi_accessible_get_action_iface (child);
68   g_assert_cmpint (atspi_action_get_n_actions (action, NULL), == , 2);
69 }
70
71 static void
72 atk_test_action_get_key_binding (gpointer fixture, gconstpointer user_data)
73 {
74   AtspiAccessible *obj = get_root_obj (DATA_FILE);
75   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL);
76   AtspiAction *action = atspi_accessible_get_action_iface (child);
77   g_assert_cmpstr (atspi_action_get_key_binding (action, 0, NULL), == ,"action1 key binding");
78 }
79
80 static void
81 atk_test_action_get_localized_name (gpointer fixture, gconstpointer user_data)
82 {
83   AtspiAccessible *obj = get_root_obj (DATA_FILE);
84   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL);
85   AtspiAction *action = atspi_accessible_get_action_iface (child);
86   g_assert_cmpstr (atspi_action_get_localized_name (action, 0, NULL), == ,"action1");
87 }
88
89 static void
90 atk_test_action_do_action (gpointer fixture, gconstpointer user_data)
91 {
92   AtspiAccessible *obj = get_root_obj (DATA_FILE);
93   AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,1, NULL);
94   AtspiAction *action = atspi_accessible_get_action_iface (child);
95   g_assert (action != NULL);
96   atspi_action_do_action (action, 0, NULL);
97   atspi_accessible_clear_cache (obj);
98   AtspiStateSet *s = atspi_accessible_get_state_set (child);
99   GArray *array = atspi_state_set_get_states (s);
100   g_assert_cmpint (array->len, ==, 1);
101 }
102
103 void
104 atk_test_action (void)
105 {
106   g_test_add_vtable (ATK_TEST_PATH_ACTION "/atk_test_action_sample_get_interface",
107                      0, NULL, NULL, atk_test_action_sample_get_interface, teardown_action_test);
108   g_test_add_vtable (ATK_TEST_PATH_ACTION "/atk_test_action_get_action_description",
109                      0, NULL, NULL, atk_test_action_get_action_description, teardown_action_test);
110   g_test_add_vtable (ATK_TEST_PATH_ACTION "/atk_test_action_get_action_name",
111                      0, NULL, NULL, atk_test_action_get_action_name, teardown_action_test);
112   g_test_add_vtable (ATK_TEST_PATH_ACTION "/atk_test_action_get_n_actions",
113                      0, NULL, NULL, atk_test_action_get_n_actions, teardown_action_test);
114   g_test_add_vtable (ATK_TEST_PATH_ACTION "/atk_test_action_get_key_binding",
115                      0, NULL, NULL, atk_test_action_get_key_binding, teardown_action_test);
116   g_test_add_vtable (ATK_TEST_PATH_ACTION "/atk_test_action_get_localized_name",
117                      0, NULL, NULL, atk_test_action_get_localized_name, teardown_action_test);
118   g_test_add_vtable (ATK_TEST_PATH_ACTION "/atk_test_action_do_action",
119                      0, NULL, NULL, atk_test_action_do_action, teardown_action_test);
120 }