2008-07-28 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tests / pyatspi / testrunner.py
1 #!/usr/bin/python
2
3 import dbus
4 import sys
5 import time
6 from random import randint
7
8 def runTestApp(module_name, dbus_name=None):
9         import os
10         from subprocess import Popen
11
12         test_data_directory = os.environ["TEST_DATA_DIRECTORY"]
13         test_modules_directory = os.environ["TEST_MODULES_DIRECTORY"]
14         test_atspi_library = os.environ["TEST_ATSPI_LIBRARY"]
15         test_application = os.environ["TEST_APPLICATION"]
16
17         test_module = os.path.join(test_modules_directory, module_name)
18
19         if (dbus_name):
20                 print " ".join([test_application,
21                         "--atspi-dbus-name", dbus_name,
22                         "--test-atspi-library", test_atspi_library,
23                         "--test-module", test_module,
24                         "--test-data-directory", test_data_directory,])
25                 pop = Popen([test_application,
26                         "--atspi-dbus-name", dbus_name,
27                         "--test-atspi-library", test_atspi_library,
28                         "--test-module", test_module,
29                         "--test-data-directory", test_data_directory,])
30         else:
31                 print " ".join([test_application,
32                         "--test-atspi-library", test_atspi_library,
33                         "--test-module", test_module,
34                         "--test-data-directory", test_data_directory,])
35                 pop = Popen([test_application,
36                         "--test-atspi-library", test_atspi_library,
37                         "--test-module", test_module,
38                         "--test-data-directory", test_data_directory,])
39
40         wait_message = """
41         The test application %s has been started with PID %d.
42         
43         To continue the test press ENTER.\n\n
44         """
45         if ("TEST_APP_WAIT_FOR_DEBUG" in os.environ.keys()):
46                 raw_input(wait_message % (module_name, pop.pid))
47
48 def main(argv):
49         testModule = argv[1]
50
51         # TODO Modify this function to add registryd as an option
52         bus = dbus.SessionBus()
53         name = "test.atspi.R" + str(randint(1, 1000)) 
54
55         app = runTestApp(testModule, name)
56         # Wait a little time for the app to start up
57         # TODO connect this up to the apps start signal
58         time.sleep(1)
59
60         to = bus.get_object(name, "/org/codethink/atspi/test")
61         test = dbus.Interface(to, "org.codethink.atspi.test")
62
63         # Run the test script here FIXME
64
65         # Inform the test app it can shut down.
66         test.finish()
67
68 if __name__=="__main__":
69         sys.exit(main(sys.argv))