test-hashmap.c revision 647f68249f90855814de6eb6b0959c6096b41cae
/***
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 <inttypes.h>
#include "strv.h"
#include "util.h"
#include "hashmap.h"
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);
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);
hashmap_move_one(n, m, "key 3");
hashmap_move_one(n, m, "key 4");
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_next(void) {
Hashmap *m;
m = hashmap_new(&string_hash_ops);
r = hashmap_next(m, "key 1");
r = hashmap_next(m, "key 2");
r = hashmap_next(m, "key 3");
r = hashmap_next(m, "key 4");
assert_se(!r);
}
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");
hashmap_free(m);
}
static void test_hashmap_put(void) {
Hashmap *m;
int valid_hashmap_put;
m = hashmap_new(&string_hash_ops);
assert_se(m);
hashmap_free(m);
}
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_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 };
m = hashmap_new(&string_hash_ops);
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");
assert_se(m);
}
static void test_hashmap_many(void) {
Hashmap *h;
unsigned i;
#define N_ENTRIES 100000
}
hashmap_free(h);
}
static void test_hashmap_first_key(void) {
m = hashmap_new(&string_hash_ops);
assert_se(m);
assert_se(!hashmap_first_key(m));
}
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));
}
static void test_uint64_compare_func(void) {
assert_se(uint64_compare_func(&a, &a) == 0);
}
static void test_trivial_compare_func(void) {
}
static void test_string_compare_func(void) {
}
}