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):
103 def test_parent(self, test):
104 root = self._cache.root
106 a = root.getChildAtIndex(1)
108 if not root.isEqual(pa):
109 test.fail("Child does not correctly report its parent")
111 def test_getIndexInParent(self, test):
112 root = self._cache.root
114 for i in range(0, root.childCount):
115 child = root.getChildAtIndex(i)
116 test.assertEqual(i, child.getIndexInParent(), "Childs index in parent reported incorrectly")
118 def test_getLocalizedRoleName(self, test):
119 root = self._cache.root
122 res = root.getLocalizedRoleName()
123 test.assertEqual(ans, res,
124 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
126 a = root.getChildAtIndex(1)
127 a = a.getChildAtIndex(0)
129 res = a.getLocalizedRoleName()
130 test.assertEqual(ans, res,
131 "Expected LocalizedRoleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
133 def test_getRelationSet(self, test):
136 def test_getRole(self, test):
137 root = self._cache.root
138 test.assertEqual(root.getRole(), 69,
139 "Expected role - \"69\". Recieved - \"%d\"" % (root.getRole(),))
141 def test_getRoleName(self, test):
142 root = self._cache.root
145 res = root.getRoleName()
146 test.assertEqual(ans, res,
147 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
149 a = root.getChildAtIndex(1)
150 a = a.getChildAtIndex(0)
152 res = a.getRoleName()
153 test.assertEqual(ans, res,
154 "Expected roleName - \"%s\". Recieved - \"%s\"" % (ans, res,))
156 def test_getState(self, test):
157 # Complete test of StateSet interface is separate
158 root = self._cache.root
159 state = root.getState()
160 list = state.getStates()
162 def test_childCount(self, test):
163 root = self._cache.root
164 test.assertEqual(root.childCount, 11,
165 "Expected role - \"11\". Recieved - \"%d\"" % (root.childCount,))
167 def test_description(self, test):
168 root = self._cache.root
169 description = "The main accessible object, root of the accessible tree"
170 test.assertEqual(root.description, description,
171 "Expected description - \"%s\". Recieved - \"%s\"" % (description, root.description,))
173 def test_tree(self, test):
175 This is a mild stress test for the
185 It checks a tree of these values is correctly
186 passed from Application to AT.
188 root = self._cache.root
190 doc = minidom.Document()
191 _createNode(root, doc)
192 answer = doc.toprettyxml()
194 correct = os.path.join(os.environ["TEST_DATA_DIRECTORY"],
195 "object-test-stage1-results.xml")
197 cstring = file.read()
199 test.assertEqual(answer, cstring, "Object tree not passed correctly")
201 def teardown(self, test):