hu Mar 28 18:27:32 2002 Owen Taylor <otaylor@redhat.com>
[atk.git] / tests / testrelation.c
blob806e48a60c674de786f9341f07ed8c292bdb9be6
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 G_CONST_RETURN gchar *name;
33 name = atk_relation_type_get_name (ATK_RELATION_LABEL_FOR);
34 g_return_val_if_fail (name, FALSE);
35 if (strcmp (name, "label-for") != 0)
37 g_print ("Unexpected name for ATK_RELATION_LABEL_FOR %s\n", name);
38 return FALSE;
41 name = atk_relation_type_get_name (ATK_RELATION_NODE_CHILD_OF);
42 g_return_val_if_fail (name, FALSE);
43 if (strcmp (name, "node-child-of") != 0)
45 g_print ("Unexpected name for ATK_RELATION_NODE_CHILD_OF %s\n", name);
46 return FALSE;
49 type1 = atk_relation_type_for_name ("controlled-by");
50 if (type1 != ATK_RELATION_CONTROLLED_BY)
52 g_print ("Unexpected type for focused\n");
53 return FALSE;
56 type1 = atk_relation_type_register ("test-state");
57 name = atk_relation_type_get_name (type1);
58 g_return_val_if_fail (name, FALSE);
59 if (strcmp (name, "test-state") != 0)
61 g_print ("Unexpected name for test-state %s\n", name);
62 return FALSE;
64 type2 = atk_relation_type_for_name ("test-state");
65 if (type1 != type2)
67 g_print ("Unexpected type for test-state\n");
68 return FALSE;
70 type2 = atk_relation_type_for_name ("TEST_STATE");
71 if (type2 != 0)
73 g_print ("Unexpected type for TEST_STATE\n");
74 return FALSE;
77 * Check that a non-existent type returns NULL
79 name = atk_relation_type_get_name (ATK_RELATION_LAST_DEFINED + 2);
80 if (name)
82 g_print ("Unexpected name for undefined type %s\n", name);
83 return FALSE;
85 return TRUE;
88 static gboolean
89 test_role (void)
91 AtkRole role1, role2;
92 G_CONST_RETURN gchar *name;
94 name = atk_role_get_name (ATK_ROLE_PAGE_TAB);
95 g_return_val_if_fail (name, FALSE);
96 if (strcmp (name, "page-tab") != 0)
98 g_print ("Unexpected name for ATK_ROLE_PAGE_TAB %s\n", name);
99 return FALSE;
102 name = atk_role_get_name (ATK_ROLE_LAYERED_PANE);
103 g_return_val_if_fail (name, FALSE);
104 if (strcmp (name, "layered-pane") != 0)
106 g_print ("Unexpected name for ATK_ROLE_LAYERED_PANE %s\n", name);
107 return FALSE;
110 role1 = atk_role_for_name ("list-item");
111 if (role1 != ATK_ROLE_LIST_ITEM)
113 g_print ("Unexpected role for list-item\n");
114 return FALSE;
117 role1 = atk_role_register ("test-role");
118 name = atk_role_get_name (role1);
119 g_return_val_if_fail (name, FALSE);
120 if (strcmp (name, "test-role") != 0)
122 g_print ("Unexpected name for test-role %s\n", name);
123 return FALSE;
125 role2 = atk_role_for_name ("test-role");
126 if (role1 != role2)
128 g_print ("Unexpected role for test-role\n");
129 return FALSE;
131 role2 = atk_role_for_name ("TEST_ROLE");
132 if (role2 != 0)
134 g_print ("Unexpected role for TEST_ROLE\n");
135 return FALSE;
138 * Check that a non-existent role returns NULL
140 name = atk_role_get_name (ATK_ROLE_LAST_DEFINED + 2);
141 if (name)
143 g_print ("Unexpected name for undefined role %s\n", name);
144 return FALSE;
146 return TRUE;
149 static gboolean
150 test_text_attr (void)
152 AtkTextAttribute attr1, attr2;
153 G_CONST_RETURN gchar *name;
155 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
156 g_return_val_if_fail (name, FALSE);
157 if (strcmp (name, "pixels-inside-wrap") != 0)
159 g_print ("Unexpected name for ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP %s\n", name);
160 return FALSE;
163 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_BG_STIPPLE);
164 g_return_val_if_fail (name, FALSE);
165 if (strcmp (name, "bg-stipple") != 0)
167 g_print ("Unexpected name for ATK_TEXT_ATTR_BG_STIPPLE %s\n", name);
168 return FALSE;
171 attr1 = atk_text_attribute_for_name ("left-margin");
172 if (attr1 != ATK_TEXT_ATTR_LEFT_MARGIN)
174 g_print ("Unexpected attribute for left-margin\n");
175 return FALSE;
178 attr1 = atk_text_attribute_register ("test-attribute");
179 name = atk_text_attribute_get_name (attr1);
180 g_return_val_if_fail (name, FALSE);
181 if (strcmp (name, "test-attribute") != 0)
183 g_print ("Unexpected name for test-attribute %s\n", name);
184 return FALSE;
186 attr2 = atk_text_attribute_for_name ("test-attribute");
187 if (attr1 != attr2)
189 g_print ("Unexpected attribute for test-attribute\n");
190 return FALSE;
192 attr2 = atk_text_attribute_for_name ("TEST_ATTR");
193 if (attr2 != 0)
195 g_print ("Unexpected attribute for TEST_ATTR\n");
196 return FALSE;
199 * Check that a non-existent attribute returns NULL
201 name = atk_text_attribute_get_name (ATK_TEXT_ATTR_LAST_DEFINED + 2);
202 if (name)
204 g_print ("Unexpected name for undefined attribute %s\n", name);
205 return FALSE;
207 return TRUE;
211 gtk_module_init (gint argc,
212 char* argv[])
214 gboolean b_ret;
216 g_print("Relation test module loaded\n");
218 b_ret = test_relation ();
219 if (b_ret)
220 g_print ("Relation tests succeeded\n");
221 else
222 g_print ("Relation tests failed\n");
223 b_ret = test_role ();
224 if (b_ret)
225 g_print ("Role tests succeeded\n");
226 else
227 g_print ("Role tests failed\n");
228 b_ret = test_text_attr ();
229 if (b_ret)
230 g_print ("Text Attribute tests succeeded\n");
231 else
232 g_print ("Text Attribute tests failed\n");
233 return 0;