Commit 77f32d91 authored by Alberto Mardegan's avatar Alberto Mardegan Committed by Tomeu Vizoso
Browse files

Support GHashTable and GError as callback/closure arguments

Marshalling of these types from C is already implemented, let's take it
into use for calbacks and closures too.

Add corresponding test cases.

https://bugzilla.gnome.org/show_bug.cgi?id=666270

Signed-off-by: Martin Pitt's avatarMartin Pitt <martin.pitt@ubuntu.com>
parent 4b9dc03d
......@@ -163,6 +163,8 @@ _pygi_closure_convert_ffi_arguments (GICallableInfo *callable_info, void **args)
g_base_info_unref (interface);
}
case GI_TYPE_TAG_ERROR:
case GI_TYPE_TAG_GHASH:
case GI_TYPE_TAG_GLIST:
case GI_TYPE_TAG_GSLIST:
g_args[i].v_pointer = * (gpointer *) args[i];
......
......@@ -12,6 +12,7 @@ import cairo
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gio
from gi.repository import Regress as Everything
if sys.version_info < (3, 0):
......@@ -350,6 +351,40 @@ class TestCallbacks(unittest.TestCase):
# make sure this doesn't assert or crash
Everything.test_simple_callback(None)
def testCallbackGError(self):
def callback(error):
self.assertEqual(error.message, 'regression test error')
self.assertTrue('g-io' in error.domain)
self.assertEqual(error.code, Gio.IOErrorEnum.NOT_SUPPORTED)
TestCallbacks.called = True
TestCallbacks.called = False
Everything.test_gerror_callback(callback)
self.assertTrue(TestCallbacks.called)
def testCallbackOwnedGError(self):
def callback(error):
self.assertEqual(error.message, 'regression test owned error')
self.assertTrue('g-io' in error.domain)
self.assertEqual(error.code, Gio.IOErrorEnum.PERMISSION_DENIED)
TestCallbacks.called = True
TestCallbacks.called = False
Everything.test_owned_gerror_callback(callback)
self.assertTrue(TestCallbacks.called)
def testCallbackHashTable(self):
def callback(data):
self.assertEqual(data, mydict)
mydict['new'] = 42
TestCallbacks.called = True
mydict = { 'foo': 1, 'bar': 2 }
TestCallbacks.called = False
Everything.test_hash_table_callback(mydict, callback)
self.assertTrue(TestCallbacks.called)
self.assertEqual(mydict, { 'foo': 1, 'bar': 2, 'new': 42 })
class TestClosures(unittest.TestCase):
def test_int_arg(self):
def callback(num):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment