Compare commits

..

No commits in common. "cb703877cb2032879d1f8f1d72405df4fd3d7dba" and "7929178411b86795c16941e8f9ccb70d798e0e23" have entirely different histories.

6 changed files with 3 additions and 57 deletions

View File

@ -111,7 +111,7 @@ target_link_libraries(assets_test
${GAME_LIBS} ${GAME_LIBS}
) )
if (BUILD_TESTING) if (UNIT_TESTING)
find_package(cmocka 1.1.0 REQUIRED) find_package(cmocka 1.1.0 REQUIRED)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()

View File

@ -1 +1 @@
ctest --output-on-failure --test-dir build/tests ctest --rerun-failed --output-on-failure --test-dir build/tests

View File

@ -93,7 +93,7 @@ uint8_t check_collision_line(const CollideEntity_t* ent, TileGrid_t* grid, bool
unsigned int tile_y2 = (ent->area.tile_y2 >= grid->height) ? grid->height - 1 : ent->area.tile_y2; unsigned int tile_y2 = (ent->area.tile_y2 >= grid->height) ? grid->height - 1 : ent->area.tile_y2;
Vector2 p1 = {ent->bbox.x, ent->bbox.y}; Vector2 p1 = {ent->bbox.x, ent->bbox.y};
Vector2 p2 = {ent->bbox.x + ent->bbox.width, ent->bbox.y + ent->bbox.height}; Vector2 p2 = {ent->bbox.x + ent->bbox.width - 1, ent->bbox.y + ent->bbox.height - 1};
for(unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++) for(unsigned int tile_y = tile_y1; tile_y <= tile_y2; tile_y++)
{ {
if (tile_y >= grid->height) return 0; if (tile_y >= grid->height) return 0;

View File

@ -5,13 +5,5 @@ 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)

View File

@ -1,5 +1,4 @@
#include "AABB.h" #include "AABB.h"
#include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
@ -26,14 +25,10 @@ static void test_line_AABB(void **state)
p1.y = 0; p1.y = 0;
p2.y = 0; p2.y = 0;
assert_false(line_in_AABB(p1, p2, box));
p2.y = 1;
assert_true(line_in_AABB(p1, p2, box)); assert_true(line_in_AABB(p1, p2, box));
p1 = (Vector2){5, 0}; p1 = (Vector2){5, 0};
p2 = (Vector2){5, 10}; p2 = (Vector2){5, 10};
assert_false(line_in_AABB(p1, p2, box));
p2 = (Vector2){6, 10};
assert_true(line_in_AABB(p1, p2, box)); assert_true(line_in_AABB(p1, p2, box));
p1 = (Vector2){14, 0}; p1 = (Vector2){14, 0};

View File

@ -1,41 +0,0 @@
#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);
}