Add tests to mouse suite; fix VS compiler warnings in tests
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Wed, 23 Jan 2013 08:03:19 -0800
changeset 6821f36771112651
parent 6820 0ce561f6c805
child 6822 18f6818ba281
Add tests to mouse suite; fix VS compiler warnings in tests
test/testautomation_audio.c
test/testautomation_mouse.c
test/testautomation_rwops.c
     1.1 --- a/test/testautomation_audio.c	Thu Jan 17 11:54:14 2013 +0000
     1.2 +++ b/test/testautomation_audio.c	Wed Jan 23 08:03:19 2013 -0800
     1.3 @@ -3,6 +3,9 @@
     1.4   * New/updated tests: aschiffler at ferzkopp dot net
     1.5   */
     1.6  
     1.7 +/* quiet windows compiler warnings */
     1.8 +#define _CRT_SECURE_NO_WARNINGS
     1.9 +
    1.10  #include <stdio.h>
    1.11  #include <string.h>
    1.12  
     2.1 --- a/test/testautomation_mouse.c	Thu Jan 17 11:54:14 2013 +0000
     2.2 +++ b/test/testautomation_mouse.c	Wed Jan 23 08:03:19 2013 -0800
     2.3 @@ -115,79 +115,79 @@
     2.4     return TEST_COMPLETED;
     2.5  }
     2.6  
     2.7 -
     2.8 -/* XPM definition of mouse Cursor */
     2.9 -static const char *_mouseArrowData[] = {
    2.10 -  /* pixels */
    2.11 -  "X                               ",
    2.12 -  "XX                              ",
    2.13 -  "X.X                             ",
    2.14 -  "X..X                            ",
    2.15 -  "X...X                           ",
    2.16 -  "X....X                          ",
    2.17 -  "X.....X                         ",
    2.18 -  "X......X                        ",
    2.19 -  "X.......X                       ",
    2.20 -  "X........X                      ",
    2.21 -  "X.....XXXXX                     ",
    2.22 -  "X..X..X                         ",
    2.23 -  "X.X X..X                        ",
    2.24 -  "XX  X..X                        ",
    2.25 -  "X    X..X                       ",
    2.26 -  "     X..X                       ",
    2.27 -  "      X..X                      ",
    2.28 -  "      X..X                      ",
    2.29 -  "       XX                       ",
    2.30 -  "                                ",
    2.31 -  "                                ",
    2.32 -  "                                ",
    2.33 -  "                                ",
    2.34 -  "                                ",
    2.35 -  "                                ",
    2.36 -  "                                ",
    2.37 -  "                                ",
    2.38 -  "                                ",
    2.39 -  "                                ",
    2.40 -  "                                ",
    2.41 -  "                                ",
    2.42 -  "                                "
    2.43 -};
    2.44 -
    2.45 -/* Helper that creates a new mouse cursor from an XPM */
    2.46 -static SDL_Cursor *_initArrowCursor(const char *image[])
    2.47 -{
    2.48 -  SDL_Cursor *cursor;
    2.49 -  int i, row, col;
    2.50 -  Uint8 data[4*32];
    2.51 -  Uint8 mask[4*32];
    2.52 -
    2.53 -  i = -1;
    2.54 -  for ( row=0; row<32; ++row ) {
    2.55 -    for ( col=0; col<32; ++col ) {
    2.56 -      if ( col % 8 ) {
    2.57 -        data[i] <<= 1;
    2.58 -        mask[i] <<= 1;
    2.59 -      } else {
    2.60 -        ++i;
    2.61 -        data[i] = mask[i] = 0;
    2.62 -      }
    2.63 -      switch (image[row][col]) {
    2.64 -        case 'X':
    2.65 -          data[i] |= 0x01;
    2.66 -          mask[i] |= 0x01;
    2.67 -          break;
    2.68 -        case '.':
    2.69 -          mask[i] |= 0x01;
    2.70 -          break;
    2.71 -        case ' ':
    2.72 -          break;
    2.73 -      }
    2.74 -    }
    2.75 -  }
    2.76 -
    2.77 -  cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
    2.78 -  return cursor;
    2.79 -}
    2.80 +
    2.81 +/* XPM definition of mouse Cursor */
    2.82 +static const char *_mouseArrowData[] = {
    2.83 +  /* pixels */
    2.84 +  "X                               ",
    2.85 +  "XX                              ",
    2.86 +  "X.X                             ",
    2.87 +  "X..X                            ",
    2.88 +  "X...X                           ",
    2.89 +  "X....X                          ",
    2.90 +  "X.....X                         ",
    2.91 +  "X......X                        ",
    2.92 +  "X.......X                       ",
    2.93 +  "X........X                      ",
    2.94 +  "X.....XXXXX                     ",
    2.95 +  "X..X..X                         ",
    2.96 +  "X.X X..X                        ",
    2.97 +  "XX  X..X                        ",
    2.98 +  "X    X..X                       ",
    2.99 +  "     X..X                       ",
   2.100 +  "      X..X                      ",
   2.101 +  "      X..X                      ",
   2.102 +  "       XX                       ",
   2.103 +  "                                ",
   2.104 +  "                                ",
   2.105 +  "                                ",
   2.106 +  "                                ",
   2.107 +  "                                ",
   2.108 +  "                                ",
   2.109 +  "                                ",
   2.110 +  "                                ",
   2.111 +  "                                ",
   2.112 +  "                                ",
   2.113 +  "                                ",
   2.114 +  "                                ",
   2.115 +  "                                "
   2.116 +};
   2.117 +
   2.118 +/* Helper that creates a new mouse cursor from an XPM */
   2.119 +static SDL_Cursor *_initArrowCursor(const char *image[])
   2.120 +{
   2.121 +  SDL_Cursor *cursor;
   2.122 +  int i, row, col;
   2.123 +  Uint8 data[4*32];
   2.124 +  Uint8 mask[4*32];
   2.125 +
   2.126 +  i = -1;
   2.127 +  for ( row=0; row<32; ++row ) {
   2.128 +    for ( col=0; col<32; ++col ) {
   2.129 +      if ( col % 8 ) {
   2.130 +        data[i] <<= 1;
   2.131 +        mask[i] <<= 1;
   2.132 +      } else {
   2.133 +        ++i;
   2.134 +        data[i] = mask[i] = 0;
   2.135 +      }
   2.136 +      switch (image[row][col]) {
   2.137 +        case 'X':
   2.138 +          data[i] |= 0x01;
   2.139 +          mask[i] |= 0x01;
   2.140 +          break;
   2.141 +        case '.':
   2.142 +          mask[i] |= 0x01;
   2.143 +          break;
   2.144 +        case ' ':
   2.145 +          break;
   2.146 +      }
   2.147 +    }
   2.148 +  }
   2.149 +
   2.150 +  cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
   2.151 +  return cursor;
   2.152 +}
   2.153  
   2.154  /**
   2.155   * @brief Check call to SDL_CreateCursor and SDL_FreeCursor
   2.156 @@ -202,8 +202,8 @@
   2.157  
   2.158  	/* Create a cursor */
   2.159  	cursor = _initArrowCursor(_mouseArrowData);
   2.160 -    SDLTest_AssertPass("Call to SDL_CreateCursor()");
   2.161 -    SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");	
   2.162 +        SDLTest_AssertPass("Call to SDL_CreateCursor()");
   2.163 +        SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");	
   2.164  	if (cursor == NULL) {
   2.165  		return TEST_ABORTED;
   2.166  	}
   2.167 @@ -222,10 +222,10 @@
   2.168  	int newState;
   2.169  	int result;
   2.170  
   2.171 -    oldState = SDL_ShowCursor(SDL_QUERY);
   2.172 +        oldState = SDL_ShowCursor(SDL_QUERY);
   2.173  	SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
   2.174  
   2.175 -    result = SDL_ShowCursor(state);
   2.176 +        result = SDL_ShowCursor(state);
   2.177  	SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE");
   2.178  	SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i", 
   2.179  		(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
   2.180 @@ -278,18 +278,18 @@
   2.181  
   2.182  	/* Create a cursor */
   2.183  	cursor = _initArrowCursor(_mouseArrowData);
   2.184 -    SDLTest_AssertPass("Call to SDL_CreateCursor()");
   2.185 -    SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");	
   2.186 +        SDLTest_AssertPass("Call to SDL_CreateCursor()");
   2.187 +        SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");	
   2.188  	if (cursor == NULL) {
   2.189  		return TEST_ABORTED;
   2.190  	}
   2.191  
   2.192  	/* Set the arrow cursor */
   2.193 -	SDL_SetCursor(cursor);
   2.194 +	SDL_SetCursor(cursor);
   2.195  	SDLTest_AssertPass("Call to SDL_SetCursor(cursor)");
   2.196  
   2.197  	/* Force redraw */
   2.198 -	SDL_SetCursor(NULL);
   2.199 +	SDL_SetCursor(NULL);
   2.200  	SDLTest_AssertPass("Call to SDL_SetCursor(NULL)");
   2.201  
   2.202  	/* Free cursor again */
   2.203 @@ -299,6 +299,143 @@
   2.204  	return TEST_COMPLETED;
   2.205  }
   2.206  
   2.207 +#define MOUSE_TESTWINDOW_WIDTH	320
   2.208 +#define MOUSE_TESTWINDOW_HEIGHT 200
   2.209 +
   2.210 +/**
   2.211 + * Create s test window
   2.212 + */
   2.213 +SDL_Window *_createTestWindow()
   2.214 +{
   2.215 +  int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
   2.216 +  SDL_Window *window;
   2.217 +  window = SDL_CreateWindow("mouse_createTestWindow", posX, posY, width, height, 0);
   2.218 +  SDLTest_AssertPass("SDL_CreateWindow()");
   2.219 +  SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
   2.220 +  return window;
   2.221 +}
   2.222 +
   2.223 +/*
   2.224 + * Destroy test window  
   2.225 + */
   2.226 +void _destroyTestWindow(SDL_Window *window)
   2.227 +{
   2.228 +  if (window != NULL) {  
   2.229 +     SDL_DestroyWindow(window);
   2.230 +     window = NULL;
   2.231 +     SDLTest_AssertPass("SDL_DestroyWindow");
   2.232 +  }
   2.233 +}
   2.234 +
   2.235 +/**
   2.236 + * @brief Check call to SDL_WarpMouseInWindow
   2.237 + * 
   2.238 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_WarpMouseInWindow
   2.239 + */
   2.240 +int
   2.241 +mouse_warpMouseInWindow(void *arg)
   2.242 +{
   2.243 +  	const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
   2.244 +  	int numPositions = 6;
   2.245 +  	int xPositions[] = {-1, 0, 1, w-1, w, w+1 };  
   2.246 +  	int yPositions[] = {-1, 0, 1, h-1, h, h+1 };
   2.247 +	int x, y, i, j;
   2.248 +	SDL_Window *window;
   2.249 +	
   2.250 +	/* Create test window */
   2.251 +	window = _createTestWindow();
   2.252 +	if (window == NULL) return TEST_ABORTED;
   2.253 +
   2.254 +	/* Mouse to random position inside window */	
   2.255 +	x = SDLTest_RandomIntegerInRange(1, w-1);
   2.256 +	y = SDLTest_RandomIntegerInRange(1, h-1);
   2.257 +	SDL_WarpMouseInWindow(window, x, y);
   2.258 +	SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
   2.259 +
   2.260 +        /* Same position again */
   2.261 +   	SDL_WarpMouseInWindow(window, x, y);
   2.262 +	SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
   2.263 +
   2.264 +	/* Mouse to various boundary positions */
   2.265 +	for (i=0; i<numPositions; i++) {	
   2.266 +	  for (j=0; j<numPositions; j++) {	
   2.267 +	    x = xPositions[i];
   2.268 +	    y = yPositions[j];
   2.269 +	    SDL_WarpMouseInWindow(window, x, y);
   2.270 +	    SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
   2.271 +
   2.272 +	    /* TODO: add tracking of events and check that each call generates a mouse motion event */
   2.273 +	    SDL_PumpEvents();
   2.274 +	    SDLTest_AssertPass("SDL_PumpEvents()");
   2.275 +	  }
   2.276 +	}
   2.277 +	
   2.278 +
   2.279 +        /* Clean up test window */	
   2.280 +	_destroyTestWindow(window);
   2.281 +	
   2.282 +	return TEST_COMPLETED;
   2.283 +}
   2.284 +
   2.285 +/**
   2.286 + * @brief Check call to SDL_GetMouseFocus
   2.287 + * 
   2.288 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetMouseFocus
   2.289 + */
   2.290 +int
   2.291 +mouse_getMouseFocus(void *arg)
   2.292 +{
   2.293 +  	const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
   2.294 +  	int x, y;
   2.295 +	SDL_Window *window;
   2.296 +	SDL_Window *focusWindow;	
   2.297 +
   2.298 +	/* Get focus - focus non-deterministic */
   2.299 +	focusWindow = SDL_GetMouseFocus();
   2.300 +	SDLTest_AssertPass("SDL_GetMouseFocus()");
   2.301 +
   2.302 +        /* Create test window */	
   2.303 +	window = _createTestWindow();
   2.304 +	if (window == NULL) return TEST_ABORTED;
   2.305 +
   2.306 +	/* Mouse to random position inside window */	
   2.307 +	x = SDLTest_RandomIntegerInRange(1, w-1);
   2.308 +	y = SDLTest_RandomIntegerInRange(1, h-1);
   2.309 +	SDL_WarpMouseInWindow(window, x, y);
   2.310 +	SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
   2.311 +
   2.312 +	/* Pump events to update focus state */
   2.313 +	SDL_PumpEvents();
   2.314 +	SDLTest_AssertPass("SDL_PumpEvents()");
   2.315 +
   2.316 +        /* Get focus with explicit window setup - focus deterministic */	
   2.317 +	focusWindow = SDL_GetMouseFocus();
   2.318 +	SDLTest_AssertPass("SDL_GetMouseFocus()");
   2.319 +	SDLTest_AssertCheck (focusWindow != NULL, "Check returned window value is not NULL");
   2.320 +	SDLTest_AssertCheck (focusWindow == window, "Check returned window value is test window");
   2.321 +
   2.322 +	/* Mouse to random position outside window */	
   2.323 +	x = SDLTest_RandomIntegerInRange(-9, -1);
   2.324 +	y = SDLTest_RandomIntegerInRange(-9, -1);
   2.325 +	SDL_WarpMouseInWindow(window, x, y);
   2.326 +	SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
   2.327 +
   2.328 +        /* Clean up test window */	
   2.329 +	_destroyTestWindow(window);
   2.330 +
   2.331 +	/* Pump events to update focus state */
   2.332 +	SDL_PumpEvents();
   2.333 +	SDLTest_AssertPass("SDL_PumpEvents()");
   2.334 +
   2.335 +        /* Get focus for non-existing window */	
   2.336 +	focusWindow = SDL_GetMouseFocus();
   2.337 +	SDLTest_AssertPass("SDL_GetMouseFocus()");
   2.338 +	SDLTest_AssertCheck (focusWindow == NULL, "Check returned window value is NULL");
   2.339 +
   2.340 +	
   2.341 +	return TEST_COMPLETED;
   2.342 +}
   2.343 +
   2.344  /* ================= Test References ================== */
   2.345  
   2.346  /* Mouse test cases */
   2.347 @@ -317,9 +454,15 @@
   2.348  static const SDLTest_TestCaseReference mouseTest5 =
   2.349  		{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED };
   2.350  
   2.351 +static const SDLTest_TestCaseReference mouseTest6 =
   2.352 +		{ (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED };
   2.353 +
   2.354 +static const SDLTest_TestCaseReference mouseTest7 =
   2.355 +		{ (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED };
   2.356 +
   2.357  /* Sequence of Mouse test cases */
   2.358  static const SDLTest_TestCaseReference *mouseTests[] =  {
   2.359 -	&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, NULL
   2.360 +	&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6, &mouseTest7, NULL
   2.361  };
   2.362  
   2.363  /* Mouse test suite (global) */
     3.1 --- a/test/testautomation_rwops.c	Thu Jan 17 11:54:14 2013 +0000
     3.2 +++ b/test/testautomation_rwops.c	Wed Jan 23 08:03:19 2013 -0800
     3.3 @@ -419,7 +419,7 @@
     3.4  rwops_testFileWriteReadEndian(void)
     3.5  {
     3.6     SDL_RWops *rw;
     3.7 -   int result;
     3.8 +   Sint64 result;
     3.9     int mode;
    3.10     size_t objectsWritten;
    3.11     Uint16 BE16value;