]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-sd-path.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 #include "alloc-util.h"
6 #include "string-util.h"
10 TEST(sd_path_lookup
) {
11 for (uint64_t i
= 0; i
< _SD_PATH_MAX
; i
++) {
12 _cleanup_free_
char *t
= NULL
, *s
= NULL
;
15 r
= sd_path_lookup(i
, NULL
, &t
);
16 if (i
== SD_PATH_USER_RUNTIME
&& r
== -ENXIO
)
20 log_info("%02"PRIu64
": \"%s\"", i
, t
);
22 assert_se(sd_path_lookup(i
, "suffix", &s
) == 0);
24 log_info("%02"PRIu64
": \"%s\"", i
, s
);
25 assert_se(endswith(s
, "/suffix"));
29 assert_se(sd_path_lookup(_SD_PATH_MAX
, NULL
, &tt
) == -EOPNOTSUPP
);
32 TEST(sd_path_lookup_strv
) {
33 for (uint64_t i
= 0; i
< _SD_PATH_MAX
; i
++) {
34 _cleanup_strv_free_
char **t
= NULL
, **s
= NULL
;
37 r
= sd_path_lookup_strv(i
, NULL
, &t
);
38 if (i
== SD_PATH_USER_RUNTIME
&& r
== -ENXIO
)
42 log_info("%02"PRIu64
":", i
);
44 log_debug(" %s", *item
);
46 assert_se(sd_path_lookup_strv(i
, "suffix", &s
) == 0);
48 log_info("%02"PRIu64
":", i
);
49 STRV_FOREACH(item
, s
) {
50 assert_se(endswith(*item
, "/suffix"));
51 log_debug(" %s", *item
);
56 assert_se(sd_path_lookup(_SD_PATH_MAX
, NULL
, &tt
) == -EOPNOTSUPP
);
59 DEFINE_TEST_MAIN(LOG_DEBUG
);