diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:46:37 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:46:40 +0900 |
commit | d71148e4448b78edde9dd063d65c00a13ed27cef (patch) | |
tree | eeadb214137573fd724c40b8698eabe38f34c18a /tests/test_gi.py | |
parent | dca4e6423c560689ee831785473ad3ab48e7548a (diff) | |
download | pygobject2-d71148e4448b78edde9dd063d65c00a13ed27cef.tar.gz pygobject2-d71148e4448b78edde9dd063d65c00a13ed27cef.tar.bz2 pygobject2-d71148e4448b78edde9dd063d65c00a13ed27cef.zip |
Imported Upstream version 3.3.2
Change-Id: I655e3eb809d4970acd866fd9eebd35be45b6f79c
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests/test_gi.py')
-rw-r--r-- | tests/test_gi.py | 184 |
1 files changed, 175 insertions, 9 deletions
diff --git a/tests/test_gi.py b/tests/test_gi.py index 2b5b5a1..50b5a25 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -562,7 +562,7 @@ class TestFloat(unittest.TestCase): MIN = GObject.constants.G_MINFLOAT def test_float_return(self): - self.assertAlmostEquals(self.MAX, GIMarshallingTests.float_return()) + self.assertAlmostEqual(self.MAX, GIMarshallingTests.float_return()) def test_float_in(self): GIMarshallingTests.float_in(Number(self.MAX)) @@ -570,10 +570,10 @@ class TestFloat(unittest.TestCase): self.assertRaises(TypeError, GIMarshallingTests.float_in, "self.MAX") def test_float_out(self): - self.assertAlmostEquals(self.MAX, GIMarshallingTests.float_out()) + self.assertAlmostEqual(self.MAX, GIMarshallingTests.float_out()) def test_float_inout(self): - self.assertAlmostEquals(self.MIN, GIMarshallingTests.float_inout(Number(self.MAX))) + self.assertAlmostEqual(self.MIN, GIMarshallingTests.float_inout(Number(self.MAX))) class TestDouble(unittest.TestCase): @@ -582,7 +582,7 @@ class TestDouble(unittest.TestCase): MIN = GObject.constants.G_MINDOUBLE def test_double_return(self): - self.assertAlmostEquals(self.MAX, GIMarshallingTests.double_return()) + self.assertAlmostEqual(self.MAX, GIMarshallingTests.double_return()) def test_double_in(self): GIMarshallingTests.double_in(Number(self.MAX)) @@ -590,10 +590,10 @@ class TestDouble(unittest.TestCase): self.assertRaises(TypeError, GIMarshallingTests.double_in, "self.MAX") def test_double_out(self): - self.assertAlmostEquals(self.MAX, GIMarshallingTests.double_out()) + self.assertAlmostEqual(self.MAX, GIMarshallingTests.double_out()) def test_double_inout(self): - self.assertAlmostEquals(self.MIN, GIMarshallingTests.double_inout(Number(self.MAX))) + self.assertAlmostEqual(self.MIN, GIMarshallingTests.double_inout(Number(self.MAX))) class TestGType(unittest.TestCase): @@ -689,6 +689,9 @@ class TestArray(unittest.TestCase): def test_array_in(self): GIMarshallingTests.array_in(Sequence([-1, 0, 1, 2])) + def test_array_in_len_zero_terminated(self): + GIMarshallingTests.array_in_len_zero_terminated(Sequence([-1, 0, 1, 2])) + def test_array_uint8_in(self): GIMarshallingTests.array_uint8_in(Sequence([97, 98, 99, 100])) GIMarshallingTests.array_uint8_in(_bytes("abcd")) @@ -745,7 +748,7 @@ class TestArray(unittest.TestCase): [1, 2, 3]) def test_array_in_nonzero_nonlen(self): - GIMarshallingTests.array_in_nonzero_nonlen(1, 'abcd') + GIMarshallingTests.array_in_nonzero_nonlen(1, b'abcd') def test_array_fixed_out_struct(self): struct1, struct2 = GIMarshallingTests.array_fixed_out_struct() @@ -795,12 +798,12 @@ class TestArrayGVariant(unittest.TestCase): def test_array_gvariant_container_in(self): v = [GLib.Variant("i", 27), GLib.Variant("s", "Hello")] - returned = [GLib.Variant.unpack(r) for r in GIMarshallingTests.array_gvariant_none_in(v)] + returned = [GLib.Variant.unpack(r) for r in GIMarshallingTests.array_gvariant_container_in(v)] self.assertEqual([27, "Hello"], returned) def test_array_gvariant_full_in(self): v = [GLib.Variant("i", 27), GLib.Variant("s", "Hello")] - returned = [GLib.Variant.unpack(r) for r in GIMarshallingTests.array_gvariant_none_in(v)] + returned = [GLib.Variant.unpack(r) for r in GIMarshallingTests.array_gvariant_full_in(v)] self.assertEqual([27, "Hello"], returned) def test_bytearray_gvariant(self): @@ -1036,6 +1039,9 @@ class TestGValue(unittest.TestCase): def test_gvalue_out(self): self.assertEqual(42, GIMarshallingTests.gvalue_out()) + def test_gvalue_out_caller_allocates(self): + self.assertEqual(42, GIMarshallingTests.gvalue_out_caller_allocates()) + def test_gvalue_inout(self): self.assertEqual('42', GIMarshallingTests.gvalue_inout(42)) value = GObject.Value() @@ -1608,6 +1614,24 @@ class TestPythonGObject(unittest.TestCase): GIMarshallingTests.Object.do_method_with_default_implementation(self, int8) self.props.int += int8 + def do_vfunc_return_value_only(self): + return 4242 + + def do_vfunc_one_out_parameter(self): + return 42.42 + + def do_vfunc_multiple_out_parameters(self): + return (42.42, 3.14) + + def do_vfunc_return_value_and_one_out_parameter(self): + return (5, 42) + + def do_vfunc_return_value_and_multiple_out_parameters(self): + return (5, 42, 99) + + def do_vfunc_caller_allocated_out_parameter(self): + return 'hello' + class SubObject(GIMarshallingTests.SubObject): def __init__(self, int): GIMarshallingTests.SubObject.__init__(self) @@ -1634,6 +1658,18 @@ class TestPythonGObject(unittest.TestCase): object_.method_with_default_implementation(42) self.assertEqual(object_.props.int, 84) + self.assertEqual(object_.vfunc_return_value_only(), 4242) + self.assertAlmostEqual(object_.vfunc_one_out_parameter(), 42.42, places=5) + + (a, b) = object_.vfunc_multiple_out_parameters() + self.assertAlmostEqual(a, 42.42, places=5) + self.assertAlmostEqual(b, 3.14, places=5) + + self.assertEqual(object_.vfunc_return_value_and_one_out_parameter(), (5, 42)) + self.assertEqual(object_.vfunc_return_value_and_multiple_out_parameters(), (5, 42, 99)) + + self.assertEqual(object_.vfunc_caller_allocated_out_parameter(), 'hello') + class ObjectWithoutVFunc(GIMarshallingTests.Object): def __init__(self, int): GIMarshallingTests.Object.__init__(self) @@ -1693,6 +1729,33 @@ class TestPythonGObject(unittest.TestCase): GIMarshallingTests.SubSubObject.do_method_deep_hierarchy(sub_sub_sub_object, 5) self.assertEqual(sub_sub_sub_object.props.int, 5) + def test_python_subsubobject_vfunc(self): + class PySubObject(GIMarshallingTests.Object): + def __init__(self): + GIMarshallingTests.Object.__init__(self) + self.sub_method_int8_called = 0 + + def do_method_int8_in(self, int8): + self.sub_method_int8_called += 1 + + class PySubSubObject(PySubObject): + def __init__(self): + PySubObject.__init__(self) + self.subsub_method_int8_called = 0 + + def do_method_int8_in(self, int8): + self.subsub_method_int8_called += 1 + + so = PySubObject() + so.method_int8_in(1) + self.assertEqual(so.sub_method_int8_called, 1) + + # it should call the method on the SubSub object only + sso = PySubSubObject() + sso.method_int8_in(1) + self.assertEqual(sso.subsub_method_int8_called, 1) + self.assertEqual(sso.sub_method_int8_called, 0) + def test_callback_in_vfunc(self): class SubObject(GIMarshallingTests.Object): def __init__(self): @@ -1987,6 +2050,9 @@ class TestPropertiesObject(unittest.TestCase): self.obj.props.some_boolean = True self.assertEqual(self.obj.props.some_boolean, True) + obj = GIMarshallingTests.PropertiesObject(some_boolean=True) + self.assertEqual(obj.props.some_boolean, True) + @unittest.expectedFailure def test_char(self): # gobject-introspection thinks it has a guint8 type tag, which is @@ -1999,47 +2065,147 @@ class TestPropertiesObject(unittest.TestCase): GLib.log_set_always_fatal(old_mask) + obj = GIMarshallingTests.PropertiesObject(some_char=-42) + self.assertEqual(obj.props.some_char, -42) + def test_uchar(self): self.assertEqual(self.obj.props.some_uchar, 0) self.obj.props.some_uchar = GObject.G_MAXUINT8 self.assertEqual(self.obj.props.some_uchar, GObject.G_MAXUINT8) + obj = GIMarshallingTests.PropertiesObject(some_uchar=42) + self.assertEqual(obj.props.some_uchar, 42) + def test_int(self): self.assertEqual(self.obj.props.some_int, 0) self.obj.props.some_int = GObject.G_MAXINT self.assertEqual(self.obj.props.some_int, GObject.G_MAXINT) + obj = GIMarshallingTests.PropertiesObject(some_int=-42) + self.assertEqual(obj.props.some_int, -42) + + self.assertRaises(TypeError, setattr, self.obj.props, 'some_int', 'foo') + self.assertRaises(TypeError, setattr, self.obj.props, 'some_int', None) + + self.assertEqual(obj.props.some_int, -42) + def test_uint(self): self.assertEqual(self.obj.props.some_uint, 0) self.obj.props.some_uint = GObject.G_MAXUINT self.assertEqual(self.obj.props.some_uint, GObject.G_MAXUINT) + obj = GIMarshallingTests.PropertiesObject(some_uint=42) + self.assertEqual(obj.props.some_uint, 42) + + self.assertRaises(TypeError, setattr, self.obj.props, 'some_uint', 'foo') + self.assertRaises(TypeError, setattr, self.obj.props, 'some_uint', None) + + self.assertEqual(obj.props.some_uint, 42) + def test_long(self): self.assertEqual(self.obj.props.some_long, 0) self.obj.props.some_long = GObject.G_MAXLONG self.assertEqual(self.obj.props.some_long, GObject.G_MAXLONG) + obj = GIMarshallingTests.PropertiesObject(some_long=-42) + self.assertEqual(obj.props.some_long, -42) + + self.assertRaises(TypeError, setattr, self.obj.props, 'some_long', 'foo') + self.assertRaises(TypeError, setattr, self.obj.props, 'some_long', None) + + self.assertEqual(obj.props.some_long, -42) + def test_ulong(self): self.assertEqual(self.obj.props.some_ulong, 0) self.obj.props.some_ulong = GObject.G_MAXULONG self.assertEqual(self.obj.props.some_ulong, GObject.G_MAXULONG) + obj = GIMarshallingTests.PropertiesObject(some_ulong=42) + self.assertEqual(obj.props.some_ulong, 42) + + self.assertRaises(TypeError, setattr, self.obj.props, 'some_ulong', 'foo') + self.assertRaises(TypeError, setattr, self.obj.props, 'some_ulong', None) + + self.assertEqual(obj.props.some_ulong, 42) + def test_int64(self): self.assertEqual(self.obj.props.some_int64, 0) self.obj.props.some_int64 = GObject.G_MAXINT64 self.assertEqual(self.obj.props.some_int64, GObject.G_MAXINT64) + obj = GIMarshallingTests.PropertiesObject(some_int64=-4200000000000000) + self.assertEqual(obj.props.some_int64, -4200000000000000) + def test_uint64(self): self.assertEqual(self.obj.props.some_uint64, 0) self.obj.props.some_uint64 = GObject.G_MAXUINT64 self.assertEqual(self.obj.props.some_uint64, GObject.G_MAXUINT64) + obj = GIMarshallingTests.PropertiesObject(some_uint64=4200000000000000) + self.assertEqual(obj.props.some_uint64, 4200000000000000) + def test_float(self): self.assertEqual(self.obj.props.some_float, 0) self.obj.props.some_float = GObject.G_MAXFLOAT self.assertEqual(self.obj.props.some_float, GObject.G_MAXFLOAT) + obj = GIMarshallingTests.PropertiesObject(some_float=42.42) + self.assertAlmostEqual(obj.props.some_float, 42.42, 4) + + obj = GIMarshallingTests.PropertiesObject(some_float=42) + self.assertAlmostEqual(obj.props.some_float, 42.0, 4) + + self.assertRaises(TypeError, setattr, self.obj.props, 'some_float', 'foo') + self.assertRaises(TypeError, setattr, self.obj.props, 'some_float', None) + + self.assertAlmostEqual(obj.props.some_float, 42.0, 4) + def test_double(self): self.assertEqual(self.obj.props.some_double, 0) self.obj.props.some_double = GObject.G_MAXDOUBLE self.assertEqual(self.obj.props.some_double, GObject.G_MAXDOUBLE) + + obj = GIMarshallingTests.PropertiesObject(some_double=42.42) + self.assertAlmostEqual(obj.props.some_double, 42.42) + + obj = GIMarshallingTests.PropertiesObject(some_double=42) + self.assertAlmostEqual(obj.props.some_double, 42.0) + + self.assertRaises(TypeError, setattr, self.obj.props, 'some_double', 'foo') + self.assertRaises(TypeError, setattr, self.obj.props, 'some_double', None) + + self.assertAlmostEqual(obj.props.some_double, 42.0) + + def test_strv(self): + self.assertEqual(self.obj.props.some_strv, []) + self.obj.props.some_strv = ['hello', 'world'] + self.assertEqual(self.obj.props.some_strv, ['hello', 'world']) + + self.assertRaises(TypeError, setattr, self.obj.props, 'some_strv', 1) + self.assertRaises(TypeError, setattr, self.obj.props, 'some_strv', 'foo') + self.assertRaises(TypeError, setattr, self.obj.props, 'some_strv', [1, 2]) + self.assertRaises(TypeError, setattr, self.obj.props, 'some_strv', ['foo', 1]) + + self.assertEqual(self.obj.props.some_strv, ['hello', 'world']) + + obj = GIMarshallingTests.PropertiesObject(some_strv=['hello', 'world']) + self.assertEqual(obj.props.some_strv, ['hello', 'world']) + + def test_boxed_struct(self): + self.assertEqual(self.obj.props.some_boxed_struct, None) + + class GStrv(list): + __gtype__ = GObject.TYPE_STRV + + struct1 = GIMarshallingTests.BoxedStruct() + struct1.long_ = 1 + + self.obj.props.some_boxed_struct = struct1 + self.assertEqual(self.obj.props.some_boxed_struct.long_, 1) + self.assertEqual(self.obj.some_boxed_struct.long_, 1) + + self.assertRaises(TypeError, setattr, self.obj.props, 'some_boxed_struct', 1) + self.assertRaises(TypeError, setattr, self.obj.props, 'some_boxed_struct', 'foo') + + obj = GIMarshallingTests.PropertiesObject(some_boxed_struct=struct1) + self.assertEqual(obj.props.some_boxed_struct.long_, 1) |