diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-12-06 04:00:45 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-12-06 04:18:14 +0100 |
commit | 4f438c638b5335cd5d8f614804743a04311689f8 (patch) | |
tree | e97ab010bc4cd8cbb5de5e967e21952342c2538c /src/test/test-escape.c | |
parent | escape: fix wrong octescape of bad character (diff) | |
download | systemd-4f438c638b5335cd5d8f614804743a04311689f8.tar.xz systemd-4f438c638b5335cd5d8f614804743a04311689f8.zip |
test: add basic tests for octescape()
Diffstat (limited to '')
-rw-r--r-- | src/test/test-escape.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/test-escape.c b/src/test/test-escape.c index da19272624..de82020d5f 100644 --- a/src/test/test-escape.c +++ b/src/test/test-escape.c @@ -219,4 +219,20 @@ TEST(quote_command_line) { "true \"\\$dollar\""); } +static void test_octescape_one(const char *s, const char *expected) { + _cleanup_free_ char *ret; + + assert_se(ret = octescape(s, strlen_ptr(s))); + log_debug("octescape(\"%s\") → \"%s\" (expected: \"%s\")", strnull(s), ret, expected); + assert_se(streq(ret, expected)); +} + +TEST(octescape) { + test_octescape_one(NULL, ""); + test_octescape_one("", ""); + test_octescape_one("foo", "foo"); + test_octescape_one("\"\\\"", "\\042\\134\\042"); + test_octescape_one("\123\213\222", "\123\\213\\222"); +} + DEFINE_TEST_MAIN(LOG_DEBUG); |