51 lines
1.7 KiB
Diff
51 lines
1.7 KiB
Diff
From 10fa59adb6e7a1df537c939e1de90a4abe880a87 Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Tue, 6 Dec 2022 12:00:45 +0900
|
|
Subject: [PATCH] test: add basic tests for octescape()
|
|
|
|
(cherry picked from commit 4f438c638b5335cd5d8f614804743a04311689f8)
|
|
(cherry picked from commit bc6fc812fdd56925b4125395d537fc8af9ffc58d)
|
|
|
|
Conflict:adapt test cases based on the existing test case framework
|
|
Reference:https://github.com/systemd/systemd-stable/commit/10fa59adb6e7a1df537c939e1de90a4abe880a87
|
|
---
|
|
src/test/test-escape.c | 17 +++++++++++++++++
|
|
1 file changed, 17 insertions(+)
|
|
|
|
diff --git a/src/test/test-escape.c b/src/test/test-escape.c
|
|
index 8bda9cd..240545c 100644
|
|
--- a/src/test/test-escape.c
|
|
+++ b/src/test/test-escape.c
|
|
@@ -215,6 +215,22 @@ static void test_quote_command_line(void) {
|
|
"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));
|
|
+}
|
|
+
|
|
+static void test_octescap(void) {
|
|
+ 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");
|
|
+}
|
|
+
|
|
int main(int argc, char *argv[]) {
|
|
test_setup_logging(LOG_DEBUG);
|
|
|
|
@@ -226,6 +242,7 @@ int main(int argc, char *argv[]) {
|
|
test_shell_escape();
|
|
test_shell_maybe_quote();
|
|
test_quote_command_line();
|
|
+ test_octescap();
|
|
|
|
return 0;
|
|
}
|
|
--
|
|
2.33.0
|