2008-06-02 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/upstream/at-spi2-core.git] / tests / clients / accessibleobject.py
1 import unittest
2 import testutil
3
4 import dbus
5 import gobject
6 import os.path
7 from dbus.mainloop.glib import DBusGMainLoop
8
9 from accessible_cache import AccessibleCache
10
11 from xml.dom import minidom
12
13 def createNode(accessible, parentElement):
14         e = minidom.Element("accessible")
15
16         e.attributes["name"] = accessible.name
17         e.attributes["role"] = str(int(accessible.role))
18         e.attributes["description"] = accessible.description
19
20         for i in range(0, accessible.numChildren):
21                 createNode(accessible.getChild(i), e)
22
23         parentElement.appendChild(e)
24
25 class AccessibleObjectTestCase(unittest.TestCase):
26         def setUp(self):
27                 DBusGMainLoop(set_as_default=True)
28                 self._app = testutil.runTestApp("libobjectapp.so")
29
30                 self._bus = dbus.SessionBus()
31                 self._loop = gobject.MainLoop()
32                 self._cache = AccessibleCache(self._bus, testutil.busname, testutil.objectpath)
33
34         def tearDown(self):
35                 del(self._bus)
36                 del(self._loop)
37                 del(self._cache)
38                 #TODO Shut down the test application.
39                 del(self._app)
40
41         def runTest(self):
42                 root = self._cache.getRootAccessible()
43                 doc = minidom.Document()
44                 createNode(root, doc)
45                 answer = doc.toprettyxml()
46                 correct = os.path.join(testutil.testdata, "object-test-stage1.xml")
47                 file = open(correct)
48                 cstring = file.read()
49                 self.assertEqual(answer, cstring, "Object tree not passed correctly")