From 7eabbee227f09cc4ff9e472520f03bba1e35596b Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 28 Jun 2013 12:51:30 +0200 Subject: path: Add p11_path_prefix() function Checks if a wellformed path is identical to or a prefix of another path. --- common/tests/test-path.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'common/tests') diff --git a/common/tests/test-path.c b/common/tests/test-path.c index ec2c200..1671381 100644 --- a/common/tests/test-path.c +++ b/common/tests/test-path.c @@ -189,6 +189,18 @@ test_parent (void) assert_ptr_eq (NULL, p11_path_parent ("")); } +static void +test_prefix (void) +{ + assert (p11_path_prefix ("/test/second", "/test")); + assert (!p11_path_prefix ("/test", "/test")); + assert (!p11_path_prefix ("/different/prefix", "/test")); + assert (!p11_path_prefix ("/te", "/test")); + assert (!p11_path_prefix ("/test", "/test/blah")); + assert (p11_path_prefix ("/test/other/second", "/test")); + assert (p11_path_prefix ("/test//other//second", "/test")); +} + int main (int argc, char *argv[]) @@ -198,6 +210,7 @@ main (int argc, p11_test (test_expand, "/path/expand"); p11_test (test_absolute, "/path/absolute"); p11_test (test_parent, "/path/parent"); + p11_test (test_prefix, "/path/prefix"); return p11_test_run (argc, argv); } -- cgit v1.1