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"]
115 test.assertEqual(attr, res, "Attributes expected %s, recieved %s" % (attr, res))
117 def test_parent(self, test):
118 root = self._desktop.getChildAtIndex(0)
120 a = root.getChildAtIndex(1)
122 if not root.isEqual(pa):
123 test.fail("Child does not correctly report its parent")
125 def test_getIndexInParent(self, test):
126 root = self._desktop.getChildAtIndex(0)
128 for i in range(0, root.childCount):
129 child = root.getChildAtIndex(i)
130 test.assertEqual(i, child.getIndexInParent(), "Childs index in parent reported incorrectly")
132 def test_getLocalizedRoleName(self, test):
133 root = self._desktop.getChildAtIndex(0)
136 res = root.getLocalizedRoleName()
137 test.assertEqual(ans, res,
138 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
140 a = root.getChildAtIndex(1)
141 a = a.getChildAtIndex(0)
142 ans = "html container"
143 res = a.getLocalizedRoleName()
144 test.assertEqual(ans, res,
145 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
147 def test_getRelationSet(self, test):
148 root = self._desktop.getChildAtIndex(0)
149 # Complete test of Relation interface is separate
150 rset = root.getRelationSet()
152 def test_getRole(self, test):
153 root = self._desktop.getChildAtIndex(0)
154 test.assertEqual(root.getRole(), 69,
155 "Expected role - \"69\". Recieved - \"%d\"" % (int(root.getRole()),))
157 def test_getRoleName(self, test):
158 root = self._desktop.getChildAtIndex(0)
161 res = root.getRoleName()
162 test.assertEqual(ans, res,
163 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
165 a = root.getChildAtIndex(1)
166 a = a.getChildAtIndex(0)
167 ans = "html container"
168 res = a.getRoleName()
169 test.assertEqual(ans, res,
170 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
172 def test_getState(self, test):
173 root = self._desktop.getChildAtIndex(0)
174 state = root.getState()
176 if not res.equals(state):
177 test.fail("States not reported correctly")
179 def test_childCount(self, test):
180 root = self._desktop.getChildAtIndex(0)
181 test.assertEqual(root.childCount, 11,
182 "Expected role - \"11\". Recieved - \"%d\"" % (root.childCount,))
184 def test_description(self, test):
185 root = self._desktop.getChildAtIndex(0)
186 description = "The main accessible object, root of the accessible tree"
187 test.assertEqual(root.description, description,
188 "Expected description - \"%s\". Recieved - \"%s\"" % (description, root.description,))
190 def test_tree(self, test):
192 This is a mild stress test for the
202 It checks a tree of these values is correctly
203 passed from Application to AT.
205 root = self._desktop.getChildAtIndex(0)
207 doc = minidom.Document()
208 _createNode(root, doc)
209 answer = doc.toprettyxml()
211 correct = os.path.join(os.environ["TEST_DATA_DIRECTORY"],
212 "accessible-test-results.xml")
214 cstring = file.read()
216 test.assertEqual(answer, cstring, "Object tree not passed correctly")
218 def teardown(self, test):