summaryrefslogtreecommitdiff
path: root/src/test/test-string-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-08-20 13:37:31 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-08-20 17:42:13 +0200
commit7eac7b4c62cdee9804f74e1cf278433de0f826e9 (patch)
treeb2b19af9c5e638803de04cb6338e0aa89b01ce1c /src/test/test-string-util.c
parentc32c4352b4ac43f4c66c733713a7ed26688dc9b6 (diff)
downloadsystemd-7eac7b4c62cdee9804f74e1cf278433de0f826e9.tar.gz
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 "".
Diffstat (limited to 'src/test/test-string-util.c')
-rw-r--r--src/test/test-string-util.c33
1 files changed, 33 insertions, 0 deletions
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();