X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Ftest%2Ftest-hashmap-plain.c;h=ce686b650caf7d6f7dedec3666016ddd8400ac91;hp=ef78ed6cc91dcbfd4390b3645721f2eedeba2cee;hb=7ad63f57b6ce7ae9e3cc19dcb441f0a4494fa3f2;hpb=9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22 diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index ef78ed6cc..ce686b650 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -194,8 +194,8 @@ static void test_hashmap_move(void) { hashmap_put(m, "key 3", val3); hashmap_put(m, "key 4", val4); - hashmap_move(n, NULL); - hashmap_move(n, m); + assert(hashmap_move(n, NULL) == 0); + assert(hashmap_move(n, m) == 0); assert_se(hashmap_size(m) == 1); r = hashmap_get(m, "key 1"); @@ -795,6 +795,23 @@ static void test_hashmap_clear_free_free(void) { assert_se(hashmap_isempty(m)); } +static void test_hashmap_reserve(void) { + _cleanup_hashmap_free_ Hashmap *m = NULL; + + m = hashmap_new(&string_hash_ops); + + assert_se(hashmap_reserve(m, 1) == 0); + assert_se(hashmap_buckets(m) < 1000); + assert_se(hashmap_reserve(m, 1000) == 0); + assert_se(hashmap_buckets(m) >= 1000); + assert_se(hashmap_isempty(m)); + + assert_se(hashmap_put(m, "key 1", (void*) "val 1") == 1); + + assert_se(hashmap_reserve(m, UINT_MAX) == -ENOMEM); + assert_se(hashmap_reserve(m, UINT_MAX - 1) == -ENOMEM); +} + void test_hashmap_funcs(void) { test_hashmap_copy(); test_hashmap_get_strv(); @@ -823,4 +840,5 @@ void test_hashmap_funcs(void) { test_hashmap_steal_first_key(); test_hashmap_steal_first(); test_hashmap_clear_free_free(); + test_hashmap_reserve(); }