summaryrefslogtreecommitdiff
path: root/tests/teststateset.c
blob: 27c15a90ed80a37797bee69fe5d7c5e47ae284cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/* ATK -  Accessibility Toolkit
 * Copyright 2001 Sun Microsystems Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <atk/atk.h>

#include <string.h>

static gboolean  test_state_set (void);
static gboolean  test_state (void);

static gboolean
test_state_set (void)
{
  AtkStateSet *state_set1, *state_set2, *state_set3;
  AtkStateType state_array[3];
  gboolean b_val;

  state_set1 = atk_state_set_new ();

  b_val = atk_state_set_is_empty (state_set1);  
  if (b_val)
  {
    g_print ("New state set is not empty\n");
    return FALSE;
  }

  b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
  if (!b_val)
  {
    g_print ("Adding new state set failed\n");
    return FALSE;
  }

  b_val = atk_state_set_is_empty (state_set1);  
  if (!b_val)
  {
    g_print ("New state set is empty when it should not be\n");
    return FALSE;
  }

  b_val = atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE);
  if (b_val)
  {
    g_print ("Adding new state set succeeded when it should not have\n");
    return FALSE;
  }

  state_array[0] = ATK_STATE_ACTIVE;
  state_array[1] = ATK_STATE_VISIBLE;
  state_array[2] = ATK_STATE_BUSY;
  atk_state_set_add_states (state_set1, state_array, 3);

  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
  if (!b_val)
  {
    g_print ("Contains state failed for ATK_STATE_ACTIVE but should not have\n");
    return FALSE;
  }
 
  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
  if (!b_val)
  {
    g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
    return FALSE;
  }
 
  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
  if (!b_val)
  {
    g_print ("Contains state failed for ATK_STATE_BUSY but should not have\n");
    return FALSE;
  }
 
  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VERTICAL);
  if (b_val)
  {
    g_print ("Contains state succeeded for ATK_STATE_VERTICAL but should not have\n");
    return FALSE;
  }
 
  atk_state_set_remove_state (state_set1, ATK_STATE_BUSY);
  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_BUSY);
  if (b_val)
  {
    g_print ("Contains state succeeded for ATK_STATE_BUSY but should not have\n");
    return FALSE;
  }
  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE);
  if (!b_val)
  {
    g_print ("Contains state failed for ATK_STATE_VISIBLE but should not have\n");
    return FALSE;
  }

  b_val = atk_state_set_contains_states (state_set1, state_array, 3);
  if (b_val)
  {
    g_print ("Contains states succeeded should not have\n");
    return FALSE;
  }

  b_val = atk_state_set_contains_states (state_set1, state_array, 2);
  if (!b_val)
  {
    g_print ("Contains states failed should not have\n");
    return FALSE;
  }

  state_array[0] = ATK_STATE_SINGLE_LINE;
  state_array[1] = ATK_STATE_VISIBLE;
  state_array[2] = ATK_STATE_VERTICAL;
 
  state_set2 = atk_state_set_new();
  atk_state_set_add_states (state_set2, state_array, 3);

  state_set3 = atk_state_set_and_sets (state_set1, state_set2);
  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
  if (!b_val)
  {
    g_print ("Contains state failed for ATK_STATE_VISIBLE after and but should not have\n");
    return FALSE;
  }
  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_BUSY);
  if (b_val)
  {
    g_print ("Contains state succeeded for ATK_STATE_BUSY after and but should not have\n");
    return FALSE;
  }
  g_object_unref (state_set3);

  atk_state_set_remove_state (state_set1, ATK_STATE_VISIBLE);
  state_set3 = atk_state_set_and_sets (state_set1, state_set2);
  if (state_set3)
  {
    g_print ("state_set 3 is not NULL after and but should be\n");
    return FALSE;
  }
 
  state_set3 = atk_state_set_or_sets (state_set1, state_set2);
  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
  if (!b_val)
  {
    g_print ("Contains state failed for ATK_STATE_VISIBLE after or but should not have\n");
    return FALSE;
  }

  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_INVALID);
  if (b_val)
  {
    g_print ("Contains state succeeded for ATK_STATE_INVALID after or but should not have\n");
    return FALSE;
  }
  g_object_unref (state_set3);

  b_val = atk_state_set_add_state (state_set1, ATK_STATE_VISIBLE);
  if (!b_val)
  {
    g_print ("Adding new state set failed\n");
    return FALSE;
  }
  state_set3 = atk_state_set_xor_sets (state_set1, state_set2);
  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE);
  if (b_val)
  {
    g_print ("Contains state succeeded for ATK_STATE_VISIBLE after xor but should not have\n");
    return FALSE;
  }

  b_val = atk_state_set_contains_state (state_set3, ATK_STATE_ACTIVE);
  if (!b_val)
  {
    g_print ("Contains state failed for ATK_STATE_ACTIVE after xor but should not have\n");
    return FALSE;
  }

  atk_state_set_clear_states (state_set1);
  b_val = atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE);
  if (b_val)
  {
    g_print ("Contains state succeeded for ATK_STATE_ACTIVE but should not have\n");
    return FALSE;
  }

  g_object_unref (state_set1);
  g_object_unref (state_set2);
  g_object_unref (state_set3);
  return TRUE;

}

static gboolean
test_state (void)
{
  AtkStateType type1, type2;
  const gchar *name;

  name = atk_state_type_get_name (ATK_STATE_VISIBLE);
  g_return_val_if_fail (name, FALSE);
  if (strcmp (name, "visible") != 0)
  {
    g_print ("Unexpected name for ATK_STATE_VISIBLE %s\n", name);
    return FALSE;
  }

  name = atk_state_type_get_name (ATK_STATE_MODAL);
  g_return_val_if_fail (name, FALSE);
  if (strcmp (name, "modal") != 0)
  {
    g_print ("Unexpected name for ATK_STATE_MODAL %s\n", name);
    return FALSE;
  }

  type1 = atk_state_type_for_name ("focused");
  if (type1 != ATK_STATE_FOCUSED)
  {
    g_print ("Unexpected type for focused\n");
    return FALSE;
  }

  type1 = atk_state_type_register ("test-state");
  name = atk_state_type_get_name (type1);
  g_return_val_if_fail (name, FALSE);
  if (strcmp (name, "test-state") != 0)
  {
    g_print ("Unexpected name for test-state %s\n", name);
    return FALSE;
  }
  type2 = atk_state_type_for_name ("test-state");
  g_return_val_if_fail (name, FALSE);
  if (type1 != type2)
  {
    g_print ("Unexpected type for test-state %d %d\n", type1, type2);
    return FALSE;
  }
  type2 = atk_state_type_for_name ("TEST_STATE");
  if (type2 != 0)
  {
    g_print ("Unexpected type for TEST_STATE\n");
    return FALSE;
  }
  /*
   * Check that a non-existent type returns NULL
   */
  name = atk_state_type_get_name (ATK_STATE_LAST_DEFINED +2);
  if (name)
  {
    g_print ("Unexpected name for undefined type\n");
    return FALSE;
  }
  return TRUE;
}

int
gtk_module_init (gint argc, char* argv[])
{
  gboolean b_ret;

  g_print("State Set test module loaded\n");

  b_ret = test_state_set ();
  if (b_ret)
  {
    g_print ("State Set tests succeeded\n");
  }
  else
  {
    g_print ("State Set tests failed\n");
  }
  b_ret = test_state ();
  if (b_ret)
  {
    g_print ("State tests succeeded\n");
  }
  else
  {
    g_print ("State tests failed\n");
  }
  return 0;
}