2008-06-13 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tests / clients / coretest.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 from random import randint
11
12
13
14 class CoreTestCase(unittest.TestCase):
15         def setUp(self):
16                 DBusGMainLoop(set_as_default=True)
17
18                 self._bus = dbus.SessionBus()
19                 self._loop = gobject.MainLoop()
20                 self._name = "test.atspi.R" + str(randint(1, 1000)) 
21                 self._match = self._bus.add_signal_receiver(self.post_application_setup,
22                                                         "started",
23                                                         "org.codethink.atspi.test",
24                                                         self._name)
25                 self._started = False
26
27                 if "TEST_APP_WAIT_FOR_DEBUG" not in os.environ.keys():
28                         gobject.timeout_add(1000, self.application_check)
29
30         def tearDown(self):
31                 #Shut down the test application
32                 self._test.finished()
33
34                 del(self._bus)
35                 del(self._loop)
36                 del(self._cache)
37                 del(self._app)
38                 del(self._test)
39
40         def application_check(self):
41                 if not self._started:
42                         self.fail("Test application did not start")
43
44         def post_application_setup(self):
45                 self._started = True
46
47                 self._cache = AccessibleCache(self._bus, self._name, "/org/freedesktop/atspi/tree")
48
49                 test_object = self._bus.get_object(self._name, "/org/codethink/atspi/test")
50                 self._test = dbus.Interface(test_object, "org.codethink.atspi.test")
51
52                 self.post_application_test()
53
54                 self._loop.quit()
55
56         def post_application_test(self):
57                 raise  Exception, "No test has been defined"