From a846570698de4e98b2427c299d088ce00420394d Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Wed, 23 Jan 2013 08:03:19 -0800 Subject: [PATCH] Add tests to mouse suite; fix VS compiler warnings in tests --- test/testautomation_audio.c | 3 + test/testautomation_mouse.c | 307 ++++++++++++++++++++++++++---------- test/testautomation_rwops.c | 2 +- 3 files changed, 229 insertions(+), 83 deletions(-) diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c index 0160d2317..3fbdf2b2f 100644 --- a/test/testautomation_audio.c +++ b/test/testautomation_audio.c @@ -3,6 +3,9 @@ * New/updated tests: aschiffler at ferzkopp dot net */ +/* quiet windows compiler warnings */ +#define _CRT_SECURE_NO_WARNINGS + #include #include diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index dc9f2cd3b..35896fe5d 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -115,79 +115,79 @@ mouse_getRelativeMouseState(void *arg) return TEST_COMPLETED; } - -/* XPM definition of mouse Cursor */ -static const char *_mouseArrowData[] = { - /* pixels */ - "X ", - "XX ", - "X.X ", - "X..X ", - "X...X ", - "X....X ", - "X.....X ", - "X......X ", - "X.......X ", - "X........X ", - "X.....XXXXX ", - "X..X..X ", - "X.X X..X ", - "XX X..X ", - "X X..X ", - " X..X ", - " X..X ", - " X..X ", - " XX ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " " -}; - -/* Helper that creates a new mouse cursor from an XPM */ -static SDL_Cursor *_initArrowCursor(const char *image[]) -{ - SDL_Cursor *cursor; - int i, row, col; - Uint8 data[4*32]; - Uint8 mask[4*32]; - - i = -1; - for ( row=0; row<32; ++row ) { - for ( col=0; col<32; ++col ) { - if ( col % 8 ) { - data[i] <<= 1; - mask[i] <<= 1; - } else { - ++i; - data[i] = mask[i] = 0; - } - switch (image[row][col]) { - case 'X': - data[i] |= 0x01; - mask[i] |= 0x01; - break; - case '.': - mask[i] |= 0x01; - break; - case ' ': - break; - } - } - } - - cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0); - return cursor; -} + +/* XPM definition of mouse Cursor */ +static const char *_mouseArrowData[] = { + /* pixels */ + "X ", + "XX ", + "X.X ", + "X..X ", + "X...X ", + "X....X ", + "X.....X ", + "X......X ", + "X.......X ", + "X........X ", + "X.....XXXXX ", + "X..X..X ", + "X.X X..X ", + "XX X..X ", + "X X..X ", + " X..X ", + " X..X ", + " X..X ", + " XX ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " " +}; + +/* Helper that creates a new mouse cursor from an XPM */ +static SDL_Cursor *_initArrowCursor(const char *image[]) +{ + SDL_Cursor *cursor; + int i, row, col; + Uint8 data[4*32]; + Uint8 mask[4*32]; + + i = -1; + for ( row=0; row<32; ++row ) { + for ( col=0; col<32; ++col ) { + if ( col % 8 ) { + data[i] <<= 1; + mask[i] <<= 1; + } else { + ++i; + data[i] = mask[i] = 0; + } + switch (image[row][col]) { + case 'X': + data[i] |= 0x01; + mask[i] |= 0x01; + break; + case '.': + mask[i] |= 0x01; + break; + case ' ': + break; + } + } + } + + cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0); + return cursor; +} /** * @brief Check call to SDL_CreateCursor and SDL_FreeCursor @@ -202,8 +202,8 @@ mouse_createFreeCursor(void *arg) /* Create a cursor */ cursor = _initArrowCursor(_mouseArrowData); - SDLTest_AssertPass("Call to SDL_CreateCursor()"); - SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL"); + SDLTest_AssertPass("Call to SDL_CreateCursor()"); + SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL"); if (cursor == NULL) { return TEST_ABORTED; } @@ -222,10 +222,10 @@ void _changeCursorVisibility(int state) int newState; int result; - oldState = SDL_ShowCursor(SDL_QUERY); + oldState = SDL_ShowCursor(SDL_QUERY); SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)"); - result = SDL_ShowCursor(state); + result = SDL_ShowCursor(state); SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE"); SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result); @@ -278,18 +278,18 @@ mouse_setCursor(void *arg) /* Create a cursor */ cursor = _initArrowCursor(_mouseArrowData); - SDLTest_AssertPass("Call to SDL_CreateCursor()"); - SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL"); + SDLTest_AssertPass("Call to SDL_CreateCursor()"); + SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL"); if (cursor == NULL) { return TEST_ABORTED; } /* Set the arrow cursor */ - SDL_SetCursor(cursor); + SDL_SetCursor(cursor); SDLTest_AssertPass("Call to SDL_SetCursor(cursor)"); /* Force redraw */ - SDL_SetCursor(NULL); + SDL_SetCursor(NULL); SDLTest_AssertPass("Call to SDL_SetCursor(NULL)"); /* Free cursor again */ @@ -299,6 +299,143 @@ mouse_setCursor(void *arg) return TEST_COMPLETED; } +#define MOUSE_TESTWINDOW_WIDTH 320 +#define MOUSE_TESTWINDOW_HEIGHT 200 + +/** + * Create s test window + */ +SDL_Window *_createTestWindow() +{ + int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT; + SDL_Window *window; + window = SDL_CreateWindow("mouse_createTestWindow", posX, posY, width, height, 0); + SDLTest_AssertPass("SDL_CreateWindow()"); + SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); + return window; +} + +/* + * Destroy test window + */ +void _destroyTestWindow(SDL_Window *window) +{ + if (window != NULL) { + SDL_DestroyWindow(window); + window = NULL; + SDLTest_AssertPass("SDL_DestroyWindow"); + } +} + +/** + * @brief Check call to SDL_WarpMouseInWindow + * + * @sa http://wiki.libsdl.org/moin.cgi/SDL_WarpMouseInWindow + */ +int +mouse_warpMouseInWindow(void *arg) +{ + const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT; + int numPositions = 6; + int xPositions[] = {-1, 0, 1, w-1, w, w+1 }; + int yPositions[] = {-1, 0, 1, h-1, h, h+1 }; + int x, y, i, j; + SDL_Window *window; + + /* Create test window */ + window = _createTestWindow(); + if (window == NULL) return TEST_ABORTED; + + /* Mouse to random position inside window */ + x = SDLTest_RandomIntegerInRange(1, w-1); + y = SDLTest_RandomIntegerInRange(1, h-1); + SDL_WarpMouseInWindow(window, x, y); + SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); + + /* Same position again */ + SDL_WarpMouseInWindow(window, x, y); + SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); + + /* Mouse to various boundary positions */ + for (i=0; i