[glib: 6/8] test-gvariant: Add and use assert_cmpstrv helper



commit 38d48b818a095d965924d494ac6130a0385e1164
Author: Christophe Fergeau <cfergeau redhat com>
Date:   Tue Oct 30 21:03:48 2018 +0100

    test-gvariant: Add and use assert_cmpstrv helper
    
    Signed-off-by: Christophe Fergeau <cfergeau redhat com>

 glib/tests/gvariant.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
---
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
index bb7fae624..ac857412f 100644
--- a/glib/tests/gvariant.c
+++ b/glib/tests/gvariant.c
@@ -2956,6 +2956,18 @@ test_varargs_empty_array (void)
   g_assert_not_reached ();
 }
 
+static void
+assert_cmpstrv (const gchar **strv1, const gchar **strv2)
+{
+  gsize i;
+
+  for (i = 0; strv1[i] != NULL && strv2[i] != NULL; i++)
+    g_assert_cmpstr (strv1[i], ==, strv2[i]);
+
+  g_assert_null (strv1[i]);
+  g_assert_null (strv2[i]);
+}
+
 static void
 test_varargs (void)
 {
@@ -3105,12 +3117,8 @@ test_varargs (void)
     g_variant_iter_next (&tuple, "^a&s", &strv);
     g_variant_iter_next (&tuple, "^as", &my_strv);
 
-    g_assert_cmpstr (strv[0], ==, "/hello");
-    g_assert_cmpstr (strv[1], ==, "/world");
-    g_assert_null (strv[2]);
-    g_assert_cmpstr (my_strv[0], ==, "/hello");
-    g_assert_cmpstr (my_strv[1], ==, "/world");
-    g_assert_null (my_strv[2]);
+    assert_cmpstrv (strv, strvector);
+    assert_cmpstrv ((const char **)my_strv, strvector);
 
     g_variant_unref (value);
     g_strfreev (my_strv);
@@ -3179,12 +3187,8 @@ test_varargs (void)
     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_null (strv[2]);
-    g_assert_cmpstr (my_strv[0], ==, "/hello");
-    g_assert_cmpstr (my_strv[1], ==, "/world");
-    g_assert_null (my_strv[2]);
+    assert_cmpstrv (strv, strvector);
+    assert_cmpstrv ((const char **)my_strv, strvector);
 
     g_variant_unref (value);
     g_strfreev (my_strv);
@@ -3232,12 +3236,8 @@ test_varargs (void)
     g_variant_iter_next (&tuple, "^a&o", &strv);
     g_variant_iter_next (&tuple, "^ao", &my_strv);
 
-    g_assert_cmpstr (strv[0], ==, "/hello");
-    g_assert_cmpstr (strv[1], ==, "/world");
-    g_assert_null (strv[2]);
-    g_assert_cmpstr (my_strv[0], ==, "/hello");
-    g_assert_cmpstr (my_strv[1], ==, "/world");
-    g_assert_null (my_strv[2]);
+    assert_cmpstrv (strv, strvector);
+    assert_cmpstrv ((const char **)my_strv, strvector);
 
     g_variant_unref (value);
     g_strfreev (my_strv);


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