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, see <http://www.gnu.org/licenses/>.
22 static gboolean test_state_set (void);
23 static gboolean test_state (void);
28 AtkStateSet *state_set1, *state_set2, *state_set3;
29 AtkStateType state_array[3];
32 state_set1 = atk_state_set_new ();
34 b_val = atk_state_set_is_empty (state_set1);
37 g_print ("New state set is not empty\n");
41 b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
44 g_print ("Adding new state set failed\n");
48 b_val = atk_state_set_is_empty (state_set1);
51 g_print ("New state set is empty when it should not be\n");
55 b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
58 g_print ("Adding new state set succeeded when it should not have\n");
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);
70 g_print ("Contains state failed for ATK_STATE_ACTIVE but should not have\n");
74 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
77 g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
81 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
84 g_print ("Contains state failed for ATK_STATE_BUSY but should not have\n");
88 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VERTICAL);
91 g_print ("Contains state succeeded for ATK_STATE_VERTICAL but should not have\n");
95 atk_state_set_remove_state (state_set1, ATK_STATE_BUSY);
96 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
99 g_print ("Contains state succeeded for ATK_STATE_BUSY but should not have\n");
102 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
105 g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
109 b_val = atk_state_set_contains_states (state_set1, state_array, 3);
112 g_print ("Contains states succeeded should not have\n");
116 b_val = atk_state_set_contains_states (state_set1, state_array, 2);
119 g_print ("Contains states failed should not have\n");
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);
134 g_print ("Contains state failed for ATK_STATE_VISIBLE after and but should not have\n");
137 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_BUSY);
140 g_print ("Contains state succeeded for ATK_STATE_BUSY after and but should not have\n");
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);
149 g_print ("state_set 3 is not NULL after and but should be\n");
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);
157 g_print ("Contains state failed for ATK_STATE_VISIBLE after or but should not have\n");
161 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_INVALID);
164 g_print ("Contains state succeeded for ATK_STATE_INVALID after or but should not have\n");
167 g_object_unref (state_set3);
169 b_val = atk_state_set_add_state (state_set1, ATK_STATE_VISIBLE);
172 g_print ("Adding new state set failed\n");
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);
179 g_print ("Contains state succeeded for ATK_STATE_VISIBLE after xor but should not have\n");
183 b_val = atk_state_set_contains_state (state_set3, ATK_STATE_ACTIVE);
186 g_print ("Contains state failed for ATK_STATE_ACTIVE after xor but should not have\n");
190 atk_state_set_clear_states (state_set1);
191 b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
194 g_print ("Contains state succeeded for ATK_STATE_ACTIVE but should not have\n");
198 g_object_unref (state_set1);
199 g_object_unref (state_set2);
200 g_object_unref (state_set3);
208 AtkStateType type1, type2;
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);
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);
227 type1 = atk_state_type_for_name ("focused");
228 if (type1 != ATK_STATE_FOCUSED)
230 g_print ("Unexpected type for focused\n");
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);
242 type2 = atk_state_type_for_name ("test-state");
243 g_return_val_if_fail (name, FALSE);
246 g_print ("Unexpected type for test-state %d %d\n", type1, type2);
249 type2 = atk_state_type_for_name ("TEST_STATE");
252 g_print ("Unexpected type for TEST_STATE\n");
256 * Check that a non-existent type returns NULL
258 name = atk_state_type_get_name (ATK_STATE_LAST_DEFINED +2);
261 g_print ("Unexpected name for undefined type\n");
268 main (gint argc, char* argv[])
272 g_print("Starting State Set test suite\n");
274 b_ret = test_state_set ();
277 g_print ("State Set tests succeeded\n");
281 g_print ("State Set tests failed\n");
283 b_ret = test_state ();
286 g_print ("State tests succeeded\n");
290 g_print ("State tests failed\n");