Updated FSF's address
[platform/upstream/atk.git] / tests / teststateset.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 #include <atk/atk.h>
19
20 #include <string.h>
21
22 static gboolean  test_state_set (void);
23 static gboolean  test_state (void);
24
25 static gboolean
26 test_state_set (void)
27 {
28   AtkStateSet *state_set1, *state_set2, *state_set3;
29   AtkStateType state_array[3];
30   gboolean b_val;
31
32   state_set1 = atk_state_set_new ();
33
34   b_val = atk_state_set_is_empty (state_set1);  
35   if (!b_val)
36   {
37     g_print ("New state set is not empty\n");
38     return FALSE;
39   }
40
41   b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
42   if (!b_val)
43   {
44     g_print ("Adding new state set failed\n");
45     return FALSE;
46   }
47
48   b_val = atk_state_set_is_empty (state_set1);  
49   if (b_val)
50   {
51     g_print ("New state set is empty when it should not be\n");
52     return FALSE;
53   }
54
55   b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
56   if (b_val)
57   {
58     g_print ("Adding new state set succeeded when it should not have\n");
59     return FALSE;
60   }
61
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);
66
67   b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
68   if (!b_val)
69   {
70     g_print ("Contains state failed for ATK_STATE_ACTIVE but should not have\n");
71     return FALSE;
72   }
73  
74   b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
75   if (!b_val)
76   {
77     g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
78     return FALSE;
79   }
80  
81   b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
82   if (!b_val)
83   {
84     g_print ("Contains state failed for ATK_STATE_BUSY but should not have\n");
85     return FALSE;
86   }
87  
88   b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VERTICAL);
89   if (b_val)
90   {
91     g_print ("Contains state succeeded for ATK_STATE_VERTICAL but should not have\n");
92     return FALSE;
93   }
94  
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)
98   {
99     g_print ("Contains state succeeded for ATK_STATE_BUSY but should not have\n");
100     return FALSE;
101   }
102   b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
103   if (!b_val)
104   {
105     g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
106     return FALSE;
107   }
108
109   b_val = atk_state_set_contains_states (state_set1, state_array, 3);
110   if (b_val)
111   {
112     g_print ("Contains states succeeded should not have\n");
113     return FALSE;
114   }
115
116   b_val = atk_state_set_contains_states (state_set1, state_array, 2);
117   if (!b_val)
118   {
119     g_print ("Contains states failed should not have\n");
120     return FALSE;
121   }
122
123   state_array[0] = ATK_STATE_SINGLE_LINE;
124   state_array[1] = ATK_STATE_VISIBLE;
125   state_array[2] = ATK_STATE_VERTICAL;
126  
127   state_set2 = atk_state_set_new();
128   atk_state_set_add_states (state_set2, state_array, 3);
129
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)
133   {
134     g_print ("Contains state failed for ATK_STATE_VISIBLE after and but should not have\n");
135     return FALSE;
136   }
137   b_val = atk_state_set_contains_state (state_set3, ATK_STATE_BUSY);
138   if (b_val)
139   {
140     g_print ("Contains state succeeded for ATK_STATE_BUSY after and but should not have\n");
141     return FALSE;
142   }
143   g_object_unref (state_set3);
144
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)
148   {
149     g_print ("state_set 3 is not NULL after and but should be\n");
150     return FALSE;
151   }
152  
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)
156   {
157     g_print ("Contains state failed for ATK_STATE_VISIBLE after or but should not have\n");
158     return FALSE;
159   }
160
161   b_val = atk_state_set_contains_state (state_set3, ATK_STATE_INVALID);
162   if (b_val)
163   {
164     g_print ("Contains state succeeded for ATK_STATE_INVALID after or but should not have\n");
165     return FALSE;
166   }
167   g_object_unref (state_set3);
168
169   b_val = atk_state_set_add_state (state_set1, ATK_STATE_VISIBLE);
170   if (!b_val)
171   {
172     g_print ("Adding new state set failed\n");
173     return FALSE;
174   }
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)
178   {
179     g_print ("Contains state succeeded for ATK_STATE_VISIBLE after xor but should not have\n");
180     return FALSE;
181   }
182
183   b_val = atk_state_set_contains_state (state_set3, ATK_STATE_ACTIVE);
184   if (!b_val)
185   {
186     g_print ("Contains state failed for ATK_STATE_ACTIVE after xor but should not have\n");
187     return FALSE;
188   }
189
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)
193   {
194     g_print ("Contains state succeeded for ATK_STATE_ACTIVE but should not have\n");
195     return FALSE;
196   }
197
198   g_object_unref (state_set1);
199   g_object_unref (state_set2);
200   g_object_unref (state_set3);
201   return TRUE;
202
203 }
204
205 static gboolean
206 test_state (void)
207 {
208   AtkStateType type1, type2;
209   const gchar *name;
210
211   name = atk_state_type_get_name (ATK_STATE_VISIBLE);
212   g_return_val_if_fail (name, FALSE);
213   if (strcmp (name, "visible") != 0)
214   {
215     g_print ("Unexpected name for ATK_STATE_VISIBLE %s\n", name);
216     return FALSE;
217   }
218
219   name = atk_state_type_get_name (ATK_STATE_MODAL);
220   g_return_val_if_fail (name, FALSE);
221   if (strcmp (name, "modal") != 0)
222   {
223     g_print ("Unexpected name for ATK_STATE_MODAL %s\n", name);
224     return FALSE;
225   }
226
227   type1 = atk_state_type_for_name ("focused");
228   if (type1 != ATK_STATE_FOCUSED)
229   {
230     g_print ("Unexpected type for focused\n");
231     return FALSE;
232   }
233
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)
238   {
239     g_print ("Unexpected name for test-state %s\n", name);
240     return FALSE;
241   }
242   type2 = atk_state_type_for_name ("test-state");
243   g_return_val_if_fail (name, FALSE);
244   if (type1 != type2)
245   {
246     g_print ("Unexpected type for test-state %d %d\n", type1, type2);
247     return FALSE;
248   }
249   type2 = atk_state_type_for_name ("TEST_STATE");
250   if (type2 != 0)
251   {
252     g_print ("Unexpected type for TEST_STATE\n");
253     return FALSE;
254   }
255   /*
256    * Check that a non-existent type returns NULL
257    */
258   name = atk_state_type_get_name (ATK_STATE_LAST_DEFINED +2);
259   if (name)
260   {
261     g_print ("Unexpected name for undefined type\n");
262     return FALSE;
263   }
264   return TRUE;
265 }
266
267 int
268 main (gint argc, char* argv[])
269 {
270   gboolean b_ret;
271
272   g_print("Starting State Set test suite\n");
273
274   b_ret = test_state_set ();
275   if (b_ret)
276   {
277     g_print ("State Set tests succeeded\n");
278   }
279   else
280   {
281     g_print ("State Set tests failed\n");
282   }
283   b_ret = test_state ();
284   if (b_ret)
285   {
286     g_print ("State tests succeeded\n");
287   }
288   else
289   {
290     g_print ("State tests failed\n");
291   }
292   return 0;
293 }