inetcomm: Implement IMimeBody_GetProp for the primary context type.
[wine.git] / dlls / inetcomm / tests / mimeole.c
blobd268e9d0505e5372167fcb8d375e74ff3be82e78
1 /*
2 * MimeOle tests
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
21 #define COBJMACROS
22 #define NONAMELESSUNION
24 #include "windows.h"
25 #include "ole2.h"
26 #include "ocidl.h"
28 #include "initguid.h"
29 #include "mimeole.h"
31 #include <stdio.h>
32 #include <assert.h>
34 #include "wine/test.h"
36 static char msg1[] =
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"
42 "foo: bar\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"
48 "foo: baz\r\n"
49 "bar: fum\r\n"
50 "\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"
55 "\r\n"
56 "Stuff\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"
60 "\r\n"
61 "More stuff\r\n"
62 "--------------1.5.0.6--\r\n";
64 static void test_CreateVirtualStream(void)
66 HRESULT hr;
67 IStream *pstm;
69 hr = MimeOleCreateVirtualStream(&pstm);
70 ok(hr == S_OK, "ret %08x\n", hr);
72 IStream_Release(pstm);
75 static void test_CreateSecurity(void)
77 HRESULT hr;
78 IMimeSecurity *sec;
80 hr = MimeOleCreateSecurity(&sec);
81 ok(hr == S_OK, "ret %08x\n", hr);
83 IMimeSecurity_Release(sec);
86 static void test_CreateBody(void)
88 HRESULT hr;
89 IMimeBody *body;
90 HBODY handle = (void *)0xdeadbeef;
91 IStream *in;
92 LARGE_INTEGER off;
93 ULARGE_INTEGER pos;
94 ENCODINGTYPE enc;
95 ULONG count, found_param, i;
96 MIMEPARAMINFO *param_info;
97 IMimeAllocator *alloc;
98 BODYOFFSETS offsets;
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);
110 off.QuadPart = 0;
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);
123 off.QuadPart = 0;
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");
137 todo_wine
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, &param_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, &param_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, &param_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);
170 found_param = 0;
171 for(i = 0; i < count; i++)
173 if(!strcmp(param_info[i].pszName, "morestuff"))
175 found_param++;
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"))
181 found_param++;
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);
192 IStream_Release(in);
193 IMimeBody_Release(body);
196 static void test_Allocator(void)
198 HRESULT hr;
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)
208 HRESULT hr;
209 IMimeMessage *msg;
210 IStream *stream;
211 LARGE_INTEGER pos;
212 LONG ref;
213 HBODY hbody;
214 IMimeBody *body;
215 BODYOFFSETS offsets;
216 ULONG count;
217 FINDBODY find_struct;
218 char text[] = "text";
219 HBODY *body_list;
220 PROPVARIANT prop;
221 static char att_pritype[] = "att:pri-content-type";
223 hr = MimeOleCreateMessage(NULL, &msg);
224 ok(hr == S_OK, "ret %08x\n", hr);
226 CreateStreamOnHGlobal(NULL, TRUE, &stream);
227 IStream_Write(stream, msg1, sizeof(msg1) - 1, NULL);
228 pos.QuadPart = 0;
229 IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
231 hr = IMimeMessage_Load(msg, stream);
232 ok(hr == S_OK, "ret %08x\n", hr);
234 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, TRUE, &count);
235 ok(hr == S_OK, "ret %08x\n", hr);
236 ok(count == 3, "got %d\n", count);
238 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, FALSE, &count);
239 ok(hr == S_OK, "ret %08x\n", hr);
240 ok(count == 3, "got %d\n", count);
242 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
243 ok(hr == S_OK, "ret %08x\n", hr);
244 hr = IMimeBody_GetOffsets(body, &offsets);
245 ok(hr == S_OK, "ret %08x\n", hr);
246 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
247 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
248 ok(offsets.cbBodyStart == 359, "got %d\n", offsets.cbBodyStart);
249 ok(offsets.cbBodyEnd == 666, "got %d\n", offsets.cbBodyEnd);
250 IMimeBody_Release(body);
252 hr = IMimeMessage_GetBody(msg, IBL_ROOT, NULL, &hbody);
254 PropVariantInit(&prop);
255 hr = IMimeMessage_GetBodyProp(msg, hbody, att_pritype, 0, &prop);
256 ok(hr == S_OK, "ret %08x\n", hr);
257 ok(prop.vt == VT_LPSTR, "vt %08x\n", prop.vt);
258 ok(!strcasecmp(prop.u.pszVal, "multipart"), "got %s\n", prop.u.pszVal);
259 PropVariantClear(&prop);
261 hr = IMimeMessage_GetBody(msg, IBL_FIRST, hbody, &hbody);
262 ok(hr == S_OK, "ret %08x\n", hr);
263 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
264 ok(hr == S_OK, "ret %08x\n", hr);
265 hr = IMimeBody_GetOffsets(body, &offsets);
266 ok(hr == S_OK, "ret %08x\n", hr);
267 ok(offsets.cbBoundaryStart == 405, "got %d\n", offsets.cbBoundaryStart);
268 ok(offsets.cbHeaderStart == 428, "got %d\n", offsets.cbHeaderStart);
269 ok(offsets.cbBodyStart == 518, "got %d\n", offsets.cbBodyStart);
270 ok(offsets.cbBodyEnd == 523, "got %d\n", offsets.cbBodyEnd);
271 IMimeBody_Release(body);
273 hr = IMimeMessage_GetBody(msg, IBL_NEXT, hbody, &hbody);
274 ok(hr == S_OK, "ret %08x\n", hr);
275 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
276 ok(hr == S_OK, "ret %08x\n", hr);
277 hr = IMimeBody_GetOffsets(body, &offsets);
278 ok(hr == S_OK, "ret %08x\n", hr);
279 ok(offsets.cbBoundaryStart == 525, "got %d\n", offsets.cbBoundaryStart);
280 ok(offsets.cbHeaderStart == 548, "got %d\n", offsets.cbHeaderStart);
281 ok(offsets.cbBodyStart == 629, "got %d\n", offsets.cbBodyStart);
282 ok(offsets.cbBodyEnd == 639, "got %d\n", offsets.cbBodyEnd);
283 IMimeBody_Release(body);
285 find_struct.pszPriType = text;
286 find_struct.pszSubType = NULL;
288 hr = IMimeMessage_FindFirst(msg, &find_struct, &hbody);
289 ok(hr == S_OK, "ret %08x\n", hr);
291 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
292 ok(hr == S_OK, "ret %08x\n", hr);
294 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
295 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
297 hr = IMimeMessage_GetAttachments(msg, &count, &body_list);
298 ok(hr == S_OK, "ret %08x\n", hr);
299 ok(count == 2, "got %d\n", count);
300 CoTaskMemFree(body_list);
302 IMimeMessage_Release(msg);
304 ref = IStream_AddRef(stream);
305 ok(ref == 2, "ref %d\n", ref);
306 IStream_Release(stream);
308 IStream_Release(stream);
311 START_TEST(mimeole)
313 OleInitialize(NULL);
314 test_CreateVirtualStream();
315 test_CreateSecurity();
316 test_CreateBody();
317 test_Allocator();
318 test_CreateMessage();
319 OleUninitialize();