test/testautomation_keyboard.c
changeset 6808 3ad413bd1cd6
parent 6807 e3610bc90cf3
child 6811 60d95fcfaf3c
     1.1 --- a/test/testautomation_keyboard.c	Thu Jan 10 23:26:49 2013 -0800
     1.2 +++ b/test/testautomation_keyboard.c	Fri Jan 11 20:36:39 2013 -0800
     1.3 @@ -279,6 +279,132 @@
     1.4     return TEST_COMPLETED;
     1.5  }
     1.6  
     1.7 +/* Internal function to test SDL_SetTextInputRect */
     1.8 +void _testSetTextInputRect(SDL_Rect refRect)
     1.9 +{
    1.10 +   SDL_Rect testRect;
    1.11 +   
    1.12 +   testRect = refRect;
    1.13 +   SDL_SetTextInputRect(&testRect);
    1.14 +   SDLTest_AssertPass("Call to SDL_SetTextInputRect with refRect(x:%i,y:%i,w:%i,h:%i)", refRect.x, refRect.y, refRect.w, refRect.h);
    1.15 +   SDLTest_AssertCheck(
    1.16 +      (refRect.x == testRect.x) && (refRect.y == testRect.y) && (refRect.w == testRect.w) && (refRect.h == testRect.h), 
    1.17 +      "Check that input data was not modified, expected: x:%i,y:%i,w:%i,h:%i, got: x:%i,y:%i,w:%i,h:%i", 
    1.18 +      refRect.x, refRect.y, refRect.w, refRect.h, 
    1.19 +      testRect.x, testRect.y, testRect.w, testRect.h);
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 + * @brief Check call to SDL_SetTextInputRect
    1.24 + * 
    1.25 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
    1.26 + */
    1.27 +int
    1.28 +keyboard_setTextInputRect(void *arg)
    1.29 +{   
    1.30 +   SDL_Rect refRect;
    1.31 +   
    1.32 +   /* Normal visible refRect, origin inside */
    1.33 +   refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
    1.34 +   refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
    1.35 +   refRect.w = SDLTest_RandomIntegerInRange(10, 50);
    1.36 +   refRect.h = SDLTest_RandomIntegerInRange(10, 50);
    1.37 +   _testSetTextInputRect(refRect);
    1.38 +   
    1.39 +   /* Normal visible refRect, origin 0,0 */
    1.40 +   refRect.x = 0;
    1.41 +   refRect.y = 0;
    1.42 +   refRect.w = SDLTest_RandomIntegerInRange(10, 50);
    1.43 +   refRect.h = SDLTest_RandomIntegerInRange(10, 50);
    1.44 +   _testSetTextInputRect(refRect);
    1.45 +
    1.46 +   /* 1Pixel refRect */
    1.47 +   refRect.x = SDLTest_RandomIntegerInRange(10, 50);;
    1.48 +   refRect.y = SDLTest_RandomIntegerInRange(10, 50);;
    1.49 +   refRect.w = 1;
    1.50 +   refRect.h = 1;
    1.51 +   _testSetTextInputRect(refRect);
    1.52 +
    1.53 +   /* 0pixel refRect */
    1.54 +   refRect.x = 1;
    1.55 +   refRect.y = 1;
    1.56 +   refRect.w = 1;
    1.57 +   refRect.h = 0;
    1.58 +   _testSetTextInputRect(refRect);
    1.59 +
    1.60 +   /* 0pixel refRect */
    1.61 +   refRect.x = 1;
    1.62 +   refRect.y = 1;
    1.63 +   refRect.w = 0;
    1.64 +   refRect.h = 1;
    1.65 +   _testSetTextInputRect(refRect);
    1.66 +
    1.67 +   /* 0pixel refRect */
    1.68 +   refRect.x = 1;
    1.69 +   refRect.y = 1;
    1.70 +   refRect.w = 0;
    1.71 +   refRect.h = 0;
    1.72 +   _testSetTextInputRect(refRect);
    1.73 +
    1.74 +   /* 0pixel refRect */
    1.75 +   refRect.x = 0;
    1.76 +   refRect.y = 0;
    1.77 +   refRect.w = 0;
    1.78 +   refRect.h = 0;
    1.79 +   _testSetTextInputRect(refRect);
    1.80 +
    1.81 +   /* negative refRect */
    1.82 +   refRect.x = SDLTest_RandomIntegerInRange(-200, -100);;
    1.83 +   refRect.y = SDLTest_RandomIntegerInRange(-200, -100);;
    1.84 +   refRect.w = 50;
    1.85 +   refRect.h = 50;
    1.86 +   _testSetTextInputRect(refRect);
    1.87 +
    1.88 +   /* oversized refRect */
    1.89 +   refRect.x = SDLTest_RandomIntegerInRange(1, 50);;
    1.90 +   refRect.y = SDLTest_RandomIntegerInRange(1, 50);;
    1.91 +   refRect.w = 5000;
    1.92 +   refRect.h = 5000;
    1.93 +   _testSetTextInputRect(refRect);
    1.94 +
    1.95 +   /* NULL refRect */
    1.96 +   SDL_SetTextInputRect(NULL);
    1.97 +   SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
    1.98 +
    1.99 +   return TEST_COMPLETED;
   1.100 +}
   1.101 +
   1.102 +/**
   1.103 + * @brief Check call to SDL_SetTextInputRect with invalid data
   1.104 + * 
   1.105 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
   1.106 + */
   1.107 +int
   1.108 +keyboard_setTextInputRectNegative(void *arg)
   1.109 +{      
   1.110 +   const char *expectedError = "Parameter is invalid";
   1.111 +   const char *error;
   1.112 +   
   1.113 +   SDL_ClearError();
   1.114 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   1.115 +   
   1.116 +   /* NULL refRect */
   1.117 +   SDL_SetTextInputRect(NULL);
   1.118 +   SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
   1.119 +   error = SDL_GetError();
   1.120 +   SDLTest_AssertPass("Call to SDL_GetError()");
   1.121 +   SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   1.122 +   if (error != NULL) {
   1.123 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   1.124 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   1.125 +   }
   1.126 +
   1.127 +   SDL_ClearError();
   1.128 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   1.129 +      
   1.130 +   return TEST_COMPLETED;
   1.131 +}
   1.132 +
   1.133  
   1.134  
   1.135  /* ================= Test References ================== */
   1.136 @@ -305,9 +431,16 @@
   1.137  static const SDLTest_TestCaseReference keyboardTest7 =
   1.138  		{ (SDLTest_TestCaseFp)keyboard_startStopTextInput, "keyboard_startStopTextInput", "Check call to SDL_StartTextInput and SDL_StopTextInput", TEST_ENABLED };
   1.139  
   1.140 +static const SDLTest_TestCaseReference keyboardTest8 =
   1.141 +		{ (SDLTest_TestCaseFp)keyboard_setTextInputRect, "keyboard_setTextInputRect", "Check call to SDL_SetTextInputRect", TEST_ENABLED };
   1.142 +
   1.143 +static const SDLTest_TestCaseReference keyboardTest9 =
   1.144 +		{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
   1.145 +
   1.146  /* Sequence of Keyboard test cases */
   1.147  static const SDLTest_TestCaseReference *keyboardTests[] =  {
   1.148 -	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, &keyboardTest7, NULL
   1.149 +	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, 
   1.150 +	&keyboardTest7, &keyboardTest8, &keyboardTest9, NULL
   1.151  };
   1.152  
   1.153  /* Keyboard test suite (global) */