7 builddir = os.environ["DBUS_TOP_BUILDDIR"]
8 pydir = builddir + "/python"
10 sys.path.insert(0, pydir)
11 sys.path.insert(0, pydir + "/.libs")
18 if not dbus.__file__.startswith(pydir):
19 raise Exception("DBus modules are not being picked up from the package")
21 if not dbus_bindings.__file__.startswith(pydir):
22 raise Exception("DBus modules are not being picked up from the package")
24 test_types_vals = [1, 12323231, 3.14159265, 99999999.99,
25 "dude", "123", "What is all the fuss about?", "gob@gob.com",
26 [1,2,3], ["how", "are", "you"], [1.23,2.3], [1], ["Hello"],
27 (1,2,3), (1,), (1,"2",3), ("2", "what"), ("you", 1.2),
28 {1:"a", 2:"b"}, {"a":1, "b":2}, {1:1.1, 2:2.2}, {1.1:"a", 1.2:"b"},
29 [[1,2,3],[2,3,4]], [["a","b"],["c","d"]],
30 ([1,2,3],"c", 1.2, ["a","b","c"], {"a": (1,"v"), "b": (2,"d")})
33 class TestDBusBindings(unittest.TestCase):
35 self.bus = dbus.SessionBus()
36 self.remote_object = self.bus.get_object("org.freedesktop.DBus.TestSuitePythonService", "/org/freedesktop/DBus/TestSuitePythonObject")
37 self.iface = dbus.Interface(self.remote_object, "org.freedesktop.DBus.TestSuiteInterface")
39 def testInterfaceKeyword(self):
40 #test dbus_interface parameter
41 print self.remote_object.Echo("dbus_interface on Proxy test Passed", dbus_interface = "org.freedesktop.DBus.TestSuiteInterface")
42 print self.iface.Echo("dbus_interface on Interface test Passed", dbus_interface = "org.freedesktop.DBus.TestSuiteInterface")
45 def testIntrospection(self):
47 print "\n********* Introspection Test ************"
48 print self.remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
49 print "Introspection test passed"
52 def testPythonTypes(self):
53 #test sending python types and getting them back
54 print "\n********* Testing Python Types ***********"
56 for send_val in test_types_vals:
57 print "Testing %s"% str(send_val)
58 recv_val = self.iface.Echo(send_val)
59 self.assertEquals(send_val, recv_val)
61 def testBenchmarkIntrospect(self):
62 print "\n********* Benchmark Introspect ************"
65 print self.iface.GetComplexArray()
68 print "Delta: %f" % (b - a)
71 def testAsyncCalls(self):
72 #test sending python types and getting them back async
73 print "\n********* Testing Async Calls ***********"
76 main_loop = gobject.MainLoop()
78 def __init__(self, test_controler, expected_result, do_exit):
79 self.expected_result = expected_result
80 self.do_exit = do_exit
81 self.test_controler = test_controler
83 def callback(self, val):
87 self.test_controler.assertEquals(val, self.expected_result)
89 def error_handler(error):
94 self.test_controler.assert_(val, False)
96 last_type = test_types_vals[-1]
97 for send_val in test_types_vals:
98 print "Testing %s"% str(send_val)
99 check = async_check(self, send_val, last_type == send_val)
100 recv_val = self.iface.Echo(send_val,
101 reply_handler = check.callback,
102 error_handler = check.error_handler)
106 class TestDBusPythonToGLibBindings(unittest.TestCase):
108 self.bus = dbus.SessionBus()
109 self.remote_object = self.bus.get_object("org.freedesktop.DBus.TestSuiteGLibService", "/org/freedesktop/DBus/Tests/MyTestObject")
110 self.iface = dbus.Interface(self.remote_object, "org.freedesktop.DBus.Tests.MyObject")
112 def testIntrospection(self):
114 print "\n********* Introspection Test ************"
115 print self.remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
116 print "Introspection test passed"
120 print "\n********* Call Test ************"
121 result = self.iface.ManyArgs(1000, 'Hello GLib', 2)
123 self.assert_(result == [2002.0, 'HELLO GLIB'])
125 arg0 = {"Dude": 1, "john": "palmieri", "python": 2.4}
126 result = self.iface.ManyStringify(arg0)
129 print "Call test passed"
132 #this crashes glib so disable it for now
135 def testPythonTypes(self):
136 print "\n********* Testing Python Types ***********"
138 for send_val in test_types_vals:
139 print "Testing %s"% str(send_val)
140 recv_val = self.iface.EchoVariant(send_val)
141 self.assertEquals(send_val, recv_val)
144 if __name__ == '__main__':
145 gobject.threads_init()
146 dbus.glib.init_threads()