mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-16 17:58:27 +00:00
Added SDL_FlipSurface() to flip a surface vertically or horizontally
Fixes https://github.com/libsdl-org/SDL/issues/8857
This commit is contained in:
parent
2cd583ee13
commit
308906ba25
13 changed files with 184 additions and 21 deletions
|
@ -22,6 +22,15 @@
|
|||
#include "testautomation_suites.h"
|
||||
#include "testautomation_images.h"
|
||||
|
||||
|
||||
#define CHECK_FUNC(FUNC, PARAMS) \
|
||||
{ \
|
||||
int result = FUNC PARAMS; \
|
||||
if (result != 0) { \
|
||||
SDLTest_AssertCheck(result == 0, "Validate result from %s, expected: 0, got: %i, %s", #FUNC, result, SDL_GetError()); \
|
||||
} \
|
||||
}
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Shared test surface */
|
||||
|
@ -791,6 +800,54 @@ static int surface_testOverflow(void *arg)
|
|||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
static int surface_testFlip(void *arg)
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
Uint8 *pixels;
|
||||
int offset;
|
||||
const char *expectedError;
|
||||
|
||||
surface = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGB24);
|
||||
SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
|
||||
|
||||
SDL_ClearError();
|
||||
expectedError = "Parameter 'surface' is invalid";
|
||||
SDL_FlipSurface(NULL, SDL_FLIP_HORIZONTAL);
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
SDL_ClearError();
|
||||
expectedError = "Parameter 'flip' is invalid";
|
||||
SDL_FlipSurface(surface, SDL_FLIP_NONE);
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
pixels = (Uint8 *)surface->pixels;
|
||||
*pixels = 0xFF;
|
||||
offset = 0;
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_VERTICAL)");
|
||||
CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_VERTICAL));
|
||||
SDLTest_AssertCheck(pixels[offset] == 0x00,
|
||||
"Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
|
||||
offset = 2 * surface->pitch;
|
||||
SDLTest_AssertCheck(pixels[offset] == 0xFF,
|
||||
"Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_HORIZONTAL)");
|
||||
CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_HORIZONTAL));
|
||||
SDLTest_AssertCheck(pixels[offset] == 0x00,
|
||||
"Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
|
||||
offset += (surface->w - 1) * surface->format->BytesPerPixel;
|
||||
SDLTest_AssertCheck(pixels[offset] == 0xFF,
|
||||
"Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
|
||||
|
||||
SDL_DestroySurface(surface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Surface test cases */
|
||||
|
@ -849,11 +906,15 @@ static const SDLTest_TestCaseReference surfaceTestOverflow = {
|
|||
surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTestFlip = {
|
||||
surface_testFlip, "surface_testFlip", "Test surface flipping.", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Surface test cases */
|
||||
static const SDLTest_TestCaseReference *surfaceTests[] = {
|
||||
&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
|
||||
&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
|
||||
&surfaceTest11, &surfaceTest12, &surfaceTestOverflow, NULL
|
||||
&surfaceTest11, &surfaceTest12, &surfaceTestOverflow, &surfaceTestFlip, NULL
|
||||
};
|
||||
|
||||
/* Surface test suite (global) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue