Fixed SDL_SetError() by making NULL fmt a no-op, update test automation
authorAndreas Schiffler
Sun, 17 Jul 2011 20:59:34 -0700
changeset 57668cc2ae74cd83
parent 5765 f4ed7142727a
child 5767 36f7413f460f
Fixed SDL_SetError() by making NULL fmt a no-op, update test automation
src/SDL_error.c
test/test-automation/testplatform/testplatform.c
     1.1 --- a/src/SDL_error.c	Sun Jul 17 19:19:35 2011 +0300
     1.2 +++ b/src/SDL_error.c	Sun Jul 17 20:59:34 2011 -0700
     1.3 @@ -55,6 +55,9 @@
     1.4      va_list ap;
     1.5      SDL_error *error;
     1.6  
     1.7 +    /* Ignore call if invalid format pointer was passed */
     1.8 +    if (fmt == NULL) return;
     1.9 +    
    1.10      /* Copy in the key, mark error as valid */
    1.11      error = SDL_GetErrBuf();
    1.12      error->error = 1;
     2.1 --- a/test/test-automation/testplatform/testplatform.c	Sun Jul 17 19:19:35 2011 +0300
     2.2 +++ b/test/test-automation/testplatform/testplatform.c	Sun Jul 17 20:59:34 2011 -0700
     2.3 @@ -352,13 +352,52 @@
     2.4  int platform_testSetErrorInvalidInput(void *arg)
     2.5  {
     2.6     const char *testError = NULL;
     2.7 +   const char *probeError = "Testing";
     2.8     char *lastError;
     2.9 +   int len;
    2.10 +
    2.11 +   // Reset
    2.12 +   SDL_ClearError();
    2.13     
    2.14 +   // Check for no-op
    2.15     SDL_SetError(testError);
    2.16     AssertPass("SDL_SetError()");
    2.17     lastError = (char *)SDL_GetError();   
    2.18 -   AssertTrue(lastError == NULL, 
    2.19 -             "SDL_GetError() == NULL");
    2.20 +   AssertTrue(lastError != NULL, 
    2.21 +             "SDL_GetError() != NULL");
    2.22 +   if (lastError != NULL)
    2.23 +   {
    2.24 +     len = strlen(lastError);
    2.25 +     AssertTrue(len == 0, 
    2.26 +             "SDL_GetError(): expected message len 0, was len: %i", 
    2.27 +             0, 
    2.28 +             len);
    2.29 +     AssertTrue(strcmp(lastError, "") == 0, 
    2.30 +             "SDL_GetError(): expected message '', was message: '%s'",           
    2.31 +             lastError);
    2.32 +   }
    2.33 +   
    2.34 +   // Set
    2.35 +   SDL_SetError(probeError);
    2.36 +   
    2.37 +   // Check for no-op
    2.38 +   SDL_SetError(testError);
    2.39 +   AssertPass("SDL_SetError()");
    2.40 +   lastError = (char *)SDL_GetError();   
    2.41 +   AssertTrue(lastError != NULL, 
    2.42 +             "SDL_GetError() != NULL");
    2.43 +   if (lastError != NULL)
    2.44 +   {
    2.45 +     len = strlen(lastError);
    2.46 +     AssertTrue(len == strlen(probeError), 
    2.47 +             "SDL_GetError(): expected message len %i, was len: %i", 
    2.48 +             strlen(probeError), 
    2.49 +             len);
    2.50 +     AssertTrue(strcmp(lastError, probeError) == 0, 
    2.51 +             "SDL_GetError(): expected message '%s', was message: '%s'",
    2.52 +             probeError,
    2.53 +             lastError);
    2.54 +   }
    2.55  
    2.56     // Clean up                
    2.57     SDL_ClearError();