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;
220 char text[] = "text";
223 static char att_pritype[] = "att:pri-content-type";
225 hr = MimeOleCreateMessage(NULL, &msg);
226 ok(hr == S_OK, "ret %08x\n", hr);
228 CreateStreamOnHGlobal(NULL, TRUE, &stream);
229 IStream_Write(stream, msg1, sizeof(msg1) - 1, NULL);
231 IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
233 hr = IMimeMessage_Load(msg, stream);
234 ok(hr == S_OK, "ret %08x\n", hr);
236 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, TRUE, &count);
237 ok(hr == S_OK, "ret %08x\n", hr);
238 ok(count == 3, "got %d\n", count);
240 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, FALSE, &count);
241 ok(hr == S_OK, "ret %08x\n", hr);
242 ok(count == 3, "got %d\n", count);
244 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
245 ok(hr == S_OK, "ret %08x\n", hr);
246 hr = IMimeBody_GetOffsets(body, &offsets);
247 ok(hr == S_OK, "ret %08x\n", hr);
248 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
249 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
250 ok(offsets.cbBodyStart == 359, "got %d\n", offsets.cbBodyStart);
251 ok(offsets.cbBodyEnd == 666, "got %d\n", offsets.cbBodyEnd);
252 IMimeBody_Release(body);
254 hr = IMimeMessage_GetBody(msg, IBL_ROOT, NULL, &hbody);
256 PropVariantInit(&prop);
257 hr = IMimeMessage_GetBodyProp(msg, hbody, att_pritype, 0, &prop);
258 ok(hr == S_OK, "ret %08x\n", hr);
259 ok(prop.vt == VT_LPSTR, "vt %08x\n", prop.vt);
260 ok(!strcasecmp(prop.u.pszVal, "multipart"), "got %s\n", prop.u.pszVal);
261 PropVariantClear(&prop);
263 hr = IMimeMessage_GetBody(msg, IBL_FIRST, hbody, &hbody);
264 ok(hr == S_OK, "ret %08x\n", hr);
265 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
266 ok(hr == S_OK, "ret %08x\n", hr);
267 hr = IMimeBody_GetOffsets(body, &offsets);
268 ok(hr == S_OK, "ret %08x\n", hr);
269 ok(offsets.cbBoundaryStart == 405, "got %d\n", offsets.cbBoundaryStart);
270 ok(offsets.cbHeaderStart == 428, "got %d\n", offsets.cbHeaderStart);
271 ok(offsets.cbBodyStart == 518, "got %d\n", offsets.cbBodyStart);
272 ok(offsets.cbBodyEnd == 523, "got %d\n", offsets.cbBodyEnd);
274 hr = IMimeBody_GetCharset(body, &hcs);
275 ok(hr == S_OK, "ret %08x\n", hr);
278 ok(hcs != NULL, "Expected non-NULL charset\n");
281 IMimeBody_Release(body);
283 hr = IMimeMessage_GetBody(msg, IBL_NEXT, hbody, &hbody);
284 ok(hr == S_OK, "ret %08x\n", hr);
285 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
286 ok(hr == S_OK, "ret %08x\n", hr);
287 hr = IMimeBody_GetOffsets(body, &offsets);
288 ok(hr == S_OK, "ret %08x\n", hr);
289 ok(offsets.cbBoundaryStart == 525, "got %d\n", offsets.cbBoundaryStart);
290 ok(offsets.cbHeaderStart == 548, "got %d\n", offsets.cbHeaderStart);
291 ok(offsets.cbBodyStart == 629, "got %d\n", offsets.cbBodyStart);
292 ok(offsets.cbBodyEnd == 639, "got %d\n", offsets.cbBodyEnd);
293 IMimeBody_Release(body);
295 find_struct.pszPriType = text;
296 find_struct.pszSubType = NULL;
298 hr = IMimeMessage_FindFirst(msg, &find_struct, &hbody);
299 ok(hr == S_OK, "ret %08x\n", hr);
301 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
302 ok(hr == S_OK, "ret %08x\n", hr);
304 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
305 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
307 hr = IMimeMessage_GetAttachments(msg, &count, &body_list);
308 ok(hr == S_OK, "ret %08x\n", hr);
309 ok(count == 2, "got %d\n", count);
310 CoTaskMemFree(body_list);
312 hr = IMimeMessage_GetCharset(body, &hcs);
313 ok(hr == S_OK, "ret %08x\n", hr);
316 ok(hcs != NULL, "Expected non-NULL charset\n");
319 IMimeMessage_Release(msg);
321 ref = IStream_AddRef(stream);
322 ok(ref == 2, "ref %d\n", ref);
323 IStream_Release(stream);
325 IStream_Release(stream);
331 test_CreateVirtualStream();
332 test_CreateSecurity();
335 test_CreateMessage();