summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:47:26 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-07-12 08:47:30 +0900
commitebea54329faf26980be8b128426e354864803e0a (patch)
tree2b659ec6011ec741841ad95be8d476554a80a277 /tests
parent845babcb58537b5d2bceb8ab9947e3420415b76f (diff)
downloadpygobject2-ebea54329faf26980be8b128426e354864803e0a.tar.gz
pygobject2-ebea54329faf26980be8b128426e354864803e0a.tar.bz2
pygobject2-ebea54329faf26980be8b128426e354864803e0a.zip
Imported Upstream version 3.3.92
Change-Id: I46cd4f47124a3743c33c40b56712ebb0febdb789 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_everything.py55
-rw-r--r--tests/test_gi.py21
-rw-r--r--tests/test_properties.py90
-rw-r--r--tests/test_signal.py174
-rw-r--r--tests/testhelpermodule.c67
5 files changed, 311 insertions, 96 deletions
diff --git a/tests/test_everything.py b/tests/test_everything.py
index c5140ed..243e770 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -690,9 +690,64 @@ class TestSignals(unittest.TestCase):
def callback(obj, obj_param):
self.assertEqual(obj_param.props.int, 3)
self.assertGreater(obj_param.__grefcount__, 1)
+ obj.called = True
+ obj.called = False
obj.connect('sig-with-obj', callback)
obj.emit_sig_with_obj()
+ self.assertTrue(obj.called)
+
+ def test_int64_param_from_py(self):
+ obj = Everything.TestObj()
+
+ def callback(obj, i):
+ obj.callback_i = i
+ return i
+
+ obj.callback_i = None
+ obj.connect('sig-with-int64-prop', callback)
+ rv = obj.emit('sig-with-int64-prop', GObject.G_MAXINT64)
+ self.assertEqual(rv, GObject.G_MAXINT64)
+ self.assertEqual(obj.callback_i, GObject.G_MAXINT64)
+
+ def test_uint64_param_from_py(self):
+ obj = Everything.TestObj()
+
+ def callback(obj, i):
+ obj.callback_i = i
+ return i
+
+ obj.callback_i = None
+ obj.connect('sig-with-uint64-prop', callback)
+ rv = obj.emit('sig-with-uint64-prop', GObject.G_MAXUINT64)
+ self.assertEqual(rv, GObject.G_MAXUINT64)
+ self.assertEqual(obj.callback_i, GObject.G_MAXUINT64)
+
+ def test_int64_param_from_c(self):
+ obj = Everything.TestObj()
+
+ def callback(obj, i):
+ obj.callback_i = i
+ return i
+
+ obj.callback_i = None
+
+ obj.connect('sig-with-int64-prop', callback)
+ obj.emit_sig_with_int64()
+ self.assertEqual(obj.callback_i, GObject.G_MAXINT64)
+
+ def test_uint64_param_from_c(self):
+ obj = Everything.TestObj()
+
+ def callback(obj, i):
+ obj.callback_i = i
+ return i
+
+ obj.callback_i = None
+
+ obj.connect('sig-with-uint64-prop', callback)
+ obj.emit_sig_with_uint64()
+ self.assertEqual(obj.callback_i, GObject.G_MAXUINT64)
class TestPango(unittest.TestCase):
diff --git a/tests/test_gi.py b/tests/test_gi.py
index c22a488..ea58547 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1042,9 +1042,18 @@ class TestGValue(unittest.TestCase):
value.set_int(42)
GIMarshallingTests.gvalue_in(value)
+ def test_gvalue_int64_in(self):
+ value = GObject.Value()
+ value.init(GObject.TYPE_INT64)
+ value.set_int64(GObject.G_MAXINT64)
+ GIMarshallingTests.gvalue_int64_in(value)
+
def test_gvalue_out(self):
self.assertEqual(42, GIMarshallingTests.gvalue_out())
+ def test_gvalue_int64_out(self):
+ self.assertEqual(GObject.G_MAXINT64, GIMarshallingTests.gvalue_int64_out())
+
def test_gvalue_out_caller_allocates(self):
self.assertEqual(42, GIMarshallingTests.gvalue_out_caller_allocates())
@@ -2385,3 +2394,15 @@ class TestProjectVersion(unittest.TestCase):
self.assertRaises(ValueError, gi.check_version, "99.0.0")
gi.check_version((3, 3, 5))
gi.check_version("3.3.5")
+
+
+class TestObjectInfo(unittest.TestCase):
+ def test_get_abstract_with_abstract(self):
+ repo = gi.gi.Repository.get_default()
+ info = repo.find_by_name('GObject', 'TypeModule')
+ self.assertTrue(info.get_abstract())
+
+ def test_get_abstract_with_concrete(self):
+ repo = gi.gi.Repository.get_default()
+ info = repo.find_by_name('GObject', 'Object')
+ self.assertFalse(info.get_abstract())
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 2b77d28..405375d 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -60,26 +60,26 @@ class PropertyObject(GObject.GObject):
type=TYPE_STRV, flags=PARAM_READWRITE | PARAM_CONSTRUCT)
-class TestProperties(unittest.TestCase):
- def testGetSet(self):
+class TestPropertyObject(unittest.TestCase):
+ def test_get_set(self):
obj = PropertyObject()
obj.props.normal = "value"
self.assertEqual(obj.props.normal, "value")
- def testListWithInstance(self):
+ def test_hasattr_on_object(self):
obj = PropertyObject()
self.assertTrue(hasattr(obj.props, "normal"))
- def testListWithoutInstance(self):
+ def test_hasattr_on_class(self):
self.assertTrue(hasattr(PropertyObject.props, "normal"))
- def testSetNoInstance(self):
+ def test_set_on_class(self):
def set(obj):
obj.props.normal = "foobar"
self.assertRaises(TypeError, set, PropertyObject)
- def testIterator(self):
+ def test_iteration(self):
for obj in (PropertyObject.props, PropertyObject().props):
for pspec in obj:
gtype = GType(pspec)
@@ -95,7 +95,7 @@ class TestProperties(unittest.TestCase):
'boxed'])
self.assertEqual(len(obj), 9)
- def testNormal(self):
+ def test_normal(self):
obj = new(PropertyObject, normal="123")
self.assertEqual(obj.props.normal, "123")
obj.set_property('normal', '456')
@@ -103,7 +103,7 @@ class TestProperties(unittest.TestCase):
obj.props.normal = '789'
self.assertEqual(obj.props.normal, "789")
- def testConstruct(self):
+ def test_construct(self):
obj = new(PropertyObject, construct="123")
self.assertEqual(obj.props.construct, "123")
obj.set_property('construct', '456')
@@ -111,7 +111,7 @@ class TestProperties(unittest.TestCase):
obj.props.construct = '789'
self.assertEqual(obj.props.construct, "789")
- def testUTF8(self):
+ def test_utf8(self):
obj = new(PropertyObject, construct_only=UNICODE_UTF8)
self.assertEqual(obj.props.construct_only, TEST_UTF8)
obj.set_property('construct', UNICODE_UTF8)
@@ -119,7 +119,7 @@ class TestProperties(unittest.TestCase):
obj.props.normal = UNICODE_UTF8
self.assertEqual(obj.props.normal, TEST_UTF8)
- def testIntToStr(self):
+ def test_int_to_str(self):
obj = new(PropertyObject, construct_only=1)
self.assertEqual(obj.props.construct_only, '1')
obj.set_property('construct', '2')
@@ -127,7 +127,7 @@ class TestProperties(unittest.TestCase):
obj.props.normal = 3
self.assertEqual(obj.props.normal, '3')
- def testConstructOnly(self):
+ def test_construct_only(self):
obj = new(PropertyObject, construct_only="123")
self.assertEqual(obj.props.construct_only, "123")
self.assertRaises(TypeError,
@@ -135,7 +135,7 @@ class TestProperties(unittest.TestCase):
self.assertRaises(TypeError,
obj.set_property, 'construct-only', '456')
- def testUint64(self):
+ def test_uint64(self):
obj = new(PropertyObject)
self.assertEqual(obj.props.uint64, 0)
obj.props.uint64 = _long(1)
@@ -146,7 +146,7 @@ class TestProperties(unittest.TestCase):
self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", _long(-1))
self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", -1)
- def testUInt64DefaultValue(self):
+ def test_uint64_default_value(self):
try:
class TimeControl(GObject.GObject):
__gproperties__ = {
@@ -158,7 +158,7 @@ class TestProperties(unittest.TestCase):
(etype, ex) = sys.exc_info()[2:]
self.fail(str(ex))
- def testEnum(self):
+ def test_enum(self):
obj = new(PropertyObject)
self.assertEqual(obj.props.enum, Gio.SocketType.STREAM)
self.assertEqual(obj.enum, Gio.SocketType.STREAM)
@@ -186,7 +186,7 @@ class TestProperties(unittest.TestCase):
self.assertRaises(TypeError, GObject.Property, type=Gio.SocketType,
default=1)
- def testFlags(self):
+ def test_flags(self):
obj = new(PropertyObject)
self.assertEqual(obj.props.flags, GIMarshallingTests.Flags.VALUE1)
self.assertEqual(obj.flags, GIMarshallingTests.Flags.VALUE1)
@@ -206,7 +206,7 @@ class TestProperties(unittest.TestCase):
self.assertRaises(TypeError, GObject.Property,
type=GIMarshallingTests.Flags, default=None)
- def testGType(self):
+ def test_gtype(self):
obj = new(PropertyObject)
self.assertEqual(obj.props.gtype, TYPE_NONE)
@@ -238,7 +238,7 @@ class TestProperties(unittest.TestCase):
self.assertEqual(obj.props.gtype, TYPE_UINT)
self.assertEqual(obj.gtype, TYPE_UINT)
- def testBoxed(self):
+ def test_boxed(self):
obj = new(PropertyObject)
regex = GLib.Regex.new('[a-z]*', 0, 0)
@@ -249,7 +249,7 @@ class TestProperties(unittest.TestCase):
self.assertRaises(TypeError, setattr, obj, 'boxed', 'foo')
self.assertRaises(TypeError, setattr, obj, 'boxed', object())
- def testStrings(self):
+ def test_strings(self):
obj = new(PropertyObject)
# Should work with actual GStrv objects as well as
@@ -299,7 +299,7 @@ class TestProperties(unittest.TestCase):
self.assertRaises(TypeError, GObject.Property, type=TYPE_STRV,
default=['hello', 1])
- def testRange(self):
+ def test_range(self):
# kiwi code
def max(c):
return 2 ** ((8 * struct.calcsize(c)) - 1) - 1
@@ -368,7 +368,7 @@ class TestProperties(unittest.TestCase):
obj.set_property(key, max)
self.assertEqual(obj.get_property(key), max)
- def testMulti(self):
+ def test_multi(self):
obj = PropertyObject()
obj.set_properties(normal="foo",
uint64=7)
@@ -378,7 +378,7 @@ class TestProperties(unittest.TestCase):
class TestProperty(unittest.TestCase):
- def testSimple(self):
+ def test_simple(self):
class C(GObject.GObject):
str = GObject.Property(type=str)
int = GObject.Property(type=int)
@@ -407,7 +407,7 @@ class TestProperty(unittest.TestCase):
o.long = _long(100)
self.assertEqual(o.long, _long(100))
- def testCustomGetter(self):
+ def test_custom_getter(self):
class C(GObject.GObject):
def get_prop(self):
return 'value'
@@ -417,7 +417,7 @@ class TestProperty(unittest.TestCase):
self.assertEqual(o.prop, 'value')
self.assertRaises(TypeError, setattr, o, 'prop', 'xxx')
- def testCustomSetter(self):
+ def test_custom_setter(self):
class C(GObject.GObject):
def set_prop(self, value):
self._value = value
@@ -433,7 +433,7 @@ class TestProperty(unittest.TestCase):
self.assertEqual(o._value, 'bar')
self.assertRaises(TypeError, getattr, o, 'prop')
- def testDecoratorDefault(self):
+ def test_decorator_default(self):
class C(GObject.GObject):
_value = 'value'
@@ -451,7 +451,7 @@ class TestProperty(unittest.TestCase):
self.assertEqual(o.value, 'blah')
self.assertEqual(o.props.value, 'blah')
- def testDecoratorWithCall(self):
+ def test_decorator_with_call(self):
class C(GObject.GObject):
_value = 1
@@ -469,7 +469,7 @@ class TestProperty(unittest.TestCase):
self.assertEqual(o.typedValue, 5)
self.assertEqual(o.props.typedValue, 5)
- def testErrors(self):
+ def test_errors(self):
self.assertRaises(TypeError, GObject.Property, type='str')
self.assertRaises(TypeError, GObject.Property, nick=False)
self.assertRaises(TypeError, GObject.Property, blurb=False)
@@ -483,18 +483,18 @@ class TestProperty(unittest.TestCase):
self.assertRaises(TypeError, GObject.Property, type=complex)
self.assertRaises(TypeError, GObject.Property, flags=-10)
- def testDefaults(self):
+ def test_defaults(self):
GObject.Property(type=bool, default=True)
GObject.Property(type=bool, default=False)
- def testNameWithUnderscore(self):
+ def test_name_with_underscore(self):
class C(GObject.GObject):
prop_name = GObject.Property(type=int)
o = C()
o.prop_name = 10
self.assertEqual(o.prop_name, 10)
- def testRange(self):
+ def test_range(self):
maxint64 = 2 ** 62 - 1
minint64 = -2 ** 62 - 1
maxuint64 = 2 ** 63 - 1
@@ -525,7 +525,7 @@ class TestProperty(unittest.TestCase):
GObject.Property, type=gtype, minimum=min,
maximum=max + 1)
- def testMinMax(self):
+ def test_min_max(self):
class C(GObject.GObject):
prop_int = GObject.Property(type=int, minimum=1, maximum=100, default=1)
prop_float = GObject.Property(type=float, minimum=0.1, maximum=10.5, default=1.1)
@@ -562,7 +562,7 @@ class TestProperty(unittest.TestCase):
finally:
GLib.log_set_always_fatal(old_mask)
- def testMultipleInstances(self):
+ def test_multiple_instances(self):
class C(GObject.GObject):
prop = GObject.Property(type=str, default='default')
@@ -574,7 +574,7 @@ class TestProperty(unittest.TestCase):
self.assertEqual(o1.prop, 'value')
self.assertEqual(o2.prop, 'default')
- def testObjectProperty(self):
+ def test_object_property(self):
class PropertyObject(GObject.GObject):
obj = GObject.Property(type=GObject.GObject)
@@ -587,7 +587,7 @@ class TestProperty(unittest.TestCase):
pobj1 = pobj2.obj
self.assertEqual(hash(pobj1), obj1_hash)
- def testObjectSubclassProperty(self):
+ def test_object_subclass_property(self):
class ObjectSubclass(GObject.GObject):
__gtype_name__ = 'ObjectSubclass'
@@ -596,7 +596,7 @@ class TestProperty(unittest.TestCase):
PropertyObjectSubclass(obj=ObjectSubclass())
- def testPropertySubclass(self):
+ def test_property_subclass(self):
# test for #470718
class A(GObject.GObject):
prop1 = GObject.Property(type=int)
@@ -610,7 +610,19 @@ class TestProperty(unittest.TestCase):
b.prop1 = 20
self.assertEqual(b.prop1, 20)
- def testPropertySubclassCustomSetter(self):
+ def test_property_subclass_c(self):
+ class A(GIMarshallingTests.PropertiesObject):
+ prop1 = GObject.Property(type=int)
+
+ a = A()
+ a.prop1 = 10
+ self.assertEqual(a.prop1, 10)
+
+ # also has parent properties
+ a.props.some_int = 20
+ self.assertEqual(a.props.some_int, 20)
+
+ def test_property_subclass_custom_setter(self):
# test for #523352
class A(GObject.GObject):
def get_first(self):
@@ -632,7 +644,7 @@ class TestProperty(unittest.TestCase):
self.assertEqual(b.second, 'second')
self.assertRaises(TypeError, setattr, b, 'second', 'foo')
- def testPropertySubclassCustomSetterError(self):
+ def test_property_subclass_custom_setter_error(self):
try:
class A(GObject.GObject):
def get_first(self):
@@ -655,7 +667,7 @@ class TestProperty(unittest.TestCase):
# Bug 644039
- def testReferenceCount(self):
+ def test_reference_count(self):
# We can check directly if an object gets finalized, so we will
# observe it indirectly through the refcount of a member object.
@@ -676,7 +688,7 @@ class TestProperty(unittest.TestCase):
del t
self.assertEqual(sys.getrefcount(o), rc)
- def testDocStringAsBlurb(self):
+ def test_doc_string_as_blurb(self):
class C(GObject.GObject):
@GObject.Property
def blurbed(self):
@@ -685,7 +697,7 @@ class TestProperty(unittest.TestCase):
self.assertEqual(C.blurbed.blurb, 'blurbed doc string')
- def testPythonToGLibTypeMapping(self):
+ def test_python_to_glib_type_mapping(self):
tester = GObject.Property()
self.assertEqual(tester._type_from_python(int), GObject.TYPE_INT)
if sys.version_info < (3, 0):
diff --git a/tests/test_signal.py b/tests/test_signal.py
index 2002c18..3b70318 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -79,14 +79,14 @@ class TestGSignalsError(unittest.TestCase):
class TestGPropertyError(unittest.TestCase):
- def testInvalidType(self, *args):
+ def test_invalid_type(self, *args):
def foo():
class Foo(GObject.GObject):
__gproperties__ = None
self.assertRaises(TypeError, foo)
gc.collect()
- def testInvalidName(self, *args):
+ def test_invalid_name(self, *args):
def foo():
class Foo(GObject.GObject):
__gproperties__ = {None: None}
@@ -96,7 +96,7 @@ class TestGPropertyError(unittest.TestCase):
class TestList(unittest.TestCase):
- def testListObject(self):
+ def test_list_names(self):
self.assertEqual(GObject.signal_list_names(C), ('my-signal',))
@@ -120,7 +120,7 @@ class Foo(GObject.GObject):
class TestAccumulator(unittest.TestCase):
- def testAccumulator(self):
+ def test_accumulator(self):
inst = Foo()
inst.connect("my-acc-signal", lambda obj: 1)
inst.connect("my-acc-signal", lambda obj: 2)
@@ -131,7 +131,7 @@ class TestAccumulator(unittest.TestCase):
retval = inst.emit("my-acc-signal")
self.assertEqual(retval, 3)
- def testAccumulatorTrueHandled(self):
+ def test_accumulator_true_handled(self):
inst = Foo()
inst.connect("my-other-acc-signal", self._true_handler1)
inst.connect("my-other-acc-signal", self._true_handler2)
@@ -181,7 +181,7 @@ class F(GObject.GObject):
class TestEmissionHook(unittest.TestCase):
- def testAdd(self):
+ def test_add(self):
self.hook = True
e = E()
e.connect('signal', self._callback)
@@ -189,7 +189,7 @@ class TestEmissionHook(unittest.TestCase):
e.emit('signal')
self.assertEqual(e.status, 3)
- def testRemove(self):
+ def test_remove(self):
self.hook = False
e = E()
e.connect('signal', self._callback)
@@ -209,7 +209,7 @@ class TestEmissionHook(unittest.TestCase):
self.assertEqual(e.status, 1)
e.status = 3
- def testCallbackReturnFalse(self):
+ def test_callback_return_false(self):
self.hook = False
obj = F()
@@ -221,7 +221,7 @@ class TestEmissionHook(unittest.TestCase):
obj.emit('signal')
self.assertEqual(obj.status, 3)
- def testCallbackReturnTrue(self):
+ def test_callback_return_true(self):
self.hook = False
obj = F()
@@ -234,7 +234,7 @@ class TestEmissionHook(unittest.TestCase):
GObject.remove_emission_hook(obj, "signal", hook_id)
self.assertEqual(obj.status, 4)
- def testCallbackReturnTrueButRemove(self):
+ def test_callback_return_true_but_remove(self):
self.hook = False
obj = F()
@@ -255,21 +255,21 @@ class TestClosures(unittest.TestCase):
def _callback(self, e):
self.count += 1
- def testDisconnect(self):
+ def test_disconnect(self):
e = E()
e.connect('signal', self._callback)
e.disconnect_by_func(self._callback)
e.emit('signal')
self.assertEqual(self.count, 0)
- def testHandlerBlock(self):
+ def test_handler_block(self):
e = E()
e.connect('signal', self._callback)
e.handler_block_by_func(self._callback)
e.emit('signal')
self.assertEqual(self.count, 0)
- def testHandlerUnBlock(self):
+ def test_handler_unblock(self):
e = E()
signal_id = e.connect('signal', self._callback)
e.handler_block(signal_id)
@@ -277,7 +277,7 @@ class TestClosures(unittest.TestCase):
e.emit('signal')
self.assertEqual(self.count, 1)
- def testHandlerBlockMethod(self):
+ def test_handler_block_method(self):
# Filed as #375589
class A:
def __init__(self):
@@ -337,29 +337,27 @@ class SigPropClass(GObject.GObject):
class TestSigProp(unittest.TestCase):
- def testEmitInPropertySetter(self):
+ def test_emit_in_property_setter(self):
obj = SigPropClass()
self.assertFalse(obj.signal_emission_failed)
-f = GObject.SignalFlags.RUN_FIRST
-l = GObject.SignalFlags.RUN_LAST
-gfloat = GObject.TYPE_FLOAT
-gdouble = GObject.TYPE_DOUBLE
-guint = GObject.TYPE_UINT
-gulong = GObject.TYPE_ULONG
-
class CM(GObject.GObject):
__gsignals__ = dict(
- test1=(f, None, ()),
- test2=(l, None, (str,)),
- test3=(l, int, (gdouble,)),
- test4=(f, None, (bool, _long, gfloat, gdouble, int, guint, gulong)),
- test_float=(l, gfloat, (gfloat,)),
- test_double=(l, gdouble, (gdouble, )),
- test_string=(l, str, (str, )),
- test_object=(l, object, (object, )),
- test_paramspec=(l, GObject.ParamSpec, ()),
+ test1=(GObject.SignalFlags.RUN_FIRST, None, ()),
+ test2=(GObject.SignalFlags.RUN_LAST, None, (str,)),
+ test3=(GObject.SignalFlags.RUN_LAST, int, (GObject.TYPE_DOUBLE,)),
+ test4=(GObject.SignalFlags.RUN_FIRST, None,
+ (bool, _long, GObject.TYPE_FLOAT, GObject.TYPE_DOUBLE, int,
+ GObject.TYPE_UINT, GObject.TYPE_ULONG)),
+ test_float=(GObject.SignalFlags.RUN_LAST, GObject.TYPE_FLOAT, (GObject.TYPE_FLOAT,)),
+ test_double=(GObject.SignalFlags.RUN_LAST, GObject.TYPE_DOUBLE, (GObject.TYPE_DOUBLE,)),
+ test_int64=(GObject.SignalFlags.RUN_LAST, GObject.TYPE_INT64, (GObject.TYPE_INT64,)),
+ test_string=(GObject.SignalFlags.RUN_LAST, str, (str,)),
+ test_object=(GObject.SignalFlags.RUN_LAST, object, (object,)),
+ test_paramspec=(GObject.SignalFlags.RUN_LAST, GObject.ParamSpec, ()),
+ test_gvalue=(GObject.SignalFlags.RUN_LAST, GObject.Value, (GObject.Value,)),
+ test_gvalue_ret=(GObject.SignalFlags.RUN_LAST, GObject.Value, (GObject.TYPE_GTYPE,)),
)
testprop = GObject.Property(type=int)
@@ -370,41 +368,51 @@ class _TestCMarshaller:
self.obj = CM()
testhelper.connectcallbacks(self.obj)
- def testTest1(self):
+ def test_test1(self):
self.obj.emit("test1")
- def testTest2(self):
+ def test_test2(self):
self.obj.emit("test2", "string")
- def testTest3(self):
+ def test_test3(self):
rv = self.obj.emit("test3", 42.0)
self.assertEqual(rv, 20)
- def testTest4(self):
+ def test_test4(self):
self.obj.emit("test4", True, _long(10), 3.14, 1.78, 20, _long(30), _long(31))
- def testTestReturnFloat(self):
+ def test_float(self):
rv = self.obj.emit("test-float", 1.234)
self.assertTrue(rv >= 1.233999 and rv <= 1.2400001, rv)
- def testTestReturnDouble(self):
+ def test_double(self):
rv = self.obj.emit("test-double", 1.234)
self.assertEqual(rv, 1.234)
- def testTestReturnString(self):
+ def test_int64(self):
+ rv = self.obj.emit("test-int64", 102030405)
+ self.assertEqual(rv, 102030405)
+
+ rv = self.obj.emit("test-int64", GObject.G_MAXINT64)
+ self.assertEqual(rv, GObject.G_MAXINT64 - 1)
+
+ rv = self.obj.emit("test-int64", GObject.G_MININT64)
+ self.assertEqual(rv, GObject.G_MININT64)
+
+ def test_string(self):
rv = self.obj.emit("test-string", "str")
self.assertEqual(rv, "str")
- def testTestReturnObject(self):
+ def test_object(self):
rv = self.obj.emit("test-object", self)
self.assertEqual(rv, self)
- def testTestReturnParamSpec(self):
+ def test_paramspec(self):
rv = self.obj.emit("test-paramspec")
self.assertEqual(rv.name, "test-param")
self.assertEqual(rv.nick, "test")
- def testTestParamSpecArgFromC(self):
+ def test_C_paramspec(self):
self.notify_called = False
def cb_notify(obj, prop):
@@ -416,6 +424,58 @@ class _TestCMarshaller:
self.obj.set_property("testprop", 42)
self.assertTrue(self.notify_called)
+ def test_gvalue(self):
+ # implicit int
+ rv = self.obj.emit("test-gvalue", 42)
+ self.assertEqual(rv, 42)
+
+ # explicit float
+ v = GObject.Value()
+ v.init(GObject.TYPE_FLOAT)
+ v.set_float(1.234)
+ rv = self.obj.emit("test-gvalue", v)
+ self.assertAlmostEqual(rv, 1.234, 4)
+
+ # implicit float
+ rv = self.obj.emit("test-gvalue", 1.234)
+ self.assertAlmostEqual(rv, 1.234, 4)
+
+ # explicit int64
+ v = GObject.Value()
+ v.init(GObject.TYPE_INT64)
+ v.set_int64(GObject.G_MAXINT64)
+ rv = self.obj.emit("test-gvalue", v)
+ self.assertEqual(rv, GObject.G_MAXINT64)
+
+ # implicit int64
+ # does not work, see https://bugzilla.gnome.org/show_bug.cgi?id=683775
+ #rv = self.obj.emit("test-gvalue", GObject.G_MAXINT64)
+ #self.assertEqual(rv, GObject.G_MAXINT64)
+
+ # explicit uint64
+ v = GObject.Value()
+ v.init(GObject.TYPE_UINT64)
+ v.set_uint64(GObject.G_MAXUINT64)
+ rv = self.obj.emit("test-gvalue", v)
+ self.assertEqual(rv, GObject.G_MAXUINT64)
+
+ # implicit uint64
+ # does not work, see https://bugzilla.gnome.org/show_bug.cgi?id=683775
+ #rv = self.obj.emit("test-gvalue", GObject.G_MAXUINT64)
+ #self.assertEqual(rv, GObject.G_MAXUINT64)
+
+ def test_gvalue_ret(self):
+ self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_INT),
+ GObject.G_MAXINT)
+ self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_UINT),
+ GObject.G_MAXUINT)
+ self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_INT64),
+ GObject.G_MAXINT64)
+ self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_UINT64),
+ GObject.G_MAXUINT64)
+ self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_STRING),
+ "hello")
+
if 'generic-c-marshaller' in GObject.features:
class TestCMarshaller(_TestCMarshaller, unittest.TestCase):
pass
@@ -428,7 +488,7 @@ else:
class TestPyGValue(unittest.TestCase):
- def testNoneNULLBoxedConversion(self):
+ def test_none_null_boxed_conversion(self):
class C(GObject.GObject):
__gsignals__ = dict(my_boxed_signal=(
GObject.SignalFlags.RUN_LAST,
@@ -476,7 +536,7 @@ class TestSignalDecorator(unittest.TestCase):
def onUnnamed(self, obj):
self.unnamedCalled = True
- def testGetSignalArgs(self):
+ def test_get_signal_args(self):
self.assertEqual(self.Decorated.pushed.get_signal_args(),
(GObject.SignalFlags.RUN_FIRST, None, tuple()))
self.assertEqual(self.Decorated.pulled.get_signal_args(),
@@ -484,7 +544,7 @@ class TestSignalDecorator(unittest.TestCase):
self.assertEqual(self.Decorated.stomped.get_signal_args(),
(GObject.SignalFlags.RUN_FIRST, None, (int,)))
- def testClosuresCalled(self):
+ def test_closures_called(self):
decorated = self.Decorated()
self.assertEqual(decorated.value, 0)
decorated.pushed.emit()
@@ -492,7 +552,7 @@ class TestSignalDecorator(unittest.TestCase):
decorated.pulled.emit()
self.assertEqual(decorated.value, 0)
- def testSignalCopy(self):
+ def test_signal_copy(self):
blah = self.Decorated.stomped.copy('blah')
self.assertEqual(str(blah), blah)
self.assertEqual(blah.func, self.Decorated.stomped.func)
@@ -501,23 +561,23 @@ class TestSignalDecorator(unittest.TestCase):
self.assertEqual(blah.arg_types, self.Decorated.stomped.arg_types)
self.assertEqual(blah.__doc__, self.Decorated.stomped.__doc__)
- def testDocString(self):
+ def test_doc_string(self):
# Test the two techniques for setting doc strings on the signals
# class variables, through the "doc" keyword or as the getter doc string.
self.assertEqual(self.Decorated.stomped.__doc__, 'this will stomp')
self.assertEqual(self.Decorated.pushed.__doc__, 'this will push')
- def testUnnamedSignalGetsNamed(self):
+ def test_unnamed_signal_gets_named(self):
self.assertEqual(str(self.Decorated.unnamed), 'unnamed')
- def testUnnamedSignalGetsCalled(self):
+ def test_unnamed_signal_gets_called(self):
obj = self.Decorated()
obj.connect('unnamed', self.onUnnamed)
self.assertEqual(self.unnamedCalled, False)
obj.emit('unnamed')
self.assertEqual(self.unnamedCalled, True)
- def NOtestOverriddenSignal(self):
+ def NOtest_overridden_signal(self):
# Test that the pushed signal is called in with super and the override
# which should both increment the "value" to 3
obj = self.DecoratedOverride()
@@ -542,14 +602,14 @@ class TestSignalConnectors(unittest.TestCase):
self.obj = None
self.value = None
- def onClicked(self, obj, value):
+ def on_clicked(self, obj, value):
self.obj = obj
self.value = value
- def testSignalEmit(self):
+ def test_signal_emit(self):
# standard callback connection with different forms of emit.
obj = self.CustomButton()
- obj.connect('clicked', self.onClicked)
+ obj.connect('clicked', self.on_clicked)
# vanilla
obj.emit('clicked', 1)
@@ -578,16 +638,16 @@ class TestSignalConnectors(unittest.TestCase):
self.assertEqual(obj, self.obj)
self.assertEqual(self.value, 1)
- def testSignalClassConnect(self):
+ def test_signal_class_connect(self):
obj = self.CustomButton()
- obj.connect(self.CustomButton.clicked, self.onClicked)
+ obj.connect(self.CustomButton.clicked, self.on_clicked)
obj.emit('clicked', 2)
self.assertEqual(obj, self.obj)
self.assertEqual(self.value, 2)
- def testSignalBoundConnect(self):
+ def test_signal_bound_connect(self):
obj = self.CustomButton()
- obj.clicked.connect(self.onClicked)
+ obj.clicked.connect(self.on_clicked)
obj.emit('clicked', 3)
self.assertEqual(obj, self.obj)
self.assertEqual(self.value, 3)
@@ -616,7 +676,7 @@ class TestPython3Signals(unittest.TestCase):
self.assertTrue('AnnotatedSignalClass' in globals())
self.AnnotatedClass = globals()['AnnotatedSignalClass']
- def testAnnotations(self):
+ def test_annotations(self):
if self.AnnotatedClass:
self.assertEqual(signalhelper.get_signal_annotations(self.AnnotatedClass.sig1.func),
(None, (int, float)))
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index cd178a1..608b8b1 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -322,6 +322,16 @@ test_double_callback (GObject *object, double d)
return d;
}
+static gint64 *
+test_int64_callback (GObject *object, gint64 i)
+{
+ g_return_val_if_fail (G_IS_OBJECT (object), -1);
+
+ if (i == G_MAXINT64)
+ return i-1;
+ return i;
+}
+
static char *
test_string_callback (GObject *object, char *s)
{
@@ -347,6 +357,51 @@ test_paramspec_callback (GObject *object)
return g_param_spec_boolean ("test-param", "test", "test boolean", TRUE, G_PARAM_READABLE);
}
+static GValue *
+test_gvalue_callback (GObject *object, const GValue *v)
+{
+ GValue *ret = g_malloc0 (sizeof (GValue));
+
+ g_return_val_if_fail (G_IS_OBJECT (object), NULL);
+ g_return_val_if_fail (G_IS_VALUE (v), NULL);
+
+ g_value_init (ret, G_VALUE_TYPE (v));
+ g_value_copy (v, ret);
+ return ret;
+}
+
+static GValue *
+test_gvalue_ret_callback (GObject *object, GType type)
+{
+ GValue *ret = g_malloc0 (sizeof (GValue));
+
+ g_return_val_if_fail (G_IS_OBJECT (object), NULL);
+
+ g_value_init (ret, type);
+
+ switch (type) {
+ case G_TYPE_INT:
+ g_value_set_int(ret, G_MAXINT);
+ break;
+ case G_TYPE_INT64:
+ g_value_set_int64(ret, G_MAXINT64);
+ break;
+ case G_TYPE_UINT:
+ g_value_set_uint(ret, G_MAXUINT);
+ break;
+ case G_TYPE_UINT64:
+ g_value_set_uint64(ret, G_MAXUINT64);
+ break;
+ case G_TYPE_STRING:
+ g_value_set_string(ret, "hello");
+ break;
+ default:
+ g_critical ("test_gvalue_ret_callback() does not support type %s", g_type_name (type));
+ }
+
+ return ret;
+}
+
static void
connectcallbacks (GObject *object)
{
@@ -382,6 +437,10 @@ connectcallbacks (GObject *object)
G_CALLBACK (test_double_callback),
NULL);
g_signal_connect (G_OBJECT (object),
+ "test_int64",
+ G_CALLBACK (test_int64_callback),
+ NULL);
+ g_signal_connect (G_OBJECT (object),
"test_string",
G_CALLBACK (test_string_callback),
NULL);
@@ -393,6 +452,14 @@ connectcallbacks (GObject *object)
"test_paramspec",
G_CALLBACK (test_paramspec_callback),
NULL);
+ g_signal_connect (G_OBJECT (object),
+ "test_gvalue",
+ G_CALLBACK (test_gvalue_callback),
+ NULL);
+ g_signal_connect (G_OBJECT (object),
+ "test_gvalue_ret",
+ G_CALLBACK (test_gvalue_ret_callback),
+ NULL);
}
static PyObject *