]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-device-nodes.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "alloc-util.h"
6 #include "device-nodes.h"
7 #include "string-util.h"
10 /* helpers for test_encode_devnode_name */
11 static char *do_encode_string(const char *in
) {
12 size_t out_len
= strlen(in
) * 4 + 1;
13 char *out
= malloc(out_len
);
16 assert_se(encode_devnode_name(in
, out
, out_len
) >= 0);
22 static bool expect_encoded_as(const char *in
, const char *expected
) {
23 _cleanup_free_
char *encoded
= do_encode_string(in
);
24 return streq(encoded
, expected
);
27 static void test_encode_devnode_name(void) {
28 assert_se(expect_encoded_as("systemd sucks", "systemd\\x20sucks"));
29 assert_se(expect_encoded_as("pinkiepie", "pinkiepie"));
30 assert_se(expect_encoded_as("valíd\\ųtf8", "valíd\\x5cųtf8"));
31 assert_se(expect_encoded_as("s/ash/ng", "s\\x2fash\\x2fng"));
32 assert_se(expect_encoded_as("/", "\\x2f"));
33 assert_se(expect_encoded_as("!", "\\x21"));
36 int main(int argc
, char *argv
[]) {
37 test_encode_devnode_name();