5 from xml.dom import minidom
8 from pasytest import PasyTest as _PasyTest
12 def _createNode(accessible, parentElement):
13 e = minidom.Element("accessible")
15 e.attributes["name"] = accessible.name
16 e.attributes["role"] = str(int(accessible.getRole()))
17 e.attributes["description"] = accessible.description
19 for i in range(0, accessible.childCount):
20 _createNode(accessible.getChildAtIndex(i), e)
22 parentElement.appendChild(e)
24 class AccessibleTest(_PasyTest):
28 "test_getChildAtIndex",
30 "test_getApplication",
33 "test_getIndexInParent",
34 "test_getLocalizedRoleName",
35 "test_getRelationSet",
45 def __init__(self, bus, path):
46 _PasyTest.__init__(self, "Accessible", False)
50 def setup(self, test):
51 self._cache = pyatspi.TestApplicationCache(self._bus, self._path)
53 def test_name(self, test):
54 root = self._cache.root
55 test.assertEqual(root.name, "main", "Expected name - \"main\". Recieved - \"%s\"" % (root.name,))
57 def test_getChildAtIndex(self, test):
58 root = self._cache.root
59 a = root.getChildAtIndex(0)
60 test.assertEqual(a.name, "gnome-settings-daemon",
61 "Expected name - \"gnome-settings-daemon\". Recieved - \"%s\"" % (a.name,))
62 b = root.getChildAtIndex(1)
63 test.assertEqual(b.name, "gnome-panel",
64 "Expected name - \"gnome-panel\". Recieved - \"%s\"" % (b.name,))
65 c = root.getChildAtIndex(2)
66 test.assertEqual(c.name, "nautilus",
67 "Expected name - \"nautilus\". Recieved - \"%s\"" % (c.name,))
69 def test_isEqual(self, test):
70 root = self._cache.root
72 a = root.getChildAtIndex(1)
74 test.fail("Same accessible found unequal to self")
76 b = root.getChildAtIndex(1)
78 test.fail("Similar accessibles found unequal")
80 test.fail("Similar accessibles found unequal")
82 c = root.getChildAtIndex(2)
84 test.fail("Different accessibles found equal")
86 test.fail("Different accessibles found equal")
88 def test_getApplication(self, test):
89 root = self._cache.root
90 application = root.getApplication()
91 if not root.isEqual(application):
92 test.fail("Root accessible does not provide itself as its Application")
94 a = root.getChildAtIndex(1)
95 application = a.getApplication()
96 if not root.isEqual(application):
97 test.fail("Child accessible does not provide the root as its Application")
100 def test_getAttributes(self, test):
101 root = self._cache.root
102 #TODO The AttributeSet test needs expanding. Check attributes are passed correctly.
103 attr = root.getAttributes()
105 def test_parent(self, test):
106 root = self._cache.root
108 a = root.getChildAtIndex(1)
110 if not root.isEqual(pa):
111 test.fail("Child does not correctly report its parent")
113 def test_getIndexInParent(self, test):
114 root = self._cache.root
116 for i in range(0, root.childCount):
117 child = root.getChildAtIndex(i)
118 test.assertEqual(i, child.getIndexInParent(), "Childs index in parent reported incorrectly")
120 def test_getLocalizedRoleName(self, test):
121 root = self._cache.root
124 res = root.getLocalizedRoleName()
125 test.assertEqual(ans, res,
126 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
128 a = root.getChildAtIndex(1)
129 a = a.getChildAtIndex(0)
130 ans = "html container"
131 res = a.getLocalizedRoleName()
132 test.assertEqual(ans, res,
133 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
135 def test_getRelationSet(self, test):
136 root = self._cache.root
137 # Complete test of Relation interface is separate
138 rset = root.getRelationSet()
140 def test_getRole(self, test):
141 root = self._cache.root
142 test.assertEqual(root.getRole(), 69,
143 "Expected role - \"69\". Recieved - \"%d\"" % (root.getRole(),))
145 def test_getRoleName(self, test):
146 root = self._cache.root
149 res = root.getRoleName()
150 test.assertEqual(ans, res,
151 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
153 a = root.getChildAtIndex(1)
154 a = a.getChildAtIndex(0)
155 ans = "html container"
156 res = a.getRoleName()
157 test.assertEqual(ans, res,
158 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
160 def test_getState(self, test):
161 # Complete test of StateSet interface is separate
162 root = self._cache.root
163 state = root.getState()
164 list = state.getStates()
166 def test_childCount(self, test):
167 root = self._cache.root
168 test.assertEqual(root.childCount, 11,
169 "Expected role - \"11\". Recieved - \"%d\"" % (root.childCount,))
171 def test_description(self, test):
172 root = self._cache.root
173 description = "The main accessible object, root of the accessible tree"
174 test.assertEqual(root.description, description,
175 "Expected description - \"%s\". Recieved - \"%s\"" % (description, root.description,))
177 def test_tree(self, test):
179 This is a mild stress test for the
189 It checks a tree of these values is correctly
190 passed from Application to AT.
192 root = self._cache.root
194 doc = minidom.Document()
195 _createNode(root, doc)
196 answer = doc.toprettyxml()
198 correct = os.path.join(os.environ["TEST_DATA_DIRECTORY"],
199 "accessible-test-results.xml")
201 cstring = file.read()
203 test.assertEqual(answer, cstring, "Object tree not passed correctly")
205 def teardown(self, test):