mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-08 05:57:26 +03:00
test: add a simple test for getenv_path_list()
(cherry picked from commit 192242c986e2462c4d2ec5b3ecd6f1ac02f9c0ad) (cherry picked from commit 9c8d8719e4d60c1220e06a10d1c8f779043bbf95)
This commit is contained in:
parent
e166b24da6
commit
e8ac7521b4
@ -462,4 +462,39 @@ TEST(strv_env_name_is_valid) {
|
||||
assert_se(!strv_env_name_is_valid((char **) repeated_env_names));
|
||||
}
|
||||
|
||||
TEST(getenv_path_list) {
|
||||
_cleanup_strv_free_ char **path_list = NULL;
|
||||
|
||||
/* Empty paths */
|
||||
FOREACH_STRING(s, "", ":", ":::::", " : ::: :: :") {
|
||||
assert_se(setenv("TEST_GETENV_PATH_LIST", s, 1) >= 0);
|
||||
assert_se(getenv_path_list("TEST_GETENV_PATH_LIST", &path_list) == -EINVAL);
|
||||
assert_se(!path_list);
|
||||
}
|
||||
|
||||
/* Invalid paths */
|
||||
FOREACH_STRING(s, ".", "..", "/../", "/", "/foo/bar/baz/../foo", "foo/bar/baz") {
|
||||
assert_se(setenv("TEST_GETENV_PATH_LIST", s, 1) >= 0);
|
||||
assert_se(getenv_path_list("TEST_GETENV_PATH_LIST", &path_list) == -EINVAL);
|
||||
assert_se(!path_list);
|
||||
}
|
||||
|
||||
/* Valid paths mixed with invalid ones */
|
||||
assert_se(setenv("TEST_GETENV_PATH_LIST", "/foo:/bar/baz:/../:/hello", 1) >= 0);
|
||||
assert_se(getenv_path_list("TEST_GETENV_PATH_LIST", &path_list) == -EINVAL);
|
||||
assert_se(!path_list);
|
||||
|
||||
/* Finally some valid paths */
|
||||
assert_se(setenv("TEST_GETENV_PATH_LIST", "/foo:/bar/baz:/hello/world:/path with spaces:/final", 1) >= 0);
|
||||
assert_se(getenv_path_list("TEST_GETENV_PATH_LIST", &path_list) >= 0);
|
||||
assert_se(streq(path_list[0], "/foo"));
|
||||
assert_se(streq(path_list[1], "/bar/baz"));
|
||||
assert_se(streq(path_list[2], "/hello/world"));
|
||||
assert_se(streq(path_list[3], "/path with spaces"));
|
||||
assert_se(streq(path_list[4], "/final"));
|
||||
assert_se(path_list[5] == NULL);
|
||||
|
||||
assert_se(unsetenv("TEST_GETENV_PATH_LIST") >= 0);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_DEBUG);
|
||||
|
Loading…
x
Reference in New Issue
Block a user