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 void test_state_set (void);
25
static void test_state (void);
26

            
27
static void
28
1
test_state_set (void)
29
{
30
  AtkStateSet *state_set1, *state_set2, *state_set3;
31
  AtkStateType state_array[3];
32

            
33
1
  state_set1 = atk_state_set_new ();
34

            
35
1
  g_assert_true (atk_state_set_is_empty (state_set1));
36

            
37
1
  g_assert_true (atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE));
38

            
39
1
  g_assert_false (atk_state_set_is_empty (state_set1));
40

            
41
1
  g_assert_false (atk_state_set_add_state (state_set1, ATK_STATE_ACTIVE));
42

            
43
1
  state_array[0] = ATK_STATE_ACTIVE;
44
1
  state_array[1] = ATK_STATE_VISIBLE;
45
1
  state_array[2] = ATK_STATE_BUSY;
46
1
  atk_state_set_add_states (state_set1, state_array, 3);
47

            
48
1
  g_assert_true (atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE));
49
1
  g_assert_true (atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE));
50
1
  g_assert_true (atk_state_set_contains_state (state_set1, ATK_STATE_BUSY));
51
1
  g_assert_false (atk_state_set_contains_state (state_set1, ATK_STATE_VERTICAL));
52

            
53
1
  atk_state_set_remove_state (state_set1, ATK_STATE_BUSY);
54
1
  g_assert_false (atk_state_set_contains_state (state_set1, ATK_STATE_BUSY));
55
1
  g_assert_true (atk_state_set_contains_state (state_set1, ATK_STATE_VISIBLE));
56
1
  g_assert_false (atk_state_set_contains_states (state_set1, state_array, 3));
57
1
  g_assert_true (atk_state_set_contains_states (state_set1, state_array, 2));
58

            
59
1
  state_array[0] = ATK_STATE_SINGLE_LINE;
60
1
  state_array[1] = ATK_STATE_VISIBLE;
61
1
  state_array[2] = ATK_STATE_VERTICAL;
62

            
63
1
  state_set2 = atk_state_set_new ();
64
1
  atk_state_set_add_states (state_set2, state_array, 3);
65

            
66
1
  state_set3 = atk_state_set_and_sets (state_set1, state_set2);
67
1
  g_assert_true (atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE));
68
1
  g_assert_false (atk_state_set_contains_state (state_set3, ATK_STATE_BUSY));
69
1
  g_object_unref (state_set3);
70

            
71
1
  atk_state_set_remove_state (state_set1, ATK_STATE_VISIBLE);
72
1
  state_set3 = atk_state_set_and_sets (state_set1, state_set2);
73
1
  g_assert_null (state_set3);
74

            
75
1
  state_set3 = atk_state_set_or_sets (state_set1, state_set2);
76
1
  g_assert_true (atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE));
77
1
  g_assert_false (atk_state_set_contains_state (state_set3, ATK_STATE_INVALID));
78
1
  g_object_unref (state_set3);
79

            
80
1
  g_assert_true (atk_state_set_add_state (state_set1, ATK_STATE_VISIBLE));
81
1
  state_set3 = atk_state_set_xor_sets (state_set1, state_set2);
82
1
  g_assert_false (atk_state_set_contains_state (state_set3, ATK_STATE_VISIBLE));
83
1
  g_assert_true (atk_state_set_contains_state (state_set3, ATK_STATE_ACTIVE));
84

            
85
1
  atk_state_set_clear_states (state_set1);
86
1
  g_assert_false (atk_state_set_contains_state (state_set1, ATK_STATE_ACTIVE));
87

            
88
1
  g_object_unref (state_set1);
89
1
  g_object_unref (state_set2);
90
1
  g_object_unref (state_set3);
91
1
}
92

            
93
static void
94
1
test_state (void)
95
{
96
  AtkStateType type1, type2;
97
  const gchar *name;
98

            
99
1
  name = atk_state_type_get_name (ATK_STATE_VISIBLE);
100
1
  g_assert_cmpstr (name, ==, "visible");
101

            
102
1
  name = atk_state_type_get_name (ATK_STATE_MODAL);
103
1
  g_assert_cmpstr (name, ==, "modal");
104

            
105
1
  g_assert_cmpint (atk_state_type_for_name ("focused"), ==, ATK_STATE_FOCUSED);
106

            
107
1
  type1 = atk_state_type_register ("test-state");
108
1
  name = atk_state_type_get_name (type1);
109
1
  g_assert_cmpstr (name, ==, "test-state");
110
1
  type2 = atk_state_type_for_name ("test-state");
111
1
  g_assert_cmpint (type1, ==, type2);
112
1
  g_assert_cmpint (atk_state_type_for_name ("TEST_STATE"), ==, 0);
113

            
114
  /*
115
   * Check that a non-existent type returns NULL
116
   */
117
1
  g_assert_null (atk_state_type_get_name (ATK_STATE_LAST_DEFINED + 2));
118
1
}
119

            
120
int
121
1
main (gint argc,
122
      char *argv[])
123
{
124
1
  g_test_init (&argc, &argv, NULL);
125
1
  g_test_add_func ("/atk/state/state_set", test_state_set);
126
1
  g_test_add_func ("/atk/state/state", test_state);
127

            
128
1
  return g_test_run ();
129
}