summaryrefslogtreecommitdiff
path: root/src/test/test-hashmap-plain.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-10-15 00:30:54 +0200
committerMichal Schmidt <mschmidt@redhat.com>2014-10-23 17:38:02 +0200
commit8f88aed740ded77af443bb1b7c79bb229b50f8f8 (patch)
treed74782f8693fdb7ce55c1d93c2fbafa716546c37 /src/test/test-hashmap-plain.c
parente4c691b59db60ef2e6d8e64766d6ae02cd0dd457 (diff)
test: add test for hashmap_reserve()
Diffstat (limited to 'src/test/test-hashmap-plain.c')
-rw-r--r--src/test/test-hashmap-plain.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c
index ef78ed6cc9..8f7c039e3d 100644
--- a/src/test/test-hashmap-plain.c
+++ b/src/test/test-hashmap-plain.c
@@ -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();
}