test/testautomation_mouse.c
changeset 6822 18f6818ba281
parent 6821 f36771112651
child 6921 9a29af9de577
equal deleted inserted replaced
6821:f36771112651 6822:18f6818ba281
    14 
    14 
    15 /* Helper to evaluate state returned from SDL_GetMouseState */
    15 /* Helper to evaluate state returned from SDL_GetMouseState */
    16 int _mouseStateCheck(Uint8 state)
    16 int _mouseStateCheck(Uint8 state)
    17 {
    17 {
    18   return (state == 0) || 
    18   return (state == 0) || 
    19          SDL_BUTTON(SDL_BUTTON_LEFT) || 
    19          (state == SDL_BUTTON(SDL_BUTTON_LEFT)) || 
    20          SDL_BUTTON(SDL_BUTTON_MIDDLE) || 
    20          (state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) || 
    21          SDL_BUTTON(SDL_BUTTON_RIGHT) || 
    21          (state == SDL_BUTTON(SDL_BUTTON_RIGHT)) || 
    22          SDL_BUTTON(SDL_BUTTON_X1) || 
    22          (state == SDL_BUTTON(SDL_BUTTON_X1)) || 
    23          SDL_BUTTON(SDL_BUTTON_X2);
    23          (state == SDL_BUTTON(SDL_BUTTON_X2));
    24 }
    24 }
    25 
    25 
    26 /**
    26 /**
    27  * @brief Check call to SDL_GetMouseState
    27  * @brief Check call to SDL_GetMouseState
    28  * 
    28  * 
   213 	SDLTest_AssertPass("Call to SDL_FreeCursor()");
   213 	SDLTest_AssertPass("Call to SDL_FreeCursor()");
   214 
   214 
   215 	return TEST_COMPLETED;
   215 	return TEST_COMPLETED;
   216 }
   216 }
   217 
   217 
       
   218 /**
       
   219  * @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor
       
   220  * 
       
   221  * @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateColorCursor
       
   222  * @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
       
   223  */
       
   224 int
       
   225 mouse_createFreeColorCursor(void *arg)
       
   226 {
       
   227 	SDL_Surface *face;
       
   228 	SDL_Cursor *cursor;	
       
   229 
       
   230 	/* Get sample surface */
       
   231 	face = SDLTest_ImageFace();
       
   232 	SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
       
   233 	if (face == NULL) return TEST_ABORTED; 
       
   234 	
       
   235 	/* Create a color cursor from surface */
       
   236 	cursor = SDL_CreateColorCursor(face, 0, 0);
       
   237         SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
       
   238         SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");	
       
   239 	if (cursor == NULL) {
       
   240 		SDL_FreeSurface(face);
       
   241 		return TEST_ABORTED;
       
   242 	}
       
   243 
       
   244 	/* Free cursor again */
       
   245 	SDL_FreeCursor(cursor);
       
   246 	SDLTest_AssertPass("Call to SDL_FreeCursor()");
       
   247 
       
   248 	/* Clean up */
       
   249 	SDL_FreeSurface(face);
       
   250 	
       
   251 	return TEST_COMPLETED;
       
   252 }
       
   253 
   218 /* Helper that changes cursor visibility */
   254 /* Helper that changes cursor visibility */
   219 void _changeCursorVisibility(int state)
   255 void _changeCursorVisibility(int state)
   220 {
   256 {
   221 	int oldState;
   257 	int oldState;
   222 	int newState;
   258 	int newState;
   297 	SDLTest_AssertPass("Call to SDL_FreeCursor()");
   333 	SDLTest_AssertPass("Call to SDL_FreeCursor()");
   298 
   334 
   299 	return TEST_COMPLETED;
   335 	return TEST_COMPLETED;
   300 }
   336 }
   301 
   337 
       
   338 /**
       
   339  * @brief Check call to SDL_GetCursor
       
   340  * 
       
   341  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetCursor
       
   342  */
       
   343 int
       
   344 mouse_getCursor(void *arg)
       
   345 {
       
   346 	SDL_Cursor *cursor;	
       
   347 
       
   348 	/* Get current cursor */
       
   349 	cursor = SDL_GetCursor();
       
   350         SDLTest_AssertPass("Call to SDL_GetCursor()");
       
   351         SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");	
       
   352 
       
   353 	return TEST_COMPLETED;
       
   354 }
       
   355 
       
   356 /**
       
   357  * @brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode
       
   358  * 
       
   359  * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetRelativeMouseMode
       
   360  * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetRelativeMouseMode
       
   361  */
       
   362 int
       
   363 mouse_getSetRelativeMouseMode(void *arg)
       
   364 {
       
   365 	int result;
       
   366         int i;
       
   367 	SDL_bool initialState;
       
   368 	SDL_bool currentState;
       
   369 
       
   370 	/* Capture original state so we can revert back to it later */
       
   371 	initialState = SDL_GetRelativeMouseMode();
       
   372         SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
       
   373 
       
   374         /* Repeat twice to check D->D transition */
       
   375         for (i=0; i<2; i++) {
       
   376  	  /* Disable - should always be supported */        
       
   377           result = SDL_SetRelativeMouseMode(SDL_FALSE);
       
   378           SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
       
   379           SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
       
   380 	  currentState = SDL_GetRelativeMouseMode();
       
   381           SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
       
   382           SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
       
   383         }
       
   384         
       
   385         /* Repeat twice to check D->E->E transition */
       
   386         for (i=0; i<2; i++) {
       
   387   	  /* Enable - may not be supported */        
       
   388           result = SDL_SetRelativeMouseMode(SDL_TRUE);
       
   389           SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)");
       
   390           if (result != -1) {
       
   391             SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
       
   392 	    currentState = SDL_GetRelativeMouseMode();
       
   393             SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
       
   394             SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState);
       
   395           }
       
   396         }
       
   397 
       
   398  	/* Disable to check E->D transition */        
       
   399         result = SDL_SetRelativeMouseMode(SDL_FALSE);
       
   400         SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
       
   401         SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
       
   402 	currentState = SDL_GetRelativeMouseMode();
       
   403         SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
       
   404         SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
       
   405         
       
   406         /* Revert to originl state - ignore result */
       
   407         result = SDL_SetRelativeMouseMode(initialState);
       
   408 
       
   409 	return TEST_COMPLETED;
       
   410 }
       
   411 
   302 #define MOUSE_TESTWINDOW_WIDTH	320
   412 #define MOUSE_TESTWINDOW_WIDTH	320
   303 #define MOUSE_TESTWINDOW_HEIGHT 200
   413 #define MOUSE_TESTWINDOW_HEIGHT 200
   304 
   414 
   305 /**
   415 /**
   306  * Create s test window
   416  * Create s test window
   453 
   563 
   454 static const SDLTest_TestCaseReference mouseTest5 =
   564 static const SDLTest_TestCaseReference mouseTest5 =
   455 		{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED };
   565 		{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED };
   456 
   566 
   457 static const SDLTest_TestCaseReference mouseTest6 =
   567 static const SDLTest_TestCaseReference mouseTest6 =
       
   568 		{ (SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED };
       
   569 
       
   570 static const SDLTest_TestCaseReference mouseTest7 =
   458 		{ (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED };
   571 		{ (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED };
   459 
   572 
   460 static const SDLTest_TestCaseReference mouseTest7 =
   573 static const SDLTest_TestCaseReference mouseTest8 =
   461 		{ (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED };
   574 		{ (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED };
       
   575 
       
   576 static const SDLTest_TestCaseReference mouseTest9 =
       
   577 		{ (SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED };
       
   578 
       
   579 static const SDLTest_TestCaseReference mouseTest10 =
       
   580 		{ (SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED };
   462 
   581 
   463 /* Sequence of Mouse test cases */
   582 /* Sequence of Mouse test cases */
   464 static const SDLTest_TestCaseReference *mouseTests[] =  {
   583 static const SDLTest_TestCaseReference *mouseTests[] =  {
   465 	&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6, &mouseTest7, NULL
   584 	&mouseTest1, &mouseTest2, &mouseTest3, &mouseTest4, &mouseTest5, &mouseTest6, 
       
   585 	&mouseTest7, &mouseTest8, &mouseTest9, &mouseTest10, NULL
   466 };
   586 };
   467 
   587 
   468 /* Mouse test suite (global) */
   588 /* Mouse test suite (global) */
   469 SDLTest_TestSuiteReference mouseTestSuite = {
   589 SDLTest_TestSuiteReference mouseTestSuite = {
   470 	"Mouse",
   590 	"Mouse",