From 0dac8a03c6ff3e1e322449fe4bc70c721a7820ac Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Mon, 25 Feb 2013 08:05:26 -0800 Subject: [PATCH] Add tests to video suite --- test/testautomation_mouse.c | 18 +-- test/testautomation_video.c | 276 ++++++++++++++++++++++++++++++++---- 2 files changed, 258 insertions(+), 36 deletions(-) diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index f236f7095..69d82dd09 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -413,13 +413,13 @@ mouse_getSetRelativeMouseMode(void *arg) #define MOUSE_TESTWINDOW_HEIGHT 200 /** - * Create s test window + * Creates a test window */ -SDL_Window *_createTestWindow() +SDL_Window *_createMouseSuiteTestWindow() { 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); + window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0); SDLTest_AssertPass("SDL_CreateWindow()"); SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); return window; @@ -428,12 +428,12 @@ SDL_Window *_createTestWindow() /* * Destroy test window */ -void _destroyTestWindow(SDL_Window *window) +void _destroyMouseSuiteTestWindow(SDL_Window *window) { if (window != NULL) { SDL_DestroyWindow(window); window = NULL; - SDLTest_AssertPass("SDL_DestroyWindow"); + SDLTest_AssertPass("SDL_DestroyWindow()"); } } @@ -453,7 +453,7 @@ mouse_warpMouseInWindow(void *arg) SDL_Window *window; /* Create test window */ - window = _createTestWindow(); + window = _createMouseSuiteTestWindow(); if (window == NULL) return TEST_ABORTED; /* Mouse to random position inside window */ @@ -482,7 +482,7 @@ mouse_warpMouseInWindow(void *arg) /* Clean up test window */ - _destroyTestWindow(window); + _destroyMouseSuiteTestWindow(window); return TEST_COMPLETED; } @@ -505,7 +505,7 @@ mouse_getMouseFocus(void *arg) SDLTest_AssertPass("SDL_GetMouseFocus()"); /* Create test window */ - window = _createTestWindow(); + window = _createMouseSuiteTestWindow(); if (window == NULL) return TEST_ABORTED; /* Mouse to random position inside window */ @@ -531,7 +531,7 @@ mouse_getMouseFocus(void *arg) SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y); /* Clean up test window */ - _destroyTestWindow(window); + _destroyMouseSuiteTestWindow(window); /* Pump events to update focus state */ SDL_PumpEvents(); diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 49c7f4c9f..d9ec69f16 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -7,6 +7,43 @@ #include "SDL.h" #include "SDL_test.h" +/* Private helpers */ + +/* + * Create a test window + */ +SDL_Window *_createVideoSuiteTestWindow(const char *title) +{ + SDL_Window* window; + int x, y, w, h; + SDL_WindowFlags flags; + + /* Standard window */ + x = SDLTest_RandomIntegerInRange(1, 100); + y = SDLTest_RandomIntegerInRange(1, 100); + w = SDLTest_RandomIntegerInRange(320, 1024); + h = SDLTest_RandomIntegerInRange(320, 768); + flags = SDL_WINDOW_SHOWN; + + window = SDL_CreateWindow(title, x, y, w, h, flags); + SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); + SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); + + return window; +} + +/* + * Destroy test window + */ +void _destroyVideoSuiteTestWindow(SDL_Window *window) +{ + if (window != NULL) { + SDL_DestroyWindow(window); + window = NULL; + SDLTest_AssertPass("Call to SDL_DestroyWindow"); + } +} + /* Test case functions */ /** @@ -133,10 +170,9 @@ video_createWindowVariousPositions(void *arg) window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } } @@ -191,10 +227,9 @@ video_createWindowVariousSizes(void *arg) window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } } @@ -269,15 +304,16 @@ video_createWindowVariousFlags(void *arg) window = SDL_CreateWindow(title, x, y, w, h, flags); SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); - if (window != NULL) { - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); - } + + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); } return TEST_COMPLETED; } + /** * @brief Tests the functionality of the SDL_GetWindowFlags function */ @@ -286,33 +322,203 @@ video_getWindowFlags(void *arg) { SDL_Window* window; const char* title = "video_getWindowFlags Test Window"; - int x, y, w, h; SDL_WindowFlags flags; Uint32 actualFlags; - /* Standard window */ - x = SDLTest_RandomIntegerInRange(1, 100); - y = SDLTest_RandomIntegerInRange(1, 100); - w = SDLTest_RandomIntegerInRange(320, 1024); - h = SDLTest_RandomIntegerInRange(320, 768); - - /* Reliable flag */ + /* Reliable flag set always set in test window */ flags = SDL_WINDOW_SHOWN; - window = SDL_CreateWindow(title, x, y, w, h, flags); - SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags); - SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL"); + /* Call against new test window */ + window = _createVideoSuiteTestWindow(title); if (window != NULL) { actualFlags = SDL_GetWindowFlags(window); SDLTest_AssertPass("Call to SDL_GetWindowFlags"); SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags); - SDL_DestroyWindow(window); - SDLTest_AssertPass("Call to SDL_DestroyWindow"); + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetNumDisplayModes function + */ +int +video_getNumDisplayModes(void *arg) +{ + int result; + int displayNum; + int i; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make call for each display */ + for (i=0; i= 1, "Validate returned value from function; expected: >=1; got: %d", result); } return TEST_COMPLETED; } +/** + * @brief Tests negative call to SDL_GetNumDisplayModes function + */ +int +video_getNumDisplayModesNegative(void *arg) +{ + int result; + int displayNum; + int displayIndex; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Invalid boundary values */ + displayIndex = SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + /* Large (out-of-bounds) display index */ + displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + displayIndex = SDLTest_RandomIntegerInRange(1000, 2000); + result = SDL_GetNumDisplayModes(displayIndex); + SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex); + SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result); + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution + */ +int +video_getClosestDisplayModeCurrentResolution(void *arg) +{ + int result; + SDL_DisplayMode current; + SDL_DisplayMode target; + SDL_DisplayMode closest; + SDL_DisplayMode* dResult; + int displayNum; + int i; + int variation; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make calls for each display */ + for (i=0; iw, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w); + SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h); + } + } + + return TEST_COMPLETED; +} + +/** + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution + */ +int +video_getClosestDisplayModeRandomResolution(void *arg) +{ + SDL_DisplayMode target; + SDL_DisplayMode closest; + SDL_DisplayMode* dResult; + int displayNum; + int i; + int variation; + + /* Get number of displays */ + displayNum = SDL_GetNumVideoDisplays(); + SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays"); + + /* Make calls for each display */ + for (i=0; i= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result); + } + + /* Clean up */ + _destroyVideoSuiteTestWindow(window); + + return TEST_COMPLETED; +} + /* ================= Test References ================== */ /* Video test cases */ @@ -329,11 +535,27 @@ static const SDLTest_TestCaseReference videoTest4 = { (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags", "Create windows using various flags", TEST_ENABLED }; static const SDLTest_TestCaseReference videoTest5 = - { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Set and get window flags", TEST_ENABLED }; + { (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags", "Get window flags set during SDL_CreateWindow", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest6 = + { (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes", "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest7 = + { (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative", "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest8 = + { (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution", "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest9 = + { (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution", "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED }; + +static const SDLTest_TestCaseReference videoTest10 = + { (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness", "Get window brightness", TEST_ENABLED }; /* Sequence of Video test cases */ static const SDLTest_TestCaseReference *videoTests[] = { - &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, NULL + &videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, + &videoTest7, &videoTest8, &videoTest9, &videoTest10, NULL }; /* Video test suite (global) */