summaryrefslogtreecommitdiffstats
path: root/tests/test_gi.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_gi.py')
-rw-r--r--tests/test_gi.py64
1 files changed, 63 insertions, 1 deletions
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 9b9a849..a9076b6 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -12,7 +12,7 @@ from datetime import datetime
import sys
sys.path.insert(0, "../")
-from gi.repository import GIMarshallingTests
+from gi.repository import GIMarshallingTests, Everything
CONSTANT_UTF8 = "const \xe2\x99\xa5 utf8"
@@ -1399,3 +1399,65 @@ class TestOverrides(unittest.TestCase):
object_ = GIMarshallingTests.overrides_object_return()
self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))
+
+
+class TestCallbacks(unittest.TestCase):
+ called = False
+ def testCallback(self):
+ TestCallbacks.called = False
+ def callback():
+ TestCallbacks.called = True
+
+ Everything.test_simple_callback(callback)
+ self.assertTrue(TestCallbacks.called)
+
+ def testCallbackException(self):
+ """
+ This test ensures that we get errors from callbacks correctly
+ and in particular that we do not segv when callbacks fail
+ """
+ def callback():
+ x = 1 / 0
+
+ try:
+ Everything.test_simple_callback(callback)
+ except ZeroDivisionError:
+ pass
+
+ def testDoubleCallbackException(self):
+ """
+ This test ensures that we get errors from callbacks correctly
+ and in particular that we do not segv when callbacks fail
+ """
+ def badcallback():
+ x = 1 / 0
+
+ def callback():
+ GIMarshallingTests.boolean_return_true()
+ GIMarshallingTests.boolean_return_false()
+ Everything.test_simple_callback(badcallback())
+
+ try:
+ Everything.test_simple_callback(callback)
+ except ZeroDivisionError:
+ pass
+
+ def testReturnValueCallback(self):
+ TestCallbacks.called = False
+ def callback():
+ TestCallbacks.called = True
+ return 44
+
+ self.assertEquals(Everything.test_callback(callback), 44)
+ self.assertTrue(TestCallbacks.called)
+
+ def testCallbackAsync(self):
+ TestCallbacks.called = False
+ def callback(foo):
+ TestCallbacks.called = True
+ return foo
+
+ Everything.test_callback_async(callback, 44);
+ i = Everything.test_callback_thaw_async();
+ self.assertEquals(44, i);
+ self.assertTrue(TestCallbacks.called)