[pygi] Add support for GArray args



commit c9d44d4d46c3da3a445000b1db592baa9c378a92
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date:   Fri Apr 30 18:17:50 2010 +0200

    Add support for GArray args
    
    https://bugzilla.gnome.org/show_bug.cgi?id=617054

 gi/pygi-invoke.c |   11 +++++++----
 tests/test_gi.py |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 4 deletions(-)
---
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 11c6f23..e5e3617 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -510,7 +510,8 @@ _prepare_invocation_state (struct invocation_state *state,
                     }
 
                     /* Get rid of the GArray. */
-                    if (array != NULL) {
+                    if ((array != NULL) &&
+                        (g_type_info_get_array_type(state->arg_type_infos[i]) == GI_ARRAY_TYPE_C)) {
                         state->args[i]->v_pointer = array->data;
 
                         if (direction != GI_DIRECTION_INOUT || transfer != GI_TRANSFER_NOTHING) {
@@ -654,7 +655,8 @@ _process_invocation_state (struct invocation_state *state,
     } else {
         GITransfer transfer;
 
-        if (state->return_type_tag == GI_TYPE_TAG_ARRAY) {
+        if ((state->return_type_tag == GI_TYPE_TAG_ARRAY) &&
+            (g_type_info_get_array_type(state->return_type_info) == GI_ARRAY_TYPE_C)) {
             /* Create a #GArray. */
             state->return_arg.v_pointer = _pygi_argument_to_array(&state->return_arg, state->args, state->return_type_info, state->is_method);
         }
@@ -722,8 +724,9 @@ _process_invocation_state (struct invocation_state *state,
 
             type_tag = g_type_info_get_tag(state->arg_type_infos[i]);
 
-            if (type_tag == GI_TYPE_TAG_ARRAY
-                    && (direction != GI_DIRECTION_IN || transfer == GI_TRANSFER_NOTHING)) {
+            if ((type_tag == GI_TYPE_TAG_ARRAY) &&
+                (g_type_info_get_array_type(state->arg_type_infos[i]) == GI_ARRAY_TYPE_C) &&
+                (direction != GI_DIRECTION_IN || transfer == GI_TRANSFER_NOTHING)) {
                 /* Create a #GArray. */
                 state->args[i]->v_pointer = _pygi_argument_to_array(state->args[i], state->args, state->arg_type_infos[i], state->is_method);
             }
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 0a3f771..9b19155 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -734,6 +734,56 @@ class TestArray(unittest.TestCase):
         self.assertEquals(('-1', '0', '1', '2'), GIMarshallingTests.array_zero_terminated_inout(('0', '1', '2')))
 
 
+class TestGArray(unittest.TestCase):
+
+    def test_garray_int_none_return(self):
+        self.assertEquals((-1, 0, 1, 2), GIMarshallingTests.garray_int_none_return())
+
+    def test_garray_utf8_none_return(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_none_return())
+
+    def test_garray_utf8_container_return(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_container_return())
+
+    def test_garray_utf8_full_return(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_full_return())
+
+    def test_garray_int_none_in(self):
+        GIMarshallingTests.garray_int_none_in(Sequence((-1, 0, 1, 2)))
+
+        self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, Sequence((-1, '0', 1, 2)))
+
+        self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, 42)
+        self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, None)
+
+    def test_garray_utf8_none_in(self):
+        GIMarshallingTests.garray_utf8_none_in(Sequence(('0', '1', '2')))
+
+    def test_garray_utf8_container_in(self):
+        GIMarshallingTests.garray_utf8_container_in(Sequence(('0', '1', '2')))
+
+    def test_garray_utf8_full_in(self):
+        GIMarshallingTests.garray_utf8_full_in(Sequence(('0', '1', '2')))
+
+    def test_garray_utf8_none_out(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_none_out())
+
+    def test_garray_utf8_container_out(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_container_out())
+
+    def test_garray_utf8_full_out(self):
+        self.assertEquals(('0', '1', '2'), GIMarshallingTests.garray_utf8_full_out())
+
+    def test_garray_utf8_none_inout(self):
+        self.assertEquals(('-2', '-1', '0', '1'), GIMarshallingTests.garray_utf8_none_inout(Sequence(('0', '1', '2'))))
+
+    def test_garray_utf8_container_inout(self):
+        self.assertEquals(('-2', '-1','0', '1'), GIMarshallingTests.garray_utf8_container_inout(('0', '1', '2')))
+
+    def test_garray_utf8_full_inout(self):
+        self.assertEquals(('-2', '-1','0', '1'), GIMarshallingTests.garray_utf8_full_inout(('0', '1', '2')))
+
+
 class TestGList(unittest.TestCase):
 
     def test_glist_int_none_return(self):



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