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
33 #include "wine/test.h"
36 #define CP_UNICODE 1200
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,
47 static HRESULT (WINAPI *pRfc1766ToLcidA)(LCID *, LPCSTR);
48 static HRESULT (WINAPI *pLcidToRfc1766A)(LCID, LPSTR, INT);
50 typedef struct lcid_tag_table {
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[] = {
72 {"de-ch", 0x0807, S_OK},
73 {"de-at", 0x0c07, S_OK},
74 {"de-lu", 0x1007, S_OK},
75 {"de-li", 0x1407, 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},
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"},
92 {"it-ch", 0x0810, S_OK},
95 {"nl-be", 0x0813, S_OK},
99 {"kok", 0x0457, S_OK, 0x0412, "x-kok"}
105 typedef struct info_table_tag {
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),
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),
177 {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
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)
230 hMlang = LoadLibraryA("mlang.dll");
233 skip("mlang not available\n");
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");
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)
261 while (*str1 && *str1==*str2) {
268 /* lstrcpyW is not supported on Win95 */
269 static void mylstrcpyW(WCHAR* str1, const WCHAR* str2)
271 while (str2 && *str2) {
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};
286 UINT lenA, lenW, expected_len;
289 /* IMultiLanguage2_ConvertStringToUnicode tests */
291 memset(bufW, 'x', sizeof(bufW));
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));
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));
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));
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);
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);
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));
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));
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));
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));
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);
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);
427 static const char *dump_mime_flags(DWORD flags)
429 static char buf[1024];
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");
451 static HRESULT check_convertible(IMultiLanguage2 *iML2, UINT from, UINT to)
453 CHAR convert[MAX_PATH];
458 static WCHAR strW[] = {'a','b','c',0};
460 /* Check to see if the target codepage has these characters or not */
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);
476 srcsz = lstrlenW(strW) + 1;
478 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, from, strW,
479 &srcsz, convert, &destsz);
485 hr = IMultiLanguage2_ConvertString(iML2, NULL, from, to, (BYTE *)convert,
486 &srcsz, dest, &destsz);
493 static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
495 IEnumCodePage *iEnumCP = NULL;
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);
514 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, &n);
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);
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);
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);
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);
539 ok(n == total, "IEnumCodePage_Next: expected %u, got %u\n", total, n);
541 flags = MIMECONTF_MIME_LATEST;
546 for (i = 0; i < n; i++)
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};
555 trace("MIMECPINFO #%u:\n"
558 "uiFamilyCodePage %u\n"
559 "wszDescription %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);
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);
583 if (winetest_debug > 1)
584 trace("TranslateCharsetInfo failed for cp %u\n", cpinfo[i].uiFamilyCodePage);
587 trace("%u: codepage %u family %u\n", i, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
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);
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");
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);
625 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszWebCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
627 ok(!lstrcmpiW(cpinfo[i].wszWebCharset, mcsi.wszCharset), "%s != %s\n",
628 wine_dbgstr_w(cpinfo[i].wszWebCharset), wine_dbgstr_w(mcsi.wszCharset));
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");
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);
651 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszHeaderCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
653 ok(!lstrcmpiW(cpinfo[i].wszHeaderCharset, mcsi.wszCharset), "%s != %s\n",
654 wine_dbgstr_w(cpinfo[i].wszHeaderCharset), wine_dbgstr_w(mcsi.wszCharset));
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");
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);
677 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszBodyCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
679 ok(!lstrcmpiW(cpinfo[i].wszBodyCharset, mcsi.wszCharset), "%s != %s\n",
680 wine_dbgstr_w(cpinfo[i].wszBodyCharset), wine_dbgstr_w(mcsi.wszCharset));
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 */
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);
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);
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++)
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;
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);
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);
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);
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);
775 ok(n == total, "IEnumScript_Next: expected %u, got %u\n", total, n);
780 for (i = 0; pGetCPInfoExA && i < n; i++)
782 #ifdef DUMP_SCRIPT_INFO
783 trace("SCRIPTINFO #%u:\n"
786 "wszDescription %s\n"
787 "wszFixedWidthFont %s\n"
788 "wszProportionalFont %s\n\n",
792 wine_dbgstr_w(sinfo[i].wszDescription),
793 wine_dbgstr_w(sinfo[i].wszFixedWidthFont),
794 wine_dbgstr_w(sinfo[i].wszProportionalFont));
795 trace("%u codepage %u\n", i, sinfo[i].uiCodePage);
799 /* now IEnumScript_Next should fail, since pointer is at the end */
801 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
802 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
804 ret = IEnumScript_Reset(iEnumScript);
805 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
807 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
808 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
809 scriptinfo_cmp(&sinfo[0], &sinfo2);
813 /* Due to a bug in MS' implementation of IEnumScript_Skip
814 * it's not used here.
816 ret = IEnumScript_Skip(iEnumScript, 1);
817 ok(ret == S_OK, "IEnumScript_Skip: expected S_OK, got %08x\n", ret);
819 for (i = 0; i < total - 1; i++)
822 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
823 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
824 scriptinfo_cmp(&sinfo[i + 1], &sinfo2);
827 HeapFree(GetProcessHeap(), 0, sinfo);
828 IEnumScript_Release(iEnumScript);
831 static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
833 DWORD dwCodePages, dwManyCodePages;
834 DWORD dwCmpCodePages;
836 static const WCHAR str[3] = { 'd', 0x0436, 0xff90 };
841 ret = IMLangFontLink_CodePageToCodePages(iMLFL, -1, &dwCodePages);
842 ok(ret == E_FAIL, "IMLangFontLink_CodePageToCodePages should fail: %x\n", ret);
843 ok(dwCodePages == 0, "expected 0, got %u\n", dwCodePages);
846 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 932, &dwCodePages);
847 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
848 ok(dwCodePages == FS_JISJAPAN, "expected FS_JISJAPAN, got %08x\n", dwCodePages);
850 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwCodePages, 1035, &CodePage);
851 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
852 ok(CodePage == 932, "Incorrect CodePage Returned (%i)\n",CodePage);
855 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1252, &dwManyCodePages);
856 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
857 ok(dwManyCodePages == FS_LATIN1, "expected FS_LATIN1, got %08x\n", dwManyCodePages);
859 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1256, &dwCodePages);
860 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
861 ok(dwCodePages == FS_ARABIC, "expected FS_ARABIC, got %08x\n", dwCodePages);
862 dwManyCodePages |= dwCodePages;
863 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 874, &dwCodePages);
864 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
865 ok(dwCodePages == FS_THAI, "expected FS_THAI, got %08x\n", dwCodePages);
866 dwManyCodePages |= dwCodePages;
868 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 1256, &CodePage);
869 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
870 ok(CodePage == 1256, "Incorrect CodePage Returned (%i)\n",CodePage);
872 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 936, &CodePage);
873 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
874 ok(CodePage == 1252, "Incorrect CodePage Returned (%i)\n",CodePage);
876 /* Tests for GetCharCodePages */
879 dwCmpCodePages = FS_LATIN1 | FS_LATIN2 | FS_CYRILLIC | FS_GREEK | FS_TURKISH
880 | FS_HEBREW | FS_ARABIC | FS_BALTIC | FS_VIETNAMESE | FS_THAI
881 | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG | FS_CHINESETRAD;
882 ret = IMLangFontLink_GetCharCodePages(iMLFL, 'd', &dwCodePages);
883 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
884 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
888 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[0], 1, 0, &dwCodePages, &processed);
889 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
890 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
891 ok(processed == 1, "expected 1, got %d\n", processed);
894 dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
895 ret = IMLangFontLink_GetCharCodePages(iMLFL, 0x0436, &dwCodePages);
896 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
897 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
901 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[1], 1, 0, &dwCodePages, &processed);
902 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
903 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
904 ok(processed == 1, "expected 1, got %d\n", processed);
907 dwCmpCodePages = FS_JISJAPAN;
908 ret = IMLangFontLink_GetCharCodePages(iMLFL, 0xff90, &dwCodePages);
909 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
910 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
914 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
915 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
916 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
917 ok(processed == 1, "expected 1, got %d\n", processed);
919 dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
922 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 2, 0, &dwCodePages, &processed);
923 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
924 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
925 ok(processed == 2, "expected 2, got %d\n", processed);
927 dwCmpCodePages = FS_JISJAPAN;
930 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 3, 0, &dwCodePages, &processed);
931 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
932 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
933 ok(processed == 3, "expected 3, got %d\n", processed);
935 dwCodePages = 0xffff;
937 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
938 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
939 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
940 ok(processed == 1, "expected 0, got %d\n", processed);
942 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, NULL, NULL);
943 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
945 dwCodePages = 0xffff;
947 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, -1, 0, &dwCodePages, &processed);
948 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
949 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
950 ok(processed == 0, "expected 0, got %d\n", processed);
952 dwCodePages = 0xffff;
954 ret = IMLangFontLink_GetStrCodePages(iMLFL, NULL, 1, 0, &dwCodePages, &processed);
955 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
956 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
957 ok(processed == 0, "expected 0, got %d\n", processed);
959 dwCodePages = 0xffff;
961 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 0, 0, &dwCodePages, &processed);
962 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
963 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
964 ok(processed == 0, "expected 0, got %d\n", processed);
967 /* copied from libs/wine/string.c */
968 static WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
972 const WCHAR *p1 = str, *p2 = sub;
973 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
974 if (!*p2) return (WCHAR *)str;
980 static void test_rfc1766(IMultiLanguage2 *iML2)
982 IEnumRfc1766 *pEnumRfc1766;
988 ret = IMultiLanguage2_EnumRfc1766(iML2, LANG_NEUTRAL, &pEnumRfc1766);
989 ok(ret == S_OK, "IMultiLanguage2_EnumRfc1766 error %08x\n", ret);
993 ret = IEnumRfc1766_Next(pEnumRfc1766, 1, &info, &n);
994 if (ret != S_OK) break;
997 trace("lcid %04x rfc_name %s locale_name %s\n",
998 info.lcid, wine_dbgstr_w(info.wszRfc1766), wine_dbgstr_w(info.wszLocaleName));
1001 ok(n == 1, "couldn't fetch 1 RFC1766INFO structure\n");
1003 /* verify the Rfc1766 value */
1004 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, info.lcid, &rfcstr);
1005 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1007 /* not an exact 1:1 correspondence between lcid and rfc1766 in the
1008 * mlang database, e.g., nb-no -> 1044 -> no */
1009 ok(strstrW(info.wszRfc1766, rfcstr) != NULL,
1010 "Expected matching locale names\n");
1012 SysFreeString(rfcstr);
1014 IEnumRfc1766_Release(pEnumRfc1766);
1017 static void test_GetLcidFromRfc1766(IMultiLanguage2 *iML2)
1019 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1024 static WCHAR en[] = { 'e','n',0 };
1025 static WCHAR en_them[] = { 'e','n','-','t','h','e','m',0 };
1026 static WCHAR english[] = { 'e','n','g','l','i','s','h',0 };
1029 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1031 MultiByteToWideChar(CP_ACP, 0, lcid_table[i].rfc1766, -1, rfc1766W, MAX_RFC1766_NAME);
1032 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, rfc1766W);
1034 /* IE <6.0 guess 0x412 (ko) from "kok" */
1035 ok((ret == lcid_table[i].hr) ||
1036 broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1037 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1039 ok((lcid == lcid_table[i].lcid) ||
1040 broken(lcid == lcid_table[i].broken_lcid), /* IE <6.0 */
1041 "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1045 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, NULL, en);
1046 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1048 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, NULL);
1049 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1051 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_them);
1052 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1056 static WCHAR en[] = {'e','n',0};
1058 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1059 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1060 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
1063 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, english);
1064 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1068 static WCHAR en[] = {'e','n',0};
1070 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1071 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1072 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
1077 static void test_Rfc1766ToLcid(void)
1083 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1085 ret = pRfc1766ToLcidA(&lcid, lcid_table[i].rfc1766);
1087 /* IE <6.0 guess 0x412 (ko) from "kok" */
1088 ok( (ret == lcid_table[i].hr) ||
1089 broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1090 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1092 ok( (lcid == lcid_table[i].lcid) ||
1093 broken(lcid == lcid_table[i].broken_lcid), /* IE <6.0 */
1094 "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1097 ret = pRfc1766ToLcidA(&lcid, NULL);
1098 ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1100 ret = pRfc1766ToLcidA(NULL, "en");
1101 ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1104 static void test_GetNumberOfCodePageInfo(IMultiLanguage2 *iML2)
1110 hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &value);
1111 ok( (hr == S_OK) && value,
1112 "got 0x%x with %d (expected S_OK with '!= 0')\n", hr, value);
1114 hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, NULL);
1115 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1119 static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
1121 CHAR expected[MAX_RFC1766_NAME];
1122 CHAR buffer[MAX_RFC1766_NAME + 1];
1127 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1131 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid_table[i].lcid, &rfcstr);
1132 ok(hr == lcid_table[i].hr,
1133 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1136 continue; /* no result-string created */
1138 WideCharToMultiByte(CP_ACP, 0, rfcstr, -1, buffer, sizeof(buffer), NULL, NULL);
1139 LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1140 lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1142 /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1143 ok( (!lstrcmpA(buffer, expected)) ||
1144 broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1145 "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1147 SysFreeString(rfcstr);
1150 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL);
1151 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1154 static void test_LcidToRfc1766(void)
1156 CHAR expected[MAX_RFC1766_NAME];
1157 CHAR buffer[MAX_RFC1766_NAME * 2];
1161 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1163 memset(buffer, '#', sizeof(buffer)-1);
1164 buffer[sizeof(buffer)-1] = '\0';
1166 hr = pLcidToRfc1766A(lcid_table[i].lcid, buffer, MAX_RFC1766_NAME);
1168 /* IE <5.0 does not recognize 0x180c (fr-mc) and 0x457 (kok) */
1169 ok( (hr == lcid_table[i].hr) ||
1170 broken(lcid_table[i].broken_lcid && (hr == E_FAIL)),
1171 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1176 LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1177 lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1179 /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1180 /* IE <5.0 return "fr" for LCID 0x180c ("fr-mc") */
1181 ok( (!lstrcmpA(buffer, expected)) ||
1182 broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1183 "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1187 memset(buffer, '#', sizeof(buffer)-1);
1188 buffer[sizeof(buffer)-1] = '\0';
1189 hr = pLcidToRfc1766A(-1, buffer, MAX_RFC1766_NAME);
1190 ok(hr == E_FAIL, "got 0x%08x and '%s' (expected E_FAIL)\n", hr, buffer);
1192 hr = pLcidToRfc1766A(LANG_ENGLISH, NULL, MAX_RFC1766_NAME);
1193 ok(hr == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", hr);
1195 memset(buffer, '#', sizeof(buffer)-1);
1196 buffer[sizeof(buffer)-1] = '\0';
1197 hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, -1);
1198 ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1200 memset(buffer, '#', sizeof(buffer)-1);
1201 buffer[sizeof(buffer)-1] = '\0';
1202 hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, 0);
1203 ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1206 static void test_GetRfc1766Info(IMultiLanguage2 *iML2)
1208 WCHAR short_broken_name[MAX_LOCALE_NAME];
1209 CHAR rfc1766A[MAX_RFC1766_NAME + 1];
1210 BYTE buffer[sizeof(RFC1766INFO) + 4];
1211 PRFC1766INFO prfc = (RFC1766INFO *) buffer;
1215 for(i = 0; i < sizeof(info_table) / sizeof(info_table[0]); i++) {
1216 memset(buffer, 'x', sizeof(RFC1766INFO) + 2);
1217 buffer[sizeof(buffer) -1] = 0;
1218 buffer[sizeof(buffer) -2] = 0;
1220 ret = IMultiLanguage2_GetRfc1766Info(iML2, info_table[i].lcid, info_table[i].lang, prfc);
1221 WideCharToMultiByte(CP_ACP, 0, prfc->wszRfc1766, -1, rfc1766A, MAX_RFC1766_NAME, NULL, NULL);
1222 ok(ret == S_OK, "#%02d: got 0x%x (expected S_OK)\n", i, ret);
1223 ok(prfc->lcid == info_table[i].lcid,
1224 "#%02d: got 0x%04x (expected 0x%04x)\n", i, prfc->lcid, info_table[i].lcid);
1226 ok(!lstrcmpA(rfc1766A, info_table[i].rfc1766),
1227 "#%02d: got '%s' (expected '%s')\n", i, rfc1766A, info_table[i].rfc1766);
1229 /* Some IE versions truncate an oversized name one character to short */
1230 mylstrcpyW(short_broken_name, info_table[i].broken_name);
1231 short_broken_name[MAX_LOCALE_NAME - 2] = '\0';
1233 if (info_table[i].todo & TODO_NAME) {
1235 ok( (!mylstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1236 broken(!mylstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1237 broken(!mylstrcmpW(prfc->wszLocaleName, short_broken_name)),
1238 "#%02d: got %s (expected %s)\n", i,
1239 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1242 ok( (!mylstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1243 broken(!mylstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1244 broken(!mylstrcmpW(prfc->wszLocaleName, short_broken_name)),
1245 "#%02d: got %s (expected %s)\n", i,
1246 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1250 /* SUBLANG_NEUTRAL only allowed for english, arabic, chinese */
1251 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_GERMAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1252 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1254 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_ITALIAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1255 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1257 /* NULL not allowed */
1258 ret = IMultiLanguage2_GetRfc1766Info(iML2, 0, LANG_ENGLISH, prfc);
1259 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1261 ret = IMultiLanguage2_GetRfc1766Info(iML2, LANG_ENGLISH, LANG_ENGLISH, NULL);
1262 ok(ret == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", ret);
1265 static void test_IMultiLanguage2_ConvertStringFromUnicode(IMultiLanguage2 *iML2)
1267 CHAR dest[MAX_PATH];
1268 CHAR invariate[MAX_PATH];
1272 static WCHAR src[] = {'a','b','c',0};
1274 memset(invariate, 'x', sizeof(invariate));
1277 memset(dest, 'x', sizeof(dest));
1278 srcsz = lstrlenW(src) + 1;
1279 destsz = sizeof(dest);
1280 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1281 &srcsz, dest, &destsz);
1282 ok(hr == S_OK || hr == E_FAIL,"expected S_OK or E_FAIL, got %08x\n",hr);
1285 ok(srcsz == lstrlenW(src) + 1,
1286 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1288 else if (hr == E_FAIL)
1291 "Expected %u, got %u\n", 0, srcsz);
1294 ok(!memcmp(dest, invariate, sizeof(dest)),
1295 "Expected dest to be unchanged, got %s\n", dest);
1296 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1298 /* pcSrcSize NULL */
1299 memset(dest, 'x', sizeof(dest));
1300 destsz = sizeof(dest);
1301 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1302 NULL, dest, &destsz);
1303 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1304 ok(!strncmp(dest, "abc", 3),
1305 "Expected first three chars to be \"abc\"\n");
1306 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1307 "Expected rest of dest to be unchanged, got %s\n", dest);
1308 ok(destsz == lstrlenW(src),
1309 "Expected %u, got %u\n", lstrlenW(src), destsz);
1311 /* both pSrcStr and pcSrcSize NULL */
1312 memset(dest, 'x', sizeof(dest));
1313 destsz = sizeof(dest);
1314 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1315 NULL, dest, &destsz);
1316 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1317 ok(!memcmp(dest, invariate, sizeof(dest)),
1318 "Expected dest to be unchanged, got %s\n", dest);
1319 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1322 memset(dest, 'x', sizeof(dest));
1323 srcsz = lstrlenW(src) + 1;
1324 destsz = sizeof(dest);
1325 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1326 &srcsz, NULL, &destsz);
1327 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1328 ok(srcsz == lstrlenW(src) + 1,
1329 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1330 ok(destsz == lstrlenW(src) + 1,
1331 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1333 /* pcDstSize NULL */
1334 memset(dest, 'x', sizeof(dest));
1335 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1336 &srcsz, dest, NULL);
1337 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1338 ok(srcsz == lstrlenW(src) + 1,
1339 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1340 ok(!memcmp(dest, invariate, sizeof(dest)),
1341 "Expected dest to be unchanged, got %s\n", dest);
1343 /* pcSrcSize is 0 */
1344 memset(dest, 'x', sizeof(dest));
1346 destsz = sizeof(dest);
1347 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1348 &srcsz, dest, &destsz);
1349 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1350 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1351 ok(!memcmp(dest, invariate, sizeof(dest)),
1352 "Expected dest to be unchanged, got %s\n", dest);
1353 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1355 /* pcSrcSize does not include NULL terminator */
1356 memset(dest, 'x', sizeof(dest));
1357 srcsz = lstrlenW(src);
1358 destsz = sizeof(dest);
1359 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1360 &srcsz, dest, &destsz);
1361 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1362 ok(srcsz == lstrlenW(src),
1363 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1364 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1365 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1366 "Expected rest of dest to be unchanged, got %s\n", dest);
1367 ok(destsz == lstrlenW(src),
1368 "Expected %u, got %u\n", lstrlenW(src), destsz);
1370 /* pcSrcSize includes NULL terminator */
1371 memset(dest, 'x', sizeof(dest));
1372 srcsz = lstrlenW(src) + 1;
1373 destsz = sizeof(dest);
1374 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1375 &srcsz, dest, &destsz);
1376 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1377 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1378 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1379 ok(destsz == lstrlenW(src) + 1,
1380 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1382 /* pcSrcSize is -1 */
1383 memset(dest, 'x', sizeof(dest));
1385 destsz = sizeof(dest);
1386 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1387 &srcsz, dest, &destsz);
1388 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1389 ok(srcsz == lstrlenW(src),
1390 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1391 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1392 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1393 "Expected rest of dest to be unchanged, got %s\n", dest);
1394 ok(destsz == lstrlenW(src),
1395 "Expected %u, got %u\n", lstrlenW(src), destsz);
1397 /* pcDstSize is 0 */
1398 memset(dest, 'x', sizeof(dest));
1399 srcsz = lstrlenW(src) + 1;
1401 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1402 &srcsz, dest, &destsz);
1403 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1404 ok(srcsz == lstrlenW(src) + 1,
1405 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1406 ok(!memcmp(dest, invariate, sizeof(dest)),
1407 "Expected dest to be unchanged, got %s\n", dest);
1408 ok(destsz == lstrlenW(src) + 1,
1409 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1411 /* pcDstSize is not large enough */
1412 memset(dest, 'x', sizeof(dest));
1413 srcsz = lstrlenW(src) + 1;
1414 destsz = lstrlenW(src);
1415 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1416 &srcsz, dest, &destsz);
1417 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1418 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1419 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1420 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1421 "Expected rest of dest to be unchanged, got %s\n", dest);
1422 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1424 /* pcDstSize (bytes) does not leave room for NULL terminator */
1425 memset(dest, 'x', sizeof(dest));
1426 srcsz = lstrlenW(src) + 1;
1427 destsz = lstrlenW(src) * sizeof(WCHAR);
1428 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1429 &srcsz, dest, &destsz);
1430 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1431 ok(srcsz == lstrlenW(src) + 1,
1432 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1433 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1434 ok(destsz == lstrlenW(src) + 1,
1435 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1438 static void test_ConvertINetUnicodeToMultiByte(void)
1440 CHAR dest[MAX_PATH];
1441 CHAR invariate[MAX_PATH];
1445 static WCHAR src[] = {'a','b','c',0};
1447 memset(invariate, 'x', sizeof(invariate));
1450 memset(dest, 'x', sizeof(dest));
1451 srcsz = lstrlenW(src) + 1;
1452 destsz = sizeof(dest);
1453 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, &srcsz, dest, &destsz);
1454 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1456 ok(srcsz == lstrlenW(src) + 1,
1457 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1458 else if (hr == E_FAIL)
1460 "Expected %u, got %u\n", 0, srcsz);
1461 ok(!memcmp(dest, invariate, sizeof(dest)),
1462 "Expected dest to be unchanged, got %s\n", dest);
1463 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1465 /* lpnWideCharCount NULL */
1466 memset(dest, 'x', sizeof(dest));
1467 destsz = sizeof(dest);
1468 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, NULL, dest, &destsz);
1469 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1470 ok(!strncmp(dest, "abc", 3),
1471 "Expected first three chars to be \"abc\"\n");
1472 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1473 "Expected rest of dest to be unchanged, got %s\n", dest);
1474 ok(destsz == lstrlenW(src),
1475 "Expected %u, got %u\n", lstrlenW(src), destsz);
1477 /* both lpSrcStr and lpnWideCharCount NULL */
1478 memset(dest, 'x', sizeof(dest));
1479 destsz = sizeof(dest);
1480 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, NULL, dest, &destsz);
1481 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1482 ok(!memcmp(dest, invariate, sizeof(dest)),
1483 "Expected dest to be unchanged, got %s\n", dest);
1484 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1487 memset(dest, 'x', sizeof(dest));
1488 srcsz = lstrlenW(src) + 1;
1489 destsz = sizeof(dest);
1490 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, NULL, &destsz);
1491 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1492 ok(srcsz == lstrlenW(src) + 1,
1493 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1494 ok(destsz == lstrlenW(src) + 1,
1495 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1497 /* lpnMultiCharCount NULL */
1498 memset(dest, 'x', sizeof(dest));
1499 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, NULL);
1500 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1501 ok(srcsz == lstrlenW(src) + 1,
1502 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1503 ok(!memcmp(dest, invariate, sizeof(dest)),
1504 "Expected dest to be unchanged, got %s\n", dest);
1506 /* lpnWideCharCount is 0 */
1507 memset(dest, 'x', sizeof(dest));
1509 destsz = sizeof(dest);
1510 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1511 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1512 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1513 ok(!memcmp(dest, invariate, sizeof(dest)),
1514 "Expected dest to be unchanged, got %s\n", dest);
1515 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1517 /* lpnWideCharCount does not include NULL terminator */
1518 memset(dest, 'x', sizeof(dest));
1519 srcsz = lstrlenW(src);
1520 destsz = sizeof(dest);
1521 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1522 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1523 ok(srcsz == lstrlenW(src),
1524 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1525 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1526 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1527 "Expected rest of dest to be unchanged, got %s\n", dest);
1528 ok(destsz == lstrlenW(src),
1529 "Expected %u, got %u\n", lstrlenW(src), destsz);
1531 /* lpnWideCharCount includes NULL terminator */
1532 memset(dest, 'x', sizeof(dest));
1533 srcsz = lstrlenW(src) + 1;
1534 destsz = sizeof(dest);
1535 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1536 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1537 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1538 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1539 ok(destsz == lstrlenW(src) + 1,
1540 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1542 /* lpnWideCharCount is -1 */
1543 memset(dest, 'x', sizeof(dest));
1545 destsz = sizeof(dest);
1546 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1547 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1548 ok(srcsz == lstrlenW(src),
1549 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1550 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1551 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1552 "Expected rest of dest to be unchanged, got %s\n", dest);
1553 ok(destsz == lstrlenW(src),
1554 "Expected %u, got %u\n", lstrlenW(src), destsz);
1556 /* lpnMultiCharCount is 0 */
1557 memset(dest, 'x', sizeof(dest));
1558 srcsz = lstrlenW(src) + 1;
1560 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1561 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1562 ok(srcsz == lstrlenW(src) + 1,
1563 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1564 ok(!memcmp(dest, invariate, sizeof(dest)),
1565 "Expected dest to be unchanged, got %s\n", dest);
1566 ok(destsz == lstrlenW(src) + 1,
1567 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1569 /* lpnMultiCharCount is not large enough */
1570 memset(dest, 'x', sizeof(dest));
1571 srcsz = lstrlenW(src) + 1;
1572 destsz = lstrlenW(src);
1573 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1574 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1575 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1576 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1577 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1578 "Expected rest of dest to be unchanged, got %s\n", dest);
1579 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1581 /* lpnMultiCharCount (bytes) does not leave room for NULL terminator */
1582 memset(dest, 'x', sizeof(dest));
1583 srcsz = lstrlenW(src) + 1;
1584 destsz = lstrlenW(src) * sizeof(WCHAR);
1585 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1586 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1587 ok(srcsz == lstrlenW(src) + 1,
1588 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1589 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1590 ok(destsz == lstrlenW(src) + 1,
1591 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1594 static void test_JapaneseConversion(void)
1597 static WCHAR unc_jp[9][12] = {
1598 {9,0x31,0x20,0x3042,0x3044,0x3046,0x3048,0x304a,0x000d,0x000a},
1599 {9,0x31,0x20,0x30a2,0x30a4,0x30a6,0x30a8,0x30aa,0x000d,0x000a},
1600 {9,0x31,0x20,0xff71,0xff72,0xff73,0xff74,0xff75,0x000d,0x000a},
1601 {9,0x31,0x20,0x3041,0x3043,0x3045,0x3047,0x3049,0x000d,0x000a},
1602 {9,0x31,0x20,0x30a1,0x30a3,0x30a5,0x30a7,0x30a9,0x000d,0x000a},
1603 {9,0x31,0x20,0xff67,0xff68,0xff69,0xff6a,0xff6b,0x000d,0x000a},
1604 {9,0x31,0x20,0x300c,0x65e5,0x672c,0x8a9e,0x300d,0x000d,0x000a},
1605 {7,0x31,0x20,0x25c7,0x25c7,0x3012,0x000d,0x000a},
1606 {11,0x31,0x20,0x203b,0x3010,0x0074,0x0065,0x0073,0x0074,0x3011,0x000d,0x000a}
1608 static CHAR jis_jp[9][27] = {
1609 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x22,0x24,0x24,0x24,0x26,0x24,0x28,
1610 0x24,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1611 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1612 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1613 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1614 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1615 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x21,0x24,0x23,0x24,0x25,0x24,0x27,
1616 0x24,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1617 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1618 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1619 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1620 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1621 {20,0x31,0x20,0x1b,0x24,0x42,0x21,0x56,0x46,0x7c,0x4b,0x5c,0x38,0x6c,
1622 0x21,0x57,0x1b,0x28,0x42,0x0d,0x0a},
1623 {16,0x31,0x20,0x1b,0x24,0x42,0x21,0x7e,0x21,0x7e,0x22,0x29,0x1b,0x28,
1625 {26,0x31,0x20,0x1b,0x24,0x42,0x22,0x28,0x21,0x5a,0x1b,0x28,0x42,0x74,
1626 0x65,0x73,0x74,0x1b,0x24,0x42,0x21,0x5b,0x1b,0x28,0x42,0x0d,0x0a}
1628 static CHAR sjis_jp[9][15] = {
1629 {14,0x31,0x20,0x82,0xa0,0x82,0xa2,0x82,0xa4,0x82,0xa6,0x82,0xa8,0x0d,0x0a},
1630 {14,0x31,0x20,0x83,0x41,0x83,0x43,0x83,0x45,0x83,0x47,0x83,0x49,0x0d,0x0a},
1631 {9,0x31,0x20,0xb1,0xb2,0xb3,0xb4,0xb5,0x0d,0x0a},
1632 {14,0x31,0x20,0x82,0x9f,0x82,0xa1,0x82,0xa3,0x82,0xa5,0x82,0xa7,0x0d,0x0a},
1633 {14,0x31,0x20,0x83,0x40,0x83,0x42,0x83,0x44,0x83,0x46,0x83,0x48,0x0d,0x0a},
1634 {9,0x31,0x20,0xa7,0xa8,0xa9,0xaa,0xab,0x0d,0x0a},
1635 {14,0x31,0x20,0x81,0x75,0x93,0xfa,0x96,0x7b,0x8c,0xea,0x81,0x76,0x0d,0x0a},
1636 {10,0x31,0x20,0x81,0x9e,0x81,0x9e,0x81,0xa7,0x0d,0x0a},
1637 {14,0x31,0x20,0x81,0xa6,0x81,0x79,0x74,0x65,0x73,0x74,0x81,0x7a,0x0d,0x0a}
1639 static CHAR euc_jp[9][15] = {
1640 {14,0x31,0x20,0xa4,0xa2,0xa4,0xa4,0xa4,0xa6,0xa4,0xa8,0xa4,0xaa,0x0d,0x0a},
1641 {14,0x31,0x20,0xa5,0xa2,0xa5,0xa4,0xa5,0xa6,0xa5,0xa8,0xa5,0xaa,0x0d,0x0a},
1642 {14,0x31,0x20,0x8e,0xb1,0x8e,0xb2,0x8e,0xb3,0x8e,0xb4,0x8e,0xb5,0x0d,0x0a},
1643 {14,0x31,0x20,0xa4,0xa1,0xa4,0xa3,0xa4,0xa5,0xa4,0xa7,0xa4,0xa9,0x0d,0x0a},
1644 {14,0x31,0x20,0xa5,0xa1,0xa5,0xa3,0xa5,0xa5,0xa5,0xa7,0xa5,0xa9,0x0d,0x0a},
1645 {14,0x31,0x20,0x8e,0xa7,0x8e,0xa8,0x8e,0xa9,0x8e,0xaa,0x8e,0xab,0x0d,0x0a},
1646 {14,0x31,0x20,0xa1,0xd6,0xc6,0xfc,0xcb,0xdc,0xb8,0xec,0xa1,0xd7,0x0d,0x0a},
1647 {10,0x31,0x20,0xa1,0xfe,0xa1,0xfe,0xa2,0xa9,0x0d,0x0a},
1648 {14,0x31,0x20,0xa2,0xa8,0xa1,0xda,0x74,0x65,0x73,0x74,0xa1,0xdb,0x0d,0x0a}
1659 for (i = 0; i < 9; i++)
1663 outlen = jis_jp[i][0];
1664 srcsz = unc_jp[i][0];
1665 hr = pConvertINetUnicodeToMultiByte(NULL, 50220, &unc_jp[i][1], &srcsz, output, &destsz);
1668 skip("Code page identifier 50220 is not supported\n");
1671 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1672 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1673 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1674 ok(memcmp(output,&jis_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1679 hr = pConvertINetMultiByteToUnicode(NULL, 50220, output, &srcsz, outputW,&destsz);
1682 * JIS does not have hankata so it get automatically converted to
1683 * zenkata. this means that strings 1 and 2 are identical as well as
1690 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i, hr);
1691 ok(destsz == unc_jp[j][0],"(%i) Expected %i, got %i\n",i,unc_jp[j][0],destsz);
1692 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1693 ok(memcmp(outputW,&unc_jp[j][1],destsz)==0,"(%i) Strings do not match\n",i);
1696 /* test unc->sjis */
1697 for (i = 0; i < 9; i++)
1700 outlen = sjis_jp[i][0];
1701 srcsz = unc_jp[i][0];
1703 hr = pConvertINetUnicodeToMultiByte(NULL, 932, &unc_jp[i][1], &srcsz, output, &destsz);
1706 skip("Code page identifier 932 is not supported\n");
1709 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1710 ok(destsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,destsz);
1711 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1712 ok(memcmp(output,&sjis_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1716 hr = pConvertINetMultiByteToUnicode(NULL, 932, output, &srcsz, outputW,&destsz);
1718 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1719 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1720 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1721 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1725 for (i = 0; i < 9; i++)
1728 outlen = euc_jp[i][0];
1729 srcsz = unc_jp[i][0];
1731 hr = pConvertINetUnicodeToMultiByte(NULL, 51932, &unc_jp[i][1], &srcsz, output, &destsz);
1734 skip("Code page identifier 51932 is not supported\n");
1737 ok(hr == S_OK, "(%i) Expected S_OK, got %08x\n",i,hr);
1738 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1739 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1740 ok(memcmp(output,&euc_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1744 hr = pConvertINetMultiByteToUnicode(NULL, 51932, output, &srcsz, outputW,&destsz);
1746 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1747 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1748 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1749 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1752 /* Japanese autodetect */
1755 srcsz = jis_jp[i][0];
1756 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &jis_jp[i][1], &srcsz, outputW, &destsz);
1759 skip("Code page identifier 50932 is not supported\n");
1762 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1763 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1764 ok(srcsz == jis_jp[i][0],"(%i) Expected %i, got %i\n",i,jis_jp[i][0],srcsz);
1765 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1769 srcsz = sjis_jp[i][0];
1770 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &sjis_jp[i][1], &srcsz, outputW, &destsz);
1771 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1772 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1773 ok(srcsz == sjis_jp[i][0],"(%i) Expected %i, got %i\n",i,sjis_jp[i][0],srcsz);
1774 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1777 static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
1781 SCRIPTFONTINFO sfi[1];
1784 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, 0, &nfonts, NULL);
1785 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1786 ok(nfonts, "unexpected result\n");
1789 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, NULL);
1790 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1791 ok(nfonts, "unexpected result\n");
1794 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, NULL);
1795 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1796 ok(nfonts, "unexpected result\n");
1799 memset(sfi, 0, sizeof(sfi));
1800 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, sfi);
1801 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1802 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1803 ok(sfi[0].scripts != 0, "unexpected result\n");
1804 ok(sfi[0].wszFont[0], "unexpected result\n");
1807 memset(sfi, 0, sizeof(sfi));
1808 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, sfi);
1809 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1810 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1811 ok(sfi[0].scripts != 0, "unexpected result\n");
1812 ok(sfi[0].wszFont[0], "unexpected result\n");
1815 static void test_CodePageToScriptID(IMLangFontLink2 *font_link)
1833 {1250, sidAsciiLatin},
1834 {1251, sidCyrillic},
1835 {1252, sidAsciiLatin},
1837 {1254, sidAsciiLatin},
1840 {1257, sidAsciiLatin},
1841 {1258, sidAsciiLatin},
1842 {CP_UNICODE, 0, E_FAIL}
1845 for (i = 0; i < sizeof(cp_sid)/sizeof(cp_sid[0]); i++)
1847 hr = IMLangFontLink2_CodePageToScriptID(font_link, cp_sid[i].cp, &sid);
1848 ok(hr == cp_sid[i].hr, "%u CodePageToScriptID failed 0x%08x %u\n", i, hr, GetLastError());
1851 ok(sid == cp_sid[i].sid,
1852 "%u got sid %u for codepage %u, expected %u\n", i, sid, cp_sid[i].cp, cp_sid[i].sid);
1857 static void test_GetFontUnicodeRanges(IMLangFontLink2 *font_link)
1861 HFONT hfont, old_hfont;
1866 hdc = CreateCompatibleDC(0);
1867 memset(&lf, 0, sizeof(lf));
1868 lstrcpyA(lf.lfFaceName, "Arial");
1869 hfont = CreateFontIndirectA(&lf);
1870 old_hfont = SelectObject(hdc, hfont);
1873 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, NULL, &count, NULL);
1874 ok(hr == E_FAIL, "expected E_FAIL, got 0x%08x\n", hr);
1876 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, NULL, NULL);
1877 ok(hr == E_INVALIDARG, "expected E_FAIL, got 0x%08x\n", hr);
1880 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, NULL);
1881 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1882 ok(count, "expected count > 0\n");
1884 ur = HeapAlloc(GetProcessHeap(), 0, sizeof(*ur) * count);
1886 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1887 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1890 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1891 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1893 HeapFree(GetProcessHeap(), 0, ur);
1895 SelectObject(hdc, old_hfont);
1896 DeleteObject(hfont);
1900 static void test_IsCodePageInstallable(IMultiLanguage2 *ml2)
1905 SetLastError(0xdeadbeef);
1906 lstrcmpW(NULL, NULL);
1907 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1909 /* This corruption leads (sometimes) to test failures in oleaut32 but also
1910 * to the inability to use the Regional Settings.
1911 * This only seems to be an issue with Win98 and IE6 (mlang version 6.0.2800.1106).
1913 * A reboot restores the codepages again.
1915 win_skip("IsCodePageInstallable could mess up the codepages on Win98\n");
1919 for (i = 0; i < 0xffff; i++)
1921 hr = IMultiLanguage2_IsCodePageInstallable(ml2, i);
1923 /* it would be better to use IMultiLanguage2_ValidateCodePageEx here but that brings
1924 * up an installation dialog on some platforms, even when specifying CPIOD_PEEK.
1926 if (IsValidCodePage(i))
1928 broken(hr == S_FALSE) || /* win2k */
1929 broken(hr == E_INVALIDARG), /* win2k */
1930 "code page %u is valid but not installable 0x%08x\n", i, hr);
1934 static void test_GetGlobalFontLinkObject(void)
1939 ret = GetGlobalFontLinkObject(NULL);
1940 ok(ret == E_INVALIDARG, "expected E_INVALIDARG got %#x\n", ret);
1942 unknown = (void *)0xdeadbeef;
1943 ret = GetGlobalFontLinkObject(&unknown);
1945 ok(ret == S_OK, "expected S_OK got %#x\n", ret);
1946 ok(unknown != NULL && unknown != (void *)0xdeadbeef,
1947 "GetGlobalFontLinkObject() returned %p\n", unknown);
1953 IMultiLanguage *iML = NULL;
1954 IMultiLanguage2 *iML2 = NULL;
1955 IMLangFontLink *iMLFL = NULL;
1956 IMLangFontLink2 *iMLFL2 = NULL;
1959 if (!init_function_ptrs())
1963 test_Rfc1766ToLcid();
1964 test_LcidToRfc1766();
1966 test_ConvertINetUnicodeToMultiByte();
1967 test_JapaneseConversion();
1969 test_GetGlobalFontLinkObject();
1971 trace("IMultiLanguage\n");
1972 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1973 &IID_IMultiLanguage, (void **)&iML);
1974 if (ret != S_OK || !iML) return;
1976 test_GetNumberOfCodePageInfo((IMultiLanguage2 *)iML);
1977 IMultiLanguage_Release(iML);
1980 /* IMultiLanguage2 (IE5.0 and above) */
1981 trace("IMultiLanguage2\n");
1982 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1983 &IID_IMultiLanguage2, (void **)&iML2);
1984 if (ret != S_OK || !iML2) return;
1987 test_GetLcidFromRfc1766(iML2);
1988 test_GetRfc1766FromLcid(iML2);
1989 test_GetRfc1766Info(iML2);
1990 test_GetNumberOfCodePageInfo(iML2);
1992 test_EnumCodePages(iML2, 0);
1993 test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
1994 test_EnumCodePages(iML2, MIMECONTF_BROWSER);
1995 test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
1996 test_EnumCodePages(iML2, MIMECONTF_VALID);
1997 /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
1998 /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/
2000 test_EnumScripts(iML2, 0);
2001 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
2002 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);
2004 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
2005 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
2006 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
2007 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
2009 test_multibyte_to_unicode_translations(iML2);
2010 test_IMultiLanguage2_ConvertStringFromUnicode(iML2);
2012 test_IsCodePageInstallable(iML2);
2014 IMultiLanguage2_Release(iML2);
2017 /* IMLangFontLink */
2018 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2019 &IID_IMLangFontLink, (void **)&iMLFL);
2020 if (ret != S_OK || !iMLFL) return;
2022 IMLangFontLink_Test(iMLFL);
2023 IMLangFontLink_Release(iMLFL);
2025 /* IMLangFontLink2 */
2026 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2027 &IID_IMLangFontLink2, (void **)&iMLFL2);
2028 if (ret != S_OK || !iMLFL2) return;
2030 test_GetScriptFontInfo(iMLFL2);
2031 test_GetFontUnicodeRanges(iMLFL2);
2032 test_CodePageToScriptID(iMLFL2);
2033 IMLangFontLink2_Release(iMLFL2);