test-gvariant: Add test for ^ay, ^&ay, ^aay, ^a&ay

This will exhibit bugs in g_variant_valist_free_nnp() as these types are
not properly handled.
This commit is contained in:
Christophe Fergeau 2018-10-25 11:14:22 +01:00
parent 361fed5d75
commit 7d1b94d71a

View File

@ -3115,6 +3115,81 @@ test_varargs (void)
g_free (strv);
}
{
const gchar *strvector[] = {"/hello", "/world", NULL};
const gchar *test_strs[] = {"/foo", "/bar", "/baz" };
GVariantBuilder builder;
GVariantIter *array;
GVariantIter tuple;
const gchar **strv;
gchar **my_strv;
GVariant *value;
gchar *str;
gint i;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("aaay"));
g_variant_builder_add (&builder, "^aay", strvector);
g_variant_builder_add (&builder, "^aay", strvector);
g_variant_builder_add (&builder, "^aay", strvector);
value = g_variant_new ("aaay", &builder);
g_variant_iter_init (&tuple, value);
i = 0;
while (g_variant_iter_loop (&tuple, "^aay", &my_strv)) {
i++;
}
g_assert (i == 3);
/* start over */
g_variant_iter_init (&tuple, value);
i = 0;
while (g_variant_iter_loop (&tuple, "^a&ay", &strv)) {
i++;
}
g_assert (i == 3);
g_variant_unref (value);
/* next test */
g_variant_builder_init (&builder, G_VARIANT_TYPE ("aay"));
g_variant_builder_add (&builder, "^ay", "/foo");
g_variant_builder_add (&builder, "^ay", "/bar");
g_variant_builder_add (&builder, "^ay", "/baz");
value = g_variant_new("(aay^aay^a&ay)", &builder, strvector, strvector);
g_variant_iter_init (&tuple, value);
g_variant_iter_next (&tuple, "aay", &array);
i = 0;
while (g_variant_iter_loop (array, "^ay", &str))
g_assert_cmpstr (str, ==, test_strs[i++]);
g_assert (i == 3);
g_variant_iter_free (array);
/* start over */
g_variant_iter_init (&tuple, value);
g_variant_iter_next (&tuple, "aay", &array);
i = 0;
while (g_variant_iter_loop (array, "^&ay", &str))
g_assert_cmpstr (str, ==, test_strs[i++]);
g_assert (i == 3);
g_variant_iter_free (array);
g_variant_iter_next (&tuple, "^a&ay", &strv);
g_variant_iter_next (&tuple, "^aay", &my_strv);
g_assert_cmpstr (strv[0], ==, "/hello");
g_assert_cmpstr (strv[1], ==, "/world");
g_assert (strv[2] == NULL);
g_assert_cmpstr (my_strv[0], ==, "/hello");
g_assert_cmpstr (my_strv[1], ==, "/world");
g_assert (my_strv[2] == NULL);
g_variant_unref (value);
g_strfreev (my_strv);
g_free (strv);
}
{
const gchar *strvector[] = {"/hello", "/world", NULL};
const gchar *test_strs[] = {"/foo", "/bar", "/baz" };