2008-08-15 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tests / pyatspi / accessibletest.py
1 import dbus
2 import gobject
3 import os.path
4
5 from xml.dom import minidom
6 import os
7
8 from pasytest import PasyTest as _PasyTest
9
10 import pyatspi
11
12 def _createNode(accessible, parentElement):
13         e = minidom.Element("accessible")
14
15         e.attributes["name"] = accessible.name
16         e.attributes["role"] = str(int(accessible.getRole()))
17         e.attributes["description"] = accessible.description
18
19         for i in range(0, accessible.childCount):
20                 _createNode(accessible.getChildAtIndex(i), e)
21
22         parentElement.appendChild(e)
23
24 class AccessibleTest(_PasyTest):
25
26         __tests__ = ["setup", "tree"]
27
28         def __init__(self, bus, path):
29                 _PasyTest.__init__(self, "Accessible", False)
30                 self._bus = bus
31                 self._path = path
32
33         def setup(self):
34                 self._cache = pyatspi.TestApplicationCache(self._bus, self._path)
35
36         def tree(self):
37                 """
38                 This is a mild stress test for the 
39                 methods:
40
41                 getChildAtIndex
42                 
43                 And the attributes:
44
45                 name
46                 description
47
48                 It checks a tree of these values is correctly
49                 passed from Application to AT.
50                 """
51                 root = self._cache.root
52
53                 doc = minidom.Document()
54                 _createNode(root, doc)
55                 answer = doc.toprettyxml()
56
57                 correct = os.path.join(os.environ["TEST_DATA_DIRECTORY"],
58                                         "object-test-stage1-results.xml")
59                 file = open(correct)
60                 cstring = file.read()
61                 
62                 self.assertEqual(answer, cstring, "Object tree not passed correctly")