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);
134 hr = IMimeBody_SetData(body, IET_8BIT, "text", "plain", &IID_IStream, in);
135 ok(hr == S_OK, "ret %08x\n", hr);
136 hr = IMimeBody_IsContentType(body, "text", "plain");
138 ok(hr == S_OK, "ret %08x\n", hr);
139 hr = IMimeBody_GetCurrentEncoding(body, &enc);
140 ok(hr == S_OK, "ret %08x\n", hr);
141 ok(enc == IET_8BIT, "encoding %d\n", enc);
143 memset(&offsets, 0xcc, sizeof(offsets));
144 hr = IMimeBody_GetOffsets(body, &offsets);
145 ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
146 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
147 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
148 ok(offsets.cbBodyStart == 0, "got %d\n", offsets.cbBodyStart);
149 ok(offsets.cbBodyEnd == 0, "got %d\n", offsets.cbBodyEnd);
151 hr = MimeOleGetAllocator(&alloc);
152 ok(hr == S_OK, "ret %08x\n", hr);
154 hr = IMimeBody_GetParameters(body, "nothere", &count, ¶m_info);
155 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
156 ok(count == 0, "got %d\n", count);
157 ok(!param_info, "got %p\n", param_info);
159 hr = IMimeBody_GetParameters(body, "bar", &count, ¶m_info);
160 ok(hr == S_OK, "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, "Content-Type", &count, ¶m_info);
165 ok(hr == S_OK, "ret %08x\n", hr);
166 todo_wine /* native adds a charset parameter */
167 ok(count == 4, "got %d\n", count);
168 ok(param_info != NULL, "got %p\n", param_info);
171 for(i = 0; i < count; i++)
173 if(!strcmp(param_info[i].pszName, "morestuff"))
176 ok(!strcmp(param_info[i].pszData, "so\\me\"thing\""),
177 "got %s\n", param_info[i].pszData);
179 else if(!strcmp(param_info[i].pszName, "stuff"))
182 ok(!strcmp(param_info[i].pszData, "du;nno"),
183 "got %s\n", param_info[i].pszData);
186 ok(found_param == 2, "matched %d params\n", found_param);
188 hr = IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
189 ok(hr == S_OK, "ret %08x\n", hr);
190 IMimeAllocator_Release(alloc);
193 IMimeBody_Release(body);
196 static void test_Allocator(void)
199 IMimeAllocator *alloc;
201 hr = MimeOleGetAllocator(&alloc);
202 ok(hr == S_OK, "ret %08x\n", hr);
203 IMimeAllocator_Release(alloc);
206 static void test_CreateMessage(void)
217 FINDBODY find_struct;
221 char text[] = "text";
224 static char att_pritype[] = "att:pri-content-type";
226 hr = MimeOleCreateMessage(NULL, &msg);
227 ok(hr == S_OK, "ret %08x\n", hr);
229 CreateStreamOnHGlobal(NULL, TRUE, &stream);
230 IStream_Write(stream, msg1, sizeof(msg1) - 1, NULL);
232 IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
234 hr = IMimeMessage_Load(msg, stream);
235 ok(hr == S_OK, "ret %08x\n", hr);
237 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, TRUE, &count);
238 ok(hr == S_OK, "ret %08x\n", hr);
239 ok(count == 3, "got %d\n", count);
241 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, FALSE, &count);
242 ok(hr == S_OK, "ret %08x\n", hr);
243 ok(count == 3, "got %d\n", count);
245 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
246 ok(hr == S_OK, "ret %08x\n", hr);
247 hr = IMimeBody_GetOffsets(body, &offsets);
248 ok(hr == S_OK, "ret %08x\n", hr);
249 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
250 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
251 ok(offsets.cbBodyStart == 359, "got %d\n", offsets.cbBodyStart);
252 ok(offsets.cbBodyEnd == 666, "got %d\n", offsets.cbBodyEnd);
253 IMimeBody_Release(body);
255 hr = IMimeMessage_GetBody(msg, IBL_ROOT, NULL, &hbody);
257 PropVariantInit(&prop);
258 hr = IMimeMessage_GetBodyProp(msg, hbody, att_pritype, 0, &prop);
259 ok(hr == S_OK, "ret %08x\n", hr);
260 ok(prop.vt == VT_LPSTR, "vt %08x\n", prop.vt);
261 ok(!strcasecmp(prop.u.pszVal, "multipart"), "got %s\n", prop.u.pszVal);
262 PropVariantClear(&prop);
264 hr = IMimeMessage_GetBody(msg, IBL_FIRST, hbody, &hbody);
265 ok(hr == S_OK, "ret %08x\n", hr);
266 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
267 ok(hr == S_OK, "ret %08x\n", hr);
268 hr = IMimeBody_GetOffsets(body, &offsets);
269 ok(hr == S_OK, "ret %08x\n", hr);
270 ok(offsets.cbBoundaryStart == 405, "got %d\n", offsets.cbBoundaryStart);
271 ok(offsets.cbHeaderStart == 428, "got %d\n", offsets.cbHeaderStart);
272 ok(offsets.cbBodyStart == 518, "got %d\n", offsets.cbBodyStart);
273 ok(offsets.cbBodyEnd == 523, "got %d\n", offsets.cbBodyEnd);
275 hr = IMimeBody_GetCharset(body, &hcs);
276 ok(hr == S_OK, "ret %08x\n", hr);
277 ok(hcs == NULL, "ret %p\n", hcs);
279 IMimeBody_Release(body);
281 hr = IMimeMessage_GetBody(msg, IBL_NEXT, hbody, &hbody);
282 ok(hr == S_OK, "ret %08x\n", hr);
283 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
284 ok(hr == S_OK, "ret %08x\n", hr);
285 hr = IMimeBody_GetOffsets(body, &offsets);
286 ok(hr == S_OK, "ret %08x\n", hr);
287 ok(offsets.cbBoundaryStart == 525, "got %d\n", offsets.cbBoundaryStart);
288 ok(offsets.cbHeaderStart == 548, "got %d\n", offsets.cbHeaderStart);
289 ok(offsets.cbBodyStart == 629, "got %d\n", offsets.cbBodyStart);
290 ok(offsets.cbBodyEnd == 639, "got %d\n", offsets.cbBodyEnd);
291 IMimeBody_Release(body);
293 find_struct.pszPriType = text;
294 find_struct.pszSubType = NULL;
296 hr = IMimeMessage_FindFirst(msg, &find_struct, &hbody);
297 ok(hr == S_OK, "ret %08x\n", hr);
299 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
300 ok(hr == S_OK, "ret %08x\n", hr);
302 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
303 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
305 hr = IMimeMessage_GetAttachments(msg, &count, &body_list);
306 ok(hr == S_OK, "ret %08x\n", hr);
307 ok(count == 2, "got %d\n", count);
308 CoTaskMemFree(body_list);
310 hr = IMimeMessage_GetCharset(body, &hcs);
311 ok(hr == S_OK, "ret %08x\n", hr);
312 ok(hcs == NULL, "ret %p\n", hcs);
313 hr = MimeOleGetCharsetInfo(hcs, &csi);
314 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
316 IMimeMessage_Release(msg);
318 ref = IStream_AddRef(stream);
319 ok(ref == 2, "ref %d\n", ref);
320 IStream_Release(stream);
322 IStream_Release(stream);
328 test_CreateVirtualStream();
329 test_CreateSecurity();
332 test_CreateMessage();