diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index aa8bc899a4c..ee704081bdc 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -92,8 +92,43 @@ static void test_sprintf( void ) } } +static void test_snprintf (void) +{ + struct snprintf_test { + const char *format; + int expected; + struct { + int retval; + int render; + } todo; + }; + /* Pre-2.1 libc behaviour, not C99 compliant. */ + const struct snprintf_test tests[] = {{"short", 5, {0, 0}}, + {"justfit", 7, {0, 0}}, + {"justfits", 8, {0, 1}}, + {"muchlonger", -1, {1, 1}}}; + char buffer[8]; + const int bufsiz = sizeof buffer; + unsigned int i; + + for (i = 0; i < sizeof tests / sizeof tests[0]; i++) { + const char *fmt = tests[i].format; + const int expect = tests[i].expected; + const int n = _snprintf (buffer, bufsiz, fmt); + const int valid = n < 0 ? bufsiz : (n == bufsiz ? n : n+1); + + todo (tests[i].todo.retval ? "wine" : "none") + ok (n == expect, "\"%s\": expected %d, returned %d", + fmt, expect, n); + todo (tests[i].todo.render ? "wine" : "none") + ok (!memcmp (fmt, buffer, valid), + "\"%s\": rendered \"%.*s\"", fmt, valid, buffer); + }; +} + START_TEST(scanf) { test_sscanf(); test_sprintf(); + test_snprintf(); }