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 unsigned int (__cdecl
*p__set_output_format
)(unsigned int);
48 static int (__cdecl
*p__vsprintf_p
)(char*, size_t, const char*, __ms_va_list
);
49 static int (__cdecl
*p_vswprintf
)(wchar_t *str
, const wchar_t *format
, __ms_va_list valist
);
50 static int (__cdecl
*p__vswprintf
)(wchar_t *str
, const wchar_t *format
, __ms_va_list valist
);
51 static int (__cdecl
*p__vswprintf_l
)(wchar_t *str
, const wchar_t *format
,
52 void *locale
, __ms_va_list valist
);
53 static int (__cdecl
*p__vswprintf_c
)(wchar_t *str
, size_t size
, const wchar_t *format
,
55 static int (__cdecl
*p__vswprintf_c_l
)(wchar_t *str
, size_t size
, const wchar_t *format
,
56 void *locale
, __ms_va_list valist
);
57 static int (__cdecl
*p__vswprintf_p_l
)(wchar_t *str
, size_t size
, const wchar_t *format
,
58 void *locale
, __ms_va_list valist
);
60 static void init( void )
62 HMODULE hmod
= GetModuleHandleA("msvcrt.dll");
64 p__vscprintf
= (void *)GetProcAddress(hmod
, "_vscprintf");
65 p__vscwprintf
= (void *)GetProcAddress(hmod
, "_vscwprintf");
66 p__vsnwprintf_s
= (void *)GetProcAddress(hmod
, "_vsnwprintf_s");
67 p__ecvt_s
= (void *)GetProcAddress(hmod
, "_ecvt_s");
68 p__fcvt_s
= (void *)GetProcAddress(hmod
, "_fcvt_s");
69 p__get_output_format
= (void *)GetProcAddress(hmod
, "_get_output_format");
70 p__set_output_format
= (void *)GetProcAddress(hmod
, "_set_output_format");
71 p__vsprintf_p
= (void*)GetProcAddress(hmod
, "_vsprintf_p");
72 p_vswprintf
= (void*)GetProcAddress(hmod
, "vswprintf");
73 p__vswprintf
= (void*)GetProcAddress(hmod
, "_vswprintf");
74 p__vswprintf_l
= (void*)GetProcAddress(hmod
, "_vswprintf_l");
75 p__vswprintf_c
= (void*)GetProcAddress(hmod
, "_vswprintf_c");
76 p__vswprintf_c_l
= (void*)GetProcAddress(hmod
, "_vswprintf_c_l");
77 p__vswprintf_p_l
= (void*)GetProcAddress(hmod
, "_vswprintf_p_l");
80 static void test_sprintf( void )
84 double pnumber
=789456123;
86 WCHAR wide
[] = { 'w','i','d','e',0};
89 r
= sprintf(buffer
,format
,pnumber
);
90 ok(!strcmp(buffer
,"+7.894561230000000e+008"),"+#23.15e failed: '%s'\n", buffer
);
91 ok( r
==23, "return count wrong\n");
94 r
= sprintf(buffer
,format
,pnumber
);
95 ok(!strcmp(buffer
,"7.894561230000000e+008 "),"-#23.15e failed: '%s'\n", buffer
);
96 ok( r
==23, "return count wrong\n");
99 r
= sprintf(buffer
,format
,pnumber
);
100 ok(!strcmp(buffer
," 7.894561230000000e+008"),"#23.15e failed: '%s'\n", buffer
);
101 ok( r
==23, "return count wrong\n");
104 r
= sprintf(buffer
,format
,pnumber
);
105 ok(!strcmp(buffer
,"8.e+008"),"#1.1g failed: '%s'\n", buffer
);
106 ok( r
==7, "return count wrong\n");
109 r
= sprintf(buffer
,format
,((ULONGLONG
)0xffffffff)*0xffffffff);
110 ok(!strcmp(buffer
,"-8589934591"),"Problem with long long\n");
111 ok( r
==11, "return count wrong\n");
114 r
= sprintf(buffer
,format
,(LONGLONG
)100);
115 ok(!strcmp(buffer
," +100") && r
==8,"+8I64d failed: '%s'\n", buffer
);
118 r
= sprintf(buffer
,format
,(LONGLONG
)100);
119 ok(!strcmp(buffer
,"+00000100") && r
==9,"+.8I64d failed: '%s'\n", buffer
);
121 format
= "%+10.8I64d";
122 r
= sprintf(buffer
,format
,(LONGLONG
)100);
123 ok(!strcmp(buffer
," +00000100") && r
==10,"+10.8I64d failed: '%s'\n", buffer
);
125 r
= sprintf(buffer
,format
,(LONGLONG
)100);
126 ok(!strcmp(buffer
,"_1I64d") && r
==6,"_1I64d failed\n");
128 format
= "%-1.5I64d";
129 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
130 ok(!strcmp(buffer
,"-00100") && r
==6,"-1.5I64d failed: '%s'\n", buffer
);
133 r
= sprintf(buffer
,format
,(LONGLONG
)100);
134 ok(!strcmp(buffer
," 100") && r
==5,"5I64d failed: '%s'\n", buffer
);
137 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
138 ok(!strcmp(buffer
," -100") && r
==5,"5I64d failed: '%s'\n", buffer
);
141 r
= sprintf(buffer
,format
,(LONGLONG
)100);
142 ok(!strcmp(buffer
,"100 ") && r
==5,"-5I64d failed: '%s'\n", buffer
);
145 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
146 ok(!strcmp(buffer
,"-100 ") && r
==5,"-5I64d failed: '%s'\n", buffer
);
149 r
= sprintf(buffer
,format
,(LONGLONG
)100);
150 ok(!strcmp(buffer
,"00100") && r
==5,"-.5I64d failed: '%s'\n", buffer
);
153 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
154 ok(!strcmp(buffer
,"-00100") && r
==6,"-.5I64d failed: '%s'\n", buffer
);
156 format
= "%-8.5I64d";
157 r
= sprintf(buffer
,format
,(LONGLONG
)100);
158 ok(!strcmp(buffer
,"00100 ") && r
==8,"-8.5I64d failed: '%s'\n", buffer
);
160 format
= "%-8.5I64d";
161 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
162 ok(!strcmp(buffer
,"-00100 ") && r
==8,"-8.5I64d failed: '%s'\n", buffer
);
165 r
= sprintf(buffer
,format
,(LONGLONG
)100);
166 ok(!strcmp(buffer
,"00100") && r
==5,"05I64d failed: '%s'\n", buffer
);
169 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
170 ok(!strcmp(buffer
,"-0100") && r
==5,"05I64d failed: '%s'\n", buffer
);
173 r
= sprintf(buffer
,format
,(LONGLONG
)100);
174 ok(!strcmp(buffer
," 100") && r
==4,"' I64d' failed: '%s'\n", buffer
);
177 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
178 ok(!strcmp(buffer
,"-100") && r
==4,"' I64d' failed: '%s'\n", buffer
);
181 r
= sprintf(buffer
,format
,(LONGLONG
)100);
182 ok(!strcmp(buffer
," 100") && r
==5,"' 5I64d' failed: '%s'\n", buffer
);
185 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
186 ok(!strcmp(buffer
," -100") && r
==5,"' 5I64d' failed: '%s'\n", buffer
);
189 r
= sprintf(buffer
,format
,(LONGLONG
)100);
190 ok(!strcmp(buffer
," 00100") && r
==6,"' .5I64d' failed: '%s'\n", buffer
);
193 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
194 ok(!strcmp(buffer
,"-00100") && r
==6,"' .5I64d' failed: '%s'\n", buffer
);
196 format
= "% 8.5I64d";
197 r
= sprintf(buffer
,format
,(LONGLONG
)100);
198 ok(!strcmp(buffer
," 00100") && r
==8,"' 8.5I64d' failed: '%s'\n", buffer
);
200 format
= "% 8.5I64d";
201 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
202 ok(!strcmp(buffer
," -00100") && r
==8,"' 8.5I64d' failed: '%s'\n", buffer
);
205 r
= sprintf(buffer
,format
,(LONGLONG
)0);
206 ok(r
==0,".0I64d failed: '%s'\n", buffer
);
208 format
= "%#+21.18I64x";
209 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
210 ok(!strcmp(buffer
," 0x00ffffffffffffff9c") && r
==21,"#+21.18I64x failed: '%s'\n", buffer
);
212 format
= "%#.25I64o";
213 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
214 ok(!strcmp(buffer
,"0001777777777777777777634") && r
==25,"#.25I64o failed: '%s'\n", buffer
);
216 format
= "%#+24.20I64o";
217 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
218 ok(!strcmp(buffer
," 01777777777777777777634") && r
==24,"#+24.20I64o failed: '%s'\n", buffer
);
220 format
= "%#+18.21I64X";
221 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
222 ok(!strcmp(buffer
,"0X00000FFFFFFFFFFFFFF9C") && r
==23,"#+18.21I64X failed: '%s '\n", buffer
);
224 format
= "%#+20.24I64o";
225 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
226 ok(!strcmp(buffer
,"001777777777777777777634") && r
==24,"#+20.24I64o failed: '%s'\n", buffer
);
228 format
= "%#+25.22I64u";
229 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
230 ok(!strcmp(buffer
," 0018446744073709551615") && r
==25,"#+25.22I64u conversion failed: '%s'\n", buffer
);
232 format
= "%#+25.22I64u";
233 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
234 ok(!strcmp(buffer
," 0018446744073709551615") && r
==25,"#+25.22I64u failed: '%s'\n", buffer
);
236 format
= "%#+30.25I64u";
237 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
238 ok(!strcmp(buffer
," 0000018446744073709551615") && r
==30,"#+30.25I64u failed: '%s'\n", buffer
);
240 format
= "%+#25.22I64d";
241 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
242 ok(!strcmp(buffer
," -0000000000000000000001") && r
==25,"+#25.22I64d failed: '%s'\n", buffer
);
244 format
= "%#-8.5I64o";
245 r
= sprintf(buffer
,format
,(LONGLONG
)100);
246 ok(!strcmp(buffer
,"00144 ") && r
==8,"-8.5I64o failed: '%s'\n", buffer
);
248 format
= "%#-+ 08.5I64d";
249 r
= sprintf(buffer
,format
,(LONGLONG
)100);
250 ok(!strcmp(buffer
,"+00100 ") && r
==8,"'#-+ 08.5I64d failed: '%s'\n", buffer
);
252 format
= "%#-+ 08.5I64d";
253 r
= sprintf(buffer
,format
,(LONGLONG
)100);
254 ok(!strcmp(buffer
,"+00100 ") && r
==8,"#-+ 08.5I64d failed: '%s'\n", buffer
);
257 r
= sprintf(buffer
,format
,(LONGLONG
)1);
258 ok(r
==80,"%s format failed\n", format
);
260 format
= "% .80I64d";
261 r
= sprintf(buffer
,format
,(LONGLONG
)1);
262 ok(r
==81,"%s format failed\n", format
);
265 r
= sprintf(buffer
,format
,1);
266 ok(r
==81,"%s format failed\n", format
);
269 r
= sprintf(buffer
,format
,((ULONGLONG
)0xffffffff)*0xffffffff);
270 ok( r
== 1 || r
== 11, "return count wrong %d\n", r
);
271 if (r
== 11) /* %ll works on Vista */
272 ok(!strcmp(buffer
, "-8589934591"), "Problem with \"ll\" interpretation '%s'\n", buffer
);
274 ok(!strcmp(buffer
, "1"), "Problem with \"ll\" interpretation '%s'\n", buffer
);
277 r
= sprintf(buffer
,format
,1);
278 ok(!strcmp(buffer
, "I"), "Problem with \"I\" interpretation\n");
279 ok( r
==1, "return count wrong\n");
282 r
= sprintf(buffer
,format
,1);
283 ok(!strcmp(buffer
,"I0d"),"I0d failed\n");
284 ok( r
==3, "return count wrong\n");
287 r
= sprintf(buffer
,format
,1);
290 ok(!strcmp(buffer
,"1"),"I32d failed, got '%s'\n",buffer
);
294 /* Older versions don't grok I32 format */
295 ok(r
== 4 && !strcmp(buffer
,"I32d"),"I32d failed, got '%s',%d\n",buffer
,r
);
299 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
300 ok(!strcmp(buffer
,"D"),"I64D failed: %s\n",buffer
);
301 ok( r
==1, "return count wrong\n");
304 r
= sprintf(buffer
,format
,1);
305 ok(!strcmp(buffer
, " 1"),"Problem with sign place-holder: '%s'\n",buffer
);
306 ok( r
==2, "return count wrong\n");
309 r
= sprintf(buffer
,format
,1);
310 ok(!strcmp(buffer
, "+1"),"Problem with sign flags: '%s'\n",buffer
);
311 ok( r
==2, "return count wrong\n");
314 r
= sprintf(buffer
,format
,wide
);
315 ok(!strcmp(buffer
,"wide"),"Problem with wide string format\n");
316 ok( r
==4, "return count wrong\n");
319 r
= sprintf(buffer
,format
,'1');
320 ok(!strcmp(buffer
,"0001"),"Character not zero-prefixed \"%s\"\n",buffer
);
321 ok( r
==4, "return count wrong\n");
324 r
= sprintf(buffer
,format
,'1');
325 ok(!strcmp(buffer
,"1 "),"Character zero-padded and/or not left-adjusted \"%s\"\n",buffer
);
326 ok( r
==4, "return count wrong\n");
329 r
= sprintf(buffer
,format
,1);
330 ok(!strcmp(buffer
,"0x0000000001"),"Hexadecimal zero-padded \"%s\"\n",buffer
);
333 r
= sprintf(buffer
,format
,1);
334 ok(!strcmp(buffer
,"0x00000001"), "Hexadecimal zero-padded precision \"%s\"\n",buffer
);
337 r
= sprintf(buffer
,format
,1);
338 ok(!strcmp(buffer
,"0x01 "), "Hexadecimal zero-padded not left-adjusted \"%s\"\n",buffer
);
341 r
= sprintf(buffer
,format
,1);
342 ok(!strcmp(buffer
,"00000001"), "Octal zero-padded \"%s\"\n",buffer
);
344 if (sizeof(void *) == 8)
347 r
= sprintf(buffer
,format
,(void *)57);
348 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
349 ok( r
==16, "return count wrong\n");
352 r
= sprintf(buffer
,format
,(void *)57);
353 ok(!strcmp(buffer
," 0X0000000000000039"),"Pointer formatted incorrectly\n");
354 ok( r
==20, "return count wrong\n");
357 r
= sprintf(buffer
,format
,(void *)57);
358 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
359 ok( r
==16, "return count wrong\n");
362 r
= sprintf(buffer
,format
,(void *)57);
363 ok(!strcmp(buffer
,"0X0000000000000039 "),"Pointer formatted incorrectly\n");
364 ok( r
==20, "return count wrong\n");
369 r
= sprintf(buffer
,format
,(void *)57);
370 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
371 ok( r
==8, "return count wrong\n");
374 r
= sprintf(buffer
,format
,(void *)57);
375 ok(!strcmp(buffer
," 0X00000039"),"Pointer formatted incorrectly\n");
376 ok( r
==12, "return count wrong\n");
379 r
= sprintf(buffer
,format
,(void *)57);
380 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
381 ok( r
==8, "return count wrong\n");
384 r
= sprintf(buffer
,format
,(void *)57);
385 ok(!strcmp(buffer
,"0X00000039 "),"Pointer formatted incorrectly\n");
386 ok( r
==12, "return count wrong\n");
390 r
= sprintf(buffer
,format
,"foo");
391 ok(!strcmp(buffer
,"0foo"),"String not zero-prefixed \"%s\"\n",buffer
);
392 ok( r
==4, "return count wrong\n");
395 r
= sprintf(buffer
,format
,"foo");
396 ok(!strcmp(buffer
,"f"),"Precision ignored \"%s\"\n",buffer
);
397 ok( r
==1, "return count wrong\n");
400 r
= sprintf(buffer
,format
,1,"foo");
401 ok(!strcmp(buffer
,"f"),"Precision ignored \"%s\"\n",buffer
);
402 ok( r
==1, "return count wrong\n");
405 r
= sprintf(buffer
,format
,-5,"foo");
406 ok(!strcmp(buffer
,"foo "),"Negative field width ignored \"%s\"\n",buffer
);
407 ok( r
==5, "return count wrong\n");
410 r
= sprintf(buffer
, format
);
411 ok(!strcmp(buffer
,"hello"), "failed\n");
412 ok( r
==5, "return count wrong\n");
415 r
= sprintf(buffer
, format
, wide
);
416 ok(!strcmp(buffer
,"wide"), "failed\n");
417 ok( r
==4, "return count wrong\n");
420 r
= sprintf(buffer
, format
, wide
);
421 ok(!strcmp(buffer
,"wide "), "failed\n");
422 ok( r
==10, "return count wrong\n");
425 r
= sprintf(buffer
, format
, wide
);
426 ok(!strcmp(buffer
," wide"), "failed\n");
427 ok( r
==10, "return count wrong\n");
429 format
= "%#+ -03whlls";
430 r
= sprintf(buffer
, format
, wide
);
431 ok(!strcmp(buffer
,"wide"), "failed\n");
432 ok( r
==4, "return count wrong\n");
435 r
= sprintf(buffer
, format
, wide
);
436 ok(!strcmp(buffer
,"0s"), "failed\n");
437 ok( r
==2, "return count wrong\n");
440 r
= sprintf(buffer
, format
, wide
);
441 ok(!strcmp(buffer
,"-s"), "failed\n");
442 ok( r
==2, "return count wrong\n");
445 r
= sprintf(buffer
, format
, wide
);
446 ok(!strcmp(buffer
,"wide"), "failed\n");
447 ok( r
==4, "return count wrong\n");
450 r
= sprintf(buffer
, format
, "not wide" );
451 ok(!strcmp(buffer
,"not wide"), "failed\n");
452 ok( r
==8, "return count wrong\n");
455 r
= sprintf(buffer
, format
);
456 ok(!strcmp(buffer
,"b"), "failed\n");
457 ok( r
==1, "return count wrong\n");
460 r
= sprintf(buffer
, format
,'a');
461 ok(!strcmp(buffer
," a"), "failed\n");
462 ok( r
==3, "return count wrong\n");
465 r
= sprintf(buffer
, format
,1234);
466 ok(!strcmp(buffer
,"1234"), "failed\n");
467 ok( r
==4, "return count wrong\n");
470 r
= sprintf(buffer
, format
);
471 ok(!strcmp(buffer
,""), "failed\n");
472 ok( r
==0, "return count wrong\n");
474 format
= "%j%k%m%q%r%t%v%y%z";
475 r
= sprintf(buffer
, format
);
476 ok(!strcmp(buffer
,"jkmqrtvyz"), "failed\n");
477 ok( r
==9, "return count wrong\n");
481 r
= sprintf(buffer
, format
, &x
);
484 /* %n format is disabled by default on vista */
485 /* FIXME: should test with _set_printf_count_output */
486 ok(x
== 0, "should not write to x: %d\n", x
);
490 ok(x
== 4, "should write to x: %d\n", x
);
491 ok(!strcmp(buffer
,"asdf"), "failed\n");
492 ok( r
==4, "return count wrong: %d\n", r
);
496 r
= sprintf(buffer
, format
,2);
497 ok(!strcmp(buffer
,"2"), "failed\n");
498 ok( r
==1, "return count wrong\n");
501 r
= sprintf(buffer
, format
,8.6);
502 ok(!strcmp(buffer
,"8.6000"), "failed\n");
503 ok( r
==6, "return count wrong\n");
506 r
= sprintf(buffer
, format
,0.6);
507 ok(!strcmp(buffer
,"0.600000"), "failed\n");
508 ok( r
==8, "return count wrong\n");
511 r
= sprintf(buffer
, format
,0.6);
512 ok(!strcmp(buffer
,"1"), "failed\n");
513 ok( r
==1, "return count wrong\n");
516 r
= sprintf(buffer
, format
,8.6);
517 ok(!strcmp(buffer
,"8.6000e+000"), "failed\n");
518 ok( r
==11, "return count wrong\n");
521 r
= sprintf(buffer
, format
,8.6);
522 ok(!strcmp(buffer
," 8.6000e+000"), "failed: %s\n", buffer
);
523 ok( r
==12, "return count wrong\n");
526 r
= sprintf(buffer
, format
,8.6);
527 ok(!strcmp(buffer
," 008.6000e+000"), "failed: %s\n", buffer
);
528 ok( r
==14, "return count wrong\n");
531 r
= sprintf(buffer
, format
,-8.6);
532 ok(!strcmp(buffer
,"-8.6000e+000"), "failed: %s\n", buffer
);
533 ok( r
==12, "return count wrong\n");
536 r
= sprintf(buffer
, format
,8.6);
537 ok(!strcmp(buffer
,"+8.6000e+000"), "failed: %s\n", buffer
);
538 ok( r
==12, "return count wrong\n");
541 r
= sprintf(buffer
, format
,8.6);
542 ok(!strcmp(buffer
,"8.6"), "failed\n");
543 ok( r
==3, "return count wrong\n");
546 r
= sprintf(buffer
, format
,-1);
547 ok(!strcmp(buffer
,"-1"), "failed\n");
548 ok( r
==2, "return count wrong\n");
551 r
= sprintf(buffer
, format
,1);
552 ok(!strcmp(buffer
,"1"), "failed\n");
553 ok( r
==1, "return count wrong\n");
556 r
= sprintf(buffer
, format
,1);
557 ok(!strcmp(buffer
,"+1"), "failed\n");
558 ok( r
==2, "return count wrong\n");
561 r
= sprintf(buffer
, format
,10);
562 ok(!strcmp(buffer
,"12"), "failed\n");
563 ok( r
==2, "return count wrong\n");
566 r
= sprintf(buffer
, format
,0);
567 if (sizeof(void *) == 8)
569 ok(!strcmp(buffer
,"0000000000000000"), "failed\n");
570 ok( r
==16, "return count wrong\n");
574 ok(!strcmp(buffer
,"00000000"), "failed\n");
575 ok( r
==8, "return count wrong\n");
579 r
= sprintf(buffer
, format
,0);
580 ok(!strcmp(buffer
,"(null)"), "failed\n");
581 ok( r
==6, "return count wrong\n");
584 r
= sprintf(buffer
, format
,"%%%%");
585 ok(!strcmp(buffer
,"%%%%"), "failed\n");
586 ok( r
==4, "return count wrong\n");
589 r
= sprintf(buffer
, format
,-1);
590 ok(!strcmp(buffer
,"4294967295"), "failed\n");
591 ok( r
==10, "return count wrong\n");
594 r
= sprintf(buffer
, format
,-1);
595 ok(!strcmp(buffer
,""), "failed\n");
596 ok( r
==0, "return count wrong\n");
599 r
= sprintf(buffer
, format
,-1);
600 ok(!strcmp(buffer
,""), "failed\n");
601 ok( r
==0, "return count wrong\n");
604 r
= sprintf(buffer
, format
,-1);
605 ok(!strcmp(buffer
,"z"), "failed\n");
606 ok( r
==1, "return count wrong\n");
609 r
= sprintf(buffer
, format
,-1);
610 ok(!strcmp(buffer
,"j"), "failed\n");
611 ok( r
==1, "return count wrong\n");
614 r
= sprintf(buffer
, format
,-1);
615 ok(!strcmp(buffer
,""), "failed\n");
616 ok( r
==0, "return count wrong\n");
619 r
= sprintf(buffer
, format
,-1);
620 ok(!strcmp(buffer
,"H"), "failed\n");
621 ok( r
==1, "return count wrong\n");
624 r
= sprintf(buffer
, format
, 0x100+'X');
625 ok(!strcmp(buffer
,"xXx"), "failed\n");
626 ok( r
==3, "return count wrong\n");
629 r
= sprintf(buffer
, format
);
630 ok(!strcmp(buffer
,"%0"), "failed: \"%s\"\n", buffer
);
631 ok( r
==2, "return count wrong\n");
634 r
= sprintf(buffer
, format
, 0x12345);
635 ok(!strcmp(buffer
,"2345"), "failed \"%s\"\n", buffer
);
638 r
= sprintf(buffer
, format
, 0x123);
639 ok(!strcmp(buffer
,"123"), "failed: \"%s\"\n", buffer
);
640 r
= sprintf(buffer
, format
, 0x12345);
641 ok(!strcmp(buffer
,"2345"), "failed \"%s\"\n", buffer
);
644 static void test_swprintf( void )
647 const wchar_t I64d
[] = {'%','I','6','4','d',0};
648 double pnumber
=789456123;
649 const wchar_t TwentyThreePoint15e
[]= {'%','+','#','2','3','.','1','5','e',0};
650 const wchar_t e008
[] = {'e','+','0','0','8',0};
651 const wchar_t string_w
[] = {'s','t','r','i','n','g',0};
652 const char string
[] = "string";
653 const wchar_t S
[]={'%','S',0};
654 const wchar_t hs
[] = {'%', 'h', 's', 0};
656 swprintf(buffer
,TwentyThreePoint15e
,pnumber
);
657 ok(wcsstr(buffer
,e008
) != 0,"Sprintf different\n");
658 swprintf(buffer
,I64d
,((ULONGLONG
)0xffffffff)*0xffffffff);
659 ok(wcslen(buffer
) == 11,"Problem with long long\n");
660 swprintf(buffer
,S
,string
);
661 ok(wcslen(buffer
) == 6,"Problem with \"%%S\" interpretation\n");
662 swprintf(buffer
, hs
, string
);
663 ok( wcscmp(string_w
,buffer
) == 0, "swprintf failed with %%hs\n");
666 static void test_snprintf (void)
668 struct snprintf_test
{
672 /* Pre-2.1 libc behaviour, not C99 compliant. */
673 const struct snprintf_test tests
[] = {{"short", 5},
678 const int bufsiz
= sizeof buffer
;
681 for (i
= 0; i
< sizeof tests
/ sizeof tests
[0]; i
++) {
682 const char *fmt
= tests
[i
].format
;
683 const int expect
= tests
[i
].expected
;
684 const int n
= _snprintf (buffer
, bufsiz
, fmt
);
685 const int valid
= n
< 0 ? bufsiz
: (n
== bufsiz
? n
: n
+1);
687 ok (n
== expect
, "\"%s\": expected %d, returned %d\n",
689 ok (!memcmp (fmt
, buffer
, valid
),
690 "\"%s\": rendered \"%.*s\"\n", fmt
, valid
, buffer
);
694 static void test_fprintf(void)
696 static const char file_name
[] = "fprintf.tst";
697 static const WCHAR utf16_test
[] = {'u','n','i','c','o','d','e','\n',0};
699 FILE *fp
= fopen(file_name
, "wb");
703 ret
= fprintf(fp
, "simple test\n");
704 ok(ret
== 12, "ret = %d\n", ret
);
706 ok(ret
== 12, "ftell returned %d\n", ret
);
708 ret
= fprintf(fp
, "contains%cnull\n", '\0');
709 ok(ret
== 14, "ret = %d\n", ret
);
711 ok(ret
== 26, "ftell returned %d\n", ret
);
713 ret
= fwprintf(fp
, utf16_test
);
714 ok(ret
== 8, "ret = %d\n", ret
);
716 ok(ret
== 42, "ftell returned %d\n", ret
);
720 fp
= fopen(file_name
, "rb");
721 ret
= fscanf(fp
, "%[^\n] ", buf
);
722 ok(ret
== 1, "ret = %d\n", ret
);
724 ok(ret
== 12, "ftell returned %d\n", ret
);
725 ok(!strcmp(buf
, "simple test"), "buf = %s\n", buf
);
727 fgets(buf
, sizeof(buf
), fp
);
729 ok(ret
== 26, "ret = %d\n", ret
);
730 ok(!memcmp(buf
, "contains\0null\n", 14), "buf = %s\n", buf
);
732 memset(buf
, 0, sizeof(buf
));
733 fgets(buf
, sizeof(buf
), fp
);
735 ok(ret
== 41, "ret = %d\n", ret
);
736 ok(!memcmp(buf
, utf16_test
, sizeof(utf16_test
)),
737 "buf = %s\n", wine_dbgstr_w((WCHAR
*)buf
));
741 fp
= fopen(file_name
, "wt");
743 ret
= fprintf(fp
, "simple test\n");
744 ok(ret
== 12, "ret = %d\n", ret
);
746 ok(ret
== 13, "ftell returned %d\n", ret
);
748 ret
= fprintf(fp
, "contains%cnull\n", '\0');
749 ok(ret
== 14, "ret = %d\n", ret
);
751 ok(ret
== 28, "ftell returned %d\n", ret
);
753 ret
= fwprintf(fp
, utf16_test
);
754 ok(ret
== 8, "ret = %d\n", ret
);
756 ok(ret
== 37, "ftell returned %d\n", ret
);
760 fp
= fopen(file_name
, "rb");
761 ret
= fscanf(fp
, "%[^\n] ", buf
);
762 ok(ret
== 1, "ret = %d\n", ret
);
764 ok(ret
== 13, "ftell returned %d\n", ret
);
765 ok(!strcmp(buf
, "simple test\r"), "buf = %s\n", buf
);
767 fgets(buf
, sizeof(buf
), fp
);
769 ok(ret
== 28, "ret = %d\n", ret
);
770 ok(!memcmp(buf
, "contains\0null\r\n", 15), "buf = %s\n", buf
);
772 fgets(buf
, sizeof(buf
), fp
);
774 ok(ret
== 37, "ret = %d\n", ret
);
775 ok(!strcmp(buf
, "unicode\r\n"), "buf = %s\n", buf
);
781 static void test_fcvt(void)
784 int dec
=100, sign
=100;
786 /* Numbers less than 1.0 with different precisions */
787 str
= _fcvt(0.0001, 1, &dec
, &sign
);
788 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
789 ok( -3 == dec
, "dec wrong %d\n", dec
);
790 ok( 0 == sign
, "sign wrong\n");
792 str
= _fcvt(0.0001, -10, &dec
, &sign
);
793 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
794 ok( -3 == dec
, "dec wrong %d\n", dec
);
795 ok( 0 == sign
, "sign wrong\n");
797 str
= _fcvt(0.0001, 10, &dec
, &sign
);
798 ok( 0 == strcmp(str
,"1000000"), "bad return '%s'\n", str
);
799 ok( -3 == dec
, "dec wrong %d\n", dec
);
800 ok( 0 == sign
, "sign wrong\n");
802 /* Basic sign test */
803 str
= _fcvt(-111.0001, 5, &dec
, &sign
);
804 ok( 0 == strcmp(str
,"11100010"), "bad return '%s'\n", str
);
805 ok( 3 == dec
, "dec wrong %d\n", dec
);
806 ok( 1 == sign
, "sign wrong\n");
808 str
= _fcvt(111.0001, 5, &dec
, &sign
);
809 ok( 0 == strcmp(str
,"11100010"), "bad return '%s'\n", str
);
810 ok( 3 == dec
, "dec wrong\n");
811 ok( 0 == sign
, "sign wrong\n");
813 /* 0.0 with different precisions */
814 str
= _fcvt(0.0, 5, &dec
, &sign
);
815 ok( 0 == strcmp(str
,"00000"), "bad return '%s'\n", str
);
816 ok( 0 == dec
, "dec wrong %d\n", dec
);
817 ok( 0 == sign
, "sign wrong\n");
819 str
= _fcvt(0.0, 0, &dec
, &sign
);
820 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
821 ok( 0 == dec
, "dec wrong %d\n", dec
);
822 ok( 0 == sign
, "sign wrong\n");
824 str
= _fcvt(0.0, -1, &dec
, &sign
);
825 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
826 ok( 0 == dec
, "dec wrong %d\n", dec
);
827 ok( 0 == sign
, "sign wrong\n");
829 /* Numbers > 1.0 with 0 or -ve precision */
830 str
= _fcvt(-123.0001, 0, &dec
, &sign
);
831 ok( 0 == strcmp(str
,"123"), "bad return '%s'\n", str
);
832 ok( 3 == dec
, "dec wrong %d\n", dec
);
833 ok( 1 == sign
, "sign wrong\n");
835 str
= _fcvt(-123.0001, -1, &dec
, &sign
);
836 ok( 0 == strcmp(str
,"12"), "bad return '%s'\n", str
);
837 ok( 3 == dec
, "dec wrong %d\n", dec
);
838 ok( 1 == sign
, "sign wrong\n");
840 str
= _fcvt(-123.0001, -2, &dec
, &sign
);
841 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
842 ok( 3 == dec
, "dec wrong %d\n", dec
);
843 ok( 1 == sign
, "sign wrong\n");
845 str
= _fcvt(-123.0001, -3, &dec
, &sign
);
846 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
847 ok( 3 == dec
, "dec wrong %d\n", dec
);
848 ok( 1 == sign
, "sign wrong\n");
850 /* Numbers > 1.0, but with rounding at the point of precision */
851 str
= _fcvt(99.99, 1, &dec
, &sign
);
852 ok( 0 == strcmp(str
,"1000"), "bad return '%s'\n", str
);
853 ok( 3 == dec
, "dec wrong %d\n", dec
);
854 ok( 0 == sign
, "sign wrong\n");
856 /* Numbers < 1.0 where rounding occurs at the point of precision */
857 str
= _fcvt(0.00636, 2, &dec
, &sign
);
858 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
859 ok( -1 == dec
, "dec wrong %d\n", dec
);
860 ok( 0 == sign
, "sign wrong\n");
862 str
= _fcvt(0.00636, 3, &dec
, &sign
);
863 ok( 0 == strcmp(str
,"6"), "bad return '%s'\n", str
);
864 ok( -2 == dec
, "dec wrong %d\n", dec
);
865 ok( 0 == sign
, "sign wrong\n");
867 str
= _fcvt(0.09999999996, 2, &dec
, &sign
);
868 ok( 0 == strcmp(str
,"10"), "bad return '%s'\n", str
);
869 ok( 0 == dec
, "dec wrong %d\n", dec
);
870 ok( 0 == sign
, "sign wrong\n");
872 str
= _fcvt(0.6, 0, &dec
, &sign
);
873 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
874 ok( 1 == dec
, "dec wrong %d\n", dec
);
875 ok( 0 == sign
, "sign wrong\n");
878 /* Don't test nrdigits < 0, msvcrt on Win9x and NT4 will corrupt memory by
879 * writing outside allocated memory */
883 const char *expstr_e
;
884 const char *expstr_f
;
888 } test_cvt_testcases
[] = {
889 { 45.0, 2, "45", "4500", 2, 2, 0 },
890 /* Numbers less than 1.0 with different precisions */
891 { 0.0001, 1, "1", "", -3, -3, 0 },
892 { 0.0001, 10,"1000000000", "1000000", -3, -3, 0 },
893 /* Basic sign test */
894 { -111.0001, 5, "11100", "11100010", 3, 3, 1 },
895 { 111.0001, 5, "11100", "11100010", 3, 3, 0 },
896 /* big numbers with low precision */
897 { 3333.3, 2, "33", "333330", 4, 4, 0 },
898 {999999999999.9, 3, "100","999999999999900", 13, 12, 0 },
899 /* 0.0 with different precisions */
900 { 0.0, 5, "00000", "00000", 0, 0, 0 },
901 { 0.0, 0, "", "", 0, 0, 0 },
902 { 0.0, -1, "", "", 0, 0, 0 },
903 /* Numbers > 1.0 with 0 or -ve precision */
904 { -123.0001, 0, "", "123", 3, 3, 1 },
905 { -123.0001, -1, "", "12", 3, 3, 1 },
906 { -123.0001, -2, "", "1", 3, 3, 1 },
907 { -123.0001, -3, "", "", 3, 3, 1 },
908 /* Numbers > 1.0, but with rounding at the point of precision */
909 { 99.99, 1, "1", "1000", 3, 3, 0 },
910 /* Numbers < 1.0 where rounding occurs at the point of precision */
911 { 0.0063, 2, "63", "1", -2, -1, 0 },
912 { 0.0063, 3, "630", "6", -2, -2, 0 },
913 { 0.09999999996, 2, "10", "10", 0, 0, 0 },
914 { 0.6, 1, "6", "6", 0, 0, 0 },
915 { 0.6, 0, "", "1", 1, 1, 0 },
916 { 0.4, 0, "", "", 0, 0, 0 },
917 { 0.49, 0, "", "", 0, 0, 0 },
918 { 0.51, 0, "", "1", 1, 1, 0 },
919 /* ask for ridiculous precision, ruin formatting this table */
920 { 1.0, 30, "100000000000000000000000000000",
921 "1000000000000000000000000000000", 1, 1, 0},
922 { 123456789012345678901.0, 30, "123456789012345680000000000000",
923 "123456789012345680000000000000000000000000000000000", 21, 21, 0},
928 static void test_xcvt(void)
931 int i
, decpt
, sign
, err
;
933 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
935 str
= _ecvt( test_cvt_testcases
[i
].value
,
936 test_cvt_testcases
[i
].nrdigits
,
939 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_e
, 15),
940 "_ecvt() bad return, got \n'%s' expected \n'%s'\n", str
,
941 test_cvt_testcases
[i
].expstr_e
);
942 ok( decpt
== test_cvt_testcases
[i
].expdecpt_e
,
943 "_ecvt() decimal point wrong, got %d expected %d\n", decpt
,
944 test_cvt_testcases
[i
].expdecpt_e
);
945 ok( sign
== test_cvt_testcases
[i
].expsign
,
946 "_ecvt() sign wrong, got %d expected %d\n", sign
,
947 test_cvt_testcases
[i
].expsign
);
949 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
951 str
= _fcvt( test_cvt_testcases
[i
].value
,
952 test_cvt_testcases
[i
].nrdigits
,
955 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_f
, 15),
956 "_fcvt() bad return, got \n'%s' expected \n'%s'\n", str
,
957 test_cvt_testcases
[i
].expstr_f
);
958 ok( decpt
== test_cvt_testcases
[i
].expdecpt_f
,
959 "_fcvt() decimal point wrong, got %d expected %d\n", decpt
,
960 test_cvt_testcases
[i
].expdecpt_f
);
961 ok( sign
== test_cvt_testcases
[i
].expsign
,
962 "_fcvt() sign wrong, got %d expected %d\n", sign
,
963 test_cvt_testcases
[i
].expsign
);
969 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
971 err
= p__ecvt_s(str
, 1024, test_cvt_testcases
[i
].value
, test_cvt_testcases
[i
].nrdigits
, &decpt
, &sign
);
972 ok(err
== 0, "_ecvt_s() failed with error code %d\n", err
);
973 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_e
, 15),
974 "_ecvt_s() bad return, got \n'%s' expected \n'%s'\n", str
,
975 test_cvt_testcases
[i
].expstr_e
);
976 ok( decpt
== test_cvt_testcases
[i
].expdecpt_e
,
977 "_ecvt_s() decimal point wrong, got %d expected %d\n", decpt
,
978 test_cvt_testcases
[i
].expdecpt_e
);
979 ok( sign
== test_cvt_testcases
[i
].expsign
,
980 "_ecvt_s() sign wrong, got %d expected %d\n", sign
,
981 test_cvt_testcases
[i
].expsign
);
986 win_skip("_ecvt_s not available\n");
994 /* invalid arguments */
995 err
= p__fcvt_s(NULL
, 0, 0.0, 0, &i
, &i
);
996 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
998 err
= p__fcvt_s(str
, 0, 0.0, 0, &i
, &i
);
999 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
1003 err
= p__fcvt_s(str
, -1, 0.0, 0, &i
, &i
);
1004 ok(err
== 0, "got %d, expected 0\n", err
);
1005 ok(str
[0] == 0, "got %c, expected 0\n", str
[0]);
1006 ok(str
[1] == 0, "got %c, expected 0\n", str
[1]);
1008 err
= p__fcvt_s(str
, 1, 0.0, 0, NULL
, &i
);
1009 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
1011 err
= p__fcvt_s(str
, 1, 0.0, 0, &i
, NULL
);
1012 ok(err
== EINVAL
, "got %d, expected EINVAL\n", err
);
1014 for( i
= 0; strcmp( test_cvt_testcases
[i
].expstr_e
, "END"); i
++){
1016 err
= p__fcvt_s(str
, 1024, test_cvt_testcases
[i
].value
, test_cvt_testcases
[i
].nrdigits
, &decpt
, &sign
);
1017 ok(err
== 0, "_fcvt_s() failed with error code %d\n", err
);
1018 ok( 0 == strncmp( str
, test_cvt_testcases
[i
].expstr_f
, 15),
1019 "_fcvt_s() bad return, got '%s' expected '%s'. test %d\n", str
,
1020 test_cvt_testcases
[i
].expstr_f
, i
);
1021 ok( decpt
== test_cvt_testcases
[i
].expdecpt_f
,
1022 "_fcvt_s() decimal point wrong, got %d expected %d\n", decpt
,
1023 test_cvt_testcases
[i
].expdecpt_f
);
1024 ok( sign
== test_cvt_testcases
[i
].expsign
,
1025 "_fcvt_s() sign wrong, got %d expected %d\n", sign
,
1026 test_cvt_testcases
[i
].expsign
);
1031 win_skip("_fcvt_s not available\n");
1034 static int __cdecl
_vsnwprintf_wrapper(wchar_t *str
, size_t len
, const wchar_t *format
, ...)
1037 __ms_va_list valist
;
1038 __ms_va_start(valist
, format
);
1039 ret
= _vsnwprintf(str
, len
, format
, valist
);
1040 __ms_va_end(valist
);
1044 static void test_vsnwprintf(void)
1046 const wchar_t format
[] = {'%','w','s','%','w','s','%','w','s',0};
1047 const wchar_t one
[] = {'o','n','e',0};
1048 const wchar_t two
[] = {'t','w','o',0};
1049 const wchar_t three
[] = {'t','h','r','e','e',0};
1055 ret
= _vsnwprintf_wrapper( str
, sizeof(str
)/sizeof(str
[0]), format
, one
, two
, three
);
1057 ok( ret
== 11, "got %d expected 11\n", ret
);
1058 WideCharToMultiByte( CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
1059 ok( !strcmp(buf
, "onetwothree"), "got %s expected 'onetwothree'\n", buf
);
1062 static int __cdecl
vswprintf_wrapper(wchar_t *str
, const wchar_t *format
, ...)
1065 __ms_va_list valist
;
1066 __ms_va_start(valist
, format
);
1067 ret
= p_vswprintf(str
, format
, valist
);
1068 __ms_va_end(valist
);
1072 static int __cdecl
_vswprintf_wrapper(wchar_t *str
, const wchar_t *format
, ...)
1075 __ms_va_list valist
;
1076 __ms_va_start(valist
, format
);
1077 ret
= p__vswprintf(str
, format
, valist
);
1078 __ms_va_end(valist
);
1082 static int __cdecl
_vswprintf_l_wrapper(wchar_t *str
, const wchar_t *format
, void *locale
, ...)
1085 __ms_va_list valist
;
1086 __ms_va_start(valist
, locale
);
1087 ret
= p__vswprintf_l(str
, format
, locale
, valist
);
1088 __ms_va_end(valist
);
1092 static int __cdecl
_vswprintf_c_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, ...)
1095 __ms_va_list valist
;
1096 __ms_va_start(valist
, format
);
1097 ret
= p__vswprintf_c(str
, size
, format
, valist
);
1098 __ms_va_end(valist
);
1102 static int __cdecl
_vswprintf_c_l_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, void *locale
, ...)
1105 __ms_va_list valist
;
1106 __ms_va_start(valist
, locale
);
1107 ret
= p__vswprintf_c_l(str
, size
, format
, locale
, valist
);
1108 __ms_va_end(valist
);
1112 static int __cdecl
_vswprintf_p_l_wrapper(wchar_t *str
, size_t size
, const wchar_t *format
, void *locale
, ...)
1115 __ms_va_list valist
;
1116 __ms_va_start(valist
, locale
);
1117 ret
= p__vswprintf_p_l(str
, size
, format
, locale
, valist
);
1118 __ms_va_end(valist
);
1122 static void test_vswprintf(void)
1124 const wchar_t format
[] = {'%','s',' ','%','d',0};
1125 const wchar_t number
[] = {'n','u','m','b','e','r',0};
1126 const wchar_t out
[] = {'n','u','m','b','e','r',' ','1','2','3',0};
1131 if (!p_vswprintf
|| !p__vswprintf
|| !p__vswprintf_l
||!p__vswprintf_c
1132 || !p__vswprintf_c_l
|| !p__vswprintf_p_l
)
1134 win_skip("_vswprintf or vswprintf not available\n");
1138 ret
= vswprintf_wrapper(buf
, format
, number
, 123);
1139 ok(ret
== 10, "got %d, expected 10\n", ret
);
1140 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1142 memset(buf
, 0, sizeof(buf
));
1143 ret
= _vswprintf_wrapper(buf
, format
, number
, 123);
1144 ok(ret
== 10, "got %d, expected 10\n", ret
);
1145 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1147 memset(buf
, 0, sizeof(buf
));
1148 ret
= _vswprintf_l_wrapper(buf
, format
, NULL
, number
, 123);
1149 ok(ret
== 10, "got %d, expected 10\n", ret
);
1150 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1152 memset(buf
, 0, sizeof(buf
));
1153 ret
= _vswprintf_c_wrapper(buf
, 20, format
, number
, 123);
1154 ok(ret
== 10, "got %d, expected 10\n", ret
);
1155 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1157 memset(buf
, 0, sizeof(buf
));
1158 ret
= _vswprintf_c_l_wrapper(buf
, 20, format
, NULL
, number
, 123);
1159 ok(ret
== 10, "got %d, expected 10\n", ret
);
1160 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1162 memset(buf
, 0, sizeof(buf
));
1163 ret
= _vswprintf_p_l_wrapper(buf
, 20, format
, NULL
, number
, 123);
1164 ok(ret
== 10, "got %d, expected 10\n", ret
);
1165 ok(!memcmp(buf
, out
, sizeof(out
)), "buf = %s\n", wine_dbgstr_w(buf
));
1168 static int __cdecl
_vscprintf_wrapper(const char *format
, ...)
1171 __ms_va_list valist
;
1172 __ms_va_start(valist
, format
);
1173 ret
= p__vscprintf(format
, valist
);
1174 __ms_va_end(valist
);
1178 static void test_vscprintf(void)
1184 win_skip("_vscprintf not available\n");
1188 ret
= _vscprintf_wrapper( "%s %d", "number", 1 );
1189 ok( ret
== 8, "got %d expected 8\n", ret
);
1192 static int __cdecl
_vscwprintf_wrapper(const wchar_t *format
, ...)
1195 __ms_va_list valist
;
1196 __ms_va_start(valist
, format
);
1197 ret
= p__vscwprintf(format
, valist
);
1198 __ms_va_end(valist
);
1202 static void test_vscwprintf(void)
1204 const wchar_t format
[] = {'%','s',' ','%','d',0};
1205 const wchar_t number
[] = {'n','u','m','b','e','r',0};
1211 win_skip("_vscwprintf not available\n");
1215 ret
= _vscwprintf_wrapper( format
, number
, 1 );
1216 ok( ret
== 8, "got %d expected 8\n", ret
);
1219 static int __cdecl
_vsnwprintf_s_wrapper(wchar_t *str
, size_t sizeOfBuffer
,
1220 size_t count
, const wchar_t *format
, ...)
1223 __ms_va_list valist
;
1224 __ms_va_start(valist
, format
);
1225 ret
= p__vsnwprintf_s(str
, sizeOfBuffer
, count
, format
, valist
);
1226 __ms_va_end(valist
);
1230 static void test_vsnwprintf_s(void)
1232 const wchar_t format
[] = { 'A','B','%','u','C',0 };
1233 const wchar_t out7
[] = { 'A','B','1','2','3','C',0 };
1234 const wchar_t out6
[] = { 'A','B','1','2','3',0 };
1235 const wchar_t out2
[] = { 'A',0 };
1236 const wchar_t out1
[] = { 0 };
1237 wchar_t buffer
[14] = { 0 };
1240 if (!p__vsnwprintf_s
)
1242 win_skip("_vsnwprintf_s not available\n");
1249 got
= _vsnwprintf_s_wrapper(buffer
, 14, _TRUNCATE
, format
, 123);
1250 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1251 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1253 got
= _vsnwprintf_s_wrapper(buffer
, 12, _TRUNCATE
, format
, 123);
1254 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1255 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1257 got
= _vsnwprintf_s_wrapper(buffer
, 7, _TRUNCATE
, format
, 123);
1258 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1259 ok( !wcscmp(out7
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1261 /* Not enough room. */
1264 got
= _vsnwprintf_s_wrapper(buffer
, 6, _TRUNCATE
, format
, 123);
1265 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1266 ok( !wcscmp(out6
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1268 got
= _vsnwprintf_s_wrapper(buffer
, 2, _TRUNCATE
, format
, 123);
1269 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1270 ok( !wcscmp(out2
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1272 got
= _vsnwprintf_s_wrapper(buffer
, 1, _TRUNCATE
, format
, 123);
1273 ok( exp
== got
, "length wrong, expect=%d, got=%d\n", exp
, got
);
1274 ok( !wcscmp(out1
, buffer
), "buffer wrong, got=%s\n", wine_dbgstr_w(buffer
));
1277 static int __cdecl
_vsprintf_p_wrapper(char *str
, size_t sizeOfBuffer
,
1278 const char *format
, ...)
1281 __ms_va_list valist
;
1282 __ms_va_start(valist
, format
);
1283 ret
= p__vsprintf_p(str
, sizeOfBuffer
, format
, valist
);
1284 __ms_va_end(valist
);
1288 static void test_vsprintf_p(void)
1293 if(!p__vsprintf_p
) {
1294 win_skip("vsprintf_p not available\n");
1298 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%s %d", "test", 1234);
1299 ok(ret
== 9, "ret = %d\n", ret
);
1300 ok(!memcmp(buf
, "test 1234", 10), "buf = %s\n", buf
);
1302 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%1$d", 1234, "additional param");
1303 ok(ret
== 4, "ret = %d\n", ret
);
1304 ok(!memcmp(buf
, "1234", 5), "buf = %s\n", buf
);
1306 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%2$s %1$d", 1234, "test");
1307 ok(ret
== 9, "ret = %d\n", ret
);
1308 ok(!memcmp(buf
, "test 1234", 10), "buf = %s\n", buf
);
1310 ret
= _vsprintf_p_wrapper(buf
, sizeof(buf
), "%2$*3$s %2$.*1$s", 2, "test", 3);
1311 ok(ret
== 7, "ret = %d\n", ret
);
1312 ok(!memcmp(buf
, "test te", 8), "buf = %s\n", buf
);
1314 /* Following test invokes invalid parameter handler */
1315 /* ret = _vsprintf_p_wrapper(buf, sizeof(buf), "%d %1$d", 1234); */
1318 static void test__get_output_format(void)
1324 if (!p__get_output_format
|| !p__set_output_format
)
1326 win_skip("_get_output_format or _set_output_format is not available\n");
1330 ret
= p__get_output_format();
1331 ok(ret
== 0, "got %d\n", ret
);
1333 c
= sprintf(buf
, "%E", 1.23);
1334 ok(c
== 13, "c = %d\n", c
);
1335 ok(!strcmp(buf
, "1.230000E+000"), "buf = %s\n", buf
);
1337 ret
= p__set_output_format(_TWO_DIGIT_EXPONENT
);
1338 ok(ret
== 0, "got %d\n", ret
);
1340 c
= sprintf(buf
, "%E", 1.23);
1341 ok(c
== 12, "c = %d\n", c
);
1342 ok(!strcmp(buf
, "1.230000E+00"), "buf = %s\n", buf
);
1344 ret
= p__get_output_format();
1345 ok(ret
== _TWO_DIGIT_EXPONENT
, "got %d\n", ret
);
1347 ret
= p__set_output_format(_TWO_DIGIT_EXPONENT
);
1348 ok(ret
== _TWO_DIGIT_EXPONENT
, "got %d\n", ret
);
1365 test_vsnwprintf_s();
1367 test__get_output_format();