summaryrefslogtreecommitdiffstats
path: root/src/test/test-hash-funcs.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:49:52 +0000
commit55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch)
tree33f869f55a1b149e9b7c2b7e201867ca5dd52992 /src/test/test-hash-funcs.c
parentInitial commit. (diff)
downloadsystemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz
systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/test-hash-funcs.c')
-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);