2009-27-09 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tests / pyatspi / statetest.py
1 import dbus
2 import gobject
3 import os.path
4
5 from xml.dom import minidom
6 import os
7
8 from pasytest import PasyTest as _PasyTest
9
10 import pyatspi
11 from pyatspi import StateSet
12
13 os = [pyatspi.STATE_MULTISELECTABLE,
14       pyatspi.STATE_PRESSED,
15       pyatspi.STATE_SHOWING,
16       pyatspi.STATE_TRANSIENT,
17       pyatspi.STATE_COLLAPSED,
18       pyatspi.STATE_EDITABLE,]
19
20 class StateTest(_PasyTest):
21
22         __tests__ = ["setup",
23                      "test_contains",
24                      "test_add",
25                      "test_remove",
26                      "test_equals",
27                      "test_compare",
28                      "test_isEmpty",
29                      "test_getStates",
30                      "teardown",
31                      ]
32
33         def __init__(self, bus, path):
34                 _PasyTest.__init__(self, "State", False)
35
36         def setup(self, test):
37                 pass
38
39         def test_contains(self, test):
40                 state = StateSet(*os)
41                 if not state.contains(pyatspi.STATE_PRESSED):
42                         test.fail("Does not find contained state")
43                 if state.contains(pyatspi.STATE_ACTIVE):
44                         test.fail("Finds state not contained")
45
46         def test_add(self, test):
47                 state = StateSet()
48                 state.add(pyatspi.STATE_PRESSED)
49                 if not state.contains(pyatspi.STATE_PRESSED):
50                         test.fail("State not added")
51
52         def test_remove(self, test):
53                 state = StateSet(*os)
54                 state.remove(pyatspi.STATE_PRESSED)
55                 if state.contains(pyatspi.STATE_PRESSED):
56                         test.fail("State not removed")
57
58         def test_equals(self, test):
59                 one = StateSet(*os)
60                 two = StateSet(*os)
61                 if not one.equals(two):
62                         test.fail("Same states not found equal")
63                 two.remove(pyatspi.STATE_PRESSED)
64                 if two.equals(one):
65                         test.fail("Unequal states found equal")
66
67         def test_isEmpty(self, test):
68                 emp = StateSet()
69                 if not emp.isEmpty():
70                         test.fail("Empty state found non-empty")
71                 emp.add(pyatspi.STATE_PRESSED)
72                 if emp.isEmpty():
73                         test.fail("State incorrectly found empty")
74
75         def test_compare(self, test):
76                 one = StateSet(*os)
77                 two = StateSet(*os)
78
79                 onemtwo = one.compare(two)
80                 if not onemtwo.isEmpty():
81                         test.fail("Equal states when compared yeilds non-empty state")
82
83                 one.add(pyatspi.STATE_ACTIVE)
84                 onemtwo = one.compare(two)
85                 
86                 act = StateSet(pyatspi.STATE_ACTIVE)
87                 if not onemtwo.equals(act):
88                         test.fail("Compared states do not yeild correct state")
89
90         def test_getStates(self, test):
91                 state = StateSet(*os)
92
93                 states = state.getStates()
94                 cone = set(states)
95                 ctwo = set(os)
96
97                 if not (cone.issubset(ctwo) and ctwo.issubset(cone)):
98                         test.fail("States not reported correctly")
99
100         def teardown(self, test):
101                 pass