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.
24 static gboolean
test_state_set (void);
25 static gboolean
test_state (void);
30 AtkStateSet
*state_set1
, *state_set2
, *state_set3
;
31 AtkStateType state_array
[3];
34 state_set1
= atk_state_set_new ();
36 b_val
= atk_state_set_is_empty (state_set1
);
39 g_print ("New state set is not empty\n");
43 b_val
= atk_state_set_add_state (state_set1
, ATK_STATE_ACTIVE
);
46 g_print ("Adding new state set failed\n");
50 b_val
= atk_state_set_is_empty (state_set1
);
53 g_print ("New state set is empty when it should not be\n");
57 b_val
= atk_state_set_add_state (state_set1
, ATK_STATE_ACTIVE
);
60 g_print ("Adding new state set succeeded when it should not have\n");
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
);
72 g_print ("Contains state failed for ATK_STATE_ACTIVE but should not have\n");
76 b_val
= atk_state_set_contains_state (state_set1
, ATK_STATE_VISIBLE
);
79 g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
83 b_val
= atk_state_set_contains_state (state_set1
, ATK_STATE_BUSY
);
86 g_print ("Contains state failed for ATK_STATE_BUSY but should not have\n");
90 b_val
= atk_state_set_contains_state (state_set1
, ATK_STATE_VERTICAL
);
93 g_print ("Contains state succeeded for ATK_STATE_VERTICAL but should not have\n");
97 atk_state_set_remove_state (state_set1
, ATK_STATE_BUSY
);
98 b_val
= atk_state_set_contains_state (state_set1
, ATK_STATE_BUSY
);
101 g_print ("Contains state succeeded for ATK_STATE_BUSY but should not have\n");
104 b_val
= atk_state_set_contains_state (state_set1
, ATK_STATE_VISIBLE
);
107 g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
111 b_val
= atk_state_set_contains_states (state_set1
, state_array
, 3);
114 g_print ("Contains states succeeded should not have\n");
118 b_val
= atk_state_set_contains_states (state_set1
, state_array
, 2);
121 g_print ("Contains states failed should not have\n");
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
);
136 g_print ("Contains state failed for ATK_STATE_VISIBLE after and but should not have\n");
139 b_val
= atk_state_set_contains_state (state_set3
, ATK_STATE_BUSY
);
142 g_print ("Contains state succeeded for ATK_STATE_BUSY after and but should not have\n");
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
);
151 g_print ("state_set 3 is not NULL after and but should be\n");
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
);
159 g_print ("Contains state failed for ATK_STATE_VISIBLE after or but should not have\n");
163 b_val
= atk_state_set_contains_state (state_set3
, ATK_STATE_INVALID
);
166 g_print ("Contains state succeeded for ATK_STATE_INVALID after or but should not have\n");
169 g_object_unref (state_set3
);
171 b_val
= atk_state_set_add_state (state_set1
, ATK_STATE_VISIBLE
);
174 g_print ("Adding new state set failed\n");
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
);
181 g_print ("Contains state succeeded for ATK_STATE_VISIBLE after xor but should not have\n");
185 b_val
= atk_state_set_contains_state (state_set3
, ATK_STATE_ACTIVE
);
188 g_print ("Contains state failed for ATK_STATE_ACTIVE after xor but should not have\n");
192 atk_state_set_clear_states (state_set1
);
193 b_val
= atk_state_set_contains_state (state_set1
, ATK_STATE_ACTIVE
);
196 g_print ("Contains state succeeded for ATK_STATE_ACTIVE but should not have\n");
200 g_object_unref (state_set1
);
201 g_object_unref (state_set2
);
202 g_object_unref (state_set3
);
210 AtkStateType type1
, type2
;
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
);
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
);
229 type1
= atk_state_type_for_name ("focused");
230 if (type1
!= ATK_STATE_FOCUSED
)
232 g_print ("Unexpected type for focused\n");
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
);
244 type2
= atk_state_type_for_name ("test-state");
245 g_return_val_if_fail (name
, FALSE
);
248 g_print ("Unexpected type for test-state %d %d\n", type1
, type2
);
251 type2
= atk_state_type_for_name ("TEST_STATE");
254 g_print ("Unexpected type for TEST_STATE\n");
258 * Check that a non-existent type returns NULL
260 name
= atk_state_type_get_name (ATK_STATE_LAST_DEFINED
+2);
263 g_print ("Unexpected name for undefined type\n");
270 main (gint argc
, char* argv
[])
274 g_print("Starting State Set test suite\n");
276 b_ret
= test_state_set ();
279 g_print ("State Set tests succeeded\n");
283 g_print ("State Set tests failed\n");
285 b_ret
= test_state ();
288 g_print ("State tests succeeded\n");
292 g_print ("State tests failed\n");