ReactOS 0.4.17-dev-357-ga8f14ff
mimeintl.c
Go to the documentation of this file.
1/*
2 * MimeInternational tests
3 *
4 * Copyright 2008 Huw Davies
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#define COBJMACROS
22#include "windows.h"
23#include "ole2.h"
24#include "ocidl.h"
25
26#include "mimeole.h"
27
28#include "initguid.h"
29#include "mlang.h"
30
31#include <stdio.h>
32
33#include "wine/test.h"
34
35static void test_create(void)
36{
37 IMimeInternational *internat, *internat2;
38 HRESULT hr;
39 ULONG ref;
40
41 hr = MimeOleGetInternat(&internat);
42 ok(hr == S_OK, "ret %08lx\n", hr);
43 hr = MimeOleGetInternat(&internat2);
44 ok(hr == S_OK, "ret %08lx\n", hr);
45
46 /* Under w2k8 it's no longer a singleton */
47 if(internat == internat2)
48 {
49 /* test to show that the object is a singleton with
50 a reference held by the dll. */
51 ref = IMimeInternational_Release(internat2);
52 ok(ref == 2 ||
53 ref == 1, /* win95 - object is a static singleton */
54 "got %ld\n", ref);
55
56 ref = IMimeInternational_Release(internat);
57 ok(ref == 1, "got %ld\n", ref);
58 }
59 else
60 {
61 ref = IMimeInternational_Release(internat2);
62 ok(ref == 0, "got %ld\n", ref);
63
64 ref = IMimeInternational_Release(internat);
65 ok(ref == 0, "got %ld\n", ref);
66 }
67
68}
69
70static inline HRESULT get_mlang(IMultiLanguage **ml)
71{
72 return CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
73 &IID_IMultiLanguage, (void **)ml);
74}
75
76static HRESULT mlang_getcsetinfo(const char *charset, MIMECSETINFO *mlang_info)
77{
79 BSTR bstr = SysAllocStringLen(NULL, len - 1);
80 HRESULT hr;
81 IMultiLanguage *ml;
82
83 MultiByteToWideChar(CP_ACP, 0, charset, -1, bstr, len);
84
85 hr = get_mlang(&ml);
86
87 if(SUCCEEDED(hr))
88 {
89 hr = IMultiLanguage_GetCharsetInfo(ml, bstr, mlang_info);
90 IMultiLanguage_Release(ml);
91 }
92 SysFreeString(bstr);
93 if(FAILED(hr)) hr = MIME_E_NOT_FOUND;
94 return hr;
95}
96
97static HRESULT mlang_getcodepageinfo(UINT cp, MIMECPINFO *mlang_cp_info)
98{
99 HRESULT hr;
100 IMultiLanguage *ml;
101
102 hr = get_mlang(&ml);
103
104 if(SUCCEEDED(hr))
105 {
106 hr = IMultiLanguage_GetCodePageInfo(ml, cp, mlang_cp_info);
107 IMultiLanguage_Release(ml);
108 }
109 return hr;
110}
111
112static HRESULT mlang_getcsetinfo_from_cp(UINT cp, CHARSETTYPE charset_type, MIMECSETINFO *mlang_info)
113{
114 MIMECPINFO mlang_cp_info;
115 WCHAR *charset_name;
116 HRESULT hr;
117 IMultiLanguage *ml;
118
119 hr = mlang_getcodepageinfo(cp, &mlang_cp_info);
120 if(FAILED(hr)) return hr;
121
122 switch(charset_type)
123 {
124 case CHARSET_BODY:
125 charset_name = mlang_cp_info.wszBodyCharset;
126 break;
127 case CHARSET_HEADER:
128 charset_name = mlang_cp_info.wszHeaderCharset;
129 break;
130 case CHARSET_WEB:
131 charset_name = mlang_cp_info.wszWebCharset;
132 break;
133 }
134
135 hr = get_mlang(&ml);
136
137 if(SUCCEEDED(hr))
138 {
139 hr = IMultiLanguage_GetCharsetInfo(ml, charset_name, mlang_info);
140 IMultiLanguage_Release(ml);
141 }
142 return hr;
143}
144
145static void test_charset(void)
146{
147 IMimeInternational *internat;
148 HRESULT hr;
149 HCHARSET hcs, hcs_windows_1252, hcs_windows_1251;
150 INETCSETINFO cs_info;
151 MIMECSETINFO mlang_cs_info;
152
153 hr = MimeOleGetInternat(&internat);
154 ok(hr == S_OK, "ret %08lx\n", hr);
155
156 hr = IMimeInternational_FindCharset(internat, "nonexistent", &hcs);
157 ok(hr == MIME_E_NOT_FOUND, "got %08lx\n", hr);
158
159 hr = IMimeInternational_FindCharset(internat, "windows-1252", &hcs_windows_1252);
160 ok(hr == S_OK, "got %08lx\n", hr);
161 hr = IMimeInternational_FindCharset(internat, "windows-1252", &hcs);
162 ok(hr == S_OK, "got %08lx\n", hr);
163 ok(hcs_windows_1252 == hcs, "got different hcharsets for the same name\n");
164 hr = IMimeInternational_FindCharset(internat, "WiNdoWs-1252", &hcs);
165 ok(hr == S_OK, "got %08lx\n", hr);
166 ok(hcs_windows_1252 == hcs, "got different hcharsets for the same name\n");
167
168 hr = IMimeInternational_FindCharset(internat, "windows-1251", &hcs_windows_1251);
169 ok(hr == S_OK, "got %08lx\n", hr);
170 ok(hcs_windows_1252 != hcs_windows_1251, "got the same hcharset for the different names\n");
171
172 hr = IMimeInternational_GetCharsetInfo(internat, hcs_windows_1252, &cs_info);
173 ok(hr == S_OK, "got %08lx\n", hr);
174
175 hr = mlang_getcsetinfo("windows-1252", &mlang_cs_info);
176 ok(hr == S_OK, "got %08lx\n", hr);
177 ok(cs_info.cpiWindows == mlang_cs_info.uiCodePage, "cpiWindows %ld while mlang uiCodePage %d\n",
178 cs_info.cpiWindows, mlang_cs_info.uiCodePage);
179 ok(cs_info.cpiInternet == mlang_cs_info.uiInternetEncoding, "cpiInternet %ld while mlang uiInternetEncoding %d\n",
180 cs_info.cpiInternet, mlang_cs_info.uiInternetEncoding);
181 ok(cs_info.hCharset == hcs_windows_1252, "hCharset doesn't match requested\n");
182 ok(!strcmp(cs_info.szName, "windows-1252"), "szName doesn't match requested\n");
183
184 hr = IMimeInternational_GetCodePageCharset(internat, 1252, CHARSET_BODY, &hcs);
185 ok(hr == S_OK, "got %08lx\n", hr);
186 hr = IMimeInternational_GetCharsetInfo(internat, hcs, &cs_info);
187 ok(hr == S_OK, "got %08lx\n", hr);
188
189 hr = mlang_getcsetinfo_from_cp(1252, CHARSET_BODY, &mlang_cs_info);
190 ok(hr == S_OK, "got %08lx\n", hr);
191 ok(cs_info.cpiWindows == mlang_cs_info.uiCodePage, "cpiWindows %ld while mlang uiCodePage %d\n",
192 cs_info.cpiWindows, mlang_cs_info.uiCodePage);
193 ok(cs_info.cpiInternet == mlang_cs_info.uiInternetEncoding, "cpiInternet %ld while mlang uiInternetEncoding %d\n",
194 cs_info.cpiInternet, mlang_cs_info.uiInternetEncoding);
195
196 IMimeInternational_Release(internat);
197}
198
199static void test_defaultcharset(void)
200{
201 IMimeInternational *internat;
202 HRESULT hr;
203 HCHARSET hcs_default, hcs, hcs_windows_1251;
204
205 hr = MimeOleGetInternat(&internat);
206 ok(hr == S_OK, "ret %08lx\n", hr);
207
208 hr = IMimeInternational_GetDefaultCharset(internat, &hcs_default);
209 ok(hr == S_OK, "ret %08lx\n", hr);
210 hr = IMimeInternational_GetCodePageCharset(internat, GetACP(), CHARSET_BODY, &hcs);
211 ok(hr == S_OK, "ret %08lx\n", hr);
212 ok(hcs_default == hcs, "Unexpected default charset\n");
213
214 hr = IMimeInternational_FindCharset(internat, "windows-1251", &hcs_windows_1251);
215 ok(hr == S_OK, "got %08lx\n", hr);
216 hr = IMimeInternational_SetDefaultCharset(internat, hcs_windows_1251);
217 ok(hr == S_OK, "ret %08lx\n", hr);
218 hr = IMimeInternational_GetDefaultCharset(internat, &hcs);
219 ok(hr == S_OK, "ret %08lx\n", hr);
220 ok(hcs == hcs_windows_1251, "didn't retrieve recently set default\n");
221 /* Set the old default back again */
222 hr = IMimeInternational_SetDefaultCharset(internat, hcs_default);
223 ok(hr == S_OK, "ret %08lx\n", hr);
224
225 IMimeInternational_Release(internat);
226}
227
228static void test_convert(void)
229{
230 IMimeInternational *internat;
231 HRESULT hr;
232 BLOB src, dst;
233 ULONG read;
234 PROPVARIANT prop_in, prop_out;
235 static char test_string[] = "test string";
236 static WCHAR test_stringW[] = L"test string";
237
238 hr = MimeOleGetInternat(&internat);
239 ok(hr == S_OK, "ret %08lx\n", hr);
240
241 src.pBlobData = (BYTE*)test_string;
242 src.cbSize = sizeof(test_string);
243 hr = IMimeInternational_ConvertBuffer(internat, 1252, 28591, &src, &dst, &read);
244 ok(hr == S_OK, "ret %08lx\n", hr);
245 ok(read == sizeof(test_string), "got %ld\n", read);
246 ok(dst.cbSize == sizeof(test_string), "got %ld\n", dst.cbSize);
247 CoTaskMemFree(dst.pBlobData);
248
249 src.cbSize = 2;
250 hr = IMimeInternational_ConvertBuffer(internat, 1252, 28591, &src, &dst, &read);
251 ok(hr == S_OK, "ret %08lx\n", hr);
252 ok(read == 2, "got %ld\n", read);
253 ok(dst.cbSize == 2, "got %ld\n", dst.cbSize);
254 CoTaskMemFree(dst.pBlobData);
255
256 prop_in.vt = VT_LPWSTR;
257 prop_in.pwszVal = test_stringW;
258 hr = IMimeInternational_ConvertString(internat, CP_UNICODE, 1252, &prop_in, &prop_out);
259 ok(hr == S_OK, "ret %08lx\n", hr);
260 ok(prop_out.vt == VT_LPSTR, "got %d\n", prop_out.vt);
261 ok(!strcmp(prop_out.pszVal, test_string), "got %s\n", prop_out.pszVal);
262 PropVariantClear(&prop_out);
263
264 /* If in.vt is VT_LPWSTR, ignore cpiSrc */
265 prop_in.vt = VT_LPWSTR;
266 prop_in.pwszVal = test_stringW;
267 hr = IMimeInternational_ConvertString(internat, 28591, 1252, &prop_in, &prop_out);
268 ok(hr == S_OK, "ret %08lx\n", hr);
269 ok(prop_out.vt == VT_LPSTR, "got %d\n", prop_out.vt);
270 ok(!strcmp(prop_out.pszVal, test_string), "got %s\n", prop_out.pszVal);
271 PropVariantClear(&prop_out);
272
273 prop_in.vt = VT_LPSTR;
274 prop_in.pszVal = test_string;
275 hr = IMimeInternational_ConvertString(internat, 28591, CP_UNICODE, &prop_in, &prop_out);
276 ok(hr == S_OK, "ret %08lx\n", hr);
277 ok(prop_out.vt == VT_LPWSTR, "got %d\n", prop_out.vt);
278 ok(!lstrcmpW(prop_out.pwszVal, test_stringW), "mismatched strings\n");
279 PropVariantClear(&prop_out);
280
281 /* If in.vt is VT_LPSTR and cpiSrc is CP_UNICODE, use another multibyte codepage (probably GetACP()) */
282 prop_in.vt = VT_LPSTR;
283 prop_in.pszVal = test_string;
284 hr = IMimeInternational_ConvertString(internat, CP_UNICODE, CP_UNICODE, &prop_in, &prop_out);
285 ok(hr == S_OK, "ret %08lx\n", hr);
286 ok(prop_out.vt == VT_LPWSTR, "got %d\n", prop_out.vt);
287 ok(!lstrcmpW(prop_out.pwszVal, test_stringW), "mismatched strings\n");
288 PropVariantClear(&prop_out);
289
290 IMimeInternational_Release(internat);
291}
292
293START_TEST(mimeintl)
294{
296 test_create();
297 test_charset();
299 test_convert();
301}
#define read
Definition: acwin.h:97
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
CFF_Charset charset
Definition: cffcmap.c:137
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
HRESULT WINAPI PropVariantClear(PROPVARIANT *pvar)
Definition: combase.c:709
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
#define CP_ACP
Definition: compat.h:109
OLECHAR * BSTR
Definition: compat.h:2293
#define MultiByteToWideChar
Definition: compat.h:110
@ VT_LPSTR
Definition: compat.h:2324
@ VT_LPWSTR
Definition: compat.h:2325
static HRESULT mlang_getcsetinfo(const char *charset, MIMECSETINFO *mlang_info)
Definition: mimeintl.c:202
HRESULT WINAPI MimeOleGetInternat(IMimeInternational **internat)
Definition: mimeintl.c:542
static HRESULT get_mlang(IMultiLanguage **ml)
Definition: mimeintl.c:64
static HRESULT mlang_getcodepageinfo(UINT cp, MIMECPINFO *mlang_cp_info)
Definition: mimeintl.c:146
UINT WINAPI GetACP(void)
Definition: locale.c:2023
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:162
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:218
#define CP_UNICODE
Definition: stg_prop.c:73
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
POINT cp
Definition: magnifier.c:59
static HRESULT mlang_getcsetinfo_from_cp(UINT cp, CHARSETTYPE charset_type, MIMECSETINFO *mlang_info)
Definition: mimeintl.c:112
static void test_create(void)
Definition: mimeintl.c:35
static void test_convert(void)
Definition: mimeintl.c:228
static void test_charset(void)
Definition: mimeintl.c:145
static void test_defaultcharset(void)
Definition: mimeintl.c:199
unsigned int UINT
Definition: ndis.h:50
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:271
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:339
short WCHAR
Definition: pedump.c:58
Definition: nspapi.h:57
Definition: send.c:48
void test_string()
Definition: test_string.cpp:38
uint32_t ULONG
Definition: typedefs.h:59
unsigned char BYTE
Definition: xxhash.c:193