2008-06-13 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tests / clients / componenttest.py
1 import testutil
2
3 import dbus
4 import gobject
5 import os.path
6 import coretest
7 from dbus.mainloop.glib import DBusGMainLoop
8
9 from accessible_cache import AccessibleCache
10 from accessible_cache import ATSPI_COMPONENT
11
12 from xml.dom import minidom
13
14 ATSPI_LAYER_WIDGET = 3
15 ATSPI_LAYER_MDI = 4
16 ATSPI_LAYER_WINDOW = 7
17
18 extents_expected = [(0,0,30,20), (40,30,30,40), (0,0,70,70)]
19 layers_expected = [ATSPI_LAYER_WINDOW, ATSPI_LAYER_WIDGET, ATSPI_LAYER_MDI]
20 zorders_expected = [0, -100, 100]
21
22 def supportsInterface(accessible, interface):
23         for itf in accessible.interfaces:
24                 if itf == interface:
25                         return True
26         return False
27
28 class ComponentTestCase(coretest.CoreTestCase):
29         def runTest(self):
30                 self._app = testutil.runTestApp("libcomponentapp.so", self._name)
31                 self._loop.run()
32
33         def post_application_test(self):
34                 #----------------------------------------
35                 comps = [None, None, None]
36                 comps[2] = self._cache.getRootAccessible()
37
38                 self.assertEqual(comps[2].numChildren, 2,
39                 """
40                 Number of child components = %d
41                 Correct number of components = 2
42                 """ % comps[2].numChildren)
43                 #----------------------------------------
44                 comps[0] = comps[2].getChild(0)
45                 comps[1] = comps[2].getChild(1)
46
47                 for comp in comps:
48                         self.assert_(supportsInterface(comp, ATSPI_COMPONENT),
49                                 """
50                                 An accessible object provided does not support the
51                                 component interface.
52                                 """)
53                 #----------------------------------------
54                 for (expected, comp) in zip(extents_expected, comps):
55                         extents = comp.getExtents(dbus.types.UInt32(0))
56                         self.assertEquals(extents, expected,
57                                         """
58                                         Extents of component do not match.
59                                         Expected: %s
60                                         Recieved: %s
61                                         """ % (str(expected), str(extents)))
62                 #----------------------------------------
63                 for (expected, comp) in zip(layers_expected, comps):
64                         layer = comp.getLayer()
65                         self.assertEquals(layer, expected,
66                                         """
67                                         Layer of component does not match.
68                                         Expected: %s
69                                         Recieved: %s
70                                         """ % (str(expected), str(layer)))
71                 #----------------------------------------
72                 #There is no defined value for the result when the layer is not WINDOW or MDI
73                 #for (expected, comp) in zip(zorders_expected, [comps[0], comps[2]]):
74                 #       zorder = comp.getMDIZOrder()
75                 #       print zorder, expected
76                 #       self.assertEquals(layer, expected,
77                 #                       """
78                 #                       ZOrder of component does not match.
79                 #                       Expected: %s
80                 #                       Recieved: %s
81                 #                       """ % (str(expected), str(zorder)))
82                 #----------------------------------------