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
34 #include "wine/test.h"
36 static void test_sprintf( void )
40 double pnumber
=789456123;
42 WCHAR wide
[] = { 'w','i','d','e',0};
45 r
= sprintf(buffer
,format
,pnumber
);
46 ok(!strcmp(buffer
,"+7.894561230000000e+008"),"+#23.15e failed: '%s'\n", buffer
);
47 ok( r
==23, "return count wrong\n");
50 r
= sprintf(buffer
,format
,pnumber
);
51 ok(!strcmp(buffer
,"7.894561230000000e+008 "),"-#23.15e failed: '%s'\n", buffer
);
52 ok( r
==23, "return count wrong\n");
55 r
= sprintf(buffer
,format
,pnumber
);
56 ok(!strcmp(buffer
," 7.894561230000000e+008"),"#23.15e failed: '%s'\n", buffer
);
57 ok( r
==23, "return count wrong\n");
60 r
= sprintf(buffer
,format
,pnumber
);
61 ok(!strcmp(buffer
,"8.e+008"),"#1.1g failed: '%s'\n", buffer
);
62 ok( r
==7, "return count wrong\n");
65 r
= sprintf(buffer
,format
,((ULONGLONG
)0xffffffff)*0xffffffff);
66 ok(!strcmp(buffer
,"-8589934591"),"Problem with long long\n");
67 ok( r
==11, "return count wrong\n");
70 r
= sprintf(buffer
,format
,(LONGLONG
)100);
71 ok(!strcmp(buffer
," +100") && r
==8,"+8I64d failed: '%s'\n", buffer
);
74 r
= sprintf(buffer
,format
,(LONGLONG
)100);
75 ok(!strcmp(buffer
,"+00000100") && r
==9,"+.8I64d failed: '%s'\n", buffer
);
77 format
= "%+10.8I64d";
78 r
= sprintf(buffer
,format
,(LONGLONG
)100);
79 ok(!strcmp(buffer
," +00000100") && r
==10,"+10.8I64d failed: '%s'\n", buffer
);
81 r
= sprintf(buffer
,format
,(LONGLONG
)100);
82 ok(!strcmp(buffer
,"_1I64d") && r
==6,"_1I64d failed\n");
85 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
86 ok(!strcmp(buffer
,"-00100") && r
==6,"-1.5I64d failed: '%s'\n", buffer
);
89 r
= sprintf(buffer
,format
,(LONGLONG
)100);
90 ok(!strcmp(buffer
," 100") && r
==5,"5I64d failed: '%s'\n", buffer
);
93 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
94 ok(!strcmp(buffer
," -100") && r
==5,"5I64d failed: '%s'\n", buffer
);
97 r
= sprintf(buffer
,format
,(LONGLONG
)100);
98 ok(!strcmp(buffer
,"100 ") && r
==5,"-5I64d failed: '%s'\n", buffer
);
101 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
102 ok(!strcmp(buffer
,"-100 ") && r
==5,"-5I64d failed: '%s'\n", buffer
);
105 r
= sprintf(buffer
,format
,(LONGLONG
)100);
106 ok(!strcmp(buffer
,"00100") && r
==5,"-.5I64d failed: '%s'\n", buffer
);
109 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
110 ok(!strcmp(buffer
,"-00100") && r
==6,"-.5I64d failed: '%s'\n", buffer
);
112 format
= "%-8.5I64d";
113 r
= sprintf(buffer
,format
,(LONGLONG
)100);
114 ok(!strcmp(buffer
,"00100 ") && r
==8,"-8.5I64d failed: '%s'\n", buffer
);
116 format
= "%-8.5I64d";
117 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
118 ok(!strcmp(buffer
,"-00100 ") && r
==8,"-8.5I64d failed: '%s'\n", buffer
);
121 r
= sprintf(buffer
,format
,(LONGLONG
)100);
122 ok(!strcmp(buffer
,"00100") && r
==5,"05I64d failed: '%s'\n", buffer
);
125 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
126 ok(!strcmp(buffer
,"-0100") && r
==5,"05I64d failed: '%s'\n", buffer
);
129 r
= sprintf(buffer
,format
,(LONGLONG
)100);
130 ok(!strcmp(buffer
," 100") && r
==4,"' I64d' failed: '%s'\n", buffer
);
133 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
134 ok(!strcmp(buffer
,"-100") && r
==4,"' I64d' 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
," 00100") && r
==6,"' .5I64d' failed: '%s'\n", buffer
);
149 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
150 ok(!strcmp(buffer
,"-00100") && r
==6,"' .5I64d' failed: '%s'\n", buffer
);
152 format
= "% 8.5I64d";
153 r
= sprintf(buffer
,format
,(LONGLONG
)100);
154 ok(!strcmp(buffer
," 00100") && r
==8,"' 8.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
);
161 r
= sprintf(buffer
,format
,(LONGLONG
)0);
162 ok(r
==0,".0I64d failed: '%s'\n", buffer
);
164 format
= "%#+21.18I64x";
165 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
166 ok(!strcmp(buffer
," 0x00ffffffffffffff9c") && r
==21,"#+21.18I64x failed: '%s'\n", buffer
);
168 format
= "%#.25I64o";
169 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
170 ok(!strcmp(buffer
,"0001777777777777777777634") && r
==25,"#.25I64o failed: '%s'\n", buffer
);
172 format
= "%#+24.20I64o";
173 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
174 ok(!strcmp(buffer
," 01777777777777777777634") && r
==24,"#+24.20I64o failed: '%s'\n", buffer
);
176 format
= "%#+18.21I64X";
177 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
178 ok(!strcmp(buffer
,"0X00000FFFFFFFFFFFFFF9C") && r
==23,"#+18.21I64X failed: '%s '\n", buffer
);
180 format
= "%#+20.24I64o";
181 r
= sprintf(buffer
,format
,(LONGLONG
)-100);
182 ok(!strcmp(buffer
,"001777777777777777777634") && r
==24,"#+20.24I64o failed: '%s'\n", buffer
);
184 format
= "%#+25.22I64u";
185 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
186 ok(!strcmp(buffer
," 0018446744073709551615") && r
==25,"#+25.22I64u conversion failed: '%s'\n", buffer
);
188 format
= "%#+25.22I64u";
189 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
190 ok(!strcmp(buffer
," 0018446744073709551615") && r
==25,"#+25.22I64u failed: '%s'\n", buffer
);
192 format
= "%#+30.25I64u";
193 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
194 ok(!strcmp(buffer
," 0000018446744073709551615") && r
==30,"#+30.25I64u failed: '%s'\n", buffer
);
196 format
= "%+#25.22I64d";
197 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
198 ok(!strcmp(buffer
," -0000000000000000000001") && r
==25,"+#25.22I64d failed: '%s'\n", buffer
);
200 format
= "%#-8.5I64o";
201 r
= sprintf(buffer
,format
,(LONGLONG
)100);
202 ok(!strcmp(buffer
,"00144 ") && r
==8,"-8.5I64o failed: '%s'\n", buffer
);
204 format
= "%#-+ 08.5I64d";
205 r
= sprintf(buffer
,format
,(LONGLONG
)100);
206 ok(!strcmp(buffer
,"+00100 ") && r
==8,"'#-+ 08.5I64d failed: '%s'\n", buffer
);
208 format
= "%#-+ 08.5I64d";
209 r
= sprintf(buffer
,format
,(LONGLONG
)100);
210 ok(!strcmp(buffer
,"+00100 ") && r
==8,"#-+ 08.5I64d failed: '%s'\n", buffer
);
213 r
= sprintf(buffer
,format
,(LONGLONG
)1);
214 ok(r
==80,"%s format failed\n", format
);
216 format
= "% .80I64d";
217 r
= sprintf(buffer
,format
,(LONGLONG
)1);
218 ok(r
==81,"%s format failed\n", format
);
221 r
= sprintf(buffer
,format
,1);
222 ok(r
==81,"%s format failed\n", format
);
225 r
= sprintf(buffer
,format
,((ULONGLONG
)0xffffffff)*0xffffffff);
226 ok( r
== 1 || r
== 11, "return count wrong %d\n", r
);
227 if (r
== 11) /* %ll works on Vista */
228 ok(!strcmp(buffer
, "-8589934591"), "Problem with \"ll\" interpretation '%s'\n", buffer
);
230 ok(!strcmp(buffer
, "1"), "Problem with \"ll\" interpretation '%s'\n", buffer
);
233 r
= sprintf(buffer
,format
,1);
234 ok(!strcmp(buffer
, "I"), "Problem with \"I\" interpretation\n");
235 ok( r
==1, "return count wrong\n");
238 r
= sprintf(buffer
,format
,1);
239 ok(!strcmp(buffer
,"I0d"),"I0d failed\n");
240 ok( r
==3, "return count wrong\n");
243 r
= sprintf(buffer
,format
,1);
246 ok(!strcmp(buffer
,"1"),"I32d failed, got '%s'\n",buffer
);
250 /* Older versions don't grok I32 format */
251 ok(r
== 4 && !strcmp(buffer
,"I32d"),"I32d failed, got '%s',%d\n",buffer
,r
);
255 r
= sprintf(buffer
,format
,(LONGLONG
)-1);
256 ok(!strcmp(buffer
,"D"),"I64D failed: %s\n",buffer
);
257 ok( r
==1, "return count wrong\n");
260 r
= sprintf(buffer
,format
,1);
261 ok(!strcmp(buffer
, " 1"),"Problem with sign place-holder: '%s'\n",buffer
);
262 ok( r
==2, "return count wrong\n");
265 r
= sprintf(buffer
,format
,1);
266 ok(!strcmp(buffer
, "+1"),"Problem with sign flags: '%s'\n",buffer
);
267 ok( r
==2, "return count wrong\n");
270 r
= sprintf(buffer
,format
,wide
);
271 ok(!strcmp(buffer
,"wide"),"Problem with wide string format\n");
272 ok( r
==4, "return count wrong\n");
275 r
= sprintf(buffer
,format
,'1');
276 ok(!strcmp(buffer
,"0001"),"Character not zero-prefixed \"%s\"\n",buffer
);
277 ok( r
==4, "return count wrong\n");
280 r
= sprintf(buffer
,format
,'1');
281 ok(!strcmp(buffer
,"1 "),"Character zero-padded and/or not left-adjusted \"%s\"\n",buffer
);
282 ok( r
==4, "return count wrong\n");
284 if (sizeof(void *) == 8)
287 r
= sprintf(buffer
,format
,(void *)57);
288 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
289 ok( r
==16, "return count wrong\n");
292 r
= sprintf(buffer
,format
,(void *)57);
293 ok(!strcmp(buffer
," 0X0000000000000039"),"Pointer formatted incorrectly\n");
294 ok( r
==20, "return count wrong\n");
297 r
= sprintf(buffer
,format
,(void *)57);
298 ok(!strcmp(buffer
,"0000000000000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
299 ok( r
==16, "return count wrong\n");
302 r
= sprintf(buffer
,format
,(void *)57);
303 ok(!strcmp(buffer
,"0X0000000000000039 "),"Pointer formatted incorrectly\n");
304 ok( r
==20, "return count wrong\n");
309 r
= sprintf(buffer
,format
,(void *)57);
310 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
311 ok( r
==8, "return count wrong\n");
314 r
= sprintf(buffer
,format
,(void *)57);
315 ok(!strcmp(buffer
," 0X00000039"),"Pointer formatted incorrectly\n");
316 ok( r
==12, "return count wrong\n");
319 r
= sprintf(buffer
,format
,(void *)57);
320 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
321 ok( r
==8, "return count wrong\n");
324 r
= sprintf(buffer
,format
,(void *)57);
325 ok(!strcmp(buffer
,"0X00000039 "),"Pointer formatted incorrectly\n");
326 ok( r
==12, "return count wrong\n");
330 r
= sprintf(buffer
,format
,"foo");
331 ok(!strcmp(buffer
,"0foo"),"String not zero-prefixed \"%s\"\n",buffer
);
332 ok( r
==4, "return count wrong\n");
335 r
= sprintf(buffer
,format
,"foo");
336 ok(!strcmp(buffer
,"f"),"Precision ignored \"%s\"\n",buffer
);
337 ok( r
==1, "return count wrong\n");
340 r
= sprintf(buffer
,format
,1,"foo");
341 ok(!strcmp(buffer
,"f"),"Precision ignored \"%s\"\n",buffer
);
342 ok( r
==1, "return count wrong\n");
345 r
= sprintf(buffer
,format
,-5,"foo");
346 ok(!strcmp(buffer
,"foo "),"Negative field width ignored \"%s\"\n",buffer
);
347 ok( r
==5, "return count wrong\n");
350 r
= sprintf(buffer
, format
);
351 ok(!strcmp(buffer
,"hello"), "failed\n");
352 ok( r
==5, "return count wrong\n");
355 r
= sprintf(buffer
, format
, wide
);
356 ok(!strcmp(buffer
,"wide"), "failed\n");
357 ok( r
==4, "return count wrong\n");
360 r
= sprintf(buffer
, format
, wide
);
361 ok(!strcmp(buffer
,"wide "), "failed\n");
362 ok( r
==10, "return count wrong\n");
365 r
= sprintf(buffer
, format
, wide
);
366 ok(!strcmp(buffer
," wide"), "failed\n");
367 ok( r
==10, "return count wrong\n");
369 format
= "%#+ -03whlls";
370 r
= sprintf(buffer
, format
, wide
);
371 ok(!strcmp(buffer
,"wide"), "failed\n");
372 ok( r
==4, "return count wrong\n");
375 r
= sprintf(buffer
, format
, wide
);
376 ok(!strcmp(buffer
,"0s"), "failed\n");
377 ok( r
==2, "return count wrong\n");
380 r
= sprintf(buffer
, format
, wide
);
381 ok(!strcmp(buffer
,"-s"), "failed\n");
382 ok( r
==2, "return count wrong\n");
385 r
= sprintf(buffer
, format
, wide
);
386 ok(!strcmp(buffer
,"wide"), "failed\n");
387 ok( r
==4, "return count wrong\n");
390 r
= sprintf(buffer
, format
, "not wide" );
391 ok(!strcmp(buffer
,"not wide"), "failed\n");
392 ok( r
==8, "return count wrong\n");
395 r
= sprintf(buffer
, format
);
396 ok(!strcmp(buffer
,"b"), "failed\n");
397 ok( r
==1, "return count wrong\n");
400 r
= sprintf(buffer
, format
,'a');
401 ok(!strcmp(buffer
," a"), "failed\n");
402 ok( r
==3, "return count wrong\n");
405 r
= sprintf(buffer
, format
,1234);
406 ok(!strcmp(buffer
,"1234"), "failed\n");
407 ok( r
==4, "return count wrong\n");
410 r
= sprintf(buffer
, format
);
411 ok(!strcmp(buffer
,""), "failed\n");
412 ok( r
==0, "return count wrong\n");
414 format
= "%j%k%m%q%r%t%v%y%z";
415 r
= sprintf(buffer
, format
);
416 ok(!strcmp(buffer
,"jkmqrtvyz"), "failed\n");
417 ok( r
==9, "return count wrong\n");
421 r
= sprintf(buffer
, format
, &x
);
424 /* %n format is disabled by default on vista */
425 /* FIXME: should test with _set_printf_count_output */
426 ok(x
== 0, "should not write to x: %d\n", x
);
430 ok(x
== 4, "should write to x: %d\n", x
);
431 ok(!strcmp(buffer
,"asdf"), "failed\n");
432 ok( r
==4, "return count wrong: %d\n", r
);
436 r
= sprintf(buffer
, format
,2);
437 ok(!strcmp(buffer
,"2"), "failed\n");
438 ok( r
==1, "return count wrong\n");
441 r
= sprintf(buffer
, format
,8.6);
442 ok(!strcmp(buffer
,"8.6000"), "failed\n");
443 ok( r
==6, "return count wrong\n");
446 r
= sprintf(buffer
, format
,0.6);
447 ok(!strcmp(buffer
,"0.600000"), "failed\n");
448 ok( r
==8, "return count wrong\n");
451 r
= sprintf(buffer
, format
,0.6);
452 ok(!strcmp(buffer
,"1"), "failed\n");
453 ok( r
==1, "return count wrong\n");
456 r
= sprintf(buffer
, format
,8.6);
457 ok(!strcmp(buffer
,"8.6000e+000"), "failed\n");
458 ok( r
==11, "return count wrong\n");
461 r
= sprintf(buffer
, format
,8.6);
462 ok(!strcmp(buffer
,"8.6"), "failed\n");
463 ok( r
==3, "return count wrong\n");
466 r
= sprintf(buffer
, format
,-1);
467 ok(!strcmp(buffer
,"-1"), "failed\n");
468 ok( r
==2, "return count wrong\n");
471 r
= sprintf(buffer
, format
,1);
472 ok(!strcmp(buffer
,"1"), "failed\n");
473 ok( r
==1, "return count wrong\n");
476 r
= sprintf(buffer
, format
,1);
477 ok(!strcmp(buffer
,"+1"), "failed\n");
478 ok( r
==2, "return count wrong\n");
481 r
= sprintf(buffer
, format
,10);
482 ok(!strcmp(buffer
,"12"), "failed\n");
483 ok( r
==2, "return count wrong\n");
486 r
= sprintf(buffer
, format
,0);
487 if (sizeof(void *) == 8)
489 ok(!strcmp(buffer
,"0000000000000000"), "failed\n");
490 ok( r
==16, "return count wrong\n");
494 ok(!strcmp(buffer
,"00000000"), "failed\n");
495 ok( r
==8, "return count wrong\n");
499 r
= sprintf(buffer
, format
,0);
500 ok(!strcmp(buffer
,"(null)"), "failed\n");
501 ok( r
==6, "return count wrong\n");
504 r
= sprintf(buffer
, format
,"%%%%");
505 ok(!strcmp(buffer
,"%%%%"), "failed\n");
506 ok( r
==4, "return count wrong\n");
509 r
= sprintf(buffer
, format
,-1);
510 ok(!strcmp(buffer
,"4294967295"), "failed\n");
511 ok( r
==10, "return count wrong\n");
514 r
= sprintf(buffer
, format
,-1);
515 ok(!strcmp(buffer
,""), "failed\n");
516 ok( r
==0, "return count wrong\n");
519 r
= sprintf(buffer
, format
,-1);
520 ok(!strcmp(buffer
,""), "failed\n");
521 ok( r
==0, "return count wrong\n");
524 r
= sprintf(buffer
, format
,-1);
525 ok(!strcmp(buffer
,"z"), "failed\n");
526 ok( r
==1, "return count wrong\n");
529 r
= sprintf(buffer
, format
,-1);
530 ok(!strcmp(buffer
,"j"), "failed\n");
531 ok( r
==1, "return count wrong\n");
534 r
= sprintf(buffer
, format
,-1);
535 ok(!strcmp(buffer
,""), "failed\n");
536 ok( r
==0, "return count wrong\n");
539 r
= sprintf(buffer
, format
,-1);
540 ok(!strcmp(buffer
,"H"), "failed\n");
541 ok( r
==1, "return count wrong\n");
544 r
= sprintf(buffer
, format
, 0x100+'X');
545 ok(!strcmp(buffer
,"xXx"), "failed\n");
546 ok( r
==3, "return count wrong\n");
549 r
= sprintf(buffer
, format
);
550 ok(!strcmp(buffer
,"%0"), "failed: \"%s\"\n", buffer
);
551 ok( r
==2, "return count wrong\n");
554 static void test_swprintf( void )
557 const wchar_t I64d
[] = {'%','I','6','4','d',0};
558 double pnumber
=789456123;
559 const wchar_t TwentyThreePoint15e
[]= {'%','+','#','2','3','.','1','5','e',0};
560 const wchar_t e008
[] = {'e','+','0','0','8',0};
561 const wchar_t string_w
[] = {'s','t','r','i','n','g',0};
562 const char string
[] = "string";
563 const wchar_t S
[]={'%','S',0};
564 const wchar_t hs
[] = {'%', 'h', 's', 0};
566 swprintf(buffer
,TwentyThreePoint15e
,pnumber
);
567 ok(wcsstr(buffer
,e008
) != 0,"Sprintf different\n");
568 swprintf(buffer
,I64d
,((ULONGLONG
)0xffffffff)*0xffffffff);
569 ok(wcslen(buffer
) == 11,"Problem with long long\n");
570 swprintf(buffer
,S
,string
);
571 ok(wcslen(buffer
) == 6,"Problem with \"%%S\" interpretation\n");
572 swprintf(buffer
, hs
, string
);
573 ok( wcscmp(string_w
,buffer
) == 0, "swprintf failed with %%hs\n");
576 static void test_snprintf (void)
578 struct snprintf_test
{
582 /* Pre-2.1 libc behaviour, not C99 compliant. */
583 const struct snprintf_test tests
[] = {{"short", 5},
588 const int bufsiz
= sizeof buffer
;
591 for (i
= 0; i
< sizeof tests
/ sizeof tests
[0]; i
++) {
592 const char *fmt
= tests
[i
].format
;
593 const int expect
= tests
[i
].expected
;
594 const int n
= _snprintf (buffer
, bufsiz
, fmt
);
595 const int valid
= n
< 0 ? bufsiz
: (n
== bufsiz
? n
: n
+1);
597 ok (n
== expect
, "\"%s\": expected %d, returned %d\n",
599 ok (!memcmp (fmt
, buffer
, valid
),
600 "\"%s\": rendered \"%.*s\"\n", fmt
, valid
, buffer
);
604 static void test_fcvt(void)
607 int dec
=100, sign
=100;
609 /* Numbers less than 1.0 with different precisions */
610 str
= _fcvt(0.0001, 1, &dec
, &sign
);
611 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
612 ok( -3 == dec
, "dec wrong %d\n", dec
);
613 ok( 0 == sign
, "sign wrong\n");
615 str
= _fcvt(0.0001, -10, &dec
, &sign
);
616 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
617 ok( -3 == dec
, "dec wrong %d\n", dec
);
618 ok( 0 == sign
, "sign wrong\n");
620 str
= _fcvt(0.0001, 10, &dec
, &sign
);
621 ok( 0 == strcmp(str
,"1000000"), "bad return '%s'\n", str
);
622 ok( -3 == dec
, "dec wrong %d\n", dec
);
623 ok( 0 == sign
, "sign wrong\n");
625 /* Basic sign test */
626 str
= _fcvt(-111.0001, 5, &dec
, &sign
);
627 ok( 0 == strcmp(str
,"11100010"), "bad return '%s'\n", str
);
628 ok( 3 == dec
, "dec wrong %d\n", dec
);
629 ok( 1 == sign
, "sign wrong\n");
631 str
= _fcvt(111.0001, 5, &dec
, &sign
);
632 ok( 0 == strcmp(str
,"11100010"), "bad return '%s'\n", str
);
633 ok( 3 == dec
, "dec wrong\n");
634 ok( 0 == sign
, "sign wrong\n");
636 /* 0.0 with different precisions */
637 str
= _fcvt(0.0, 5, &dec
, &sign
);
638 ok( 0 == strcmp(str
,"00000"), "bad return '%s'\n", str
);
639 ok( 0 == dec
, "dec wrong %d\n", dec
);
640 ok( 0 == sign
, "sign wrong\n");
642 str
= _fcvt(0.0, 0, &dec
, &sign
);
643 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
644 ok( 0 == dec
, "dec wrong %d\n", dec
);
645 ok( 0 == sign
, "sign wrong\n");
647 str
= _fcvt(0.0, -1, &dec
, &sign
);
648 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
649 ok( 0 == dec
, "dec wrong %d\n", dec
);
650 ok( 0 == sign
, "sign wrong\n");
652 /* Numbers > 1.0 with 0 or -ve precision */
653 str
= _fcvt(-123.0001, 0, &dec
, &sign
);
654 ok( 0 == strcmp(str
,"123"), "bad return '%s'\n", str
);
655 ok( 3 == dec
, "dec wrong %d\n", dec
);
656 ok( 1 == sign
, "sign wrong\n");
658 str
= _fcvt(-123.0001, -1, &dec
, &sign
);
659 ok( 0 == strcmp(str
,"12"), "bad return '%s'\n", str
);
660 ok( 3 == dec
, "dec wrong %d\n", dec
);
661 ok( 1 == sign
, "sign wrong\n");
663 str
= _fcvt(-123.0001, -2, &dec
, &sign
);
664 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
665 ok( 3 == dec
, "dec wrong %d\n", dec
);
666 ok( 1 == sign
, "sign wrong\n");
668 str
= _fcvt(-123.0001, -3, &dec
, &sign
);
669 ok( 0 == strcmp(str
,""), "bad return '%s'\n", str
);
670 ok( 3 == dec
, "dec wrong %d\n", dec
);
671 ok( 1 == sign
, "sign wrong\n");
673 /* Numbers > 1.0, but with rounding at the point of precision */
674 str
= _fcvt(99.99, 1, &dec
, &sign
);
675 ok( 0 == strcmp(str
,"1000"), "bad return '%s'\n", str
);
676 ok( 3 == dec
, "dec wrong %d\n", dec
);
677 ok( 0 == sign
, "sign wrong\n");
679 /* Numbers < 1.0 where rounding occurs at the point of precision */
680 str
= _fcvt(0.00636, 2, &dec
, &sign
);
681 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
682 ok( -1 == dec
, "dec wrong %d\n", dec
);
683 ok( 0 == sign
, "sign wrong\n");
685 str
= _fcvt(0.00636, 3, &dec
, &sign
);
686 ok( 0 == strcmp(str
,"6"), "bad return '%s'\n", str
);
687 ok( -2 == dec
, "dec wrong %d\n", dec
);
688 ok( 0 == sign
, "sign wrong\n");
690 str
= _fcvt(0.09999999996, 2, &dec
, &sign
);
691 ok( 0 == strcmp(str
,"10"), "bad return '%s'\n", str
);
692 ok( 0 == dec
, "dec wrong %d\n", dec
);
693 ok( 0 == sign
, "sign wrong\n");
695 str
= _fcvt(0.6, 0, &dec
, &sign
);
696 ok( 0 == strcmp(str
,"1"), "bad return '%s'\n", str
);
697 ok( 1 == dec
, "dec wrong %d\n", dec
);
698 ok( 0 == sign
, "sign wrong\n");
701 static int _vsnwprintf_wrapper(wchar_t *str
, size_t len
, const wchar_t *format
, ...)
705 __ms_va_start(valist
, format
);
706 ret
= _vsnwprintf(str
, len
, format
, valist
);
711 static void test_vsnwprintf(void)
713 const wchar_t format
[] = {'%','w','s','%','w','s','%','w','s',0};
714 const wchar_t one
[] = {'o','n','e',0};
715 const wchar_t two
[] = {'t','w','o',0};
716 const wchar_t three
[] = {'t','h','r','e','e',0};
722 ret
= _vsnwprintf_wrapper( str
, sizeof(str
)/sizeof(str
[0]), format
, one
, two
, three
);
724 ok( ret
== 11, "got %d expected 11\n", ret
);
725 WideCharToMultiByte( CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
726 ok( !strcmp(buf
, "onetwothree"), "got %s expected 'onetwothree'\n", buf
);