diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-10 09:31:28 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-04-10 09:39:14 +0900 |
commit | de68bf789607e83d0a3c31b34b5e7a9efe319131 (patch) | |
tree | ea5e5e0d4236c7bf2ef8286b50d85b284d7d0120 /src/test | |
parent | 3a7ba9f6b9d9a80c7f909bfbf24b5fc8c99a3176 (diff) | |
download | systemd-de68bf789607e83d0a3c31b34b5e7a9efe319131.tar.gz |
test: add tests about iterator position for path_find_{first,last}_component()
When path_find_first_component() returns the last component, the iterator
must be an empty string. The fact is heavily used in chaseat(). Let's
explicitly test it.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-path-util.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 87e33919e0..e40ffea4d5 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -676,9 +676,10 @@ static void test_path_find_first_component_one( r = path_find_first_component(&p, accept_dot_dot, &e); if (r <= 0) { if (r == 0) { - if (path) + if (path) { assert_se(p == path + strlen_ptr(path)); - else + assert_se(isempty(p)); + } else assert_se(!p); assert_se(!e); } @@ -691,6 +692,15 @@ static void test_path_find_first_component_one( assert_se(strcspn(e, "/") == (size_t) r); assert_se(strlen_ptr(*expected) == (size_t) r); assert_se(strneq(e, *expected++, r)); + + assert_se(p); + log_debug("p=%s", p); + if (!isempty(*expected)) + assert_se(startswith(p, *expected)); + else if (ret >= 0) { + assert_se(p == path + strlen_ptr(path)); + assert_se(isempty(p)); + } } } @@ -712,7 +722,7 @@ TEST(path_find_first_component) { test_path_find_first_component_one("././//.///aa/bbb//./ccc", false, STRV_MAKE("aa", "bbb", "ccc"), 0); test_path_find_first_component_one("././//.///aa/.../../bbb//./ccc/.", false, STRV_MAKE("aa", "..."), -EINVAL); test_path_find_first_component_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.", false, STRV_MAKE("aaa", ".bbb"), -EINVAL); - test_path_find_first_component_one("a/foo./b", false, STRV_MAKE("a", "foo.", "b"), 0); + test_path_find_first_component_one("a/foo./b//././/", false, STRV_MAKE("a", "foo.", "b"), 0); test_path_find_first_component_one(NULL, true, NULL, 0); test_path_find_first_component_one("", true, NULL, 0); @@ -728,7 +738,7 @@ TEST(path_find_first_component) { test_path_find_first_component_one("././//.///aa/bbb//./ccc", true, STRV_MAKE("aa", "bbb", "ccc"), 0); test_path_find_first_component_one("././//.///aa/.../../bbb//./ccc/.", true, STRV_MAKE("aa", "...", "..", "bbb", "ccc"), 0); test_path_find_first_component_one("//./aaa///.//./.bbb/..///c.//d.dd///..eeee/.", true, STRV_MAKE("aaa", ".bbb", "..", "c.", "d.dd", "..eeee"), 0); - test_path_find_first_component_one("a/foo./b", true, STRV_MAKE("a", "foo.", "b"), 0); + test_path_find_first_component_one("a/foo./b//././/", true, STRV_MAKE("a", "foo.", "b"), 0); memset(foo, 'a', sizeof(foo) -1); char_array_0(foo); @@ -770,6 +780,15 @@ static void test_path_find_last_component_one( assert_se(strcspn(e, "/") == (size_t) r); assert_se(strlen_ptr(*expected) == (size_t) r); assert_se(strneq(e, *expected++, r)); + + assert_se(next); + log_debug("path=%s\nnext=%s", path, next); + if (!isempty(*expected)) { + assert_se(next < path + strlen(path)); + assert_se(next >= path + strlen(*expected)); + assert_se(startswith(next - strlen(*expected), *expected)); + } else if (ret >= 0) + assert_se(next == path); } } |