1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-26 14:04:03 +03:00

test: add test cases for EXTRACT_KEEP_QUOTE and EXTRACT_UNQUOTE

This commit is contained in:
Yu Watanabe 2021-06-21 21:11:23 +09:00
parent 1104d11429
commit f59551f18e

View File

@ -442,6 +442,46 @@ static void test_extract_first_word(void) {
assert_se(extract_first_word(&p, &t, "=\", ", 0) > 0);
assert_se(streq(t, "baldo"));
free(t);
p = original = "mode=\"1777\",size=\"10%\",nr_inodes=\"400\"k,uid=\"496,,107\"520,gi\"\"'d=49610,'\"\"7520,context=\"system_u:object_r:svirt_sandbox_file_t:s0:c0,c1\"";
assert_se(extract_first_word(&p, &t, ",", EXTRACT_KEEP_QUOTE) > 0);
assert_se(streq(t, "mode=\"1777\""));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_KEEP_QUOTE) > 0);
assert_se(streq(t, "size=\"10%\""));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_KEEP_QUOTE) > 0);
assert_se(streq(t, "nr_inodes=\"400\"k"));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_KEEP_QUOTE) > 0);
assert_se(streq(t, "uid=\"496,,107\"520"));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_KEEP_QUOTE) > 0);
assert_se(streq(t, "gi\"\"'d=49610,'\"\"7520"));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_KEEP_QUOTE) > 0);
assert_se(streq(t, "context=\"system_u:object_r:svirt_sandbox_file_t:s0:c0,c1\""));
free(t);
p = original = "mode=\"1777\",size=\"10%\",nr_inodes=\"400\"k,uid=\"496,,107\"520,gi\"\"'d=49610,'\"\"7520,context=\"system_u:object_r:svirt_sandbox_file_t:s0:c0,c1\"";
assert_se(extract_first_word(&p, &t, ",", EXTRACT_UNQUOTE) > 0);
assert_se(streq(t, "mode=1777"));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_UNQUOTE) > 0);
assert_se(streq(t, "size=10%"));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_UNQUOTE) > 0);
assert_se(streq(t, "nr_inodes=400k"));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_UNQUOTE) > 0);
assert_se(streq(t, "uid=496,,107520"));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_UNQUOTE) > 0);
assert_se(streq(t, "gid=49610,7520"));
free(t);
assert_se(extract_first_word(&p, &t, ",", EXTRACT_UNQUOTE) > 0);
assert_se(streq(t, "context=system_u:object_r:svirt_sandbox_file_t:s0:c0,c1"));
free(t);
}
static void test_extract_first_word_and_warn(void) {