Added new roles to atkobject.h
[atk.git] / tests / teststateset.c
blob7132d29c1ec1b4b584062cfb85aae5e92f4a64f5
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 static gboolean test_state_set ();
23 static gboolean test_state ();
25 static gboolean
26 test_state_set ()
28 AtkStateSet *state_set1, *state_set2, *state_set3;
29 AtkStateType state_array[3];
30 gboolean b_val;
32 state_set1 = atk_state_set_new ();
34 b_val = atk_state_set_is_empty (state_set1);
35 if (b_val)
37 g_print ("New state set is not empty\n");
38 return FALSE;
41 b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
42 if (!b_val)
44 g_print ("Adding new state set failed\n");
45 return FALSE;
48 b_val = atk_state_set_is_empty (state_set1);
49 if (!b_val)
51 g_print ("New state set is empty when it should not be\n");
52 return FALSE;
55 b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
56 if (b_val)
58 g_print ("Adding new state set succeeded when it should not have\n");
59 return FALSE;
62 state_array[0] = ATK_STATE_ACTIVE;
63 state_array[1] = ATK_STATE_VISIBLE;
64 state_array[2] = ATK_STATE_BUSY;
65 atk_state_set_add_states (state_set1, state_array, 3);
67 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
68 if (!b_val)
70 g_print ("Contains state failed for ATK_STATE_ACTIVE but should not have\n");
71 return FALSE;
74 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
75 if (!b_val)
77 g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
78 return FALSE;
81 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
82 if (!b_val)
84 g_print ("Contains state failed for ATK_STATE_BUSY but should not have\n");
85 return FALSE;
88 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VERTICAL);
89 if (b_val)
91 g_print ("Contains state succeeded for ATK_STATE_VERTICAL but should not have\n");
92 return FALSE;
95 atk_state_set_remove_state (state_set1, ATK_STATE_BUSY);
96 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
97 if (b_val)
99 g_print ("Contains state succeeded for ATK_STATE_BUSY but should not have\n");
100 return FALSE;
102 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
103 if (!b_val)
105 g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
106 return FALSE;
109 b_val = atk_state_set_contains_states (state_set1, state_array, 3);
110 if (b_val)
112 g_print ("Contains states succeeded should not have\n");
113 return FALSE;
116 b_val = atk_state_set_contains_states (state_set1, state_array, 2);
117 if (!b_val)
119 g_print ("Contains states failed should not have\n");
120 return FALSE;
123 state_array[0] = ATK_STATE_SINGLE_LINE;
124 state_array[1] = ATK_STATE_VISIBLE;
125 state_array[2] = ATK_STATE_VERTICAL;
127 state_set2 = atk_state_set_new();
128 atk_state_set_add_states (state_set2, state_array, 3);
130 state_set3 = atk_state_set_and_sets (state_set1, state_set2);
131 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
132 if (!b_val)
134 g_print ("Contains state failed for ATK_STATE_VISIBLE after and but should not have\n");
135 return FALSE;
137 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_BUSY);
138 if (b_val)
140 g_print ("Contains state succeeded for ATK_STATE_BUSY after and but should not have\n");
141 return FALSE;
143 g_object_unref (state_set3);
145 atk_state_set_remove_state (state_set1, ATK_STATE_VISIBLE);
146 state_set3 = atk_state_set_and_sets (state_set1, state_set2);
147 if (state_set3)
149 g_print ("state_set 3 is not NULL after and but should be\n");
150 return FALSE;
153 state_set3 = atk_state_set_or_sets (state_set1, state_set2);
154 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
155 if (!b_val)
157 g_print ("Contains state failed for ATK_STATE_VISIBLE after or but should not have\n");
158 return FALSE;
161 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_INVALID);
162 if (b_val)
164 g_print ("Contains state succeeded for ATK_STATE_INVALID after or but should not have\n");
165 return FALSE;
167 g_object_unref (state_set3);
169 b_val = atk_state_set_add_state (state_set1, ATK_STATE_VISIBLE);
170 if (!b_val)
172 g_print ("Adding new state set failed\n");
173 return FALSE;
175 state_set3 = atk_state_set_xor_sets (state_set1, state_set2);
176 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
177 if (b_val)
179 g_print ("Contains state succeeded for ATK_STATE_VISIBLE after xor but should not have\n");
180 return FALSE;
183 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_ACTIVE);
184 if (!b_val)
186 g_print ("Contains state failed for ATK_STATE_ACTIVE after xor but should not have\n");
187 return FALSE;
190 atk_state_set_clear_states (state_set1);
191 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
192 if (b_val)
194 g_print ("Contains state succeeded for ATK_STATE_ACTIVE but should not have\n");
195 return FALSE;
198 g_object_unref (state_set1);
199 g_object_unref (state_set2);
200 g_object_unref (state_set3);
201 return TRUE;
205 static gboolean
206 test_state ()
208 AtkStateType type1, type2;
209 G_CONST_RETURN gchar *name;
211 name = atk_state_type_get_name (ATK_STATE_VISIBLE);
212 g_return_val_if_fail (name, FALSE);
213 if (strcmp (name, "visible") != 0)
215 g_print ("Unexpected name for ATK_STATE_VISIBLE %s\n", name);
216 return FALSE;
219 name = atk_state_type_get_name (ATK_STATE_MODAL);
220 g_return_val_if_fail (name, FALSE);
221 if (strcmp (name, "modal") != 0)
223 g_print ("Unexpected name for ATK_STATE_MODAL %s\n", name);
224 return FALSE;
227 type1 = atk_state_type_for_name ("focused");
228 if (type1 != ATK_STATE_FOCUSED)
230 g_print ("Unexpected type for focused\n");
231 return FALSE;
234 type1 = atk_state_type_register ("test_state");
235 name = atk_state_type_get_name (type1);
236 g_return_val_if_fail (name, FALSE);
237 if (strcmp (name, "test_state") != 0)
239 g_print ("Unexpected name for test_state %s\n", name);
240 return FALSE;
242 type2 = atk_state_type_for_name ("test_state");
243 g_return_val_if_fail (name, FALSE);
244 if (type1 != type2)
246 g_print ("Unexpected type for test_state\n");
247 return FALSE;
249 type2 = atk_state_type_for_name ("TEST-STATE");
250 if (type2 != 0)
252 g_print ("Unexpected type for TEST-STATE\n");
253 return FALSE;
256 * Check that a non-existent type returns NULL
258 name = atk_state_type_get_name (ATK_STATE_LAST_DEFINED +2);
259 if (name)
261 g_print ("Unexpected name for undefined type\n");
262 return FALSE;
264 return TRUE;
268 gtk_module_init (gint argc, char* argv[])
270 gboolean b_ret;
272 g_print("State Set test module loaded\n");
274 b_ret = test_state_set ();
275 if (b_ret)
277 g_print ("State Set tests succeeded\n");
279 else
281 g_print ("State Set tests failed\n");
283 b_ret = test_state ();
284 if (b_ret)
286 g_print ("State tests succeeded\n");
288 else
290 g_print ("State tests failed\n");
292 return 0;