2008-09-10 13:06:46 +02:00
|
|
|
/*
|
|
|
|
* MimeInternational tests
|
|
|
|
*
|
|
|
|
* Copyright 2008 Huw Davies
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "ocidl.h"
|
|
|
|
|
|
|
|
#include "mimeole.h"
|
|
|
|
|
2008-09-10 15:12:07 +02:00
|
|
|
#include "initguid.h"
|
|
|
|
#include "mlang.h"
|
|
|
|
|
2008-09-10 13:06:46 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
|
|
|
static void test_create(void)
|
|
|
|
{
|
|
|
|
IMimeInternational *internat, *internat2;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
hr = MimeOleGetInternat(&internat);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 13:06:46 +02:00
|
|
|
hr = MimeOleGetInternat(&internat2);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 13:06:46 +02:00
|
|
|
|
2008-10-29 06:13:13 +01:00
|
|
|
/* Under w2k8 it's no longer a singleton */
|
|
|
|
if(internat == internat2)
|
|
|
|
{
|
|
|
|
/* test to show that the object is a singleton with
|
|
|
|
a reference held by the dll. */
|
|
|
|
ref = IMimeInternational_Release(internat2);
|
2009-02-17 16:42:09 +01:00
|
|
|
ok(ref == 2 ||
|
|
|
|
ref == 1, /* win95 - object is a static singleton */
|
2022-02-28 08:26:45 +01:00
|
|
|
"got %ld\n", ref);
|
2008-10-29 06:13:13 +01:00
|
|
|
|
|
|
|
ref = IMimeInternational_Release(internat);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(ref == 1, "got %ld\n", ref);
|
2008-10-29 06:13:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ref = IMimeInternational_Release(internat2);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(ref == 0, "got %ld\n", ref);
|
2008-10-29 06:13:13 +01:00
|
|
|
|
|
|
|
ref = IMimeInternational_Release(internat);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(ref == 0, "got %ld\n", ref);
|
2008-10-29 06:13:13 +01:00
|
|
|
}
|
2008-09-10 13:06:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-10 15:12:07 +02:00
|
|
|
static inline HRESULT get_mlang(IMultiLanguage **ml)
|
|
|
|
{
|
|
|
|
return CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
|
|
|
|
&IID_IMultiLanguage, (void **)ml);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT mlang_getcsetinfo(const char *charset, MIMECSETINFO *mlang_info)
|
|
|
|
{
|
|
|
|
DWORD len = MultiByteToWideChar(CP_ACP, 0, charset, -1, NULL, 0);
|
|
|
|
BSTR bstr = SysAllocStringLen(NULL, len - 1);
|
|
|
|
HRESULT hr;
|
|
|
|
IMultiLanguage *ml;
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, charset, -1, bstr, len);
|
|
|
|
|
|
|
|
hr = get_mlang(&ml);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IMultiLanguage_GetCharsetInfo(ml, bstr, mlang_info);
|
|
|
|
IMultiLanguage_Release(ml);
|
|
|
|
}
|
|
|
|
SysFreeString(bstr);
|
|
|
|
if(FAILED(hr)) hr = MIME_E_NOT_FOUND;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-09-10 15:34:30 +02:00
|
|
|
static HRESULT mlang_getcodepageinfo(UINT cp, MIMECPINFO *mlang_cp_info)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IMultiLanguage *ml;
|
|
|
|
|
|
|
|
hr = get_mlang(&ml);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IMultiLanguage_GetCodePageInfo(ml, cp, mlang_cp_info);
|
|
|
|
IMultiLanguage_Release(ml);
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT mlang_getcsetinfo_from_cp(UINT cp, CHARSETTYPE charset_type, MIMECSETINFO *mlang_info)
|
|
|
|
{
|
|
|
|
MIMECPINFO mlang_cp_info;
|
|
|
|
WCHAR *charset_name;
|
|
|
|
HRESULT hr;
|
|
|
|
IMultiLanguage *ml;
|
|
|
|
|
|
|
|
hr = mlang_getcodepageinfo(cp, &mlang_cp_info);
|
|
|
|
if(FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
switch(charset_type)
|
|
|
|
{
|
|
|
|
case CHARSET_BODY:
|
|
|
|
charset_name = mlang_cp_info.wszBodyCharset;
|
|
|
|
break;
|
|
|
|
case CHARSET_HEADER:
|
|
|
|
charset_name = mlang_cp_info.wszHeaderCharset;
|
|
|
|
break;
|
|
|
|
case CHARSET_WEB:
|
|
|
|
charset_name = mlang_cp_info.wszWebCharset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = get_mlang(&ml);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IMultiLanguage_GetCharsetInfo(ml, charset_name, mlang_info);
|
|
|
|
IMultiLanguage_Release(ml);
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
2008-09-10 15:12:07 +02:00
|
|
|
|
2008-09-10 13:38:41 +02:00
|
|
|
static void test_charset(void)
|
|
|
|
{
|
|
|
|
IMimeInternational *internat;
|
|
|
|
HRESULT hr;
|
|
|
|
HCHARSET hcs, hcs_windows_1252, hcs_windows_1251;
|
2008-09-10 15:12:07 +02:00
|
|
|
INETCSETINFO cs_info;
|
|
|
|
MIMECSETINFO mlang_cs_info;
|
2008-09-10 13:38:41 +02:00
|
|
|
|
|
|
|
hr = MimeOleGetInternat(&internat);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 13:38:41 +02:00
|
|
|
|
2010-03-20 15:24:53 +01:00
|
|
|
hr = IMimeInternational_FindCharset(internat, "nonexistent", &hcs);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == MIME_E_NOT_FOUND, "got %08lx\n", hr);
|
2008-09-10 13:38:41 +02:00
|
|
|
|
|
|
|
hr = IMimeInternational_FindCharset(internat, "windows-1252", &hcs_windows_1252);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
2008-09-10 13:38:41 +02:00
|
|
|
hr = IMimeInternational_FindCharset(internat, "windows-1252", &hcs);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
2008-09-10 13:38:41 +02:00
|
|
|
ok(hcs_windows_1252 == hcs, "got different hcharsets for the same name\n");
|
2008-09-22 11:50:06 +02:00
|
|
|
hr = IMimeInternational_FindCharset(internat, "WiNdoWs-1252", &hcs);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
2008-09-22 11:50:06 +02:00
|
|
|
ok(hcs_windows_1252 == hcs, "got different hcharsets for the same name\n");
|
2008-09-10 13:38:41 +02:00
|
|
|
|
|
|
|
hr = IMimeInternational_FindCharset(internat, "windows-1251", &hcs_windows_1251);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
2008-09-10 13:38:41 +02:00
|
|
|
ok(hcs_windows_1252 != hcs_windows_1251, "got the same hcharset for the different names\n");
|
|
|
|
|
2008-09-10 15:12:07 +02:00
|
|
|
hr = IMimeInternational_GetCharsetInfo(internat, hcs_windows_1252, &cs_info);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
2008-09-10 15:12:07 +02:00
|
|
|
|
|
|
|
hr = mlang_getcsetinfo("windows-1252", &mlang_cs_info);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
|
|
|
ok(cs_info.cpiWindows == mlang_cs_info.uiCodePage, "cpiWindows %ld while mlang uiCodePage %d\n",
|
2008-09-10 15:12:07 +02:00
|
|
|
cs_info.cpiWindows, mlang_cs_info.uiCodePage);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(cs_info.cpiInternet == mlang_cs_info.uiInternetEncoding, "cpiInternet %ld while mlang uiInternetEncoding %d\n",
|
2008-09-10 15:12:07 +02:00
|
|
|
cs_info.cpiInternet, mlang_cs_info.uiInternetEncoding);
|
|
|
|
ok(cs_info.hCharset == hcs_windows_1252, "hCharset doesn't match requested\n");
|
|
|
|
ok(!strcmp(cs_info.szName, "windows-1252"), "szName doesn't match requested\n");
|
|
|
|
|
2008-09-10 15:34:30 +02:00
|
|
|
hr = IMimeInternational_GetCodePageCharset(internat, 1252, CHARSET_BODY, &hcs);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
2008-09-10 15:34:30 +02:00
|
|
|
hr = IMimeInternational_GetCharsetInfo(internat, hcs, &cs_info);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
2008-09-10 15:34:30 +02:00
|
|
|
|
|
|
|
hr = mlang_getcsetinfo_from_cp(1252, CHARSET_BODY, &mlang_cs_info);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
|
|
|
ok(cs_info.cpiWindows == mlang_cs_info.uiCodePage, "cpiWindows %ld while mlang uiCodePage %d\n",
|
2008-09-10 15:34:30 +02:00
|
|
|
cs_info.cpiWindows, mlang_cs_info.uiCodePage);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(cs_info.cpiInternet == mlang_cs_info.uiInternetEncoding, "cpiInternet %ld while mlang uiInternetEncoding %d\n",
|
2008-09-10 15:34:30 +02:00
|
|
|
cs_info.cpiInternet, mlang_cs_info.uiInternetEncoding);
|
|
|
|
|
2008-09-10 13:38:41 +02:00
|
|
|
IMimeInternational_Release(internat);
|
|
|
|
}
|
|
|
|
|
2008-09-10 15:42:42 +02:00
|
|
|
static void test_defaultcharset(void)
|
|
|
|
{
|
|
|
|
IMimeInternational *internat;
|
|
|
|
HRESULT hr;
|
2008-09-10 15:51:45 +02:00
|
|
|
HCHARSET hcs_default, hcs, hcs_windows_1251;
|
2008-09-10 15:42:42 +02:00
|
|
|
|
|
|
|
hr = MimeOleGetInternat(&internat);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 15:42:42 +02:00
|
|
|
|
|
|
|
hr = IMimeInternational_GetDefaultCharset(internat, &hcs_default);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 15:42:42 +02:00
|
|
|
hr = IMimeInternational_GetCodePageCharset(internat, GetACP(), CHARSET_BODY, &hcs);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 15:42:42 +02:00
|
|
|
ok(hcs_default == hcs, "Unexpected default charset\n");
|
|
|
|
|
2008-09-10 15:51:45 +02:00
|
|
|
hr = IMimeInternational_FindCharset(internat, "windows-1251", &hcs_windows_1251);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "got %08lx\n", hr);
|
2008-09-10 15:51:45 +02:00
|
|
|
hr = IMimeInternational_SetDefaultCharset(internat, hcs_windows_1251);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 15:51:45 +02:00
|
|
|
hr = IMimeInternational_GetDefaultCharset(internat, &hcs);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 15:51:45 +02:00
|
|
|
ok(hcs == hcs_windows_1251, "didn't retrieve recently set default\n");
|
|
|
|
/* Set the old default back again */
|
|
|
|
hr = IMimeInternational_SetDefaultCharset(internat, hcs_default);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-10 15:51:45 +02:00
|
|
|
|
2008-09-10 15:42:42 +02:00
|
|
|
IMimeInternational_Release(internat);
|
|
|
|
}
|
|
|
|
|
2008-09-15 13:40:22 +02:00
|
|
|
static void test_convert(void)
|
|
|
|
{
|
|
|
|
IMimeInternational *internat;
|
|
|
|
HRESULT hr;
|
|
|
|
BLOB src, dst;
|
|
|
|
ULONG read;
|
2008-09-16 12:49:02 +02:00
|
|
|
PROPVARIANT prop_in, prop_out;
|
|
|
|
static char test_string[] = "test string";
|
2020-10-23 11:20:01 +02:00
|
|
|
static WCHAR test_stringW[] = L"test string";
|
2008-09-15 13:40:22 +02:00
|
|
|
|
|
|
|
hr = MimeOleGetInternat(&internat);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-15 13:40:22 +02:00
|
|
|
|
|
|
|
src.pBlobData = (BYTE*)test_string;
|
|
|
|
src.cbSize = sizeof(test_string);
|
|
|
|
hr = IMimeInternational_ConvertBuffer(internat, 1252, 28591, &src, &dst, &read);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
|
|
|
ok(read == sizeof(test_string), "got %ld\n", read);
|
|
|
|
ok(dst.cbSize == sizeof(test_string), "got %ld\n", dst.cbSize);
|
2008-09-15 13:40:22 +02:00
|
|
|
CoTaskMemFree(dst.pBlobData);
|
|
|
|
|
|
|
|
src.cbSize = 2;
|
|
|
|
hr = IMimeInternational_ConvertBuffer(internat, 1252, 28591, &src, &dst, &read);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
|
|
|
ok(read == 2, "got %ld\n", read);
|
|
|
|
ok(dst.cbSize == 2, "got %ld\n", dst.cbSize);
|
2008-09-15 13:40:22 +02:00
|
|
|
CoTaskMemFree(dst.pBlobData);
|
|
|
|
|
2008-09-16 12:49:02 +02:00
|
|
|
prop_in.vt = VT_LPWSTR;
|
2021-03-27 16:02:06 +01:00
|
|
|
prop_in.pwszVal = test_stringW;
|
2008-09-16 12:49:02 +02:00
|
|
|
hr = IMimeInternational_ConvertString(internat, CP_UNICODE, 1252, &prop_in, &prop_out);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-16 12:49:02 +02:00
|
|
|
ok(prop_out.vt == VT_LPSTR, "got %d\n", prop_out.vt);
|
2021-03-27 16:02:06 +01:00
|
|
|
ok(!strcmp(prop_out.pszVal, test_string), "got %s\n", prop_out.pszVal);
|
2008-09-16 12:49:02 +02:00
|
|
|
PropVariantClear(&prop_out);
|
|
|
|
|
|
|
|
/* If in.vt is VT_LPWSTR, ignore cpiSrc */
|
|
|
|
prop_in.vt = VT_LPWSTR;
|
2021-03-27 16:02:06 +01:00
|
|
|
prop_in.pwszVal = test_stringW;
|
2008-09-16 12:49:02 +02:00
|
|
|
hr = IMimeInternational_ConvertString(internat, 28591, 1252, &prop_in, &prop_out);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-16 12:49:02 +02:00
|
|
|
ok(prop_out.vt == VT_LPSTR, "got %d\n", prop_out.vt);
|
2021-03-27 16:02:06 +01:00
|
|
|
ok(!strcmp(prop_out.pszVal, test_string), "got %s\n", prop_out.pszVal);
|
2008-09-16 12:49:02 +02:00
|
|
|
PropVariantClear(&prop_out);
|
|
|
|
|
|
|
|
prop_in.vt = VT_LPSTR;
|
2021-03-27 16:02:06 +01:00
|
|
|
prop_in.pszVal = test_string;
|
2008-09-16 12:49:02 +02:00
|
|
|
hr = IMimeInternational_ConvertString(internat, 28591, CP_UNICODE, &prop_in, &prop_out);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-16 12:49:02 +02:00
|
|
|
ok(prop_out.vt == VT_LPWSTR, "got %d\n", prop_out.vt);
|
2021-03-27 16:02:06 +01:00
|
|
|
ok(!lstrcmpW(prop_out.pwszVal, test_stringW), "mismatched strings\n");
|
2008-09-16 12:49:02 +02:00
|
|
|
PropVariantClear(&prop_out);
|
|
|
|
|
|
|
|
/* If in.vt is VT_LPSTR and cpiSrc is CP_UNICODE, use another multibyte codepage (probably GetACP()) */
|
|
|
|
prop_in.vt = VT_LPSTR;
|
2021-03-27 16:02:06 +01:00
|
|
|
prop_in.pszVal = test_string;
|
2008-09-16 12:49:02 +02:00
|
|
|
hr = IMimeInternational_ConvertString(internat, CP_UNICODE, CP_UNICODE, &prop_in, &prop_out);
|
2022-02-28 08:26:45 +01:00
|
|
|
ok(hr == S_OK, "ret %08lx\n", hr);
|
2008-09-16 12:49:02 +02:00
|
|
|
ok(prop_out.vt == VT_LPWSTR, "got %d\n", prop_out.vt);
|
2021-03-27 16:02:06 +01:00
|
|
|
ok(!lstrcmpW(prop_out.pwszVal, test_stringW), "mismatched strings\n");
|
2008-09-16 12:49:02 +02:00
|
|
|
PropVariantClear(&prop_out);
|
|
|
|
|
2008-09-15 13:40:22 +02:00
|
|
|
IMimeInternational_Release(internat);
|
|
|
|
}
|
|
|
|
|
2008-09-10 13:06:46 +02:00
|
|
|
START_TEST(mimeintl)
|
|
|
|
{
|
|
|
|
OleInitialize(NULL);
|
|
|
|
test_create();
|
2008-09-10 13:38:41 +02:00
|
|
|
test_charset();
|
2008-09-10 15:42:42 +02:00
|
|
|
test_defaultcharset();
|
2008-09-15 13:40:22 +02:00
|
|
|
test_convert();
|
2008-09-10 13:06:46 +02:00
|
|
|
OleUninitialize();
|
|
|
|
}
|