test/testautomation_pixels.c
changeset 7151 99a4964db4c3
parent 7142 f4a670e51cde
child 7153 51cf5475ac56
     1.1 --- a/test/testautomation_pixels.c	Sun May 05 16:01:19 2013 +0200
     1.2 +++ b/test/testautomation_pixels.c	Sun May 05 11:17:40 2013 -0700
     1.3 @@ -108,6 +108,9 @@
     1.4  int
     1.5  pixels_allocFreeFormat(void *arg)
     1.6  {
     1.7 +  const char *expectedError = "Parameter 'format' is invalid";
     1.8 +  const char *error;   
     1.9 +  char message[256];
    1.10    int i;
    1.11    Uint32 format;
    1.12    Uint32 masks;
    1.13 @@ -149,15 +152,34 @@
    1.14    }
    1.15    
    1.16    /* Negative cases */
    1.17 +  
    1.18 +  /* Invalid Format */  
    1.19 +  SDL_ClearError();
    1.20 +  SDLTest_AssertPass("Call to SDL_ClearError()");
    1.21    format = 0xffffffff;
    1.22    result = SDL_AllocFormat(format);
    1.23    SDLTest_AssertPass("Call to SDL_AllocFormat(0xffffffff)");
    1.24    SDLTest_AssertCheck(result == NULL, "Verify result is NULL");  
    1.25 -  /* TODO: check error code */
    1.26 +  error = SDL_GetError();
    1.27 +  SDLTest_AssertPass("Call to SDL_GetError()");
    1.28 +  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
    1.29 +  if (error != NULL) {
    1.30 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
    1.31 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
    1.32 +  }
    1.33  
    1.34 +  /* Invalid free pointer */
    1.35 +  SDL_ClearError();
    1.36 +  SDLTest_AssertPass("Call to SDL_ClearError()");
    1.37    SDL_FreeFormat(NULL);
    1.38    SDLTest_AssertPass("Call to SDL_FreeFormat(NULL)");
    1.39 -  /* TODO: check error code */
    1.40 +  error = SDL_GetError();
    1.41 +  SDLTest_AssertPass("Call to SDL_GetError()");
    1.42 +  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
    1.43 +  if (error != NULL) {
    1.44 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0, 
    1.45 +          "Validate error message, expected: '%s', got: '%s'", expectedError, error);
    1.46 +  }
    1.47    
    1.48    return TEST_COMPLETED;
    1.49  }
    1.50 @@ -171,6 +193,10 @@
    1.51  int
    1.52  pixels_allocFreePalette(void *arg)
    1.53  {
    1.54 +  const char *expectedError1 = "Parameter 'ncolors' is invalid";
    1.55 +  const char *expectedError2 = "Parameter 'palette' is invalid";
    1.56 +  const char *error;   
    1.57 +  char message[256];
    1.58    int variation;
    1.59    int i;
    1.60    int ncolors;
    1.61 @@ -216,16 +242,140 @@
    1.62    }
    1.63  
    1.64    /* Negative cases */
    1.65 +    
    1.66 +  /* Invalid number of colors */
    1.67    for (ncolors = 0; ncolors > -3; ncolors--) {
    1.68 +    SDL_ClearError();
    1.69 +    SDLTest_AssertPass("Call to SDL_ClearError()");
    1.70      result = SDL_AllocPalette(ncolors);
    1.71      SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
    1.72      SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
    1.73 -    /* TODO: check error code */
    1.74 +    error = SDL_GetError();
    1.75 +    SDLTest_AssertPass("Call to SDL_GetError()");
    1.76 +    SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
    1.77 +    if (error != NULL) {
    1.78 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0, 
    1.79 +          "Validate error message, expected: '%s', got: '%s'", expectedError1, error);
    1.80 +    }
    1.81    }
    1.82  
    1.83 +  /* Invalid free pointer */
    1.84 +  SDL_ClearError();
    1.85 +  SDLTest_AssertPass("Call to SDL_ClearError()");
    1.86    SDL_FreePalette(NULL);
    1.87    SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
    1.88 -  /* TODO: check error code */
    1.89 +  error = SDL_GetError();
    1.90 +  SDLTest_AssertPass("Call to SDL_GetError()");
    1.91 +  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
    1.92 +  if (error != NULL) {
    1.93 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0, 
    1.94 +          "Validate error message, expected: '%s', got: '%s'", expectedError2, error);
    1.95 +  }
    1.96 +    
    1.97 +  return TEST_COMPLETED;
    1.98 +}
    1.99 +
   1.100 +/**
   1.101 + * @brief Call to SDL_CalculateGammaRamp
   1.102 + *
   1.103 + * @sa http://wiki.libsdl.org/moin.fcg/SDL_CalculateGammaRamp
   1.104 + */
   1.105 +int
   1.106 +pixels_calcGammaRamp(void *arg)
   1.107 +{
   1.108 +  const char *expectedError1 = "Parameter 'gamma' is invalid";
   1.109 +  const char *expectedError2 = "Parameter 'ramp' is invalid";
   1.110 +  const char *error;   
   1.111 +  char message[256];
   1.112 +  float gamma;
   1.113 +  Uint16 *ramp;
   1.114 +  int variation;
   1.115 +  int i;
   1.116 +  int changed;
   1.117 +  Uint16 magic = 0xbeef;
   1.118 +
   1.119 +  /* Allocate temp ramp array and fill with some value*/
   1.120 +  ramp = (Uint16 *)SDL_malloc(256 * sizeof(Uint16));
   1.121 +  SDLTest_AssertCheck(ramp != NULL, "Validate temp ramp array could be allocated");
   1.122 +  if (ramp == NULL) return TEST_ABORTED;
   1.123 +  
   1.124 +  /* Make call with different gamma values */
   1.125 +  for (variation = 0; variation < 4; variation++) {
   1.126 +    switch (variation) {
   1.127 +      /* gamma = 0 all black */
   1.128 +      case 0:      
   1.129 +        gamma = 0.0f;
   1.130 +        break;
   1.131 +      /* gamma = 1 identity */
   1.132 +      case 1:
   1.133 +        gamma = 1.0f;
   1.134 +        break;
   1.135 +      /* gamma = ]0,1[ normal range */  
   1.136 +      case 2:
   1.137 +        gamma = 0.01f + 0.98f * SDLTest_RandomUnitFloat();
   1.138 +        break;
   1.139 +      /* gamma = >1.0 non-standard range */  
   1.140 +      case 3:
   1.141 +        gamma = 0.01f + 0.98f * SDLTest_RandomUnitFloat();
   1.142 +        break;
   1.143 +    }
   1.144 +
   1.145 +    /* Make call and check that values were updated */  
   1.146 +    for (i = 0; i < 256; i++) ramp[i] = magic;
   1.147 +    SDL_CalculateGammaRamp(gamma, ramp);
   1.148 +    SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
   1.149 +    changed = 0;
   1.150 +    for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
   1.151 +    SDLTest_AssertCheck(changed > 250, "Validate that ramp was calculated; expected: >250 values changed, got: %d values changed", changed);
   1.152 +
   1.153 +    /* Additional value checks for some cases */
   1.154 +    i = SDLTest_RandomIntegerInRange(64,192);
   1.155 +    switch (variation) {
   1.156 +      case 0:
   1.157 +        SDLTest_AssertCheck(ramp[i] == 0, "Validate value at position %d; expected: 0, got: %d", i, ramp[i]);
   1.158 +        break;
   1.159 +      case 1:
   1.160 +        SDLTest_AssertCheck(ramp[i] == (i << 8) | i, "Validate value at position %d; expected: %d, got: %d", i, (i << 8) | i, ramp[i]);
   1.161 +        break;
   1.162 +      case 2:
   1.163 +      case 3:
   1.164 +        SDLTest_AssertCheck(ramp[i] > 0, "Validate value at position %d; expected: >0, got: %d", i, ramp[i]);
   1.165 +        break;
   1.166 +    }
   1.167 +  }
   1.168 +
   1.169 +  
   1.170 +  /* Negative cases */
   1.171 +  SDL_ClearError();
   1.172 +  SDLTest_AssertPass("Call to SDL_ClearError()");
   1.173 +  gamma = -1;
   1.174 +  for (i=0; i<256; i++) ramp[i] = magic;
   1.175 +  SDL_CalculateGammaRamp(gamma, ramp);
   1.176 +  SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(%f)", gamma);
   1.177 +  error = SDL_GetError();
   1.178 +  SDLTest_AssertPass("Call to SDL_GetError()");
   1.179 +  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   1.180 +  if (error != NULL) {
   1.181 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0, 
   1.182 +          "Validate error message, expected: '%s', got: '%s'", expectedError1, error);
   1.183 +  }
   1.184 +  changed = 0;
   1.185 +  for (i = 0; i < 256; i++) if (ramp[i] != magic) changed++;
   1.186 +  SDLTest_AssertCheck(changed ==0, "Validate that ramp unchanged; expected: 0 values changed got: %d values changed", changed);
   1.187 +
   1.188 +  SDL_CalculateGammaRamp(0.5f, NULL);
   1.189 +  SDLTest_AssertPass("Call to SDL_CalculateGammaRamp(0.5,NULL)");
   1.190 +  error = SDL_GetError();
   1.191 +  SDLTest_AssertPass("Call to SDL_GetError()");
   1.192 +  SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
   1.193 +  if (error != NULL) {
   1.194 +      SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0, 
   1.195 +          "Validate error message, expected: '%s', got: '%s'", expectedError2, error);
   1.196 +  }
   1.197 +  
   1.198 +  /* Cleanup */
   1.199 +  SDL_free(ramp);
   1.200 +    
   1.201      
   1.202    return TEST_COMPLETED;
   1.203  }
   1.204 @@ -239,9 +389,12 @@
   1.205  static const SDLTest_TestCaseReference pixelsTest2 =
   1.206  		{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED };
   1.207  
   1.208 +static const SDLTest_TestCaseReference pixelsTest3 =
   1.209 +		{ (SDLTest_TestCaseFp)pixels_calcGammaRamp, "pixels_calcGammaRamp", "Call to SDL_CalculateGammaRamp", TEST_ENABLED };
   1.210 +
   1.211  /* Sequence of Pixels test cases */
   1.212  static const SDLTest_TestCaseReference *pixelsTests[] =  {
   1.213 -	&pixelsTest1, &pixelsTest2, NULL
   1.214 +	&pixelsTest1, &pixelsTest2, &pixelsTest3, NULL
   1.215  };
   1.216  
   1.217  /* Pixels test suite (global) */