2 * Unit tests for code page to/from unicode translations
4 * Copyright (c) 2002 Dmitry Timoshkov
5 * Copyright (c) 2008 Colin Finck
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
31 static const WCHAR foobarW
[] = {'f','o','o','b','a','r',0};
33 static void test_destination_buffer(void)
40 SetLastError(0xdeadbeef);
41 needed
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, NULL
, 0, NULL
, NULL
);
42 ok( (needed
> 0), "returned %d with %u (expected '> 0')\n",
43 needed
, GetLastError());
46 buffer
= HeapAlloc(GetProcessHeap(), 0, maxsize
);
47 if (buffer
== NULL
) return;
50 memset(buffer
, 'x', maxsize
);
51 buffer
[maxsize
] = '\0';
52 SetLastError(0xdeadbeef);
53 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, buffer
, needed
+1, NULL
, NULL
);
54 ok( (len
> 0), "returned %d with %u and '%s' (expected '> 0')\n",
55 len
, GetLastError(), buffer
);
57 memset(buffer
, 'x', maxsize
);
58 buffer
[maxsize
] = '\0';
59 SetLastError(0xdeadbeef);
60 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, buffer
, needed
, NULL
, NULL
);
61 ok( (len
> 0), "returned %d with %u and '%s' (expected '> 0')\n",
62 len
, GetLastError(), buffer
);
64 memset(buffer
, 'x', maxsize
);
65 buffer
[maxsize
] = '\0';
66 SetLastError(0xdeadbeef);
67 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, buffer
, needed
-1, NULL
, NULL
);
68 ok( !len
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
69 "returned %d with %u and '%s' (expected '0' with "
70 "ERROR_INSUFFICIENT_BUFFER)\n", len
, GetLastError(), buffer
);
72 memset(buffer
, 'x', maxsize
);
73 buffer
[maxsize
] = '\0';
74 SetLastError(0xdeadbeef);
75 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, buffer
, 1, NULL
, NULL
);
76 ok( !len
&& (GetLastError() == ERROR_INSUFFICIENT_BUFFER
),
77 "returned %d with %u and '%s' (expected '0' with "
78 "ERROR_INSUFFICIENT_BUFFER)\n", len
, GetLastError(), buffer
);
80 SetLastError(0xdeadbeef);
81 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, buffer
, 0, NULL
, NULL
);
82 ok( (len
> 0), "returned %d with %u (expected '> 0')\n",
85 SetLastError(0xdeadbeef);
86 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, NULL
, needed
, NULL
, NULL
);
87 ok( !len
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
88 "returned %d with %u (expected '0' with "
89 "ERROR_INVALID_PARAMETER)\n", len
, GetLastError());
91 HeapFree(GetProcessHeap(), 0, buffer
);
95 static void test_null_source(void)
101 len
= WideCharToMultiByte(CP_ACP
, 0, NULL
, 0, NULL
, 0, NULL
, NULL
);
102 GLE
= GetLastError();
103 ok(!len
&& GLE
== ERROR_INVALID_PARAMETER
,
104 "WideCharToMultiByte returned %d with GLE=%u (expected 0 with ERROR_INVALID_PARAMETER)\n",
108 len
= WideCharToMultiByte(CP_ACP
, 0, NULL
, -1, NULL
, 0, NULL
, NULL
);
109 GLE
= GetLastError();
110 ok(!len
&& GLE
== ERROR_INVALID_PARAMETER
,
111 "WideCharToMultiByte returned %d with GLE=%u (expected 0 with ERROR_INVALID_PARAMETER)\n",
115 static void test_negative_source_length(void)
121 /* Test, whether any negative source length works as strlen() + 1 */
122 SetLastError( 0xdeadbeef );
123 memset(buf
,'x',sizeof(buf
));
124 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -2002, buf
, 10, NULL
, NULL
);
125 ok(len
== 7 && GetLastError() == 0xdeadbeef,
126 "WideCharToMultiByte(-2002): len=%d error=%u\n", len
, GetLastError());
127 ok(!lstrcmpA(buf
, "foobar"),
128 "WideCharToMultiByte(-2002): expected \"foobar\" got \"%s\"\n", buf
);
130 SetLastError( 0xdeadbeef );
131 memset(bufW
,'x',sizeof(bufW
));
132 len
= MultiByteToWideChar(CP_ACP
, 0, "foobar", -2002, bufW
, 10);
133 ok(len
== 7 && !lstrcmpW(bufW
, foobarW
) && GetLastError() == 0xdeadbeef,
134 "MultiByteToWideChar(-2002): len=%d error=%u\n", len
, GetLastError());
136 SetLastError(0xdeadbeef);
137 memset(bufW
, 'x', sizeof(bufW
));
138 len
= MultiByteToWideChar(CP_ACP
, 0, "foobar", -1, bufW
, 6);
139 ok(len
== 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
140 "MultiByteToWideChar(-1): len=%d error=%u\n", len
, GetLastError());
143 #define LONGBUFLEN 100000
144 static void test_negative_dest_length(void)
147 static char buf
[LONGBUFLEN
];
148 static WCHAR originalW
[LONGBUFLEN
];
149 static char originalA
[LONGBUFLEN
];
152 /* Test return on -1 dest length */
153 SetLastError( 0xdeadbeef );
154 memset(buf
,'x',sizeof(buf
));
155 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, buf
, -1, NULL
, NULL
);
157 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
,
158 "WideCharToMultiByte(destlen -1): len=%d error=%x\n", len
, GetLastError());
161 /* Test return on -1000 dest length */
162 SetLastError( 0xdeadbeef );
163 memset(buf
,'x',sizeof(buf
));
164 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, buf
, -1000, NULL
, NULL
);
166 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
,
167 "WideCharToMultiByte(destlen -1000): len=%d error=%x\n", len
, GetLastError());
170 /* Test return on INT_MAX dest length */
171 SetLastError( 0xdeadbeef );
172 memset(buf
,'x',sizeof(buf
));
173 len
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, buf
, INT_MAX
, NULL
, NULL
);
174 ok(len
== 7 && !lstrcmpA(buf
, "foobar") && GetLastError() == 0xdeadbeef,
175 "WideCharToMultiByte(destlen INT_MAX): len=%d error=%x\n", len
, GetLastError());
177 /* Test return on INT_MAX dest length and very long input */
178 SetLastError( 0xdeadbeef );
179 memset(buf
,'x',sizeof(buf
));
180 for (i
=0; i
< LONGBUFLEN
- 1; i
++) {
184 originalW
[LONGBUFLEN
-1] = 0;
185 originalA
[LONGBUFLEN
-1] = 0;
186 len
= WideCharToMultiByte(CP_ACP
, 0, originalW
, -1, buf
, INT_MAX
, NULL
, NULL
);
187 theError
= GetLastError();
188 ok(len
== LONGBUFLEN
&& !lstrcmpA(buf
, originalA
) && theError
== 0xdeadbeef,
189 "WideCharToMultiByte(srclen %d, destlen INT_MAX): len %d error=%x\n", LONGBUFLEN
, len
, theError
);
193 static void test_other_invalid_parameters(void)
195 char c_string
[] = "Hello World";
196 size_t c_string_len
= sizeof(c_string
);
197 WCHAR w_string
[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
198 size_t w_string_len
= sizeof(w_string
) / sizeof(WCHAR
);
202 /* srclen=0 => ERROR_INVALID_PARAMETER */
203 SetLastError(0xdeadbeef);
204 len
= WideCharToMultiByte(CP_ACP
, 0, w_string
, 0, c_string
, c_string_len
, NULL
, NULL
);
205 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
207 SetLastError(0xdeadbeef);
208 len
= MultiByteToWideChar(CP_ACP
, 0, c_string
, 0, w_string
, w_string_len
);
209 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
212 /* dst=NULL but dstlen not 0 => ERROR_INVALID_PARAMETER */
213 SetLastError(0xdeadbeef);
214 len
= WideCharToMultiByte(CP_ACP
, 0, w_string
, w_string_len
, NULL
, c_string_len
, NULL
, NULL
);
215 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
217 SetLastError(0xdeadbeef);
218 len
= MultiByteToWideChar(CP_ACP
, 0, c_string
, c_string_len
, NULL
, w_string_len
);
219 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
222 /* CP_UTF7, CP_UTF8, or CP_SYMBOL and defchar not NULL => ERROR_INVALID_PARAMETER */
223 /* CP_SYMBOL's behavior here is undocumented */
224 SetLastError(0xdeadbeef);
225 len
= WideCharToMultiByte(CP_UTF7
, 0, w_string
, w_string_len
, c_string
, c_string_len
, c_string
, NULL
);
226 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
228 SetLastError(0xdeadbeef);
229 len
= WideCharToMultiByte(CP_UTF8
, 0, w_string
, w_string_len
, c_string
, c_string_len
, c_string
, NULL
);
230 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
232 SetLastError(0xdeadbeef);
233 len
= WideCharToMultiByte(CP_SYMBOL
, 0, w_string
, w_string_len
, c_string
, c_string_len
, c_string
, NULL
);
234 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
237 /* CP_UTF7, CP_UTF8, or CP_SYMBOL and used not NULL => ERROR_INVALID_PARAMETER */
238 /* CP_SYMBOL's behavior here is undocumented */
239 SetLastError(0xdeadbeef);
240 len
= WideCharToMultiByte(CP_UTF7
, 0, w_string
, w_string_len
, c_string
, c_string_len
, NULL
, &used
);
241 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
243 SetLastError(0xdeadbeef);
244 len
= WideCharToMultiByte(CP_UTF8
, 0, w_string
, w_string_len
, c_string
, c_string_len
, NULL
, &used
);
245 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
247 SetLastError(0xdeadbeef);
248 len
= WideCharToMultiByte(CP_SYMBOL
, 0, w_string
, w_string_len
, c_string
, c_string_len
, NULL
, &used
);
249 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
252 /* CP_UTF7, flags not 0 and used not NULL => ERROR_INVALID_PARAMETER */
253 /* (tests precedence of ERROR_INVALID_PARAMETER over ERROR_INVALID_FLAGS) */
254 /* The same test with CP_SYMBOL instead of CP_UTF7 gives ERROR_INVALID_FLAGS
255 instead except on Windows NT4 */
256 SetLastError(0xdeadbeef);
257 len
= WideCharToMultiByte(CP_UTF7
, 1, w_string
, w_string_len
, c_string
, c_string_len
, NULL
, &used
);
258 ok(len
== 0 && GetLastError() == ERROR_INVALID_PARAMETER
, "len=%d error=%x\n", len
, GetLastError());
261 static void test_overlapped_buffers(void)
263 static const WCHAR strW
[] = {'j','u','s','t',' ','a',' ','t','e','s','t',0};
264 static const char strA
[] = "just a test";
268 SetLastError(0xdeadbeef);
269 memcpy(buf
+ 1, strW
, sizeof(strW
));
270 ret
= WideCharToMultiByte(CP_ACP
, 0, (WCHAR
*)(buf
+ 1), -1, buf
, sizeof(buf
), NULL
, NULL
);
271 ok(ret
== sizeof(strA
), "unexpected ret %d\n", ret
);
272 ok(!memcmp(buf
, strA
, sizeof(strA
)), "conversion failed: %s\n", buf
);
273 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
276 static void test_string_conversion(LPBOOL bUsedDefaultChar
)
281 WCHAR wc1
= 228; /* Western Windows-1252 character */
282 WCHAR wc2
= 1088; /* Russian Windows-1251 character not displayable for Windows-1252 */
283 static const WCHAR wcs
[] = {'T', 'h', 1088, 'i', 0}; /* String with ASCII characters and a Russian character */
284 static const WCHAR dbwcs
[] = {28953, 25152, 0}; /* String with Chinese (codepage 950) characters */
285 static const WCHAR dbwcs2
[] = {0x7bb8, 0x3d, 0xc813, 0xac00, 0xb77d, 0};
286 static const char default_char
[] = {0xa3, 0xbf, 0};
288 SetLastError(0xdeadbeef);
289 ret
= WideCharToMultiByte(1252, 0, &wc1
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
290 ok(ret
== 1, "ret is %d\n", ret
);
291 ok(mbc
== '\xe4', "mbc is %d\n", mbc
);
292 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
293 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
295 SetLastError(0xdeadbeef);
296 ret
= WideCharToMultiByte(1252, 0, &wc2
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
297 ok(ret
== 1, "ret is %d\n", ret
);
298 ok(mbc
== 63, "mbc is %d\n", mbc
);
299 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
300 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
302 if (IsValidCodePage(1251))
304 SetLastError(0xdeadbeef);
305 ret
= WideCharToMultiByte(1251, 0, &wc2
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
306 ok(ret
== 1, "ret is %d\n", ret
);
307 ok(mbc
== '\xf0', "mbc is %d\n", mbc
);
308 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
309 ok(GetLastError() == 0xdeadbeef ||
310 broken(GetLastError() == 0), /* win95 */
311 "GetLastError() is %u\n", GetLastError());
313 SetLastError(0xdeadbeef);
314 ret
= WideCharToMultiByte(1251, 0, &wc1
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
315 ok(ret
== 1, "ret is %d\n", ret
);
316 ok(mbc
== 97, "mbc is %d\n", mbc
);
317 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
318 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
321 skip("Codepage 1251 not available\n");
323 /* This call triggers the last Win32 error */
324 SetLastError(0xdeadbeef);
325 ret
= WideCharToMultiByte(1252, 0, wcs
, -1, &mbc
, 1, NULL
, bUsedDefaultChar
);
326 ok(ret
== 0, "ret is %d\n", ret
);
327 ok(mbc
== 84, "mbc is %d\n", mbc
);
328 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
329 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "GetLastError() is %u\n", GetLastError());
331 SetLastError(0xdeadbeef);
332 ret
= WideCharToMultiByte(1252, 0, wcs
, -1, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
333 ok(ret
== 5, "ret is %d\n", ret
);
334 ok(!strcmp(mbs
, "Th?i"), "mbs is %s\n", mbs
);
335 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
336 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
339 /* WideCharToMultiByte mustn't add any null character automatically.
340 So in this case, we should get the same string again, even if we only copied the first three bytes. */
341 SetLastError(0xdeadbeef);
342 ret
= WideCharToMultiByte(1252, 0, wcs
, 3, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
343 ok(ret
== 3, "ret is %d\n", ret
);
344 ok(!strcmp(mbs
, "Th?i"), "mbs is %s\n", mbs
);
345 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
346 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
349 /* Now this shouldn't be the case like above as we zeroed the complete string buffer. */
350 SetLastError(0xdeadbeef);
351 ret
= WideCharToMultiByte(1252, 0, wcs
, 3, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
352 ok(ret
== 3, "ret is %d\n", ret
);
353 ok(!strcmp(mbs
, "Th?"), "mbs is %s\n", mbs
);
354 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
355 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
357 /* Double-byte tests */
358 ret
= WideCharToMultiByte(1252, 0, dbwcs
, 3, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
359 ok(ret
== 3, "ret is %d\n", ret
);
360 ok(!strcmp(mbs
, "??"), "mbs is %s\n", mbs
);
361 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
363 ret
= WideCharToMultiByte(936, WC_COMPOSITECHECK
, dbwcs2
, -1, mbs
, sizeof(mbs
), (const char *)default_char
, bUsedDefaultChar
);
364 ok(ret
== 10, "ret is %d\n", ret
);
365 ok(!strcmp(mbs
, "\xf3\xe7\x3d\xa3\xbf\xa3\xbf\xa3\xbf"), "mbs is %s\n", mbs
);
366 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
368 /* Length-only tests */
369 SetLastError(0xdeadbeef);
370 ret
= WideCharToMultiByte(1252, 0, &wc2
, 1, NULL
, 0, NULL
, bUsedDefaultChar
);
371 ok(ret
== 1, "ret is %d\n", ret
);
372 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
373 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
375 SetLastError(0xdeadbeef);
376 ret
= WideCharToMultiByte(1252, 0, wcs
, -1, NULL
, 0, NULL
, bUsedDefaultChar
);
377 ok(ret
== 5, "ret is %d\n", ret
);
378 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
379 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
381 if (!IsValidCodePage(950))
383 skip("Codepage 950 not available\n");
387 /* Double-byte tests */
388 SetLastError(0xdeadbeef);
389 ret
= WideCharToMultiByte(950, 0, dbwcs
, -1, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
390 ok(ret
== 5, "ret is %d\n", ret
);
391 ok(!strcmp(mbs
, "\xb5H\xa9\xd2"), "mbs is %s\n", mbs
);
392 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
393 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
395 SetLastError(0xdeadbeef);
396 ret
= WideCharToMultiByte(950, 0, dbwcs
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
397 ok(ret
== 0, "ret is %d\n", ret
);
398 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
399 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "GetLastError() is %u\n", GetLastError());
402 SetLastError(0xdeadbeef);
403 ret
= WideCharToMultiByte(950, 0, dbwcs
, 1, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
404 ok(ret
== 2, "ret is %d\n", ret
);
405 ok(!strcmp(mbs
, "\xb5H"), "mbs is %s\n", mbs
);
406 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
407 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
409 /* Length-only tests */
410 SetLastError(0xdeadbeef);
411 ret
= WideCharToMultiByte(950, 0, dbwcs
, 1, NULL
, 0, NULL
, bUsedDefaultChar
);
412 ok(ret
== 2, "ret is %d\n", ret
);
413 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
414 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
416 SetLastError(0xdeadbeef);
417 ret
= WideCharToMultiByte(950, 0, dbwcs
, -1, NULL
, 0, NULL
, bUsedDefaultChar
);
418 ok(ret
== 5, "ret is %d\n", ret
);
419 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
420 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
423 static void test_utf7_encoding(void)
426 char output
[16], expected
[16];
427 int i
, len
, expected_len
;
429 static const BOOL directly_encodable_table
[] =
431 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, /* 0x00 - 0x0F */
432 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1F */
433 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* 0x20 - 0x2F */
434 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x30 - 0x3F */
435 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4F */
436 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x50 - 0x5F */
437 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6F */
438 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70 - 0x7F */
440 static const char base64_encoding_table
[] =
441 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
450 /* expected outputs */
451 char expected_dst
[16];
457 /* tests string conversion with srclen=-1 */
459 {0x4F60,0x597D,0x5417,0}, -1, output
, sizeof(output
) - 1,
462 /* tests string conversion with srclen=-2 */
464 {0x4F60,0x597D,0x5417,0}, -2, output
, sizeof(output
) - 1,
467 /* tests string conversion with dstlen=strlen(expected_dst) */
469 {0x4F60,0x597D,0x5417,0}, -1, output
, 10,
472 /* tests string conversion with dstlen=strlen(expected_dst)+1 */
474 {0x4F60,0x597D,0x5417,0}, -1, output
, 11,
477 /* tests string conversion with dstlen=strlen(expected_dst)+2 */
479 {0x4F60,0x597D,0x5417,0}, -1, output
, 12,
482 /* tests dry run with dst=NULL and dstlen=0 */
484 {0x4F60,0x597D,0x5417,0}, -1, NULL
, 0,
487 /* tests dry run with dst!=NULL and dstlen=0 */
489 {0x4F60,0x597D,0x5417,0}, -1, output
, 0,
492 /* tests srclen < strlenW(src) with directly encodable chars */
494 {'h','e','l','l','o',0}, 2, output
, sizeof(output
) - 1,
497 /* tests srclen < strlenW(src) with non-directly encodable chars */
499 {0x4F60,0x597D,0x5417,0}, 2, output
, sizeof(output
) - 1,
502 /* tests a single null char */
504 {0}, -1, output
, sizeof(output
) - 1,
507 /* tests a buffer that runs out while not encoding a UTF-7 sequence */
509 {'h','e','l','l','o',0}, -1, output
, 2,
512 /* tests a buffer that runs out after writing 1 base64 character */
514 {0x4F60,0x0001,0}, -1, output
, 2,
517 /* tests a buffer that runs out after writing 2 base64 characters */
519 {0x4F60,0x0001,0}, -1, output
, 3,
522 /* tests a buffer that runs out after writing 3 base64 characters */
524 {0x4F60,0x0001,0}, -1, output
, 4,
527 /* tests a buffer that runs out just after writing the + sign */
529 {0x4F60,0}, -1, output
, 1,
532 /* tests a buffer that runs out just before writing the - sign
533 * the number of bits to encode here is evenly divisible by 6 */
535 {0x4F60,0x597D,0x5417,0}, -1, output
, 9,
538 /* tests a buffer that runs out just before writing the - sign
539 * the number of bits to encode here is NOT evenly divisible by 6 */
541 {0x4F60,0}, -1, output
, 4,
544 /* tests a buffer that runs out in the middle of escaping a + sign */
546 {'+',0}, -1, output
, 1,
551 /* test which characters are encoded if surrounded by non-encoded characters */
552 for (i
= 0; i
<= 0xFFFF; i
++)
559 memset(output
, '#', sizeof(output
) - 1);
560 output
[sizeof(output
) - 1] = 0;
562 len
= WideCharToMultiByte(CP_UTF7
, 0, input
, 4, output
, sizeof(output
) - 1, NULL
, NULL
);
566 /* '+' is a special case and is encoded as "+-" */
568 strcpy(expected
, " +- ");
570 else if (i
<= 0x7F && directly_encodable_table
[i
])
572 /* encodes directly */
574 sprintf(expected
, " %c ", i
);
580 sprintf(expected
, " +%c%c%c- ",
581 base64_encoding_table
[(i
& 0xFC00) >> 10],
582 base64_encoding_table
[(i
& 0x03F0) >> 4],
583 base64_encoding_table
[(i
& 0x000F) << 2]);
586 ok(len
== expected_len
, "i=0x%04x: expected len=%i, got len=%i\n", i
, expected_len
, len
);
587 ok(memcmp(output
, expected
, expected_len
) == 0,
588 "i=0x%04x: expected output='%s', got output='%s'\n", i
, expected
, output
);
589 ok(output
[expected_len
] == '#', "i=0x%04x: expected output[%i]='#', got output[%i]=%i\n",
590 i
, expected_len
, expected_len
, output
[expected_len
]);
593 /* test which one-byte characters are absorbed into surrounding base64 blocks
594 * (Windows always ends the base64 block when it encounters a directly encodable character) */
595 for (i
= 0; i
<= 0xFFFF; i
++)
602 memset(output
, '#', sizeof(output
) - 1);
603 output
[sizeof(output
) - 1] = 0;
605 len
= WideCharToMultiByte(CP_UTF7
, 0, input
, 4, output
, sizeof(output
) - 1, NULL
, NULL
);
609 /* '+' is a special case and is encoded as "+-" */
611 strcpy(expected
, "+JnI-+-+JnI-");
613 else if (i
<= 0x7F && directly_encodable_table
[i
])
615 /* encodes directly */
617 sprintf(expected
, "+JnI-%c+JnI-", i
);
623 sprintf(expected
, "+Jn%c%c%c%cZy-",
624 base64_encoding_table
[8 | ((i
& 0xC000) >> 14)],
625 base64_encoding_table
[(i
& 0x3F00) >> 8],
626 base64_encoding_table
[(i
& 0x00FC) >> 2],
627 base64_encoding_table
[((i
& 0x0003) << 4) | 2]);
630 ok(len
== expected_len
, "i=0x%04x: expected len=%i, got len=%i\n", i
, expected_len
, len
);
631 ok(memcmp(output
, expected
, expected_len
) == 0,
632 "i=0x%04x: expected output='%s', got output='%s'\n", i
, expected
, output
);
633 ok(output
[expected_len
] == '#', "i=0x%04x: expected output[%i]='#', got output[%i]=%i\n",
634 i
, expected_len
, expected_len
, output
[expected_len
]);
637 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
639 memset(output
, '#', sizeof(output
) - 1);
640 output
[sizeof(output
) - 1] = 0;
641 SetLastError(0xdeadbeef);
643 len
= WideCharToMultiByte(CP_UTF7
, 0, tests
[i
].src
, tests
[i
].srclen
,
644 tests
[i
].dst
, tests
[i
].dstlen
, NULL
, NULL
);
648 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
649 "tests[%i]: expected error=0x%x, got error=0x%x\n",
650 i
, ERROR_INSUFFICIENT_BUFFER
, GetLastError());
652 ok(len
== tests
[i
].len
, "tests[%i]: expected len=%i, got len=%i\n", i
, tests
[i
].len
, len
);
656 ok(memcmp(tests
[i
].dst
, tests
[i
].expected_dst
, tests
[i
].chars_written
) == 0,
657 "tests[%i]: expected dst='%s', got dst='%s'\n",
658 i
, tests
[i
].expected_dst
, tests
[i
].dst
);
659 ok(tests
[i
].dst
[tests
[i
].chars_written
] == '#',
660 "tests[%i]: expected dst[%i]='#', got dst[%i]=%i\n",
661 i
, tests
[i
].chars_written
, tests
[i
].chars_written
, tests
[i
].dst
[tests
[i
].chars_written
]);
666 static void test_utf7_decoding(void)
669 WCHAR output
[32], expected
[32];
670 int i
, len
, expected_len
;
672 static const signed char base64_decoding_table
[] =
674 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0F */
675 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1F */
676 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /* 0x20-0x2F */
677 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 0x30-0x3F */
678 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40-0x4F */
679 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, /* 0x50-0x5F */
680 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60-0x6F */
681 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 0x70-0x7F */
691 /* expected outputs */
692 WCHAR expected_dst
[32];
698 /* tests string conversion with srclen=-1 */
700 "+T2BZfQ-", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
701 {0x4F60,0x597D,0}, 3, 3
703 /* tests string conversion with srclen=-2 */
705 "+T2BZfQ-", -2, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
706 {0x4F60,0x597D,0}, 3, 3
708 /* tests string conversion with dstlen=strlen(expected_dst) */
710 "+T2BZfQ-", -1, output
, 2,
711 {0x4F60,0x597D}, 2, 0
713 /* tests string conversion with dstlen=strlen(expected_dst)+1 */
715 "+T2BZfQ-", -1, output
, 3,
716 {0x4F60,0x597D,0}, 3, 3
718 /* tests string conversion with dstlen=strlen(expected_dst)+2 */
720 "+T2BZfQ-", -1, output
, 4,
721 {0x4F60,0x597D,0}, 3, 3
723 /* tests dry run with dst=NULL and dstlen=0 */
725 "+T2BZfQ-", -1, NULL
, 0,
728 /* tests dry run with dst!=NULL and dstlen=0 */
730 "+T2BZfQ-", -1, output
, 0,
733 /* tests ill-formed UTF-7: 6 bits, not enough for a byte pair */
735 "+T-+T-+T-hello", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
736 {'h','e','l','l','o',0}, 6, 6
738 /* tests ill-formed UTF-7: 12 bits, not enough for a byte pair */
740 "+T2-+T2-+T2-hello", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
741 {'h','e','l','l','o',0}, 6, 6
743 /* tests ill-formed UTF-7: 18 bits, not a multiple of 16 and the last bit is a 1 */
745 "+T2B-+T2B-+T2B-hello", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
746 {0x4F60,0x4F60,0x4F60,'h','e','l','l','o',0}, 9, 9
748 /* tests ill-formed UTF-7: 24 bits, a multiple of 8 but not a multiple of 16 */
750 "+T2BZ-+T2BZ-+T2BZ-hello", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
751 {0x4F60,0x4F60,0x4F60,'h','e','l','l','o',0}, 9, 9
753 /* tests UTF-7 followed by characters that should be encoded but aren't */
755 "+T2BZ-\x82\xFE", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
756 {0x4F60,0x0082,0x00FE,0}, 4, 4
758 /* tests srclen > strlen(src) */
760 "a\0b", 4, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
763 /* tests srclen < strlen(src) outside of a UTF-7 sequence */
765 "hello", 2, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
768 /* tests srclen < strlen(src) inside of a UTF-7 sequence */
770 "+T2BZfQ-", 4, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
773 /* tests srclen < strlen(src) right at the beginning of a UTF-7 sequence */
775 "hi+T2A-", 3, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
778 /* tests srclen < strlen(src) right at the end of a UTF-7 sequence */
780 "+T2A-hi", 5, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
783 /* tests srclen < strlen(src) at the beginning of an escaped + sign */
785 "hi+-", 3, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
788 /* tests srclen < strlen(src) at the end of an escaped + sign */
790 "+-hi", 2, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
793 /* tests len=0 but no error */
795 "+", 1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
798 /* tests a single null char */
800 "", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
803 /* tests a buffer that runs out while not decoding a UTF-7 sequence */
805 "hello", -1, output
, 2,
808 /* tests a buffer that runs out in the middle of decoding a UTF-7 sequence */
810 "+T2BZfQ-", -1, output
, 1,
815 /* test which one-byte characters remove stray + signs */
816 for (i
= 0; i
< 256; i
++)
818 sprintf(input
, "+%c+AAA", i
);
820 memset(output
, 0x23, sizeof(output
) - sizeof(WCHAR
));
821 output
[sizeof(output
) / sizeof(WCHAR
) - 1] = 0;
823 len
= MultiByteToWideChar(CP_UTF7
, 0, input
, 7, output
, sizeof(output
) / sizeof(WCHAR
) - 1);
827 /* removes the - sign */
829 expected
[0] = 0x002B;
833 else if (i
<= 0x7F && base64_decoding_table
[i
] != -1)
835 /* absorbs the character into the base64 sequence */
837 expected
[0] = (base64_decoding_table
[i
] << 10) | 0x03E0;
842 /* removes the + sign */
848 expected
[expected_len
] = 0x2323;
850 ok(len
== expected_len
, "i=0x%02x: expected len=%i, got len=%i\n", i
, expected_len
, len
);
851 ok(memcmp(output
, expected
, (expected_len
+ 1) * sizeof(WCHAR
)) == 0,
852 "i=0x%02x: expected output=%s, got output=%s\n",
853 i
, wine_dbgstr_wn(expected
, expected_len
+ 1), wine_dbgstr_wn(output
, expected_len
+ 1));
856 /* test which one-byte characters terminate a sequence
857 * also test whether the unfinished byte pair is discarded or not */
858 for (i
= 0; i
< 256; i
++)
860 sprintf(input
, "+B%c+AAA", i
);
862 memset(output
, 0x23, sizeof(output
) - sizeof(WCHAR
));
863 output
[sizeof(output
) / sizeof(WCHAR
) - 1] = 0;
865 len
= MultiByteToWideChar(CP_UTF7
, 0, input
, 8, output
, sizeof(output
) / sizeof(WCHAR
) - 1);
869 /* explicitly terminates */
876 if (base64_decoding_table
[i
] != -1)
878 /* absorbs the character into the base64 sequence */
880 expected
[0] = 0x0400 | (base64_decoding_table
[i
] << 4) | 0x000F;
881 expected
[1] = 0x8000;
886 /* implicitly terminates and discards the unfinished byte pair */
895 /* implicitly terminates but does not the discard unfinished byte pair */
898 expected
[1] = 0x0400;
901 expected
[expected_len
] = 0x2323;
903 ok(len
== expected_len
, "i=0x%02x: expected len=%i, got len=%i\n", i
, expected_len
, len
);
904 ok(memcmp(output
, expected
, (expected_len
+ 1) * sizeof(WCHAR
)) == 0,
905 "i=0x%02x: expected output=%s, got output=%s\n",
906 i
, wine_dbgstr_wn(expected
, expected_len
+ 1), wine_dbgstr_wn(output
, expected_len
+ 1));
909 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
911 memset(output
, 0x23, sizeof(output
) - sizeof(WCHAR
));
912 output
[sizeof(output
) / sizeof(WCHAR
) - 1] = 0;
913 SetLastError(0xdeadbeef);
915 len
= MultiByteToWideChar(CP_UTF7
, 0, tests
[i
].src
, tests
[i
].srclen
,
916 tests
[i
].dst
, tests
[i
].dstlen
);
918 tests
[i
].expected_dst
[tests
[i
].chars_written
] = 0x2323;
920 if (!tests
[i
].len
&& tests
[i
].chars_written
)
922 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
923 "tests[%i]: expected error=0x%x, got error=0x%x\n",
924 i
, ERROR_INSUFFICIENT_BUFFER
, GetLastError());
926 ok(len
== tests
[i
].len
, "tests[%i]: expected len=%i, got len=%i\n", i
, tests
[i
].len
, len
);
930 ok(memcmp(tests
[i
].dst
, tests
[i
].expected_dst
, (tests
[i
].chars_written
+ 1) * sizeof(WCHAR
)) == 0,
931 "tests[%i]: expected dst=%s, got dst=%s\n",
932 i
, wine_dbgstr_wn(tests
[i
].expected_dst
, tests
[i
].chars_written
+ 1),
933 wine_dbgstr_wn(tests
[i
].dst
, tests
[i
].chars_written
+ 1));
938 static void test_undefined_byte_char(void)
940 static const struct tag_testset
{
945 { 874, "\xdd", TRUE
},
946 { 932, "\xfe", TRUE
},
947 { 932, "\x80", FALSE
},
948 { 936, "\xff", TRUE
},
949 { 949, "\xff", TRUE
},
950 { 950, "\xff", TRUE
},
951 { 1252, "\x90", FALSE
},
952 { 1253, "\xaa", TRUE
},
953 { 1255, "\xff", TRUE
},
954 { 1257, "\xa5", TRUE
},
958 for (i
= 0; i
< (sizeof(testset
) / sizeof(testset
[0])); i
++) {
959 if (! IsValidCodePage(testset
[i
].codepage
))
961 skip("Codepage %d not available\n", testset
[i
].codepage
);
965 SetLastError(0xdeadbeef);
966 ret
= MultiByteToWideChar(testset
[i
].codepage
, MB_ERR_INVALID_CHARS
,
967 testset
[i
].str
, -1, NULL
, 0);
968 if (testset
[i
].is_error
) {
969 ok(ret
== 0 && GetLastError() == ERROR_NO_UNICODE_TRANSLATION
,
970 "ret is %d, GetLastError is %u (cp %d)\n",
971 ret
, GetLastError(), testset
[i
].codepage
);
974 ok(ret
== strlen(testset
[i
].str
)+1 && GetLastError() == 0xdeadbeef,
975 "ret is %d, GetLastError is %u (cp %d)\n",
976 ret
, GetLastError(), testset
[i
].codepage
);
979 SetLastError(0xdeadbeef);
980 ret
= MultiByteToWideChar(testset
[i
].codepage
, 0,
981 testset
[i
].str
, -1, NULL
, 0);
982 ok(ret
== strlen(testset
[i
].str
)+1 && GetLastError() == 0xdeadbeef,
983 "ret is %d, GetLastError is %u (cp %d)\n",
984 ret
, GetLastError(), testset
[i
].codepage
);
988 static void test_threadcp(void)
990 static const LCID ENGLISH
= MAKELCID(MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), SORT_DEFAULT
);
991 static const LCID HINDI
= MAKELCID(MAKELANGID(LANG_HINDI
, SUBLANG_HINDI_INDIA
), SORT_DEFAULT
);
992 static const LCID GEORGIAN
= MAKELCID(MAKELANGID(LANG_GEORGIAN
, SUBLANG_GEORGIAN_GEORGIA
), SORT_DEFAULT
);
993 static const LCID RUSSIAN
= MAKELCID(MAKELANGID(LANG_RUSSIAN
, SUBLANG_RUSSIAN_RUSSIA
), SORT_DEFAULT
);
994 static const LCID JAPANESE
= MAKELCID(MAKELANGID(LANG_JAPANESE
, SUBLANG_JAPANESE_JAPAN
), SORT_DEFAULT
);
995 static const LCID CHINESE
= MAKELCID(MAKELANGID(LANG_CHINESE
, SUBLANG_CHINESE_SIMPLIFIED
), SORT_DEFAULT
);
997 BOOL islead
, islead_acp
;
1016 struct test_islead_nocp
{
1019 } isleads_nocp
[] = {
1031 struct test_islead
{
1036 { ENGLISH
, 0x00, FALSE
},
1037 { ENGLISH
, 0x81, FALSE
},
1038 { ENGLISH
, 0xa0, FALSE
},
1039 { ENGLISH
, 0xe0, FALSE
},
1041 { RUSSIAN
, 0x00, FALSE
},
1042 { RUSSIAN
, 0x81, FALSE
},
1043 { RUSSIAN
, 0xa0, FALSE
},
1044 { RUSSIAN
, 0xe0, FALSE
},
1046 { JAPANESE
, 0x00, FALSE
},
1047 { JAPANESE
, 0x81, TRUE
},
1048 { JAPANESE
, 0xa0, FALSE
},
1049 { JAPANESE
, 0xe0, TRUE
},
1051 { CHINESE
, 0x00, FALSE
},
1052 { CHINESE
, 0x81, TRUE
},
1053 { CHINESE
, 0xa0, TRUE
},
1054 { CHINESE
, 0xe0, TRUE
},
1057 last
= GetThreadLocale();
1060 for (i
= 0; i
< sizeof(lcids
)/sizeof(lcids
[0]); i
++)
1062 SetThreadLocale(lcids
[i
].lcid
);
1065 GetLocaleInfoA(lcids
[i
].lcid
, LOCALE_IDEFAULTANSICODEPAGE
|LOCALE_RETURN_NUMBER
, (LPSTR
)&cp
, sizeof(cp
));
1066 ok(cp
== lcids
[i
].threadcp
, "wrong codepage %u for lcid %04x, should be %u\n", cp
, lcids
[i
].threadcp
, cp
);
1068 /* GetCPInfoEx/GetCPInfo - CP_ACP */
1069 SetLastError(0xdeadbeef);
1070 memset(&cpi
, 0, sizeof(cpi
));
1071 ret
= GetCPInfoExA(CP_ACP
, 0, &cpi
);
1072 ok(ret
, "GetCPInfoExA failed for lcid %04x, error %d\n", lcids
[i
].lcid
, GetLastError());
1073 ok(cpi
.CodePage
== acp
, "wrong codepage %u for lcid %04x, should be %u\n", cpi
.CodePage
, lcids
[i
].lcid
, acp
);
1075 /* WideCharToMultiByte - CP_ACP */
1076 num
= WideCharToMultiByte(CP_ACP
, 0, foobarW
, -1, NULL
, 0, NULL
, NULL
);
1077 ok(num
== 7, "ret is %d (%04x)\n", num
, lcids
[i
].lcid
);
1079 /* MultiByteToWideChar - CP_ACP */
1080 num
= MultiByteToWideChar(CP_ACP
, 0, "foobar", -1, NULL
, 0);
1081 ok(num
== 7, "ret is %d (%04x)\n", num
, lcids
[i
].lcid
);
1083 /* GetCPInfoEx/GetCPInfo - CP_THREAD_ACP */
1084 SetLastError(0xdeadbeef);
1085 memset(&cpi
, 0, sizeof(cpi
));
1086 ret
= GetCPInfoExA(CP_THREAD_ACP
, 0, &cpi
);
1087 ok(ret
, "GetCPInfoExA failed for lcid %04x, error %d\n", lcids
[i
].lcid
, GetLastError());
1088 if (lcids
[i
].threadcp
)
1089 ok(cpi
.CodePage
== lcids
[i
].threadcp
, "wrong codepage %u for lcid %04x, should be %u\n",
1090 cpi
.CodePage
, lcids
[i
].lcid
, lcids
[i
].threadcp
);
1092 ok(cpi
.CodePage
== acp
, "wrong codepage %u for lcid %04x, should be %u\n",
1093 cpi
.CodePage
, lcids
[i
].lcid
, acp
);
1095 /* WideCharToMultiByte - CP_THREAD_ACP */
1096 num
= WideCharToMultiByte(CP_THREAD_ACP
, 0, foobarW
, -1, NULL
, 0, NULL
, NULL
);
1097 ok(num
== 7, "ret is %d (%04x)\n", num
, lcids
[i
].lcid
);
1099 /* MultiByteToWideChar - CP_THREAD_ACP */
1100 num
= MultiByteToWideChar(CP_THREAD_ACP
, 0, "foobar", -1, NULL
, 0);
1101 ok(num
== 7, "ret is %d (%04x)\n", num
, lcids
[i
].lcid
);
1104 /* IsDBCSLeadByteEx - locales without codepage */
1105 for (i
= 0; i
< sizeof(isleads_nocp
)/sizeof(isleads_nocp
[0]); i
++)
1107 SetThreadLocale(isleads_nocp
[i
].lcid
);
1109 islead_acp
= IsDBCSLeadByteEx(CP_ACP
, isleads_nocp
[i
].testchar
);
1110 islead
= IsDBCSLeadByteEx(CP_THREAD_ACP
, isleads_nocp
[i
].testchar
);
1112 ok(islead
== islead_acp
, "wrong islead %i for test char %x in lcid %04x. should be %i\n",
1113 islead
, isleads_nocp
[i
].testchar
, isleads_nocp
[i
].lcid
, islead_acp
);
1116 /* IsDBCSLeadByteEx - locales with codepage */
1117 for (i
= 0; i
< sizeof(isleads
)/sizeof(isleads
[0]); i
++)
1119 SetThreadLocale(isleads
[i
].lcid
);
1121 islead
= IsDBCSLeadByteEx(CP_THREAD_ACP
, isleads
[i
].testchar
);
1122 ok(islead
== isleads
[i
].islead
, "wrong islead %i for test char %x in lcid %04x. should be %i\n",
1123 islead
, isleads
[i
].testchar
, isleads
[i
].lcid
, isleads
[i
].islead
);
1126 SetThreadLocale(last
);
1129 START_TEST(codepage
)
1131 BOOL bUsedDefaultChar
;
1133 test_destination_buffer();
1135 test_negative_source_length();
1136 test_negative_dest_length();
1137 test_other_invalid_parameters();
1138 test_overlapped_buffers();
1140 /* WideCharToMultiByte has two code paths, test both here */
1141 test_string_conversion(NULL
);
1142 test_string_conversion(&bUsedDefaultChar
);
1144 test_utf7_encoding();
1145 test_utf7_decoding();
1147 test_undefined_byte_char();