X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftest%2Ftest-path-util.c;h=6396fcb3980f3eb1348646309cbb7becb1edca53;hb=e0952d9d021234e79f3a70f33a9e5d201872a417;hp=58b456a29183da7116d40475cf9a0f00b80912b1;hpb=f08c4c08c7c2ce0fdfb4cf49642b00fbfb15185f;p=elogind.git diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 58b456a29..6396fcb39 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -27,23 +27,37 @@ #include "macro.h" #include "strv.h" +#define test_path_compare(a, b, result) { \ + assert_se(path_compare(a, b) == result); \ + assert_se(path_compare(b, a) == -result); \ + assert_se(path_equal(a, b) == !result); \ + assert_se(path_equal(b, a) == !result); \ + } static void test_path(void) { - assert_se(path_equal("/goo", "/goo")); - assert_se(path_equal("//goo", "/goo")); - assert_se(path_equal("//goo/////", "/goo")); - assert_se(path_equal("goo/////", "goo")); + test_path_compare("/goo", "/goo", 0); + test_path_compare("/goo", "/goo", 0); + test_path_compare("//goo", "/goo", 0); + test_path_compare("//goo/////", "/goo", 0); + test_path_compare("goo/////", "goo", 0); + + test_path_compare("/goo/boo", "/goo//boo", 0); + test_path_compare("//goo/boo", "/goo/boo//", 0); - assert_se(path_equal("/goo/boo", "/goo//boo")); - assert_se(path_equal("//goo/boo", "/goo/boo//")); + test_path_compare("/", "///", 0); - assert_se(path_equal("/", "///")); + test_path_compare("/x", "x/", 1); + test_path_compare("x/", "/", -1); - assert_se(!path_equal("/x", "x/")); - assert_se(!path_equal("x/", "/")); + test_path_compare("/x/./y", "x/y", 1); + test_path_compare("x/.y", "x/y", -1); - assert_se(!path_equal("/x/./y", "x/y")); - assert_se(!path_equal("x/.y", "x/y")); + test_path_compare("foo", "/foo", -1); + test_path_compare("/foo", "/foo/bar", -1); + test_path_compare("/foo/aaa", "/foo/b", -1); + test_path_compare("/foo/aaa", "/foo/b/a", -1); + test_path_compare("/foo/a", "/foo/aaa", -1); + test_path_compare("/foo/a/b", "/foo/aaa", -1); assert_se(path_is_absolute("/")); assert_se(!path_is_absolute("./")); @@ -176,13 +190,13 @@ static void test_path_join(void) { test_join("/root", "/a/b", "/c", "/root/a/b/c"); test_join("/root", "a/b", "c", "/root/a/b/c"); test_join("/root", "/a/b", "c", "/root/a/b/c"); - test_join("/root", "/", "c", "/root//c"); + test_join("/root", "/", "c", "/root/c"); test_join("/root", "/", NULL, "/root/"); test_join(NULL, "/a/b", "/c", "/a/b/c"); test_join(NULL, "a/b", "c", "a/b/c"); test_join(NULL, "/a/b", "c", "/a/b/c"); - test_join(NULL, "/", "c", "//c"); + test_join(NULL, "/", "c", "/c"); test_join(NULL, "/", NULL, "/"); }