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.Registry(self._path)
59 self._desktop = self._registry.getDesktop(0)
61 def test_name(self, test):
62 root = self._desktop.getChildAtIndex(0)
63 test.assertEqual(root.name, "main", "Expected name - \"main\". Recieved - \"%s\"" % (root.name,))
65 def test_getChildAtIndex(self, test):
66 root = self._desktop.getChildAtIndex(0)
67 a = root.getChildAtIndex(0)
68 test.assertEqual(a.name, "gnome-settings-daemon",
69 "Expected name - \"gnome-settings-daemon\". Recieved - \"%s\"" % (a.name,))
70 b = root.getChildAtIndex(1)
71 test.assertEqual(b.name, "gnome-panel",
72 "Expected name - \"gnome-panel\". Recieved - \"%s\"" % (b.name,))
73 c = root.getChildAtIndex(2)
74 test.assertEqual(c.name, "nautilus",
75 "Expected name - \"nautilus\". Recieved - \"%s\"" % (c.name,))
77 def test_isEqual(self, test):
78 root = self._desktop.getChildAtIndex(0)
80 a = root.getChildAtIndex(1)
82 test.fail("Same accessible found unequal to self")
84 b = root.getChildAtIndex(1)
86 test.fail("Similar accessibles found unequal")
88 test.fail("Similar accessibles found unequal")
90 c = root.getChildAtIndex(2)
92 test.fail("Different accessibles found equal")
94 test.fail("Different accessibles found equal")
96 def test_getApplication(self, test):
97 root = self._desktop.getChildAtIndex(0)
98 application = root.getApplication()
99 if not root.isEqual(application):
100 test.fail("Root accessible does not provide itself as its Application")
102 a = root.getChildAtIndex(1)
103 application = a.getApplication()
104 if not root.isEqual(application):
105 test.fail("Child accessible does not provide the root as its Application")
108 def test_getAttributes(self, test):
109 root = self._desktop.getChildAtIndex(0)
110 attr = root.getAttributes()
111 res = ["foo:bar", "baz:qux", "quux:corge"]
112 test.assertEqual(attr, res, "Attributes expected %s, recieved %s" % (attr, res))
115 def test_parent(self, test):
116 root = self._desktop.getChildAtIndex(0)
118 a = root.getChildAtIndex(1)
120 if not root.isEqual(pa):
121 test.fail("Child does not correctly report its parent")
123 def test_getIndexInParent(self, test):
124 root = self._desktop.getChildAtIndex(0)
126 for i in range(0, root.childCount):
127 child = root.getChildAtIndex(i)
128 test.assertEqual(i, child.getIndexInParent(), "Childs index in parent reported incorrectly")
130 def test_getLocalizedRoleName(self, test):
131 root = self._desktop.getChildAtIndex(0)
134 res = root.getLocalizedRoleName()
135 test.assertEqual(ans, res,
136 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
138 a = root.getChildAtIndex(1)
139 a = a.getChildAtIndex(0)
140 ans = "html container"
141 res = a.getLocalizedRoleName()
142 test.assertEqual(ans, res,
143 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
145 def test_getRelationSet(self, test):
146 root = self._desktop.getChildAtIndex(0)
147 # Complete test of Relation interface is separate
148 rset = root.getRelationSet()
150 def test_getRole(self, test):
151 root = self._desktop.getChildAtIndex(0)
152 test.assertEqual(root.getRole(), 69,
153 "Expected role - \"69\". Recieved - \"%d\"" % (root.getRole(),))
155 def test_getRoleName(self, test):
156 root = self._desktop.getChildAtIndex(0)
159 res = root.getRoleName()
160 test.assertEqual(ans, res,
161 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
163 a = root.getChildAtIndex(1)
164 a = a.getChildAtIndex(0)
165 ans = "html container"
166 res = a.getRoleName()
167 test.assertEqual(ans, res,
168 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
170 def test_getState(self, test):
171 root = self._desktop.getChildAtIndex(0)
172 state = root.getState()
174 if not res.equals(state):
175 test.fail("States not reported correctly")
177 def test_childCount(self, test):
178 root = self._desktop.getChildAtIndex(0)
179 test.assertEqual(root.childCount, 11,
180 "Expected role - \"11\". Recieved - \"%d\"" % (root.childCount,))
182 def test_description(self, test):
183 root = self._desktop.getChildAtIndex(0)
184 description = "The main accessible object, root of the accessible tree"
185 test.assertEqual(root.description, description,
186 "Expected description - \"%s\". Recieved - \"%s\"" % (description, root.description,))
188 def test_tree(self, test):
190 This is a mild stress test for the
200 It checks a tree of these values is correctly
201 passed from Application to AT.
203 root = self._desktop.getChildAtIndex(0)
205 doc = minidom.Document()
206 _createNode(root, doc)
207 answer = doc.toprettyxml()
209 correct = os.path.join(os.environ["TEST_DATA_DIRECTORY"],
210 "accessible-test-results.xml")
212 cstring = file.read()
214 test.assertEqual(answer, cstring, "Object tree not passed correctly")
216 def teardown(self, test):