Update SDL_InvalidParamError to take param name; add additional fuzzer function; add new tests to keyboard test suite; improve surface test suite
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sat, 12 Jan 2013 22:58:12 -0800
changeset 681160d95fcfaf3c
parent 6810 b5609445aa4c
child 6812 1f92a4ad24e7
Update SDL_InvalidParamError to take param name; add additional fuzzer function; add new tests to keyboard test suite; improve surface test suite
include/SDL_error.h
include/SDL_test_fuzzer.h
src/SDL_error.c
src/events/SDL_keyboard.c
src/test/SDL_test_fuzzer.c
src/video/android/SDL_androidkeyboard.c
src/video/cocoa/SDL_cocoakeyboard.m
src/video/windows/SDL_windowskeyboard.c
test/testautomation_keyboard.c
test/testautomation_surface.c
     1.1 --- a/include/SDL_error.h	Sat Jan 12 14:06:58 2013 -0500
     1.2 +++ b/include/SDL_error.h	Sat Jan 12 22:58:12 2013 -0800
     1.3 @@ -52,7 +52,7 @@
     1.4  /*@{*/
     1.5  #define SDL_OutOfMemory()	SDL_Error(SDL_ENOMEM)
     1.6  #define SDL_Unsupported()	SDL_Error(SDL_UNSUPPORTED)
     1.7 -#define SDL_InvalidParamError()	SDL_Error(SDL_INVALIDPARAM)
     1.8 +#define SDL_InvalidParamError(param)	SDL_SetError("Parameter '%s' is invalid", (param))
     1.9  typedef enum
    1.10  {
    1.11      SDL_ENOMEM,
    1.12 @@ -60,7 +60,6 @@
    1.13      SDL_EFWRITE,
    1.14      SDL_EFSEEK,
    1.15      SDL_UNSUPPORTED,
    1.16 -    SDL_INVALIDPARAM,
    1.17      SDL_LASTERROR
    1.18  } SDL_errorcode;
    1.19  extern DECLSPEC void SDLCALL SDL_Error(SDL_errorcode code);
     2.1 --- a/include/SDL_test_fuzzer.h	Sat Jan 12 14:06:58 2013 -0500
     2.2 +++ b/include/SDL_test_fuzzer.h	Sat Jan 12 22:58:12 2013 -0800
     2.3 @@ -329,30 +329,44 @@
     2.4  
     2.5  
     2.6  /**
     2.7 - * Generates random null-terminated string. The maximum length for
     2.8 - * the string is 255 characters and it can contain ASCII characters
     2.9 - * from 1 to 127.
    2.10 + * Generates random null-terminated string. The minimum length for
    2.11 + * the string is 1 character, maximum length for the string is 255 
    2.12 + * characters and it can contain ASCII characters from 32 to 126.
    2.13   *
    2.14   * Note: Returned string needs to be deallocated.
    2.15   *
    2.16 - * \returns newly allocated random string
    2.17 + * \returns Newly allocated random string; or NULL if length was invalid or string could not be allocated.
    2.18   */
    2.19  char * SDLTest_RandomAsciiString();
    2.20  
    2.21  
    2.22  /**
    2.23   * Generates random null-terminated string. The maximum length for
    2.24 - * the string is defined by maxLenght parameter.
    2.25 - * String can contain ASCII characters from 1 to 127.
    2.26 + * the string is defined by the maxLength parameter.
    2.27 + * String can contain ASCII characters from 32 to 126.
    2.28   *
    2.29   * Note: Returned string needs to be deallocated.
    2.30   *
    2.31 - * \param maxLength Maximum length of the generated string
    2.32 + * \param maxLength The maximum length of the generated string.
    2.33   *
    2.34 - * \returns newly allocated random string
    2.35 + * \returns Newly allocated random string; or NULL if maxLength was invalid or string could not be allocated. 
    2.36   */
    2.37  char * SDLTest_RandomAsciiStringWithMaximumLength(int maxLength);
    2.38  
    2.39 +
    2.40 +/**
    2.41 + * Generates random null-terminated string. The length for
    2.42 + * the string is defined by the size parameter.
    2.43 + * String can contain ASCII characters from 32 to 126.
    2.44 + *
    2.45 + * Note: Returned string needs to be deallocated.
    2.46 + *
    2.47 + * \param size The length of the generated string
    2.48 + *
    2.49 + * \returns Newly allocated random string; or NULL if size was invalid or string could not be allocated.
    2.50 + */
    2.51 +char * SDLTest_RandomAsciiStringOfSize(int size);
    2.52 +
    2.53  /**
    2.54   * Returns the invocation count for the fuzzer since last ...FuzzerInit.
    2.55   */
     3.1 --- a/src/SDL_error.c	Sat Jan 12 14:06:58 2013 -0500
     3.2 +++ b/src/SDL_error.c	Sat Jan 12 22:58:12 2013 -0800
     3.3 @@ -235,9 +235,6 @@
     3.4      case SDL_UNSUPPORTED:
     3.5          SDL_SetError("That operation is not supported");
     3.6          break;
     3.7 -    case SDL_INVALIDPARAM:
     3.8 -        SDL_SetError("Parameter is invalid");
     3.9 -        break;
    3.10      default:
    3.11          SDL_SetError("Unknown SDL error");
    3.12          break;
     4.1 --- a/src/events/SDL_keyboard.c	Sat Jan 12 14:06:58 2013 -0500
     4.2 +++ b/src/events/SDL_keyboard.c	Sat Jan 12 22:58:12 2013 -0800
     4.3 @@ -895,17 +895,20 @@
     4.4  	int i;
     4.5  
     4.6  	if (!name || !*name) {
     4.7 +	        SDL_InvalidParamError("name");
     4.8  		return SDL_SCANCODE_UNKNOWN;
     4.9  	}
    4.10  
    4.11  	for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
    4.12  		if (!SDL_scancode_names[i]) {
    4.13  			continue;
    4.14 -		}
    4.15 +		}		
    4.16  		if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
    4.17  			return (SDL_Scancode)i;
    4.18  		}
    4.19  	}
    4.20 +
    4.21 +	SDL_InvalidParamError("name");
    4.22  	return SDL_SCANCODE_UNKNOWN;
    4.23  }
    4.24  
     5.1 --- a/src/test/SDL_test_fuzzer.c	Sat Jan 12 14:06:58 2013 -0500
     5.2 +++ b/src/test/SDL_test_fuzzer.c	Sat Jan 12 22:58:12 2013 -0800
     5.3 @@ -614,25 +614,37 @@
     5.4  char *
     5.5  SDLTest_RandomAsciiString()
     5.6  {
     5.7 -	// note: fuzzerInvocationCounter is increment in the RandomAsciiStringWithMaximumLenght
     5.8  	return SDLTest_RandomAsciiStringWithMaximumLength(255);
     5.9  }
    5.10  
    5.11  char *
    5.12 -SDLTest_RandomAsciiStringWithMaximumLength(int maxSize)
    5.13 +SDLTest_RandomAsciiStringWithMaximumLength(int maxLength)
    5.14  {
    5.15  	int size;
    5.16 +
    5.17 +	if(maxLength < 1) {
    5.18 +                SDL_InvalidParamError("maxLength");
    5.19 +		return NULL;
    5.20 +	}
    5.21 +
    5.22 +	size = (SDLTest_RandomUint32() % (maxLength + 1));
    5.23 +	
    5.24 +	return SDLTest_RandomAsciiStringOfSize(size);	
    5.25 +}
    5.26 +
    5.27 +char *
    5.28 +SDLTest_RandomAsciiStringOfSize(int size)
    5.29 +{
    5.30  	char *string;
    5.31  	int counter;
    5.32  
    5.33 -	fuzzerInvocationCounter++;
    5.34  
    5.35 -	if(maxSize < 1) {
    5.36 +	if(size < 1) {
    5.37 +                SDL_InvalidParamError("size");
    5.38  		return NULL;
    5.39  	}
    5.40  
    5.41 -	size = (SDLTest_RandomUint32() % (maxSize + 1)) + 1;
    5.42 -	string = (char *)SDL_malloc(size * sizeof(char));
    5.43 +	string = (char *)SDL_malloc((size + 1) * sizeof(char));
    5.44  	if (string==NULL) {
    5.45  	  return NULL;
    5.46          }
    5.47 @@ -643,5 +655,7 @@
    5.48  
    5.49  	string[counter] = '\0';
    5.50  
    5.51 +	fuzzerInvocationCounter++;
    5.52 +
    5.53  	return string;
    5.54  }
     6.1 --- a/src/video/android/SDL_androidkeyboard.c	Sat Jan 12 14:06:58 2013 -0500
     6.2 +++ b/src/video/android/SDL_androidkeyboard.c	Sat Jan 12 22:58:12 2013 -0800
     6.3 @@ -318,7 +318,7 @@
     6.4      SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
     6.5  
     6.6      if (!rect) {
     6.7 -        SDL_InvalidParamError();
     6.8 +        SDL_InvalidParamError("rect");
     6.9          return;
    6.10      }
    6.11      
     7.1 --- a/src/video/cocoa/SDL_cocoakeyboard.m	Sat Jan 12 14:06:58 2013 -0500
     7.2 +++ b/src/video/cocoa/SDL_cocoakeyboard.m	Sat Jan 12 22:58:12 2013 -0800
     7.3 @@ -669,7 +669,7 @@
     7.4      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     7.5  
     7.6      if (!rect) {
     7.7 -	SDL_InvalidParamError();
     7.8 +	SDL_InvalidParamError("rect");
     7.9  	return;
    7.10      }
    7.11  
     8.1 --- a/src/video/windows/SDL_windowskeyboard.c	Sat Jan 12 14:06:58 2013 -0500
     8.2 +++ b/src/video/windows/SDL_windowskeyboard.c	Sat Jan 12 22:58:12 2013 -0800
     8.3 @@ -214,7 +214,7 @@
     8.4      SDL_VideoData *videodata = (SDL_VideoData *)_this->driverdata;
     8.5      
     8.6      if (!rect) {
     8.7 -        SDL_InvalidParamError();
     8.8 +        SDL_InvalidParamError("rect");
     8.9          return;
    8.10      }
    8.11      
     9.1 --- a/test/testautomation_keyboard.c	Sat Jan 12 14:06:58 2013 -0500
     9.2 +++ b/test/testautomation_keyboard.c	Sat Jan 12 22:58:12 2013 -0800
     9.3 @@ -382,7 +382,7 @@
     9.4  int
     9.5  keyboard_setTextInputRectNegative(void *arg)
     9.6  {      
     9.7 -   const char *expectedError = "Parameter is invalid";
     9.8 +   const char *expectedError = "Parameter 'rect' is invalid";
     9.9     const char *error;
    9.10     
    9.11     SDL_ClearError();
    9.12 @@ -405,6 +405,157 @@
    9.13     return TEST_COMPLETED;
    9.14  }
    9.15  
    9.16 +/**
    9.17 + * @brief Check call to SDL_GetScancodeFromKey
    9.18 + * 
    9.19 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
    9.20 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
    9.21 + */
    9.22 +int
    9.23 +keyboard_getScancodeFromKey(void *arg)
    9.24 +{      
    9.25 +   SDL_Scancode scancode;
    9.26 +   
    9.27 +   /* Regular key */
    9.28 +   scancode = SDL_GetScancodeFromKey(SDLK_4);
    9.29 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_4)");
    9.30 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromKey, expected: %i, got: %i", SDL_SCANCODE_4, scancode); 
    9.31 +
    9.32 +   /* Virtual key */
    9.33 +   scancode = SDL_GetScancodeFromKey(SDLK_PLUS);
    9.34 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromKey(SDLK_PLUS)");
    9.35 +   SDLTest_AssertCheck(scancode == 0, "Validate return value from SDL_GetScancodeFromKey, expected: 0, got: %i", scancode); 
    9.36 +        
    9.37 +   return TEST_COMPLETED;
    9.38 +}
    9.39 +
    9.40 +/**
    9.41 + * @brief Check call to SDL_GetScancodeFromName
    9.42 + * 
    9.43 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
    9.44 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
    9.45 + */
    9.46 +int
    9.47 +keyboard_getScancodeFromName(void *arg)
    9.48 +{      
    9.49 +   SDL_Scancode scancode;
    9.50 +
    9.51 +   /* Regular key, 1 character, first name in list */
    9.52 +   scancode = SDL_GetScancodeFromName("A");
    9.53 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('A')");
    9.54 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_A, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_A, scancode); 
    9.55 +
    9.56 +   /* Regular key, 1 character */
    9.57 +   scancode = SDL_GetScancodeFromName("4");
    9.58 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('4')");
    9.59 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_4, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_4, scancode); 
    9.60 +
    9.61 +   /* Regular key, 2 characters */
    9.62 +   scancode = SDL_GetScancodeFromName("F1");
    9.63 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('F1')");
    9.64 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_F1, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_F1, scancode); 
    9.65 +
    9.66 +   /* Regular key, 3 characters */
    9.67 +   scancode = SDL_GetScancodeFromName("End");
    9.68 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('End')");
    9.69 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_END, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_END, scancode); 
    9.70 +
    9.71 +   /* Regular key, 4 characters */
    9.72 +   scancode = SDL_GetScancodeFromName("Find");
    9.73 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Find')");
    9.74 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_FIND, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_FIND, scancode); 
    9.75 +
    9.76 +   /* Regular key, several characters */
    9.77 +   scancode = SDL_GetScancodeFromName("Backspace");
    9.78 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Backspace')");
    9.79 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_BACKSPACE, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_BACKSPACE, scancode); 
    9.80 +
    9.81 +   /* Regular key, several characters with space */
    9.82 +   scancode = SDL_GetScancodeFromName("Keypad Enter");
    9.83 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Keypad Enter')");
    9.84 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_KP_ENTER, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_KP_ENTER, scancode); 
    9.85 +
    9.86 +   /* Regular key, last name in list */
    9.87 +   scancode = SDL_GetScancodeFromName("Sleep");
    9.88 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('Sleep')");
    9.89 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_SLEEP, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_SLEEP, scancode); 
    9.90 +   
    9.91 +   return TEST_COMPLETED;
    9.92 +}
    9.93 +
    9.94 +/**
    9.95 + * @brief Check call to SDL_GetScancodeFromName with invalid data
    9.96 + * 
    9.97 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
    9.98 + * @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
    9.99 + */
   9.100 +int
   9.101 +keyboard_getScancodeFromNameNegative(void *arg)
   9.102 +{      
   9.103 +   char *name;
   9.104 +   SDL_Scancode scancode;
   9.105 +   const char *expectedError = "Parameter 'name' is invalid";
   9.106 +   const char *error;
   9.107 +
   9.108 +   SDL_ClearError();
   9.109 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   9.110 +
   9.111 +   /* Random string input */
   9.112 +   name = SDLTest_RandomAsciiStringOfSize(32);
   9.113 +   SDLTest_Assert(name != NULL, "Check that random name is not NULL");
   9.114 +   if (name == NULL) {
   9.115 +      return TEST_ABORTED;
   9.116 +   }   
   9.117 +   scancode = SDL_GetScancodeFromName((const char *)name);
   9.118 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
   9.119 +   SDL_free(name);
   9.120 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   9.121 +   error = SDL_GetError();
   9.122 +   SDLTest_AssertPass("Call to SDL_GetError()");
   9.123 +   SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   9.124 +   if (error != NULL) {
   9.125 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   9.126 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   9.127 +   }
   9.128 +
   9.129 +   SDL_ClearError();
   9.130 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   9.131 +         
   9.132 +   /* Zero length string input */
   9.133 +   name = "";
   9.134 +   scancode = SDL_GetScancodeFromName((const char *)name);
   9.135 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
   9.136 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   9.137 +   error = SDL_GetError();
   9.138 +   SDLTest_AssertPass("Call to SDL_GetError()");
   9.139 +   SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   9.140 +   if (error != NULL) {
   9.141 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   9.142 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   9.143 +   }
   9.144 +
   9.145 +   SDL_ClearError();
   9.146 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   9.147 +
   9.148 +   /* NULL input */
   9.149 +   name = NULL;
   9.150 +   scancode = SDL_GetScancodeFromName((const char *)name);
   9.151 +   SDLTest_AssertPass("Call to SDL_GetScancodeFromName(NULL)");
   9.152 +   SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
   9.153 +   error = SDL_GetError();
   9.154 +   SDLTest_AssertPass("Call to SDL_GetError()");
   9.155 +   SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   9.156 +   if (error != NULL) {
   9.157 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
   9.158 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
   9.159 +   }
   9.160 +
   9.161 +   SDL_ClearError();
   9.162 +   SDLTest_AssertPass("Call to SDL_ClearError()");
   9.163 +   
   9.164 +   return TEST_COMPLETED;
   9.165 +}
   9.166 +
   9.167  
   9.168  
   9.169  /* ================= Test References ================== */
   9.170 @@ -437,10 +588,19 @@
   9.171  static const SDLTest_TestCaseReference keyboardTest9 =
   9.172  		{ (SDLTest_TestCaseFp)keyboard_setTextInputRectNegative, "keyboard_setTextInputRectNegative", "Check call to SDL_SetTextInputRect with invalid data", TEST_ENABLED };
   9.173  
   9.174 +static const SDLTest_TestCaseReference keyboardTest10 =
   9.175 +		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromKey, "keyboard_getScancodeFromKey", "Check call to SDL_GetScancodeFromKey", TEST_ENABLED };
   9.176 +
   9.177 +static const SDLTest_TestCaseReference keyboardTest11 =
   9.178 +		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromName, "keyboard_getScancodeFromName", "Check call to SDL_GetScancodeFromName", TEST_ENABLED };
   9.179 +
   9.180 +static const SDLTest_TestCaseReference keyboardTest12 =
   9.181 +		{ (SDLTest_TestCaseFp)keyboard_getScancodeFromNameNegative, "keyboard_getScancodeFromNameNegative", "Check call to SDL_GetScancodeFromName with invalid data", TEST_ENABLED };
   9.182 +
   9.183  /* Sequence of Keyboard test cases */
   9.184  static const SDLTest_TestCaseReference *keyboardTests[] =  {
   9.185  	&keyboardTest1, &keyboardTest2, &keyboardTest3, &keyboardTest4, &keyboardTest5, &keyboardTest6, 
   9.186 -	&keyboardTest7, &keyboardTest8, &keyboardTest9, NULL
   9.187 +	&keyboardTest7, &keyboardTest8, &keyboardTest9, &keyboardTest10, &keyboardTest11, &keyboardTest12, NULL
   9.188  };
   9.189  
   9.190  /* Keyboard test suite (global) */
    10.1 --- a/test/testautomation_surface.c	Sat Jan 12 14:06:58 2013 -0500
    10.2 +++ b/test/testautomation_surface.c	Sat Jan 12 22:58:12 2013 -0800
    10.3 @@ -4,7 +4,7 @@
    10.4   */
    10.5  
    10.6  /* Supress C4996 VS compiler warnings for unlink() */
    10.7 -#define _CRT_SECURE_NO_DEPRECATE
    10.8 +#define _CRT_SECURE_NO_DEPRECATE
    10.9  #define _CRT_NONSTDC_NO_DEPRECATE
   10.10  
   10.11  #include <stdio.h>
   10.12 @@ -27,26 +27,37 @@
   10.13  
   10.14  /* Fixture */
   10.15  
   10.16 -/* Create a 32-bit writable surface for screen tests */
   10.17 +/* Create a 32-bit writable surface for blitting tests */
   10.18  void
   10.19  _surfaceSetUp(void *arg)
   10.20  {
   10.21 -    Uint32 rmask, gmask, bmask, amask;
   10.22 -#if SDL_BYTEORDER == SDL_BIG_ENDIAN
   10.23 -    rmask = 0xff000000;
   10.24 -    gmask = 0x00ff0000;
   10.25 -    bmask = 0x0000ff00;
   10.26 -    amask = 0x000000ff;
   10.27 -#else
   10.28 -    rmask = 0x000000ff;
   10.29 -    gmask = 0x0000ff00;
   10.30 -    bmask = 0x00ff0000;
   10.31 -    amask = 0xff000000;
   10.32 -#endif
   10.33 -
   10.34 -	referenceSurface = SDLTest_ImageBlit(); /* For size info */
   10.35 -	testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
   10.36 +    int result;
   10.37 +    SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
   10.38 +    SDL_BlendMode currentBlendMode;
   10.39 +    Uint32 rmask, gmask, bmask, amask;
   10.40 +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
   10.41 +    rmask = 0xff000000;
   10.42 +    gmask = 0x00ff0000;
   10.43 +    bmask = 0x0000ff00;
   10.44 +    amask = 0x000000ff;
   10.45 +#else
   10.46 +    rmask = 0x000000ff;
   10.47 +    gmask = 0x0000ff00;
   10.48 +    bmask = 0x00ff0000;
   10.49 +    amask = 0xff000000;
   10.50 +#endif
   10.51 +
   10.52 +    referenceSurface = SDLTest_ImageBlit(); /* For size info */
   10.53 +    testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
   10.54      SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
   10.55 +    if (testSurface != NULL) {
   10.56 +      /* Disable blend mode for target surface */
   10.57 +      result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
   10.58 +      SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
   10.59 +      result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
   10.60 +      SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
   10.61 +      SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);      
   10.62 +    }
   10.63  }
   10.64  
   10.65  void
   10.66 @@ -69,10 +80,10 @@
   10.67  {
   10.68  	int ret;
   10.69  	Uint32 color;
   10.70 -	
   10.71 +
   10.72  	/* Clear surface. */
   10.73 -	color = SDL_MapRGB( testSurface->format, 0, 0, 0);
   10.74 -	SDLTest_AssertPass("Call to SDL_MapRGB()");
   10.75 +	color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
   10.76 +	SDLTest_AssertPass("Call to SDL_MapRGBA()");
   10.77  	ret = SDL_FillRect( testSurface, NULL, color);
   10.78  	SDLTest_AssertPass("Call to SDL_FillRect()");
   10.79  	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
   10.80 @@ -103,6 +114,21 @@
   10.81  	SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
   10.82  	if (face == NULL) return;
   10.83  
   10.84 +        /* Reset alpha modulation */	
   10.85 +	ret = SDL_SetSurfaceAlphaMod(face, 255);
   10.86 +	SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
   10.87 +	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
   10.88 +
   10.89 +        /* Reset color modulation */	
   10.90 +	ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
   10.91 +	SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
   10.92 +	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
   10.93 +
   10.94 +        /* Reset color key */	
   10.95 +	ret = SDL_SetColorKey(face, SDL_FALSE, 0);
   10.96 +	SDLTest_AssertPass("Call to SDL_SetColorKey()");
   10.97 +	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
   10.98 +
   10.99  	/* Clear the test surface */
  10.100          _clearTestSurface();
  10.101          
  10.102 @@ -141,11 +167,16 @@
  10.103  		else if (mode == -4) {
  10.104  			/* Crazy blending mode magic. */
  10.105  			nmode = (i/4*j/4) % 4;
  10.106 -			if (nmode==0) bmode = SDL_BLENDMODE_NONE;
  10.107 -			else if (nmode==1) bmode = SDL_BLENDMODE_BLEND;
  10.108 -			else if (nmode==2) bmode = SDL_BLENDMODE_ADD;
  10.109 -			else if (nmode==3) bmode = SDL_BLENDMODE_MOD;
  10.110 -			ret = SDL_SetSurfaceBlendMode( face, bmode );		
  10.111 +			if (nmode==0) {
  10.112 +				bmode = SDL_BLENDMODE_NONE;
  10.113 +			} else if (nmode==1) {
  10.114 +				bmode = SDL_BLENDMODE_BLEND;
  10.115 +			} else if (nmode==2) {
  10.116 +				bmode = SDL_BLENDMODE_ADD;				
  10.117 +			} else if (nmode==3) {
  10.118 +				bmode = SDL_BLENDMODE_MOD;
  10.119 +			}
  10.120 +			ret = SDL_SetSurfaceBlendMode( face, bmode );
  10.121  			if (ret != 0) checkFailCount4++;
  10.122  		}
  10.123  
  10.124 @@ -473,7 +504,7 @@
  10.125     int ret;
  10.126     SDL_Surface *referenceSurface;
  10.127  
  10.128 -   /* All blitting */ 
  10.129 +   /* All blitting modes */ 
  10.130     _testBlitBlendMode(-4);
  10.131     
  10.132     /* Verify result by comparing surfaces */