2004-05-30 05:30:09 +00:00
|
|
|
import dbus
|
|
|
|
|
|
2004-05-30 06:21:00 +00:00
|
|
|
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)))
|
2004-05-30 05:30:09 +00:00
|
|
|
|
2004-05-30 06:21:00 +00:00
|
|
|
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):
|
2004-05-30 05:30:09 +00:00
|
|
|
global remote_object
|
|
|
|
|
echoed = remote_object.Echo(value)
|
2004-05-30 06:21:00 +00:00
|
|
|
ensure_same(value, echoed)
|
|
|
|
|
|
|
|
|
|
def TestEchoList(sent_list):
|
|
|
|
|
assert(type(sent_list) == list)
|
|
|
|
|
|
|
|
|
|
global remote_object
|
|
|
|
|
|
|
|
|
|
reply_list = remote_object.Echo(sent_list)
|
2004-05-30 05:30:09 +00:00
|
|
|
|
2004-05-30 06:21:00 +00:00
|
|
|
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)))
|
2004-05-30 05:30:09 +00:00
|
|
|
|
2004-05-30 06:21:00 +00:00
|
|
|
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)))
|
2004-05-30 05:30:09 +00:00
|
|
|
|
2004-05-30 06:21:00 +00:00
|
|
|
for i in range(len(sent_list)):
|
|
|
|
|
ensure_same(sent_list[i], reply_list[i])
|
2004-06-01 06:13:31 +00:00
|
|
|
|
|
|
|
|
def TestEchoDict(sent_dict):
|
|
|
|
|
assert(type(sent_dict) == dict)
|
|
|
|
|
|
|
|
|
|
global remote_object
|
|
|
|
|
|
|
|
|
|
reply_dict = remote_object.Echo(sent_dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert(type(reply_dict) == dict)
|
|
|
|
|
|
|
|
|
|
assert(len(reply_dict) == len(sent_dict))
|
|
|
|
|
|
|
|
|
|
for key in sent_dict.keys():
|
|
|
|
|
ensure_same(reply_dict[key], sent_dict[key])
|
2004-05-30 06:21:00 +00:00
|
|
|
|
2004-05-30 05:30:09 +00:00
|
|
|
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")
|
2004-07-18 21:44:37 +00:00
|
|
|
TestEcho(dbus.ObjectPath("/test/path"))
|
|
|
|
|
TestEcho(dbus.ByteArray("blahblahblah"))
|
2004-06-01 01:20:59 +00:00
|
|
|
|
|
|
|
|
string_list = []
|
|
|
|
|
for i in range(200):
|
|
|
|
|
string_list.append("List item " + str(i))
|
|
|
|
|
TestEchoList(string_list)
|
|
|
|
|
|
|
|
|
|
int_list = range(200)
|
|
|
|
|
TestEchoList(int_list)
|
|
|
|
|
|
|
|
|
|
path_list = []
|
|
|
|
|
for i in range(200):
|
2004-07-18 21:44:37 +00:00
|
|
|
path_list.append(dbus.ObjectPath("/some/object/path" + str(i)))
|
2004-06-01 01:20:59 +00:00
|
|
|
TestEchoList(path_list)
|
|
|
|
|
|
|
|
|
|
double_list = []
|
|
|
|
|
for i in range(200):
|
|
|
|
|
double_list.append(float(i) / 1000)
|
|
|
|
|
TestEchoList(double_list)
|
2004-06-01 06:13:31 +00:00
|
|
|
|
|
|
|
|
#FIXME: this currently fails!
|
|
|
|
|
#empty_list = []
|
|
|
|
|
#TestEchoList(empty_list)
|
|
|
|
|
|
|
|
|
|
string_to_int_dict = {}
|
|
|
|
|
for i in range(200):
|
|
|
|
|
string_to_int_dict["key" + str(i)] = i
|
|
|
|
|
TestEchoDict(string_to_int_dict)
|
|
|
|
|
|
|
|
|
|
string_to_double_dict = {}
|
|
|
|
|
for i in range(200):
|
|
|
|
|
string_to_double_dict["key" + str(i)] = float(i) / 1000
|
|
|
|
|
TestEchoDict(string_to_double_dict)
|
|
|
|
|
|
|
|
|
|
string_to_string_dict = {}
|
|
|
|
|
for i in range(200):
|
|
|
|
|
string_to_string_dict["key" + str(i)] = "value" + str(i)
|
|
|
|
|
TestEchoDict(string_to_string_dict)
|
|
|
|
|
|
|
|
|
|
#FIXME: this currently crashes dbus in c code
|
|
|
|
|
#empty_dict = {}
|
|
|
|
|
#TestEchoDict(empty_dict)
|