summaryrefslogtreecommitdiffstats
path: root/src/test/test-hash-funcs.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/test-hash-funcs.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/test/test-hash-funcs.c b/src/test/test-hash-funcs.c
new file mode 100644
index 0000000..f5166c1
--- /dev/null
+++ b/src/test/test-hash-funcs.c
@@ -0,0 +1,77 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "tests.h"
+#include "hash-funcs.h"
+#include "set.h"
+
+TEST(path_hash_set) {
+ /* The goal is to make sure that non-simplified path are hashed as expected,
+ * and that we don't need to simplify them beforehand. */
+
+ /* No freeing of keys, we operate on static strings hereā€¦ */
+ _cleanup_set_free_ Set *set = NULL;
+
+ assert_se(set_isempty(set));
+ assert_se(set_ensure_put(&set, &path_hash_ops, "foo") == 1);
+ assert_se(set_ensure_put(&set, &path_hash_ops, "foo") == 0);
+ assert_se(set_ensure_put(&set, &path_hash_ops, "bar") == 1);
+ assert_se(set_ensure_put(&set, &path_hash_ops, "bar") == 0);
+ assert_se(set_ensure_put(&set, &path_hash_ops, "/foo") == 1);
+ assert_se(set_ensure_put(&set, &path_hash_ops, "/bar") == 1);
+ assert_se(set_ensure_put(&set, &path_hash_ops, "/foo/.") == 0);
+ assert_se(set_ensure_put(&set, &path_hash_ops, "/./bar/./.") == 0);
+
+ assert_se(set_contains(set, "foo"));
+ assert_se(set_contains(set, "bar"));
+ assert_se(set_contains(set, "./foo"));
+ assert_se(set_contains(set, "./foo/."));
+ assert_se(set_contains(set, "./bar"));
+ assert_se(set_contains(set, "./bar/."));
+ assert_se(set_contains(set, "/foo"));
+ assert_se(set_contains(set, "/bar"));
+ assert_se(set_contains(set, "//./foo"));
+ assert_se(set_contains(set, "///./foo/."));
+ assert_se(set_contains(set, "////./bar"));
+ assert_se(set_contains(set, "/////./bar/."));
+
+ assert_se(set_contains(set, "foo/"));
+ assert_se(set_contains(set, "bar/"));
+ assert_se(set_contains(set, "./foo/"));
+ assert_se(set_contains(set, "./foo/./"));
+ assert_se(set_contains(set, "./bar/"));
+ assert_se(set_contains(set, "./bar/./"));
+ assert_se(set_contains(set, "/foo/"));
+ assert_se(set_contains(set, "/bar/"));
+ assert_se(set_contains(set, "//./foo/"));
+ assert_se(set_contains(set, "///./foo/./"));
+ assert_se(set_contains(set, "////./bar/"));
+ assert_se(set_contains(set, "/////./bar/./"));
+
+ assert_se(!set_contains(set, "foo."));
+ assert_se(!set_contains(set, ".bar"));
+ assert_se(!set_contains(set, "./foo."));
+ assert_se(!set_contains(set, "./.foo/."));
+ assert_se(!set_contains(set, "../bar"));
+ assert_se(!set_contains(set, "./bar/.."));
+ assert_se(!set_contains(set, "./foo.."));
+ assert_se(!set_contains(set, "/..bar"));
+ assert_se(!set_contains(set, "//../foo"));
+ assert_se(!set_contains(set, "///../foo/."));
+ assert_se(!set_contains(set, "////../bar"));
+ assert_se(!set_contains(set, "/////../bar/."));
+
+ assert_se(!set_contains(set, "foo./"));
+ assert_se(!set_contains(set, ".bar/"));
+ assert_se(!set_contains(set, "./foo./"));
+ assert_se(!set_contains(set, "./.foo/./"));
+ assert_se(!set_contains(set, "../bar/"));
+ assert_se(!set_contains(set, "./bar/../"));
+ assert_se(!set_contains(set, "./foo../"));
+ assert_se(!set_contains(set, "/..bar/"));
+ assert_se(!set_contains(set, "//../foo/"));
+ assert_se(!set_contains(set, "///../foo/./"));
+ assert_se(!set_contains(set, "////../bar/"));
+ assert_se(!set_contains(set, "/////../bar/./"));
+}
+
+DEFINE_TEST_MAIN(LOG_INFO);