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 static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
259 /* these APIs are broken regarding constness of the input buffer */
260 char stringA[] = "Just a test string\0"; /* double 0 for CP_UNICODE tests */
261 WCHAR stringW[] = {'J','u','s','t',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
264 UINT lenA, lenW, expected_len;
267 /* IMultiLanguage2_ConvertStringToUnicode tests */
269 memset(bufW, 'x', sizeof(bufW));
271 lenW = sizeof(bufW)/sizeof(bufW[0]);
272 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
273 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
274 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
275 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
277 memset(bufW, 'x', sizeof(bufW));
279 lenW = sizeof(bufW)/sizeof(bufW[0]);
280 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
281 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
282 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
283 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
284 if (lenW < sizeof(bufW)/sizeof(bufW[0])) {
285 /* can only happen if the convert call fails */
286 ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
287 bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
289 ok(!lstrcmpW(bufW, stringW), "bufW/stringW mismatch\n");
291 memset(bufW, 'x', sizeof(bufW));
294 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
295 ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringToUnicode should fail: %08x\n", ret);
296 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
297 /* still has to do partial conversion */
298 ok(!memcmp(bufW, stringW, 5 * sizeof(WCHAR)), "bufW/stringW mismatch\n");
300 memset(bufW, 'x', sizeof(bufW));
302 lenW = sizeof(bufW)/sizeof(bufW[0]);
303 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, CP_UNICODE, stringA, &lenA, bufW, &lenW);
304 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
305 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
306 ok(lenW == lstrlenW(stringW)/(int)sizeof(WCHAR), "wrong lenW %u\n", lenW);
307 ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
308 bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
309 ok(!lstrcmpA((LPCSTR)bufW, stringA), "bufW/stringA mismatch\n");
311 memset(bufW, 'x', sizeof(bufW));
312 lenA = lstrlenA(stringA);
314 ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, NULL, &lenW);
315 ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
316 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
317 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
318 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
320 memset(bufW, 'x', sizeof(bufW));
321 lenA = lstrlenA(stringA);
322 lenW = sizeof(bufW)/sizeof(bufW[0]);
323 ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
324 ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
325 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
326 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
327 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
329 memset(bufW, 'x', sizeof(bufW));
330 lenA = lstrlenA(stringA);
332 ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
333 ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
334 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
335 expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
336 ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
338 /* IMultiLanguage2_ConvertStringFromUnicode tests */
340 memset(bufA, 'x', sizeof(bufA));
343 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
344 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
345 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
346 ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
348 memset(bufA, 'x', sizeof(bufA));
351 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
352 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
353 ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
354 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
355 ok(bufA[lenA] != 0, "buf should not be 0 terminated\n");
356 bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
357 ok(!lstrcmpA(bufA, stringA), "bufA/stringA mismatch\n");
359 memset(bufA, 'x', sizeof(bufA));
362 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
363 ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringFromUnicode should fail: %08x\n", ret);
364 ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
365 /* still has to do partial conversion */
366 ok(!memcmp(bufA, stringA, 5), "bufW/stringW mismatch\n");
368 memset(bufA, 'x', sizeof(bufA));
371 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, CP_UNICODE, stringW, &lenW, bufA, &lenA);
372 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
373 ok(lenA == lstrlenA(stringA) * (int)sizeof(WCHAR), "wrong lenA %u\n", lenA);
374 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
375 ok(bufA[lenA] != 0 && bufA[lenA+1] != 0, "buf should not be 0 terminated\n");
376 bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
377 bufA[lenA+1] = 0; /* sizeof(WCHAR) */
378 ok(!lstrcmpW((LPCWSTR)bufA, stringW), "bufA/stringW mismatch\n");
380 memset(bufA, 'x', sizeof(bufA));
381 lenW = lstrlenW(stringW);
383 ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, NULL, &lenA);
384 ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
385 ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
386 expected_len = WideCharToMultiByte(1252, 0, stringW, lenW, NULL, 0, NULL, NULL);
387 ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);
390 static void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
392 ok(cpinfo1->dwFlags == cpinfo2->dwFlags, "dwFlags mismatch: %08x != %08x\n", cpinfo1->dwFlags, cpinfo2->dwFlags);
393 ok(cpinfo1->uiCodePage == cpinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", cpinfo1->uiCodePage, cpinfo2->uiCodePage);
394 ok(cpinfo1->uiFamilyCodePage == cpinfo2->uiFamilyCodePage, "uiFamilyCodePage mismatch: %u != %u\n", cpinfo1->uiFamilyCodePage, cpinfo2->uiFamilyCodePage);
395 ok(!lstrcmpW(cpinfo1->wszDescription, cpinfo2->wszDescription), "wszDescription mismatch\n");
396 ok(!lstrcmpW(cpinfo1->wszWebCharset, cpinfo2->wszWebCharset), "wszWebCharset mismatch\n");
397 ok(!lstrcmpW(cpinfo1->wszHeaderCharset, cpinfo2->wszHeaderCharset), "wszHeaderCharset mismatch\n");
398 ok(!lstrcmpW(cpinfo1->wszBodyCharset, cpinfo2->wszBodyCharset), "wszBodyCharset mismatch\n");
399 ok(!lstrcmpW(cpinfo1->wszFixedWidthFont, cpinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
400 ok(!lstrcmpW(cpinfo1->wszProportionalFont, cpinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
401 ok(cpinfo1->bGDICharset == cpinfo2->bGDICharset, "bGDICharset mismatch: %d != %d\n", cpinfo1->bGDICharset, cpinfo2->bGDICharset);
405 static const char *dump_mime_flags(DWORD flags)
407 static char buf[1024];
411 if (flags & MIMECONTF_MAILNEWS) strcat(buf, " MIMECONTF_MAILNEWS");
412 if (flags & MIMECONTF_BROWSER) strcat(buf, " MIMECONTF_BROWSER");
413 if (flags & MIMECONTF_MINIMAL) strcat(buf, " MIMECONTF_MINIMAL");
414 if (flags & MIMECONTF_IMPORT) strcat(buf, " MIMECONTF_IMPORT");
415 if (flags & MIMECONTF_SAVABLE_MAILNEWS) strcat(buf, " MIMECONTF_SAVABLE_MAILNEWS");
416 if (flags & MIMECONTF_SAVABLE_BROWSER) strcat(buf, " MIMECONTF_SAVABLE_BROWSER");
417 if (flags & MIMECONTF_EXPORT) strcat(buf, " MIMECONTF_EXPORT");
418 if (flags & MIMECONTF_PRIVCONVERTER) strcat(buf, " MIMECONTF_PRIVCONVERTER");
419 if (flags & MIMECONTF_VALID) strcat(buf, " MIMECONTF_VALID");
420 if (flags & MIMECONTF_VALID_NLS) strcat(buf, " MIMECONTF_VALID_NLS");
421 if (flags & MIMECONTF_MIME_IE4) strcat(buf, " MIMECONTF_MIME_IE4");
422 if (flags & MIMECONTF_MIME_LATEST) strcat(buf, " MIMECONTF_MIME_LATEST");
423 if (flags & MIMECONTF_MIME_REGISTRY) strcat(buf, " MIMECONTF_MIME_REGISTRY");
429 static HRESULT check_convertible(IMultiLanguage2 *iML2, UINT from, UINT to)
431 CHAR convert[MAX_PATH];
436 static WCHAR strW[] = {'a','b','c',0};
438 /* Check to see if the target codepage has these characters or not */
444 cb = WideCharToMultiByte( from, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
445 strW, 3, ch, sizeof(ch), NULL, &fDefaultChar);
447 if(cb == 0 || fDefaultChar)
449 trace("target codepage %i does not contain 'abc'\n",from);
454 srcsz = lstrlenW(strW) + 1;
456 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, from, strW,
457 &srcsz, convert, &destsz);
463 hr = IMultiLanguage2_ConvertString(iML2, NULL, from, to, (BYTE *)convert,
464 &srcsz, dest, &destsz);
471 static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
473 IEnumCodePage *iEnumCP = NULL;
481 ret = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &total);
482 ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfCodePageInfo: expected S_OK/!0, got %08x/%u\n", ret, total);
484 trace("total mlang supported codepages %u\n", total);
486 ret = IMultiLanguage2_EnumCodePages(iML2, flags, LANG_NEUTRAL, &iEnumCP);
487 ok(ret == S_OK && iEnumCP, "IMultiLanguage2_EnumCodePages: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumCP);
489 ret = IEnumCodePage_Reset(iEnumCP);
490 ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
492 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, &n);
494 ok(n == 0 && ret == S_FALSE, "IEnumCodePage_Next: expected 0/S_FALSE, got %u/%08x\n", n, ret);
495 else if (ret == E_FAIL)
496 ok(n == 65536 && ret == E_FAIL, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
497 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, NULL);
499 ok(ret == S_FALSE, "IEnumCodePage_Next: expected S_FALSE, got %08x\n", ret);
500 else if (ret == E_FAIL)
501 ok(n == 65536 && ret == E_FAIL, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
503 cpinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*cpinfo) * total * 2);
506 ret = IEnumCodePage_Next(iEnumCP, 0, cpinfo, &n);
507 ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
510 ret = IEnumCodePage_Next(iEnumCP, n, cpinfo, &n);
511 ok(ret == S_OK && n != 0, "IEnumCodePage_Next: expected S_OK/!0, got %08x/%u\n", ret, n);
513 trace("flags %08x, enumerated codepages %u\n", flags, n);
517 ok(n == total, "IEnumCodePage_Next: expected %u, got %u\n", total, n);
519 flags = MIMECONTF_MIME_LATEST;
524 for (i = 0; i < n; i++)
528 HRESULT convertible = S_OK;
529 static const WCHAR autoW[] = {'_','a','u','t','o',0};
530 static const WCHAR feffW[] = {'u','n','i','c','o','d','e','F','E','F','F',0};
533 trace("MIMECPINFO #%u:\n"
536 "uiFamilyCodePage %u\n"
537 "wszDescription %s\n"
539 "wszHeaderCharset %s\n"
540 "wszBodyCharset %s\n"
541 "wszFixedWidthFont %s\n"
542 "wszProportionalFont %s\n"
543 "bGDICharset %d\n\n",
545 cpinfo[i].dwFlags, dump_mime_flags(cpinfo[i].dwFlags),
546 cpinfo[i].uiCodePage,
547 cpinfo[i].uiFamilyCodePage,
548 wine_dbgstr_w(cpinfo[i].wszDescription),
549 wine_dbgstr_w(cpinfo[i].wszWebCharset),
550 wine_dbgstr_w(cpinfo[i].wszHeaderCharset),
551 wine_dbgstr_w(cpinfo[i].wszBodyCharset),
552 wine_dbgstr_w(cpinfo[i].wszFixedWidthFont),
553 wine_dbgstr_w(cpinfo[i].wszProportionalFont),
554 cpinfo[i].bGDICharset);
556 ok(cpinfo[i].dwFlags & flags, "enumerated flags %08x do not include requested %08x\n", cpinfo[i].dwFlags, flags);
558 if (TranslateCharsetInfo((DWORD *)(INT_PTR)cpinfo[i].uiFamilyCodePage, &csi, TCI_SRCCODEPAGE))
559 ok(cpinfo[i].bGDICharset == csi.ciCharset, "%d != %d\n", cpinfo[i].bGDICharset, csi.ciCharset);
561 if (winetest_debug > 1)
562 trace("TranslateCharsetInfo failed for cp %u\n", cpinfo[i].uiFamilyCodePage);
565 trace("%u: codepage %u family %u\n", i, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
568 /* support files for some codepages might be not installed, or
569 * the codepage is just an alias.
571 if (IsValidCodePage(cpinfo[i].uiCodePage))
573 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UNICODE);
574 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(%u -> CP_UNICODE) = %08x\n", cpinfo[i].uiCodePage, ret);
575 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, cpinfo[i].uiCodePage);
576 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
578 convertible = check_convertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
579 if (convertible != E_FAIL)
581 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
582 ok(ret == convertible, "IMultiLanguage2_IsConvertible(%u -> CP_UTF8) = %08x\n", cpinfo[i].uiCodePage, ret);
583 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, cpinfo[i].uiCodePage);
584 ok(ret == convertible, "IMultiLanguage2_IsConvertible(CP_UTF8 -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
588 if (winetest_debug > 1)
589 trace("IsValidCodePage failed for cp %u\n", cpinfo[i].uiCodePage);
591 if (memcmp(cpinfo[i].wszWebCharset,feffW,sizeof(WCHAR)*11)==0)
592 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
595 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszWebCharset, &mcsi);
596 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
597 if (memcmp(cpinfo[i].wszWebCharset, autoW, 5 * sizeof(WCHAR)))
599 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
601 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszWebCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
603 ok(!lstrcmpiW(cpinfo[i].wszWebCharset, mcsi.wszCharset), "%s != %s\n",
604 wine_dbgstr_w(cpinfo[i].wszWebCharset), wine_dbgstr_w(mcsi.wszCharset));
608 /* native mlang returns completely messed up encodings in some cases */
609 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
610 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
611 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
612 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
617 if (memcmp(cpinfo[i].wszHeaderCharset,feffW,sizeof(WCHAR)*11)==0)
618 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
621 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszHeaderCharset, &mcsi);
622 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
623 if (memcmp(cpinfo[i].wszHeaderCharset, autoW, 5 * sizeof(WCHAR)))
625 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
627 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszHeaderCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
629 ok(!lstrcmpiW(cpinfo[i].wszHeaderCharset, mcsi.wszCharset), "%s != %s\n",
630 wine_dbgstr_w(cpinfo[i].wszHeaderCharset), wine_dbgstr_w(mcsi.wszCharset));
634 /* native mlang returns completely messed up encodings in some cases */
635 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
636 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
637 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
638 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
643 if (memcmp(cpinfo[i].wszBodyCharset,feffW,sizeof(WCHAR)*11)==0)
644 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
647 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszBodyCharset, &mcsi);
648 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
649 if (memcmp(cpinfo[i].wszBodyCharset, autoW, 5 * sizeof(WCHAR)))
651 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
653 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszBodyCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
655 ok(!lstrcmpiW(cpinfo[i].wszBodyCharset, mcsi.wszCharset), "%s != %s\n",
656 wine_dbgstr_w(cpinfo[i].wszBodyCharset), wine_dbgstr_w(mcsi.wszCharset));
660 /* native mlang returns completely messed up encodings in some cases */
661 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
662 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
663 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
664 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
670 /* now IEnumCodePage_Next should fail, since pointer is at the end */
672 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
673 ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
675 ret = IEnumCodePage_Reset(iEnumCP);
676 ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
678 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
679 ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
680 cpinfo_cmp(&cpinfo[0], &cpinfo2);
684 /* Due to a bug in MS' implementation of IEnumCodePage_Skip
685 * it's not used here.
687 ret = IEnumCodePage_Skip(iEnumCP, 1);
688 ok(ret == S_OK, "IEnumCodePage_Skip: expected S_OK, got %08x\n", ret);
690 for (i = 0; i < total - 1; i++)
693 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
694 ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
695 cpinfo_cmp(&cpinfo[i + 1], &cpinfo2);
698 HeapFree(GetProcessHeap(), 0, cpinfo);
699 IEnumCodePage_Release(iEnumCP);
702 static void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
704 ok(sinfo1->ScriptId == sinfo2->ScriptId, "ScriptId mismatch: %d != %d\n", sinfo1->ScriptId, sinfo2->ScriptId);
705 ok(sinfo1->uiCodePage == sinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", sinfo1->uiCodePage, sinfo2->uiCodePage);
706 ok(!lstrcmpW(sinfo1->wszDescription, sinfo2->wszDescription), "wszDescription mismatch\n");
707 ok(!lstrcmpW(sinfo1->wszFixedWidthFont, sinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
708 ok(!lstrcmpW(sinfo1->wszProportionalFont, sinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
711 static void test_EnumScripts(IMultiLanguage2 *iML2, DWORD flags)
713 IEnumScript *iEnumScript = NULL;
721 ret = IMultiLanguage2_GetNumberOfScripts(iML2, &total);
722 ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfScripts: expected S_OK/!0, got %08x/%u\n", ret, total);
724 trace("total mlang supported scripts %u\n", total);
726 ret = IMultiLanguage2_EnumScripts(iML2, flags, LANG_NEUTRAL, &iEnumScript);
727 ok(ret == S_OK && iEnumScript, "IMultiLanguage2_EnumScripts: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumScript);
729 ret = IEnumScript_Reset(iEnumScript);
730 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
732 ret = IEnumScript_Next(iEnumScript, 0, NULL, &n);
733 ok(n == 65536 && ret == E_FAIL, "IEnumScript_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
734 ret = IEnumScript_Next(iEnumScript, 0, NULL, NULL);
735 ok(ret == E_FAIL, "IEnumScript_Next: expected E_FAIL, got %08x\n", ret);
737 sinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*sinfo) * total * 2);
740 ret = IEnumScript_Next(iEnumScript, 0, sinfo, &n);
741 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
744 ret = IEnumScript_Next(iEnumScript, n, sinfo, &n);
745 ok(ret == S_OK && n != 0, "IEnumScript_Next: expected S_OK, got %08x/%u\n", ret, n);
747 trace("flags %08x, enumerated scripts %u\n", flags, n);
751 ok(n == total, "IEnumScript_Next: expected %u, got %u\n", total, n);
756 for (i = 0; pGetCPInfoExA && i < n; i++)
758 #ifdef DUMP_SCRIPT_INFO
759 trace("SCRIPTINFO #%u:\n"
762 "wszDescription %s\n"
763 "wszFixedWidthFont %s\n"
764 "wszProportionalFont %s\n\n",
768 wine_dbgstr_w(sinfo[i].wszDescription),
769 wine_dbgstr_w(sinfo[i].wszFixedWidthFont),
770 wine_dbgstr_w(sinfo[i].wszProportionalFont));
771 trace("%u codepage %u\n", i, sinfo[i].uiCodePage);
775 /* now IEnumScript_Next should fail, since pointer is at the end */
777 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
778 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
780 ret = IEnumScript_Reset(iEnumScript);
781 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
783 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
784 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
785 scriptinfo_cmp(&sinfo[0], &sinfo2);
789 /* Due to a bug in MS' implementation of IEnumScript_Skip
790 * it's not used here.
792 ret = IEnumScript_Skip(iEnumScript, 1);
793 ok(ret == S_OK, "IEnumScript_Skip: expected S_OK, got %08x\n", ret);
795 for (i = 0; i < total - 1; i++)
798 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
799 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
800 scriptinfo_cmp(&sinfo[i + 1], &sinfo2);
803 HeapFree(GetProcessHeap(), 0, sinfo);
804 IEnumScript_Release(iEnumScript);
807 static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
809 DWORD dwCodePages, dwManyCodePages;
810 DWORD dwCmpCodePages;
812 static const WCHAR str[3] = { 'd', 0x0436, 0xff90 };
817 ret = IMLangFontLink_CodePageToCodePages(iMLFL, -1, &dwCodePages);
818 ok(ret == E_FAIL, "IMLangFontLink_CodePageToCodePages should fail: %x\n", ret);
819 ok(dwCodePages == 0, "expected 0, got %u\n", dwCodePages);
822 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 932, &dwCodePages);
823 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
824 ok(dwCodePages == FS_JISJAPAN, "expected FS_JISJAPAN, got %08x\n", dwCodePages);
826 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwCodePages, 1035, &CodePage);
827 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
828 ok(CodePage == 932, "Incorrect CodePage Returned (%i)\n",CodePage);
831 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1252, &dwManyCodePages);
832 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
833 ok(dwManyCodePages == FS_LATIN1, "expected FS_LATIN1, got %08x\n", dwManyCodePages);
835 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1256, &dwCodePages);
836 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
837 ok(dwCodePages == FS_ARABIC, "expected FS_ARABIC, got %08x\n", dwCodePages);
838 dwManyCodePages |= dwCodePages;
839 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 874, &dwCodePages);
840 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
841 ok(dwCodePages == FS_THAI, "expected FS_THAI, got %08x\n", dwCodePages);
842 dwManyCodePages |= dwCodePages;
844 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 1256, &CodePage);
845 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
846 ok(CodePage == 1256, "Incorrect CodePage Returned (%i)\n",CodePage);
848 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 936, &CodePage);
849 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
850 ok(CodePage == 1252, "Incorrect CodePage Returned (%i)\n",CodePage);
852 /* Tests for GetCharCodePages */
855 dwCmpCodePages = FS_LATIN1 | FS_LATIN2 | FS_CYRILLIC | FS_GREEK | FS_TURKISH
856 | FS_HEBREW | FS_ARABIC | FS_BALTIC | FS_VIETNAMESE | FS_THAI
857 | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG | FS_CHINESETRAD;
858 ret = IMLangFontLink_GetCharCodePages(iMLFL, 'd', &dwCodePages);
859 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
860 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
864 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[0], 1, 0, &dwCodePages, &processed);
865 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
866 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
867 ok(processed == 1, "expected 1, got %d\n", processed);
870 dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
871 ret = IMLangFontLink_GetCharCodePages(iMLFL, 0x0436, &dwCodePages);
872 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
873 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
877 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[1], 1, 0, &dwCodePages, &processed);
878 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
879 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
880 ok(processed == 1, "expected 1, got %d\n", processed);
883 dwCmpCodePages = FS_JISJAPAN;
884 ret = IMLangFontLink_GetCharCodePages(iMLFL, 0xff90, &dwCodePages);
885 ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
886 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
890 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
891 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
892 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
893 ok(processed == 1, "expected 1, got %d\n", processed);
895 dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
898 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 2, 0, &dwCodePages, &processed);
899 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
900 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
901 ok(processed == 2, "expected 2, got %d\n", processed);
903 dwCmpCodePages = FS_JISJAPAN;
906 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 3, 0, &dwCodePages, &processed);
907 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
908 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
909 ok(processed == 3, "expected 3, got %d\n", processed);
911 dwCodePages = 0xffff;
913 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
914 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
915 ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
916 ok(processed == 1, "expected 0, got %d\n", processed);
918 ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, NULL, NULL);
919 ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
921 dwCodePages = 0xffff;
923 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, -1, 0, &dwCodePages, &processed);
924 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
925 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
926 ok(processed == 0, "expected 0, got %d\n", processed);
928 dwCodePages = 0xffff;
930 ret = IMLangFontLink_GetStrCodePages(iMLFL, NULL, 1, 0, &dwCodePages, &processed);
931 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
932 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
933 ok(processed == 0, "expected 0, got %d\n", processed);
935 dwCodePages = 0xffff;
937 ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 0, 0, &dwCodePages, &processed);
938 ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
939 ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
940 ok(processed == 0, "expected 0, got %d\n", processed);
943 /* copied from libs/wine/string.c */
944 static WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
948 const WCHAR *p1 = str, *p2 = sub;
949 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
950 if (!*p2) return (WCHAR *)str;
956 static void test_rfc1766(IMultiLanguage2 *iML2)
958 IEnumRfc1766 *pEnumRfc1766;
964 ret = IMultiLanguage2_EnumRfc1766(iML2, LANG_NEUTRAL, &pEnumRfc1766);
965 ok(ret == S_OK, "IMultiLanguage2_EnumRfc1766 error %08x\n", ret);
969 ret = IEnumRfc1766_Next(pEnumRfc1766, 1, &info, &n);
970 if (ret != S_OK) break;
973 trace("lcid %04x rfc_name %s locale_name %s\n",
974 info.lcid, wine_dbgstr_w(info.wszRfc1766), wine_dbgstr_w(info.wszLocaleName));
977 ok(n == 1, "couldn't fetch 1 RFC1766INFO structure\n");
979 /* verify the Rfc1766 value */
980 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, info.lcid, &rfcstr);
981 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
983 /* not an exact 1:1 correspondence between lcid and rfc1766 in the
984 * mlang database, e.g., nb-no -> 1044 -> no */
985 ok(strstrW(info.wszRfc1766, rfcstr) != NULL,
986 "Expected matching locale names\n");
988 SysFreeString(rfcstr);
990 IEnumRfc1766_Release(pEnumRfc1766);
993 static void test_GetLcidFromRfc1766(IMultiLanguage2 *iML2)
995 WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1000 static WCHAR en[] = { 'e','n',0 };
1001 static WCHAR en_them[] = { 'e','n','-','t','h','e','m',0 };
1002 static WCHAR english[] = { 'e','n','g','l','i','s','h',0 };
1005 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1007 MultiByteToWideChar(CP_ACP, 0, lcid_table[i].rfc1766, -1, rfc1766W, MAX_RFC1766_NAME);
1008 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, rfc1766W);
1010 /* IE <6.0 guess 0x412 (ko) from "kok" */
1011 ok((ret == lcid_table[i].hr) ||
1012 broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1013 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1015 ok((lcid == lcid_table[i].lcid) ||
1016 broken(lcid == lcid_table[i].broken_lcid), /* IE <6.0 */
1017 "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1021 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, NULL, en);
1022 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1024 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, NULL);
1025 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1027 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_them);
1028 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1032 static WCHAR en[] = {'e','n',0};
1034 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1035 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1036 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
1039 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, english);
1040 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1044 static WCHAR en[] = {'e','n',0};
1046 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1047 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1048 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
1053 static void test_Rfc1766ToLcid(void)
1059 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1061 ret = pRfc1766ToLcidA(&lcid, lcid_table[i].rfc1766);
1063 /* IE <6.0 guess 0x412 (ko) from "kok" */
1064 ok( (ret == lcid_table[i].hr) ||
1065 broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1066 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1068 ok( (lcid == lcid_table[i].lcid) ||
1069 broken(lcid == lcid_table[i].broken_lcid), /* IE <6.0 */
1070 "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1073 ret = pRfc1766ToLcidA(&lcid, NULL);
1074 ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1076 ret = pRfc1766ToLcidA(NULL, "en");
1077 ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1080 static void test_GetNumberOfCodePageInfo(IMultiLanguage2 *iML2)
1086 hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &value);
1087 ok( (hr == S_OK) && value,
1088 "got 0x%x with %d (expected S_OK with '!= 0')\n", hr, value);
1090 hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, NULL);
1091 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1095 static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
1097 CHAR expected[MAX_RFC1766_NAME];
1098 CHAR buffer[MAX_RFC1766_NAME + 1];
1103 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1107 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid_table[i].lcid, &rfcstr);
1108 ok(hr == lcid_table[i].hr,
1109 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1112 continue; /* no result-string created */
1114 WideCharToMultiByte(CP_ACP, 0, rfcstr, -1, buffer, sizeof(buffer), NULL, NULL);
1115 LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1116 lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1118 /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1119 ok( (!lstrcmpA(buffer, expected)) ||
1120 broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1121 "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1123 SysFreeString(rfcstr);
1126 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL);
1127 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1130 static void test_LcidToRfc1766(void)
1132 CHAR expected[MAX_RFC1766_NAME];
1133 CHAR buffer[MAX_RFC1766_NAME * 2];
1137 for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1139 memset(buffer, '#', sizeof(buffer)-1);
1140 buffer[sizeof(buffer)-1] = '\0';
1142 hr = pLcidToRfc1766A(lcid_table[i].lcid, buffer, MAX_RFC1766_NAME);
1144 /* IE <5.0 does not recognize 0x180c (fr-mc) and 0x457 (kok) */
1145 ok( (hr == lcid_table[i].hr) ||
1146 broken(lcid_table[i].broken_lcid && (hr == E_FAIL)),
1147 "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1152 LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1153 lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1155 /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1156 /* IE <5.0 return "fr" for LCID 0x180c ("fr-mc") */
1157 ok( (!lstrcmpA(buffer, expected)) ||
1158 broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1159 "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1163 memset(buffer, '#', sizeof(buffer)-1);
1164 buffer[sizeof(buffer)-1] = '\0';
1165 hr = pLcidToRfc1766A(-1, buffer, MAX_RFC1766_NAME);
1166 ok(hr == E_FAIL, "got 0x%08x and '%s' (expected E_FAIL)\n", hr, buffer);
1168 hr = pLcidToRfc1766A(LANG_ENGLISH, NULL, MAX_RFC1766_NAME);
1169 ok(hr == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", hr);
1171 memset(buffer, '#', sizeof(buffer)-1);
1172 buffer[sizeof(buffer)-1] = '\0';
1173 hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, -1);
1174 ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1176 memset(buffer, '#', sizeof(buffer)-1);
1177 buffer[sizeof(buffer)-1] = '\0';
1178 hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, 0);
1179 ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1182 static void test_GetRfc1766Info(IMultiLanguage2 *iML2)
1184 WCHAR short_broken_name[MAX_LOCALE_NAME];
1185 CHAR rfc1766A[MAX_RFC1766_NAME + 1];
1186 BYTE buffer[sizeof(RFC1766INFO) + 4];
1187 PRFC1766INFO prfc = (RFC1766INFO *) buffer;
1191 for(i = 0; i < sizeof(info_table) / sizeof(info_table[0]); i++) {
1192 memset(buffer, 'x', sizeof(RFC1766INFO) + 2);
1193 buffer[sizeof(buffer) -1] = 0;
1194 buffer[sizeof(buffer) -2] = 0;
1196 ret = IMultiLanguage2_GetRfc1766Info(iML2, info_table[i].lcid, info_table[i].lang, prfc);
1197 WideCharToMultiByte(CP_ACP, 0, prfc->wszRfc1766, -1, rfc1766A, MAX_RFC1766_NAME, NULL, NULL);
1198 ok(ret == S_OK, "#%02d: got 0x%x (expected S_OK)\n", i, ret);
1199 ok(prfc->lcid == info_table[i].lcid,
1200 "#%02d: got 0x%04x (expected 0x%04x)\n", i, prfc->lcid, info_table[i].lcid);
1202 ok(!lstrcmpA(rfc1766A, info_table[i].rfc1766),
1203 "#%02d: got '%s' (expected '%s')\n", i, rfc1766A, info_table[i].rfc1766);
1205 /* Some IE versions truncate an oversized name one character too short */
1206 if (info_table[i].broken_name) {
1207 lstrcpyW(short_broken_name, info_table[i].broken_name);
1208 short_broken_name[MAX_LOCALE_NAME - 2] = 0;
1211 if (info_table[i].todo & TODO_NAME) {
1213 ok( (!lstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1214 (info_table[i].broken_name && (
1215 broken(!lstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1216 broken(!lstrcmpW(prfc->wszLocaleName, short_broken_name)))),
1217 "#%02d: got %s (expected %s)\n", i,
1218 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1221 ok( (!lstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1222 (info_table[i].broken_name && (
1223 broken(!lstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1224 broken(!lstrcmpW(prfc->wszLocaleName, short_broken_name)))),
1225 "#%02d: got %s (expected %s)\n", i,
1226 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1230 /* SUBLANG_NEUTRAL only allowed for English, Arabic, Chinese */
1231 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_GERMAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1232 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1234 ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_ITALIAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1235 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1237 /* NULL not allowed */
1238 ret = IMultiLanguage2_GetRfc1766Info(iML2, 0, LANG_ENGLISH, prfc);
1239 ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1241 ret = IMultiLanguage2_GetRfc1766Info(iML2, LANG_ENGLISH, LANG_ENGLISH, NULL);
1242 ok(ret == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", ret);
1245 static void test_IMultiLanguage2_ConvertStringFromUnicode(IMultiLanguage2 *iML2)
1247 CHAR dest[MAX_PATH];
1248 CHAR invariate[MAX_PATH];
1252 static WCHAR src[] = {'a','b','c',0};
1254 memset(invariate, 'x', sizeof(invariate));
1257 memset(dest, 'x', sizeof(dest));
1258 srcsz = lstrlenW(src) + 1;
1259 destsz = sizeof(dest);
1260 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1261 &srcsz, dest, &destsz);
1262 ok(hr == S_OK || hr == E_FAIL,"expected S_OK or E_FAIL, got %08x\n",hr);
1265 ok(srcsz == lstrlenW(src) + 1,
1266 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1268 else if (hr == E_FAIL)
1271 "Expected %u, got %u\n", 0, srcsz);
1274 ok(!memcmp(dest, invariate, sizeof(dest)),
1275 "Expected dest to be unchanged, got %s\n", dest);
1276 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1278 /* pcSrcSize NULL */
1279 memset(dest, 'x', sizeof(dest));
1280 destsz = sizeof(dest);
1281 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1282 NULL, dest, &destsz);
1283 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1284 ok(!strncmp(dest, "abc", 3),
1285 "Expected first three chars to be \"abc\"\n");
1286 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1287 "Expected rest of dest to be unchanged, got %s\n", dest);
1288 ok(destsz == lstrlenW(src),
1289 "Expected %u, got %u\n", lstrlenW(src), destsz);
1291 /* both pSrcStr and pcSrcSize NULL */
1292 memset(dest, 'x', sizeof(dest));
1293 destsz = sizeof(dest);
1294 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1295 NULL, dest, &destsz);
1296 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1297 ok(!memcmp(dest, invariate, sizeof(dest)),
1298 "Expected dest to be unchanged, got %s\n", dest);
1299 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1302 memset(dest, 'x', sizeof(dest));
1303 srcsz = lstrlenW(src) + 1;
1304 destsz = sizeof(dest);
1305 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1306 &srcsz, NULL, &destsz);
1307 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1308 ok(srcsz == lstrlenW(src) + 1,
1309 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1310 ok(destsz == lstrlenW(src) + 1,
1311 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1313 /* pcDstSize NULL */
1314 memset(dest, 'x', sizeof(dest));
1315 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1316 &srcsz, dest, NULL);
1317 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1318 ok(srcsz == lstrlenW(src) + 1,
1319 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1320 ok(!memcmp(dest, invariate, sizeof(dest)),
1321 "Expected dest to be unchanged, got %s\n", dest);
1323 /* pcSrcSize is 0 */
1324 memset(dest, 'x', sizeof(dest));
1326 destsz = sizeof(dest);
1327 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1328 &srcsz, dest, &destsz);
1329 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1330 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1331 ok(!memcmp(dest, invariate, sizeof(dest)),
1332 "Expected dest to be unchanged, got %s\n", dest);
1333 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1335 /* pcSrcSize does not include NULL terminator */
1336 memset(dest, 'x', sizeof(dest));
1337 srcsz = lstrlenW(src);
1338 destsz = sizeof(dest);
1339 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1340 &srcsz, dest, &destsz);
1341 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1342 ok(srcsz == lstrlenW(src),
1343 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1344 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1345 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1346 "Expected rest of dest to be unchanged, got %s\n", dest);
1347 ok(destsz == lstrlenW(src),
1348 "Expected %u, got %u\n", lstrlenW(src), destsz);
1350 /* pcSrcSize includes NULL terminator */
1351 memset(dest, 'x', sizeof(dest));
1352 srcsz = lstrlenW(src) + 1;
1353 destsz = sizeof(dest);
1354 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1355 &srcsz, dest, &destsz);
1356 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1357 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1358 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1359 ok(destsz == lstrlenW(src) + 1,
1360 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1362 /* pcSrcSize is -1 */
1363 memset(dest, 'x', sizeof(dest));
1365 destsz = sizeof(dest);
1366 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1367 &srcsz, dest, &destsz);
1368 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1369 ok(srcsz == lstrlenW(src),
1370 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1371 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1372 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1373 "Expected rest of dest to be unchanged, got %s\n", dest);
1374 ok(destsz == lstrlenW(src),
1375 "Expected %u, got %u\n", lstrlenW(src), destsz);
1377 /* pcDstSize is 0 */
1378 memset(dest, 'x', sizeof(dest));
1379 srcsz = lstrlenW(src) + 1;
1381 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1382 &srcsz, dest, &destsz);
1383 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1384 ok(srcsz == lstrlenW(src) + 1,
1385 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1386 ok(!memcmp(dest, invariate, sizeof(dest)),
1387 "Expected dest to be unchanged, got %s\n", dest);
1388 ok(destsz == lstrlenW(src) + 1,
1389 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1391 /* pcDstSize is not large enough */
1392 memset(dest, 'x', sizeof(dest));
1393 srcsz = lstrlenW(src) + 1;
1394 destsz = lstrlenW(src);
1395 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1396 &srcsz, dest, &destsz);
1397 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1398 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1399 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1400 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1401 "Expected rest of dest to be unchanged, got %s\n", dest);
1402 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1404 /* pcDstSize (bytes) does not leave room for NULL terminator */
1405 memset(dest, 'x', sizeof(dest));
1406 srcsz = lstrlenW(src) + 1;
1407 destsz = lstrlenW(src) * sizeof(WCHAR);
1408 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1409 &srcsz, dest, &destsz);
1410 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1411 ok(srcsz == lstrlenW(src) + 1,
1412 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1413 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1414 ok(destsz == lstrlenW(src) + 1,
1415 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1418 static void test_ConvertINetUnicodeToMultiByte(void)
1420 CHAR dest[MAX_PATH];
1421 CHAR invariate[MAX_PATH];
1425 static WCHAR src[] = {'a','b','c',0};
1427 memset(invariate, 'x', sizeof(invariate));
1430 memset(dest, 'x', sizeof(dest));
1431 srcsz = lstrlenW(src) + 1;
1432 destsz = sizeof(dest);
1433 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, &srcsz, dest, &destsz);
1434 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1436 ok(srcsz == lstrlenW(src) + 1,
1437 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1438 else if (hr == E_FAIL)
1440 "Expected %u, got %u\n", 0, srcsz);
1441 ok(!memcmp(dest, invariate, sizeof(dest)),
1442 "Expected dest to be unchanged, got %s\n", dest);
1443 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1445 /* lpnWideCharCount NULL */
1446 memset(dest, 'x', sizeof(dest));
1447 destsz = sizeof(dest);
1448 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, NULL, dest, &destsz);
1449 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1450 ok(!strncmp(dest, "abc", 3),
1451 "Expected first three chars to be \"abc\"\n");
1452 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1453 "Expected rest of dest to be unchanged, got %s\n", dest);
1454 ok(destsz == lstrlenW(src),
1455 "Expected %u, got %u\n", lstrlenW(src), destsz);
1457 /* both lpSrcStr and lpnWideCharCount NULL */
1458 memset(dest, 'x', sizeof(dest));
1459 destsz = sizeof(dest);
1460 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, NULL, dest, &destsz);
1461 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
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);
1467 memset(dest, 'x', sizeof(dest));
1468 srcsz = lstrlenW(src) + 1;
1469 destsz = sizeof(dest);
1470 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, NULL, &destsz);
1471 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1472 ok(srcsz == lstrlenW(src) + 1,
1473 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1474 ok(destsz == lstrlenW(src) + 1,
1475 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1477 /* lpnMultiCharCount NULL */
1478 memset(dest, 'x', sizeof(dest));
1479 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, NULL);
1480 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1481 ok(srcsz == lstrlenW(src) + 1,
1482 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1483 ok(!memcmp(dest, invariate, sizeof(dest)),
1484 "Expected dest to be unchanged, got %s\n", dest);
1486 /* lpnWideCharCount is 0 */
1487 memset(dest, 'x', sizeof(dest));
1489 destsz = sizeof(dest);
1490 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1491 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1492 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1493 ok(!memcmp(dest, invariate, sizeof(dest)),
1494 "Expected dest to be unchanged, got %s\n", dest);
1495 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1497 /* lpnWideCharCount does not include NULL terminator */
1498 memset(dest, 'x', sizeof(dest));
1499 srcsz = lstrlenW(src);
1500 destsz = sizeof(dest);
1501 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1502 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1503 ok(srcsz == lstrlenW(src),
1504 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1505 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1506 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1507 "Expected rest of dest to be unchanged, got %s\n", dest);
1508 ok(destsz == lstrlenW(src),
1509 "Expected %u, got %u\n", lstrlenW(src), destsz);
1511 /* lpnWideCharCount includes NULL terminator */
1512 memset(dest, 'x', sizeof(dest));
1513 srcsz = lstrlenW(src) + 1;
1514 destsz = sizeof(dest);
1515 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1516 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1517 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1518 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1519 ok(destsz == lstrlenW(src) + 1,
1520 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1522 /* lpnWideCharCount is -1 */
1523 memset(dest, 'x', sizeof(dest));
1525 destsz = sizeof(dest);
1526 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1527 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1528 ok(srcsz == lstrlenW(src),
1529 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1530 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1531 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1532 "Expected rest of dest to be unchanged, got %s\n", dest);
1533 ok(destsz == lstrlenW(src),
1534 "Expected %u, got %u\n", lstrlenW(src), destsz);
1536 /* lpnMultiCharCount is 0 */
1537 memset(dest, 'x', sizeof(dest));
1538 srcsz = lstrlenW(src) + 1;
1540 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1541 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1542 ok(srcsz == lstrlenW(src) + 1,
1543 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1544 ok(!memcmp(dest, invariate, sizeof(dest)),
1545 "Expected dest to be unchanged, got %s\n", dest);
1546 ok(destsz == lstrlenW(src) + 1,
1547 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1549 /* lpnMultiCharCount is not large enough */
1550 memset(dest, 'x', sizeof(dest));
1551 srcsz = lstrlenW(src) + 1;
1552 destsz = lstrlenW(src);
1553 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1554 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1555 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1556 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1557 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1558 "Expected rest of dest to be unchanged, got %s\n", dest);
1559 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1561 /* lpnMultiCharCount (bytes) does not leave room for NULL terminator */
1562 memset(dest, 'x', sizeof(dest));
1563 srcsz = lstrlenW(src) + 1;
1564 destsz = lstrlenW(src) * sizeof(WCHAR);
1565 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1566 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1567 ok(srcsz == lstrlenW(src) + 1,
1568 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1569 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1570 ok(destsz == lstrlenW(src) + 1,
1571 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1574 static void test_JapaneseConversion(void)
1577 static WCHAR unc_jp[9][12] = {
1578 {9,0x31,0x20,0x3042,0x3044,0x3046,0x3048,0x304a,0x000d,0x000a},
1579 {9,0x31,0x20,0x30a2,0x30a4,0x30a6,0x30a8,0x30aa,0x000d,0x000a},
1580 {9,0x31,0x20,0xff71,0xff72,0xff73,0xff74,0xff75,0x000d,0x000a},
1581 {9,0x31,0x20,0x3041,0x3043,0x3045,0x3047,0x3049,0x000d,0x000a},
1582 {9,0x31,0x20,0x30a1,0x30a3,0x30a5,0x30a7,0x30a9,0x000d,0x000a},
1583 {9,0x31,0x20,0xff67,0xff68,0xff69,0xff6a,0xff6b,0x000d,0x000a},
1584 {9,0x31,0x20,0x300c,0x65e5,0x672c,0x8a9e,0x300d,0x000d,0x000a},
1585 {7,0x31,0x20,0x25c7,0x25c7,0x3012,0x000d,0x000a},
1586 {11,0x31,0x20,0x203b,0x3010,0x0074,0x0065,0x0073,0x0074,0x3011,0x000d,0x000a}
1588 static CHAR jis_jp[9][27] = {
1589 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x22,0x24,0x24,0x24,0x26,0x24,0x28,
1590 0x24,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1591 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1592 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1593 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1594 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1595 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x21,0x24,0x23,0x24,0x25,0x24,0x27,
1596 0x24,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1597 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1598 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1599 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1600 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1601 {20,0x31,0x20,0x1b,0x24,0x42,0x21,0x56,0x46,0x7c,0x4b,0x5c,0x38,0x6c,
1602 0x21,0x57,0x1b,0x28,0x42,0x0d,0x0a},
1603 {16,0x31,0x20,0x1b,0x24,0x42,0x21,0x7e,0x21,0x7e,0x22,0x29,0x1b,0x28,
1605 {26,0x31,0x20,0x1b,0x24,0x42,0x22,0x28,0x21,0x5a,0x1b,0x28,0x42,0x74,
1606 0x65,0x73,0x74,0x1b,0x24,0x42,0x21,0x5b,0x1b,0x28,0x42,0x0d,0x0a}
1608 static CHAR sjis_jp[9][15] = {
1609 {14,0x31,0x20,0x82,0xa0,0x82,0xa2,0x82,0xa4,0x82,0xa6,0x82,0xa8,0x0d,0x0a},
1610 {14,0x31,0x20,0x83,0x41,0x83,0x43,0x83,0x45,0x83,0x47,0x83,0x49,0x0d,0x0a},
1611 {9,0x31,0x20,0xb1,0xb2,0xb3,0xb4,0xb5,0x0d,0x0a},
1612 {14,0x31,0x20,0x82,0x9f,0x82,0xa1,0x82,0xa3,0x82,0xa5,0x82,0xa7,0x0d,0x0a},
1613 {14,0x31,0x20,0x83,0x40,0x83,0x42,0x83,0x44,0x83,0x46,0x83,0x48,0x0d,0x0a},
1614 {9,0x31,0x20,0xa7,0xa8,0xa9,0xaa,0xab,0x0d,0x0a},
1615 {14,0x31,0x20,0x81,0x75,0x93,0xfa,0x96,0x7b,0x8c,0xea,0x81,0x76,0x0d,0x0a},
1616 {10,0x31,0x20,0x81,0x9e,0x81,0x9e,0x81,0xa7,0x0d,0x0a},
1617 {14,0x31,0x20,0x81,0xa6,0x81,0x79,0x74,0x65,0x73,0x74,0x81,0x7a,0x0d,0x0a}
1619 static CHAR euc_jp[9][15] = {
1620 {14,0x31,0x20,0xa4,0xa2,0xa4,0xa4,0xa4,0xa6,0xa4,0xa8,0xa4,0xaa,0x0d,0x0a},
1621 {14,0x31,0x20,0xa5,0xa2,0xa5,0xa4,0xa5,0xa6,0xa5,0xa8,0xa5,0xaa,0x0d,0x0a},
1622 {14,0x31,0x20,0x8e,0xb1,0x8e,0xb2,0x8e,0xb3,0x8e,0xb4,0x8e,0xb5,0x0d,0x0a},
1623 {14,0x31,0x20,0xa4,0xa1,0xa4,0xa3,0xa4,0xa5,0xa4,0xa7,0xa4,0xa9,0x0d,0x0a},
1624 {14,0x31,0x20,0xa5,0xa1,0xa5,0xa3,0xa5,0xa5,0xa5,0xa7,0xa5,0xa9,0x0d,0x0a},
1625 {14,0x31,0x20,0x8e,0xa7,0x8e,0xa8,0x8e,0xa9,0x8e,0xaa,0x8e,0xab,0x0d,0x0a},
1626 {14,0x31,0x20,0xa1,0xd6,0xc6,0xfc,0xcb,0xdc,0xb8,0xec,0xa1,0xd7,0x0d,0x0a},
1627 {10,0x31,0x20,0xa1,0xfe,0xa1,0xfe,0xa2,0xa9,0x0d,0x0a},
1628 {14,0x31,0x20,0xa2,0xa8,0xa1,0xda,0x74,0x65,0x73,0x74,0xa1,0xdb,0x0d,0x0a}
1639 for (i = 0; i < 9; i++)
1643 outlen = jis_jp[i][0];
1644 srcsz = unc_jp[i][0];
1645 hr = pConvertINetUnicodeToMultiByte(NULL, 50220, &unc_jp[i][1], &srcsz, output, &destsz);
1648 skip("Code page identifier 50220 is not supported\n");
1651 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1652 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1653 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1654 ok(memcmp(output,&jis_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1659 hr = pConvertINetMultiByteToUnicode(NULL, 50220, output, &srcsz, outputW,&destsz);
1662 * JIS does not have hankata so it get automatically converted to
1663 * zenkata. this means that strings 1 and 2 are identical as well as
1670 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i, hr);
1671 ok(destsz == unc_jp[j][0],"(%i) Expected %i, got %i\n",i,unc_jp[j][0],destsz);
1672 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1673 ok(memcmp(outputW,&unc_jp[j][1],destsz)==0,"(%i) Strings do not match\n",i);
1676 /* test unc->sjis */
1677 for (i = 0; i < 9; i++)
1680 outlen = sjis_jp[i][0];
1681 srcsz = unc_jp[i][0];
1683 hr = pConvertINetUnicodeToMultiByte(NULL, 932, &unc_jp[i][1], &srcsz, output, &destsz);
1686 skip("Code page identifier 932 is not supported\n");
1689 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1690 ok(destsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,destsz);
1691 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1692 ok(memcmp(output,&sjis_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1696 hr = pConvertINetMultiByteToUnicode(NULL, 932, output, &srcsz, outputW,&destsz);
1698 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1699 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1700 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1701 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1705 for (i = 0; i < 9; i++)
1708 outlen = euc_jp[i][0];
1709 srcsz = unc_jp[i][0];
1711 hr = pConvertINetUnicodeToMultiByte(NULL, 51932, &unc_jp[i][1], &srcsz, output, &destsz);
1714 skip("Code page identifier 51932 is not supported\n");
1717 ok(hr == S_OK, "(%i) Expected S_OK, got %08x\n",i,hr);
1718 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1719 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1720 ok(memcmp(output,&euc_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1724 hr = pConvertINetMultiByteToUnicode(NULL, 51932, output, &srcsz, outputW,&destsz);
1726 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1727 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1728 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1729 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1732 /* Japanese autodetect */
1735 srcsz = jis_jp[i][0];
1736 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &jis_jp[i][1], &srcsz, outputW, &destsz);
1739 skip("Code page identifier 50932 is not supported\n");
1742 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1743 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1744 ok(srcsz == jis_jp[i][0],"(%i) Expected %i, got %i\n",i,jis_jp[i][0],srcsz);
1745 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1749 srcsz = sjis_jp[i][0];
1750 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &sjis_jp[i][1], &srcsz, outputW, &destsz);
1751 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1752 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1753 ok(srcsz == sjis_jp[i][0],"(%i) Expected %i, got %i\n",i,sjis_jp[i][0],srcsz);
1754 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1757 static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
1761 SCRIPTFONTINFO sfi[1];
1764 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, 0, &nfonts, NULL);
1765 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1766 ok(nfonts, "unexpected result\n");
1769 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, NULL);
1770 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1771 ok(nfonts, "unexpected result\n");
1774 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, NULL);
1775 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1776 ok(nfonts, "unexpected result\n");
1779 memset(sfi, 0, sizeof(sfi));
1780 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, sfi);
1781 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1782 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1783 ok(sfi[0].scripts != 0, "unexpected result\n");
1784 ok(sfi[0].wszFont[0], "unexpected result\n");
1787 memset(sfi, 0, sizeof(sfi));
1788 hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, sfi);
1789 ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1790 ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1791 ok(sfi[0].scripts != 0, "unexpected result\n");
1792 ok(sfi[0].wszFont[0], "unexpected result\n");
1795 static void test_CodePageToScriptID(IMLangFontLink2 *font_link)
1813 {1250, sidAsciiLatin},
1814 {1251, sidCyrillic},
1815 {1252, sidAsciiLatin},
1817 {1254, sidAsciiLatin},
1820 {1257, sidAsciiLatin},
1821 {1258, sidAsciiLatin},
1822 {CP_UNICODE, 0, E_FAIL}
1825 for (i = 0; i < sizeof(cp_sid)/sizeof(cp_sid[0]); i++)
1827 hr = IMLangFontLink2_CodePageToScriptID(font_link, cp_sid[i].cp, &sid);
1828 ok(hr == cp_sid[i].hr, "%u CodePageToScriptID failed 0x%08x %u\n", i, hr, GetLastError());
1831 ok(sid == cp_sid[i].sid,
1832 "%u got sid %u for codepage %u, expected %u\n", i, sid, cp_sid[i].cp, cp_sid[i].sid);
1837 static void test_GetFontUnicodeRanges(IMLangFontLink2 *font_link)
1841 HFONT hfont, old_hfont;
1846 hdc = CreateCompatibleDC(0);
1847 memset(&lf, 0, sizeof(lf));
1848 lstrcpyA(lf.lfFaceName, "Arial");
1849 hfont = CreateFontIndirectA(&lf);
1850 old_hfont = SelectObject(hdc, hfont);
1853 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, NULL, &count, NULL);
1854 ok(hr == E_FAIL, "expected E_FAIL, got 0x%08x\n", hr);
1856 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, NULL, NULL);
1857 ok(hr == E_INVALIDARG, "expected E_FAIL, got 0x%08x\n", hr);
1860 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, NULL);
1861 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1862 ok(count, "expected count > 0\n");
1864 ur = HeapAlloc(GetProcessHeap(), 0, sizeof(*ur) * count);
1866 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1867 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1870 hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1871 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1873 HeapFree(GetProcessHeap(), 0, ur);
1875 SelectObject(hdc, old_hfont);
1876 DeleteObject(hfont);
1880 static void test_IsCodePageInstallable(IMultiLanguage2 *ml2)
1885 for (i = 0; i < 0xffff; i++)
1887 hr = IMultiLanguage2_IsCodePageInstallable(ml2, i);
1889 /* it would be better to use IMultiLanguage2_ValidateCodePageEx here but that brings
1890 * up an installation dialog on some platforms, even when specifying CPIOD_PEEK.
1892 if (IsValidCodePage(i))
1894 broken(hr == S_FALSE) || /* win2k */
1895 broken(hr == E_INVALIDARG), /* win2k */
1896 "code page %u is valid but not installable 0x%08x\n", i, hr);
1900 static void test_GetGlobalFontLinkObject(void)
1905 ret = GetGlobalFontLinkObject(NULL);
1906 ok(ret == E_INVALIDARG, "expected E_INVALIDARG got %#x\n", ret);
1908 unknown = (void *)0xdeadbeef;
1909 ret = GetGlobalFontLinkObject(&unknown);
1911 ok(ret == S_OK, "expected S_OK got %#x\n", ret);
1912 ok(unknown != NULL && unknown != (void *)0xdeadbeef,
1913 "GetGlobalFontLinkObject() returned %p\n", unknown);
1919 IMultiLanguage *iML = NULL;
1920 IMultiLanguage2 *iML2 = NULL;
1921 IMLangFontLink *iMLFL = NULL;
1922 IMLangFontLink2 *iMLFL2 = NULL;
1925 if (!init_function_ptrs())
1929 test_Rfc1766ToLcid();
1930 test_LcidToRfc1766();
1932 test_ConvertINetUnicodeToMultiByte();
1933 test_JapaneseConversion();
1935 test_GetGlobalFontLinkObject();
1937 trace("IMultiLanguage\n");
1938 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1939 &IID_IMultiLanguage, (void **)&iML);
1940 if (ret != S_OK || !iML) return;
1942 test_GetNumberOfCodePageInfo((IMultiLanguage2 *)iML);
1943 IMultiLanguage_Release(iML);
1946 /* IMultiLanguage2 (IE5.0 and above) */
1947 trace("IMultiLanguage2\n");
1948 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1949 &IID_IMultiLanguage2, (void **)&iML2);
1950 if (ret != S_OK || !iML2) return;
1953 test_GetLcidFromRfc1766(iML2);
1954 test_GetRfc1766FromLcid(iML2);
1955 test_GetRfc1766Info(iML2);
1956 test_GetNumberOfCodePageInfo(iML2);
1958 test_EnumCodePages(iML2, 0);
1959 test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
1960 test_EnumCodePages(iML2, MIMECONTF_BROWSER);
1961 test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
1962 test_EnumCodePages(iML2, MIMECONTF_VALID);
1963 /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
1964 /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/
1966 test_EnumScripts(iML2, 0);
1967 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
1968 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);
1970 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
1971 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
1972 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
1973 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
1975 test_multibyte_to_unicode_translations(iML2);
1976 test_IMultiLanguage2_ConvertStringFromUnicode(iML2);
1978 test_IsCodePageInstallable(iML2);
1980 IMultiLanguage2_Release(iML2);
1983 /* IMLangFontLink */
1984 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1985 &IID_IMLangFontLink, (void **)&iMLFL);
1986 if (ret != S_OK || !iMLFL) return;
1988 IMLangFontLink_Test(iMLFL);
1989 IMLangFontLink_Release(iMLFL);
1991 /* IMLangFontLink2 */
1992 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1993 &IID_IMLangFontLink2, (void **)&iMLFL2);
1994 if (ret != S_OK || !iMLFL2) return;
1996 test_GetScriptFontInfo(iMLFL2);
1997 test_GetFontUnicodeRanges(iMLFL2);
1998 test_CodePageToScriptID(iMLFL2);
1999 IMLangFontLink2_Release(iMLFL2);