strv: introduce strv_extend_joined() and strv_extend_joined_with_size()

This commit is contained in:
Yu Watanabe
2025-11-01 00:59:36 +09:00
parent 69350ee3e3
commit 19bbcd35d7
3 changed files with 40 additions and 0 deletions
+24
View File
@@ -762,6 +762,30 @@ TEST(strv_extendf_with_size) {
ASSERT_STREQ(a[1], "test3 bar foo 128");
}
TEST(strv_extend_joined) {
_cleanup_strv_free_ char **a = NULL;
ASSERT_OK(strv_extend_joined(&a, "hoge"));
ASSERT_OK(strv_extend_joined(&a, "aaa", "bbb", "ccc"));
ASSERT_EQ(strv_length(a), 2u);
ASSERT_STREQ(a[0], "hoge");
ASSERT_STREQ(a[1], "aaabbbccc");
}
TEST(strv_extend_joined_with_size) {
_cleanup_strv_free_ char **a = NULL;
size_t n = 0;
ASSERT_OK(strv_extend_joined_with_size(&a, &n, "hoge"));
ASSERT_OK(strv_extend_joined_with_size(&a, &n, "aaa", "bbb", "ccc"));
ASSERT_EQ(n, 2u);
ASSERT_EQ(strv_length(a), n);
ASSERT_STREQ(a[0], "hoge");
ASSERT_STREQ(a[1], "aaabbbccc");
}
TEST(strv_foreach) {
_cleanup_strv_free_ char **a;
unsigned i = 0;