1
/*
2
 * AT-SPI - Assistive Service Provider Interface
3
 * (Gnome AccessibiliTestAppFixture, DATA_FILE, fixture_setup://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 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-document.xml"
27

            
28
static void
29
1
atk_test_document_get_document_iface (TestAppFixture *fixture, gconstpointer user_data)
30
{
31
1
  AtspiAccessible *obj = fixture->root_obj;
32
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
33
1
  AtspiDocument *iface = atspi_accessible_get_document_iface (child);
34
1
  g_assert_nonnull (iface);
35
1
  g_object_unref (iface);
36
1
  g_object_unref (child);
37
1
}
38

            
39
static void
40
1
atk_test_document_get_locale (TestAppFixture *fixture, gconstpointer user_data)
41
{
42
1
  AtspiAccessible *obj = fixture->root_obj;
43
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
44
1
  AtspiDocument *iface = atspi_accessible_get_document_iface (child);
45
1
  g_assert_nonnull (iface);
46

            
47
1
  gchar *str = atspi_document_get_locale (iface, NULL);
48
1
  g_assert_cmpstr (str, ==, "document_locale");
49
1
  g_free (str);
50
1
  g_object_unref (iface);
51
1
  g_object_unref (child);
52
1
}
53

            
54
static void
55
1
atk_test_document_get_attribute_value (TestAppFixture *fixture, gconstpointer user_data)
56
{
57
1
  AtspiAccessible *obj = fixture->root_obj;
58
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
59
1
  AtspiDocument *iface = atspi_accessible_get_document_iface (child);
60
  gchar *str;
61
1
  g_assert_nonnull (iface);
62

            
63
1
  str = atspi_document_get_document_attribute_value (iface, "atspi1", NULL);
64
1
  g_assert_cmpstr (str, ==, "test1");
65
1
  g_free (str);
66
1
  str = atspi_document_get_document_attribute_value (iface, "atspi2", NULL);
67
1
  g_assert_cmpstr (str, ==, "test2");
68
1
  g_free (str);
69
1
  g_object_unref (iface);
70
1
  g_object_unref (child);
71
1
}
72

            
73
static void
74
1
atk_test_document_get_attributes (TestAppFixture *fixture, gconstpointer user_data)
75
{
76
1
  AtspiAccessible *obj = fixture->root_obj;
77
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
78
1
  AtspiDocument *iface = atspi_accessible_get_document_iface (child);
79
1
  g_assert_nonnull (iface);
80

            
81
1
  GHashTable *attr = atspi_document_get_document_attributes (iface, NULL);
82
  GHashTableIter iter;
83
  gpointer key, value;
84
1
  g_hash_table_iter_init (&iter, attr);
85

            
86
3
  while (g_hash_table_iter_next (&iter, &key, &value))
87
    {
88
2
      const char *key_str = key;
89
2
      const char *value_str = value;
90

            
91
2
      if (strcmp (key_str, "atspi1") == 0)
92
        {
93
1
          g_assert_cmpstr (value_str, ==, "test1");
94
        }
95
1
      else if (strcmp (key_str, "atspi2") == 0)
96
        {
97
1
          g_assert_cmpstr (value_str, ==, "test2");
98
        }
99
      else
100
        {
101
          g_assert_not_reached ();
102
        }
103
    }
104
1
  g_hash_table_unref (attr);
105
1
  g_object_unref (iface);
106
1
  g_object_unref (child);
107
1
}
108

            
109
static void
110
1
atk_test_document_text_selections (TestAppFixture *fixture, gconstpointer user_data)
111
{
112
1
  AtspiAccessible *obj = fixture->root_obj;
113
1
  AtspiAccessible *child = atspi_accessible_get_child_at_index (obj, 1, NULL);
114
1
  AtspiDocument *iface = atspi_accessible_get_document_iface (child);
115
  GArray *selections;
116
  AtspiTextSelection selection;
117

            
118
1
  g_assert_nonnull (iface);
119

            
120
1
  selections = atspi_document_get_text_selections (iface, NULL);
121
1
  g_assert_true (selections);
122
1
  g_assert_cmpint (selections->len, ==, 0);
123
1
  g_array_free (selections, TRUE);
124

            
125
1
  selections = g_array_new (FALSE, TRUE, sizeof (AtspiTextSelection));
126
1
  selection.start_object = obj;
127
1
  selection.start_offset = 0;
128
1
  selection.end_object = obj;
129
1
  selection.end_offset = 2;
130
1
  selection.start_is_active = TRUE;
131
1
  g_array_append_val (selections, selection);
132
1
  selection.start_offset = 3;
133
1
  selection.end_offset = 5;
134
1
  selection.start_is_active = FALSE;
135
1
  g_array_append_val (selections, selection);
136
1
  atspi_document_set_text_selections (iface, selections, NULL);
137
1
  g_array_free (selections, TRUE);
138

            
139
1
  selections = atspi_document_get_text_selections (iface, NULL);
140
1
  g_assert_true (selections);
141
1
  g_assert_cmpint (selections->len, ==, 2);
142
1
  selection = g_array_index (selections, AtspiTextSelection, 0);
143
1
  g_assert_true (selection.start_object == obj);
144
1
  g_assert_cmpint (selection.start_offset, ==, 0);
145
1
  g_assert_cmpint (selection.end_offset, ==, 2);
146
1
  g_assert_true (selection.start_is_active);
147
1
  selection = g_array_index (selections, AtspiTextSelection, 1);
148
1
  g_assert_true (selection.start_object == obj);
149
1
  g_assert_cmpint (selection.start_offset, ==, 3);
150
1
  g_assert_cmpint (selection.end_offset, ==, 5);
151
1
  g_assert_false (selection.start_is_active);
152
1
  g_array_free (selections, TRUE);
153

            
154
1
  g_object_unref (iface);
155
1
  g_object_unref (child);
156
1
}
157

            
158
void
159
1
atk_test_document (void)
160
{
161
1
  g_test_add ("/document/atk_test_document_get_document_iface",
162
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_document_get_document_iface, fixture_teardown);
163
1
  g_test_add ("/document/atk_test_document_get_locale",
164
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_document_get_locale, fixture_teardown);
165
1
  g_test_add ("/document/atk_test_document_get_attribute_value",
166
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_document_get_attribute_value, fixture_teardown);
167
1
  g_test_add ("/document/atk_test_document_get_attributes",
168
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_document_get_attributes, fixture_teardown);
169
1
  g_test_add ("/document/atk_test_document_text_selections",
170
              TestAppFixture, DATA_FILE, fixture_setup, atk_test_document_text_selections, fixture_teardown);
171
1
}