test/testautomation_video.c
changeset 6921 9a29af9de577
parent 6891 177f29ae5279
child 6936 76d9c31e823d
     1.1 --- a/test/testautomation_video.c	Mon Feb 25 00:54:25 2013 -0800
     1.2 +++ b/test/testautomation_video.c	Mon Feb 25 08:05:26 2013 -0800
     1.3 @@ -7,6 +7,43 @@
     1.4  #include "SDL.h"
     1.5  #include "SDL_test.h"
     1.6  
     1.7 +/* Private helpers */
     1.8 +
     1.9 +/* 
    1.10 + * Create a test window
    1.11 + */
    1.12 +SDL_Window *_createVideoSuiteTestWindow(const char *title)
    1.13 +{
    1.14 +  SDL_Window* window;
    1.15 +  int x, y, w, h;
    1.16 +  SDL_WindowFlags flags;
    1.17 +
    1.18 +  /* Standard window */
    1.19 +  x = SDLTest_RandomIntegerInRange(1, 100);
    1.20 +  y = SDLTest_RandomIntegerInRange(1, 100);
    1.21 +  w = SDLTest_RandomIntegerInRange(320, 1024);
    1.22 +  h = SDLTest_RandomIntegerInRange(320, 768);
    1.23 +  flags = SDL_WINDOW_SHOWN;
    1.24 +  
    1.25 +  window = SDL_CreateWindow(title, x, y, w, h, flags);
    1.26 +  SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
    1.27 +  SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
    1.28 +
    1.29 +  return window;
    1.30 +}
    1.31 +
    1.32 +/*
    1.33 + * Destroy test window  
    1.34 + */
    1.35 +void _destroyVideoSuiteTestWindow(SDL_Window *window)
    1.36 +{
    1.37 +  if (window != NULL) {  
    1.38 +     SDL_DestroyWindow(window);
    1.39 +     window = NULL;
    1.40 +     SDLTest_AssertPass("Call to SDL_DestroyWindow");
    1.41 +  }
    1.42 +}
    1.43 +
    1.44  /* Test case functions */
    1.45  
    1.46  /**
    1.47 @@ -133,10 +170,9 @@
    1.48      window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
    1.49      SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
    1.50      SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
    1.51 -    if (window != NULL) {
    1.52 -      SDL_DestroyWindow(window);
    1.53 -      SDLTest_AssertPass("Call to SDL_DestroyWindow");
    1.54 -    }
    1.55 +
    1.56 +    /* Clean up */    
    1.57 +    _destroyVideoSuiteTestWindow(window);
    1.58     }
    1.59    } 
    1.60  
    1.61 @@ -191,10 +227,9 @@
    1.62      window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
    1.63      SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
    1.64      SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
    1.65 -    if (window != NULL) {
    1.66 -      SDL_DestroyWindow(window);
    1.67 -      SDLTest_AssertPass("Call to SDL_DestroyWindow");
    1.68 -    }
    1.69 +
    1.70 +    /* Clean up */    
    1.71 +    _destroyVideoSuiteTestWindow(window);
    1.72     }
    1.73    }  
    1.74  
    1.75 @@ -269,15 +304,16 @@
    1.76      window = SDL_CreateWindow(title, x, y, w, h, flags);
    1.77      SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
    1.78      SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
    1.79 -    if (window != NULL) {
    1.80 -      SDL_DestroyWindow(window);
    1.81 -      SDLTest_AssertPass("Call to SDL_DestroyWindow");
    1.82 -    }   
    1.83 +
    1.84 +
    1.85 +    /* Clean up */    
    1.86 +    _destroyVideoSuiteTestWindow(window);  
    1.87    }
    1.88  
    1.89    return TEST_COMPLETED;
    1.90  }
    1.91  
    1.92 +
    1.93  /**
    1.94   * @brief Tests the functionality of the SDL_GetWindowFlags function
    1.95   */
    1.96 @@ -286,30 +322,200 @@
    1.97  {
    1.98    SDL_Window* window;
    1.99    const char* title = "video_getWindowFlags Test Window";
   1.100 -  int x, y, w, h;
   1.101    SDL_WindowFlags flags;
   1.102    Uint32 actualFlags;
   1.103    
   1.104 -  /* Standard window */
   1.105 -  x = SDLTest_RandomIntegerInRange(1, 100);
   1.106 -  y = SDLTest_RandomIntegerInRange(1, 100);
   1.107 -  w = SDLTest_RandomIntegerInRange(320, 1024);
   1.108 -  h = SDLTest_RandomIntegerInRange(320, 768);
   1.109 -  
   1.110 -  /* Reliable flag */
   1.111 +  /* Reliable flag set always set in test window */
   1.112    flags = SDL_WINDOW_SHOWN;
   1.113    
   1.114 -  window = SDL_CreateWindow(title, x, y, w, h, flags);
   1.115 -  SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
   1.116 -  SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   1.117 +  /* Call against new test window */ 
   1.118 +  window = _createVideoSuiteTestWindow(title);
   1.119    if (window != NULL) {
   1.120        actualFlags = SDL_GetWindowFlags(window);
   1.121        SDLTest_AssertPass("Call to SDL_GetWindowFlags");
   1.122        SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
   1.123 -      SDL_DestroyWindow(window);
   1.124 -      SDLTest_AssertPass("Call to SDL_DestroyWindow");  
   1.125    }
   1.126  
   1.127 +  /* Clean up */    
   1.128 +  _destroyVideoSuiteTestWindow(window);
   1.129 +  
   1.130 +  return TEST_COMPLETED;
   1.131 +}
   1.132 +
   1.133 +/**
   1.134 + * @brief Tests the functionality of the SDL_GetNumDisplayModes function
   1.135 + */
   1.136 +int
   1.137 +video_getNumDisplayModes(void *arg)
   1.138 +{
   1.139 +  int result;
   1.140 +  int displayNum;
   1.141 +  int i;
   1.142 +
   1.143 +  /* Get number of displays */
   1.144 +  displayNum = SDL_GetNumVideoDisplays();
   1.145 +  SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
   1.146 +
   1.147 +  /* Make call for each display */  
   1.148 +  for (i=0; i<displayNum; i++) {
   1.149 +    result = SDL_GetNumDisplayModes(i);
   1.150 +    SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
   1.151 +    SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
   1.152 +  }
   1.153 +
   1.154 +  return TEST_COMPLETED;
   1.155 +}
   1.156 +
   1.157 +/**
   1.158 + * @brief Tests negative call to SDL_GetNumDisplayModes function
   1.159 + */
   1.160 +int
   1.161 +video_getNumDisplayModesNegative(void *arg)
   1.162 +{
   1.163 +  int result;
   1.164 +  int displayNum;
   1.165 +  int displayIndex;
   1.166 +
   1.167 +  /* Get number of displays */
   1.168 +  displayNum = SDL_GetNumVideoDisplays();
   1.169 +  SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
   1.170 +
   1.171 +  /* Invalid boundary values */
   1.172 +  displayIndex =  SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
   1.173 +  result = SDL_GetNumDisplayModes(displayIndex);
   1.174 +  SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
   1.175 +  SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);  
   1.176 +  
   1.177 +  /* Large (out-of-bounds) display index */
   1.178 +  displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
   1.179 +  result = SDL_GetNumDisplayModes(displayIndex);
   1.180 +  SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
   1.181 +  SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);  
   1.182 +
   1.183 +  displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
   1.184 +  result = SDL_GetNumDisplayModes(displayIndex);
   1.185 +  SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
   1.186 +  SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);  
   1.187 +
   1.188 +  return TEST_COMPLETED;
   1.189 +}
   1.190 +
   1.191 +/**
   1.192 + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
   1.193 + */
   1.194 +int
   1.195 +video_getClosestDisplayModeCurrentResolution(void *arg)
   1.196 +{
   1.197 +  int result;
   1.198 +  SDL_DisplayMode current; 
   1.199 +  SDL_DisplayMode target; 
   1.200 +  SDL_DisplayMode closest;
   1.201 +  SDL_DisplayMode* dResult;
   1.202 +  int displayNum;
   1.203 +  int i;
   1.204 +  int variation;
   1.205 +
   1.206 +  /* Get number of displays */
   1.207 +  displayNum = SDL_GetNumVideoDisplays();
   1.208 +  SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
   1.209 +
   1.210 +  /* Make calls for each display */  
   1.211 +  for (i=0; i<displayNum; i++) {
   1.212 +    SDLTest_Log("Testing against display: %d", i);
   1.213 +  
   1.214 +    /* Get first display mode to get a sane resolution; this should always work */
   1.215 +    result = SDL_GetDisplayMode(i, 0, &current);
   1.216 +    SDLTest_AssertPass("Call to SDL_GetDisplayMode");
   1.217 +    SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
   1.218 +    if (result != 0) {
   1.219 +      return TEST_ABORTED;
   1.220 +    }
   1.221 +       
   1.222 +    /* Set the desired resolution equals to current resolution */
   1.223 +    target.w = current.w;
   1.224 +    target.h = current.h;    
   1.225 +    for (variation = 0; variation < 8; variation ++) {
   1.226 +      /* Vary constraints on other query parameters */
   1.227 +      target.format = (variation & 1) ? current.format : 0;
   1.228 +      target.refresh_rate = (variation & 2) ? current.refresh_rate : 0;
   1.229 +      target.driverdata = (variation & 4) ? current.driverdata : 0;
   1.230 +          
   1.231 +      /* Make call */
   1.232 +      dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
   1.233 +      SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
   1.234 +      SDLTest_AssertCheck(dResult != NULL, "Verify returned value is not NULL");
   1.235 +    
   1.236 +      /* Check that one gets the current resolution back again */
   1.237 +      SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
   1.238 +      SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
   1.239 +      SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
   1.240 +      SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
   1.241 +    }
   1.242 +  }
   1.243 +
   1.244 +  return TEST_COMPLETED;
   1.245 +}
   1.246 +
   1.247 +/**
   1.248 + * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
   1.249 + */
   1.250 +int
   1.251 +video_getClosestDisplayModeRandomResolution(void *arg)
   1.252 +{
   1.253 +  SDL_DisplayMode target; 
   1.254 +  SDL_DisplayMode closest;
   1.255 +  SDL_DisplayMode* dResult;
   1.256 +  int displayNum;
   1.257 +  int i;
   1.258 +  int variation;
   1.259 +
   1.260 +  /* Get number of displays */
   1.261 +  displayNum = SDL_GetNumVideoDisplays();
   1.262 +  SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
   1.263 +
   1.264 +  /* Make calls for each display */  
   1.265 +  for (i=0; i<displayNum; i++) {
   1.266 +    SDLTest_Log("Testing against display: %d", i);
   1.267 +         
   1.268 +    for (variation = 0; variation < 16; variation ++) {
   1.269 +    
   1.270 +      /* Set random constraints */
   1.271 +      target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
   1.272 +      target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;    
   1.273 +      target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
   1.274 +      target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0;
   1.275 +      target.driverdata = 0;
   1.276 +          
   1.277 +      /* Make call; may or may not find anything, so don't validate any further */
   1.278 +      dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
   1.279 +      SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);      
   1.280 +    }
   1.281 +  }
   1.282 +
   1.283 +  return TEST_COMPLETED;
   1.284 +}
   1.285 +
   1.286 +/**
   1.287 + * @brief Tests call to SDL_GetWindowBrightness
   1.288 + */
   1.289 +int
   1.290 +video_getWindowBrightness(void *arg)
   1.291 +{
   1.292 +  SDL_Window* window;
   1.293 +  const char* title = "video_getWindowBrightness Test Window";
   1.294 +  float result;
   1.295 +
   1.296 +  /* Call against new test window */ 
   1.297 +  window = _createVideoSuiteTestWindow(title);
   1.298 +  if (window != NULL) {
   1.299 +      result = SDL_GetWindowBrightness(window);
   1.300 +      SDLTest_AssertPass("Call to SDL_GetWindowBrightness");
   1.301 +      SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
   1.302 +  }
   1.303 +
   1.304 +  /* Clean up */    
   1.305 +  _destroyVideoSuiteTestWindow(window);
   1.306 +  
   1.307    return TEST_COMPLETED;
   1.308  }
   1.309  
   1.310 @@ -329,11 +535,27 @@
   1.311  		{ (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags",  "Create windows using various flags", TEST_ENABLED };
   1.312  
   1.313  static const SDLTest_TestCaseReference videoTest5 =
   1.314 -		{ (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags",  "Set and get window flags", TEST_ENABLED };
   1.315 +		{ (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags",  "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
   1.316 +
   1.317 +static const SDLTest_TestCaseReference videoTest6 =
   1.318 +		{ (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes",  "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
   1.319 +
   1.320 +static const SDLTest_TestCaseReference videoTest7 =
   1.321 +		{ (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative",  "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
   1.322 +
   1.323 +static const SDLTest_TestCaseReference videoTest8 =
   1.324 +		{ (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution",  "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
   1.325 +
   1.326 +static const SDLTest_TestCaseReference videoTest9 =
   1.327 +		{ (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution",  "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
   1.328 +
   1.329 +static const SDLTest_TestCaseReference videoTest10 =
   1.330 +		{ (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness",  "Get window brightness", TEST_ENABLED };
   1.331  
   1.332  /* Sequence of Video test cases */
   1.333  static const SDLTest_TestCaseReference *videoTests[] =  {
   1.334 -	&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, NULL
   1.335 +	&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, 
   1.336 +	&videoTest7, &videoTest8, &videoTest9, &videoTest10, NULL
   1.337  };
   1.338  
   1.339  /* Video test suite (global) */