1 /* Unit test suite for the wsprintf functions
3 * Copyright 2002 Bill Medland
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
35 { "%I64X", ((ULONGLONG
)0x12345 << 32) | 0x67890a, "123450067890A" },
36 { "%I32X", ((ULONGLONG
)0x12345 << 32) | 0x67890a, "67890A" },
37 { "%I64d", (ULONGLONG
)543210 * 1000000, "543210000000" },
38 { "%I64X", (LONGLONG
)-0x12345, "FFFFFFFFFFFEDCBB" },
39 { "%I32x", (LONGLONG
)-0x12345, "fffedcbb" },
40 { "%I64u", (LONGLONG
)-123, "18446744073709551493" },
41 { "%Id", (LONGLONG
)-12345, "-12345" },
43 { "%Ix", ((ULONGLONG
)0x12345 << 32) | 0x67890a, "123450067890a" },
44 { "%Ix", (LONGLONG
)-0x12345, "fffffffffffedcbb" },
45 { "%p", (LONGLONG
)-0x12345, "FFFFFFFFFFFEDCBB" },
47 { "%Ix", ((ULONGLONG
)0x12345 << 32) | 0x67890a, "67890a" },
48 { "%Ix", (LONGLONG
)-0x12345, "fffedcbb" },
49 { "%p", (LONGLONG
)-0x12345, "FFFEDCBB" },
53 static void wsprintfATest(void)
55 char buf
[25], star
[4], partial
[4];
56 static const WCHAR starW
[] = L
"\x2606";
57 static const WCHAR fffeW
[] = L
"\xfffe";
58 static const WCHAR wineW
[] = L
"\xd83c\xdf77"; /* U+1F377: wine glass */
66 { starW
, "%.1S", partial
, 1 },
67 { starW
, "%.2S", star
, 2 },
68 { starW
, "%.3S", star
, 2 },
69 { fffeW
, "%.1S", "?", 1 },
70 { fffeW
, "%.2S", "?", 1 },
71 { wineW
, "%.2S", "??", 2 },
72 { star
, "%.1s", partial
, 1 },
73 { (void *)0x2606, "%2C", star
, 2 },
74 { (void *)0xfffd, "%C", "?", 1 },
75 { (void *)0xe199, "%2c", " \x99", 2 },
81 rc
=wsprintfA(buf
, "%010ld", -1);
82 ok(rc
== 10, "wsprintfA length failure: rc=%d error=%d\n",rc
,GetLastError());
83 ok((lstrcmpA(buf
, "-000000001") == 0),
84 "wsprintfA zero padded negative value failure: buf=[%s]\n",buf
);
85 rc
= wsprintfA(buf
, "%I64X", (ULONGLONG
)0);
86 if (rc
== 4 && !lstrcmpA(buf
, "I64X"))
88 win_skip( "I64 formats not supported\n" );
91 for (i
= 0; i
< ARRAY_SIZE(i64_formats
); i
++)
93 rc
= wsprintfA(buf
, i64_formats
[i
].fmt
, i64_formats
[i
].value
);
94 ok(rc
== strlen(i64_formats
[i
].res
), "%u: wsprintfA length failure: rc=%d\n", i
, rc
);
95 ok(!strcmp(buf
, i64_formats
[i
].res
), "%u: wrong result [%s]\n", i
, buf
);
98 if (!GetCPInfo(CP_ACP
, &cpinfo
) || cpinfo
.MaxCharSize
<= 1)
100 skip("Multi-byte wsprintfA test isn't available for the current codepage\n");
104 rc
= WideCharToMultiByte(CP_ACP
, 0, starW
, -1, star
, sizeof(star
), NULL
, NULL
);
105 ok(rc
== 3, "unexpected rc, got %d\n", rc
);
106 partial
[0] = star
[0];
109 for (i
= 0; i
< ARRAY_SIZE(testcase
); i
++)
111 memset(buf
, 0x11, sizeof(buf
));
112 rc
= wsprintfA(buf
, testcase
[i
].fmt
, testcase
[i
].input
);
114 ok(rc
== testcase
[i
].rc
,
115 "%u: expected %d, got %d\n",
116 i
, testcase
[i
].rc
, rc
);
118 ok(!strcmp(buf
, testcase
[i
].str
),
119 "%u: expected %s, got %s\n",
120 i
, wine_dbgstr_a(testcase
[i
].str
), wine_dbgstr_an(buf
, rc
));
124 static WCHAR
my_btowc(BYTE c
)
127 if (!IsDBCSLeadByte(c
) &&
128 MultiByteToWideChar(CP_ACP
, 0, (const char *)&c
, 1, &wc
, 1) > 0)
133 static void wsprintfWTest(void)
135 static const WCHAR stars
[] = L
"*\x2606\x2605";
136 WCHAR def_spc
[] = L
"*?\x2605 ";
137 WCHAR buf
[25], fmt
[25], res
[25], wcA1
, wc99
;
138 char stars_mb
[8], partial00
[8], partialFF
[8];
146 { stars_mb
, L
"%.3S", stars
, 3 },
147 { partial00
, L
"%-4S", L
"*\0 ", 4 },
148 { partialFF
, L
"%-4S", def_spc
, 4 },
154 rc
=wsprintfW(buf
, L
"%010ld", -1);
155 if (rc
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
157 win_skip("wsprintfW is not implemented\n");
160 ok(rc
== 10, "wsPrintfW length failure: rc=%d error=%d\n",rc
,GetLastError());
161 ok((lstrcmpW(buf
, L
"-000000001") == 0),
162 "wsprintfW zero padded negative value failure\n");
163 rc
= wsprintfW(buf
, L
"%I64x", (ULONGLONG
)0 );
164 if (rc
== 4 && !lstrcmpW(buf
, L
"I64x"))
166 win_skip( "I64 formats not supported\n" );
169 for (i
= 0; i
< ARRAY_SIZE(i64_formats
); i
++)
171 MultiByteToWideChar( CP_ACP
, 0, i64_formats
[i
].fmt
, -1, fmt
, ARRAY_SIZE(fmt
));
172 MultiByteToWideChar( CP_ACP
, 0, i64_formats
[i
].res
, -1, res
, ARRAY_SIZE(res
));
173 rc
= wsprintfW(buf
, fmt
, i64_formats
[i
].value
);
174 ok(rc
== lstrlenW(res
), "%u: wsprintfW length failure: rc=%d\n", i
, rc
);
175 ok(!lstrcmpW(buf
, res
), "%u: wrong result [%s]\n", i
, wine_dbgstr_w(buf
));
178 rc
= wsprintfW(buf
, L
"%2c", L
'*');
179 ok(rc
== 2, "expected 2, got %d\n", rc
);
180 ok(buf
[0] == L
' ', "expected \\x0020, got \\x%04x\n", buf
[0]);
181 ok(buf
[1] == L
'*', "expected \\x%04x, got \\x%04x\n", L
'*', buf
[1]);
183 rc
= wsprintfW(buf
, L
"%c", L
'\x2605');
184 ok(rc
== 1, "expected 1, got %d\n", rc
);
185 ok(buf
[0] == L
'\x2605', "expected \\x%04x, got \\x%04x\n", L
'\x2605', buf
[0]);
187 wcA1
= my_btowc(0xA1);
188 rc
= wsprintfW(buf
, L
"%C", 0xA1);
189 ok(rc
== 1, "expected 1, got %d\n", rc
);
190 ok(buf
[0] == wcA1
, "expected \\x%04x, got \\x%04x\n", wcA1
, buf
[0]);
192 rc
= wsprintfW(buf
, L
"%C", 0x81A1);
193 ok(rc
== 1, "expected 1, got %d\n", rc
);
194 ok(buf
[0] == wcA1
, "expected \\x%04x, got \\x%04x\n", wcA1
, buf
[0]);
196 wc99
= my_btowc(0x99);
197 rc
= wsprintfW(buf
, L
"%2C", 0xe199);
198 ok(rc
== 2, "expected 1, got %d\n", rc
);
199 ok(buf
[0] == L
' ', "expected \\x0020, got \\x%04x\n", buf
[0]);
200 ok(buf
[1] == wc99
, "expected \\x%04x, got \\x%04x\n", wc99
, buf
[1]);
202 if (!GetCPInfoExW(CP_ACP
, 0, &cpinfoex
) || cpinfoex
.MaxCharSize
<= 1)
204 skip("Multi-byte wsprintfW test isn't available for the current codepage\n");
207 def_spc
[1] = cpinfoex
.UnicodeDefaultChar
;
209 rc
= WideCharToMultiByte(CP_ACP
, 0, stars
, -1, stars_mb
, sizeof(stars_mb
), NULL
, NULL
);
210 ok(rc
== 6, "expected 6, got %d\n", rc
);
211 strcpy(partial00
, stars_mb
);
213 strcpy(partialFF
, stars_mb
);
216 for (i
= 0; i
< ARRAY_SIZE(testcase
); i
++)
218 memset(buf
, 0x11, sizeof(buf
));
219 rc
= wsprintfW(buf
, testcase
[i
].fmt
, testcase
[i
].input
);
221 ok(rc
== testcase
[i
].rc
,
222 "%u: expected %d, got %d\n",
223 i
, testcase
[i
].rc
, rc
);
225 ok(!memcmp(buf
, testcase
[i
].str
, (testcase
[i
].rc
+ 1) * sizeof(WCHAR
)),
226 "%u: expected %s, got %s\n", i
,
227 wine_dbgstr_wn(testcase
[i
].str
, testcase
[i
].rc
+ 1),
228 wine_dbgstr_wn(buf
, rc
+ 1));
232 /* Test if the CharUpper / CharLower functions return true 16 bit results,
233 if the input is a 16 bit input value. */
235 static void CharUpperTest(void)
242 out
= (INT_PTR
)CharUpperA((LPSTR
)i
);
243 if ((out
>> 16) != 0)
249 ok(!failed
,"CharUpper failed - 16bit input (0x%0lx) returned 32bit result (0x%0lx)\n",i
,out
);
252 static void CharLowerTest(void)
259 out
= (INT_PTR
)CharLowerA((LPSTR
)i
);
260 if ((out
>> 16) != 0)
266 ok(!failed
,"CharLower failed - 16bit input (0x%0lx) returned 32bit result (0x%0lx)\n",i
,out
);