tests: Use const instead G_CONST_RETURN
[platform/upstream/atk.git] / tests / testrelation.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <atk/atk.h>
21
22 #include <string.h>
23
24 static gboolean  test_relation (void);
25 static gboolean  test_role (void);
26
27 static gboolean
28 test_relation (void)
29 {
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; 
38
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)
42     {
43       g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
44       return FALSE;
45     }
46
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)
50     {
51       g_print ("Unexpected name for ATK_RELATION_NODE_CHILD_OF %s\n", name);
52       return FALSE;
53     }
54
55   name = atk_relation_type_get_name (ATK_RELATION_EMBEDS);
56   g_return_val_if_fail (name, FALSE);
57   if (strcmp (name, "embeds") != 0)
58     {
59       g_print ("Unexpected name for ATK_RELATION_EMBEDS %s\n", name);
60       return FALSE;
61     }
62
63   type1 = atk_relation_type_for_name ("embedded-by");
64   if (type1 != ATK_RELATION_EMBEDDED_BY)
65     {
66       g_print ("Unexpected role for ATK_RELATION_EMBEDDED_BY\n");
67       return FALSE;
68     }
69
70   type1 = atk_relation_type_for_name ("controlled-by");
71   if (type1 != ATK_RELATION_CONTROLLED_BY)
72     {
73       g_print ("Unexpected name for ATK_RELATION_CONTROLLED_BY\n");
74       return FALSE;
75     }
76
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)
81     {
82       g_print ("Unexpected name for test-state %s\n", name);
83       return FALSE;
84     }
85   type2 = atk_relation_type_for_name ("test-state");
86   if (type1 != type2)
87   {
88     g_print ("Unexpected type for test-state\n");
89     return FALSE;
90   }
91   type2 = atk_relation_type_for_name ("TEST_STATE");
92   if (type2 != 0)
93     {
94       g_print ("Unexpected type for TEST_STATE\n");
95       return FALSE;
96     }
97   /*
98    * Check that a non-existent type returns NULL
99    */
100   name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
101   if (name)
102     {
103       g_print ("Unexpected name for undefined type %s\n", name);
104       return FALSE;
105     }
106
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)
110     {
111       g_print ("Unexpected return value for atk_object_add_relationship\n");
112       return FALSE;
113     }
114   set = atk_object_ref_relation_set (obj);
115   if (!set)
116     {
117       g_print ("Unexpected return value for atk_object_ref_relation_set\n");
118       return FALSE;
119     }
120   n_relations = atk_relation_set_get_n_relations (set);
121   if (n_relations != 1)
122     {
123       g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 1);
124       return FALSE;
125     }
126   relation = atk_relation_set_get_relation (set, 0);  
127   if (!relation)
128     {
129       g_print ("Unexpected return value for atk_object_relation_set_get_relation\n");
130       return FALSE;
131     }
132   type1 = atk_relation_get_relation_type (relation);
133   if (type1 != ATK_RELATION_LABEL_FOR)
134     {
135       g_print ("Unexpected return value for atk_relation_get_relation_type\n");
136       return FALSE;
137     }
138   array = atk_relation_get_target (relation);
139   if (obj != g_ptr_array_index (array, 0))
140     {
141       g_print ("Unexpected return value for atk_relation_get_target\n");
142       return FALSE;
143     }
144   g_object_unref (set);
145   ret_value = atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
146   if (!ret_value)
147     {
148       g_print ("Unexpected return value for atk_object_remove_relationship\n");
149       return FALSE;
150     }
151   set = atk_object_ref_relation_set (obj);
152   if (!set)
153     {
154       g_print ("Unexpected return value for atk_object_ref_relation_set\n");
155       return FALSE;
156     }
157   n_relations = atk_relation_set_get_n_relations (set);
158   if (n_relations != 0)
159     {
160       g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 0);
161       return FALSE;
162     }
163   g_object_unref (set);
164   g_object_unref (obj);
165   return TRUE;
166 }
167
168 static gboolean
169 test_role (void)
170 {
171   AtkRole role1, role2;
172   const gchar *name;
173
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)
177     {
178       g_print ("Unexpected name for ATK_ROLE_PAGE_TAB %s\n", name);
179       return FALSE;
180     }
181
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)
185     {
186       g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE %s\n", name);
187       return FALSE;
188     }
189
190   role1 = atk_role_for_name ("list-item");
191   if (role1 != ATK_ROLE_LIST_ITEM)
192     {
193       g_print ("Unexpected role for list-item\n");
194       return FALSE;
195     }
196
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)
201     {
202       g_print ("Unexpected name for test-role %s\n", name);
203       return FALSE;
204     }
205   role2 = atk_role_for_name ("test-role");
206   if (role1 != role2)
207   {
208     g_print ("Unexpected role for test-role\n");
209     return FALSE;
210   }
211   role2 = atk_role_for_name ("TEST_ROLE");
212   if (role2 != 0)
213     {
214       g_print ("Unexpected role for TEST_ROLE\n");
215       return FALSE;
216     }
217   /*
218    * Check that a non-existent role returns NULL
219    */
220   name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
221   if (name)
222     {
223       g_print ("Unexpected name for undefined role %s\n", name);
224       return FALSE;
225     }
226   return TRUE;
227 }
228
229 static gboolean
230 test_text_attr (void)
231 {
232   AtkTextAttribute attr1, attr2;
233   const gchar *name;
234
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)
238     {
239       g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
240       return FALSE;
241     }
242
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)
246     {
247       g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
248       return FALSE;
249     }
250
251   attr1 = atk_text_attribute_for_name ("left-margin");
252   if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
253     {
254       g_print ("Unexpected attribute for left-margin\n");
255       return FALSE;
256     }
257
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)
262     {
263       g_print ("Unexpected name for test-attribute %s\n", name);
264       return FALSE;
265     }
266   attr2 = atk_text_attribute_for_name ("test-attribute");
267   if (attr1 != attr2)
268   {
269     g_print ("Unexpected attribute for test-attribute\n");
270     return FALSE;
271   }
272   attr2 = atk_text_attribute_for_name ("TEST_ATTR");
273   if (attr2 != 0)
274     {
275       g_print ("Unexpected attribute for TEST_ATTR\n");
276       return FALSE;
277     }
278   /*
279    * Check that a non-existent attribute returns NULL
280    */
281   name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
282   if (name)
283     {
284       g_print ("Unexpected name for undefined attribute %s\n", name);
285       return FALSE;
286     }
287   return TRUE;
288 }
289
290 int
291 gtk_module_init (gint  argc, 
292                  char* argv[])
293 {
294   gboolean b_ret;
295
296   g_print("Relation test module loaded\n");
297
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;
314 }