test-hashmap-plain.c revision 9ba81d5a61b7c992a1d2e5e02f334b8e2a0b0c22
/***
This file is part of systemd
Copyright 2013 Daniel Buch
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "strv.h"
#include "util.h"
#include "hashmap.h"
void test_hashmap_funcs(void);
static void test_hashmap_replace(void) {
Hashmap *m;
m = hashmap_new(&string_hash_ops);
r = hashmap_get(m, "key 3");
r = hashmap_get(m, "key 5");
hashmap_free(m);
}
static void test_hashmap_copy(void) {
m = hashmap_new(&string_hash_ops);
copy = hashmap_copy(m);
hashmap_free(m);
}
static void test_hashmap_get_strv(void) {
Hashmap *m;
char **strv;
m = hashmap_new(&string_hash_ops);
strv = hashmap_get_strv(m);
#ifndef ORDERED
#endif
hashmap_free(m);
}
static void test_hashmap_move_one(void) {
Hashmap *m, *n;
m = hashmap_new(&string_hash_ops);
n = hashmap_new(&string_hash_ops);
r = hashmap_get(n, "key 3");
r = hashmap_get(n, "key 4");
r = hashmap_get(m, "key 3");
assert_se(!r);
}
static void test_hashmap_move(void) {
Hashmap *m, *n;
m = hashmap_new(&string_hash_ops);
n = hashmap_new(&string_hash_ops);
hashmap_move(n, NULL);
hashmap_move(n, m);
r = hashmap_get(m, "key 1");
r = hashmap_get(n, "key 1");
r = hashmap_get(n, "key 2");
r = hashmap_get(n, "key 3");
r = hashmap_get(n, "key 4");
}
static void test_hashmap_update(void) {
Hashmap *m;
m = hashmap_new(&string_hash_ops);
r = hashmap_get(m, "key 1");
r = hashmap_get(m, "key 1");
r = hashmap_get(m, "key 1");
hashmap_free(m);
}
static void test_hashmap_put(void) {
int valid_hashmap_put;
void *val1 = (void*) "val 1";
assert_se(m);
hashmap_free(m);
}
static void test_hashmap_remove(void) {
char *r;
m = hashmap_new(&string_hash_ops);
assert_se(m);
r = hashmap_remove(m, "no such key");
r = hashmap_remove(m, "key 1");
r = hashmap_get(m, "key 2");
}
static void test_hashmap_remove2(void) {
char key1[] = "key 1";
char key2[] = "key 2";
char val1[] = "val 1";
char val2[] = "val 2";
void *r, *r2;
m = hashmap_new(&string_hash_ops);
assert_se(m);
free(r);
r = hashmap_get(m, key2);
}
static void test_hashmap_remove_value(void) {
char *r;
m = hashmap_new(&string_hash_ops);
assert_se(m);
r = hashmap_get(m, "key 2");
r = hashmap_get(m, "key 2");
}
static void test_hashmap_remove_and_put(void) {
int valid;
char *r;
m = hashmap_new(&string_hash_ops);
assert_se(m);
r = hashmap_get(m, "key 2");
}
static void test_hashmap_remove_and_replace(void) {
int valid;
void *r;
m = hashmap_new(&trivial_hash_ops);
assert_se(m);
r = hashmap_get(m, key2);
r = hashmap_get(m, key2);
}
static void test_hashmap_ensure_allocated(void) {
Hashmap *m;
int valid_hashmap;
m = hashmap_new(&string_hash_ops);
assert_se(valid_hashmap == 0);
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 *s;
const char *key;
static const char key_table[] =
"key 1\0"
"key 2\0"
"key 3\0"
"key 4\0";
m = hashmap_new(&string_hash_ops);
HASHMAP_FOREACH_KEY(s, key, m, i) {
key_found[0] = true;
key_found[1] = true;
key_found[2] = true;
key_found[3] = 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++;
m = hashmap_new(&string_hash_ops);
count = 0;
HASHMAP_FOREACH(s, m, i)
count++;
HASHMAP_FOREACH(s, m, i) {
value_found[0] = true;
value_found[1] = true;
value_found[2] = true;
value_found[3] = true;
}
assert_se(m);
}
static void test_hashmap_merge(void) {
Hashmap *m;
Hashmap *n;
n = hashmap_new(&string_hash_ops);
m = hashmap_new(&string_hash_ops);
assert_se(hashmap_merge(m, n) == 0);
r = hashmap_get(m, "Key 3");
r = hashmap_get(m, "Key 4");
assert_se(n);
assert_se(m);
hashmap_free(n);
}
static void test_hashmap_contains(void) {
Hashmap *m;
char *val1;
m = hashmap_new(&string_hash_ops);
assert_se(m);
}
static void test_hashmap_isempty(void) {
Hashmap *m;
char *val1;
m = hashmap_new(&string_hash_ops);
assert_se(hashmap_isempty(m));
assert_se(!hashmap_isempty(m));
assert_se(m);
}
static void test_hashmap_size(void) {
Hashmap *m;
m = hashmap_new(&string_hash_ops);
assert_se(m);
}
static void test_hashmap_get(void) {
Hashmap *m;
char *r;
char *val;
m = hashmap_new(&string_hash_ops);
r = hashmap_get(m, "Key 1");
r = hashmap_get(m, "no such key");
assert_se(m);
}
static void test_hashmap_get2(void) {
Hashmap *m;
char *r;
char *val;
char key_orig[] = "Key 1";
void *key_copy;
m = hashmap_new(&string_hash_ops);
assert_se(m);
}
}
static const struct hash_ops crippled_hashmap_ops = {
};
static void test_hashmap_many(void) {
Hashmap *h;
unsigned i, j;
void *v, *k;
static const struct {
unsigned n_entries;
} tests[] = {
};
for (j = 0; j < ELEMENTSOF(tests); j++) {
}
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) {
m = hashmap_new(&string_hash_ops);
assert_se(m);
assert_se(!hashmap_first(m));
#ifdef ORDERED
#endif
}
static void test_hashmap_first_key(void) {
m = hashmap_new(&string_hash_ops);
assert_se(m);
assert_se(!hashmap_first_key(m));
#ifdef ORDERED
#endif
}
static void test_hashmap_steal_first_key(void) {
m = hashmap_new(&string_hash_ops);
assert_se(m);
assert_se(hashmap_isempty(m));
}
static void test_hashmap_steal_first(void) {
int seen[3] = {};
char *val;
m = hashmap_new(&string_hash_ops);
assert_se(m);
while ((val = hashmap_steal_first(m)))
assert_se(hashmap_isempty(m));
}
static void test_hashmap_clear_free_free(void) {
m = hashmap_new(&string_hash_ops);
assert_se(m);
assert_se(hashmap_isempty(m));
}
void test_hashmap_funcs(void) {
}