ReactOS  0.4.14-dev-50-g13bb5e2
mimeintl.c File Reference
#include "windows.h"
#include "ole2.h"
#include "ocidl.h"
#include "mimeole.h"
#include "initguid.h"
#include "mlang.h"
#include <stdio.h>
#include "wine/test.h"
Include dependency graph for mimeintl.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 
#define NONAMELESSUNION
 

Functions

static void test_create (void)
 
static HRESULT get_mlang (IMultiLanguage **ml)
 
static HRESULT mlang_getcsetinfo (const char *charset, MIMECSETINFO *mlang_info)
 
static HRESULT mlang_getcodepageinfo (UINT cp, MIMECPINFO *mlang_cp_info)
 
static HRESULT mlang_getcsetinfo_from_cp (UINT cp, CHARSETTYPE charset_type, MIMECSETINFO *mlang_info)
 
static void test_charset (void)
 
static void test_defaultcharset (void)
 
static void test_convert (void)
 
 START_TEST (mimeintl)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file mimeintl.c.

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 22 of file mimeintl.c.

Function Documentation

◆ get_mlang()

static HRESULT get_mlang ( IMultiLanguage **  ml)
inlinestatic

Definition at line 72 of file mimeintl.c.

73 {
74  return CoCreateInstance(&CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
75  &IID_IMultiLanguage, (void **)ml);
76 }
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3234

Referenced by mlang_getcodepageinfo(), mlang_getcsetinfo(), and mlang_getcsetinfo_from_cp().

◆ mlang_getcodepageinfo()

static HRESULT mlang_getcodepageinfo ( UINT  cp,
MIMECPINFO *  mlang_cp_info 
)
static

Definition at line 99 of file mimeintl.c.

100 {
101  HRESULT hr;
102  IMultiLanguage *ml;
103 
104  hr = get_mlang(&ml);
105 
106  if(SUCCEEDED(hr))
107  {
108  hr = IMultiLanguage_GetCodePageInfo(ml, cp, mlang_cp_info);
109  IMultiLanguage_Release(ml);
110  }
111  return hr;
112 }
HRESULT hr
Definition: shlfolder.c:183
static HRESULT get_mlang(IMultiLanguage **ml)
Definition: mimeintl.c:72
LONG HRESULT
Definition: typedefs.h:77
POINT cp
Definition: magnifier.c:59
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by mlang_getcsetinfo_from_cp().

◆ mlang_getcsetinfo()

static HRESULT mlang_getcsetinfo ( const char charset,
MIMECSETINFO *  mlang_info 
)
static

Definition at line 78 of file mimeintl.c.

79 {
81  BSTR bstr = SysAllocStringLen(NULL, len - 1);
82  HRESULT hr;
83  IMultiLanguage *ml;
84 
85  MultiByteToWideChar(CP_ACP, 0, charset, -1, bstr, len);
86 
87  hr = get_mlang(&ml);
88 
89  if(SUCCEEDED(hr))
90  {
91  hr = IMultiLanguage_GetCharsetInfo(ml, bstr, mlang_info);
92  IMultiLanguage_Release(ml);
93  }
94  SysFreeString(bstr);
95  if(FAILED(hr)) hr = MIME_E_NOT_FOUND;
96  return hr;
97 }
CFF_Charset charset
Definition: cffcmap.c:138
HRESULT hr
Definition: shlfolder.c:183
BSTR WINAPI SysAllocStringLen(const OLECHAR *str, unsigned int len)
Definition: oleaut.c:342
#define CP_ACP
Definition: compat.h:99
OLECHAR * BSTR
Definition: compat.h:1934
static HRESULT get_mlang(IMultiLanguage **ml)
Definition: mimeintl.c:72
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
Definition: oleaut.c:274
#define MultiByteToWideChar
Definition: compat.h:100
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by test_charset().

◆ mlang_getcsetinfo_from_cp()

static HRESULT mlang_getcsetinfo_from_cp ( UINT  cp,
CHARSETTYPE  charset_type,
MIMECSETINFO *  mlang_info 
)
static

Definition at line 114 of file mimeintl.c.

115 {
116  MIMECPINFO mlang_cp_info;
117  WCHAR *charset_name;
118  HRESULT hr;
119  IMultiLanguage *ml;
120 
121  hr = mlang_getcodepageinfo(cp, &mlang_cp_info);
122  if(FAILED(hr)) return hr;
123 
124  switch(charset_type)
125  {
126  case CHARSET_BODY:
127  charset_name = mlang_cp_info.wszBodyCharset;
128  break;
129  case CHARSET_HEADER:
130  charset_name = mlang_cp_info.wszHeaderCharset;
131  break;
132  case CHARSET_WEB:
133  charset_name = mlang_cp_info.wszWebCharset;
134  break;
135  }
136 
137  hr = get_mlang(&ml);
138 
139  if(SUCCEEDED(hr))
140  {
141  hr = IMultiLanguage_GetCharsetInfo(ml, charset_name, mlang_info);
142  IMultiLanguage_Release(ml);
143  }
144  return hr;
145 }
HRESULT hr
Definition: shlfolder.c:183
static HRESULT get_mlang(IMultiLanguage **ml)
Definition: mimeintl.c:72
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
static HRESULT mlang_getcodepageinfo(UINT cp, MIMECPINFO *mlang_cp_info)
Definition: mimeintl.c:99
POINT cp
Definition: magnifier.c:59
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by test_charset().

◆ START_TEST()

START_TEST ( mimeintl  )

Definition at line 295 of file mimeintl.c.

296 {
298  test_create();
299  test_charset();
301  test_convert();
302  OleUninitialize();
303 }
static void test_create(void)
Definition: mimeintl.c:37
static void test_charset(void)
Definition: mimeintl.c:147
static void test_convert(void)
Definition: mimeintl.c:230
static void test_defaultcharset(void)
Definition: mimeintl.c:201
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
Definition: ole2.c:172
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:233

◆ test_charset()

static void test_charset ( void  )
static

Definition at line 147 of file mimeintl.c.

148 {
149  IMimeInternational *internat;
150  HRESULT hr;
151  HCHARSET hcs, hcs_windows_1252, hcs_windows_1251;
152  INETCSETINFO cs_info;
153  MIMECSETINFO mlang_cs_info;
154 
155  hr = MimeOleGetInternat(&internat);
156  ok(hr == S_OK, "ret %08x\n", hr);
157 
158  hr = IMimeInternational_FindCharset(internat, "nonexistent", &hcs);
159  ok(hr == MIME_E_NOT_FOUND, "got %08x\n", hr);
160 
161  hr = IMimeInternational_FindCharset(internat, "windows-1252", &hcs_windows_1252);
162  ok(hr == S_OK, "got %08x\n", hr);
163  hr = IMimeInternational_FindCharset(internat, "windows-1252", &hcs);
164  ok(hr == S_OK, "got %08x\n", hr);
165  ok(hcs_windows_1252 == hcs, "got different hcharsets for the same name\n");
166  hr = IMimeInternational_FindCharset(internat, "WiNdoWs-1252", &hcs);
167  ok(hr == S_OK, "got %08x\n", hr);
168  ok(hcs_windows_1252 == hcs, "got different hcharsets for the same name\n");
169 
170  hr = IMimeInternational_FindCharset(internat, "windows-1251", &hcs_windows_1251);
171  ok(hr == S_OK, "got %08x\n", hr);
172  ok(hcs_windows_1252 != hcs_windows_1251, "got the same hcharset for the different names\n");
173 
174  hr = IMimeInternational_GetCharsetInfo(internat, hcs_windows_1252, &cs_info);
175  ok(hr == S_OK, "got %08x\n", hr);
176 
177  hr = mlang_getcsetinfo("windows-1252", &mlang_cs_info);
178  ok(hr == S_OK, "got %08x\n", hr);
179  ok(cs_info.cpiWindows == mlang_cs_info.uiCodePage, "cpiWindows %d while mlang uiCodePage %d\n",
180  cs_info.cpiWindows, mlang_cs_info.uiCodePage);
181  ok(cs_info.cpiInternet == mlang_cs_info.uiInternetEncoding, "cpiInternet %d while mlang uiInternetEncoding %d\n",
182  cs_info.cpiInternet, mlang_cs_info.uiInternetEncoding);
183  ok(cs_info.hCharset == hcs_windows_1252, "hCharset doesn't match requested\n");
184  ok(!strcmp(cs_info.szName, "windows-1252"), "szName doesn't match requested\n");
185 
186  hr = IMimeInternational_GetCodePageCharset(internat, 1252, CHARSET_BODY, &hcs);
187  ok(hr == S_OK, "got %08x\n", hr);
188  hr = IMimeInternational_GetCharsetInfo(internat, hcs, &cs_info);
189  ok(hr == S_OK, "got %08x\n", hr);
190 
191  hr = mlang_getcsetinfo_from_cp(1252, CHARSET_BODY, &mlang_cs_info);
192  ok(hr == S_OK, "got %08x\n", hr);
193  ok(cs_info.cpiWindows == mlang_cs_info.uiCodePage, "cpiWindows %d while mlang uiCodePage %d\n",
194  cs_info.cpiWindows, mlang_cs_info.uiCodePage);
195  ok(cs_info.cpiInternet == mlang_cs_info.uiInternetEncoding, "cpiInternet %d while mlang uiInternetEncoding %d\n",
196  cs_info.cpiInternet, mlang_cs_info.uiInternetEncoding);
197 
198  IMimeInternational_Release(internat);
199 }
static HRESULT mlang_getcsetinfo_from_cp(UINT cp, CHARSETTYPE charset_type, MIMECSETINFO *mlang_info)
Definition: mimeintl.c:114
HRESULT hr
Definition: shlfolder.c:183
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI MimeOleGetInternat(IMimeInternational **internat)
Definition: mimeintl.c:544
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
static HRESULT mlang_getcsetinfo(const char *charset, MIMECSETINFO *mlang_info)
Definition: mimeintl.c:78
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

Referenced by START_TEST().

◆ test_convert()

static void test_convert ( void  )
static

Definition at line 230 of file mimeintl.c.

231 {
232  IMimeInternational *internat;
233  HRESULT hr;
234  BLOB src, dst;
235  ULONG read;
236  PROPVARIANT prop_in, prop_out;
237  static char test_string[] = "test string";
238  static WCHAR test_stringW[] = {'t','e','s','t',' ','s','t','r','i','n','g',0};
239 
240  hr = MimeOleGetInternat(&internat);
241  ok(hr == S_OK, "ret %08x\n", hr);
242 
243  src.pBlobData = (BYTE*)test_string;
244  src.cbSize = sizeof(test_string);
245  hr = IMimeInternational_ConvertBuffer(internat, 1252, 28591, &src, &dst, &read);
246  ok(hr == S_OK, "ret %08x\n", hr);
247  ok(read == sizeof(test_string), "got %d\n", read);
248  ok(dst.cbSize == sizeof(test_string), "got %d\n", dst.cbSize);
249  CoTaskMemFree(dst.pBlobData);
250 
251  src.cbSize = 2;
252  hr = IMimeInternational_ConvertBuffer(internat, 1252, 28591, &src, &dst, &read);
253  ok(hr == S_OK, "ret %08x\n", hr);
254  ok(read == 2, "got %d\n", read);
255  ok(dst.cbSize == 2, "got %d\n", dst.cbSize);
256  CoTaskMemFree(dst.pBlobData);
257 
258  prop_in.vt = VT_LPWSTR;
259  prop_in.u.pwszVal = test_stringW;
260  hr = IMimeInternational_ConvertString(internat, CP_UNICODE, 1252, &prop_in, &prop_out);
261  ok(hr == S_OK, "ret %08x\n", hr);
262  ok(prop_out.vt == VT_LPSTR, "got %d\n", prop_out.vt);
263  ok(!strcmp(prop_out.u.pszVal, test_string), "got %s\n", prop_out.u.pszVal);
264  PropVariantClear(&prop_out);
265 
266  /* If in.vt is VT_LPWSTR, ignore cpiSrc */
267  prop_in.vt = VT_LPWSTR;
268  prop_in.u.pwszVal = test_stringW;
269  hr = IMimeInternational_ConvertString(internat, 28591, 1252, &prop_in, &prop_out);
270  ok(hr == S_OK, "ret %08x\n", hr);
271  ok(prop_out.vt == VT_LPSTR, "got %d\n", prop_out.vt);
272  ok(!strcmp(prop_out.u.pszVal, test_string), "got %s\n", prop_out.u.pszVal);
273  PropVariantClear(&prop_out);
274 
275  prop_in.vt = VT_LPSTR;
276  prop_in.u.pszVal = test_string;
277  hr = IMimeInternational_ConvertString(internat, 28591, CP_UNICODE, &prop_in, &prop_out);
278  ok(hr == S_OK, "ret %08x\n", hr);
279  ok(prop_out.vt == VT_LPWSTR, "got %d\n", prop_out.vt);
280  ok(!lstrcmpW(prop_out.u.pwszVal, test_stringW), "mismatched strings\n");
281  PropVariantClear(&prop_out);
282 
283  /* If in.vt is VT_LPSTR and cpiSrc is CP_UNICODE, use another multibyte codepage (probably GetACP()) */
284  prop_in.vt = VT_LPSTR;
285  prop_in.u.pszVal = test_string;
286  hr = IMimeInternational_ConvertString(internat, CP_UNICODE, CP_UNICODE, &prop_in, &prop_out);
287  ok(hr == S_OK, "ret %08x\n", hr);
288  ok(prop_out.vt == VT_LPWSTR, "got %d\n", prop_out.vt);
289  ok(!lstrcmpW(prop_out.u.pwszVal, test_stringW), "mismatched strings\n");
290  PropVariantClear(&prop_out);
291 
292  IMimeInternational_Release(internat);
293 }
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
HRESULT hr
Definition: shlfolder.c:183
HRESULT WINAPI PropVariantClear(PROPVARIANT *pvar)
Definition: ole2.c:2952
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
Definition: nspapi.h:57
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
unsigned char BYTE
Definition: mem.h:68
GLenum src
Definition: glext.h:6340
HRESULT WINAPI MimeOleGetInternat(IMimeInternational **internat)
Definition: mimeintl.c:544
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
GLenum GLenum dst
Definition: glext.h:6340
void test_string()
Definition: test_string.cpp:38
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define CP_UNICODE
Definition: stg_prop.c:81
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

Referenced by START_TEST().

◆ test_create()

static void test_create ( void  )
static

Definition at line 37 of file mimeintl.c.

38 {
39  IMimeInternational *internat, *internat2;
40  HRESULT hr;
41  ULONG ref;
42 
43  hr = MimeOleGetInternat(&internat);
44  ok(hr == S_OK, "ret %08x\n", hr);
45  hr = MimeOleGetInternat(&internat2);
46  ok(hr == S_OK, "ret %08x\n", hr);
47 
48  /* Under w2k8 it's no longer a singleton */
49  if(internat == internat2)
50  {
51  /* test to show that the object is a singleton with
52  a reference held by the dll. */
53  ref = IMimeInternational_Release(internat2);
54  ok(ref == 2 ||
55  ref == 1, /* win95 - object is a static singleton */
56  "got %d\n", ref);
57 
58  ref = IMimeInternational_Release(internat);
59  ok(ref == 1, "got %d\n", ref);
60  }
61  else
62  {
63  ref = IMimeInternational_Release(internat2);
64  ok(ref == 0, "got %d\n", ref);
65 
66  ref = IMimeInternational_Release(internat);
67  ok(ref == 0, "got %d\n", ref);
68  }
69 
70 }
HRESULT hr
Definition: shlfolder.c:183
Definition: send.c:47
GLenum GLint ref
Definition: glext.h:6028
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI MimeOleGetInternat(IMimeInternational **internat)
Definition: mimeintl.c:544
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57
unsigned int ULONG
Definition: retypes.h:1

Referenced by START_TEST().

◆ test_defaultcharset()

static void test_defaultcharset ( void  )
static

Definition at line 201 of file mimeintl.c.

202 {
203  IMimeInternational *internat;
204  HRESULT hr;
205  HCHARSET hcs_default, hcs, hcs_windows_1251;
206 
207  hr = MimeOleGetInternat(&internat);
208  ok(hr == S_OK, "ret %08x\n", hr);
209 
210  hr = IMimeInternational_GetDefaultCharset(internat, &hcs_default);
211  ok(hr == S_OK, "ret %08x\n", hr);
212  hr = IMimeInternational_GetCodePageCharset(internat, GetACP(), CHARSET_BODY, &hcs);
213  ok(hr == S_OK, "ret %08x\n", hr);
214  ok(hcs_default == hcs, "Unexpected default charset\n");
215 
216  hr = IMimeInternational_FindCharset(internat, "windows-1251", &hcs_windows_1251);
217  ok(hr == S_OK, "got %08x\n", hr);
218  hr = IMimeInternational_SetDefaultCharset(internat, hcs_windows_1251);
219  ok(hr == S_OK, "ret %08x\n", hr);
220  hr = IMimeInternational_GetDefaultCharset(internat, &hcs);
221  ok(hr == S_OK, "ret %08x\n", hr);
222  ok(hcs == hcs_windows_1251, "didn't retrieve recently set default\n");
223  /* Set the old default back again */
224  hr = IMimeInternational_SetDefaultCharset(internat, hcs_default);
225  ok(hr == S_OK, "ret %08x\n", hr);
226 
227  IMimeInternational_Release(internat);
228 }
HRESULT hr
Definition: shlfolder.c:183
UINT WINAPI GetACP(VOID)
Definition: nls.c:2169
LONG HRESULT
Definition: typedefs.h:77
HRESULT WINAPI MimeOleGetInternat(IMimeInternational **internat)
Definition: mimeintl.c:544
#define S_OK
Definition: intsafe.h:59
#define ok(value,...)
Definition: atltest.h:57

Referenced by START_TEST().