]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-device-nodes.c
test: Use TEST macro
[thirdparty/systemd.git] / src / test / test-device-nodes.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <stdio.h>
4 #include <sys/types.h>
5
6 #include "alloc-util.h"
7 #include "device-nodes.h"
8 #include "string-util.h"
9 #include "tests.h"
10
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);
15
16 assert_se(out);
17 assert_se(encode_devnode_name(in, out, out_len) >= 0);
18 puts(out);
19
20 return out;
21 }
22
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);
26 }
27
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"));
36 }
37
38 DEFINE_TEST_MAIN(LOG_DEBUG);