1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
24 static gboolean test_relation (void);
25 static gboolean test_role (void);
30 AtkRelationType type1, type2;
31 G_CONST_RETURN gchar *name;
35 AtkRelation *relation;
39 name = atk_relation_type_get_name (ATK_RELATION_LABEL_FOR);
40 g_return_val_if_fail (name, FALSE);
41 if (strcmp (name, "label-for") != 0)
43 g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
47 name = atk_relation_type_get_name (ATK_RELATION_NODE_CHILD_OF);
48 g_return_val_if_fail (name, FALSE);
49 if (strcmp (name, "node-child-of") != 0)
51 g_print ("Unexpected name for ATK_RELATION_NODE_CHILD_OF %s\n", name);
55 name = atk_relation_type_get_name (ATK_RELATION_EMBEDS);
56 g_return_val_if_fail (name, FALSE);
57 if (strcmp (name, "embeds") != 0)
59 g_print ("Unexpected name for ATK_RELATION_EMBEDS %s\n", name);
63 type1 = atk_relation_type_for_name ("embedded-by");
64 if (type1 != ATK_RELATION_EMBEDDED_BY)
66 g_print ("Unexpected role for ATK_RELATION_EMBEDDED_BY\n");
70 type1 = atk_relation_type_for_name ("controlled-by");
71 if (type1 != ATK_RELATION_CONTROLLED_BY)
73 g_print ("Unexpected name for ATK_RELATION_CONTROLLED_BY\n");
77 type1 = atk_relation_type_register ("test-state");
78 name = atk_relation_type_get_name (type1);
79 g_return_val_if_fail (name, FALSE);
80 if (strcmp (name, "test-state") != 0)
82 g_print ("Unexpected name for test-state %s\n", name);
85 type2 = atk_relation_type_for_name ("test-state");
88 g_print ("Unexpected type for test-state\n");
91 type2 = atk_relation_type_for_name ("TEST_STATE");
94 g_print ("Unexpected type for TEST_STATE\n");
98 * Check that a non-existent type returns NULL
100 name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
103 g_print ("Unexpected name for undefined type %s\n", name);
107 obj = g_object_new (ATK_TYPE_OBJECT, NULL);
108 ret_value = atk_object_add_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
111 g_print ("Unexpected return value for atk_object_add_relationship\n");
114 set = atk_object_ref_relation_set (obj);
117 g_print ("Unexpected return value for atk_object_ref_relation_set\n");
120 n_relations = atk_relation_set_get_n_relations (set);
121 if (n_relations != 1)
123 g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 1);
126 relation = atk_relation_set_get_relation (set, 0);
129 g_print ("Unexpected return value for atk_object_relation_set_get_relation\n");
132 type1 = atk_relation_get_relation_type (relation);
133 if (type1 != ATK_RELATION_LABEL_FOR)
135 g_print ("Unexpected return value for atk_relation_get_relation_type\n");
138 array = atk_relation_get_target (relation);
139 if (obj != g_ptr_array_index (array, 0))
141 g_print ("Unexpected return value for atk_relation_get_target\n");
144 g_object_unref (set);
145 ret_value = atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
148 g_print ("Unexpected return value for atk_object_remove_relationship\n");
151 set = atk_object_ref_relation_set (obj);
154 g_print ("Unexpected return value for atk_object_ref_relation_set\n");
157 n_relations = atk_relation_set_get_n_relations (set);
158 if (n_relations != 0)
160 g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 0);
163 g_object_unref (set);
164 g_object_unref (obj);
171 AtkRole role1, role2;
172 G_CONST_RETURN gchar *name;
174 name = atk_role_get_name (ATK_ROLE_PAGE_TAB);
175 g_return_val_if_fail (name, FALSE);
176 if (strcmp (name, "page-tab") != 0)
178 g_print ("Unexpected name for ATK_ROLE_PAGE_TAB %s\n", name);
182 name = atk_role_get_name (ATK_ROLE_LAYERED_PANE);
183 g_return_val_if_fail (name, FALSE);
184 if (strcmp (name, "layered-pane") != 0)
186 g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE %s\n", name);
190 role1 = atk_role_for_name ("list-item");
191 if (role1 != ATK_ROLE_LIST_ITEM)
193 g_print ("Unexpected role for list-item\n");
197 role1 = atk_role_register ("test-role");
198 name = atk_role_get_name (role1);
199 g_return_val_if_fail (name, FALSE);
200 if (strcmp (name, "test-role") != 0)
202 g_print ("Unexpected name for test-role %s\n", name);
205 role2 = atk_role_for_name ("test-role");
208 g_print ("Unexpected role for test-role\n");
211 role2 = atk_role_for_name ("TEST_ROLE");
214 g_print ("Unexpected role for TEST_ROLE\n");
218 * Check that a non-existent role returns NULL
220 name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
223 g_print ("Unexpected name for undefined role %s\n", name);
230 test_text_attr (void)
232 AtkTextAttribute attr1, attr2;
233 G_CONST_RETURN gchar *name;
235 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
236 g_return_val_if_fail (name, FALSE);
237 if (strcmp (name, "pixels-inside-wrap") != 0)
239 g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
243 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
244 g_return_val_if_fail (name, FALSE);
245 if (strcmp (name, "bg-stipple") != 0)
247 g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
251 attr1 = atk_text_attribute_for_name ("left-margin");
252 if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
254 g_print ("Unexpected attribute for left-margin\n");
258 attr1 = atk_text_attribute_register ("test-attribute");
259 name = atk_text_attribute_get_name (attr1);
260 g_return_val_if_fail (name, FALSE);
261 if (strcmp (name, "test-attribute") != 0)
263 g_print ("Unexpected name for test-attribute %s\n", name);
266 attr2 = atk_text_attribute_for_name ("test-attribute");
269 g_print ("Unexpected attribute for test-attribute\n");
272 attr2 = atk_text_attribute_for_name ("TEST_ATTR");
275 g_print ("Unexpected attribute for TEST_ATTR\n");
279 * Check that a non-existent attribute returns NULL
281 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
284 g_print ("Unexpected name for undefined attribute %s\n", name);
291 gtk_module_init (gint argc,
296 g_print("Relation test module loaded\n");
298 b_ret = test_relation ();
300 g_print ("Relation tests succeeded\n");
302 g_print ("Relation tests failed\n");
303 b_ret = test_role ();
305 g_print ("Role tests succeeded\n");
307 g_print ("Role tests failed\n");
308 b_ret = test_text_attr ();
310 g_print ("Text Attribute tests succeeded\n");
312 g_print ("Text Attribute tests failed\n");