From 7eac7b4c62cdee9804f74e1cf278433de0f826e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 20 Aug 2020 13:37:31 +0200 Subject: [PATCH] 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 "". --- src/test/test-string-util.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index 13936f6d25..1127d398a5 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();