diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | tests/test_signal.py | 45 |
2 files changed, 50 insertions, 0 deletions
@@ -1,5 +1,10 @@ 2006-09-16 Gustavo J. A. M. Carneiro <gjc@gnome.org> + * tests/test_signal.py (TestEmissionHook.testCallbackReturnFalse) + (TestEmissionHook.testCallbackReturnTrue) + (TestEmissionHook.testCallbackReturnTrueButRemove): Add a few more + emission hook tests. + * gobject/gobjectmodule.c (pyg_add_emission_hook): One too many DECREF on 'extra_args'. diff --git a/tests/test_signal.py b/tests/test_signal.py index bb33fb8..a2018a9 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -139,6 +139,16 @@ class E(gobject.GObject): assert self.status == 0 self.status = 1 +class F(gobject.GObject): + __gsignals__ = { 'signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ()) } + def __init__(self): + gobject.GObject.__init__(self) + self.status = 0 + + def do_signal(self): + self.status += 1 + class TestEmissionHook(unittest.TestCase): def testAdd(self): self.hook = True @@ -168,6 +178,41 @@ class TestEmissionHook(unittest.TestCase): self.assertEqual(e.status, 1) e.status = 3 + def testCallbackReturnFalse(self): + self.hook = False + obj = F() + def _emission_hook(obj): + obj.status += 1 + return False + hook_id = gobject.add_emission_hook(obj, "signal", _emission_hook) + obj.emit('signal') + obj.emit('signal') + self.assertEqual(obj.status, 3) + + def testCallbackReturnTrue(self): + self.hook = False + obj = F() + def _emission_hook(obj): + obj.status += 1 + return True + hook_id = gobject.add_emission_hook(obj, "signal", _emission_hook) + obj.emit('signal') + obj.emit('signal') + gobject.remove_emission_hook(obj, "signal", hook_id) + self.assertEqual(obj.status, 4) + + def testCallbackReturnTrueButRemove(self): + self.hook = False + obj = F() + def _emission_hook(obj): + obj.status += 1 + return True + hook_id = gobject.add_emission_hook(obj, "signal", _emission_hook) + obj.emit('signal') + gobject.remove_emission_hook(obj, "signal", hook_id) + obj.emit('signal') + self.assertEqual(obj.status, 3) + class TestClosures(unittest.TestCase): def setUp(self): self.count = 0 |