test-hashmap.c revision d5099efc47d4e6ac60816b5381a5f607ab03f06e
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani This file is part of systemd
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Copyright 2013 Daniel Buch
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani systemd is free software; you can redistribute it and/or modify it
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani under the terms of the GNU Lesser General Public License as published by
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani the Free Software Foundation; either version 2.1 of the License, or
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani (at your option) any later version.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani systemd is distributed in the hope that it will be useful, but
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani WITHOUT ANY WARRANTY; without even the implied warranty of
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Lesser General Public License for more details.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani You should have received a copy of the GNU Lesser General Public License
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani along with systemd; If not, see <http://www.gnu.org/licenses/>.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_replace(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_copy(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_get_strv(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_move_one(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_next(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_update(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_put(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani valid_hashmap_put = hashmap_put(m, "key 1", (void*) (const char *) "val 1");
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_remove_and_put(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani valid = hashmap_remove_and_put(m, "unvalid key", "new key", NULL);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani valid = hashmap_put(m, "key 1", (void*) (const char *) "val 1");
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani valid = hashmap_remove_and_put(m, "key 1", "key 2", (void*) (const char *) "val 2");
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani valid = hashmap_put(m, "key 3", (void*) (const char *) "val 3");
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani valid = hashmap_remove_and_put(m, "key 3", "key 2", (void*) (const char *) "val 2");
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_ensure_allocated(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani valid_hashmap = hashmap_ensure_allocated(&m, &string_hash_ops);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_foreach_key(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani bool key_found[] = { false, false, false, false };
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani const char *s;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani const char *key;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani static const char key_table[] =
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani hashmap_put(m, key, (void*) (const char*) "my dummy val");
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani else if (!key_found[1] && streq(key, "key 2"))
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani else if (!key_found[2] && streq(key, "key 3"))
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani assert_se(key_found[0] && key_found[1] && key_found[2] && !key_found[3]);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistatic void test_hashmap_foreach(void) {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani bool value_found[] = { false, false, false, false };
HASHMAP_FOREACH(s, m, i) {
value_found[0] = true;
assert_se(m);
static void test_hashmap_foreach_backwards(void) {
Hashmap *m;
Iterator i;
bool value_found[] = { false, false, false, false };
HASHMAP_FOREACH_BACKWARDS(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_many(void) {
Hashmap *h;
hashmap_free(h);
static void test_hashmap_first_key(void) {
assert_se(m);
static void test_hashmap_last(void) {
assert_se(m);
static void test_hashmap_steal_first_key(void) {
assert_se(m);
static void test_hashmap_clear_free_free(void) {
assert_se(m);
static void test_uint64_compare_func(void) {
static void test_trivial_compare_func(void) {
static void test_string_compare_func(void) {