Got the suite rebuilding, most tests pass, actor and sprite are failing
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user