1 /*
2  * Unit test suite for MLANG APIs.
3  *
4  * Copyright 2004 Dmitry Timoshkov
5  * Copyright 2009 Detlef Riekenberg
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #define COBJMACROS
23 
24 #include <stdarg.h>
25 #include <stdio.h>
26 
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "initguid.h"
31 #include "mlang.h"
32 
33 #include "wine/test.h"
34 
35 #ifndef CP_UNICODE
36 #define CP_UNICODE 1200
37 #endif
38 
39 /* #define DUMP_CP_INFO */
40 /* #define DUMP_SCRIPT_INFO */
41 
42 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
43 static HRESULT (WINAPI *pConvertINetMultiByteToUnicode)(LPDWORD, DWORD, LPCSTR,
44                                                         LPINT, LPWSTR, LPINT);
45 static HRESULT (WINAPI *pConvertINetUnicodeToMultiByte)(LPDWORD, DWORD, LPCWSTR,
46                                                         LPINT, LPSTR, LPINT);
47 static HRESULT (WINAPI *pRfc1766ToLcidA)(LCID *, LPCSTR);
48 static HRESULT (WINAPI *pLcidToRfc1766A)(LCID, LPSTR, INT);
49 
50 typedef struct lcid_tag_table {
51     LPCSTR rfc1766;
52     LCID lcid;
53     HRESULT hr;
54     LCID broken_lcid;
55     LPCSTR broken_rfc;
56 } lcid_table_entry;
57 
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 */
61 
62 static const lcid_table_entry  lcid_table[] = {
63     {"e",     -1,       E_FAIL},
64     {"",      -1,       E_FAIL},
65     {"-",     -1,       E_FAIL},
66     {"e-",    -1,       E_FAIL},
67 
68     {"ar",    1,        S_OK},
69     {"zh",    4,        S_OK},
70 
71     {"de",    0x0407,   S_OK},
72     {"de-ch", 0x0807,   S_OK},
73     {"de-at", 0x0c07,   S_OK},
74     {"de-lu", 0x1007,   S_OK},
75     {"de-li", 0x1407,   S_OK},
76 
77     {"en",    9,        S_OK},
78     {"en-gb", 0x809,    S_OK},
79     {"en-GB", 0x809,    S_OK},
80     {"EN-GB", 0x809,    S_OK},
81     {"en-US", 0x409,    S_OK},
82     {"en-us", 0x409,    S_OK},
83 
84     {"fr",    0x040c,   S_OK},
85     {"fr-be", 0x080c,   S_OK},
86     {"fr-ca", 0x0c0c,   S_OK},
87     {"fr-ch", 0x100c,   S_OK},
88     {"fr-lu", 0x140c,   S_OK},
89     {"fr-mc", 0x180c,   S_OK, 0x040c, "fr"},
90 
91     {"it",    0x0410,   S_OK},
92     {"it-ch", 0x0810,   S_OK},
93 
94     {"nl",    0x0413,   S_OK},
95     {"nl-be", 0x0813,   S_OK},
96     {"pl",    0x0415,   S_OK},
97     {"ru",    0x0419,   S_OK},
98 
99     {"kok",   0x0457,   S_OK, 0x0412, "x-kok"}
100 
101 };
102 
103 #define TODO_NAME 1
104 
105 typedef struct info_table_tag {
106     LCID lcid;
107     LANGID lang;
108     DWORD todo;
109     LPCSTR rfc1766;
110     LPCWSTR localename;
111     LPCWSTR broken_name;
112 } info_table_entry;
113 
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_enus2[] ={'E','n','g','l','i','s','c','h',' ',
125                                 '(','V','e','r','e','i','n','i','g','t','e',' ',
126                                 'S','t','a','a','t','e','n',')',0};
127 static const WCHAR de_de[] =   {'D','e','u','t','s','c','h',' ',
128                                 '(','D','e','u','t','s','c','h','l','a','n','d',')',0};
129 static const WCHAR de_deat[] = {'D','e','u','t','s','c','h',' ',
130                                 '(',0xD6,'s','t','e','r','r','e','i','c','h',')',0};
131 static const WCHAR de_dech[] = {'D','e','u','t','s','c','h',' ',
132                                 '(','S','c','h','w','e','i','z',')',0};
133 
134 static const WCHAR en_en[] =   {'E','n','g','l','i','s','h',0};
135 static const WCHAR en_enca[] = {'E','n','g','l','i','s','h',' ',
136                                 '(','C','a','n','a','d','a',')',0};
137 static const WCHAR en_engb[] = {'E','n','g','l','i','s','h',' ',
138                                 '(','U','n','i','t','e','d',' ','K','i','n','g','d','o','m',')',0};
139 static const WCHAR en_enus[] = {'E','n','g','l','i','s','h',' ',
140                                 '(','U','n','i','t','e','d',' ','S','t','a','t','e','s',')',0};
141 static const WCHAR en_de[] =   {'G','e','r','m','a','n',' ',
142                                 '(','G','e','r','m','a','n','y',')',0};
143 static const WCHAR en_deat[] = {'G','e','r','m','a','n',' ',
144                                 '(','A','u','s','t','r','i','a',')',0};
145 static const WCHAR en_dech[] = {'G','e','r','m','a','n',' ',
146                                 '(','S','w','i','t','z','e','r','l','a','n','d',')',0};
147 
148 static const WCHAR fr_en[] =   {'A','n','g','l','a','i','s',0};
149 static const WCHAR fr_enca[] = {'A','n','g','l','a','i','s',' ',
150                                 '(','C','a','n','a','d','a',')',0};
151 static const WCHAR fr_engb[] = {'A','n','g','l','a','i','s',' ',
152                                 '(','R','o','y','a','u','m','e','-','U','n','i',')',0};
153 static const WCHAR fr_enus[] = {'A','n','g','l','a','i','s',' ',
154                                 '(',0xC9, 't','a','t','s','-','U','n','i','s',')',0};
155 static const WCHAR fr_enus2[] ={'A','n','g','l','a','i','s',' ',
156                                 '(','U','.','S','.',')',0};
157 static const WCHAR fr_de[] =   {'A','l','l','e','m','a','n','d',' ',
158                                 '(','A','l','l','e','m','a','g','n','e',')',0};
159 static const WCHAR fr_de2[] =  {'A','l','l','e','m','a','n','d',' ',
160                                 '(','S','t','a','n','d','a','r','d',')',0};
161 static const WCHAR fr_deat[] = {'A','l','l','e','m','a','n','d',' ',
162                                 '(','A','u','t','r','i','c','h','e',')',0};
163 static const WCHAR fr_dech[] = {'A','l','l','e','m','a','n','d',' ',
164                                 '(','S','u','i','s','s','e',')',0};
165 
166 static const info_table_entry  info_table[] = {
167     {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),        MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
168          0, "en", en_en},
169     {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),        MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
170          0, "en-us", en_enus},
171     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK),     MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
172          0, "en-gb", en_engb},
173     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),     MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
174          0, "en-us", en_enus},
175     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN),    MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
176          0, "en-ca", en_enca},
177 
178     {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),         MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
179          0, "de", en_de},
180     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN),          MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
181          0, "de", en_de},
182     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS),    MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
183          0, "de-ch", en_dech},
184     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),
185          0, "de-at", en_deat},
186 
187     {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),        MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
188          TODO_NAME, "en", de_en},
189     {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),        MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
190          TODO_NAME, "en-us", de_enus, de_enus2},
191     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK),     MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
192          TODO_NAME, "en-gb", de_engb, de_engb2},
193     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),     MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
194          TODO_NAME, "en-us", de_enus, de_enus2},
195     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN),    MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
196          TODO_NAME, "en-ca", de_enca},
197 
198     {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),         MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
199          TODO_NAME, "de", de_de},
200     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN),          MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
201          TODO_NAME, "de",de_de},
202     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS),    MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
203          TODO_NAME, "de-ch", de_dech},
204     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),
205          TODO_NAME, "de-at", de_deat},
206 
207     {MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL),        MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
208          TODO_NAME, "en", fr_en},
209     {MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT),        MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
210          TODO_NAME, "en-us", fr_enus, fr_enus2},
211     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK),     MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
212          TODO_NAME, "en-gb", fr_engb},
213     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),     MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
214          TODO_NAME, "en-us", fr_enus, fr_enus2},
215     {MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN),    MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
216          TODO_NAME, "en-ca", fr_enca},
217 
218     {MAKELANGID(LANG_GERMAN, SUBLANG_DEFAULT),         MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
219          TODO_NAME, "de", fr_de, fr_de2},
220     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN),          MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
221          TODO_NAME, "de", fr_de, fr_de2},
222     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS),    MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
223          TODO_NAME, "de-ch", fr_dech},
224     {MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), MAKELANGID(LANG_FRENCH, SUBLANG_DEFAULT),
225          TODO_NAME, "de-at", fr_deat}
226 
227 };
228 
229 static BOOL init_function_ptrs(void)
230 {
231     HMODULE hMlang;
232 
233     hMlang = GetModuleHandleA("mlang.dll");
234     pConvertINetMultiByteToUnicode = (void *)GetProcAddress(hMlang, "ConvertINetMultiByteToUnicode");
235     pConvertINetUnicodeToMultiByte = (void *)GetProcAddress(hMlang, "ConvertINetUnicodeToMultiByte");
236     pRfc1766ToLcidA = (void *)GetProcAddress(hMlang, "Rfc1766ToLcidA");
237     pLcidToRfc1766A = (void *)GetProcAddress(hMlang, "LcidToRfc1766A");
238 
239     pGetCPInfoExA = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetCPInfoExA");
240 
241     return TRUE;
242 }
243 
244 #define ok_w2(format, szString1, szString2) \
245 \
246     if (lstrcmpW((szString1), (szString2)) != 0) \
247     { \
248         CHAR string1[256], string2[256]; \
249         WideCharToMultiByte(CP_ACP, 0, (szString1), -1, string1, 256, NULL, NULL); \
250         WideCharToMultiByte(CP_ACP, 0, (szString2), -1, string2, 256, NULL, NULL); \
251         ok(0, (format), string1, string2); \
252     }
253 
254 static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
255 {
256     /* these APIs are broken regarding constness of the input buffer */
257     char stringA[] = "Just a test string\0"; /* double 0 for CP_UNICODE tests */
258     WCHAR stringW[] = {'J','u','s','t',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
259     char bufA[256];
260     WCHAR bufW[256];
261     UINT lenA, lenW, expected_len;
262     HRESULT ret;
263 
264     /* IMultiLanguage2_ConvertStringToUnicode tests */
265 
266     memset(bufW, 'x', sizeof(bufW));
267     lenA = 0;
268     lenW = sizeof(bufW)/sizeof(bufW[0]);
269     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
270     ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
271     ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
272     ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
273 
274     memset(bufW, 'x', sizeof(bufW));
275     lenA = -1;
276     lenW = sizeof(bufW)/sizeof(bufW[0]);
277     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
278     ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
279     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
280     ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
281     if (lenW < sizeof(bufW)/sizeof(bufW[0])) {
282        /* can only happen if the convert call fails */
283        ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
284        bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
285     }
286     ok(!lstrcmpW(bufW, stringW), "bufW/stringW mismatch\n");
287 
288     memset(bufW, 'x', sizeof(bufW));
289     lenA = -1;
290     lenW = 5;
291     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
292     ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringToUnicode should fail: %08x\n", ret);
293     ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
294     /* still has to do partial conversion */
295     ok(!memcmp(bufW, stringW, 5 * sizeof(WCHAR)), "bufW/stringW mismatch\n");
296 
297     memset(bufW, 'x', sizeof(bufW));
298     lenA = -1;
299     lenW = sizeof(bufW)/sizeof(bufW[0]);
300     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, CP_UNICODE, stringA, &lenA, bufW, &lenW);
301     ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
302     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
303     ok(lenW == lstrlenW(stringW)/(int)sizeof(WCHAR), "wrong lenW %u\n", lenW);
304     ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
305     bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
306     ok(!lstrcmpA((LPCSTR)bufW, stringA), "bufW/stringA mismatch\n");
307 
308     memset(bufW, 'x', sizeof(bufW));
309     lenA = lstrlenA(stringA);
310     lenW = 0;
311     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, NULL, &lenW);
312     ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
313     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
314     expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
315     ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
316 
317     memset(bufW, 'x', sizeof(bufW));
318     lenA = lstrlenA(stringA);
319     lenW = sizeof(bufW)/sizeof(bufW[0]);
320     ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
321     ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
322     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
323     expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
324     ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
325 
326     memset(bufW, 'x', sizeof(bufW));
327     lenA = lstrlenA(stringA);
328     lenW = 0;
329     ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
330     ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
331     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
332     expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
333     ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
334 
335     /* IMultiLanguage2_ConvertStringFromUnicode tests */
336 
337     memset(bufA, 'x', sizeof(bufA));
338     lenW = 0;
339     lenA = sizeof(bufA);
340     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
341     ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
342     ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
343     ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
344 
345     memset(bufA, 'x', sizeof(bufA));
346     lenW = -1;
347     lenA = sizeof(bufA);
348     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
349     ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
350     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
351     ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
352     ok(bufA[lenA] != 0, "buf should not be 0 terminated\n");
353     bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
354     ok(!lstrcmpA(bufA, stringA), "bufA/stringA mismatch\n");
355 
356     memset(bufA, 'x', sizeof(bufA));
357     lenW = -1;
358     lenA = 5;
359     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
360     ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringFromUnicode should fail: %08x\n", ret);
361     ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
362     /* still has to do partial conversion */
363     ok(!memcmp(bufA, stringA, 5), "bufW/stringW mismatch\n");
364 
365     memset(bufA, 'x', sizeof(bufA));
366     lenW = -1;
367     lenA = sizeof(bufA);
368     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, CP_UNICODE, stringW, &lenW, bufA, &lenA);
369     ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
370     ok(lenA == lstrlenA(stringA) * (int)sizeof(WCHAR), "wrong lenA %u\n", lenA);
371     ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
372     ok(bufA[lenA] != 0 && bufA[lenA+1] != 0, "buf should not be 0 terminated\n");
373     bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
374     bufA[lenA+1] = 0; /* sizeof(WCHAR) */
375     ok(!lstrcmpW((LPCWSTR)bufA, stringW), "bufA/stringW mismatch\n");
376 
377     memset(bufA, 'x', sizeof(bufA));
378     lenW = lstrlenW(stringW);
379     lenA = 0;
380     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, NULL, &lenA);
381     ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
382     ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
383     expected_len = WideCharToMultiByte(1252, 0, stringW, lenW, NULL, 0, NULL, NULL);
384     ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);
385 }
386 
387 static void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
388 {
389     ok(cpinfo1->dwFlags == cpinfo2->dwFlags, "dwFlags mismatch: %08x != %08x\n", cpinfo1->dwFlags, cpinfo2->dwFlags);
390     ok(cpinfo1->uiCodePage == cpinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", cpinfo1->uiCodePage, cpinfo2->uiCodePage);
391     ok(cpinfo1->uiFamilyCodePage == cpinfo2->uiFamilyCodePage, "uiFamilyCodePage mismatch: %u != %u\n", cpinfo1->uiFamilyCodePage, cpinfo2->uiFamilyCodePage);
392     ok(!lstrcmpW(cpinfo1->wszDescription, cpinfo2->wszDescription), "wszDescription mismatch\n");
393     ok(!lstrcmpW(cpinfo1->wszWebCharset, cpinfo2->wszWebCharset), "wszWebCharset mismatch\n");
394     ok(!lstrcmpW(cpinfo1->wszHeaderCharset, cpinfo2->wszHeaderCharset), "wszHeaderCharset mismatch\n");
395     ok(!lstrcmpW(cpinfo1->wszBodyCharset, cpinfo2->wszBodyCharset), "wszBodyCharset mismatch\n");
396     ok(!lstrcmpW(cpinfo1->wszFixedWidthFont, cpinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
397     ok(!lstrcmpW(cpinfo1->wszProportionalFont, cpinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
398     ok(cpinfo1->bGDICharset == cpinfo2->bGDICharset, "bGDICharset mismatch: %d != %d\n", cpinfo1->bGDICharset, cpinfo2->bGDICharset);
399 }
400 
401 #ifdef DUMP_CP_INFO
402 static const char *dump_mime_flags(DWORD flags)
403 {
404     static char buf[1024];
405 
406     buf[0] = 0;
407 
408     if (flags & MIMECONTF_MAILNEWS) strcat(buf, " MIMECONTF_MAILNEWS");
409     if (flags & MIMECONTF_BROWSER) strcat(buf, " MIMECONTF_BROWSER");
410     if (flags & MIMECONTF_MINIMAL) strcat(buf, " MIMECONTF_MINIMAL");
411     if (flags & MIMECONTF_IMPORT) strcat(buf, " MIMECONTF_IMPORT");
412     if (flags & MIMECONTF_SAVABLE_MAILNEWS) strcat(buf, " MIMECONTF_SAVABLE_MAILNEWS");
413     if (flags & MIMECONTF_SAVABLE_BROWSER) strcat(buf, " MIMECONTF_SAVABLE_BROWSER");
414     if (flags & MIMECONTF_EXPORT) strcat(buf, " MIMECONTF_EXPORT");
415     if (flags & MIMECONTF_PRIVCONVERTER) strcat(buf, " MIMECONTF_PRIVCONVERTER");
416     if (flags & MIMECONTF_VALID) strcat(buf, " MIMECONTF_VALID");
417     if (flags & MIMECONTF_VALID_NLS) strcat(buf, " MIMECONTF_VALID_NLS");
418     if (flags & MIMECONTF_MIME_IE4) strcat(buf, " MIMECONTF_MIME_IE4");
419     if (flags & MIMECONTF_MIME_LATEST) strcat(buf, " MIMECONTF_MIME_LATEST");
420     if (flags & MIMECONTF_MIME_REGISTRY) strcat(buf, " MIMECONTF_MIME_REGISTRY");
421 
422     return buf;
423 }
424 #endif
425 
426 static HRESULT check_convertible(IMultiLanguage2 *iML2, UINT from, UINT to)
427 {
428     CHAR convert[MAX_PATH];
429     BYTE dest[MAX_PATH];
430     HRESULT hr;
431     UINT srcsz, destsz;
432 
433     static WCHAR strW[] = {'a','b','c',0};
434 
435     /* Check to see if the target codepage has these characters or not */
436     if (from != CP_UTF8)
437     {
438         BOOL fDefaultChar;
439         char ch[10];
440         int cb;
441         cb = WideCharToMultiByte( from, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
442                                   strW, 3, ch, sizeof(ch), NULL, &fDefaultChar);
443 
444         if(cb == 0 || fDefaultChar)
445         {
446             trace("target codepage %i does not contain 'abc'\n",from);
447             return E_FAIL;
448         }
449     }
450 
451     srcsz = lstrlenW(strW) + 1;
452     destsz = MAX_PATH;
453     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, from, strW,
454                                                   &srcsz, convert, &destsz);
455     if (hr != S_OK)
456         return S_FALSE;
457 
458     srcsz = -1;
459     destsz = MAX_PATH;
460     hr = IMultiLanguage2_ConvertString(iML2, NULL, from, to, (BYTE *)convert,
461                                        &srcsz, dest, &destsz);
462     if (hr != S_OK)
463         return S_FALSE;
464 
465     return S_OK;
466 }
467 
468 static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
469 {
470     IEnumCodePage *iEnumCP = NULL;
471     MIMECPINFO *cpinfo;
472     MIMECPINFO cpinfo2;
473     HRESULT ret;
474     ULONG i, n;
475     UINT total;
476 
477     total = 0;
478     ret = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &total);
479     ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfCodePageInfo: expected S_OK/!0, got %08x/%u\n", ret, total);
480 
481     trace("total mlang supported codepages %u\n", total);
482 
483     ret = IMultiLanguage2_EnumCodePages(iML2, flags, LANG_NEUTRAL, &iEnumCP);
484     ok(ret == S_OK && iEnumCP, "IMultiLanguage2_EnumCodePages: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumCP);
485 
486     ret = IEnumCodePage_Reset(iEnumCP);
487     ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
488     n = 65536;
489     ret = IEnumCodePage_Next(iEnumCP, 0, NULL, &n);
490     ok(ret == S_FALSE || ret == E_FAIL,
491             "IEnumCodePage_Next: expected S_FALSE or E_FAIL, got %08x\n", ret);
492     if (ret == S_FALSE)
493         ok(n == 0, "IEnumCodePage_Next: expected 0/S_FALSE, got %u/%08x\n", n, ret);
494     else if (ret == E_FAIL)
495         ok(n == 65536, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
496     ret = IEnumCodePage_Next(iEnumCP, 0, NULL, NULL);
497     ok(ret == S_FALSE || ret == E_FAIL,
498             "IEnumCodePage_Next: expected S_FALSE or E_FAIL, got %08x\n", ret);
499 
500     cpinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*cpinfo) * total * 2);
501 
502     n = total * 2;
503     ret = IEnumCodePage_Next(iEnumCP, 0, cpinfo, &n);
504     ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
505 
506     n = total * 2;
507     ret = IEnumCodePage_Next(iEnumCP, n, cpinfo, &n);
508     ok(ret == S_OK && n != 0, "IEnumCodePage_Next: expected S_OK/!0, got %08x/%u\n", ret, n);
509 
510     trace("flags %08x, enumerated codepages %u\n", flags, n);
511 
512     if (!flags)
513     {
514 	ok(n == total, "IEnumCodePage_Next: expected %u, got %u\n", total, n);
515 
516 	flags = MIMECONTF_MIME_LATEST;
517     }
518 
519     total = n;
520 
521     for (i = 0; i < n; i++)
522     {
523 	CHARSETINFO csi;
524 	MIMECSETINFO mcsi;
525         HRESULT convertible = S_OK;
526 	static const WCHAR autoW[] = {'_','a','u','t','o',0};
527 	static const WCHAR feffW[] = {'u','n','i','c','o','d','e','F','E','F','F',0};
528 
529 #ifdef DUMP_CP_INFO
530 	trace("MIMECPINFO #%u:\n"
531 	      "dwFlags %08x %s\n"
532 	      "uiCodePage %u\n"
533 	      "uiFamilyCodePage %u\n"
534 	      "wszDescription %s\n"
535 	      "wszWebCharset %s\n"
536 	      "wszHeaderCharset %s\n"
537 	      "wszBodyCharset %s\n"
538 	      "wszFixedWidthFont %s\n"
539 	      "wszProportionalFont %s\n"
540 	      "bGDICharset %d\n\n",
541 	      i,
542 	      cpinfo[i].dwFlags, dump_mime_flags(cpinfo[i].dwFlags),
543 	      cpinfo[i].uiCodePage,
544 	      cpinfo[i].uiFamilyCodePage,
545 	      wine_dbgstr_w(cpinfo[i].wszDescription),
546 	      wine_dbgstr_w(cpinfo[i].wszWebCharset),
547 	      wine_dbgstr_w(cpinfo[i].wszHeaderCharset),
548 	      wine_dbgstr_w(cpinfo[i].wszBodyCharset),
549 	      wine_dbgstr_w(cpinfo[i].wszFixedWidthFont),
550 	      wine_dbgstr_w(cpinfo[i].wszProportionalFont),
551 	      cpinfo[i].bGDICharset);
552 #endif
553 	ok(cpinfo[i].dwFlags & flags, "enumerated flags %08x do not include requested %08x\n", cpinfo[i].dwFlags, flags);
554 
555 	if (TranslateCharsetInfo((DWORD *)(INT_PTR)cpinfo[i].uiFamilyCodePage, &csi, TCI_SRCCODEPAGE))
556 	    ok(cpinfo[i].bGDICharset == csi.ciCharset, "%d != %d\n", cpinfo[i].bGDICharset, csi.ciCharset);
557 	else
558             if (winetest_debug > 1)
559                 trace("TranslateCharsetInfo failed for cp %u\n", cpinfo[i].uiFamilyCodePage);
560 
561 #ifdef DUMP_CP_INFO
562         trace("%u: codepage %u family %u\n", i, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
563 #endif
564 
565 	/* support files for some codepages might be not installed, or
566 	 * the codepage is just an alias.
567 	 */
568 	if (IsValidCodePage(cpinfo[i].uiCodePage))
569 	{
570 	    ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UNICODE);
571 	    ok(ret == S_OK, "IMultiLanguage2_IsConvertible(%u -> CP_UNICODE) = %08x\n", cpinfo[i].uiCodePage, ret);
572 	    ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, cpinfo[i].uiCodePage);
573 	    ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
574 
575             convertible = check_convertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
576             if (convertible != E_FAIL)
577             {
578                 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
579                 ok(ret == convertible, "IMultiLanguage2_IsConvertible(%u -> CP_UTF8) = %08x\n", cpinfo[i].uiCodePage, ret);
580                 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, cpinfo[i].uiCodePage);
581                 ok(ret == convertible, "IMultiLanguage2_IsConvertible(CP_UTF8 -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
582             }
583 	}
584 	else
585             if (winetest_debug > 1)
586                 trace("IsValidCodePage failed for cp %u\n", cpinfo[i].uiCodePage);
587 
588     if (memcmp(cpinfo[i].wszWebCharset,feffW,sizeof(WCHAR)*11)==0)
589         skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
590     else
591     {
592         ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszWebCharset, &mcsi);
593         /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
594         if (memcmp(cpinfo[i].wszWebCharset, autoW, 5 * sizeof(WCHAR)))
595         {
596             ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
597 #ifdef DUMP_CP_INFO
598             trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszWebCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
599 #endif
600             ok(!lstrcmpiW(cpinfo[i].wszWebCharset, mcsi.wszCharset), "%s != %s\n",
601                wine_dbgstr_w(cpinfo[i].wszWebCharset), wine_dbgstr_w(mcsi.wszCharset));
602 
603         if (0)
604         {
605             /* native mlang returns completely messed up encodings in some cases */
606             ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
607             "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
608             ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
609             "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
610             }
611         }
612     }
613 
614     if (memcmp(cpinfo[i].wszHeaderCharset,feffW,sizeof(WCHAR)*11)==0)
615         skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
616     else
617     {
618         ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszHeaderCharset, &mcsi);
619         /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
620         if (memcmp(cpinfo[i].wszHeaderCharset, autoW, 5 * sizeof(WCHAR)))
621         {
622             ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
623 #ifdef DUMP_CP_INFO
624             trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszHeaderCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
625 #endif
626             ok(!lstrcmpiW(cpinfo[i].wszHeaderCharset, mcsi.wszCharset), "%s != %s\n",
627                wine_dbgstr_w(cpinfo[i].wszHeaderCharset), wine_dbgstr_w(mcsi.wszCharset));
628 
629         if (0)
630         {
631             /* native mlang returns completely messed up encodings in some cases */
632             ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
633             "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
634             ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
635             "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
636         }
637         }
638     }
639 
640     if (memcmp(cpinfo[i].wszBodyCharset,feffW,sizeof(WCHAR)*11)==0)
641         skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
642     else
643     {
644         ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszBodyCharset, &mcsi);
645         /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
646         if (memcmp(cpinfo[i].wszBodyCharset, autoW, 5 * sizeof(WCHAR)))
647         {
648             ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
649 #ifdef DUMP_CP_INFO
650             trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszBodyCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
651 #endif
652             ok(!lstrcmpiW(cpinfo[i].wszBodyCharset, mcsi.wszCharset), "%s != %s\n",
653                wine_dbgstr_w(cpinfo[i].wszBodyCharset), wine_dbgstr_w(mcsi.wszCharset));
654 
655         if (0)
656         {
657             /* native mlang returns completely messed up encodings in some cases */
658             ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
659             "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
660             ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
661             "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
662         }
663         }
664     }
665     }
666 
667     /* now IEnumCodePage_Next should fail, since pointer is at the end */
668     n = 1;
669     ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
670     ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
671 
672     ret = IEnumCodePage_Reset(iEnumCP);
673     ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
674     n = 0;
675     ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
676     ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
677     cpinfo_cmp(cpinfo, &cpinfo2);
678 
679     if (0)
680     {
681     /* Due to a bug in MS' implementation of IEnumCodePage_Skip
682      * it's not used here.
683      */
684     ret = IEnumCodePage_Skip(iEnumCP, 1);
685     ok(ret == S_OK, "IEnumCodePage_Skip: expected S_OK, got %08x\n", ret);
686     }
687     for (i = 0; i < total - 1; i++)
688     {
689         n = 0;
690         ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
691         ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
692         cpinfo_cmp(&cpinfo[i + 1], &cpinfo2);
693     }
694 
695     HeapFree(GetProcessHeap(), 0, cpinfo);
696     IEnumCodePage_Release(iEnumCP);
697 }
698 
699 static void test_GetCharsetInfo_other(IMultiLanguage *ml)
700 {
701     WCHAR asciiW[] = {'a','s','c','i','i',0};
702     WCHAR iso88591_1W[] =    {'I','S','O','-','8','8','5','9','-','1',0};
703     WCHAR iso88591_1retW[] = {'i','s','o','-','8','8','5','9','-','1',0};
704     WCHAR iso88591_2W[] =    {'I','S','O','8','8','5','9','-','1',0};
705     WCHAR iso88591_2retW[] = {'i','s','o','8','8','5','9','-','1',0};
706     WCHAR iso88591_3W[] =    {'I','S','O','8','8','5','9','1',0};
707     WCHAR iso88591_4W[] =    {'I','S','O','-','8','8','5','9','1',0};
708     WCHAR iso88591_5W[] =    {'I','S','O','8','8','-','5','9','1',0};
709     WCHAR iso88591_6W[] =    {'-','I','S','O','8','8','5','9','1',0};
710     WCHAR iso88591_7W[] =    {' ','I','S','O','-','8','8','5','9','-','1',0};
711     struct other {
712         int todo;
713         HRESULT hr;
714         WCHAR* charset;
715         WCHAR* ret_charset;
716     } other[] = {
717         { 0, S_OK,   asciiW, asciiW },
718         { 0, S_OK,   iso88591_1W, iso88591_1retW },
719         { 1, S_OK,   iso88591_2W, iso88591_2retW },
720         { 0, E_FAIL, iso88591_3W, 0 },
721         { 0, E_FAIL, iso88591_4W, 0 },
722         { 0, E_FAIL, iso88591_5W, 0 },
723         { 0, E_FAIL, iso88591_6W, 0 },
724         { 0, E_FAIL, iso88591_7W, 0 },
725     };
726     MIMECSETINFO info;
727     HRESULT hr;
728     int i;
729 
730     for (i = 0; i < sizeof(other)/sizeof(*other); i++)
731     {
732         hr = IMultiLanguage_GetCharsetInfo(ml, other[i].charset, &info);
733 
734         todo_wine_if(other[i].todo)
735         ok(hr == other[i].hr, "#%d: got %08x, expected %08x\n", i, hr, other[i].hr);
736 
737         if (hr == S_OK)
738             todo_wine_if(other[i].todo)
739             ok(!lstrcmpW(info.wszCharset, other[i].ret_charset), "#%d: got %s, expected %s\n",
740                 i, wine_dbgstr_w(info.wszCharset), wine_dbgstr_w(other[i].ret_charset));
741     }
742 }
743 
744 static void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
745 {
746     ok(sinfo1->ScriptId == sinfo2->ScriptId, "ScriptId mismatch: %d != %d\n", sinfo1->ScriptId, sinfo2->ScriptId);
747     ok(sinfo1->uiCodePage == sinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", sinfo1->uiCodePage, sinfo2->uiCodePage);
748     ok(!lstrcmpW(sinfo1->wszDescription, sinfo2->wszDescription), "wszDescription mismatch\n");
749     ok(!lstrcmpW(sinfo1->wszFixedWidthFont, sinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
750     ok(!lstrcmpW(sinfo1->wszProportionalFont, sinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
751 }
752 
753 static void test_EnumScripts(IMultiLanguage2 *iML2, DWORD flags)
754 {
755     IEnumScript *iEnumScript = NULL;
756     SCRIPTINFO *sinfo;
757     SCRIPTINFO sinfo2;
758     HRESULT ret;
759     ULONG i, n;
760     UINT total;
761 
762     total = 0;
763     ret = IMultiLanguage2_GetNumberOfScripts(iML2, &total);
764     ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfScripts: expected S_OK/!0, got %08x/%u\n", ret, total);
765 
766     trace("total mlang supported scripts %u\n", total);
767 
768     ret = IMultiLanguage2_EnumScripts(iML2, flags, LANG_NEUTRAL, &iEnumScript);
769     ok(ret == S_OK && iEnumScript, "IMultiLanguage2_EnumScripts: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumScript);
770 
771     ret = IEnumScript_Reset(iEnumScript);
772     ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
773     n = 65536;
774     ret = IEnumScript_Next(iEnumScript, 0, NULL, &n);
775     ok(n == 65536 && ret == E_FAIL, "IEnumScript_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
776     ret = IEnumScript_Next(iEnumScript, 0, NULL, NULL);
777     ok(ret == E_FAIL, "IEnumScript_Next: expected E_FAIL, got %08x\n", ret);
778 
779     sinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*sinfo) * total * 2);
780 
781     n = total * 2;
782     ret = IEnumScript_Next(iEnumScript, 0, sinfo, &n);
783     ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
784 
785     n = total * 2;
786     ret = IEnumScript_Next(iEnumScript, n, sinfo, &n);
787     ok(ret == S_OK && n != 0, "IEnumScript_Next: expected S_OK, got %08x/%u\n", ret, n);
788 
789     trace("flags %08x, enumerated scripts %u\n", flags, n);
790 
791     if (!flags)
792     {
793 	ok(n == total, "IEnumScript_Next: expected %u, got %u\n", total, n);
794     }
795 
796     total = n;
797 
798     for (i = 0; pGetCPInfoExA && i < n; i++)
799     {
800 #ifdef DUMP_SCRIPT_INFO
801 	trace("SCRIPTINFO #%u:\n"
802 	      "ScriptId %08x\n"
803 	      "uiCodePage %u\n"
804 	      "wszDescription %s\n"
805 	      "wszFixedWidthFont %s\n"
806 	      "wszProportionalFont %s\n\n",
807 	      i,
808 	      sinfo[i].ScriptId,
809 	      sinfo[i].uiCodePage,
810 	      wine_dbgstr_w(sinfo[i].wszDescription),
811 	      wine_dbgstr_w(sinfo[i].wszFixedWidthFont),
812 	      wine_dbgstr_w(sinfo[i].wszProportionalFont));
813         trace("%u codepage %u\n", i, sinfo[i].uiCodePage);
814 #endif
815     }
816 
817     /* now IEnumScript_Next should fail, since pointer is at the end */
818     n = 1;
819     ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
820     ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
821 
822     ret = IEnumScript_Reset(iEnumScript);
823     ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
824     n = 0;
825     ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
826     ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
827     scriptinfo_cmp(sinfo, &sinfo2);
828 
829     if (0)
830     {
831     /* Due to a bug in MS' implementation of IEnumScript_Skip
832      * it's not used here.
833      */
834     ret = IEnumScript_Skip(iEnumScript, 1);
835     ok(ret == S_OK, "IEnumScript_Skip: expected S_OK, got %08x\n", ret);
836     }
837     for (i = 0; i < total - 1; i++)
838     {
839         n = 0;
840         ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
841         ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
842         scriptinfo_cmp(&sinfo[i + 1], &sinfo2);
843     }
844 
845     HeapFree(GetProcessHeap(), 0, sinfo);
846     IEnumScript_Release(iEnumScript);
847 }
848 
849 static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
850 {
851     DWORD dwCodePages, dwManyCodePages;
852     DWORD dwCmpCodePages;
853     UINT CodePage;
854     static const WCHAR str[] = { 'd', 0x0436, 0xff90 };
855     LONG processed;
856     HRESULT ret;
857 
858     dwCodePages = ~0u;
859     ret = IMLangFontLink_CodePageToCodePages(iMLFL, -1, &dwCodePages);
860     ok(ret == E_FAIL, "IMLangFontLink_CodePageToCodePages should fail: %x\n", ret);
861     ok(dwCodePages == 0, "expected 0, got %u\n", dwCodePages);
862 
863     dwCodePages = 0;
864     ret = IMLangFontLink_CodePageToCodePages(iMLFL, 932, &dwCodePages);
865     ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
866     ok(dwCodePages == FS_JISJAPAN, "expected FS_JISJAPAN, got %08x\n", dwCodePages);
867     CodePage = 0;
868     ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwCodePages, 1035, &CodePage);
869     ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
870     ok(CodePage == 932, "Incorrect CodePage Returned (%i)\n",CodePage);
871 
872     dwManyCodePages = 0;
873     ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1252, &dwManyCodePages);
874     ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
875     ok(dwManyCodePages == FS_LATIN1, "expected FS_LATIN1, got %08x\n", dwManyCodePages);
876     dwCodePages = 0;
877     ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1256, &dwCodePages);
878     ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
879     ok(dwCodePages == FS_ARABIC, "expected FS_ARABIC, got %08x\n", dwCodePages);
880     dwManyCodePages |= dwCodePages;
881     ret = IMLangFontLink_CodePageToCodePages(iMLFL, 874, &dwCodePages);
882     ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
883     ok(dwCodePages == FS_THAI, "expected FS_THAI, got %08x\n", dwCodePages);
884     dwManyCodePages |= dwCodePages;
885 
886     ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 1256, &CodePage);
887     ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
888     ok(CodePage == 1256, "Incorrect CodePage Returned (%i)\n",CodePage);
889 
890     ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 936, &CodePage);
891     ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
892     ok(CodePage == 1252, "Incorrect CodePage Returned (%i)\n",CodePage);
893 
894     /* Tests for GetCharCodePages */
895 
896     /* Latin 1 */
897     dwCmpCodePages = FS_LATIN1 | FS_LATIN2 | FS_CYRILLIC | FS_GREEK | FS_TURKISH
898         | FS_HEBREW | FS_ARABIC | FS_BALTIC | FS_VIETNAMESE | FS_THAI
899         | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG | FS_CHINESETRAD;
900     ret = IMLangFontLink_GetCharCodePages(iMLFL, 'd', &dwCodePages);
901     ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
902     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
903 
904     dwCodePages = 0;
905     processed = 0;
906     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 1, 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 == 1, "expected 1, got %d\n", processed);
910 
911     /* Cyrillic */
912     dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
913     ret = IMLangFontLink_GetCharCodePages(iMLFL, 0x0436, &dwCodePages);
914     ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
915     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
916 
917     dwCodePages = 0;
918     processed = 0;
919     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[1], 1, 0, &dwCodePages, &processed);
920     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
921     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
922     ok(processed == 1, "expected 1, got %d\n", processed);
923 
924     /* Japanese */
925     dwCmpCodePages =  FS_JISJAPAN;
926     ret = IMLangFontLink_GetCharCodePages(iMLFL, 0xff90, &dwCodePages);
927     ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
928     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
929 
930     dwCodePages = 0;
931     processed = 0;
932     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
933     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
934     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
935     ok(processed == 1, "expected 1, got %d\n", processed);
936 
937     dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
938     dwCodePages = 0;
939     processed = 0;
940     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 2, 0, &dwCodePages, &processed);
941     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
942     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
943     ok(processed == 2, "expected 2, got %d\n", processed);
944 
945     dwCmpCodePages = FS_JISJAPAN;
946     dwCodePages = 0;
947     processed = 0;
948     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 3, 0, &dwCodePages, &processed);
949     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
950     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
951     ok(processed == 3, "expected 3, got %d\n", processed);
952 
953     dwCodePages = 0xffff;
954     processed = -1;
955     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
956     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
957     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
958     ok(processed == 1, "expected 0, got %d\n", processed);
959 
960     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, NULL, NULL);
961     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
962 
963     dwCodePages = 0xffff;
964     processed = -1;
965     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, -1, 0, &dwCodePages, &processed);
966     ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
967     ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
968     ok(processed == 0, "expected 0, got %d\n", processed);
969 
970     dwCodePages = 0xffff;
971     processed = -1;
972     ret = IMLangFontLink_GetStrCodePages(iMLFL, NULL, 1, 0, &dwCodePages, &processed);
973     ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
974     ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
975     ok(processed == 0, "expected 0, got %d\n", processed);
976 
977     dwCodePages = 0xffff;
978     processed = -1;
979     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 0, 0, &dwCodePages, &processed);
980     ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
981     ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
982     ok(processed == 0, "expected 0, got %d\n", processed);
983 }
984 
985 /* copied from libs/wine/string.c */
986 static WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
987 {
988     while (*str)
989     {
990         const WCHAR *p1 = str, *p2 = sub;
991         while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
992         if (!*p2) return (WCHAR *)str;
993         str++;
994     }
995     return NULL;
996 }
997 
998 static void test_rfc1766(IMultiLanguage2 *iML2)
999 {
1000     IEnumRfc1766 *pEnumRfc1766;
1001     RFC1766INFO info;
1002     ULONG n;
1003     HRESULT ret;
1004     BSTR rfcstr;
1005 
1006     ret = IMultiLanguage2_EnumRfc1766(iML2, LANG_NEUTRAL, &pEnumRfc1766);
1007     ok(ret == S_OK, "IMultiLanguage2_EnumRfc1766 error %08x\n", ret);
1008 
1009     while (1)
1010     {
1011         ret = IEnumRfc1766_Next(pEnumRfc1766, 1, &info, &n);
1012         if (ret != S_OK) break;
1013 
1014 #ifdef DUMP_CP_INFO
1015         trace("lcid %04x rfc_name %s locale_name %s\n",
1016               info.lcid, wine_dbgstr_w(info.wszRfc1766), wine_dbgstr_w(info.wszLocaleName));
1017 #endif
1018 
1019         ok(n == 1, "couldn't fetch 1 RFC1766INFO structure\n");
1020 
1021         /* verify the Rfc1766 value */
1022         ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, info.lcid, &rfcstr);
1023         ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1024 
1025         /* not an exact 1:1 correspondence between lcid and rfc1766 in the
1026          * mlang database, e.g., nb-no -> 1044 -> no */
1027         ok(strstrW(info.wszRfc1766, rfcstr) != NULL,
1028            "Expected matching locale names\n");
1029 
1030         SysFreeString(rfcstr);
1031     }
1032     IEnumRfc1766_Release(pEnumRfc1766);
1033 }
1034 
1035 static void test_GetLcidFromRfc1766(IMultiLanguage2 *iML2)
1036 {
1037     WCHAR rfc1766W[MAX_RFC1766_NAME + 1];
1038     LCID lcid;
1039     HRESULT ret;
1040     DWORD i;
1041 
1042     static WCHAR en[] = { 'e','n',0 };
1043     static WCHAR en_them[] = { 'e','n','-','t','h','e','m',0 };
1044     static WCHAR english[] = { 'e','n','g','l','i','s','h',0 };
1045 
1046 
1047     for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1048         lcid = -1;
1049         MultiByteToWideChar(CP_ACP, 0, lcid_table[i].rfc1766, -1, rfc1766W, MAX_RFC1766_NAME);
1050         ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, rfc1766W);
1051 
1052         /* IE <6.0 guess 0x412 (ko) from "kok" */
1053         ok((ret == lcid_table[i].hr) ||
1054             broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1055             "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1056 
1057         ok((lcid == lcid_table[i].lcid) ||
1058             broken(lcid == lcid_table[i].broken_lcid),   /* IE <6.0 */
1059             "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1060     }
1061 
1062 
1063     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, NULL, en);
1064     ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1065 
1066     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, NULL);
1067     ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
1068 
1069     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_them);
1070     ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1071     if (ret == S_FALSE)
1072     {
1073         BSTR rfcstr;
1074         static WCHAR en[] = {'e','n',0};
1075 
1076         ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1077         ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1078         ok_w2("Expected \"%s\",  got \"%s\"n", en, rfcstr);
1079     }
1080 
1081     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, english);
1082     ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
1083     if (ret == S_FALSE)
1084     {
1085         BSTR rfcstr;
1086         static WCHAR en[] = {'e','n',0};
1087 
1088         ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
1089         ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
1090         ok_w2("Expected \"%s\",  got \"%s\"n", en, rfcstr);
1091     }
1092 
1093 }
1094 
1095 static void test_Rfc1766ToLcid(void)
1096 {
1097     LCID lcid;
1098     HRESULT ret;
1099     DWORD i;
1100 
1101     for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1102         lcid = -1;
1103         ret = pRfc1766ToLcidA(&lcid, lcid_table[i].rfc1766);
1104 
1105         /* IE <6.0 guess 0x412 (ko) from "kok" */
1106         ok( (ret == lcid_table[i].hr) ||
1107             broken(lcid_table[i].broken_lcid && (ret == S_FALSE)),
1108             "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, ret, lcid_table[i].hr);
1109 
1110         ok( (lcid == lcid_table[i].lcid) ||
1111             broken(lcid == lcid_table[i].broken_lcid),  /* IE <6.0 */
1112             "#%02d: got LCID 0x%x (expected 0x%x)\n", i, lcid, lcid_table[i].lcid);
1113     }
1114 
1115     ret = pRfc1766ToLcidA(&lcid, NULL);
1116     ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1117 
1118     ret = pRfc1766ToLcidA(NULL, "en");
1119     ok(ret == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", ret);
1120 }
1121 
1122 static void test_GetNumberOfCodePageInfo(IMultiLanguage2 *iML2)
1123 {
1124     HRESULT hr;
1125     UINT value;
1126 
1127     value = 0xdeadbeef;
1128     hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &value);
1129     ok( (hr == S_OK) && value,
1130         "got 0x%x with %d (expected S_OK with '!= 0')\n", hr, value);
1131 
1132     hr = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, NULL);
1133     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1134 
1135 }
1136 
1137 static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
1138 {
1139     CHAR expected[MAX_RFC1766_NAME];
1140     CHAR buffer[MAX_RFC1766_NAME + 1];
1141     DWORD i;
1142     HRESULT hr;
1143     BSTR rfcstr;
1144 
1145     for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1146         buffer[0] = '\0';
1147 
1148         rfcstr = NULL;
1149         hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid_table[i].lcid, &rfcstr);
1150         ok(hr == lcid_table[i].hr,
1151             "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1152 
1153         if (hr != S_OK)
1154             continue;   /* no result-string created */
1155 
1156         WideCharToMultiByte(CP_ACP, 0, rfcstr, -1, buffer, sizeof(buffer), NULL, NULL);
1157         LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1158                     lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1159 
1160         /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1161         ok( (!lstrcmpA(buffer, expected)) ||
1162             broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1163             "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1164 
1165         SysFreeString(rfcstr);
1166     }
1167 
1168     hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL);
1169     ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1170 }
1171 
1172 static void test_LcidToRfc1766(void)
1173 {
1174     CHAR expected[MAX_RFC1766_NAME];
1175     CHAR buffer[MAX_RFC1766_NAME * 2];
1176     HRESULT hr;
1177     DWORD i;
1178 
1179     for(i = 0; i < sizeof(lcid_table) / sizeof(lcid_table[0]); i++) {
1180 
1181         memset(buffer, '#', sizeof(buffer)-1);
1182         buffer[sizeof(buffer)-1] = '\0';
1183 
1184         hr = pLcidToRfc1766A(lcid_table[i].lcid, buffer, MAX_RFC1766_NAME);
1185 
1186         /* IE <5.0 does not recognize 0x180c (fr-mc) and 0x457 (kok) */
1187         ok( (hr == lcid_table[i].hr) ||
1188             broken(lcid_table[i].broken_lcid && (hr == E_FAIL)),
1189             "#%02d: HRESULT 0x%x (expected 0x%x)\n", i, hr, lcid_table[i].hr);
1190 
1191         if (hr != S_OK)
1192             continue;
1193 
1194         LCMapStringA(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, lcid_table[i].rfc1766,
1195                     lstrlenA(lcid_table[i].rfc1766) + 1, expected, MAX_RFC1766_NAME);
1196 
1197         /* IE <6.0 return "x-kok" for LCID 0x457 ("kok") */
1198         /* IE <5.0 return "fr" for LCID 0x180c ("fr-mc") */
1199         ok( (!lstrcmpA(buffer, expected)) ||
1200             broken(!lstrcmpA(buffer, lcid_table[i].broken_rfc)),
1201             "#%02d: got '%s' (expected '%s')\n", i, buffer, expected);
1202 
1203     }
1204 
1205     memset(buffer, '#', sizeof(buffer)-1);
1206     buffer[sizeof(buffer)-1] = '\0';
1207     hr = pLcidToRfc1766A(-1, buffer, MAX_RFC1766_NAME);
1208     ok(hr == E_FAIL, "got 0x%08x and '%s' (expected E_FAIL)\n", hr, buffer);
1209 
1210     hr = pLcidToRfc1766A(LANG_ENGLISH, NULL, MAX_RFC1766_NAME);
1211     ok(hr == E_INVALIDARG, "got 0x%08x (expected E_INVALIDARG)\n", hr);
1212 
1213     memset(buffer, '#', sizeof(buffer)-1);
1214     buffer[sizeof(buffer)-1] = '\0';
1215     hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, -1);
1216     ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1217 
1218     memset(buffer, '#', sizeof(buffer)-1);
1219     buffer[sizeof(buffer)-1] = '\0';
1220     hr = pLcidToRfc1766A(LANG_ENGLISH, buffer, 0);
1221     ok(hr == E_INVALIDARG, "got 0x%08x and '%s' (expected E_INVALIDARG)\n", hr, buffer);
1222 }
1223 
1224 static void test_GetRfc1766Info(IMultiLanguage2 *iML2)
1225 {
1226     WCHAR short_broken_name[MAX_LOCALE_NAME];
1227     CHAR rfc1766A[MAX_RFC1766_NAME + 1];
1228     BYTE buffer[sizeof(RFC1766INFO) + 4];
1229     PRFC1766INFO prfc = (RFC1766INFO *) buffer;
1230     HRESULT ret;
1231     DWORD i;
1232 
1233     for(i = 0; i < sizeof(info_table) / sizeof(info_table[0]); i++) {
1234         memset(buffer, 'x', sizeof(RFC1766INFO) + 2);
1235         buffer[sizeof(buffer) -1] = 0;
1236         buffer[sizeof(buffer) -2] = 0;
1237 
1238         ret = IMultiLanguage2_GetRfc1766Info(iML2, info_table[i].lcid, info_table[i].lang, prfc);
1239         WideCharToMultiByte(CP_ACP, 0, prfc->wszRfc1766, -1, rfc1766A, MAX_RFC1766_NAME, NULL, NULL);
1240         ok(ret == S_OK, "#%02d: got 0x%x (expected S_OK)\n", i, ret);
1241         ok(prfc->lcid == info_table[i].lcid,
1242             "#%02d: got 0x%04x (expected 0x%04x)\n", i, prfc->lcid, info_table[i].lcid);
1243 
1244         ok(!lstrcmpA(rfc1766A, info_table[i].rfc1766),
1245             "#%02d: got '%s' (expected '%s')\n", i, rfc1766A, info_table[i].rfc1766);
1246 
1247         /* Some IE versions truncate an oversized name one character too short */
1248         if (info_table[i].broken_name) {
1249             lstrcpyW(short_broken_name, info_table[i].broken_name);
1250             short_broken_name[MAX_LOCALE_NAME - 2] = 0;
1251         }
1252 
1253         todo_wine_if (info_table[i].todo & TODO_NAME) {
1254             ok( (!lstrcmpW(prfc->wszLocaleName, info_table[i].localename)) ||
1255                (info_table[i].broken_name && (
1256                 broken(!lstrcmpW(prfc->wszLocaleName, info_table[i].broken_name)) || /* IE < 6.0 */
1257                 broken(!lstrcmpW(prfc->wszLocaleName, short_broken_name)))),
1258                 "#%02d: got %s (expected %s)\n", i,
1259                 wine_dbgstr_w(prfc->wszLocaleName), wine_dbgstr_w(info_table[i].localename));
1260         }
1261     }
1262 
1263     /* SUBLANG_NEUTRAL only allowed for English, Arabic, Chinese */
1264     ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_GERMAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1265     ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1266 
1267     ret = IMultiLanguage2_GetRfc1766Info(iML2, MAKELANGID(LANG_ITALIAN, SUBLANG_NEUTRAL), LANG_ENGLISH, prfc);
1268     ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1269 
1270     /* NULL not allowed */
1271     ret = IMultiLanguage2_GetRfc1766Info(iML2, 0, LANG_ENGLISH, prfc);
1272     ok(ret == E_FAIL, "got 0x%x (expected E_FAIL)\n", ret);
1273 
1274     ret = IMultiLanguage2_GetRfc1766Info(iML2, LANG_ENGLISH, LANG_ENGLISH, NULL);
1275     ok(ret == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", ret);
1276 }
1277 
1278 static void test_IMultiLanguage2_ConvertStringFromUnicode(IMultiLanguage2 *iML2)
1279 {
1280     CHAR dest[MAX_PATH];
1281     CHAR invariate[MAX_PATH];
1282     UINT srcsz, destsz;
1283     HRESULT hr;
1284 
1285     static WCHAR src[] = {'a','b','c',0};
1286 
1287     memset(invariate, 'x', sizeof(invariate));
1288 
1289     /* pSrcStr NULL */
1290     memset(dest, 'x', sizeof(dest));
1291     srcsz = lstrlenW(src) + 1;
1292     destsz = sizeof(dest);
1293     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1294                                                   &srcsz, dest, &destsz);
1295     ok(hr == S_OK || hr == E_FAIL,"expected S_OK or E_FAIL, got %08x\n",hr);
1296     if (hr == S_OK)
1297     {
1298         ok(srcsz == lstrlenW(src) + 1,
1299            "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1300     }
1301     else if (hr == E_FAIL)
1302     {
1303         ok(srcsz == 0,
1304            "Expected %u, got %u\n", 0, srcsz);
1305     }
1306 
1307     ok(!memcmp(dest, invariate, sizeof(dest)),
1308        "Expected dest to be unchanged, got %s\n", dest);
1309     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1310 
1311     /* pcSrcSize NULL */
1312     memset(dest, 'x', sizeof(dest));
1313     destsz = sizeof(dest);
1314     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1315                                                   NULL, dest, &destsz);
1316     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1317     ok(!strncmp(dest, "abc", 3),
1318        "Expected first three chars to be \"abc\"\n");
1319     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1320        "Expected rest of dest to be unchanged, got %s\n", dest);
1321     ok(destsz == lstrlenW(src),
1322        "Expected %u, got %u\n", lstrlenW(src), destsz);
1323 
1324     /* both pSrcStr and pcSrcSize NULL */
1325     memset(dest, 'x', sizeof(dest));
1326     destsz = sizeof(dest);
1327     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
1328                                                   NULL, dest, &destsz);
1329     ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1330     ok(!memcmp(dest, invariate, sizeof(dest)),
1331        "Expected dest to be unchanged, got %s\n", dest);
1332     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1333 
1334     /* pDstStr NULL */
1335     memset(dest, 'x', sizeof(dest));
1336     srcsz = lstrlenW(src) + 1;
1337     destsz = sizeof(dest);
1338     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1339                                                   &srcsz, NULL, &destsz);
1340     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1341     ok(srcsz == lstrlenW(src) + 1,
1342        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1343     ok(destsz == lstrlenW(src) + 1,
1344        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1345 
1346     /* pcDstSize NULL */
1347     memset(dest, 'x', sizeof(dest));
1348     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1349                                                   &srcsz, dest, NULL);
1350     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1351     ok(srcsz == lstrlenW(src) + 1,
1352        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1353     ok(!memcmp(dest, invariate, sizeof(dest)),
1354        "Expected dest to be unchanged, got %s\n", dest);
1355 
1356     /* pcSrcSize is 0 */
1357     memset(dest, 'x', sizeof(dest));
1358     srcsz = 0;
1359     destsz = sizeof(dest);
1360     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1361                                                   &srcsz, dest, &destsz);
1362     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1363     ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1364     ok(!memcmp(dest, invariate, sizeof(dest)),
1365        "Expected dest to be unchanged, got %s\n", dest);
1366     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1367 
1368     /* pcSrcSize does not include NULL terminator */
1369     memset(dest, 'x', sizeof(dest));
1370     srcsz = lstrlenW(src);
1371     destsz = sizeof(dest);
1372     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1373                                                   &srcsz, dest, &destsz);
1374     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1375     ok(srcsz == lstrlenW(src),
1376        "Expected %u, got %u\n", lstrlenW(src), srcsz);
1377     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1378     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1379        "Expected rest of dest to be unchanged, got %s\n", dest);
1380     ok(destsz == lstrlenW(src),
1381        "Expected %u, got %u\n", lstrlenW(src), destsz);
1382 
1383     /* pcSrcSize includes NULL terminator */
1384     memset(dest, 'x', sizeof(dest));
1385     srcsz = lstrlenW(src) + 1;
1386     destsz = sizeof(dest);
1387     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1388                                                   &srcsz, dest, &destsz);
1389     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1390     ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1391     ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1392     ok(destsz == lstrlenW(src) + 1,
1393        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1394 
1395     /* pcSrcSize is -1 */
1396     memset(dest, 'x', sizeof(dest));
1397     srcsz = -1;
1398     destsz = sizeof(dest);
1399     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1400                                                   &srcsz, dest, &destsz);
1401     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1402     ok(srcsz == lstrlenW(src),
1403        "Expected %u, got %u\n", lstrlenW(src), srcsz);
1404     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1405     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1406        "Expected rest of dest to be unchanged, got %s\n", dest);
1407     ok(destsz == lstrlenW(src),
1408        "Expected %u, got %u\n", lstrlenW(src), destsz);
1409 
1410     /* pcDstSize is 0 */
1411     memset(dest, 'x', sizeof(dest));
1412     srcsz = lstrlenW(src) + 1;
1413     destsz = 0;
1414     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1415                                                   &srcsz, dest, &destsz);
1416     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1417     ok(srcsz == lstrlenW(src) + 1,
1418        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1419     ok(!memcmp(dest, invariate, sizeof(dest)),
1420        "Expected dest to be unchanged, got %s\n", dest);
1421     ok(destsz == lstrlenW(src) + 1,
1422        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1423 
1424     /* pcDstSize is not large enough */
1425     memset(dest, 'x', sizeof(dest));
1426     srcsz = lstrlenW(src) + 1;
1427     destsz = lstrlenW(src);
1428     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1429                                                   &srcsz, dest, &destsz);
1430     ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1431     ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1432     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1433     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1434        "Expected rest of dest to be unchanged, got %s\n", dest);
1435     ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1436 
1437     /* pcDstSize (bytes) does not leave room for NULL terminator */
1438     memset(dest, 'x', sizeof(dest));
1439     srcsz = lstrlenW(src) + 1;
1440     destsz = lstrlenW(src) * sizeof(WCHAR);
1441     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1442                                                   &srcsz, dest, &destsz);
1443     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1444     ok(srcsz == lstrlenW(src) + 1,
1445        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1446     ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1447     ok(destsz == lstrlenW(src) + 1,
1448        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1449 }
1450 
1451 static void test_ConvertINetUnicodeToMultiByte(void)
1452 {
1453     CHAR dest[MAX_PATH];
1454     CHAR invariate[MAX_PATH];
1455     INT srcsz, destsz;
1456     HRESULT hr;
1457 
1458     static WCHAR src[] = {'a','b','c',0};
1459 
1460     memset(invariate, 'x', sizeof(invariate));
1461 
1462     /* lpSrcStr NULL */
1463     memset(dest, 'x', sizeof(dest));
1464     srcsz = lstrlenW(src) + 1;
1465     destsz = sizeof(dest);
1466     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, &srcsz, dest, &destsz);
1467     ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1468     if (hr == S_OK)
1469         ok(srcsz == lstrlenW(src) + 1,
1470            "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1471     else if (hr == E_FAIL)
1472         ok(srcsz == 0,
1473            "Expected %u, got %u\n", 0, srcsz);
1474     ok(!memcmp(dest, invariate, sizeof(dest)),
1475        "Expected dest to be unchanged, got %s\n", dest);
1476     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1477 
1478     /* lpnWideCharCount NULL */
1479     memset(dest, 'x', sizeof(dest));
1480     destsz = sizeof(dest);
1481     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, NULL, dest, &destsz);
1482     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1483     ok(!strncmp(dest, "abc", 3),
1484        "Expected first three chars to be \"abc\"\n");
1485     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1486        "Expected rest of dest to be unchanged, got %s\n", dest);
1487     ok(destsz == lstrlenW(src),
1488        "Expected %u, got %u\n", lstrlenW(src), destsz);
1489 
1490     /* both lpSrcStr and lpnWideCharCount NULL */
1491     memset(dest, 'x', sizeof(dest));
1492     destsz = sizeof(dest);
1493     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, NULL, dest, &destsz);
1494     ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1495     ok(!memcmp(dest, invariate, sizeof(dest)),
1496        "Expected dest to be unchanged, got %s\n", dest);
1497     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1498 
1499     /* lpDstStr NULL */
1500     memset(dest, 'x', sizeof(dest));
1501     srcsz = lstrlenW(src) + 1;
1502     destsz = sizeof(dest);
1503     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, NULL, &destsz);
1504     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1505     ok(srcsz == lstrlenW(src) + 1,
1506        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1507     ok(destsz == lstrlenW(src) + 1,
1508        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1509 
1510     /* lpnMultiCharCount NULL */
1511     memset(dest, 'x', sizeof(dest));
1512     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, NULL);
1513     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1514     ok(srcsz == lstrlenW(src) + 1,
1515        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1516     ok(!memcmp(dest, invariate, sizeof(dest)),
1517        "Expected dest to be unchanged, got %s\n", dest);
1518 
1519     /* lpnWideCharCount is 0 */
1520     memset(dest, 'x', sizeof(dest));
1521     srcsz = 0;
1522     destsz = sizeof(dest);
1523     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1524     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1525     ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1526     ok(!memcmp(dest, invariate, sizeof(dest)),
1527        "Expected dest to be unchanged, got %s\n", dest);
1528     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1529 
1530     /* lpnWideCharCount does not include NULL terminator */
1531     memset(dest, 'x', sizeof(dest));
1532     srcsz = lstrlenW(src);
1533     destsz = sizeof(dest);
1534     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1535     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1536     ok(srcsz == lstrlenW(src),
1537        "Expected %u, got %u\n", lstrlenW(src), srcsz);
1538     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1539     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1540        "Expected rest of dest to be unchanged, got %s\n", dest);
1541     ok(destsz == lstrlenW(src),
1542        "Expected %u, got %u\n", lstrlenW(src), destsz);
1543 
1544     /* lpnWideCharCount includes NULL terminator */
1545     memset(dest, 'x', sizeof(dest));
1546     srcsz = lstrlenW(src) + 1;
1547     destsz = sizeof(dest);
1548     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1549     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1550     ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1551     ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1552     ok(destsz == lstrlenW(src) + 1,
1553        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1554 
1555     /* lpnWideCharCount is -1 */
1556     memset(dest, 'x', sizeof(dest));
1557     srcsz = -1;
1558     destsz = sizeof(dest);
1559     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1560     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1561     ok(srcsz == lstrlenW(src),
1562        "Expected %u, got %u\n", lstrlenW(src), srcsz);
1563     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1564     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1565        "Expected rest of dest to be unchanged, got %s\n", dest);
1566     ok(destsz == lstrlenW(src),
1567        "Expected %u, got %u\n", lstrlenW(src), destsz);
1568 
1569     /* lpnMultiCharCount is 0 */
1570     memset(dest, 'x', sizeof(dest));
1571     srcsz = lstrlenW(src) + 1;
1572     destsz = 0;
1573     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1574     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1575     ok(srcsz == lstrlenW(src) + 1,
1576        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1577     ok(!memcmp(dest, invariate, sizeof(dest)),
1578        "Expected dest to be unchanged, got %s\n", dest);
1579     ok(destsz == lstrlenW(src) + 1,
1580        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1581 
1582     /* lpnMultiCharCount is not large enough */
1583     memset(dest, 'x', sizeof(dest));
1584     srcsz = lstrlenW(src) + 1;
1585     destsz = lstrlenW(src);
1586     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1587     ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1588     ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1589     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1590     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1591        "Expected rest of dest to be unchanged, got %s\n", dest);
1592     ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1593 
1594     /* lpnMultiCharCount (bytes) does not leave room for NULL terminator */
1595     memset(dest, 'x', sizeof(dest));
1596     srcsz = lstrlenW(src) + 1;
1597     destsz = lstrlenW(src) * sizeof(WCHAR);
1598     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1599     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1600     ok(srcsz == lstrlenW(src) + 1,
1601        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1602     ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1603     ok(destsz == lstrlenW(src) + 1,
1604        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1605 }
1606 
1607 static void test_JapaneseConversion(void)
1608 {
1609     /* Data */
1610     static WCHAR unc_jp[9][12] = {
1611   {9,0x31,0x20,0x3042,0x3044,0x3046,0x3048,0x304a,0x000d,0x000a},
1612   {9,0x31,0x20,0x30a2,0x30a4,0x30a6,0x30a8,0x30aa,0x000d,0x000a},
1613   {9,0x31,0x20,0xff71,0xff72,0xff73,0xff74,0xff75,0x000d,0x000a},
1614   {9,0x31,0x20,0x3041,0x3043,0x3045,0x3047,0x3049,0x000d,0x000a},
1615   {9,0x31,0x20,0x30a1,0x30a3,0x30a5,0x30a7,0x30a9,0x000d,0x000a},
1616   {9,0x31,0x20,0xff67,0xff68,0xff69,0xff6a,0xff6b,0x000d,0x000a},
1617   {9,0x31,0x20,0x300c,0x65e5,0x672c,0x8a9e,0x300d,0x000d,0x000a},
1618   {7,0x31,0x20,0x25c7,0x25c7,0x3012,0x000d,0x000a},
1619   {11,0x31,0x20,0x203b,0x3010,0x0074,0x0065,0x0073,0x0074,0x3011,0x000d,0x000a}
1620     };
1621     static CHAR jis_jp[9][27] = {
1622   {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x22,0x24,0x24,0x24,0x26,0x24,0x28,
1623       0x24,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1624   {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1625       0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1626   {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1627       0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1628   {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x21,0x24,0x23,0x24,0x25,0x24,0x27,
1629       0x24,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1630   {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1631       0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1632   {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1633       0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1634   {20,0x31,0x20,0x1b,0x24,0x42,0x21,0x56,0x46,0x7c,0x4b,0x5c,0x38,0x6c,
1635       0x21,0x57,0x1b,0x28,0x42,0x0d,0x0a},
1636   {16,0x31,0x20,0x1b,0x24,0x42,0x21,0x7e,0x21,0x7e,0x22,0x29,0x1b,0x28,
1637       0x42,0x0d,0x0a},
1638   {26,0x31,0x20,0x1b,0x24,0x42,0x22,0x28,0x21,0x5a,0x1b,0x28,0x42,0x74,
1639       0x65,0x73,0x74,0x1b,0x24,0x42,0x21,0x5b,0x1b,0x28,0x42,0x0d,0x0a}
1640     };
1641     static CHAR sjis_jp[9][15] = {
1642   {14,0x31,0x20,0x82,0xa0,0x82,0xa2,0x82,0xa4,0x82,0xa6,0x82,0xa8,0x0d,0x0a},
1643   {14,0x31,0x20,0x83,0x41,0x83,0x43,0x83,0x45,0x83,0x47,0x83,0x49,0x0d,0x0a},
1644   {9,0x31,0x20,0xb1,0xb2,0xb3,0xb4,0xb5,0x0d,0x0a},
1645   {14,0x31,0x20,0x82,0x9f,0x82,0xa1,0x82,0xa3,0x82,0xa5,0x82,0xa7,0x0d,0x0a},
1646   {14,0x31,0x20,0x83,0x40,0x83,0x42,0x83,0x44,0x83,0x46,0x83,0x48,0x0d,0x0a},
1647   {9,0x31,0x20,0xa7,0xa8,0xa9,0xaa,0xab,0x0d,0x0a},
1648   {14,0x31,0x20,0x81,0x75,0x93,0xfa,0x96,0x7b,0x8c,0xea,0x81,0x76,0x0d,0x0a},
1649   {10,0x31,0x20,0x81,0x9e,0x81,0x9e,0x81,0xa7,0x0d,0x0a},
1650   {14,0x31,0x20,0x81,0xa6,0x81,0x79,0x74,0x65,0x73,0x74,0x81,0x7a,0x0d,0x0a}
1651     };
1652     static CHAR euc_jp[9][15] = {
1653   {14,0x31,0x20,0xa4,0xa2,0xa4,0xa4,0xa4,0xa6,0xa4,0xa8,0xa4,0xaa,0x0d,0x0a},
1654   {14,0x31,0x20,0xa5,0xa2,0xa5,0xa4,0xa5,0xa6,0xa5,0xa8,0xa5,0xaa,0x0d,0x0a},
1655   {14,0x31,0x20,0x8e,0xb1,0x8e,0xb2,0x8e,0xb3,0x8e,0xb4,0x8e,0xb5,0x0d,0x0a},
1656   {14,0x31,0x20,0xa4,0xa1,0xa4,0xa3,0xa4,0xa5,0xa4,0xa7,0xa4,0xa9,0x0d,0x0a},
1657   {14,0x31,0x20,0xa5,0xa1,0xa5,0xa3,0xa5,0xa5,0xa5,0xa7,0xa5,0xa9,0x0d,0x0a},
1658   {14,0x31,0x20,0x8e,0xa7,0x8e,0xa8,0x8e,0xa9,0x8e,0xaa,0x8e,0xab,0x0d,0x0a},
1659   {14,0x31,0x20,0xa1,0xd6,0xc6,0xfc,0xcb,0xdc,0xb8,0xec,0xa1,0xd7,0x0d,0x0a},
1660   {10,0x31,0x20,0xa1,0xfe,0xa1,0xfe,0xa2,0xa9,0x0d,0x0a},
1661   {14,0x31,0x20,0xa2,0xa8,0xa1,0xda,0x74,0x65,0x73,0x74,0xa1,0xdb,0x0d,0x0a}
1662     };
1663 
1664     INT srcsz, destsz;
1665     INT i;
1666     HRESULT hr;
1667     CHAR output[30];
1668     WCHAR outputW[30];
1669     int outlen;
1670 
1671     /* test unc->jis */
1672     for (i = 0; i < 9; i++)
1673     {
1674         int j;
1675         destsz = 30;
1676         outlen = jis_jp[i][0];
1677         srcsz = unc_jp[i][0];
1678         hr = pConvertINetUnicodeToMultiByte(NULL, 50220, &unc_jp[i][1], &srcsz, output, &destsz);
1679         if (hr == S_FALSE)
1680         {
1681             skip("Code page identifier 50220 is not supported\n");
1682             break;
1683         }
1684         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1685         ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1686         ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1687         ok(memcmp(output,&jis_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1688 
1689         /* and back */
1690         srcsz = outlen;
1691         destsz = 30;
1692         hr = pConvertINetMultiByteToUnicode(NULL, 50220, output, &srcsz, outputW,&destsz);
1693 
1694         /*
1695          * JIS does not have hankata so it get automatically converted to
1696          * zenkata. this means that strings 1 and 2 are identical as well as
1697          * strings 4 and 5.
1698          */
1699         j = i;
1700         if (i == 2) j = 1;
1701         if (i == 5) j = 4;
1702 
1703         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i, hr);
1704         ok(destsz == unc_jp[j][0],"(%i) Expected %i, got %i\n",i,unc_jp[j][0],destsz);
1705         ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1706         ok(memcmp(outputW,&unc_jp[j][1],destsz)==0,"(%i) Strings do not match\n",i);
1707     }
1708 
1709     /* test unc->sjis */
1710     for (i = 0; i < 9; i++)
1711     {
1712         destsz = 30;
1713         outlen = sjis_jp[i][0];
1714         srcsz = unc_jp[i][0];
1715 
1716         hr = pConvertINetUnicodeToMultiByte(NULL, 932, &unc_jp[i][1], &srcsz, output, &destsz);
1717         if (hr == S_FALSE)
1718         {
1719             skip("Code page identifier 932 is not supported\n");
1720             break;
1721         }
1722         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1723         ok(destsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,destsz);
1724         ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1725         ok(memcmp(output,&sjis_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1726 
1727         srcsz = outlen;
1728         destsz = 30;
1729         hr = pConvertINetMultiByteToUnicode(NULL, 932, output, &srcsz, outputW,&destsz);
1730 
1731         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1732         ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1733         ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1734         ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1735     }
1736 
1737     /* test unc->euc */
1738     for (i = 0; i < 9; i++)
1739     {
1740         destsz = 30;
1741         outlen = euc_jp[i][0];
1742         srcsz = unc_jp[i][0];
1743 
1744         hr = pConvertINetUnicodeToMultiByte(NULL, 51932, &unc_jp[i][1], &srcsz, output, &destsz);
1745         if (hr == S_FALSE)
1746         {
1747             skip("Code page identifier 51932 is not supported\n");
1748             break;
1749         }
1750         ok(hr == S_OK, "(%i) Expected S_OK, got %08x\n",i,hr);
1751         ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1752         ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1753         ok(memcmp(output,&euc_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1754 
1755         srcsz = outlen;
1756         destsz = 30;
1757         hr = pConvertINetMultiByteToUnicode(NULL, 51932, output, &srcsz, outputW,&destsz);
1758 
1759         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1760         ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1761         ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1762         ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1763     }
1764 
1765     /* Japanese autodetect */
1766     i = 0;
1767     destsz = 30;
1768     srcsz = jis_jp[i][0];
1769     hr = pConvertINetMultiByteToUnicode(NULL, 50932, &jis_jp[i][1], &srcsz, outputW, &destsz);
1770     if (hr == S_FALSE)
1771     {
1772         skip("Code page identifier 50932 is not supported\n");
1773         return;
1774     }
1775     ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1776     ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1777     ok(srcsz == jis_jp[i][0],"(%i) Expected %i, got %i\n",i,jis_jp[i][0],srcsz);
1778     ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1779 
1780     i = 1;
1781     destsz = 30;
1782     srcsz = sjis_jp[i][0];
1783     hr = pConvertINetMultiByteToUnicode(NULL, 50932, &sjis_jp[i][1], &srcsz, outputW, &destsz);
1784     ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1785     ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1786     ok(srcsz == sjis_jp[i][0],"(%i) Expected %i, got %i\n",i,sjis_jp[i][0],srcsz);
1787     ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1788 }
1789 
1790 static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
1791 {
1792     HRESULT hr;
1793     UINT nfonts;
1794     SCRIPTFONTINFO sfi[1];
1795 
1796     nfonts = 0;
1797     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, 0, &nfonts, NULL);
1798     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1799     ok(nfonts, "unexpected result\n");
1800 
1801     nfonts = 0;
1802     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, NULL);
1803     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1804     ok(nfonts, "unexpected result\n");
1805 
1806     nfonts = 0;
1807     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, NULL);
1808     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1809     ok(nfonts, "unexpected result\n");
1810 
1811     nfonts = 1;
1812     memset(sfi, 0, sizeof(sfi));
1813     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, sfi);
1814     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1815     ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1816     ok(sfi[0].scripts != 0, "unexpected result\n");
1817     ok(sfi[0].wszFont[0], "unexpected result\n");
1818 
1819     nfonts = 1;
1820     memset(sfi, 0, sizeof(sfi));
1821     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidAsciiLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, sfi);
1822     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1823     ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1824     ok(sfi[0].scripts != 0, "unexpected result\n");
1825     ok(sfi[0].wszFont[0], "unexpected result\n");
1826 }
1827 
1828 static void test_CodePageToScriptID(IMLangFontLink2 *font_link)
1829 {
1830     HRESULT hr;
1831     UINT i;
1832     SCRIPT_ID sid;
1833     static const struct
1834     {
1835         UINT cp;
1836         SCRIPT_ID sid;
1837         HRESULT hr;
1838     }
1839     cp_sid[] =
1840     {
1841         {874,  sidThai},
1842         {932,  sidKana},
1843         {936,  sidHan},
1844         {949,  sidHangul},
1845         {950,  sidBopomofo},
1846         {1250, sidAsciiLatin},
1847         {1251, sidCyrillic},
1848         {1252, sidAsciiLatin},
1849         {1253, sidGreek},
1850         {1254, sidAsciiLatin},
1851         {1255, sidHebrew},
1852         {1256, sidArabic},
1853         {1257, sidAsciiLatin},
1854         {1258, sidAsciiLatin},
1855         {CP_UNICODE, 0, E_FAIL}
1856     };
1857 
1858     for (i = 0; i < sizeof(cp_sid)/sizeof(cp_sid[0]); i++)
1859     {
1860         hr = IMLangFontLink2_CodePageToScriptID(font_link, cp_sid[i].cp, &sid);
1861         ok(hr == cp_sid[i].hr, "%u CodePageToScriptID failed 0x%08x %u\n", i, hr, GetLastError());
1862         if (SUCCEEDED(hr))
1863         {
1864             ok(sid == cp_sid[i].sid,
1865                "%u got sid %u for codepage %u, expected %u\n", i, sid, cp_sid[i].cp, cp_sid[i].sid);
1866         }
1867     }
1868 }
1869 
1870 static void test_GetFontUnicodeRanges(IMLangFontLink2 *font_link)
1871 {
1872     HRESULT hr;
1873     UINT count;
1874     HFONT hfont, old_hfont;
1875     LOGFONTA lf;
1876     HDC hdc;
1877     UNICODERANGE *ur;
1878 
1879     hdc = CreateCompatibleDC(0);
1880     memset(&lf, 0, sizeof(lf));
1881     lstrcpyA(lf.lfFaceName, "Arial");
1882     hfont = CreateFontIndirectA(&lf);
1883     old_hfont = SelectObject(hdc, hfont);
1884 
1885     count = 0;
1886     hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, NULL, &count, NULL);
1887     ok(hr == E_FAIL, "expected E_FAIL, got 0x%08x\n", hr);
1888 
1889     hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, NULL, NULL);
1890     ok(hr == E_INVALIDARG, "expected E_FAIL, got 0x%08x\n", hr);
1891 
1892     count = 0;
1893     hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, NULL);
1894     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1895     ok(count, "expected count > 0\n");
1896 
1897     ur = HeapAlloc(GetProcessHeap(), 0, sizeof(*ur) * count);
1898 
1899     hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1900     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1901 
1902     count--;
1903     hr = IMLangFontLink2_GetFontUnicodeRanges(font_link, hdc, &count, ur);
1904     ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1905 
1906     HeapFree(GetProcessHeap(), 0, ur);
1907 
1908     SelectObject(hdc, old_hfont);
1909     DeleteObject(hfont);
1910     DeleteDC(hdc);
1911 }
1912 
1913 static void test_IsCodePageInstallable(IMultiLanguage2 *ml2)
1914 {
1915     UINT i;
1916     HRESULT hr;
1917 
1918     for (i = 0; i < 0xffff; i++)
1919     {
1920         hr = IMultiLanguage2_IsCodePageInstallable(ml2, i);
1921 
1922         /* it would be better to use IMultiLanguage2_ValidateCodePageEx here but that brings
1923          * up an installation dialog on some platforms, even when specifying CPIOD_PEEK.
1924          */
1925         if (IsValidCodePage(i))
1926             ok(hr == S_OK ||
1927                broken(hr == S_FALSE) ||  /* win2k */
1928                broken(hr == E_INVALIDARG),  /* win2k */
1929                "code page %u is valid but not installable 0x%08x\n", i, hr);
1930     }
1931 }
1932 
1933 static void test_GetGlobalFontLinkObject(void)
1934 {
1935     HRESULT ret;
1936     void *unknown;
1937 
1938     ret = GetGlobalFontLinkObject(NULL);
1939     ok(ret == E_INVALIDARG, "expected E_INVALIDARG got %#x\n", ret);
1940 
1941     unknown = (void *)0xdeadbeef;
1942     ret = GetGlobalFontLinkObject(&unknown);
1943 todo_wine {
1944     ok(ret == S_OK, "expected S_OK got %#x\n", ret);
1945     ok(unknown != NULL && unknown != (void *)0xdeadbeef,
1946        "GetGlobalFontLinkObject() returned %p\n", unknown);
1947     }
1948 }
1949 
1950 static void test_IMLangConvertCharset(IMultiLanguage *ml)
1951 {
1952     IMLangConvertCharset *convert;
1953     WCHAR strW[] = {'a','b','c','d',0};
1954     UINT cp, src_size, dst_size;
1955     char strA[] = "abcd";
1956     WCHAR buffW[20];
1957     HRESULT hr;
1958 
1959     hr = IMultiLanguage_CreateConvertCharset(ml, CP_ACP, CP_UTF8, 0, &convert);
1960 todo_wine
1961     ok(hr == S_FALSE, "expected S_FALSE got 0x%08x\n", hr);
1962 
1963     hr = IMLangConvertCharset_GetSourceCodePage(convert, NULL);
1964     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1965 
1966     cp = CP_UTF8;
1967     hr = IMLangConvertCharset_GetSourceCodePage(convert, &cp);
1968     ok(hr == S_OK, "expected S_OK got 0x%08x\n", hr);
1969     ok(cp == CP_ACP, "got %d\n", cp);
1970 
1971     hr = IMLangConvertCharset_GetDestinationCodePage(convert, NULL);
1972     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1973 
1974     cp = CP_ACP;
1975     hr = IMLangConvertCharset_GetDestinationCodePage(convert, &cp);
1976     ok(hr == S_OK, "expected S_OK got 0x%08x\n", hr);
1977     ok(cp == CP_UTF8, "got %d\n", cp);
1978 
1979     /* DoConversionToUnicode */
1980     hr = IMLangConvertCharset_Initialize(convert, CP_UTF8, CP_UNICODE, 0);
1981     ok(hr == S_OK, "expected S_OK got 0x%08x\n", hr);
1982 
1983     hr = IMLangConvertCharset_DoConversionToUnicode(convert, NULL, NULL, NULL, NULL);
1984     ok(hr == E_FAIL || broken(hr == S_OK) /* win2k */, "got 0x%08x\n", hr);
1985 
1986     src_size = -1;
1987     dst_size = 20;
1988     buffW[0] = 0;
1989     buffW[4] = 4;
1990     hr = IMLangConvertCharset_DoConversionToUnicode(convert, strA, &src_size, buffW, &dst_size);
1991     ok(hr == S_OK, "got 0x%08x\n", hr);
1992     ok(!memcmp(buffW, strW, 4*sizeof(WCHAR)), "got converted string %s\n", wine_dbgstr_wn(buffW, dst_size));
1993     ok(dst_size == 4, "got %d\n", dst_size);
1994     ok(buffW[4] == 4, "got %d\n", buffW[4]);
1995     ok(src_size == 4, "got %d\n", src_size);
1996 
1997     src_size = -1;
1998     dst_size = 0;
1999     buffW[0] = 1;
2000     hr = IMLangConvertCharset_DoConversionToUnicode(convert, strA, &src_size, buffW, &dst_size);
2001     ok(hr == S_OK, "got 0x%08x\n", hr);
2002     ok(buffW[0] == 1, "got %d\n", buffW[0]);
2003     ok(dst_size == 4, "got %d\n", dst_size);
2004     ok(src_size == 4, "got %d\n", src_size);
2005 
2006     hr = IMLangConvertCharset_Initialize(convert, CP_UNICODE, CP_UNICODE, 0);
2007     ok(hr == S_OK, "expected S_OK got 0x%08x\n", hr);
2008 
2009     IMLangConvertCharset_Release(convert);
2010 }
2011 
2012 static const char stream_data[] = "VCARD2.1test;test";
2013 static ULONG stream_pos;
2014 
2015 static HRESULT WINAPI stream_QueryInterface(IStream *iface, REFIID riid, void **obj)
2016 {
2017     ok(FALSE, "unexpected call\n");
2018     return E_NOINTERFACE;
2019 }
2020 
2021 static ULONG WINAPI stream_AddRef(IStream *iface)
2022 {
2023     ok(FALSE, "unexpected call\n");
2024     return 2;
2025 }
2026 
2027 static ULONG WINAPI stream_Release(IStream *iface)
2028 {
2029     ok(FALSE, "unexpected call\n");
2030     return 1;
2031 }
2032 
2033 static HRESULT WINAPI stream_Read(IStream *iface, void *buf, ULONG len, ULONG *read)
2034 {
2035     ULONG size;
2036 
2037     if (stream_pos == sizeof(stream_data) - 1)
2038     {
2039         *read = 0;
2040         return S_FALSE;
2041     }
2042     size = min(sizeof(stream_data) - 1 - stream_pos, len);
2043     memcpy(buf, stream_data + stream_pos, size);
2044     stream_pos += size;
2045     *read = size;
2046     return S_OK;
2047 }
2048 
2049 static HRESULT WINAPI stream_Write(IStream *iface, const void *buf, ULONG len, ULONG *written)
2050 {
2051     ok(FALSE, "unexpected call\n");
2052     return E_NOTIMPL;
2053 }
2054 
2055 static HRESULT WINAPI stream_Seek(IStream *iface, LARGE_INTEGER move, DWORD origin,
2056     ULARGE_INTEGER *newpos)
2057 {
2058     if (origin == STREAM_SEEK_SET)
2059         stream_pos = move.QuadPart;
2060     else if (origin == STREAM_SEEK_CUR)
2061         stream_pos += move.QuadPart;
2062     else if (origin == STREAM_SEEK_END)
2063         stream_pos = sizeof(stream_data) - 1 - move.QuadPart;
2064 
2065     if (newpos) newpos->QuadPart = stream_pos;
2066     return S_OK;
2067 }
2068 
2069 static HRESULT WINAPI stream_SetSize(IStream *iface, ULARGE_INTEGER newsize)
2070 {
2071     ok(FALSE, "unexpected call\n");
2072     return E_NOTIMPL;
2073 }
2074 
2075 static HRESULT WINAPI stream_CopyTo(IStream *iface, IStream *stream, ULARGE_INTEGER len,
2076     ULARGE_INTEGER *read, ULARGE_INTEGER *written)
2077 {
2078     ok(FALSE, "unexpected call\n");
2079     return E_NOTIMPL;
2080 }
2081 
2082 static HRESULT WINAPI stream_Commit(IStream *iface, DWORD flags)
2083 {
2084     ok(FALSE, "unexpected call\n");
2085     return E_NOTIMPL;
2086 }
2087 
2088 static HRESULT WINAPI stream_Revert(IStream *iface)
2089 {
2090     ok(FALSE, "unexpected call\n");
2091     return E_NOTIMPL;
2092 }
2093 
2094 static HRESULT WINAPI stream_LockRegion(IStream *iface, ULARGE_INTEGER offset,
2095     ULARGE_INTEGER len, DWORD locktype)
2096 {
2097     ok(FALSE, "unexpected call\n");
2098     return E_NOTIMPL;
2099 }
2100 
2101 static HRESULT WINAPI stream_UnlockRegion(IStream *iface, ULARGE_INTEGER offset,
2102     ULARGE_INTEGER len, DWORD locktype)
2103 {
2104     ok(FALSE, "unexpected call\n");
2105     return E_NOTIMPL;
2106 }
2107 
2108 static HRESULT WINAPI stream_Stat(IStream *iface, STATSTG *stg, DWORD flag)
2109 {
2110     ok(FALSE, "unexpected call\n");
2111     return E_NOTIMPL;
2112 }
2113 
2114 static HRESULT WINAPI stream_Clone(IStream *iface, IStream **stream)
2115 {
2116     ok(FALSE, "unexpected call\n");
2117     return E_NOTIMPL;
2118 }
2119 
2120 static /* const */ IStreamVtbl stream_vtbl =
2121 {
2122     stream_QueryInterface,
2123     stream_AddRef,
2124     stream_Release,
2125     stream_Read,
2126     stream_Write,
2127     stream_Seek,
2128     stream_SetSize,
2129     stream_CopyTo,
2130     stream_Commit,
2131     stream_Revert,
2132     stream_LockRegion,
2133     stream_UnlockRegion,
2134     stream_Stat,
2135     stream_Clone
2136 };
2137 
2138 static IStream test_stream = { &stream_vtbl };
2139 
2140 static void test_DetectOutboundCodePageInIStream(IMultiLanguage3 *ml)
2141 {
2142     HRESULT hr;
2143     UINT nb_detected, detected[4];
2144     UINT preferred[] = {1250,1251,1252,65001};
2145     UINT preferred2[] = {1250,1251,1252};
2146 
2147     nb_detected = 0;
2148     memset(detected, 0, sizeof(detected));
2149     hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2150         MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2151         sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2152     ok(hr == E_INVALIDARG, "got %08x\n", hr);
2153 
2154     nb_detected = 1;
2155     memset(detected, 0, sizeof(detected));
2156     hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2157         MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2158         sizeof(preferred)/sizeof(preferred[0]), NULL, &nb_detected, NULL);
2159     ok(hr == E_INVALIDARG, "got %08x\n", hr);
2160 
2161     nb_detected = 1;
2162     memset(detected, 0, sizeof(detected));
2163     hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2164         MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2165         sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2166     ok(hr == S_OK, "got %08x\n", hr);
2167     ok(nb_detected == 1, "got %u\n", nb_detected);
2168     ok(detected[0] == 65001, "got %u\n", detected[0]);
2169 
2170     nb_detected = 2;
2171     memset(detected, 0, sizeof(detected));
2172     hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2173         MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2174         sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2175     ok(hr == S_OK, "got %08x\n", hr);
2176     todo_wine ok(nb_detected == 2, "got %u\n", nb_detected);
2177     ok(detected[0] == 65001, "got %u\n", detected[0]);
2178     todo_wine ok(detected[1] == 65000, "got %u\n", detected[1]);
2179 
2180     nb_detected = 3;
2181     memset(detected, 0, sizeof(detected));
2182     hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2183         MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2184         sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2185     ok(hr == S_OK, "got %08x\n", hr);
2186     todo_wine ok(nb_detected == 3, "got %u\n", nb_detected);
2187     ok(detected[0] == 65001, "got %u\n", detected[0]);
2188     todo_wine ok(detected[1] == 65000, "got %u\n", detected[1]);
2189     todo_wine ok(detected[2] == 1200, "got %u\n", detected[2]);
2190 
2191     nb_detected = 4;
2192     memset(detected, 0, sizeof(detected));
2193     hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2194         MLDETECTF_PRESERVE_ORDER, &test_stream, preferred,
2195         sizeof(preferred)/sizeof(preferred[0]), detected, &nb_detected, NULL);
2196     ok(hr == S_OK, "got %08x\n", hr);
2197     todo_wine ok(nb_detected == 3, "got %u\n", nb_detected);
2198     ok(detected[0] == 65001, "got %u\n", detected[0]);
2199     todo_wine ok(detected[1] == 65000, "got %u\n", detected[1]);
2200     todo_wine ok(detected[2] == 1200, "got %u\n", detected[2]);
2201     ok(detected[3] == 0, "got %u\n", detected[3]);
2202 
2203     nb_detected = 3;
2204     memset(detected, 0, sizeof(detected));
2205     hr = IMultiLanguage3_DetectOutboundCodePageInIStream(ml,
2206         MLDETECTF_PRESERVE_ORDER, &test_stream, preferred2,
2207         sizeof(preferred2)/sizeof(preferred2[0]), detected, &nb_detected, NULL);
2208     ok(hr == S_OK, "got %08x\n", hr);
2209     todo_wine ok(nb_detected == 3, "got %u\n", nb_detected);
2210     ok(detected[0] == 65001, "got %u\n", detected[0]);
2211     todo_wine ok(detected[1] == 65000, "got %u\n", detected[1]);
2212     todo_wine ok(detected[2] == 1200, "got %u\n", detected[2]);
2213 }
2214 
2215 START_TEST(mlang)
2216 {
2217     IMultiLanguage  *iML = NULL;
2218     IMultiLanguage2 *iML2 = NULL;
2219     IMultiLanguage3 *iML3 = NULL;
2220     IMLangFontLink  *iMLFL = NULL;
2221     IMLangFontLink2 *iMLFL2 = NULL;
2222     HRESULT ret;
2223 
2224     if (!init_function_ptrs())
2225         return;
2226 
2227     CoInitialize(NULL);
2228     test_Rfc1766ToLcid();
2229     test_LcidToRfc1766();
2230 
2231     test_ConvertINetUnicodeToMultiByte();
2232     test_JapaneseConversion();
2233 
2234     test_GetGlobalFontLinkObject();
2235 
2236     trace("IMultiLanguage\n");
2237     ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2238                            &IID_IMultiLanguage, (void **)&iML);
2239     if (ret != S_OK || !iML) return;
2240 
2241     test_GetNumberOfCodePageInfo((IMultiLanguage2 *)iML);
2242     test_IMLangConvertCharset(iML);
2243     test_GetCharsetInfo_other(iML);
2244     IMultiLanguage_Release(iML);
2245 
2246 
2247     /* IMultiLanguage2 (IE5.0 and above) */
2248     trace("IMultiLanguage2\n");
2249     ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2250                            &IID_IMultiLanguage2, (void **)&iML2);
2251     if (ret != S_OK || !iML2) return;
2252 
2253     test_rfc1766(iML2);
2254     test_GetLcidFromRfc1766(iML2);
2255     test_GetRfc1766FromLcid(iML2);
2256     test_GetRfc1766Info(iML2);
2257     test_GetNumberOfCodePageInfo(iML2);
2258 
2259     test_EnumCodePages(iML2, 0);
2260     test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
2261     test_EnumCodePages(iML2, MIMECONTF_BROWSER);
2262     test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
2263     test_EnumCodePages(iML2, MIMECONTF_VALID);
2264     /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
2265     /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/
2266 
2267     test_EnumScripts(iML2, 0);
2268     test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
2269     test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);
2270 
2271     ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
2272     ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
2273     ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
2274     ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
2275 
2276     test_multibyte_to_unicode_translations(iML2);
2277     test_IMultiLanguage2_ConvertStringFromUnicode(iML2);
2278 
2279     test_IsCodePageInstallable(iML2);
2280 
2281     IMultiLanguage2_Release(iML2);
2282 
2283 
2284     /* IMLangFontLink */
2285     ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2286                            &IID_IMLangFontLink, (void **)&iMLFL);
2287     if (ret != S_OK || !iMLFL) return;
2288 
2289     IMLangFontLink_Test(iMLFL);
2290     IMLangFontLink_Release(iMLFL);
2291 
2292     /* IMLangFontLink2 */
2293     ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2294                            &IID_IMLangFontLink2, (void **)&iMLFL2);
2295     if (ret != S_OK || !iMLFL2) return;
2296 
2297     test_GetScriptFontInfo(iMLFL2);
2298     test_GetFontUnicodeRanges(iMLFL2);
2299     test_CodePageToScriptID(iMLFL2);
2300     IMLangFontLink2_Release(iMLFL2);
2301 
2302     trace("IMultiLanguage3\n");
2303     ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
2304                            &IID_IMultiLanguage3, (void **)&iML3);
2305     if (ret == S_OK)
2306     {
2307         test_DetectOutboundCodePageInIStream(iML3);
2308         IMultiLanguage3_Release(iML3);
2309     }
2310 
2311     CoUninitialize();
2312 }
2313