32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt/***
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt This file is part of systemd
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Copyright 2013 Daniel Buch
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt systemd is free software; you can redistribute it and/or modify it
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt under the terms of the GNU Lesser General Public License as published by
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt the Free Software Foundation; either version 2.1 of the License, or
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt (at your option) any later version.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt systemd is distributed in the hope that it will be useful, but
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt WITHOUT ANY WARRANTY; without even the implied warranty of
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Lesser General Public License for more details.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt You should have received a copy of the GNU Lesser General Public License
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt along with systemd; If not, see <http://www.gnu.org/licenses/>.
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt***/
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "alloc-util.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "hashmap.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "string-util.h"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include "strv.h"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#include "util.h"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtvoid test_hashmap_funcs(void);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_replace(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1, *val2, *val3, *val4, *val5, *r;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("val1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val2 = strdup("val2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val3 = strdup("val3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val4 = strdup("val4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val5 = strdup("val5");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val5);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 2", val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 3", val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 4", val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_replace(m, "key 3", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "key 3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "val1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_replace(m, "key 5", val5);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "key 5");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "val5"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt free(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt free(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt free(val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt free(val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt free(val5);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_copy(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m, *copy;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1, *val2, *val3, *val4, *r;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("val1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val2 = strdup("val2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val3 = strdup("val3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val4 = strdup("val4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 2", val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 3", val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 4", val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt copy = hashmap_copy(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(copy, "key 1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "val1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(copy, "key 2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "val2"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(copy, "key 3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "val3"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(copy, "key 4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "val4"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(copy);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_get_strv(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char **strv;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1, *val2, *val3, *val4;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("val1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val2 = strdup("val2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val3 = strdup("val3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val4 = strdup("val4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 2", val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 3", val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 4", val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt strv = hashmap_get_strv(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#ifndef ORDERED
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt strv = strv_sort(strv);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#endif
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(strv[0], "val1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(strv[1], "val2"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(strv[2], "val3"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(strv[3], "val4"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt strv_free(strv);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_move_one(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m, *n;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1, *val2, *val3, *val4, *r;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("val1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val2 = strdup("val2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val3 = strdup("val3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val4 = strdup("val4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt n = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 2", val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 3", val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 4", val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_move_one(n, NULL, "key 3") == -ENOENT);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_move_one(n, m, "key 5") == -ENOENT);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_move_one(n, m, "key 3") == 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_move_one(n, m, "key 4") == 0);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(n, "key 3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(r && streq(r, "val3"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(n, "key 4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(r && streq(r, "val4"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "key 3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(!r);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_move_one(n, m, "key 3") == -EEXIST);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_free_free(m);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_free_free(n);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic void test_hashmap_move(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt Hashmap *m, *n;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char *val1, *val2, *val3, *val4, *r;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt val1 = strdup("val1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(val1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt val2 = strdup("val2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(val2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt val3 = strdup("val3");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(val3);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt val4 = strdup("val4");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(val4);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt m = hashmap_new(&string_hash_ops);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt n = hashmap_new(&string_hash_ops);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(n, "key 1", strdup(val1));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, "key 1", val1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, "key 2", val2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, "key 3", val3);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, "key 4", val4);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
e80afdb3e4a1239ce0bffa4215d6a227caf3d833Michal Schmidt assert_se(hashmap_move(n, NULL) == 0);
e80afdb3e4a1239ce0bffa4215d6a227caf3d833Michal Schmidt assert_se(hashmap_move(n, m) == 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_size(m) == 1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, "key 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r && streq(r, "val1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(n, "key 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r && streq(r, "val1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(n, "key 2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r && streq(r, "val2"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(n, "key 3");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r && streq(r, "val3"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(n, "key 4");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r && streq(r, "val4"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(n);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_update(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1, *val2, *r;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("old_value");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val2 = strdup("new_value");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "key 1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "old_value"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_update(m, "key 2", val2) == -ENOENT);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, "key 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, "old_value"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_update(m, "key 1", val2) == 0);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "key 1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "new_value"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt free(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt free(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_put(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt Hashmap *m = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int valid_hashmap_put;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt void *val1 = (void*) "val 1";
435fc3176520a58f1c20ccb983c9fb40b30a1471Martin Pitt void *val2 = (void*) "val 2";
435fc3176520a58f1c20ccb983c9fb40b30a1471Martin Pitt _cleanup_free_ char* key1 = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
61c81750217af7492be86adde81b28e310cd5e82Tom Gundersen assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) >= 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid_hashmap_put = hashmap_put(m, "key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(valid_hashmap_put == 1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_put(m, "key 1", val1) == 0);
435fc3176520a58f1c20ccb983c9fb40b30a1471Martin Pitt assert_se(hashmap_put(m, "key 1", val2) == -EEXIST);
435fc3176520a58f1c20ccb983c9fb40b30a1471Martin Pitt key1 = strdup("key 1");
435fc3176520a58f1c20ccb983c9fb40b30a1471Martin Pitt assert_se(hashmap_put(m, key1, val1) == 0);
435fc3176520a58f1c20ccb983c9fb40b30a1471Martin Pitt assert_se(hashmap_put(m, key1, val2) == -EEXIST);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic void test_hashmap_remove(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char *r;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove(NULL, "key 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt m = hashmap_new(&string_hash_ops);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(m);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove(m, "no such key");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, "key 1", (void*) "val 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, "key 2", (void*) "val 2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove(m, "key 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, "val 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, "key 2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, "val 2"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_get(m, "key 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic void test_hashmap_remove2(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt _cleanup_hashmap_free_free_free_ Hashmap *m = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char key1[] = "key 1";
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char key2[] = "key 2";
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char val1[] = "val 1";
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char val2[] = "val 2";
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt void *r, *r2;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove2(NULL, "key 1", &r2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt m = hashmap_new(&string_hash_ops);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(m);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove2(m, "no such key", &r2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, strdup(key1), strdup(val1));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, strdup(key2), strdup(val2));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove2(m, key1, &r2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, val1));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r2, key1));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt free(r);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt free(r2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, key2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, val2));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_get(m, key1));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic void test_hashmap_remove_value(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char *r;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove_value(NULL, "key 1", (void*) "val 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt m = hashmap_new(&string_hash_ops);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(m);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove_value(m, "key 1", (void*) "val 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, "key 1", (void*) "val 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, "key 2", (void*) "val 2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove_value(m, "key 1", (void*) "val 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, "val 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, "key 2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, "val 2"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_get(m, "key 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_remove_value(m, "key 2", (void*) "val 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, "key 2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, "val 2"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_get(m, "key 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_remove_and_put(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int valid;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *r;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid = hashmap_remove_and_put(m, "invalid key", "new key", NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == -ENOENT);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt valid = hashmap_put(m, "key 1", (void*) (const char *) "val 1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(valid == 1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid = hashmap_remove_and_put(NULL, "key 1", "key 2", (void*) (const char *) "val 2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == -ENOENT);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt valid = hashmap_remove_and_put(m, "key 1", "key 2", (void*) (const char *) "val 2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(valid == 0);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "key 2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, "val 2"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(!hashmap_get(m, "key 1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt valid = hashmap_put(m, "key 3", (void*) (const char *) "val 3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(valid == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt valid = hashmap_remove_and_put(m, "key 3", "key 2", (void*) (const char *) "val 2");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == -EEXIST);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic void test_hashmap_remove_and_replace(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt int valid;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt void *key1 = UINT_TO_PTR(1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt void *key2 = UINT_TO_PTR(2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt void *key3 = UINT_TO_PTR(3);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt void *r;
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt int i, j;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt m = hashmap_new(&trivial_hash_ops);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(m);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid = hashmap_remove_and_replace(m, key1, key2, NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == -ENOENT);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid = hashmap_put(m, key1, key1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == 1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid = hashmap_remove_and_replace(NULL, key1, key2, key2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == -ENOENT);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid = hashmap_remove_and_replace(m, key1, key2, key2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, key2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == key2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_get(m, key1));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid = hashmap_put(m, key3, key3);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == 1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt valid = hashmap_remove_and_replace(m, key3, key2, key2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(valid == 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, key2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == key2);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_get(m, key3));
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt /* Repeat this test several times to increase the chance of hitting
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt * the less likely case in hashmap_remove_and_replace where it
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt * compensates for the backward shift. */
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt for (i = 0; i < 20; i++) {
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt hashmap_clear(m);
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt for (j = 1; j < 7; j++)
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt hashmap_put(m, UINT_TO_PTR(10*i + j), UINT_TO_PTR(10*i + j));
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt valid = hashmap_remove_and_replace(m, UINT_TO_PTR(10*i + 1),
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt UINT_TO_PTR(10*i + 2),
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt UINT_TO_PTR(10*i + 2));
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt assert_se(valid == 0);
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt assert_se(!hashmap_get(m, UINT_TO_PTR(10*i + 1)));
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt for (j = 2; j < 7; j++) {
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt r = hashmap_get(m, UINT_TO_PTR(10*i + j));
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt assert_se(r == UINT_TO_PTR(10*i + j));
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt }
e1323fbfbe8a574f28b704f2df8ce7f99e3a28f5Michal Schmidt }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_ensure_allocated(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int valid_hashmap;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt valid_hashmap = hashmap_ensure_allocated(&m, &string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(valid_hashmap == 0);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_foreach_key(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Iterator i;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt bool key_found[] = { false, false, false, false };
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt const char *s;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt const char *key;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt static const char key_table[] =
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "key 1\0"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "key 2\0"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "key 3\0"
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt "key 4\0";
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt NULSTR_FOREACH(key, key_table)
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, key, (void*) (const char*) "my dummy val");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt HASHMAP_FOREACH_KEY(s, key, m, i) {
8927b1dad2d4a7330174cb924090b4635a2547fbDavid Herrmann assert(s);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (!key_found[0] && streq(key, "key 1"))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt key_found[0] = true;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt else if (!key_found[1] && streq(key, "key 2"))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt key_found[1] = true;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt else if (!key_found[2] && streq(key, "key 3"))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt key_found[2] = true;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt else if (!key_found[3] && streq(key, "fail"))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt key_found[3] = true;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(key_found[0] && key_found[1] && key_found[2] && !key_found[3]);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_foreach(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Iterator i;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt bool value_found[] = { false, false, false, false };
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1, *val2, *val3, *val4, *s;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt unsigned count;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("my val1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val2 = strdup("my val2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val3 = strdup("my val3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val4 = strdup("my val4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt m = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt count = 0;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt HASHMAP_FOREACH(s, m, i)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt count++;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(count == 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt count = 0;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt HASHMAP_FOREACH(s, m, i)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt count++;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(count == 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 2", val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 3", val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 4", val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt HASHMAP_FOREACH(s, m, i) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt if (!value_found[0] && streq(s, val1))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt value_found[0] = true;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt else if (!value_found[1] && streq(s, val2))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt value_found[1] = true;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt else if (!value_found[2] && streq(s, val3))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt value_found[2] = true;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt else if (!value_found[3] && streq(s, val4))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt value_found[3] = true;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(value_found[0] && value_found[1] && value_found[2] && value_found[3]);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_merge(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *n;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1, *val2, *val3, *val4, *r;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("my val1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val2 = strdup("my val2");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val3 = strdup("my val3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val4 = strdup("my val4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt n = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 2", val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(n, "Key 3", val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(n, "Key 4", val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_merge(m, n) == 0);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "Key 3");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(r && streq(r, "my val3"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "Key 4");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(r && streq(r, "my val4"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(n);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free(n);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_contains(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("my val");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(!hashmap_contains(m, "Key 1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_contains(m, "Key 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_contains(m, "Key 2"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_contains(NULL, "Key 1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_isempty(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("my val");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_isempty(m));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(!hashmap_isempty(m));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_size(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val1, *val2, *val3, *val4;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val1 = strdup("my val");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val2 = strdup("my val");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val3 = strdup("my val");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val4 = strdup("my val");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_size(NULL) == 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_buckets(NULL) == 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 1", val1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 2", val2);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 3", val3);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 4", val4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_size(m) == 4);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_buckets(m) >= 4);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_get(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *m;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *r;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt val = strdup("my val");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(val);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(NULL, "Key 1");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_put(m, "Key 1", val);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt r = hashmap_get(m, "Key 1");
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(r, val));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get(m, "no such key");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_free_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic void test_hashmap_get2(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt Hashmap *m;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char *r;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char *val;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt char key_orig[] = "Key 1";
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt void *key_copy;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt val = strdup("my val");
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(val);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt key_copy = strdup(key_orig);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(key_copy);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get2(NULL, key_orig, &key_copy);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt m = hashmap_new(&string_hash_ops);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_put(m, key_copy, val);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt key_copy = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get2(m, key_orig, &key_copy);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(r, val));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(key_orig != key_copy);
b669934fae49c9158c35e612e54e1765edca8584Thomas Hindoe Paaboel Andersen assert_se(streq(key_orig, key_copy));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt r = hashmap_get2(m, "no such key", NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(r == NULL);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(m);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_free_free_free(m);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersenstatic void crippled_hashmap_func(const void *p, struct siphash *state) {
b826ab586c9e0a9c0d438a75c28cf3a8ab485929Tom Gundersen return trivial_hash_func(INT_TO_PTR(PTR_TO_INT(p) & 0xff), state);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic const struct hash_ops crippled_hashmap_ops = {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt .hash = crippled_hashmap_func,
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt .compare = trivial_compare_func,
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt};
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_many(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt Hashmap *h;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt unsigned i, j;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt void *v, *k;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt static const struct {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt const struct hash_ops *ops;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt unsigned n_entries;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt } tests[] = {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt { .ops = NULL, .n_entries = 1 << 20 },
11de3decc9357714498f96e13f1c1c2da1046811Michal Schmidt { .ops = &crippled_hashmap_ops, .n_entries = 1 << 14 },
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt };
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt for (j = 0; j < ELEMENTSOF(tests); j++) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(h = hashmap_new(tests[j].ops));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt for (i = 1; i < tests[j].n_entries*3; i+=3) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_put(h, UINT_TO_PTR(i), UINT_TO_PTR(i)) >= 0);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(PTR_TO_UINT(hashmap_get(h, UINT_TO_PTR(i))) == i);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt }
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt for (i = 1; i < tests[j].n_entries*3; i++)
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_contains(h, UINT_TO_PTR(i)) == (i % 3 == 1));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
ce79279bff6e7a1a17070509a039ab635796f129Michal Schmidt log_info("%u <= %u * 0.8 = %g", hashmap_size(h), hashmap_buckets(h), hashmap_buckets(h) * 0.8);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
ce79279bff6e7a1a17070509a039ab635796f129Michal Schmidt assert_se(hashmap_size(h) <= hashmap_buckets(h) * 0.8);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_size(h) == tests[j].n_entries);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt while (!hashmap_isempty(h)) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt k = hashmap_first_key(h);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt v = hashmap_remove(h, k);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(v == k);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt }
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt hashmap_free(h);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt }
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt}
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidtstatic void test_hashmap_first(void) {
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt m = hashmap_new(&string_hash_ops);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(m);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(!hashmap_first(m));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_put(m, "key 1", (void*) "val 1") == 1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(hashmap_first(m), "val 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_put(m, "key 2", (void*) "val 2") == 1);
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt#ifdef ORDERED
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(hashmap_first(m), "val 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(hashmap_remove(m, "key 1"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt assert_se(streq(hashmap_first(m), "val 2"));
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt#endif
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_first_key(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(!hashmap_first_key(m));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, "key 1", NULL) == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(hashmap_first_key(m), "key 1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, "key 2", NULL) == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#ifdef ORDERED
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(hashmap_first_key(m), "key 1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_remove(m, "key 1") == NULL);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(hashmap_first_key(m), "key 2"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt#endif
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_steal_first_key(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(!hashmap_steal_first_key(m));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, "key 1", NULL) == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(streq(hashmap_steal_first_key(m), "key 1"));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_isempty(m));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_steal_first(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt int seen[3] = {};
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt char *val;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, "key 1", (void*) "1") == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, "key 2", (void*) "22") == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, "key 3", (void*) "333") == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt while ((val = hashmap_steal_first(m)))
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt seen[strlen(val) - 1]++;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(seen[0] == 1 && seen[1] == 1 && seen[2] == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_isempty(m));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtstatic void test_hashmap_clear_free_free(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt m = hashmap_new(&string_hash_ops);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, strdup("key 1"), NULL) == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, strdup("key 2"), NULL) == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_put(m, strdup("key 3"), NULL) == 1);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt hashmap_clear_free_free(m);
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt assert_se(hashmap_isempty(m));
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidtstatic void test_hashmap_reserve(void) {
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt _cleanup_hashmap_free_ Hashmap *m = NULL;
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt m = hashmap_new(&string_hash_ops);
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt assert_se(hashmap_reserve(m, 1) == 0);
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt assert_se(hashmap_buckets(m) < 1000);
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt assert_se(hashmap_reserve(m, 1000) == 0);
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt assert_se(hashmap_buckets(m) >= 1000);
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt assert_se(hashmap_isempty(m));
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt assert_se(hashmap_put(m, "key 1", (void*) "val 1") == 1);
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt assert_se(hashmap_reserve(m, UINT_MAX) == -ENOMEM);
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt assert_se(hashmap_reserve(m, UINT_MAX - 1) == -ENOMEM);
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt}
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidtvoid test_hashmap_funcs(void) {
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_copy();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_get_strv();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_move_one();
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt test_hashmap_move();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_replace();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_update();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_put();
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt test_hashmap_remove();
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt test_hashmap_remove2();
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt test_hashmap_remove_value();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_remove_and_put();
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt test_hashmap_remove_and_replace();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_ensure_allocated();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_foreach();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_foreach_key();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_contains();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_merge();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_isempty();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_get();
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt test_hashmap_get2();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_size();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_many();
9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22Michal Schmidt test_hashmap_first();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_first_key();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_steal_first_key();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_steal_first();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt test_hashmap_clear_free_free();
8f88aed740ded77af443bb1b7c79bb229b50f8f8Michal Schmidt test_hashmap_reserve();
32a4456cc252689f51f383d150d34ed636bfec4dMichal Schmidt}