wined3d: Handle the sampler type shift in the frontend.
[wine] / dlls / mlang / tests / mlang.c
1 /*
2  * Unit test suite for MLANG APIs.
3  *
4  * Copyright 2004 Dmitry Timoshkov
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "initguid.h"
29 #include "mlang.h"
30
31 #include "wine/test.h"
32
33 #ifndef CP_UNICODE
34 #define CP_UNICODE 1200
35 #endif
36
37 #if 0
38 #define DUMP_CP_INFO
39 #define DUMP_SCRIPT_INFO
40
41 #if defined DUMP_CP_INFO || defined DUMP_SCRIPT_INFO
42 #include "wine/debug.h"
43 #endif
44 #endif /* 0 */
45
46 static BOOL (WINAPI *pGetCPInfoExA)(UINT, DWORD, LPCPINFOEXA);
47 static HRESULT (WINAPI *pConvertINetMultiByteToUnicode)(LPDWORD, DWORD, LPCSTR,
48                                                         LPINT, LPWSTR, LPINT);
49 static HRESULT (WINAPI *pConvertINetUnicodeToMultiByte)(LPDWORD, DWORD, LPCWSTR,
50                                                         LPINT, LPSTR, LPINT);
51
52 static BOOL init_function_ptrs(void)
53 {
54     HMODULE hMlang;
55
56     hMlang = LoadLibraryA("mlang.dll");
57     if (!hMlang)
58     {
59         skip("mlang not available\n");
60         return FALSE;
61     }
62
63     pConvertINetMultiByteToUnicode = (void *)GetProcAddress(hMlang, "ConvertINetMultiByteToUnicode");
64     pConvertINetUnicodeToMultiByte = (void *)GetProcAddress(hMlang, "ConvertINetUnicodeToMultiByte");
65
66     pGetCPInfoExA = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetCPInfoExA");
67
68     return TRUE;
69 }
70
71 #define ok_w2(format, szString1, szString2) \
72 \
73     if (lstrcmpW((szString1), (szString2)) != 0) \
74     { \
75         CHAR string1[256], string2[256]; \
76         WideCharToMultiByte(CP_ACP, 0, (szString1), -1, string1, 256, NULL, NULL); \
77         WideCharToMultiByte(CP_ACP, 0, (szString2), -1, string2, 256, NULL, NULL); \
78         ok(0, (format), string1, string2); \
79     }
80
81 static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
82 {
83     /* these APIs are broken regarding constness of the input buffer */
84     char stringA[] = "Just a test string\0"; /* double 0 for CP_UNICODE tests */
85     WCHAR stringW[] = {'J','u','s','t',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
86     char bufA[256];
87     WCHAR bufW[256];
88     UINT lenA, lenW, expected_len;
89     HRESULT ret;
90
91     /* IMultiLanguage2_ConvertStringToUnicode tests */
92
93     memset(bufW, 'x', sizeof(bufW));
94     lenA = 0;
95     lenW = sizeof(bufW)/sizeof(bufW[0]);
96     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
97     ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
98     ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
99     ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
100
101     memset(bufW, 'x', sizeof(bufW));
102     lenA = -1;
103     lenW = sizeof(bufW)/sizeof(bufW[0]);
104     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
105     ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
106     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
107     ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
108     if (lenW < sizeof(bufW)/sizeof(bufW[0])) {
109        /* can only happen if the convert call fails */
110        ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
111        bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
112     }
113     ok(!lstrcmpW(bufW, stringW), "bufW/stringW mismatch\n");
114
115     memset(bufW, 'x', sizeof(bufW));
116     lenA = -1;
117     lenW = 5;
118     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
119     ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringToUnicode should fail: %08x\n", ret);
120     ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
121     /* still has to do partial conversion */
122     ok(!memcmp(bufW, stringW, 5 * sizeof(WCHAR)), "bufW/stringW mismatch\n");
123
124     memset(bufW, 'x', sizeof(bufW));
125     lenA = -1;
126     lenW = sizeof(bufW)/sizeof(bufW[0]);
127     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, CP_UNICODE, stringA, &lenA, bufW, &lenW);
128     ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
129     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
130     ok(lenW == lstrlenW(stringW)/(int)sizeof(WCHAR), "wrong lenW %u\n", lenW);
131     ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
132     bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
133     ok(!lstrcmpA((LPCSTR)bufW, stringA), "bufW/stringA mismatch\n");
134
135     memset(bufW, 'x', sizeof(bufW));
136     lenA = lstrlenA(stringA);
137     lenW = 0;
138     ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, NULL, &lenW);
139     ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
140     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
141     expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
142     ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
143
144     memset(bufW, 'x', sizeof(bufW));
145     lenA = lstrlenA(stringA);
146     lenW = sizeof(bufW)/sizeof(bufW[0]);
147     ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
148     ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
149     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
150     expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
151     ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
152
153     memset(bufW, 'x', sizeof(bufW));
154     lenA = lstrlenA(stringA);
155     lenW = 0;
156     ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, (INT *)&lenA, NULL, (INT *)&lenW);
157     ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
158     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
159     expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
160     ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
161
162     /* IMultiLanguage2_ConvertStringFromUnicode tests */
163
164     memset(bufA, 'x', sizeof(bufA));
165     lenW = 0;
166     lenA = sizeof(bufA);
167     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
168     ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
169     ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
170     ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
171
172     memset(bufA, 'x', sizeof(bufA));
173     lenW = -1;
174     lenA = sizeof(bufA);
175     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
176     ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
177     ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
178     ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
179     ok(bufA[lenA] != 0, "buf should not be 0 terminated\n");
180     bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
181     ok(!lstrcmpA(bufA, stringA), "bufA/stringA mismatch\n");
182
183     memset(bufA, 'x', sizeof(bufA));
184     lenW = -1;
185     lenA = 5;
186     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
187     ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringFromUnicode should fail: %08x\n", ret);
188     ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
189     /* still has to do partial conversion */
190     ok(!memcmp(bufA, stringA, 5), "bufW/stringW mismatch\n");
191
192     memset(bufA, 'x', sizeof(bufA));
193     lenW = -1;
194     lenA = sizeof(bufA);
195     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, CP_UNICODE, stringW, &lenW, bufA, &lenA);
196     ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
197     ok(lenA == lstrlenA(stringA) * (int)sizeof(WCHAR), "wrong lenA %u\n", lenA);
198     ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
199     ok(bufA[lenA] != 0 && bufA[lenA+1] != 0, "buf should not be 0 terminated\n");
200     bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
201     bufA[lenA+1] = 0; /* sizeof(WCHAR) */
202     ok(!lstrcmpW((LPCWSTR)bufA, stringW), "bufA/stringW mismatch\n");
203
204     memset(bufA, 'x', sizeof(bufA));
205     lenW = lstrlenW(stringW);
206     lenA = 0;
207     ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, NULL, &lenA);
208     ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
209     ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
210     expected_len = WideCharToMultiByte(1252, 0, stringW, lenW, NULL, 0, NULL, NULL);
211     ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);
212 }
213
214 static void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
215 {
216     ok(cpinfo1->dwFlags == cpinfo2->dwFlags, "dwFlags mismatch: %08x != %08x\n", cpinfo1->dwFlags, cpinfo2->dwFlags);
217     ok(cpinfo1->uiCodePage == cpinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", cpinfo1->uiCodePage, cpinfo2->uiCodePage);
218     ok(cpinfo1->uiFamilyCodePage == cpinfo2->uiFamilyCodePage, "uiFamilyCodePage mismatch: %u != %u\n", cpinfo1->uiFamilyCodePage, cpinfo2->uiFamilyCodePage);
219     ok(!lstrcmpW(cpinfo1->wszDescription, cpinfo2->wszDescription), "wszDescription mismatch\n");
220     ok(!lstrcmpW(cpinfo1->wszWebCharset, cpinfo2->wszWebCharset), "wszWebCharset mismatch\n");
221     ok(!lstrcmpW(cpinfo1->wszHeaderCharset, cpinfo2->wszHeaderCharset), "wszHeaderCharset mismatch\n");
222     ok(!lstrcmpW(cpinfo1->wszBodyCharset, cpinfo2->wszBodyCharset), "wszBodyCharset mismatch\n");
223     ok(!lstrcmpW(cpinfo1->wszFixedWidthFont, cpinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
224     ok(!lstrcmpW(cpinfo1->wszProportionalFont, cpinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
225     ok(cpinfo1->bGDICharset == cpinfo2->bGDICharset, "bGDICharset mismatch: %d != %d\n", cpinfo1->bGDICharset, cpinfo2->bGDICharset);
226 }
227
228 #ifdef DUMP_CP_INFO
229 static const char *dump_mime_flags(DWORD flags)
230 {
231     static char buf[1024];
232
233     buf[0] = 0;
234
235     if (flags & MIMECONTF_MAILNEWS) strcat(buf, " MIMECONTF_MAILNEWS");
236     if (flags & MIMECONTF_BROWSER) strcat(buf, " MIMECONTF_BROWSER");
237     if (flags & MIMECONTF_MINIMAL) strcat(buf, " MIMECONTF_MINIMAL");
238     if (flags & MIMECONTF_IMPORT) strcat(buf, " MIMECONTF_IMPORT");
239     if (flags & MIMECONTF_SAVABLE_MAILNEWS) strcat(buf, " MIMECONTF_SAVABLE_MAILNEWS");
240     if (flags & MIMECONTF_SAVABLE_BROWSER) strcat(buf, " MIMECONTF_SAVABLE_BROWSER");
241     if (flags & MIMECONTF_EXPORT) strcat(buf, " MIMECONTF_EXPORT");
242     if (flags & MIMECONTF_PRIVCONVERTER) strcat(buf, " MIMECONTF_PRIVCONVERTER");
243     if (flags & MIMECONTF_VALID) strcat(buf, " MIMECONTF_VALID");
244     if (flags & MIMECONTF_VALID_NLS) strcat(buf, " MIMECONTF_VALID_NLS");
245     if (flags & MIMECONTF_MIME_IE4) strcat(buf, " MIMECONTF_MIME_IE4");
246     if (flags & MIMECONTF_MIME_LATEST) strcat(buf, " MIMECONTF_MIME_LATEST");
247     if (flags & MIMECONTF_MIME_REGISTRY) strcat(buf, " MIMECONTF_MIME_REGISTRY");
248
249     return buf;
250 }
251 #endif
252
253 static HRESULT check_convertible(IMultiLanguage2 *iML2, UINT from, UINT to)
254 {
255     CHAR convert[MAX_PATH];
256     BYTE dest[MAX_PATH];
257     HRESULT hr;
258     UINT srcsz, destsz;
259
260     static WCHAR strW[] = {'a','b','c',0};
261
262     /* Check to see if the target codepage has these characters or not */
263     if (from != CP_UTF8)
264     {
265         BOOL fDefaultChar;
266         char ch[10];
267         int cb;
268         cb = WideCharToMultiByte( from, WC_NO_BEST_FIT_CHARS | WC_COMPOSITECHECK | WC_DEFAULTCHAR,
269                                   strW, 3, ch, sizeof(ch), NULL, &fDefaultChar);
270
271         if(cb == 0 || fDefaultChar)
272         {
273             trace("target codepage %i does not contain 'abc'\n",from);
274             return E_FAIL;
275         }
276     }
277
278     srcsz = lstrlenW(strW) + 1;
279     destsz = MAX_PATH;
280     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, from, strW,
281                                                   &srcsz, convert, &destsz);
282     if (hr != S_OK)
283         return S_FALSE;
284
285     srcsz = -1;
286     destsz = MAX_PATH;
287     hr = IMultiLanguage2_ConvertString(iML2, NULL, from, to, (BYTE *)convert,
288                                        &srcsz, dest, &destsz);
289     if (hr != S_OK)
290         return S_FALSE;
291
292     return S_OK;
293 }
294
295 static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
296 {
297     IEnumCodePage *iEnumCP = NULL;
298     MIMECPINFO *cpinfo;
299     MIMECPINFO cpinfo2;
300     HRESULT ret;
301     ULONG i, n;
302     UINT total;
303
304     total = 0;
305     ret = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &total);
306     ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfCodePageInfo: expected S_OK/!0, got %08x/%u\n", ret, total);
307
308     trace("total mlang supported codepages %u\n", total);
309
310     ret = IMultiLanguage2_EnumCodePages(iML2, flags, LANG_NEUTRAL, &iEnumCP);
311     ok(ret == S_OK && iEnumCP, "IMultiLanguage2_EnumCodePages: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumCP);
312
313     ret = IEnumCodePage_Reset(iEnumCP);
314     ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
315     n = 65536;
316     ret = IEnumCodePage_Next(iEnumCP, 0, NULL, &n);
317     if (ret == S_FALSE)
318         ok(n == 0 && ret == S_FALSE, "IEnumCodePage_Next: expected 0/S_FALSE, got %u/%08x\n", n, ret);
319     else if (ret == E_FAIL)
320         ok(n == 65536 && ret == E_FAIL, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
321     ret = IEnumCodePage_Next(iEnumCP, 0, NULL, NULL);
322     if (ret == S_FALSE)
323         ok(ret == S_FALSE, "IEnumCodePage_Next: expected S_FALSE, got %08x\n", ret);
324     else if (ret == E_FAIL)
325         ok(n == 65536 && ret == E_FAIL, "IEnumCodePage_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
326
327     cpinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*cpinfo) * total * 2);
328
329     n = total * 2;
330     ret = IEnumCodePage_Next(iEnumCP, 0, cpinfo, &n);
331     ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
332
333     n = total * 2;
334     ret = IEnumCodePage_Next(iEnumCP, n, cpinfo, &n);
335     ok(ret == S_OK && n != 0, "IEnumCodePage_Next: expected S_OK/!0, got %08x/%u\n", ret, n);
336
337     trace("flags %08x, enumerated codepages %u\n", flags, n);
338
339     if (!flags)
340     {
341         ok(n == total, "IEnumCodePage_Next: expected %u, got %u\n", total, n);
342
343         flags = MIMECONTF_MIME_LATEST;
344     }
345
346     total = n;
347
348     for (i = 0; i < n; i++)
349     {
350         CHARSETINFO csi;
351         MIMECSETINFO mcsi;
352         HRESULT convertible = S_OK;
353         static const WCHAR autoW[] = {'_','a','u','t','o',0};
354         static const WCHAR feffW[] = {'u','n','i','c','o','d','e','F','E','F','F',0};
355
356 #ifdef DUMP_CP_INFO
357         trace("MIMECPINFO #%u:\n"
358               "dwFlags %08x %s\n"
359               "uiCodePage %u\n"
360               "uiFamilyCodePage %u\n"
361               "wszDescription %s\n"
362               "wszWebCharset %s\n"
363               "wszHeaderCharset %s\n"
364               "wszBodyCharset %s\n"
365               "wszFixedWidthFont %s\n"
366               "wszProportionalFont %s\n"
367               "bGDICharset %d\n\n",
368               i,
369               cpinfo[i].dwFlags, dump_mime_flags(cpinfo[i].dwFlags),
370               cpinfo[i].uiCodePage,
371               cpinfo[i].uiFamilyCodePage,
372               wine_dbgstr_w(cpinfo[i].wszDescription),
373               wine_dbgstr_w(cpinfo[i].wszWebCharset),
374               wine_dbgstr_w(cpinfo[i].wszHeaderCharset),
375               wine_dbgstr_w(cpinfo[i].wszBodyCharset),
376               wine_dbgstr_w(cpinfo[i].wszFixedWidthFont),
377               wine_dbgstr_w(cpinfo[i].wszProportionalFont),
378               cpinfo[i].bGDICharset);
379 #endif
380         ok(cpinfo[i].dwFlags & flags, "enumerated flags %08x do not include requested %08x\n", cpinfo[i].dwFlags, flags);
381
382         if (TranslateCharsetInfo((DWORD *)(INT_PTR)cpinfo[i].uiFamilyCodePage, &csi, TCI_SRCCODEPAGE))
383             ok(cpinfo[i].bGDICharset == csi.ciCharset, "%d != %d\n", cpinfo[i].bGDICharset, csi.ciCharset);
384         else
385             trace("TranslateCharsetInfo failed for cp %u\n", cpinfo[i].uiFamilyCodePage);
386
387 #ifdef DUMP_CP_INFO
388         trace("%u: codepage %u family %u\n", i, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
389 #endif
390         /* Win95 does not support UTF-7 */
391         if (cpinfo[i].uiCodePage == CP_UTF7) continue;
392
393         /* support files for some codepages might be not installed, or
394          * the codepage is just an alias.
395          */
396         if (IsValidCodePage(cpinfo[i].uiCodePage))
397         {
398             ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UNICODE);
399             ok(ret == S_OK, "IMultiLanguage2_IsConvertible(%u -> CP_UNICODE) = %08x\n", cpinfo[i].uiCodePage, ret);
400             ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, cpinfo[i].uiCodePage);
401             ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
402
403             convertible = check_convertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
404             if (convertible != E_FAIL)
405             {
406                 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
407                 ok(ret == convertible, "IMultiLanguage2_IsConvertible(%u -> CP_UTF8) = %08x\n", cpinfo[i].uiCodePage, ret);
408                 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, cpinfo[i].uiCodePage);
409                 ok(ret == convertible, "IMultiLanguage2_IsConvertible(CP_UTF8 -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
410             }
411         }
412         else
413             trace("IsValidCodePage failed for cp %u\n", cpinfo[i].uiCodePage);
414
415     if (memcmp(cpinfo[i].wszWebCharset,feffW,sizeof(WCHAR)*11)==0)
416         skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
417     else
418     {
419         ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszWebCharset, &mcsi);
420         /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
421         if (memcmp(cpinfo[i].wszWebCharset, autoW, 5 * sizeof(WCHAR)))
422         {
423             ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
424 #ifdef DUMP_CP_INFO
425             trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszWebCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
426 #endif
427             ok(!lstrcmpiW(cpinfo[i].wszWebCharset, mcsi.wszCharset),
428 #ifdef DUMP_CP_INFO
429                     "%s != %s\n",
430             wine_dbgstr_w(cpinfo[i].wszWebCharset), wine_dbgstr_w(mcsi.wszCharset));
431 #else
432                     "wszWebCharset mismatch\n");
433 #endif
434
435         if (0)
436         {
437             /* native mlang returns completely messed up encodings in some cases */
438             ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
439             "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
440             ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
441             "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
442             }
443         }
444     }
445
446     if (memcmp(cpinfo[i].wszHeaderCharset,feffW,sizeof(WCHAR)*11)==0)
447         skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
448     else
449     {
450         ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszHeaderCharset, &mcsi);
451         /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
452         if (memcmp(cpinfo[i].wszHeaderCharset, autoW, 5 * sizeof(WCHAR)))
453         {
454             ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
455 #ifdef DUMP_CP_INFO
456             trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszHeaderCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
457 #endif
458             ok(!lstrcmpiW(cpinfo[i].wszHeaderCharset, mcsi.wszCharset),
459 #ifdef DUMP_CP_INFO
460                     "%s != %s\n",
461             wine_dbgstr_w(cpinfo[i].wszHeaderCharset), wine_dbgstr_w(mcsi.wszCharset));
462 #else
463                     "wszHeaderCharset mismatch\n");
464 #endif
465
466         if (0)
467         {
468             /* native mlang returns completely messed up encodings in some cases */
469             ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
470             "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
471             ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
472             "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
473         }
474         }
475     }
476
477     if (memcmp(cpinfo[i].wszBodyCharset,feffW,sizeof(WCHAR)*11)==0)
478         skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
479     else
480     {
481         ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszBodyCharset, &mcsi);
482         /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
483         if (memcmp(cpinfo[i].wszBodyCharset, autoW, 5 * sizeof(WCHAR)))
484         {
485             ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
486 #ifdef DUMP_CP_INFO
487             trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszBodyCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
488 #endif
489             ok(!lstrcmpiW(cpinfo[i].wszBodyCharset, mcsi.wszCharset),
490 #ifdef DUMP_CP_INFO
491                     "%s != %s\n",
492             wine_dbgstr_w(cpinfo[i].wszBodyCharset), wine_dbgstr_w(mcsi.wszCharset));
493 #else
494                     "wszBodyCharset mismatch\n");
495 #endif
496
497         if (0)
498         {
499             /* native mlang returns completely messed up encodings in some cases */
500             ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
501             "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
502             ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
503             "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
504         }
505         }
506     }
507     }
508
509     /* now IEnumCodePage_Next should fail, since pointer is at the end */
510     n = 1;
511     ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
512     ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
513
514     ret = IEnumCodePage_Reset(iEnumCP);
515     ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
516     n = 0;
517     ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
518     ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
519     cpinfo_cmp(&cpinfo[0], &cpinfo2);
520
521     if (0)
522     {
523     /* Due to a bug in MS' implementation of IEnumCodePage_Skip
524      * it's not used here.
525      */
526     ret = IEnumCodePage_Skip(iEnumCP, 1);
527     ok(ret == S_OK, "IEnumCodePage_Skip: expected S_OK, got %08x\n", ret);
528     }
529     for (i = 0; i < total - 1; i++)
530     {
531         n = 0;
532         ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
533         ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
534         cpinfo_cmp(&cpinfo[i + 1], &cpinfo2);
535     }
536
537     HeapFree(GetProcessHeap(), 0, cpinfo);
538     IEnumCodePage_Release(iEnumCP);
539 }
540
541 static void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
542 {
543     ok(sinfo1->ScriptId == sinfo2->ScriptId, "ScriptId mismatch: %d != %d\n", sinfo1->ScriptId, sinfo2->ScriptId);
544     ok(sinfo1->uiCodePage == sinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", sinfo1->uiCodePage, sinfo2->uiCodePage);
545     ok(!lstrcmpW(sinfo1->wszDescription, sinfo2->wszDescription), "wszDescription mismatch\n");
546     ok(!lstrcmpW(sinfo1->wszFixedWidthFont, sinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
547     ok(!lstrcmpW(sinfo1->wszProportionalFont, sinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
548 }
549
550 static void test_EnumScripts(IMultiLanguage2 *iML2, DWORD flags)
551 {
552     IEnumScript *iEnumScript = NULL;
553     SCRIPTINFO *sinfo;
554     SCRIPTINFO sinfo2;
555     HRESULT ret;
556     ULONG i, n;
557     UINT total;
558
559     total = 0;
560     ret = IMultiLanguage2_GetNumberOfScripts(iML2, &total);
561     ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfScripts: expected S_OK/!0, got %08x/%u\n", ret, total);
562
563     trace("total mlang supported scripts %u\n", total);
564
565     ret = IMultiLanguage2_EnumScripts(iML2, flags, LANG_NEUTRAL, &iEnumScript);
566     ok(ret == S_OK && iEnumScript, "IMultiLanguage2_EnumScripts: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumScript);
567
568     ret = IEnumScript_Reset(iEnumScript);
569     ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
570     n = 65536;
571     ret = IEnumScript_Next(iEnumScript, 0, NULL, &n);
572     ok(n == 65536 && ret == E_FAIL, "IEnumScript_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
573     ret = IEnumScript_Next(iEnumScript, 0, NULL, NULL);
574     ok(ret == E_FAIL, "IEnumScript_Next: expected E_FAIL, got %08x\n", ret);
575
576     sinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*sinfo) * total * 2);
577
578     n = total * 2;
579     ret = IEnumScript_Next(iEnumScript, 0, sinfo, &n);
580     ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
581
582     n = total * 2;
583     ret = IEnumScript_Next(iEnumScript, n, sinfo, &n);
584     ok(ret == S_OK && n != 0, "IEnumScript_Next: expected S_OK, got %08x/%u\n", ret, n);
585
586     trace("flags %08x, enumerated scripts %u\n", flags, n);
587
588     if (!flags)
589     {
590         ok(n == total, "IEnumScript_Next: expected %u, got %u\n", total, n);
591         flags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
592     }
593
594     total = n;
595
596     for (i = 0; pGetCPInfoExA && i < n; i++)
597     {
598 #ifdef DUMP_SCRIPT_INFO
599         trace("SCRIPTINFO #%u:\n"
600               "ScriptId %08x\n"
601               "uiCodePage %u\n"
602               "wszDescription %s\n"
603               "wszFixedWidthFont %s\n"
604               "wszProportionalFont %s\n\n",
605               i,
606               sinfo[i].ScriptId,
607               sinfo[i].uiCodePage,
608               wine_dbgstr_w(sinfo[i].wszDescription),
609               wine_dbgstr_w(sinfo[i].wszFixedWidthFont),
610               wine_dbgstr_w(sinfo[i].wszProportionalFont));
611         trace("%u codepage %u\n", i, sinfo[i].uiCodePage);
612 #endif
613     }
614
615     /* now IEnumScript_Next should fail, since pointer is at the end */
616     n = 1;
617     ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
618     ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
619
620     ret = IEnumScript_Reset(iEnumScript);
621     ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
622     n = 0;
623     ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
624     ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
625     scriptinfo_cmp(&sinfo[0], &sinfo2);
626
627     if (0)
628     {
629     /* Due to a bug in MS' implementation of IEnumScript_Skip
630      * it's not used here.
631      */
632     ret = IEnumScript_Skip(iEnumScript, 1);
633     ok(ret == S_OK, "IEnumScript_Skip: expected S_OK, got %08x\n", ret);
634     }
635     for (i = 0; i < total - 1; i++)
636     {
637         n = 0;
638         ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
639         ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
640         scriptinfo_cmp(&sinfo[i + 1], &sinfo2);
641     }
642
643     HeapFree(GetProcessHeap(), 0, sinfo);
644     IEnumScript_Release(iEnumScript);
645 }
646
647 static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
648 {
649     DWORD dwCodePages, dwManyCodePages;
650     DWORD dwCmpCodePages;
651     UINT CodePage;
652     static const WCHAR str[3] = { 'd', 0x0436, 0xff90 };
653     LONG processed;
654     HRESULT ret;
655
656     dwCodePages = ~0u;
657     ret = IMLangFontLink_CodePageToCodePages(iMLFL, -1, &dwCodePages);
658     ok(ret == E_FAIL, "IMLangFontLink_CodePageToCodePages should fail: %x\n", ret);
659     ok(dwCodePages == 0, "expected 0, got %u\n", dwCodePages);
660
661     dwCodePages = 0;
662     ret = IMLangFontLink_CodePageToCodePages(iMLFL, 932, &dwCodePages);
663     ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
664     ok(dwCodePages == FS_JISJAPAN, "expected FS_JISJAPAN, got %08x\n", dwCodePages);
665     CodePage = 0;
666     ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwCodePages, 1035, &CodePage);
667     ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
668     ok(CodePage == 932, "Incorrect CodePage Returned (%i)\n",CodePage);
669
670     dwManyCodePages = 0;
671     ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1252, &dwManyCodePages);
672     ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
673     ok(dwManyCodePages == FS_LATIN1, "expected FS_LATIN1, got %08x\n", dwManyCodePages);
674     dwCodePages = 0;
675     ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1256, &dwCodePages);
676     ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
677     ok(dwCodePages == FS_ARABIC, "expected FS_ARABIC, got %08x\n", dwCodePages);
678     dwManyCodePages |= dwCodePages;
679     ret = IMLangFontLink_CodePageToCodePages(iMLFL, 874, &dwCodePages);
680     ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
681     ok(dwCodePages == FS_THAI, "expected FS_THAI, got %08x\n", dwCodePages);
682     dwManyCodePages |= dwCodePages;
683
684     ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 1256, &CodePage);
685     ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
686     ok(CodePage == 1256, "Incorrect CodePage Returned (%i)\n",CodePage);
687
688     ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 936, &CodePage);
689     ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
690     ok(CodePage == 1252, "Incorrect CodePage Returned (%i)\n",CodePage);
691
692     /* Tests for GetCharCodePages */
693
694     /* Latin 1 */
695     dwCmpCodePages = FS_LATIN1 | FS_LATIN2 | FS_CYRILLIC | FS_GREEK | FS_TURKISH
696         | FS_HEBREW | FS_ARABIC | FS_BALTIC | FS_VIETNAMESE | FS_THAI
697         | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG | FS_CHINESETRAD;
698     ret = IMLangFontLink_GetCharCodePages(iMLFL, 'd', &dwCodePages);
699     ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
700     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
701
702     dwCodePages = 0;
703     processed = 0;
704     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[0], 1, 0, &dwCodePages, &processed);
705     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
706     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
707     ok(processed == 1, "expected 1, got %d\n", processed);
708
709     /* Cyrillic */
710     dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
711     ret = IMLangFontLink_GetCharCodePages(iMLFL, 0x0436, &dwCodePages);
712     ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
713     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
714
715     dwCodePages = 0;
716     processed = 0;
717     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[1], 1, 0, &dwCodePages, &processed);
718     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
719     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
720     ok(processed == 1, "expected 1, got %d\n", processed);
721
722     /* Japanese */
723     dwCmpCodePages =  FS_JISJAPAN;
724     ret = IMLangFontLink_GetCharCodePages(iMLFL, 0xff90, &dwCodePages);
725     ok(ret == S_OK, "IMLangFontLink_GetCharCodePages error %x\n", ret);
726     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
727
728     dwCodePages = 0;
729     processed = 0;
730     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
731     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
732     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
733     ok(processed == 1, "expected 1, got %d\n", processed);
734
735     dwCmpCodePages = FS_CYRILLIC | FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG;
736     dwCodePages = 0;
737     processed = 0;
738     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 2, 0, &dwCodePages, &processed);
739     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
740     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
741     ok(processed == 2, "expected 2, got %d\n", processed);
742
743     dwCmpCodePages = FS_JISJAPAN;
744     dwCodePages = 0;
745     processed = 0;
746     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 3, 0, &dwCodePages, &processed);
747     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
748     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
749     ok(processed == 3, "expected 3, got %d\n", processed);
750
751     dwCodePages = 0xffff;
752     processed = -1;
753     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, &dwCodePages, &processed);
754     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
755     ok(dwCodePages == dwCmpCodePages, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
756     ok(processed == 1, "expected 0, got %d\n", processed);
757
758     ret = IMLangFontLink_GetStrCodePages(iMLFL, &str[2], 1, 0, NULL, NULL);
759     ok(ret == S_OK, "IMLangFontLink_GetStrCodePages error %x\n", ret);
760
761     dwCodePages = 0xffff;
762     processed = -1;
763     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, -1, 0, &dwCodePages, &processed);
764     ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
765     ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
766     ok(processed == 0, "expected 0, got %d\n", processed);
767
768     dwCodePages = 0xffff;
769     processed = -1;
770     ret = IMLangFontLink_GetStrCodePages(iMLFL, NULL, 1, 0, &dwCodePages, &processed);
771     ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
772     ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
773     ok(processed == 0, "expected 0, got %d\n", processed);
774
775     dwCodePages = 0xffff;
776     processed = -1;
777     ret = IMLangFontLink_GetStrCodePages(iMLFL, str, 0, 0, &dwCodePages, &processed);
778     ok(ret == E_INVALIDARG, "IMLangFontLink_GetStrCodePages should fail: %x\n", ret);
779     ok(dwCodePages == 0, "expected %x, got %x\n", dwCmpCodePages, dwCodePages);
780     ok(processed == 0, "expected 0, got %d\n", processed);
781 }
782
783 /* copied from libs/wine/string.c */
784 static WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
785 {
786     while (*str)
787     {
788         const WCHAR *p1 = str, *p2 = sub;
789         while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
790         if (!*p2) return (WCHAR *)str;
791         str++;
792     }
793     return NULL;
794 }
795
796 static void test_rfc1766(IMultiLanguage2 *iML2)
797 {
798     IEnumRfc1766 *pEnumRfc1766;
799     RFC1766INFO info;
800     ULONG n;
801     HRESULT ret;
802     BSTR rfcstr;
803
804     ret = IMultiLanguage2_EnumRfc1766(iML2, LANG_NEUTRAL, &pEnumRfc1766);
805     ok(ret == S_OK, "IMultiLanguage2_EnumRfc1766 error %08x\n", ret);
806
807     while (1)
808     {
809         ret = IEnumRfc1766_Next(pEnumRfc1766, 1, &info, &n);
810         if (ret != S_OK) break;
811
812 #ifdef DUMP_CP_INFO
813         trace("lcid %04x rfc_name %s locale_name %s\n",
814               info.lcid, wine_dbgstr_w(info.wszRfc1766), wine_dbgstr_w(info.wszLocaleName));
815 #endif
816
817         ok(n == 1, "couldn't fetch 1 RFC1766INFO structure\n");
818
819         /* verify the Rfc1766 value */
820         ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, info.lcid, &rfcstr);
821         ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
822
823         /* not an exact 1:1 correspondence between lcid and rfc1766 in the
824          * mlang database, e.g., nb-no -> 1044 -> no */
825         ok(strstrW(info.wszRfc1766, rfcstr) != NULL,
826            "Expected matching locale names\n");
827
828         SysFreeString(rfcstr);
829     }
830     IEnumRfc1766_Release(pEnumRfc1766);
831 }
832
833 static void test_GetLcidFromRfc1766(IMultiLanguage2 *iML2)
834 {
835     LCID lcid;
836     HRESULT ret;
837
838     static WCHAR e[] = { 'e',0 };
839     static WCHAR en[] = { 'e','n',0 };
840     static WCHAR empty[] = { 0 };
841     static WCHAR dash[] = { '-',0 };
842     static WCHAR e_dash[] = { 'e','-',0 };
843     static WCHAR en_gb[] = { 'e','n','-','g','b',0 };
844     static WCHAR en_us[] = { 'e','n','-','u','s',0 };
845     static WCHAR en_them[] = { 'e','n','-','t','h','e','m',0 };
846     static WCHAR english[] = { 'e','n','g','l','i','s','h',0 };
847
848     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, NULL, en);
849     ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
850
851     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, NULL);
852     ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
853
854     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, e);
855     ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);
856
857     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, empty);
858     ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);
859
860     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, dash);
861     ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);
862
863     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, e_dash);
864     ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);
865
866     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_them);
867     ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
868     if (ret == S_FALSE)
869     {
870         BSTR rfcstr;
871         static WCHAR en[] = {'e','n',0};
872
873         ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
874         ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
875         ok_w2("Expected \"%s\",  got \"%s\"n", en, rfcstr);
876     }
877
878     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, english);
879     ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
880     if (ret == S_FALSE)
881     {
882         BSTR rfcstr;
883         static WCHAR en[] = {'e','n',0};
884
885         ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
886         ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
887         ok_w2("Expected \"%s\",  got \"%s\"n", en, rfcstr);
888     }
889
890     lcid = 0;
891
892     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en);
893     ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
894     ok(lcid == 9, "got wrong lcid: %04x\n", lcid);
895
896     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_gb);
897     ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
898     ok(lcid == 0x809, "got wrong lcid: %04x\n", lcid);
899
900     ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_us);
901     ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
902     ok(lcid == 0x409, "got wrong lcid: %04x\n", lcid);
903 }
904
905 static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
906 {
907     HRESULT hr;
908     BSTR rfcstr;
909     LCID lcid;
910
911     static WCHAR kok[] = {'k','o','k',0};
912
913     hr = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, kok);
914     /*
915      * S_FALSE happens when 'kok' instead matches to a different Rfc1766 name
916      * for example 'ko' so it is not a failure but does not give us what 
917      * we are looking for
918      */
919     if (hr != S_FALSE)
920     {
921         ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
922
923         hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
924         ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
925         ok_w2("Expected \"%s\",  got \"%s\"n", kok, rfcstr);
926         SysFreeString(rfcstr);
927     }
928 }
929
930 static void test_IMultiLanguage2_ConvertStringFromUnicode(IMultiLanguage2 *iML2)
931 {
932     CHAR dest[MAX_PATH];
933     CHAR invariate[MAX_PATH];
934     UINT srcsz, destsz;
935     HRESULT hr;
936
937     static WCHAR src[] = {'a','b','c',0};
938
939     memset(invariate, 'x', sizeof(invariate));
940
941     /* pSrcStr NULL */
942     memset(dest, 'x', sizeof(dest));
943     srcsz = lstrlenW(src) + 1;
944     destsz = sizeof(dest);
945     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
946                                                   &srcsz, dest, &destsz);
947     ok(hr == S_OK || hr == E_FAIL,"expected S_OK or E_FAIL, got %08x\n",hr);
948     if (hr == S_OK)
949     {
950         ok(srcsz == lstrlenW(src) + 1,
951            "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
952     }
953     else if (hr == E_FAIL)
954     {
955         ok(srcsz == 0,
956            "Expected %u, got %u\n", 0, srcsz);
957     }
958
959     ok(!memcmp(dest, invariate, sizeof(dest)),
960        "Expected dest to be unchanged, got %s\n", dest);
961     ok(destsz == 0, "Expected 0, got %u\n", destsz);
962
963     /* pcSrcSize NULL */
964     memset(dest, 'x', sizeof(dest));
965     destsz = sizeof(dest);
966     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
967                                                   NULL, dest, &destsz);
968     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
969     ok(!strncmp(dest, "abc", 3),
970        "Expected first three chars to be \"abc\"\n");
971     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
972        "Expected rest of dest to be unchanged, got %s\n", dest);
973     ok(destsz == lstrlenW(src),
974        "Expected %u, got %u\n", lstrlenW(src), destsz);
975
976     /* both pSrcStr and pcSrcSize NULL */
977     memset(dest, 'x', sizeof(dest));
978     destsz = sizeof(dest);
979     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
980                                                   NULL, dest, &destsz);
981     ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
982     ok(!memcmp(dest, invariate, sizeof(dest)),
983        "Expected dest to be unchanged, got %s\n", dest);
984     ok(destsz == 0, "Expected 0, got %u\n", destsz);
985
986     /* pDstStr NULL */
987     memset(dest, 'x', sizeof(dest));
988     srcsz = lstrlenW(src) + 1;
989     destsz = sizeof(dest);
990     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
991                                                   &srcsz, NULL, &destsz);
992     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
993     ok(srcsz == lstrlenW(src) + 1,
994        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
995     ok(destsz == lstrlenW(src) + 1,
996        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
997
998     /* pcDstSize NULL */
999     memset(dest, 'x', sizeof(dest));
1000     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1001                                                   &srcsz, dest, NULL);
1002     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1003     ok(srcsz == lstrlenW(src) + 1,
1004        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1005     ok(!memcmp(dest, invariate, sizeof(dest)),
1006        "Expected dest to be unchanged, got %s\n", dest);
1007
1008     /* pcSrcSize is 0 */
1009     memset(dest, 'x', sizeof(dest));
1010     srcsz = 0;
1011     destsz = sizeof(dest);
1012     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1013                                                   &srcsz, dest, &destsz);
1014     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1015     ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1016     ok(!memcmp(dest, invariate, sizeof(dest)),
1017        "Expected dest to be unchanged, got %s\n", dest);
1018     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1019
1020     /* pcSrcSize does not include NULL terminator */
1021     memset(dest, 'x', sizeof(dest));
1022     srcsz = lstrlenW(src);
1023     destsz = sizeof(dest);
1024     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1025                                                   &srcsz, dest, &destsz);
1026     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1027     ok(srcsz == lstrlenW(src),
1028        "Expected %u, got %u\n", lstrlenW(src), srcsz);
1029     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1030     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1031        "Expected rest of dest to be unchanged, got %s\n", dest);
1032     ok(destsz == lstrlenW(src),
1033        "Expected %u, got %u\n", lstrlenW(src), destsz);
1034
1035     /* pcSrcSize includes NULL terminator */
1036     memset(dest, 'x', sizeof(dest));
1037     srcsz = lstrlenW(src) + 1;
1038     destsz = sizeof(dest);
1039     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1040                                                   &srcsz, dest, &destsz);
1041     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1042     ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1043     ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1044     ok(destsz == lstrlenW(src) + 1,
1045        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1046
1047     /* pcSrcSize is -1 */
1048     memset(dest, 'x', sizeof(dest));
1049     srcsz = -1;
1050     destsz = sizeof(dest);
1051     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1052                                                   &srcsz, dest, &destsz);
1053     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1054     ok(srcsz == lstrlenW(src),
1055        "Expected %u, got %u\n", lstrlenW(src), srcsz);
1056     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1057     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1058        "Expected rest of dest to be unchanged, got %s\n", dest);
1059     ok(destsz == lstrlenW(src),
1060        "Expected %u, got %u\n", lstrlenW(src), destsz);
1061
1062     /* pcDstSize is 0 */
1063     memset(dest, 'x', sizeof(dest));
1064     srcsz = lstrlenW(src) + 1;
1065     destsz = 0;
1066     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1067                                                   &srcsz, dest, &destsz);
1068     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1069     ok(srcsz == lstrlenW(src) + 1,
1070        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1071     ok(!memcmp(dest, invariate, sizeof(dest)),
1072        "Expected dest to be unchanged, got %s\n", dest);
1073     ok(destsz == lstrlenW(src) + 1,
1074        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1075
1076     /* pcDstSize is not large enough */
1077     memset(dest, 'x', sizeof(dest));
1078     srcsz = lstrlenW(src) + 1;
1079     destsz = lstrlenW(src);
1080     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1081                                                   &srcsz, dest, &destsz);
1082     ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1083     ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1084     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1085     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1086        "Expected rest of dest to be unchanged, got %s\n", dest);
1087     ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1088
1089     /* pcDstSize (bytes) does not leave room for NULL terminator */
1090     memset(dest, 'x', sizeof(dest));
1091     srcsz = lstrlenW(src) + 1;
1092     destsz = lstrlenW(src) * sizeof(WCHAR);
1093     hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
1094                                                   &srcsz, dest, &destsz);
1095     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1096     ok(srcsz == lstrlenW(src) + 1,
1097        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1098     ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1099     ok(destsz == lstrlenW(src) + 1,
1100        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1101 }
1102
1103 static void test_ConvertINetUnicodeToMultiByte(void)
1104 {
1105     CHAR dest[MAX_PATH];
1106     CHAR invariate[MAX_PATH];
1107     INT srcsz, destsz;
1108     HRESULT hr;
1109
1110     static WCHAR src[] = {'a','b','c',0};
1111
1112     memset(invariate, 'x', sizeof(invariate));
1113
1114     /* lpSrcStr NULL */
1115     memset(dest, 'x', sizeof(dest));
1116     srcsz = lstrlenW(src) + 1;
1117     destsz = sizeof(dest);
1118     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, &srcsz, dest, &destsz);
1119     ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1120     if (hr == S_OK)
1121         ok(srcsz == lstrlenW(src) + 1,
1122            "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1123     else if (hr == E_FAIL)
1124         ok(srcsz == 0,
1125            "Expected %u, got %u\n", 0, srcsz);
1126     ok(!memcmp(dest, invariate, sizeof(dest)),
1127        "Expected dest to be unchanged, got %s\n", dest);
1128     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1129
1130     /* lpnWideCharCount NULL */
1131     memset(dest, 'x', sizeof(dest));
1132     destsz = sizeof(dest);
1133     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, NULL, dest, &destsz);
1134     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1135     ok(!strncmp(dest, "abc", 3),
1136        "Expected first three chars to be \"abc\"\n");
1137     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1138        "Expected rest of dest to be unchanged, got %s\n", dest);
1139     ok(destsz == lstrlenW(src),
1140        "Expected %u, got %u\n", lstrlenW(src), destsz);
1141
1142     /* both lpSrcStr and lpnWideCharCount NULL */
1143     memset(dest, 'x', sizeof(dest));
1144     destsz = sizeof(dest);
1145     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, NULL, dest, &destsz);
1146     ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1147     ok(!memcmp(dest, invariate, sizeof(dest)),
1148        "Expected dest to be unchanged, got %s\n", dest);
1149     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1150
1151     /* lpDstStr NULL */
1152     memset(dest, 'x', sizeof(dest));
1153     srcsz = lstrlenW(src) + 1;
1154     destsz = sizeof(dest);
1155     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, NULL, &destsz);
1156     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1157     ok(srcsz == lstrlenW(src) + 1,
1158        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1159     ok(destsz == lstrlenW(src) + 1,
1160        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1161
1162     /* lpnMultiCharCount NULL */
1163     memset(dest, 'x', sizeof(dest));
1164     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, NULL);
1165     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1166     ok(srcsz == lstrlenW(src) + 1,
1167        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1168     ok(!memcmp(dest, invariate, sizeof(dest)),
1169        "Expected dest to be unchanged, got %s\n", dest);
1170
1171     /* lpnWideCharCount is 0 */
1172     memset(dest, 'x', sizeof(dest));
1173     srcsz = 0;
1174     destsz = sizeof(dest);
1175     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1176     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1177     ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1178     ok(!memcmp(dest, invariate, sizeof(dest)),
1179        "Expected dest to be unchanged, got %s\n", dest);
1180     ok(destsz == 0, "Expected 0, got %u\n", destsz);
1181
1182     /* lpnWideCharCount does not include NULL terminator */
1183     memset(dest, 'x', sizeof(dest));
1184     srcsz = lstrlenW(src);
1185     destsz = sizeof(dest);
1186     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1187     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1188     ok(srcsz == lstrlenW(src),
1189        "Expected %u, got %u\n", lstrlenW(src), srcsz);
1190     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1191     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1192        "Expected rest of dest to be unchanged, got %s\n", dest);
1193     ok(destsz == lstrlenW(src),
1194        "Expected %u, got %u\n", lstrlenW(src), destsz);
1195
1196     /* lpnWideCharCount includes NULL terminator */
1197     memset(dest, 'x', sizeof(dest));
1198     srcsz = lstrlenW(src) + 1;
1199     destsz = sizeof(dest);
1200     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1201     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1202     ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1203     ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1204     ok(destsz == lstrlenW(src) + 1,
1205        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1206
1207     /* lpnWideCharCount is -1 */
1208     memset(dest, 'x', sizeof(dest));
1209     srcsz = -1;
1210     destsz = sizeof(dest);
1211     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1212     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1213     ok(srcsz == lstrlenW(src),
1214        "Expected %u, got %u\n", lstrlenW(src), srcsz);
1215     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1216     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1217        "Expected rest of dest to be unchanged, got %s\n", dest);
1218     ok(destsz == lstrlenW(src),
1219        "Expected %u, got %u\n", lstrlenW(src), destsz);
1220
1221     /* lpnMultiCharCount is 0 */
1222     memset(dest, 'x', sizeof(dest));
1223     srcsz = lstrlenW(src) + 1;
1224     destsz = 0;
1225     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1226     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1227     ok(srcsz == lstrlenW(src) + 1,
1228        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1229     ok(!memcmp(dest, invariate, sizeof(dest)),
1230        "Expected dest to be unchanged, got %s\n", dest);
1231     ok(destsz == lstrlenW(src) + 1,
1232        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1233
1234     /* lpnMultiCharCount is not large enough */
1235     memset(dest, 'x', sizeof(dest));
1236     srcsz = lstrlenW(src) + 1;
1237     destsz = lstrlenW(src);
1238     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1239     ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1240     ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1241     ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1242     ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1243        "Expected rest of dest to be unchanged, got %s\n", dest);
1244     ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1245
1246     /* lpnMultiCharCount (bytes) does not leave room for NULL terminator */
1247     memset(dest, 'x', sizeof(dest));
1248     srcsz = lstrlenW(src) + 1;
1249     destsz = lstrlenW(src) * sizeof(WCHAR);
1250     hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1251     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1252     ok(srcsz == lstrlenW(src) + 1,
1253        "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1254     ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1255     ok(destsz == lstrlenW(src) + 1,
1256        "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1257 }
1258
1259 static void test_JapaneseConversion(void)
1260 {
1261     /* Data */
1262     static WCHAR unc_jp[9][12] = {
1263   {9,0x31,0x20,0x3042,0x3044,0x3046,0x3048,0x304a,0x000d,0x000a},
1264   {9,0x31,0x20,0x30a2,0x30a4,0x30a6,0x30a8,0x30aa,0x000d,0x000a},
1265   {9,0x31,0x20,0xff71,0xff72,0xff73,0xff74,0xff75,0x000d,0x000a},
1266   {9,0x31,0x20,0x3041,0x3043,0x3045,0x3047,0x3049,0x000d,0x000a},
1267   {9,0x31,0x20,0x30a1,0x30a3,0x30a5,0x30a7,0x30a9,0x000d,0x000a},
1268   {9,0x31,0x20,0xff67,0xff68,0xff69,0xff6a,0xff6b,0x000d,0x000a},
1269   {9,0x31,0x20,0x300c,0x65e5,0x672c,0x8a9e,0x300d,0x000d,0x000a},
1270   {7,0x31,0x20,0x25c7,0x25c7,0x3012,0x000d,0x000a},
1271   {11,0x31,0x20,0x203b,0x3010,0x0074,0x0065,0x0073,0x0074,0x3011,0x000d,0x000a}
1272     };
1273     static CHAR jis_jp[9][27] = {
1274   {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x22,0x24,0x24,0x24,0x26,0x24,0x28,
1275       0x24,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1276   {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1277       0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1278   {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,
1279       0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1280   {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x21,0x24,0x23,0x24,0x25,0x24,0x27,
1281       0x24,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1282   {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1283       0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1284   {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,
1285       0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1286   {20,0x31,0x20,0x1b,0x24,0x42,0x21,0x56,0x46,0x7c,0x4b,0x5c,0x38,0x6c,
1287       0x21,0x57,0x1b,0x28,0x42,0x0d,0x0a},
1288   {16,0x31,0x20,0x1b,0x24,0x42,0x21,0x7e,0x21,0x7e,0x22,0x29,0x1b,0x28,
1289       0x42,0x0d,0x0a},
1290   {26,0x31,0x20,0x1b,0x24,0x42,0x22,0x28,0x21,0x5a,0x1b,0x28,0x42,0x74,
1291       0x65,0x73,0x74,0x1b,0x24,0x42,0x21,0x5b,0x1b,0x28,0x42,0x0d,0x0a}
1292     };
1293     static CHAR sjis_jp[9][15] = {
1294   {14,0x31,0x20,0x82,0xa0,0x82,0xa2,0x82,0xa4,0x82,0xa6,0x82,0xa8,0x0d,0x0a},
1295   {14,0x31,0x20,0x83,0x41,0x83,0x43,0x83,0x45,0x83,0x47,0x83,0x49,0x0d,0x0a},
1296   {9,0x31,0x20,0xb1,0xb2,0xb3,0xb4,0xb5,0x0d,0x0a},
1297   {14,0x31,0x20,0x82,0x9f,0x82,0xa1,0x82,0xa3,0x82,0xa5,0x82,0xa7,0x0d,0x0a},
1298   {14,0x31,0x20,0x83,0x40,0x83,0x42,0x83,0x44,0x83,0x46,0x83,0x48,0x0d,0x0a},
1299   {9,0x31,0x20,0xa7,0xa8,0xa9,0xaa,0xab,0x0d,0x0a},
1300   {14,0x31,0x20,0x81,0x75,0x93,0xfa,0x96,0x7b,0x8c,0xea,0x81,0x76,0x0d,0x0a},
1301   {10,0x31,0x20,0x81,0x9e,0x81,0x9e,0x81,0xa7,0x0d,0x0a},
1302   {14,0x31,0x20,0x81,0xa6,0x81,0x79,0x74,0x65,0x73,0x74,0x81,0x7a,0x0d,0x0a}
1303     };
1304     static CHAR euc_jp[9][15] = {
1305   {14,0x31,0x20,0xa4,0xa2,0xa4,0xa4,0xa4,0xa6,0xa4,0xa8,0xa4,0xaa,0x0d,0x0a},
1306   {14,0x31,0x20,0xa5,0xa2,0xa5,0xa4,0xa5,0xa6,0xa5,0xa8,0xa5,0xaa,0x0d,0x0a},
1307   {14,0x31,0x20,0x8e,0xb1,0x8e,0xb2,0x8e,0xb3,0x8e,0xb4,0x8e,0xb5,0x0d,0x0a},
1308   {14,0x31,0x20,0xa4,0xa1,0xa4,0xa3,0xa4,0xa5,0xa4,0xa7,0xa4,0xa9,0x0d,0x0a},
1309   {14,0x31,0x20,0xa5,0xa1,0xa5,0xa3,0xa5,0xa5,0xa5,0xa7,0xa5,0xa9,0x0d,0x0a},
1310   {14,0x31,0x20,0x8e,0xa7,0x8e,0xa8,0x8e,0xa9,0x8e,0xaa,0x8e,0xab,0x0d,0x0a},
1311   {14,0x31,0x20,0xa1,0xd6,0xc6,0xfc,0xcb,0xdc,0xb8,0xec,0xa1,0xd7,0x0d,0x0a},
1312   {10,0x31,0x20,0xa1,0xfe,0xa1,0xfe,0xa2,0xa9,0x0d,0x0a},
1313   {14,0x31,0x20,0xa2,0xa8,0xa1,0xda,0x74,0x65,0x73,0x74,0xa1,0xdb,0x0d,0x0a}
1314     };
1315
1316     INT srcsz, destsz;
1317     INT i;
1318     HRESULT hr;
1319     CHAR output[30];
1320     WCHAR outputW[30];
1321     int outlen;
1322
1323     /* test unc->jis */
1324     for (i = 0; i < 9; i++)
1325     {
1326         int j;
1327         destsz = 30;
1328         outlen = jis_jp[i][0];
1329         srcsz = unc_jp[i][0];
1330         hr = pConvertINetUnicodeToMultiByte(NULL, 50220, &unc_jp[i][1], &srcsz, output, &destsz);
1331         if (hr == S_FALSE)
1332         {
1333             skip("Code page identifier 50220 is not supported\n");
1334             break;
1335         }
1336         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1337         ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1338         ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1339         ok(memcmp(output,&jis_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1340
1341         /* and back */
1342         srcsz = outlen;
1343         destsz = 30;
1344         hr = pConvertINetMultiByteToUnicode(NULL, 50220, output, &srcsz, outputW,&destsz);
1345
1346         /*
1347          * JIS does not have hankata so it get automatically converted to
1348          * zenkata. this means that strings 1 and 2 are identical as well as
1349          * strings 4 and 5.
1350          */
1351         j = i;
1352         if (i == 2) j = 1;
1353         if (i == 5) j = 4;
1354
1355         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i, hr);
1356         ok(destsz == unc_jp[j][0],"(%i) Expected %i, got %i\n",i,unc_jp[j][0],destsz);
1357         ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1358         ok(memcmp(outputW,&unc_jp[j][1],destsz)==0,"(%i) Strings do not match\n",i);
1359     }
1360
1361     /* test unc->sjis */
1362     for (i = 0; i < 9; i++)
1363     {
1364         destsz = 30;
1365         outlen = sjis_jp[i][0];
1366         srcsz = unc_jp[i][0];
1367
1368         hr = pConvertINetUnicodeToMultiByte(NULL, 932, &unc_jp[i][1], &srcsz, output, &destsz);
1369         if (hr == S_FALSE)
1370         {
1371             skip("Code page identifier 932 is not supported\n");
1372             break;
1373         }
1374         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1375         ok(destsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,destsz);
1376         ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1377         ok(memcmp(output,&sjis_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1378
1379         srcsz = outlen;
1380         destsz = 30;
1381         hr = pConvertINetMultiByteToUnicode(NULL, 932, output, &srcsz, outputW,&destsz);
1382
1383         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1384         ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1385         ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1386         ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1387     }
1388
1389     /* test unc->euc */
1390     for (i = 0; i < 9; i++)
1391     {
1392         destsz = 30;
1393         outlen = euc_jp[i][0];
1394         srcsz = unc_jp[i][0];
1395
1396         hr = pConvertINetUnicodeToMultiByte(NULL, 51932, &unc_jp[i][1], &srcsz, output, &destsz);
1397         if (hr == S_FALSE)
1398         {
1399             skip("Code page identifier 51932 is not supported\n");
1400             break;
1401         }
1402         ok(hr == S_OK, "(%i) Expected S_OK, got %08x\n",i,hr);
1403         ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1404         ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1405         ok(memcmp(output,&euc_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1406
1407         srcsz = outlen;
1408         destsz = 30;
1409         hr = pConvertINetMultiByteToUnicode(NULL, 51932, output, &srcsz, outputW,&destsz);
1410
1411         ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1412         ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1413         ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1414         ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1415     }
1416
1417     /* Japanese autodetect */
1418     i = 0;
1419     destsz = 30;
1420     srcsz = jis_jp[i][0];
1421     hr = pConvertINetMultiByteToUnicode(NULL, 50932, &jis_jp[i][1], &srcsz, outputW, &destsz);
1422     if (hr == S_FALSE)
1423     {
1424         skip("Code page identifier 50932 is not supported\n");
1425         return;
1426     }
1427     ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1428     ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1429     ok(srcsz == jis_jp[i][0],"(%i) Expected %i, got %i\n",i,jis_jp[i][0],srcsz);
1430     ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1431
1432     i = 1;
1433     destsz = 30;
1434     srcsz = sjis_jp[i][0];
1435     hr = pConvertINetMultiByteToUnicode(NULL, 50932, &sjis_jp[i][1], &srcsz, outputW, &destsz);
1436     ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1437     ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1438     ok(srcsz == sjis_jp[i][0],"(%i) Expected %i, got %i\n",i,sjis_jp[i][0],srcsz);
1439     ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1440 }
1441
1442 static void test_GetScriptFontInfo(IMLangFontLink2 *font_link)
1443 {
1444     HRESULT hr;
1445     UINT nfonts;
1446     SCRIPTFONTINFO sfi[1];
1447
1448     nfonts = 0;
1449     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidLatin, 0, &nfonts, NULL);
1450     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1451     ok(nfonts, "unexpected result\n");
1452
1453     nfonts = 0;
1454     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, NULL);
1455     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1456     ok(nfonts, "unexpected result\n");
1457
1458     nfonts = 0;
1459     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, NULL);
1460     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1461     ok(nfonts, "unexpected result\n");
1462
1463     nfonts = 1;
1464     memset(sfi, 0, sizeof(sfi));
1465     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidLatin, SCRIPTCONTF_FIXED_FONT, &nfonts, sfi);
1466     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1467     ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1468     ok(sfi[0].scripts != 0, "unexpected result\n");
1469     ok(sfi[0].wszFont[0], "unexpected result\n");
1470
1471     nfonts = 1;
1472     memset(sfi, 0, sizeof(sfi));
1473     hr = IMLangFontLink2_GetScriptFontInfo(font_link, sidLatin, SCRIPTCONTF_PROPORTIONAL_FONT, &nfonts, sfi);
1474     ok(hr == S_OK, "GetScriptFontInfo failed %u\n", GetLastError());
1475     ok(nfonts == 1, "got %u, expected 1\n", nfonts);
1476     ok(sfi[0].scripts != 0, "unexpected result\n");
1477     ok(sfi[0].wszFont[0], "unexpected result\n");
1478 }
1479
1480 START_TEST(mlang)
1481 {
1482     IMultiLanguage2 *iML2 = NULL;
1483     IMLangFontLink  *iMLFL = NULL;
1484     IMLangFontLink2 *iMLFL2 = NULL;
1485     HRESULT ret;
1486
1487     if (!init_function_ptrs())
1488         return;
1489
1490     CoInitialize(NULL);
1491     ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1492                            &IID_IMultiLanguage2, (void **)&iML2);
1493     if (ret != S_OK || !iML2) return;
1494
1495     test_rfc1766(iML2);
1496     test_GetLcidFromRfc1766(iML2);
1497     test_GetRfc1766FromLcid(iML2);
1498
1499     test_EnumCodePages(iML2, 0);
1500     test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
1501     test_EnumCodePages(iML2, MIMECONTF_BROWSER);
1502     test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
1503     test_EnumCodePages(iML2, MIMECONTF_VALID);
1504     /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
1505     /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/
1506
1507     test_EnumScripts(iML2, 0);
1508     test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
1509     test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);
1510
1511     ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
1512     ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
1513     ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
1514     ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
1515
1516     test_multibyte_to_unicode_translations(iML2);
1517     test_IMultiLanguage2_ConvertStringFromUnicode(iML2);
1518
1519     IMultiLanguage2_Release(iML2);
1520
1521     test_ConvertINetUnicodeToMultiByte();
1522
1523     test_JapaneseConversion();
1524
1525     ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1526                            &IID_IMLangFontLink, (void **)&iMLFL);
1527     if (ret != S_OK || !iMLFL) return;
1528
1529     IMLangFontLink_Test(iMLFL);
1530     IMLangFontLink_Release(iMLFL);
1531
1532     ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1533                            &IID_IMLangFontLink2, (void **)&iMLFL2);
1534     if (ret != S_OK || !iMLFL2) return;
1535
1536     test_GetScriptFontInfo(iMLFL2);
1537     IMLangFontLink2_Release(iMLFL2);
1538
1539     CoUninitialize();
1540 }