test/testautomation_mouse.c
changeset 6822 18f6818ba281
parent 6821 f36771112651
child 6921 9a29af9de577
     1.1 --- a/test/testautomation_mouse.c	Wed Jan 23 08:03:19 2013 -0800
     1.2 +++ b/test/testautomation_mouse.c	Thu Jan 24 07:58:59 2013 -0800
     1.3 @@ -16,11 +16,11 @@
     1.4  int _mouseStateCheck(Uint8 state)
     1.5  {
     1.6    return (state == 0) || 
     1.7 -         SDL_BUTTON(SDL_BUTTON_LEFT) || 
     1.8 -         SDL_BUTTON(SDL_BUTTON_MIDDLE) || 
     1.9 -         SDL_BUTTON(SDL_BUTTON_RIGHT) || 
    1.10 -         SDL_BUTTON(SDL_BUTTON_X1) || 
    1.11 -         SDL_BUTTON(SDL_BUTTON_X2);
    1.12 +         (state == SDL_BUTTON(SDL_BUTTON_LEFT)) || 
    1.13 +         (state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) || 
    1.14 +         (state == SDL_BUTTON(SDL_BUTTON_RIGHT)) || 
    1.15 +         (state == SDL_BUTTON(SDL_BUTTON_X1)) || 
    1.16 +         (state == SDL_BUTTON(SDL_BUTTON_X2));
    1.17  }
    1.18  
    1.19  /**
    1.20 @@ -215,6 +215,42 @@
    1.21  	return TEST_COMPLETED;
    1.22  }
    1.23  
    1.24 +/**
    1.25 + * @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor
    1.26 + * 
    1.27 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateColorCursor
    1.28 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
    1.29 + */
    1.30 +int
    1.31 +mouse_createFreeColorCursor(void *arg)
    1.32 +{
    1.33 +	SDL_Surface *face;
    1.34 +	SDL_Cursor *cursor;	
    1.35 +
    1.36 +	/* Get sample surface */
    1.37 +	face = SDLTest_ImageFace();
    1.38 +	SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
    1.39 +	if (face == NULL) return TEST_ABORTED; 
    1.40 +	
    1.41 +	/* Create a color cursor from surface */
    1.42 +	cursor = SDL_CreateColorCursor(face, 0, 0);
    1.43 +        SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
    1.44 +        SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");	
    1.45 +	if (cursor == NULL) {
    1.46 +		SDL_FreeSurface(face);
    1.47 +		return TEST_ABORTED;
    1.48 +	}
    1.49 +
    1.50 +	/* Free cursor again */
    1.51 +	SDL_FreeCursor(cursor);
    1.52 +	SDLTest_AssertPass("Call to SDL_FreeCursor()");
    1.53 +
    1.54 +	/* Clean up */
    1.55 +	SDL_FreeSurface(face);
    1.56 +	
    1.57 +	return TEST_COMPLETED;
    1.58 +}
    1.59 +
    1.60  /* Helper that changes cursor visibility */
    1.61  void _changeCursorVisibility(int state)
    1.62  {
    1.63 @@ -299,6 +335,80 @@
    1.64  	return TEST_COMPLETED;
    1.65  }
    1.66  
    1.67 +/**
    1.68 + * @brief Check call to SDL_GetCursor
    1.69 + * 
    1.70 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetCursor
    1.71 + */
    1.72 +int
    1.73 +mouse_getCursor(void *arg)
    1.74 +{
    1.75 +	SDL_Cursor *cursor;	
    1.76 +
    1.77 +	/* Get current cursor */
    1.78 +	cursor = SDL_GetCursor();
    1.79 +        SDLTest_AssertPass("Call to SDL_GetCursor()");
    1.80 +        SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");	
    1.81 +
    1.82 +	return TEST_COMPLETED;
    1.83 +}
    1.84 +
    1.85 +/**
    1.86 + * @brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode
    1.87 + * 
    1.88 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetRelativeMouseMode
    1.89 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetRelativeMouseMode
    1.90 + */
    1.91 +int
    1.92 +mouse_getSetRelativeMouseMode(void *arg)
    1.93 +{
    1.94 +	int result;
    1.95 +        int i;
    1.96 +	SDL_bool initialState;
    1.97 +	SDL_bool currentState;
    1.98 +
    1.99 +	/* Capture original state so we can revert back to it later */
   1.100 +	initialState = SDL_GetRelativeMouseMode();
   1.101 +        SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
   1.102 +
   1.103 +        /* Repeat twice to check D->D transition */
   1.104 +        for (i=0; i<2; i++) {
   1.105 + 	  /* Disable - should always be supported */        
   1.106 +          result = SDL_SetRelativeMouseMode(SDL_FALSE);
   1.107 +          SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
   1.108 +          SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
   1.109 +	  currentState = SDL_GetRelativeMouseMode();
   1.110 +          SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
   1.111 +          SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
   1.112 +        }
   1.113 +        
   1.114 +        /* Repeat twice to check D->E->E transition */
   1.115 +        for (i=0; i<2; i++) {
   1.116 +  	  /* Enable - may not be supported */        
   1.117 +          result = SDL_SetRelativeMouseMode(SDL_TRUE);
   1.118 +          SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)");
   1.119 +          if (result != -1) {
   1.120 +            SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
   1.121 +	    currentState = SDL_GetRelativeMouseMode();
   1.122 +            SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
   1.123 +            SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState);
   1.124 +          }
   1.125 +        }
   1.126 +
   1.127 + 	/* Disable to check E->D transition */        
   1.128 +        result = SDL_SetRelativeMouseMode(SDL_FALSE);
   1.129 +        SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
   1.130 +        SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
   1.131 +	currentState = SDL_GetRelativeMouseMode();
   1.132 +        SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
   1.133 +        SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
   1.134 +        
   1.135 +        /* Revert to originl state - ignore result */
   1.136 +        result = SDL_SetRelativeMouseMode(initialState);
   1.137 +
   1.138 +	return TEST_COMPLETED;
   1.139 +}
   1.140 +
   1.141  #define MOUSE_TESTWINDOW_WIDTH	320
   1.142  #define MOUSE_TESTWINDOW_HEIGHT 200
   1.143  
   1.144 @@ -455,14 +565,24 @@
   1.145  		{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED };
   1.146  
   1.147  static const SDLTest_TestCaseReference mouseTest6 =
   1.148 +		{ (SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED };
   1.149 +
   1.150 +static const SDLTest_TestCaseReference mouseTest7 =
   1.151  		{ (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED };
   1.152  
   1.153 -static const SDLTest_TestCaseReference mouseTest7 =
   1.154 +static const SDLTest_TestCaseReference mouseTest8 =
   1.155  		{ (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED };
   1.156  
   1.157 +static const SDLTest_TestCaseReference mouseTest9 =
   1.158 +		{ (SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED };
   1.159 +
   1.160 +static const SDLTest_TestCaseReference mouseTest10 =
   1.161 +		{ (SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED };
   1.162 +
   1.163  /* Sequence of Mouse test cases */
   1.164  static const SDLTest_TestCaseReference *mouseTests[] =  {
   1.165 -	&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6, &mouseTest7, NULL
   1.166 +	&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6, 
   1.167 +	&mouseTest7, &mouseTest8, &mouseTest9, &mouseTest10, NULL
   1.168  };
   1.169  
   1.170  /* Mouse test suite (global) */