summaryrefslogtreecommitdiffstats
path: root/src/test/test-sysctl-util.c
blob: a6f449b76478ad88d147025742a02e11d67ea375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include "strv.h"
#include "sysctl-util.h"
#include "tests.h"

static const char* cases[] = {
        "a.b.c", "a/b/c",
        "a/b/c", "a/b/c",
        "a/b.c/d", "a/b.c/d",
        "a.b/c.d", "a/b.c/d",

        "net.ipv4.conf.enp3s0/200.forwarding", "net/ipv4/conf/enp3s0.200/forwarding",
        "net/ipv4/conf/enp3s0.200/forwarding", "net/ipv4/conf/enp3s0.200/forwarding",

        "a...b...c", "a/b/c",
        "a///b///c", "a/b/c",
        ".a...b...c", "a/b/c",
        "/a///b///c", "a/b/c",
        NULL,
};

static void test_sysctl_normalize(void) {
        log_info("/* %s */", __func__);

        const char **s, **expected;
        STRV_FOREACH_PAIR(s, expected, cases) {
                _cleanup_free_ char *t;

                assert_se(t = strdup(*s));
                assert_se(sysctl_normalize(t) == t);

                log_info("\"%s\"\"%s\", expected \"%s\"", *s, t, *expected);
                assert_se(streq(t, *expected));
        }
}

int main(int argc, char *argv[]) {
        test_setup_logging(LOG_INFO);

        test_sysctl_normalize();

        return 0;
}