[pygobject] Support GHashTable and GError as callback/closure arguments



commit 77f32d9110bfeb6dad8457f565b4c70b5998fef6
Author: Alberto Mardegan <mardy users sourceforge net>
Date:   Thu Dec 15 16:12:01 2011 +0200

    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 <martin pitt ubuntu com>

 gi/pygi-closure.c        |    2 ++
 tests/test_everything.py |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index 7cd0436..6fc08fb 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -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];
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 43735e5..8084ba1 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -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):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]