Add new internal error message for invalid parameters; add validation of input rect in SDL_SetTextInputRect; add test cases for SDL_SetTextInputRect to keyboard suite
This commit is contained in:
parent
054a17097d
commit
a20096403e
6 changed files with 156 additions and 1 deletions
|
@ -52,6 +52,7 @@ extern DECLSPEC void SDLCALL SDL_ClearError(void);
|
|||
/*@{*/
|
||||
#define SDL_OutOfMemory() SDL_Error(SDL_ENOMEM)
|
||||
#define SDL_Unsupported() SDL_Error(SDL_UNSUPPORTED)
|
||||
#define SDL_InvalidParamError() SDL_Error(SDL_INVALIDPARAM)
|
||||
typedef enum
|
||||
{
|
||||
SDL_ENOMEM,
|
||||
|
@ -59,6 +60,7 @@ typedef enum
|
|||
SDL_EFWRITE,
|
||||
SDL_EFSEEK,
|
||||
SDL_UNSUPPORTED,
|
||||
SDL_INVALIDPARAM,
|
||||
SDL_LASTERROR
|
||||
} SDL_errorcode;
|
||||
extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code);
|
||||
|
|
|
@ -235,6 +235,9 @@ SDL_Error(SDL_errorcode code)
|
|||
case SDL_UNSUPPORTED:
|
||||
SDL_SetError("That operation is not supported");
|
||||
break;
|
||||
case SDL_INVALIDPARAM:
|
||||
SDL_SetError("Parameter is invalid");
|
||||
break;
|
||||
default:
|
||||
SDL_SetError("Unknown SDL error");
|
||||
break;
|
||||
|
|
|
@ -316,6 +316,12 @@ void
|
|||
Android_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||
|
||||
if (!rect) {
|
||||
SDL_InvalidParamError();
|
||||
return;
|
||||
}
|
||||
|
||||
videodata->textRect = *rect;
|
||||
}
|
||||
|
||||
|
|
|
@ -668,6 +668,11 @@ Cocoa_SetTextInputRect(_THIS, SDL_Rect *rect)
|
|||
{
|
||||
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
|
||||
|
||||
if (!rect) {
|
||||
SDL_InvalidParamError();
|
||||
return;
|
||||
}
|
||||
|
||||
[data->fieldEdit setInputRect: rect];
|
||||
}
|
||||
|
||||
|
|
|
@ -212,6 +212,12 @@ void
|
|||
WIN_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
|
||||
|
||||
if (!rect) {
|
||||
SDL_InvalidParamError();
|
||||
return;
|
||||
}
|
||||
|
||||
videodata->ime_rect = *rect;
|
||||
}
|
||||
|
||||
|
|
|
@ -279,6 +279,132 @@ keyboard_startStopTextInput(void *arg)
|
|||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* Internal function to test SDL_SetTextInputRect */
|
||||
void _testSetTextInputRect(SDL_Rect refRect)
|
||||
{
|
||||
SDL_Rect testRect;
|
||||
|
||||
testRect = refRect;
|
||||
SDL_SetTextInputRect(&testRect);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%i,y:%i,w:%i,h:%i)", refRect.x, refRect.y, refRect.w, refRect.h);
|
||||
SDLTest_AssertCheck(
|
||||
(refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h),
|
||||
"Check that input data was not modified, expected: x:%i,y:%i,w:%i,h:%i, got: x:%i,y:%i,w:%i,h:%i",
|
||||
refRect.x, refRect.y, refRect.w, refRect.h,
|
||||
testRect.x, testRect.y, testRect.w, testRect.h);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_SetTextInputRect
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
|
||||
*/
|
||||
int
|
||||
keyboard_setTextInputRect(void *arg)
|
||||
{
|
||||
SDL_Rect refRect;
|
||||
|
||||
/* Normal visible refRect, origin inside */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
|
||||
refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
|
||||
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
|
||||
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* Normal visible refRect, origin 0,0 */
|
||||
refRect.x = 0;
|
||||
refRect.y = 0;
|
||||
refRect.w = SDLTest_RandomIntegerInRange(10, 50);
|
||||
refRect.h = SDLTest_RandomIntegerInRange(10, 50);
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 1Pixel refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(10, 50);;
|
||||
refRect.y = SDLTest_RandomIntegerInRange(10, 50);;
|
||||
refRect.w = 1;
|
||||
refRect.h = 1;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 1;
|
||||
refRect.h = 0;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 0;
|
||||
refRect.h = 1;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 1;
|
||||
refRect.y = 1;
|
||||
refRect.w = 0;
|
||||
refRect.h = 0;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* 0pixel refRect */
|
||||
refRect.x = 0;
|
||||
refRect.y = 0;
|
||||
refRect.w = 0;
|
||||
refRect.h = 0;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* negative refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(-200, -100);;
|
||||
refRect.y = SDLTest_RandomIntegerInRange(-200, -100);;
|
||||
refRect.w = 50;
|
||||
refRect.h = 50;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* oversized refRect */
|
||||
refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
|
||||
refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
|
||||
refRect.w = 5000;
|
||||
refRect.h = 5000;
|
||||
_testSetTextInputRect(refRect);
|
||||
|
||||
/* NULL refRect */
|
||||
SDL_SetTextInputRect(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_SetTextInputRect with invalid data
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
|
||||
*/
|
||||
int
|
||||
keyboard_setTextInputRectNegative(void *arg)
|
||||
{
|
||||
const char *expectedError = "Parameter is invalid";
|
||||
const char *error;
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
|
||||
/* NULL refRect */
|
||||
SDL_SetTextInputRect(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
|
||||
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 ================== */
|
||||
|
@ -305,9 +431,16 @@ static const SDLTest_TestCaseReference keyboardTest6 =
|
|||
static const SDLTest_TestCaseReference keyboardTest7 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest8 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference keyboardTest9 =
|
||||
{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
|
||||
|
||||
/* Sequence of Keyboard test cases */
|
||||
static const SDLTest_TestCaseReference *keyboardTests[] = {
|
||||
&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, &keyboardTest7, NULL
|
||||
&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6,
|
||||
&keyboardTest7, &keyboardTest8, &keyboardTest9, NULL
|
||||
};
|
||||
|
||||
/* Keyboard test suite (global) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue