2004-05-30 Seth Nickell <seth@gnome.org>
* 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 :-(
+
+2004-05-30 Seth Nickell <seth@gnome.org>
+
+ * python/dbus_bindings.pyx.in:
Add support for ObjectPath type.
if arg_type == TYPE_INVALID:
raise TypeError, 'Invalid arg type in MessageIter'
+ elif arg_type == TYPE_NIL:
+ retval = None
elif arg_type == TYPE_STRING:
retval = self.get_string()
elif arg_type == TYPE_INT32:
def get_array_type(self):
return dbus_message_iter_get_array_type(self.iter)
- def get_byte(self):
- return chr(dbus_message_iter_get_byte(self.iter))
+ # FIXME: implement get_byte
+ #def get_byte(self):
+ # return dbus_message_iter_get_byte(self.iter)
def get_boolean(self):
return dbus_message_iter_get_boolean(self.iter)
elif value_type == str:
retval = self.append_string(value)
elif value_type == list:
- if (len(list) == 0):
+ if (len(value) == 0):
raise TypeError, "Empty list"
- list_type = type(list[0])
+ list_type = type(value[0])
if list_type == str:
- self.append_string_array(list)
- elif isinstance(list[0], ObjectPath):
- self.append_object_path_array(list)
+ self.append_string_array(value)
+ elif isinstance(value[0], ObjectPath):
+ self.append_object_path_array(value)
else:
raise TypeError, "List of unknown type '%s'" % (list_type)
elif isinstance(value, ObjectPath):
return dbus_message_iter_append_dict_key(self.iter, value)
def append_object_path(self, value):
- return dbus_message_iter_append_object_path(self.iter, str(value))
+ return dbus_message_iter_append_object_path(self.iter, value)
# FIXME: append_array, append_dict_array, append_boolean_array, append_int32_array, append_uint32_array, append_double_array
item = list[i]
if not isinstance(item, ObjectPath):
raise TypeError
- value[i] = str(item)
+ value[i] = item
- return dbus_message_iter_append_object_path_array(self,iter, value, length)
+ return dbus_message_iter_append_object_path_array(self.iter, value, length)
- def append_string_array(self, list):
+ def append_string_array(self, python_list):
cdef char **value
cdef int length
- length = len(list)
+ cdef dbus_bool_t return_code
+ length = len(python_list)
value = <char**>malloc(length)
for i from 0 <= i < length:
- item = list[i]
+ item = python_list[i]
if type(item) != str:
raise TypeError
value[i] = item
if type == TYPE_INVALID:
break
+ elif type == TYPE_NIL:
+ arg = 'nil:None\n'
elif type == TYPE_STRING:
str = iter.get_string()
arg = 'string:%s\n' % (str)
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)))
-def TestEcho(value, should_be_equal = True):
+ 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)
- if type(echoed) != type(value):
- raise Exception ("Sending %s, expected echo of type %s, but got %s" % (value, type(value), type(echoed)))
+ ensure_same(value, echoed)
+
+def TestEchoList(sent_list):
+ assert(type(sent_list) == list)
+
+ global remote_object
+
+ reply_list = remote_object.Echo(sent_list)
- if echoed.__class__ != value.__class__:
- raise Exception ("Sending %s, expected echo to be of class %s, but got %s" % (value, value.__class__, echoed.__class__))
+ 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 should_be_equal:
- if echoed != value:
- raise Exception("Sending %s, expected echo to be the same, but was %s" % (value, echoed))
+ 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")
TestEcho("HelloWorld")
TestEcho(dbus_bindings.ObjectPath("/test/path"))
+#FIXME!!! Crashes on lists ?!?
+#TestEchoList(["one", "two", "three", "four"])