Make CryptImport/ExportPublicKeyInfoEx behave the way MSDN describes
[wine/gsoc-2012-control.git] / dlls / msvcrt / tests / printf.c
blob9c3fdea8acfab2a532ee7792c876130b50a41aa3
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <stdio.h>
25 #include "wine/test.h"
27 static void test_sprintf( void )
29 char buffer[100];
30 const char *format;
31 double pnumber=789456123;
32 int x, r;
33 WCHAR wide[] = { 'w','i','d','e',0};
35 format = "%+#23.15e";
36 r = sprintf(buffer,format,pnumber);
37 todo_wine {
38 ok(!strcmp(buffer,"+7.894561230000000e+008"),"exponent format incorrect\n");
40 ok( r==23, "return count wrong\n");
42 todo_wine {
43 format = "%I64d";
44 r = sprintf(buffer,format,((ULONGLONG)0xffffffff)*0xffffffff);
45 ok(!strcmp(buffer,"-8589934591"),"Problem with long long\n");
46 ok( r==11, "return count wrong\n");
49 format = "%lld";
50 r = sprintf(buffer,format,((ULONGLONG)0xffffffff)*0xffffffff);
51 ok(!strcmp(buffer, "1"), "Problem with \"ll\" interpretation\n");
52 ok( r==1, "return count wrong\n");
54 format = "%S";
55 r = sprintf(buffer,format,wide);
56 ok(!strcmp(buffer,"wide"),"Problem with wide string format\n");
57 ok( r==4, "return count wrong\n");
59 format = "%04c";
60 r = sprintf(buffer,format,'1');
61 ok(!strcmp(buffer,"0001"),"Character not zero-prefixed \"%s\"\n",buffer);
62 ok( r==4, "return count wrong\n");
64 format = "%p";
65 r = sprintf(buffer,format,(void *)57);
66 ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
67 ok( r==8, "return count wrong\n");
69 format = "%#012p";
70 r = sprintf(buffer,format,(void *)57);
71 ok(!strcmp(buffer," 0X00000039"),"Pointer formatted incorrectly\n");
72 ok( r==12, "return count wrong\n");
74 format = "%Fp";
75 r = sprintf(buffer,format,(void *)57);
76 ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
77 ok( r==8, "return count wrong\n");
79 format = "%04s";
80 r = sprintf(buffer,format,"foo");
81 ok(!strcmp(buffer,"0foo"),"String not zero-prefixed \"%s\"\n",buffer);
82 ok( r==4, "return count wrong\n");
84 format = "%.1s";
85 r = sprintf(buffer,format,"foo");
86 ok(!strcmp(buffer,"f"),"Precision ignored \"%s\"\n",buffer);
87 ok( r==1, "return count wrong\n");
89 format = "%.*s";
90 r = sprintf(buffer,format,1,"foo");
91 ok(!strcmp(buffer,"f"),"Precision ignored \"%s\"\n",buffer);
92 ok( r==1, "return count wrong\n");
94 format = "%#-012p";
95 r = sprintf(buffer,format,(void *)57);
96 ok(!strcmp(buffer,"0X00000039 "),"Pointer formatted incorrectly\n");
97 ok( r==12, "return count wrong\n");
99 format = "hello";
100 r = sprintf(buffer, format);
101 ok(!strcmp(buffer,"hello"), "failed\n");
102 ok( r==5, "return count wrong\n");
104 format = "%ws";
105 r = sprintf(buffer, format, wide);
106 ok(!strcmp(buffer,"wide"), "failed\n");
107 ok( r==4, "return count wrong\n");
109 format = "%-10ws";
110 r = sprintf(buffer, format, wide );
111 ok(!strcmp(buffer,"wide "), "failed\n");
112 ok( r==10, "return count wrong\n");
114 format = "%10ws";
115 r = sprintf(buffer, format, wide );
116 ok(!strcmp(buffer," wide"), "failed\n");
117 ok( r==10, "return count wrong\n");
119 format = "%#+ -03whlls";
120 r = sprintf(buffer, format, wide );
121 ok(!strcmp(buffer,"wide"), "failed\n");
122 ok( r==4, "return count wrong\n");
124 format = "%w0s";
125 r = sprintf(buffer, format, wide );
126 ok(!strcmp(buffer,"0s"), "failed\n");
127 ok( r==2, "return count wrong\n");
129 format = "%w-s";
130 r = sprintf(buffer, format, wide );
131 ok(!strcmp(buffer,"-s"), "failed\n");
132 ok( r==2, "return count wrong\n");
134 format = "%ls";
135 r = sprintf(buffer, format, wide );
136 ok(!strcmp(buffer,"wide"), "failed\n");
137 ok( r==4, "return count wrong\n");
139 format = "%Ls";
140 r = sprintf(buffer, format, "not wide" );
141 ok(!strcmp(buffer,"not wide"), "failed\n");
142 ok( r==8, "return count wrong\n");
144 format = "%b";
145 r = sprintf(buffer, format);
146 ok(!strcmp(buffer,"b"), "failed\n");
147 ok( r==1, "return count wrong\n");
149 format = "%3c";
150 r = sprintf(buffer, format,'a');
151 ok(!strcmp(buffer," a"), "failed\n");
152 ok( r==3, "return count wrong\n");
154 format = "%3d";
155 r = sprintf(buffer, format,1234);
156 ok(!strcmp(buffer,"1234"), "failed\n");
157 ok( r==4, "return count wrong\n");
159 format = "%3h";
160 r = sprintf(buffer, format);
161 ok(!strcmp(buffer,""), "failed\n");
162 ok( r==0, "return count wrong\n");
164 format = "%j%k%m%q%r%t%v%y%z";
165 r = sprintf(buffer, format);
166 ok(!strcmp(buffer,"jkmqrtvyz"), "failed\n");
167 ok( r==9, "return count wrong\n");
169 format = "asdf%n";
170 x = 0;
171 r = sprintf(buffer, format, &x );
172 ok(x == 4, "should write to x\n");
173 ok(!strcmp(buffer,"asdf"), "failed\n");
174 ok( r==4, "return count wrong\n");
176 format = "%-1d";
177 r = sprintf(buffer, format,2);
178 ok(!strcmp(buffer,"2"), "failed\n");
179 ok( r==1, "return count wrong\n");
181 format = "%2.4f";
182 r = sprintf(buffer, format,8.6);
183 ok(!strcmp(buffer,"8.6000"), "failed\n");
184 ok( r==6, "return count wrong\n");
186 todo_wine {
187 format = "%2.4e";
188 r = sprintf(buffer, format,8.6);
189 ok(!strcmp(buffer,"8.6000e+000"), "failed\n");
190 ok( r==11, "return count wrong\n");
193 format = "%2.4g";
194 r = sprintf(buffer, format,8.6);
195 ok(!strcmp(buffer,"8.6"), "failed\n");
196 ok( r==3, "return count wrong\n");
198 format = "%-i";
199 r = sprintf(buffer, format,-1);
200 ok(!strcmp(buffer,"-1"), "failed\n");
201 ok( r==2, "return count wrong\n");
203 format = "%-i";
204 r = sprintf(buffer, format,1);
205 ok(!strcmp(buffer,"1"), "failed\n");
206 ok( r==1, "return count wrong\n");
208 format = "%+i";
209 r = sprintf(buffer, format,1);
210 ok(!strcmp(buffer,"+1"), "failed\n");
211 ok( r==2, "return count wrong\n");
213 format = "%o";
214 r = sprintf(buffer, format,10);
215 ok(!strcmp(buffer,"12"), "failed\n");
216 ok( r==2, "return count wrong\n");
218 format = "%p";
219 r = sprintf(buffer, format,0);
220 ok(!strcmp(buffer,"00000000"), "failed\n");
221 ok( r==8, "return count wrong\n");
223 format = "%s";
224 r = sprintf(buffer, format,0);
225 ok(!strcmp(buffer,"(null)"), "failed\n");
226 ok( r==6, "return count wrong\n");
228 format = "%s";
229 r = sprintf(buffer, format,"%%%%");
230 ok(!strcmp(buffer,"%%%%"), "failed\n");
231 ok( r==4, "return count wrong\n");
233 format = "%u";
234 r = sprintf(buffer, format,-1);
235 ok(!strcmp(buffer,"4294967295"), "failed\n");
236 ok( r==10, "return count wrong\n");
238 format = "%w";
239 r = sprintf(buffer, format,-1);
240 ok(!strcmp(buffer,""), "failed\n");
241 ok( r==0, "return count wrong\n");
243 format = "%h";
244 r = sprintf(buffer, format,-1);
245 ok(!strcmp(buffer,""), "failed\n");
246 ok( r==0, "return count wrong\n");
248 format = "%z";
249 r = sprintf(buffer, format,-1);
250 ok(!strcmp(buffer,"z"), "failed\n");
251 ok( r==1, "return count wrong\n");
253 format = "%j";
254 r = sprintf(buffer, format,-1);
255 ok(!strcmp(buffer,"j"), "failed\n");
256 ok( r==1, "return count wrong\n");
258 format = "%F";
259 r = sprintf(buffer, format,-1);
260 ok(!strcmp(buffer,""), "failed\n");
261 ok( r==0, "return count wrong\n");
263 format = "%H";
264 r = sprintf(buffer, format,-1);
265 ok(!strcmp(buffer,"H"), "failed\n");
266 ok( r==1, "return count wrong\n");
268 format = "x%cx";
269 r = sprintf(buffer, format, 0x100+'X');
270 ok(!strcmp(buffer,"xXx"), "failed\n");
271 ok( r==3, "return count wrong\n");
273 format = "%%0";
274 r = sprintf(buffer, format);
275 ok(!strcmp(buffer,"%0"), "failed: \"%s\"\n", buffer);
276 ok( r==2, "return count wrong\n");
279 static void test_swprintf( void )
281 wchar_t buffer[100];
282 const wchar_t I64d[] = {'%','I','6','4','d',0};
283 double pnumber=789456123;
284 const wchar_t TwentyThreePoint15e[]= {'%','+','#','2','3','.','1','5','e',0};
285 const wchar_t e008[] = {'e','+','0','0','8',0};
286 const char string[]={'s','t','r','i','n','g',0};
287 const wchar_t S[]={'%','S',0};
288 swprintf(buffer,TwentyThreePoint15e,pnumber);
289 todo_wine
291 ok(wcsstr(buffer,e008) != 0,"Sprintf different\n");
293 swprintf(buffer,I64d,((ULONGLONG)0xffffffff)*0xffffffff);
294 todo_wine
296 ok(wcslen(buffer) == 11,"Problem with long long\n");
298 swprintf(buffer,S,string);
299 ok(wcslen(buffer) == 6,"Problem with \"%%S\" interpretation\n");
302 static void test_fwprintf( void )
304 const char *string="not a wide string";
305 todo_wine
307 ok(fwprintf(fopen("nul","r+"),(wchar_t *)string) == -1,"Non-wide string should not be printed by fwprintf\n");
311 static void test_snprintf (void)
313 struct snprintf_test {
314 const char *format;
315 int expected;
316 struct {
317 int retval;
318 int render;
319 } todo;
321 /* Pre-2.1 libc behaviour, not C99 compliant. */
322 const struct snprintf_test tests[] = {{"short", 5, {0, 0}},
323 {"justfit", 7, {0, 0}},
324 {"justfits", 8, {0, 1}},
325 {"muchlonger", -1, {1, 1}}};
326 char buffer[8];
327 const int bufsiz = sizeof buffer;
328 unsigned int i;
330 for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
331 const char *fmt = tests[i].format;
332 const int expect = tests[i].expected;
333 const int n = _snprintf (buffer, bufsiz, fmt);
334 const int valid = n < 0 ? bufsiz : (n == bufsiz ? n : n+1);
336 todo (tests[i].todo.retval ? "wine" : "none")
337 ok (n == expect, "\"%s\": expected %d, returned %d\n",
338 fmt, expect, n);
339 todo (tests[i].todo.render ? "wine" : "none")
340 ok (!memcmp (fmt, buffer, valid),
341 "\"%s\": rendered \"%.*s\"\n", fmt, valid, buffer);
345 START_TEST(printf)
347 test_sprintf();
348 test_swprintf();
349 test_fwprintf();
350 test_snprintf();