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