| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-path.h" |
| 4 |
|
| 5 |
#include "alloc-util.h" |
| 6 |
#include "string-util.h" |
| 7 |
#include "strv.h" |
| 8 |
#include "tests.h" |
| 9 |
|
| 10 |
TEST(sd_path_lookup) { |
| 11 |
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) { |
| 12 |
_cleanup_free_ char *t = NULL, *s = NULL; |
| 13 |
int r; |
| 14 |
|
| 15 |
r = sd_path_lookup(i, NULL, &t); |
| 16 |
if (i == SD_PATH_USER_RUNTIME && r == -ENXIO) |
| 17 |
continue; |
| 18 |
assert_se(r == 0); |
| 19 |
assert_se(t); |
| 20 |
log_info("%02"PRIu64": \"%s\"", i, t); |
| 21 |
|
| 22 |
assert_se(sd_path_lookup(i, "suffix", &s) == 0); |
| 23 |
assert_se(s); |
| 24 |
log_info("%02"PRIu64": \"%s\"", i, s); |
| 25 |
assert_se(endswith(s, "/suffix")); |
| 26 |
} |
| 27 |
|
| 28 |
char *tt; |
| 29 |
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP); |
| 30 |
} |
| 31 |
|
| 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; |
| 35 |
int r; |
| 36 |
|
| 37 |
r = sd_path_lookup_strv(i, NULL, &t); |
| 38 |
if (i == SD_PATH_USER_RUNTIME && r == -ENXIO) |
| 39 |
continue; |
| 40 |
assert_se(r == 0); |
| 41 |
assert_se(t); |
| 42 |
log_info("%02"PRIu64":", i); |
| 43 |
STRV_FOREACH(item, t) |
| 44 |
log_debug(" %s", *item); |
| 45 |
|
| 46 |
assert_se(sd_path_lookup_strv(i, "suffix", &s) == 0); |
| 47 |
assert_se(s); |
| 48 |
log_info("%02"PRIu64":", i); |
| 49 |
STRV_FOREACH(item, s) { |
| 50 |
assert_se(endswith(*item, "/suffix")); |
| 51 |
log_debug(" %s", *item); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
char *tt; |
| 56 |
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP); |
| 57 |
} |
| 58 |
|
| 59 |
DEFINE_TEST_MAIN(LOG_DEBUG); |