diff options
author | Stef Walter <stef@thewalter.net> | 2013-06-14 12:53:15 +0200 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2013-06-14 12:59:29 +0200 |
commit | 045df29606ea9853b4fc8bdba062a5e4a7a5be95 (patch) | |
tree | ef19ba4bb04471cf3c42d6bd3d1f4c11a1d4d754 /common/tests | |
parent | 8c6dd48789bdaf2a3dc800df7ed3416ddc3b7e1f (diff) |
path: Add p11_path_parent() function
Gets the parent element of the path, removing the last component.
Handles trailing and duplicate path separators correctly.
Diffstat (limited to 'common/tests')
-rw-r--r-- | common/tests/test-path.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/common/tests/test-path.c b/common/tests/test-path.c index f1bccbd..ec2c200 100644 --- a/common/tests/test-path.c +++ b/common/tests/test-path.c @@ -173,6 +173,22 @@ test_absolute (void) #endif } +static void +test_parent (void) +{ + check_equals_and_free ("/", p11_path_parent ("/root")); + check_equals_and_free ("/", p11_path_parent ("/root/")); + check_equals_and_free ("/", p11_path_parent ("/root//")); + check_equals_and_free ("/root", p11_path_parent ("/root/second")); + check_equals_and_free ("/root", p11_path_parent ("/root//second")); + check_equals_and_free ("/root", p11_path_parent ("/root//second//")); + check_equals_and_free ("/root", p11_path_parent ("/root///second")); + check_equals_and_free ("/root/second", p11_path_parent ("/root/second/test.file")); + assert_ptr_eq (NULL, p11_path_parent ("/")); + assert_ptr_eq (NULL, p11_path_parent ("//")); + assert_ptr_eq (NULL, p11_path_parent ("")); +} + int main (int argc, char *argv[]) @@ -181,6 +197,7 @@ main (int argc, p11_test (test_build, "/path/build"); p11_test (test_expand, "/path/expand"); p11_test (test_absolute, "/path/absolute"); + p11_test (test_parent, "/path/parent"); return p11_test_run (argc, argv); } |