Merge branch 'improve-documentation' into 'master'
[atk.git] / tests / testrelation.c
blob6cc0be5edcd3df9f4f49f13e009d641c409a7cca
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
25 test_relation (void)
27 AtkRelationType type1, type2;
28 const gchar *name;
29 AtkObject *obj;
30 gboolean ret_value;
31 AtkRelationSet *set;
32 AtkRelation *relation;
33 gint n_relations;
34 GPtrArray *array;
36 name = atk_relation_type_get_name (ATK_RELATION_LABEL_FOR);
37 g_return_val_if_fail (name, FALSE);
38 if (strcmp (name, "label-for") != 0)
40 g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
41 return FALSE;
44 name = atk_relation_type_get_name (ATK_RELATION_NODE_CHILD_OF);
45 g_return_val_if_fail (name, FALSE);
46 if (strcmp (name, "node-child-of") != 0)
48 g_print ("Unexpected name for ATK_RELATION_NODE_CHILD_OF %s\n", name);
49 return FALSE;
52 name = atk_relation_type_get_name (ATK_RELATION_EMBEDS);
53 g_return_val_if_fail (name, FALSE);
54 if (strcmp (name, "embeds") != 0)
56 g_print ("Unexpected name for ATK_RELATION_EMBEDS %s\n", name);
57 return FALSE;
60 type1 = atk_relation_type_for_name ("embedded-by");
61 if (type1 != ATK_RELATION_EMBEDDED_BY)
63 g_print ("Unexpected role for ATK_RELATION_EMBEDDED_BY\n");
64 return FALSE;
67 type1 = atk_relation_type_for_name ("controlled-by");
68 if (type1 != ATK_RELATION_CONTROLLED_BY)
70 g_print ("Unexpected name for ATK_RELATION_CONTROLLED_BY\n");
71 return FALSE;
74 type1 = atk_relation_type_register ("test-state");
75 name = atk_relation_type_get_name (type1);
76 g_return_val_if_fail (name, FALSE);
77 if (strcmp (name, "test-state") != 0)
79 g_print ("Unexpected name for test-state %s\n", name);
80 return FALSE;
82 type2 = atk_relation_type_for_name ("test-state");
83 if (type1 != type2)
85 g_print ("Unexpected type for test-state\n");
86 return FALSE;
88 type2 = atk_relation_type_for_name ("TEST_STATE");
89 if (type2 != 0)
91 g_print ("Unexpected type for TEST_STATE\n");
92 return FALSE;
95 * Check that a non-existent type returns NULL
97 name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
98 if (name)
100 g_print ("Unexpected name for undefined type %s\n", name);
101 return FALSE;
104 obj = g_object_new (ATK_TYPE_OBJECT, NULL);
105 ret_value = atk_object_add_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
106 if (!ret_value)
108 g_print ("Unexpected return value for atk_object_add_relationship\n");
109 return FALSE;
111 set = atk_object_ref_relation_set (obj);
112 if (!set)
114 g_print ("Unexpected return value for atk_object_ref_relation_set\n");
115 return FALSE;
117 n_relations = atk_relation_set_get_n_relations (set);
118 if (n_relations != 1)
120 g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 1);
121 return FALSE;
123 relation = atk_relation_set_get_relation (set, 0);
124 if (!relation)
126 g_print ("Unexpected return value for atk_object_relation_set_get_relation\n");
127 return FALSE;
129 type1 = atk_relation_get_relation_type (relation);
130 if (type1 != ATK_RELATION_LABEL_FOR)
132 g_print ("Unexpected return value for atk_relation_get_relation_type\n");
133 return FALSE;
135 array = atk_relation_get_target (relation);
136 if (obj != g_ptr_array_index (array, 0))
138 g_print ("Unexpected return value for atk_relation_get_target\n");
139 return FALSE;
141 g_object_unref (set);
142 ret_value = atk_object_remove_relationship (obj, ATK_RELATION_LABEL_FOR, obj);
143 if (!ret_value)
145 g_print ("Unexpected return value for atk_object_remove_relationship\n");
146 return FALSE;
148 set = atk_object_ref_relation_set (obj);
149 if (!set)
151 g_print ("Unexpected return value for atk_object_ref_relation_set\n");
152 return FALSE;
154 n_relations = atk_relation_set_get_n_relations (set);
155 if (n_relations != 0)
157 g_print ("Unexpected return value (%d) for atk_relation_set_get_n_relations expected value: %d\n", n_relations, 0);
158 return FALSE;
160 g_object_unref (set);
161 g_object_unref (obj);
162 return TRUE;
165 static gboolean
166 test_text_attr (void)
168 AtkTextAttribute attr1, attr2;
169 const gchar *name;
171 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
172 g_return_val_if_fail (name, FALSE);
173 if (strcmp (name, "pixels-inside-wrap") != 0)
175 g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
176 return FALSE;
179 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
180 g_return_val_if_fail (name, FALSE);
181 if (strcmp (name, "bg-stipple") != 0)
183 g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
184 return FALSE;
187 attr1 = atk_text_attribute_for_name ("left-margin");
188 if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
190 g_print ("Unexpected attribute for left-margin\n");
191 return FALSE;
194 attr1 = atk_text_attribute_register ("test-attribute");
195 name = atk_text_attribute_get_name (attr1);
196 g_return_val_if_fail (name, FALSE);
197 if (strcmp (name, "test-attribute") != 0)
199 g_print ("Unexpected name for test-attribute %s\n", name);
200 return FALSE;
202 attr2 = atk_text_attribute_for_name ("test-attribute");
203 if (attr1 != attr2)
205 g_print ("Unexpected attribute for test-attribute\n");
206 return FALSE;
208 attr2 = atk_text_attribute_for_name ("TEST_ATTR");
209 if (attr2 != 0)
211 g_print ("Unexpected attribute for TEST_ATTR\n");
212 return FALSE;
215 * Check that a non-existent attribute returns NULL
217 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
218 if (name)
220 g_print ("Unexpected name for undefined attribute %s\n", name);
221 return FALSE;
223 return TRUE;
227 main (gint argc,
228 char* argv[])
230 gboolean b_ret;
232 g_print("Starting Relation test suite\n");
234 b_ret = test_relation ();
235 if (b_ret)
236 g_print ("Relation tests succeeded\n");
237 else
238 g_print ("Relation tests failed\n");
240 b_ret = test_text_attr ();
241 if (b_ret)
242 g_print ("Text Attribute tests succeeded\n");
243 else
244 g_print ("Text Attribute tests failed\n");
246 return 0;