1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2012 Lennart Poettering
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.
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.
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/>.
26 #include "unit-name.h"
29 int main(int argc, char* argv[]) {
32 t = unit_name_replace_instance("foo@.service", "waldo");
36 t = unit_name_replace_instance("foo@xyz.service", "waldo");
40 t = unit_name_replace_instance("xyz", "waldo");
44 t = unit_name_replace_instance("", "waldo");
48 t = unit_name_replace_instance("", "");
52 t = unit_name_replace_instance("foo.service", "waldo");
56 t = unit_name_from_path("/waldo", ".mount");
58 k = unit_name_to_path(t);
63 t = unit_name_from_path("/waldo/quuix", ".mount");
65 k = unit_name_to_path(t);
70 t = unit_name_from_path("/waldo/quuix/", ".mount");
72 k = unit_name_to_path(t);
77 t = unit_name_from_path("/", ".mount");
79 k = unit_name_to_path(t);
84 t = unit_name_from_path("///", ".mount");
86 k = unit_name_to_path(t);
91 t = unit_name_from_path_instance("waldo", "/waldo", ".mount");
95 t = unit_name_from_path_instance("waldo", "/waldo////quuix////", ".mount");
99 t = unit_name_from_path_instance("waldo", "/", ".mount");
103 t = unit_name_from_path_instance("wa--ldo", "/--", ".mount");
107 assert_se(t = unit_name_mangle("/home"));
108 assert_se(k = unit_name_mangle(t));
110 assert_se(streq(t, k));
114 assert_se(t = unit_name_mangle("/dev/sda"));
115 assert_se(k = unit_name_mangle(t));
117 assert_se(streq(t, k));
121 assert_se(t = unit_name_mangle("üxknürz.service"));
122 assert_se(k = unit_name_mangle(t));
124 assert_se(streq(t, k));
128 assert_se(t = unit_name_mangle("foobar-meh...waldi.service"));
129 assert_se(k = unit_name_mangle(t));
131 assert_se(streq(t, k));
135 assert_se(t = unit_name_mangle("_____####----.....service"));
136 assert_se(k = unit_name_mangle(t));
138 assert_se(streq(t, k));
142 assert_se(t = unit_name_mangle("_____##@;;;,,,##----.....service"));
143 assert_se(k = unit_name_mangle(t));
145 assert_se(streq(t, k));
149 assert_se(t = unit_name_mangle("xxx@@@@/////\\\\\\\\\\yyy.service"));
150 assert_se(k = unit_name_mangle(t));
152 assert_se(streq(t, k));