Give CC to gir scanner
[atk.git] / tests / teststateset.c
bloba9a3a6c857f62098917f7db378be83218352d953
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_state_set (void);
25 static gboolean test_state (void);
27 static gboolean
28 test_state_set (void)
30 AtkStateSet *state_set1, *state_set2, *state_set3;
31 AtkStateType state_array[3];
32 gboolean b_val;
34 state_set1 = atk_state_set_new ();
36 b_val = atk_state_set_is_empty (state_set1);
37 if (!b_val)
39 g_print ("New state set is not empty\n");
40 return FALSE;
43 b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
44 if (!b_val)
46 g_print ("Adding new state set failed\n");
47 return FALSE;
50 b_val = atk_state_set_is_empty (state_set1);
51 if (b_val)
53 g_print ("New state set is empty when it should not be\n");
54 return FALSE;
57 b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
58 if (b_val)
60 g_print ("Adding new state set succeeded when it should not have\n");
61 return FALSE;
64 state_array[0] = ATK_STATE_ACTIVE;
65 state_array[1] = ATK_STATE_VISIBLE;
66 state_array[2] = ATK_STATE_BUSY;
67 atk_state_set_add_states (state_set1, state_array, 3);
69 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
70 if (!b_val)
72 g_print ("Contains state failed for ATK_STATE_ACTIVE but should not have\n");
73 return FALSE;
76 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
77 if (!b_val)
79 g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
80 return FALSE;
83 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
84 if (!b_val)
86 g_print ("Contains state failed for ATK_STATE_BUSY but should not have\n");
87 return FALSE;
90 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VERTICAL);
91 if (b_val)
93 g_print ("Contains state succeeded for ATK_STATE_VERTICAL but should not have\n");
94 return FALSE;
97 atk_state_set_remove_state (state_set1, ATK_STATE_BUSY);
98 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
99 if (b_val)
101 g_print ("Contains state succeeded for ATK_STATE_BUSY but should not have\n");
102 return FALSE;
104 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
105 if (!b_val)
107 g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
108 return FALSE;
111 b_val = atk_state_set_contains_states (state_set1, state_array, 3);
112 if (b_val)
114 g_print ("Contains states succeeded should not have\n");
115 return FALSE;
118 b_val = atk_state_set_contains_states (state_set1, state_array, 2);
119 if (!b_val)
121 g_print ("Contains states failed should not have\n");
122 return FALSE;
125 state_array[0] = ATK_STATE_SINGLE_LINE;
126 state_array[1] = ATK_STATE_VISIBLE;
127 state_array[2] = ATK_STATE_VERTICAL;
129 state_set2 = atk_state_set_new();
130 atk_state_set_add_states (state_set2, state_array, 3);
132 state_set3 = atk_state_set_and_sets (state_set1, state_set2);
133 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
134 if (!b_val)
136 g_print ("Contains state failed for ATK_STATE_VISIBLE after and but should not have\n");
137 return FALSE;
139 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_BUSY);
140 if (b_val)
142 g_print ("Contains state succeeded for ATK_STATE_BUSY after and but should not have\n");
143 return FALSE;
145 g_object_unref (state_set3);
147 atk_state_set_remove_state (state_set1, ATK_STATE_VISIBLE);
148 state_set3 = atk_state_set_and_sets (state_set1, state_set2);
149 if (state_set3)
151 g_print ("state_set 3 is not NULL after and but should be\n");
152 return FALSE;
155 state_set3 = atk_state_set_or_sets (state_set1, state_set2);
156 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
157 if (!b_val)
159 g_print ("Contains state failed for ATK_STATE_VISIBLE after or but should not have\n");
160 return FALSE;
163 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_INVALID);
164 if (b_val)
166 g_print ("Contains state succeeded for ATK_STATE_INVALID after or but should not have\n");
167 return FALSE;
169 g_object_unref (state_set3);
171 b_val = atk_state_set_add_state (state_set1, ATK_STATE_VISIBLE);
172 if (!b_val)
174 g_print ("Adding new state set failed\n");
175 return FALSE;
177 state_set3 = atk_state_set_xor_sets (state_set1, state_set2);
178 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
179 if (b_val)
181 g_print ("Contains state succeeded for ATK_STATE_VISIBLE after xor but should not have\n");
182 return FALSE;
185 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_ACTIVE);
186 if (!b_val)
188 g_print ("Contains state failed for ATK_STATE_ACTIVE after xor but should not have\n");
189 return FALSE;
192 atk_state_set_clear_states (state_set1);
193 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
194 if (b_val)
196 g_print ("Contains state succeeded for ATK_STATE_ACTIVE but should not have\n");
197 return FALSE;
200 g_object_unref (state_set1);
201 g_object_unref (state_set2);
202 g_object_unref (state_set3);
203 return TRUE;
207 static gboolean
208 test_state (void)
210 AtkStateType type1, type2;
211 const gchar *name;
213 name = atk_state_type_get_name (ATK_STATE_VISIBLE);
214 g_return_val_if_fail (name, FALSE);
215 if (strcmp (name, "visible") != 0)
217 g_print ("Unexpected name for ATK_STATE_VISIBLE %s\n", name);
218 return FALSE;
221 name = atk_state_type_get_name (ATK_STATE_MODAL);
222 g_return_val_if_fail (name, FALSE);
223 if (strcmp (name, "modal") != 0)
225 g_print ("Unexpected name for ATK_STATE_MODAL %s\n", name);
226 return FALSE;
229 type1 = atk_state_type_for_name ("focused");
230 if (type1 != ATK_STATE_FOCUSED)
232 g_print ("Unexpected type for focused\n");
233 return FALSE;
236 type1 = atk_state_type_register ("test-state");
237 name = atk_state_type_get_name (type1);
238 g_return_val_if_fail (name, FALSE);
239 if (strcmp (name, "test-state") != 0)
241 g_print ("Unexpected name for test-state %s\n", name);
242 return FALSE;
244 type2 = atk_state_type_for_name ("test-state");
245 g_return_val_if_fail (name, FALSE);
246 if (type1 != type2)
248 g_print ("Unexpected type for test-state %d %d\n", type1, type2);
249 return FALSE;
251 type2 = atk_state_type_for_name ("TEST_STATE");
252 if (type2 != 0)
254 g_print ("Unexpected type for TEST_STATE\n");
255 return FALSE;
258 * Check that a non-existent type returns NULL
260 name = atk_state_type_get_name (ATK_STATE_LAST_DEFINED +2);
261 if (name)
263 g_print ("Unexpected name for undefined type\n");
264 return FALSE;
266 return TRUE;
270 main (gint argc, char* argv[])
272 gboolean b_ret;
274 g_print("Starting State Set test suite\n");
276 b_ret = test_state_set ();
277 if (b_ret)
279 g_print ("State Set tests succeeded\n");
281 else
283 g_print ("State Set tests failed\n");
285 b_ret = test_state ();
286 if (b_ret)
288 g_print ("State tests succeeded\n");
290 else
292 g_print ("State tests failed\n");
294 return 0;