From 045df29606ea9853b4fc8bdba062a5e4a7a5be95 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 14 Jun 2013 12:53:15 +0200 Subject: path: Add p11_path_parent() function Gets the parent element of the path, removing the last component. Handles trailing and duplicate path separators correctly. --- common/tests/test-path.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'common/tests') 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); } -- cgit v1.1