mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-25 09:20:10 +01:00
* python/dbus_bindings.pyx.in: * python/tests/test-client.py: Add some more tests and fix errors that crop up. Unfortunately, currently it seems like marshalling and unmarshalling of lists is completely broken :-(
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
import dbus
|
|
import dbus_bindings
|
|
|
|
def ensure_same(expected, received):
|
|
if type(received) != type(expected):
|
|
raise Exception ("Sending %s, expected echo of type %s, but got %s" % (expected, type(expected), type(received)))
|
|
|
|
if received.__class__ != expected.__class__:
|
|
raise Exception ("Sending %s, expected echo to be of class %s, but got %s" % (expected, expected.__class__, received.__class__))
|
|
|
|
if received != expected:
|
|
raise Exception("Sending %s, expected echo to be the same, but was %s" % (expected, received))
|
|
|
|
def TestEcho(value):
|
|
global remote_object
|
|
echoed = remote_object.Echo(value)
|
|
ensure_same(value, echoed)
|
|
|
|
def TestEchoList(sent_list):
|
|
assert(type(sent_list) == list)
|
|
|
|
global remote_object
|
|
|
|
reply_list = remote_object.Echo(sent_list)
|
|
|
|
if type(reply_list) != list:
|
|
raise Exception ("Sending list %s, expected echo to be a list, but it was %s" % (sent_list, type(reply_list)))
|
|
|
|
if len(reply_list) != len(sent_list):
|
|
raise Exception ("Sending list %s, expected echo of length %d, but length was %d" % (len(sent_list), len(reply_list)))
|
|
|
|
for i in range(len(sent_list)):
|
|
ensure_same(sent_list[i], reply_list[i])
|
|
|
|
session_bus = dbus.SessionBus()
|
|
|
|
remote_service = session_bus.get_service("org.designfu.Test")
|
|
remote_object = remote_service.get_object("/TestObject", "org.designfu.Test")
|
|
|
|
TestEcho(chr(120))
|
|
TestEcho(10)
|
|
TestEcho(39.5)
|
|
TestEcho("HelloWorld")
|
|
TestEcho(dbus_bindings.ObjectPath("/test/path"))
|
|
|
|
#FIXME!!! Crashes on lists ?!?
|
|
#TestEchoList(["one", "two", "three", "four"])
|