Add simple test for mempool
parent
494c9e9e46
commit
cb703877cb
|
@ -1 +1 @@
|
||||||
ctest --rerun-failed --output-on-failure --test-dir build/tests
|
ctest --output-on-failure --test-dir build/tests
|
||||||
|
|
|
@ -5,5 +5,13 @@ target_link_libraries(AABBTest PRIVATE
|
||||||
lib_scenes
|
lib_scenes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_executable(MemPoolTest test_mempool.c)
|
||||||
|
target_compile_features(MemPoolTest PRIVATE c_std_99)
|
||||||
|
target_link_libraries(MemPoolTest PRIVATE
|
||||||
|
cmocka
|
||||||
|
lib_scenes
|
||||||
|
)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_test(NAME AABBTest COMMAND AABBTest)
|
add_test(NAME AABBTest COMMAND AABBTest)
|
||||||
|
add_test(NAME MemPoolTest COMMAND MemPoolTest)
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include "mempool.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
|
||||||
|
static int setup_mempool(void** state)
|
||||||
|
{
|
||||||
|
init_memory_pools();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int teardown_mempool(void** state)
|
||||||
|
{
|
||||||
|
free_memory_pools();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_simple_get_and_free(void **state)
|
||||||
|
{
|
||||||
|
unsigned long idx;
|
||||||
|
Entity_t* ent = new_entity_from_mempool(&idx);
|
||||||
|
|
||||||
|
Entity_t* q_ent = get_entity_wtih_id(idx);
|
||||||
|
|
||||||
|
assert_memory_equal(ent, q_ent, sizeof(Entity_t));
|
||||||
|
|
||||||
|
free_entity_to_mempool(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
const struct CMUnitTest tests[] = {
|
||||||
|
cmocka_unit_test_setup_teardown(test_simple_get_and_free, setup_mempool, teardown_mempool),
|
||||||
|
};
|
||||||
|
|
||||||
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||||
|
}
|
Loading…
Reference in New Issue