comctl32/tests: Add NULL terminator to unicode string constant.
[wine/hramrach.git] / dlls / inetcomm / tests / mimeole.c
blob7edef676f5039f1fa860b614d24f80c807130c36
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 "initguid.h"
25 #include "windows.h"
26 #include "ole2.h"
27 #include "ocidl.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);
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");
139 todo_wine
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, &param_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, &param_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, &param_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);
175 found_param = 0;
176 for(i = 0; i < count; i++)
178 if(!strcmp(param_info[i].pszName, "morestuff"))
180 found_param++;
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"))
186 found_param++;
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);
197 IStream_Release(in);
198 IMimeBody_Release(body);
201 static void test_Allocator(void)
203 HRESULT hr;
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)
213 HRESULT hr;
214 IMimeMessage *msg;
215 IStream *stream;
216 LARGE_INTEGER pos;
217 LONG ref;
218 HBODY hbody;
219 IMimeBody *body;
220 BODYOFFSETS offsets;
221 ULONG count;
222 FINDBODY find_struct;
223 HCHARSET hcs;
225 char text[] = "text";
226 HBODY *body_list;
227 PROPVARIANT prop;
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);
235 pos.QuadPart = 0;
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);
261 PropVariantInit(&prop);
262 hr = IMimeMessage_GetBodyProp(msg, hbody, att_pritype, 0, &prop);
263 ok(hr == S_OK, "ret %08x\n", hr);
264 ok(prop.vt == VT_LPSTR, "vt %08x\n", prop.vt);
265 ok(!strcasecmp(prop.u.pszVal, "multipart"), "got %s\n", prop.u.pszVal);
266 PropVariantClear(&prop);
268 hr = IMimeMessage_GetBody(msg, IBL_FIRST, hbody, &hbody);
269 ok(hr == S_OK, "ret %08x\n", hr);
270 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
271 ok(hr == S_OK, "ret %08x\n", hr);
272 hr = IMimeBody_GetOffsets(body, &offsets);
273 ok(hr == S_OK, "ret %08x\n", hr);
274 ok(offsets.cbBoundaryStart == 405, "got %d\n", offsets.cbBoundaryStart);
275 ok(offsets.cbHeaderStart == 428, "got %d\n", offsets.cbHeaderStart);
276 ok(offsets.cbBodyStart == 518, "got %d\n", offsets.cbBodyStart);
277 ok(offsets.cbBodyEnd == 523, "got %d\n", offsets.cbBodyEnd);
279 hr = IMimeBody_GetCharset(body, &hcs);
280 ok(hr == S_OK, "ret %08x\n", hr);
281 todo_wine
283 ok(hcs != NULL, "Expected non-NULL charset\n");
286 IMimeBody_Release(body);
288 hr = IMimeMessage_GetBody(msg, IBL_NEXT, hbody, &hbody);
289 ok(hr == S_OK, "ret %08x\n", hr);
290 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
291 ok(hr == S_OK, "ret %08x\n", hr);
292 hr = IMimeBody_GetOffsets(body, &offsets);
293 ok(hr == S_OK, "ret %08x\n", hr);
294 ok(offsets.cbBoundaryStart == 525, "got %d\n", offsets.cbBoundaryStart);
295 ok(offsets.cbHeaderStart == 548, "got %d\n", offsets.cbHeaderStart);
296 ok(offsets.cbBodyStart == 629, "got %d\n", offsets.cbBodyStart);
297 ok(offsets.cbBodyEnd == 639, "got %d\n", offsets.cbBodyEnd);
298 IMimeBody_Release(body);
300 find_struct.pszPriType = text;
301 find_struct.pszSubType = NULL;
303 hr = IMimeMessage_FindFirst(msg, &find_struct, &hbody);
304 ok(hr == S_OK, "ret %08x\n", hr);
306 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
307 ok(hr == S_OK, "ret %08x\n", hr);
309 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
310 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
312 hr = IMimeMessage_GetAttachments(msg, &count, &body_list);
313 ok(hr == S_OK, "ret %08x\n", hr);
314 ok(count == 2, "got %d\n", count);
315 CoTaskMemFree(body_list);
317 hr = IMimeMessage_GetCharset(body, &hcs);
318 ok(hr == S_OK, "ret %08x\n", hr);
319 todo_wine
321 ok(hcs != NULL, "Expected non-NULL charset\n");
324 IMimeMessage_Release(msg);
326 ref = IStream_AddRef(stream);
327 ok(ref == 2 ||
328 broken(ref == 1), /* win95 */
329 "ref %d\n", ref);
330 IStream_Release(stream);
332 IStream_Release(stream);
335 START_TEST(mimeole)
337 OleInitialize(NULL);
338 test_CreateVirtualStream();
339 test_CreateSecurity();
340 test_CreateBody();
341 test_Allocator();
342 test_CreateMessage();
343 OleUninitialize();