Got the suite rebuilding, most tests pass, actor and sprite are failing
This commit is contained in:
46
src/util.c
46
src/util.c
@@ -10,11 +10,11 @@
|
||||
#include <sdl3game/registry.h>
|
||||
#include <sdl3game/game.h>
|
||||
|
||||
ErrorContext *rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
akerr_ErrorContext *rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, dest, ERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
FAIL_ZERO_RETURN(errctx, rect, ERR_NULLPOINTER, "NULL Rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, dest, AKERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
FAIL_ZERO_RETURN(errctx, rect, AKERR_NULLPOINTER, "NULL Rectangle reference");
|
||||
dest->topleft.x = rect->x;
|
||||
dest->topleft.y = rect->y;
|
||||
dest->bottomleft.x = rect->x;
|
||||
@@ -26,12 +26,12 @@ ErrorContext *rectangle_points(RectanglePoints *dest, SDL_FRect *rect)
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *collide_point_rectangle(point *p, RectanglePoints *rp, bool *collide)
|
||||
akerr_ErrorContext *collide_point_rectangle(point *p, RectanglePoints *rp, bool *collide)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, p, ERR_NULLPOINTER, "NULL Point reference");
|
||||
FAIL_ZERO_RETURN(errctx, rp, ERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
FAIL_ZERO_RETURN(errctx, collide, ERR_NULLPOINTER, "NULL boolean reference");
|
||||
FAIL_ZERO_RETURN(errctx, p, AKERR_NULLPOINTER, "NULL Point reference");
|
||||
FAIL_ZERO_RETURN(errctx, rp, AKERR_NULLPOINTER, "NULL RectanglePoints reference");
|
||||
FAIL_ZERO_RETURN(errctx, collide, AKERR_NULLPOINTER, "NULL boolean reference");
|
||||
if ( (p->x >= rp->topleft.x) && (p->y >= rp->topleft.y) &&
|
||||
(p->x <= rp->bottomright.x) && (p->y <= rp->bottomright.y) ) {
|
||||
*collide = true;
|
||||
@@ -41,14 +41,14 @@ ErrorContext *collide_point_rectangle(point *p, RectanglePoints *rp, bool *colli
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide)
|
||||
akerr_ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide)
|
||||
{
|
||||
RectanglePoints r1p;
|
||||
RectanglePoints r2p;
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, r1, ERR_NULLPOINTER, "NULL rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, r2, ERR_NULLPOINTER, "NULL rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, collide, ERR_NULLPOINTER, "NULL collision flag reference");
|
||||
FAIL_ZERO_RETURN(errctx, r1, AKERR_NULLPOINTER, "NULL rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, r2, AKERR_NULLPOINTER, "NULL rectangle reference");
|
||||
FAIL_ZERO_RETURN(errctx, collide, AKERR_NULLPOINTER, "NULL collision flag reference");
|
||||
|
||||
ATTEMPT {
|
||||
CATCH(errctx, rectangle_points(&r1p, r1));
|
||||
@@ -95,16 +95,16 @@ ErrorContext *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide)
|
||||
}
|
||||
|
||||
|
||||
ErrorContext *compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2)
|
||||
akerr_ErrorContext *compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2)
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
FAIL_ZERO_RETURN(errctx, s1, ERR_NULLPOINTER, "NULL Surface pointer");
|
||||
FAIL_ZERO_RETURN(errctx, s2, ERR_NULLPOINTER, "NULL Surface pointer");
|
||||
FAIL_NONZERO_RETURN(errctx, memcmp(s1->pixels, s2->pixels, (s1->pitch * s1->h)), ERR_VALUE, "Comparison surfaces are not equal");
|
||||
FAIL_ZERO_RETURN(errctx, s1, AKERR_NULLPOINTER, "NULL Surface pointer");
|
||||
FAIL_ZERO_RETURN(errctx, s2, AKERR_NULLPOINTER, "NULL Surface pointer");
|
||||
FAIL_NONZERO_RETURN(errctx, memcmp(s1->pixels, s2->pixels, (s1->pitch * s1->h)), AKERR_VALUE, "Comparison surfaces are not equal");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout)
|
||||
akerr_ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout)
|
||||
{
|
||||
SDL_Surface *s1 = NULL;
|
||||
SDL_Surface *s2 = NULL;
|
||||
@@ -115,8 +115,8 @@ ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y,
|
||||
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
FAIL_ZERO_BREAK(errctx, t1, ERR_NULLPOINTER, "NULL texture");
|
||||
FAIL_ZERO_BREAK(errctx, t2, ERR_NULLPOINTER, "NULL texture");
|
||||
FAIL_ZERO_BREAK(errctx, t1, AKERR_NULLPOINTER, "NULL texture");
|
||||
FAIL_ZERO_BREAK(errctx, t2, AKERR_NULLPOINTER, "NULL texture");
|
||||
|
||||
CATCH(errctx, heap_next_string(&tmpstring));
|
||||
SDL_RenderClear(renderer);
|
||||
@@ -127,17 +127,17 @@ ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y,
|
||||
t1,
|
||||
&src,
|
||||
&dest),
|
||||
ERR_SDL,
|
||||
AKERR_SDL,
|
||||
"Failed to render test texture");
|
||||
s1 = SDL_RenderReadPixels(renderer, &read);
|
||||
FAIL_ZERO_BREAK(errctx, s1, ERR_SDL, "Failed to read pixels from renderer");
|
||||
FAIL_ZERO_BREAK(errctx, s1, AKERR_SDL, "Failed to read pixels from renderer");
|
||||
|
||||
if ( writeout != NULL ) {
|
||||
snprintf((char *)&tmpstring->data, MAX_STRING_LENGTH, "%s%s", SDL_GetBasePath(), writeout);
|
||||
FAIL_ZERO_BREAK(
|
||||
errctx,
|
||||
IMG_SavePNG(s1, (char *)&tmpstring->data),
|
||||
ERR_IO,
|
||||
AKERR_IO,
|
||||
"Unable to save %s: %s",
|
||||
(char *)&tmpstring->data,
|
||||
SDL_GetError());
|
||||
@@ -152,10 +152,10 @@ ErrorContext *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y,
|
||||
t2,
|
||||
&src,
|
||||
&dest),
|
||||
ERR_SDL,
|
||||
AKERR_SDL,
|
||||
"Failed to render test texture");
|
||||
s2 = SDL_RenderReadPixels(renderer, &read);
|
||||
FAIL_ZERO_BREAK(errctx, s2, ERR_SDL, "Failed to read pixels from renderer");
|
||||
FAIL_ZERO_BREAK(errctx, s2, AKERR_SDL, "Failed to read pixels from renderer");
|
||||
|
||||
CATCH(errctx, compare_sdl_surfaces(s1, s2));
|
||||
} CLEANUP {
|
||||
|
||||
Reference in New Issue
Block a user