Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes based on CR.
  • Loading branch information
mkauppila committed Jul 11, 2011
1 parent 7639a65 commit 92c9dd3
Showing 1 changed file with 61 additions and 29 deletions.
90 changes: 61 additions & 29 deletions test/test-automation/testsurface/testsurface.c
Expand Up @@ -8,10 +8,6 @@

#include "../SDL_test.h"

#include "../common/common.h"
#include "../common/images.h"


/* Test case references */
static const TestCaseReference test1 =
(TestCaseReference){ "surface_testLoad", "Tests sprite loading.", TEST_ENABLED, 0, 0};
Expand All @@ -22,29 +18,45 @@ static const TestCaseReference test2 =
static const TestCaseReference test3 =
(TestCaseReference){ "surface_testBlitBlend", "Tests some more blitting routines.", TEST_ENABLED, 0, 0};

static const TestCaseReference test4 =
(TestCaseReference){ "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED, 0, 0};


/* Test suite */
extern const TestCaseReference *testSuite[] = {
&test1, &test2, &test3, NULL
&test1, &test2, &test3, &test4, NULL
};


TestCaseReference **QueryTestSuite() {
return (TestCaseReference **)testSuite;
}

/* Test helpers */
/* Helper functions for the test cases */

#define TEST_SURFACE_WIDTH 80
#define TEST_SURFACE_HEIGHT 60

/*!
* Creates test surface
*/
SDL_Surface *
CreateTestSurface() {
SDL_Surface *testsur;
_CreateTestSurface()
{
SDL_Surface *testsur = NULL;

/* Create the test surface. */
testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
RMASK, GMASK, BMASK, AMASK );
testsur = SDL_CreateRGBSurface( 0,
TEST_SURFACE_WIDTH, TEST_SURFACE_HEIGHT, 32,
RMASK, GMASK, BMASK, AMASK );

if(testsur->w != TEST_SURFACE_WIDTH) {
AssertFail("Test surface width doesn't match");
}

if(testsur->h != TEST_SURFACE_HEIGHT) {
AssertFail("Test surface height doesn't match");
}

AssertTrue(testsur != NULL, "SDL_CreateRGBSurface");

Expand All @@ -54,17 +66,19 @@ CreateTestSurface() {
/**
* @brief Tests a blend mode.
*/
int testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
int _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
{
int ret;
int i, j, ni, nj;
SDL_Rect rect;

AssertTrue(testsur != NULL, "testsur != NULL");
AssertTrue(face != NULL, "face != NULL");

/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
SDL_MapRGB( testsur->format, 0, 0, 0 ) );
if(ret == 0)
return 1;
AssertTrue(ret != 0, "SDL_FillRect");

/* Steps to take. */
ni = testsur->w - face->w;
Expand All @@ -79,16 +93,14 @@ int testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
for (i=0; i <= ni; i+=4) {
/* Set blend mode. */
ret = SDL_SetSurfaceBlendMode( face, mode );
if (ret == 0)
return 1;
AssertTrue(ret != 0, "SDL_SetSurfaceBlendMode");

/* Blitting. */
rect.x = i;
rect.y = j;
// TODO Add pixel level validation, SDL_BlitSurface might be no-op
ret = SDL_BlitSurface( face, NULL, testsur, &rect );
if(ret == 0)
return 1;
}
AssertTrue(ret != 0, "SDL_BlitSurface"); }
}

return 0;
Expand All @@ -106,7 +118,7 @@ void surface_testLoad(void *arg)
ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");

SDL_Surface *testsur = CreateTestSurface();
SDL_Surface *testsur = _CreateTestSurface();

/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
Expand Down Expand Up @@ -146,6 +158,22 @@ void surface_testLoad(void *arg)
}


/**
* @brief Tests sprite loading. A failure case.
*/
void surface_testLoadFailure(void *arg)
{
int ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");

SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");

AssertTrue(face == NULL, "SDL_CreateLoadBmp");

SDL_Quit();
}


/**
* @brief Tests some blitting routines.
*/
Expand All @@ -159,7 +187,7 @@ void surface_testBlit(void *arg)
ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");

SDL_Surface *testsur = CreateTestSurface();
SDL_Surface *testsur = _CreateTestSurface();

/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
Expand Down Expand Up @@ -196,6 +224,7 @@ void surface_testBlit(void *arg)
/* Blitting. */
rect.x = i;
rect.y = j;
// TODO Add pixel level validation, SDL_BlitSurface might be no-op
ret = SDL_BlitSurface( face, NULL, testsur, &rect );

AssertTrue(ret == 0, "SDL_BlitSurface");
Expand All @@ -221,6 +250,7 @@ void surface_testBlit(void *arg)
/* Blitting. */
rect.x = i;
rect.y = j;
// TODO Add pixel level validation, SDL_BlitSurface might be no-op
ret = SDL_BlitSurface( face, NULL, testsur, &rect );

AssertTrue(ret == 0, "SDL_BlitSurface");
Expand Down Expand Up @@ -250,6 +280,7 @@ void surface_testBlit(void *arg)
/* Blitting. */
rect.x = i;
rect.y = j;
// TODO Add pixel level validation, SDL_BlitSurface might be no-op
ret = SDL_BlitSurface( face, NULL, testsur, &rect );
AssertTrue(ret == 0, "SDL_BlitSurface");
}
Expand Down Expand Up @@ -280,7 +311,7 @@ void surface_testBlitBlend(void *arg)
ret = SDL_Init(SDL_INIT_VIDEO);
AssertTrue(ret == 0, "SDL_Init(SDL_INIT_VIDEO)");

SDL_Surface *testsur = CreateTestSurface();
SDL_Surface *testsur = _CreateTestSurface();

/* Clear surface. */
ret = SDL_FillRect( testsur, NULL,
Expand All @@ -306,38 +337,39 @@ void surface_testBlitBlend(void *arg)
AssertTrue(face != NULL, "SDL_CreateRGBSurfaceFrom");

/* Set alpha mod. */
// TODO alpha value could be generated by fuzzer
ret = SDL_SetSurfaceAlphaMod( face, 100 );
AssertTrue(ret == 0, "SDL_SetSurfaceAlphaMod");

/* Steps to take. */
ni = testsur->w - face->w;
nj = testsur->h - face->h;

AssertTrue(ni != 0, "ni != 0");
AssertTrue(nj != 0, "nj != 0");

/* Constant values. */
rect.w = face->w;
rect.h = face->h;

/* Test None. */
if (testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE ))
return;
_testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE );

AssertTrue(surface_compare( testsur, &img_blendNone, 0 ) == 0,
"Comparing blitting blending output (using SDL_BLENDMODE_NONE).");

/* Test Blend. */
if (testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND ))
return;
_testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND );
AssertTrue(surface_compare( testsur, &img_blendBlend, 0 ) == 0,
"Comparing blitting blending output (using SDL_BLENDMODE_BLEND).");

/* Test Add. */
if (testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD ))
return;
_testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD );
AssertTrue(surface_compare( testsur, &img_blendAdd, 0 ) == 0,
"Comparing blitting blending output (using SDL_BLENDMODE_ADD).");

/* Test Mod. */
if (testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD ))
return;
_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD );
AssertTrue(surface_compare( testsur, &img_blendMod, 0 ) == 0,
"Comparing blitting blending output not the same (using SDL_BLENDMODE_MOD).");

Expand Down

0 comments on commit 92c9dd3

Please sign in to comment.