summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRobert McQueen <robot101@debian.org>2005-10-29 19:13:17 +0000
committerRobert McQueen <robot101@debian.org>2005-10-29 19:13:17 +0000
commit20bcbaf21f4e94c48d6348a4ba8013d20f9e4d36 (patch)
treecf690b655da24bcd25d678bdd178d42064934258 /test
parent2d74492ba2c61a41d9d22a8872806a8184acef16 (diff)
2005-10-29 Robert McQueen <robot101@debian.org>
* python/decorators.py: Add optional arguments to the method and signal decorators to allow you to specify the signature of arguments and return values. Preserve the doc strings of signal functions in the decorated version, for pydoc and friends. * python/dbus_bindings.pyx, python/proxies.py: Replace the parse_signature_block function with an iterable dbus.Signature() type. Fix a bug in MessageIter.append_strict where you could append anything by claiming it was a string. * python/service.py: Use the out_signature decoration on methods to marshal return values, meaning you no longer require dbus.Array() or dbus.Dictionary() to indicate the type when returning empty arrays or dictionaries. Fix a bug where exceptions which are defined in __main__ are not turned into error replies. * test/python/test-client.py, test/python/test-service.py: Add test for correct marshalling of return values according to out_signature. Fix a bug in the async call test where the error_handler is missing a self argument.
Diffstat (limited to 'test')
-rwxr-xr-xtest/python/test-client.py41
-rwxr-xr-xtest/python/test-service.py36
2 files changed, 76 insertions, 1 deletions
diff --git a/test/python/test-client.py b/test/python/test-client.py
index 3cc1542b..699bdc45 100755
--- a/test/python/test-client.py
+++ b/test/python/test-client.py
@@ -88,7 +88,7 @@ class TestDBusBindings(unittest.TestCase):
self.test_controler.assertEquals(val, self.expected_result)
- def error_handler(error):
+ def error_handler(self, error):
print error
if self.do_exit:
main_loop.quit()
@@ -105,6 +105,45 @@ class TestDBusBindings(unittest.TestCase):
main_loop.run()
+ def testReturnMarshalling(self):
+ print "\n********* Testing return marshalling ***********"
+
+ # these values are the same as in the server, and the
+ # methods should only succeed when they are called with
+ # the right value number, because they have out_signature
+ # decorations, and return an unmatching type when called
+ # with a different number
+ values = ["", ("",""), ("","",""), [], {}, ["",""], ["","",""]]
+ methods = [
+ (self.iface.ReturnOneString, set([0]), set([0])),
+ (self.iface.ReturnTwoStrings, set([1, 5]), set([5])),
+ (self.iface.ReturnStruct, set([1, 5]), set([1])),
+ # all of our test values are sequences so will marshall correctly into an array :P
+ (self.iface.ReturnArray, set(range(len(values))), set([3, 5, 6])),
+ (self.iface.ReturnDict, set([0, 3, 4]), set([4]))
+ ]
+
+ for (method, success_values, return_values) in methods:
+ print "\nTrying correct behaviour of", method._method_name
+ for value in range(len(values)):
+ try:
+ ret = method(value)
+ except Exception, e:
+ print "%s(%s) raised %s" % (method._method_name, repr(values[value]), e.__class__)
+
+ # should fail if it tried to marshal the wrong type
+ self.assert_(value not in success_values, "%s should succeed when we ask it to return %s\n%s" % (method._method_name, repr(values[value]), e))
+ else:
+ print "%s(%s) returned %s" % (method._method_name, repr(values[value]), repr(ret))
+
+ # should only succeed if it's the right return type
+ self.assert_(value in success_values, "%s should fail when we ask it to return %s" % (method._method_name, repr(values[value])))
+
+ # check the value is right too :D
+ returns = map(lambda n: values[n], return_values)
+ self.assert_(ret in returns, "%s should return one of %s" % (method._method_name, repr(returns)))
+ print
+
class TestDBusPythonToGLibBindings(unittest.TestCase):
def setUp(self):
self.bus = dbus.SessionBus()
diff --git a/test/python/test-service.py b/test/python/test-service.py
index 36c2df7c..3686480f 100755
--- a/test/python/test-service.py
+++ b/test/python/test-service.py
@@ -36,6 +36,42 @@ class TestObject(dbus.service.Object):
return dbus.Array(ret, signature="(uus)")
+ def returnValue(self, test):
+ if test == 0:
+ return ""
+ elif test == 1:
+ return "",""
+ elif test == 2:
+ return "","",""
+ elif test == 3:
+ return []
+ elif test == 4:
+ return {}
+ elif test == 5:
+ return ["",""]
+ elif test == 6:
+ return ["","",""]
+
+ @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='s')
+ def ReturnOneString(self, test):
+ return self.returnValue(test)
+
+ @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='ss')
+ def ReturnTwoStrings(self, test):
+ return self.returnValue(test)
+
+ @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='(ss)')
+ def ReturnStruct(self, test):
+ return self.returnValue(test)
+
+ @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='as')
+ def ReturnArray(self, test):
+ return self.returnValue(test)
+
+ @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface", in_signature='u', out_signature='a{ss}')
+ def ReturnDict(self, test):
+ return self.returnValue(test)
+
session_bus = dbus.SessionBus()
name = dbus.service.BusName("org.freedesktop.DBus.TestSuitePythonService", bus=session_bus)
object = TestObject(name)