mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-15 04:05:11 +01:00
Merge branch 'backport-1043-variant-bytes-glib-2-62' into 'glib-2-62'
Backport !1043 “gvariant: Handle empty serialisations in get_child_value()” to glib-2-62 See merge request GNOME/glib!1128
This commit is contained in:
commit
ed8c69eb03
@ -949,6 +949,12 @@ g_variant_get_data_as_bytes (GVariant *value)
|
|||||||
data = value->contents.serialised.data;
|
data = value->contents.serialised.data;
|
||||||
size = value->size;
|
size = value->size;
|
||||||
|
|
||||||
|
if (data == NULL)
|
||||||
|
{
|
||||||
|
g_assert (size == 0);
|
||||||
|
data = bytes_data;
|
||||||
|
}
|
||||||
|
|
||||||
if (data == bytes_data && size == bytes_size)
|
if (data == bytes_data && size == bytes_size)
|
||||||
return g_bytes_ref (value->contents.serialised.bytes);
|
return g_bytes_ref (value->contents.serialised.bytes);
|
||||||
else
|
else
|
||||||
|
@ -2303,6 +2303,46 @@ test_byteswaps (void)
|
|||||||
g_variant_type_info_assert_no_infos ();
|
g_variant_type_info_assert_no_infos ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_serialiser_children (void)
|
||||||
|
{
|
||||||
|
GBytes *data1, *data2;
|
||||||
|
GVariant *child1, *child2;
|
||||||
|
GVariantType *mv_type = g_variant_type_new_maybe (G_VARIANT_TYPE_VARIANT);
|
||||||
|
GVariant *variant, *child;
|
||||||
|
|
||||||
|
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/issues/1865");
|
||||||
|
g_test_summary ("Test that getting a child variant before and after "
|
||||||
|
"serialisation of the parent works");
|
||||||
|
|
||||||
|
/* Construct a variable sized array containing a child which serialises to a
|
||||||
|
* zero-length bytestring. */
|
||||||
|
child = g_variant_new_maybe (G_VARIANT_TYPE_VARIANT, NULL);
|
||||||
|
variant = g_variant_new_array (mv_type, &child, 1);
|
||||||
|
|
||||||
|
/* Get the child before serialising. */
|
||||||
|
child1 = g_variant_get_child_value (variant, 0);
|
||||||
|
data1 = g_variant_get_data_as_bytes (child1);
|
||||||
|
|
||||||
|
/* Serialise the parent variant. */
|
||||||
|
g_variant_get_data (variant);
|
||||||
|
|
||||||
|
/* Get the child again after serialising — this uses a different code path. */
|
||||||
|
child2 = g_variant_get_child_value (variant, 0);
|
||||||
|
data2 = g_variant_get_data_as_bytes (child2);
|
||||||
|
|
||||||
|
/* Check things are equal. */
|
||||||
|
g_assert_cmpvariant (child1, child2);
|
||||||
|
g_assert_true (g_bytes_equal (data1, data2));
|
||||||
|
|
||||||
|
g_variant_unref (child2);
|
||||||
|
g_variant_unref (child1);
|
||||||
|
g_variant_unref (variant);
|
||||||
|
g_bytes_unref (data2);
|
||||||
|
g_bytes_unref (data1);
|
||||||
|
g_variant_type_free (mv_type);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_fuzz (gdouble *fuzziness)
|
test_fuzz (gdouble *fuzziness)
|
||||||
{
|
{
|
||||||
@ -5075,6 +5115,7 @@ main (int argc, char **argv)
|
|||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
g_test_init (&argc, &argv, NULL);
|
g_test_init (&argc, &argv, NULL);
|
||||||
|
g_test_bug_base ("");
|
||||||
|
|
||||||
g_test_add_func ("/gvariant/type", test_gvarianttype);
|
g_test_add_func ("/gvariant/type", test_gvarianttype);
|
||||||
g_test_add_func ("/gvariant/type/string-scan/recursion/tuple",
|
g_test_add_func ("/gvariant/type/string-scan/recursion/tuple",
|
||||||
@ -5088,6 +5129,7 @@ main (int argc, char **argv)
|
|||||||
g_test_add_func ("/gvariant/serialiser/variant", test_variants);
|
g_test_add_func ("/gvariant/serialiser/variant", test_variants);
|
||||||
g_test_add_func ("/gvariant/serialiser/strings", test_strings);
|
g_test_add_func ("/gvariant/serialiser/strings", test_strings);
|
||||||
g_test_add_func ("/gvariant/serialiser/byteswap", test_byteswaps);
|
g_test_add_func ("/gvariant/serialiser/byteswap", test_byteswaps);
|
||||||
|
g_test_add_func ("/gvariant/serialiser/children", test_serialiser_children);
|
||||||
|
|
||||||
for (i = 1; i <= 20; i += 4)
|
for (i = 1; i <= 20; i += 4)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user