summaryrefslogtreecommitdiffstats
path: root/src/test/test-strv.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-02-16 15:41:55 +0100
committerLennart Poettering <lennart@poettering.net>2023-02-17 09:55:35 +0100
commit4ea517a6e07f47117348c68c6fe087bf6d401558 (patch)
tree1fa110ee7ee35a2c987c6e19f37d3c0606a91931 /src/test/test-strv.c
parentman: document new --kill-value= switch to systemctl (diff)
downloadsystemd-4ea517a6e07f47117348c68c6fe087bf6d401558.tar.xz
systemd-4ea517a6e07f47117348c68c6fe087bf6d401558.zip
strv: add strv_copy_n() helper for copying part of a n strv
Diffstat (limited to '')
-rw-r--r--src/test/test-strv.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index 5c03eaa960..0f08dd4615 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -954,4 +954,44 @@ TEST(strv_extend_join) {
assert_se(streq(v[1], "ABC=QER"));
}
+TEST(strv_copy_n) {
+ char **x = STRV_MAKE("a", "b", "c", "d", "e");
+ _cleanup_strv_free_ char **l = NULL;
+
+ l = strv_copy_n(x, 0);
+ assert_se(strv_equal(l, NULL));
+ strv_free(l);
+
+ l = strv_copy_n(x, 0);
+ assert_se(strv_equal(l, (char**) { NULL }));
+ strv_free(l);
+
+ l = strv_copy_n(x, 1);
+ assert_se(strv_equal(l, STRV_MAKE("a")));
+ strv_free(l);
+
+ l = strv_copy_n(x, 2);
+ assert_se(strv_equal(l, STRV_MAKE("a", "b")));
+ strv_free(l);
+
+ l = strv_copy_n(x, 3);
+ assert_se(strv_equal(l, STRV_MAKE("a", "b", "c")));
+ strv_free(l);
+
+ l = strv_copy_n(x, 4);
+ assert_se(strv_equal(l, STRV_MAKE("a", "b", "c", "d")));
+ strv_free(l);
+
+ l = strv_copy_n(x, 5);
+ assert_se(strv_equal(l, STRV_MAKE("a", "b", "c", "d", "e")));
+ strv_free(l);
+
+ l = strv_copy_n(x, 6);
+ assert_se(strv_equal(l, STRV_MAKE("a", "b", "c", "d", "e")));
+ strv_free(l);
+
+ l = strv_copy_n(x, SIZE_MAX);
+ assert_se(strv_equal(l, STRV_MAKE("a", "b", "c", "d", "e")));
+}
+
DEFINE_TEST_MAIN(LOG_INFO);