tests: fix hyphenation on testrelation.c
[atk.git] / tests / testrelation.c
blob8111d888b3bdc99b7ce7d3ae166f8ba83a5d6461
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.
20 #include <atk/atk.h>
22 #include <string.h>
24 static gboolean test_relation (void);
25 static gboolean test_role (void);
27 static gboolean
28 test_relation (void)
30 AtkRelationType type1, type2;
31 const gchar *name;
32 AtkObject *obj;
33 gboolean ret_value;
34 AtkRelationSet *set;
35 AtkRelation *relation;
36 gint n_relations;
37 GPtrArray *array;
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);
44 return FALSE;
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);
52 return FALSE;
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);
60 return FALSE;
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");
67 return FALSE;
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");
74 return FALSE;
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);
83 return FALSE;
85 type2 = atk_relation_type_for_name ("test-state");
86 if (type1 != type2)
88 g_print ("Unexpected type for test-state\n");
89 return FALSE;
91 type2 = atk_relation_type_for_name ("TEST_STATE");
92 if (type2 != 0)
94 g_print ("Unexpected type for TEST_STATE\n");
95 return FALSE;
98 * Check that a non-existent type returns NULL
100 name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
101 if (name)
103 g_print ("Unexpected name for undefined type %s\n", name);
104 return FALSE;
107 obj = g_object_new (ATK_TYPE_OBJECT, NULL);
108 ret_value = atk_object_add_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
109 if (!ret_value)
111 g_print ("Unexpected return value for atk_object_add_relationship\n");
112 return FALSE;
114 set = atk_object_ref_relation_set (obj);
115 if (!set)
117 g_print ("Unexpected return value for atk_object_ref_relation_set\n");
118 return FALSE;
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);
124 return FALSE;
126 relation = atk_relation_set_get_relation (set, 0);
127 if (!relation)
129 g_print ("Unexpected return value for atk_object_relation_set_get_relation\n");
130 return FALSE;
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");
136 return FALSE;
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");
142 return FALSE;
144 g_object_unref (set);
145 ret_value = atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
146 if (!ret_value)
148 g_print ("Unexpected return value for atk_object_remove_relationship\n");
149 return FALSE;
151 set = atk_object_ref_relation_set (obj);
152 if (!set)
154 g_print ("Unexpected return value for atk_object_ref_relation_set\n");
155 return FALSE;
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);
161 return FALSE;
163 g_object_unref (set);
164 g_object_unref (obj);
165 return TRUE;
168 static gboolean
169 test_role (void)
171 AtkRole role1, role2;
172 const 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);
179 return FALSE;
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);
187 return FALSE;
190 role1 = atk_role_for_name ("list item");
191 if (role1 != ATK_ROLE_LIST_ITEM)
193 g_print ("Unexpected role for list item\n");
194 return FALSE;
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);
203 return FALSE;
205 role2 = atk_role_for_name ("test-role");
206 if (role1 != role2)
208 g_print ("Unexpected role for test-role\n");
209 return FALSE;
211 role2 = atk_role_for_name ("TEST_ROLE");
212 if (role2 != 0)
214 g_print ("Unexpected role for TEST_ROLE\n");
215 return FALSE;
218 * Check that a non-existent role returns NULL
220 name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
221 if (name)
223 g_print ("Unexpected name for undefined role %s\n", name);
224 return FALSE;
226 return TRUE;
229 static gboolean
230 test_text_attr (void)
232 AtkTextAttribute attr1, attr2;
233 const 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);
240 return FALSE;
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);
248 return FALSE;
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");
255 return FALSE;
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);
264 return FALSE;
266 attr2 = atk_text_attribute_for_name ("test-attribute");
267 if (attr1 != attr2)
269 g_print ("Unexpected attribute for test-attribute\n");
270 return FALSE;
272 attr2 = atk_text_attribute_for_name ("TEST_ATTR");
273 if (attr2 != 0)
275 g_print ("Unexpected attribute for TEST_ATTR\n");
276 return FALSE;
279 * Check that a non-existent attribute returns NULL
281 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
282 if (name)
284 g_print ("Unexpected name for undefined attribute %s\n", name);
285 return FALSE;
287 return TRUE;
291 gtk_module_init (gint argc,
292 char* argv[])
294 gboolean b_ret;
296 g_print("Relation test module loaded\n");
298 b_ret = test_relation ();
299 if (b_ret)
300 g_print ("Relation tests succeeded\n");
301 else
302 g_print ("Relation tests failed\n");
303 b_ret = test_role ();
304 if (b_ret)
305 g_print ("Role tests succeeded\n");
306 else
307 g_print ("Role tests failed\n");
308 b_ret = test_text_attr ();
309 if (b_ret)
310 g_print ("Text Attribute tests succeeded\n");
311 else
312 g_print ("Text Attribute tests failed\n");
313 return 0;