summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2015-03-16 21:58:35 +0100
committerMichal Schmidt <mschmidt@redhat.com>2015-03-16 22:01:41 +0100
commit2230852bd9755e1b7bfd1260082471f559b0a005 (patch)
tree939362eed4ff66bb8b32f1791d0ae33840c8254a /src/test
parent9a3d3aace311e85627115d89e4dfe1d71c01b7e3 (diff)
shared: add path_compare(), an ordering path comparison
... and make path_equal() a simple wrapper around it.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-path-util.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
index 11aa52aaed..6396fcb398 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("./"));