diff --git a/engine/tests/base/manual/cc_test.c b/engine/tests/base/manual/cc_test.c index c791ede..d5ec52f 100644 --- a/engine/tests/base/manual/cc_test.c +++ b/engine/tests/base/manual/cc_test.c @@ -1,5 +1,6 @@ #include #include "base.h" +#include "memory_arena.h" #include int main(void) { @@ -27,6 +28,29 @@ int main(void) { mem_arena_print(); } + { + cc_map(char*, int) str_map; + cc_init(&str_map); + cc_reserve(&str_map, 4); + mem_arena_print(); + { + // For char*, you have to allocated memory (static or dynamic) + char* sample = mem_arena_malloc(4); + memcpy(sample, "lol", 4); + cc_insert(&str_map, sample, 15); + } + int* val = cc_get(&str_map, "lol"); + printf("str key get: %p\n", val); + mem_arena_print(); + // Need to retrieve char* to free, if it is dynamic + // On retrive, dereference to get point and free + // Safer to NULL check first + // but we know it exists + mem_arena_free((void*)*cc_key_for(&str_map, val)); + cc_cleanup(&str_map); + mem_arena_print(); + } + { printf("Map of maps\n"); cc_map(int, cc_map(int,int)) map_of_map;