Got the suite rebuilding, most tests pass, actor and sprite are failing
This commit is contained in:
@@ -15,9 +15,9 @@
|
||||
#include <sdl3game/heap.h>
|
||||
|
||||
int UNHANDLED_ERROR_BEHAVIOR;
|
||||
ErrorContext *unhandled_error_context;
|
||||
akerr_ErrorContext *unhandled_error_context;
|
||||
|
||||
void handle_unhandled_error_noexit(ErrorContext *errctx)
|
||||
void handle_unhandled_error_noexit(akerr_ErrorContext *errctx)
|
||||
{
|
||||
if ( errctx == NULL ) {
|
||||
return;
|
||||
@@ -33,7 +33,7 @@ void handle_unhandled_error_noexit(ErrorContext *errctx)
|
||||
}
|
||||
|
||||
int actor_updated;
|
||||
ErrorContext *actor_update_noop(actor *obj)
|
||||
akerr_ErrorContext *actor_update_noop(actor *obj)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
actor_updated = 1;
|
||||
@@ -42,44 +42,43 @@ ErrorContext *actor_update_noop(actor *obj)
|
||||
|
||||
// Currently the renderer assumes there is a global variable named `renderer`
|
||||
int actor_rendered;
|
||||
ErrorContext *actor_render_noop(actor *obj, SDL_Renderer *r)
|
||||
akerr_ErrorContext *actor_render_noop(actor *obj, SDL_Renderer *r)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
actor_rendered = 1;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_registry_actor_iterator_nullpointers(void)
|
||||
akerr_ErrorContext *test_registry_actor_iterator_nullpointers(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
ErrorUnhandledErrorHandler defaulthandler = error_handler_unhandled_error;
|
||||
akerr_ErrorUnhandledErrorHandler defaulthandler = akerr_handler_unhandled_error;
|
||||
|
||||
error_handler_unhandled_error = handle_unhandled_error_noexit;
|
||||
akerr_handler_unhandled_error = handle_unhandled_error_noexit;
|
||||
ATTEMPT {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_SET;
|
||||
DETECT(unhandled_error_context, registry_iterate_actor(NULL, REGISTRY_ACTOR, ""));
|
||||
} CLEANUP {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_EXIT;
|
||||
} PROCESS(unhandled_error_context) {
|
||||
} HANDLE(unhandled_error_context, ERR_NULLPOINTER) {
|
||||
} HANDLE(unhandled_error_context, AKERR_NULLPOINTER) {
|
||||
printf("Handled\n");
|
||||
} FINISH(unhandled_error_context, true);
|
||||
IGNORE(heap_release_error(unhandled_error_context));
|
||||
error_handler_unhandled_error = defaulthandler;
|
||||
akerr_handler_unhandled_error = defaulthandler;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_registry_actor_iterator_missingactor(void)
|
||||
akerr_ErrorContext *test_registry_actor_iterator_missingactor(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
ErrorUnhandledErrorHandler defaulthandler = error_handler_unhandled_error;
|
||||
akerr_ErrorUnhandledErrorHandler defaulthandler = akerr_handler_unhandled_error;
|
||||
|
||||
iterator iter = {
|
||||
.layerid = 0,
|
||||
.flags = 0
|
||||
};
|
||||
error_handler_unhandled_error = handle_unhandled_error_noexit;
|
||||
akerr_handler_unhandled_error = handle_unhandled_error_noexit;
|
||||
ATTEMPT {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_SET;
|
||||
DETECT(
|
||||
@@ -92,25 +91,24 @@ ErrorContext *test_registry_actor_iterator_missingactor(void)
|
||||
} CLEANUP {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_EXIT;
|
||||
} PROCESS(unhandled_error_context) {
|
||||
} HANDLE(unhandled_error_context, ERR_KEY) {
|
||||
} HANDLE(unhandled_error_context, AKERR_KEY) {
|
||||
printf("Handled\n");
|
||||
} FINISH(unhandled_error_context, true);
|
||||
IGNORE(heap_release_error(unhandled_error_context));
|
||||
error_handler_unhandled_error = defaulthandler;
|
||||
akerr_handler_unhandled_error = defaulthandler;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_registry_actor_iterator_updaterender(void)
|
||||
akerr_ErrorContext *test_registry_actor_iterator_updaterender(void)
|
||||
{
|
||||
actor *testactor;
|
||||
iterator iter = {
|
||||
.layerid = 0,
|
||||
.flags = ITERATOR_OP_UPDATE | ITERATOR_OP_RENDER
|
||||
};
|
||||
ErrorUnhandledErrorHandler defaulthandler = error_handler_unhandled_error;
|
||||
akerr_ErrorUnhandledErrorHandler defaulthandler = akerr_handler_unhandled_error;
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
error_handler_unhandled_error = handle_unhandled_error_noexit;
|
||||
akerr_handler_unhandled_error = handle_unhandled_error_noexit;
|
||||
ATTEMPT {
|
||||
UNHANDLED_ERROR_BEHAVIOR = UNHANDLED_ERROR_SET;
|
||||
CATCH(unhandled_error_context, heap_next_actor(&testactor));
|
||||
@@ -131,13 +129,13 @@ ErrorContext *test_registry_actor_iterator_updaterender(void)
|
||||
FAIL_ZERO_BREAK(
|
||||
unhandled_error_context,
|
||||
actor_updated,
|
||||
ERR_BEHAVIOR,
|
||||
AKERR_BEHAVIOR,
|
||||
"actor->updatefunc not called by the iterator"
|
||||
);
|
||||
FAIL_ZERO_BREAK(
|
||||
unhandled_error_context,
|
||||
actor_rendered,
|
||||
ERR_BEHAVIOR,
|
||||
AKERR_BEHAVIOR,
|
||||
"actor->renderfunc not called by the iterator"
|
||||
);
|
||||
} CLEANUP {
|
||||
@@ -146,13 +144,12 @@ ErrorContext *test_registry_actor_iterator_updaterender(void)
|
||||
} PROCESS(unhandled_error_context) {
|
||||
} FINISH(unhandled_error_context, true);
|
||||
|
||||
IGNORE(heap_release_error(unhandled_error_context));
|
||||
error_handler_unhandled_error = defaulthandler;
|
||||
akerr_handler_unhandled_error = defaulthandler;
|
||||
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_actor_set_character(void)
|
||||
akerr_ErrorContext *test_actor_set_character(void)
|
||||
{
|
||||
actor *testactor = NULL;
|
||||
character *testchar = NULL;
|
||||
@@ -163,7 +160,7 @@ ErrorContext *test_actor_set_character(void)
|
||||
CATCH(errctx, actor_set_character(NULL, "test"));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
printf("Handled\n");
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -180,7 +177,7 @@ ErrorContext *test_actor_set_character(void)
|
||||
} CLEANUP {
|
||||
IGNORE(heap_release_actor(testactor));
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
printf("Handled\n");
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -205,7 +202,7 @@ ErrorContext *test_actor_set_character(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_actor_manage_children(void)
|
||||
akerr_ErrorContext *test_actor_manage_children(void)
|
||||
{
|
||||
actor *parent = NULL;
|
||||
actor *child = NULL;
|
||||
@@ -238,12 +235,12 @@ ErrorContext *test_actor_manage_children(void)
|
||||
CATCH(errctx, parent->addchild(parent, child));
|
||||
} CLEANUP {
|
||||
if ( errctx == NULL ) {
|
||||
FAIL(errctx, ERR_BEHAVIOR, "addchild does not throw ERR_RELATIONSHIP when child already has a parent");
|
||||
FAIL(errctx, AKERR_BEHAVIOR, "addchild does not throw AKERR_RELATIONSHIP when child already has a parent");
|
||||
}
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_RELATIONSHIP) {
|
||||
} HANDLE(errctx, AKERR_RELATIONSHIP) {
|
||||
// Expected behavior
|
||||
SDL_Log("addchild throws ERR_RELATIONSHIP when child already has a parent");
|
||||
SDL_Log("addchild throws AKERR_RELATIONSHIP when child already has a parent");
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
@@ -251,23 +248,23 @@ ErrorContext *test_actor_manage_children(void)
|
||||
CATCH(errctx, parent->addchild(parent, child));
|
||||
} CLEANUP {
|
||||
if ( errctx == NULL ) {
|
||||
FAIL(errctx, ERR_BEHAVIOR, "addchild does not throw ERR_OUTOFBOUNDS when all children already set");
|
||||
FAIL(errctx, AKERR_BEHAVIOR, "addchild does not throw AKERR_OUTOFBOUNDS when all children already set");
|
||||
}
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_OUTOFBOUNDS) {
|
||||
} HANDLE(errctx, AKERR_OUTOFBOUNDS) {
|
||||
// Expected behavior
|
||||
SDL_Log("addchild throws ERR_OUTOFBOUNDS when all children already set");
|
||||
SDL_Log("addchild throws AKERR_OUTOFBOUNDS when all children already set");
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_release_actor(parent));
|
||||
// All actor objects on the heap should be empty now
|
||||
for ( i = 0; i < MAX_HEAP_ACTOR; i++) {
|
||||
FAIL_NONZERO_BREAK(errctx, HEAP_ACTOR[i].refcount, ERR_VALUE, "Actor not properly cleared");
|
||||
FAIL_NONZERO_BREAK(errctx, HEAP_ACTOR[i].parent, ERR_VALUE, "Actor not properly cleared");
|
||||
FAIL_NONZERO_BREAK(errctx, HEAP_ACTOR[i].refcount, AKERR_VALUE, "Actor not properly cleared");
|
||||
FAIL_NONZERO_BREAK(errctx, HEAP_ACTOR[i].parent, AKERR_VALUE, "Actor not properly cleared");
|
||||
for ( j = 0 ; j < ACTOR_MAX_CHILDREN; j++) {
|
||||
if ( HEAP_ACTOR[i].children[j] != NULL ) {
|
||||
FAIL(errctx, ERR_VALUE, "Actor not properly cleared");
|
||||
FAIL(errctx, AKERR_VALUE, "Actor not properly cleared");
|
||||
goto _test_actor_addchild_heaprelease_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -277,7 +274,7 @@ ErrorContext *test_actor_manage_children(void)
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
SDL_GetPointerProperty(REGISTRY_ACTOR, (char *)&tmpstring->data, NULL),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Child %s was not removed from the registry",
|
||||
(char *)&tmpstring->data);
|
||||
}
|
||||
@@ -293,13 +290,13 @@ _test_actor_addchild_heaprelease_cleanup:
|
||||
CATCH(errctx, actor_initialize(child, "child"));
|
||||
// Don't release our claim on the child. The child should not be reclaimed.
|
||||
CATCH(errctx, heap_release_actor(parent));
|
||||
FAIL_NONZERO_BREAK(errctx, child->parent, ERR_VALUE, "Child still references released parent");
|
||||
FAIL_ZERO_BREAK(errctx, child->refcount, ERR_VALUE, "Child prematurely released");
|
||||
FAIL_NONZERO_BREAK(errctx, strcmp(child->name, "child"), ERR_VALUE, "Child had identity erased");
|
||||
FAIL_NONZERO_BREAK(errctx, child->parent, AKERR_VALUE, "Child still references released parent");
|
||||
FAIL_ZERO_BREAK(errctx, child->refcount, AKERR_VALUE, "Child prematurely released");
|
||||
FAIL_NONZERO_BREAK(errctx, strcmp(child->name, "child"), AKERR_VALUE, "Child had identity erased");
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
(child == SDL_GetPointerProperty(REGISTRY_ACTOR, child->name, NULL)),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Child prematurely removed from the registry");
|
||||
// Now we can release the child
|
||||
CATCH(errctx, heap_release_actor(child));
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <sdl3game/character.h>
|
||||
#include <sdl3game/actor.h>
|
||||
#include <sdl3game/error.h>
|
||||
#include <sdl3game/heap.h>
|
||||
#include <sdl3game/registry.h>
|
||||
#include <sdl3game/iterator.h>
|
||||
@@ -10,7 +11,7 @@
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
ErrorContext *test_character_initialize()
|
||||
akerr_ErrorContext *test_character_initialize()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
character *testchar = NULL;
|
||||
@@ -20,18 +21,18 @@ ErrorContext *test_character_initialize()
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
SDL_GetPointerProperty(REGISTRY_CHARACTER, "testchar", NULL),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Character was not placed in the registry");
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
strcmp((char *)&testchar->name, "testchar"),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Character was not named properly ('testchar' vs '%s')",
|
||||
(char *)&testchar->name);
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testchar->state_sprites,
|
||||
ERR_NULLPOINTER,
|
||||
AKERR_NULLPOINTER,
|
||||
"Character state sprites map was not initialized");
|
||||
} CLEANUP {
|
||||
IGNORE(heap_release_character(testchar));
|
||||
@@ -40,7 +41,7 @@ ErrorContext *test_character_initialize()
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_character_sprite_mgmt()
|
||||
akerr_ErrorContext *test_character_sprite_mgmt()
|
||||
{
|
||||
character *testchar = NULL;
|
||||
sprite *testsprite = NULL;
|
||||
@@ -54,21 +55,21 @@ ErrorContext *test_character_sprite_mgmt()
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testsprite,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Sprite loaded from json but not in registry");
|
||||
CATCH(errctx, sprite_load_json("assets/testsprite2.json"));
|
||||
testsprite2 = SDL_GetPointerProperty(REGISTRY_SPRITE, "testsprite2", NULL);
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testsprite2,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Sprite 2 loaded from json but not in registry");
|
||||
CATCH(errctx, testchar->sprite_add(testchar, testsprite, ACTOR_STATE_ALIVE));
|
||||
CATCH(errctx, testchar->sprite_add(testchar, testsprite2, ACTOR_STATE_DEAD));
|
||||
CATCH(errctx, testchar->sprite_get(testchar, (ACTOR_STATE_ALIVE), &comparesprite));
|
||||
FAIL_ZERO_BREAK(errctx, (comparesprite == testsprite), ERR_VALUE, "Wrong sprite for state ACTOR_STATE_ALIVE | ACTOR_STATE_FACE_LEFT");
|
||||
FAIL_ZERO_BREAK(errctx, (comparesprite == testsprite), AKERR_VALUE, "Wrong sprite for state ACTOR_STATE_ALIVE | ACTOR_STATE_FACE_LEFT");
|
||||
CATCH(errctx, testchar->sprite_get(testchar, ACTOR_STATE_DEAD, &comparesprite));
|
||||
FAIL_ZERO_BREAK(errctx, (comparesprite == testsprite2), ERR_VALUE, "Wrong sprite for state ACTOR_STATE_DEAD");
|
||||
FAIL_ZERO_BREAK(errctx, (comparesprite == testsprite2), AKERR_VALUE, "Wrong sprite for state ACTOR_STATE_DEAD");
|
||||
} CLEANUP {
|
||||
IGNORE(heap_release_sprite(testsprite));
|
||||
IGNORE(heap_release_sprite(testsprite2));
|
||||
@@ -78,7 +79,7 @@ ErrorContext *test_character_sprite_mgmt()
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_character_iterate_state_sprites()
|
||||
akerr_ErrorContext *test_character_iterate_state_sprites()
|
||||
{
|
||||
character *testchar = NULL;
|
||||
sprite *testsprite = NULL;
|
||||
@@ -93,14 +94,14 @@ ErrorContext *test_character_iterate_state_sprites()
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testsprite,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Sprite loaded from json but not in registry");
|
||||
CATCH(errctx, sprite_load_json("assets/testsprite2.json"));
|
||||
testsprite2 = SDL_GetPointerProperty(REGISTRY_SPRITE, "testsprite2", NULL);
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testsprite2,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Sprite 2 loaded from json but not in registry");
|
||||
CATCH(errctx, testchar->sprite_add(testchar, testsprite, ACTOR_STATE_ALIVE));
|
||||
CATCH(errctx, testchar->sprite_add(testchar, testsprite2, ACTOR_STATE_DEAD));
|
||||
@@ -113,12 +114,12 @@ ErrorContext *test_character_iterate_state_sprites()
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
(testsprite->refcount > 1),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"heap_release_sprite not called for testsprite from iterator");
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
(testsprite2->refcount > 1),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"heap_release_sprite not called for testsprite from iterator");
|
||||
} CLEANUP {
|
||||
IGNORE(heap_release_sprite(testsprite));
|
||||
@@ -129,7 +130,7 @@ ErrorContext *test_character_iterate_state_sprites()
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_character_load_json()
|
||||
akerr_ErrorContext *test_character_load_json()
|
||||
{
|
||||
character *testcharacter = NULL;
|
||||
sprite *testsprite = NULL;
|
||||
@@ -146,14 +147,14 @@ ErrorContext *test_character_load_json()
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testsprite,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Sprite loaded from json but not in registry");
|
||||
CATCH(errctx, sprite_load_json("assets/testsprite2.json"));
|
||||
testsprite2 = SDL_GetPointerProperty(REGISTRY_SPRITE, "testsprite2", NULL);
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testsprite2,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Sprite 2 loaded from json but not in registry");
|
||||
|
||||
CATCH(errctx, character_load_json("assets/testcharacter.json"));
|
||||
@@ -161,15 +162,15 @@ ErrorContext *test_character_load_json()
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testcharacter,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Character loaded from json but not in registry");
|
||||
CATCH(errctx, testcharacter->sprite_get(testcharacter, (ACTOR_STATE_ALIVE | ACTOR_STATE_FACE_LEFT), &comparesprite));
|
||||
FAIL_ZERO_BREAK(errctx, (comparesprite == testsprite), ERR_VALUE, "Wrong sprite for state ACTOR_STATE_ALIVE");
|
||||
FAIL_ZERO_BREAK(errctx, (comparesprite == testsprite), AKERR_VALUE, "Wrong sprite for state ACTOR_STATE_ALIVE");
|
||||
CATCH(errctx, testcharacter->sprite_get(testcharacter, ACTOR_STATE_DEAD, &comparesprite));
|
||||
FAIL_ZERO_BREAK(errctx, (comparesprite == testsprite2), ERR_VALUE, "Wrong sprite for state ACTOR_STATE_DEAD");
|
||||
FAIL_ZERO_BREAK(errctx, (comparesprite == testsprite2), AKERR_VALUE, "Wrong sprite for state ACTOR_STATE_DEAD");
|
||||
|
||||
FAIL_ZERO_BREAK(errctx, (testcharacter->vx != 0.200000003), ERR_VALUE, "Wrong X velocity for test character");
|
||||
FAIL_ZERO_BREAK(errctx, (testcharacter->vy != 0.200000003), ERR_VALUE, "Wrong Y velocity for test character");
|
||||
FAIL_ZERO_BREAK(errctx, (testcharacter->vx != 0.200000003), AKERR_VALUE, "Wrong X velocity for test character");
|
||||
FAIL_ZERO_BREAK(errctx, (testcharacter->vy != 0.200000003), AKERR_VALUE, "Wrong Y velocity for test character");
|
||||
|
||||
// Release our handles on the sprites so the character's heap_release can reduce them to 0
|
||||
CATCH(errctx, heap_release_sprite(testsprite));
|
||||
@@ -180,7 +181,7 @@ ErrorContext *test_character_load_json()
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
((testsprite->refcount < tsrc) || (testsprite2->refcount < tsrc2)),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"character did not reduce reference count of its child sprites when released");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
@@ -195,11 +196,11 @@ int main(void)
|
||||
SDL_SetAppMetadata("SDL3-GameTest", "0.1", "net.aklabs.sdl3-gametest");
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO )) {
|
||||
FAIL_BREAK(errctx, ERR_SDL, "Couldn't initialize SDL: %s", SDL_GetError());
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Couldn't initialize SDL: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer("net/aklabs/libsdl3game/test_character", 640, 480, SDL_WINDOW_HIDDEN, &window, &renderer)) {
|
||||
FAIL_BREAK(errctx, ERR_SDL, "Couldn't create window/renderer: %s", SDL_GetError());
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Couldn't create window/renderer: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
CATCH(errctx, heap_init());
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <sdl3game/sprite.h>
|
||||
#include <sdl3game/actor.h>
|
||||
#include <sdl3game/registry.h>
|
||||
#include <sdl3game/error.h>
|
||||
|
||||
int numsprites = 8;
|
||||
char *spritepaths[] = {
|
||||
@@ -39,11 +40,11 @@ int main(void)
|
||||
SDL_SetAppMetadata("SDL3-GameTest", "0.1", "net.aklabs.sdl3-gametest");
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO )) {
|
||||
FAIL_BREAK(errctx, ERR_SDL, "Couldn't initialize SDL: %s", SDL_GetError());
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Couldn't initialize SDL: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer("net/aklabs/libsdl3game/test_sprite", 640, 480, 0, &window, &renderer)) {
|
||||
FAIL_BREAK(errctx, ERR_SDL, "Couldn't create window/renderer: %s", SDL_GetError());
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Couldn't create window/renderer: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
CATCH(errctx, heap_init());
|
||||
@@ -67,7 +68,7 @@ int main(void)
|
||||
REGISTRY_CHARACTER,
|
||||
"little guy",
|
||||
NULL);
|
||||
FAIL_ZERO_BREAK(errctx, actorptr->basechar, ERR_REGISTRY, "Can't load character 'little guy' from the registry");
|
||||
FAIL_ZERO_BREAK(errctx, actorptr->basechar, AKERR_REGISTRY, "Can't load character 'little guy' from the registry");
|
||||
actorptr->movement_controls_face = false;
|
||||
actorptr->state = (ACTOR_STATE_ALIVE | ACTOR_STATE_FACE_LEFT);
|
||||
actorptr->x = 320;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <akerror.h>
|
||||
#include <sdl3game/registry.h>
|
||||
|
||||
typedef ErrorContext *(*RegistryFuncPtr)(void);
|
||||
typedef akerr_ErrorContext *(*RegistryFuncPtr)(void);
|
||||
|
||||
void *sdl_calloc_always_fails(size_t a, size_t b)
|
||||
{
|
||||
@@ -11,7 +11,7 @@ void *sdl_calloc_always_fails(size_t a, size_t b)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ErrorContext *test_registry_init(RegistryFuncPtr funcptr)
|
||||
akerr_ErrorContext *test_registry_init(RegistryFuncPtr funcptr)
|
||||
{
|
||||
SDL_malloc_func malloc_func;
|
||||
SDL_calloc_func calloc_func;
|
||||
@@ -43,17 +43,17 @@ ErrorContext *test_registry_init(RegistryFuncPtr funcptr)
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
|
||||
FAIL_RETURN(errctx, ERR_BEHAVIOR, "SDL memory allocator fails but registry reports successful property creation");
|
||||
FAIL_RETURN(errctx, AKERR_BEHAVIOR, "SDL memory allocator fails but registry reports successful property creation");
|
||||
}
|
||||
|
||||
ErrorContext *test_registry_init_creation_failures(void)
|
||||
akerr_ErrorContext *test_registry_init_creation_failures(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
CATCH(errctx, test_registry_init(®istry_init_actor));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
printf("Sucess\n");
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -61,7 +61,7 @@ ErrorContext *test_registry_init_creation_failures(void)
|
||||
CATCH(errctx, test_registry_init(®istry_init_sprite));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
printf("Sucess\n");
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -69,7 +69,7 @@ ErrorContext *test_registry_init_creation_failures(void)
|
||||
CATCH(errctx, test_registry_init(®istry_init_spritesheet));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
printf("Sucess\n");
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -77,7 +77,7 @@ ErrorContext *test_registry_init_creation_failures(void)
|
||||
CATCH(errctx, test_registry_init(®istry_init_character));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
printf("Sucess\n");
|
||||
} FINISH(errctx, true);
|
||||
SUCCEED_RETURN(errctx);
|
||||
|
||||
@@ -9,11 +9,12 @@
|
||||
#include <sdl3game/sprite.h>
|
||||
#include <sdl3game/heap.h>
|
||||
#include <sdl3game/util.h>
|
||||
#include <sdl3game/error.h>
|
||||
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
ErrorContext *test_spritesheet_initialize(void)
|
||||
akerr_ErrorContext *test_spritesheet_initialize(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
spritesheet *sheet = NULL;
|
||||
@@ -28,16 +29,16 @@ ErrorContext *test_spritesheet_initialize(void)
|
||||
|
||||
snprintf((char *)&tmpstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/spritesheet.png");
|
||||
CATCH(errctx, spritesheet_initialize(sheet, 48, 48, "assets/spritesheet.png"));
|
||||
FAIL_ZERO_BREAK(errctx, sheet->texture, ERR_VALUE, "spritesheet_initialize failed to load the sprite texture");
|
||||
FAIL_ZERO_BREAK(errctx, sheet->texture, AKERR_VALUE, "spritesheet_initialize failed to load the sprite texture");
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
((sheet->texture->w != 576) || (sheet->texture->h != 384)),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Loaded texture was not the correct size");
|
||||
|
||||
snprintf((char *)&tmpstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/spritesheet.png");
|
||||
image = IMG_LoadTexture(renderer, (char *)&tmpstr->data);
|
||||
FAIL_ZERO_BREAK(errctx, image, ERR_SDL, "Failed to load comparison image");
|
||||
FAIL_ZERO_BREAK(errctx, image, AKERR_SDL, "Failed to load comparison image");
|
||||
|
||||
CATCH(
|
||||
errctx,
|
||||
@@ -51,7 +52,7 @@ ErrorContext *test_spritesheet_initialize(void)
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
SDL_GetPointerProperty(REGISTRY_SPRITESHEET, "assets/spritesheet.png", NULL),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Spritesheet was not placed in the registry");
|
||||
|
||||
} CLEANUP {
|
||||
@@ -64,7 +65,7 @@ ErrorContext *test_spritesheet_initialize(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_sprite_initialize(void)
|
||||
akerr_ErrorContext *test_sprite_initialize(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
spritesheet *testsheet = NULL;
|
||||
@@ -82,14 +83,14 @@ ErrorContext *test_sprite_initialize(void)
|
||||
|
||||
snprintf((char *)&tmpstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/spritesheet.png");
|
||||
CATCH(errctx, spritesheet_initialize(testsheet, 48, 48, "assets/spritesheet.png"));
|
||||
FAIL_ZERO_BREAK(errctx, testsheet, ERR_VALUE, "spritesheet_initialize failed");
|
||||
FAIL_ZERO_BREAK(errctx, testsheet, AKERR_VALUE, "spritesheet_initialize failed");
|
||||
|
||||
CATCH(errctx, sprite_initialize(testsprite, "test", testsheet));
|
||||
FAIL_NONZERO_BREAK(errctx, (testsprite->sheet != testsheet), ERR_VALUE, "Initialized sprite uses wrong sheet");
|
||||
FAIL_NONZERO_BREAK(errctx, (testsprite->sheet != testsheet), AKERR_VALUE, "Initialized sprite uses wrong sheet");
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
SDL_GetPointerProperty(REGISTRY_SPRITE, "test", NULL),
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"Sprite was not placed in the registry");
|
||||
|
||||
} CLEANUP {
|
||||
@@ -100,7 +101,7 @@ ErrorContext *test_sprite_initialize(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_sprite_load_json(void)
|
||||
akerr_ErrorContext *test_sprite_load_json(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
sprite *testsprite = NULL;
|
||||
@@ -120,25 +121,25 @@ ErrorContext *test_sprite_load_json(void)
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testsprite,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"sprite_load_json succeeds but sprite is not placed in the registry");
|
||||
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->width == 48), ERR_VALUE, "width incorrect (48 : %d)", testsprite->width);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->height == 48), ERR_VALUE, "height incorrect (48 : %d)", testsprite->height);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->speed == 100), ERR_VALUE, "speed incorrect (100 : %d)", testsprite->speed);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->loop == true), ERR_VALUE, "loop incorrect (1 : %d)", testsprite->loop);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->loopReverse == true), ERR_VALUE, "loopReverse incorrect (1 : %d)", testsprite->loopReverse);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->frames == 3), ERR_VALUE, "frame count incorrect (3 : %d)", testsprite->frames);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->frameids[0] == 12), ERR_VALUE, "frameids[0] incorrect (12 : %d)", testsprite->frameids[0]);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->frameids[1] == 13), ERR_VALUE, "frameids[1] incorrect (13 : %d)", testsprite->frameids[1]);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->frameids[2] == 14), ERR_VALUE, "frameids[2] incorrect (14 : %d)", testsprite->frameids[2]);
|
||||
FAIL_NONZERO_BREAK(errctx, strcmp(testsprite->name, "testsprite"), ERR_VALUE, "name incorrect (testsprite : %s)", (char *)testsprite->name);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->width == 48), AKERR_VALUE, "width incorrect (48 : %d)", testsprite->width);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->height == 48), AKERR_VALUE, "height incorrect (48 : %d)", testsprite->height);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->speed == 100), AKERR_VALUE, "speed incorrect (100 : %d)", testsprite->speed);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->loop == true), AKERR_VALUE, "loop incorrect (1 : %d)", testsprite->loop);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->loopReverse == true), AKERR_VALUE, "loopReverse incorrect (1 : %d)", testsprite->loopReverse);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->frames == 3), AKERR_VALUE, "frame count incorrect (3 : %d)", testsprite->frames);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->frameids[0] == 12), AKERR_VALUE, "frameids[0] incorrect (12 : %d)", testsprite->frameids[0]);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->frameids[1] == 13), AKERR_VALUE, "frameids[1] incorrect (13 : %d)", testsprite->frameids[1]);
|
||||
FAIL_ZERO_BREAK(errctx, (testsprite->frameids[2] == 14), AKERR_VALUE, "frameids[2] incorrect (14 : %d)", testsprite->frameids[2]);
|
||||
FAIL_NONZERO_BREAK(errctx, strcmp(testsprite->name, "testsprite"), AKERR_VALUE, "name incorrect (testsprite : %s)", (char *)testsprite->name);
|
||||
|
||||
// Is it using the right spritesheet?
|
||||
|
||||
snprintf((char *)&tmpstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/spritesheet.png");
|
||||
image = IMG_LoadTexture(renderer, (char *)&tmpstr->data);
|
||||
FAIL_ZERO_BREAK(errctx, image, ERR_SDL, "Failed to load comparison image");
|
||||
FAIL_ZERO_BREAK(errctx, image, AKERR_SDL, "Failed to load comparison image");
|
||||
|
||||
CATCH(
|
||||
errctx,
|
||||
@@ -157,13 +158,13 @@ ErrorContext *test_sprite_load_json(void)
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testsprite,
|
||||
ERR_KEY,
|
||||
AKERR_KEY,
|
||||
"sprite_load_json succeeds but second sprite is not placed in the registry");
|
||||
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
(testsprite->sheet == testsprite2->sheet),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Previously loaded spritesheets are not reused");
|
||||
|
||||
} CLEANUP {
|
||||
@@ -190,11 +191,11 @@ int main(void)
|
||||
SDL_SetAppMetadata("SDL3-GameTest", "0.1", "net.aklabs.sdl3-gametest");
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO )) {
|
||||
FAIL_BREAK(errctx, ERR_SDL, "Couldn't initialize SDL: %s", SDL_GetError());
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Couldn't initialize SDL: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer("net/aklabs/libsdl3game/test_sprite", 640, 480, 0, &window, &renderer)) {
|
||||
FAIL_BREAK(errctx, ERR_SDL, "Couldn't create window/renderer: %s", SDL_GetError());
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Couldn't create window/renderer: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
CATCH(errctx, heap_init());
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
void reset_string_heap(void);
|
||||
|
||||
ErrorContext *test_fresh_heap_gives_strings(void)
|
||||
akerr_ErrorContext *test_fresh_heap_gives_strings(void)
|
||||
{
|
||||
string *ptr = NULL;
|
||||
|
||||
@@ -22,7 +22,7 @@ ErrorContext *test_fresh_heap_gives_strings(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ErrorContext *test_string_heap_error_when_no_strings_left(void)
|
||||
akerr_ErrorContext *test_string_heap_error_when_no_strings_left(void)
|
||||
{
|
||||
string *ptr;
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -34,15 +34,15 @@ ErrorContext *test_string_heap_error_when_no_strings_left(void)
|
||||
CATCH(errctx, heap_next_string(&ptr));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
return 0;
|
||||
} FINISH(errctx, true);
|
||||
}
|
||||
FAIL_RETURN(errctx, ERR_OUTOFBOUNDS, "Expected ERR_NULLPOINTER when accessing beyond string heap bounds");
|
||||
FAIL_RETURN(errctx, AKERR_OUTOFBOUNDS, "Expected AKERR_NULLPOINTER when accessing beyond string heap bounds");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_string_heap_honors_refcount(void)
|
||||
akerr_ErrorContext *test_string_heap_honors_refcount(void)
|
||||
{
|
||||
string *firstptr = &HEAP_STRING[0];
|
||||
string *secondptr = &HEAP_STRING[1];
|
||||
@@ -53,7 +53,7 @@ ErrorContext *test_string_heap_honors_refcount(void)
|
||||
if ( testptr != firstptr ) {
|
||||
FAIL_RETURN(
|
||||
errctx,
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Expected testptr to equal (HEAP_STRING[0] = %p) but got %p",
|
||||
firstptr,
|
||||
testptr
|
||||
@@ -61,12 +61,12 @@ ErrorContext *test_string_heap_honors_refcount(void)
|
||||
}
|
||||
CATCH(errctx, string_initialize(testptr, NULL));
|
||||
if ( testptr->refcount == 0 ) {
|
||||
FAIL_RETURN(errctx, ERR_VALUE, "Expected string reference count to be nonzero but got 0");
|
||||
FAIL_RETURN(errctx, AKERR_VALUE, "Expected string reference count to be nonzero but got 0");
|
||||
}
|
||||
if ( testptr != firstptr ) {
|
||||
FAIL_RETURN(
|
||||
errctx,
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Expected testptr to equal (HEAP_STRING[1] = %p) but got %p",
|
||||
secondptr,
|
||||
testptr
|
||||
@@ -79,7 +79,7 @@ ErrorContext *test_string_heap_honors_refcount(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_strcpy_to_all_strings_no_segfault(void)
|
||||
akerr_ErrorContext *test_strcpy_to_all_strings_no_segfault(void)
|
||||
{
|
||||
char copybuf[MAX_STRING_LENGTH];
|
||||
string *ptr;
|
||||
@@ -96,22 +96,22 @@ ErrorContext *test_strcpy_to_all_strings_no_segfault(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_string_initialize(void)
|
||||
akerr_ErrorContext *test_string_initialize(void)
|
||||
{
|
||||
string *ptr;
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
CATCH(errctx, heap_next_string(&ptr));
|
||||
CATCH(errctx, string_initialize(ptr, NULL));
|
||||
FAIL_NONZERO_BREAK(errctx, ptr->data[0], ERR_VALUE, "Expected empty zero length string data");
|
||||
FAIL_NONZERO_BREAK(errctx, ptr->data[0], AKERR_VALUE, "Expected empty zero length string data");
|
||||
|
||||
CATCH(errctx, heap_release_string(ptr));
|
||||
CATCH(errctx, heap_next_string(&ptr));
|
||||
CATCH(errctx, string_initialize(ptr, "Test value"));
|
||||
FAIL_NONZERO_BREAK(errctx, strcmp((char *)&ptr->data, "Test value"), ERR_VALUE, "Expected 'Test value', got %s", (char *)&ptr->data);
|
||||
FAIL_NONZERO_BREAK(errctx, strcmp((char *)&ptr->data, "Test value"), AKERR_VALUE, "Expected 'Test value', got %s", (char *)&ptr->data);
|
||||
|
||||
CATCH(errctx, heap_release_string(NULL));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Failure to properly handle NULL pointer");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Failure to properly handle NULL pointer");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <sdl3game/game.h>
|
||||
#include <sdl3game/json_helpers.h>
|
||||
|
||||
ErrorContext *test_tilemap_get_json_tilemap_property(void)
|
||||
akerr_ErrorContext *test_tilemap_get_json_tilemap_property(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
json_t *jsondoc = NULL;
|
||||
@@ -29,7 +29,7 @@ ErrorContext *test_tilemap_get_json_tilemap_property(void)
|
||||
"assets/snippets/test_tilemap_get_json_tilemap_property.json"
|
||||
);
|
||||
jsondoc = json_load_file((char *)&tmpstr->data, 0, (json_error_t *)&jsonerr);
|
||||
FAIL_ZERO_BREAK(errctx, jsondoc, ERR_NULLPOINTER, "Failure loading json fixture: %s", (char *)jsonerr.text);
|
||||
FAIL_ZERO_BREAK(errctx, jsondoc, AKERR_NULLPOINTER, "Failure loading json fixture: %s", (char *)jsonerr.text);
|
||||
CATCH(
|
||||
errctx,
|
||||
get_json_properties_string(
|
||||
@@ -41,7 +41,7 @@ ErrorContext *test_tilemap_get_json_tilemap_property(void)
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
strcmp((char *)&tmpstr->data, "testcharacter"),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Incorrect value loaded from property `character` (`testcharacter` vs `%s`)",
|
||||
(char *)&tmpstr->data
|
||||
);
|
||||
@@ -56,7 +56,7 @@ ErrorContext *test_tilemap_get_json_tilemap_property(void)
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
(propnum != 6),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Incorrect value loaded from property `state` (6 vs %d)",
|
||||
propnum
|
||||
);
|
||||
@@ -72,7 +72,7 @@ ErrorContext *test_tilemap_get_json_tilemap_property(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_tilemap_compute_tileset_offsets(void)
|
||||
akerr_ErrorContext *test_tilemap_compute_tileset_offsets(void)
|
||||
{
|
||||
int comparison_values[8] = {
|
||||
0, // Tile 0 X
|
||||
@@ -116,7 +116,7 @@ ErrorContext *test_tilemap_compute_tileset_offsets(void)
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
(*comparison_ptrs[i] != comparison_values[i]),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Tile offset incorrectly calculated for index %d (%d vs %d)",
|
||||
i,
|
||||
*comparison_ptrs[i],
|
||||
@@ -129,7 +129,7 @@ ErrorContext *test_tilemap_compute_tileset_offsets(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_tilemap_load_layer_objects(void)
|
||||
akerr_ErrorContext *test_tilemap_load_layer_objects(void)
|
||||
{
|
||||
string *pathstr;
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -144,7 +144,7 @@ ErrorContext *test_tilemap_load_layer_objects(void)
|
||||
CATCH(errctx, heap_next_string(&pathstr));
|
||||
snprintf((char *)&pathstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/testmap.tmj");
|
||||
doc = json_load_file((char *)&pathstr->data, 0, &errdata);
|
||||
FAIL_ZERO_BREAK(errctx, doc, ERR_NULLPOINTER, "Failed to load testmap: %s", (char *)&errdata.text);
|
||||
FAIL_ZERO_BREAK(errctx, doc, AKERR_NULLPOINTER, "Failed to load testmap: %s", (char *)&errdata.text);
|
||||
CATCH(errctx, get_json_array_value(doc, "layers", &layers));
|
||||
CATCH(errctx, get_json_array_index_object(layers, 1, &objectlayer));
|
||||
CATCH(errctx, tilemap_load_layer_objects(&gamemap, objectlayer, 1));
|
||||
@@ -153,7 +153,7 @@ ErrorContext *test_tilemap_load_layer_objects(void)
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
testactor,
|
||||
ERR_NULLPOINTER,
|
||||
AKERR_NULLPOINTER,
|
||||
"Test Actor was not loaded from the test map"
|
||||
);
|
||||
if ( (testactor->basechar != SDL_GetPointerProperty(REGISTRY_CHARACTER, "testcharacter", NULL)) ||
|
||||
@@ -162,7 +162,7 @@ ErrorContext *test_tilemap_load_layer_objects(void)
|
||||
(testactor->visible != true) ||
|
||||
(testactor->x != 16) ||
|
||||
(testactor->y != 16) ) {
|
||||
FAIL_BREAK(errctx, ERR_VALUE, "Test actor was loaded with incorrect values (check gdb)");
|
||||
FAIL_BREAK(errctx, AKERR_VALUE, "Test actor was loaded with incorrect values (check gdb)");
|
||||
}
|
||||
} CLEANUP {
|
||||
if ( pathstr != NULL ) {
|
||||
@@ -176,7 +176,7 @@ ErrorContext *test_tilemap_load_layer_objects(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_tilemap_load_layer_tile(void)
|
||||
akerr_ErrorContext *test_tilemap_load_layer_tile(void)
|
||||
{
|
||||
string *pathstr;
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -192,7 +192,7 @@ ErrorContext *test_tilemap_load_layer_tile(void)
|
||||
CATCH(errctx, heap_next_string(&pathstr));
|
||||
snprintf((char *)&pathstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/testmap.tmj");
|
||||
doc = json_load_file((char *)&pathstr->data, 0, &errdata);
|
||||
FAIL_ZERO_BREAK(errctx, doc, ERR_NULLPOINTER, "Failed to load testmap: %s", (char *)&errdata.text);
|
||||
FAIL_ZERO_BREAK(errctx, doc, AKERR_NULLPOINTER, "Failed to load testmap: %s", (char *)&errdata.text);
|
||||
CATCH(errctx, get_json_array_value(doc, "layers", &layers));
|
||||
CATCH(errctx, get_json_array_index_object(layers, 0, &tilelayer));
|
||||
CATCH(errctx, get_json_array_value(tilelayer, "data", &tiledata));
|
||||
@@ -201,7 +201,7 @@ ErrorContext *test_tilemap_load_layer_tile(void)
|
||||
(gamemap.layers[0].data[1] != 2) ||
|
||||
(gamemap.layers[0].data[2] != 3) ||
|
||||
(gamemap.layers[0].data[3] != 4) ) {
|
||||
FAIL_BREAK(errctx, ERR_VALUE, "Test tilemap layer 0 tiles loaded with incorrect values (check gdb)");
|
||||
FAIL_BREAK(errctx, AKERR_VALUE, "Test tilemap layer 0 tiles loaded with incorrect values (check gdb)");
|
||||
}
|
||||
} CLEANUP {
|
||||
if ( pathstr != NULL ) {
|
||||
@@ -215,7 +215,7 @@ ErrorContext *test_tilemap_load_layer_tile(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_tilemap_load_layers(void)
|
||||
akerr_ErrorContext *test_tilemap_load_layers(void)
|
||||
{
|
||||
string *pathstr;
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -229,12 +229,12 @@ ErrorContext *test_tilemap_load_layers(void)
|
||||
CATCH(errctx, heap_next_string(&pathstr));
|
||||
snprintf((char *)&pathstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/testmap.tmj");
|
||||
doc = json_load_file((char *)&pathstr->data, 0, &errdata);
|
||||
FAIL_ZERO_BREAK(errctx, doc, ERR_NULLPOINTER, "Failed to load testmap: %s", (char *)&errdata.text);
|
||||
FAIL_ZERO_BREAK(errctx, doc, AKERR_NULLPOINTER, "Failed to load testmap: %s", (char *)&errdata.text);
|
||||
CATCH(errctx, tilemap_load_layers(&gamemap, doc));
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
(gamemap.numlayers != 3),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Map layer count incorrect"
|
||||
);
|
||||
for ( i = 0; i < gamemap.numlayers; i++ ) {
|
||||
@@ -243,7 +243,7 @@ ErrorContext *test_tilemap_load_layers(void)
|
||||
(gamemap.layers[i].id != (i + 1)) ||
|
||||
(gamemap.layers[i].x != 0) ||
|
||||
(gamemap.layers[i].y != 0) ) {
|
||||
FAIL(errctx, ERR_VALUE, "Map layer data loaded incorrectly (see gdb)");
|
||||
FAIL(errctx, AKERR_VALUE, "Map layer data loaded incorrectly (see gdb)");
|
||||
goto _test_tilemap_load_layers_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -251,18 +251,18 @@ ErrorContext *test_tilemap_load_layers(void)
|
||||
if ( (gamemap.layers[1].objects[0].actorptr != SDL_GetPointerProperty(REGISTRY_ACTOR, "testactor", NULL)) ||
|
||||
(gamemap.layers[1].objects[1].name[0] != '\0' ) ||
|
||||
(gamemap.layers[1].objects[1].id != 0) ) {
|
||||
FAIL_BREAK(errctx, ERR_VALUE, "Map layer 2 should have 1 loaded object (testactor) and nothing else (see gdb)");
|
||||
FAIL_BREAK(errctx, AKERR_VALUE, "Map layer 2 should have 1 loaded object (testactor) and nothing else (see gdb)");
|
||||
}
|
||||
// Layer 1 and 3 should have no objects
|
||||
for ( i = 0; i < TILEMAP_MAX_OBJECTS_PER_LAYER ; i++ ) {
|
||||
if ( gamemap.layers[0].objects[i].id != 0 ) {
|
||||
FAIL(errctx, ERR_VALUE, "Map layers 1 and 3 should have no objects loaded but found objects");
|
||||
FAIL(errctx, AKERR_VALUE, "Map layers 1 and 3 should have no objects loaded but found objects");
|
||||
goto _test_tilemap_load_layers_cleanup;
|
||||
}
|
||||
}
|
||||
for ( i = 0; i < TILEMAP_MAX_OBJECTS_PER_LAYER ; i++ ) {
|
||||
if ( gamemap.layers[2].objects[i].id != 0 ) {
|
||||
FAIL(errctx, ERR_VALUE, "Map layers 1 and 3 should have no objects loaded but found objects");
|
||||
FAIL(errctx, AKERR_VALUE, "Map layers 1 and 3 should have no objects loaded but found objects");
|
||||
goto _test_tilemap_load_layers_cleanup;
|
||||
}
|
||||
}
|
||||
@@ -276,7 +276,7 @@ ErrorContext *test_tilemap_load_layers(void)
|
||||
(gamemap.layers[2].data[2] != 0) ||
|
||||
(gamemap.layers[2].data[3] != 6)
|
||||
) {
|
||||
FAIL_BREAK(errctx, ERR_VALUE, "Map layers 1 and 3 should have tile data but it is incorrect");
|
||||
FAIL_BREAK(errctx, AKERR_VALUE, "Map layers 1 and 3 should have tile data but it is incorrect");
|
||||
}
|
||||
_test_tilemap_load_layers_cleanup:
|
||||
} CLEANUP {
|
||||
@@ -291,7 +291,7 @@ _test_tilemap_load_layers_cleanup:
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_tilemap_load_tilesets(void)
|
||||
akerr_ErrorContext *test_tilemap_load_tilesets(void)
|
||||
{
|
||||
string *pathstr = NULL;
|
||||
PREPARE_ERROR(errctx);
|
||||
@@ -305,9 +305,9 @@ ErrorContext *test_tilemap_load_tilesets(void)
|
||||
CATCH(errctx, heap_next_string(&pathstr));
|
||||
snprintf((char *)&pathstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/testmap.tmj");
|
||||
doc = json_load_file((char *)&pathstr->data, 0, &errdata);
|
||||
FAIL_ZERO_BREAK(errctx, doc, ERR_NULLPOINTER, "Failed to load testmap: %s", (char *)&errdata.text);
|
||||
FAIL_ZERO_BREAK(errctx, doc, AKERR_NULLPOINTER, "Failed to load testmap: %s", (char *)&errdata.text);
|
||||
CATCH(errctx, tilemap_load_tilesets(&gamemap, doc));
|
||||
FAIL_NONZERO_BREAK(errctx, (gamemap.numtilesets != 1), ERR_VALUE, "Incorrect number of tilesets loaded for map");
|
||||
FAIL_NONZERO_BREAK(errctx, (gamemap.numtilesets != 1), AKERR_VALUE, "Incorrect number of tilesets loaded for map");
|
||||
if ( (gamemap.tilesets[0].columns != 48 ) ||
|
||||
(gamemap.tilesets[0].firstgid != 1) ||
|
||||
(gamemap.tilesets[0].imageheight != 576) ||
|
||||
@@ -317,17 +317,17 @@ ErrorContext *test_tilemap_load_tilesets(void)
|
||||
(gamemap.tilesets[0].tilecount != 1728) ||
|
||||
(gamemap.tilesets[0].tileheight != 16) ||
|
||||
(gamemap.tilesets[0].tilewidth != 16) ) {
|
||||
FAIL_BREAK(errctx, ERR_VALUE, "Tileset loaded with incorrect values");
|
||||
FAIL_BREAK(errctx, AKERR_VALUE, "Tileset loaded with incorrect values");
|
||||
}
|
||||
FAIL_NONZERO_BREAK(
|
||||
errctx,
|
||||
strcmp((char *)&gamemap.tilesets[0].name, "World_A1"),
|
||||
ERR_VALUE,
|
||||
AKERR_VALUE,
|
||||
"Tileset loaded with incorrect name");
|
||||
|
||||
snprintf((char *)&pathstr->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), "assets/World_A1.png");
|
||||
image = IMG_LoadTexture(renderer, (char *)&pathstr->data);
|
||||
FAIL_ZERO_BREAK(errctx, image, ERR_SDL, "Failed to load comparison image");
|
||||
FAIL_ZERO_BREAK(errctx, image, AKERR_SDL, "Failed to load comparison image");
|
||||
|
||||
CATCH(
|
||||
errctx,
|
||||
@@ -350,7 +350,7 @@ ErrorContext *test_tilemap_load_tilesets(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_tilemap_load(void)
|
||||
akerr_ErrorContext *test_tilemap_load(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
@@ -364,7 +364,7 @@ ErrorContext *test_tilemap_load(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_tilemap_draw(void)
|
||||
akerr_ErrorContext *test_tilemap_draw(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
@@ -376,7 +376,7 @@ ErrorContext *test_tilemap_draw(void)
|
||||
}
|
||||
|
||||
|
||||
ErrorContext *test_tilemap_draw_tileset(void)
|
||||
akerr_ErrorContext *test_tilemap_draw_tileset(void)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
|
||||
@@ -395,11 +395,11 @@ int main(void)
|
||||
SDL_SetAppMetadata("SDL3-GameTest", "0.1", "net.aklabs.sdl3-gametest");
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO )) {
|
||||
FAIL_BREAK(errctx, ERR_SDL, "Couldn't initialize SDL: %s", SDL_GetError());
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Couldn't initialize SDL: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer("net/aklabs/libsdl3game/test_sprite", 768, 576, 0, &window, &renderer)) {
|
||||
FAIL_BREAK(errctx, ERR_SDL, "Couldn't create window/renderer: %s", SDL_GetError());
|
||||
FAIL_BREAK(errctx, AKERR_SDL, "Couldn't create window/renderer: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
CATCH(errctx, registry_init());
|
||||
|
||||
80
tests/util.c
80
tests/util.c
@@ -2,7 +2,7 @@
|
||||
#include <akerror.h>
|
||||
#include <sdl3game/util.h>
|
||||
|
||||
ErrorContext *test_rectangle_points_nullpointers(void)
|
||||
akerr_ErrorContext *test_rectangle_points_nullpointers(void)
|
||||
{
|
||||
RectanglePoints points;
|
||||
SDL_FRect testrect;
|
||||
@@ -10,28 +10,28 @@ ErrorContext *test_rectangle_points_nullpointers(void)
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, rectangle_points(NULL, NULL));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "rectangle_points fails to FAIL with all NULL pointers");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "rectangle_points fails to FAIL with all NULL pointers");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, rectangle_points(NULL, &testrect));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "rectangle_points fails to FAIL with NULL SDL_FRect pointer");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "rectangle_points fails to FAIL with NULL SDL_FRect pointer");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, rectangle_points(&points, NULL));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "rectangle_points fails to FAIL with NULL RectanglePoints pointer");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "rectangle_points fails to FAIL with NULL RectanglePoints pointer");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -44,7 +44,7 @@ ErrorContext *test_rectangle_points_nullpointers(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_rectangle_points_math(void)
|
||||
akerr_ErrorContext *test_rectangle_points_math(void)
|
||||
{
|
||||
RectanglePoints points;
|
||||
SDL_FRect testrect = {.x = 0, .y = 0, .w = 32, .h = 32};
|
||||
@@ -63,7 +63,7 @@ ErrorContext *test_rectangle_points_math(void)
|
||||
points.bottomright.y != 32 ) {
|
||||
FAIL_BREAK(
|
||||
errctx,
|
||||
ERR_BEHAVIOR,
|
||||
AKERR_BEHAVIOR,
|
||||
"rectangle_points incorrectly calculated points for {x=0, y=0, w=32, h=32} to {topleft={%d, %d}, topright={%d, %d}, bottomleft={%d, %d}, bottomright={%d, %d}}",
|
||||
points.topleft.x, points.topleft.y,
|
||||
points.topright.x, points.topright.y,
|
||||
@@ -77,7 +77,7 @@ ErrorContext *test_rectangle_points_math(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_collide_point_rectangle_nullpointers(void)
|
||||
akerr_ErrorContext *test_collide_point_rectangle_nullpointers(void)
|
||||
{
|
||||
point testpoint;
|
||||
RectanglePoints testrectpoints;
|
||||
@@ -87,37 +87,37 @@ ErrorContext *test_collide_point_rectangle_nullpointers(void)
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, collide_point_rectangle(&testpoint, &testrectpoints, NULL));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "collide_point_rectangle(*, *, NULL) failed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "collide_point_rectangle(*, *, NULL) failed");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, collide_point_rectangle(&testpoint, NULL, &testcollide));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "collide_point_rectangle(*, NULL, *) failed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "collide_point_rectangle(*, NULL, *) failed");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, collide_point_rectangle(NULL, &testrectpoints, &testcollide));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "collide_point_rectangle(NULL, *, *) failed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "collide_point_rectangle(NULL, *, *) failed");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, collide_point_rectangle(NULL, NULL, NULL));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "collide_point_rectangle(NULL, NULL, NULL) failed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "collide_point_rectangle(NULL, NULL, NULL) failed");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -130,7 +130,7 @@ ErrorContext *test_collide_point_rectangle_nullpointers(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_collide_point_rectangle_logic(void)
|
||||
akerr_ErrorContext *test_collide_point_rectangle_logic(void)
|
||||
{
|
||||
point testpoint = {.x = 16, .y = 16};
|
||||
SDL_FRect testrect = { .x = 0, .y = 0, .w = 32, .h = 32};
|
||||
@@ -142,14 +142,14 @@ ErrorContext *test_collide_point_rectangle_logic(void)
|
||||
CATCH(errctx, rectangle_points(&testrectpoints, &testrect));
|
||||
CATCH(errctx, collide_point_rectangle(&testpoint, &testrectpoints, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
testpoint.x = 48;
|
||||
testpoint.y = 48;
|
||||
CATCH(errctx, collide_point_rectangle(&testpoint, &testrectpoints, &testcollide));
|
||||
if ( testcollide == true ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Invalid collision reported");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Invalid collision reported");
|
||||
}
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
@@ -157,7 +157,7 @@ ErrorContext *test_collide_point_rectangle_logic(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_collide_rectangles_nullpointers(void)
|
||||
akerr_ErrorContext *test_collide_rectangles_nullpointers(void)
|
||||
{
|
||||
SDL_FRect testrect1;
|
||||
SDL_FRect testrect2;
|
||||
@@ -167,37 +167,37 @@ ErrorContext *test_collide_rectangles_nullpointers(void)
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, NULL));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "collide_rectangles(*, *, NULL) failed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "collide_rectangles(*, *, NULL) failed");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, collide_rectangles(&testrect1, NULL, &testcollide));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "collide_rectangles(*, NULL, *) failed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "collide_rectangles(*, NULL, *) failed");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, collide_rectangles(NULL, &testrect2, &testcollide));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "collide_rectangles(NULL, *, *) failed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "collide_rectangles(NULL, *, *) failed");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, collide_rectangles(NULL, NULL, NULL));
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "collide_rectangles(NULL, NULL, NULL) failed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "collide_rectangles(NULL, NULL, NULL) failed");
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} HANDLE(errctx, ERR_NULLPOINTER) {
|
||||
} HANDLE(errctx, AKERR_NULLPOINTER) {
|
||||
// noop
|
||||
} FINISH(errctx, true);
|
||||
|
||||
@@ -210,7 +210,7 @@ ErrorContext *test_collide_rectangles_nullpointers(void)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *test_collide_rectangles_logic(void)
|
||||
akerr_ErrorContext *test_collide_rectangles_logic(void)
|
||||
{
|
||||
SDL_FRect testrect1 = { .x = 0, .y = 0, .w = 32, .h = 32};
|
||||
SDL_FRect testrect2 = { .x = 30, .y = 30, .w = 40, .h = 40};
|
||||
@@ -222,14 +222,14 @@ ErrorContext *test_collide_rectangles_logic(void)
|
||||
// Collision overlapping on the top left
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
// Collision overlapping on the top right
|
||||
testrect1.x = 64;
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
// Collision overlapping on the bottom left
|
||||
@@ -237,7 +237,7 @@ ErrorContext *test_collide_rectangles_logic(void)
|
||||
testrect1.y = 32;
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
// Collision overlapping on the bottom right
|
||||
@@ -245,7 +245,7 @@ ErrorContext *test_collide_rectangles_logic(void)
|
||||
testrect1.y = 32;
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
// Collision overlapping the top edge
|
||||
@@ -255,7 +255,7 @@ ErrorContext *test_collide_rectangles_logic(void)
|
||||
testrect1.h = 32;
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
// Collision overlapping the left edge
|
||||
@@ -265,7 +265,7 @@ ErrorContext *test_collide_rectangles_logic(void)
|
||||
testrect1.h = 80;
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
// Collision overlapping the right edge
|
||||
@@ -275,7 +275,7 @@ ErrorContext *test_collide_rectangles_logic(void)
|
||||
testrect1.h = 80;
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
// Collision overlapping the bottom edge
|
||||
@@ -285,7 +285,7 @@ ErrorContext *test_collide_rectangles_logic(void)
|
||||
testrect1.h = 32;
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == false ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Valid collision missed");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Valid collision missed");
|
||||
}
|
||||
|
||||
// Not colliding
|
||||
@@ -295,7 +295,7 @@ ErrorContext *test_collide_rectangles_logic(void)
|
||||
testrect1.h = 16;
|
||||
CATCH(errctx, collide_rectangles(&testrect1, &testrect2, &testcollide));
|
||||
if ( testcollide == true ) {
|
||||
FAIL_BREAK(errctx, ERR_BEHAVIOR, "Invalid collision reported");
|
||||
FAIL_BREAK(errctx, AKERR_BEHAVIOR, "Invalid collision reported");
|
||||
}
|
||||
|
||||
} CLEANUP {
|
||||
|
||||
Reference in New Issue
Block a user