]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-device-nodes.c
Merge pull request #1821 from darkcircle/ko-catalog-translation
[thirdparty/systemd.git] / src / test / test-device-nodes.c
CommitLineData
8f6ce71f
DR
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Dave Reisner
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <sys/types.h>
23
b5efdb8a 24#include "alloc-util.h"
8f6ce71f 25#include "device-nodes.h"
07630cea 26#include "string-util.h"
8f6ce71f
DR
27#include "util.h"
28
29/* helpers for test_encode_devnode_name */
30static char *do_encode_string(const char *in) {
1d5989fd 31 size_t out_len = strlen(in) * 4 + 1;
8f6ce71f
DR
32 char *out = malloc(out_len);
33
34 assert_se(out);
35 assert_se(encode_devnode_name(in, out, out_len) >= 0);
36 puts(out);
37
38 return out;
39}
40
41static bool expect_encoded_as(const char *in, const char *expected) {
42 _cleanup_free_ char *encoded = do_encode_string(in);
43 return streq(encoded, expected);
44}
45
46static void test_encode_devnode_name(void) {
47 assert_se(expect_encoded_as("systemd sucks", "systemd\\x20sucks"));
48 assert_se(expect_encoded_as("pinkiepie", "pinkiepie"));
49 assert_se(expect_encoded_as("valíd\\ųtf8", "valíd\\x5cųtf8"));
50 assert_se(expect_encoded_as("s/ash/ng", "s\\x2fash\\x2fng"));
1d5989fd
DR
51 assert_se(expect_encoded_as("/", "\\x2f"));
52 assert_se(expect_encoded_as("!", "\\x21"));
8f6ce71f
DR
53}
54
55int main(int argc, char *argv[]) {
56 test_encode_devnode_name();
57
58 return 0;
59}