[glib/wip/nielsdg/g_assert_cmpstrv: 2/2] gio, glib: Use g_assert_cmpstrv where it makes sense




commit 217454261751060e55a48a9e2053e8166a215d93
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Nov 1 16:18:28 2020 +0100

    gio, glib: Use g_assert_cmpstrv where it makes sense

 gio/tests/desktop-app-info.c |  7 ++-----
 glib/tests/gvariant.c        | 24 ++++++------------------
 glib/tests/strfuncs.c        |  4 +---
 3 files changed, 9 insertions(+), 26 deletions(-)
---
diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c
index f4e509a59..27af9934e 100644
--- a/gio/tests/desktop-app-info.c
+++ b/gio/tests/desktop-app-info.c
@@ -350,6 +350,7 @@ wait_for_file (const gchar *want_this,
 static void
 test_actions (void)
 {
+  const char *expected[] = { "frob", "tweak", "twiddle", "broken", NULL };
   const gchar * const *actions;
   GDesktopAppInfo *appinfo;
   gchar *name;
@@ -358,11 +359,7 @@ test_actions (void)
   g_assert_nonnull (appinfo);
 
   actions = g_desktop_app_info_list_actions (appinfo);
-  g_assert_cmpstr (actions[0], ==, "frob");
-  g_assert_cmpstr (actions[1], ==, "tweak");
-  g_assert_cmpstr (actions[2], ==, "twiddle");
-  g_assert_cmpstr (actions[3], ==, "broken");
-  g_assert_cmpstr (actions[4], ==, NULL);
+  g_assert_cmpstrv (actions, expected);
 
   name = g_desktop_app_info_get_action_name (appinfo, "frob");
   g_assert_cmpstr (name, ==, "Frobnicate");
diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c
index 3905e20bc..479881ace 100644
--- a/glib/tests/gvariant.c
+++ b/glib/tests/gvariant.c
@@ -2996,18 +2996,6 @@ 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)
 {
@@ -3157,8 +3145,8 @@ test_varargs (void)
     g_variant_iter_next (&tuple, "^a&s", &strv);
     g_variant_iter_next (&tuple, "^as", &my_strv);
 
-    assert_cmpstrv (strv, strvector);
-    assert_cmpstrv ((const char **)my_strv, strvector);
+    g_assert_cmpstrv (strv, strvector);
+    g_assert_cmpstrv ((const char **)my_strv, strvector);
 
     g_variant_unref (value);
     g_strfreev (my_strv);
@@ -3227,8 +3215,8 @@ test_varargs (void)
     g_variant_iter_next (&tuple, "^a&ay", &strv);
     g_variant_iter_next (&tuple, "^aay", &my_strv);
 
-    assert_cmpstrv (strv, strvector);
-    assert_cmpstrv ((const char **)my_strv, strvector);
+    g_assert_cmpstrv (strv, strvector);
+    g_assert_cmpstrv ((const char **)my_strv, strvector);
 
     g_variant_unref (value);
     g_strfreev (my_strv);
@@ -3276,8 +3264,8 @@ test_varargs (void)
     g_variant_iter_next (&tuple, "^a&o", &strv);
     g_variant_iter_next (&tuple, "^ao", &my_strv);
 
-    assert_cmpstrv (strv, strvector);
-    assert_cmpstrv ((const char **)my_strv, strvector);
+    g_assert_cmpstrv (strv, strvector);
+    g_assert_cmpstrv ((const char **)my_strv, strvector);
 
     g_variant_unref (value);
     g_strfreev (my_strv);
diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c
index 3947fdf9a..37cbc5a8a 100644
--- a/glib/tests/strfuncs.c
+++ b/glib/tests/strfuncs.c
@@ -525,9 +525,7 @@ test_strdupv (void)
 
   copy = g_strdupv (vec);
   g_assert_nonnull (copy);
-  g_assert_cmpstr (copy[0], ==, "Foo");
-  g_assert_cmpstr (copy[1], ==, "Bar");
-  g_assert_null (copy[2]);
+  g_assert_cmpstrv (copy, vec);
   g_strfreev (copy);
 }
 


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