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 type1 = atk_relation_type_for_name ("controlled-by");
56 if (type1 != ATK_RELATION_CONTROLLED_BY)
58 g_print ("Unexpected type for focused\n");
62 type1 = atk_relation_type_register ("test-state");
63 name = atk_relation_type_get_name (type1);
64 g_return_val_if_fail (name, FALSE);
65 if (strcmp (name, "test-state") != 0)
67 g_print ("Unexpected name for test-state %s\n", name);
70 type2 = atk_relation_type_for_name ("test-state");
73 g_print ("Unexpected type for test-state\n");
76 type2 = atk_relation_type_for_name ("TEST_STATE");
79 g_print ("Unexpected type for TEST_STATE\n");
83 * Check that a non-existent type returns NULL
85 name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
88 g_print ("Unexpected name for undefined type %s\n", name);
92 obj = g_object_new (ATK_TYPE_OBJECT, NULL);
93 ret_value = atk_object_add_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
96 g_print ("Unexpected return value for atk_object_add_relationship\n");
99 set = atk_object_ref_relation_set (obj);
102 g_print ("Unexpected return value for atk_object_ref_relation_set\n");
105 n_relations = atk_relation_set_get_n_relations (set);
106 if (n_relations != 1)
108 g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 1);
111 relation = atk_relation_set_get_relation (set, 0);
114 g_print ("Unexpected return value for atk_object_relation_set_get_relation\n");
117 type1 = atk_relation_get_relation_type (relation);
118 if (type1 != ATK_RELATION_LABEL_FOR)
120 g_print ("Unexpected return value for atk_relation_get_relation_type\n");
123 array = atk_relation_get_target (relation);
124 if (obj != g_ptr_array_index (array, 0))
126 g_print ("Unexpected return value for atk_relation_get_target\n");
129 g_object_unref (set);
130 ret_value = atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
133 g_print ("Unexpected return value for atk_object_remove_relationship\n");
136 set = atk_object_ref_relation_set (obj);
139 g_print ("Unexpected return value for atk_object_ref_relation_set\n");
142 n_relations = atk_relation_set_get_n_relations (set);
143 if (n_relations != 0)
145 g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 0);
148 g_object_unref (set);
149 g_object_unref (obj);
156 AtkRole role1, role2;
157 G_CONST_RETURN gchar *name;
159 name = atk_role_get_name (ATK_ROLE_PAGE_TAB);
160 g_return_val_if_fail (name, FALSE);
161 if (strcmp (name, "page-tab") != 0)
163 g_print ("Unexpected name for ATK_ROLE_PAGE_TAB %s\n", name);
167 name = atk_role_get_name (ATK_ROLE_LAYERED_PANE);
168 g_return_val_if_fail (name, FALSE);
169 if (strcmp (name, "layered-pane") != 0)
171 g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE %s\n", name);
175 role1 = atk_role_for_name ("list-item");
176 if (role1 != ATK_ROLE_LIST_ITEM)
178 g_print ("Unexpected role for list-item\n");
182 role1 = atk_role_register ("test-role");
183 name = atk_role_get_name (role1);
184 g_return_val_if_fail (name, FALSE);
185 if (strcmp (name, "test-role") != 0)
187 g_print ("Unexpected name for test-role %s\n", name);
190 role2 = atk_role_for_name ("test-role");
193 g_print ("Unexpected role for test-role\n");
196 role2 = atk_role_for_name ("TEST_ROLE");
199 g_print ("Unexpected role for TEST_ROLE\n");
203 * Check that a non-existent role returns NULL
205 name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
208 g_print ("Unexpected name for undefined role %s\n", name);
215 test_text_attr (void)
217 AtkTextAttribute attr1, attr2;
218 G_CONST_RETURN gchar *name;
220 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
221 g_return_val_if_fail (name, FALSE);
222 if (strcmp (name, "pixels-inside-wrap") != 0)
224 g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
228 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
229 g_return_val_if_fail (name, FALSE);
230 if (strcmp (name, "bg-stipple") != 0)
232 g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
236 attr1 = atk_text_attribute_for_name ("left-margin");
237 if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
239 g_print ("Unexpected attribute for left-margin\n");
243 attr1 = atk_text_attribute_register ("test-attribute");
244 name = atk_text_attribute_get_name (attr1);
245 g_return_val_if_fail (name, FALSE);
246 if (strcmp (name, "test-attribute") != 0)
248 g_print ("Unexpected name for test-attribute %s\n", name);
251 attr2 = atk_text_attribute_for_name ("test-attribute");
254 g_print ("Unexpected attribute for test-attribute\n");
257 attr2 = atk_text_attribute_for_name ("TEST_ATTR");
260 g_print ("Unexpected attribute for TEST_ATTR\n");
264 * Check that a non-existent attribute returns NULL
266 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
269 g_print ("Unexpected name for undefined attribute %s\n", name);
276 gtk_module_init (gint argc,
281 g_print("Relation test module loaded\n");
283 b_ret = test_relation ();
285 g_print ("Relation tests succeeded\n");
287 g_print ("Relation tests failed\n");
288 b_ret = test_role ();
290 g_print ("Role tests succeeded\n");
292 g_print ("Role tests failed\n");
293 b_ret = test_text_attr ();
295 g_print ("Text Attribute tests succeeded\n");
297 g_print ("Text Attribute tests failed\n");