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 Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 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
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the
19
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
 * Boston, MA 02110-1301, 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
1
atk_test_action_sample_get_interface (TestAppFixture *fixture, gconstpointer user_data)
30
{
31
1
  AtspiAccessible *obj = fixture->root_obj;
32
1
  check_name (obj, "root_object");
33
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
34
1
  AtspiAction *iface = atspi_accessible_get_action_iface (child);
35
1
  g_assert_nonnull (iface);
36
1
  g_object_unref (iface);
37
1
  g_object_unref (child);
38
1
}
39

            
40
static void
41
1
atk_test_action_get_action_description (TestAppFixture *fixture, gconstpointer user_data)
42
{
43
1
  AtspiAccessible *obj = fixture->root_obj;
44
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
45
1
  AtspiAction *action = atspi_accessible_get_action_iface (child);
46
1
  gchar *str = atspi_action_get_action_description (action, 0, NULL);
47
1
  g_assert_cmpstr (str, ==, "action1 description");
48
1
  g_free (str);
49
1
  g_object_unref (action);
50
1
  g_object_unref (child);
51
1
}
52

            
53
static void
54
1
atk_test_action_get_action_name (TestAppFixture *fixture, gconstpointer user_data)
55
{
56
1
  AtspiAccessible *obj = fixture->root_obj;
57
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
58
1
  AtspiAction *action = atspi_accessible_get_action_iface (child);
59
1
  gchar *str = atspi_action_get_action_name (action, 0, NULL);
60
1
  g_assert_cmpstr (str, ==, "action1");
61
1
  g_free (str);
62
1
  g_object_unref (action);
63
1
  g_object_unref (child);
64
1
}
65

            
66
static void
67
1
atk_test_action_get_n_actions (TestAppFixture *fixture, gconstpointer user_data)
68
{
69
1
  AtspiAccessible *obj = fixture->root_obj;
70
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
71
1
  AtspiAction *action = atspi_accessible_get_action_iface (child);
72
1
  g_assert_cmpint (atspi_action_get_n_actions (action, NULL), ==, 2);
73
1
  g_object_unref (action);
74
1
  g_object_unref (child);
75
1
}
76

            
77
static void
78
1
atk_test_action_get_key_binding (TestAppFixture *fixture, gconstpointer user_data)
79
{
80
1
  AtspiAccessible *obj = fixture->root_obj;
81
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
82
1
  AtspiAction *action = atspi_accessible_get_action_iface (child);
83
1
  gchar *str = atspi_action_get_key_binding (action, 0, NULL);
84
1
  g_assert_cmpstr (str, ==, "action1 key binding");
85
1
  g_free (str);
86
1
  g_object_unref (action);
87
1
  g_object_unref (child);
88
1
}
89

            
90
static void
91
1
atk_test_action_get_localized_name (TestAppFixture *fixture, gconstpointer user_data)
92
{
93
1
  AtspiAccessible *obj = fixture->root_obj;
94
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
95
1
  AtspiAction *action = atspi_accessible_get_action_iface (child);
96
1
  gchar *str = atspi_action_get_localized_name (action, 0, NULL);
97
1
  g_assert_cmpstr (str, ==, "action1");
98
1
  g_free (str);
99
1
  g_object_unref (action);
100
1
  g_object_unref (child);
101
1
}
102

            
103
static void
104
1
atk_test_action_do_action (TestAppFixture *fixture, gconstpointer user_data)
105
{
106
1
  AtspiAccessible *obj = fixture->root_obj;
107
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
108
1
  AtspiAction *action = atspi_accessible_get_action_iface (child);
109
1
  g_assert_nonnull (action);
110
1
  atspi_action_do_action (action, 0, NULL);
111
1
  atspi_accessible_clear_cache (obj);
112
1
  AtspiStateSet *s = atspi_accessible_get_state_set (child);
113
1
  GArray *array = atspi_state_set_get_states (s);
114
1
  g_assert_cmpint (array->len, ==, 1);
115
1
  g_array_free (array, TRUE);
116
1
  g_object_unref (s);
117
1
  g_object_unref (action);
118
1
  g_object_unref (child);
119
1
}
120

            
121
void
122
1
atk_test_action (void)
123
{
124
1
  g_test_add ("/action/atk_test_action_sample_get_interface",
125
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_action_sample_get_interface, fixture_teardown);
126
1
  g_test_add ("/action/atk_test_action_get_action_description",
127
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_action_get_action_description, fixture_teardown);
128
1
  g_test_add ("/action/atk_test_action_get_action_name",
129
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_action_get_action_name, fixture_teardown);
130
1
  g_test_add ("/action/atk_test_action_get_n_actions",
131
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_action_get_n_actions, fixture_teardown);
132
1
  g_test_add ("/action/atk_test_action_get_key_binding",
133
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_action_get_key_binding, fixture_teardown);
134
1
  g_test_add ("/action/atk_test_action_get_localized_name",
135
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_action_get_localized_name, fixture_teardown);
136
1
  g_test_add ("/action/atk_test_action_do_action",
137
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_action_do_action, fixture_teardown);
138
1
}