Update SDL_InvalidParamError to take param name; add additional fuzzer function; add new tests to keyboard test suite; improve surface test suite
This commit is contained in:
parent
c1e8384624
commit
b4a190fb6f
10 changed files with 272 additions and 54 deletions
|
@ -52,7 +52,7 @@ extern DECLSPEC void SDLCALL SDL_ClearError(void);
|
||||||
/*@{*/
|
/*@{*/
|
||||||
#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
|
#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
|
||||||
#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
|
#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
|
||||||
#define SDL_InvalidParamError() SDL_Error(SDL_INVALIDPARAM)
|
#define SDL_InvalidParamError(param) SDL_SetError("Parameter '%s' is invalid", (param))
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
SDL_ENOMEM,
|
SDL_ENOMEM,
|
||||||
|
@ -60,7 +60,6 @@ typedef enum
|
||||||
SDL_EFWRITE,
|
SDL_EFWRITE,
|
||||||
SDL_EFSEEK,
|
SDL_EFSEEK,
|
||||||
SDL_UNSUPPORTED,
|
SDL_UNSUPPORTED,
|
||||||
SDL_INVALIDPARAM,
|
|
||||||
SDL_LASTERROR
|
SDL_LASTERROR
|
||||||
} SDL_errorcode;
|
} SDL_errorcode;
|
||||||
extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code);
|
extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code);
|
||||||
|
|
|
@ -329,30 +329,44 @@ Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates random null-terminated string. The maximum length for
|
* Generates random null-terminated string. The minimum length for
|
||||||
* the string is 255 characters and it can contain ASCII characters
|
* the string is 1 character, maximum length for the string is 255
|
||||||
* from 1 to 127.
|
* characters and it can contain ASCII characters from 32 to 126.
|
||||||
*
|
*
|
||||||
* Note: Returned string needs to be deallocated.
|
* Note: Returned string needs to be deallocated.
|
||||||
*
|
*
|
||||||
* \returns newly allocated random string
|
* \returns Newly allocated random string; or NULL if length was invalid or string could not be allocated.
|
||||||
*/
|
*/
|
||||||
char * SDLTest_RandomAsciiString();
|
char * SDLTest_RandomAsciiString();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates random null-terminated string. The maximum length for
|
* Generates random null-terminated string. The maximum length for
|
||||||
* the string is defined by maxLenght parameter.
|
* the string is defined by the maxLength parameter.
|
||||||
* String can contain ASCII characters from 1 to 127.
|
* String can contain ASCII characters from 32 to 126.
|
||||||
*
|
*
|
||||||
* Note: Returned string needs to be deallocated.
|
* Note: Returned string needs to be deallocated.
|
||||||
*
|
*
|
||||||
* \param maxLength Maximum length of the generated string
|
* \param maxLength The maximum length of the generated string.
|
||||||
*
|
*
|
||||||
* \returns newly allocated random string
|
* \returns Newly allocated random string; or NULL if maxLength was invalid or string could not be allocated.
|
||||||
*/
|
*/
|
||||||
char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
|
char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates random null-terminated string. The length for
|
||||||
|
* the string is defined by the size parameter.
|
||||||
|
* String can contain ASCII characters from 32 to 126.
|
||||||
|
*
|
||||||
|
* Note: Returned string needs to be deallocated.
|
||||||
|
*
|
||||||
|
* \param size The length of the generated string
|
||||||
|
*
|
||||||
|
* \returns Newly allocated random string; or NULL if size was invalid or string could not be allocated.
|
||||||
|
*/
|
||||||
|
char * SDLTest_RandomAsciiStringOfSize(int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the invocation count for the fuzzer since last ...FuzzerInit.
|
* Returns the invocation count for the fuzzer since last ...FuzzerInit.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -235,9 +235,6 @@ SDL_Error(SDL_errorcode code)
|
||||||
case SDL_UNSUPPORTED:
|
case SDL_UNSUPPORTED:
|
||||||
SDL_SetError("That operation is not supported");
|
SDL_SetError("That operation is not supported");
|
||||||
break;
|
break;
|
||||||
case SDL_INVALIDPARAM:
|
|
||||||
SDL_SetError("Parameter is invalid");
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
SDL_SetError("Unknown SDL error");
|
SDL_SetError("Unknown SDL error");
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -895,6 +895,7 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!name || !*name) {
|
if (!name || !*name) {
|
||||||
|
SDL_InvalidParamError("name");
|
||||||
return SDL_SCANCODE_UNKNOWN;
|
return SDL_SCANCODE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -906,6 +907,8 @@ SDL_Scancode SDL_GetScancodeFromName(const char *name)
|
||||||
return (SDL_Scancode)i;
|
return (SDL_Scancode)i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_InvalidParamError("name");
|
||||||
return SDL_SCANCODE_UNKNOWN;
|
return SDL_SCANCODE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -614,25 +614,37 @@ SDLTest_RandomDouble()
|
||||||
char *
|
char *
|
||||||
SDLTest_RandomAsciiString()
|
SDLTest_RandomAsciiString()
|
||||||
{
|
{
|
||||||
// note: fuzzerInvocationCounter is increment in the RandomAsciiStringWithMaximumLenght
|
|
||||||
return SDLTest_RandomAsciiStringWithMaximumLength(255);
|
return SDLTest_RandomAsciiStringWithMaximumLength(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
SDLTest_RandomAsciiStringWithMaximumLength(int maxSize)
|
SDLTest_RandomAsciiStringWithMaximumLength(int maxLength)
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
char *string;
|
|
||||||
int counter;
|
|
||||||
|
|
||||||
fuzzerInvocationCounter++;
|
if(maxLength < 1) {
|
||||||
|
SDL_InvalidParamError("maxLength");
|
||||||
if(maxSize < 1) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = (SDLTest_RandomUint32() % (maxSize + 1)) + 1;
|
size = (SDLTest_RandomUint32() % (maxLength + 1));
|
||||||
string = (char *)SDL_malloc(size * sizeof(char));
|
|
||||||
|
return SDLTest_RandomAsciiStringOfSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
SDLTest_RandomAsciiStringOfSize(int size)
|
||||||
|
{
|
||||||
|
char *string;
|
||||||
|
int counter;
|
||||||
|
|
||||||
|
|
||||||
|
if(size < 1) {
|
||||||
|
SDL_InvalidParamError("size");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
string = (char *)SDL_malloc((size + 1) * sizeof(char));
|
||||||
if (string==NULL) {
|
if (string==NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -643,5 +655,7 @@ SDLTest_RandomAsciiStringWithMaximumLength(int maxSize)
|
||||||
|
|
||||||
string[counter] = '\0';
|
string[counter] = '\0';
|
||||||
|
|
||||||
|
fuzzerInvocationCounter++;
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,7 +318,7 @@ Android_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||||
|
|
||||||
if (!rect) {
|
if (!rect) {
|
||||||
SDL_InvalidParamError();
|
SDL_InvalidParamError("rect");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -669,7 +669,7 @@ Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||||
|
|
||||||
if (!rect) {
|
if (!rect) {
|
||||||
SDL_InvalidParamError();
|
SDL_InvalidParamError("rect");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -214,7 +214,7 @@ WIN_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||||
|
|
||||||
if (!rect) {
|
if (!rect) {
|
||||||
SDL_InvalidParamError();
|
SDL_InvalidParamError("rect");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -382,7 +382,7 @@ keyboard_setTextInputRect(void *arg)
|
||||||
int
|
int
|
||||||
keyboard_setTextInputRectNegative(void *arg)
|
keyboard_setTextInputRectNegative(void *arg)
|
||||||
{
|
{
|
||||||
const char *expectedError = "Parameter is invalid";
|
const char *expectedError = "Parameter 'rect' is invalid";
|
||||||
const char *error;
|
const char *error;
|
||||||
|
|
||||||
SDL_ClearError();
|
SDL_ClearError();
|
||||||
|
@ -405,6 +405,157 @@ keyboard_setTextInputRectNegative(void *arg)
|
||||||
return TEST_COMPLETED;
|
return TEST_COMPLETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check call to SDL_GetScancodeFromKey
|
||||||
|
*
|
||||||
|
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
|
||||||
|
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
keyboard_getScancodeFromKey(void *arg)
|
||||||
|
{
|
||||||
|
SDL_Scancode scancode;
|
||||||
|
|
||||||
|
/* Regular key */
|
||||||
|
scancode = SDL_GetScancodeFromKey(SDLK_4);
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
|
||||||
|
|
||||||
|
/* Virtual key */
|
||||||
|
scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
|
||||||
|
SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode);
|
||||||
|
|
||||||
|
return TEST_COMPLETED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check call to SDL_GetScancodeFromName
|
||||||
|
*
|
||||||
|
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
|
||||||
|
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
keyboard_getScancodeFromName(void *arg)
|
||||||
|
{
|
||||||
|
SDL_Scancode scancode;
|
||||||
|
|
||||||
|
/* Regular key, 1 character, first name in list */
|
||||||
|
scancode = SDL_GetScancodeFromName("A");
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode);
|
||||||
|
|
||||||
|
/* Regular key, 1 character */
|
||||||
|
scancode = SDL_GetScancodeFromName("4");
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode);
|
||||||
|
|
||||||
|
/* Regular key, 2 characters */
|
||||||
|
scancode = SDL_GetScancodeFromName("F1");
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode);
|
||||||
|
|
||||||
|
/* Regular key, 3 characters */
|
||||||
|
scancode = SDL_GetScancodeFromName("End");
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode);
|
||||||
|
|
||||||
|
/* Regular key, 4 characters */
|
||||||
|
scancode = SDL_GetScancodeFromName("Find");
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode);
|
||||||
|
|
||||||
|
/* Regular key, several characters */
|
||||||
|
scancode = SDL_GetScancodeFromName("Backspace");
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode);
|
||||||
|
|
||||||
|
/* Regular key, several characters with space */
|
||||||
|
scancode = SDL_GetScancodeFromName("Keypad Enter");
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode);
|
||||||
|
|
||||||
|
/* Regular key, last name in list */
|
||||||
|
scancode = SDL_GetScancodeFromName("Sleep");
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode);
|
||||||
|
|
||||||
|
return TEST_COMPLETED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check call to SDL_GetScancodeFromName with invalid data
|
||||||
|
*
|
||||||
|
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
|
||||||
|
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
keyboard_getScancodeFromNameNegative(void *arg)
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
SDL_Scancode scancode;
|
||||||
|
const char *expectedError = "Parameter 'name' is invalid";
|
||||||
|
const char *error;
|
||||||
|
|
||||||
|
SDL_ClearError();
|
||||||
|
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||||
|
|
||||||
|
/* Random string input */
|
||||||
|
name = SDLTest_RandomAsciiStringOfSize(32);
|
||||||
|
SDLTest_Assert(name != NULL, "Check that random name is not NULL");
|
||||||
|
if (name == NULL) {
|
||||||
|
return TEST_ABORTED;
|
||||||
|
}
|
||||||
|
scancode = SDL_GetScancodeFromName((const char *)name);
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
|
||||||
|
SDL_free(name);
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
|
||||||
|
error = SDL_GetError();
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||||
|
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||||
|
if (error != NULL) {
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||||
|
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_ClearError();
|
||||||
|
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||||
|
|
||||||
|
/* Zero length string input */
|
||||||
|
name = "";
|
||||||
|
scancode = SDL_GetScancodeFromName((const char *)name);
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
|
||||||
|
error = SDL_GetError();
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||||
|
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||||
|
if (error != NULL) {
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||||
|
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_ClearError();
|
||||||
|
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||||
|
|
||||||
|
/* NULL input */
|
||||||
|
name = NULL;
|
||||||
|
scancode = SDL_GetScancodeFromName((const char *)name);
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
|
||||||
|
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
|
||||||
|
error = SDL_GetError();
|
||||||
|
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||||
|
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||||
|
if (error != NULL) {
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||||
|
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_ClearError();
|
||||||
|
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||||
|
|
||||||
|
return TEST_COMPLETED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ================= Test References ================== */
|
/* ================= Test References ================== */
|
||||||
|
@ -437,10 +588,19 @@ static const SDLTest_TestCaseReference keyboardTest8 =
|
||||||
static const SDLTest_TestCaseReference keyboardTest9 =
|
static const SDLTest_TestCaseReference keyboardTest9 =
|
||||||
{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
|
{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
|
||||||
|
|
||||||
|
static const SDLTest_TestCaseReference keyboardTest10 =
|
||||||
|
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED };
|
||||||
|
|
||||||
|
static const SDLTest_TestCaseReference keyboardTest11 =
|
||||||
|
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED };
|
||||||
|
|
||||||
|
static const SDLTest_TestCaseReference keyboardTest12 =
|
||||||
|
{ (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED };
|
||||||
|
|
||||||
/* Sequence of Keyboard test cases */
|
/* Sequence of Keyboard test cases */
|
||||||
static const SDLTest_TestCaseReference *keyboardTests[] = {
|
static const SDLTest_TestCaseReference *keyboardTests[] = {
|
||||||
&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6,
|
&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6,
|
||||||
&keyboardTest7, &keyboardTest8, &keyboardTest9, NULL
|
&keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12, NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Keyboard test suite (global) */
|
/* Keyboard test suite (global) */
|
||||||
|
|
|
@ -27,10 +27,13 @@ static SDL_Surface *testSurface = NULL;
|
||||||
|
|
||||||
/* Fixture */
|
/* Fixture */
|
||||||
|
|
||||||
/* Create a 32-bit writable surface for screen tests */
|
/* Create a 32-bit writable surface for blitting tests */
|
||||||
void
|
void
|
||||||
_surfaceSetUp(void *arg)
|
_surfaceSetUp(void *arg)
|
||||||
{
|
{
|
||||||
|
int result;
|
||||||
|
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||||
|
SDL_BlendMode currentBlendMode;
|
||||||
Uint32 rmask, gmask, bmask, amask;
|
Uint32 rmask, gmask, bmask, amask;
|
||||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||||
rmask = 0xff000000;
|
rmask = 0xff000000;
|
||||||
|
@ -47,6 +50,14 @@ _surfaceSetUp(void *arg)
|
||||||
referenceSurface = SDLTest_ImageBlit(); /* For size info */
|
referenceSurface = SDLTest_ImageBlit(); /* For size info */
|
||||||
testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
|
testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
|
||||||
SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
|
SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
|
||||||
|
if (testSurface != NULL) {
|
||||||
|
/* Disable blend mode for target surface */
|
||||||
|
result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
|
||||||
|
SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
|
||||||
|
result = SDL_GetSurfaceBlendMode(testSurface, ¤tBlendMode);
|
||||||
|
SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
|
||||||
|
SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -71,8 +82,8 @@ void _clearTestSurface()
|
||||||
Uint32 color;
|
Uint32 color;
|
||||||
|
|
||||||
/* Clear surface. */
|
/* Clear surface. */
|
||||||
color = SDL_MapRGB( testSurface->format, 0, 0, 0);
|
color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
|
||||||
SDLTest_AssertPass("Call to SDL_MapRGB()");
|
SDLTest_AssertPass("Call to SDL_MapRGBA()");
|
||||||
ret = SDL_FillRect( testSurface, NULL, color);
|
ret = SDL_FillRect( testSurface, NULL, color);
|
||||||
SDLTest_AssertPass("Call to SDL_FillRect()");
|
SDLTest_AssertPass("Call to SDL_FillRect()");
|
||||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
|
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
|
||||||
|
@ -103,6 +114,21 @@ void _testBlitBlendMode(int mode)
|
||||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||||
if (face == NULL) return;
|
if (face == NULL) return;
|
||||||
|
|
||||||
|
/* Reset alpha modulation */
|
||||||
|
ret = SDL_SetSurfaceAlphaMod(face, 255);
|
||||||
|
SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
|
||||||
|
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
|
||||||
|
|
||||||
|
/* Reset color modulation */
|
||||||
|
ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
|
||||||
|
SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
|
||||||
|
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
|
||||||
|
|
||||||
|
/* Reset color key */
|
||||||
|
ret = SDL_SetColorKey(face, SDL_FALSE, 0);
|
||||||
|
SDLTest_AssertPass("Call to SDL_SetColorKey()");
|
||||||
|
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
|
||||||
|
|
||||||
/* Clear the test surface */
|
/* Clear the test surface */
|
||||||
_clearTestSurface();
|
_clearTestSurface();
|
||||||
|
|
||||||
|
@ -141,10 +167,15 @@ void _testBlitBlendMode(int mode)
|
||||||
else if (mode == -4) {
|
else if (mode == -4) {
|
||||||
/* Crazy blending mode magic. */
|
/* Crazy blending mode magic. */
|
||||||
nmode = (i/4*j/4) % 4;
|
nmode = (i/4*j/4) % 4;
|
||||||
if (nmode==0) bmode = SDL_BLENDMODE_NONE;
|
if (nmode==0) {
|
||||||
else if (nmode==1) bmode = SDL_BLENDMODE_BLEND;
|
bmode = SDL_BLENDMODE_NONE;
|
||||||
else if (nmode==2) bmode = SDL_BLENDMODE_ADD;
|
} else if (nmode==1) {
|
||||||
else if (nmode==3) bmode = SDL_BLENDMODE_MOD;
|
bmode = SDL_BLENDMODE_BLEND;
|
||||||
|
} else if (nmode==2) {
|
||||||
|
bmode = SDL_BLENDMODE_ADD;
|
||||||
|
} else if (nmode==3) {
|
||||||
|
bmode = SDL_BLENDMODE_MOD;
|
||||||
|
}
|
||||||
ret = SDL_SetSurfaceBlendMode( face, bmode );
|
ret = SDL_SetSurfaceBlendMode( face, bmode );
|
||||||
if (ret != 0) checkFailCount4++;
|
if (ret != 0) checkFailCount4++;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +504,7 @@ surface_testBlitBlendLoop(void *arg) {
|
||||||
int ret;
|
int ret;
|
||||||
SDL_Surface *referenceSurface;
|
SDL_Surface *referenceSurface;
|
||||||
|
|
||||||
/* All blitting */
|
/* All blitting modes */
|
||||||
_testBlitBlendMode(-4);
|
_testBlitBlendMode(-4);
|
||||||
|
|
||||||
/* Verify result by comparing surfaces */
|
/* Verify result by comparing surfaces */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue