Add test for SDL_GetPixelFormatName to Pixels suite; minor improvements to Pixels suite
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Mon, 06 May 2013 08:13:44 -0700
changeset 715351cf5475ac56
parent 7152 e9ed46195235
child 7154 aa20e0c00d38
Add test for SDL_GetPixelFormatName to Pixels suite; minor improvements to Pixels suite
test/testautomation_pixels.c
     1.1 --- a/test/testautomation_pixels.c	Sun May 05 21:01:20 2013 -0400
     1.2 +++ b/test/testautomation_pixels.c	Mon May 06 08:13:44 2013 -0700
     1.3 @@ -97,6 +97,19 @@
     1.4      "SDL_PIXELFORMAT_YVYU" 
     1.5    };
     1.6  
     1.7 +/* Definition of some invalid formats for negative tests */
     1.8 +const int _numInvalidPixelFormats = 2;
     1.9 +Uint32 _invalidPixelFormats[] = 
    1.10 +  {
    1.11 +    0xfffffffe,
    1.12 +    0xffffffff
    1.13 +  };
    1.14 +char* _invalidPixelFormatsVerbose[] = 
    1.15 +  {
    1.16 +    "SDL_PIXELFORMAT_UNKNOWN",
    1.17 +    "SDL_PIXELFORMAT_UNKNOWN"
    1.18 +  };
    1.19 +
    1.20  /* Test case functions */
    1.21  
    1.22  /**
    1.23 @@ -108,14 +121,34 @@
    1.24  int
    1.25  pixels_allocFreeFormat(void *arg)
    1.26  {
    1.27 +  const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
    1.28    const char *expectedError = "Parameter 'format' is invalid";
    1.29    const char *error;   
    1.30 -  char message[256];
    1.31    int i;
    1.32    Uint32 format;
    1.33    Uint32 masks;
    1.34    SDL_PixelFormat* result;
    1.35  
    1.36 +  /* Blank/unknown format */
    1.37 +  format = 0;
    1.38 +  SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
    1.39 +  
    1.40 +  /* Allocate format */
    1.41 +  result = SDL_AllocFormat(format);
    1.42 +  SDLTest_AssertPass("Call to SDL_AllocFormat()");
    1.43 +  SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");  
    1.44 +  if (result != NULL) {
    1.45 +    SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %u, got %u", format, result->format);  
    1.46 +    SDLTest_AssertCheck(result->BitsPerPixel == 0, "Verify value of result.BitsPerPixel; expected: 0, got %u", result->BitsPerPixel);  
    1.47 +    SDLTest_AssertCheck(result->BytesPerPixel == 0, "Verify value of result.BytesPerPixel; expected: 0, got %u", result->BytesPerPixel);  
    1.48 +    masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
    1.49 +    SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %u", masks);
    1.50 +      
    1.51 +    /* Deallocate again */
    1.52 +    SDL_FreeFormat(result);
    1.53 +    SDLTest_AssertPass("Call to SDL_FreeFormat()");          
    1.54 +  }
    1.55 +
    1.56    /* RGB formats */
    1.57    for (i = 0; i < _numRGBPixelFormats; i++) {
    1.58      format = _RGBPixelFormats[i];
    1.59 @@ -153,19 +186,21 @@
    1.60    
    1.61    /* Negative cases */
    1.62    
    1.63 -  /* Invalid Format */  
    1.64 -  SDL_ClearError();
    1.65 -  SDLTest_AssertPass("Call to SDL_ClearError()");
    1.66 -  format = 0xffffffff;
    1.67 -  result = SDL_AllocFormat(format);
    1.68 -  SDLTest_AssertPass("Call to SDL_AllocFormat(0xffffffff)");
    1.69 -  SDLTest_AssertCheck(result == NULL, "Verify result is NULL");  
    1.70 -  error = SDL_GetError();
    1.71 -  SDLTest_AssertPass("Call to SDL_GetError()");
    1.72 -  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
    1.73 -  if (error != NULL) {
    1.74 +  /* Invalid Formats */  
    1.75 +  for (i = 0; i < _numInvalidPixelFormats; i++) {
    1.76 +    SDL_ClearError();
    1.77 +    SDLTest_AssertPass("Call to SDL_ClearError()");
    1.78 +    format = _invalidPixelFormats[i];
    1.79 +    result = SDL_AllocFormat(format);
    1.80 +    SDLTest_AssertPass("Call to SDL_AllocFormat(%u)", format);
    1.81 +    SDLTest_AssertCheck(result == NULL, "Verify result is NULL");  
    1.82 +    error = SDL_GetError();
    1.83 +    SDLTest_AssertPass("Call to SDL_GetError()");
    1.84 +    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
    1.85 +    if (error != NULL) {
    1.86        SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
    1.87            "Validate error message, expected: '%s', got: '%s'", expectedError, error);
    1.88 +    }
    1.89    }
    1.90  
    1.91    /* Invalid free pointer */
    1.92 @@ -185,6 +220,90 @@
    1.93  }
    1.94  
    1.95  /**
    1.96 + * @brief Call to SDL_GetPixelFormatName
    1.97 + *
    1.98 + * @sa http://wiki.libsdl.org/moin.fcg/SDL_GetPixelFormatName
    1.99 + */
   1.100 +int
   1.101 +pixels_getPixelFormatName(void *arg)
   1.102 +{
   1.103 +  const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
   1.104 +  const char *error;   
   1.105 +  int i;
   1.106 +  Uint32 format;
   1.107 +  char* result;
   1.108 +
   1.109 +  /* Blank/undefined format */
   1.110 +  format = 0;
   1.111 +  SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
   1.112 +  
   1.113 +  /* Get name of format */
   1.114 +  result = (char *)SDL_GetPixelFormatName(format);
   1.115 +  SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
   1.116 +  SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");  
   1.117 +  if (result != NULL) {
   1.118 +      SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
   1.119 +      SDLTest_AssertCheck(SDL_strcmp(result, unknownFormat) == 0, 
   1.120 +        "Verify result text; expected: %s, got %s", unknownFormat, result);
   1.121 +  }
   1.122 +
   1.123 +  /* RGB formats */
   1.124 +  for (i = 0; i < _numRGBPixelFormats; i++) {
   1.125 +    format = _RGBPixelFormats[i];
   1.126 +    SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
   1.127 +  
   1.128 +    /* Get name of format */
   1.129 +    result = (char *)SDL_GetPixelFormatName(format);
   1.130 +    SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
   1.131 +    SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");  
   1.132 +    if (result != NULL) {
   1.133 +      SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
   1.134 +      SDLTest_AssertCheck(SDL_strcmp(result, _RGBPixelFormatsVerbose[i]) == 0, 
   1.135 +        "Verify result text; expected: %s, got %s", _RGBPixelFormatsVerbose[i], result);
   1.136 +    }
   1.137 +  }
   1.138 +
   1.139 +  /* Non-RGB formats */
   1.140 +  for (i = 0; i < _numNonRGBPixelFormats; i++) {
   1.141 +    format = _nonRGBPixelFormats[i];
   1.142 +    SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
   1.143 +  
   1.144 +    /* Get name of format */
   1.145 +    result = (char *)SDL_GetPixelFormatName(format);
   1.146 +    SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
   1.147 +    SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");  
   1.148 +    if (result != NULL) {
   1.149 +      SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
   1.150 +      SDLTest_AssertCheck(SDL_strcmp(result, _nonRGBPixelFormatsVerbose[i]) == 0, 
   1.151 +        "Verify result text; expected: %s, got %s", _nonRGBPixelFormatsVerbose[i], result);
   1.152 +    }
   1.153 +  }
   1.154 +  
   1.155 +  /* Negative cases */
   1.156 +  
   1.157 +  /* Invalid Formats */  
   1.158 +  SDL_ClearError();
   1.159 +  SDLTest_AssertPass("Call to SDL_ClearError()");
   1.160 +  for (i = 0; i < _numInvalidPixelFormats; i++) {
   1.161 +    format = _invalidPixelFormats[i];
   1.162 +    result = (char *)SDL_GetPixelFormatName(format);
   1.163 +    SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", format);
   1.164 +    SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");  
   1.165 +    if (result != NULL) {
   1.166 +      SDLTest_AssertCheck(SDL_strlen(result) > 0, 
   1.167 +        "Verify result is non-empty; got: %s", result);
   1.168 +      SDLTest_AssertCheck(SDL_strcmp(result, _invalidPixelFormatsVerbose[i]) == 0,
   1.169 +        "Validate name is UNKNOWN, expected: '%s', got: '%s'", _invalidPixelFormatsVerbose[i], result);
   1.170 +    }
   1.171 +    error = SDL_GetError();
   1.172 +    SDLTest_AssertPass("Call to SDL_GetError()");
   1.173 +    SDLTest_AssertCheck(error != NULL && SDL_strlen(error) == 0, "Validate that error message is empty");
   1.174 +  }
   1.175 +
   1.176 +  return TEST_COMPLETED;
   1.177 +}
   1.178 +
   1.179 +/**
   1.180   * @brief Call to SDL_AllocPalette and SDL_FreePalette
   1.181   *
   1.182   * @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocPalette
   1.183 @@ -196,7 +315,6 @@
   1.184    const char *expectedError1 = "Parameter 'ncolors' is invalid";
   1.185    const char *expectedError2 = "Parameter 'palette' is invalid";
   1.186    const char *error;   
   1.187 -  char message[256];
   1.188    int variation;
   1.189    int i;
   1.190    int ncolors;
   1.191 @@ -286,7 +404,6 @@
   1.192    const char *expectedError1 = "Parameter 'gamma' is invalid";
   1.193    const char *expectedError2 = "Parameter 'ramp' is invalid";
   1.194    const char *error;   
   1.195 -  char message[256];
   1.196    float gamma;
   1.197    Uint16 *ramp;
   1.198    int variation;
   1.199 @@ -310,13 +427,13 @@
   1.200        case 1:
   1.201          gamma = 1.0f;
   1.202          break;
   1.203 -      /* gamma = ]0,1[ normal range */  
   1.204 +      /* gamma = [0.2,0.8] normal range */  
   1.205        case 2:
   1.206 -        gamma = 0.01f + 0.98f * SDLTest_RandomUnitFloat();
   1.207 +        gamma = 0.2f + 0.8f * SDLTest_RandomUnitFloat();
   1.208          break;
   1.209 -      /* gamma = >1.0 non-standard range */  
   1.210 +      /* gamma = >1.1 non-standard range */  
   1.211        case 3:
   1.212 -        gamma = 0.01f + 0.98f * SDLTest_RandomUnitFloat();
   1.213 +        gamma = 1.1f + SDLTest_RandomUnitFloat();
   1.214          break;
   1.215      }
   1.216  
   1.217 @@ -343,7 +460,6 @@
   1.218          break;
   1.219      }
   1.220    }
   1.221 -
   1.222    
   1.223    /* Negative cases */
   1.224    SDL_ClearError();
   1.225 @@ -392,9 +508,12 @@
   1.226  static const SDLTest_TestCaseReference pixelsTest3 =
   1.227  		{ (SDLTest_TestCaseFp)pixels_calcGammaRamp, "pixels_calcGammaRamp", "Call to SDL_CalculateGammaRamp", TEST_ENABLED };
   1.228  
   1.229 +static const SDLTest_TestCaseReference pixelsTest4 =
   1.230 +		{ (SDLTest_TestCaseFp)pixels_getPixelFormatName, "pixels_getPixelFormatName", "Call to SDL_GetPixelFormatName", TEST_ENABLED };
   1.231 +
   1.232  /* Sequence of Pixels test cases */
   1.233  static const SDLTest_TestCaseReference *pixelsTests[] =  {
   1.234 -	&pixelsTest1, &pixelsTest2, &pixelsTest3, NULL
   1.235 +	&pixelsTest1, &pixelsTest2, &pixelsTest3, &pixelsTest4, NULL
   1.236  };
   1.237  
   1.238  /* Pixels test suite (global) */