test-hashmap-plain.c revision 61c81750217af7492be86adde81b28e310cd5e82
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering This file is part of systemd
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering Copyright 2013 Daniel Buch
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering systemd is free software; you can redistribute it and/or modify it
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering under the terms of the GNU Lesser General Public License as published by
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering (at your option) any later version.
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering systemd is distributed in the hope that it will be useful, but
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering Lesser General Public License for more details.
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering You should have received a copy of the GNU Lesser General Public License
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic void test_hashmap_replace(void) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering char *val1, *val2, *val3, *val4, *val5, *r;
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic void test_hashmap_copy(void) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic void test_hashmap_get_strv(void) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic void test_hashmap_move_one(void) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_move_one(n, NULL, "key 3") == -ENOENT);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_move_one(n, m, "key 5") == -ENOENT);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_move_one(n, m, "key 3") == 0);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_move_one(n, m, "key 4") == 0);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_move_one(n, m, "key 3") == -EEXIST);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic void test_hashmap_move(void) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic void test_hashmap_update(void) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_update(m, "key 2", val2) == -ENOENT);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_update(m, "key 1", val2) == 0);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic void test_hashmap_put(void) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) >= 0);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering valid_hashmap_put = hashmap_put(m, "key 1", val1);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_put(m, "key 1", val1) == 0);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering assert_se(hashmap_put(m, "key 1", (void *)"val 2") == -EEXIST);
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poetteringstatic void test_hashmap_remove(void) {
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering _cleanup_hashmap_free_ Hashmap *m = NULL;
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering hashmap_put(m, "key 1", (void*) "val 1");
84ac7bea360cd369df26910e9685a7eed2327088Lennart Poettering hashmap_put(m, "key 2", (void*) "val 2");
static void test_hashmap_remove2(void) {
void *r, *r2;
assert_se(m);
free(r);
static void test_hashmap_remove_value(void) {
assert_se(m);
static void test_hashmap_remove_and_put(void) {
int valid;
assert_se(m);
static void test_hashmap_remove_and_replace(void) {
int valid;
assert_se(m);
hashmap_clear(m);
static void test_hashmap_ensure_allocated(void) {
Hashmap *m;
int valid_hashmap;
assert_se(m);
hashmap_free(m);
static void test_hashmap_foreach_key(void) {
Hashmap *m;
Iterator i;
bool key_found[] = { false, false, false, false };
const char *key;
static const char key_table[] =
key_found[0] = true;
assert_se(m);
hashmap_free(m);
static void test_hashmap_foreach(void) {
Hashmap *m;
Iterator i;
bool value_found[] = { false, false, false, false };
unsigned count;
m = NULL;
count = 0;
HASHMAP_FOREACH(s, m, i)
count++;
count = 0;
HASHMAP_FOREACH(s, m, i)
count++;
HASHMAP_FOREACH(s, m, i) {
value_found[0] = true;
assert_se(m);
static void test_hashmap_merge(void) {
Hashmap *m;
Hashmap *n;
assert_se(n);
assert_se(m);
hashmap_free(n);
static void test_hashmap_contains(void) {
Hashmap *m;
char *val1;
assert_se(m);
static void test_hashmap_isempty(void) {
Hashmap *m;
char *val1;
assert_se(m);
static void test_hashmap_size(void) {
Hashmap *m;
assert_se(m);
static void test_hashmap_get(void) {
Hashmap *m;
char *val;
assert_se(m);
static void test_hashmap_get2(void) {
Hashmap *m;
char *val;
void *key_copy;
assert_se(m);
static void test_hashmap_many(void) {
Hashmap *h;
unsigned n_entries;
} tests[] = {
while (!hashmap_isempty(h)) {
k = hashmap_first_key(h);
v = hashmap_remove(h, k);
assert_se(v == k);
hashmap_free(h);
static void test_hashmap_first(void) {
assert_se(m);
#ifdef ORDERED
static void test_hashmap_first_key(void) {
assert_se(m);
#ifdef ORDERED
static void test_hashmap_steal_first_key(void) {
assert_se(m);
static void test_hashmap_steal_first(void) {
char *val;
assert_se(m);
static void test_hashmap_clear_free_free(void) {
assert_se(m);
static void test_hashmap_reserve(void) {
void test_hashmap_funcs(void) {