2 * MimeInternational tests
4 * Copyright 2008 Huw Davies
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
22 #define NONAMELESSUNION
36 #include "wine/test.h"
38 static void test_create(void)
40 IMimeInternational
*internat
, *internat2
;
44 hr
= MimeOleGetInternat(&internat
);
45 ok(hr
== S_OK
, "ret %08x\n", hr
);
46 hr
= MimeOleGetInternat(&internat2
);
47 ok(hr
== S_OK
, "ret %08x\n", hr
);
49 /* test to show that the object is a singleton with
50 a reference held by the dll. */
51 ok(internat
== internat2
, "instances differ\n");
52 ref
= IMimeInternational_Release(internat2
);
53 ok(ref
== 2, "got %d\n", ref
);
55 IMimeInternational_Release(internat
);
58 static inline HRESULT
get_mlang(IMultiLanguage
**ml
)
60 return CoCreateInstance(&CLSID_CMultiLanguage
, NULL
, CLSCTX_INPROC_SERVER
| CLSCTX_INPROC_HANDLER
,
61 &IID_IMultiLanguage
, (void **)ml
);
64 static HRESULT
mlang_getcsetinfo(const char *charset
, MIMECSETINFO
*mlang_info
)
66 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, charset
, -1, NULL
, 0);
67 BSTR bstr
= SysAllocStringLen(NULL
, len
- 1);
71 MultiByteToWideChar(CP_ACP
, 0, charset
, -1, bstr
, len
);
77 hr
= IMultiLanguage_GetCharsetInfo(ml
, bstr
, mlang_info
);
78 IMultiLanguage_Release(ml
);
81 if(FAILED(hr
)) hr
= MIME_E_NOT_FOUND
;
85 static HRESULT
mlang_getcodepageinfo(UINT cp
, MIMECPINFO
*mlang_cp_info
)
94 hr
= IMultiLanguage_GetCodePageInfo(ml
, cp
, mlang_cp_info
);
95 IMultiLanguage_Release(ml
);
100 static HRESULT
mlang_getcsetinfo_from_cp(UINT cp
, CHARSETTYPE charset_type
, MIMECSETINFO
*mlang_info
)
102 MIMECPINFO mlang_cp_info
;
107 hr
= mlang_getcodepageinfo(cp
, &mlang_cp_info
);
108 if(FAILED(hr
)) return hr
;
113 charset_name
= mlang_cp_info
.wszBodyCharset
;
116 charset_name
= mlang_cp_info
.wszHeaderCharset
;
119 charset_name
= mlang_cp_info
.wszWebCharset
;
127 hr
= IMultiLanguage_GetCharsetInfo(ml
, charset_name
, mlang_info
);
128 IMultiLanguage_Release(ml
);
133 static void test_charset(void)
135 IMimeInternational
*internat
;
137 HCHARSET hcs
, hcs_windows_1252
, hcs_windows_1251
;
138 INETCSETINFO cs_info
;
139 MIMECSETINFO mlang_cs_info
;
141 hr
= MimeOleGetInternat(&internat
);
142 ok(hr
== S_OK
, "ret %08x\n", hr
);
144 hr
= IMimeInternational_FindCharset(internat
, "non-existent", &hcs
);
145 ok(hr
== MIME_E_NOT_FOUND
, "got %08x\n", hr
);
147 hr
= IMimeInternational_FindCharset(internat
, "windows-1252", &hcs_windows_1252
);
148 ok(hr
== S_OK
, "got %08x\n", hr
);
149 hr
= IMimeInternational_FindCharset(internat
, "windows-1252", &hcs
);
150 ok(hr
== S_OK
, "got %08x\n", hr
);
151 ok(hcs_windows_1252
== hcs
, "got different hcharsets for the same name\n");
153 hr
= IMimeInternational_FindCharset(internat
, "windows-1251", &hcs_windows_1251
);
154 ok(hr
== S_OK
, "got %08x\n", hr
);
155 ok(hcs_windows_1252
!= hcs_windows_1251
, "got the same hcharset for the different names\n");
157 hr
= IMimeInternational_GetCharsetInfo(internat
, hcs_windows_1252
, &cs_info
);
158 ok(hr
== S_OK
, "got %08x\n", hr
);
160 hr
= mlang_getcsetinfo("windows-1252", &mlang_cs_info
);
161 ok(hr
== S_OK
, "got %08x\n", hr
);
162 ok(cs_info
.cpiWindows
== mlang_cs_info
.uiCodePage
, "cpiWindows %d while mlang uiCodePage %d\n",
163 cs_info
.cpiWindows
, mlang_cs_info
.uiCodePage
);
164 ok(cs_info
.cpiInternet
== mlang_cs_info
.uiInternetEncoding
, "cpiInternet %d while mlang uiInternetEncoding %d\n",
165 cs_info
.cpiInternet
, mlang_cs_info
.uiInternetEncoding
);
166 ok(cs_info
.hCharset
== hcs_windows_1252
, "hCharset doesn't match requested\n");
167 ok(!strcmp(cs_info
.szName
, "windows-1252"), "szName doesn't match requested\n");
169 hr
= IMimeInternational_GetCodePageCharset(internat
, 1252, CHARSET_BODY
, &hcs
);
170 ok(hr
== S_OK
, "got %08x\n", hr
);
171 hr
= IMimeInternational_GetCharsetInfo(internat
, hcs
, &cs_info
);
172 ok(hr
== S_OK
, "got %08x\n", hr
);
174 hr
= mlang_getcsetinfo_from_cp(1252, CHARSET_BODY
, &mlang_cs_info
);
175 ok(hr
== S_OK
, "got %08x\n", hr
);
176 ok(cs_info
.cpiWindows
== mlang_cs_info
.uiCodePage
, "cpiWindows %d while mlang uiCodePage %d\n",
177 cs_info
.cpiWindows
, mlang_cs_info
.uiCodePage
);
178 ok(cs_info
.cpiInternet
== mlang_cs_info
.uiInternetEncoding
, "cpiInternet %d while mlang uiInternetEncoding %d\n",
179 cs_info
.cpiInternet
, mlang_cs_info
.uiInternetEncoding
);
181 IMimeInternational_Release(internat
);
184 static void test_defaultcharset(void)
186 IMimeInternational
*internat
;
188 HCHARSET hcs_default
, hcs
, hcs_windows_1251
;
190 hr
= MimeOleGetInternat(&internat
);
191 ok(hr
== S_OK
, "ret %08x\n", hr
);
193 hr
= IMimeInternational_GetDefaultCharset(internat
, &hcs_default
);
194 ok(hr
== S_OK
, "ret %08x\n", hr
);
195 hr
= IMimeInternational_GetCodePageCharset(internat
, GetACP(), CHARSET_BODY
, &hcs
);
196 ok(hr
== S_OK
, "ret %08x\n", hr
);
197 ok(hcs_default
== hcs
, "Unexpected default charset\n");
199 hr
= IMimeInternational_FindCharset(internat
, "windows-1251", &hcs_windows_1251
);
200 ok(hr
== S_OK
, "got %08x\n", hr
);
201 hr
= IMimeInternational_SetDefaultCharset(internat
, hcs_windows_1251
);
202 ok(hr
== S_OK
, "ret %08x\n", hr
);
203 hr
= IMimeInternational_GetDefaultCharset(internat
, &hcs
);
204 ok(hr
== S_OK
, "ret %08x\n", hr
);
205 ok(hcs
== hcs_windows_1251
, "didn't retrieve recently set default\n");
206 /* Set the old default back again */
207 hr
= IMimeInternational_SetDefaultCharset(internat
, hcs_default
);
208 ok(hr
== S_OK
, "ret %08x\n", hr
);
210 IMimeInternational_Release(internat
);
213 static void test_convert(void)
215 IMimeInternational
*internat
;
219 static const char test_string
[] = "test string";
221 hr
= MimeOleGetInternat(&internat
);
222 ok(hr
== S_OK
, "ret %08x\n", hr
);
224 src
.pBlobData
= (BYTE
*)test_string
;
225 src
.cbSize
= sizeof(test_string
);
226 hr
= IMimeInternational_ConvertBuffer(internat
, 1252, 28591, &src
, &dst
, &read
);
227 ok(hr
== S_OK
, "ret %08x\n", hr
);
228 ok(read
== sizeof(test_string
), "got %d\n", read
);
229 ok(dst
.cbSize
== sizeof(test_string
), "got %d\n", dst
.cbSize
);
230 CoTaskMemFree(dst
.pBlobData
);
233 hr
= IMimeInternational_ConvertBuffer(internat
, 1252, 28591, &src
, &dst
, &read
);
234 ok(hr
== S_OK
, "ret %08x\n", hr
);
235 ok(read
== 2, "got %d\n", read
);
236 ok(dst
.cbSize
== 2, "got %d\n", dst
.cbSize
);
237 CoTaskMemFree(dst
.pBlobData
);
239 IMimeInternational_Release(internat
);
247 test_defaultcharset();