test/testautomation_video.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Sat, 16 Feb 2013 23:09:10 -0800
changeset 6891 177f29ae5279
parent 6800 26c6795ec1a4
child 6921 9a29af9de577
permissions -rw-r--r--
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 /* Test case functions */
    11 
    12 /**
    13  * @brief Enable and disable screensaver while checking state
    14  */
    15 int
    16 video_enableDisableScreensaver(void *arg)
    17 {
    18 	SDL_bool initialResult;
    19 	SDL_bool result;
    20 
    21 	/* Get current state and proceed according to current state */
    22 	initialResult = SDL_IsScreenSaverEnabled();
    23 	SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");	
    24 	if (initialResult == SDL_TRUE) {
    25 	
    26 	  /* Currently enabled: disable first, then enable again */
    27 	  
    28 	  /* Disable screensaver and check */	
    29 	  SDL_DisableScreenSaver();
    30 	  SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");	
    31 	  result = SDL_IsScreenSaverEnabled();
    32 	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
    33 	  SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);
    34 	
    35 	  /* Enable screensaver and check */	
    36 	  SDL_EnableScreenSaver();
    37 	  SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
    38 	  result = SDL_IsScreenSaverEnabled();
    39 	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
    40 	  SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
    41 
    42 	} else {
    43 
    44 	  /* Currently disabled: enable first, then disable again */
    45 	  
    46 	  /* Enable screensaver and check */	
    47 	  SDL_EnableScreenSaver();
    48 	  SDLTest_AssertPass("Call to SDL_EnableScreenSaver()");
    49 	  result = SDL_IsScreenSaverEnabled();
    50 	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
    51 	  SDLTest_AssertCheck(result == SDL_TRUE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_TRUE, result);
    52 
    53 	  /* Disable screensaver and check */	
    54 	  SDL_DisableScreenSaver();
    55 	  SDLTest_AssertPass("Call to SDL_DisableScreenSaver()");	
    56 	  result = SDL_IsScreenSaverEnabled();
    57 	  SDLTest_AssertPass("Call to SDL_IsScreenSaverEnabled()");
    58 	  SDLTest_AssertCheck(result == SDL_FALSE, "Verify result from SDL_IsScreenSaverEnabled, expected: %i, got: %i", SDL_FALSE, result);	
    59 	}	
    60 	
    61 	return TEST_COMPLETED;
    62 }
    63 
    64 /**
    65  * @brief Tests the functionality of the SDL_CreateWindow function using different positions
    66  */
    67 int
    68 video_createWindowVariousPositions(void *arg)
    69 {
    70   SDL_Window* window;
    71   const char* title = "video_createWindowVariousPositions Test Window";
    72   int x, y, w, h;
    73   int xVariation, yVariation;
    74   
    75   for (xVariation = 0; xVariation < 6; xVariation++) {
    76    for (yVariation = 0; yVariation < 6; yVariation++) {
    77     switch(xVariation) {
    78      case 0:
    79       /* Zero X Position */  
    80       x = 0;
    81       break;
    82      case 1:
    83       /* Random X position inside screen */  
    84       x = SDLTest_RandomIntegerInRange(1, 100);
    85       break;
    86      case 2:
    87       /* Random X position outside screen (positive) */  
    88       x = SDLTest_RandomIntegerInRange(10000, 11000);
    89       break;
    90      case 3:
    91       /* Random X position outside screen (negative) */  
    92       x = SDLTest_RandomIntegerInRange(-1000, -100);
    93       break;
    94      case 4:
    95       /* Centered X position */  
    96       x = SDL_WINDOWPOS_CENTERED;
    97       break;
    98      case 5:
    99       /* Undefined X position */  
   100       x = SDL_WINDOWPOS_UNDEFINED;
   101       break;
   102     }
   103 
   104     switch(yVariation) {
   105      case 0:
   106       /* Zero X Position */  
   107       y = 0;
   108       break;
   109      case 1:
   110       /* Random X position inside screen */  
   111       y = SDLTest_RandomIntegerInRange(1, 100);
   112       break;
   113      case 2:
   114       /* Random X position outside screen (positive) */  
   115       y = SDLTest_RandomIntegerInRange(10000, 11000);
   116       break;
   117      case 3:
   118       /* Random Y position outside screen (negative) */  
   119       y = SDLTest_RandomIntegerInRange(-1000, -100);
   120       break;
   121      case 4:
   122       /* Centered Y position */  
   123       y = SDL_WINDOWPOS_CENTERED;
   124       break;
   125      case 5:
   126       /* Undefined Y position */  
   127       y = SDL_WINDOWPOS_UNDEFINED;
   128       break;
   129     }
   130      
   131     w = SDLTest_RandomIntegerInRange(32, 96);
   132     h = SDLTest_RandomIntegerInRange(32, 96);
   133     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);
   135     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   136     if (window != NULL) {
   137       SDL_DestroyWindow(window);
   138       SDLTest_AssertPass("Call to SDL_DestroyWindow");
   139     }
   140    }
   141   } 
   142 
   143   return TEST_COMPLETED;
   144 }
   145 
   146 /**
   147  * @brief Tests the functionality of the SDL_CreateWindow function using different sizes
   148  */
   149 int
   150 video_createWindowVariousSizes(void *arg)
   151 {
   152   SDL_Window* window;
   153   const char* title = "video_createWindowVariousSizes Test Window";
   154   int x, y, w, h;
   155   int wVariation, hVariation;
   156   
   157   x = SDLTest_RandomIntegerInRange(1, 100);
   158   y = SDLTest_RandomIntegerInRange(1, 100);
   159   for (wVariation = 0; wVariation < 3; wVariation++) {
   160    for (hVariation = 0; hVariation < 3; hVariation++) {
   161     switch(wVariation) {
   162      case 0:
   163       /* Width of 1 */  
   164       w = 1;
   165       break;
   166      case 1:
   167       /* Random "normal" width */  
   168       w = SDLTest_RandomIntegerInRange(320, 1920);
   169       break;
   170      case 2:
   171       /* Random "large" width */  
   172       w = SDLTest_RandomIntegerInRange(2048, 4095);
   173       break;
   174     }
   175 
   176     switch(hVariation) {
   177      case 0:
   178       /* Height of 1 */  
   179       h = 1;
   180       break;
   181      case 1:
   182       /* Random "normal" height */  
   183       h = SDLTest_RandomIntegerInRange(320, 1080);
   184       break;
   185      case 2:
   186       /* Random "large" height */  
   187       h = SDLTest_RandomIntegerInRange(2048, 4095);
   188       break;
   189      }
   190      
   191     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);
   193     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   194     if (window != NULL) {
   195       SDL_DestroyWindow(window);
   196       SDLTest_AssertPass("Call to SDL_DestroyWindow");
   197     }
   198    }
   199   }  
   200 
   201   return TEST_COMPLETED;
   202 }
   203 
   204 /**
   205  * @brief Tests the functionality of the SDL_CreateWindow function using different flags
   206  */
   207 int
   208 video_createWindowVariousFlags(void *arg)
   209 {
   210   SDL_Window* window;
   211   const char* title = "video_createWindowVariousFlags Test Window";
   212   int x, y, w, h;
   213   int fVariation;
   214   SDL_WindowFlags flags;
   215   
   216   /* Standard window */
   217   x = SDLTest_RandomIntegerInRange(1, 100);
   218   y = SDLTest_RandomIntegerInRange(1, 100);
   219   w = SDLTest_RandomIntegerInRange(320, 1024);
   220   h = SDLTest_RandomIntegerInRange(320, 768);
   221 
   222   for (fVariation = 0; fVariation < 13; fVariation++) {
   223     switch(fVariation) {
   224      case 0:
   225       flags = SDL_WINDOW_FULLSCREEN;
   226       /* Skip - blanks screen; comment out next line to run test */
   227       continue;   
   228       break;
   229      case 1:
   230       flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
   231       /* Skip - blanks screen; comment out next line to run test */
   232       continue;  
   233       break;
   234      case 2:
   235       flags = SDL_WINDOW_OPENGL;
   236       break;  
   237      case 3:
   238       flags = SDL_WINDOW_SHOWN;
   239       break;   
   240      case 4:    
   241       flags = SDL_WINDOW_HIDDEN;
   242       break;     
   243      case 5:
   244       flags = SDL_WINDOW_BORDERLESS;
   245       break;       
   246      case 6:
   247       flags = SDL_WINDOW_RESIZABLE;
   248       break;         
   249      case 7:
   250       flags = SDL_WINDOW_MINIMIZED;
   251       break;           
   252      case 8:
   253       flags = SDL_WINDOW_MAXIMIZED;
   254       break;
   255      case 9: 
   256       flags = SDL_WINDOW_INPUT_GRABBED;
   257       break;
   258      case 10:              
   259       flags = SDL_WINDOW_INPUT_FOCUS;
   260       break;                 
   261      case 11:                      
   262       flags = SDL_WINDOW_MOUSE_FOCUS;
   263       break;
   264      case 12: 
   265       flags = SDL_WINDOW_FOREIGN;
   266       break;
   267     }
   268        
   269     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);
   271     SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   272     if (window != NULL) {
   273       SDL_DestroyWindow(window);
   274       SDLTest_AssertPass("Call to SDL_DestroyWindow");
   275     }   
   276   }
   277 
   278   return TEST_COMPLETED;
   279 }
   280 
   281 /**
   282  * @brief Tests the functionality of the SDL_GetWindowFlags function
   283  */
   284 int
   285 video_getWindowFlags(void *arg)
   286 {
   287   SDL_Window* window;
   288   const char* title = "video_getWindowFlags Test Window";
   289   int x, y, w, h;
   290   SDL_WindowFlags flags;
   291   Uint32 actualFlags;
   292   
   293   /* Standard 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;
   301   
   302   window = SDL_CreateWindow(title, x, y, w, h, flags);
   303   SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
   304   SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
   305   if (window != NULL) {
   306       actualFlags = SDL_GetWindowFlags(window);
   307       SDLTest_AssertPass("Call to SDL_GetWindowFlags");
   308       SDLTest_AssertCheck((flags & actualFlags) == flags, "Verify returned value has flags %d set, got: %d", flags, actualFlags);
   309       SDL_DestroyWindow(window);
   310       SDLTest_AssertPass("Call to SDL_DestroyWindow");  
   311   }
   312 
   313   return TEST_COMPLETED;
   314 }
   315 
   316 /* ================= Test References ================== */
   317 
   318 /* Video test cases */
   319 static const SDLTest_TestCaseReference videoTest1 =
   320 		{ (SDLTest_TestCaseFp)video_enableDisableScreensaver, "video_enableDisableScreensaver",  "Enable and disable screenaver while checking state", TEST_ENABLED };
   321 
   322 static const SDLTest_TestCaseReference videoTest2 =
   323 		{ (SDLTest_TestCaseFp)video_createWindowVariousPositions, "video_createWindowVariousPositions",  "Create windows at various locations", TEST_ENABLED };
   324 
   325 static const SDLTest_TestCaseReference videoTest3 =
   326 		{ (SDLTest_TestCaseFp)video_createWindowVariousSizes, "video_createWindowVariousSizes",  "Create windows with various sizes", TEST_ENABLED };
   327 
   328 static const SDLTest_TestCaseReference videoTest4 =
   329 		{ (SDLTest_TestCaseFp)video_createWindowVariousFlags, "video_createWindowVariousFlags",  "Create windows using various flags", TEST_ENABLED };
   330 
   331 static const SDLTest_TestCaseReference videoTest5 =
   332 		{ (SDLTest_TestCaseFp)video_getWindowFlags, "video_getWindowFlags",  "Set and get window flags", TEST_ENABLED };
   333 
   334 /* Sequence of Video test cases */
   335 static const SDLTest_TestCaseReference *videoTests[] =  {
   336 	&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, NULL
   337 };
   338 
   339 /* Video test suite (global) */
   340 SDLTest_TestSuiteReference videoTestSuite = {
   341 	"Video",
   342 	NULL,
   343 	videoTests,
   344 	NULL
   345 };