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
35 #include "wine/test.h"
38 "MIME-Version: 1.0\r\n"
39 "Content-Type: multipart/mixed;\r\n"
40 " boundary=\"------------1.5.0.6\";\r\n"
41 " stuff=\"du;nno\";\r\n"
42 " morestuff=\"so\\\\me\\\"thing\\\"\"\r\n"
44 "From: Huw Davies <huw@codeweavers.com>\r\n"
45 "From: Me <xxx@codeweavers.com>\r\n"
46 "To: wine-patches <wine-patches@winehq.org>\r\n"
47 "Cc: Huw Davies <huw@codeweavers.com>,\r\n"
48 " \"Fred Bloggs\" <fred@bloggs.com>\r\n"
52 "This is a multi-part message in MIME format.\r\n"
53 "--------------1.5.0.6\r\n"
54 "Content-Type: text/plain; format=fixed; charset=UTF-8\r\n"
55 "Content-Transfer-Encoding: 8bit\r\n"
58 "--------------1.5.0.6\r\n"
59 "Content-Type: text/plain; charset=\"us-ascii\"\r\n"
60 "Content-Transfer-Encoding: 7bit\r\n"
63 "--------------1.5.0.6--\r\n";
65 static void test_CreateVirtualStream(void)
70 hr = MimeOleCreateVirtualStream(&pstm);
71 ok(hr == S_OK, "ret %08x\n", hr);
73 IStream_Release(pstm);
76 static void test_CreateSecurity(void)
81 hr = MimeOleCreateSecurity(&sec);
82 ok(hr == S_OK, "ret %08x\n", hr);
84 IMimeSecurity_Release(sec);
87 static void test_CreateBody(void)
91 HBODY handle = (void *)0xdeadbeef;
96 ULONG count, found_param, i;
97 MIMEPARAMINFO *param_info;
98 IMimeAllocator *alloc;
101 hr = CoCreateInstance(&CLSID_IMimeBody, NULL, CLSCTX_INPROC_SERVER, &IID_IMimeBody, (void**)&body);
102 ok(hr == S_OK, "ret %08x\n", hr);
104 hr = IMimeBody_GetHandle(body, &handle);
105 ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
106 ok(handle == NULL, "handle %p\n", handle);
108 hr = CreateStreamOnHGlobal(NULL, TRUE, &in);
109 ok(hr == S_OK, "ret %08x\n", hr);
110 IStream_Write(in, msg1, sizeof(msg1) - 1, NULL);
112 IStream_Seek(in, off, STREAM_SEEK_SET, NULL);
114 /* Need to call InitNew before Load otherwise Load crashes with native inetcomm */
115 hr = IMimeBody_InitNew(body);
116 ok(hr == S_OK, "ret %08x\n", hr);
118 hr = IMimeBody_GetCurrentEncoding(body, &enc);
119 ok(hr == S_OK, "ret %08x\n", hr);
120 ok(enc == IET_7BIT, "encoding %d\n", enc);
122 hr = IMimeBody_Load(body, in);
123 ok(hr == S_OK, "ret %08x\n", hr);
125 IStream_Seek(in, off, STREAM_SEEK_CUR, &pos);
126 ok(pos.u.LowPart == 359, "pos %u\n", pos.u.LowPart);
128 hr = IMimeBody_IsContentType(body, "multipart", "mixed");
129 ok(hr == S_OK, "ret %08x\n", hr);
130 hr = IMimeBody_IsContentType(body, "text", "plain");
131 ok(hr == S_FALSE, "ret %08x\n", hr);
132 hr = IMimeBody_IsContentType(body, NULL, "mixed");
133 ok(hr == S_OK, "ret %08x\n", hr);
135 hr = IMimeBody_SetData(body, IET_8BIT, "text", "plain", &IID_IStream, in);
136 ok(hr == S_OK, "ret %08x\n", hr);
137 hr = IMimeBody_IsContentType(body, "text", "plain");
139 ok(hr == S_OK, "ret %08x\n", hr);
140 hr = IMimeBody_GetCurrentEncoding(body, &enc);
141 ok(hr == S_OK, "ret %08x\n", hr);
142 ok(enc == IET_8BIT, "encoding %d\n", enc);
144 memset(&offsets, 0xcc, sizeof(offsets));
145 hr = IMimeBody_GetOffsets(body, &offsets);
146 ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
147 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
148 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
149 ok(offsets.cbBodyStart == 0, "got %d\n", offsets.cbBodyStart);
150 ok(offsets.cbBodyEnd == 0, "got %d\n", offsets.cbBodyEnd);
152 hr = MimeOleGetAllocator(&alloc);
153 ok(hr == S_OK, "ret %08x\n", hr);
155 hr = IMimeBody_GetParameters(body, "nothere", &count, ¶m_info);
156 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
157 ok(count == 0, "got %d\n", count);
158 ok(!param_info, "got %p\n", param_info);
160 hr = IMimeBody_GetParameters(body, "bar", &count, ¶m_info);
161 ok(hr == S_OK, "ret %08x\n", hr);
162 ok(count == 0, "got %d\n", count);
163 ok(!param_info, "got %p\n", param_info);
165 hr = IMimeBody_GetParameters(body, "Content-Type", &count, ¶m_info);
166 ok(hr == S_OK, "ret %08x\n", hr);
167 todo_wine /* native adds a charset parameter */
168 ok(count == 4, "got %d\n", count);
169 ok(param_info != NULL, "got %p\n", param_info);
172 for(i = 0; i < count; i++)
174 if(!strcmp(param_info[i].pszName, "morestuff"))
177 ok(!strcmp(param_info[i].pszData, "so\\me\"thing\""),
178 "got %s\n", param_info[i].pszData);
180 else if(!strcmp(param_info[i].pszName, "stuff"))
183 ok(!strcmp(param_info[i].pszData, "du;nno"),
184 "got %s\n", param_info[i].pszData);
187 ok(found_param == 2, "matched %d params\n", found_param);
189 hr = IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
190 ok(hr == S_OK, "ret %08x\n", hr);
191 IMimeAllocator_Release(alloc);
194 IMimeBody_Release(body);
197 static void test_Allocator(void)
200 IMimeAllocator *alloc;
202 hr = MimeOleGetAllocator(&alloc);
203 ok(hr == S_OK, "ret %08x\n", hr);
204 IMimeAllocator_Release(alloc);
207 static void test_CreateMessage(void)
218 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);
279 ok(hcs != NULL, "Expected non-NULL charset\n");
282 IMimeBody_Release(body);
284 hr = IMimeMessage_GetBody(msg, IBL_NEXT, hbody, &hbody);
285 ok(hr == S_OK, "ret %08x\n", hr);
286 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
287 ok(hr == S_OK, "ret %08x\n", hr);
288 hr = IMimeBody_GetOffsets(body, &offsets);
289 ok(hr == S_OK, "ret %08x\n", hr);
290 ok(offsets.cbBoundaryStart == 525, "got %d\n", offsets.cbBoundaryStart);
291 ok(offsets.cbHeaderStart == 548, "got %d\n", offsets.cbHeaderStart);
292 ok(offsets.cbBodyStart == 629, "got %d\n", offsets.cbBodyStart);
293 ok(offsets.cbBodyEnd == 639, "got %d\n", offsets.cbBodyEnd);
294 IMimeBody_Release(body);
296 find_struct.pszPriType = text;
297 find_struct.pszSubType = NULL;
299 hr = IMimeMessage_FindFirst(msg, &find_struct, &hbody);
300 ok(hr == S_OK, "ret %08x\n", hr);
302 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
303 ok(hr == S_OK, "ret %08x\n", hr);
305 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
306 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
308 hr = IMimeMessage_GetAttachments(msg, &count, &body_list);
309 ok(hr == S_OK, "ret %08x\n", hr);
310 ok(count == 2, "got %d\n", count);
311 CoTaskMemFree(body_list);
313 hr = IMimeMessage_GetCharset(body, &hcs);
314 ok(hr == S_OK, "ret %08x\n", hr);
317 ok(hcs != NULL, "Expected non-NULL charset\n");
320 IMimeMessage_Release(msg);
322 ref = IStream_AddRef(stream);
323 ok(ref == 2, "ref %d\n", ref);
324 IStream_Release(stream);
326 IStream_Release(stream);
332 test_CreateVirtualStream();
333 test_CreateSecurity();
336 test_CreateMessage();