summaryrefslogtreecommitdiffstats
path: root/src/test/test-hash-funcs.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:35:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:35:18 +0000
commitb750101eb236130cf056c675997decbac904cc49 (patch)
treea5df1a06754bdd014cb975c051c83b01c9a97532 /src/test/test-hash-funcs.c
parentInitial commit. (diff)
downloadsystemd-b750101eb236130cf056c675997decbac904cc49.tar.xz
systemd-b750101eb236130cf056c675997decbac904cc49.zip
Adding upstream version 252.22.upstream/252.22
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);