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 */
286 SetLastError(0xdeadbeef);
287 ret
= WideCharToMultiByte(1252, 0, &wc1
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
288 ok(ret
== 1, "ret is %d\n", ret
);
289 ok(mbc
== '\xe4', "mbc is %d\n", mbc
);
290 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
291 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
293 SetLastError(0xdeadbeef);
294 ret
= WideCharToMultiByte(1252, 0, &wc2
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
295 ok(ret
== 1, "ret is %d\n", ret
);
296 ok(mbc
== 63, "mbc is %d\n", mbc
);
297 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
298 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
300 if (IsValidCodePage(1251))
302 SetLastError(0xdeadbeef);
303 ret
= WideCharToMultiByte(1251, 0, &wc2
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
304 ok(ret
== 1, "ret is %d\n", ret
);
305 ok(mbc
== '\xf0', "mbc is %d\n", mbc
);
306 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
307 ok(GetLastError() == 0xdeadbeef ||
308 broken(GetLastError() == 0), /* win95 */
309 "GetLastError() is %u\n", GetLastError());
311 SetLastError(0xdeadbeef);
312 ret
= WideCharToMultiByte(1251, 0, &wc1
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
313 ok(ret
== 1, "ret is %d\n", ret
);
314 ok(mbc
== 97, "mbc is %d\n", mbc
);
315 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
316 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
319 skip("Codepage 1251 not available\n");
321 /* This call triggers the last Win32 error */
322 SetLastError(0xdeadbeef);
323 ret
= WideCharToMultiByte(1252, 0, wcs
, -1, &mbc
, 1, NULL
, bUsedDefaultChar
);
324 ok(ret
== 0, "ret is %d\n", ret
);
325 ok(mbc
== 84, "mbc is %d\n", mbc
);
326 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
327 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "GetLastError() is %u\n", GetLastError());
329 SetLastError(0xdeadbeef);
330 ret
= WideCharToMultiByte(1252, 0, wcs
, -1, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
331 ok(ret
== 5, "ret is %d\n", ret
);
332 ok(!strcmp(mbs
, "Th?i"), "mbs is %s\n", mbs
);
333 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
334 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
337 /* WideCharToMultiByte mustn't add any null character automatically.
338 So in this case, we should get the same string again, even if we only copied the first three bytes. */
339 SetLastError(0xdeadbeef);
340 ret
= WideCharToMultiByte(1252, 0, wcs
, 3, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
341 ok(ret
== 3, "ret is %d\n", ret
);
342 ok(!strcmp(mbs
, "Th?i"), "mbs is %s\n", mbs
);
343 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
344 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
347 /* Now this shouldn't be the case like above as we zeroed the complete string buffer. */
348 SetLastError(0xdeadbeef);
349 ret
= WideCharToMultiByte(1252, 0, wcs
, 3, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
350 ok(ret
== 3, "ret is %d\n", ret
);
351 ok(!strcmp(mbs
, "Th?"), "mbs is %s\n", mbs
);
352 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
353 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
355 /* Double-byte tests */
356 ret
= WideCharToMultiByte(1252, 0, dbwcs
, 3, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
357 ok(ret
== 3, "ret is %d\n", ret
);
358 ok(!strcmp(mbs
, "??"), "mbs is %s\n", mbs
);
359 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
361 /* Length-only tests */
362 SetLastError(0xdeadbeef);
363 ret
= WideCharToMultiByte(1252, 0, &wc2
, 1, NULL
, 0, NULL
, bUsedDefaultChar
);
364 ok(ret
== 1, "ret is %d\n", ret
);
365 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
366 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
368 SetLastError(0xdeadbeef);
369 ret
= WideCharToMultiByte(1252, 0, wcs
, -1, NULL
, 0, NULL
, bUsedDefaultChar
);
370 ok(ret
== 5, "ret is %d\n", ret
);
371 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== TRUE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
372 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
374 if (!IsValidCodePage(950))
376 skip("Codepage 950 not available\n");
380 /* Double-byte tests */
381 SetLastError(0xdeadbeef);
382 ret
= WideCharToMultiByte(950, 0, dbwcs
, -1, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
383 ok(ret
== 5, "ret is %d\n", ret
);
384 ok(!strcmp(mbs
, "\xb5H\xa9\xd2"), "mbs is %s\n", mbs
);
385 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
386 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
388 SetLastError(0xdeadbeef);
389 ret
= WideCharToMultiByte(950, 0, dbwcs
, 1, &mbc
, 1, NULL
, bUsedDefaultChar
);
390 ok(ret
== 0, "ret is %d\n", ret
);
391 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
392 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "GetLastError() is %u\n", GetLastError());
395 SetLastError(0xdeadbeef);
396 ret
= WideCharToMultiByte(950, 0, dbwcs
, 1, mbs
, sizeof(mbs
), NULL
, bUsedDefaultChar
);
397 ok(ret
== 2, "ret is %d\n", ret
);
398 ok(!strcmp(mbs
, "\xb5H"), "mbs is %s\n", mbs
);
399 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
400 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
402 /* Length-only tests */
403 SetLastError(0xdeadbeef);
404 ret
= WideCharToMultiByte(950, 0, dbwcs
, 1, NULL
, 0, NULL
, bUsedDefaultChar
);
405 ok(ret
== 2, "ret is %d\n", ret
);
406 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
407 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
409 SetLastError(0xdeadbeef);
410 ret
= WideCharToMultiByte(950, 0, dbwcs
, -1, NULL
, 0, NULL
, bUsedDefaultChar
);
411 ok(ret
== 5, "ret is %d\n", ret
);
412 if(bUsedDefaultChar
) ok(*bUsedDefaultChar
== FALSE
, "bUsedDefaultChar is %d\n", *bUsedDefaultChar
);
413 ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
416 static void test_utf7_encoding(void)
419 char output
[16], expected
[16];
420 int i
, len
, expected_len
;
422 static const BOOL directly_encodable_table
[] =
424 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, /* 0x00 - 0x0F */
425 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1F */
426 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, /* 0x20 - 0x2F */
427 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 0x30 - 0x3F */
428 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4F */
429 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 0x50 - 0x5F */
430 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6F */
431 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 /* 0x70 - 0x7F */
433 static const char base64_encoding_table
[] =
434 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
443 /* expected outputs */
444 char expected_dst
[16];
450 /* tests string conversion with srclen=-1 */
452 {0x4F60,0x597D,0x5417,0}, -1, output
, sizeof(output
) - 1,
455 /* tests string conversion with srclen=-2 */
457 {0x4F60,0x597D,0x5417,0}, -2, output
, sizeof(output
) - 1,
460 /* tests string conversion with dstlen=strlen(expected_dst) */
462 {0x4F60,0x597D,0x5417,0}, -1, output
, 10,
465 /* tests string conversion with dstlen=strlen(expected_dst)+1 */
467 {0x4F60,0x597D,0x5417,0}, -1, output
, 11,
470 /* tests string conversion with dstlen=strlen(expected_dst)+2 */
472 {0x4F60,0x597D,0x5417,0}, -1, output
, 12,
475 /* tests dry run with dst=NULL and dstlen=0 */
477 {0x4F60,0x597D,0x5417,0}, -1, NULL
, 0,
480 /* tests dry run with dst!=NULL and dstlen=0 */
482 {0x4F60,0x597D,0x5417,0}, -1, output
, 0,
485 /* tests srclen < strlenW(src) with directly encodable chars */
487 {'h','e','l','l','o',0}, 2, output
, sizeof(output
) - 1,
490 /* tests srclen < strlenW(src) with non-directly encodable chars */
492 {0x4F60,0x597D,0x5417,0}, 2, output
, sizeof(output
) - 1,
495 /* tests a single null char */
497 {0}, -1, output
, sizeof(output
) - 1,
500 /* tests a buffer that runs out while not encoding a UTF-7 sequence */
502 {'h','e','l','l','o',0}, -1, output
, 2,
505 /* tests a buffer that runs out after writing 1 base64 character */
507 {0x4F60,0x0001,0}, -1, output
, 2,
510 /* tests a buffer that runs out after writing 2 base64 characters */
512 {0x4F60,0x0001,0}, -1, output
, 3,
515 /* tests a buffer that runs out after writing 3 base64 characters */
517 {0x4F60,0x0001,0}, -1, output
, 4,
520 /* tests a buffer that runs out just after writing the + sign */
522 {0x4F60,0}, -1, output
, 1,
525 /* tests a buffer that runs out just before writing the - sign
526 * the number of bits to encode here is evenly divisible by 6 */
528 {0x4F60,0x597D,0x5417,0}, -1, output
, 9,
531 /* tests a buffer that runs out just before writing the - sign
532 * the number of bits to encode here is NOT evenly divisible by 6 */
534 {0x4F60,0}, -1, output
, 4,
537 /* tests a buffer that runs out in the middle of escaping a + sign */
539 {'+',0}, -1, output
, 1,
544 /* test which characters are encoded if surrounded by non-encoded characters */
545 for (i
= 0; i
<= 0xFFFF; i
++)
552 memset(output
, '#', sizeof(output
) - 1);
553 output
[sizeof(output
) - 1] = 0;
555 len
= WideCharToMultiByte(CP_UTF7
, 0, input
, 4, output
, sizeof(output
) - 1, NULL
, NULL
);
559 /* '+' is a special case and is encoded as "+-" */
561 strcpy(expected
, " +- ");
563 else if (i
<= 0x7F && directly_encodable_table
[i
])
565 /* encodes directly */
567 sprintf(expected
, " %c ", i
);
573 sprintf(expected
, " +%c%c%c- ",
574 base64_encoding_table
[(i
& 0xFC00) >> 10],
575 base64_encoding_table
[(i
& 0x03F0) >> 4],
576 base64_encoding_table
[(i
& 0x000F) << 2]);
579 ok(len
== expected_len
, "i=0x%04x: expected len=%i, got len=%i\n", i
, expected_len
, len
);
580 ok(memcmp(output
, expected
, expected_len
) == 0,
581 "i=0x%04x: expected output='%s', got output='%s'\n", i
, expected
, output
);
582 ok(output
[expected_len
] == '#', "i=0x%04x: expected output[%i]='#', got output[%i]=%i\n",
583 i
, expected_len
, expected_len
, output
[expected_len
]);
586 /* test which one-byte characters are absorbed into surrounding base64 blocks
587 * (Windows always ends the base64 block when it encounters a directly encodable character) */
588 for (i
= 0; i
<= 0xFFFF; i
++)
595 memset(output
, '#', sizeof(output
) - 1);
596 output
[sizeof(output
) - 1] = 0;
598 len
= WideCharToMultiByte(CP_UTF7
, 0, input
, 4, output
, sizeof(output
) - 1, NULL
, NULL
);
602 /* '+' is a special case and is encoded as "+-" */
604 strcpy(expected
, "+JnI-+-+JnI-");
606 else if (i
<= 0x7F && directly_encodable_table
[i
])
608 /* encodes directly */
610 sprintf(expected
, "+JnI-%c+JnI-", i
);
616 sprintf(expected
, "+Jn%c%c%c%cZy-",
617 base64_encoding_table
[8 | ((i
& 0xC000) >> 14)],
618 base64_encoding_table
[(i
& 0x3F00) >> 8],
619 base64_encoding_table
[(i
& 0x00FC) >> 2],
620 base64_encoding_table
[((i
& 0x0003) << 4) | 2]);
623 ok(len
== expected_len
, "i=0x%04x: expected len=%i, got len=%i\n", i
, expected_len
, len
);
624 ok(memcmp(output
, expected
, expected_len
) == 0,
625 "i=0x%04x: expected output='%s', got output='%s'\n", i
, expected
, output
);
626 ok(output
[expected_len
] == '#', "i=0x%04x: expected output[%i]='#', got output[%i]=%i\n",
627 i
, expected_len
, expected_len
, output
[expected_len
]);
630 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); i
++)
632 memset(output
, '#', sizeof(output
) - 1);
633 output
[sizeof(output
) - 1] = 0;
634 SetLastError(0xdeadbeef);
636 len
= WideCharToMultiByte(CP_UTF7
, 0, tests
[i
].src
, tests
[i
].srclen
,
637 tests
[i
].dst
, tests
[i
].dstlen
, NULL
, NULL
);
641 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
642 "tests[%i]: expected error=0x%x, got error=0x%x\n",
643 i
, ERROR_INSUFFICIENT_BUFFER
, GetLastError());
645 ok(len
== tests
[i
].len
, "tests[%i]: expected len=%i, got len=%i\n", i
, tests
[i
].len
, len
);
649 ok(memcmp(tests
[i
].dst
, tests
[i
].expected_dst
, tests
[i
].chars_written
) == 0,
650 "tests[%i]: expected dst='%s', got dst='%s'\n",
651 i
, tests
[i
].expected_dst
, tests
[i
].dst
);
652 ok(tests
[i
].dst
[tests
[i
].chars_written
] == '#',
653 "tests[%i]: expected dst[%i]='#', got dst[%i]=%i\n",
654 i
, tests
[i
].chars_written
, tests
[i
].chars_written
, tests
[i
].dst
[tests
[i
].chars_written
]);
659 static void test_utf7_decoding(void)
662 WCHAR output
[32], expected
[32];
663 int i
, len
, expected_len
;
665 static const signed char base64_decoding_table
[] =
667 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00-0x0F */
668 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10-0x1F */
669 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /* 0x20-0x2F */
670 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, /* 0x30-0x3F */
671 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, /* 0x40-0x4F */
672 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, /* 0x50-0x5F */
673 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, /* 0x60-0x6F */
674 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 /* 0x70-0x7F */
684 /* expected outputs */
685 WCHAR expected_dst
[32];
691 /* tests string conversion with srclen=-1 */
693 "+T2BZfQ-", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
694 {0x4F60,0x597D,0}, 3, 3
696 /* tests string conversion with srclen=-2 */
698 "+T2BZfQ-", -2, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
699 {0x4F60,0x597D,0}, 3, 3
701 /* tests string conversion with dstlen=strlen(expected_dst) */
703 "+T2BZfQ-", -1, output
, 2,
704 {0x4F60,0x597D}, 2, 0
706 /* tests string conversion with dstlen=strlen(expected_dst)+1 */
708 "+T2BZfQ-", -1, output
, 3,
709 {0x4F60,0x597D,0}, 3, 3
711 /* tests string conversion with dstlen=strlen(expected_dst)+2 */
713 "+T2BZfQ-", -1, output
, 4,
714 {0x4F60,0x597D,0}, 3, 3
716 /* tests dry run with dst=NULL and dstlen=0 */
718 "+T2BZfQ-", -1, NULL
, 0,
721 /* tests dry run with dst!=NULL and dstlen=0 */
723 "+T2BZfQ-", -1, output
, 0,
726 /* tests ill-formed UTF-7: 6 bits, not enough for a byte pair */
728 "+T-+T-+T-hello", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
729 {'h','e','l','l','o',0}, 6, 6
731 /* tests ill-formed UTF-7: 12 bits, not enough for a byte pair */
733 "+T2-+T2-+T2-hello", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
734 {'h','e','l','l','o',0}, 6, 6
736 /* tests ill-formed UTF-7: 18 bits, not a multiple of 16 and the last bit is a 1 */
738 "+T2B-+T2B-+T2B-hello", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
739 {0x4F60,0x4F60,0x4F60,'h','e','l','l','o',0}, 9, 9
741 /* tests ill-formed UTF-7: 24 bits, a multiple of 8 but not a multiple of 16 */
743 "+T2BZ-+T2BZ-+T2BZ-hello", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
744 {0x4F60,0x4F60,0x4F60,'h','e','l','l','o',0}, 9, 9
746 /* tests UTF-7 followed by characters that should be encoded but aren't */
748 "+T2BZ-\x82\xFE", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
749 {0x4F60,0x0082,0x00FE,0}, 4, 4
751 /* tests srclen > strlen(src) */
753 "a\0b", 4, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
756 /* tests srclen < strlen(src) outside of a UTF-7 sequence */
758 "hello", 2, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
761 /* tests srclen < strlen(src) inside of a UTF-7 sequence */
763 "+T2BZfQ-", 4, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
766 /* tests srclen < strlen(src) right at the beginning of a UTF-7 sequence */
768 "hi+T2A-", 3, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
771 /* tests srclen < strlen(src) right at the end of a UTF-7 sequence */
773 "+T2A-hi", 5, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
776 /* tests srclen < strlen(src) at the beginning of an escaped + sign */
778 "hi+-", 3, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
781 /* tests srclen < strlen(src) at the end of an escaped + sign */
783 "+-hi", 2, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
786 /* tests len=0 but no error */
788 "+", 1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
791 /* tests a single null char */
793 "", -1, output
, sizeof(output
) / sizeof(WCHAR
) - 1,
796 /* tests a buffer that runs out while not decoding a UTF-7 sequence */
798 "hello", -1, output
, 2,
801 /* tests a buffer that runs out in the middle of decoding a UTF-7 sequence */
803 "+T2BZfQ-", -1, output
, 1,
808 if (MultiByteToWideChar(CP_UTF7
, 0, "foobar", -1, NULL
, 0) == 0 &&
809 GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
811 skip("UTF-7 decoding not implemented\n");
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();