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._registry = pyatspi.registry.Registry(self._path)
52 self._desktop = self._registry.getDesktop(0)
54 def test_name(self, test):
55 root = self._desktop.getChildAtIndex(0)
56 test.assertEqual(root.name, "main", "Expected name - \"main\". Recieved - \"%s\"" % (root.name,))
58 def test_getChildAtIndex(self, test):
59 root = self._desktop.getChildAtIndex(0)
60 a = root.getChildAtIndex(0)
61 test.assertEqual(a.name, "gnome-settings-daemon",
62 "Expected name - \"gnome-settings-daemon\". Recieved - \"%s\"" % (a.name,))
63 b = root.getChildAtIndex(1)
64 test.assertEqual(b.name, "gnome-panel",
65 "Expected name - \"gnome-panel\". Recieved - \"%s\"" % (b.name,))
66 c = root.getChildAtIndex(2)
67 test.assertEqual(c.name, "nautilus",
68 "Expected name - \"nautilus\". Recieved - \"%s\"" % (c.name,))
70 def test_isEqual(self, test):
71 root = self._desktop.getChildAtIndex(0)
73 a = root.getChildAtIndex(1)
75 test.fail("Same accessible found unequal to self")
77 b = root.getChildAtIndex(1)
79 test.fail("Similar accessibles found unequal")
81 test.fail("Similar accessibles found unequal")
83 c = root.getChildAtIndex(2)
85 test.fail("Different accessibles found equal")
87 test.fail("Different accessibles found equal")
89 def test_getApplication(self, test):
90 root = self._desktop.getChildAtIndex(0)
91 application = root.getApplication()
92 if not root.isEqual(application):
93 test.fail("Root accessible does not provide itself as its Application")
95 a = root.getChildAtIndex(1)
96 application = a.getApplication()
97 if not root.isEqual(application):
98 test.fail("Child accessible does not provide the root as its Application")
101 def test_getAttributes(self, test):
102 root = self._desktop.getChildAtIndex(0)
103 #TODO The AttributeSet test needs expanding. Check attributes are passed correctly.
104 attr = root.getAttributes()
106 def test_parent(self, test):
107 root = self._desktop.getChildAtIndex(0)
109 a = root.getChildAtIndex(1)
111 if not root.isEqual(pa):
112 test.fail("Child does not correctly report its parent")
114 def test_getIndexInParent(self, test):
115 root = self._desktop.getChildAtIndex(0)
117 for i in range(0, root.childCount):
118 child = root.getChildAtIndex(i)
119 test.assertEqual(i, child.getIndexInParent(), "Childs index in parent reported incorrectly")
121 def test_getLocalizedRoleName(self, test):
122 root = self._desktop.getChildAtIndex(0)
125 res = root.getLocalizedRoleName()
126 test.assertEqual(ans, res,
127 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
129 a = root.getChildAtIndex(1)
130 a = a.getChildAtIndex(0)
131 ans = "html container"
132 res = a.getLocalizedRoleName()
133 test.assertEqual(ans, res,
134 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
136 def test_getRelationSet(self, test):
137 root = self._desktop.getChildAtIndex(0)
138 # Complete test of Relation interface is separate
139 rset = root.getRelationSet()
141 def test_getRole(self, test):
142 root = self._desktop.getChildAtIndex(0)
143 test.assertEqual(root.getRole(), 69,
144 "Expected role - \"69\". Recieved - \"%d\"" % (root.getRole(),))
146 def test_getRoleName(self, test):
147 root = self._desktop.getChildAtIndex(0)
150 res = root.getRoleName()
151 test.assertEqual(ans, res,
152 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
154 a = root.getChildAtIndex(1)
155 a = a.getChildAtIndex(0)
156 ans = "html container"
157 res = a.getRoleName()
158 test.assertEqual(ans, res,
159 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
161 def test_getState(self, test):
162 # Complete test of StateSet interface is separate
163 root = self._desktop.getChildAtIndex(0)
164 state = root.getState()
165 list = state.getStates()
167 def test_childCount(self, test):
168 root = self._desktop.getChildAtIndex(0)
169 test.assertEqual(root.childCount, 11,
170 "Expected role - \"11\". Recieved - \"%d\"" % (root.childCount,))
172 def test_description(self, test):
173 root = self._desktop.getChildAtIndex(0)
174 description = "The main accessible object, root of the accessible tree"
175 test.assertEqual(root.description, description,
176 "Expected description - \"%s\". Recieved - \"%s\"" % (description, root.description,))
178 def test_tree(self, test):
180 This is a mild stress test for the
190 It checks a tree of these values is correctly
191 passed from Application to AT.
193 root = self._desktop.getChildAtIndex(0)
195 doc = minidom.Document()
196 _createNode(root, doc)
197 answer = doc.toprettyxml()
199 correct = os.path.join(os.environ["TEST_DATA_DIRECTORY"],
200 "accessible-test-results.xml")
202 cstring = file.read()
204 test.assertEqual(answer, cstring, "Object tree not passed correctly")
206 def teardown(self, test):