summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-02-03 02:05:59 +0100
committerLennart Poettering <lennart@poettering.net>2015-02-03 02:05:59 +0100
commit63c372cb9df3bee01e3bf8cd7f96f336bddda846 (patch)
treebf4d1b6e41f72927a2b58e7dd21daa0c496aaa96 /src/test
parent44de0efc6e406515fc1cf8b95d9655d0d7f7ffff (diff)
util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the same time, add support for NULL sentinels, even if they are normally not necessary.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-conf-files.c8
-rw-r--r--src/test/test-copy.c12
-rw-r--r--src/test/test-namespace.c4
-rw-r--r--src/test/test-path-lookup.c4
-rw-r--r--src/test/test-path.c4
-rw-r--r--src/test/test-tmpfiles.c2
-rw-r--r--src/test/test-util.c36
7 files changed, 41 insertions, 29 deletions
diff --git a/src/test/test-conf-files.c b/src/test/test-conf-files.c
index 71cfc022dd..894c7f742f 100644
--- a/src/test/test-conf-files.c
+++ b/src/test/test-conf-files.c
@@ -59,12 +59,12 @@ static void test_conf_files_list(bool use_root) {
search_2 = "/dir2";
} else {
root_dir = NULL;
- search_1 = strappenda(tmp_dir, "/dir1");
- search_2 = strappenda(tmp_dir, "/dir2");
+ search_1 = strjoina(tmp_dir, "/dir1");
+ search_2 = strjoina(tmp_dir, "/dir2");
}
- expect_a = strappenda(tmp_dir, "/dir1/a.conf");
- expect_b = strappenda(tmp_dir, "/dir2/b.conf");
+ expect_a = strjoina(tmp_dir, "/dir1/a.conf");
+ expect_b = strjoina(tmp_dir, "/dir2/b.conf");
assert_se(conf_files_list(&found_files, ".conf", root_dir, search_1, search_2, NULL) == 0);
strv_print(found_files);
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
index 3e1607e51d..5c96f61005 100644
--- a/src/test/test-copy.c
+++ b/src/test/test-copy.c
@@ -90,15 +90,15 @@ static void test_copy_tree(void) {
rm_rf_dangerous(original_dir, false, true, false);
STRV_FOREACH(p, files) {
- char *f = strappenda(original_dir, *p);
+ char *f = strjoina(original_dir, *p);
assert_se(mkdir_parents(f, 0755) >= 0);
assert_se(write_string_file(f, "file") == 0);
}
STRV_FOREACH_PAIR(link, p, links) {
- char *f = strappenda(original_dir, *p);
- char *l = strappenda(original_dir, *link);
+ char *f = strjoina(original_dir, *p);
+ char *l = strjoina(original_dir, *link);
assert_se(mkdir_parents(l, 0755) >= 0);
assert_se(symlink(f, l) == 0);
@@ -109,7 +109,7 @@ static void test_copy_tree(void) {
STRV_FOREACH(p, files) {
_cleanup_free_ char *buf = NULL;
size_t sz = 0;
- char *f = strappenda(copy_dir, *p);
+ char *f = strjoina(copy_dir, *p);
assert_se(access(f, F_OK) == 0);
assert_se(read_full_file(f, &buf, &sz) == 0);
@@ -118,8 +118,8 @@ static void test_copy_tree(void) {
STRV_FOREACH_PAIR(link, p, links) {
_cleanup_free_ char *target = NULL;
- char *f = strappenda(original_dir, *p);
- char *l = strappenda(copy_dir, *link);
+ char *f = strjoina(original_dir, *p);
+ char *l = strjoina(copy_dir, *link);
assert_se(readlink_and_canonicalize(l, &target) == 0);
assert_se(path_equal(f, target));
diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c
index 084a58f3aa..2397db5fff 100644
--- a/src/test/test-namespace.c
+++ b/src/test/test-namespace.c
@@ -42,8 +42,8 @@ static void test_tmpdir(const char *id, const char *A, const char *B) {
assert_se((x.st_mode & 01777) == 0700);
assert_se((y.st_mode & 01777) == 0700);
- c = strappenda(a, "/tmp");
- d = strappenda(b, "/tmp");
+ c = strjoina(a, "/tmp");
+ d = strjoina(b, "/tmp");
assert_se(stat(c, &x) >= 0);
assert_se(stat(d, &y) >= 0);
diff --git a/src/test/test-path-lookup.c b/src/test/test-path-lookup.c
index a6ce8c9d8d..38e5c93df6 100644
--- a/src/test/test-path-lookup.c
+++ b/src/test/test-path-lookup.c
@@ -33,9 +33,9 @@ static void test_paths(SystemdRunningAs running_as, bool personal) {
char *exists, *not;
assert_se(mkdtemp(template));
- exists = strappenda(template, "/exists");
+ exists = strjoina(template, "/exists");
assert_se(mkdir(exists, 0755) == 0);
- not = strappenda(template, "/not");
+ not = strjoina(template, "/not");
assert_se(lookup_paths_init(&lp, running_as, personal, NULL, exists, not, not) == 0);
diff --git a/src/test/test-path.c b/src/test/test-path.c
index 1512ae2b19..4f9f5c1344 100644
--- a/src/test/test-path.c
+++ b/src/test/test-path.c
@@ -47,7 +47,7 @@ static int setup_test(Manager **m) {
assert_se(manager_startup(tmp, NULL, NULL) >= 0);
STRV_FOREACH(test_path, tests_path) {
- rm_rf_dangerous(strappenda("/tmp/test-path_", *test_path), false, true, false);
+ rm_rf_dangerous(strjoina("/tmp/test-path_", *test_path), false, true, false);
}
*m = tmp;
@@ -201,7 +201,7 @@ static void test_path_directorynotempty(Manager *m) {
assert_se(access(test_path, F_OK) < 0);
assert_se(mkdir_p(test_path, 0755) >= 0);
- assert_se(touch(strappenda(test_path, "test_file")) >= 0);
+ assert_se(touch(strjoina(test_path, "test_file")) >= 0);
check_stop_unlink(m, unit, test_path, NULL);
}
diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c
index 84050c6fa4..4b72c4a8fa 100644
--- a/src/test/test-tmpfiles.c
+++ b/src/test/test-tmpfiles.c
@@ -30,7 +30,7 @@
int main(int argc, char** argv) {
const char *p = argv[1] ?: "/tmp";
- char *pattern = strappenda(p, "/systemd-test-XXXXXX");
+ char *pattern = strjoina(p, "/systemd-test-XXXXXX");
_cleanup_close_ int fd, fd2;
_cleanup_free_ char *cmd, *cmd2;
diff --git a/src/test/test-util.c b/src/test/test-util.c
index f2b7038a4d..804f522e92 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -1072,17 +1072,29 @@ static void test_strshorten(void) {
assert_se(strlen(strshorten(s, 0)) == 0);
}
-static void test_strappenda(void) {
+static void test_strjoina(void) {
char *actual;
- actual = strappenda("", "foo", "bar");
+ actual = strjoina("", "foo", "bar");
assert_se(streq(actual, "foobar"));
- actual = strappenda("foo", "bar", "baz");
+ actual = strjoina("foo", "bar", "baz");
assert_se(streq(actual, "foobarbaz"));
- actual = strappenda("foo", "", "bar", "baz");
+ actual = strjoina("foo", "", "bar", "baz");
assert_se(streq(actual, "foobarbaz"));
+
+ actual = strjoina("foo");
+ assert_se(streq(actual, "foo"));
+
+ actual = strjoina(NULL);
+ assert_se(streq(actual, ""));
+
+ actual = strjoina(NULL, "foo");
+ assert_se(streq(actual, ""));
+
+ actual = strjoina("foo", NULL, "bar");
+ assert_se(streq(actual, "foo"));
}
static void test_is_symlink(void) {
@@ -1231,13 +1243,13 @@ static void test_execute_directory(void) {
assert_se(mkdtemp(template_lo));
assert_se(mkdtemp(template_hi));
- name = strappenda(template_lo, "/script");
- name2 = strappenda(template_hi, "/script2");
- name3 = strappenda(template_lo, "/useless");
- overridden = strappenda(template_lo, "/overridden");
- override = strappenda(template_hi, "/overridden");
- masked = strappenda(template_lo, "/masked");
- mask = strappenda(template_hi, "/masked");
+ name = strjoina(template_lo, "/script");
+ name2 = strjoina(template_hi, "/script2");
+ name3 = strjoina(template_lo, "/useless");
+ overridden = strjoina(template_lo, "/overridden");
+ override = strjoina(template_hi, "/overridden");
+ masked = strjoina(template_lo, "/masked");
+ mask = strjoina(template_hi, "/masked");
assert_se(write_string_file(name, "#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/it_works") == 0);
assert_se(write_string_file(name2, "#!/bin/sh\necho 'Executing '$0\ntouch $(dirname $0)/it_works2") == 0);
@@ -1562,7 +1574,7 @@ int main(int argc, char *argv[]) {
test_read_one_char();
test_ignore_signals();
test_strshorten();
- test_strappenda();
+ test_strjoina();
test_is_symlink();
test_pid_is_unwaited();
test_pid_is_alive();