/***
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 "alloc-util.h"
#include "hashmap.h"
#include "string-util.h"
#include "strv.h"
#include "util.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);
assert_se(hashmap_move(n, m) == 0);
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;
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) {
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;
int i, j;
m = hashmap_new(&trivial_hash_ops);
assert_se(m);
r = hashmap_get(m, key2);
r = hashmap_get(m, key2);
/* Repeat this test several times to increase the chance of hitting
* the less likely case in hashmap_remove_and_replace where it
* compensates for the backward shift. */
for (i = 0; i < 20; i++) {
hashmap_clear(m);
for (j = 1; j < 7; j++)
for (j = 2; j < 7; j++) {
}
}
}
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) {
assert(s);
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;
void *key_copy;
m = hashmap_new(&string_hash_ops);
assert_se(m);
}
}
};
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) {
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_hashmap_reserve(void) {
m = hashmap_new(&string_hash_ops);
assert_se(hashmap_isempty(m));
}
void test_hashmap_funcs(void) {
}