Added the beginning of automated tests for the standard C library routines.
Implemented more SDL_snprintf format specifiers.
This commit is contained in:
parent
00abdbbc2a
commit
03210bff7e
4 changed files with 359 additions and 135 deletions
|
@ -1079,8 +1079,7 @@ SDL_sscanf(const char *text, const char *fmt, ...)
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
if (text[index] == '0') {
|
if (text[index] == '0') {
|
||||||
if (SDL_tolower((unsigned char) text[index + 1])
|
if (SDL_tolower((unsigned char) text[index + 1]) == 'x') {
|
||||||
== 'x') {
|
|
||||||
radix = 16;
|
radix = 16;
|
||||||
} else {
|
} else {
|
||||||
radix = 8;
|
radix = 8;
|
||||||
|
@ -1273,133 +1272,177 @@ SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
|
||||||
#undef SDL_vsnprintf
|
#undef SDL_vsnprintf
|
||||||
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); }
|
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap) { return SDL_vsnprintf_inline(text, maxlen, fmt, ap); }
|
||||||
#else
|
#else
|
||||||
|
/* FIXME: implement more of the format specifiers */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
SDL_bool left_justify;
|
||||||
|
SDL_bool force_sign;
|
||||||
|
SDL_bool force_type;
|
||||||
|
SDL_bool pad_zeroes;
|
||||||
|
SDL_bool do_lowercase;
|
||||||
|
int width;
|
||||||
|
int radix;
|
||||||
|
int precision;
|
||||||
|
} SDL_FormatInfo;
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
SDL_PrintLong(char *text, long value, int radix, size_t maxlen)
|
SDL_PrintString(char *text, size_t maxlen, SDL_FormatInfo *info, const char *string)
|
||||||
|
{
|
||||||
|
return SDL_strlcpy(text, string, maxlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
SDL_PrintLong(char *text, size_t maxlen, SDL_FormatInfo *info, long value)
|
||||||
{
|
{
|
||||||
char num[130];
|
char num[130];
|
||||||
size_t size;
|
|
||||||
|
|
||||||
SDL_ltoa(value, num, radix);
|
SDL_ltoa(value, num, info ? info->radix : 10);
|
||||||
size = SDL_strlen(num);
|
return SDL_PrintString(text, maxlen, info, num);
|
||||||
if (size >= maxlen) {
|
|
||||||
size = maxlen - 1;
|
|
||||||
}
|
|
||||||
SDL_strlcpy(text, num, size + 1);
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
SDL_PrintUnsignedLong(char *text, unsigned long value, int radix,
|
SDL_PrintUnsignedLong(char *text, size_t maxlen, SDL_FormatInfo *info, unsigned long value)
|
||||||
size_t maxlen)
|
|
||||||
{
|
{
|
||||||
char num[130];
|
char num[130];
|
||||||
size_t size;
|
|
||||||
|
|
||||||
SDL_ultoa(value, num, radix);
|
SDL_ultoa(value, num, info ? info->radix : 10);
|
||||||
size = SDL_strlen(num);
|
return SDL_PrintString(text, maxlen, info, num);
|
||||||
if (size >= maxlen) {
|
|
||||||
size = maxlen - 1;
|
|
||||||
}
|
|
||||||
SDL_strlcpy(text, num, size + 1);
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
SDL_PrintLongLong(char *text, Sint64 value, int radix, size_t maxlen)
|
SDL_PrintLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Sint64 value)
|
||||||
{
|
{
|
||||||
char num[130];
|
char num[130];
|
||||||
size_t size;
|
|
||||||
|
|
||||||
SDL_lltoa(value, num, radix);
|
SDL_lltoa(value, num, info ? info->radix : 10);
|
||||||
size = SDL_strlen(num);
|
return SDL_PrintString(text, maxlen, info, num);
|
||||||
if (size >= maxlen) {
|
|
||||||
size = maxlen - 1;
|
|
||||||
}
|
|
||||||
SDL_strlcpy(text, num, size + 1);
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
SDL_PrintUnsignedLongLong(char *text, Uint64 value, int radix, size_t maxlen)
|
SDL_PrintUnsignedLongLong(char *text, size_t maxlen, SDL_FormatInfo *info, Uint64 value)
|
||||||
{
|
{
|
||||||
char num[130];
|
char num[130];
|
||||||
size_t size;
|
|
||||||
|
|
||||||
SDL_ulltoa(value, num, radix);
|
SDL_ulltoa(value, num, info ? info->radix : 10);
|
||||||
size = SDL_strlen(num);
|
return SDL_PrintString(text, maxlen, info, num);
|
||||||
if (size >= maxlen) {
|
|
||||||
size = maxlen - 1;
|
|
||||||
}
|
|
||||||
SDL_strlcpy(text, num, size + 1);
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
SDL_PrintFloat(char *text, double arg, size_t maxlen)
|
SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
|
||||||
{
|
{
|
||||||
|
int i, width;
|
||||||
|
size_t len, spot;
|
||||||
|
size_t left = maxlen;
|
||||||
char *textstart = text;
|
char *textstart = text;
|
||||||
|
|
||||||
if (arg) {
|
if (arg) {
|
||||||
/* This isn't especially accurate, but hey, it's easy. :) */
|
/* This isn't especially accurate, but hey, it's easy. :) */
|
||||||
const double precision = 0.00000001;
|
double precision = 1.0;
|
||||||
size_t len;
|
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
|
|
||||||
if (arg < 0) {
|
if (arg < 0) {
|
||||||
*text++ = '-';
|
if (left > 1) {
|
||||||
--maxlen;
|
*text = '-';
|
||||||
|
--left;
|
||||||
|
}
|
||||||
|
++text;
|
||||||
arg = -arg;
|
arg = -arg;
|
||||||
|
} else if (info->force_sign) {
|
||||||
|
if (left > 1) {
|
||||||
|
*text = '+';
|
||||||
|
--left;
|
||||||
|
}
|
||||||
|
++text;
|
||||||
}
|
}
|
||||||
value = (unsigned long) arg;
|
value = (unsigned long) arg;
|
||||||
len = SDL_PrintUnsignedLong(text, value, 10, maxlen);
|
len = SDL_PrintUnsignedLong(text, left, NULL, value);
|
||||||
text += len;
|
text += len;
|
||||||
maxlen -= len;
|
if (len >= left) {
|
||||||
|
left = SDL_min(left, 1);
|
||||||
|
} else {
|
||||||
|
left -= len;
|
||||||
|
}
|
||||||
arg -= value;
|
arg -= value;
|
||||||
if (arg > precision && maxlen) {
|
if (info->precision < 0) {
|
||||||
|
info->precision = 6;
|
||||||
|
}
|
||||||
|
for (i = 0; i < info->precision; ++i) {
|
||||||
|
precision *= 0.1;
|
||||||
|
}
|
||||||
|
if (info->force_type || info->precision > 0) {
|
||||||
int mult = 10;
|
int mult = 10;
|
||||||
*text++ = '.';
|
if (left > 1) {
|
||||||
while ((arg > precision) && maxlen) {
|
*text = '.';
|
||||||
|
--left;
|
||||||
|
}
|
||||||
|
++text;
|
||||||
|
while (info->precision-- > 0) {
|
||||||
value = (unsigned long) (arg * mult);
|
value = (unsigned long) (arg * mult);
|
||||||
len = SDL_PrintUnsignedLong(text, value, 10, maxlen);
|
len = SDL_PrintUnsignedLong(text, left, NULL, value);
|
||||||
text += len;
|
text += len;
|
||||||
maxlen -= len;
|
if (len >= left) {
|
||||||
|
left = SDL_min(left, 1);
|
||||||
|
} else {
|
||||||
|
left -= len;
|
||||||
|
}
|
||||||
arg -= (double) value / mult;
|
arg -= (double) value / mult;
|
||||||
mult *= 10;
|
mult *= 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*text++ = '0';
|
if (left > 1) {
|
||||||
|
*text = '0';
|
||||||
|
--left;
|
||||||
|
}
|
||||||
|
++text;
|
||||||
|
if (info->force_type) {
|
||||||
|
if (left > 1) {
|
||||||
|
*text = '.';
|
||||||
|
--left;
|
||||||
|
}
|
||||||
|
++text;
|
||||||
}
|
}
|
||||||
return (text - textstart);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
width = info->width - (int)(text - textstart);
|
||||||
SDL_PrintString(char *text, const char *string, size_t maxlen)
|
if (width > 0) {
|
||||||
{
|
char fill = info->pad_zeroes ? '0' : ' ';
|
||||||
char *textstart = text;
|
char *end = text+left-1;
|
||||||
while (*string && maxlen--) {
|
len = (text - textstart);
|
||||||
*text++ = *string++;
|
for (len = (text - textstart); len--; ) {
|
||||||
|
if ((textstart+len+width) < end) {
|
||||||
|
*(textstart+len+width) = *(textstart+len);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
len = (size_t)width;
|
||||||
|
text += len;
|
||||||
|
if (len >= left) {
|
||||||
|
left = SDL_min(left, 1);
|
||||||
|
} else {
|
||||||
|
left -= len;
|
||||||
|
}
|
||||||
|
while (len--) {
|
||||||
|
if (textstart+len < end) {
|
||||||
|
textstart[len] = fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (text - textstart);
|
return (text - textstart);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
|
SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
|
size_t left = maxlen;
|
||||||
char *textstart = text;
|
char *textstart = text;
|
||||||
if (maxlen <= 0) {
|
|
||||||
return 0;
|
while (*fmt) {
|
||||||
}
|
|
||||||
--maxlen; /* For the trailing '\0' */
|
|
||||||
while (*fmt && maxlen) {
|
|
||||||
if (*fmt == '%') {
|
if (*fmt == '%') {
|
||||||
SDL_bool done = SDL_FALSE;
|
SDL_bool done = SDL_FALSE;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
SDL_bool do_lowercase = SDL_FALSE;
|
SDL_bool check_flag;
|
||||||
int radix = 10;
|
SDL_FormatInfo info;
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
DO_INT,
|
DO_INT,
|
||||||
|
@ -1407,21 +1450,59 @@ SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
|
||||||
DO_LONGLONG
|
DO_LONGLONG
|
||||||
} inttype = DO_INT;
|
} inttype = DO_INT;
|
||||||
|
|
||||||
|
SDL_zero(info);
|
||||||
|
info.radix = 10;
|
||||||
|
info.precision = -1;
|
||||||
|
|
||||||
|
check_flag = SDL_TRUE;
|
||||||
|
while (check_flag) {
|
||||||
++fmt;
|
++fmt;
|
||||||
/* FIXME: implement more of the format specifiers */
|
switch (*fmt) {
|
||||||
while (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) {
|
case '-':
|
||||||
++fmt;
|
info.left_justify = SDL_TRUE;
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
info.force_sign = SDL_TRUE;
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
info.force_type = SDL_TRUE;
|
||||||
|
break;
|
||||||
|
case '0':
|
||||||
|
info.pad_zeroes = SDL_TRUE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
check_flag = SDL_FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*fmt >= '0' && *fmt <= '9') {
|
||||||
|
info.width = SDL_strtol(fmt, (char **)&fmt, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*fmt == '.') {
|
||||||
|
++fmt;
|
||||||
|
if (*fmt >= '0' && *fmt <= '9') {
|
||||||
|
info.precision = SDL_strtol(fmt, (char **)&fmt, 0);
|
||||||
|
} else {
|
||||||
|
info.precision = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
switch (*fmt) {
|
switch (*fmt) {
|
||||||
case '%':
|
case '%':
|
||||||
|
if (left > 1) {
|
||||||
*text = '%';
|
*text = '%';
|
||||||
|
}
|
||||||
len = 1;
|
len = 1;
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
/* char is promoted to int when passed through (...) */
|
/* char is promoted to int when passed through (...) */
|
||||||
|
if (left > 1) {
|
||||||
*text = (char) va_arg(ap, int);
|
*text = (char) va_arg(ap, int);
|
||||||
|
}
|
||||||
len = 1;
|
len = 1;
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
break;
|
break;
|
||||||
|
@ -1443,78 +1524,67 @@ SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
|
||||||
case 'd':
|
case 'd':
|
||||||
switch (inttype) {
|
switch (inttype) {
|
||||||
case DO_INT:
|
case DO_INT:
|
||||||
len =
|
len = SDL_PrintLong(text, left, &info,
|
||||||
SDL_PrintLong(text,
|
(long) va_arg(ap, int));
|
||||||
(long) va_arg(ap, int),
|
|
||||||
radix, maxlen);
|
|
||||||
break;
|
break;
|
||||||
case DO_LONG:
|
case DO_LONG:
|
||||||
len =
|
len = SDL_PrintLong(text, left, &info,
|
||||||
SDL_PrintLong(text, va_arg(ap, long),
|
va_arg(ap, long));
|
||||||
radix, maxlen);
|
|
||||||
break;
|
break;
|
||||||
case DO_LONGLONG:
|
case DO_LONGLONG:
|
||||||
len =
|
len = SDL_PrintLongLong(text, left, &info,
|
||||||
SDL_PrintLongLong(text,
|
va_arg(ap, Sint64));
|
||||||
va_arg(ap, Sint64),
|
|
||||||
radix, maxlen);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
case 'x':
|
case 'x':
|
||||||
do_lowercase = SDL_TRUE;
|
info.do_lowercase = SDL_TRUE;
|
||||||
/* Fall through to 'X' handling */
|
/* Fall through to 'X' handling */
|
||||||
case 'X':
|
case 'X':
|
||||||
if (radix == 10) {
|
if (info.radix == 10) {
|
||||||
radix = 16;
|
info.radix = 16;
|
||||||
}
|
}
|
||||||
if (*fmt == 'p') {
|
if (*fmt == 'p') {
|
||||||
inttype = DO_LONG;
|
inttype = DO_LONG;
|
||||||
}
|
}
|
||||||
/* Fall through to unsigned handling */
|
/* Fall through to unsigned handling */
|
||||||
case 'o':
|
case 'o':
|
||||||
if (radix == 10) {
|
if (info.radix == 10) {
|
||||||
radix = 8;
|
info.radix = 8;
|
||||||
}
|
}
|
||||||
/* Fall through to unsigned handling */
|
/* Fall through to unsigned handling */
|
||||||
case 'u':
|
case 'u':
|
||||||
switch (inttype) {
|
switch (inttype) {
|
||||||
case DO_INT:
|
case DO_INT:
|
||||||
len = SDL_PrintUnsignedLong(text, (unsigned long)
|
len = SDL_PrintUnsignedLong(text, left, &info,
|
||||||
va_arg(ap,
|
(unsigned long)
|
||||||
unsigned
|
va_arg(ap, unsigned int));
|
||||||
int),
|
|
||||||
radix, maxlen);
|
|
||||||
break;
|
break;
|
||||||
case DO_LONG:
|
case DO_LONG:
|
||||||
len =
|
len = SDL_PrintUnsignedLong(text, left, &info,
|
||||||
SDL_PrintUnsignedLong(text,
|
va_arg(ap, unsigned long));
|
||||||
va_arg(ap,
|
|
||||||
unsigned
|
|
||||||
long),
|
|
||||||
radix, maxlen);
|
|
||||||
break;
|
break;
|
||||||
case DO_LONGLONG:
|
case DO_LONGLONG:
|
||||||
len =
|
len = SDL_PrintUnsignedLongLong(text, left, &info,
|
||||||
SDL_PrintUnsignedLongLong(text,
|
va_arg(ap, Uint64));
|
||||||
va_arg(ap,
|
|
||||||
Uint64),
|
|
||||||
radix, maxlen);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (do_lowercase) {
|
if (info.do_lowercase) {
|
||||||
SDL_strlwr(text);
|
size_t i;
|
||||||
|
for (i = 0; i < len && i < left; ++i) {
|
||||||
|
text[i] = SDL_tolower((unsigned char)text[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
len = SDL_PrintFloat(text, va_arg(ap, double), maxlen);
|
len = SDL_PrintFloat(text, left, &info, va_arg(ap, double));
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
len = SDL_PrintString(text, va_arg(ap, char *), maxlen);
|
len = SDL_PrintString(text, left, &info, va_arg(ap, char *));
|
||||||
done = SDL_TRUE;
|
done = SDL_TRUE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1524,14 +1594,23 @@ SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
|
||||||
++fmt;
|
++fmt;
|
||||||
}
|
}
|
||||||
text += len;
|
text += len;
|
||||||
maxlen -= len;
|
if (len >= left) {
|
||||||
|
left = SDL_min(left, 1);
|
||||||
} else {
|
} else {
|
||||||
*text++ = *fmt++;
|
left -= len;
|
||||||
--maxlen;
|
}
|
||||||
|
} else {
|
||||||
|
if (left > 1) {
|
||||||
|
*text = *fmt;
|
||||||
|
--left;
|
||||||
|
}
|
||||||
|
++fmt;
|
||||||
|
++text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (left > 0) {
|
||||||
*text = '\0';
|
*text = '\0';
|
||||||
|
}
|
||||||
return (int)(text - textstart);
|
return (int)(text - textstart);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -69,22 +69,23 @@ testaudioinfo$(EXE): $(srcdir)/testaudioinfo.c
|
||||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||||
|
|
||||||
testautomation$(EXE): $(srcdir)/testautomation.c \
|
testautomation$(EXE): $(srcdir)/testautomation.c \
|
||||||
|
$(srcdir)/testautomation_audio.c \
|
||||||
$(srcdir)/testautomation_clipboard.c \
|
$(srcdir)/testautomation_clipboard.c \
|
||||||
|
$(srcdir)/testautomation_events.c \
|
||||||
|
$(srcdir)/testautomation_keyboard.c \
|
||||||
$(srcdir)/testautomation_main.c \
|
$(srcdir)/testautomation_main.c \
|
||||||
|
$(srcdir)/testautomation_mouse.c \
|
||||||
|
$(srcdir)/testautomation_pixels.c \
|
||||||
$(srcdir)/testautomation_platform.c \
|
$(srcdir)/testautomation_platform.c \
|
||||||
$(srcdir)/testautomation_rect.c \
|
$(srcdir)/testautomation_rect.c \
|
||||||
$(srcdir)/testautomation_render.c \
|
$(srcdir)/testautomation_render.c \
|
||||||
$(srcdir)/testautomation_rwops.c \
|
$(srcdir)/testautomation_rwops.c \
|
||||||
$(srcdir)/testautomation_audio.c \
|
|
||||||
$(srcdir)/testautomation_surface.c \
|
|
||||||
$(srcdir)/testautomation_events.c \
|
|
||||||
$(srcdir)/testautomation_keyboard.c \
|
|
||||||
$(srcdir)/testautomation_video.c \
|
|
||||||
$(srcdir)/testautomation_syswm.c \
|
|
||||||
$(srcdir)/testautomation_sdltest.c \
|
$(srcdir)/testautomation_sdltest.c \
|
||||||
$(srcdir)/testautomation_mouse.c \
|
$(srcdir)/testautomation_stdlib.c \
|
||||||
|
$(srcdir)/testautomation_surface.c \
|
||||||
|
$(srcdir)/testautomation_syswm.c \
|
||||||
$(srcdir)/testautomation_timer.c \
|
$(srcdir)/testautomation_timer.c \
|
||||||
$(srcdir)/testautomation_pixels.c
|
$(srcdir)/testautomation_video.c
|
||||||
$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS)
|
$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS)
|
||||||
|
|
||||||
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
|
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
|
||||||
|
|
142
test/testautomation_stdlib.c
Normal file
142
test/testautomation_stdlib.c
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/**
|
||||||
|
* Standard C library routine test suite
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "SDL.h"
|
||||||
|
#include "SDL_test.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Test case functions */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Call to SDL_strlcpy
|
||||||
|
*/
|
||||||
|
#undef SDL_strlcpy
|
||||||
|
int
|
||||||
|
stdlib_strlcpy(void *arg)
|
||||||
|
{
|
||||||
|
size_t result;
|
||||||
|
char text[1024];
|
||||||
|
const char *expected;
|
||||||
|
|
||||||
|
result = SDL_strlcpy(text, "foo", sizeof(text));
|
||||||
|
expected = "foo";
|
||||||
|
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_strlcpy(text, "foo", 2);
|
||||||
|
expected = "f";
|
||||||
|
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||||
|
|
||||||
|
return TEST_COMPLETED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Call to SDL_snprintf
|
||||||
|
*/
|
||||||
|
#undef SDL_snprintf
|
||||||
|
int
|
||||||
|
stdlib_snprintf(void *arg)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
char text[1024];
|
||||||
|
const char *expected;
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%s", "foo");
|
||||||
|
expected = "foo";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, 2, "%s", "foo");
|
||||||
|
expected = "f";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(NULL, 0, "%s", "foo");
|
||||||
|
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
|
||||||
|
expected = "1.000000";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
|
||||||
|
expected = "1";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
|
||||||
|
expected = "1.";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
|
||||||
|
expected = "1.333333";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
|
||||||
|
expected = "+1.333333";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
|
||||||
|
expected = "1.33";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
|
||||||
|
expected = " 1.33";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
|
||||||
|
expected = "001.33";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||||
|
|
||||||
|
result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||||
|
expected = "001.";
|
||||||
|
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
|
||||||
|
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||||
|
SDLTest_AssertCheck(result == 6, "Check result value, expected: 6, got: %d", result);
|
||||||
|
|
||||||
|
return TEST_COMPLETED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================= Test References ================== */
|
||||||
|
|
||||||
|
/* Standard C routine test cases */
|
||||||
|
static const SDLTest_TestCaseReference stdlibTest1 =
|
||||||
|
{ (SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED };
|
||||||
|
|
||||||
|
static const SDLTest_TestCaseReference stdlibTest2 =
|
||||||
|
{ (SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_sprintf", TEST_ENABLED };
|
||||||
|
|
||||||
|
/* Sequence of Standard C routine test cases */
|
||||||
|
static const SDLTest_TestCaseReference *stdlibTests[] = {
|
||||||
|
&stdlibTest1, &stdlibTest2, NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Timer test suite (global) */
|
||||||
|
SDLTest_TestSuiteReference stdlibTestSuite = {
|
||||||
|
"Standard C routines",
|
||||||
|
NULL,
|
||||||
|
stdlibTests,
|
||||||
|
NULL
|
||||||
|
};
|
|
@ -14,17 +14,18 @@ extern SDLTest_TestSuiteReference clipboardTestSuite;
|
||||||
extern SDLTest_TestSuiteReference eventsTestSuite;
|
extern SDLTest_TestSuiteReference eventsTestSuite;
|
||||||
extern SDLTest_TestSuiteReference keyboardTestSuite;
|
extern SDLTest_TestSuiteReference keyboardTestSuite;
|
||||||
extern SDLTest_TestSuiteReference mainTestSuite;
|
extern SDLTest_TestSuiteReference mainTestSuite;
|
||||||
|
extern SDLTest_TestSuiteReference mouseTestSuite;
|
||||||
|
extern SDLTest_TestSuiteReference pixelsTestSuite;
|
||||||
extern SDLTest_TestSuiteReference platformTestSuite;
|
extern SDLTest_TestSuiteReference platformTestSuite;
|
||||||
extern SDLTest_TestSuiteReference rectTestSuite;
|
extern SDLTest_TestSuiteReference rectTestSuite;
|
||||||
extern SDLTest_TestSuiteReference renderTestSuite;
|
extern SDLTest_TestSuiteReference renderTestSuite;
|
||||||
extern SDLTest_TestSuiteReference rwopsTestSuite;
|
extern SDLTest_TestSuiteReference rwopsTestSuite;
|
||||||
|
extern SDLTest_TestSuiteReference sdltestTestSuite;
|
||||||
|
extern SDLTest_TestSuiteReference stdlibTestSuite;
|
||||||
extern SDLTest_TestSuiteReference surfaceTestSuite;
|
extern SDLTest_TestSuiteReference surfaceTestSuite;
|
||||||
extern SDLTest_TestSuiteReference syswmTestSuite;
|
extern SDLTest_TestSuiteReference syswmTestSuite;
|
||||||
extern SDLTest_TestSuiteReference sdltestTestSuite;
|
|
||||||
extern SDLTest_TestSuiteReference videoTestSuite;
|
|
||||||
extern SDLTest_TestSuiteReference mouseTestSuite;
|
|
||||||
extern SDLTest_TestSuiteReference timerTestSuite;
|
extern SDLTest_TestSuiteReference timerTestSuite;
|
||||||
extern SDLTest_TestSuiteReference pixelsTestSuite;
|
extern SDLTest_TestSuiteReference videoTestSuite;
|
||||||
|
|
||||||
// All test suites
|
// All test suites
|
||||||
SDLTest_TestSuiteReference *testSuites[] = {
|
SDLTest_TestSuiteReference *testSuites[] = {
|
||||||
|
@ -33,17 +34,18 @@ SDLTest_TestSuiteReference *testSuites[] = {
|
||||||
&eventsTestSuite,
|
&eventsTestSuite,
|
||||||
&keyboardTestSuite,
|
&keyboardTestSuite,
|
||||||
&mainTestSuite,
|
&mainTestSuite,
|
||||||
|
&mouseTestSuite,
|
||||||
|
&pixelsTestSuite,
|
||||||
&platformTestSuite,
|
&platformTestSuite,
|
||||||
&rectTestSuite,
|
&rectTestSuite,
|
||||||
&renderTestSuite,
|
&renderTestSuite,
|
||||||
&rwopsTestSuite,
|
&rwopsTestSuite,
|
||||||
|
&sdltestTestSuite,
|
||||||
|
&stdlibTestSuite,
|
||||||
&surfaceTestSuite,
|
&surfaceTestSuite,
|
||||||
&syswmTestSuite,
|
&syswmTestSuite,
|
||||||
&sdltestTestSuite,
|
|
||||||
&videoTestSuite,
|
|
||||||
&mouseTestSuite,
|
|
||||||
&timerTestSuite,
|
&timerTestSuite,
|
||||||
&pixelsTestSuite,
|
&videoTestSuite,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue