Added the beginning of automated tests for the standard C library routines.
authorSam Lantinga <slouken@libsdl.org>
Fri, 24 May 2013 03:23:21 -0700
changeset 72163586fc0ba156
parent 7215 41e739a52f69
child 7217 ae087380127d
Added the beginning of automated tests for the standard C library routines.
Implemented more SDL_snprintf format specifiers.
src/stdlib/SDL_string.c
test/Makefile.in
test/testautomation_stdlib.c
test/testautomation_suites.h
     1.1 --- a/src/stdlib/SDL_string.c	Thu May 23 23:27:48 2013 -0700
     1.2 +++ b/src/stdlib/SDL_string.c	Fri May 24 03:23:21 2013 -0700
     1.3 @@ -1079,8 +1079,7 @@
     1.4                              ++index;
     1.5                          }
     1.6                          if (text[index] == '0') {
     1.7 -                            if (SDL_tolower((unsigned char) text[index + 1])
     1.8 -                                == 'x') {
     1.9 +                            if (SDL_tolower((unsigned char) text[index + 1]) == 'x') {
    1.10                                  radix = 16;
    1.11                              } else {
    1.12                                  radix = 8;
    1.13 @@ -1273,133 +1272,177 @@
    1.14  #undef SDL_vsnprintf
    1.15  int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); }
    1.16  #else
    1.17 + /* FIXME: implement more of the format specifiers */
    1.18 +typedef struct
    1.19 +{
    1.20 +    SDL_bool left_justify;
    1.21 +    SDL_bool force_sign;
    1.22 +    SDL_bool force_type;
    1.23 +    SDL_bool pad_zeroes;
    1.24 +    SDL_bool do_lowercase;
    1.25 +    int width;
    1.26 +    int radix;
    1.27 +    int precision;
    1.28 +} SDL_FormatInfo;
    1.29 +
    1.30  static size_t
    1.31 -SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
    1.32 +SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
    1.33  {
    1.34 -    char num[130];
    1.35 -    size_t size;
    1.36 -
    1.37 -    SDL_ltoa(value, num, radix);
    1.38 -    size = SDL_strlen(num);
    1.39 -    if (size >= maxlen) {
    1.40 -        size = maxlen - 1;
    1.41 -    }
    1.42 -    SDL_strlcpy(text, num, size + 1);
    1.43 -
    1.44 -    return size;
    1.45 +    return SDL_strlcpy(text, string, maxlen);
    1.46  }
    1.47  
    1.48  static size_t
    1.49 -SDL_PrintUnsignedLong(char *text, unsigned long value, int radix,
    1.50 -                      size_t maxlen)
    1.51 +SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
    1.52  {
    1.53      char num[130];
    1.54 -    size_t size;
    1.55  
    1.56 -    SDL_ultoa(value, num, radix);
    1.57 -    size = SDL_strlen(num);
    1.58 -    if (size >= maxlen) {
    1.59 -        size = maxlen - 1;
    1.60 -    }
    1.61 -    SDL_strlcpy(text, num, size + 1);
    1.62 -
    1.63 -    return size;
    1.64 +    SDL_ltoa(value, num, info ? info->radix : 10);
    1.65 +    return SDL_PrintString(text, maxlen, info, num);
    1.66  }
    1.67  
    1.68  static size_t
    1.69 -SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen)
    1.70 +SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned long value)
    1.71  {
    1.72      char num[130];
    1.73 -    size_t size;
    1.74  
    1.75 -    SDL_lltoa(value, num, radix);
    1.76 -    size = SDL_strlen(num);
    1.77 -    if (size >= maxlen) {
    1.78 -        size = maxlen - 1;
    1.79 -    }
    1.80 -    SDL_strlcpy(text, num, size + 1);
    1.81 -
    1.82 -    return size;
    1.83 +    SDL_ultoa(value, num, info ? info->radix : 10);
    1.84 +    return SDL_PrintString(text, maxlen, info, num);
    1.85  }
    1.86  
    1.87  static size_t
    1.88 -SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen)
    1.89 +SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value)
    1.90  {
    1.91      char num[130];
    1.92 -    size_t size;
    1.93  
    1.94 -    SDL_ulltoa(value, num, radix);
    1.95 -    size = SDL_strlen(num);
    1.96 -    if (size >= maxlen) {
    1.97 -        size = maxlen - 1;
    1.98 -    }
    1.99 -    SDL_strlcpy(text, num, size + 1);
   1.100 -
   1.101 -    return size;
   1.102 +    SDL_lltoa(value, num, info ? info->radix : 10);
   1.103 +    return SDL_PrintString(text, maxlen, info, num);
   1.104  }
   1.105  
   1.106  static size_t
   1.107 -SDL_PrintFloat(char *text, double arg, size_t maxlen)
   1.108 +SDL_PrintUnsignedLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Uint64 value)
   1.109  {
   1.110 +    char num[130];
   1.111 +
   1.112 +    SDL_ulltoa(value, num, info ? info->radix : 10);
   1.113 +    return SDL_PrintString(text, maxlen, info, num);
   1.114 +}
   1.115 +
   1.116 +static size_t
   1.117 +SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
   1.118 +{
   1.119 +    int i, width;
   1.120 +    size_t len, spot;
   1.121 +    size_t left = maxlen;
   1.122      char *textstart = text;
   1.123 +
   1.124      if (arg) {
   1.125          /* This isn't especially accurate, but hey, it's easy. :) */
   1.126 -        const double precision = 0.00000001;
   1.127 -        size_t len;
   1.128 +        double precision = 1.0;
   1.129          unsigned long value;
   1.130  
   1.131          if (arg < 0) {
   1.132 -            *text++ = '-';
   1.133 -            --maxlen;
   1.134 +            if (left > 1) {
   1.135 +                *text = '-';
   1.136 +                --left;
   1.137 +            }
   1.138 +            ++text;
   1.139              arg = -arg;
   1.140 +        } else if (info->force_sign) {
   1.141 +            if (left > 1) {
   1.142 +                *text = '+';
   1.143 +                --left;
   1.144 +            }
   1.145 +            ++text;
   1.146          }
   1.147          value = (unsigned long) arg;
   1.148 -        len = SDL_PrintUnsignedLong(text, value, 10, maxlen);
   1.149 +        len = SDL_PrintUnsignedLong(text, left, NULL, value);
   1.150          text += len;
   1.151 -        maxlen -= len;
   1.152 +        if (len >= left) {
   1.153 +            left = SDL_min(left, 1);
   1.154 +        } else {
   1.155 +            left -= len;
   1.156 +        }
   1.157          arg -= value;
   1.158 -        if (arg > precision && maxlen) {
   1.159 +        if (info->precision < 0) {
   1.160 +            info->precision = 6;
   1.161 +        }
   1.162 +        for (i = 0; i < info->precision; ++i) {
   1.163 +            precision *= 0.1;
   1.164 +        }
   1.165 +        if (info->force_type || info->precision > 0) {
   1.166              int mult = 10;
   1.167 -            *text++ = '.';
   1.168 -            while ((arg > precision) && maxlen) {
   1.169 +            if (left > 1) {
   1.170 +                *text = '.';
   1.171 +                --left;
   1.172 +            }
   1.173 +            ++text;
   1.174 +            while (info->precision-- > 0) {
   1.175                  value = (unsigned long) (arg * mult);
   1.176 -                len = SDL_PrintUnsignedLong(text, value, 10, maxlen);
   1.177 +                len = SDL_PrintUnsignedLong(text, left, NULL, value);
   1.178                  text += len;
   1.179 -                maxlen -= len;
   1.180 +                if (len >= left) {
   1.181 +                    left = SDL_min(left, 1);
   1.182 +                } else {
   1.183 +                    left -= len;
   1.184 +                }
   1.185                  arg -= (double) value / mult;
   1.186                  mult *= 10;
   1.187              }
   1.188          }
   1.189      } else {
   1.190 -        *text++ = '0';
   1.191 +        if (left > 1) {
   1.192 +            *text = '0';
   1.193 +            --left;
   1.194 +        }
   1.195 +        ++text;
   1.196 +        if (info->force_type) {
   1.197 +            if (left > 1) {
   1.198 +                *text = '.';
   1.199 +                --left;
   1.200 +            }
   1.201 +            ++text;
   1.202 +        }
   1.203      }
   1.204 -    return (text - textstart);
   1.205 -}
   1.206  
   1.207 -static size_t
   1.208 -SDL_PrintString(char *text, const char *string, size_t maxlen)
   1.209 -{
   1.210 -    char *textstart = text;
   1.211 -    while (*string && maxlen--) {
   1.212 -        *text++ = *string++;
   1.213 +    width = info->width - (int)(text - textstart);
   1.214 +    if (width > 0) {
   1.215 +        char fill = info->pad_zeroes ? '0' : ' ';
   1.216 +        char *end = text+left-1;
   1.217 +        len = (text - textstart);
   1.218 +        for (len = (text - textstart); len--; ) {
   1.219 +            if ((textstart+len+width) < end) {
   1.220 +                *(textstart+len+width) = *(textstart+len);
   1.221 +            }
   1.222 +        }
   1.223 +        len = (size_t)width;
   1.224 +        text += len;
   1.225 +        if (len >= left) {
   1.226 +            left = SDL_min(left, 1);
   1.227 +        } else {
   1.228 +            left -= len;
   1.229 +        }
   1.230 +        while (len--) {
   1.231 +            if (textstart+len < end) {
   1.232 +                textstart[len] = fill;
   1.233 +            }
   1.234 +        }
   1.235      }
   1.236 +
   1.237      return (text - textstart);
   1.238  }
   1.239  
   1.240  int
   1.241  SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
   1.242  {
   1.243 +    size_t left = maxlen;
   1.244      char *textstart = text;
   1.245 -    if (maxlen <= 0) {
   1.246 -        return 0;
   1.247 -    }
   1.248 -    --maxlen;                   /* For the trailing '\0' */
   1.249 -    while (*fmt && maxlen) {
   1.250 +
   1.251 +    while (*fmt) {
   1.252          if (*fmt == '%') {
   1.253              SDL_bool done = SDL_FALSE;
   1.254              size_t len = 0;
   1.255 -            SDL_bool do_lowercase = SDL_FALSE;
   1.256 -            int radix = 10;
   1.257 +            SDL_bool check_flag;
   1.258 +            SDL_FormatInfo info;
   1.259              enum
   1.260              {
   1.261                  DO_INT,
   1.262 @@ -1407,21 +1450,59 @@
   1.263                  DO_LONGLONG
   1.264              } inttype = DO_INT;
   1.265  
   1.266 -            ++fmt;
   1.267 -            /* FIXME: implement more of the format specifiers */
   1.268 -            while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
   1.269 +            SDL_zero(info);
   1.270 +            info.radix = 10;
   1.271 +            info.precision = -1;
   1.272 +
   1.273 +            check_flag = SDL_TRUE;
   1.274 +            while (check_flag) {
   1.275                  ++fmt;
   1.276 +                switch (*fmt) {
   1.277 +                case '-':
   1.278 +                    info.left_justify = SDL_TRUE;
   1.279 +                    break;
   1.280 +                case '+':
   1.281 +                    info.force_sign = SDL_TRUE;
   1.282 +                    break;
   1.283 +                case '#':
   1.284 +                    info.force_type = SDL_TRUE;
   1.285 +                    break;
   1.286 +                case '0':
   1.287 +                    info.pad_zeroes = SDL_TRUE;
   1.288 +                    break;
   1.289 +                default:
   1.290 +                    check_flag = SDL_FALSE;
   1.291 +                    break;
   1.292 +                }
   1.293              }
   1.294 +
   1.295 +            if (*fmt >= '0' && *fmt <= '9') {
   1.296 +                info.width = SDL_strtol(fmt, (char **)&fmt, 0);
   1.297 +            }
   1.298 +
   1.299 +            if (*fmt == '.') {
   1.300 +                ++fmt;
   1.301 +                if (*fmt >= '0' && *fmt <= '9') {
   1.302 +                    info.precision = SDL_strtol(fmt, (char **)&fmt, 0);
   1.303 +                } else {
   1.304 +                    info.precision = 0;
   1.305 +                }
   1.306 +            }
   1.307 +
   1.308              while (!done) {
   1.309                  switch (*fmt) {
   1.310                  case '%':
   1.311 -                    *text = '%';
   1.312 +                    if (left > 1) {
   1.313 +                        *text = '%';
   1.314 +                    }
   1.315                      len = 1;
   1.316                      done = SDL_TRUE;
   1.317                      break;
   1.318                  case 'c':
   1.319                      /* char is promoted to int when passed through (...) */
   1.320 -                    *text = (char) va_arg(ap, int);
   1.321 +                    if (left > 1) {
   1.322 +                        *text = (char) va_arg(ap, int);
   1.323 +                    }
   1.324                      len = 1;
   1.325                      done = SDL_TRUE;
   1.326                      break;
   1.327 @@ -1443,78 +1524,67 @@
   1.328                  case 'd':
   1.329                      switch (inttype) {
   1.330                      case DO_INT:
   1.331 -                        len =
   1.332 -                            SDL_PrintLong(text,
   1.333 -                                          (long) va_arg(ap, int),
   1.334 -                                          radix, maxlen);
   1.335 +                        len = SDL_PrintLong(text, left, &info,
   1.336 +                                            (long) va_arg(ap, int));
   1.337                          break;
   1.338                      case DO_LONG:
   1.339 -                        len =
   1.340 -                            SDL_PrintLong(text, va_arg(ap, long),
   1.341 -                                          radix, maxlen);
   1.342 +                        len = SDL_PrintLong(text, left, &info,
   1.343 +                                            va_arg(ap, long));
   1.344                          break;
   1.345                      case DO_LONGLONG:
   1.346 -                        len =
   1.347 -                            SDL_PrintLongLong(text,
   1.348 -                                              va_arg(ap, Sint64),
   1.349 -                                              radix, maxlen);
   1.350 +                        len = SDL_PrintLongLong(text, left, &info,
   1.351 +                                                va_arg(ap, Sint64));
   1.352                          break;
   1.353                      }
   1.354                      done = SDL_TRUE;
   1.355                      break;
   1.356                  case 'p':
   1.357                  case 'x':
   1.358 -                    do_lowercase = SDL_TRUE;
   1.359 +                    info.do_lowercase = SDL_TRUE;
   1.360                      /* Fall through to 'X' handling */
   1.361                  case 'X':
   1.362 -                    if (radix == 10) {
   1.363 -                        radix = 16;
   1.364 +                    if (info.radix == 10) {
   1.365 +                        info.radix = 16;
   1.366                      }
   1.367                      if (*fmt == 'p') {
   1.368                          inttype = DO_LONG;
   1.369                      }
   1.370                      /* Fall through to unsigned handling */
   1.371                  case 'o':
   1.372 -                    if (radix == 10) {
   1.373 -                        radix = 8;
   1.374 +                    if (info.radix == 10) {
   1.375 +                        info.radix = 8;
   1.376                      }
   1.377                      /* Fall through to unsigned handling */
   1.378                  case 'u':
   1.379                      switch (inttype) {
   1.380                      case DO_INT:
   1.381 -                        len = SDL_PrintUnsignedLong(text, (unsigned long)
   1.382 -                                                    va_arg(ap,
   1.383 -                                                           unsigned
   1.384 -                                                           int),
   1.385 -                                                    radix, maxlen);
   1.386 +                        len = SDL_PrintUnsignedLong(text, left, &info,
   1.387 +                                                    (unsigned long)
   1.388 +                                                    va_arg(ap, unsigned int));
   1.389                          break;
   1.390                      case DO_LONG:
   1.391 -                        len =
   1.392 -                            SDL_PrintUnsignedLong(text,
   1.393 -                                                  va_arg(ap,
   1.394 -                                                         unsigned
   1.395 -                                                         long),
   1.396 -                                                  radix, maxlen);
   1.397 +                        len = SDL_PrintUnsignedLong(text, left, &info,
   1.398 +                                                    va_arg(ap, unsigned long));
   1.399                          break;
   1.400                      case DO_LONGLONG:
   1.401 -                        len =
   1.402 -                            SDL_PrintUnsignedLongLong(text,
   1.403 -                                                      va_arg(ap,
   1.404 -                                                             Uint64),
   1.405 -                                                      radix, maxlen);
   1.406 +                        len = SDL_PrintUnsignedLongLong(text, left, &info,
   1.407 +                                                        va_arg(ap, Uint64));
   1.408                          break;
   1.409                      }
   1.410 -                    if (do_lowercase) {
   1.411 -                        SDL_strlwr(text);
   1.412 +                    if (info.do_lowercase) {
   1.413 +                        size_t i;
   1.414 +                        for (i = 0; i < len && i < left; ++i) {
   1.415 +                            text[i] = SDL_tolower((unsigned char)text[i]);
   1.416 +                        }
   1.417                      }
   1.418                      done = SDL_TRUE;
   1.419                      break;
   1.420                  case 'f':
   1.421 -                    len = SDL_PrintFloat(text, va_arg(ap, double), maxlen);
   1.422 +                    len = SDL_PrintFloat(text, left, &info, va_arg(ap, double));
   1.423                      done = SDL_TRUE;
   1.424                      break;
   1.425                  case 's':
   1.426 -                    len = SDL_PrintString(text, va_arg(ap, char *), maxlen);
   1.427 +                    len = SDL_PrintString(text, left, &info, va_arg(ap, char *));
   1.428                      done = SDL_TRUE;
   1.429                      break;
   1.430                  default:
   1.431 @@ -1524,14 +1594,23 @@
   1.432                  ++fmt;
   1.433              }
   1.434              text += len;
   1.435 -            maxlen -= len;
   1.436 +            if (len >= left) {
   1.437 +                left = SDL_min(left, 1);
   1.438 +            } else {
   1.439 +                left -= len;
   1.440 +            }
   1.441          } else {
   1.442 -            *text++ = *fmt++;
   1.443 -            --maxlen;
   1.444 +            if (left > 1) {
   1.445 +                *text = *fmt;
   1.446 +                --left;
   1.447 +            }
   1.448 +            ++fmt;
   1.449 +            ++text;
   1.450          }
   1.451      }
   1.452 -    *text = '\0';
   1.453 -
   1.454 +    if (left > 0) {
   1.455 +        *text = '\0';
   1.456 +    }
   1.457      return (int)(text - textstart);
   1.458  }
   1.459  #endif
     2.1 --- a/test/Makefile.in	Thu May 23 23:27:48 2013 -0700
     2.2 +++ b/test/Makefile.in	Fri May 24 03:23:21 2013 -0700
     2.3 @@ -69,22 +69,23 @@
     2.4  	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
     2.5  
     2.6  testautomation$(EXE): $(srcdir)/testautomation.c \
     2.7 +		      $(srcdir)/testautomation_audio.c \
     2.8  		      $(srcdir)/testautomation_clipboard.c \
     2.9 +		      $(srcdir)/testautomation_events.c \
    2.10 +		      $(srcdir)/testautomation_keyboard.c \
    2.11  		      $(srcdir)/testautomation_main.c \
    2.12 +		      $(srcdir)/testautomation_mouse.c \
    2.13 +		      $(srcdir)/testautomation_pixels.c \
    2.14  		      $(srcdir)/testautomation_platform.c \
    2.15  		      $(srcdir)/testautomation_rect.c \
    2.16  		      $(srcdir)/testautomation_render.c \
    2.17  		      $(srcdir)/testautomation_rwops.c \
    2.18 -		      $(srcdir)/testautomation_audio.c \
    2.19 +		      $(srcdir)/testautomation_sdltest.c \
    2.20 +		      $(srcdir)/testautomation_stdlib.c \
    2.21  		      $(srcdir)/testautomation_surface.c \
    2.22 -		      $(srcdir)/testautomation_events.c \
    2.23 -		      $(srcdir)/testautomation_keyboard.c \
    2.24 -		      $(srcdir)/testautomation_video.c \
    2.25  		      $(srcdir)/testautomation_syswm.c \
    2.26 -		      $(srcdir)/testautomation_sdltest.c \
    2.27 -		      $(srcdir)/testautomation_mouse.c \
    2.28  		      $(srcdir)/testautomation_timer.c \
    2.29 -		      $(srcdir)/testautomation_pixels.c		      
    2.30 +		      $(srcdir)/testautomation_video.c
    2.31  	$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS) 
    2.32  
    2.33  testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/testautomation_stdlib.c	Fri May 24 03:23:21 2013 -0700
     3.3 @@ -0,0 +1,142 @@
     3.4 +/**
     3.5 + * Standard C library routine test suite
     3.6 + */
     3.7 +
     3.8 +#include <stdio.h>
     3.9 +
    3.10 +#include "SDL.h"
    3.11 +#include "SDL_test.h"
    3.12 +
    3.13 +
    3.14 +/* Test case functions */
    3.15 +
    3.16 +/**
    3.17 + * @brief Call to SDL_strlcpy
    3.18 + */
    3.19 +#undef SDL_strlcpy
    3.20 +int
    3.21 +stdlib_strlcpy(void *arg)
    3.22 +{
    3.23 +  size_t result;
    3.24 +  char text[1024];
    3.25 +  const char *expected;
    3.26 +
    3.27 +  result = SDL_strlcpy(text, "foo", sizeof(text));
    3.28 +  expected = "foo";
    3.29 +  SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
    3.30 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.31 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    3.32 +
    3.33 +  result = SDL_strlcpy(text, "foo", 2);
    3.34 +  expected = "f";
    3.35 +  SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
    3.36 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.37 +  SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
    3.38 +
    3.39 +  return TEST_COMPLETED;
    3.40 +}
    3.41 +
    3.42 +/**
    3.43 + * @brief Call to SDL_snprintf
    3.44 + */
    3.45 +#undef SDL_snprintf
    3.46 +int
    3.47 +stdlib_snprintf(void *arg)
    3.48 +{
    3.49 +  int result;
    3.50 +  char text[1024];
    3.51 +  const char *expected;
    3.52 +
    3.53 +  result = SDL_snprintf(text, sizeof(text), "%s", "foo");
    3.54 +  expected = "foo";
    3.55 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
    3.56 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.57 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    3.58 +
    3.59 +  result = SDL_snprintf(text, 2, "%s", "foo");
    3.60 +  expected = "f";
    3.61 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
    3.62 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.63 +  SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
    3.64 +
    3.65 +  result = SDL_snprintf(NULL, 0, "%s", "foo");
    3.66 +  SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
    3.67 +
    3.68 +  result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
    3.69 +  expected = "1.000000";
    3.70 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
    3.71 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.72 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    3.73 +
    3.74 +  result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
    3.75 +  expected = "1";
    3.76 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
    3.77 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.78 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    3.79 +
    3.80 +  result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
    3.81 +  expected = "1.";
    3.82 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
    3.83 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.84 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    3.85 +
    3.86 +  result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
    3.87 +  expected = "1.333333";
    3.88 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
    3.89 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.90 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    3.91 +
    3.92 +  result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
    3.93 +  expected = "+1.333333";
    3.94 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
    3.95 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
    3.96 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
    3.97 +
    3.98 +  result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
    3.99 +  expected = "1.33";
   3.100 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
   3.101 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
   3.102 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
   3.103 +
   3.104 +  result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
   3.105 +  expected = "  1.33";
   3.106 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
   3.107 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   3.108 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
   3.109 +
   3.110 +  result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
   3.111 +  expected = "001.33";
   3.112 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
   3.113 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   3.114 +  SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
   3.115 +
   3.116 +  result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
   3.117 +  expected = "001.";
   3.118 +  SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
   3.119 +  SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
   3.120 +  SDLTest_AssertCheck(result == 6, "Check result value, expected: 6, got: %d", result);
   3.121 +
   3.122 +  return TEST_COMPLETED;
   3.123 +}
   3.124 +
   3.125 +/* ================= Test References ================== */
   3.126 +
   3.127 +/* Standard C routine test cases */
   3.128 +static const SDLTest_TestCaseReference stdlibTest1 =
   3.129 +        { (SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED };
   3.130 +
   3.131 +static const SDLTest_TestCaseReference stdlibTest2 =
   3.132 +        { (SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_sprintf", TEST_ENABLED };
   3.133 +
   3.134 +/* Sequence of Standard C routine test cases */
   3.135 +static const SDLTest_TestCaseReference *stdlibTests[] =  {
   3.136 +    &stdlibTest1, &stdlibTest2, NULL
   3.137 +};
   3.138 +
   3.139 +/* Timer test suite (global) */
   3.140 +SDLTest_TestSuiteReference stdlibTestSuite = {
   3.141 +    "Standard C routines",
   3.142 +    NULL,
   3.143 +    stdlibTests,
   3.144 +    NULL
   3.145 +};
     4.1 --- a/test/testautomation_suites.h	Thu May 23 23:27:48 2013 -0700
     4.2 +++ b/test/testautomation_suites.h	Fri May 24 03:23:21 2013 -0700
     4.3 @@ -14,17 +14,18 @@
     4.4  extern SDLTest_TestSuiteReference eventsTestSuite;
     4.5  extern SDLTest_TestSuiteReference keyboardTestSuite;
     4.6  extern SDLTest_TestSuiteReference mainTestSuite;
     4.7 +extern SDLTest_TestSuiteReference mouseTestSuite;
     4.8 +extern SDLTest_TestSuiteReference pixelsTestSuite;
     4.9  extern SDLTest_TestSuiteReference platformTestSuite;
    4.10  extern SDLTest_TestSuiteReference rectTestSuite;
    4.11  extern SDLTest_TestSuiteReference renderTestSuite;
    4.12  extern SDLTest_TestSuiteReference rwopsTestSuite;
    4.13 +extern SDLTest_TestSuiteReference sdltestTestSuite;
    4.14 +extern SDLTest_TestSuiteReference stdlibTestSuite;
    4.15  extern SDLTest_TestSuiteReference surfaceTestSuite;
    4.16  extern SDLTest_TestSuiteReference syswmTestSuite;
    4.17 -extern SDLTest_TestSuiteReference sdltestTestSuite;
    4.18 +extern SDLTest_TestSuiteReference timerTestSuite;
    4.19  extern SDLTest_TestSuiteReference videoTestSuite;
    4.20 -extern SDLTest_TestSuiteReference mouseTestSuite;
    4.21 -extern SDLTest_TestSuiteReference timerTestSuite;
    4.22 -extern SDLTest_TestSuiteReference pixelsTestSuite;
    4.23  
    4.24  // All test suites
    4.25  SDLTest_TestSuiteReference *testSuites[] =  {
    4.26 @@ -33,17 +34,18 @@
    4.27      &eventsTestSuite,
    4.28      &keyboardTestSuite,
    4.29      &mainTestSuite,
    4.30 +    &mouseTestSuite,
    4.31 +    &pixelsTestSuite,
    4.32      &platformTestSuite,
    4.33      &rectTestSuite,
    4.34      &renderTestSuite,
    4.35      &rwopsTestSuite,
    4.36 +    &sdltestTestSuite,
    4.37 +    &stdlibTestSuite,
    4.38      &surfaceTestSuite,
    4.39      &syswmTestSuite,
    4.40 -    &sdltestTestSuite,
    4.41 +    &timerTestSuite,
    4.42      &videoTestSuite,
    4.43 -    &mouseTestSuite,
    4.44 -    &timerTestSuite,
    4.45 -    &pixelsTestSuite,
    4.46      NULL
    4.47  };
    4.48