mlang/tests: Skip testing a codepage returning the buggy, legacy unicodeFEFF charset...
[wine/wine64.git] / dlls / mlang / tests / mlang.c
blob96aef1c2605dc19ca15c42169236142ad3726a06
1 /*
2 * Unit test suite for MLANG APIs.
4 * Copyright 2004 Dmitry Timoshkov
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.
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.
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
21 #define COBJMACROS
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "initguid.h"
29 #include "mlang.h"
31 #include "wine/test.h"
33 #ifndef CP_UNICODE
34 #define CP_UNICODE 1200
35 #endif
37 #if 0
38 #define DUMP_CP_INFO
39 #define DUMP_SCRIPT_INFO
41 #if defined DUMP_CP_INFO || defined DUMP_SCRIPT_INFO
42 #include "wine/debug.h"
43 #endif
44 #endif /* 0 */
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);
52 static BOOL init_function_ptrs(void)
54 HMODULE hMlang;
56 hMlang = LoadLibraryA("mlang.dll");
57 if (!hMlang)
59 skip("mlang not available\n");
60 return FALSE;
63 pConvertINetMultiByteToUnicode = (void *)GetProcAddress(hMlang, "ConvertINetMultiByteToUnicode");
64 pConvertINetUnicodeToMultiByte = (void *)GetProcAddress(hMlang, "ConvertINetUnicodeToMultiByte");
66 pGetCPInfoExA = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetCPInfoExA");
68 return TRUE;
71 #define ok_w2(format, szString1, szString2) \
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); \
81 static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
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;
91 /* IMultiLanguage2_ConvertStringToUnicode tests */
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);
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 */
113 ok(!lstrcmpW(bufW, stringW), "bufW/stringW mismatch\n");
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");
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");
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);
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);
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);
162 /* IMultiLanguage2_ConvertStringFromUnicode tests */
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);
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");
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");
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");
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);
214 static inline void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
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);
228 #ifdef DUMP_CP_INFO
229 static const char *dump_mime_flags(DWORD flags)
231 static char buf[1024];
233 buf[0] = 0;
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");
249 return buf;
251 #endif
253 static BOOL check_convertible(IMultiLanguage2 *iML2, UINT from, UINT to)
255 CHAR convert[MAX_PATH];
256 BYTE dest[MAX_PATH];
257 HRESULT hr;
258 UINT srcsz, destsz;
260 static WCHAR strW[] = {'a','b','c',0};
262 srcsz = lstrlenW(strW) + 1;
263 destsz = MAX_PATH;
264 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, from, strW,
265 &srcsz, convert, &destsz);
266 if (hr != S_OK)
267 return FALSE;
269 srcsz = -1;
270 destsz = MAX_PATH;
271 hr = IMultiLanguage2_ConvertString(iML2, NULL, from, to, (BYTE *)convert,
272 &srcsz, dest, &destsz);
273 if (hr != S_OK)
274 return FALSE;
276 return TRUE;
279 static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
281 IEnumCodePage *iEnumCP = NULL;
282 MIMECPINFO *cpinfo;
283 MIMECPINFO cpinfo2;
284 HRESULT ret;
285 ULONG i, n;
286 UINT total;
288 total = 0;
289 ret = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &total);
290 ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfCodePageInfo: expected S_OK/!0, got %08x/%u\n", ret, total);
292 trace("total mlang supported codepages %u\n", total);
294 ret = IMultiLanguage2_EnumCodePages(iML2, flags, LANG_NEUTRAL, &iEnumCP);
295 ok(ret == S_OK && iEnumCP, "IMultiLanguage2_EnumCodePages: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumCP);
297 ret = IEnumCodePage_Reset(iEnumCP);
298 ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
299 n = 65536;
300 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, &n);
301 ok(n == 0 && ret == S_FALSE, "IEnumCodePage_Next: expected 0/S_FALSE, got %u/%08x\n", n, ret);
302 ret = IEnumCodePage_Next(iEnumCP, 0, NULL, NULL);
303 ok(ret == S_FALSE, "IEnumCodePage_Next: expected S_FALSE, got %08x\n", ret);
305 cpinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*cpinfo) * total * 2);
307 n = total * 2;
308 ret = IEnumCodePage_Next(iEnumCP, 0, cpinfo, &n);
309 ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
311 n = total * 2;
312 ret = IEnumCodePage_Next(iEnumCP, n, cpinfo, &n);
313 ok(ret == S_OK && n != 0, "IEnumCodePage_Next: expected S_OK/!0, got %08x/%u\n", ret, n);
315 trace("flags %08x, enumerated codepages %u\n", flags, n);
317 if (!flags)
319 ok(n == total, "IEnumCodePage_Next: expected %u, got %u\n", total, n);
321 flags = MIMECONTF_MIME_LATEST;
324 total = n;
326 for (i = 0; i < n; i++)
328 CHARSETINFO csi;
329 MIMECSETINFO mcsi;
330 BOOL convertible;
331 HRESULT check = S_OK;
332 static const WCHAR autoW[] = {'_','a','u','t','o',0};
333 static const WCHAR feffW[] = {'u','n','i','c','o','d','e','F','E','F','F',0};
335 #ifdef DUMP_CP_INFO
336 trace("MIMECPINFO #%u:\n"
337 "dwFlags %08x %s\n"
338 "uiCodePage %u\n"
339 "uiFamilyCodePage %u\n"
340 "wszDescription %s\n"
341 "wszWebCharset %s\n"
342 "wszHeaderCharset %s\n"
343 "wszBodyCharset %s\n"
344 "wszFixedWidthFont %s\n"
345 "wszProportionalFont %s\n"
346 "bGDICharset %d\n\n",
348 cpinfo[i].dwFlags, dump_mime_flags(cpinfo[i].dwFlags),
349 cpinfo[i].uiCodePage,
350 cpinfo[i].uiFamilyCodePage,
351 wine_dbgstr_w(cpinfo[i].wszDescription),
352 wine_dbgstr_w(cpinfo[i].wszWebCharset),
353 wine_dbgstr_w(cpinfo[i].wszHeaderCharset),
354 wine_dbgstr_w(cpinfo[i].wszBodyCharset),
355 wine_dbgstr_w(cpinfo[i].wszFixedWidthFont),
356 wine_dbgstr_w(cpinfo[i].wszProportionalFont),
357 cpinfo[i].bGDICharset);
358 #endif
359 ok(cpinfo[i].dwFlags & flags, "enumerated flags %08x do not include requested %08x\n", cpinfo[i].dwFlags, flags);
361 if (TranslateCharsetInfo((DWORD *)cpinfo[i].uiFamilyCodePage, &csi, TCI_SRCCODEPAGE))
362 ok(cpinfo[i].bGDICharset == csi.ciCharset, "%d != %d\n", cpinfo[i].bGDICharset, csi.ciCharset);
363 else
364 trace("TranslateCharsetInfo failed for cp %u\n", cpinfo[i].uiFamilyCodePage);
366 #ifdef DUMP_CP_INFO
367 trace("%u: codepage %u family %u\n", i, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
368 #endif
369 /* Win95 does not support UTF-7 */
370 if (cpinfo[i].uiCodePage == CP_UTF7) continue;
372 /* support files for some codepages might be not installed, or
373 * the codepage is just an alias.
375 if (IsValidCodePage(cpinfo[i].uiCodePage))
377 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UNICODE);
378 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(%u -> CP_UNICODE) = %08x\n", cpinfo[i].uiCodePage, ret);
379 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, cpinfo[i].uiCodePage);
380 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
382 convertible = check_convertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
383 if (!convertible)
384 check = S_FALSE;
386 ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
387 ok(ret == check, "IMultiLanguage2_IsConvertible(%u -> CP_UTF8) = %08x\n", cpinfo[i].uiCodePage, ret);
388 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, cpinfo[i].uiCodePage);
389 ok(ret == check, "IMultiLanguage2_IsConvertible(CP_UTF8 -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
391 else
392 trace("IsValidCodePage failed for cp %u\n", cpinfo[i].uiCodePage);
394 if (memcmp(cpinfo[i].wszWebCharset,feffW,sizeof(WCHAR)*11)==0)
395 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
396 else
398 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszWebCharset, &mcsi);
399 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
400 if (memcmp(cpinfo[i].wszWebCharset, autoW, 5 * sizeof(WCHAR)))
402 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
403 #ifdef DUMP_CP_INFO
404 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszWebCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
405 #endif
406 ok(!lstrcmpiW(cpinfo[i].wszWebCharset, mcsi.wszCharset),
407 #ifdef DUMP_CP_INFO
408 "%s != %s\n",
409 wine_dbgstr_w(cpinfo[i].wszWebCharset), wine_dbgstr_w(mcsi.wszCharset));
410 #else
411 "wszWebCharset mismatch\n");
412 #endif
414 if (0)
416 /* native mlang returns completely messed up encodings in some cases */
417 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
418 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
419 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
420 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
425 if (memcmp(cpinfo[i].wszHeaderCharset,feffW,sizeof(WCHAR)*11)==0)
426 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
427 else
429 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszHeaderCharset, &mcsi);
430 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
431 if (memcmp(cpinfo[i].wszHeaderCharset, autoW, 5 * sizeof(WCHAR)))
433 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
434 #ifdef DUMP_CP_INFO
435 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszHeaderCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
436 #endif
437 ok(!lstrcmpiW(cpinfo[i].wszHeaderCharset, mcsi.wszCharset),
438 #ifdef DUMP_CP_INFO
439 "%s != %s\n",
440 wine_dbgstr_w(cpinfo[i].wszHeaderCharset), wine_dbgstr_w(mcsi.wszCharset));
441 #else
442 "wszHeaderCharset mismatch\n");
443 #endif
445 if (0)
447 /* native mlang returns completely messed up encodings in some cases */
448 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
449 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
450 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
451 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
456 if (memcmp(cpinfo[i].wszBodyCharset,feffW,sizeof(WCHAR)*11)==0)
457 skip("Legacy windows bug returning invalid charset of unicodeFEFF\n");
458 else
460 ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszBodyCharset, &mcsi);
461 /* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
462 if (memcmp(cpinfo[i].wszBodyCharset, autoW, 5 * sizeof(WCHAR)))
464 ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
465 #ifdef DUMP_CP_INFO
466 trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszBodyCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
467 #endif
468 ok(!lstrcmpiW(cpinfo[i].wszBodyCharset, mcsi.wszCharset),
469 #ifdef DUMP_CP_INFO
470 "%s != %s\n",
471 wine_dbgstr_w(cpinfo[i].wszBodyCharset), wine_dbgstr_w(mcsi.wszCharset));
472 #else
473 "wszBodyCharset mismatch\n");
474 #endif
476 if (0)
478 /* native mlang returns completely messed up encodings in some cases */
479 ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
480 "%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
481 ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
482 "%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
488 /* now IEnumCodePage_Next should fail, since pointer is at the end */
489 n = 1;
490 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
491 ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
493 ret = IEnumCodePage_Reset(iEnumCP);
494 ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
495 n = 0;
496 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
497 ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
498 cpinfo_cmp(&cpinfo[0], &cpinfo2);
500 if (0)
502 /* Due to a bug in MS' implementation of IEnumCodePage_Skip
503 * it's not used here.
505 ret = IEnumCodePage_Skip(iEnumCP, 1);
506 ok(ret == S_OK, "IEnumCodePage_Skip: expected S_OK, got %08x\n", ret);
508 for (i = 0; i < total - 1; i++)
510 n = 0;
511 ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
512 ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
513 cpinfo_cmp(&cpinfo[i + 1], &cpinfo2);
516 HeapFree(GetProcessHeap(), 0, cpinfo);
517 IEnumCodePage_Release(iEnumCP);
520 static inline void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
522 ok(sinfo1->ScriptId == sinfo2->ScriptId, "ScriptId mismatch: %d != %d\n", sinfo1->ScriptId, sinfo2->ScriptId);
523 ok(sinfo1->uiCodePage == sinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", sinfo1->uiCodePage, sinfo2->uiCodePage);
524 ok(!lstrcmpW(sinfo1->wszDescription, sinfo2->wszDescription), "wszDescription mismatch\n");
525 ok(!lstrcmpW(sinfo1->wszFixedWidthFont, sinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
526 ok(!lstrcmpW(sinfo1->wszProportionalFont, sinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
529 static void test_EnumScripts(IMultiLanguage2 *iML2, DWORD flags)
531 IEnumScript *iEnumScript = NULL;
532 SCRIPTINFO *sinfo;
533 SCRIPTINFO sinfo2;
534 HRESULT ret;
535 ULONG i, n;
536 UINT total;
538 total = 0;
539 ret = IMultiLanguage2_GetNumberOfScripts(iML2, &total);
540 ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfScripts: expected S_OK/!0, got %08x/%u\n", ret, total);
542 trace("total mlang supported scripts %u\n", total);
544 ret = IMultiLanguage2_EnumScripts(iML2, flags, LANG_NEUTRAL, &iEnumScript);
545 ok(ret == S_OK && iEnumScript, "IMultiLanguage2_EnumScripts: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumScript);
547 ret = IEnumScript_Reset(iEnumScript);
548 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
549 n = 65536;
550 ret = IEnumScript_Next(iEnumScript, 0, NULL, &n);
551 ok(n == 65536 && ret == E_FAIL, "IEnumScript_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
552 ret = IEnumScript_Next(iEnumScript, 0, NULL, NULL);
553 ok(ret == E_FAIL, "IEnumScript_Next: expected E_FAIL, got %08x\n", ret);
555 sinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*sinfo) * total * 2);
557 n = total * 2;
558 ret = IEnumScript_Next(iEnumScript, 0, sinfo, &n);
559 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
561 n = total * 2;
562 ret = IEnumScript_Next(iEnumScript, n, sinfo, &n);
563 ok(ret == S_OK && n != 0, "IEnumScript_Next: expected S_OK, got %08x/%u\n", ret, n);
565 trace("flags %08x, enumerated scripts %u\n", flags, n);
567 if (!flags)
569 ok(n == total, "IEnumScript_Next: expected %u, got %u\n", total, n);
570 flags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
573 total = n;
575 for (i = 0; pGetCPInfoExA && i < n; i++)
577 #ifdef DUMP_SCRIPT_INFO
578 trace("SCRIPTINFO #%u:\n"
579 "ScriptId %08x\n"
580 "uiCodePage %u\n"
581 "wszDescription %s\n"
582 "wszFixedWidthFont %s\n"
583 "wszProportionalFont %s\n\n",
585 sinfo[i].ScriptId,
586 sinfo[i].uiCodePage,
587 wine_dbgstr_w(sinfo[i].wszDescription),
588 wine_dbgstr_w(sinfo[i].wszFixedWidthFont),
589 wine_dbgstr_w(sinfo[i].wszProportionalFont));
590 trace("%u codepage %u\n", i, sinfo[i].uiCodePage);
591 #endif
594 /* now IEnumScript_Next should fail, since pointer is at the end */
595 n = 1;
596 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
597 ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
599 ret = IEnumScript_Reset(iEnumScript);
600 ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
601 n = 0;
602 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
603 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
604 scriptinfo_cmp(&sinfo[0], &sinfo2);
606 if (0)
608 /* Due to a bug in MS' implementation of IEnumScript_Skip
609 * it's not used here.
611 ret = IEnumScript_Skip(iEnumScript, 1);
612 ok(ret == S_OK, "IEnumScript_Skip: expected S_OK, got %08x\n", ret);
614 for (i = 0; i < total - 1; i++)
616 n = 0;
617 ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
618 ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
619 scriptinfo_cmp(&sinfo[i + 1], &sinfo2);
622 HeapFree(GetProcessHeap(), 0, sinfo);
623 IEnumScript_Release(iEnumScript);
626 static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
628 DWORD dwCodePages, dwManyCodePages;
629 UINT CodePage;
630 HRESULT ret;
632 dwCodePages = ~0u;
633 ret = IMLangFontLink_CodePageToCodePages(iMLFL, -1, &dwCodePages);
634 ok(ret == E_FAIL, "IMLangFontLink_CodePageToCodePages should fail: %x\n", ret);
635 ok(dwCodePages == 0, "expected 0, got %u\n", dwCodePages);
637 dwCodePages = 0;
638 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 932, &dwCodePages);
639 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
640 ok(dwCodePages == FS_JISJAPAN, "expected FS_JISJAPAN, got %08x\n", dwCodePages);
641 CodePage = 0;
642 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwCodePages, 1035, &CodePage);
643 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
644 ok(CodePage == 932, "Incorrect CodePage Returned (%i)\n",CodePage);
646 dwManyCodePages = 0;
647 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1252, &dwManyCodePages);
648 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
649 ok(dwManyCodePages == FS_LATIN1, "expected FS_LATIN1, got %08x\n", dwManyCodePages);
650 dwCodePages = 0;
651 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 1256, &dwCodePages);
652 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
653 ok(dwCodePages == FS_ARABIC, "expected FS_ARABIC, got %08x\n", dwCodePages);
654 dwManyCodePages |= dwCodePages;
655 ret = IMLangFontLink_CodePageToCodePages(iMLFL, 874, &dwCodePages);
656 ok(ret == S_OK, "IMLangFontLink_CodePageToCodePages error %x\n", ret);
657 ok(dwCodePages == FS_THAI, "expected FS_THAI, got %08x\n", dwCodePages);
658 dwManyCodePages |= dwCodePages;
660 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 1256, &CodePage);
661 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
662 ok(CodePage == 1256, "Incorrect CodePage Returned (%i)\n",CodePage);
664 ret = IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 936, &CodePage);
665 ok(ret == S_OK, "IMLangFontLink_CodePagesToCodePage error %x\n", ret);
666 ok(CodePage == 1252, "Incorrect CodePage Returned (%i)\n",CodePage);
669 /* copied from libs/wine/string.c */
670 WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
672 while (*str)
674 const WCHAR *p1 = str, *p2 = sub;
675 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
676 if (!*p2) return (WCHAR *)str;
677 str++;
679 return NULL;
682 static void test_rfc1766(IMultiLanguage2 *iML2)
684 IEnumRfc1766 *pEnumRfc1766;
685 RFC1766INFO info;
686 ULONG n;
687 HRESULT ret;
688 BSTR rfcstr;
690 ret = IMultiLanguage2_EnumRfc1766(iML2, LANG_NEUTRAL, &pEnumRfc1766);
691 ok(ret == S_OK, "IMultiLanguage2_EnumRfc1766 error %08x\n", ret);
693 while (1)
695 ret = IEnumRfc1766_Next(pEnumRfc1766, 1, &info, &n);
696 if (ret != S_OK) break;
698 #ifdef DUMP_CP_INFO
699 trace("lcid %04x rfc_name %s locale_name %s\n",
700 info.lcid, wine_dbgstr_w(info.wszRfc1766), wine_dbgstr_w(info.wszLocaleName));
701 #endif
703 ok(n == 1, "couldn't fetch 1 RFC1766INFO structure\n");
705 /* verify the Rfc1766 value */
706 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, info.lcid, &rfcstr);
707 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
709 /* not an exact 1:1 correspondence between lcid and rfc1766 in the
710 * mlang database, e.g., nb-no -> 1044 -> no */
711 ok(strstrW(info.wszRfc1766, rfcstr) != NULL,
712 "Expected matching locale names\n");
714 SysFreeString(rfcstr);
716 IEnumRfc1766_Release(pEnumRfc1766);
719 static void test_GetLcidFromRfc1766(IMultiLanguage2 *iML2)
721 LCID lcid;
722 HRESULT ret;
724 static WCHAR e[] = { 'e',0 };
725 static WCHAR en[] = { 'e','n',0 };
726 static WCHAR empty[] = { 0 };
727 static WCHAR dash[] = { '-',0 };
728 static WCHAR e_dash[] = { 'e','-',0 };
729 static WCHAR en_gb[] = { 'e','n','-','g','b',0 };
730 static WCHAR en_us[] = { 'e','n','-','u','s',0 };
731 static WCHAR en_them[] = { 'e','n','-','t','h','e','m',0 };
732 static WCHAR english[] = { 'e','n','g','l','i','s','h',0 };
734 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, NULL, en);
735 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
737 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, NULL);
738 ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);
740 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, e);
741 ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);
743 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, empty);
744 ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);
746 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, dash);
747 ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);
749 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, e_dash);
750 ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);
752 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_them);
753 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
754 if (ret == S_FALSE)
756 BSTR rfcstr;
757 static WCHAR en[] = {'e','n',0};
759 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
760 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
761 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
764 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, english);
765 ok((ret == E_FAIL || ret == S_FALSE), "GetLcidFromRfc1766 returned: %08x\n", ret);
766 if (ret == S_FALSE)
768 BSTR rfcstr;
769 static WCHAR en[] = {'e','n',0};
771 ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
772 ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);
773 ok_w2("Expected \"%s\", got \"%s\"n", en, rfcstr);
776 lcid = 0;
778 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en);
779 ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
780 ok(lcid == 9, "got wrong lcid: %04x\n", lcid);
782 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_gb);
783 ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
784 ok(lcid == 0x809, "got wrong lcid: %04x\n", lcid);
786 ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_us);
787 ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
788 ok(lcid == 0x409, "got wrong lcid: %04x\n", lcid);
791 static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
793 HRESULT hr;
794 BSTR rfcstr;
795 LCID lcid;
797 static WCHAR kok[] = {'k','o','k',0};
799 hr = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, kok);
801 * S_FALSE happens when 'kok' instead matches to a different Rfc1766 name
802 * for example 'ko' so it is not a failure but does not give us what
803 * we are looking for
805 if (hr != S_FALSE)
807 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
809 hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
810 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
811 ok_w2("Expected \"%s\", got \"%s\"n", kok, rfcstr);
813 SysFreeString(rfcstr);
816 static void test_IMultiLanguage2_ConvertStringFromUnicode(IMultiLanguage2 *iML2)
818 CHAR dest[MAX_PATH];
819 CHAR invariate[MAX_PATH];
820 UINT srcsz, destsz;
821 HRESULT hr;
823 static WCHAR src[] = {'a','b','c',0};
825 memset(invariate, 'x', sizeof(invariate));
827 /* pSrcStr NULL */
828 memset(dest, 'x', sizeof(dest));
829 srcsz = lstrlenW(src) + 1;
830 destsz = sizeof(dest);
831 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
832 &srcsz, dest, &destsz);
833 ok(hr == S_OK || hr == E_FAIL,"expected S_OK or E_FAIL, got %08x\n",hr);
834 if (hr == S_OK)
836 ok(srcsz == lstrlenW(src) + 1,
837 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
839 else if (hr == E_FAIL)
841 ok(srcsz == 0,
842 "Expected %u, got %u\n", 0, srcsz);
845 ok(!memcmp(dest, invariate, sizeof(dest)),
846 "Expected dest to be unchanged, got %s\n", dest);
847 ok(destsz == 0, "Expected 0, got %u\n", destsz);
849 /* pcSrcSize NULL */
850 memset(dest, 'x', sizeof(dest));
851 destsz = sizeof(dest);
852 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
853 NULL, dest, &destsz);
854 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
855 ok(!strncmp(dest, "abc", 3),
856 "Expected first three chars to be \"abc\"\n");
857 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
858 "Expected rest of dest to be unchanged, got %s\n", dest);
859 ok(destsz == lstrlenW(src),
860 "Expected %u, got %u\n", lstrlenW(src), destsz);
862 /* both pSrcStr and pcSrcSize NULL */
863 memset(dest, 'x', sizeof(dest));
864 destsz = sizeof(dest);
865 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, NULL,
866 NULL, dest, &destsz);
867 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
868 ok(!memcmp(dest, invariate, sizeof(dest)),
869 "Expected dest to be unchanged, got %s\n", dest);
870 ok(destsz == 0, "Expected 0, got %u\n", destsz);
872 /* pDstStr NULL */
873 memset(dest, 'x', sizeof(dest));
874 srcsz = lstrlenW(src) + 1;
875 destsz = sizeof(dest);
876 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
877 &srcsz, NULL, &destsz);
878 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
879 ok(srcsz == lstrlenW(src) + 1,
880 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
881 ok(destsz == lstrlenW(src) + 1,
882 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
884 /* pcDstSize NULL */
885 memset(dest, 'x', sizeof(dest));
886 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
887 &srcsz, dest, NULL);
888 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
889 ok(srcsz == lstrlenW(src) + 1,
890 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
891 ok(!memcmp(dest, invariate, sizeof(dest)),
892 "Expected dest to be unchanged, got %s\n", dest);
894 /* pcSrcSize is 0 */
895 memset(dest, 'x', sizeof(dest));
896 srcsz = 0;
897 destsz = sizeof(dest);
898 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
899 &srcsz, dest, &destsz);
900 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
901 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
902 ok(!memcmp(dest, invariate, sizeof(dest)),
903 "Expected dest to be unchanged, got %s\n", dest);
904 ok(destsz == 0, "Expected 0, got %u\n", destsz);
906 /* pcSrcSize does not include NULL terminator */
907 memset(dest, 'x', sizeof(dest));
908 srcsz = lstrlenW(src);
909 destsz = sizeof(dest);
910 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
911 &srcsz, dest, &destsz);
912 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
913 ok(srcsz == lstrlenW(src),
914 "Expected %u, got %u\n", lstrlenW(src), srcsz);
915 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
916 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
917 "Expected rest of dest to be unchanged, got %s\n", dest);
918 ok(destsz == lstrlenW(src),
919 "Expected %u, got %u\n", lstrlenW(src), destsz);
921 /* pcSrcSize includes NULL terminator */
922 memset(dest, 'x', sizeof(dest));
923 srcsz = lstrlenW(src) + 1;
924 destsz = sizeof(dest);
925 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
926 &srcsz, dest, &destsz);
927 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
928 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
929 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
930 ok(destsz == lstrlenW(src) + 1,
931 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
933 /* pcSrcSize is -1 */
934 memset(dest, 'x', sizeof(dest));
935 srcsz = -1;
936 destsz = sizeof(dest);
937 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
938 &srcsz, dest, &destsz);
939 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
940 ok(srcsz == lstrlenW(src),
941 "Expected %u, got %u\n", lstrlenW(src), srcsz);
942 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
943 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
944 "Expected rest of dest to be unchanged, got %s\n", dest);
945 ok(destsz == lstrlenW(src),
946 "Expected %u, got %u\n", lstrlenW(src), destsz);
948 /* pcDstSize is 0 */
949 memset(dest, 'x', sizeof(dest));
950 srcsz = lstrlenW(src) + 1;
951 destsz = 0;
952 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
953 &srcsz, dest, &destsz);
954 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
955 ok(srcsz == lstrlenW(src) + 1,
956 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
957 ok(!memcmp(dest, invariate, sizeof(dest)),
958 "Expected dest to be unchanged, got %s\n", dest);
959 ok(destsz == lstrlenW(src) + 1,
960 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
962 /* pcDstSize is not large enough */
963 memset(dest, 'x', sizeof(dest));
964 srcsz = lstrlenW(src) + 1;
965 destsz = lstrlenW(src);
966 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
967 &srcsz, dest, &destsz);
968 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
969 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
970 ok(!strncmp(dest, "abc", 3), "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 == 0, "Expected 0, got %u\n", srcsz);
975 /* pcDstSize (bytes) does not leave room for NULL terminator */
976 memset(dest, 'x', sizeof(dest));
977 srcsz = lstrlenW(src) + 1;
978 destsz = lstrlenW(src) * sizeof(WCHAR);
979 hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, src,
980 &srcsz, dest, &destsz);
981 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
982 ok(srcsz == lstrlenW(src) + 1,
983 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
984 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
985 ok(destsz == lstrlenW(src) + 1,
986 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
989 static void test_ConvertINetUnicodeToMultiByte(void)
991 CHAR dest[MAX_PATH];
992 CHAR invariate[MAX_PATH];
993 INT srcsz, destsz;
994 HRESULT hr;
996 static WCHAR src[] = {'a','b','c',0};
998 memset(invariate, 'x', sizeof(invariate));
1000 /* lpSrcStr NULL */
1001 memset(dest, 'x', sizeof(dest));
1002 srcsz = lstrlenW(src) + 1;
1003 destsz = sizeof(dest);
1004 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, &srcsz, dest, &destsz);
1005 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1006 if (hr == S_OK)
1007 ok(srcsz == lstrlenW(src) + 1,
1008 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1009 else if (hr == E_FAIL)
1010 ok(srcsz == 0,
1011 "Expected %u, got %u\n", 0, srcsz);
1012 ok(!memcmp(dest, invariate, sizeof(dest)),
1013 "Expected dest to be unchanged, got %s\n", dest);
1014 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1016 /* lpnWideCharCount NULL */
1017 memset(dest, 'x', sizeof(dest));
1018 destsz = sizeof(dest);
1019 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, NULL, dest, &destsz);
1020 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1021 ok(!strncmp(dest, "abc", 3),
1022 "Expected first three chars to be \"abc\"\n");
1023 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1024 "Expected rest of dest to be unchanged, got %s\n", dest);
1025 ok(destsz == lstrlenW(src),
1026 "Expected %u, got %u\n", lstrlenW(src), destsz);
1028 /* both lpSrcStr and lpnWideCharCount NULL */
1029 memset(dest, 'x', sizeof(dest));
1030 destsz = sizeof(dest);
1031 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, NULL, NULL, dest, &destsz);
1032 ok(hr == S_OK || hr == E_FAIL, "Expected S_OK or E_FAIL, got %08x\n", hr);
1033 ok(!memcmp(dest, invariate, sizeof(dest)),
1034 "Expected dest to be unchanged, got %s\n", dest);
1035 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1037 /* lpDstStr NULL */
1038 memset(dest, 'x', sizeof(dest));
1039 srcsz = lstrlenW(src) + 1;
1040 destsz = sizeof(dest);
1041 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, NULL, &destsz);
1042 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1043 ok(srcsz == lstrlenW(src) + 1,
1044 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1045 ok(destsz == lstrlenW(src) + 1,
1046 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1048 /* lpnMultiCharCount NULL */
1049 memset(dest, 'x', sizeof(dest));
1050 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, NULL);
1051 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1052 ok(srcsz == lstrlenW(src) + 1,
1053 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1054 ok(!memcmp(dest, invariate, sizeof(dest)),
1055 "Expected dest to be unchanged, got %s\n", dest);
1057 /* lpnWideCharCount is 0 */
1058 memset(dest, 'x', sizeof(dest));
1059 srcsz = 0;
1060 destsz = sizeof(dest);
1061 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1062 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1063 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1064 ok(!memcmp(dest, invariate, sizeof(dest)),
1065 "Expected dest to be unchanged, got %s\n", dest);
1066 ok(destsz == 0, "Expected 0, got %u\n", destsz);
1068 /* lpnWideCharCount does not include NULL terminator */
1069 memset(dest, 'x', sizeof(dest));
1070 srcsz = lstrlenW(src);
1071 destsz = sizeof(dest);
1072 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1073 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1074 ok(srcsz == lstrlenW(src),
1075 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1076 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1077 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1078 "Expected rest of dest to be unchanged, got %s\n", dest);
1079 ok(destsz == lstrlenW(src),
1080 "Expected %u, got %u\n", lstrlenW(src), destsz);
1082 /* lpnWideCharCount includes NULL terminator */
1083 memset(dest, 'x', sizeof(dest));
1084 srcsz = lstrlenW(src) + 1;
1085 destsz = sizeof(dest);
1086 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1087 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1088 ok(srcsz == lstrlenW(src) + 1, "Expected 3, got %u\n", srcsz);
1089 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1090 ok(destsz == lstrlenW(src) + 1,
1091 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1093 /* lpnWideCharCount is -1 */
1094 memset(dest, 'x', sizeof(dest));
1095 srcsz = -1;
1096 destsz = sizeof(dest);
1097 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1098 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1099 ok(srcsz == lstrlenW(src),
1100 "Expected %u, got %u\n", lstrlenW(src), srcsz);
1101 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1102 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1103 "Expected rest of dest to be unchanged, got %s\n", dest);
1104 ok(destsz == lstrlenW(src),
1105 "Expected %u, got %u\n", lstrlenW(src), destsz);
1107 /* lpnMultiCharCount is 0 */
1108 memset(dest, 'x', sizeof(dest));
1109 srcsz = lstrlenW(src) + 1;
1110 destsz = 0;
1111 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1112 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1113 ok(srcsz == lstrlenW(src) + 1,
1114 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1115 ok(!memcmp(dest, invariate, sizeof(dest)),
1116 "Expected dest to be unchanged, got %s\n", dest);
1117 ok(destsz == lstrlenW(src) + 1,
1118 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1120 /* lpnMultiCharCount is not large enough */
1121 memset(dest, 'x', sizeof(dest));
1122 srcsz = lstrlenW(src) + 1;
1123 destsz = lstrlenW(src);
1124 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1125 ok(hr == E_FAIL, "Expected E_FAIL, got %08x\n", hr);
1126 ok(srcsz == 0, "Expected 0, got %u\n", srcsz);
1127 ok(!strncmp(dest, "abc", 3), "Expected first three chars to be \"abc\"\n");
1128 ok(!memcmp(&dest[3], invariate, sizeof(dest) - 3),
1129 "Expected rest of dest to be unchanged, got %s\n", dest);
1130 ok(destsz == 0, "Expected 0, got %u\n", srcsz);
1132 /* lpnMultiCharCount (bytes) does not leave room for NULL terminator */
1133 memset(dest, 'x', sizeof(dest));
1134 srcsz = lstrlenW(src) + 1;
1135 destsz = lstrlenW(src) * sizeof(WCHAR);
1136 hr = pConvertINetUnicodeToMultiByte(NULL, 1252, src, &srcsz, dest, &destsz);
1137 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1138 ok(srcsz == lstrlenW(src) + 1,
1139 "Expected %u, got %u\n", lstrlenW(src) + 1, srcsz);
1140 ok(!lstrcmpA(dest, "abc"), "Expected \"abc\", got \"%s\"\n", dest);
1141 ok(destsz == lstrlenW(src) + 1,
1142 "Expected %u, got %u\n", lstrlenW(src) + 1, destsz);
1145 static void test_JapaneseConversion(void)
1147 /* Data */
1148 static WCHAR unc_jp[9][12] = {
1149 {9,0x31,0x20,0x3042,0x3044,0x3046,0x3048,0x304a,0x000d,0x000a},
1150 {9,0x31,0x20,0x30a2,0x30a4,0x30a6,0x30a8,0x30aa,0x000d,0x000a},
1151 {9,0x31,0x20,0xff71,0xff72,0xff73,0xff74,0xff75,0x000d,0x000a},
1152 {9,0x31,0x20,0x3041,0x3043,0x3045,0x3047,0x3049,0x000d,0x000a},
1153 {9,0x31,0x20,0x30a1,0x30a3,0x30a5,0x30a7,0x30a9,0x000d,0x000a},
1154 {9,0x31,0x20,0xff67,0xff68,0xff69,0xff6a,0xff6b,0x000d,0x000a},
1155 {9,0x31,0x20,0x300c,0x65e5,0x672c,0x8a9e,0x300d,0x000d,0x000a},
1156 {7,0x31,0x20,0x25c7,0x25c7,0x3012,0x000d,0x000a},
1157 {11,0x31,0x20,0x203b,0x3010,0x0074,0x0065,0x0073,0x0074,0x3011,0x000d,0x000a}
1159 static CHAR jis_jp[9][27] = {
1160 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x22,0x24,0x24,0x24,0x26,0x24,0x28,
1161 0x24,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1162 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,\
1163 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1164 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x22,0x25,0x24,0x25,0x26,0x25,0x28,\
1165 0x25,0x2a,0x1b,0x28,0x42,0x0d,0x0a},
1166 {20,0x31,0x20,0x1b,0x24,0x42,0x24,0x21,0x24,0x23,0x24,0x25,0x24,0x27,\
1167 0x24,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1168 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,\
1169 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1170 {20,0x31,0x20,0x1b,0x24,0x42,0x25,0x21,0x25,0x23,0x25,0x25,0x25,0x27,\
1171 0x25,0x29,0x1b,0x28,0x42,0x0d,0x0a},
1172 {20,0x31,0x20,0x1b,0x24,0x42,0x21,0x56,0x46,0x7c,0x4b,0x5c,0x38,0x6c,\
1173 0x21,0x57,0x1b,0x28,0x42,0x0d,0x0a},
1174 {16,0x31,0x20,0x1b,0x24,0x42,0x21,0x7e,0x21,0x7e,0x22,0x29,0x1b,0x28,\
1175 0x42,0x0d,0x0a},
1176 {26,0x31,0x20,0x1b,0x24,0x42,0x22,0x28,0x21,0x5a,0x1b,0x28,0x42,0x74,\
1177 0x65,0x73,0x74,0x1b,0x24,0x42,0x21,0x5b,0x1b,0x28,0x42,0x0d,0x0a}
1179 static CHAR sjis_jp[9][15] = {
1180 {14,0x31,0x20,0x82,0xa0,0x82,0xa2,0x82,0xa4,0x82,0xa6,0x82,0xa8,0x0d,0x0a},
1181 {14,0x31,0x20,0x83,0x41,0x83,0x43,0x83,0x45,0x83,0x47,0x83,0x49,0x0d,0x0a},
1182 {9,0x31,0x20,0xb1,0xb2,0xb3,0xb4,0xb5,0x0d,0x0a},
1183 {14,0x31,0x20,0x82,0x9f,0x82,0xa1,0x82,0xa3,0x82,0xa5,0x82,0xa7,0x0d,0x0a},
1184 {14,0x31,0x20,0x83,0x40,0x83,0x42,0x83,0x44,0x83,0x46,0x83,0x48,0x0d,0x0a},
1185 {9,0x31,0x20,0xa7,0xa8,0xa9,0xaa,0xab,0x0d,0x0a},
1186 {14,0x31,0x20,0x81,0x75,0x93,0xfa,0x96,0x7b,0x8c,0xea,0x81,0x76,0x0d,0x0a},
1187 {10,0x31,0x20,0x81,0x9e,0x81,0x9e,0x81,0xa7,0x0d,0x0a},
1188 {14,0x31,0x20,0x81,0xa6,0x81,0x79,0x74,0x65,0x73,0x74,0x81,0x7a,0x0d,0x0a}
1190 static CHAR euc_jp[9][15] = {
1191 {14,0x31,0x20,0xa4,0xa2,0xa4,0xa4,0xa4,0xa6,0xa4,0xa8,0xa4,0xaa,0x0d,0x0a},
1192 {14,0x31,0x20,0xa5,0xa2,0xa5,0xa4,0xa5,0xa6,0xa5,0xa8,0xa5,0xaa,0x0d,0x0a},
1193 {14,0x31,0x20,0x8e,0xb1,0x8e,0xb2,0x8e,0xb3,0x8e,0xb4,0x8e,0xb5,0x0d,0x0a},
1194 {14,0x31,0x20,0xa4,0xa1,0xa4,0xa3,0xa4,0xa5,0xa4,0xa7,0xa4,0xa9,0x0d,0x0a},
1195 {14,0x31,0x20,0xa5,0xa1,0xa5,0xa3,0xa5,0xa5,0xa5,0xa7,0xa5,0xa9,0x0d,0x0a},
1196 {14,0x31,0x20,0x8e,0xa7,0x8e,0xa8,0x8e,0xa9,0x8e,0xaa,0x8e,0xab,0x0d,0x0a},
1197 {14,0x31,0x20,0xa1,0xd6,0xc6,0xfc,0xcb,0xdc,0xb8,0xec,0xa1,0xd7,0x0d,0x0a},
1198 {10,0x31,0x20,0xa1,0xfe,0xa1,0xfe,0xa2,0xa9,0x0d,0x0a},
1199 {14,0x31,0x20,0xa2,0xa8,0xa1,0xda,0x74,0x65,0x73,0x74,0xa1,0xdb,0x0d,0x0a}
1202 INT srcsz, destsz;
1203 INT i;
1204 HRESULT hr;
1205 CHAR output[30];
1206 WCHAR outputW[30];
1207 int outlen;
1209 /* test unc->jis */
1210 for (i = 0; i < 9; i++)
1212 int j;
1213 destsz = 30;
1214 outlen = jis_jp[i][0];
1215 srcsz = unc_jp[i][0];
1216 hr = pConvertINetUnicodeToMultiByte(NULL, 50220, &unc_jp[i][1], &srcsz, output, &destsz);
1217 if (hr == S_FALSE)
1219 skip("Code page identifier 50220 is not supported\n");
1220 break;
1222 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1223 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1224 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1225 ok(memcmp(output,&jis_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1227 /* and back */
1228 srcsz = outlen;
1229 destsz = 30;
1230 hr = pConvertINetMultiByteToUnicode(NULL, 50220, output, &srcsz, outputW,&destsz);
1233 * JIS does not have hankata so it get automatically converted to
1234 * zenkata. this means that strings 1 and 2 are identical as well as
1235 * strings 4 and 5.
1237 j = i;
1238 if (i == 2) j = 1;
1239 if (i == 5) j = 4;
1241 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i, hr);
1242 ok(destsz == unc_jp[j][0],"(%i) Expected %i, got %i\n",i,unc_jp[j][0],destsz);
1243 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1244 ok(memcmp(outputW,&unc_jp[j][1],destsz)==0,"(%i) Strings do not match\n",i);
1247 /* test unc->sjis */
1248 for (i = 0; i < 9; i++)
1250 destsz = 30;
1251 outlen = sjis_jp[i][0];
1252 srcsz = unc_jp[i][0];
1254 hr = pConvertINetUnicodeToMultiByte(NULL, 932, &unc_jp[i][1], &srcsz, output, &destsz);
1255 if (hr == S_FALSE)
1257 skip("Code page identifier 932 is not supported\n");
1258 break;
1260 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1261 ok(destsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,destsz);
1262 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],srcsz);
1263 ok(memcmp(output,&sjis_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1265 srcsz = outlen;
1266 destsz = 30;
1267 hr = pConvertINetMultiByteToUnicode(NULL, 932, output, &srcsz, outputW,&destsz);
1269 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n", i, hr);
1270 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1271 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1272 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1275 /* test unc->euc */
1276 for (i = 0; i < 9; i++)
1278 destsz = 30;
1279 outlen = euc_jp[i][0];
1280 srcsz = unc_jp[i][0];
1282 hr = pConvertINetUnicodeToMultiByte(NULL, 51932, &unc_jp[i][1], &srcsz, output, &destsz);
1283 if (hr == S_FALSE)
1285 skip("Code page identifier 51932 is not supported\n");
1286 break;
1288 ok(hr == S_OK, "(%i) Expected S_OK, got %08x\n",i,hr);
1289 ok(destsz == outlen, "(%i) Expected %i, got %i\n",i,outlen,destsz);
1290 ok(srcsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1291 ok(memcmp(output,&euc_jp[i][1],outlen)==0,"(%i) Strings do not match\n",i);
1293 srcsz = outlen;
1294 destsz = 30;
1295 hr = pConvertINetMultiByteToUnicode(NULL, 51932, output, &srcsz, outputW,&destsz);
1297 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1298 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1299 ok(srcsz == outlen,"(%i) Expected %i, got %i\n",i,outlen,srcsz);
1300 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1303 /* Japanese autodetect */
1304 i = 0;
1305 destsz = 30;
1306 srcsz = jis_jp[i][0];
1307 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &jis_jp[i][1], &srcsz, outputW, &destsz);
1308 if (hr == S_FALSE)
1310 skip("Code page identifier 50932 is not supported\n");
1311 return;
1313 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1314 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1315 ok(srcsz == jis_jp[i][0],"(%i) Expected %i, got %i\n",i,jis_jp[i][0],srcsz);
1316 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1318 i = 1;
1319 destsz = 30;
1320 srcsz = sjis_jp[i][0];
1321 hr = pConvertINetMultiByteToUnicode(NULL, 50932, &sjis_jp[i][1], &srcsz, outputW, &destsz);
1322 ok(hr == S_OK,"(%i) Expected S_OK, got %08x\n",i,hr);
1323 ok(destsz == unc_jp[i][0],"(%i) Expected %i, got %i\n",i,unc_jp[i][0],destsz);
1324 ok(srcsz == sjis_jp[i][0],"(%i) Expected %i, got %i\n",i,sjis_jp[i][0],srcsz);
1325 ok(memcmp(outputW,&unc_jp[i][1],destsz)==0,"(%i) Strings do not match\n",i);
1328 START_TEST(mlang)
1330 IMultiLanguage2 *iML2 = NULL;
1331 IMLangFontLink *iMLFL = NULL;
1332 HRESULT ret;
1334 if (!init_function_ptrs())
1335 return;
1337 CoInitialize(NULL);
1338 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1339 &IID_IMultiLanguage2, (void **)&iML2);
1340 if (ret != S_OK || !iML2) return;
1342 test_rfc1766(iML2);
1343 test_GetLcidFromRfc1766(iML2);
1344 test_GetRfc1766FromLcid(iML2);
1346 test_EnumCodePages(iML2, 0);
1347 test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
1348 test_EnumCodePages(iML2, MIMECONTF_BROWSER);
1349 test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
1350 test_EnumCodePages(iML2, MIMECONTF_VALID);
1351 /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
1352 /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/
1354 test_EnumScripts(iML2, 0);
1355 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
1356 test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);
1358 ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
1359 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
1360 ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
1361 ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
1363 test_multibyte_to_unicode_translations(iML2);
1364 test_IMultiLanguage2_ConvertStringFromUnicode(iML2);
1366 IMultiLanguage2_Release(iML2);
1368 test_ConvertINetUnicodeToMultiByte();
1370 test_JapaneseConversion();
1372 ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
1373 &IID_IMLangFontLink, (void **)&iMLFL);
1374 if (ret != S_OK || !iML2) return;
1376 IMLangFontLink_Test(iMLFL);
1377 IMLangFontLink_Release(iMLFL);
1379 CoUninitialize();