diff options
| author | Emmanuele Bassi <ebassi@linux.intel.com> | 2011-08-23 20:42:15 +0100 | 
|---|---|---|
| committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2011-08-23 20:42:15 +0100 | 
| commit | c2f5b8bc64f9ac06b2dda8662924d88cc759718e (patch) | |
| tree | cabd60183519378fb298b3907ac76789b78eaa05 /json-glib/tests/serialize-complex.c | |
| parent | bcfac335a8e4086ff6afa5f267f9886a4d1b6370 (diff) | |
| download | json-glib-c2f5b8bc64f9ac06b2dda8662924d88cc759718e.tar.gz | |
gobject: Deserialize CONSTRUCT properties
While we have to give up deserializing CONSTRUCT_ONLY properties with
JsonSerializable, CONSTRUCT properties should just be deserialized like
any other property.
Sadly, there's still a refuse in the json_gobject_new() code that skips
CONSTRUCT properties along with CONSTRUCT_ONLY ones — a remnant of a
period when we deserialized them both without JsonSerializable.
https://bugzilla.gnome.org/show_bug.cgi?id=655526
Diffstat (limited to 'json-glib/tests/serialize-complex.c')
| -rw-r--r-- | json-glib/tests/serialize-complex.c | 19 | 
1 files changed, 18 insertions, 1 deletions
| diff --git a/json-glib/tests/serialize-complex.c b/json-glib/tests/serialize-complex.c index 86eca85..4594fdb 100644 --- a/json-glib/tests/serialize-complex.c +++ b/json-glib/tests/serialize-complex.c @@ -33,6 +33,7 @@ struct _TestObject    gboolean bar;    gchar *baz;    TestBoxed blah; +  gdouble meh;  };  struct _TestObjectClass @@ -83,7 +84,8 @@ enum    PROP_FOO,    PROP_BAR,    PROP_BAZ, -  PROP_BLAH +  PROP_BLAH, +  PROP_MEH  };  static JsonSerializableIface *serializable_iface = NULL; @@ -167,6 +169,9 @@ test_object_set_property (GObject      *gobject,        g_free (TEST_OBJECT (gobject)->baz);        TEST_OBJECT (gobject)->baz = g_value_dup_string (value);        break; +    case PROP_MEH: +      TEST_OBJECT (gobject)->meh = g_value_get_double (value); +      break;      default:        G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);      } @@ -192,6 +197,9 @@ test_object_get_property (GObject    *gobject,      case PROP_BLAH:        g_value_set_boxed (value, &(TEST_OBJECT (gobject)->blah));        break; +    case PROP_MEH: +      g_value_set_double (value, TEST_OBJECT (gobject)->meh); +      break;      default:        G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);      } @@ -226,6 +234,12 @@ test_object_class_init (TestObjectClass *klass)                                     g_param_spec_boxed ("blah", "Blah", "Blah",                                                         TEST_TYPE_BOXED,                                                         G_PARAM_READABLE)); +  g_object_class_install_property (gobject_class, +                                   PROP_MEH, +                                   g_param_spec_double ("meh", "Meh", "Meh", +                                                        0.0, 1.0, 0.0, +                                                        G_PARAM_READWRITE | +                                                        G_PARAM_CONSTRUCT));  }  static void @@ -234,6 +248,7 @@ test_object_init (TestObject *object)    object->foo = 42;    object->bar = TRUE;    object->baz = g_strdup ("Test"); +  object->meh = 0.0;    object->blah.foo = object->foo;    object->blah.bar = object->bar; @@ -246,6 +261,7 @@ test_serialize (void)                                    "foo", 47,                                    "bar", FALSE,                                    "baz", "Hello, World!", +                                  "meh", 0.5,                                    NULL);    JsonParser *parser = json_parser_new ();    GError *error = NULL; @@ -271,6 +287,7 @@ test_serialize (void)    g_assert_cmpint (json_object_get_int_member (object, "foo"), ==, 47);    g_assert (!json_object_get_boolean_member (object, "bar"));    g_assert_cmpstr (json_object_get_string_member (object, "baz"), ==, "Hello, World!"); +  g_assert_cmpfloat (json_object_get_double_member (object, "meh"), ==, 0.5);    /* blah is read-only */    g_assert (json_object_has_member (object, "blah")); | 
