]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-unit-name.c
tree-wide: remove Emacs lines from all files
[thirdparty/systemd.git] / src / test / test-unit-name.c
CommitLineData
b0193f1c
LP
1/***
2 This file is part of systemd.
3
4 Copyright 2012 Lennart Poettering
1682ff60 5 Copyright 2013 Zbigniew Jędrzejewski-Szmek
068ae9fb 6 Copyright 2014 Ronny Chevalier
b0193f1c
LP
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
07630cea 22#include <pwd.h>
b0193f1c
LP
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26
b5efdb8a 27#include "alloc-util.h"
2aaafcf5 28#include "glob-util.h"
07630cea
LP
29#include "hostname-util.h"
30#include "macro.h"
1682ff60 31#include "manager.h"
07630cea
LP
32#include "path-util.h"
33#include "specifier.h"
34#include "string-util.h"
35#include "test-helper.h"
b0193f1c 36#include "unit-name.h"
1682ff60 37#include "unit-printf.h"
07630cea 38#include "unit.h"
79413b67 39#include "user-util.h"
b0193f1c
LP
40#include "util.h"
41
7410616c
LP
42static void test_unit_name_is_valid(void) {
43 assert_se(unit_name_is_valid("foo.service", UNIT_NAME_ANY));
44 assert_se(unit_name_is_valid("foo.service", UNIT_NAME_PLAIN));
45 assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_INSTANCE));
46 assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_TEMPLATE));
47 assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
48
49 assert_se(unit_name_is_valid("foo@bar.service", UNIT_NAME_ANY));
50 assert_se(!unit_name_is_valid("foo@bar.service", UNIT_NAME_PLAIN));
51 assert_se(unit_name_is_valid("foo@bar.service", UNIT_NAME_INSTANCE));
52 assert_se(!unit_name_is_valid("foo@bar.service", UNIT_NAME_TEMPLATE));
53 assert_se(unit_name_is_valid("foo@bar.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
54
55 assert_se(unit_name_is_valid("foo@.service", UNIT_NAME_ANY));
56 assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_PLAIN));
57 assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE));
58 assert_se(unit_name_is_valid("foo@.service", UNIT_NAME_TEMPLATE));
59 assert_se(unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
60
61 assert_se(!unit_name_is_valid(".service", UNIT_NAME_ANY));
62 assert_se(!unit_name_is_valid("", UNIT_NAME_ANY));
63 assert_se(!unit_name_is_valid("foo.waldo", UNIT_NAME_ANY));
64 assert_se(!unit_name_is_valid("@.service", UNIT_NAME_ANY));
65 assert_se(!unit_name_is_valid("@piep.service", UNIT_NAME_ANY));
66}
3251c0d2 67
21868586 68static void test_unit_name_replace_instance_one(const char *pattern, const char *repl, const char *expected, int ret) {
7410616c
LP
69 _cleanup_free_ char *t = NULL;
70 assert_se(unit_name_replace_instance(pattern, repl, &t) == ret);
71 puts(strna(t));
72 assert_se(streq_ptr(t, expected));
73}
3251c0d2 74
21868586 75static void test_unit_name_replace_instance(void) {
3251c0d2 76 puts("-------------------------------------------------");
21868586
LP
77 test_unit_name_replace_instance_one("foo@.service", "waldo", "foo@waldo.service", 0);
78 test_unit_name_replace_instance_one("foo@xyz.service", "waldo", "foo@waldo.service", 0);
79 test_unit_name_replace_instance_one("xyz", "waldo", NULL, -EINVAL);
80 test_unit_name_replace_instance_one("", "waldo", NULL, -EINVAL);
81 test_unit_name_replace_instance_one("foo.service", "waldo", NULL, -EINVAL);
82 test_unit_name_replace_instance_one(".service", "waldo", NULL, -EINVAL);
83 test_unit_name_replace_instance_one("foo@", "waldo", NULL, -EINVAL);
84 test_unit_name_replace_instance_one("@bar", "waldo", NULL, -EINVAL);
7410616c 85}
3251c0d2 86
21868586 87static void test_unit_name_from_path_one(const char *path, const char *suffix, const char *expected, int ret) {
7410616c 88 _cleanup_free_ char *t = NULL;
3251c0d2 89
7410616c
LP
90 assert_se(unit_name_from_path(path, suffix, &t) == ret);
91 puts(strna(t));
92 assert_se(streq_ptr(t, expected));
3251c0d2 93
7410616c
LP
94 if (t) {
95 _cleanup_free_ char *k = NULL;
96 assert_se(unit_name_to_path(t, &k) == 0);
97 puts(strna(k));
98 assert_se(path_equal(k, isempty(path) ? "/" : path));
99 }
100}
3251c0d2 101
21868586 102static void test_unit_name_from_path(void) {
3251c0d2 103 puts("-------------------------------------------------");
21868586
LP
104 test_unit_name_from_path_one("/waldo", ".mount", "waldo.mount", 0);
105 test_unit_name_from_path_one("/waldo/quuix", ".mount", "waldo-quuix.mount", 0);
106 test_unit_name_from_path_one("/waldo/quuix/", ".mount", "waldo-quuix.mount", 0);
107 test_unit_name_from_path_one("", ".mount", "-.mount", 0);
108 test_unit_name_from_path_one("/", ".mount", "-.mount", 0);
109 test_unit_name_from_path_one("///", ".mount", "-.mount", 0);
110 test_unit_name_from_path_one("/foo/../bar", ".mount", NULL, -EINVAL);
111 test_unit_name_from_path_one("/foo/./bar", ".mount", NULL, -EINVAL);
7410616c
LP
112}
113
21868586 114static void test_unit_name_from_path_instance_one(const char *pattern, const char *path, const char *suffix, const char *expected, int ret) {
7410616c
LP
115 _cleanup_free_ char *t = NULL;
116
117 assert_se(unit_name_from_path_instance(pattern, path, suffix, &t) == ret);
118 puts(strna(t));
119 assert_se(streq_ptr(t, expected));
120
121 if (t) {
122 _cleanup_free_ char *k = NULL, *v = NULL;
123
124 assert_se(unit_name_to_instance(t, &k) > 0);
125 assert_se(unit_name_path_unescape(k, &v) == 0);
126 assert_se(path_equal(v, isempty(path) ? "/" : path));
3251c0d2 127 }
7410616c 128}
3251c0d2 129
21868586 130static void test_unit_name_from_path_instance(void) {
7410616c 131 puts("-------------------------------------------------");
b0193f1c 132
21868586
LP
133 test_unit_name_from_path_instance_one("waldo", "/waldo", ".mount", "waldo@waldo.mount", 0);
134 test_unit_name_from_path_instance_one("waldo", "/waldo////quuix////", ".mount", "waldo@waldo-quuix.mount", 0);
135 test_unit_name_from_path_instance_one("waldo", "/", ".mount", "waldo@-.mount", 0);
136 test_unit_name_from_path_instance_one("waldo", "", ".mount", "waldo@-.mount", 0);
137 test_unit_name_from_path_instance_one("waldo", "///", ".mount", "waldo@-.mount", 0);
138 test_unit_name_from_path_instance_one("waldo", "..", ".mount", NULL, -EINVAL);
139 test_unit_name_from_path_instance_one("waldo", "/foo", ".waldi", NULL, -EINVAL);
140 test_unit_name_from_path_instance_one("wa--ldo", "/--", ".mount", "wa--ldo@\\x2d\\x2d.mount", 0);
7410616c
LP
141}
142
21868586 143static void test_unit_name_to_path_one(const char *unit, const char *path, int ret) {
7410616c
LP
144 _cleanup_free_ char *p = NULL;
145
146 assert_se(unit_name_to_path(unit, &p) == ret);
147 assert_se(streq_ptr(path, p));
148}
149
21868586
LP
150static void test_unit_name_to_path(void) {
151 test_unit_name_to_path_one("home.mount", "/home", 0);
152 test_unit_name_to_path_one("home-lennart.mount", "/home/lennart", 0);
153 test_unit_name_to_path_one("home-lennart-.mount", NULL, -EINVAL);
154 test_unit_name_to_path_one("-home-lennart.mount", NULL, -EINVAL);
155 test_unit_name_to_path_one("-home--lennart.mount", NULL, -EINVAL);
156 test_unit_name_to_path_one("home-..-lennart.mount", NULL, -EINVAL);
157 test_unit_name_to_path_one("", NULL, -EINVAL);
158 test_unit_name_to_path_one("home/foo", NULL, -EINVAL);
7410616c
LP
159}
160
2aaafcf5 161static void test_unit_name_mangle_one(UnitNameMangle allow_globs, const char *pattern, const char *expect, int ret) {
7410616c
LP
162 _cleanup_free_ char *t = NULL;
163
2aaafcf5 164 assert_se(unit_name_mangle(pattern, allow_globs, &t) == ret);
7410616c
LP
165 puts(strna(t));
166 assert_se(streq_ptr(t, expect));
167
168 if (t) {
169 _cleanup_free_ char *k = NULL;
170
2aaafcf5
LP
171 assert_se(unit_name_is_valid(t, UNIT_NAME_ANY) ||
172 (allow_globs == UNIT_NAME_GLOB && string_is_glob(t)));
7410616c 173
2aaafcf5 174 assert_se(unit_name_mangle(t, allow_globs, &k) == 0);
7410616c
LP
175 assert_se(streq_ptr(t, k));
176 }
177}
178
21868586 179static void test_unit_name_mangle(void) {
7410616c 180 puts("-------------------------------------------------");
2aaafcf5
LP
181 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "foo.service", "foo.service", 0);
182 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "/home", "home.mount", 1);
183 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "/dev/sda", "dev-sda.device", 1);
184 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "üxknürz.service", "\\xc3\\xbcxkn\\xc3\\xbcrz.service", 1);
185 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "foobar-meh...waldi.service", "foobar-meh...waldi.service", 0);
186 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "_____####----.....service", "_____\\x23\\x23\\x23\\x23----.....service", 1);
187 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "_____##@;;;,,,##----.....service", "_____\\x23\\x23@\\x3b\\x3b\\x3b\\x2c\\x2c\\x2c\\x23\\x23----.....service", 1);
188 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "xxx@@@@/////\\\\\\\\\\yyy.service", "xxx@@@@-----\\\\\\\\\\yyy.service", 1);
189 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "", NULL, -EINVAL);
190
191 test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo.service", "foo.service", 0);
192 test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo", "foo.service", 1);
193 test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo*", "foo*", 0);
194 test_unit_name_mangle_one(UNIT_NAME_GLOB, "ü*", "\\xc3\\xbc*", 1);
1682ff60
ZJS
195}
196
49e5de64 197static int test_unit_printf(void) {
39883f62 198 Manager *m = NULL;
1682ff60 199 Unit *u, *u2;
c5e33bf8 200 int r;
1682ff60 201
79413b67 202 _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *uid = NULL, *user = NULL, *shell = NULL, *home = NULL;
1682ff60 203
19f6d710
LP
204 assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid);
205 assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid);
79413b67
LP
206 assert_se(host = gethostname_malloc());
207 assert_se(user = getusername_malloc());
208 assert_se(asprintf(&uid, UID_FMT, getuid()));
209 assert_se(get_home_dir(&home) >= 0);
210 assert_se(get_shell(&shell) >= 0);
1682ff60 211
b2c23da8 212 r = manager_new(MANAGER_USER, true, &m);
a454d241 213 if (r == -EPERM || r == -EACCES || r == -EADDRINUSE) {
c5e33bf8 214 puts("manager_new: Permission denied. Skipping test.");
49e5de64 215 return EXIT_TEST_SKIP;
c5e33bf8 216 }
bdf7026e 217 assert_se(r == 0);
1682ff60
ZJS
218
219#define expect(unit, pattern, expected) \
220 { \
fa3cd739 221 char *e; \
e1ba963f 222 _cleanup_free_ char *t = NULL; \
19f6d710 223 assert_se(unit_full_printf(unit, pattern, &t) >= 0); \
c5e33bf8 224 printf("result: %s\nexpect: %s\n", t, expected); \
fa3cd739 225 if ((e = endswith(expected, "*"))) \
bdf7026e 226 assert_se(strncmp(t, e, e-expected)); \
fa3cd739 227 else \
bdf7026e 228 assert_se(streq(t, expected)); \
1682ff60
ZJS
229 }
230
6dbfd104 231 assert_se(setenv("XDG_RUNTIME_DIR", "/run/user/1/", 1) == 0);
1682ff60
ZJS
232
233 assert_se(u = unit_new(m, sizeof(Service)));
234 assert_se(unit_add_name(u, "blah.service") == 0);
235 assert_se(unit_add_name(u, "blah.service") == 0);
236
237 /* general tests */
238 expect(u, "%%", "%");
239 expect(u, "%%s", "%s");
240 expect(u, "%", ""); // REALLY?
241
242 /* normal unit */
243 expect(u, "%n", "blah.service");
14b0295f 244 expect(u, "%f", "/blah");
1682ff60
ZJS
245 expect(u, "%N", "blah");
246 expect(u, "%p", "blah");
247 expect(u, "%P", "blah");
248 expect(u, "%i", "");
79413b67
LP
249 expect(u, "%u", user);
250 expect(u, "%U", uid);
251 expect(u, "%h", home);
1682ff60
ZJS
252 expect(u, "%m", mid);
253 expect(u, "%b", bid);
254 expect(u, "%H", host);
fa3cd739 255 expect(u, "%t", "/run/user/*");
1682ff60
ZJS
256
257 /* templated */
258 assert_se(u2 = unit_new(m, sizeof(Service)));
259 assert_se(unit_add_name(u2, "blah@foo-foo.service") == 0);
260 assert_se(unit_add_name(u2, "blah@foo-foo.service") == 0);
261
262 expect(u2, "%n", "blah@foo-foo.service");
263 expect(u2, "%N", "blah@foo-foo");
14b0295f 264 expect(u2, "%f", "/foo/foo");
1682ff60
ZJS
265 expect(u2, "%p", "blah");
266 expect(u2, "%P", "blah");
267 expect(u2, "%i", "foo-foo");
268 expect(u2, "%I", "foo/foo");
79413b67
LP
269 expect(u2, "%u", user);
270 expect(u2, "%U", uid);
271 expect(u2, "%h", home);
1682ff60
ZJS
272 expect(u2, "%m", mid);
273 expect(u2, "%b", bid);
274 expect(u2, "%H", host);
fa3cd739 275 expect(u2, "%t", "/run/user/*");
49e5de64 276
b463b813 277 manager_free(m);
fee0a921 278#undef expect
b463b813 279
49e5de64 280 return 0;
1682ff60
ZJS
281}
282
068ae9fb
RC
283static void test_unit_instance_is_valid(void) {
284 assert_se(unit_instance_is_valid("fooBar"));
285 assert_se(unit_instance_is_valid("foo-bar"));
286 assert_se(unit_instance_is_valid("foo.stUff"));
287 assert_se(unit_instance_is_valid("fOo123.stuff"));
288 assert_se(unit_instance_is_valid("@f_oo123.Stuff"));
289
290 assert_se(!unit_instance_is_valid("$¢£"));
291 assert_se(!unit_instance_is_valid(""));
292 assert_se(!unit_instance_is_valid("foo bar"));
293 assert_se(!unit_instance_is_valid("foo/bar"));
294}
295
296static void test_unit_prefix_is_valid(void) {
297 assert_se(unit_prefix_is_valid("fooBar"));
298 assert_se(unit_prefix_is_valid("foo-bar"));
299 assert_se(unit_prefix_is_valid("foo.stUff"));
300 assert_se(unit_prefix_is_valid("fOo123.stuff"));
301 assert_se(unit_prefix_is_valid("foo123.Stuff"));
302
303 assert_se(!unit_prefix_is_valid("$¢£"));
304 assert_se(!unit_prefix_is_valid(""));
305 assert_se(!unit_prefix_is_valid("foo bar"));
306 assert_se(!unit_prefix_is_valid("foo/bar"));
307 assert_se(!unit_prefix_is_valid("@foo-bar"));
308}
309
310static void test_unit_name_change_suffix(void) {
7410616c 311 char *t;
068ae9fb 312
7410616c
LP
313 assert_se(unit_name_change_suffix("foo.mount", ".service", &t) == 0);
314 assert_se(streq(t, "foo.service"));
315 free(t);
068ae9fb 316
7410616c
LP
317 assert_se(unit_name_change_suffix("foo@stuff.service", ".socket", &t) == 0);
318 assert_se(streq(t, "foo@stuff.socket"));
319 free(t);
068ae9fb
RC
320}
321
322static void test_unit_name_build(void) {
7410616c 323 char *t;
068ae9fb 324
7410616c
LP
325 assert_se(unit_name_build("foo", "bar", ".service", &t) == 0);
326 assert_se(streq(t, "foo@bar.service"));
327 free(t);
068ae9fb 328
7410616c
LP
329 assert_se(unit_name_build("fo0-stUff_b", "bar", ".mount", &t) == 0);
330 assert_se(streq(t, "fo0-stUff_b@bar.mount"));
331 free(t);
068ae9fb 332
7410616c
LP
333 assert_se(unit_name_build("foo", NULL, ".service", &t) == 0);
334 assert_se(streq(t, "foo.service"));
335 free(t);
068ae9fb
RC
336}
337
93c47472
LP
338static void test_slice_name_is_valid(void) {
339 assert_se(slice_name_is_valid("-.slice"));
340 assert_se(slice_name_is_valid("foo.slice"));
341 assert_se(slice_name_is_valid("foo-bar.slice"));
342 assert_se(slice_name_is_valid("foo-bar-baz.slice"));
343 assert_se(!slice_name_is_valid("-foo-bar-baz.slice"));
344 assert_se(!slice_name_is_valid("foo-bar-baz-.slice"));
345 assert_se(!slice_name_is_valid("-foo-bar-baz-.slice"));
346 assert_se(!slice_name_is_valid("foo-bar--baz.slice"));
347 assert_se(!slice_name_is_valid("foo--bar--baz.slice"));
348 assert_se(!slice_name_is_valid(".slice"));
349 assert_se(!slice_name_is_valid(""));
350 assert_se(!slice_name_is_valid("foo.service"));
351}
352
068ae9fb
RC
353static void test_build_subslice(void) {
354 char *a;
355 char *b;
356
7410616c
LP
357 assert_se(slice_build_subslice("-.slice", "foo", &a) >= 0);
358 assert_se(slice_build_subslice(a, "bar", &b) >= 0);
068ae9fb 359 free(a);
7410616c 360 assert_se(slice_build_subslice(b, "barfoo", &a) >= 0);
068ae9fb 361 free(b);
7410616c 362 assert_se(slice_build_subslice(a, "foobar", &b) >= 0);
068ae9fb
RC
363 free(a);
364 assert_se(streq(b, "foo-bar-barfoo-foobar.slice"));
365 free(b);
366
7410616c
LP
367 assert_se(slice_build_subslice("foo.service", "bar", &a) < 0);
368 assert_se(slice_build_subslice("foo", "bar", &a) < 0);
068ae9fb
RC
369}
370
93c47472
LP
371static void test_build_parent_slice_one(const char *name, const char *expect, int ret) {
372 _cleanup_free_ char *s = NULL;
373
374 assert_se(slice_build_parent_slice(name, &s) == ret);
375 assert_se(streq_ptr(s, expect));
376}
377
378static void test_build_parent_slice(void) {
379 test_build_parent_slice_one("-.slice", NULL, 0);
380 test_build_parent_slice_one("foo.slice", "-.slice", 1);
381 test_build_parent_slice_one("foo-bar.slice", "foo.slice", 1);
382 test_build_parent_slice_one("foo-bar-baz.slice", "foo-bar.slice", 1);
383 test_build_parent_slice_one("foo-bar--baz.slice", NULL, -EINVAL);
384 test_build_parent_slice_one("-foo-bar.slice", NULL, -EINVAL);
385 test_build_parent_slice_one("foo-bar-.slice", NULL, -EINVAL);
386 test_build_parent_slice_one("foo-bar.service", NULL, -EINVAL);
387 test_build_parent_slice_one(".slice", NULL, -EINVAL);
388}
389
068ae9fb
RC
390static void test_unit_name_to_instance(void) {
391 char *instance;
392 int r;
393
394 r = unit_name_to_instance("foo@bar.service", &instance);
395 assert_se(r >= 0);
396 assert_se(streq(instance, "bar"));
397 free(instance);
398
fee0a921
RC
399 r = unit_name_to_instance("foo@.service", &instance);
400 assert_se(r >= 0);
401 assert_se(streq(instance, ""));
402 free(instance);
403
7410616c 404 r = unit_name_to_instance("fo0-stUff_b@b.service", &instance);
068ae9fb
RC
405 assert_se(r >= 0);
406 assert_se(streq(instance, "b"));
407 free(instance);
408
7410616c
LP
409 r = unit_name_to_instance("foo.service", &instance);
410 assert_se(r == 0);
068ae9fb
RC
411 assert_se(!instance);
412
413 r = unit_name_to_instance("fooj@unk", &instance);
414 assert_se(r < 0);
fee0a921
RC
415
416 r = unit_name_to_instance("foo@", &instance);
417 assert_se(r < 0);
068ae9fb
RC
418}
419
420static void test_unit_name_escape(void) {
421 _cleanup_free_ char *r;
422
423 r = unit_name_escape("ab+-c.a/bc@foo.service");
424 assert_se(r);
425 assert_se(streq(r, "ab\\x2b\\x2dc.a-bc\\x40foo.service"));
426}
427
fee0a921 428
7410616c
LP
429static void test_u_n_t_one(const char *name, const char *expected, int ret) {
430 _cleanup_free_ char *f = NULL;
fee0a921 431
7410616c
LP
432 assert_se(unit_name_template(name, &f) == ret);
433 printf("got: %s, expected: %s\n", strna(f), strna(expected));
434 assert_se(streq_ptr(f, expected));
435}
436
437static void test_unit_name_template(void) {
438 test_u_n_t_one("foo@bar.service", "foo@.service", 0);
439 test_u_n_t_one("foo.mount", NULL, -EINVAL);
fee0a921
RC
440}
441
93c47472
LP
442static void test_unit_name_path_unescape_one(const char *name, const char *path, int ret) {
443 _cleanup_free_ char *p = NULL;
444
445 assert_se(unit_name_path_unescape(name, &p) == ret);
446 assert_se(streq_ptr(path, p));
447}
448
449static void test_unit_name_path_unescape(void) {
450
451 test_unit_name_path_unescape_one("foo", "/foo", 0);
452 test_unit_name_path_unescape_one("foo-bar", "/foo/bar", 0);
453 test_unit_name_path_unescape_one("foo-.bar", "/foo/.bar", 0);
454 test_unit_name_path_unescape_one("foo-bar-baz", "/foo/bar/baz", 0);
455 test_unit_name_path_unescape_one("-", "/", 0);
456 test_unit_name_path_unescape_one("--", NULL, -EINVAL);
457 test_unit_name_path_unescape_one("-foo-bar", NULL, -EINVAL);
458 test_unit_name_path_unescape_one("foo--bar", NULL, -EINVAL);
459 test_unit_name_path_unescape_one("foo-bar-", NULL, -EINVAL);
460 test_unit_name_path_unescape_one(".-bar", NULL, -EINVAL);
461 test_unit_name_path_unescape_one("foo-..", NULL, -EINVAL);
462 test_unit_name_path_unescape_one("", NULL, -EINVAL);
463}
464
1682ff60 465int main(int argc, char* argv[]) {
143bfdaf 466 int rc = 0;
7410616c 467 test_unit_name_is_valid();
21868586
LP
468 test_unit_name_replace_instance();
469 test_unit_name_from_path();
470 test_unit_name_from_path_instance();
471 test_unit_name_mangle();
472 test_unit_name_to_path();
143bfdaf 473 TEST_REQ_RUNNING_SYSTEMD(rc = test_unit_printf());
068ae9fb
RC
474 test_unit_instance_is_valid();
475 test_unit_prefix_is_valid();
476 test_unit_name_change_suffix();
477 test_unit_name_build();
93c47472 478 test_slice_name_is_valid();
068ae9fb 479 test_build_subslice();
93c47472 480 test_build_parent_slice();
068ae9fb
RC
481 test_unit_name_to_instance();
482 test_unit_name_escape();
fee0a921 483 test_unit_name_template();
93c47472 484 test_unit_name_path_unescape();
068ae9fb 485
143bfdaf 486 return rc;
b0193f1c 487}