[glib: 1/8] test-gvariant: Add test for ^ay, ^&ay, ^aay, ^a&ay



commit 7d1b94d71aa675e401be805a943fec8056961b5e
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Thu Oct 25 11:14:22 2018 +0100

    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.

 glib/tests/gvariant.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
---
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
index 54cef6777..912b13a7b 100644
--- a/glib/tests/gvariant.c
+++ b/glib/tests/gvariant.c
@@ -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" };


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