test/testautomation_video.c
changeset 6921 9a29af9de577
parent 6891 177f29ae5279
child 6936 76d9c31e823d
equal deleted inserted replaced
6920:a966229b4107 6921:9a29af9de577
     4 
     4 
     5 #include <stdio.h>
     5 #include <stdio.h>
     6 
     6 
     7 #include "SDL.h"
     7 #include "SDL.h"
     8 #include "SDL_test.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 }
     9 
    46 
    10 /* Test case functions */
    47 /* Test case functions */
    11 
    48 
    12 /**
    49 /**
    13  * @brief Enable and disable screensaver while checking state
    50  * @brief Enable and disable screensaver while checking state
   131     w = SDLTest_RandomIntegerInRange(32, 96);
   168     w = SDLTest_RandomIntegerInRange(32, 96);
   132     h = SDLTest_RandomIntegerInRange(32, 96);
   169     h = SDLTest_RandomIntegerInRange(32, 96);
   133     window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
   170     window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
   134     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
   171     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
   135     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   172     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   136     if (window != NULL) {
   173 
   137       SDL_DestroyWindow(window);
   174     /* Clean up */    
   138       SDLTest_AssertPass("Call to SDL_DestroyWindow");
   175     _destroyVideoSuiteTestWindow(window);
   139     }
       
   140    }
   176    }
   141   } 
   177   } 
   142 
   178 
   143   return TEST_COMPLETED;
   179   return TEST_COMPLETED;
   144 }
   180 }
   189      }
   225      }
   190      
   226      
   191     window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
   227     window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN);
   192     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
   228     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
   193     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   229     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   194     if (window != NULL) {
   230 
   195       SDL_DestroyWindow(window);
   231     /* Clean up */    
   196       SDLTest_AssertPass("Call to SDL_DestroyWindow");
   232     _destroyVideoSuiteTestWindow(window);
   197     }
       
   198    }
   233    }
   199   }  
   234   }  
   200 
   235 
   201   return TEST_COMPLETED;
   236   return TEST_COMPLETED;
   202 }
   237 }
   267     }
   302     }
   268        
   303        
   269     window = SDL_CreateWindow(title, x, y, w, h, flags);
   304     window = SDL_CreateWindow(title, x, y, w, h, flags);
   270     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
   305     SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
   271     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   306     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   272     if (window != NULL) {
   307 
   273       SDL_DestroyWindow(window);
   308 
   274       SDLTest_AssertPass("Call to SDL_DestroyWindow");
   309     /* Clean up */    
   275     }   
   310     _destroyVideoSuiteTestWindow(window);  
   276   }
   311   }
   277 
   312 
   278   return TEST_COMPLETED;
   313   return TEST_COMPLETED;
   279 }
   314 }
       
   315 
   280 
   316 
   281 /**
   317 /**
   282  * @brief Tests the functionality of the SDL_GetWindowFlags function
   318  * @brief Tests the functionality of the SDL_GetWindowFlags function
   283  */
   319  */
   284 int
   320 int
   285 video_getWindowFlags(void *arg)
   321 video_getWindowFlags(void *arg)
   286 {
   322 {
   287   SDL_Window* window;
   323   SDL_Window* window;
   288   const char* title = "video_getWindowFlags Test Window";
   324   const char* title = "video_getWindowFlags Test Window";
   289   int x, y, w, h;
       
   290   SDL_WindowFlags flags;
   325   SDL_WindowFlags flags;
   291   Uint32 actualFlags;
   326   Uint32 actualFlags;
   292   
   327   
   293   /* Standard window */
   328   /* Reliable flag set always set in test window */
   294   x = SDLTest_RandomIntegerInRange(1, 100);
       
   295   y = SDLTest_RandomIntegerInRange(1, 100);
       
   296   w = SDLTest_RandomIntegerInRange(320, 1024);
       
   297   h = SDLTest_RandomIntegerInRange(320, 768);
       
   298   
       
   299   /* Reliable flag */
       
   300   flags = SDL_WINDOW_SHOWN;
   329   flags = SDL_WINDOW_SHOWN;
   301   
   330   
   302   window = SDL_CreateWindow(title, x, y, w, h, flags);
   331   /* Call against new test window */ 
   303   SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
   332   window = _createVideoSuiteTestWindow(title);
   304   SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
       
   305   if (window != NULL) {
   333   if (window != NULL) {
   306       actualFlags = SDL_GetWindowFlags(window);
   334       actualFlags = SDL_GetWindowFlags(window);
   307       SDLTest_AssertPass("Call to SDL_GetWindowFlags");
   335       SDLTest_AssertPass("Call to SDL_GetWindowFlags");
   308       SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
   336       SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
   309       SDL_DestroyWindow(window);
   337   }
   310       SDLTest_AssertPass("Call to SDL_DestroyWindow");  
   338 
   311   }
   339   /* Clean up */    
   312 
   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 int
       
   502 video_getWindowBrightness(void *arg)
       
   503 {
       
   504   SDL_Window* window;
       
   505   const char* title = "video_getWindowBrightness Test Window";
       
   506   float result;
       
   507 
       
   508   /* Call against new test window */ 
       
   509   window = _createVideoSuiteTestWindow(title);
       
   510   if (window != NULL) {
       
   511       result = SDL_GetWindowBrightness(window);
       
   512       SDLTest_AssertPass("Call to SDL_GetWindowBrightness");
       
   513       SDLTest_AssertCheck(result >= 0.0 && result <= 1.0, "Validate range of result value; expected: [0.0, 1.0], got: %f", result);
       
   514   }
       
   515 
       
   516   /* Clean up */    
       
   517   _destroyVideoSuiteTestWindow(window);
       
   518   
   313   return TEST_COMPLETED;
   519   return TEST_COMPLETED;
   314 }
   520 }
   315 
   521 
   316 /* ================= Test References ================== */
   522 /* ================= Test References ================== */
   317 
   523 
   327 
   533 
   328 static const SDLTest_TestCaseReference videoTest4 =
   534 static const SDLTest_TestCaseReference videoTest4 =
   329 		{ (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags",  "Create windows using various flags", TEST_ENABLED };
   535 		{ (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags",  "Create windows using various flags", TEST_ENABLED };
   330 
   536 
   331 static const SDLTest_TestCaseReference videoTest5 =
   537 static const SDLTest_TestCaseReference videoTest5 =
   332 		{ (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags",  "Set and get window flags", TEST_ENABLED };
   538 		{ (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags",  "Get window flags set during SDL_CreateWindow", TEST_ENABLED };
       
   539 
       
   540 static const SDLTest_TestCaseReference videoTest6 =
       
   541 		{ (SDLTest_TestCaseFp)video_getNumDisplayModes, "video_getNumDisplayModes",  "Use SDL_GetNumDisplayModes function to get number of display modes", TEST_ENABLED };
       
   542 
       
   543 static const SDLTest_TestCaseReference videoTest7 =
       
   544 		{ (SDLTest_TestCaseFp)video_getNumDisplayModesNegative, "video_getNumDisplayModesNegative",  "Negative tests for SDL_GetNumDisplayModes", TEST_ENABLED };
       
   545 
       
   546 static const SDLTest_TestCaseReference videoTest8 =
       
   547 		{ (SDLTest_TestCaseFp)video_getClosestDisplayModeCurrentResolution, "video_getClosestDisplayModeCurrentResolution",  "Use function to get closes match to requested display mode for current resolution", TEST_ENABLED };
       
   548 
       
   549 static const SDLTest_TestCaseReference videoTest9 =
       
   550 		{ (SDLTest_TestCaseFp)video_getClosestDisplayModeRandomResolution, "video_getClosestDisplayModeRandomResolution",  "Use function to get closes match to requested display mode for random resolution", TEST_ENABLED };
       
   551 
       
   552 static const SDLTest_TestCaseReference videoTest10 =
       
   553 		{ (SDLTest_TestCaseFp)video_getWindowBrightness, "video_getWindowBrightness",  "Get window brightness", TEST_ENABLED };
   333 
   554 
   334 /* Sequence of Video test cases */
   555 /* Sequence of Video test cases */
   335 static const SDLTest_TestCaseReference *videoTests[] =  {
   556 static const SDLTest_TestCaseReference *videoTests[] =  {
   336 	&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, NULL
   557 	&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6, 
       
   558 	&videoTest7, &videoTest8, &videoTest9, &videoTest10, NULL
   337 };
   559 };
   338 
   560 
   339 /* Video test suite (global) */
   561 /* Video test suite (global) */
   340 SDLTest_TestSuiteReference videoTestSuite = {
   562 SDLTest_TestSuiteReference videoTestSuite = {
   341 	"Video",
   563 	"Video",