From f9b12b0d466df67ec6d35c8b2bf8c8345f829a29 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Thu, 24 Jan 2013 07:58:59 -0800 Subject: [PATCH] Add mouse tests; update test suites --- test/testautomation_audio.c | 17 ++-- test/testautomation_clipboard.c | 6 +- test/testautomation_mouse.c | 134 ++++++++++++++++++++++++++++++-- test/testautomation_render.c | 23 ++++-- test/testautomation_surface.c | 80 +++++++++---------- 5 files changed, 192 insertions(+), 68 deletions(-) diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c index 3fbdf2b2f..2a7065f4c 100644 --- a/test/testautomation_audio.c +++ b/test/testautomation_audio.c @@ -3,9 +3,6 @@ * New/updated tests: aschiffler at ferzkopp dot net */ -/* quiet windows compiler warnings */ -#define _CRT_SECURE_NO_WARNINGS - #include #include @@ -311,29 +308,29 @@ int audio_buildAudioCVTNegative() SDLTest_AssertPass("Call to SDL_ClearError()"); /* Set various invalid format inputs */ - strcpy(message, "Invalid: "); + SDL_strlcpy(message, "Invalid: ", 256); if (i & 1) { - strcat(message, " spec1.format"); + SDL_strlcat(message, " spec1.format", 256); spec1.format = 0; } if (i & 2) { - strcat(message, " spec1.channels"); + SDL_strlcat(message, " spec1.channels", 256); spec1.channels = 0; } if (i & 4) { - strcat(message, " spec1.freq"); + SDL_strlcat(message, " spec1.freq", 256); spec1.freq = 0; } if (i & 8) { - strcat(message, " spec2.format"); + SDL_strlcat(message, " spec2.format", 256); spec2.format = 0; } if (i & 16) { - strcat(message, " spec2.channels"); + SDL_strlcat(message, " spec2.channels", 256); spec2.channels = 0; } if (i & 32) { - strcat(message, " spec2.freq"); + SDL_strlcat(message, " spec2.freq", 256); spec2.freq = 0; } SDLTest_Log(message); diff --git a/test/testautomation_clipboard.c b/test/testautomation_clipboard.c index 2dc9dbdee..858b22bc8 100644 --- a/test/testautomation_clipboard.c +++ b/test/testautomation_clipboard.c @@ -118,9 +118,9 @@ clipboard_testClipboardTextFunctions(void *arg) charResult != NULL, "Verify SDL_GetClipboardText did not return NULL"); SDLTest_AssertCheck( - strlen(charResult) == 0, + SDL_strlen(charResult) == 0, "Verify SDL_GetClipboardText returned string with length 0, got length %i", - strlen(charResult)); + SDL_strlen(charResult)); intResult = SDL_SetClipboardText((const char *)text); SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded"); SDLTest_AssertCheck( @@ -128,7 +128,7 @@ clipboard_testClipboardTextFunctions(void *arg) "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i", intResult); SDLTest_AssertCheck( - strcmp(textRef, text) == 0, + SDL_strcmp(textRef, text) == 0, "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'", textRef, text); boolResult = SDL_HasClipboardText(); diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index 35896fe5d..f236f7095 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -16,11 +16,11 @@ int _mouseStateCheck(Uint8 state) { return (state == 0) || - SDL_BUTTON(SDL_BUTTON_LEFT) || - SDL_BUTTON(SDL_BUTTON_MIDDLE) || - SDL_BUTTON(SDL_BUTTON_RIGHT) || - SDL_BUTTON(SDL_BUTTON_X1) || - SDL_BUTTON(SDL_BUTTON_X2); + (state == SDL_BUTTON(SDL_BUTTON_LEFT)) || + (state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) || + (state == SDL_BUTTON(SDL_BUTTON_RIGHT)) || + (state == SDL_BUTTON(SDL_BUTTON_X1)) || + (state == SDL_BUTTON(SDL_BUTTON_X2)); } /** @@ -215,6 +215,42 @@ mouse_createFreeCursor(void *arg) return TEST_COMPLETED; } +/** + * @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor + * + * @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateColorCursor + * @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor + */ +int +mouse_createFreeColorCursor(void *arg) +{ + SDL_Surface *face; + SDL_Cursor *cursor; + + /* Get sample surface */ + face = SDLTest_ImageFace(); + SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL"); + if (face == NULL) return TEST_ABORTED; + + /* Create a color cursor from surface */ + cursor = SDL_CreateColorCursor(face, 0, 0); + SDLTest_AssertPass("Call to SDL_CreateColorCursor()"); + SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL"); + if (cursor == NULL) { + SDL_FreeSurface(face); + return TEST_ABORTED; + } + + /* Free cursor again */ + SDL_FreeCursor(cursor); + SDLTest_AssertPass("Call to SDL_FreeCursor()"); + + /* Clean up */ + SDL_FreeSurface(face); + + return TEST_COMPLETED; +} + /* Helper that changes cursor visibility */ void _changeCursorVisibility(int state) { @@ -299,6 +335,80 @@ mouse_setCursor(void *arg) return TEST_COMPLETED; } +/** + * @brief Check call to SDL_GetCursor + * + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetCursor + */ +int +mouse_getCursor(void *arg) +{ + SDL_Cursor *cursor; + + /* Get current cursor */ + cursor = SDL_GetCursor(); + SDLTest_AssertPass("Call to SDL_GetCursor()"); + SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL"); + + return TEST_COMPLETED; +} + +/** + * @brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode + * + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetRelativeMouseMode + * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetRelativeMouseMode + */ +int +mouse_getSetRelativeMouseMode(void *arg) +{ + int result; + int i; + SDL_bool initialState; + SDL_bool currentState; + + /* Capture original state so we can revert back to it later */ + initialState = SDL_GetRelativeMouseMode(); + SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); + + /* Repeat twice to check D->D transition */ + for (i=0; i<2; i++) { + /* Disable - should always be supported */ + result = SDL_SetRelativeMouseMode(SDL_FALSE); + SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)"); + SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); + currentState = SDL_GetRelativeMouseMode(); + SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); + SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState); + } + + /* Repeat twice to check D->E->E transition */ + for (i=0; i<2; i++) { + /* Enable - may not be supported */ + result = SDL_SetRelativeMouseMode(SDL_TRUE); + SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)"); + if (result != -1) { + SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); + currentState = SDL_GetRelativeMouseMode(); + SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); + SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState); + } + } + + /* Disable to check E->D transition */ + result = SDL_SetRelativeMouseMode(SDL_FALSE); + SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)"); + SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result); + currentState = SDL_GetRelativeMouseMode(); + SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()"); + SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState); + + /* Revert to originl state - ignore result */ + result = SDL_SetRelativeMouseMode(initialState); + + return TEST_COMPLETED; +} + #define MOUSE_TESTWINDOW_WIDTH 320 #define MOUSE_TESTWINDOW_HEIGHT 200 @@ -455,14 +565,24 @@ static const SDLTest_TestCaseReference mouseTest5 = { (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED }; static const SDLTest_TestCaseReference mouseTest6 = - { (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED }; + { (SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED }; static const SDLTest_TestCaseReference mouseTest7 = + { (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED }; + +static const SDLTest_TestCaseReference mouseTest8 = { (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED }; +static const SDLTest_TestCaseReference mouseTest9 = + { (SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED }; + +static const SDLTest_TestCaseReference mouseTest10 = + { (SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED }; + /* Sequence of Mouse test cases */ static const SDLTest_TestCaseReference *mouseTests[] = { - &mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6, &mouseTest7, NULL + &mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6, + &mouseTest7, &mouseTest8, &mouseTest9, &mouseTest10, NULL }; /* Mouse test suite (global) */ diff --git a/test/testautomation_render.c b/test/testautomation_render.c index eb129202b..e33cd064c 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -969,30 +969,37 @@ _hasTexAlpha(void) static void _compare(SDL_Surface *referenceSurface, int allowable_error) { - int ret; + int result; SDL_Rect rect; - Uint8 pix[4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H]; + Uint8 *pixels; SDL_Surface *testSurface; /* Read pixels. */ + pixels = (Uint8 *)SDL_malloc(4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H); + SDLTest_AssertCheck(pixels != NULL, "Validate allocated temp pixel buffer"); + if (pixels == NULL) return; + /* Explicitly specify the rect in case the window isn't the expected size... */ rect.x = 0; rect.y = 0; rect.w = TESTRENDER_SCREEN_W; rect.h = TESTRENDER_SCREEN_H; - ret = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pix, 80*4 ); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", ret); + result = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pixels, 80*4 ); + SDLTest_AssertCheck(result == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", result); /* Create surface. */ - testSurface = SDL_CreateRGBSurfaceFrom( pix, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4, + testSurface = SDL_CreateRGBSurfaceFrom(pixels, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4, RENDER_COMPARE_RMASK, RENDER_COMPARE_GMASK, RENDER_COMPARE_BMASK, RENDER_COMPARE_AMASK); - SDLTest_AssertCheck(testSurface != NULL, "Verify result from SDL_CreateRGBSurfaceFrom"); + SDLTest_AssertCheck(testSurface != NULL, "Verify result from SDL_CreateRGBSurfaceFrom is not NULL"); /* Compare surface. */ - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, allowable_error ); - SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); + result = SDLTest_CompareSurfaces( testSurface, referenceSurface, allowable_error ); + SDLTest_AssertCheck(result == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", result); /* Clean up. */ + if (pixels != NULL) { + SDL_free(pixels); + } if (testSurface != NULL) { SDL_FreeSurface(testSurface); } diff --git a/test/testautomation_surface.c b/test/testautomation_surface.c index 6979d9288..a049f6fbe 100644 --- a/test/testautomation_surface.c +++ b/test/testautomation_surface.c @@ -326,19 +326,19 @@ int surface_testBlit(void *arg) { int ret; - SDL_Surface *referenceSurface; + SDL_Surface *compareSurface; /* Basic blitting */ _testBlitBlendMode(-1); /* Verify result by comparing surfaces */ - referenceSurface = SDLTest_ImageBlit(); - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 ); + compareSurface = SDLTest_ImageBlit(); + ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); /* Clean up. */ - if (referenceSurface != NULL) { - SDL_FreeSurface( referenceSurface ); + if (compareSurface != NULL) { + SDL_FreeSurface( compareSurface ); } return TEST_COMPLETED; @@ -351,19 +351,19 @@ int surface_testBlitColorMod(void *arg) { int ret; - SDL_Surface *referenceSurface; + SDL_Surface *compareSurface; /* Basic blitting with color mod */ _testBlitBlendMode(-2); /* Verify result by comparing surfaces */ - referenceSurface = SDLTest_ImageBlitColor(); - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 ); + compareSurface = SDLTest_ImageBlitColor(); + ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); /* Clean up. */ - if (referenceSurface != NULL) { - SDL_FreeSurface( referenceSurface ); + if (compareSurface != NULL) { + SDL_FreeSurface( compareSurface ); } return TEST_COMPLETED; @@ -376,19 +376,19 @@ int surface_testBlitAlphaMod(void *arg) { int ret; - SDL_Surface *referenceSurface; + SDL_Surface *compareSurface; /* Basic blitting with alpha mod */ _testBlitBlendMode(-3); /* Verify result by comparing surfaces */ - referenceSurface = SDLTest_ImageBlitAlpha(); - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 ); + compareSurface = SDLTest_ImageBlitAlpha(); + ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); /* Clean up. */ - if (referenceSurface != NULL) { - SDL_FreeSurface( referenceSurface ); + if (compareSurface != NULL) { + SDL_FreeSurface( compareSurface ); } return TEST_COMPLETED; @@ -402,19 +402,19 @@ int surface_testBlitBlendNone(void *arg) { int ret; - SDL_Surface *referenceSurface; + SDL_Surface *compareSurface; /* Basic blitting */ _testBlitBlendMode(SDL_BLENDMODE_NONE); /* Verify result by comparing surfaces */ - referenceSurface = SDLTest_ImageBlitBlendNone(); - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 ); + compareSurface = SDLTest_ImageBlitBlendNone(); + ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); /* Clean up. */ - if (referenceSurface != NULL) { - SDL_FreeSurface( referenceSurface ); + if (compareSurface != NULL) { + SDL_FreeSurface( compareSurface ); } return TEST_COMPLETED; @@ -427,19 +427,19 @@ int surface_testBlitBlendBlend(void *arg) { int ret; - SDL_Surface *referenceSurface; + SDL_Surface *compareSurface; /* Blend blitting */ _testBlitBlendMode(SDL_BLENDMODE_BLEND); /* Verify result by comparing surfaces */ - referenceSurface = SDLTest_ImageBlitBlend(); - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 ); + compareSurface = SDLTest_ImageBlitBlend(); + ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); /* Clean up. */ - if (referenceSurface != NULL) { - SDL_FreeSurface( referenceSurface ); + if (compareSurface != NULL) { + SDL_FreeSurface( compareSurface ); } return TEST_COMPLETED; @@ -452,19 +452,19 @@ int surface_testBlitBlendAdd(void *arg) { int ret; - SDL_Surface *referenceSurface; + SDL_Surface *compareSurface; /* Add blitting */ _testBlitBlendMode(SDL_BLENDMODE_ADD); /* Verify result by comparing surfaces */ - referenceSurface = SDLTest_ImageBlitBlendAdd(); - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 ); + compareSurface = SDLTest_ImageBlitBlendAdd(); + ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); /* Clean up. */ - if (referenceSurface != NULL) { - SDL_FreeSurface( referenceSurface ); + if (compareSurface != NULL) { + SDL_FreeSurface( compareSurface ); } return TEST_COMPLETED; @@ -477,19 +477,19 @@ int surface_testBlitBlendMod(void *arg) { int ret; - SDL_Surface *referenceSurface; + SDL_Surface *compareSurface; /* Mod blitting */ _testBlitBlendMode(SDL_BLENDMODE_MOD); /* Verify result by comparing surfaces */ - referenceSurface = SDLTest_ImageBlitBlendMod(); - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 ); + compareSurface = SDLTest_ImageBlitBlendMod(); + ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); /* Clean up. */ - if (referenceSurface != NULL) { - SDL_FreeSurface( referenceSurface ); + if (compareSurface != NULL) { + SDL_FreeSurface( compareSurface ); } return TEST_COMPLETED; @@ -502,19 +502,19 @@ int surface_testBlitBlendLoop(void *arg) { int ret; - SDL_Surface *referenceSurface; + SDL_Surface *compareSurface; /* All blitting modes */ _testBlitBlendMode(-4); /* Verify result by comparing surfaces */ - referenceSurface = SDLTest_ImageBlitBlendAll(); - ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 ); + compareSurface = SDLTest_ImageBlitBlendAll(); + ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); /* Clean up. */ - if (referenceSurface != NULL) { - SDL_FreeSurface( referenceSurface ); + if (compareSurface != NULL) { + SDL_FreeSurface(compareSurface); } return TEST_COMPLETED;