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.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c
index b319fa6ba9..ee4c0e66db 100644
--- a/src/test/test-hashmap.c
+++ b/src/test/test-hashmap.c
@@ -1,11 +1,17 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- Copyright © 2013 Daniel Buch
-***/
#include "hashmap.h"
#include "util.h"
+unsigned custom_counter = 0;
+static void custom_destruct(void* p) {
+ custom_counter--;
+ free(p);
+}
+
+DEFINE_HASH_OPS_FULL(boring_hash_ops, char, string_hash_func, string_compare_func, free, char, free);
+DEFINE_HASH_OPS_FULL(custom_hash_ops, char, string_hash_func, string_compare_func, custom_destruct, char, custom_destruct);
+
void test_hashmap_funcs(void);
void test_ordered_hashmap_funcs(void);
@@ -13,6 +19,8 @@ static void test_ordered_hashmap_next(void) {
_cleanup_ordered_hashmap_free_ OrderedHashmap *m = NULL;
int i;
+ log_info("/* %s */", __func__);
+
assert_se(m = ordered_hashmap_new(NULL));
for (i = -2; i <= 2; i++)
assert_se(ordered_hashmap_put(m, INT_TO_PTR(i), INT_TO_PTR(i+10)) == 1);
@@ -35,6 +43,8 @@ static void test_hashmap_free_with_destructor(void) {
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);
@@ -90,6 +100,8 @@ static void test_iterated_cache(void) {
Hashmap *m;
IteratedCache *c;
+ log_info("/* %s */", __func__);
+
assert_se(m = hashmap_new(NULL));
assert_se(c = hashmap_iterated_cache_new(m));
compare_cache(m, c);
@@ -125,6 +137,8 @@ static void test_iterated_cache(void) {
static void test_path_hashmap(void) {
_cleanup_hashmap_free_ Hashmap *h = NULL;
+ log_info("/* %s */", __func__);
+
assert_se(h = hashmap_new(&path_hash_ops));
assert_se(hashmap_put(h, "foo", INT_TO_PTR(1)) >= 0);