Add new test suite (mouse) with a few new tests
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sun, 06 Jan 2013 18:19:30 -0800
changeset 6801f92e3d5f71a2
parent 6800 26c6795ec1a4
child 6802 8a6b8ce97656
child 6803 fbe83a6d10fa
Add new test suite (mouse) with a few new tests
VisualC/tests/testautomation/testautomation_vs2010.vcxproj
VisualC/tests/testautomation/testautomation_vs2012.vcxproj
test/Makefile.in
test/testautomation_mouse.c
test/testautomation_suites.h
     1.1 --- a/VisualC/tests/testautomation/testautomation_vs2010.vcxproj	Sun Jan 06 15:17:59 2013 -0800
     1.2 +++ b/VisualC/tests/testautomation/testautomation_vs2010.vcxproj	Sun Jan 06 18:19:30 2013 -0800
     1.3 @@ -188,6 +188,7 @@
     1.4      <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
     1.5      <ClCompile Include="..\..\..\test\testautomation_video.c" />
     1.6      <ClCompile Include="..\..\..\test\testautomation_syswm.c" />
     1.7 +    <ClCompile Include="..\..\..\test\testautomation_mouse.c" />
     1.8    </ItemGroup>
     1.9    <ItemGroup>
    1.10      <ClInclude Include="..\..\..\test\testautomation_suites.h" />
     2.1 --- a/VisualC/tests/testautomation/testautomation_vs2012.vcxproj	Sun Jan 06 15:17:59 2013 -0800
     2.2 +++ b/VisualC/tests/testautomation/testautomation_vs2012.vcxproj	Sun Jan 06 18:19:30 2013 -0800
     2.3 @@ -192,6 +192,7 @@
     2.4      <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
     2.5      <ClCompile Include="..\..\..\test\testautomation_video.c" />
     2.6      <ClCompile Include="..\..\..\test\testautomation_syswm.c" />
     2.7 +    <ClCompile Include="..\..\..\test\testautomation_mouse.c" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <ClInclude Include="..\..\..\test\testautomation_suites.h" />
     3.1 --- a/test/Makefile.in	Sun Jan 06 15:17:59 2013 -0800
     3.2 +++ b/test/Makefile.in	Sun Jan 06 18:19:30 2013 -0800
     3.3 @@ -79,7 +79,8 @@
     3.4  		      $(srcdir)/testautomation_events.c \
     3.5  		      $(srcdir)/testautomation_keyboard.c \
     3.6  		      $(srcdir)/testautomation_video.c \
     3.7 -		      $(srcdir)/testautomation_syswm.c
     3.8 +		      $(srcdir)/testautomation_syswm.c \
     3.9 +		      $(srcdir)/testautomation_mouse.c
    3.10  	$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS) 
    3.11  
    3.12  testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/testautomation_mouse.c	Sun Jan 06 18:19:30 2013 -0800
     4.3 @@ -0,0 +1,331 @@
     4.4 +/**
     4.5 + * Mouse test suite
     4.6 + */
     4.7 +
     4.8 +#include <stdio.h>
     4.9 +#include <limits.h>
    4.10 +
    4.11 +#include "SDL.h"
    4.12 +#include "SDL_test.h"
    4.13 +
    4.14 +/* ================= Test Case Implementation ================== */
    4.15 +
    4.16 +/* Test case functions */
    4.17 +
    4.18 +/* Helper to evaluate state returned from SDL_GetMouseState */
    4.19 +int _mouseStateCheck(Uint8 state)
    4.20 +{
    4.21 +  return (state == 0) || 
    4.22 +         SDL_BUTTON(SDL_BUTTON_LEFT) || 
    4.23 +         SDL_BUTTON(SDL_BUTTON_MIDDLE) || 
    4.24 +         SDL_BUTTON(SDL_BUTTON_RIGHT) || 
    4.25 +         SDL_BUTTON(SDL_BUTTON_X1) || 
    4.26 +         SDL_BUTTON(SDL_BUTTON_X2);
    4.27 +}
    4.28 +
    4.29 +/**
    4.30 + * @brief Check call to SDL_GetMouseState
    4.31 + * 
    4.32 + */
    4.33 +int
    4.34 +mouse_getMouseState(void *arg)
    4.35 +{
    4.36 +   int x;
    4.37 +   int y;
    4.38 +   Uint8 state;
    4.39 +
    4.40 +   /* Pump some events to update mouse state */
    4.41 +   SDL_PumpEvents();
    4.42 +   SDLTest_AssertPass("Call to SDL_PumpEvents()");
    4.43 +
    4.44 +   /* Case where x, y pointer is NULL */    
    4.45 +   state = SDL_GetMouseState(NULL, NULL);
    4.46 +   SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, NULL)");
    4.47 +   SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
    4.48 +
    4.49 +   /* Case where x pointer is not NULL */
    4.50 +   x = INT_MIN;
    4.51 +   state = SDL_GetMouseState(&x, NULL);
    4.52 +   SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)");
    4.53 +   SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
    4.54 +   SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
    4.55 +
    4.56 +   /* Case where y pointer is not NULL */
    4.57 +   y = INT_MIN;
    4.58 +   state = SDL_GetMouseState(NULL, &y);
    4.59 +   SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)");
    4.60 +   SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
    4.61 +   SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
    4.62 +
    4.63 +   /* Case where x and y pointer is not NULL */
    4.64 +   x = INT_MIN;
    4.65 +   y = INT_MIN;
    4.66 +   state = SDL_GetMouseState(&x, &y);
    4.67 +   SDLTest_AssertPass("Call to SDL_GetMouseState(&x, &y)");
    4.68 +   SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
    4.69 +   SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
    4.70 +   SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
    4.71 +   
    4.72 +   return TEST_COMPLETED;
    4.73 +}
    4.74 +
    4.75 +/**
    4.76 + * @brief Check call to SDL_GetRelativeMouseState
    4.77 + * 
    4.78 + */
    4.79 +int
    4.80 +mouse_getRelativeMouseState(void *arg)
    4.81 +{
    4.82 +   int x;
    4.83 +   int y;
    4.84 +   Uint8 state;
    4.85 +
    4.86 +   /* Pump some events to update mouse state */
    4.87 +   SDL_PumpEvents();
    4.88 +   SDLTest_AssertPass("Call to SDL_PumpEvents()");
    4.89 +
    4.90 +   /* Case where x, y pointer is NULL */    
    4.91 +   state = SDL_GetRelativeMouseState(NULL, NULL);
    4.92 +   SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, NULL)");
    4.93 +   SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
    4.94 +
    4.95 +   /* Case where x pointer is not NULL */
    4.96 +   x = INT_MIN;
    4.97 +   state = SDL_GetRelativeMouseState(&x, NULL);
    4.98 +   SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)");
    4.99 +   SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
   4.100 +   SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
   4.101 +
   4.102 +   /* Case where y pointer is not NULL */
   4.103 +   y = INT_MIN;
   4.104 +   state = SDL_GetRelativeMouseState(NULL, &y);
   4.105 +   SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)");
   4.106 +   SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
   4.107 +   SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
   4.108 +
   4.109 +   /* Case where x and y pointer is not NULL */
   4.110 +   x = INT_MIN;
   4.111 +   y = INT_MIN;
   4.112 +   state = SDL_GetRelativeMouseState(&x, &y);
   4.113 +   SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, &y)");
   4.114 +   SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
   4.115 +   SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
   4.116 +   SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
   4.117 +   
   4.118 +   return TEST_COMPLETED;
   4.119 +}
   4.120 +
   4.121 +
   4.122 +/* XPM definition of mouse Cursor */
   4.123 +static const char *_mouseArrowData[] = {
   4.124 +  /* pixels */
   4.125 +  "X                               ",
   4.126 +  "XX                              ",
   4.127 +  "X.X                             ",
   4.128 +  "X..X                            ",
   4.129 +  "X...X                           ",
   4.130 +  "X....X                          ",
   4.131 +  "X.....X                         ",
   4.132 +  "X......X                        ",
   4.133 +  "X.......X                       ",
   4.134 +  "X........X                      ",
   4.135 +  "X.....XXXXX                     ",
   4.136 +  "X..X..X                         ",
   4.137 +  "X.X X..X                        ",
   4.138 +  "XX  X..X                        ",
   4.139 +  "X    X..X                       ",
   4.140 +  "     X..X                       ",
   4.141 +  "      X..X                      ",
   4.142 +  "      X..X                      ",
   4.143 +  "       XX                       ",
   4.144 +  "                                ",
   4.145 +  "                                ",
   4.146 +  "                                ",
   4.147 +  "                                ",
   4.148 +  "                                ",
   4.149 +  "                                ",
   4.150 +  "                                ",
   4.151 +  "                                ",
   4.152 +  "                                ",
   4.153 +  "                                ",
   4.154 +  "                                ",
   4.155 +  "                                ",
   4.156 +  "                                "
   4.157 +};
   4.158 +
   4.159 +/* Helper that creates a new mouse cursor from an XPM */
   4.160 +static SDL_Cursor *_initArrowCursor(const char *image[])
   4.161 +{
   4.162 +  SDL_Cursor *cursor;
   4.163 +  int i, row, col;
   4.164 +  Uint8 data[4*32];
   4.165 +  Uint8 mask[4*32];
   4.166 +
   4.167 +  i = -1;
   4.168 +  for ( row=0; row<32; ++row ) {
   4.169 +    for ( col=0; col<32; ++col ) {
   4.170 +      if ( col % 8 ) {
   4.171 +        data[i] <<= 1;
   4.172 +        mask[i] <<= 1;
   4.173 +      } else {
   4.174 +        ++i;
   4.175 +        data[i] = mask[i] = 0;
   4.176 +      }
   4.177 +      switch (image[row][col]) {
   4.178 +        case 'X':
   4.179 +          data[i] |= 0x01;
   4.180 +          mask[i] |= 0x01;
   4.181 +          break;
   4.182 +        case '.':
   4.183 +          mask[i] |= 0x01;
   4.184 +          break;
   4.185 +        case ' ':
   4.186 +          break;
   4.187 +      }
   4.188 +    }
   4.189 +  }
   4.190 +
   4.191 +  cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
   4.192 +  return cursor;
   4.193 +}
   4.194 +
   4.195 +/**
   4.196 + * @brief Check call to SDL_CreateCursor and SDL_FreeCursor
   4.197 + * 
   4.198 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateCursor
   4.199 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
   4.200 + */
   4.201 +int
   4.202 +mouse_createFreeCursor(void *arg)
   4.203 +{
   4.204 +	SDL_Cursor *cursor;	
   4.205 +
   4.206 +	/* Create a cursor */
   4.207 +	cursor = _initArrowCursor(_mouseArrowData);
   4.208 +    SDLTest_AssertPass("Call to SDL_CreateCursor()");
   4.209 +    SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");	
   4.210 +	if (cursor == NULL) {
   4.211 +		return TEST_ABORTED;
   4.212 +	}
   4.213 +
   4.214 +	/* Free cursor again */
   4.215 +	SDL_FreeCursor(cursor);
   4.216 +	SDLTest_AssertPass("Call to SDL_FreeCursor()");
   4.217 +
   4.218 +	return TEST_COMPLETED;
   4.219 +}
   4.220 +
   4.221 +/* Helper that changes cursor visibility */
   4.222 +void _changeCursorVisibility(int state)
   4.223 +{
   4.224 +	int oldState;
   4.225 +	int newState;
   4.226 +	int result;
   4.227 +
   4.228 +    oldState = SDL_ShowCursor(SDL_QUERY);
   4.229 +	SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
   4.230 +
   4.231 +    result = SDL_ShowCursor(state);
   4.232 +	SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE");
   4.233 +	SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i", 
   4.234 +		(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
   4.235 +    
   4.236 +	newState = SDL_ShowCursor(SDL_QUERY);
   4.237 +	SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
   4.238 +	SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i", 
   4.239 +		state, newState);
   4.240 +}
   4.241 +
   4.242 +/**
   4.243 + * @brief Check call to SDL_ShowCursor
   4.244 + * 
   4.245 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_ShowCursor
   4.246 + */
   4.247 +int
   4.248 +mouse_showCursor(void *arg)
   4.249 +{
   4.250 +	int currentState;
   4.251 +
   4.252 +	/* Get current state */
   4.253 +	currentState = SDL_ShowCursor(SDL_QUERY);
   4.254 +	SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
   4.255 +	SDLTest_AssertCheck(currentState == SDL_DISABLE || currentState == SDL_ENABLE, 
   4.256 +		"Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState);
   4.257 +	if (currentState == SDL_DISABLE) {
   4.258 +		/* Show the cursor, then hide it again */
   4.259 +		_changeCursorVisibility(SDL_ENABLE);
   4.260 +		_changeCursorVisibility(SDL_DISABLE);
   4.261 +	} else if (currentState == SDL_ENABLE) {
   4.262 +		/* Hide the cursor, then show it again */
   4.263 +		_changeCursorVisibility(SDL_DISABLE);
   4.264 +		_changeCursorVisibility(SDL_ENABLE);
   4.265 +	} else {
   4.266 +		return TEST_ABORTED;
   4.267 +	}
   4.268 +
   4.269 +	return TEST_COMPLETED;
   4.270 +}
   4.271 +
   4.272 +/**
   4.273 + * @brief Check call to SDL_SetCursor
   4.274 + * 
   4.275 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetCursor
   4.276 + */
   4.277 +int
   4.278 +mouse_setCursor(void *arg)
   4.279 +{
   4.280 +	SDL_Cursor *cursor;	
   4.281 +
   4.282 +	/* Create a cursor */
   4.283 +	cursor = _initArrowCursor(_mouseArrowData);
   4.284 +    SDLTest_AssertPass("Call to SDL_CreateCursor()");
   4.285 +    SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");	
   4.286 +	if (cursor == NULL) {
   4.287 +		return TEST_ABORTED;
   4.288 +	}
   4.289 +
   4.290 +	/* Set the arrow cursor */
   4.291 +	SDL_SetCursor(cursor);
   4.292 +	SDLTest_AssertPass("Call to SDL_SetCursor(cursor)");
   4.293 +
   4.294 +	/* Force redraw */
   4.295 +	SDL_SetCursor(NULL);
   4.296 +	SDLTest_AssertPass("Call to SDL_SetCursor(NULL)");
   4.297 +
   4.298 +	/* Free cursor again */
   4.299 +	SDL_FreeCursor(cursor);
   4.300 +	SDLTest_AssertPass("Call to SDL_FreeCursor()");
   4.301 +
   4.302 +	return TEST_COMPLETED;
   4.303 +}
   4.304 +
   4.305 +/* ================= Test References ================== */
   4.306 +
   4.307 +/* Mouse test cases */
   4.308 +static const SDLTest_TestCaseReference mouseTest1 =
   4.309 +		{ (SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED };
   4.310 +
   4.311 +static const SDLTest_TestCaseReference mouseTest2 =
   4.312 +		{ (SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED };
   4.313 +
   4.314 +static const SDLTest_TestCaseReference mouseTest3 =
   4.315 +		{ (SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED };
   4.316 +
   4.317 +static const SDLTest_TestCaseReference mouseTest4 =
   4.318 +		{ (SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED };
   4.319 +
   4.320 +static const SDLTest_TestCaseReference mouseTest5 =
   4.321 +		{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED };
   4.322 +
   4.323 +/* Sequence of Mouse test cases */
   4.324 +static const SDLTest_TestCaseReference *mouseTests[] =  {
   4.325 +	&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, NULL
   4.326 +};
   4.327 +
   4.328 +/* Mouse test suite (global) */
   4.329 +SDLTest_TestSuiteReference mouseTestSuite = {
   4.330 +	"Mouse",
   4.331 +	NULL,
   4.332 +	mouseTests,
   4.333 +	NULL
   4.334 +};
     5.1 --- a/test/testautomation_suites.h	Sun Jan 06 15:17:59 2013 -0800
     5.2 +++ b/test/testautomation_suites.h	Sun Jan 06 18:19:30 2013 -0800
     5.3 @@ -20,6 +20,7 @@
     5.4  extern SDLTest_TestSuiteReference surfaceTestSuite;
     5.5  extern SDLTest_TestSuiteReference syswmTestSuite;
     5.6  extern SDLTest_TestSuiteReference videoTestSuite;
     5.7 +extern SDLTest_TestSuiteReference mouseTestSuite;
     5.8  
     5.9  // All test suites
    5.10  SDLTest_TestSuiteReference *testSuites[] =  {
    5.11 @@ -34,6 +35,7 @@
    5.12  	&surfaceTestSuite,
    5.13  	&syswmTestSuite,
    5.14  	&videoTestSuite,
    5.15 +	&mouseTestSuite,
    5.16  	NULL
    5.17  };
    5.18