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
35 #include "wine/test.h"
37 static int (__cdecl
*p__vscprintf
)(const char *format
, __ms_va_list valist
);
38 static int (__cdecl
*p__vscwprintf
)(const wchar_t *format
, __ms_va_list valist
);
39 static int (__cdecl
*p__vsnwprintf_s
)(wchar_t *str
, size_t sizeOfBuffer
,
40 size_t count
, const wchar_t *format
,
42 static int (__cdecl
*p__ecvt_s
)(char *buffer
, size_t length
, double number
,
43 int ndigits
, int *decpt
, int *sign
);
44 static int (__cdecl
*p__fcvt_s
)(char *buffer
, size_t length
, double number
,
45 int ndigits
, int *decpt
, int *sign
);
46 static unsigned int (__cdecl
*p__get_output_format
)(void);
47 static int (__cdecl
*p__vsprintf_p
)(char*, size_t, const char*, __ms_va_list
);
48 static int (__cdecl
*p_vswprintf
)(wchar_t *str
, const wchar_t *format
, __ms_va_list valist
);
49 static int (__cdecl
*p__vswprintf
)(wchar_t *str
, const wchar_t *format
, __ms_va_list valist
);
50 static int (__cdecl
*p__vswprintf_l
)(wchar_t *str
, const wchar_t *format
,
51 void *locale
, __ms_va_list valist
);
52 static int (__cdecl
*p__vswprintf_c
)(wchar_t *str
, size_t size
, const wchar_t *format
,
54 static int (__cdecl
*p__vswprintf_c_l
)(wchar_t *str
, size_t size
, const wchar_t *format
,
55 void *locale
, __ms_va_list valist
);
56 static int (__cdecl
*p__vswprintf_p_l
)(wchar_t *str
, size_t size
, const wchar_t *format
,
57 void *locale
, __ms_va_list valist
);
59 static void init( void )
61 HMODULE hmod
= GetModuleHandleA("msvcrt.dll");
63 p__vscprintf
= (void *)GetProcAddress(hmod
, "_vscprintf");
64 p__vscwprintf
= (void *)GetProcAddress(hmod
, "_vscwprintf");
65 p__vsnwprintf_s
= (void *)GetProcAddress(hmod
, "_vsnwprintf_s");
66 p__ecvt_s
= (void *)GetProcAddress(hmod
, "_ecvt_s");
67 p__fcvt_s
= (void *)GetProcAddress(hmod
, "_fcvt_s");
68 p__get_output_format
= (void *)GetProcAddress(hmod
, "_get_output_format");
69 p__vsprintf_p
= (void*)GetProcAddress(hmod
, "_vsprintf_p");
70 p_vswprintf
= (void*)GetProcAddress(hmod
, "vswprintf");
71 p__vswprintf
= (void*)GetProcAddress(hmod
, "_vswprintf");
72 p__vswprintf_l
= (void*)GetProcAddress(hmod
, "_vswprintf_l");
73 p__vswprintf_c
= (void*)GetProcAddress(hmod
, "_vswprintf_c");
74 p__vswprintf_c_l
= (void*)GetProcAddress(hmod
, "_vswprintf_c_l");
75 p__vswprintf_p_l
= (void*)GetProcAddress(hmod
, "_vswprintf_p_l");
78 static void test_sprintf( void )
82 double pnumber
=789456123;
84 WCHAR wide
[] = { 'w','i','d','e',0};
87 r
= sprintf(buffer
,format
,pnumber
);
88 ok(!strcmp(buffer
,"+7.894561230000000e+008"),"+#23.15e failed: '%s'\n", buffer
);
89 ok( r
==23, "return count wrong\n");
92 r
= sprintf(buffer
,format
,pnumber
);
93 ok(!strcmp(buffer
,"7.894561230000000e+008 "),"-#23.15e failed: '%s'\n", buffer
);
94 ok( r
==23, "return count wrong\n");
97 r
= sprintf(buffer
,format
,pnumber
);
98 ok(!strcmp(buffer
," 7.894561230000000e+008"),"#23.15e failed: '%s'\n", buffer
);
99 ok( r
==23, "return count wrong\n");
102 r
= sprintf(buffer
,format
,pnumber
);
103 ok(!strcmp(buffer
,"8.e+008"),"#1.1g failed: '%s'\n", buffer
);
104 ok( r
==7, "return count wrong\n");
107 r
= sprintf(buffer
,format
,((ULONGLONG
)0xffffffff)*0xffffffff);
108 ok(!strcmp(buffer
,"-8589934591"),"Problem with long long\n");
109 ok( r
==11, "return count wrong\n");
112 r
= sprintf(buffer
,format
,(LONGLONG
)100);
113 ok(!strcmp(buffer
," +100") && r
==8,"+8I64d failed: '%s'\n", buffer
);
116 r
= sprintf(buffer
,format
,(LONGLONG
)100);
117 ok(!strcmp(buffer
,"+00000100") && r
==9,"+.8I64d failed: '%s'\n", buffer
);
119 format
= "%+10.8I64d";
120 r
= sprintf(buffer
,format
,(LONGLONG
)100);
121 ok(!strcmp(buffer
," +00000100") && r
==10,"+10.8I64d failed: '%s'\n", buffer
);
123 r
= sprintf(buffer
,format
,(LONGLONG
)100);
124 ok(!strcmp(buffer
,"_1I64d") && r
==6,"_1I64d failed\n");
126 format
= "%-1.5I64d";
127 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
128 ok(!strcmp(buffer
,"-00100") && r
==6,"-1.5I64d failed: '%s'\n", buffer
);
131 r
= sprintf(buffer
,format
,(LONGLONG
)100);
132 ok(!strcmp(buffer
," 100") && r
==5,"5I64d failed: '%s'\n", buffer
);
135 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
136 ok(!strcmp(buffer
," -100") && r
==5,"5I64d failed: '%s'\n", buffer
);
139 r
= sprintf(buffer
,format
,(LONGLONG
)100);
140 ok(!strcmp(buffer
,"100 ") && r
==5,"-5I64d failed: '%s'\n", buffer
);
143 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
144 ok(!strcmp(buffer
,"-100 ") && r
==5,"-5I64d failed: '%s'\n", buffer
);
147 r
= sprintf(buffer
,format
,(LONGLONG
)100);
148 ok(!strcmp(buffer
,"00100") && r
==5,"-.5I64d failed: '%s'\n", buffer
);
151 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
152 ok(!strcmp(buffer
,"-00100") && r
==6,"-.5I64d failed: '%s'\n", buffer
);
154 format
= "%-8.5I64d";
155 r
= sprintf(buffer
,format
,(LONGLONG
)100);
156 ok(!strcmp(buffer
,"00100 ") && r
==8,"-8.5I64d failed: '%s'\n", buffer
);
158 format
= "%-8.5I64d";
159 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
160 ok(!strcmp(buffer
,"-00100 ") && r
==8,"-8.5I64d failed: '%s'\n", buffer
);
163 r
= sprintf(buffer
,format
,(LONGLONG
)100);
164 ok(!strcmp(buffer
,"00100") && r
==5,"05I64d failed: '%s'\n", buffer
);
167 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
168 ok(!strcmp(buffer
,"-0100") && r
==5,"05I64d failed: '%s'\n", buffer
);
171 r
= sprintf(buffer
,format
,(LONGLONG
)100);
172 ok(!strcmp(buffer
," 100") && r
==4,"' I64d' failed: '%s'\n", buffer
);
175 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
176 ok(!strcmp(buffer
,"-100") && r
==4,"' I64d' failed: '%s'\n", buffer
);
179 r
= sprintf(buffer
,format
,(LONGLONG
)100);
180 ok(!strcmp(buffer
," 100") && r
==5,"' 5I64d' failed: '%s'\n", buffer
);
183 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
184 ok(!strcmp(buffer
," -100") && r
==5,"' 5I64d' failed: '%s'\n", buffer
);
187 r
= sprintf(buffer
,format
,(LONGLONG
)100);
188 ok(!strcmp(buffer
," 00100") && r
==6,"' .5I64d' failed: '%s'\n", buffer
);
191 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
192 ok(!strcmp(buffer
,"-00100") && r
==6,"' .5I64d' failed: '%s'\n", buffer
);
194 format
= "% 8.5I64d";
195 r
= sprintf(buffer
,format
,(LONGLONG
)100);
196 ok(!strcmp(buffer
," 00100") && r
==8,"' 8.5I64d' failed: '%s'\n", buffer
);
198 format
= "% 8.5I64d";
199 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
200 ok(!strcmp(buffer
," -00100") && r
==8,"' 8.5I64d' failed: '%s'\n", buffer
);
203 r
= sprintf(buffer
,format
,(LONGLONG
)0);
204 ok(r
==0,".0I64d failed: '%s'\n", buffer
);
206 format
= "%#+21.18I64x";
207 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
208 ok(!strcmp(buffer
," 0x00ffffffffffffff9c") && r
==21,"#+21.18I64x failed: '%s'\n", buffer
);
210 format
= "%#.25I64o";
211 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
212 ok(!strcmp(buffer
,"0001777777777777777777634") && r
==25,"#.25I64o failed: '%s'\n", buffer
);
214 format
= "%#+24.20I64o";
215 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
216 ok(!strcmp(buffer
," 01777777777777777777634") && r
==24,"#+24.20I64o failed: '%s'\n", buffer
);
218 format
= "%#+18.21I64X";
219 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
220 ok(!strcmp(buffer
,"0X00000FFFFFFFFFFFFFF9C") && r
==23,"#+18.21I64X failed: '%s '\n", buffer
);
222 format
= "%#+20.24I64o";
223 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
224 ok(!strcmp(buffer
,"001777777777777777777634") && r
==24,"#+20.24I64o failed: '%s'\n", buffer
);
226 format
= "%#+25.22I64u";
227 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
228 ok(!strcmp(buffer
," 0018446744073709551615") && r
==25,"#+25.22I64u conversion failed: '%s'\n", buffer
);
230 format
= "%#+25.22I64u";
231 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
232 ok(!strcmp(buffer
," 0018446744073709551615") && r
==25,"#+25.22I64u failed: '%s'\n", buffer
);
234 format
= "%#+30.25I64u";
235 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
236 ok(!strcmp(buffer
," 0000018446744073709551615") && r
==30,"#+30.25I64u failed: '%s'\n", buffer
);
238 format
= "%+#25.22I64d";
239 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
240 ok(!strcmp(buffer
," -0000000000000000000001") && r
==25,"+#25.22I64d failed: '%s'\n", buffer
);
242 format
= "%#-8.5I64o";
243 r
= sprintf(buffer
,format
,(LONGLONG
)100);
244 ok(!strcmp(buffer
,"00144 ") && r
==8,"-8.5I64o failed: '%s'\n", buffer
);
246 format
= "%#-+ 08.5I64d";
247 r
= sprintf(buffer
,format
,(LONGLONG
)100);
248 ok(!strcmp(buffer
,"+00100 ") && r
==8,"'#-+ 08.5I64d failed: '%s'\n", buffer
);
250 format
= "%#-+ 08.5I64d";
251 r
= sprintf(buffer
,format
,(LONGLONG
)100);
252 ok(!strcmp(buffer
,"+00100 ") && r
==8,"#-+ 08.5I64d failed: '%s'\n", buffer
);
255 r
= sprintf(buffer
,format
,(LONGLONG
)1);
256 ok(r
==80,"%s format failed\n", format
);
258 format
= "% .80I64d";
259 r
= sprintf(buffer
,format
,(LONGLONG
)1);
260 ok(r
==81,"%s format failed\n", format
);
263 r
= sprintf(buffer
,format
,1);
264 ok(r
==81,"%s format failed\n", format
);
267 r
= sprintf(buffer
,format
,((ULONGLONG
)0xffffffff)*0xffffffff);
268 ok( r
== 1 || r
== 11, "return count wrong %d\n", r
);
269 if (r
== 11) /* %ll works on Vista */
270 ok(!strcmp(buffer
, "-8589934591"), "Problem with \"ll\" interpretation '%s'\n", buffer
);
272 ok(!strcmp(buffer
, "1"), "Problem with \"ll\" interpretation '%s'\n", buffer
);
275 r
= sprintf(buffer
,format
,1);
276 ok(!strcmp(buffer
, "I"), "Problem with \"I\" interpretation\n");
277 ok( r
==1, "return count wrong\n");
280 r
= sprintf(buffer
,format
,1);
281 ok(!strcmp(buffer
,"I0d"),"I0d failed\n");
282 ok( r
==3, "return count wrong\n");
285 r
= sprintf(buffer
,format
,1);
288 ok(!strcmp(buffer
,"1"),"I32d failed, got '%s'\n",buffer
);
292 /* Older versions don't grok I32 format */
293 ok(r
== 4 && !strcmp(buffer
,"I32d"),"I32d failed, got '%s',%d\n",buffer
,r
);
297 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
298 ok(!strcmp(buffer
,"D"),"I64D failed: %s\n",buffer
);
299 ok( r
==1, "return count wrong\n");
302 r
= sprintf(buffer
,format
,1);
303 ok(!strcmp(buffer
, " 1"),"Problem with sign place-holder: '%s'\n",buffer
);
304 ok( r
==2, "return count wrong\n");
307 r
= sprintf(buffer
,format
,1);
308 ok(!strcmp(buffer
, "+1"),"Problem with sign flags: '%s'\n",buffer
);
309 ok( r
==2, "return count wrong\n");
312 r
= sprintf(buffer
,format
,wide
);
313 ok(!strcmp(buffer
,"wide"),"Problem with wide string format\n");
314 ok( r
==4, "return count wrong\n");
317 r
= sprintf(buffer
,format
,'1');
318 ok(!strcmp(buffer
,"0001"),"Character not zero-prefixed \"%s\"\n",buffer
);
319 ok( r
==4, "return count wrong\n");
322 r
= sprintf(buffer
,format
,'1');
323 ok(!strcmp(buffer
,"1 "),"Character zero-padded and/or not left-adjusted \"%s\"\n",buffer
);
324 ok( r
==4, "return count wrong\n");
327 r
= sprintf(buffer
,format
,1);
328 ok(!strcmp(buffer
,"0x0000000001"),"Hexadecimal zero-padded \"%s\"\n",buffer
);
331 r
= sprintf(buffer
,format
,1);
332 ok(!strcmp(buffer
,"0x00000001"), "Hexadecimal zero-padded precision \"%s\"\n",buffer
);
335 r
= sprintf(buffer
,format
,1);
336 ok(!strcmp(buffer
,"0x01 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer
);
339 r
= sprintf(buffer
,format
,1);
340 ok(!strcmp(buffer
,"00000001"), "Octal zero-padded \"%s\"\n",buffer
);
342 if (sizeof(void *) == 8)
345 r
= sprintf(buffer
,format
,(void *)57);
346 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
347 ok( r
==16, "return count wrong\n");
350 r
= sprintf(buffer
,format
,(void *)57);
351 ok(!strcmp(buffer
," 0X0000000000000039"),"Pointer formatted incorrectly\n");
352 ok( r
==20, "return count wrong\n");
355 r
= sprintf(buffer
,format
,(void *)57);
356 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
357 ok( r
==16, "return count wrong\n");
360 r
= sprintf(buffer
,format
,(void *)57);
361 ok(!strcmp(buffer
,"0X0000000000000039 "),"Pointer formatted incorrectly\n");
362 ok( r
==20, "return count wrong\n");
367 r
= sprintf(buffer
,format
,(void *)57);
368 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
369 ok( r
==8, "return count wrong\n");
372 r
= sprintf(buffer
,format
,(void *)57);
373 ok(!strcmp(buffer
," 0X00000039"),"Pointer formatted incorrectly\n");
374 ok( r
==12, "return count wrong\n");
377 r
= sprintf(buffer
,format
,(void *)57);
378 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
379 ok( r
==8, "return count wrong\n");
382 r
= sprintf(buffer
,format
,(void *)57);
383 ok(!strcmp(buffer
,"0X00000039 "),"Pointer formatted incorrectly\n");
384 ok( r
==12, "return count wrong\n");
388 r
= sprintf(buffer
,format
,"foo");
389 ok(!strcmp(buffer
,"0foo"),"String not zero-prefixed \"%s\"\n",buffer
);
390 ok( r
==4, "return count wrong\n");
393 r
= sprintf(buffer
,format
,"foo");
394 ok(!strcmp(buffer
,"f"),"Precision ignored \"%s\"\n",buffer
);
395 ok( r
==1, "return count wrong\n");
398 r
= sprintf(buffer
,format
,1,"foo");
399 ok(!strcmp(buffer
,"f"),"Precision ignored \"%s\"\n",buffer
);
400 ok( r
==1, "return count wrong\n");
403 r
= sprintf(buffer
,format
,-5,"foo");
404 ok(!strcmp(buffer
,"foo "),"Negative field width ignored \"%s\"\n",buffer
);
405 ok( r
==5, "return count wrong\n");
408 r
= sprintf(buffer
, format
);
409 ok(!strcmp(buffer
,"hello"), "failed\n");
410 ok( r
==5, "return count wrong\n");
413 r
= sprintf(buffer
, format
, wide
);
414 ok(!strcmp(buffer
,"wide"), "failed\n");
415 ok( r
==4, "return count wrong\n");
418 r
= sprintf(buffer
, format
, wide
);
419 ok(!strcmp(buffer
,"wide "), "failed\n");
420 ok( r
==10, "return count wrong\n");
423 r
= sprintf(buffer
, format
, wide
);
424 ok(!strcmp(buffer
," wide"), "failed\n");
425 ok( r
==10, "return count wrong\n");
427 format
= "%#+ -03whlls";
428 r
= sprintf(buffer
, format
, wide
);
429 ok(!strcmp(buffer
,"wide"), "failed\n");
430 ok( r
==4, "return count wrong\n");
433 r
= sprintf(buffer
, format
, wide
);
434 ok(!strcmp(buffer
,"0s"), "failed\n");
435 ok( r
==2, "return count wrong\n");
438 r
= sprintf(buffer
, format
, wide
);
439 ok(!strcmp(buffer
,"-s"), "failed\n");
440 ok( r
==2, "return count wrong\n");
443 r
= sprintf(buffer
, format
, wide
);
444 ok(!strcmp(buffer
,"wide"), "failed\n");
445 ok( r
==4, "return count wrong\n");
448 r
= sprintf(buffer
, format
, "not wide" );
449 ok(!strcmp(buffer
,"not wide"), "failed\n");
450 ok( r
==8, "return count wrong\n");
453 r
= sprintf(buffer
, format
);
454 ok(!strcmp(buffer
,"b"), "failed\n");
455 ok( r
==1, "return count wrong\n");
458 r
= sprintf(buffer
, format
,'a');
459 ok(!strcmp(buffer
," a"), "failed\n");
460 ok( r
==3, "return count wrong\n");
463 r
= sprintf(buffer
, format
,1234);
464 ok(!strcmp(buffer
,"1234"), "failed\n");
465 ok( r
==4, "return count wrong\n");
468 r
= sprintf(buffer
, format
);
469 ok(!strcmp(buffer
,""), "failed\n");
470 ok( r
==0, "return count wrong\n");
472 format
= "%j%k%m%q%r%t%v%y%z";
473 r
= sprintf(buffer
, format
);
474 ok(!strcmp(buffer
,"jkmqrtvyz"), "failed\n");
475 ok( r
==9, "return count wrong\n");
479 r
= sprintf(buffer
, format
, &x
);
482 /* %n format is disabled by default on vista */
483 /* FIXME: should test with _set_printf_count_output */
484 ok(x
== 0, "should not write to x: %d\n", x
);
488 ok(x
== 4, "should write to x: %d\n", x
);
489 ok(!strcmp(buffer
,"asdf"), "failed\n");
490 ok( r
==4, "return count wrong: %d\n", r
);
494 r
= sprintf(buffer
, format
,2);
495 ok(!strcmp(buffer
,"2"), "failed\n");
496 ok( r
==1, "return count wrong\n");
499 r
= sprintf(buffer
, format
,8.6);
500 ok(!strcmp(buffer
,"8.6000"), "failed\n");
501 ok( r
==6, "return count wrong\n");
504 r
= sprintf(buffer
, format
,0.6);
505 ok(!strcmp(buffer
,"0.600000"), "failed\n");
506 ok( r
==8, "return count wrong\n");
509 r
= sprintf(buffer
, format
,0.6);
510 ok(!strcmp(buffer
,"1"), "failed\n");
511 ok( r
==1, "return count wrong\n");
514 r
= sprintf(buffer
, format
,8.6);
515 ok(!strcmp(buffer
,"8.6000e+000"), "failed\n");
516 ok( r
==11, "return count wrong\n");
519 r
= sprintf(buffer
, format
,8.6);
520 ok(!strcmp(buffer
,"8.6"), "failed\n");
521 ok( r
==3, "return count wrong\n");
524 r
= sprintf(buffer
, format
,-1);
525 ok(!strcmp(buffer
,"-1"), "failed\n");
526 ok( r
==2, "return count wrong\n");
529 r
= sprintf(buffer
, format
,1);
530 ok(!strcmp(buffer
,"1"), "failed\n");
531 ok( r
==1, "return count wrong\n");
534 r
= sprintf(buffer
, format
,1);
535 ok(!strcmp(buffer
,"+1"), "failed\n");
536 ok( r
==2, "return count wrong\n");
539 r
= sprintf(buffer
, format
,10);
540 ok(!strcmp(buffer
,"12"), "failed\n");
541 ok( r
==2, "return count wrong\n");
544 r
= sprintf(buffer
, format
,0);
545 if (sizeof(void *) == 8)
547 ok(!strcmp(buffer
,"0000000000000000"), "failed\n");
548 ok( r
==16, "return count wrong\n");
552 ok(!strcmp(buffer
,"00000000"), "failed\n");
553 ok( r
==8, "return count wrong\n");
557 r
= sprintf(buffer
, format
,0);
558 ok(!strcmp(buffer
,"(null)"), "failed\n");
559 ok( r
==6, "return count wrong\n");
562 r
= sprintf(buffer
, format
,"%%%%");
563 ok(!strcmp(buffer
,"%%%%"), "failed\n");
564 ok( r
==4, "return count wrong\n");
567 r
= sprintf(buffer
, format
,-1);
568 ok(!strcmp(buffer
,"4294967295"), "failed\n");
569 ok( r
==10, "return count wrong\n");
572 r
= sprintf(buffer
, format
,-1);
573 ok(!strcmp(buffer
,""), "failed\n");
574 ok( r
==0, "return count wrong\n");
577 r
= sprintf(buffer
, format
,-1);
578 ok(!strcmp(buffer
,""), "failed\n");
579 ok( r
==0, "return count wrong\n");
582 r
= sprintf(buffer
, format
,-1);
583 ok(!strcmp(buffer
,"z"), "failed\n");
584 ok( r
==1, "return count wrong\n");
587 r
= sprintf(buffer
, format
,-1);
588 ok(!strcmp(buffer
,"j"), "failed\n");
589 ok( r
==1, "return count wrong\n");
592 r
= sprintf(buffer
, format
,-1);
593 ok(!strcmp(buffer
,""), "failed\n");
594 ok( r
==0, "return count wrong\n");
597 r
= sprintf(buffer
, format
,-1);
598 ok(!strcmp(buffer
,"H"), "failed\n");
599 ok( r
==1, "return count wrong\n");
602 r
= sprintf(buffer
, format
, 0x100+'X');
603 ok(!strcmp(buffer
,"xXx"), "failed\n");
604 ok( r
==3, "return count wrong\n");
607 r
= sprintf(buffer
, format
);
608 ok(!strcmp(buffer
,"%0"), "failed: \"%s\"\n", buffer
);
609 ok( r
==2, "return count wrong\n");
612 r
= sprintf(buffer
, format
, 0x12345);
613 ok(!strcmp(buffer
,"2345"), "failed \"%s\"\n", buffer
);
616 r
= sprintf(buffer
, format
, 0x123);
617 ok(!strcmp(buffer
,"123"), "failed: \"%s\"\n", buffer
);
618 r
= sprintf(buffer
, format
, 0x12345);
619 ok(!strcmp(buffer
,"2345"), "failed \"%s\"\n", buffer
);
622 static void test_swprintf( void )
625 const wchar_t I64d
[] = {'%','I','6','4','d',0};
626 double pnumber
=789456123;
627 const wchar_t TwentyThreePoint15e
[]= {'%','+','#','2','3','.','1','5','e',0};
628 const wchar_t e008
[] = {'e','+','0','0','8',0};
629 const wchar_t string_w
[] = {'s','t','r','i','n','g',0};
630 const char string
[] = "string";
631 const wchar_t S
[]={'%','S',0};
632 const wchar_t hs
[] = {'%', 'h', 's', 0};
634 swprintf(buffer
,TwentyThreePoint15e
,pnumber
);
635 ok(wcsstr(buffer
,e008
) != 0,"Sprintf different\n");
636 swprintf(buffer
,I64d
,((ULONGLONG
)0xffffffff)*0xffffffff);
637 ok(wcslen(buffer
) == 11,"Problem with long long\n");
638 swprintf(buffer
,S
,string
);
639 ok(wcslen(buffer
) == 6,"Problem with \"%%S\" interpretation\n");
640 swprintf(buffer
, hs
, string
);
641 ok( wcscmp(string_w
,buffer
) == 0, "swprintf failed with %%hs\n");
644 static void test_snprintf (void)
646 struct snprintf_test
{
650 /* Pre-2.1 libc behaviour, not C99 compliant. */
651 const struct snprintf_test tests
[] = {{"short", 5},
656 const int bufsiz
= sizeof buffer
;
659 for (i
= 0; i
< sizeof tests
/ sizeof tests
[0]; i
++) {
660 const char *fmt
= tests
[i
].format
;
661 const int expect
= tests
[i
].expected
;
662 const int n
= _snprintf (buffer
, bufsiz
, fmt
);
663 const int valid
= n
< 0 ? bufsiz
: (n
== bufsiz
? n
: n
+1);
665 ok (n
== expect
, "\"%s\": expected %d, returned %d\n",
667 ok (!memcmp (fmt
, buffer
, valid
),
668 "\"%s\": rendered \"%.*s\"\n", fmt
, valid
, buffer
);
672 static void test_fprintf(void)
674 static char file_name
[] = "fprintf.tst";
675 FILE *fp
= fopen(file_name
, "wb");
679 ret
= fprintf(fp
, "simple test\n");
680 ok(ret
== 12, "ret = %d\n", ret
);
682 ok(ret
== 12, "ftell returned %d\n", ret
);
684 ret
= fprintf(fp
, "contains%cnull\n", '\0');
685 ok(ret
== 14, "ret = %d\n", ret
);
687 ok(ret
== 26, "ftell returned %d\n", ret
);
691 fp
= fopen(file_name
, "rb");
692 ret
= fscanf(fp
, "%[^\n] ", buf
);
693 ok(ret
== 1, "ret = %d\n", ret
);
695 ok(ret
== 12, "ftell returned %d\n", ret
);
696 ok(!strcmp(buf
, "simple test"), "buf = %s\n", buf
);
698 fgets(buf
, sizeof(buf
), fp
);
700 ok(ret
== 26, "ret = %d\n", ret
);
701 ok(!memcmp(buf
, "contains\0null\n", 14), "buf = %s\n", buf
);
707 static void test_fcvt(void)
710 int dec
=100, sign
=100;
712 /* Numbers less than 1.0 with different precisions */
713 str
= _fcvt(0.0001, 1, &dec
, &sign
);
714 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
715 ok( -3 == dec
, "dec wrong %d\n", dec
);
716 ok( 0 == sign
, "sign wrong\n");
718 str
= _fcvt(0.0001, -10, &dec
, &sign
);
719 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
720 ok( -3 == dec
, "dec wrong %d\n", dec
);
721 ok( 0 == sign
, "sign wrong\n");
723 str
= _fcvt(0.0001, 10, &dec
, &sign
);
724 ok( 0 == strcmp(str
,"1000000"), "bad return '%s'\n", str
);
725 ok( -3 == dec
, "dec wrong %d\n", dec
);
726 ok( 0 == sign
, "sign wrong\n");
728 /* Basic sign test */
729 str
= _fcvt(-111.0001, 5, &dec
, &sign
);
730 ok( 0 == strcmp(str
,"11100010"), "bad return '%s'\n", str
);
731 ok( 3 == dec
, "dec wrong %d\n", dec
);
732 ok( 1 == sign
, "sign wrong\n");
734 str
= _fcvt(111.0001, 5, &dec
, &sign
);
735 ok( 0 == strcmp(str
,"11100010"), "bad return '%s'\n", str
);
736 ok( 3 == dec
, "dec wrong\n");
737 ok( 0 == sign
, "sign wrong\n");
739 /* 0.0 with different precisions */
740 str
= _fcvt(0.0, 5, &dec
, &sign
);
741 ok( 0 == strcmp(str
,"00000"), "bad return '%s'\n", str
);
742 ok( 0 == dec
, "dec wrong %d\n", dec
);
743 ok( 0 == sign
, "sign wrong\n");
745 str
= _fcvt(0.0, 0, &dec
, &sign
);
746 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
747 ok( 0 == dec
, "dec wrong %d\n", dec
);
748 ok( 0 == sign
, "sign wrong\n");
750 str
= _fcvt(0.0, -1, &dec
, &sign
);
751 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
752 ok( 0 == dec
, "dec wrong %d\n", dec
);
753 ok( 0 == sign
, "sign wrong\n");
755 /* Numbers > 1.0 with 0 or -ve precision */
756 str
= _fcvt(-123.0001, 0, &dec
, &sign
);
757 ok( 0 == strcmp(str
,"123"), "bad return '%s'\n", str
);
758 ok( 3 == dec
, "dec wrong %d\n", dec
);
759 ok( 1 == sign
, "sign wrong\n");
761 str
= _fcvt(-123.0001, -1, &dec
, &sign
);
762 ok( 0 == strcmp(str
,"12"), "bad return '%s'\n", str
);
763 ok( 3 == dec
, "dec wrong %d\n", dec
);
764 ok( 1 == sign
, "sign wrong\n");
766 str
= _fcvt(-123.0001, -2, &dec
, &sign
);
767 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
768 ok( 3 == dec
, "dec wrong %d\n", dec
);
769 ok( 1 == sign
, "sign wrong\n");
771 str
= _fcvt(-123.0001, -3, &dec
, &sign
);
772 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
773 ok( 3 == dec
, "dec wrong %d\n", dec
);
774 ok( 1 == sign
, "sign wrong\n");
776 /* Numbers > 1.0, but with rounding at the point of precision */
777 str
= _fcvt(99.99, 1, &dec
, &sign
);
778 ok( 0 == strcmp(str
,"1000"), "bad return '%s'\n", str
);
779 ok( 3 == dec
, "dec wrong %d\n", dec
);
780 ok( 0 == sign
, "sign wrong\n");
782 /* Numbers < 1.0 where rounding occurs at the point of precision */
783 str
= _fcvt(0.00636, 2, &dec
, &sign
);
784 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
785 ok( -1 == dec
, "dec wrong %d\n", dec
);
786 ok( 0 == sign
, "sign wrong\n");
788 str
= _fcvt(0.00636, 3, &dec
, &sign
);
789 ok( 0 == strcmp(str
,"6"), "bad return '%s'\n", str
);
790 ok( -2 == dec
, "dec wrong %d\n", dec
);
791 ok( 0 == sign
, "sign wrong\n");
793 str
= _fcvt(0.09999999996, 2, &dec
, &sign
);
794 ok( 0 == strcmp(str
,"10"), "bad return '%s'\n", str
);
795 ok( 0 == dec
, "dec wrong %d\n", dec
);
796 ok( 0 == sign
, "sign wrong\n");
798 str
= _fcvt(0.6, 0, &dec
, &sign
);
799 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
800 ok( 1 == dec
, "dec wrong %d\n", dec
);
801 ok( 0 == sign
, "sign wrong\n");
804 /* Don't test nrdigits < 0, msvcrt on Win9x and NT4 will corrupt memory by
805 * writing outside allocated memory */
809 const char *expstr_e
;
810 const char *expstr_f
;
814 } test_cvt_testcases
[] = {
815 { 45.0, 2, "45", "4500", 2, 2, 0 },
816 /* Numbers less than 1.0 with different precisions */
817 { 0.0001, 1, "1", "", -3, -3, 0 },
818 { 0.0001, 10,"1000000000", "1000000", -3, -3, 0 },
819 /* Basic sign test */
820 { -111.0001, 5, "11100", "11100010", 3, 3, 1 },
821 { 111.0001, 5, "11100", "11100010", 3, 3, 0 },
822 /* big numbers with low precision */
823 { 3333.3, 2, "33", "333330", 4, 4, 0 },
824 {999999999999.9, 3, "100","999999999999900", 13, 12, 0 },
825 /* 0.0 with different precisions */
826 { 0.0, 5, "00000", "00000", 0, 0, 0 },
827 { 0.0, 0, "", "", 0, 0, 0 },
828 { 0.0, -1, "", "", 0, 0, 0 },
829 /* Numbers > 1.0 with 0 or -ve precision */
830 { -123.0001, 0, "", "123", 3, 3, 1 },
831 { -123.0001, -1, "", "12", 3, 3, 1 },
832 { -123.0001, -2, "", "1", 3, 3, 1 },
833 { -123.0001, -3, "", "", 3, 3, 1 },
834 /* Numbers > 1.0, but with rounding at the point of precision */
835 { 99.99, 1, "1", "1000", 3, 3, 0 },
836 /* Numbers < 1.0 where rounding occurs at the point of precision */
837 { 0.0063, 2, "63", "1", -2, -1, 0 },
838 { 0.0063, 3, "630", "6", -2, -2, 0 },
839 { 0.09999999996, 2, "10", "10", 0, 0, 0 },
840 { 0.6, 1, "6", "6", 0, 0, 0 },
841 { 0.6, 0, "", "1", 1, 1, 0 },
842 { 0.4, 0, "", "", 0, 0, 0 },
843 { 0.49, 0, "", "", 0, 0, 0 },
844 { 0.51, 0, "", "1", 1, 1, 0 },
845 /* ask for ridiculous precision, ruin formatting this table */
846 { 1.0, 30, "100000000000000000000000000000",
847 "1000000000000000000000000000000", 1, 1, 0},
848 { 123456789012345678901.0, 30, "123456789012345680000000000000",
849 "123456789012345680000000000000000000000000000000000", 21, 21, 0},
854 static void test_xcvt(void)
857 int i
, decpt
, sign
, err
;
859 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
861 str
= _ecvt( test_cvt_testcases
[i
].value
,
862 test_cvt_testcases
[i
].nrdigits
,
865 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_e
, 15),
866 "_ecvt() bad return, got \n'%s' expected \n'%s'\n", str
,
867 test_cvt_testcases
[i
].expstr_e
);
868 ok( decpt
== test_cvt_testcases
[i
].expdecpt_e
,
869 "_ecvt() decimal point wrong, got %d expected %d\n", decpt
,
870 test_cvt_testcases
[i
].expdecpt_e
);
871 ok( sign
== test_cvt_testcases
[i
].expsign
,
872 "_ecvt() sign wrong, got %d expected %d\n", sign
,
873 test_cvt_testcases
[i
].expsign
);
875 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
877 str
= _fcvt( test_cvt_testcases
[i
].value
,
878 test_cvt_testcases
[i
].nrdigits
,
881 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_f
, 15),
882 "_fcvt() bad return, got \n'%s' expected \n'%s'\n", str
,
883 test_cvt_testcases
[i
].expstr_f
);
884 ok( decpt
== test_cvt_testcases
[i
].expdecpt_f
,
885 "_fcvt() decimal point wrong, got %d expected %d\n", decpt
,
886 test_cvt_testcases
[i
].expdecpt_f
);
887 ok( sign
== test_cvt_testcases
[i
].expsign
,
888 "_fcvt() sign wrong, got %d expected %d\n", sign
,
889 test_cvt_testcases
[i
].expsign
);
895 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
897 err
= p__ecvt_s(str
, 1024, test_cvt_testcases
[i
].value
, test_cvt_testcases
[i
].nrdigits
, &decpt
, &sign
);
898 ok(err
== 0, "_ecvt_s() failed with error code %d\n", err
);
899 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_e
, 15),
900 "_ecvt_s() bad return, got \n'%s' expected \n'%s'\n", str
,
901 test_cvt_testcases
[i
].expstr_e
);
902 ok( decpt
== test_cvt_testcases
[i
].expdecpt_e
,
903 "_ecvt_s() decimal point wrong, got %d expected %d\n", decpt
,
904 test_cvt_testcases
[i
].expdecpt_e
);
905 ok( sign
== test_cvt_testcases
[i
].expsign
,
906 "_ecvt_s() sign wrong, got %d expected %d\n", sign
,
907 test_cvt_testcases
[i
].expsign
);
912 win_skip("_ecvt_s not available\n");
920 /* invalid arguments */
921 err
= p__fcvt_s(NULL
, 0, 0.0, 0, &i
, &i
);
922 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
924 err
= p__fcvt_s(str
, 0, 0.0, 0, &i
, &i
);
925 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
929 err
= p__fcvt_s(str
, -1, 0.0, 0, &i
, &i
);
930 ok(err
== 0, "got %d, expected 0\n", err
);
931 ok(str
[0] == 0, "got %c, expected 0\n", str
[0]);
932 ok(str
[1] == 0, "got %c, expected 0\n", str
[1]);
934 err
= p__fcvt_s(str
, 1, 0.0, 0, NULL
, &i
);
935 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
937 err
= p__fcvt_s(str
, 1, 0.0, 0, &i
, NULL
);
938 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
940 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
942 err
= p__fcvt_s(str
, 1024, test_cvt_testcases
[i
].value
, test_cvt_testcases
[i
].nrdigits
, &decpt
, &sign
);
943 ok(err
== 0, "_fcvt_s() failed with error code %d\n", err
);
944 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_f
, 15),
945 "_fcvt_s() bad return, got '%s' expected '%s'. test %d\n", str
,
946 test_cvt_testcases
[i
].expstr_f
, i
);
947 ok( decpt
== test_cvt_testcases
[i
].expdecpt_f
,
948 "_fcvt_s() decimal point wrong, got %d expected %d\n", decpt
,
949 test_cvt_testcases
[i
].expdecpt_f
);
950 ok( sign
== test_cvt_testcases
[i
].expsign
,
951 "_fcvt_s() sign wrong, got %d expected %d\n", sign
,
952 test_cvt_testcases
[i
].expsign
);
957 win_skip("_fcvt_s not available\n");
960 static int __cdecl
_vsnwprintf_wrapper(wchar_t *str
, size_t len
, const wchar_t *format
, ...)
964 __ms_va_start(valist
, format
);
965 ret
= _vsnwprintf(str
, len
, format
, valist
);
970 static void test_vsnwprintf(void)
972 const wchar_t format
[] = {'%','w','s','%','w','s','%','w','s',0};
973 const wchar_t one
[] = {'o','n','e',0};
974 const wchar_t two
[] = {'t','w','o',0};
975 const wchar_t three
[] = {'t','h','r','e','e',0};
981 ret
= _vsnwprintf_wrapper( str
, sizeof(str
)/sizeof(str
[0]), format
, one
, two
, three
);
983 ok( ret
== 11, "got %d expected 11\n", ret
);
984 WideCharToMultiByte( CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
985 ok( !strcmp(buf
, "onetwothree"), "got %s expected 'onetwothree'\n", buf
);
988 static int __cdecl
vswprintf_wrapper(wchar_t *str
, const wchar_t *format
, ...)
992 __ms_va_start(valist
, format
);
993 ret
= p_vswprintf(str
, format
, valist
);
998 static int __cdecl
_vswprintf_wrapper(wchar_t *str
, const wchar_t *format
, ...)
1001 __ms_va_list valist
;
1002 __ms_va_start(valist
, format
);
1003 ret
= p__vswprintf(str
, format
, valist
);
1004 __ms_va_end(valist
);
1008 static int __cdecl
_vswprintf_l_wrapper(wchar_t *str
, const wchar_t *format
, void *locale
, ...)
1011 __ms_va_list valist
;
1012 __ms_va_start(valist
, locale
);
1013 ret
= p__vswprintf_l(str
, format
, locale
, valist
);
1014 __ms_va_end(valist
);
1018 static int __cdecl
_vswprintf_c_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, ...)
1021 __ms_va_list valist
;
1022 __ms_va_start(valist
, format
);
1023 ret
= p__vswprintf_c(str
, size
, format
, valist
);
1024 __ms_va_end(valist
);
1028 static int __cdecl
_vswprintf_c_l_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, void *locale
, ...)
1031 __ms_va_list valist
;
1032 __ms_va_start(valist
, locale
);
1033 ret
= p__vswprintf_c_l(str
, size
, format
, locale
, valist
);
1034 __ms_va_end(valist
);
1038 static int __cdecl
_vswprintf_p_l_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, void *locale
, ...)
1041 __ms_va_list valist
;
1042 __ms_va_start(valist
, locale
);
1043 ret
= p__vswprintf_p_l(str
, size
, format
, locale
, valist
);
1044 __ms_va_end(valist
);
1048 static void test_vswprintf(void)
1050 const wchar_t format
[] = {'%','s',' ','%','d',0};
1051 const wchar_t number
[] = {'n','u','m','b','e','r',0};
1052 const wchar_t out
[] = {'n','u','m','b','e','r',' ','1','2','3',0};
1057 if (!p_vswprintf
|| !p__vswprintf
|| !p__vswprintf_l
||!p__vswprintf_c
1058 || !p__vswprintf_c_l
|| !p__vswprintf_p_l
)
1060 win_skip("_vswprintf or vswprintf not available\n");
1064 ret
= vswprintf_wrapper(buf
, format
, number
, 123);
1065 ok(ret
== 10, "got %d, expected 10\n", ret
);
1066 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1068 memset(buf
, 0, sizeof(buf
));
1069 ret
= _vswprintf_wrapper(buf
, format
, number
, 123);
1070 ok(ret
== 10, "got %d, expected 10\n", ret
);
1071 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1073 memset(buf
, 0, sizeof(buf
));
1074 ret
= _vswprintf_l_wrapper(buf
, format
, NULL
, number
, 123);
1075 ok(ret
== 10, "got %d, expected 10\n", ret
);
1076 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1078 memset(buf
, 0, sizeof(buf
));
1079 ret
= _vswprintf_c_wrapper(buf
, 20, format
, number
, 123);
1080 ok(ret
== 10, "got %d, expected 10\n", ret
);
1081 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1083 memset(buf
, 0, sizeof(buf
));
1084 ret
= _vswprintf_c_l_wrapper(buf
, 20, format
, NULL
, number
, 123);
1085 ok(ret
== 10, "got %d, expected 10\n", ret
);
1086 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1088 memset(buf
, 0, sizeof(buf
));
1089 ret
= _vswprintf_p_l_wrapper(buf
, 20, format
, NULL
, number
, 123);
1090 ok(ret
== 10, "got %d, expected 10\n", ret
);
1091 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1094 static int __cdecl
_vscprintf_wrapper(const char *format
, ...)
1097 __ms_va_list valist
;
1098 __ms_va_start(valist
, format
);
1099 ret
= p__vscprintf(format
, valist
);
1100 __ms_va_end(valist
);
1104 static void test_vscprintf(void)
1110 win_skip("_vscprintf not available\n");
1114 ret
= _vscprintf_wrapper( "%s %d", "number", 1 );
1115 ok( ret
== 8, "got %d expected 8\n", ret
);
1118 static int __cdecl
_vscwprintf_wrapper(const wchar_t *format
, ...)
1121 __ms_va_list valist
;
1122 __ms_va_start(valist
, format
);
1123 ret
= p__vscwprintf(format
, valist
);
1124 __ms_va_end(valist
);
1128 static void test_vscwprintf(void)
1130 const wchar_t format
[] = {'%','s',' ','%','d',0};
1131 const wchar_t number
[] = {'n','u','m','b','e','r',0};
1137 win_skip("_vscwprintf not available\n");
1141 ret
= _vscwprintf_wrapper( format
, number
, 1 );
1142 ok( ret
== 8, "got %d expected 8\n", ret
);
1145 static int __cdecl
_vsnwprintf_s_wrapper(wchar_t *str
, size_t sizeOfBuffer
,
1146 size_t count
, const wchar_t *format
, ...)
1149 __ms_va_list valist
;
1150 __ms_va_start(valist
, format
);
1151 ret
= p__vsnwprintf_s(str
, sizeOfBuffer
, count
, format
, valist
);
1152 __ms_va_end(valist
);
1156 static void test_vsnwprintf_s(void)
1158 const wchar_t format
[] = { 'A','B','%','u','C',0 };
1159 const wchar_t out7
[] = { 'A','B','1','2','3','C',0 };
1160 const wchar_t out6
[] = { 'A','B','1','2','3',0 };
1161 const wchar_t out2
[] = { 'A',0 };
1162 const wchar_t out1
[] = { 0 };
1163 wchar_t buffer
[14] = { 0 };
1166 if (!p__vsnwprintf_s
)
1168 win_skip("_vsnwprintf_s not available\n");
1175 got
= _vsnwprintf_s_wrapper(buffer
, 14, _TRUNCATE
, format
, 123);
1176 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1177 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1179 got
= _vsnwprintf_s_wrapper(buffer
, 12, _TRUNCATE
, format
, 123);
1180 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1181 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1183 got
= _vsnwprintf_s_wrapper(buffer
, 7, _TRUNCATE
, format
, 123);
1184 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1185 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1187 /* Not enough room. */
1190 got
= _vsnwprintf_s_wrapper(buffer
, 6, _TRUNCATE
, format
, 123);
1191 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1192 ok( !wcscmp(out6
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1194 got
= _vsnwprintf_s_wrapper(buffer
, 2, _TRUNCATE
, format
, 123);
1195 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1196 ok( !wcscmp(out2
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1198 got
= _vsnwprintf_s_wrapper(buffer
, 1, _TRUNCATE
, format
, 123);
1199 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1200 ok( !wcscmp(out1
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1203 static int __cdecl
_vsprintf_p_wrapper(char *str
, size_t sizeOfBuffer
,
1204 const char *format
, ...)
1207 __ms_va_list valist
;
1208 __ms_va_start(valist
, format
);
1209 ret
= p__vsprintf_p(str
, sizeOfBuffer
, format
, valist
);
1210 __ms_va_end(valist
);
1214 static void test_vsprintf_p(void)
1219 if(!p__vsprintf_p
) {
1220 win_skip("vsprintf_p not available\n");
1224 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%s %d", "test", 1234);
1225 ok(ret
== 9, "ret = %d\n", ret
);
1226 ok(!memcmp(buf
, "test 1234", 10), "buf = %s\n", buf
);
1228 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%1$d", 1234, "additional param");
1229 ok(ret
== 4, "ret = %d\n", ret
);
1230 ok(!memcmp(buf
, "1234", 5), "buf = %s\n", buf
);
1232 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%2$s %1$d", 1234, "test");
1233 ok(ret
== 9, "ret = %d\n", ret
);
1234 ok(!memcmp(buf
, "test 1234", 10), "buf = %s\n", buf
);
1236 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%2$*3$s %2$.*1$s", 2, "test", 3);
1237 ok(ret
== 7, "ret = %d\n", ret
);
1238 ok(!memcmp(buf
, "test te", 8), "buf = %s\n", buf
);
1240 /* Following test invokes invalid parameter handler */
1241 /* ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%d %1$d", 1234); */
1244 static void test__get_output_format(void)
1248 if (!p__get_output_format
)
1250 win_skip("_get_output_format not available\n");
1254 ret
= p__get_output_format();
1255 ok(ret
== 0, "got %d\n", ret
);
1272 test_vsnwprintf_s();
1274 test__get_output_format();