2 * Conformance tests for *printf functions.
4 * Copyright 2002 Uwe Bonnes
5 * Copyright 2004 Aneurin Price
6 * Copyright 2005 Mike McCormack
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* With Visual Studio >= 2005, swprintf() takes an extra parameter unless
24 * the following macro is defined.
26 #define _CRT_NON_CONFORMING_SWPRINTFS
36 #include "wine/test.h"
38 static inline float __port_infinity(void)
40 static const unsigned __inf_bytes
= 0x7f800000;
41 return *(const float *)&__inf_bytes
;
43 #define INFINITY __port_infinity()
45 static inline float __port_nan(void)
47 static const unsigned __nan_bytes
= 0x7fc00000;
48 return *(const float *)&__nan_bytes
;
50 #define NAN __port_nan()
52 static inline float __port_ind(void)
54 static const unsigned __ind_bytes
= 0xffc00000;
55 return *(const float *)&__ind_bytes
;
57 #define IND __port_ind()
59 static int (__cdecl
*p__vscprintf
)(const char *format
, __ms_va_list valist
);
60 static int (__cdecl
*p__vscwprintf
)(const wchar_t *format
, __ms_va_list valist
);
61 static int (__cdecl
*p__vsnwprintf_s
)(wchar_t *str
, size_t sizeOfBuffer
,
62 size_t count
, const wchar_t *format
,
64 static int (__cdecl
*p__ecvt_s
)(char *buffer
, size_t length
, double number
,
65 int ndigits
, int *decpt
, int *sign
);
66 static int (__cdecl
*p__fcvt_s
)(char *buffer
, size_t length
, double number
,
67 int ndigits
, int *decpt
, int *sign
);
68 static unsigned int (__cdecl
*p__get_output_format
)(void);
69 static unsigned int (__cdecl
*p__set_output_format
)(unsigned int);
70 static int (__cdecl
*p__vsprintf_p
)(char*, size_t, const char*, __ms_va_list
);
71 static int (__cdecl
*p_vswprintf
)(wchar_t *str
, const wchar_t *format
, __ms_va_list valist
);
72 static int (__cdecl
*p__vswprintf
)(wchar_t *str
, const wchar_t *format
, __ms_va_list valist
);
73 static int (__cdecl
*p__vswprintf_l
)(wchar_t *str
, const wchar_t *format
,
74 void *locale
, __ms_va_list valist
);
75 static int (__cdecl
*p__vswprintf_c
)(wchar_t *str
, size_t size
, const wchar_t *format
,
77 static int (__cdecl
*p__vswprintf_c_l
)(wchar_t *str
, size_t size
, const wchar_t *format
,
78 void *locale
, __ms_va_list valist
);
79 static int (__cdecl
*p__vswprintf_p_l
)(wchar_t *str
, size_t size
, const wchar_t *format
,
80 void *locale
, __ms_va_list valist
);
82 static void init( void )
84 HMODULE hmod
= GetModuleHandleA("msvcrt.dll");
86 p__vscprintf
= (void *)GetProcAddress(hmod
, "_vscprintf");
87 p__vscwprintf
= (void *)GetProcAddress(hmod
, "_vscwprintf");
88 p__vsnwprintf_s
= (void *)GetProcAddress(hmod
, "_vsnwprintf_s");
89 p__ecvt_s
= (void *)GetProcAddress(hmod
, "_ecvt_s");
90 p__fcvt_s
= (void *)GetProcAddress(hmod
, "_fcvt_s");
91 p__get_output_format
= (void *)GetProcAddress(hmod
, "_get_output_format");
92 p__set_output_format
= (void *)GetProcAddress(hmod
, "_set_output_format");
93 p__vsprintf_p
= (void*)GetProcAddress(hmod
, "_vsprintf_p");
94 p_vswprintf
= (void*)GetProcAddress(hmod
, "vswprintf");
95 p__vswprintf
= (void*)GetProcAddress(hmod
, "_vswprintf");
96 p__vswprintf_l
= (void*)GetProcAddress(hmod
, "_vswprintf_l");
97 p__vswprintf_c
= (void*)GetProcAddress(hmod
, "_vswprintf_c");
98 p__vswprintf_c_l
= (void*)GetProcAddress(hmod
, "_vswprintf_c_l");
99 p__vswprintf_p_l
= (void*)GetProcAddress(hmod
, "_vswprintf_p_l");
102 static void test_sprintf( void )
106 double pnumber
=789456123;
108 WCHAR wide
[] = { 'w','i','d','e',0};
110 format
= "%+#23.15e";
111 r
= sprintf(buffer
,format
,pnumber
);
112 ok(!strcmp(buffer
,"+7.894561230000000e+008"),"+#23.15e failed: '%s'\n", buffer
);
113 ok( r
==23, "return count wrong\n");
115 format
= "%-#23.15e";
116 r
= sprintf(buffer
,format
,pnumber
);
117 ok(!strcmp(buffer
,"7.894561230000000e+008 "),"-#23.15e failed: '%s'\n", buffer
);
118 ok( r
==23, "return count wrong\n");
121 r
= sprintf(buffer
,format
,pnumber
);
122 ok(!strcmp(buffer
," 7.894561230000000e+008"),"#23.15e failed: '%s'\n", buffer
);
123 ok( r
==23, "return count wrong\n");
126 r
= sprintf(buffer
,format
,pnumber
);
127 ok(!strcmp(buffer
,"8.e+008"),"#1.1g failed: '%s'\n", buffer
);
128 ok( r
==7, "return count wrong\n");
131 r
= sprintf(buffer
,format
,((ULONGLONG
)0xffffffff)*0xffffffff);
132 ok(!strcmp(buffer
,"-8589934591"),"Problem with long long\n");
133 ok( r
==11, "return count wrong\n");
136 r
= sprintf(buffer
,format
,(LONGLONG
)100);
137 ok(!strcmp(buffer
," +100") && r
==8,"+8I64d failed: '%s'\n", buffer
);
140 r
= sprintf(buffer
,format
,(LONGLONG
)100);
141 ok(!strcmp(buffer
,"+00000100") && r
==9,"+.8I64d failed: '%s'\n", buffer
);
143 format
= "%+10.8I64d";
144 r
= sprintf(buffer
,format
,(LONGLONG
)100);
145 ok(!strcmp(buffer
," +00000100") && r
==10,"+10.8I64d failed: '%s'\n", buffer
);
147 r
= sprintf(buffer
,format
,(LONGLONG
)100);
148 ok(!strcmp(buffer
,"_1I64d") && r
==6,"_1I64d failed\n");
150 format
= "%-1.5I64d";
151 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
152 ok(!strcmp(buffer
,"-00100") && r
==6,"-1.5I64d failed: '%s'\n", buffer
);
155 r
= sprintf(buffer
,format
,(LONGLONG
)100);
156 ok(!strcmp(buffer
," 100") && r
==5,"5I64d failed: '%s'\n", buffer
);
159 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
160 ok(!strcmp(buffer
," -100") && r
==5,"5I64d failed: '%s'\n", buffer
);
163 r
= sprintf(buffer
,format
,(LONGLONG
)100);
164 ok(!strcmp(buffer
,"100 ") && r
==5,"-5I64d failed: '%s'\n", buffer
);
167 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
168 ok(!strcmp(buffer
,"-100 ") && r
==5,"-5I64d failed: '%s'\n", buffer
);
171 r
= sprintf(buffer
,format
,(LONGLONG
)100);
172 ok(!strcmp(buffer
,"00100") && r
==5,"-.5I64d failed: '%s'\n", buffer
);
175 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
176 ok(!strcmp(buffer
,"-00100") && r
==6,"-.5I64d failed: '%s'\n", buffer
);
178 format
= "%-8.5I64d";
179 r
= sprintf(buffer
,format
,(LONGLONG
)100);
180 ok(!strcmp(buffer
,"00100 ") && r
==8,"-8.5I64d failed: '%s'\n", buffer
);
182 format
= "%-8.5I64d";
183 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
184 ok(!strcmp(buffer
,"-00100 ") && r
==8,"-8.5I64d failed: '%s'\n", buffer
);
187 r
= sprintf(buffer
,format
,(LONGLONG
)100);
188 ok(!strcmp(buffer
,"00100") && r
==5,"05I64d failed: '%s'\n", buffer
);
191 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
192 ok(!strcmp(buffer
,"-0100") && r
==5,"05I64d failed: '%s'\n", buffer
);
195 r
= sprintf(buffer
,format
,(LONGLONG
)100);
196 ok(!strcmp(buffer
," 100") && r
==4,"' I64d' failed: '%s'\n", buffer
);
199 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
200 ok(!strcmp(buffer
,"-100") && r
==4,"' I64d' failed: '%s'\n", buffer
);
203 r
= sprintf(buffer
,format
,(LONGLONG
)100);
204 ok(!strcmp(buffer
," 100") && r
==5,"' 5I64d' failed: '%s'\n", buffer
);
207 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
208 ok(!strcmp(buffer
," -100") && r
==5,"' 5I64d' failed: '%s'\n", buffer
);
211 r
= sprintf(buffer
,format
,(LONGLONG
)100);
212 ok(!strcmp(buffer
," 00100") && r
==6,"' .5I64d' failed: '%s'\n", buffer
);
215 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
216 ok(!strcmp(buffer
,"-00100") && r
==6,"' .5I64d' failed: '%s'\n", buffer
);
218 format
= "% 8.5I64d";
219 r
= sprintf(buffer
,format
,(LONGLONG
)100);
220 ok(!strcmp(buffer
," 00100") && r
==8,"' 8.5I64d' failed: '%s'\n", buffer
);
222 format
= "% 8.5I64d";
223 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
224 ok(!strcmp(buffer
," -00100") && r
==8,"' 8.5I64d' failed: '%s'\n", buffer
);
227 r
= sprintf(buffer
,format
,(LONGLONG
)0);
228 ok(r
==0,".0I64d failed: '%s'\n", buffer
);
230 format
= "%#+21.18I64x";
231 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
232 ok(!strcmp(buffer
," 0x00ffffffffffffff9c") && r
==21,"#+21.18I64x failed: '%s'\n", buffer
);
234 format
= "%#.25I64o";
235 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
236 ok(!strcmp(buffer
,"0001777777777777777777634") && r
==25,"#.25I64o failed: '%s'\n", buffer
);
238 format
= "%#+24.20I64o";
239 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
240 ok(!strcmp(buffer
," 01777777777777777777634") && r
==24,"#+24.20I64o failed: '%s'\n", buffer
);
242 format
= "%#+18.21I64X";
243 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
244 ok(!strcmp(buffer
,"0X00000FFFFFFFFFFFFFF9C") && r
==23,"#+18.21I64X failed: '%s '\n", buffer
);
246 format
= "%#+20.24I64o";
247 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
248 ok(!strcmp(buffer
,"001777777777777777777634") && r
==24,"#+20.24I64o failed: '%s'\n", buffer
);
250 format
= "%#+25.22I64u";
251 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
252 ok(!strcmp(buffer
," 0018446744073709551615") && r
==25,"#+25.22I64u conversion failed: '%s'\n", buffer
);
254 format
= "%#+25.22I64u";
255 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
256 ok(!strcmp(buffer
," 0018446744073709551615") && r
==25,"#+25.22I64u failed: '%s'\n", buffer
);
258 format
= "%#+30.25I64u";
259 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
260 ok(!strcmp(buffer
," 0000018446744073709551615") && r
==30,"#+30.25I64u failed: '%s'\n", buffer
);
262 format
= "%+#25.22I64d";
263 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
264 ok(!strcmp(buffer
," -0000000000000000000001") && r
==25,"+#25.22I64d failed: '%s'\n", buffer
);
266 format
= "%#-8.5I64o";
267 r
= sprintf(buffer
,format
,(LONGLONG
)100);
268 ok(!strcmp(buffer
,"00144 ") && r
==8,"-8.5I64o failed: '%s'\n", buffer
);
270 format
= "%#-+ 08.5I64d";
271 r
= sprintf(buffer
,format
,(LONGLONG
)100);
272 ok(!strcmp(buffer
,"+00100 ") && r
==8,"'#-+ 08.5I64d failed: '%s'\n", buffer
);
274 format
= "%#-+ 08.5I64d";
275 r
= sprintf(buffer
,format
,(LONGLONG
)100);
276 ok(!strcmp(buffer
,"+00100 ") && r
==8,"#-+ 08.5I64d failed: '%s'\n", buffer
);
279 r
= sprintf(buffer
,format
,(LONGLONG
)1);
280 ok(r
==80,"%s format failed\n", format
);
282 format
= "% .80I64d";
283 r
= sprintf(buffer
,format
,(LONGLONG
)1);
284 ok(r
==81,"%s format failed\n", format
);
287 r
= sprintf(buffer
,format
,1);
288 ok(r
==81,"%s format failed\n", format
);
291 r
= sprintf(buffer
,format
,((ULONGLONG
)0xffffffff)*0xffffffff);
292 ok( r
== 1 || r
== 11, "return count wrong %d\n", r
);
293 if (r
== 11) /* %ll works on Vista */
294 ok(!strcmp(buffer
, "-8589934591"), "Problem with \"ll\" interpretation '%s'\n", buffer
);
296 ok(!strcmp(buffer
, "1"), "Problem with \"ll\" interpretation '%s'\n", buffer
);
299 r
= sprintf(buffer
,format
,1);
300 ok(!strcmp(buffer
, "I"), "Problem with \"I\" interpretation\n");
301 ok( r
==1, "return count wrong\n");
304 r
= sprintf(buffer
,format
,1);
305 ok(!strcmp(buffer
,"I0d"),"I0d failed\n");
306 ok( r
==3, "return count wrong\n");
309 r
= sprintf(buffer
,format
,1);
312 ok(!strcmp(buffer
,"1"),"I32d failed, got '%s'\n",buffer
);
316 /* Older versions don't grok I32 format */
317 ok(r
== 4 && !strcmp(buffer
,"I32d"),"I32d failed, got '%s',%d\n",buffer
,r
);
321 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
322 ok(!strcmp(buffer
,"D"),"I64D failed: %s\n",buffer
);
323 ok( r
==1, "return count wrong\n");
326 r
= sprintf(buffer
,format
,1);
327 ok(!strcmp(buffer
, "zx"), "Problem with \"z\" interpretation\n");
328 ok( r
==2, "return count wrong\n");
331 r
= sprintf(buffer
,format
,1);
332 ok(!strcmp(buffer
, " 1"),"Problem with sign place-holder: '%s'\n",buffer
);
333 ok( r
==2, "return count wrong\n");
336 r
= sprintf(buffer
,format
,1);
337 ok(!strcmp(buffer
, "+1"),"Problem with sign flags: '%s'\n",buffer
);
338 ok( r
==2, "return count wrong\n");
341 r
= sprintf(buffer
,format
,wide
);
342 ok(!strcmp(buffer
,"wide"),"Problem with wide string format\n");
343 ok( r
==4, "return count wrong\n");
346 r
= sprintf(buffer
,format
,'1');
347 ok(!strcmp(buffer
,"0001"),"Character not zero-prefixed \"%s\"\n",buffer
);
348 ok( r
==4, "return count wrong\n");
351 r
= sprintf(buffer
,format
,'1');
352 ok(!strcmp(buffer
,"1 "),"Character zero-padded and/or not left-adjusted \"%s\"\n",buffer
);
353 ok( r
==4, "return count wrong\n");
356 r
= sprintf(buffer
,format
,1);
357 ok(!strcmp(buffer
,"0x0000000001"),"Hexadecimal zero-padded \"%s\"\n",buffer
);
358 ok( r
==12, "return count wrong\n");
360 r
= sprintf(buffer
,format
,0);
361 ok(!strcmp(buffer
,"000000000000"),"Hexadecimal zero-padded \"%s\"\n",buffer
);
362 ok( r
==12, "return count wrong\n");
365 r
= sprintf(buffer
,format
,1);
366 ok(!strcmp(buffer
,"0x00000001"), "Hexadecimal zero-padded precision \"%s\"\n",buffer
);
367 ok( r
==10, "return count wrong\n");
369 r
= sprintf(buffer
,format
,0);
370 ok(!strcmp(buffer
,"00000000"), "Hexadecimal zero-padded precision \"%s\"\n",buffer
);
371 ok( r
==8, "return count wrong\n");
374 r
= sprintf(buffer
,format
,1);
375 ok(!strcmp(buffer
,"0x01 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer
);
376 ok( r
==8, "return count wrong\n");
378 r
= sprintf(buffer
,format
,0);
379 ok(!strcmp(buffer
,"00 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer
);
380 ok( r
==8, "return count wrong\n");
383 r
= sprintf(buffer
,format
,1);
384 ok(!strcmp(buffer
,"0x1"), "Hexadecimal zero-padded zero-precision \"%s\"\n",buffer
);
385 ok( r
==3, "return count wrong\n");
387 r
= sprintf(buffer
,format
,0);
388 ok(!strcmp(buffer
,""), "Hexadecimal zero-padded zero-precision \"%s\"\n",buffer
);
389 ok( r
==0, "return count wrong\n");
392 r
= sprintf(buffer
,format
,1);
393 ok(!strcmp(buffer
,"00000001"), "Octal zero-padded \"%s\"\n",buffer
);
394 ok( r
==8, "return count wrong\n");
397 r
= sprintf(buffer
,format
,1);
398 ok(!strcmp(buffer
,"01"), "Octal zero-padded \"%s\"\n",buffer
);
399 ok( r
==2, "return count wrong\n");
401 r
= sprintf(buffer
,format
,0);
402 ok(!strcmp(buffer
,"0"), "Octal zero-padded \"%s\"\n",buffer
);
403 ok( r
==1, "return count wrong\n");
405 if (sizeof(void *) == 8)
408 r
= sprintf(buffer
,format
,(void *)57);
409 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
410 ok( r
==16, "return count wrong\n");
413 r
= sprintf(buffer
,format
,(void *)57);
414 ok(!strcmp(buffer
," 0X0000000000000039"),"Pointer formatted incorrectly\n");
415 ok( r
==20, "return count wrong\n");
418 r
= sprintf(buffer
,format
,(void *)57);
419 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
420 ok( r
==16, "return count wrong\n");
423 r
= sprintf(buffer
,format
,(void *)57);
424 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
425 ok( r
==16, "return count wrong\n");
428 r
= sprintf(buffer
,format
,(void *)57);
429 ok(!strcmp(buffer
,"0X0000000000000039 "),"Pointer formatted incorrectly\n");
430 ok( r
==20, "return count wrong\n");
433 r
= sprintf(buffer
,format
,(size_t)0x12345678123456,1);
434 ok(!strcmp(buffer
,"12345678123456 1"),"buffer = %s\n",buffer
);
435 ok( r
==16, "return count wrong\n");
440 r
= sprintf(buffer
,format
,(void *)57);
441 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
442 ok( r
==8, "return count wrong\n");
445 r
= sprintf(buffer
,format
,(void *)57);
446 ok(!strcmp(buffer
," 0X00000039"),"Pointer formatted incorrectly\n");
447 ok( r
==12, "return count wrong\n");
450 r
= sprintf(buffer
,format
,(void *)57);
451 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
452 ok( r
==8, "return count wrong\n");
455 r
= sprintf(buffer
,format
,(void *)57);
456 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
457 ok( r
==8, "return count wrong\n");
460 r
= sprintf(buffer
,format
,(void *)57);
461 ok(!strcmp(buffer
,"0X00000039 "),"Pointer formatted incorrectly\n");
462 ok( r
==12, "return count wrong\n");
465 r
= sprintf(buffer
,format
,0x123456,1);
466 ok(!strcmp(buffer
,"123456 1"),"buffer = %s\n",buffer
);
467 ok( r
==8, "return count wrong\n");
471 r
= sprintf(buffer
,format
,"foo");
472 ok(!strcmp(buffer
,"0foo"),"String not zero-prefixed \"%s\"\n",buffer
);
473 ok( r
==4, "return count wrong\n");
476 r
= sprintf(buffer
,format
,"foo");
477 ok(!strcmp(buffer
,"f"),"Precision ignored \"%s\"\n",buffer
);
478 ok( r
==1, "return count wrong\n");
481 r
= sprintf(buffer
,format
,1,"foo");
482 ok(!strcmp(buffer
,"f"),"Precision ignored \"%s\"\n",buffer
);
483 ok( r
==1, "return count wrong\n");
486 r
= sprintf(buffer
,format
,-5,"foo");
487 ok(!strcmp(buffer
,"foo "),"Negative field width ignored \"%s\"\n",buffer
);
488 ok( r
==5, "return count wrong\n");
491 r
= sprintf(buffer
, format
);
492 ok(!strcmp(buffer
,"hello"), "failed\n");
493 ok( r
==5, "return count wrong\n");
496 r
= sprintf(buffer
, format
, wide
);
497 ok(!strcmp(buffer
,"wide"), "failed\n");
498 ok( r
==4, "return count wrong\n");
501 r
= sprintf(buffer
, format
, wide
);
502 ok(!strcmp(buffer
,"wide "), "failed\n");
503 ok( r
==10, "return count wrong\n");
506 r
= sprintf(buffer
, format
, wide
);
507 ok(!strcmp(buffer
," wide"), "failed\n");
508 ok( r
==10, "return count wrong\n");
510 format
= "%#+ -03whlls";
511 r
= sprintf(buffer
, format
, wide
);
512 ok(!strcmp(buffer
,"wide"), "failed\n");
513 ok( r
==4, "return count wrong\n");
516 r
= sprintf(buffer
, format
, wide
);
517 ok(!strcmp(buffer
,"0s"), "failed\n");
518 ok( r
==2, "return count wrong\n");
521 r
= sprintf(buffer
, format
, wide
);
522 ok(!strcmp(buffer
,"-s"), "failed\n");
523 ok( r
==2, "return count wrong\n");
526 r
= sprintf(buffer
, format
, wide
);
527 ok(!strcmp(buffer
,"wide"), "failed\n");
528 ok( r
==4, "return count wrong\n");
531 r
= sprintf(buffer
, format
, "not wide" );
532 ok(!strcmp(buffer
,"not wide"), "failed\n");
533 ok( r
==8, "return count wrong\n");
536 r
= sprintf(buffer
, format
);
537 ok(!strcmp(buffer
,"b"), "failed\n");
538 ok( r
==1, "return count wrong\n");
541 r
= sprintf(buffer
, format
,'a');
542 ok(!strcmp(buffer
," a"), "failed\n");
543 ok( r
==3, "return count wrong\n");
546 r
= sprintf(buffer
, format
,1234);
547 ok(!strcmp(buffer
,"1234"), "failed\n");
548 ok( r
==4, "return count wrong\n");
551 r
= sprintf(buffer
, format
);
552 ok(!strcmp(buffer
,""), "failed\n");
553 ok( r
==0, "return count wrong\n");
555 format
= "%j%k%m%q%r%t%v%y%z";
556 r
= sprintf(buffer
, format
);
557 ok(!strcmp(buffer
,"jkmqrtvyz"), "failed\n");
558 ok( r
==9, "return count wrong\n");
562 r
= sprintf(buffer
, format
, &x
);
565 /* %n format is disabled by default on vista */
566 /* FIXME: should test with _set_printf_count_output */
567 ok(x
== 0, "should not write to x: %d\n", x
);
571 ok(x
== 4, "should write to x: %d\n", x
);
572 ok(!strcmp(buffer
,"asdf"), "failed\n");
573 ok( r
==4, "return count wrong: %d\n", r
);
577 r
= sprintf(buffer
, format
,2);
578 ok(!strcmp(buffer
,"2"), "failed\n");
579 ok( r
==1, "return count wrong\n");
582 r
= sprintf(buffer
, format
,8.6);
583 ok(!strcmp(buffer
,"8.6000"), "failed\n");
584 ok( r
==6, "return count wrong\n");
587 r
= sprintf(buffer
, format
,0.6);
588 ok(!strcmp(buffer
,"0.600000"), "failed\n");
589 ok( r
==8, "return count wrong\n");
592 r
= sprintf(buffer
, format
,0.6);
593 ok(!strcmp(buffer
,"1"), "failed\n");
594 ok( r
==1, "return count wrong\n");
597 r
= sprintf(buffer
, format
,8.6);
598 ok(!strcmp(buffer
,"8.6000e+000"), "failed\n");
599 ok( r
==11, "return count wrong\n");
602 r
= sprintf(buffer
, format
,8.6);
603 ok(!strcmp(buffer
," 8.6000e+000"), "failed: %s\n", buffer
);
604 ok( r
==12, "return count wrong\n");
607 r
= sprintf(buffer
, format
,8.6);
608 ok(!strcmp(buffer
," 008.6000e+000"), "failed: %s\n", buffer
);
609 ok( r
==14, "return count wrong\n");
612 r
= sprintf(buffer
, format
,-8.6);
613 ok(!strcmp(buffer
,"-8.6000e+000"), "failed: %s\n", buffer
);
614 ok( r
==12, "return count wrong\n");
617 r
= sprintf(buffer
, format
,8.6);
618 ok(!strcmp(buffer
,"+8.6000e+000"), "failed: %s\n", buffer
);
619 ok( r
==12, "return count wrong\n");
622 r
= sprintf(buffer
, format
,8.6);
623 ok(!strcmp(buffer
,"8.6"), "failed\n");
624 ok( r
==3, "return count wrong\n");
627 r
= sprintf(buffer
, format
,-1);
628 ok(!strcmp(buffer
,"-1"), "failed\n");
629 ok( r
==2, "return count wrong\n");
632 r
= sprintf(buffer
, format
,1);
633 ok(!strcmp(buffer
,"1"), "failed\n");
634 ok( r
==1, "return count wrong\n");
637 r
= sprintf(buffer
, format
,1);
638 ok(!strcmp(buffer
,"+1"), "failed\n");
639 ok( r
==2, "return count wrong\n");
642 r
= sprintf(buffer
, format
,10);
643 ok(!strcmp(buffer
,"12"), "failed\n");
644 ok( r
==2, "return count wrong\n");
647 r
= sprintf(buffer
, format
,0);
648 if (sizeof(void *) == 8)
650 ok(!strcmp(buffer
,"0000000000000000"), "failed\n");
651 ok( r
==16, "return count wrong\n");
655 ok(!strcmp(buffer
,"00000000"), "failed\n");
656 ok( r
==8, "return count wrong\n");
660 r
= sprintf(buffer
, format
,0);
661 ok(!strcmp(buffer
,"(null)"), "failed\n");
662 ok( r
==6, "return count wrong\n");
665 r
= sprintf(buffer
, format
,"%%%%");
666 ok(!strcmp(buffer
,"%%%%"), "failed\n");
667 ok( r
==4, "return count wrong\n");
670 r
= sprintf(buffer
, format
,-1);
671 ok(!strcmp(buffer
,"4294967295"), "failed\n");
672 ok( r
==10, "return count wrong\n");
675 r
= sprintf(buffer
, format
,-1);
676 ok(!strcmp(buffer
,""), "failed\n");
677 ok( r
==0, "return count wrong\n");
680 r
= sprintf(buffer
, format
,-1);
681 ok(!strcmp(buffer
,""), "failed\n");
682 ok( r
==0, "return count wrong\n");
685 r
= sprintf(buffer
, format
,-1);
686 ok(!strcmp(buffer
,"z"), "failed\n");
687 ok( r
==1, "return count wrong\n");
690 r
= sprintf(buffer
, format
,-1);
691 ok(!strcmp(buffer
,"j"), "failed\n");
692 ok( r
==1, "return count wrong\n");
695 r
= sprintf(buffer
, format
,-1);
696 ok(!strcmp(buffer
,""), "failed\n");
697 ok( r
==0, "return count wrong\n");
700 r
= sprintf(buffer
, format
,-1);
701 ok(!strcmp(buffer
,""), "failed\n");
702 ok( r
==0, "return count wrong\n");
705 r
= sprintf(buffer
, format
,-1);
706 ok(!strcmp(buffer
,"H"), "failed\n");
707 ok( r
==1, "return count wrong\n");
710 r
= sprintf(buffer
, format
, 0x100+'X');
711 ok(!strcmp(buffer
,"xXx"), "failed\n");
712 ok( r
==3, "return count wrong\n");
715 r
= sprintf(buffer
, format
);
716 ok(!strcmp(buffer
,"%0"), "failed: \"%s\"\n", buffer
);
717 ok( r
==2, "return count wrong\n");
720 r
= sprintf(buffer
, format
, 0x12345);
721 ok(!strcmp(buffer
,"2345"), "failed \"%s\"\n", buffer
);
724 r
= sprintf(buffer
, format
, 0x123);
725 ok(!strcmp(buffer
,"123"), "failed: \"%s\"\n", buffer
);
726 r
= sprintf(buffer
, format
, 0x12345);
727 ok(!strcmp(buffer
,"2345"), "failed \"%s\"\n", buffer
);
730 r
= sprintf(buffer
, format
, IND
);
731 ok(r
==9, "r = %d\n", r
);
732 ok(!strcmp(buffer
, "-1.#IND00"), "failed: \"%s\"\n", buffer
);
733 r
= sprintf(buffer
, format
, NAN
);
734 ok(r
==8, "r = %d\n", r
);
735 ok(!strcmp(buffer
, "1.#QNAN0"), "failed: \"%s\"\n", buffer
);
736 r
= sprintf(buffer
, format
, INFINITY
);
737 ok(r
==8, "r = %d\n", r
);
738 ok(!strcmp(buffer
, "1.#INF00"), "failed: \"%s\"\n", buffer
);
741 r
= sprintf(buffer
, format
, IND
);
742 ok(r
==14, "r = %d\n", r
);
743 ok(!strcmp(buffer
, "-1.#IND00e+000"), "failed: \"%s\"\n", buffer
);
744 r
= sprintf(buffer
, format
, NAN
);
745 ok(r
==13, "r = %d\n", r
);
746 ok(!strcmp(buffer
, "1.#QNAN0e+000"), "failed: \"%s\"\n", buffer
);
747 r
= sprintf(buffer
, format
, INFINITY
);
748 ok(r
==13, "r = %d\n", r
);
749 ok(!strcmp(buffer
, "1.#INF00e+000"), "failed: \"%s\"\n", buffer
);
752 r
= sprintf(buffer
, format
, IND
);
753 ok(r
==7, "r = %d\n", r
);
754 ok(!strcmp(buffer
, "-1.#IND"), "failed: \"%s\"\n", buffer
);
755 r
= sprintf(buffer
, format
, NAN
);
756 ok(r
==7, "r = %d\n", r
);
757 ok(!strcmp(buffer
, "1.#QNAN"), "failed: \"%s\"\n", buffer
);
758 r
= sprintf(buffer
, format
, INFINITY
);
759 ok(r
==6, "r = %d\n", r
);
760 ok(!strcmp(buffer
, "1.#INF"), "failed: \"%s\"\n", buffer
);
763 r
= sprintf(buffer
, format
, IND
);
764 ok(r
==10, "r = %d\n", r
);
765 ok(!strcmp(buffer
, "-000001.#J"), "failed: \"%s\"\n", buffer
);
766 r
= sprintf(buffer
, format
, NAN
);
767 ok(r
==10, "r = %d\n", r
);
768 ok(!strcmp(buffer
, "0000001.#R"), "failed: \"%s\"\n", buffer
);
769 r
= sprintf(buffer
, format
, INFINITY
);
770 ok(r
==10, "r = %d\n", r
);
771 ok(!strcmp(buffer
, "0000001.#J"), "failed: \"%s\"\n", buffer
);
774 r
= sprintf(buffer
, format
, 'a');
775 ok(r
==1, "r = %d\n", r
);
776 ok(!strcmp(buffer
, "a"), "failed: \"%s\"\n", buffer
);
777 r
= sprintf(buffer
, format
, 0xa082);
778 ok(r
==1, "r = %d\n", r
);
779 ok(!strcmp(buffer
, "\x82"), "failed: \"%s\"\n", buffer
);
782 r
= sprintf(buffer
, format
, 'a');
783 ok(r
==1, "r = %d\n", r
);
784 ok(!strcmp(buffer
, "a"), "failed: \"%s\"\n", buffer
);
785 r
= sprintf(buffer
, format
, 0x3042);
786 ok(r
==0, "r = %d\n", r
);
787 ok(!strcmp(buffer
, ""), "failed: \"%s\"\n", buffer
);
789 if(!setlocale(LC_ALL
, "Japanese_Japan.932")) {
790 win_skip("Japanese_Japan.932 locale not available\n");
795 r
= sprintf(buffer
, format
, 0xa082);
796 ok(r
==1, "r = %d\n", r
);
797 ok(!strcmp(buffer
, "\x82"), "failed: \"%s\"\n", buffer
);
800 r
= sprintf(buffer
, format
, 0x3042);
801 ok(r
==2, "r = %d\n", r
);
802 ok(!strcmp(buffer
, "\x82\xa0"), "failed: \"%s\"\n", buffer
);
804 setlocale(LC_ALL
, "C");
807 static void test_swprintf( void )
810 const wchar_t I64d
[] = {'%','I','6','4','d',0};
811 double pnumber
=789456123;
812 const wchar_t TwentyThreePoint15e
[]= {'%','+','#','2','3','.','1','5','e',0};
813 const wchar_t e008
[] = {'e','+','0','0','8',0};
814 const wchar_t string_w
[] = {'s','t','r','i','n','g',0};
815 const char string
[] = "string";
816 const wchar_t S
[]={'%','S',0};
817 const wchar_t hs
[] = {'%', 'h', 's', 0};
819 swprintf(buffer
,TwentyThreePoint15e
,pnumber
);
820 ok(wcsstr(buffer
,e008
) != 0,"Sprintf different\n");
821 swprintf(buffer
,I64d
,((ULONGLONG
)0xffffffff)*0xffffffff);
822 ok(wcslen(buffer
) == 11,"Problem with long long\n");
823 swprintf(buffer
,S
,string
);
824 ok(wcslen(buffer
) == 6,"Problem with \"%%S\" interpretation\n");
825 swprintf(buffer
, hs
, string
);
826 ok( wcscmp(string_w
,buffer
) == 0, "swprintf failed with %%hs\n");
829 static void test_snprintf (void)
831 struct snprintf_test
{
835 /* Pre-2.1 libc behaviour, not C99 compliant. */
836 const struct snprintf_test tests
[] = {{"short", 5},
841 const int bufsiz
= sizeof buffer
;
844 for (i
= 0; i
< sizeof tests
/ sizeof tests
[0]; i
++) {
845 const char *fmt
= tests
[i
].format
;
846 const int expect
= tests
[i
].expected
;
847 const int n
= _snprintf (buffer
, bufsiz
, fmt
);
848 const int valid
= n
< 0 ? bufsiz
: (n
== bufsiz
? n
: n
+1);
850 ok (n
== expect
, "\"%s\": expected %d, returned %d\n",
852 ok (!memcmp (fmt
, buffer
, valid
),
853 "\"%s\": rendered \"%.*s\"\n", fmt
, valid
, buffer
);
857 static void test_fprintf(void)
859 static const char file_name
[] = "fprintf.tst";
860 static const WCHAR utf16_test
[] = {'u','n','i','c','o','d','e','\n',0};
862 FILE *fp
= fopen(file_name
, "wb");
866 ret
= fprintf(fp
, "simple test\n");
867 ok(ret
== 12, "ret = %d\n", ret
);
869 ok(ret
== 12, "ftell returned %d\n", ret
);
871 ret
= fprintf(fp
, "contains%cnull\n", '\0');
872 ok(ret
== 14, "ret = %d\n", ret
);
874 ok(ret
== 26, "ftell returned %d\n", ret
);
876 ret
= fwprintf(fp
, utf16_test
);
877 ok(ret
== 8, "ret = %d\n", ret
);
879 ok(ret
== 42, "ftell returned %d\n", ret
);
883 fp
= fopen(file_name
, "rb");
884 ret
= fscanf(fp
, "%[^\n] ", buf
);
885 ok(ret
== 1, "ret = %d\n", ret
);
887 ok(ret
== 12, "ftell returned %d\n", ret
);
888 ok(!strcmp(buf
, "simple test"), "buf = %s\n", buf
);
890 fgets(buf
, sizeof(buf
), fp
);
892 ok(ret
== 26, "ret = %d\n", ret
);
893 ok(!memcmp(buf
, "contains\0null\n", 14), "buf = %s\n", buf
);
895 memset(buf
, 0, sizeof(buf
));
896 fgets(buf
, sizeof(buf
), fp
);
898 ok(ret
== 41, "ret = %d\n", ret
);
899 ok(!memcmp(buf
, utf16_test
, sizeof(utf16_test
)),
900 "buf = %s\n", wine_dbgstr_w((WCHAR
*)buf
));
904 fp
= fopen(file_name
, "wt");
906 ret
= fprintf(fp
, "simple test\n");
907 ok(ret
== 12, "ret = %d\n", ret
);
909 ok(ret
== 13, "ftell returned %d\n", ret
);
911 ret
= fprintf(fp
, "contains%cnull\n", '\0');
912 ok(ret
== 14, "ret = %d\n", ret
);
914 ok(ret
== 28, "ftell returned %d\n", ret
);
916 ret
= fwprintf(fp
, utf16_test
);
917 ok(ret
== 8, "ret = %d\n", ret
);
919 ok(ret
== 37, "ftell returned %d\n", ret
);
923 fp
= fopen(file_name
, "rb");
924 ret
= fscanf(fp
, "%[^\n] ", buf
);
925 ok(ret
== 1, "ret = %d\n", ret
);
927 ok(ret
== 13, "ftell returned %d\n", ret
);
928 ok(!strcmp(buf
, "simple test\r"), "buf = %s\n", buf
);
930 fgets(buf
, sizeof(buf
), fp
);
932 ok(ret
== 28, "ret = %d\n", ret
);
933 ok(!memcmp(buf
, "contains\0null\r\n", 15), "buf = %s\n", buf
);
935 fgets(buf
, sizeof(buf
), fp
);
937 ok(ret
== 37, "ret = %d\n", ret
);
938 ok(!strcmp(buf
, "unicode\r\n"), "buf = %s\n", buf
);
944 static void test_fcvt(void)
947 int dec
=100, sign
=100;
949 /* Numbers less than 1.0 with different precisions */
950 str
= _fcvt(0.0001, 1, &dec
, &sign
);
951 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
952 ok( -3 == dec
, "dec wrong %d\n", dec
);
953 ok( 0 == sign
, "sign wrong\n");
955 str
= _fcvt(0.0001, -10, &dec
, &sign
);
956 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
957 ok( -3 == dec
, "dec wrong %d\n", dec
);
958 ok( 0 == sign
, "sign wrong\n");
960 str
= _fcvt(0.0001, 10, &dec
, &sign
);
961 ok( 0 == strcmp(str
,"1000000"), "bad return '%s'\n", str
);
962 ok( -3 == dec
, "dec wrong %d\n", dec
);
963 ok( 0 == sign
, "sign wrong\n");
965 /* Basic sign test */
966 str
= _fcvt(-111.0001, 5, &dec
, &sign
);
967 ok( 0 == strcmp(str
,"11100010"), "bad return '%s'\n", str
);
968 ok( 3 == dec
, "dec wrong %d\n", dec
);
969 ok( 1 == sign
, "sign wrong\n");
971 str
= _fcvt(111.0001, 5, &dec
, &sign
);
972 ok( 0 == strcmp(str
,"11100010"), "bad return '%s'\n", str
);
973 ok( 3 == dec
, "dec wrong\n");
974 ok( 0 == sign
, "sign wrong\n");
976 /* 0.0 with different precisions */
977 str
= _fcvt(0.0, 5, &dec
, &sign
);
978 ok( 0 == strcmp(str
,"00000"), "bad return '%s'\n", str
);
979 ok( 0 == dec
, "dec wrong %d\n", dec
);
980 ok( 0 == sign
, "sign wrong\n");
982 str
= _fcvt(0.0, 0, &dec
, &sign
);
983 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
984 ok( 0 == dec
, "dec wrong %d\n", dec
);
985 ok( 0 == sign
, "sign wrong\n");
987 str
= _fcvt(0.0, -1, &dec
, &sign
);
988 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
989 ok( 0 == dec
, "dec wrong %d\n", dec
);
990 ok( 0 == sign
, "sign wrong\n");
992 /* Numbers > 1.0 with 0 or -ve precision */
993 str
= _fcvt(-123.0001, 0, &dec
, &sign
);
994 ok( 0 == strcmp(str
,"123"), "bad return '%s'\n", str
);
995 ok( 3 == dec
, "dec wrong %d\n", dec
);
996 ok( 1 == sign
, "sign wrong\n");
998 str
= _fcvt(-123.0001, -1, &dec
, &sign
);
999 ok( 0 == strcmp(str
,"12"), "bad return '%s'\n", str
);
1000 ok( 3 == dec
, "dec wrong %d\n", dec
);
1001 ok( 1 == sign
, "sign wrong\n");
1003 str
= _fcvt(-123.0001, -2, &dec
, &sign
);
1004 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
1005 ok( 3 == dec
, "dec wrong %d\n", dec
);
1006 ok( 1 == sign
, "sign wrong\n");
1008 str
= _fcvt(-123.0001, -3, &dec
, &sign
);
1009 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
1010 ok( 3 == dec
, "dec wrong %d\n", dec
);
1011 ok( 1 == sign
, "sign wrong\n");
1013 /* Numbers > 1.0, but with rounding at the point of precision */
1014 str
= _fcvt(99.99, 1, &dec
, &sign
);
1015 ok( 0 == strcmp(str
,"1000"), "bad return '%s'\n", str
);
1016 ok( 3 == dec
, "dec wrong %d\n", dec
);
1017 ok( 0 == sign
, "sign wrong\n");
1019 /* Numbers < 1.0 where rounding occurs at the point of precision */
1020 str
= _fcvt(0.00636, 2, &dec
, &sign
);
1021 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
1022 ok( -1 == dec
, "dec wrong %d\n", dec
);
1023 ok( 0 == sign
, "sign wrong\n");
1025 str
= _fcvt(0.00636, 3, &dec
, &sign
);
1026 ok( 0 == strcmp(str
,"6"), "bad return '%s'\n", str
);
1027 ok( -2 == dec
, "dec wrong %d\n", dec
);
1028 ok( 0 == sign
, "sign wrong\n");
1030 str
= _fcvt(0.09999999996, 2, &dec
, &sign
);
1031 ok( 0 == strcmp(str
,"10"), "bad return '%s'\n", str
);
1032 ok( 0 == dec
, "dec wrong %d\n", dec
);
1033 ok( 0 == sign
, "sign wrong\n");
1035 str
= _fcvt(0.6, 0, &dec
, &sign
);
1036 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
1037 ok( 1 == dec
, "dec wrong %d\n", dec
);
1038 ok( 0 == sign
, "sign wrong\n");
1041 /* Don't test nrdigits < 0, msvcrt on Win9x and NT4 will corrupt memory by
1042 * writing outside allocated memory */
1046 const char *expstr_e
;
1047 const char *expstr_f
;
1051 } test_cvt_testcases
[] = {
1052 { 45.0, 2, "45", "4500", 2, 2, 0 },
1053 /* Numbers less than 1.0 with different precisions */
1054 { 0.0001, 1, "1", "", -3, -3, 0 },
1055 { 0.0001, 10,"1000000000", "1000000", -3, -3, 0 },
1056 /* Basic sign test */
1057 { -111.0001, 5, "11100", "11100010", 3, 3, 1 },
1058 { 111.0001, 5, "11100", "11100010", 3, 3, 0 },
1059 /* big numbers with low precision */
1060 { 3333.3, 2, "33", "333330", 4, 4, 0 },
1061 {999999999999.9, 3, "100","999999999999900", 13, 12, 0 },
1062 /* 0.0 with different precisions */
1063 { 0.0, 5, "00000", "00000", 0, 0, 0 },
1064 { 0.0, 0, "", "", 0, 0, 0 },
1065 { 0.0, -1, "", "", 0, 0, 0 },
1066 /* Numbers > 1.0 with 0 or -ve precision */
1067 { -123.0001, 0, "", "123", 3, 3, 1 },
1068 { -123.0001, -1, "", "12", 3, 3, 1 },
1069 { -123.0001, -2, "", "1", 3, 3, 1 },
1070 { -123.0001, -3, "", "", 3, 3, 1 },
1071 /* Numbers > 1.0, but with rounding at the point of precision */
1072 { 99.99, 1, "1", "1000", 3, 3, 0 },
1073 /* Numbers < 1.0 where rounding occurs at the point of precision */
1074 { 0.0063, 2, "63", "1", -2, -1, 0 },
1075 { 0.0063, 3, "630", "6", -2, -2, 0 },
1076 { 0.09999999996, 2, "10", "10", 0, 0, 0 },
1077 { 0.6, 1, "6", "6", 0, 0, 0 },
1078 { 0.6, 0, "", "1", 1, 1, 0 },
1079 { 0.4, 0, "", "", 0, 0, 0 },
1080 { 0.49, 0, "", "", 0, 0, 0 },
1081 { 0.51, 0, "", "1", 1, 1, 0 },
1082 /* ask for ridiculous precision, ruin formatting this table */
1083 { 1.0, 30, "100000000000000000000000000000",
1084 "1000000000000000000000000000000", 1, 1, 0},
1085 { 123456789012345678901.0, 30, "123456789012345680000000000000",
1086 "123456789012345680000000000000000000000000000000000", 21, 21, 0},
1091 static void test_xcvt(void)
1094 int i
, decpt
, sign
, err
;
1096 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
1098 str
= _ecvt( test_cvt_testcases
[i
].value
,
1099 test_cvt_testcases
[i
].nrdigits
,
1102 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_e
, 15),
1103 "_ecvt() bad return, got \n'%s' expected \n'%s'\n", str
,
1104 test_cvt_testcases
[i
].expstr_e
);
1105 ok( decpt
== test_cvt_testcases
[i
].expdecpt_e
,
1106 "_ecvt() decimal point wrong, got %d expected %d\n", decpt
,
1107 test_cvt_testcases
[i
].expdecpt_e
);
1108 ok( sign
== test_cvt_testcases
[i
].expsign
,
1109 "_ecvt() sign wrong, got %d expected %d\n", sign
,
1110 test_cvt_testcases
[i
].expsign
);
1112 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
1114 str
= _fcvt( test_cvt_testcases
[i
].value
,
1115 test_cvt_testcases
[i
].nrdigits
,
1118 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_f
, 15),
1119 "_fcvt() bad return, got \n'%s' expected \n'%s'\n", str
,
1120 test_cvt_testcases
[i
].expstr_f
);
1121 ok( decpt
== test_cvt_testcases
[i
].expdecpt_f
,
1122 "_fcvt() decimal point wrong, got %d expected %d\n", decpt
,
1123 test_cvt_testcases
[i
].expdecpt_f
);
1124 ok( sign
== test_cvt_testcases
[i
].expsign
,
1125 "_fcvt() sign wrong, got %d expected %d\n", sign
,
1126 test_cvt_testcases
[i
].expsign
);
1132 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
1134 err
= p__ecvt_s(str
, 1024, test_cvt_testcases
[i
].value
, test_cvt_testcases
[i
].nrdigits
, &decpt
, &sign
);
1135 ok(err
== 0, "_ecvt_s() failed with error code %d\n", err
);
1136 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_e
, 15),
1137 "_ecvt_s() bad return, got \n'%s' expected \n'%s'\n", str
,
1138 test_cvt_testcases
[i
].expstr_e
);
1139 ok( decpt
== test_cvt_testcases
[i
].expdecpt_e
,
1140 "_ecvt_s() decimal point wrong, got %d expected %d\n", decpt
,
1141 test_cvt_testcases
[i
].expdecpt_e
);
1142 ok( sign
== test_cvt_testcases
[i
].expsign
,
1143 "_ecvt_s() sign wrong, got %d expected %d\n", sign
,
1144 test_cvt_testcases
[i
].expsign
);
1149 win_skip("_ecvt_s not available\n");
1157 /* invalid arguments */
1158 err
= p__fcvt_s(NULL
, 0, 0.0, 0, &i
, &i
);
1159 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
1161 err
= p__fcvt_s(str
, 0, 0.0, 0, &i
, &i
);
1162 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
1166 err
= p__fcvt_s(str
, -1, 0.0, 0, &i
, &i
);
1167 ok(err
== 0, "got %d, expected 0\n", err
);
1168 ok(str
[0] == 0, "got %c, expected 0\n", str
[0]);
1169 ok(str
[1] == 0, "got %c, expected 0\n", str
[1]);
1171 err
= p__fcvt_s(str
, 1, 0.0, 0, NULL
, &i
);
1172 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
1174 err
= p__fcvt_s(str
, 1, 0.0, 0, &i
, NULL
);
1175 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
1177 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
1179 err
= p__fcvt_s(str
, 1024, test_cvt_testcases
[i
].value
, test_cvt_testcases
[i
].nrdigits
, &decpt
, &sign
);
1180 ok(err
== 0, "_fcvt_s() failed with error code %d\n", err
);
1181 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_f
, 15),
1182 "_fcvt_s() bad return, got '%s' expected '%s'. test %d\n", str
,
1183 test_cvt_testcases
[i
].expstr_f
, i
);
1184 ok( decpt
== test_cvt_testcases
[i
].expdecpt_f
,
1185 "_fcvt_s() decimal point wrong, got %d expected %d\n", decpt
,
1186 test_cvt_testcases
[i
].expdecpt_f
);
1187 ok( sign
== test_cvt_testcases
[i
].expsign
,
1188 "_fcvt_s() sign wrong, got %d expected %d\n", sign
,
1189 test_cvt_testcases
[i
].expsign
);
1194 win_skip("_fcvt_s not available\n");
1197 static int WINAPIV
_vsnwprintf_wrapper(wchar_t *str
, size_t len
, const wchar_t *format
, ...)
1200 __ms_va_list valist
;
1201 __ms_va_start(valist
, format
);
1202 ret
= _vsnwprintf(str
, len
, format
, valist
);
1203 __ms_va_end(valist
);
1207 static void test_vsnwprintf(void)
1209 const wchar_t format
[] = {'%','w','s','%','w','s','%','w','s',0};
1210 const wchar_t one
[] = {'o','n','e',0};
1211 const wchar_t two
[] = {'t','w','o',0};
1212 const wchar_t three
[] = {'t','h','r','e','e',0};
1218 ret
= _vsnwprintf_wrapper( str
, sizeof(str
)/sizeof(str
[0]), format
, one
, two
, three
);
1220 ok( ret
== 11, "got %d expected 11\n", ret
);
1221 WideCharToMultiByte( CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
1222 ok( !strcmp(buf
, "onetwothree"), "got %s expected 'onetwothree'\n", buf
);
1224 ret
= _vsnwprintf_wrapper( str
, 0, format
, one
, two
, three
);
1225 ok( ret
== -1, "got %d, expected -1\n", ret
);
1227 ret
= _vsnwprintf_wrapper( NULL
, 0, format
, one
, two
, three
);
1228 ok( ret
== 11 || broken(ret
== -1 /* Win2k */), "got %d, expected 11\n", ret
);
1231 static int WINAPIV
vswprintf_wrapper(wchar_t *str
, const wchar_t *format
, ...)
1234 __ms_va_list valist
;
1235 __ms_va_start(valist
, format
);
1236 ret
= p_vswprintf(str
, format
, valist
);
1237 __ms_va_end(valist
);
1241 static int WINAPIV
_vswprintf_wrapper(wchar_t *str
, const wchar_t *format
, ...)
1244 __ms_va_list valist
;
1245 __ms_va_start(valist
, format
);
1246 ret
= p__vswprintf(str
, format
, valist
);
1247 __ms_va_end(valist
);
1251 static int WINAPIV
_vswprintf_l_wrapper(wchar_t *str
, const wchar_t *format
, void *locale
, ...)
1254 __ms_va_list valist
;
1255 __ms_va_start(valist
, locale
);
1256 ret
= p__vswprintf_l(str
, format
, locale
, valist
);
1257 __ms_va_end(valist
);
1261 static int WINAPIV
_vswprintf_c_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, ...)
1264 __ms_va_list valist
;
1265 __ms_va_start(valist
, format
);
1266 ret
= p__vswprintf_c(str
, size
, format
, valist
);
1267 __ms_va_end(valist
);
1271 static int WINAPIV
_vswprintf_c_l_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, void *locale
, ...)
1274 __ms_va_list valist
;
1275 __ms_va_start(valist
, locale
);
1276 ret
= p__vswprintf_c_l(str
, size
, format
, locale
, valist
);
1277 __ms_va_end(valist
);
1281 static int WINAPIV
_vswprintf_p_l_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, void *locale
, ...)
1284 __ms_va_list valist
;
1285 __ms_va_start(valist
, locale
);
1286 ret
= p__vswprintf_p_l(str
, size
, format
, locale
, valist
);
1287 __ms_va_end(valist
);
1291 static void test_vswprintf(void)
1293 const wchar_t format
[] = {'%','s',' ','%','d',0};
1294 const wchar_t number
[] = {'n','u','m','b','e','r',0};
1295 const wchar_t out
[] = {'n','u','m','b','e','r',' ','1','2','3',0};
1300 if (!p_vswprintf
|| !p__vswprintf
|| !p__vswprintf_l
||!p__vswprintf_c
1301 || !p__vswprintf_c_l
|| !p__vswprintf_p_l
)
1303 win_skip("_vswprintf or vswprintf not available\n");
1307 ret
= vswprintf_wrapper(buf
, format
, number
, 123);
1308 ok(ret
== 10, "got %d, expected 10\n", ret
);
1309 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1311 memset(buf
, 0, sizeof(buf
));
1312 ret
= _vswprintf_wrapper(buf
, format
, number
, 123);
1313 ok(ret
== 10, "got %d, expected 10\n", ret
);
1314 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1316 memset(buf
, 0, sizeof(buf
));
1317 ret
= _vswprintf_l_wrapper(buf
, format
, NULL
, number
, 123);
1318 ok(ret
== 10, "got %d, expected 10\n", ret
);
1319 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1321 memset(buf
, 0, sizeof(buf
));
1322 ret
= _vswprintf_c_wrapper(buf
, 20, format
, number
, 123);
1323 ok(ret
== 10, "got %d, expected 10\n", ret
);
1324 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1326 memset(buf
, 0, sizeof(buf
));
1327 ret
= _vswprintf_c_l_wrapper(buf
, 20, format
, NULL
, number
, 123);
1328 ok(ret
== 10, "got %d, expected 10\n", ret
);
1329 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1331 memset(buf
, 0, sizeof(buf
));
1332 ret
= _vswprintf_p_l_wrapper(buf
, 20, format
, NULL
, number
, 123);
1333 ok(ret
== 10, "got %d, expected 10\n", ret
);
1334 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1337 static int WINAPIV
_vscprintf_wrapper(const char *format
, ...)
1340 __ms_va_list valist
;
1341 __ms_va_start(valist
, format
);
1342 ret
= p__vscprintf(format
, valist
);
1343 __ms_va_end(valist
);
1347 static void test_vscprintf(void)
1353 win_skip("_vscprintf not available\n");
1357 ret
= _vscprintf_wrapper( "%s %d", "number", 1 );
1358 ok( ret
== 8, "got %d expected 8\n", ret
);
1361 static int WINAPIV
_vscwprintf_wrapper(const wchar_t *format
, ...)
1364 __ms_va_list valist
;
1365 __ms_va_start(valist
, format
);
1366 ret
= p__vscwprintf(format
, valist
);
1367 __ms_va_end(valist
);
1371 static void test_vscwprintf(void)
1373 const wchar_t format
[] = {'%','s',' ','%','d',0};
1374 const wchar_t number
[] = {'n','u','m','b','e','r',0};
1380 win_skip("_vscwprintf not available\n");
1384 ret
= _vscwprintf_wrapper( format
, number
, 1 );
1385 ok( ret
== 8, "got %d expected 8\n", ret
);
1388 static int WINAPIV
_vsnwprintf_s_wrapper(wchar_t *str
, size_t sizeOfBuffer
,
1389 size_t count
, const wchar_t *format
, ...)
1392 __ms_va_list valist
;
1393 __ms_va_start(valist
, format
);
1394 ret
= p__vsnwprintf_s(str
, sizeOfBuffer
, count
, format
, valist
);
1395 __ms_va_end(valist
);
1399 static void test_vsnwprintf_s(void)
1401 const wchar_t format
[] = { 'A','B','%','u','C',0 };
1402 const wchar_t out7
[] = { 'A','B','1','2','3','C',0 };
1403 const wchar_t out6
[] = { 'A','B','1','2','3',0 };
1404 const wchar_t out2
[] = { 'A',0 };
1405 const wchar_t out1
[] = { 0 };
1406 wchar_t buffer
[14] = { 0 };
1409 if (!p__vsnwprintf_s
)
1411 win_skip("_vsnwprintf_s not available\n");
1418 got
= _vsnwprintf_s_wrapper(buffer
, 14, _TRUNCATE
, format
, 123);
1419 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1420 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1422 got
= _vsnwprintf_s_wrapper(buffer
, 12, _TRUNCATE
, format
, 123);
1423 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1424 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1426 got
= _vsnwprintf_s_wrapper(buffer
, 7, _TRUNCATE
, format
, 123);
1427 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1428 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1430 /* Not enough room. */
1433 got
= _vsnwprintf_s_wrapper(buffer
, 6, _TRUNCATE
, format
, 123);
1434 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1435 ok( !wcscmp(out6
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1437 got
= _vsnwprintf_s_wrapper(buffer
, 2, _TRUNCATE
, format
, 123);
1438 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1439 ok( !wcscmp(out2
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1441 got
= _vsnwprintf_s_wrapper(buffer
, 1, _TRUNCATE
, format
, 123);
1442 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1443 ok( !wcscmp(out1
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1446 static int WINAPIV
_vsprintf_p_wrapper(char *str
, size_t sizeOfBuffer
,
1447 const char *format
, ...)
1450 __ms_va_list valist
;
1451 __ms_va_start(valist
, format
);
1452 ret
= p__vsprintf_p(str
, sizeOfBuffer
, format
, valist
);
1453 __ms_va_end(valist
);
1457 static void test_vsprintf_p(void)
1462 if(!p__vsprintf_p
) {
1463 win_skip("vsprintf_p not available\n");
1467 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%s %d", "test", 1234);
1468 ok(ret
== 9, "ret = %d\n", ret
);
1469 ok(!memcmp(buf
, "test 1234", 10), "buf = %s\n", buf
);
1471 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%1$d", 1234, "additional param");
1472 ok(ret
== 4, "ret = %d\n", ret
);
1473 ok(!memcmp(buf
, "1234", 5), "buf = %s\n", buf
);
1475 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%2$s %1$d", 1234, "test");
1476 ok(ret
== 9, "ret = %d\n", ret
);
1477 ok(!memcmp(buf
, "test 1234", 10), "buf = %s\n", buf
);
1479 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%2$*3$s %2$.*1$s", 2, "test", 3);
1480 ok(ret
== 7, "ret = %d\n", ret
);
1481 ok(!memcmp(buf
, "test te", 8), "buf = %s\n", buf
);
1483 /* Following test invokes invalid parameter handler */
1484 /* ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%d %1$d", 1234); */
1487 static void test__get_output_format(void)
1493 if (!p__get_output_format
|| !p__set_output_format
)
1495 win_skip("_get_output_format or _set_output_format is not available\n");
1499 ret
= p__get_output_format();
1500 ok(ret
== 0, "got %d\n", ret
);
1502 c
= sprintf(buf
, "%E", 1.23);
1503 ok(c
== 13, "c = %d\n", c
);
1504 ok(!strcmp(buf
, "1.230000E+000"), "buf = %s\n", buf
);
1506 ret
= p__set_output_format(_TWO_DIGIT_EXPONENT
);
1507 ok(ret
== 0, "got %d\n", ret
);
1509 c
= sprintf(buf
, "%E", 1.23);
1510 ok(c
== 12, "c = %d\n", c
);
1511 ok(!strcmp(buf
, "1.230000E+00"), "buf = %s\n", buf
);
1513 ret
= p__get_output_format();
1514 ok(ret
== _TWO_DIGIT_EXPONENT
, "got %d\n", ret
);
1516 ret
= p__set_output_format(_TWO_DIGIT_EXPONENT
);
1517 ok(ret
== _TWO_DIGIT_EXPONENT
, "got %d\n", ret
);
1534 test_vsnwprintf_s();
1536 test__get_output_format();