2 * Conformance tests for *printf functions.
4 * Copyright 2002 Uwe Bonnes
5 * Copyright 2004 Aneurin Price
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/test.h"
26 static void test_sprintf( void )
29 const char *I64d
= "%I64d";
30 const char *O4c
= "%04c";
31 const char *O4s
= "%04s";
32 const char *hash012p
= "%#012p";
33 double pnumber
=789456123;
34 /** WCHAR widestring[]={'w','i','d','e','s','t','r','i','n','g',0};**/
35 sprintf(buffer
,"%+#23.15e",pnumber
);
38 ok(strstr(buffer
,"e+008") != 0,"Sprintf different \"%s\"\n",buffer
);
40 sprintf(buffer
,I64d
,((ULONGLONG
)0xffffffff)*0xffffffff);
43 ok(strlen(buffer
) == 11,"Problem with long long \"%s\"\n",buffer
);
45 sprintf(buffer
,"%lld",((ULONGLONG
)0xffffffff)*0xffffffff);
48 ok(strlen(buffer
) == 1,"Problem with \"ll\" interpretation \"%s\"\n",buffer
);
50 /** This one actually crashes WINE at the moment, when using builtin msvcrt.dll.
51 sprintf(buffer,"%S",widestring);
54 ok(strlen(buffer) == 10,"Problem with \"%%S\" interpretation \"%s\"\n",buffer);
57 sprintf(buffer
,O4c
,'1');
60 ok(!strcmp(buffer
,"0001"),"Character not zero-prefixed \"%s\"\n",buffer
);
62 sprintf(buffer
,"%p",(void *)57);
65 ok(!strcmp(buffer
,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
67 sprintf(buffer
,hash012p
,(void *)57);
70 ok(!strcmp(buffer
," 0X00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer
);
72 sprintf(buffer
,O4s
,"foo");/**Warning again**/
75 ok(!strcmp(buffer
,"0foo"),"String not zero-prefixed \"%s\"\n",buffer
);
79 static void test_swprintf( void )
82 const wchar_t I64d
[] = {'%','I','6','4','d',0};
83 double pnumber
=789456123;
84 const wchar_t TwentyThreePoint15e
[]= {'%','+','#','2','3','.','1','5','e',0};
85 const wchar_t e008
[] = {'e','+','0','0','8',0};
86 const char string
[]={'s','t','r','i','n','g',0};
87 const wchar_t S
[]={'%','S',0};
88 swprintf(buffer
,TwentyThreePoint15e
,pnumber
);
91 ok(wcsstr(buffer
,e008
) != 0,"Sprintf different\n");
93 swprintf(buffer
,I64d
,((ULONGLONG
)0xffffffff)*0xffffffff);
96 ok(wcslen(buffer
) == 11,"Problem with long long\n");
98 swprintf(buffer
,S
,string
);
99 ok(wcslen(buffer
) == 6,"Problem with \"%%S\" interpretation\n");
102 static void test_fwprintf( void )
104 const char *string
="not a wide string";
107 ok(fwprintf(fopen("nul","r+"),(wchar_t *)string
) == -1,"Non-wide string should not be printed by fwprintf\n");
111 static void test_snprintf (void)
113 struct snprintf_test
{
121 /* Pre-2.1 libc behaviour, not C99 compliant. */
122 const struct snprintf_test tests
[] = {{"short", 5, {0, 0}},
123 {"justfit", 7, {0, 0}},
124 {"justfits", 8, {0, 1}},
125 {"muchlonger", -1, {1, 1}}};
127 const int bufsiz
= sizeof buffer
;
130 for (i
= 0; i
< sizeof tests
/ sizeof tests
[0]; i
++) {
131 const char *fmt
= tests
[i
].format
;
132 const int expect
= tests
[i
].expected
;
133 const int n
= _snprintf (buffer
, bufsiz
, fmt
);
134 const int valid
= n
< 0 ? bufsiz
: (n
== bufsiz
? n
: n
+1);
136 todo (tests
[i
].todo
.retval
? "wine" : "none")
137 ok (n
== expect
, "\"%s\": expected %d, returned %d\n",
139 todo (tests
[i
].todo
.render
? "wine" : "none")
140 ok (!memcmp (fmt
, buffer
, valid
),
141 "\"%s\": rendered \"%.*s\"\n", fmt
, valid
, buffer
);