diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c index 6f7ebde5127..44b84691f02 100644 --- a/dlls/msvcrt/tests/printf.c +++ b/dlls/msvcrt/tests/printf.c @@ -90,466 +90,257 @@ static void init( void ) static void test_sprintf( void ) { + struct { + const char *format; + int r; + const char *out; + enum { + NO_ARG, + INT_ARG, + ULONGLONG_ARG, + DOUBLE_ARG, + PTR_ARG + } type; + int arg_i; + ULONGLONG arg_ull; + double arg_d; + const void *arg_ptr; + } tests[] = { + { "%+#23.15e", 23, "+7.894561230000000e+008", DOUBLE_ARG, 0, 0, 789456123 }, + { "%-#23.15e", 23, "7.894561230000000e+008 ", DOUBLE_ARG, 0, 0, 789456123 }, + { "%#23.15e", 23, " 7.894561230000000e+008", DOUBLE_ARG, 0, 0, 789456123 }, + { "%#1.1g", 7, "8.e+008", DOUBLE_ARG, 0, 0, 789456123 }, + { "%I64d", 11, "-8589934591", ULONGLONG_ARG, 0, ((ULONGLONG)0xffffffff)*0xffffffff }, + { "%+8I64d", 8, " +100", ULONGLONG_ARG, 0, 100 }, + { "%+.8I64d", 9, "+00000100", ULONGLONG_ARG, 0, 100 }, + { "%+10.8I64d", 10, " +00000100", ULONGLONG_ARG, 0, 100 }, + { "%_1I64d", 6, "_1I64d", ULONGLONG_ARG, 0, 100 }, + { "%-1.5I64d", 6, "-00100", ULONGLONG_ARG, 0, -100 }, + { "%5I64d", 5, " 100", ULONGLONG_ARG, 0, 100 }, + { "%5I64d", 5, " -100", ULONGLONG_ARG, 0, -100 }, + { "%-5I64d", 5, "100 ", ULONGLONG_ARG, 0, 100 }, + { "%-5I64d", 5, "-100 ", ULONGLONG_ARG, 0, -100 }, + { "%-.5I64d", 5, "00100", ULONGLONG_ARG, 0, 100 }, + { "%-.5I64d", 6, "-00100", ULONGLONG_ARG, 0, -100 }, + { "%-8.5I64d", 8, "00100 ", ULONGLONG_ARG, 0, 100 }, + { "%-8.5I64d", 8, "-00100 ", ULONGLONG_ARG, 0, -100 }, + { "%05I64d", 5, "00100", ULONGLONG_ARG, 0, 100 }, + { "%05I64d", 5, "-0100", ULONGLONG_ARG, 0, -100 }, + { "% I64d", 4, " 100", ULONGLONG_ARG, 0, 100 }, + { "% I64d", 4, "-100", ULONGLONG_ARG, 0, -100 }, + { "% 5I64d", 5, " 100", ULONGLONG_ARG, 0, 100 }, + { "% 5I64d", 5, " -100", ULONGLONG_ARG, 0, -100 }, + { "% .5I64d", 6, " 00100", ULONGLONG_ARG, 0, 100 }, + { "% .5I64d", 6, "-00100", ULONGLONG_ARG, 0, -100 }, + { "% 8.5I64d", 8, " 00100", ULONGLONG_ARG, 0, 100 }, + { "% 8.5I64d", 8, " -00100", ULONGLONG_ARG, 0, -100 }, + { "%.0I64d", 0, "", ULONGLONG_ARG }, + { "%#+21.18I64x", 21, " 0x00ffffffffffffff9c", ULONGLONG_ARG, 0, -100 }, + { "%#.25I64o", 25, "0001777777777777777777634", ULONGLONG_ARG, 0, -100 }, + { "%#+24.20I64o", 24, " 01777777777777777777634", ULONGLONG_ARG, 0, -100 }, + { "%#+18.21I64X", 23, "0X00000FFFFFFFFFFFFFF9C", ULONGLONG_ARG, 0, -100 }, + { "%#+20.24I64o", 24, "001777777777777777777634", ULONGLONG_ARG, 0, -100 }, + { "%#+25.22I64u", 25, " 0018446744073709551615", ULONGLONG_ARG, 0, -1 }, + { "%#+25.22I64u", 25, " 0018446744073709551615", ULONGLONG_ARG, 0, -1 }, + { "%#+30.25I64u", 30, " 0000018446744073709551615", ULONGLONG_ARG, 0, -1 }, + { "%+#25.22I64d", 25, " -0000000000000000000001", ULONGLONG_ARG, 0, -1 }, + { "%#-8.5I64o", 8, "00144 ", ULONGLONG_ARG, 0, 100 }, + { "%#-+ 08.5I64d", 8, "+00100 ", ULONGLONG_ARG, 0, 100 }, + { "%.80I64d", 80, + "00000000000000000000000000000000000000000000000000000000000000000000000000000001", + ULONGLONG_ARG, 0, 1 }, + { "% .80I64d", 81, + " 00000000000000000000000000000000000000000000000000000000000000000000000000000001", + ULONGLONG_ARG, 0, 1 }, + { "% .80d", 81, + " 00000000000000000000000000000000000000000000000000000000000000000000000000000001", + INT_ARG, 1 }, + { "%I", 1, "I", INT_ARG, 1 }, + { "%I0d", 3, "I0d", INT_ARG, 1 }, + { "%I64D", 1, "D", ULONGLONG_ARG, 0, -1 }, + { "%zx", 2, "zx", INT_ARG, 1 }, + { "% d", 2, " 1", INT_ARG, 1 }, + { "%+ d", 2, "+1", INT_ARG, 1 }, + { "%S", 4, "wide", PTR_ARG, 0, 0, 0, L"wide" }, + { "%04c", 4, "0001", INT_ARG, '1' }, + { "%-04c", 4, "1 ", INT_ARG, '1' }, + { "%#012x", 12, "0x0000000001", INT_ARG, 1 }, + { "%#012x", 12, "000000000000", INT_ARG, 0 }, + { "%#04.8x", 10, "0x00000001", INT_ARG, 1 }, + { "%#04.8x", 8, "00000000", INT_ARG, 0 }, + { "%#-08.2x", 8, "0x01 ", INT_ARG, 1 }, + { "%#-08.2x", 8, "00 ", INT_ARG, 0 }, + { "%#.0x", 3, "0x1", INT_ARG, 1 }, + { "%#.0x", 0, "", INT_ARG, 0 }, + { "%#08o", 8, "00000001", INT_ARG, 1 }, + { "%#o", 2, "01", INT_ARG, 1 }, + { "%#o", 1, "0", INT_ARG, 0 }, + { "%04s", 4, "0foo", PTR_ARG, 0, 0, 0, "foo" }, + { "%.1s", 1, "f", PTR_ARG, 0, 0, 0, "foo" }, + { "hello", 5, "hello", NO_ARG }, + { "%ws", 4, "wide", PTR_ARG, 0, 0, 0, L"wide" }, + { "%-10ws", 10, "wide ", PTR_ARG, 0, 0, 0, L"wide" }, + { "%10ws", 10, " wide", PTR_ARG, 0, 0, 0, L"wide" }, + { "%#+ -03whlls", 4, "wide", PTR_ARG, 0, 0, 0, L"wide" }, + { "%w0s", 2, "0s", PTR_ARG, 0, 0, 0, L"wide" }, + { "%w-s", 2, "-s", PTR_ARG, 0, 0, 0, L"wide" }, + { "%ls", 4, "wide", PTR_ARG, 0, 0, 0, L"wide" }, + { "%Ls", 8, "not wide", PTR_ARG, 0, 0, 0, "not wide" }, + { "%b", 1, "b", NO_ARG }, + { "%3c", 3, " a", INT_ARG, 'a' }, + { "%3d", 4, "1234", INT_ARG, 1234 }, + { "%3h", 0, "", NO_ARG }, + { "%j%k%m%q%r%t%v%y%z", 9, "jkmqrtvyz", NO_ARG }, + { "%-1d", 1, "2", INT_ARG, 2 }, + { "%2.4f", 6, "8.6000", DOUBLE_ARG, 0, 0, 8.6 }, + { "%0f", 8, "0.600000", DOUBLE_ARG, 0, 0, 0.6 }, + { "%.0f", 1, "1", DOUBLE_ARG, 0, 0, 0.6 }, + { "%2.4e", 11, "8.6000e+000", DOUBLE_ARG, 0, 0, 8.6 }, + { "% 2.4e", 12, " 8.6000e+000", DOUBLE_ARG, 0, 0, 8.6 }, + { "% 014.4e", 14, " 008.6000e+000", DOUBLE_ARG, 0, 0, 8.6 }, + { "% 2.4e", 12, "-8.6000e+000", DOUBLE_ARG, 0, 0, -8.6 }, + { "%+2.4e", 12, "+8.6000e+000", DOUBLE_ARG, 0, 0, 8.6 }, + { "%2.4g", 3, "8.6", DOUBLE_ARG, 0, 0, 8.6 }, + { "%-i", 2, "-1", INT_ARG, -1 }, + { "%-i", 1, "1", INT_ARG, 1 }, + { "%+i", 2, "+1", INT_ARG, 1 }, + { "%o", 2, "12", INT_ARG, 10 }, + { "%s", 6, "(null)", PTR_ARG, 0, 0, 0, NULL }, + { "%s", 4, "%%%%", PTR_ARG, 0, 0, 0, "%%%%" }, + { "%u", 10, "4294967295", INT_ARG, -1 }, + { "%w", 0, "", INT_ARG, -1 }, + { "%h", 0, "", INT_ARG, -1 }, + { "%z", 1, "z", INT_ARG, -1 }, + { "%j", 1, "j", INT_ARG, -1 }, + { "%F", 0, "", INT_ARG, -1 }, + { "%N", 0, "", INT_ARG, -1 }, + { "%H", 1, "H", INT_ARG, -1 }, + { "x%cx", 3, "xXx", INT_ARG, 0x100+'X' }, + { "%%0", 2, "%0", NO_ARG }, + { "%hx", 4, "2345", INT_ARG, 0x12345 }, + { "%hhx", 3, "123", INT_ARG, 0x123 }, + { "%hhx", 4, "2345", INT_ARG, 0x12345 }, + { "%lf", 9, "-1.#IND00", DOUBLE_ARG, 0, 0, IND }, + { "%lf", 8, "1.#QNAN0", DOUBLE_ARG, 0, 0, NAN }, + { "%lf", 8, "1.#INF00", DOUBLE_ARG, 0, 0, INFINITY }, + { "%le", 14, "-1.#IND00e+000", DOUBLE_ARG, 0, 0, IND }, + { "%le", 13, "1.#QNAN0e+000", DOUBLE_ARG, 0, 0, NAN }, + { "%le", 13, "1.#INF00e+000", DOUBLE_ARG, 0, 0, INFINITY }, + { "%lg", 7, "-1.#IND", DOUBLE_ARG, 0, 0, IND }, + { "%lg", 7, "1.#QNAN", DOUBLE_ARG, 0, 0, NAN }, + { "%lg", 6, "1.#INF", DOUBLE_ARG, 0, 0, INFINITY }, + { "%010.2lf", 10, "-000001.#J", DOUBLE_ARG, 0, 0, IND }, + { "%010.2lf", 10, "0000001.#R", DOUBLE_ARG, 0, 0, NAN }, + { "%010.2lf", 10, "0000001.#J", DOUBLE_ARG, 0, 0, INFINITY }, + { "%c", 1, "a", INT_ARG, 'a' }, + { "%c", 1, "\x82", INT_ARG, 0xa082 }, + { "%C", 1, "a", INT_ARG, 'a' }, + { "%C", 0, "", INT_ARG, 0x3042 }, + { "a%Cb", 2, "ab", INT_ARG, 0x3042 }, + }; + char buffer[100]; - const char *format; - double pnumber=789456123; - int x, r; - WCHAR wide[] = { 'w','i','d','e',0}; - WCHAR buf_w[2]; + int i, x, r = 0; - format = "%+#23.15e"; - r = p_sprintf(buffer,format,pnumber); - ok(!strcmp(buffer,"+7.894561230000000e+008"),"+#23.15e failed: '%s'\n", buffer); - ok( r==23, "return count wrong\n"); + for (i=0; i