[gobject-introspection] tests: Add marshalling test for a boxed struct property



commit 5b8f63cb767424008a0549a28177574eb7538be9
Author: Martin Pitt <martinpitt gnome org>
Date:   Tue Jun 5 11:48:15 2012 +0200

    tests: Add marshalling test for a boxed struct property
    
    Also make the _copy()/_free() methods for GIMarshallingTestsBoxedStruct get
    along with NULL values.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676603

 tests/gimarshallingtests.c |   19 ++++++++++++++++++-
 tests/gimarshallingtests.h |    1 +
 2 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c
index aa78154..38c278a 100644
--- a/tests/gimarshallingtests.c
+++ b/tests/gimarshallingtests.c
@@ -3469,6 +3469,9 @@ gi_marshalling_tests_boxed_struct_copy (GIMarshallingTestsBoxedStruct *struct_)
 {
     GIMarshallingTestsBoxedStruct *new_struct;
 
+    if (struct_ == NULL)
+        return NULL;
+
     new_struct = g_slice_new (GIMarshallingTestsBoxedStruct);
 
     *new_struct = *struct_;
@@ -3479,7 +3482,8 @@ gi_marshalling_tests_boxed_struct_copy (GIMarshallingTestsBoxedStruct *struct_)
 static void
 gi_marshalling_tests_boxed_struct_free (GIMarshallingTestsBoxedStruct *struct_)
 {
-    g_slice_free (GIMarshallingTestsBoxedStruct, struct_);
+    if (struct_ != NULL)
+        g_slice_free (GIMarshallingTestsBoxedStruct, struct_);
 }
 
 GType
@@ -4444,6 +4448,7 @@ enum  {
     SOME_FLOAT_PROPERTY,
     SOME_DOUBLE_PROPERTY,
     SOME_STRV_PROPERTY,
+    SOME_BOXED_STRUCT_PROPERTY,
 };
 
 G_DEFINE_TYPE (GIMarshallingTestsPropertiesObject, gi_marshalling_tests_properties_object, G_TYPE_OBJECT);
@@ -4501,6 +4506,9 @@ gi_marshalling_tests_properties_object_get_property (GObject * object, guint pro
         case SOME_STRV_PROPERTY:
             g_value_set_boxed (value, self->some_strv);
             break;
+        case SOME_BOXED_STRUCT_PROPERTY:
+            g_value_set_boxed (value, self->some_boxed_struct);
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
             break;
@@ -4550,6 +4558,10 @@ gi_marshalling_tests_properties_object_set_property (GObject * object, guint pro
             g_strfreev (self->some_strv);
             self->some_strv = g_strdupv (g_value_get_boxed (value));
             break;
+        case SOME_BOXED_STRUCT_PROPERTY:
+            gi_marshalling_tests_boxed_struct_free (self->some_boxed_struct);
+            self->some_boxed_struct = gi_marshalling_tests_boxed_struct_copy (g_value_get_boxed (value));
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
             break;
@@ -4612,6 +4624,11 @@ gi_marshalling_tests_properties_object_class_init (GIMarshallingTestsPropertiesO
     g_object_class_install_property (object_class, SOME_STRV_PROPERTY,
         g_param_spec_boxed ("some-strv", "some-strv", "some-strv", G_TYPE_STRV,
             G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
+
+    g_object_class_install_property (object_class, SOME_BOXED_STRUCT_PROPERTY,
+        g_param_spec_boxed ("some-boxed-struct", "some-boxed-struct", "some-boxed-struct", 
+            gi_marshalling_tests_boxed_struct_get_type(),
+            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
 }
 
 GIMarshallingTestsPropertiesObject*
diff --git a/tests/gimarshallingtests.h b/tests/gimarshallingtests.h
index 7300b2a..b687943 100644
--- a/tests/gimarshallingtests.h
+++ b/tests/gimarshallingtests.h
@@ -1005,6 +1005,7 @@ struct _GIMarshallingTestsPropertiesObject {
     gfloat some_float;
     gdouble some_double;
     gchar **some_strv;
+    GIMarshallingTestsBoxedStruct* some_boxed_struct; 
 };
 
 struct _GIMarshallingTestsPropertiesObjectClass {



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