4 * Copyright 2007 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
34 #include "wine/test.h"
37 "MIME-Version: 1.0\r\n"
38 "Content-Type: multipart/mixed;\r\n"
39 " boundary=\"------------1.5.0.6\";\r\n"
40 " stuff=\"du;nno\";\r\n"
41 " morestuff=\"so\\\\me\\\"thing\\\"\"\r\n"
43 "From: Huw Davies <huw@codeweavers.com>\r\n"
44 "From: Me <xxx@codeweavers.com>\r\n"
45 "To: wine-patches <wine-patches@winehq.org>\r\n"
46 "Cc: Huw Davies <huw@codeweavers.com>,\r\n"
47 " \"Fred Bloggs\" <fred@bloggs.com>\r\n"
51 "This is a multi-part message in MIME format.\r\n"
52 "--------------1.5.0.6\r\n"
53 "Content-Type: text/plain; format=fixed; charset=UTF-8\r\n"
54 "Content-Transfer-Encoding: 8bit\r\n"
57 "--------------1.5.0.6\r\n"
58 "Content-Type: text/plain; charset=\"us-ascii\"\r\n"
59 "Content-Transfer-Encoding: 7bit\r\n"
62 "--------------1.5.0.6--\r\n";
64 static void test_CreateVirtualStream(void)
69 hr = MimeOleCreateVirtualStream(&pstm);
70 ok(hr == S_OK, "ret %08x\n", hr);
72 IStream_Release(pstm);
75 static void test_CreateSecurity(void)
80 hr = MimeOleCreateSecurity(&sec);
81 ok(hr == S_OK, "ret %08x\n", hr);
83 IMimeSecurity_Release(sec);
86 static void test_CreateBody(void)
90 HBODY handle = (void *)0xdeadbeef;
95 ULONG count, found_param, i;
96 MIMEPARAMINFO *param_info;
97 IMimeAllocator *alloc;
100 hr = CoCreateInstance(&CLSID_IMimeBody, NULL, CLSCTX_INPROC_SERVER, &IID_IMimeBody, (void**)&body);
101 ok(hr == S_OK, "ret %08x\n", hr);
103 hr = IMimeBody_GetHandle(body, &handle);
104 ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
105 ok(handle == NULL, "handle %p\n", handle);
107 hr = CreateStreamOnHGlobal(NULL, TRUE, &in);
108 ok(hr == S_OK, "ret %08x\n", hr);
109 IStream_Write(in, msg1, sizeof(msg1) - 1, NULL);
111 IStream_Seek(in, off, STREAM_SEEK_SET, NULL);
113 /* Need to call InitNew before Load otherwise Load crashes with native inetcomm */
114 hr = IMimeBody_InitNew(body);
115 ok(hr == S_OK, "ret %08x\n", hr);
117 hr = IMimeBody_GetCurrentEncoding(body, &enc);
118 ok(hr == S_OK, "ret %08x\n", hr);
119 ok(enc == IET_7BIT, "encoding %d\n", enc);
121 hr = IMimeBody_Load(body, in);
122 ok(hr == S_OK, "ret %08x\n", hr);
124 IStream_Seek(in, off, STREAM_SEEK_CUR, &pos);
125 ok(pos.u.LowPart == 359, "pos %u\n", pos.u.LowPart);
127 hr = IMimeBody_IsContentType(body, "multipart", "mixed");
128 ok(hr == S_OK, "ret %08x\n", hr);
129 hr = IMimeBody_IsContentType(body, "text", "plain");
130 ok(hr == S_FALSE, "ret %08x\n", hr);
131 hr = IMimeBody_IsContentType(body, NULL, "mixed");
132 ok(hr == S_OK, "ret %08x\n", hr);
133 hr = IMimeBody_IsType(body, IBT_EMPTY);
134 ok(hr == S_OK, "got %08x\n", hr);
136 hr = IMimeBody_SetData(body, IET_8BIT, "text", "plain", &IID_IStream, in);
137 ok(hr == S_OK, "ret %08x\n", hr);
138 hr = IMimeBody_IsContentType(body, "text", "plain");
140 ok(hr == S_OK, "ret %08x\n", hr);
141 hr = IMimeBody_GetCurrentEncoding(body, &enc);
142 ok(hr == S_OK, "ret %08x\n", hr);
143 ok(enc == IET_8BIT, "encoding %d\n", enc);
145 memset(&offsets, 0xcc, sizeof(offsets));
146 hr = IMimeBody_GetOffsets(body, &offsets);
147 ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
148 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
149 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
150 ok(offsets.cbBodyStart == 0, "got %d\n", offsets.cbBodyStart);
151 ok(offsets.cbBodyEnd == 0, "got %d\n", offsets.cbBodyEnd);
153 hr = IMimeBody_IsType(body, IBT_EMPTY);
154 ok(hr == S_FALSE, "got %08x\n", hr);
156 hr = MimeOleGetAllocator(&alloc);
157 ok(hr == S_OK, "ret %08x\n", hr);
159 hr = IMimeBody_GetParameters(body, "nothere", &count, ¶m_info);
160 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
161 ok(count == 0, "got %d\n", count);
162 ok(!param_info, "got %p\n", param_info);
164 hr = IMimeBody_GetParameters(body, "bar", &count, ¶m_info);
165 ok(hr == S_OK, "ret %08x\n", hr);
166 ok(count == 0, "got %d\n", count);
167 ok(!param_info, "got %p\n", param_info);
169 hr = IMimeBody_GetParameters(body, "Content-Type", &count, ¶m_info);
170 ok(hr == S_OK, "ret %08x\n", hr);
171 todo_wine /* native adds a charset parameter */
172 ok(count == 4, "got %d\n", count);
173 ok(param_info != NULL, "got %p\n", param_info);
176 for(i = 0; i < count; i++)
178 if(!strcmp(param_info[i].pszName, "morestuff"))
181 ok(!strcmp(param_info[i].pszData, "so\\me\"thing\""),
182 "got %s\n", param_info[i].pszData);
184 else if(!strcmp(param_info[i].pszName, "stuff"))
187 ok(!strcmp(param_info[i].pszData, "du;nno"),
188 "got %s\n", param_info[i].pszData);
191 ok(found_param == 2, "matched %d params\n", found_param);
193 hr = IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
194 ok(hr == S_OK, "ret %08x\n", hr);
195 IMimeAllocator_Release(alloc);
198 IMimeBody_Release(body);
201 static void test_Allocator(void)
204 IMimeAllocator *alloc;
206 hr = MimeOleGetAllocator(&alloc);
207 ok(hr == S_OK, "ret %08x\n", hr);
208 IMimeAllocator_Release(alloc);
211 static void test_CreateMessage(void)
222 FINDBODY find_struct;
225 char text[] = "text";
228 static char att_pritype[] = "att:pri-content-type";
230 hr = MimeOleCreateMessage(NULL, &msg);
231 ok(hr == S_OK, "ret %08x\n", hr);
233 CreateStreamOnHGlobal(NULL, TRUE, &stream);
234 IStream_Write(stream, msg1, sizeof(msg1) - 1, NULL);
236 IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
238 hr = IMimeMessage_Load(msg, stream);
239 ok(hr == S_OK, "ret %08x\n", hr);
241 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, TRUE, &count);
242 ok(hr == S_OK, "ret %08x\n", hr);
243 ok(count == 3, "got %d\n", count);
245 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, FALSE, &count);
246 ok(hr == S_OK, "ret %08x\n", hr);
247 ok(count == 3, "got %d\n", count);
249 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
250 ok(hr == S_OK, "ret %08x\n", hr);
251 hr = IMimeBody_GetOffsets(body, &offsets);
252 ok(hr == S_OK, "ret %08x\n", hr);
253 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
254 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
255 ok(offsets.cbBodyStart == 359, "got %d\n", offsets.cbBodyStart);
256 ok(offsets.cbBodyEnd == 666, "got %d\n", offsets.cbBodyEnd);
257 IMimeBody_Release(body);
259 hr = IMimeMessage_GetBody(msg, IBL_ROOT, NULL, &hbody);
260 ok(hr == S_OK, "ret %08x\n", hr);
262 PropVariantInit(&prop);
263 hr = IMimeMessage_GetBodyProp(msg, hbody, att_pritype, 0, &prop);
264 ok(hr == S_OK, "ret %08x\n", hr);
265 ok(prop.vt == VT_LPSTR, "vt %08x\n", prop.vt);
266 ok(!strcasecmp(prop.u.pszVal, "multipart"), "got %s\n", prop.u.pszVal);
267 PropVariantClear(&prop);
269 hr = IMimeMessage_GetBody(msg, IBL_FIRST, hbody, &hbody);
270 ok(hr == S_OK, "ret %08x\n", hr);
271 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
272 ok(hr == S_OK, "ret %08x\n", hr);
273 hr = IMimeBody_GetOffsets(body, &offsets);
274 ok(hr == S_OK, "ret %08x\n", hr);
275 ok(offsets.cbBoundaryStart == 405, "got %d\n", offsets.cbBoundaryStart);
276 ok(offsets.cbHeaderStart == 428, "got %d\n", offsets.cbHeaderStart);
277 ok(offsets.cbBodyStart == 518, "got %d\n", offsets.cbBodyStart);
278 ok(offsets.cbBodyEnd == 523, "got %d\n", offsets.cbBodyEnd);
280 hr = IMimeBody_GetCharset(body, &hcs);
281 ok(hr == S_OK, "ret %08x\n", hr);
284 ok(hcs != NULL, "Expected non-NULL charset\n");
287 IMimeBody_Release(body);
289 hr = IMimeMessage_GetBody(msg, IBL_NEXT, hbody, &hbody);
290 ok(hr == S_OK, "ret %08x\n", hr);
291 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
292 ok(hr == S_OK, "ret %08x\n", hr);
293 hr = IMimeBody_GetOffsets(body, &offsets);
294 ok(hr == S_OK, "ret %08x\n", hr);
295 ok(offsets.cbBoundaryStart == 525, "got %d\n", offsets.cbBoundaryStart);
296 ok(offsets.cbHeaderStart == 548, "got %d\n", offsets.cbHeaderStart);
297 ok(offsets.cbBodyStart == 629, "got %d\n", offsets.cbBodyStart);
298 ok(offsets.cbBodyEnd == 639, "got %d\n", offsets.cbBodyEnd);
299 IMimeBody_Release(body);
301 find_struct.pszPriType = text;
302 find_struct.pszSubType = NULL;
304 hr = IMimeMessage_FindFirst(msg, &find_struct, &hbody);
305 ok(hr == S_OK, "ret %08x\n", hr);
307 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
308 ok(hr == S_OK, "ret %08x\n", hr);
310 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
311 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
313 hr = IMimeMessage_GetAttachments(msg, &count, &body_list);
314 ok(hr == S_OK, "ret %08x\n", hr);
315 ok(count == 2, "got %d\n", count);
316 CoTaskMemFree(body_list);
318 hr = IMimeMessage_GetCharset(body, &hcs);
319 ok(hr == S_OK, "ret %08x\n", hr);
322 ok(hcs != NULL, "Expected non-NULL charset\n");
325 IMimeMessage_Release(msg);
327 ref = IStream_AddRef(stream);
329 broken(ref == 1), /* win95 */
331 IStream_Release(stream);
333 IStream_Release(stream);
339 test_CreateVirtualStream();
340 test_CreateSecurity();
343 test_CreateMessage();