From: Zbigniew Jędrzejewski-Szmek Date: Thu, 20 Aug 2020 11:37:31 +0000 (+0200) Subject: test-string-util: add a test for strjoin() X-Git-Tag: v247-rc1~387^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7eac7b4c62cdee9804f74e1cf278433de0f826e9;p=thirdparty%2Fsystemd.git test-string-util: add a test for strjoin() Strangely, we didn't have one so far. I mostly wanted to verify that NULL can be used in any spot at behaves the same as "". --- diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 13936f6d25f..1127d398a5f 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -326,6 +326,38 @@ static void test_strjoina(void) { assert_se(streq(actual, "foo")); } +static void test_strjoin(void) { + char *actual; + + actual = strjoin("", "foo", "bar"); + assert_se(streq(actual, "foobar")); + mfree(actual); + + actual = strjoin("foo", "bar", "baz"); + assert_se(streq(actual, "foobarbaz")); + mfree(actual); + + actual = strjoin("foo", "", "bar", "baz"); + assert_se(streq(actual, "foobarbaz")); + mfree(actual); + + actual = strjoin("foo", NULL); + assert_se(streq(actual, "foo")); + mfree(actual); + + actual = strjoin(NULL, NULL); + assert_se(streq(actual, "")); + mfree(actual); + + actual = strjoin(NULL, "foo"); + assert_se(streq(actual, "")); + mfree(actual); + + actual = strjoin("foo", NULL, "bar"); + assert_se(streq(actual, "foo")); + mfree(actual); +} + static void test_strcmp_ptr(void) { assert_se(strcmp_ptr(NULL, NULL) == 0); assert_se(strcmp_ptr("", NULL) > 0); @@ -727,6 +759,7 @@ int main(int argc, char *argv[]) { test_ascii_strlower(); test_strshorten(); test_strjoina(); + test_strjoin(); test_strcmp_ptr(); test_foreach_word(); test_foreach_word_quoted();