2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2020-03-23 19:12:55 +01:00
|
|
|
|
|
|
|
#include "sd-path.h"
|
|
|
|
|
|
|
|
#include "alloc-util.h"
|
|
|
|
#include "string-util.h"
|
|
|
|
#include "strv.h"
|
|
|
|
#include "tests.h"
|
|
|
|
|
2020-03-23 19:50:59 +01:00
|
|
|
static void test_sd_path_lookup(void) {
|
2020-03-23 19:12:55 +01:00
|
|
|
log_info("/* %s */", __func__);
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
|
2020-03-26 17:40:33 +01:00
|
|
|
_cleanup_free_ char *t = NULL, *s = NULL;
|
|
|
|
int r;
|
2020-03-23 19:12:55 +01:00
|
|
|
|
2020-03-26 17:40:33 +01:00
|
|
|
r = sd_path_lookup(i, NULL, &t);
|
|
|
|
if (i == SD_PATH_USER_RUNTIME && r == -ENXIO)
|
|
|
|
continue;
|
|
|
|
assert_se(r == 0);
|
2020-03-23 19:12:55 +01:00
|
|
|
assert_se(t);
|
|
|
|
log_info("%02"PRIu64": \"%s\"", i, t);
|
|
|
|
|
2020-03-23 19:50:59 +01:00
|
|
|
assert_se(sd_path_lookup(i, "suffix", &s) == 0);
|
2020-03-23 19:12:55 +01:00
|
|
|
assert_se(s);
|
|
|
|
log_info("%02"PRIu64": \"%s\"", i, s);
|
|
|
|
assert_se(endswith(s, "/suffix"));
|
|
|
|
}
|
|
|
|
|
|
|
|
char *tt;
|
2020-03-23 19:50:59 +01:00
|
|
|
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
|
2020-03-23 19:12:55 +01:00
|
|
|
}
|
|
|
|
|
2020-03-23 19:50:59 +01:00
|
|
|
static void test_sd_path_lookup_strv(void) {
|
2020-03-23 19:12:55 +01:00
|
|
|
log_info("/* %s */", __func__);
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < _SD_PATH_MAX; i++) {
|
2020-03-26 17:40:33 +01:00
|
|
|
_cleanup_strv_free_ char **t = NULL, **s = NULL;
|
2020-03-23 19:12:55 +01:00
|
|
|
char **item;
|
2020-03-26 17:40:33 +01:00
|
|
|
int r;
|
2020-03-23 19:12:55 +01:00
|
|
|
|
2020-03-26 17:40:33 +01:00
|
|
|
r = sd_path_lookup_strv(i, NULL, &t);
|
|
|
|
if (i == SD_PATH_USER_RUNTIME && r == -ENXIO)
|
|
|
|
continue;
|
|
|
|
assert_se(r == 0);
|
2020-03-23 19:12:55 +01:00
|
|
|
assert_se(t);
|
|
|
|
log_info("%02"PRIu64":", i);
|
|
|
|
STRV_FOREACH(item, t)
|
|
|
|
log_debug(" %s", *item);
|
|
|
|
|
2020-03-23 19:50:59 +01:00
|
|
|
assert_se(sd_path_lookup_strv(i, "suffix", &s) == 0);
|
2020-03-23 19:12:55 +01:00
|
|
|
assert_se(s);
|
|
|
|
log_info("%02"PRIu64":", i);
|
|
|
|
STRV_FOREACH(item, s) {
|
|
|
|
assert_se(endswith(*item, "/suffix"));
|
|
|
|
log_debug(" %s", *item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *tt;
|
2020-03-23 19:50:59 +01:00
|
|
|
assert_se(sd_path_lookup(_SD_PATH_MAX, NULL, &tt) == -EOPNOTSUPP);
|
2020-03-23 19:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
test_setup_logging(LOG_DEBUG);
|
|
|
|
|
2020-03-23 19:50:59 +01:00
|
|
|
test_sd_path_lookup();
|
|
|
|
test_sd_path_lookup_strv();
|
2020-03-23 19:12:55 +01:00
|
|
|
}
|