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