summaryrefslogtreecommitdiff
path: root/src/test/test-hashmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-hashmap.c')
-rw-r--r--src/test/test-hashmap.c64
1 files changed, 8 insertions, 56 deletions
diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c
index ee4c0e66db..1a6e8ffa58 100644
--- a/src/test/test-hashmap.c
+++ b/src/test/test-hashmap.c
@@ -31,31 +31,6 @@ static void test_ordered_hashmap_next(void) {
assert_se(!ordered_hashmap_next(m, INT_TO_PTR(3)));
}
-typedef struct Item {
- int seen;
-} Item;
-static void item_seen(Item *item) {
- item->seen++;
-}
-
-static void test_hashmap_free_with_destructor(void) {
- Hashmap *m;
- struct Item items[4] = {};
- unsigned i;
-
- log_info("/* %s */", __func__);
-
- assert_se(m = hashmap_new(NULL));
- for (i = 0; i < ELEMENTSOF(items) - 1; i++)
- assert_se(hashmap_put(m, INT_TO_PTR(i), items + i) == 1);
-
- m = hashmap_free_with_destructor(m, item_seen);
- assert_se(items[0].seen == 1);
- assert_se(items[1].seen == 1);
- assert_se(items[2].seen == 1);
- assert_se(items[3].seen == 0);
-}
-
static void test_uint64_compare_func(void) {
const uint64_t a = 0x100, b = 0x101;
@@ -134,47 +109,24 @@ static void test_iterated_cache(void) {
assert_se(iterated_cache_free(c) == NULL);
}
-static void test_path_hashmap(void) {
- _cleanup_hashmap_free_ Hashmap *h = NULL;
+int main(int argc, const char *argv[]) {
+ /* This file tests in test-hashmap-plain.c, and tests in test-hashmap-ordered.c, which is generated
+ * from test-hashmap-plain.c. Hashmap tests should be added to test-hashmap-plain.c, and here only if
+ * they don't apply to ordered hashmaps. */
- log_info("/* %s */", __func__);
+ log_parse_environment();
+ log_open();
- assert_se(h = hashmap_new(&path_hash_ops));
-
- assert_se(hashmap_put(h, "foo", INT_TO_PTR(1)) >= 0);
- assert_se(hashmap_put(h, "/foo", INT_TO_PTR(2)) >= 0);
- assert_se(hashmap_put(h, "//foo", INT_TO_PTR(3)) == -EEXIST);
- assert_se(hashmap_put(h, "//foox/", INT_TO_PTR(4)) >= 0);
- assert_se(hashmap_put(h, "/foox////", INT_TO_PTR(5)) == -EEXIST);
- assert_se(hashmap_put(h, "foo//////bar/quux//", INT_TO_PTR(6)) >= 0);
- assert_se(hashmap_put(h, "foo/bar//quux/", INT_TO_PTR(8)) == -EEXIST);
-
- assert_se(hashmap_get(h, "foo") == INT_TO_PTR(1));
- assert_se(hashmap_get(h, "foo/") == INT_TO_PTR(1));
- assert_se(hashmap_get(h, "foo////") == INT_TO_PTR(1));
- assert_se(hashmap_get(h, "/foo") == INT_TO_PTR(2));
- assert_se(hashmap_get(h, "//foo") == INT_TO_PTR(2));
- assert_se(hashmap_get(h, "/////foo////") == INT_TO_PTR(2));
- assert_se(hashmap_get(h, "/////foox////") == INT_TO_PTR(4));
- assert_se(hashmap_get(h, "/foox/") == INT_TO_PTR(4));
- assert_se(hashmap_get(h, "/foox") == INT_TO_PTR(4));
- assert_se(!hashmap_get(h, "foox"));
- assert_se(hashmap_get(h, "foo/bar/quux") == INT_TO_PTR(6));
- assert_se(hashmap_get(h, "foo////bar////quux/////") == INT_TO_PTR(6));
- assert_se(!hashmap_get(h, "/foo////bar////quux/////"));
-}
-
-int main(int argc, const char *argv[]) {
test_hashmap_funcs();
test_ordered_hashmap_funcs();
+ log_info("/************ non-shared tests ************/");
+
test_ordered_hashmap_next();
- test_hashmap_free_with_destructor();
test_uint64_compare_func();
test_trivial_compare_func();
test_string_compare_func();
test_iterated_cache();
- test_path_hashmap();
return 0;
}