5 from xml.dom import minidom
8 from pasytest import PasyTest as _PasyTest
11 from pyatspi import StateSet
13 st = [pyatspi.STATE_MULTI_LINE,
15 pyatspi.STATE_INDETERMINATE,
16 pyatspi.STATE_SUPPORTS_AUTOCOMPLETION,
17 pyatspi.STATE_VERTICAL,]
19 def _createNode(accessible, parentElement):
20 e = minidom.Element("accessible")
22 e.attributes["name"] = accessible.name
23 e.attributes["role"] = str(int(accessible.getRole()))
24 e.attributes["description"] = accessible.description
26 for i in range(0, accessible.childCount):
27 _createNode(accessible.getChildAtIndex(i), e)
29 parentElement.appendChild(e)
31 class AccessibleTest(_PasyTest):
35 "test_getChildAtIndex",
37 "test_getApplication",
40 "test_getIndexInParent",
41 "test_getLocalizedRoleName",
42 "test_getRelationSet",
52 def __init__(self, bus, path):
53 _PasyTest.__init__(self, "Accessible", False)
57 def setup(self, test):
58 self._registry = pyatspi.Registry()
60 self._desktop = self._registry.getDesktop(0)
62 def test_name(self, test):
63 root = self._desktop.getChildAtIndex(0)
64 test.assertEqual(root.name, "main", "Expected name - \"main\". Recieved - \"%s\"" % (root.name,))
66 def test_getChildAtIndex(self, test):
67 root = self._desktop.getChildAtIndex(0)
68 a = root.getChildAtIndex(0)
69 test.assertEqual(a.name, "gnome-settings-daemon",
70 "Expected name - \"gnome-settings-daemon\". Recieved - \"%s\"" % (a.name,))
71 b = root.getChildAtIndex(1)
72 test.assertEqual(b.name, "gnome-panel",
73 "Expected name - \"gnome-panel\". Recieved - \"%s\"" % (b.name,))
74 c = root.getChildAtIndex(2)
75 test.assertEqual(c.name, "nautilus",
76 "Expected name - \"nautilus\". Recieved - \"%s\"" % (c.name,))
78 def test_isEqual(self, test):
79 root = self._desktop.getChildAtIndex(0)
81 a = root.getChildAtIndex(1)
83 test.fail("Same accessible found unequal to self")
85 b = root.getChildAtIndex(1)
87 test.fail("Similar accessibles found unequal")
89 test.fail("Similar accessibles found unequal")
91 c = root.getChildAtIndex(2)
93 test.fail("Different accessibles found equal")
95 test.fail("Different accessibles found equal")
97 def test_getApplication(self, test):
98 root = self._desktop.getChildAtIndex(0)
99 application = root.getApplication()
100 if not root.isEqual(application):
101 test.fail("Root accessible does not provide itself as its Application")
103 a = root.getChildAtIndex(1)
104 application = a.getApplication()
105 if not root.isEqual(application):
106 test.fail("Child accessible does not provide the root as its Application")
109 def test_getAttributes(self, test):
110 root = self._desktop.getChildAtIndex(0)
111 attr = root.getAttributes()
112 res = ["foo:bar", "baz:qux", "quux:corge"]
113 test.assertEqual(attr, res, "Attributes expected %s, recieved %s" % (attr, res))
116 def test_parent(self, test):
117 root = self._desktop.getChildAtIndex(0)
119 a = root.getChildAtIndex(1)
121 if not root.isEqual(pa):
122 test.fail("Child does not correctly report its parent")
124 def test_getIndexInParent(self, test):
125 root = self._desktop.getChildAtIndex(0)
127 for i in range(0, root.childCount):
128 child = root.getChildAtIndex(i)
129 test.assertEqual(i, child.getIndexInParent(), "Childs index in parent reported incorrectly")
131 def test_getLocalizedRoleName(self, test):
132 root = self._desktop.getChildAtIndex(0)
135 res = root.getLocalizedRoleName()
136 test.assertEqual(ans, res,
137 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
139 a = root.getChildAtIndex(1)
140 a = a.getChildAtIndex(0)
141 ans = "html container"
142 res = a.getLocalizedRoleName()
143 test.assertEqual(ans, res,
144 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
146 def test_getRelationSet(self, test):
147 root = self._desktop.getChildAtIndex(0)
148 # Complete test of Relation interface is separate
149 rset = root.getRelationSet()
151 def test_getRole(self, test):
152 root = self._desktop.getChildAtIndex(0)
153 test.assertEqual(root.getRole(), 69,
154 "Expected role - \"69\". Recieved - \"%d\"" % (root.getRole(),))
156 def test_getRoleName(self, test):
157 root = self._desktop.getChildAtIndex(0)
160 res = root.getRoleName()
161 test.assertEqual(ans, res,
162 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
164 a = root.getChildAtIndex(1)
165 a = a.getChildAtIndex(0)
166 ans = "html container"
167 res = a.getRoleName()
168 test.assertEqual(ans, res,
169 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
171 def test_getState(self, test):
172 root = self._desktop.getChildAtIndex(0)
173 state = root.getState()
175 if not res.equals(state):
176 test.fail("States not reported correctly")
178 def test_childCount(self, test):
179 root = self._desktop.getChildAtIndex(0)
180 test.assertEqual(root.childCount, 11,
181 "Expected role - \"11\". Recieved - \"%d\"" % (root.childCount,))
183 def test_description(self, test):
184 root = self._desktop.getChildAtIndex(0)
185 description = "The main accessible object, root of the accessible tree"
186 test.assertEqual(root.description, description,
187 "Expected description - \"%s\". Recieved - \"%s\"" % (description, root.description,))
189 def test_tree(self, test):
191 This is a mild stress test for the
201 It checks a tree of these values is correctly
202 passed from Application to AT.
204 root = self._desktop.getChildAtIndex(0)
206 doc = minidom.Document()
207 _createNode(root, doc)
208 answer = doc.toprettyxml()
210 correct = os.path.join(os.environ["TEST_DATA_DIRECTORY"],
211 "accessible-test-results.xml")
213 cstring = file.read()
215 test.assertEqual(answer, cstring, "Object tree not passed correctly")
217 def teardown(self, test):