ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
b7dd4d
From d829e7163f6a98547cef3b0106a6a98728275065 Mon Sep 17 00:00:00 2001
b7dd4d
From: Yu Watanabe <watanabe.yu+github@gmail.com>
b7dd4d
Date: Tue, 11 Sep 2018 13:35:27 +0900
b7dd4d
Subject: [PATCH] test: add tests for strv_join_prefix()
b7dd4d
b7dd4d
(cherry picked from commit 474a595af7544a670de70e1eb873bcee1bb00044)
b7dd4d
b7dd4d
Related: #2049788
b7dd4d
---
b7dd4d
 src/test/test-strv.c | 33 +++++++++++++++++++++++++++++++++
b7dd4d
 1 file changed, 33 insertions(+)
b7dd4d
b7dd4d
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
b7dd4d
index 79d999d3ed..9e7d98500f 100644
b7dd4d
--- a/src/test/test-strv.c
b7dd4d
+++ b/src/test/test-strv.c
b7dd4d
@@ -158,6 +158,38 @@ static void test_strv_join(void) {
b7dd4d
         assert_se(streq(w, ""));
b7dd4d
 }
b7dd4d
 
b7dd4d
+static void test_strv_join_prefix(void) {
b7dd4d
+        _cleanup_free_ char *p = NULL, *q = NULL, *r = NULL, *s = NULL, *t = NULL, *v = NULL, *w = NULL;
b7dd4d
+
b7dd4d
+        p = strv_join_prefix((char **)input_table_multiple, ", ", "foo");
b7dd4d
+        assert_se(p);
b7dd4d
+        assert_se(streq(p, "fooone, footwo, foothree"));
b7dd4d
+
b7dd4d
+        q = strv_join_prefix((char **)input_table_multiple, ";", "foo");
b7dd4d
+        assert_se(q);
b7dd4d
+        assert_se(streq(q, "fooone;footwo;foothree"));
b7dd4d
+
b7dd4d
+        r = strv_join_prefix((char **)input_table_multiple, NULL, "foo");
b7dd4d
+        assert_se(r);
b7dd4d
+        assert_se(streq(r, "fooone footwo foothree"));
b7dd4d
+
b7dd4d
+        s = strv_join_prefix((char **)input_table_one, ", ", "foo");
b7dd4d
+        assert_se(s);
b7dd4d
+        assert_se(streq(s, "fooone"));
b7dd4d
+
b7dd4d
+        t = strv_join_prefix((char **)input_table_none, ", ", "foo");
b7dd4d
+        assert_se(t);
b7dd4d
+        assert_se(streq(t, ""));
b7dd4d
+
b7dd4d
+        v = strv_join_prefix((char **)input_table_two_empties, ", ", "foo");
b7dd4d
+        assert_se(v);
b7dd4d
+        assert_se(streq(v, "foo, foo"));
b7dd4d
+
b7dd4d
+        w = strv_join_prefix((char **)input_table_one_empty, ", ", "foo");
b7dd4d
+        assert_se(w);
b7dd4d
+        assert_se(streq(w, "foo"));
b7dd4d
+}
b7dd4d
+
b7dd4d
 static void test_strv_unquote(const char *quoted, char **list) {
b7dd4d
         _cleanup_strv_free_ char **s;
b7dd4d
         _cleanup_free_ char *j;
b7dd4d
@@ -722,6 +754,7 @@ int main(int argc, char *argv[]) {
b7dd4d
         test_strv_find_prefix();
b7dd4d
         test_strv_find_startswith();
b7dd4d
         test_strv_join();
b7dd4d
+        test_strv_join_prefix();
b7dd4d
 
b7dd4d
         test_strv_unquote("    foo=bar     \"waldo\"    zzz    ", STRV_MAKE("foo=bar", "waldo", "zzz"));
b7dd4d
         test_strv_unquote("", STRV_MAKE_EMPTY);