[pygobject] Support setting string fields in structs



commit 58bd307c57d542a8f69867dea2d0a0eb51230c7b
Author: Vadim Rutkovsky <vrutkovs redhat com>
Date:   Fri Jan 11 15:41:27 2013 +0100

    Support setting string fields in structs
    
    Co-Authored-By: Martin Pitt <martinpitt gnome org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=678401

 gi/pygi-info.c   |    3 ++-
 tests/test_gi.py |   16 ++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/gi/pygi-info.c b/gi/pygi-info.c
index e726b2d..cd3d97d 100644
--- a/gi/pygi-info.c
+++ b/gi/pygi-info.c
@@ -1510,7 +1510,8 @@ _wrap_g_field_info_set_value (PyGIBaseInfo *self,
 
         g_base_info_unref (info);
     } else if (g_type_info_is_pointer (field_type_info)
-            && g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_VOID) {
+            && (g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_VOID
+                || g_type_info_get_tag (field_type_info) == GI_TYPE_TAG_UTF8)) {
 
         value = _pygi_argument_from_object (py_value, field_type_info, GI_TRANSFER_NOTHING);
         if (PyErr_Occurred()) {
diff --git a/tests/test_gi.py b/tests/test_gi.py
index a1c167f..5fd5261 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1752,6 +1752,7 @@ class TestStructure(unittest.TestCase):
         self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
 
         self.assertEqual(0, struct.long_)
+        self.assertEqual(None, struct.string_)
         self.assertEqual([], struct.g_strv)
 
         del struct
@@ -1759,14 +1760,20 @@ class TestStructure(unittest.TestCase):
     def test_boxed_struct_new(self):
         struct = GIMarshallingTests.BoxedStruct.new()
         self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
+        self.assertEqual(struct.long_, 0)
+        self.assertEqual(struct.string_, None)
 
         del struct
 
     def test_boxed_struct_copy(self):
         struct = GIMarshallingTests.BoxedStruct()
+        struct.long_ = 42
+        struct.string_ = 'hello'
 
         new_struct = struct.copy()
         self.assertTrue(isinstance(new_struct, GIMarshallingTests.BoxedStruct))
+        self.assertEqual(new_struct.long_, 42)
+        self.assertEqual(new_struct.string_, 'hello')
 
         del new_struct
         del struct
@@ -1776,6 +1783,7 @@ class TestStructure(unittest.TestCase):
 
         self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
         self.assertEqual(42, struct.long_)
+        self.assertEqual('hello', struct.string_)
         self.assertEqual(['0', '1', '2'], struct.g_strv)
 
         del struct
@@ -1808,6 +1816,14 @@ class TestStructure(unittest.TestCase):
         del in_struct
         del out_struct
 
+    def test_struct_field_assignment(self):
+        struct = GIMarshallingTests.BoxedStruct()
+
+        struct.long_ = 42
+        struct.string_ = 'hello'
+        self.assertEqual(struct.long_, 42)
+        self.assertEqual(struct.string_, 'hello')
+
     def test_union(self):
         union = GIMarshallingTests.Union()
 



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