summaryrefslogtreecommitdiffstats
path: root/src/test/test-strv.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-03-05 01:29:57 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-03-05 01:29:57 +0100
commitf385c447870e0783814b37cb11a38187533458db (patch)
treef7e8f12e618a407938fe97fd0a1db58527c89c22 /src/test/test-strv.c
parentcopy: move sync_rights() to copy.c and rename copy_rights() (diff)
downloadsystemd-f385c447870e0783814b37cb11a38187533458db.tar.xz
systemd-f385c447870e0783814b37cb11a38187533458db.zip
strv: introduce strv_split_newlines_full()
Diffstat (limited to 'src/test/test-strv.c')
-rw-r--r--src/test/test-strv.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/test-strv.c b/src/test/test-strv.c
index 6b5005f9fc..162d8bed95 100644
--- a/src/test/test-strv.c
+++ b/src/test/test-strv.c
@@ -118,6 +118,20 @@ static const char* const input_table_one_empty[] = {
NULL,
};
+static const char* const input_table_unescape[] = {
+ "ID_VENDOR=QEMU",
+ "ID_VENDOR_ENC=QEMUx20x20x20x20",
+ "ID_MODEL_ENC=QEMUx20HARDDISKx20x20x20",
+ NULL,
+};
+
+static const char* const input_table_retain_escape[] = {
+ "ID_VENDOR=QEMU",
+ "ID_VENDOR_ENC=QEMU\\x20\\x20\\x20\\x20",
+ "ID_MODEL_ENC=QEMU\\x20HARDDISK\\x20\\x20\\x20",
+ NULL,
+};
+
static void test_strv_find(void) {
log_info("/* %s */", __func__);
@@ -453,6 +467,25 @@ static void test_strv_split_newlines(void) {
assert_se(streq(*s, input_table_multiple[i++]));
}
+static void test_strv_split_newlines_full(void) {
+ const char str[] =
+ "ID_VENDOR=QEMU\n"
+ "ID_VENDOR_ENC=QEMU\\x20\\x20\\x20\\x20\n"
+ "ID_MODEL_ENC=QEMU\\x20HARDDISK\\x20\\x20\\x20\n"
+ "\n\n\n";
+ _cleanup_strv_free_ char **l = NULL;
+
+ log_info("/* %s */", __func__);
+
+ assert_se(strv_split_newlines_full(&l, str, 0) == 3);
+ assert_se(strv_equal(l, (char**) input_table_unescape));
+
+ l = strv_free(l);
+
+ assert_se(strv_split_newlines_full(&l, str, EXTRACT_RETAIN_ESCAPE) == 3);
+ assert_se(strv_equal(l, (char**) input_table_retain_escape));
+}
+
static void test_strv_split_nulstr(void) {
_cleanup_strv_free_ char **l = NULL;
const char nulstr[] = "str0\0str1\0str2\0str3\0";
@@ -1031,6 +1064,7 @@ int main(int argc, char *argv[]) {
test_strv_split_full();
test_strv_split_colon_pairs();
test_strv_split_newlines();
+ test_strv_split_newlines_full();
test_strv_split_nulstr();
test_strv_parse_nulstr();
test_strv_overlap();