]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-device-nodes.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "alloc-util.h"
7 #include "device-nodes.h"
8 #include "string-util.h"
11 /* helpers for test_encode_devnode_name */
12 static char *do_encode_string(const char *in
) {
13 size_t out_len
= strlen(in
) * 4 + 1;
14 char *out
= malloc(out_len
);
17 assert_se(encode_devnode_name(in
, out
, out_len
) >= 0);
23 static bool expect_encoded_as(const char *in
, const char *expected
) {
24 _cleanup_free_
char *encoded
= do_encode_string(in
);
25 return streq(encoded
, expected
);
28 TEST(encode_devnode_name
) {
29 assert_se(expect_encoded_as("systemd sucks", "systemd\\x20sucks"));
30 assert_se(expect_encoded_as("pinkiepie", "pinkiepie"));
31 assert_se(expect_encoded_as("valíd\\ųtf8", "valíd\\x5cųtf8"));
32 assert_se(expect_encoded_as("s/ash/ng", "s\\x2fash\\x2fng"));
33 assert_se(expect_encoded_as("/", "\\x2f"));
34 assert_se(expect_encoded_as("!", "\\x21"));
35 assert_se(expect_encoded_as("QEMU ", "QEMU\\x20\\x20\\x20\\x20"));
38 DEFINE_TEST_MAIN(LOG_DEBUG
);