summaryrefslogtreecommitdiffstats
path: root/src/test/test-set.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-25 13:54:44 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-12-02 12:05:16 +0100
commit98233ee5e031cf39f5be73651a1f05c52927116b (patch)
treede35dadf5120e845f5404fb8ed65e17a485274dc /src/test/test-set.c
parenthash-func: add destructors for key and value (diff)
downloadsystemd-98233ee5e031cf39f5be73651a1f05c52927116b.tar.xz
systemd-98233ee5e031cf39f5be73651a1f05c52927116b.zip
test: add tests for destructors of hashmap or set
Diffstat (limited to 'src/test/test-set.c')
-rw-r--r--src/test/test-set.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/test-set.c b/src/test/test-set.c
index 6307403e4c..340edeb65f 100644
--- a/src/test/test-set.c
+++ b/src/test/test-set.c
@@ -45,6 +45,24 @@ static void test_set_free_with_destructor(void) {
assert_se(items[3].seen == 0);
}
+DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(item_hash_ops, void, trivial_hash_func, trivial_compare_func, Item, item_seen);
+
+static void test_set_free_with_hash_ops(void) {
+ Set *m;
+ struct Item items[4] = {};
+ unsigned i;
+
+ assert_se(m = set_new(&item_hash_ops));
+ for (i = 0; i < ELEMENTSOF(items) - 1; i++)
+ assert_se(set_put(m, items + i) == 1);
+
+ m = set_free(m);
+ 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_set_put(void) {
_cleanup_set_free_ Set *m = NULL;
@@ -64,6 +82,7 @@ static void test_set_put(void) {
int main(int argc, const char *argv[]) {
test_set_steal_first();
test_set_free_with_destructor();
+ test_set_free_with_hash_ops();
test_set_put();
return 0;