test/testautomation_video.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Thu, 28 Feb 2013 09:11:04 -0800
changeset 6936 76d9c31e823d
parent 6921 9a29af9de577
child 6956 afdc35fa58e9
permissions -rw-r--r--
Add additional input validation to SDL_GetWindowDisplayMode; add tests to video suite
     1 /**
     2  * Video test suite
     3  */
     4 
     5 #include <stdio.h>
     6 
     7 #include "SDL.h"
     8 #include "SDL_test.h"
     9 
    10 /* Private helpers */
    11 
    12 /* 
    13  * Create a test window
    14  */
    15 SDL_Window *_createVideoSuiteTestWindow(const char *title)
    16 {
    17   SDL_Window* window;
    18   int x, y, w, h;
    19   SDL_WindowFlags flags;
    20 
    21   /* Standard window */
    22   x = SDLTest_RandomIntegerInRange(1, 100);
    23   y = SDLTest_RandomIntegerInRange(1, 100);
    24   w = SDLTest_RandomIntegerInRange(320, 1024);
    25   h = SDLTest_RandomIntegerInRange(320, 768);
    26   flags = SDL_WINDOW_SHOWN;
    27   
    28   window = SDL_CreateWindow(title, x, y, w, h, flags);
    29   SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
    30   SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
    31 
    32   return window;
    33 }
    34 
    35 /*
    36  * Destroy test window  
    37  */
    38 void _destroyVideoSuiteTestWindow(SDL_Window *window)
    39 {
    40   if (window != NULL) {  
    41      SDL_DestroyWindow(window);
    42      window = NULL;
    43      SDLTest_AssertPass("Call to SDL_DestroyWindow");
    44   }
    45 }
    46 
    47 /* Test case functions */
    48 
    49 /**
    50  * @brief Enable and disable screensaver while checking state
    51  */
    52 int
    53 video_enableDisableScreensaver(void *arg)
    54 {
    55 	SDL_bool initialResult;
    56 	SDL_bool result;
    57 
    58 	/* Get current state and proceed according to current state */
    59 	initialResult = SDL_IsScreenSaverEnabled();
    60 	SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");	
    61 	if (initialResult == SDL_TRUE) {
    62 	
    63 	  /* Currently enabled: disable first, then enable again */
    64 	  
    65 	  /* Disable screensaver and check */	
    66 	  SDL_DisableScreenSaver();
    67 	  SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");	
    68 	  result = SDL_IsScreenSaverEnabled();
    69 	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
    70 	  SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
    71 	
    72 	  /* Enable screensaver and check */	
    73 	  SDL_EnableScreenSaver();
    74 	  SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
    75 	  result = SDL_IsScreenSaverEnabled();
    76 	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
    77 	  SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
    78 
    79 	} else {
    80 
    81 	  /* Currently disabled: enable first, then disable again */
    82 	  
    83 	  /* Enable screensaver and check */	
    84 	  SDL_EnableScreenSaver();
    85 	  SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
    86 	  result = SDL_IsScreenSaverEnabled();
    87 	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
    88 	  SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
    89 
    90 	  /* Disable screensaver and check */	
    91 	  SDL_DisableScreenSaver();
    92 	  SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");	
    93 	  result = SDL_IsScreenSaverEnabled();
    94 	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
    95 	  SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);	
    96 	}	
    97 	
    98 	return TEST_COMPLETED;
    99 }
   100 
   101 /**
   102  * @brief Tests the functionality of the SDL_CreateWindow function using different positions
   103  */
   104 int
   105 video_createWindowVariousPositions(void *arg)
   106 {
   107   SDL_Window* window;
   108   const char* title = "video_createWindowVariousPositions Test Window";
   109   int x, y, w, h;
   110   int xVariation, yVariation;
   111   
   112   for (xVariation = 0; xVariation < 6; xVariation++) {
   113    for (yVariation = 0; yVariation < 6; yVariation++) {
   114     switch(xVariation) {
   115      case 0:
   116       /* Zero X Position */  
   117       x = 0;
   118       break;
   119      case 1:
   120       /* Random X position inside screen */  
   121       x = SDLTest_RandomIntegerInRange(1, 100);
   122       break;
   123      case 2:
   124       /* Random X position outside screen (positive) */  
   125       x = SDLTest_RandomIntegerInRange(10000, 11000);
   126       break;
   127      case 3:
   128       /* Random X position outside screen (negative) */  
   129       x = SDLTest_RandomIntegerInRange(-1000, -100);
   130       break;
   131      case 4:
   132       /* Centered X position */  
   133       x = SDL_WINDOWPOS_CENTERED;
   134       break;
   135      case 5:
   136       /* Undefined X position */  
   137       x = SDL_WINDOWPOS_UNDEFINED;
   138       break;
   139     }
   140 
   141     switch(yVariation) {
   142      case 0:
   143       /* Zero X Position */  
   144       y = 0;
   145       break;
   146      case 1:
   147       /* Random X position inside screen */  
   148       y = SDLTest_RandomIntegerInRange(1, 100);
   149       break;
   150      case 2:
   151       /* Random X position outside screen (positive) */  
   152       y = SDLTest_RandomIntegerInRange(10000, 11000);
   153       break;
   154      case 3:
   155       /* Random Y position outside screen (negative) */  
   156       y = SDLTest_RandomIntegerInRange(-1000, -100);
   157       break;
   158      case 4:
   159       /* Centered Y position */  
   160       y = SDL_WINDOWPOS_CENTERED;
   161       break;
   162      case 5:
   163       /* Undefined Y position */  
   164       y = SDL_WINDOWPOS_UNDEFINED;
   165       break;
   166     }
   167      
   168     w = SDLTest_RandomIntegerInRange(32, 96);
   169     h = SDLTest_RandomIntegerInRange(32, 96);
   170     window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
   171     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
   172     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   173 
   174     /* Clean up */    
   175     _destroyVideoSuiteTestWindow(window);
   176    }
   177   } 
   178 
   179   return TEST_COMPLETED;
   180 }
   181 
   182 /**
   183  * @brief Tests the functionality of the SDL_CreateWindow function using different sizes
   184  */
   185 int
   186 video_createWindowVariousSizes(void *arg)
   187 {
   188   SDL_Window* window;
   189   const char* title = "video_createWindowVariousSizes Test Window";
   190   int x, y, w, h;
   191   int wVariation, hVariation;
   192   
   193   x = SDLTest_RandomIntegerInRange(1, 100);
   194   y = SDLTest_RandomIntegerInRange(1, 100);
   195   for (wVariation = 0; wVariation < 3; wVariation++) {
   196    for (hVariation = 0; hVariation < 3; hVariation++) {
   197     switch(wVariation) {
   198      case 0:
   199       /* Width of 1 */  
   200       w = 1;
   201       break;
   202      case 1:
   203       /* Random "normal" width */  
   204       w = SDLTest_RandomIntegerInRange(320, 1920);
   205       break;
   206      case 2:
   207       /* Random "large" width */  
   208       w = SDLTest_RandomIntegerInRange(2048, 4095);
   209       break;
   210     }
   211 
   212     switch(hVariation) {
   213      case 0:
   214       /* Height of 1 */  
   215       h = 1;
   216       break;
   217      case 1:
   218       /* Random "normal" height */  
   219       h = SDLTest_RandomIntegerInRange(320, 1080);
   220       break;
   221      case 2:
   222       /* Random "large" height */  
   223       h = SDLTest_RandomIntegerInRange(2048, 4095);
   224       break;
   225      }
   226      
   227     window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
   228     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
   229     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   230 
   231     /* Clean up */    
   232     _destroyVideoSuiteTestWindow(window);
   233    }
   234   }  
   235 
   236   return TEST_COMPLETED;
   237 }
   238 
   239 /**
   240  * @brief Tests the functionality of the SDL_CreateWindow function using different flags
   241  */
   242 int
   243 video_createWindowVariousFlags(void *arg)
   244 {
   245   SDL_Window* window;
   246   const char* title = "video_createWindowVariousFlags Test Window";
   247   int x, y, w, h;
   248   int fVariation;
   249   SDL_WindowFlags flags;
   250   
   251   /* Standard window */
   252   x = SDLTest_RandomIntegerInRange(1, 100);
   253   y = SDLTest_RandomIntegerInRange(1, 100);
   254   w = SDLTest_RandomIntegerInRange(320, 1024);
   255   h = SDLTest_RandomIntegerInRange(320, 768);
   256 
   257   for (fVariation = 0; fVariation < 13; fVariation++) {
   258     switch(fVariation) {
   259      case 0:
   260       flags = SDL_WINDOW_FULLSCREEN;
   261       /* Skip - blanks screen; comment out next line to run test */
   262       continue;   
   263       break;
   264      case 1:
   265       flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
   266       /* Skip - blanks screen; comment out next line to run test */
   267       continue;  
   268       break;
   269      case 2:
   270       flags = SDL_WINDOW_OPENGL;
   271       break;  
   272      case 3:
   273       flags = SDL_WINDOW_SHOWN;
   274       break;   
   275      case 4:    
   276       flags = SDL_WINDOW_HIDDEN;
   277       break;     
   278      case 5:
   279       flags = SDL_WINDOW_BORDERLESS;
   280       break;       
   281      case 6:
   282       flags = SDL_WINDOW_RESIZABLE;
   283       break;         
   284      case 7:
   285       flags = SDL_WINDOW_MINIMIZED;
   286       break;           
   287      case 8:
   288       flags = SDL_WINDOW_MAXIMIZED;
   289       break;
   290      case 9: 
   291       flags = SDL_WINDOW_INPUT_GRABBED;
   292       break;
   293      case 10:              
   294       flags = SDL_WINDOW_INPUT_FOCUS;
   295       break;                 
   296      case 11:                      
   297       flags = SDL_WINDOW_MOUSE_FOCUS;
   298       break;
   299      case 12: 
   300       flags = SDL_WINDOW_FOREIGN;
   301       break;
   302     }
   303        
   304     window = SDL_CreateWindow(title, x, y, w, h, flags);
   305     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
   306     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   307 
   308 
   309     /* Clean up */    
   310     _destroyVideoSuiteTestWindow(window);  
   311   }
   312 
   313   return TEST_COMPLETED;
   314 }
   315 
   316 
   317 /**
   318  * @brief Tests the functionality of the SDL_GetWindowFlags function
   319  */
   320 int
   321 video_getWindowFlags(void *arg)
   322 {
   323   SDL_Window* window;
   324   const char* title = "video_getWindowFlags Test Window";
   325   SDL_WindowFlags flags;
   326   Uint32 actualFlags;
   327   
   328   /* Reliable flag set always set in test window */
   329   flags = SDL_WINDOW_SHOWN;
   330   
   331   /* Call against new test window */ 
   332   window = _createVideoSuiteTestWindow(title);
   333   if (window != NULL) {
   334       actualFlags = SDL_GetWindowFlags(window);
   335       SDLTest_AssertPass("Call to SDL_GetWindowFlags");
   336       SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
   337   }
   338 
   339   /* Clean up */    
   340   _destroyVideoSuiteTestWindow(window);
   341   
   342   return TEST_COMPLETED;
   343 }
   344 
   345 /**
   346  * @brief Tests the functionality of the SDL_GetNumDisplayModes function
   347  */
   348 int
   349 video_getNumDisplayModes(void *arg)
   350 {
   351   int result;
   352   int displayNum;
   353   int i;
   354 
   355   /* Get number of displays */
   356   displayNum = SDL_GetNumVideoDisplays();
   357   SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
   358 
   359   /* Make call for each display */  
   360   for (i=0; i<displayNum; i++) {
   361     result = SDL_GetNumDisplayModes(i);
   362     SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d)", i);
   363     SDLTest_AssertCheck(result >= 1, "Validate returned value from function; expected: >=1; got: %d", result);
   364   }
   365 
   366   return TEST_COMPLETED;
   367 }
   368 
   369 /**
   370  * @brief Tests negative call to SDL_GetNumDisplayModes function
   371  */
   372 int
   373 video_getNumDisplayModesNegative(void *arg)
   374 {
   375   int result;
   376   int displayNum;
   377   int displayIndex;
   378 
   379   /* Get number of displays */
   380   displayNum = SDL_GetNumVideoDisplays();
   381   SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
   382 
   383   /* Invalid boundary values */
   384   displayIndex =  SDLTest_RandomSint32BoundaryValue(0, displayNum, SDL_FALSE);
   385   result = SDL_GetNumDisplayModes(displayIndex);
   386   SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/boundary)", displayIndex);
   387   SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);  
   388   
   389   /* Large (out-of-bounds) display index */
   390   displayIndex = SDLTest_RandomIntegerInRange(-2000, -1000);
   391   result = SDL_GetNumDisplayModes(displayIndex);
   392   SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large negative)", displayIndex);
   393   SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);  
   394 
   395   displayIndex = SDLTest_RandomIntegerInRange(1000, 2000);
   396   result = SDL_GetNumDisplayModes(displayIndex);
   397   SDLTest_AssertPass("Call to SDL_GetNumDisplayModes(%d=out-of-bounds/large positive)", displayIndex);
   398   SDLTest_AssertCheck(result < 0, "Validate returned value from function; expected: <0; got: %d", result);  
   399 
   400   return TEST_COMPLETED;
   401 }
   402 
   403 /**
   404  * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against current resolution
   405  */
   406 int
   407 video_getClosestDisplayModeCurrentResolution(void *arg)
   408 {
   409   int result;
   410   SDL_DisplayMode current; 
   411   SDL_DisplayMode target; 
   412   SDL_DisplayMode closest;
   413   SDL_DisplayMode* dResult;
   414   int displayNum;
   415   int i;
   416   int variation;
   417 
   418   /* Get number of displays */
   419   displayNum = SDL_GetNumVideoDisplays();
   420   SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
   421 
   422   /* Make calls for each display */  
   423   for (i=0; i<displayNum; i++) {
   424     SDLTest_Log("Testing against display: %d", i);
   425   
   426     /* Get first display mode to get a sane resolution; this should always work */
   427     result = SDL_GetDisplayMode(i, 0, &current);
   428     SDLTest_AssertPass("Call to SDL_GetDisplayMode");
   429     SDLTest_AssertCheck(result == 0, "Verify return value, expected: 0, got: %d", result);
   430     if (result != 0) {
   431       return TEST_ABORTED;
   432     }
   433        
   434     /* Set the desired resolution equals to current resolution */
   435     target.w = current.w;
   436     target.h = current.h;    
   437     for (variation = 0; variation < 8; variation ++) {
   438       /* Vary constraints on other query parameters */
   439       target.format = (variation & 1) ? current.format : 0;
   440       target.refresh_rate = (variation & 2) ? current.refresh_rate : 0;
   441       target.driverdata = (variation & 4) ? current.driverdata : 0;
   442           
   443       /* Make call */
   444       dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
   445       SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=current/variation%d)", variation);
   446       SDLTest_AssertCheck(dResult != NULL, "Verify returned value is not NULL");
   447     
   448       /* Check that one gets the current resolution back again */
   449       SDLTest_AssertCheck(closest.w == current.w, "Verify returned width matches current width; expected: %d, got: %d", current.w, closest.w);
   450       SDLTest_AssertCheck(closest.h == current.h, "Verify returned height matches current height; expected: %d, got: %d", current.h, closest.h);
   451       SDLTest_AssertCheck(closest.w == dResult->w, "Verify return value matches assigned value; expected: %d, got: %d", closest.w, dResult->w);
   452       SDLTest_AssertCheck(closest.h == dResult->h, "Verify return value matches assigned value; expected: %d, got: %d", closest.h, dResult->h);
   453     }
   454   }
   455 
   456   return TEST_COMPLETED;
   457 }
   458 
   459 /**
   460  * @brief Tests the functionality of the SDL_GetClosestDisplayMode function against random resolution
   461  */
   462 int
   463 video_getClosestDisplayModeRandomResolution(void *arg)
   464 {
   465   SDL_DisplayMode target; 
   466   SDL_DisplayMode closest;
   467   SDL_DisplayMode* dResult;
   468   int displayNum;
   469   int i;
   470   int variation;
   471 
   472   /* Get number of displays */
   473   displayNum = SDL_GetNumVideoDisplays();
   474   SDLTest_AssertPass("Call to SDL_GetNumVideoDisplays");
   475 
   476   /* Make calls for each display */  
   477   for (i=0; i<displayNum; i++) {
   478     SDLTest_Log("Testing against display: %d", i);
   479          
   480     for (variation = 0; variation < 16; variation ++) {
   481     
   482       /* Set random constraints */
   483       target.w = (variation & 1) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;
   484       target.h = (variation & 2) ? SDLTest_RandomIntegerInRange(1, 4096) : 0;    
   485       target.format = (variation & 4) ? SDLTest_RandomIntegerInRange(1, 10) : 0;
   486       target.refresh_rate = (variation & 8) ? SDLTest_RandomIntegerInRange(25, 120) : 0;
   487       target.driverdata = 0;
   488           
   489       /* Make call; may or may not find anything, so don't validate any further */
   490       dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
   491       SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);      
   492     }
   493   }
   494 
   495   return TEST_COMPLETED;
   496 }
   497 
   498 /**
   499  * @brief Tests call to SDL_GetWindowBrightness
   500  *
   501 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness
   502  */
   503 int
   504 video_getWindowBrightness(void *arg)
   505 {
   506   SDL_Window* window;
   507   const char* title = "video_getWindowBrightness Test Window";
   508   float result;
   509 
   510   /* Call against new test window */ 
   511   window = _createVideoSuiteTestWindow(title);
   512   if (window != NULL) {
   513       result = SDL_GetWindowBrightness(window);
   514       SDLTest_AssertPass("Call to SDL_GetWindowBrightness");
   515       SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
   516   }
   517 
   518   /* Clean up */    
   519   _destroyVideoSuiteTestWindow(window);
   520   
   521   return TEST_COMPLETED;
   522 }
   523 
   524 /**
   525  * @brief Tests call to SDL_GetWindowBrightness with invalid input
   526  *
   527 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness
   528  */
   529 int
   530 video_getWindowBrightnessNegative(void *arg)
   531 {
   532   const char *invalidWindowError = "Invalid window";
   533   char *lastError;
   534   const char* title = "video_getWindowBrightnessNegative Test Window";
   535   float result;
   536 
   537   /* Call against invalid window */ 
   538   result = SDL_GetWindowBrightness(NULL);
   539   SDLTest_AssertPass("Call to SDL_GetWindowBrightness(window=NULL)");
   540   SDLTest_AssertCheck(result == 1.0, "Validate result value; expected: 1.0, got: %f", result);
   541   lastError = (char *)SDL_GetError();
   542   SDLTest_AssertPass("SDL_GetError()");
   543   SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
   544   if (lastError != NULL) {
   545       SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
   546          "SDL_GetError(): expected message '%s', was message: '%s'",
   547          invalidWindowError,
   548          lastError);
   549   }
   550 
   551   return TEST_COMPLETED;
   552 }
   553 
   554 /**
   555  * @brief Tests call to SDL_GetWindowDisplayMode
   556  *
   557  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
   558  */
   559 int
   560 video_getWindowDisplayMode(void *arg)
   561 {
   562   SDL_Window* window;
   563   const char* title = "video_getWindowDisplayMode Test Window";
   564   SDL_DisplayMode mode;
   565   int result;
   566 
   567   /* Invalidate part of the mode content so we can check values later */
   568   mode.w = -1;
   569   mode.h = -1;
   570   mode.refresh_rate = -1;
   571 
   572   /* Call against new test window */ 
   573   window = _createVideoSuiteTestWindow(title);
   574   if (window != NULL) {
   575       result = SDL_GetWindowDisplayMode(window, &mode);
   576       SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode");
   577       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   578       SDLTest_AssertCheck(mode.w > 0, "Validate mode.w content; expected: >0, got: %d", mode.w);
   579       SDLTest_AssertCheck(mode.h > 0, "Validate mode.h content; expected: >0, got: %d", mode.h);
   580       SDLTest_AssertCheck(mode.refresh_rate > 0, "Validate mode.refresh_rate content; expected: >0, got: %d", mode.refresh_rate);
   581   }
   582 
   583   /* Clean up */    
   584   _destroyVideoSuiteTestWindow(window);
   585   
   586   return TEST_COMPLETED;
   587 }
   588 
   589 /**
   590  * @brief Tests call to SDL_GetWindowDisplayMode with invalid input
   591  *
   592  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
   593  */
   594 int
   595 video_getWindowDisplayModeNegative(void *arg)
   596 {
   597   const char *expectedError = "Parameter 'mode' is invalid";
   598   const char *invalidWindowError = "Invalid window";
   599   char *lastError;
   600   SDL_Window* window;
   601   const char* title = "video_getWindowDisplayModeNegative Test Window";
   602   SDL_DisplayMode mode;
   603   int result;
   604 
   605   /* Call against new test window */ 
   606   window = _createVideoSuiteTestWindow(title);
   607   if (window != NULL) {
   608       result = SDL_GetWindowDisplayMode(window, NULL);
   609       SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(...,mode=NULL)");
   610       SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
   611       lastError = (char *)SDL_GetError();
   612       SDLTest_AssertPass("SDL_GetError()");
   613       SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
   614       if (lastError != NULL) {
   615       	SDLTest_AssertCheck(SDL_strcmp(lastError, expectedError) == 0,
   616              "SDL_GetError(): expected message '%s', was message: '%s'",
   617              expectedError,
   618              lastError);
   619       }
   620   }
   621 
   622   /* Clean up */    
   623   _destroyVideoSuiteTestWindow(window);
   624   
   625   /* Call against invalid window */
   626   result = SDL_GetWindowDisplayMode(NULL, &mode);
   627   SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode(window=NULL,...)");
   628   SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %d", result);
   629   lastError = (char *)SDL_GetError();
   630   SDLTest_AssertPass("SDL_GetError()");
   631   SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
   632   if (lastError != NULL) {
   633       SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
   634          "SDL_GetError(): expected message '%s', was message: '%s'",
   635          invalidWindowError,
   636          lastError);
   637   }
   638   
   639   return TEST_COMPLETED;
   640 }
   641 
   642 /**
   643  * @brief Tests call to SDL_GetWindowGammaRamp
   644  *
   645  * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
   646  */
   647 int
   648 video_getWindowGammaRamp(void *arg)
   649 {
   650   SDL_Window* window;
   651   const char* title = "video_getWindowGammaRamp Test Window";
   652   Uint16 red[256];
   653   Uint16 green[256];
   654   Uint16 blue[256];
   655   int result;
   656 
   657   /* Call against new test window */ 
   658   window = _createVideoSuiteTestWindow(title);
   659   if (window != NULL) {
   660       /* Retrieve no channel */
   661       result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL);
   662       SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(all NULL)");
   663       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   664 
   665       /* Retrieve single channel */
   666       result = SDL_GetWindowGammaRamp(window, red, NULL, NULL);
   667       SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r)");
   668       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   669 
   670       result = SDL_GetWindowGammaRamp(window, NULL, green, NULL);
   671       SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g)");
   672       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   673 
   674       result = SDL_GetWindowGammaRamp(window, NULL, NULL, blue);
   675       SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(b)");
   676       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   677 
   678       /* Retrieve two channels */
   679       result = SDL_GetWindowGammaRamp(window, red, green, NULL);
   680       SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r, g)");
   681       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   682 
   683       result = SDL_GetWindowGammaRamp(window, NULL, green, blue);
   684       SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(g,b)");
   685       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   686 
   687       result = SDL_GetWindowGammaRamp(window, red, NULL, blue);
   688       SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,b)");
   689       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   690 
   691       /* Retrieve all channels */
   692       result = SDL_GetWindowGammaRamp(window, red, green, blue);
   693       SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(r,g,b)");
   694       SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
   695   }
   696 
   697   /* Clean up */    
   698   _destroyVideoSuiteTestWindow(window);
   699   
   700   return TEST_COMPLETED;
   701 }
   702 
   703 /**
   704  * @brief Tests call to SDL_GetWindowGammaRamp with invalid input
   705  *
   706 * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
   707  */
   708 int
   709 video_getWindowGammaRampNegative(void *arg)
   710 {
   711   const char *invalidWindowError = "Invalid window";
   712   char *lastError;
   713   const char* title = "video_getWindowGammaRampNegative Test Window";
   714   Uint16 red[256];
   715   Uint16 green[256];
   716   Uint16 blue[256];
   717   int result;
   718 
   719   /* Call against invalid window */ 
   720   result = SDL_GetWindowGammaRamp(NULL, red, green, blue);
   721   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)");
   722   SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %f", result);
   723   lastError = (char *)SDL_GetError();
   724   SDLTest_AssertPass("SDL_GetError()");
   725   SDLTest_AssertCheck(lastError != NULL, "Verify error message is not NULL");
   726   if (lastError != NULL) {
   727       SDLTest_AssertCheck(SDL_strcmp(lastError, invalidWindowError) == 0,
   728          "SDL_GetError(): expected message '%s', was message: '%s'",
   729          invalidWindowError,
   730          lastError);
   731   }
   732 
   733   return TEST_COMPLETED;
   734 }
   735 
   736 /* ================= Test References ================== */
   737 
   738 /* Video test cases */
   739 static const SDLTest_TestCaseReference videoTest1 =
   740 		{ (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver",  "Enable and disable screenaver while checking state", TEST_ENABLED };
   741 
   742 static const SDLTest_TestCaseReference videoTest2 =
   743 		{ (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions",  "Create windows at various locations", TEST_ENABLED };
   744 
   745 static const SDLTest_TestCaseReference videoTest3 =
   746 		{ (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes",  "Create windows with various sizes", TEST_ENABLED };
   747 
   748 static const SDLTest_TestCaseReference videoTest4 =
   749 		{ (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags",  "Create windows using various flags", TEST_ENABLED };
   750 
   751 static const SDLTest_TestCaseReference videoTest5 =
   752 		{ (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags",  "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
   753 
   754 static const SDLTest_TestCaseReference videoTest6 =
   755 		{ (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes",  "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
   756 
   757 static const SDLTest_TestCaseReference videoTest7 =
   758 		{ (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative",  "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
   759 
   760 static const SDLTest_TestCaseReference videoTest8 =
   761 		{ (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution",  "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
   762 
   763 static const SDLTest_TestCaseReference videoTest9 =
   764 		{ (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution",  "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
   765 
   766 static const SDLTest_TestCaseReference videoTest10 =
   767 		{ (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness",  "Get window brightness", TEST_ENABLED };
   768 
   769 static const SDLTest_TestCaseReference videoTest11 =
   770 		{ (SDLTest_TestCaseFp)video_getWindowBrightnessNegative, "video_getWindowBrightnessNegative",  "Get window brightness with invalid input", TEST_ENABLED };
   771 
   772 static const SDLTest_TestCaseReference videoTest12 =
   773 		{ (SDLTest_TestCaseFp)video_getWindowDisplayMode, "video_getWindowDisplayMode",  "Get window display mode", TEST_ENABLED };
   774 
   775 static const SDLTest_TestCaseReference videoTest13 =
   776 		{ (SDLTest_TestCaseFp)video_getWindowDisplayModeNegative, "video_getWindowDisplayModeNegative",  "Get window display mode with invalid input", TEST_ENABLED };
   777 
   778 static const SDLTest_TestCaseReference videoTest14 =
   779 		{ (SDLTest_TestCaseFp)video_getWindowGammaRamp, "video_getWindowGammaRamp",  "Get window gamma ramp", TEST_ENABLED };
   780 
   781 static const SDLTest_TestCaseReference videoTest15 =
   782 		{ (SDLTest_TestCaseFp)video_getWindowGammaRampNegative, "video_getWindowGammaRampNegative",  "Get window gamma ramp against invalid input", TEST_ENABLED };
   783 
   784 /* Sequence of Video test cases */
   785 static const SDLTest_TestCaseReference *videoTests[] =  {
   786 	&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, 
   787 	&videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12, 
   788 	&videoTest13, &videoTest14, &videoTest15, NULL
   789 };
   790 
   791 /* Video test suite (global) */
   792 SDLTest_TestSuiteReference videoTestSuite = {
   793 	"Video",
   794 	NULL,
   795 	videoTests,
   796 	NULL
   797 };