kernel32: Update Italian translation.
[wine/testsucceed.git] / dlls / mlang / tests / mlang.c
blob2c4e0c17678c7ad2ff18d410bd41c68737a0e5a7
1 /*
2 * Unit test suite for MLANG APIs.
4 * Copyright 2004 Dmitry Timoshkov
5 * Copyright 2009 Detlef Riekenberg
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
22 #define COBJMACROS
24 #include <stdarg.h>
25 #include <stdio.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "initguid.h"
31 #include "mlang.h"
33 #include "wine/test.h"
35 #ifndef CP_UNICODE
36 #define CP_UNICODE 1200
37 #endif
39 /* #define DUMP_CP_INFO */
40 /* #define DUMP_SCRIPT_INFO */
42 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
43 static HRESULT (WINAPI *pConvertINetMultiByteToUnicode)(LPDWORD, DWORD, LPCSTR,
44 LPINT, LPWSTR, LPINT);
45 static HRESULT (WINAPI *pConvertINetUnicodeToMultiByte)(LPDWORD, DWORD, LPCWSTR,
46 LPINT, LPSTR, LPINT);
47 static HRESULT (WINAPI *pRfc1766ToLcidA)(LCID *, LPCSTR);
48 static HRESULT (WINAPI *pLcidToRfc1766A)(LCID, LPSTR, INT);
50 typedef struct lcid_tag_table {
51 LPCSTR rfc1766;
52 LCID lcid;
53 HRESULT hr;
54 LCID broken_lcid;
55 LPCSTR broken_rfc;
56 } lcid_table_entry;
58 /* en, ar and zh use SUBLANG_NEUTRAL for the rfc1766 name without the country
59 all others suppress the country with SUBLANG_DEFAULT.
60 For 3 letter language codes, the rfc1766 is too small for the country */
62 static const lcid_table_entry lcid_table[] = {
63 {"e", -1, E_FAIL},
64 {"", -1, E_FAIL},
65 {"-", -1, E_FAIL},
66 {"e-", -1, E_FAIL},
68 {"ar", 1, S_OK},
69 {"zh", 4, S_OK},
71 {"de", 0x0407, S_OK},
72 {"de-ch", 0x0807, S_OK},
73 {"de-at", 0x0c07, S_OK},
74 {"de-lu", 0x1007, S_OK},
75 {"de-li", 0x1407, S_OK},
77 {"en", 9, S_OK},
78 {"en-gb", 0x809, S_OK},
79 {"en-GB", 0x809, S_OK},
80 {"EN-GB", 0x809, S_OK},
81 {"en-US", 0x409, S_OK},
82 {"en-us", 0x409, S_OK},
84 {"fr", 0x040c, S_OK},
85 {"fr-be", 0x080c, S_OK},
86 {"fr-ca", 0x0c0c, S_OK},
87 {"fr-ch", 0x100c, S_OK},
88 {"fr-lu", 0x140c, S_OK},
89 {"fr-mc", 0x180c, S_OK, 0x040c, "fr"},
91 {"it", 0x0410, S_OK},
92 {"it-ch", 0x0810, S_OK},
94 {"nl", 0x0413, S_OK},
95 {"nl-be", 0x0813, S_OK},
96 {"pl", 0x0415, S_OK},
97 {"ru", 0x0419, S_OK},
99 {"kok", 0x0457, S_OK, 0x0412, "x-kok"}
103 #define TODO_NAME 1
105 typedef struct info_table_tag {
106 LCID lcid;
107 LANGID lang;
108 DWORD todo;
109 LPCSTR rfc1766;
110 LPCWSTR localename;
111 LPCWSTR broken_name;
112 } info_table_entry;
114 static const WCHAR de_en[] = {'E','n','g','l','i','s','c','h',0};
115 static const WCHAR de_enca[] = {'E','n','g','l','i','s','c','h',' ',
116 '(','K','a','n','a','d','a',')',0};
117 static const WCHAR de_engb[] = {'E','n','g','l','i','s','c','h',' ',
118 '(','G','r','o',0xDF,'b','r','i','t','a','n','n','i','e','n',')',0};
119 static const WCHAR de_engb2[] ={'E','n','g','l','i','s','c','h',' ',
120 '(','V','e','r','e','i','n','i','g','t','e','s',' ',
121 'K',0xF6,'n','i','g','r','e','i','c',0};
122 static const WCHAR de_enus[] = {'E','n','g','l','i','s','c','h',' ',
123 '(','U','S','A',')',0};
124 static const WCHAR de_de[] = {'D','e','u','t','s','c','h',' ',
125 '(','D','e','u','t','s','c','h','l','a','n','d',')',0};
126 static const WCHAR de_deat[] = {'D','e','u','t','s','c','h',' ',
127 '(',0xD6,'s','t','e','r','r','e','i','c','h',')',0};
128 static const WCHAR de_dech[] = {'D','e','u','t','s','c','h',' ',
129 '(','S','c','h','w','e','i','z',')',0};
131 static const WCHAR en_en[] = {'E','n','g','l','i','s','h',0};
132 static const WCHAR en_enca[] = {'E','n','g','l','i','s','h',' ',
133 '(','C','a','n','a','d','a',')',0};
134 static const WCHAR en_engb[] = {'E','n','g','l','i','s','h',' ',
135 '(','U','n','i','t','e','d',' ','K','i','n','g','d','o','m',')',0};
136 static const WCHAR en_enus[] = {'E','n','g','l','i','s','h',' ',
137 '(','U','n','i','t','e','d',' ','S','t','a','t','e','s',')',0};
138 static const WCHAR en_de[] = {'G','e','r','m','a','n',' ',
139 '(','G','e','r','m','a','n','y',')',0};
140 static const WCHAR en_deat[] = {'G','e','r','m','a','n',' ',
141 '(','A','u','s','t','r','i','a',')',0};
142 static const WCHAR en_dech[] = {'G','e','r','m','a','n',' ',
143 '(','S','w','i','t','z','e','r','l','a','n','d',')',0};
145 static const WCHAR fr_en[] = {'A','n','g','l','a','i','s',0};
146 static const WCHAR fr_enca[] = {'A','n','g','l','a','i','s',' ',
147 '(','C','a','n','a','d','a',')',0};
148 static const WCHAR fr_engb[] = {'A','n','g','l','a','i','s',' ',
149 '(','R','o','y','a','u','m','e','-','U','n','i',')',0};
150 static const WCHAR fr_enus[] = {'A','n','g','l','a','i','s',' ',
151 '(',0xC9, 't','a','t','s','-','U','n','i','s',')',0};
152 static const WCHAR fr_enus2[] ={'A','n','g','l','a','i','s',' ',
153 '(','U','.','S','.',')',0};
154 static const WCHAR fr_de[] = {'A','l','l','e','m','a','n','d',' ',
155 '(','A','l','l','e','m','a','g','n','e',')',0};
156 static const WCHAR fr_de2[] = {'A','l','l','e','m','a','n','d',' ',
157 '(','S','t','a','n','d','a','r','d',')',0};
158 static const WCHAR fr_deat[] = {'A','l','l','e','m','a','n','d',' ',
159 '(','A','u','t','r','i','c','h','e',')',0};
160 static const WCHAR fr_dech[] = {'A','l','l','e','m','a','n','d',' ',
161 '(','S','u','i','s','s','e',')',0};
163 static const info_table_entry info_table[] = {
164 {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
165 0, "en", en_en},
166 {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
167 0, "en-us", en_enus},
168 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
169 0, "en-gb", en_engb},
170 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
171 0, "en-us", en_enus},
172 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
173 0, "en-ca", en_enca},
175 {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
176 0, "de", en_de},
177 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
178 0, "de", en_de},
179 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
180 0, "de-ch", en_dech},
181 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
182 0, "de-at", en_deat},
184 {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
185 TODO_NAME, "en", de_en},
186 {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
187 TODO_NAME, "en-us", de_enus},
188 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
189 TODO_NAME, "en-gb", de_engb, de_engb2},
190 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
191 TODO_NAME, "en-us", de_enus},
192 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
193 TODO_NAME, "en-ca", de_enca},
195 {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
196 TODO_NAME, "de", de_de},
197 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
198 TODO_NAME, "de",de_de},
199 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
200 TODO_NAME, "de-ch", de_dech},
201 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
202 TODO_NAME, "de-at", de_deat},
204 {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
205 TODO_NAME, "en", fr_en},
206 {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
207 TODO_NAME, "en-us", fr_enus, fr_enus2},
208 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
209 TODO_NAME, "en-gb", fr_engb},
210 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
211 TODO_NAME, "en-us", fr_enus, fr_enus2},
212 {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
213 TODO_NAME, "en-ca", fr_enca},
215 {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
216 TODO_NAME, "de", fr_de, fr_de2},
217 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
218 TODO_NAME, "de", fr_de, fr_de2},
219 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
220 TODO_NAME, "de-ch", fr_dech},
221 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
222 TODO_NAME, "de-at", fr_deat}
226 static BOOL init_function_ptrs(void)
228 HMODULE hMlang;
230 hMlang = LoadLibraryA("mlang.dll");
231 if (!hMlang)
233 skip("mlang not available\n");
234 return FALSE;
237 pConvertINetMultiByteToUnicode = (void *)GetProcAddress(hMlang, "ConvertINetMultiByteToUnicode");
238 pConvertINetUnicodeToMultiByte = (void *)GetProcAddress(hMlang, "ConvertINetUnicodeToMultiByte");
239 pRfc1766ToLcidA = (void *)GetProcAddress(hMlang, "Rfc1766ToLcidA");
240 pLcidToRfc1766A = (void *)GetProcAddress(hMlang, "LcidToRfc1766A");
242 pGetCPInfoExA = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetCPInfoExA");
244 return TRUE;
247 #define ok_w2(format, szString1, szString2) \
249 if (lstrcmpW((szString1), (szString2)) != 0) \
251 CHAR string1[256], string2[256]; \
252 WideCharToMultiByte(CP_ACP, 0, (szString1), -1, string1, 256, NULL, NULL); \
253 WideCharToMultiByte(CP_ACP, 0, (szString2), -1, string2, 256, NULL, NULL); \
254 ok(0, (format), string1, string2); \
257 /* lstrcmpW is not supported on Win9x! */
258 static int mylstrcmpW(const WCHAR* str1, const WCHAR* str2)
260 if (!str2) return 1;
261 while (*str1 && *str1==*str2) {
262 str1++;
263 str2++;
265 return *str1-*str2;
268 /* lstrcpyW is not supported on Win95 */
269 static void mylstrcpyW(WCHAR* str1, const WCHAR* str2)
271 while (str2 && *str2) {
272 *str1 = *str2;
273 str1++;
274 str2++;
276 *str1 = '\0';
279 static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
281 /* these APIs are broken regarding constness of the input buffer */
282 char stringA[] = "Just a test string\0"; /* double 0 for CP_UNICODE tests */
283 WCHAR stringW[] = {'J','u','s','t',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
284 char bufA[256];
285 WCHAR bufW[256];
286 UINT lenA, lenW, expected_len;
287 HRESULT ret;
289 /* IMultiLanguage2_ConvertStringToUnicode tests */
291 memset(bufW, 'x', sizeof(bufW));
292 lenA = 0;
293 lenW = sizeof(bufW)/sizeof(bufW[0]);
294 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
295 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
296 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
297 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
299 memset(bufW, 'x', sizeof(bufW));
300 lenA = -1;
301 lenW = sizeof(bufW)/sizeof(bufW[0]);
302 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
303 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
304 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
305 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
306 if (lenW < sizeof(bufW)/sizeof(bufW[0])) {
307 /* can only happen if the convert call fails */
308 ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
309 bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
311 ok(!lstrcmpW(bufW, stringW), "bufW/stringW mismatch\n");
313 memset(bufW, 'x', sizeof(bufW));
314 lenA = -1;
315 lenW = 5;
316 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
317 ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringToUnicode should fail: %08x\n", ret);
318 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
319 /* still has to do partial conversion */
320 ok(!memcmp(bufW, stringW, 5 * sizeof(WCHAR)), "bufW/stringW mismatch\n");
322 memset(bufW, 'x', sizeof(bufW));
323 lenA = -1;
324 lenW = sizeof(bufW)/sizeof(bufW[0]);
325 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, CP_UNICODE, stringA, &lenA, bufW, &lenW);
326 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
327 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
328 ok(lenW == lstrlenW(stringW)/(int)sizeof(WCHAR), "wrong lenW %u\n", lenW);
329 ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
330 bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
331 ok(!lstrcmpA((LPCSTR)bufW, stringA), "bufW/stringA mismatch\n");
333 memset(bufW, 'x', sizeof(bufW));
334 lenA = lstrlenA(stringA);
335 lenW = 0;
336 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, NULL, &lenW);
337 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
338 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
339 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
340 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
342 memset(bufW, 'x', sizeof(bufW));
343 lenA = lstrlenA(stringA);
344 lenW = sizeof(bufW)/sizeof(bufW[0]);
345 ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
346 ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
347 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
348 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
349 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
351 memset(bufW, 'x', sizeof(bufW));
352 lenA = lstrlenA(stringA);
353 lenW = 0;
354 ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
355 ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
356 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
357 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
358 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
360 /* IMultiLanguage2_ConvertStringFromUnicode tests */
362 memset(bufA, 'x', sizeof(bufA));
363 lenW = 0;
364 lenA = sizeof(bufA);
365 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
366 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
367 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
368 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
370 memset(bufA, 'x', sizeof(bufA));
371 lenW = -1;
372 lenA = sizeof(bufA);
373 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
374 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
375 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
376 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
377 ok(bufA[lenA] != 0, "buf should not be 0 terminated\n");
378 bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
379 ok(!lstrcmpA(bufA, stringA), "bufA/stringA mismatch\n");
381 memset(bufA, 'x', sizeof(bufA));
382 lenW = -1;
383 lenA = 5;
384 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
385 ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringFromUnicode should fail: %08x\n", ret);
386 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
387 /* still has to do partial conversion */
388 ok(!memcmp(bufA, stringA, 5), "bufW/stringW mismatch\n");
390 memset(bufA, 'x', sizeof(bufA));
391 lenW = -1;
392 lenA = sizeof(bufA);
393 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, CP_UNICODE, stringW, &lenW, bufA, &lenA);
394 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
395 ok(lenA == lstrlenA(stringA) * (int)sizeof(WCHAR), "wrong lenA %u\n", lenA);
396 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
397 ok(bufA[lenA] != 0 && bufA[lenA+1] != 0, "buf should not be 0 terminated\n");
398 bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
399 bufA[lenA+1] = 0; /* sizeof(WCHAR) */
400 ok(!lstrcmpW((LPCWSTR)bufA, stringW), "bufA/stringW mismatch\n");
402 memset(bufA, 'x', sizeof(bufA));
403 lenW = lstrlenW(stringW);
404 lenA = 0;
405 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, NULL, &lenA);
406 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
407 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
408 expected_len = WideCharToMultiByte(1252, 0, stringW, lenW, NULL, 0, NULL, NULL);
409 ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);
412 static void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
414 ok(cpinfo1->dwFlags == cpinfo2->dwFlags, "dwFlags mismatch: %08x != %08x\n", cpinfo1->dwFlags, cpinfo2->dwFlags);
415 ok(cpinfo1->uiCodePage == cpinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", cpinfo1->uiCodePage, cpinfo2->uiCodePage);
416 ok(cpinfo1->uiFamilyCodePage == cpinfo2->uiFamilyCodePage, "uiFamilyCodePage mismatch: %u != %u\n", cpinfo1->uiFamilyCodePage, cpinfo2->uiFamilyCodePage);
417 ok(!lstrcmpW(cpinfo1->wszDescription, cpinfo2->wszDescription), "wszDescription mismatch\n");
418 ok(!lstrcmpW(cpinfo1->wszWebCharset, cpinfo2->wszWebCharset), "wszWebCharset mismatch\n");
419 ok(!lstrcmpW(cpinfo1->wszHeaderCharset, cpinfo2->wszHeaderCharset), "wszHeaderCharset mismatch\n");
420 ok(!lstrcmpW(cpinfo1->wszBodyCharset, cpinfo2->wszBodyCharset), "wszBodyCharset mismatch\n");
421 ok(!lstrcmpW(cpinfo1->wszFixedWidthFont, cpinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
422 ok(!lstrcmpW(cpinfo1->wszProportionalFont, cpinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
423 ok(cpinfo1->bGDICharset == cpinfo2->bGDICharset, "bGDICharset mismatch: %d != %d\n", cpinfo1->bGDICharset, cpinfo2->bGDICharset);
426 #ifdef DUMP_CP_INFO
427 static const char *dump_mime_flags(DWORD flags)
429 static char buf[1024];
431 buf[0] = 0;
433 if (flags & MIMECONTF_MAILNEWS) strcat(buf, " MIMECONTF_MAILNEWS");
434 if (flags & MIMECONTF_BROWSER) strcat(buf, " MIMECONTF_BROWSER");
435 if (flags & MIMECONTF_MINIMAL) strcat(buf, " MIMECONTF_MINIMAL");
436 if (flags & MIMECONTF_IMPORT) strcat(buf, " MIMECONTF_IMPORT");
437 if (flags & MIMECONTF_SAVABLE_MAILNEWS) strcat(buf, " MIMECONTF_SAVABLE_MAILNEWS");
438 if (flags & MIMECONTF_SAVABLE_BROWSER) strcat(buf, " MIMECONTF_SAVABLE_BROWSER");
439 if (flags & MIMECONTF_EXPORT) strcat(buf, " MIMECONTF_EXPORT");
440 if (flags & MIMECONTF_PRIVCONVERTER) strcat(buf, " MIMECONTF_PRIVCONVERTER");
441 if (flags & MIMECONTF_VALID) strcat(buf, " MIMECONTF_VALID");
442 if (flags & MIMECONTF_VALID_NLS) strcat(buf, " MIMECONTF_VALID_NLS");
443 if (flags & MIMECONTF_MIME_IE4) strcat(buf, " MIMECONTF_MIME_IE4");
444 if (flags & MIMECONTF_MIME_LATEST) strcat(buf, " MIMECONTF_MIME_LATEST");
445 if (flags & MIMECONTF_MIME_REGISTRY) strcat(buf, " MIMECONTF_MIME_REGISTRY");
447 return buf;
449 #endif
451 static HRESULT check_convertible(IMultiLanguage2 *iML2, UINT from, UINT to)
453 CHAR convert[MAX_PATH];
454 BYTE dest[MAX_PATH];
455 HRESULT hr;
456 UINT srcsz, destsz;
458 static WCHAR strW[] = {'a','b','c',0};
460 /* Check to see if the target codepage has these characters or not */
461 if (from != CP_UTF8)
463 BOOL fDefaultChar;
464 char ch[10];
465 int cb;
466 cb = WideCharToMultiByte( from, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
467 strW, 3, ch, sizeof(ch), NULL, &fDefaultChar);
469 if(cb == 0 || fDefaultChar)
471 trace("target codepage %i does not contain 'abc'\n",from);
472 return E_FAIL;
476 srcsz = lstrlenW(strW) + 1;
477 destsz = MAX_PATH;
478 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, from, strW,
479 &srcsz, convert, &destsz);
480 if (hr != S_OK)
481 return S_FALSE;
483 srcsz = -1;
484 destsz = MAX_PATH;
485 hr = IMultiLanguage2_ConvertString(iML2, NULL, from, to, (BYTE *)convert,
486 &srcsz, dest, &destsz);
487 if (hr != S_OK)
488 return S_FALSE;
490 return S_OK;
493 static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
495 IEnumCodePage *iEnumCP = NULL;
496 MIMECPINFO *cpinfo;
497 MIMECPINFO cpinfo2;
498 HRESULT ret;
499 ULONG i, n;
500 UINT total;
502 total = 0;
503 ret = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &total);
504 ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfCodePageInfo: expected S_OK/!0, got %08x/%u\n", ret, total);
506 trace("total mlang supported codepages %u\n", total);
508 ret = IMultiLanguage2_EnumCodePages(iML2, flags, LANG_NEUTRAL, &iEnumCP);
509 ok(ret == S_OK && iEnumCP, "IMultiLanguage2_EnumCodePages: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumCP);
511 ret = IEnumCodePage_Reset(iEnumCP);
512 ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
513 n = 65536;
514 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, &n);
515 if (ret == S_FALSE)
516 ok(n == 0 && ret == S_FALSE, "IEnumCodePage_Next: expected 0/S_FALSE, got %u/%08x\n", n, ret);
517 else if (ret == E_FAIL)
518 ok(n == 65536 && ret == E_FAIL, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
519 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, NULL);
520 if (ret == S_FALSE)
521 ok(ret == S_FALSE, "IEnumCodePage_Next: expected S_FALSE, got %08x\n", ret);
522 else if (ret == E_FAIL)
523 ok(n == 65536 && ret == E_FAIL, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
525 cpinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*cpinfo) * total * 2);
527 n = total * 2;
528 ret = IEnumCodePage_Next(iEnumCP, 0, cpinfo, &n);
529 ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
531 n = total * 2;
532 ret = IEnumCodePage_Next(iEnumCP, n, cpinfo, &n);
533 ok(ret == S_OK && n != 0, "IEnumCodePage_Next: expected S_OK/!0, got %08x/%u\n", ret, n);
535 trace("flags %08x, enumerated codepages %u\n", flags, n);
537 if (!flags)
539 ok(n == total, "IEnumCodePage_Next: expected %u, got %u\n", total, n);
541 flags = MIMECONTF_MIME_LATEST;
544 total = n;
546 for (i = 0; i < n; i++)
548 CHARSETINFO csi;
549 MIMECSETINFO mcsi;
550 HRESULT convertible = S_OK;
551 static const WCHAR autoW[] = {'_','a','u','t','o',0};
552 static const WCHAR feffW[] = {'u','n','i','c','o','d','e','F','E','F','F',0};
554 #ifdef DUMP_CP_INFO
555 trace("MIMECPINFO #%u:\n"
556 "dwFlags %08x %s\n"
557 "uiCodePage %u\n"
558 "uiFamilyCodePage %u\n"
559 "wszDescription %s\n"
560 "wszWebCharset %s\n"
561 "wszHeaderCharset %s\n"
562 "wszBodyCharset %s\n"
563 "wszFixedWidthFont %s\n"
564 "wszProportionalFont %s\n"
565 "bGDICharset %d\n\n",
567 cpinfo[i].dwFlags, dump_mime_flags(cpinfo[i].dwFlags),
568 cpinfo[i].uiCodePage,
569 cpinfo[i].uiFamilyCodePage,
570 wine_dbgstr_w(cpinfo[i].wszDescription),
571 wine_dbgstr_w(cpinfo[i].wszWebCharset),
572 wine_dbgstr_w(cpinfo[i].wszHeaderCharset),
573 wine_dbgstr_w(cpinfo[i].wszBodyCharset),
574 wine_dbgstr_w(cpinfo[i].wszFixedWidthFont),
575 wine_dbgstr_w(cpinfo[i].wszProportionalFont),
576 cpinfo[i].bGDICharset);
577 #endif
578 ok(cpinfo[i].dwFlags & flags, "enumerated flags %08x do not include requested %08x\n", cpinfo[i].dwFlags, flags);
580 if (TranslateCharsetInfo((DWORD *)(INT_PTR)cpinfo[i].uiFamilyCodePage, &csi, TCI_SRCCODEPAGE))
581 ok(cpinfo[i].bGDICharset == csi.ciCharset, "%d != %d\n", cpinfo[i].bGDICharset, csi.ciCharset);
582 else
583 if (winetest_debug > 1)
584 trace("TranslateCharsetInfo failed for cp %u\n", cpinfo[i].uiFamilyCodePage);
586 #ifdef DUMP_CP_INFO
587 trace("%u: codepage %u family %u\n", i, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
588 #endif
589 /* Win95 does not support UTF-7 */
590 if (cpinfo[i].uiCodePage == CP_UTF7) continue;
592 /* support files for some codepages might be not installed, or
593 * the codepage is just an alias.
595 if (IsValidCodePage(cpinfo[i].uiCodePage))
597 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UNICODE);
598 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(%u -> CP_UNICODE) = %08x\n", cpinfo[i].uiCodePage, ret);
599 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, cpinfo[i].uiCodePage);
600 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
602 convertible = check_convertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
603 if (convertible != E_FAIL)
605 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
606 ok(ret == convertible, "IMultiLanguage2_IsConvertible(%u -> CP_UTF8) = %08x\n", cpinfo[i].uiCodePage, ret);
607 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, cpinfo[i].uiCodePage);
608 ok(ret == convertible, "IMultiLanguage2_IsConvertible(CP_UTF8 -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
611 else
612 if (winetest_debug > 1)
613 trace("IsValidCodePage failed for cp %u\n", cpinfo[i].uiCodePage);
615 if (memcmp(cpinfo[i].wszWebCharset,feffW,sizeof(WCHAR)*11)==0)
616 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
617 else
619 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszWebCharset, &mcsi);
620 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
621 if (memcmp(cpinfo[i].wszWebCharset, autoW, 5 * sizeof(WCHAR)))
623 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
624 #ifdef DUMP_CP_INFO
625 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszWebCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
626 #endif
627 ok(!lstrcmpiW(cpinfo[i].wszWebCharset, mcsi.wszCharset), "%s != %s\n",
628 wine_dbgstr_w(cpinfo[i].wszWebCharset), wine_dbgstr_w(mcsi.wszCharset));
630 if (0)
632 /* native mlang returns completely messed up encodings in some cases */
633 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
634 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
635 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
636 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
641 if (memcmp(cpinfo[i].wszHeaderCharset,feffW,sizeof(WCHAR)*11)==0)
642 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
643 else
645 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszHeaderCharset, &mcsi);
646 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
647 if (memcmp(cpinfo[i].wszHeaderCharset, autoW, 5 * sizeof(WCHAR)))
649 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
650 #ifdef DUMP_CP_INFO
651 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszHeaderCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
652 #endif
653 ok(!lstrcmpiW(cpinfo[i].wszHeaderCharset, mcsi.wszCharset), "%s != %s\n",
654 wine_dbgstr_w(cpinfo[i].wszHeaderCharset), wine_dbgstr_w(mcsi.wszCharset));
656 if (0)
658 /* native mlang returns completely messed up encodings in some cases */
659 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
660 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
661 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
662 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
667 if (memcmp(cpinfo[i].wszBodyCharset,feffW,sizeof(WCHAR)*11)==0)
668 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
669 else
671 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszBodyCharset, &mcsi);
672 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
673 if (memcmp(cpinfo[i].wszBodyCharset, autoW, 5 * sizeof(WCHAR)))
675 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
676 #ifdef DUMP_CP_INFO
677 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszBodyCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
678 #endif
679 ok(!lstrcmpiW(cpinfo[i].wszBodyCharset, mcsi.wszCharset), "%s != %s\n",
680 wine_dbgstr_w(cpinfo[i].wszBodyCharset), wine_dbgstr_w(mcsi.wszCharset));
682 if (0)
684 /* native mlang returns completely messed up encodings in some cases */
685 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
686 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
687 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
688 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
694 /* now IEnumCodePage_Next should fail, since pointer is at the end */
695 n = 1;
696 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
697 ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
699 ret = IEnumCodePage_Reset(iEnumCP);
700 ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
701 n = 0;
702 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
703 ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
704 cpinfo_cmp(&cpinfo[0], &cpinfo2);
706 if (0)
708 /* Due to a bug in MS' implementation of IEnumCodePage_Skip
709 * it's not used here.
711 ret = IEnumCodePage_Skip(iEnumCP, 1);
712 ok(ret == S_OK, "IEnumCodePage_Skip: expected S_OK, got %08x\n", ret);
714 for (i = 0; i < total - 1; i++)
716 n = 0;
717 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
718 ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
719 cpinfo_cmp(&cpinfo[i + 1], &cpinfo2);
722 HeapFree(GetProcessHeap(), 0, cpinfo);
723 IEnumCodePage_Release(iEnumCP);
726 static void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
728 ok(sinfo1->ScriptId == sinfo2->ScriptId, "ScriptId mismatch: %d != %d\n", sinfo1->ScriptId, sinfo2->ScriptId);
729 ok(sinfo1->uiCodePage == sinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", sinfo1->uiCodePage, sinfo2->uiCodePage);
730 ok(!lstrcmpW(sinfo1->wszDescription, sinfo2->wszDescription), "wszDescription mismatch\n");
731 ok(!lstrcmpW(sinfo1->wszFixedWidthFont, sinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
732 ok(!lstrcmpW(sinfo1->wszProportionalFont, sinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
735 static void test_EnumScripts(IMultiLanguage2 *iML2, DWORD flags)
737 IEnumScript *iEnumScript = NULL;
738 SCRIPTINFO *sinfo;
739 SCRIPTINFO sinfo2;
740 HRESULT ret;
741 ULONG i, n;
742 UINT total;
744 total = 0;
745 ret = IMultiLanguage2_GetNumberOfScripts(iML2, &total);
746 ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfScripts: expected S_OK/!0, got %08x/%u\n", ret, total);
748 trace("total mlang supported scripts %u\n", total);
750 ret = IMultiLanguage2_EnumScripts(iML2, flags, LANG_NEUTRAL, &iEnumScript);
751 ok(ret == S_OK && iEnumScript, "IMultiLanguage2_EnumScripts: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumScript);
753 ret = IEnumScript_Reset(iEnumScript);
754 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
755 n = 65536;
756 ret = IEnumScript_Next(iEnumScript, 0, NULL, &n);
757 ok(n == 65536 && ret == E_FAIL, "IEnumScript_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
758 ret = IEnumScript_Next(iEnumScript, 0, NULL, NULL);
759 ok(ret == E_FAIL, "IEnumScript_Next: expected E_FAIL, got %08x\n", ret);
761 sinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*sinfo) * total * 2);
763 n = total * 2;
764 ret = IEnumScript_Next(iEnumScript, 0, sinfo, &n);
765 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
767 n = total * 2;
768 ret = IEnumScript_Next(iEnumScript, n, sinfo, &n);
769 ok(ret == S_OK && n != 0, "IEnumScript_Next: expected S_OK, got %08x/%u\n", ret, n);
771 trace("flags %08x, enumerated scripts %u\n", flags, n);
773 if (!flags)
775 ok(n == total, "IEnumScript_Next: expected %u, got %u\n", total, n);
776 flags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
779 total = n;
781 for (i = 0; pGetCPInfoExA && i < n; i++)
783 #ifdef DUMP_SCRIPT_INFO
784 trace("SCRIPTINFO #%u:\n"
785 "ScriptId %08x\n"
786 "uiCodePage %u\n"
787 "wszDescription %s\n"
788 "wszFixedWidthFont %s\n"
789 "wszProportionalFont %s\n\n",
791 sinfo[i].ScriptId,
792 sinfo[i].uiCodePage,
793 wine_dbgstr_w(sinfo[i].wszDescription),
794 wine_dbgstr_w(sinfo[i].wszFixedWidthFont),
795 wine_dbgstr_w(sinfo[i].wszProportionalFont));
796 trace("%u codepage %u\n", i, sinfo[i].uiCodePage);
797 #endif
800 /* now IEnumScript_Next should fail, since pointer is at the end */
801 n = 1;
802 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
803 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
805 ret = IEnumScript_Reset(iEnumScript);
806 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
807 n = 0;
808 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
809 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
810 scriptinfo_cmp(&sinfo[0], &sinfo2);
812 if (0)
814 /* Due to a bug in MS' implementation of IEnumScript_Skip
815 * it's not used here.
817 ret = IEnumScript_Skip(iEnumScript, 1);
818 ok(ret == S_OK, "IEnumScript_Skip: expected S_OK, got %08x\n", ret);
820 for (i = 0; i < total - 1; i++)
822 n = 0;
823 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
824 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
825 scriptinfo_cmp(&sinfo[i + 1], &sinfo2);
828 HeapFree(GetProcessHeap(), 0, sinfo);
829 IEnumScript_Release(iEnumScript);
832 static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
834 DWORD dwCodePages, dwManyCodePages;
835 DWORD dwCmpCodePages;
836 UINT CodePage;
837 static const WCHAR str[3] = { 'd', 0x0436, 0xff90 };
838 LONG processed;
839 HRESULT ret;
841 dwCodePages = ~0u;
842 ret = IMLangFontLink_CodePageToCodePages(iMLFL, -1, &dwCodePages);
843 ok(ret == E_FAIL, "IMLangFontLink_CodePageToCodePages should fail: %x\n", ret);
844 ok(dwCodePages == 0, "expected 0, got %u\n", dwCodePages);
846 dwCodePages = 0;
847 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 932, &dwCodePages);
848 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
849 ok(dwCodePages == FS_JISJAPAN, "expected FS_JISJAPAN, got %08x\n", dwCodePages);
850 CodePage = 0;
851 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwCodePages, 1035, &CodePage);
852 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
853 ok(CodePage == 932, "Incorrect CodePage Returned (%i)\n",CodePage);
855 dwManyCodePages = 0;
856 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1252, &dwManyCodePages);
857 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
858 ok(dwManyCodePages == FS_LATIN1, "expected FS_LATIN1, got %08x\n", dwManyCodePages);
859 dwCodePages = 0;
860 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1256, &dwCodePages);
861 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
862 ok(dwCodePages == FS_ARABIC, "expected FS_ARABIC, got %08x\n", dwCodePages);
863 dwManyCodePages |= dwCodePages;
864 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 874, &dwCodePages);
865 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
866 ok(dwCodePages == FS_THAI, "expected FS_THAI, got %08x\n", dwCodePages);
867 dwManyCodePages |= dwCodePages;
869 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 1256, &CodePage);
870 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
871 ok(CodePage == 1256, "Incorrect CodePage Returned (%i)\n",CodePage);
873 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 936, &CodePage);
874 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
875 ok(CodePage == 1252, "Incorrect CodePage Returned (%i)\n",CodePage);
877 /* Tests for GetCharCodePages */
879 /* Latin 1 */
880 dwCmpCodePages = FS_LATIN1 | FS_LATIN2 | FS_CYRILLIC | FS_GREEK | FS_TURKISH
881 | FS_HEBREW | FS_ARABIC | FS_BALTIC | FS_VIETNAMESE | FS_THAI
882 | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG | FS_CHINESETRAD;
883 ret = IMLangFontLink_GetCharCodePages(iMLFL, 'd', &dwCodePages);
884 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
885 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
887 dwCodePages = 0;
888 processed = 0;
889 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[0], 1, 0, &dwCodePages, &processed);
890 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
891 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
892 ok(processed == 1, "expected 1, got %d\n", processed);
894 /* Cyrillic */
895 dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
896 ret = IMLangFontLink_GetCharCodePages(iMLFL, 0x0436, &dwCodePages);
897 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
898 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
900 dwCodePages = 0;
901 processed = 0;
902 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[1], 1, 0, &dwCodePages, &processed);
903 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
904 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
905 ok(processed == 1, "expected 1, got %d\n", processed);
907 /* Japanese */
908 dwCmpCodePages = FS_JISJAPAN;
909 ret = IMLangFontLink_GetCharCodePages(iMLFL, 0xff90, &dwCodePages);
910 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
911 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
913 dwCodePages = 0;
914 processed = 0;
915 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
916 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
917 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
918 ok(processed == 1, "expected 1, got %d\n", processed);
920 dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
921 dwCodePages = 0;
922 processed = 0;
923 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 2, 0, &dwCodePages, &processed);
924 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
925 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
926 ok(processed == 2, "expected 2, got %d\n", processed);
928 dwCmpCodePages = FS_JISJAPAN;
929 dwCodePages = 0;
930 processed = 0;
931 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 3, 0, &dwCodePages, &processed);
932 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
933 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
934 ok(processed == 3, "expected 3, got %d\n", processed);
936 dwCodePages = 0xffff;
937 processed = -1;
938 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
939 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
940 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
941 ok(processed == 1, "expected 0, got %d\n", processed);
943 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, NULL, NULL);
944 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
946 dwCodePages = 0xffff;
947 processed = -1;
948 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, -1, 0, &dwCodePages, &processed);
949 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
950 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
951 ok(processed == 0, "expected 0, got %d\n", processed);
953 dwCodePages = 0xffff;
954 processed = -1;
955 ret = IMLangFontLink_GetStrCodePages(iMLFL, NULL, 1, 0, &dwCodePages, &processed);
956 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
957 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
958 ok(processed == 0, "expected 0, got %d\n", processed);
960 dwCodePages = 0xffff;
961 processed = -1;
962 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 0, 0, &dwCodePages, &processed);
963 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
964 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
965 ok(processed == 0, "expected 0, got %d\n", processed);
968 /* copied from libs/wine/string.c */
969 static WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
971 while (*str)
973 const WCHAR *p1 = str, *p2 = sub;
974 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
975 if (!*p2) return (WCHAR *)str;
976 str++;
978 return NULL;
981 static void test_rfc1766(IMultiLanguage2 *iML2)
983 IEnumRfc1766 *pEnumRfc1766;
984 RFC1766INFO info;
985 ULONG n;
986 HRESULT ret;
987 BSTR rfcstr;
989 ret = IMultiLanguage2_EnumRfc1766(iML2, LANG_NEUTRAL, &pEnumRfc1766);
990 ok(ret == S_OK, "IMultiLanguage2_EnumRfc1766 error %08x\n", ret);
992 while (1)
994 ret = IEnumRfc1766_Next(pEnumRfc1766, 1, &info, &n);
995 if (ret != S_OK) break;
997 #ifdef DUMP_CP_INFO
998 trace("lcid %04x rfc_name %s locale_name %s\n",
999 info.lcid, wine_dbgstr_w(info.wszRfc1766), wine_dbgstr_w(info.wszLocaleName));
1000 #endif
1002 ok(n == 1, "couldn't fetch 1 RFC1766INFO structure\n");
1004 /* verify the Rfc1766 value */
1005 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, info.lcid, &rfcstr);
1006 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1008 /* not an exact 1:1 correspondence between lcid and rfc1766 in the
1009 * mlang database, e.g., nb-no -> 1044 -> no */
1010 ok(strstrW(info.wszRfc1766, rfcstr) != NULL,
1011 "Expected matching locale names\n");
1013 SysFreeString(rfcstr);
1015 IEnumRfc1766_Release(pEnumRfc1766);
1018 static void test_GetLcidFromRfc1766(IMultiLanguage2 *iML2)
1020 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1021 LCID lcid;
1022 HRESULT ret;
1023 DWORD i;
1025 static WCHAR en[] = { 'e','n',0 };
1026 static WCHAR en_them[] = { 'e','n','-','t','h','e','m',0 };
1027 static WCHAR english[] = { 'e','n','g','l','i','s','h',0 };
1030 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1031 lcid = -1;
1032 MultiByteToWideChar(CP_ACP, 0, lcid_table[i].rfc1766, -1, rfc1766W, MAX_RFC1766_NAME);
1033 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, rfc1766W);
1035 /* IE <6.0 guess 0x412 (ko) from "kok" */
1036 ok((ret == lcid_table[i].hr) ||
1037 broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1038 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1040 ok((lcid == lcid_table[i].lcid) ||
1041 broken(lcid == lcid_table[i].broken_lcid), /* IE <6.0 */
1042 "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1046 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, NULL, en);
1047 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1049 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, NULL);
1050 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1052 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_them);
1053 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1054 if (ret == S_FALSE)
1056 BSTR rfcstr;
1057 static WCHAR en[] = {'e','n',0};
1059 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1060 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1061 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
1064 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, english);
1065 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1066 if (ret == S_FALSE)
1068 BSTR rfcstr;
1069 static WCHAR en[] = {'e','n',0};
1071 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1072 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1073 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
1078 static void test_Rfc1766ToLcid(void)
1080 LCID lcid;
1081 HRESULT ret;
1082 DWORD i;
1084 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1085 lcid = -1;
1086 ret = pRfc1766ToLcidA(&lcid, lcid_table[i].rfc1766);
1088 /* IE <6.0 guess 0x412 (ko) from "kok" */
1089 ok( (ret == lcid_table[i].hr) ||
1090 broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1091 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1093 ok( (lcid == lcid_table[i].lcid) ||
1094 broken(lcid == lcid_table[i].broken_lcid), /* IE <6.0 */
1095 "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1098 ret = pRfc1766ToLcidA(&lcid, NULL);
1099 ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1101 ret = pRfc1766ToLcidA(NULL, "en");
1102 ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1105 static void test_GetNumberOfCodePageInfo(IMultiLanguage2 *iML2)
1107 HRESULT hr;
1108 UINT value;
1110 value = 0xdeadbeef;
1111 hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &value);
1112 ok( (hr == S_OK) && value,
1113 "got 0x%x with %d (expected S_OK with '!= 0')\n", hr, value);
1115 hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, NULL);
1116 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1120 static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
1122 CHAR expected[MAX_RFC1766_NAME];
1123 CHAR buffer[MAX_RFC1766_NAME + 1];
1124 DWORD i;
1125 HRESULT hr;
1126 BSTR rfcstr;
1128 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1129 buffer[0] = '\0';
1131 rfcstr = NULL;
1132 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid_table[i].lcid, &rfcstr);
1133 ok(hr == lcid_table[i].hr,
1134 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1136 if (hr != S_OK)
1137 continue; /* no result-string created */
1139 WideCharToMultiByte(CP_ACP, 0, rfcstr, -1, buffer, sizeof(buffer), NULL, NULL);
1140 LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1141 lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1143 /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1144 ok( (!lstrcmpA(buffer, expected)) ||
1145 broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1146 "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1148 SysFreeString(rfcstr);
1151 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL);
1152 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1155 static void test_LcidToRfc1766(void)
1157 CHAR expected[MAX_RFC1766_NAME];
1158 CHAR buffer[MAX_RFC1766_NAME * 2];
1159 HRESULT hr;
1160 DWORD i;
1162 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1164 memset(buffer, '#', sizeof(buffer)-1);
1165 buffer[sizeof(buffer)-1] = '\0';
1167 hr = pLcidToRfc1766A(lcid_table[i].lcid, buffer, MAX_RFC1766_NAME);
1169 /* IE <5.0 does not recognize 0x180c (fr-mc) and 0x457 (kok) */
1170 ok( (hr == lcid_table[i].hr) ||
1171 broken(lcid_table[i].broken_lcid && (hr == E_FAIL)),
1172 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1174 if (hr != S_OK)
1175 continue;
1177 LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1178 lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1180 /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1181 /* IE <5.0 return "fr" for LCID 0x180c ("fr-mc") */
1182 ok( (!lstrcmpA(buffer, expected)) ||
1183 broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1184 "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1188 memset(buffer, '#', sizeof(buffer)-1);
1189 buffer[sizeof(buffer)-1] = '\0';
1190 hr = pLcidToRfc1766A(-1, buffer, MAX_RFC1766_NAME);
1191 ok(hr == E_FAIL, "got 0x%08x and '%s' (expected E_FAIL)\n", hr, buffer);
1193 hr = pLcidToRfc1766A(LANG_ENGLISH, NULL, MAX_RFC1766_NAME);
1194 ok(hr == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", hr);
1196 memset(buffer, '#', sizeof(buffer)-1);
1197 buffer[sizeof(buffer)-1] = '\0';
1198 hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, -1);
1199 ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1201 memset(buffer, '#', sizeof(buffer)-1);
1202 buffer[sizeof(buffer)-1] = '\0';
1203 hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, 0);
1204 ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1207 static void test_GetRfc1766Info(IMultiLanguage2 *iML2)
1209 WCHAR short_broken_name[MAX_LOCALE_NAME];
1210 CHAR rfc1766A[MAX_RFC1766_NAME + 1];
1211 BYTE buffer[sizeof(RFC1766INFO) + 4];
1212 PRFC1766INFO prfc = (RFC1766INFO *) buffer;
1213 HRESULT ret;
1214 DWORD i;
1216 for(i = 0; i < sizeof(info_table) / sizeof(info_table[0]); i++) {
1217 memset(buffer, 'x', sizeof(RFC1766INFO) + 2);
1218 buffer[sizeof(buffer) -1] = 0;
1219 buffer[sizeof(buffer) -2] = 0;
1221 ret = IMultiLanguage2_GetRfc1766Info(iML2, info_table[i].lcid, info_table[i].lang, prfc);
1222 WideCharToMultiByte(CP_ACP, 0, prfc->wszRfc1766, -1, rfc1766A, MAX_RFC1766_NAME, NULL, NULL);
1223 ok(ret == S_OK, "#%02d: got 0x%x (expected S_OK)\n", i, ret);
1224 ok(prfc->lcid == info_table[i].lcid,
1225 "#%02d: got 0x%04x (expected 0x%04x)\n", i, prfc->lcid, info_table[i].lcid);
1227 ok(!lstrcmpA(rfc1766A, info_table[i].rfc1766),
1228 "#%02d: got '%s' (expected '%s')\n", i, rfc1766A, info_table[i].rfc1766);
1230 /* Some IE versions truncate an oversized name one character to short */
1231 mylstrcpyW(short_broken_name, info_table[i].broken_name);
1232 short_broken_name[MAX_LOCALE_NAME - 2] = '\0';
1234 if (info_table[i].todo & TODO_NAME) {
1235 todo_wine
1236 ok( (!mylstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1237 broken(!mylstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1238 broken(!mylstrcmpW(prfc->wszLocaleName, short_broken_name)),
1239 "#%02d: got %s (expected %s)\n", i,
1240 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1242 else
1243 ok( (!mylstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1244 broken(!mylstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1245 broken(!mylstrcmpW(prfc->wszLocaleName, short_broken_name)),
1246 "#%02d: got %s (expected %s)\n", i,
1247 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1251 /* SUBLANG_NEUTRAL only allowed for english, arabic, chinese */
1252 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_GERMAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1253 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1255 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_ITALIAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1256 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1258 /* NULL not allowed */
1259 ret = IMultiLanguage2_GetRfc1766Info(iML2, 0, LANG_ENGLISH, prfc);
1260 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1262 ret = IMultiLanguage2_GetRfc1766Info(iML2, LANG_ENGLISH, LANG_ENGLISH, NULL);
1263 ok(ret == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", ret);
1266 static void test_IMultiLanguage2_ConvertStringFromUnicode(IMultiLanguage2 *iML2)
1268 CHAR dest[MAX_PATH];
1269 CHAR invariate[MAX_PATH];
1270 UINT srcsz, destsz;
1271 HRESULT hr;
1273 static WCHAR src[] = {'a','b','c',0};
1275 memset(invariate, 'x', sizeof(invariate));
1277 /* pSrcStr NULL */
1278 memset(dest, 'x', sizeof(dest));
1279 srcsz = lstrlenW(src) + 1;
1280 destsz = sizeof(dest);
1281 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1282 &srcsz, dest, &destsz);
1283 ok(hr == S_OK || hr == E_FAIL,"expected S_OK or E_FAIL, got %08x\n",hr);
1284 if (hr == S_OK)
1286 ok(srcsz == lstrlenW(src) + 1,
1287 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1289 else if (hr == E_FAIL)
1291 ok(srcsz == 0,
1292 "Expected %u, got %u\n", 0, srcsz);
1295 ok(!memcmp(dest, invariate, sizeof(dest)),
1296 "Expected dest to be unchanged, got %s\n", dest);
1297 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1299 /* pcSrcSize NULL */
1300 memset(dest, 'x', sizeof(dest));
1301 destsz = sizeof(dest);
1302 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1303 NULL, dest, &destsz);
1304 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1305 ok(!strncmp(dest, "abc", 3),
1306 "Expected first three chars to be \"abc\"\n");
1307 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1308 "Expected rest of dest to be unchanged, got %s\n", dest);
1309 ok(destsz == lstrlenW(src),
1310 "Expected %u, got %u\n", lstrlenW(src), destsz);
1312 /* both pSrcStr and pcSrcSize NULL */
1313 memset(dest, 'x', sizeof(dest));
1314 destsz = sizeof(dest);
1315 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1316 NULL, dest, &destsz);
1317 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1318 ok(!memcmp(dest, invariate, sizeof(dest)),
1319 "Expected dest to be unchanged, got %s\n", dest);
1320 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1322 /* pDstStr NULL */
1323 memset(dest, 'x', sizeof(dest));
1324 srcsz = lstrlenW(src) + 1;
1325 destsz = sizeof(dest);
1326 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1327 &srcsz, NULL, &destsz);
1328 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1329 ok(srcsz == lstrlenW(src) + 1,
1330 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1331 ok(destsz == lstrlenW(src) + 1,
1332 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1334 /* pcDstSize NULL */
1335 memset(dest, 'x', sizeof(dest));
1336 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1337 &srcsz, dest, NULL);
1338 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1339 ok(srcsz == lstrlenW(src) + 1,
1340 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1341 ok(!memcmp(dest, invariate, sizeof(dest)),
1342 "Expected dest to be unchanged, got %s\n", dest);
1344 /* pcSrcSize is 0 */
1345 memset(dest, 'x', sizeof(dest));
1346 srcsz = 0;
1347 destsz = sizeof(dest);
1348 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1349 &srcsz, dest, &destsz);
1350 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1351 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1352 ok(!memcmp(dest, invariate, sizeof(dest)),
1353 "Expected dest to be unchanged, got %s\n", dest);
1354 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1356 /* pcSrcSize does not include NULL terminator */
1357 memset(dest, 'x', sizeof(dest));
1358 srcsz = lstrlenW(src);
1359 destsz = sizeof(dest);
1360 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1361 &srcsz, dest, &destsz);
1362 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1363 ok(srcsz == lstrlenW(src),
1364 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1365 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1366 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1367 "Expected rest of dest to be unchanged, got %s\n", dest);
1368 ok(destsz == lstrlenW(src),
1369 "Expected %u, got %u\n", lstrlenW(src), destsz);
1371 /* pcSrcSize includes NULL terminator */
1372 memset(dest, 'x', sizeof(dest));
1373 srcsz = lstrlenW(src) + 1;
1374 destsz = sizeof(dest);
1375 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1376 &srcsz, dest, &destsz);
1377 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1378 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1379 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1380 ok(destsz == lstrlenW(src) + 1,
1381 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1383 /* pcSrcSize is -1 */
1384 memset(dest, 'x', sizeof(dest));
1385 srcsz = -1;
1386 destsz = sizeof(dest);
1387 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1388 &srcsz, dest, &destsz);
1389 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1390 ok(srcsz == lstrlenW(src),
1391 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1392 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1393 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1394 "Expected rest of dest to be unchanged, got %s\n", dest);
1395 ok(destsz == lstrlenW(src),
1396 "Expected %u, got %u\n", lstrlenW(src), destsz);
1398 /* pcDstSize is 0 */
1399 memset(dest, 'x', sizeof(dest));
1400 srcsz = lstrlenW(src) + 1;
1401 destsz = 0;
1402 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1403 &srcsz, dest, &destsz);
1404 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1405 ok(srcsz == lstrlenW(src) + 1,
1406 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1407 ok(!memcmp(dest, invariate, sizeof(dest)),
1408 "Expected dest to be unchanged, got %s\n", dest);
1409 ok(destsz == lstrlenW(src) + 1,
1410 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1412 /* pcDstSize is not large enough */
1413 memset(dest, 'x', sizeof(dest));
1414 srcsz = lstrlenW(src) + 1;
1415 destsz = lstrlenW(src);
1416 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1417 &srcsz, dest, &destsz);
1418 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1419 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1420 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1421 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1422 "Expected rest of dest to be unchanged, got %s\n", dest);
1423 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1425 /* pcDstSize (bytes) does not leave room for NULL terminator */
1426 memset(dest, 'x', sizeof(dest));
1427 srcsz = lstrlenW(src) + 1;
1428 destsz = lstrlenW(src) * sizeof(WCHAR);
1429 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1430 &srcsz, dest, &destsz);
1431 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1432 ok(srcsz == lstrlenW(src) + 1,
1433 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1434 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1435 ok(destsz == lstrlenW(src) + 1,
1436 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1439 static void test_ConvertINetUnicodeToMultiByte(void)
1441 CHAR dest[MAX_PATH];
1442 CHAR invariate[MAX_PATH];
1443 INT srcsz, destsz;
1444 HRESULT hr;
1446 static WCHAR src[] = {'a','b','c',0};
1448 memset(invariate, 'x', sizeof(invariate));
1450 /* lpSrcStr NULL */
1451 memset(dest, 'x', sizeof(dest));
1452 srcsz = lstrlenW(src) + 1;
1453 destsz = sizeof(dest);
1454 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, &srcsz, dest, &destsz);
1455 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1456 if (hr == S_OK)
1457 ok(srcsz == lstrlenW(src) + 1,
1458 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1459 else if (hr == E_FAIL)
1460 ok(srcsz == 0,
1461 "Expected %u, got %u\n", 0, srcsz);
1462 ok(!memcmp(dest, invariate, sizeof(dest)),
1463 "Expected dest to be unchanged, got %s\n", dest);
1464 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1466 /* lpnWideCharCount NULL */
1467 memset(dest, 'x', sizeof(dest));
1468 destsz = sizeof(dest);
1469 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, NULL, dest, &destsz);
1470 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1471 ok(!strncmp(dest, "abc", 3),
1472 "Expected first three chars to be \"abc\"\n");
1473 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1474 "Expected rest of dest to be unchanged, got %s\n", dest);
1475 ok(destsz == lstrlenW(src),
1476 "Expected %u, got %u\n", lstrlenW(src), destsz);
1478 /* both lpSrcStr and lpnWideCharCount NULL */
1479 memset(dest, 'x', sizeof(dest));
1480 destsz = sizeof(dest);
1481 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, NULL, dest, &destsz);
1482 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1483 ok(!memcmp(dest, invariate, sizeof(dest)),
1484 "Expected dest to be unchanged, got %s\n", dest);
1485 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1487 /* lpDstStr NULL */
1488 memset(dest, 'x', sizeof(dest));
1489 srcsz = lstrlenW(src) + 1;
1490 destsz = sizeof(dest);
1491 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, NULL, &destsz);
1492 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1493 ok(srcsz == lstrlenW(src) + 1,
1494 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1495 ok(destsz == lstrlenW(src) + 1,
1496 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1498 /* lpnMultiCharCount NULL */
1499 memset(dest, 'x', sizeof(dest));
1500 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, NULL);
1501 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1502 ok(srcsz == lstrlenW(src) + 1,
1503 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1504 ok(!memcmp(dest, invariate, sizeof(dest)),
1505 "Expected dest to be unchanged, got %s\n", dest);
1507 /* lpnWideCharCount is 0 */
1508 memset(dest, 'x', sizeof(dest));
1509 srcsz = 0;
1510 destsz = sizeof(dest);
1511 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1512 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1513 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1514 ok(!memcmp(dest, invariate, sizeof(dest)),
1515 "Expected dest to be unchanged, got %s\n", dest);
1516 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1518 /* lpnWideCharCount does not include NULL terminator */
1519 memset(dest, 'x', sizeof(dest));
1520 srcsz = lstrlenW(src);
1521 destsz = sizeof(dest);
1522 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1523 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1524 ok(srcsz == lstrlenW(src),
1525 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1526 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1527 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1528 "Expected rest of dest to be unchanged, got %s\n", dest);
1529 ok(destsz == lstrlenW(src),
1530 "Expected %u, got %u\n", lstrlenW(src), destsz);
1532 /* lpnWideCharCount includes NULL terminator */
1533 memset(dest, 'x', sizeof(dest));
1534 srcsz = lstrlenW(src) + 1;
1535 destsz = sizeof(dest);
1536 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1537 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1538 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1539 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1540 ok(destsz == lstrlenW(src) + 1,
1541 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1543 /* lpnWideCharCount is -1 */
1544 memset(dest, 'x', sizeof(dest));
1545 srcsz = -1;
1546 destsz = sizeof(dest);
1547 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1548 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1549 ok(srcsz == lstrlenW(src),
1550 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1551 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1552 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1553 "Expected rest of dest to be unchanged, got %s\n", dest);
1554 ok(destsz == lstrlenW(src),
1555 "Expected %u, got %u\n", lstrlenW(src), destsz);
1557 /* lpnMultiCharCount is 0 */
1558 memset(dest, 'x', sizeof(dest));
1559 srcsz = lstrlenW(src) + 1;
1560 destsz = 0;
1561 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1562 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1563 ok(srcsz == lstrlenW(src) + 1,
1564 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1565 ok(!memcmp(dest, invariate, sizeof(dest)),
1566 "Expected dest to be unchanged, got %s\n", dest);
1567 ok(destsz == lstrlenW(src) + 1,
1568 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1570 /* lpnMultiCharCount is not large enough */
1571 memset(dest, 'x', sizeof(dest));
1572 srcsz = lstrlenW(src) + 1;
1573 destsz = lstrlenW(src);
1574 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1575 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1576 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1577 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1578 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1579 "Expected rest of dest to be unchanged, got %s\n", dest);
1580 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1582 /* lpnMultiCharCount (bytes) does not leave room for NULL terminator */
1583 memset(dest, 'x', sizeof(dest));
1584 srcsz = lstrlenW(src) + 1;
1585 destsz = lstrlenW(src) * sizeof(WCHAR);
1586 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1587 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1588 ok(srcsz == lstrlenW(src) + 1,
1589 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1590 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1591 ok(destsz == lstrlenW(src) + 1,
1592 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1595 static void test_JapaneseConversion(void)
1597 /* Data */
1598 static WCHAR unc_jp[9][12] = {
1599 {9,0x31,0x20,0x3042,0x3044,0x3046,0x3048,0x304a,0x000d,0x000a},
1600 {9,0x31,0x20,0x30a2,0x30a4,0x30a6,0x30a8,0x30aa,0x000d,0x000a},
1601 {9,0x31,0x20,0xff71,0xff72,0xff73,0xff74,0xff75,0x000d,0x000a},
1602 {9,0x31,0x20,0x3041,0x3043,0x3045,0x3047,0x3049,0x000d,0x000a},
1603 {9,0x31,0x20,0x30a1,0x30a3,0x30a5,0x30a7,0x30a9,0x000d,0x000a},
1604 {9,0x31,0x20,0xff67,0xff68,0xff69,0xff6a,0xff6b,0x000d,0x000a},
1605 {9,0x31,0x20,0x300c,0x65e5,0x672c,0x8a9e,0x300d,0x000d,0x000a},
1606 {7,0x31,0x20,0x25c7,0x25c7,0x3012,0x000d,0x000a},
1607 {11,0x31,0x20,0x203b,0x3010,0x0074,0x0065,0x0073,0x0074,0x3011,0x000d,0x000a}
1609 static CHAR jis_jp[9][27] = {
1610 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x22,0x24,0x24,0x24,0x26,0x24,0x28,
1611 0x24,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1612 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1613 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1614 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1615 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1616 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x21,0x24,0x23,0x24,0x25,0x24,0x27,
1617 0x24,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1618 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1619 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1620 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1621 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1622 {20,0x31,0x20,0x1b,0x24,0x42,0x21,0x56,0x46,0x7c,0x4b,0x5c,0x38,0x6c,
1623 0x21,0x57,0x1b,0x28,0x42,0x0d,0x0a},
1624 {16,0x31,0x20,0x1b,0x24,0x42,0x21,0x7e,0x21,0x7e,0x22,0x29,0x1b,0x28,
1625 0x42,0x0d,0x0a},
1626 {26,0x31,0x20,0x1b,0x24,0x42,0x22,0x28,0x21,0x5a,0x1b,0x28,0x42,0x74,
1627 0x65,0x73,0x74,0x1b,0x24,0x42,0x21,0x5b,0x1b,0x28,0x42,0x0d,0x0a}
1629 static CHAR sjis_jp[9][15] = {
1630 {14,0x31,0x20,0x82,0xa0,0x82,0xa2,0x82,0xa4,0x82,0xa6,0x82,0xa8,0x0d,0x0a},
1631 {14,0x31,0x20,0x83,0x41,0x83,0x43,0x83,0x45,0x83,0x47,0x83,0x49,0x0d,0x0a},
1632 {9,0x31,0x20,0xb1,0xb2,0xb3,0xb4,0xb5,0x0d,0x0a},
1633 {14,0x31,0x20,0x82,0x9f,0x82,0xa1,0x82,0xa3,0x82,0xa5,0x82,0xa7,0x0d,0x0a},
1634 {14,0x31,0x20,0x83,0x40,0x83,0x42,0x83,0x44,0x83,0x46,0x83,0x48,0x0d,0x0a},
1635 {9,0x31,0x20,0xa7,0xa8,0xa9,0xaa,0xab,0x0d,0x0a},
1636 {14,0x31,0x20,0x81,0x75,0x93,0xfa,0x96,0x7b,0x8c,0xea,0x81,0x76,0x0d,0x0a},
1637 {10,0x31,0x20,0x81,0x9e,0x81,0x9e,0x81,0xa7,0x0d,0x0a},
1638 {14,0x31,0x20,0x81,0xa6,0x81,0x79,0x74,0x65,0x73,0x74,0x81,0x7a,0x0d,0x0a}
1640 static CHAR euc_jp[9][15] = {
1641 {14,0x31,0x20,0xa4,0xa2,0xa4,0xa4,0xa4,0xa6,0xa4,0xa8,0xa4,0xaa,0x0d,0x0a},
1642 {14,0x31,0x20,0xa5,0xa2,0xa5,0xa4,0xa5,0xa6,0xa5,0xa8,0xa5,0xaa,0x0d,0x0a},
1643 {14,0x31,0x20,0x8e,0xb1,0x8e,0xb2,0x8e,0xb3,0x8e,0xb4,0x8e,0xb5,0x0d,0x0a},
1644 {14,0x31,0x20,0xa4,0xa1,0xa4,0xa3,0xa4,0xa5,0xa4,0xa7,0xa4,0xa9,0x0d,0x0a},
1645 {14,0x31,0x20,0xa5,0xa1,0xa5,0xa3,0xa5,0xa5,0xa5,0xa7,0xa5,0xa9,0x0d,0x0a},
1646 {14,0x31,0x20,0x8e,0xa7,0x8e,0xa8,0x8e,0xa9,0x8e,0xaa,0x8e,0xab,0x0d,0x0a},
1647 {14,0x31,0x20,0xa1,0xd6,0xc6,0xfc,0xcb,0xdc,0xb8,0xec,0xa1,0xd7,0x0d,0x0a},
1648 {10,0x31,0x20,0xa1,0xfe,0xa1,0xfe,0xa2,0xa9,0x0d,0x0a},
1649 {14,0x31,0x20,0xa2,0xa8,0xa1,0xda,0x74,0x65,0x73,0x74,0xa1,0xdb,0x0d,0x0a}
1652 INT srcsz, destsz;
1653 INT i;
1654 HRESULT hr;
1655 CHAR output[30];
1656 WCHAR outputW[30];
1657 int outlen;
1659 /* test unc->jis */
1660 for (i = 0; i < 9; i++)
1662 int j;
1663 destsz = 30;
1664 outlen = jis_jp[i][0];
1665 srcsz = unc_jp[i][0];
1666 hr = pConvertINetUnicodeToMultiByte(NULL, 50220, &unc_jp[i][1], &srcsz, output, &destsz);
1667 if (hr == S_FALSE)
1669 skip("Code page identifier 50220 is not supported\n");
1670 break;
1672 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1673 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1674 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1675 ok(memcmp(output,&jis_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1677 /* and back */
1678 srcsz = outlen;
1679 destsz = 30;
1680 hr = pConvertINetMultiByteToUnicode(NULL, 50220, output, &srcsz, outputW,&destsz);
1683 * JIS does not have hankata so it get automatically converted to
1684 * zenkata. this means that strings 1 and 2 are identical as well as
1685 * strings 4 and 5.
1687 j = i;
1688 if (i == 2) j = 1;
1689 if (i == 5) j = 4;
1691 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i, hr);
1692 ok(destsz == unc_jp[j][0],"(%i) Expected %i, got %i\n",i,unc_jp[j][0],destsz);
1693 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1694 ok(memcmp(outputW,&unc_jp[j][1],destsz)==0,"(%i) Strings do not match\n",i);
1697 /* test unc->sjis */
1698 for (i = 0; i < 9; i++)
1700 destsz = 30;
1701 outlen = sjis_jp[i][0];
1702 srcsz = unc_jp[i][0];
1704 hr = pConvertINetUnicodeToMultiByte(NULL, 932, &unc_jp[i][1], &srcsz, output, &destsz);
1705 if (hr == S_FALSE)
1707 skip("Code page identifier 932 is not supported\n");
1708 break;
1710 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1711 ok(destsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,destsz);
1712 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1713 ok(memcmp(output,&sjis_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1715 srcsz = outlen;
1716 destsz = 30;
1717 hr = pConvertINetMultiByteToUnicode(NULL, 932, output, &srcsz, outputW,&destsz);
1719 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1720 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1721 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1722 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1725 /* test unc->euc */
1726 for (i = 0; i < 9; i++)
1728 destsz = 30;
1729 outlen = euc_jp[i][0];
1730 srcsz = unc_jp[i][0];
1732 hr = pConvertINetUnicodeToMultiByte(NULL, 51932, &unc_jp[i][1], &srcsz, output, &destsz);
1733 if (hr == S_FALSE)
1735 skip("Code page identifier 51932 is not supported\n");
1736 break;
1738 ok(hr == S_OK, "(%i) Expected S_OK, got %08x\n",i,hr);
1739 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1740 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1741 ok(memcmp(output,&euc_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1743 srcsz = outlen;
1744 destsz = 30;
1745 hr = pConvertINetMultiByteToUnicode(NULL, 51932, output, &srcsz, outputW,&destsz);
1747 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1748 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1749 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1750 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1753 /* Japanese autodetect */
1754 i = 0;
1755 destsz = 30;
1756 srcsz = jis_jp[i][0];
1757 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &jis_jp[i][1], &srcsz, outputW, &destsz);
1758 if (hr == S_FALSE)
1760 skip("Code page identifier 50932 is not supported\n");
1761 return;
1763 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1764 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1765 ok(srcsz == jis_jp[i][0],"(%i) Expected %i, got %i\n",i,jis_jp[i][0],srcsz);
1766 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1768 i = 1;
1769 destsz = 30;
1770 srcsz = sjis_jp[i][0];
1771 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &sjis_jp[i][1], &srcsz, outputW, &destsz);
1772 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1773 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1774 ok(srcsz == sjis_jp[i][0],"(%i) Expected %i, got %i\n",i,sjis_jp[i][0],srcsz);
1775 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1778 static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
1780 HRESULT hr;
1781 UINT nfonts;
1782 SCRIPTFONTINFO sfi[1];
1784 nfonts = 0;
1785 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, 0, &nfonts, NULL);
1786 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1787 ok(nfonts, "unexpected result\n");
1789 nfonts = 0;
1790 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, NULL);
1791 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1792 ok(nfonts, "unexpected result\n");
1794 nfonts = 0;
1795 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, NULL);
1796 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1797 ok(nfonts, "unexpected result\n");
1799 nfonts = 1;
1800 memset(sfi, 0, sizeof(sfi));
1801 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, sfi);
1802 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1803 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1804 ok(sfi[0].scripts != 0, "unexpected result\n");
1805 ok(sfi[0].wszFont[0], "unexpected result\n");
1807 nfonts = 1;
1808 memset(sfi, 0, sizeof(sfi));
1809 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, sfi);
1810 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1811 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1812 ok(sfi[0].scripts != 0, "unexpected result\n");
1813 ok(sfi[0].wszFont[0], "unexpected result\n");
1816 static void test_CodePageToScriptID(IMLangFontLink2 *font_link)
1818 HRESULT hr;
1819 UINT i;
1820 SCRIPT_ID sid;
1821 static const struct
1823 UINT cp;
1824 SCRIPT_ID sid;
1825 HRESULT hr;
1827 cp_sid[] =
1829 {874, sidThai},
1830 {932, sidKana},
1831 {936, sidHan},
1832 {949, sidHangul},
1833 {950, sidBopomofo},
1834 {1250, sidAsciiLatin},
1835 {1251, sidCyrillic},
1836 {1252, sidAsciiLatin},
1837 {1253, sidGreek},
1838 {1254, sidAsciiLatin},
1839 {1255, sidHebrew},
1840 {1256, sidArabic},
1841 {1257, sidAsciiLatin},
1842 {1258, sidAsciiLatin},
1843 {CP_UNICODE, 0, E_FAIL}
1846 for (i = 0; i < sizeof(cp_sid)/sizeof(cp_sid[0]); i++)
1848 hr = IMLangFontLink2_CodePageToScriptID(font_link, cp_sid[i].cp, &sid);
1849 ok(hr == cp_sid[i].hr, "%u CodePageToScriptID failed 0x%08x %u\n", i, hr, GetLastError());
1850 if (SUCCEEDED(hr))
1852 ok(sid == cp_sid[i].sid,
1853 "%u got sid %u for codepage %u, expected %u\n", i, sid, cp_sid[i].cp, cp_sid[i].sid);
1858 static void test_GetFontUnicodeRanges(IMLangFontLink2 *font_link)
1860 HRESULT hr;
1861 UINT count;
1862 HFONT hfont, old_hfont;
1863 LOGFONTA lf;
1864 HDC hdc;
1865 UNICODERANGE *ur;
1867 hdc = CreateCompatibleDC(0);
1868 memset(&lf, 0, sizeof(lf));
1869 lstrcpyA(lf.lfFaceName, "Arial");
1870 hfont = CreateFontIndirectA(&lf);
1871 old_hfont = SelectObject(hdc, hfont);
1873 count = 0;
1874 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, NULL, &count, NULL);
1875 ok(hr == E_FAIL, "expected E_FAIL, got 0x%08x\n", hr);
1877 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, NULL, NULL);
1878 ok(hr == E_INVALIDARG, "expected E_FAIL, got 0x%08x\n", hr);
1880 count = 0;
1881 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, NULL);
1882 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1883 ok(count, "expected count > 0\n");
1885 ur = HeapAlloc(GetProcessHeap(), 0, sizeof(*ur) * count);
1887 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1888 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1890 count--;
1891 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1892 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1894 HeapFree(GetProcessHeap(), 0, ur);
1896 SelectObject(hdc, old_hfont);
1897 DeleteObject(hfont);
1898 DeleteDC(hdc);
1901 static void test_IsCodePageInstallable(IMultiLanguage2 *ml2)
1903 UINT i;
1904 HRESULT hr;
1906 SetLastError(0xdeadbeef);
1907 lstrcmpW(NULL, NULL);
1908 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1910 /* This corruption leads (sometimes) to test failures in oleaut32 but also
1911 * to the inability to use the Regional Settings.
1912 * This only seems to be an issue with Win98 and IE6 (mlang version 6.0.2800.1106).
1914 * A reboot restores the codepages again.
1916 win_skip("IsCodePageInstallable could mess up the codepages on Win98\n");
1917 return;
1920 for (i = 0; i < 0xffff; i++)
1922 hr = IMultiLanguage2_IsCodePageInstallable(ml2, i);
1924 /* it would be better to use IMultiLanguage2_ValidateCodePageEx here but that brings
1925 * up an installation dialog on some platforms, even when specifying CPIOD_PEEK.
1927 if (IsValidCodePage(i))
1928 ok(hr == S_OK ||
1929 broken(hr == S_FALSE) || /* win2k */
1930 broken(hr == E_INVALIDARG), /* win2k */
1931 "code page %u is valid but not installable 0x%08x\n", i, hr);
1935 START_TEST(mlang)
1937 IMultiLanguage *iML = NULL;
1938 IMultiLanguage2 *iML2 = NULL;
1939 IMLangFontLink *iMLFL = NULL;
1940 IMLangFontLink2 *iMLFL2 = NULL;
1941 HRESULT ret;
1943 if (!init_function_ptrs())
1944 return;
1946 CoInitialize(NULL);
1947 test_Rfc1766ToLcid();
1948 test_LcidToRfc1766();
1950 test_ConvertINetUnicodeToMultiByte();
1951 test_JapaneseConversion();
1954 trace("IMultiLanguage\n");
1955 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1956 &IID_IMultiLanguage, (void **)&iML);
1957 if (ret != S_OK || !iML) return;
1959 test_GetNumberOfCodePageInfo((IMultiLanguage2 *)iML);
1960 IMultiLanguage_Release(iML);
1963 /* IMultiLanguage2 (IE5.0 and above) */
1964 trace("IMultiLanguage2\n");
1965 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1966 &IID_IMultiLanguage2, (void **)&iML2);
1967 if (ret != S_OK || !iML2) return;
1969 test_rfc1766(iML2);
1970 test_GetLcidFromRfc1766(iML2);
1971 test_GetRfc1766FromLcid(iML2);
1972 test_GetRfc1766Info(iML2);
1973 test_GetNumberOfCodePageInfo(iML2);
1975 test_EnumCodePages(iML2, 0);
1976 test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
1977 test_EnumCodePages(iML2, MIMECONTF_BROWSER);
1978 test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
1979 test_EnumCodePages(iML2, MIMECONTF_VALID);
1980 /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
1981 /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/
1983 test_EnumScripts(iML2, 0);
1984 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
1985 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);
1987 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
1988 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
1989 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
1990 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
1992 test_multibyte_to_unicode_translations(iML2);
1993 test_IMultiLanguage2_ConvertStringFromUnicode(iML2);
1995 test_IsCodePageInstallable(iML2);
1997 IMultiLanguage2_Release(iML2);
2000 /* IMLangFontLink */
2001 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2002 &IID_IMLangFontLink, (void **)&iMLFL);
2003 if (ret != S_OK || !iMLFL) return;
2005 IMLangFontLink_Test(iMLFL);
2006 IMLangFontLink_Release(iMLFL);
2008 /* IMLangFontLink2 */
2009 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2010 &IID_IMLangFontLink2, (void **)&iMLFL2);
2011 if (ret != S_OK || !iMLFL2) return;
2013 test_GetScriptFontInfo(iMLFL2);
2014 test_GetFontUnicodeRanges(iMLFL2);
2015 test_CodePageToScriptID(iMLFL2);
2016 IMLangFontLink2_Release(iMLFL2);
2018 CoUninitialize();