tests: Add marshalling test for a boxed struct property
authorMartin Pitt <martinpitt@gnome.org>
Tue, 5 Jun 2012 09:48:15 +0000 (11:48 +0200)
committerMartin Pitt <martinpitt@gnome.org>
Tue, 5 Jun 2012 09:48:47 +0000 (11:48 +0200)
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
tests/gimarshallingtests.h

index aa78154..38c278a 100644 (file)
@@ -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*
index 7300b2a..b687943 100644 (file)
@@ -1005,6 +1005,7 @@ struct _GIMarshallingTestsPropertiesObject {
     gfloat some_float;
     gdouble some_double;
     gchar **some_strv;
+    GIMarshallingTestsBoxedStruct* some_boxed_struct; 
 };
 
 struct _GIMarshallingTestsPropertiesObjectClass {