mlang.c 34.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Unit test suite for MLANG APIs.
 *
 * Copyright 2004 Dmitry Timoshkov
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35
 */

#define COBJMACROS

#include <stdarg.h>

#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "mlang.h"

#include "wine/test.h"

#ifndef CP_UNICODE
#define CP_UNICODE 1200
#endif

36 37 38
#if 0
#define DUMP_CP_INFO
#define DUMP_SCRIPT_INFO
39

40
#if defined DUMP_CP_INFO || defined DUMP_SCRIPT_INFO
41 42
#include "wine/debug.h"
#endif
43
#endif /* 0 */
44

45 46
#define TRACE_2 OutputDebugStringA

47 48 49 50 51 52 53 54 55 56 57
static CHAR string1[MAX_PATH], string2[MAX_PATH];

#define ok_w2(format, szString1, szString2) \
\
    if (lstrcmpW(szString1, szString2) != 0) \
    { \
        WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
        WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
        ok(0, format, string1, string2); \
    }

58 59
static BOOL (WINAPI *pGetCPInfoExA)(UINT,DWORD,LPCPINFOEXA);

60 61 62 63 64 65 66
static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
{
    /* these APIs are broken regarding constness of the input buffer */
    char stringA[] = "Just a test string\0"; /* double 0 for CP_UNICODE tests */
    WCHAR stringW[] = {'J','u','s','t',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0};
    char bufA[256];
    WCHAR bufW[256];
Mike McCormack's avatar
Mike McCormack committed
67
    UINT lenA, lenW, expected_len;
68
    HRESULT ret;
69 70 71 72 73 74 75 76 77 78 79
    HMODULE hMlang;
    FARPROC pConvertINetMultiByteToUnicode;
    FARPROC pConvertINetUnicodeToMultiByte;

    hMlang = LoadLibraryA("mlang.dll");
    ok(hMlang != 0, "couldn't load mlang.dll\n");

    pConvertINetMultiByteToUnicode = GetProcAddress(hMlang, "ConvertINetMultiByteToUnicode");
    ok(pConvertINetMultiByteToUnicode != NULL, "couldn't resolve ConvertINetMultiByteToUnicode\n");
    pConvertINetUnicodeToMultiByte = GetProcAddress(hMlang, "ConvertINetUnicodeToMultiByte");
    ok(pConvertINetUnicodeToMultiByte != NULL, "couldn't resolve ConvertINetUnicodeToMultiByte\n");
80 81 82 83 84 85 86 87

    /* IMultiLanguage2_ConvertStringToUnicode tests */

    memset(bufW, 'x', sizeof(bufW));
    lenA = 0;
    lenW = sizeof(bufW)/sizeof(bufW[0]);
    TRACE_2("Call IMultiLanguage2_ConvertStringToUnicode\n");
    ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
88
    ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
89 90 91 92 93 94 95 96
    ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
    ok(lenW == 0, "expected lenW 0, got %u\n", lenW);

    memset(bufW, 'x', sizeof(bufW));
    lenA = -1;
    lenW = sizeof(bufW)/sizeof(bufW[0]);
    TRACE_2("Call IMultiLanguage2_ConvertStringToUnicode\n");
    ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
97
    ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
98 99
    ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
    ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
100 101 102 103 104
    if (lenW < sizeof(bufW)/sizeof(bufW[0])) {
       /* can only happen if the convert call fails */
       ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
       bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
    }
105 106 107 108 109 110 111
    ok(!lstrcmpW(bufW, stringW), "bufW/stringW mismatch\n");

    memset(bufW, 'x', sizeof(bufW));
    lenA = -1;
    lenW = 5;
    TRACE_2("Call IMultiLanguage2_ConvertStringToUnicode\n");
    ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, bufW, &lenW);
112
    ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringToUnicode should fail: %08x\n", ret);
113 114 115 116 117 118 119 120 121
    ok(lenW == 0, "expected lenW 0, got %u\n", lenW);
    /* still has to do partial conversion */
    ok(!memcmp(bufW, stringW, 5 * sizeof(WCHAR)), "bufW/stringW mismatch\n");

    memset(bufW, 'x', sizeof(bufW));
    lenA = -1;
    lenW = sizeof(bufW)/sizeof(bufW[0]);
    TRACE_2("Call IMultiLanguage2_ConvertStringToUnicode\n");
    ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, CP_UNICODE, stringA, &lenA, bufW, &lenW);
122
    ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
123
    ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
124
    ok(lenW == lstrlenW(stringW)/(int)sizeof(WCHAR), "wrong lenW %u\n", lenW);
125 126 127 128
    ok(bufW[lenW] != 0, "buf should not be 0 terminated\n");
    bufW[lenW] = 0; /* -1 doesn't include 0 terminator */
    ok(!lstrcmpA((LPCSTR)bufW, stringA), "bufW/stringA mismatch\n");

129 130 131 132
    memset(bufW, 'x', sizeof(bufW));
    lenA = lstrlenA(stringA);
    lenW = 0;
    ret = IMultiLanguage2_ConvertStringToUnicode(iML2, NULL, 1252, stringA, &lenA, NULL, &lenW);
133
    ok(ret == S_OK, "IMultiLanguage2_ConvertStringToUnicode failed: %08x\n", ret);
134 135 136 137 138 139 140 141
    ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
    expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
    ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);

    memset(bufW, 'x', sizeof(bufW));
    lenA = lstrlenA(stringA);
    lenW = sizeof(bufW)/sizeof(bufW[0]);
    ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, &lenA, NULL, &lenW);
142
    ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
143 144 145 146 147 148 149 150
    ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
    expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
    ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);

    memset(bufW, 'x', sizeof(bufW));
    lenA = lstrlenA(stringA);
    lenW = 0;
    ret = pConvertINetMultiByteToUnicode(NULL, 1252, stringA, &lenA, NULL, &lenW);
151
    ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08x\n", ret);
152 153 154 155
    ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
    expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0);
    ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);

156 157 158 159 160 161 162
    /* IMultiLanguage2_ConvertStringFromUnicode tests */

    memset(bufA, 'x', sizeof(bufA));
    lenW = 0;
    lenA = sizeof(bufA);
    TRACE_2("Call IMultiLanguage2_ConvertStringFromUnicode\n");
    ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
163
    ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
164 165 166 167 168 169 170 171
    ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
    ok(lenW == 0, "expected lenW 0, got %u\n", lenW);

    memset(bufA, 'x', sizeof(bufA));
    lenW = -1;
    lenA = sizeof(bufA);
    TRACE_2("Call IMultiLanguage2_ConvertStringFromUnicode\n");
    ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
172
    ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
173 174 175 176 177 178 179 180 181 182 183
    ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
    ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
    ok(bufA[lenA] != 0, "buf should not be 0 terminated\n");
    bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
    ok(!lstrcmpA(bufA, stringA), "bufA/stringA mismatch\n");

    memset(bufA, 'x', sizeof(bufA));
    lenW = -1;
    lenA = 5;
    TRACE_2("Call IMultiLanguage2_ConvertStringFromUnicode\n");
    ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, bufA, &lenA);
184
    ok(ret == E_FAIL, "IMultiLanguage2_ConvertStringFromUnicode should fail: %08x\n", ret);
185 186 187 188 189 190 191 192 193
    ok(lenA == 0, "expected lenA 0, got %u\n", lenA);
    /* still has to do partial conversion */
    ok(!memcmp(bufA, stringA, 5), "bufW/stringW mismatch\n");

    memset(bufA, 'x', sizeof(bufA));
    lenW = -1;
    lenA = sizeof(bufA);
    TRACE_2("Call IMultiLanguage2_ConvertStringFromUnicode\n");
    ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, CP_UNICODE, stringW, &lenW, bufA, &lenA);
194
    ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
195
    ok(lenA == lstrlenA(stringA) * (int)sizeof(WCHAR), "wrong lenA %u\n", lenA);
196 197 198 199 200
    ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
    ok(bufA[lenA] != 0 && bufA[lenA+1] != 0, "buf should not be 0 terminated\n");
    bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
    bufA[lenA+1] = 0; /* sizeof(WCHAR) */
    ok(!lstrcmpW((LPCWSTR)bufA, stringW), "bufA/stringW mismatch\n");
201 202 203 204 205

    memset(bufA, 'x', sizeof(bufA));
    lenW = lstrlenW(stringW);
    lenA = 0;
    ret = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, 1252, stringW, &lenW, NULL, &lenA);
206
    ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
207 208 209 210 211 212 213 214
    ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
    expected_len = WideCharToMultiByte(1252, 0, stringW, lenW, NULL, 0, NULL, NULL);
    ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);

    memset(bufA, 'x', sizeof(bufA));
    lenW = lstrlenW(stringW);
    lenA = sizeof(bufA);
    ret = pConvertINetUnicodeToMultiByte(NULL, 1252, stringW, &lenW, NULL, &lenA);
215
    ok(ret == S_OK, "ConvertINetUnicodeToMultiByte failed: %08x\n", ret);
216 217 218 219 220 221 222 223
    ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
    expected_len = WideCharToMultiByte(1252, 0, stringW, lenW, NULL, 0, NULL, NULL);
    ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);

    memset(bufA, 'x', sizeof(bufA));
    lenW = lstrlenW(stringW);
    lenA = 0;
    ret = pConvertINetUnicodeToMultiByte(NULL, 1252, stringW, &lenW, NULL, &lenA);
224
    ok(ret == S_OK, "ConvertINetUnicodeToMultiByte failed: %08x\n", ret);
225 226 227
    ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
    expected_len = WideCharToMultiByte(1252, 0, stringW, lenW, NULL, 0, NULL, NULL);
    ok(lenA == expected_len, "expected lenA %u, got %u\n", expected_len, lenA);
228 229
}

230
static inline void cpinfo_cmp(MIMECPINFO *cpinfo1, MIMECPINFO *cpinfo2)
231
{
232
    ok(cpinfo1->dwFlags == cpinfo2->dwFlags, "dwFlags mismatch: %08x != %08x\n", cpinfo1->dwFlags, cpinfo2->dwFlags);
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
    ok(cpinfo1->uiCodePage == cpinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", cpinfo1->uiCodePage, cpinfo2->uiCodePage);
    ok(cpinfo1->uiFamilyCodePage == cpinfo2->uiFamilyCodePage, "uiFamilyCodePage mismatch: %u != %u\n", cpinfo1->uiFamilyCodePage, cpinfo2->uiFamilyCodePage);
    ok(!lstrcmpW(cpinfo1->wszDescription, cpinfo2->wszDescription), "wszDescription mismatch\n");
    ok(!lstrcmpW(cpinfo1->wszWebCharset, cpinfo2->wszWebCharset), "wszWebCharset mismatch\n");
    ok(!lstrcmpW(cpinfo1->wszHeaderCharset, cpinfo2->wszHeaderCharset), "wszHeaderCharset mismatch\n");
    ok(!lstrcmpW(cpinfo1->wszBodyCharset, cpinfo2->wszBodyCharset), "wszBodyCharset mismatch\n");
    ok(!lstrcmpW(cpinfo1->wszFixedWidthFont, cpinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
    ok(!lstrcmpW(cpinfo1->wszProportionalFont, cpinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
    ok(cpinfo1->bGDICharset == cpinfo2->bGDICharset, "bGDICharset mismatch: %d != %d\n", cpinfo1->bGDICharset, cpinfo2->bGDICharset);
}

#ifdef DUMP_CP_INFO
static const char *dump_mime_flags(DWORD flags)
{
    static char buf[1024];

    buf[0] = 0;

    if (flags & MIMECONTF_MAILNEWS) strcat(buf, " MIMECONTF_MAILNEWS");
    if (flags & MIMECONTF_BROWSER) strcat(buf, " MIMECONTF_BROWSER");
    if (flags & MIMECONTF_MINIMAL) strcat(buf, " MIMECONTF_MINIMAL");
    if (flags & MIMECONTF_IMPORT) strcat(buf, " MIMECONTF_IMPORT");
    if (flags & MIMECONTF_SAVABLE_MAILNEWS) strcat(buf, " MIMECONTF_SAVABLE_MAILNEWS");
    if (flags & MIMECONTF_SAVABLE_BROWSER) strcat(buf, " MIMECONTF_SAVABLE_BROWSER");
    if (flags & MIMECONTF_EXPORT) strcat(buf, " MIMECONTF_EXPORT");
    if (flags & MIMECONTF_PRIVCONVERTER) strcat(buf, " MIMECONTF_PRIVCONVERTER");
    if (flags & MIMECONTF_VALID) strcat(buf, " MIMECONTF_VALID");
    if (flags & MIMECONTF_VALID_NLS) strcat(buf, " MIMECONTF_VALID_NLS");
    if (flags & MIMECONTF_MIME_IE4) strcat(buf, " MIMECONTF_MIME_IE4");
    if (flags & MIMECONTF_MIME_LATEST) strcat(buf, " MIMECONTF_MIME_LATEST");
    if (flags & MIMECONTF_MIME_REGISTRY) strcat(buf, " MIMECONTF_MIME_REGISTRY");

    return buf;
}
#endif

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
static BOOL check_convertible(IMultiLanguage2 *iML2, UINT from, UINT to)
{
    CHAR convert[MAX_PATH];
    BYTE dest[MAX_PATH];
    HRESULT hr;
    UINT srcsz, destsz;

    static WCHAR strW[] = {'a','b','c',0};

    srcsz = -1;
    destsz = MAX_PATH;
    hr = IMultiLanguage2_ConvertStringFromUnicode(iML2, NULL, from, strW,
                                                  &srcsz, convert, &destsz);
    if (hr != S_OK)
        return FALSE;

    srcsz = -1;
    destsz = MAX_PATH;
    hr = IMultiLanguage2_ConvertString(iML2, NULL, from, to, (BYTE *)convert,
                                       &srcsz, dest, &destsz);
    if (hr != S_OK)
        return FALSE;

    return TRUE;
}

295 296 297 298 299 300 301 302 303 304 305 306
static void test_EnumCodePages(IMultiLanguage2 *iML2, DWORD flags)
{
    IEnumCodePage *iEnumCP = NULL;
    MIMECPINFO *cpinfo;
    MIMECPINFO cpinfo2;
    HRESULT ret;
    ULONG i, n;
    UINT total;

    total = 0;
    TRACE_2("Call IMultiLanguage2_GetNumberOfCodePageInfo\n");
    ret = IMultiLanguage2_GetNumberOfCodePageInfo(iML2, &total);
307
    ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfCodePageInfo: expected S_OK/!0, got %08x/%u\n", ret, total);
308 309 310 311 312

    trace("total mlang supported codepages %u\n", total);

    TRACE_2("Call IMultiLanguage2_EnumCodePages\n");
    ret = IMultiLanguage2_EnumCodePages(iML2, flags, LANG_NEUTRAL, &iEnumCP);
313 314
    trace("IMultiLanguage2_EnumCodePages = %08x, iEnumCP = %p\n", ret, iEnumCP);
    ok(ret == S_OK && iEnumCP, "IMultiLanguage2_EnumCodePages: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumCP);
315 316 317

    TRACE_2("Call IEnumCodePage_Reset\n");
    ret = IEnumCodePage_Reset(iEnumCP);
318
    ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
319 320 321
    n = 65536;
    TRACE_2("Call IEnumCodePage_Next\n");
    ret = IEnumCodePage_Next(iEnumCP, 0, NULL, &n);
322
    ok(n == 0 && ret == S_FALSE, "IEnumCodePage_Next: expected 0/S_FALSE, got %u/%08x\n", n, ret);
323 324
    TRACE_2("Call IEnumCodePage_Next\n");
    ret = IEnumCodePage_Next(iEnumCP, 0, NULL, NULL);
325
    ok(ret == S_FALSE, "IEnumCodePage_Next: expected S_FALSE, got %08x\n", ret);
326 327 328 329 330 331

    cpinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*cpinfo) * total * 2);

    n = total * 2;
    TRACE_2("Call IEnumCodePage_Next\n");
    ret = IEnumCodePage_Next(iEnumCP, 0, cpinfo, &n);
332 333
    trace("IEnumCodePage_Next = %08x, n = %u\n", ret, n);
    ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
334 335 336 337

    n = total * 2;
    TRACE_2("Call IEnumCodePage_Next\n");
    ret = IEnumCodePage_Next(iEnumCP, n, cpinfo, &n);
338
    ok(ret == S_OK && n != 0, "IEnumCodePage_Next: expected S_OK/!0, got %08x/%u\n", ret, n);
339

340
    trace("flags %08x, enumerated codepages %u\n", flags, n);
341 342 343

    if (!flags)
    {
344
	ok(n == total, "IEnumCodePage_Next: expected %u, got %u\n", total, n);
345 346 347 348 349 350 351 352 353

	flags = MIMECONTF_MIME_LATEST;
    }

    total = n;

    for (i = 0; i < n; i++)
    {
	CHARSETINFO csi;
354
	MIMECSETINFO mcsi;
355 356
        BOOL convertible;
        HRESULT check = S_OK;
357 358
	static const WCHAR autoW[] = {'_','a','u','t','o',0};

359
#ifdef DUMP_CP_INFO
360 361
	trace("MIMECPINFO #%u:\n"
	      "dwFlags %08x %s\n"
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
	      "uiCodePage %u\n"
	      "uiFamilyCodePage %u\n"
	      "wszDescription %s\n"
	      "wszWebCharset %s\n"
	      "wszHeaderCharset %s\n"
	      "wszBodyCharset %s\n"
	      "wszFixedWidthFont %s\n"
	      "wszProportionalFont %s\n"
	      "bGDICharset %d\n\n",
	      i,
	      cpinfo[i].dwFlags, dump_mime_flags(cpinfo[i].dwFlags),
	      cpinfo[i].uiCodePage,
	      cpinfo[i].uiFamilyCodePage,
	      wine_dbgstr_w(cpinfo[i].wszDescription),
	      wine_dbgstr_w(cpinfo[i].wszWebCharset),
	      wine_dbgstr_w(cpinfo[i].wszHeaderCharset),
	      wine_dbgstr_w(cpinfo[i].wszBodyCharset),
	      wine_dbgstr_w(cpinfo[i].wszFixedWidthFont),
	      wine_dbgstr_w(cpinfo[i].wszProportionalFont),
	      cpinfo[i].bGDICharset);
#endif
383
	ok(cpinfo[i].dwFlags & flags, "enumerated flags %08x do not include requested %08x\n", cpinfo[i].dwFlags, flags);
384 385 386 387 388 389

	if (TranslateCharsetInfo((DWORD *)cpinfo[i].uiFamilyCodePage, &csi, TCI_SRCCODEPAGE))
	    ok(cpinfo[i].bGDICharset == csi.ciCharset, "%d != %d\n", cpinfo[i].bGDICharset, csi.ciCharset);
	else
	    trace("TranslateCharsetInfo failed for cp %u\n", cpinfo[i].uiFamilyCodePage);

390
        trace("%u: codepage %u family %u\n", i, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
391 392 393 394 395 396 397 398 399 400 401

        /* Win95 does not support UTF-7 */
        if (cpinfo[i].uiCodePage == CP_UTF7) continue;

	/* support files for some codepages might be not installed, or
	 * the codepage is just an alias.
	 */
	if (IsValidCodePage(cpinfo[i].uiCodePage))
	{
	    TRACE_2("Call IMultiLanguage2_IsConvertible\n");
	    ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UNICODE);
402
	    ok(ret == S_OK, "IMultiLanguage2_IsConvertible(%u -> CP_UNICODE) = %08x\n", cpinfo[i].uiCodePage, ret);
403 404
	    TRACE_2("Call IMultiLanguage2_IsConvertible\n");
	    ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, cpinfo[i].uiCodePage);
405
	    ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
406

407 408 409 410
            convertible = check_convertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
            if (!convertible)
                check = S_FALSE;

411 412
	    TRACE_2("Call IMultiLanguage2_IsConvertible\n");
	    ret = IMultiLanguage2_IsConvertible(iML2, cpinfo[i].uiCodePage, CP_UTF8);
413
	    ok(ret == check, "IMultiLanguage2_IsConvertible(%u -> CP_UTF8) = %08x\n", cpinfo[i].uiCodePage, ret);
414 415
	    TRACE_2("Call IMultiLanguage2_IsConvertible\n");
	    ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, cpinfo[i].uiCodePage);
416
	    ok(ret == check, "IMultiLanguage2_IsConvertible(CP_UTF8 -> %u) = %08x\n", cpinfo[i].uiCodePage, ret);
417 418 419 420
	}
	else
	    trace("IsValidCodePage failed for cp %u\n", cpinfo[i].uiCodePage);

421 422 423 424
	ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszWebCharset, &mcsi);
	/* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
	if (memcmp(cpinfo[i].wszWebCharset, autoW, 5 * sizeof(WCHAR)))
	{
425
	    ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
426 427 428 429 430 431 432 433
#ifdef DUMP_CP_INFO
	    trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszWebCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
#endif
	    ok(!lstrcmpiW(cpinfo[i].wszWebCharset, mcsi.wszCharset),
#ifdef DUMP_CP_INFO
                "%s != %s\n",
		wine_dbgstr_w(cpinfo[i].wszWebCharset), wine_dbgstr_w(mcsi.wszCharset));
#else
434
                "wszWebCharset mismatch\n");
435 436
#endif

437 438 439
	if (0)
	{
	    /* native mlang returns completely messed up encodings in some cases */
440 441 442 443
	    ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
		"%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
	    ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
		"%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
444
        }
445 446 447 448 449 450
	}

	ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszHeaderCharset, &mcsi);
	/* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
	if (memcmp(cpinfo[i].wszHeaderCharset, autoW, 5 * sizeof(WCHAR)))
	{
451
	    ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
452 453 454 455 456 457 458 459
#ifdef DUMP_CP_INFO
	    trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszHeaderCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
#endif
	    ok(!lstrcmpiW(cpinfo[i].wszHeaderCharset, mcsi.wszCharset),
#ifdef DUMP_CP_INFO
                "%s != %s\n",
		wine_dbgstr_w(cpinfo[i].wszHeaderCharset), wine_dbgstr_w(mcsi.wszCharset));
#else
460
                "wszHeaderCharset mismatch\n");
461 462
#endif

463 464 465
	if (0)
	{
	    /* native mlang returns completely messed up encodings in some cases */
466 467 468 469
	    ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
		"%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
	    ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
		"%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
470
	}
471 472 473 474 475 476
	}

	ret = IMultiLanguage2_GetCharsetInfo(iML2, cpinfo[i].wszBodyCharset, &mcsi);
	/* _autoxxx charsets are a fake and GetCharsetInfo fails for them */
	if (memcmp(cpinfo[i].wszBodyCharset, autoW, 5 * sizeof(WCHAR)))
	{
477
	    ok (ret == S_OK, "IMultiLanguage2_GetCharsetInfo failed: %08x\n", ret);
478 479 480 481 482 483 484 485
#ifdef DUMP_CP_INFO
	    trace("%s: %u %u %s\n", wine_dbgstr_w(cpinfo[i].wszBodyCharset), mcsi.uiCodePage, mcsi.uiInternetEncoding, wine_dbgstr_w(mcsi.wszCharset));
#endif
	    ok(!lstrcmpiW(cpinfo[i].wszBodyCharset, mcsi.wszCharset),
#ifdef DUMP_CP_INFO
                "%s != %s\n",
		wine_dbgstr_w(cpinfo[i].wszBodyCharset), wine_dbgstr_w(mcsi.wszCharset));
#else
486
                "wszBodyCharset mismatch\n");
487 488
#endif

489 490 491
	if (0)
	{
	    /* native mlang returns completely messed up encodings in some cases */
492 493 494 495
	    ok(mcsi.uiInternetEncoding == cpinfo[i].uiCodePage || mcsi.uiInternetEncoding == cpinfo[i].uiFamilyCodePage,
		"%u != %u || %u\n", mcsi.uiInternetEncoding, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
	    ok(mcsi.uiCodePage == cpinfo[i].uiCodePage || mcsi.uiCodePage == cpinfo[i].uiFamilyCodePage,
		"%u != %u || %u\n", mcsi.uiCodePage, cpinfo[i].uiCodePage, cpinfo[i].uiFamilyCodePage);
496
	}
497
	}
498 499 500 501 502
    }

    /* now IEnumCodePage_Next should fail, since pointer is at the end */
    n = 1;
    ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
503
    ok(ret == S_FALSE && n == 0, "IEnumCodePage_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
504 505

    ret = IEnumCodePage_Reset(iEnumCP);
506
    ok(ret == S_OK, "IEnumCodePage_Reset: expected S_OK, got %08x\n", ret);
507 508
    n = 0;
    ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
509
    ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
510 511
    cpinfo_cmp(&cpinfo[0], &cpinfo2);

512 513
    if (0)
    {
514 515 516 517
    /* Due to a bug in MS' implementation of IEnumCodePage_Skip
     * it's not used here.
     */
    ret = IEnumCodePage_Skip(iEnumCP, 1);
518
    ok(ret == S_OK, "IEnumCodePage_Skip: expected S_OK, got %08x\n", ret);
519
    }
520 521 522 523
    for (i = 0; i < total - 1; i++)
    {
        n = 0;
        ret = IEnumCodePage_Next(iEnumCP, 1, &cpinfo2, &n);
524
        ok(n == 1 && ret == S_OK, "IEnumCodePage_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
525 526 527 528 529 530 531
        cpinfo_cmp(&cpinfo[i + 1], &cpinfo2);
    }

    HeapFree(GetProcessHeap(), 0, cpinfo);
    IEnumCodePage_Release(iEnumCP);
}

532
static inline void scriptinfo_cmp(SCRIPTINFO *sinfo1, SCRIPTINFO *sinfo2)
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
{
    ok(sinfo1->ScriptId == sinfo2->ScriptId, "ScriptId mismatch: %d != %d\n", sinfo1->ScriptId, sinfo2->ScriptId);
    ok(sinfo1->uiCodePage == sinfo2->uiCodePage, "uiCodePage mismatch: %u != %u\n", sinfo1->uiCodePage, sinfo2->uiCodePage);
    ok(!lstrcmpW(sinfo1->wszDescription, sinfo2->wszDescription), "wszDescription mismatch\n");
    ok(!lstrcmpW(sinfo1->wszFixedWidthFont, sinfo2->wszFixedWidthFont), "wszFixedWidthFont mismatch\n");
    ok(!lstrcmpW(sinfo1->wszProportionalFont, sinfo2->wszProportionalFont), "wszProportionalFont mismatch\n");
}

static void test_EnumScripts(IMultiLanguage2 *iML2, DWORD flags)
{
    IEnumScript *iEnumScript = NULL;
    SCRIPTINFO *sinfo;
    SCRIPTINFO sinfo2;
    HRESULT ret;
    ULONG i, n;
    UINT total;

    total = 0;
    TRACE_2("Call IMultiLanguage2_GetNumberOfScripts\n");
    ret = IMultiLanguage2_GetNumberOfScripts(iML2, &total);
553
    ok(ret == S_OK && total != 0, "IMultiLanguage2_GetNumberOfScripts: expected S_OK/!0, got %08x/%u\n", ret, total);
554 555 556 557 558

    trace("total mlang supported scripts %u\n", total);

    TRACE_2("Call IMultiLanguage2_EnumScripts\n");
    ret = IMultiLanguage2_EnumScripts(iML2, flags, LANG_NEUTRAL, &iEnumScript);
559 560
    trace("IMultiLanguage2_EnumScripts = %08x, iEnumScript = %p\n", ret, iEnumScript);
    ok(ret == S_OK && iEnumScript, "IMultiLanguage2_EnumScripts: expected S_OK/!NULL, got %08x/%p\n", ret, iEnumScript);
561 562 563

    TRACE_2("Call IEnumScript_Reset\n");
    ret = IEnumScript_Reset(iEnumScript);
564
    ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
565 566 567
    n = 65536;
    TRACE_2("Call IEnumScript_Next\n");
    ret = IEnumScript_Next(iEnumScript, 0, NULL, &n);
568
    ok(n == 65536 && ret == E_FAIL, "IEnumScript_Next: expected 65536/E_FAIL, got %u/%08x\n", n, ret);
569 570
    TRACE_2("Call IEnumScript_Next\n");
    ret = IEnumScript_Next(iEnumScript, 0, NULL, NULL);
571
    ok(ret == E_FAIL, "IEnumScript_Next: expected E_FAIL, got %08x\n", ret);
572 573 574 575 576 577

    sinfo = HeapAlloc(GetProcessHeap(), 0, sizeof(*sinfo) * total * 2);

    n = total * 2;
    TRACE_2("Call IEnumScript_Next\n");
    ret = IEnumScript_Next(iEnumScript, 0, sinfo, &n);
578
    ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
579 580 581 582

    n = total * 2;
    TRACE_2("Call IEnumScript_Next\n");
    ret = IEnumScript_Next(iEnumScript, n, sinfo, &n);
583
    ok(ret == S_OK && n != 0, "IEnumScript_Next: expected S_OK, got %08x/%u\n", ret, n);
584

585
    trace("flags %08x, enumerated scripts %u\n", flags, n);
586 587 588

    if (!flags)
    {
589
	ok(n == total, "IEnumScript_Next: expected %u, got %u\n", total, n);
590 591 592 593 594
	flags = SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM;
    }

    total = n;

595
    for (i = 0; pGetCPInfoExA && i < n; i++)
596 597
    {
#ifdef DUMP_SCRIPT_INFO
598
	trace("SCRIPTINFO #%u:\n"
599
	      "ScriptId %08x\n"
600 601 602 603 604 605 606 607 608 609 610
	      "uiCodePage %u\n"
	      "wszDescription %s\n"
	      "wszFixedWidthFont %s\n"
	      "wszProportionalFont %s\n\n",
	      i,
	      sinfo[i].ScriptId,
	      sinfo[i].uiCodePage,
	      wine_dbgstr_w(sinfo[i].wszDescription),
	      wine_dbgstr_w(sinfo[i].wszFixedWidthFont),
	      wine_dbgstr_w(sinfo[i].wszProportionalFont));
#endif
611
        trace("%u codepage %u\n", i, sinfo[i].uiCodePage);
612 613 614 615 616
    }

    /* now IEnumScript_Next should fail, since pointer is at the end */
    n = 1;
    ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
617
    ok(ret == S_FALSE && n == 0, "IEnumScript_Next: expected S_FALSE/0, got %08x/%u\n", ret, n);
618 619

    ret = IEnumScript_Reset(iEnumScript);
620
    ok(ret == S_OK, "IEnumScript_Reset: expected S_OK, got %08x\n", ret);
621 622
    n = 0;
    ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
623
    ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
624 625
    scriptinfo_cmp(&sinfo[0], &sinfo2);

626 627
    if (0)
    {
628 629 630 631
    /* Due to a bug in MS' implementation of IEnumScript_Skip
     * it's not used here.
     */
    ret = IEnumScript_Skip(iEnumScript, 1);
632
    ok(ret == S_OK, "IEnumScript_Skip: expected S_OK, got %08x\n", ret);
633
    }
634 635 636 637
    for (i = 0; i < total - 1; i++)
    {
        n = 0;
        ret = IEnumScript_Next(iEnumScript, 1, &sinfo2, &n);
638
        ok(n == 1 && ret == S_OK, "IEnumScript_Next: expected 1/S_OK, got %u/%08x\n", n, ret);
639 640 641 642 643 644 645
        scriptinfo_cmp(&sinfo[i + 1], &sinfo2);
    }

    HeapFree(GetProcessHeap(), 0, sinfo);
    IEnumScript_Release(iEnumScript);
}

646
static void IMLangFontLink_Test(IMLangFontLink* iMLFL)
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
{
    DWORD   dwCodePages = 0;
    DWORD   dwManyCodePages = 0;
    UINT    CodePage = 0;

    ok(IMLangFontLink_CodePageToCodePages(iMLFL, 932, &dwCodePages)==S_OK,
            "IMLangFontLink_CodePageToCodePages failed\n");
    ok (dwCodePages != 0, "No CodePages returned\n");
    ok(IMLangFontLink_CodePagesToCodePage(iMLFL, dwCodePages, 1035,
                &CodePage)==S_OK, 
            "IMLangFontLink_CodePagesToCodePage failed\n");
    ok(CodePage == 932, "Incorrect CodePage Returned (%i)\n",CodePage);

    ok(IMLangFontLink_CodePageToCodePages(iMLFL, 1252, &dwCodePages)==S_OK,
            "IMLangFontLink_CodePageToCodePages failed\n");
    dwManyCodePages = dwManyCodePages | dwCodePages;
    ok(IMLangFontLink_CodePageToCodePages(iMLFL, 1256, &dwCodePages)==S_OK,
            "IMLangFontLink_CodePageToCodePages failed\n");
    dwManyCodePages = dwManyCodePages | dwCodePages;
    ok(IMLangFontLink_CodePageToCodePages(iMLFL, 874, &dwCodePages)==S_OK,
            "IMLangFontLink_CodePageToCodePages failed\n");
    dwManyCodePages = dwManyCodePages | dwCodePages;

    ok(IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 1256,
                &CodePage)==S_OK, 
            "IMLangFontLink_CodePagesToCodePage failed\n");
    ok(CodePage == 1256, "Incorrect CodePage Returned (%i)\n",CodePage);

    ok(IMLangFontLink_CodePagesToCodePage(iMLFL, dwManyCodePages, 936,
                &CodePage)==S_OK, 
            "IMLangFontLink_CodePagesToCodePage failed\n");
    ok(CodePage == 1252, "Incorrect CodePage Returned (%i)\n",CodePage);
}

681 682 683 684 685 686 687 688 689 690 691 692 693
/* copied from libs/wine/string.c */
WCHAR *strstrW(const WCHAR *str, const WCHAR *sub)
{
    while (*str)
    {
        const WCHAR *p1 = str, *p2 = sub;
        while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
        if (!*p2) return (WCHAR *)str;
        str++;
    }
    return NULL;
}

694 695 696 697 698 699
static void test_rfc1766(IMultiLanguage2 *iML2)
{
    IEnumRfc1766 *pEnumRfc1766;
    RFC1766INFO info;
    ULONG n;
    HRESULT ret;
700
    BSTR rfcstr;
701 702

    ret = IMultiLanguage2_EnumRfc1766(iML2, LANG_NEUTRAL, &pEnumRfc1766);
703
    ok(ret == S_OK, "IMultiLanguage2_EnumRfc1766 error %08x\n", ret);
704 705 706 707 708 709 710

    while (1)
    {
        ret = IEnumRfc1766_Next(pEnumRfc1766, 1, &info, &n);
        if (ret != S_OK) break;

#ifdef DUMP_CP_INFO
711
        trace("lcid %04x rfc_name %s locale_name %s\n",
712 713 714 715
              info.lcid, wine_dbgstr_w(info.wszRfc1766), wine_dbgstr_w(info.wszLocaleName));
#endif

        ok(n == 1, "couldn't fetch 1 RFC1766INFO structure\n");
716 717 718 719 720 721 722 723 724 725 726

        /* verify the Rfc1766 value */
        ret = IMultiLanguage2_GetRfc1766FromLcid(iML2, info.lcid, &rfcstr);
        ok(ret == S_OK, "Expected S_OK, got %08x\n", ret);

        /* not an exact 1:1 correspondence between lcid and rfc1766 in the
         * mlang database, e.g., nb-no -> 1044 -> no */
        ok(strstrW(info.wszRfc1766, rfcstr) != NULL,
           "Expected matching locale names\n");

        SysFreeString(rfcstr);
727
    }
728
    IEnumRfc1766_Release(pEnumRfc1766);
729 730
}

731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
static void test_GetLcidFromRfc1766(IMultiLanguage2 *iML2)
{
    LCID lcid;
    HRESULT ret;

    static WCHAR e[] = { 'e',0 };
    static WCHAR en[] = { 'e','n',0 };
    static WCHAR empty[] = { 0 };
    static WCHAR dash[] = { '-',0 };
    static WCHAR e_dash[] = { 'e','-',0 };
    static WCHAR en_gb[] = { 'e','n','-','g','b',0 };
    static WCHAR en_us[] = { 'e','n','-','u','s',0 };
    static WCHAR en_them[] = { 'e','n','-','t','h','e','m',0 };
    static WCHAR english[] = { 'e','n','g','l','i','s','h',0 };

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, NULL, en);
    ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, NULL);
    ok(ret == E_INVALIDARG, "GetLcidFromRfc1766 returned: %08x\n", ret);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, e);
    ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, empty);
    ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, dash);
    ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, e_dash);
    ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_them);
    ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, english);
    ok(ret == E_FAIL, "GetLcidFromRfc1766 returned: %08x\n", ret);

    lcid = 0;

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en);
    ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
    ok(lcid == 9, "got wrong lcid: %04x\n", lcid);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_gb);
    ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
    ok(lcid == 0x809, "got wrong lcid: %04x\n", lcid);

    ret = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, en_us);
    ok(ret == S_OK, "GetLcidFromRfc1766 returned: %08x\n", ret);
    ok(lcid == 0x409, "got wrong lcid: %04x\n", lcid);
}

785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802
static void test_GetRfc1766FromLcid(IMultiLanguage2 *iML2)
{
    HRESULT hr;
    BSTR rfcstr;
    LCID lcid;

    static WCHAR kok[] = {'k','o','k',0};

    hr = IMultiLanguage2_GetLcidFromRfc1766(iML2, &lcid, kok);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    hr = IMultiLanguage2_GetRfc1766FromLcid(iML2, lcid, &rfcstr);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
    ok_w2("Expected \"%s\",  got \"%s\"n", kok, rfcstr);

    SysFreeString(rfcstr);
}

803 804 805
START_TEST(mlang)
{
    IMultiLanguage2 *iML2 = NULL;
806
    IMLangFontLink  *iMLFL = NULL;
807 808
    HRESULT ret;

809 810
    pGetCPInfoExA = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetCPInfoExA");

811 812 813 814 815
    CoInitialize(NULL);
    TRACE_2("Call CoCreateInstance\n");
    ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
                           &IID_IMultiLanguage2, (void **)&iML2);

816
    trace("ret = %08x, MultiLanguage2 iML2 = %p\n", ret, iML2);
817 818
    if (ret != S_OK || !iML2) return;

819
    test_rfc1766(iML2);
820
    test_GetLcidFromRfc1766(iML2);
821
    test_GetRfc1766FromLcid(iML2);
822

823 824 825 826 827 828 829 830
    test_EnumCodePages(iML2, 0);
    test_EnumCodePages(iML2, MIMECONTF_MIME_LATEST);
    test_EnumCodePages(iML2, MIMECONTF_BROWSER);
    test_EnumCodePages(iML2, MIMECONTF_MINIMAL);
    test_EnumCodePages(iML2, MIMECONTF_VALID);
    /* FIXME: why MIMECONTF_MIME_REGISTRY returns 0 of supported codepages? */
    /*test_EnumCodePages(iML2, MIMECONTF_MIME_REGISTRY);*/

831 832 833 834
    test_EnumScripts(iML2, 0);
    test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER);
    test_EnumScripts(iML2, SCRIPTCONTF_SCRIPT_USER | SCRIPTCONTF_SCRIPT_HIDE | SCRIPTCONTF_SCRIPT_SYSTEM);

835 836
    TRACE_2("Call IMultiLanguage2_IsConvertible\n");
    ret = IMultiLanguage2_IsConvertible(iML2, CP_UTF8, CP_UNICODE);
837
    ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UTF8 -> CP_UNICODE) = %08x\n", ret);
838 839
    TRACE_2("Call IMultiLanguage2_IsConvertible\n");
    ret = IMultiLanguage2_IsConvertible(iML2, CP_UNICODE, CP_UTF8);
840
    ok(ret == S_OK, "IMultiLanguage2_IsConvertible(CP_UNICODE -> CP_UTF8) = %08x\n", ret);
841 842 843 844 845

    test_multibyte_to_unicode_translations(iML2);

    IMultiLanguage2_Release(iML2);

846 847 848
    ret = CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER,
                           &IID_IMLangFontLink, (void **)&iMLFL);

849
    trace("ret = %08x, IMLangFontLink iMLFL = %p\n", ret, iMLFL);
850 851 852 853 854
    if (ret != S_OK || !iML2) return;

    IMLangFontLink_Test(iMLFL);
    IMLangFontLink_Release(iMLFL);
    
855 856
    CoUninitialize();
}