From 2591ce9abb4b7e5c3be6d6d722298407e0bff21d Mon Sep 17 00:00:00 2001 From: Martin Stoilov Date: Tue, 7 Jun 2011 22:51:51 -0700 Subject: [PATCH] addig rmap test --- tests/testmisc/rmap-test.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/testmisc/rmap-test.c diff --git a/tests/testmisc/rmap-test.c b/tests/testmisc/rmap-test.c new file mode 100644 index 0000000..6a4012b --- /dev/null +++ b/tests/testmisc/rmap-test.c @@ -0,0 +1,44 @@ +#include +#include +#include "rmem.h" +#include "rmap.h" +#include "rstring.h" + + +rlong test_rmap_add(rmap_t *map, const rchar *name, rlong val) +{ + return r_map_add_s(map, name, &val); +} + + +void test_rmap_print(rmap_t * map, rsize_t index) +{ + if (r_map_value(map, index)) + fprintf(stdout, "(Index: %3ld) Key: %s, Value: %ld\n", index, r_map_key(map, index), *((rlong*)r_map_value(map, index))); + else + fprintf(stdout, "Invalid Index: %ld\n", index); +} + + +int main(int argc, char *argv[]) +{ + rmap_t *map = r_map_create(sizeof(rlong), 7); + + test_rmap_add(map, "one", 1); + test_rmap_add(map, "two", 2); + test_rmap_add(map, "three", 3); + r_map_delete(map, 1); + r_map_delete(map, 1); + test_rmap_add(map, "four", 4); + + test_rmap_print(map, 0); + test_rmap_print(map, 1); + test_rmap_print(map, 2); + test_rmap_print(map, 3); + + r_map_destroy(map); + + fprintf(stdout, "Max alloc mem: %ld\n", r_debug_get_maxmem()); + fprintf(stdout, "Leaked mem: %ld\n", r_debug_get_allocmem()); + return 0; +} -- 1.7.9.5