summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGustavo J. A. M. Carneiro <gjc@src.gnome.org>2006-01-11 16:09:18 +0000
committerGustavo J. A. M. Carneiro <gjc@src.gnome.org>2006-01-11 16:09:18 +0000
commite370df75fb2cfdd780188af1e81416a5443cb6e9 (patch)
tree0e54a2fdc133bc24d05caa5782eb8021efd1d737 /tests
parenta4834ddbe8dfe5b0f131ba3c1331de0b05f67a0f (diff)
signal accumulators
Diffstat (limited to 'tests')
-rw-r--r--tests/runtests.py3
-rw-r--r--tests/test_signal.py52
2 files changed, 54 insertions, 1 deletions
diff --git a/tests/runtests.py b/tests/runtests.py
index 3ae7185..da866d4 100644
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -21,7 +21,8 @@ else:
common.importModules(buildDir=buildDir,
srcDir=srcDir)
-SKIP_FILES = ['common', 'runtests']
+SKIP_FILES = ['common', 'runtests',
+ 'test_enum', 'test_conversion']
dir = os.path.split(os.path.abspath(__file__))[0]
os.chdir(dir)
diff --git a/tests/test_signal.py b/tests/test_signal.py
index 36014fc..87c62f6 100644
--- a/tests/test_signal.py
+++ b/tests/test_signal.py
@@ -77,5 +77,57 @@ class TestList(unittest.TestCase):
def testListObject(self):
self.assertEqual(gobject.signal_list_names(C), ('my-signal',))
+
+def my_accumulator(ihint, return_accu, handler_return, user_data):
+ """An accumulator that stops emission when the sum of handler
+ returned values reaches 3"""
+ assert user_data == "accum data"
+ if return_accu >= 3:
+ return False, return_accu
+ return True, return_accu + handler_return
+
+class Foo(gobject.GObject):
+ __gsignals__ = {
+ 'my-acc-signal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_INT,
+ (), my_accumulator, "accum data"),
+ 'my-other-acc-signal': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_BOOLEAN,
+ (), gobject.signal_accumulator_true_handled)
+ }
+
+class TestAccumulator(unittest.TestCase):
+
+ def testAccumulator(self):
+ inst = Foo()
+ inst.connect("my-acc-signal", lambda obj: 1)
+ inst.connect("my-acc-signal", lambda obj: 2)
+ ## the value returned in the following handler will not be
+ ## considered, because at this point the accumulator already
+ ## reached its limit.
+ inst.connect("my-acc-signal", lambda obj: 3)
+ retval = inst.emit("my-acc-signal")
+ self.assertEqual(retval, 3)
+
+ def testAccumulatorTrueHandled(self):
+ inst = Foo()
+ inst.connect("my-other-acc-signal", self._true_handler1)
+ inst.connect("my-other-acc-signal", self._true_handler2)
+ ## the following handler will not be called because handler2
+ ## returns True, so it should stop the emission.
+ inst.connect("my-other-acc-signal", self._true_handler3)
+ self.__true_val = None
+ inst.emit("my-other-acc-signal")
+ self.assertEqual(self.__true_val, 2)
+
+ def _true_handler1(self, obj):
+ self.__true_val = 1
+ return False
+ def _true_handler2(self, obj):
+ self.__true_val = 2
+ return True
+ def _true_handler3(self, obj):
+ self.__true_val = 3
+ return False
+
+
if __name__ == '__main__':
unittest.main()