Revert "winex11.drv: Optimise getting the bits of a DIB after calling SetDIBits."
[wine] / dlls / inetcomm / tests / mimeole.c
1 /*
2  * MimeOle tests
3  *
4  * Copyright 2007 Huw Davies
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define COBJMACROS
22 #define NONAMELESSUNION
23
24 #include "initguid.h"
25 #include "windows.h"
26 #include "ole2.h"
27 #include "ocidl.h"
28
29 #include "initguid.h"
30 #include "mimeole.h"
31
32 #include <stdio.h>
33 #include <assert.h>
34
35 #include "wine/test.h"
36
37 static char msg1[] =
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"
43     "foo: bar\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"
49     "foo: baz\r\n"
50     "bar: fum\r\n"
51     "\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"
56     "\r\n"
57     "Stuff\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"
61     "\r\n"
62     "More stuff\r\n"
63     "--------------1.5.0.6--\r\n";
64
65 static void test_CreateVirtualStream(void)
66 {
67     HRESULT hr;
68     IStream *pstm;
69
70     hr = MimeOleCreateVirtualStream(&pstm);
71     ok(hr == S_OK, "ret %08x\n", hr);
72
73     IStream_Release(pstm);
74 }
75
76 static void test_CreateSecurity(void)
77 {
78     HRESULT hr;
79     IMimeSecurity *sec;
80
81     hr = MimeOleCreateSecurity(&sec);
82     ok(hr == S_OK, "ret %08x\n", hr);
83
84     IMimeSecurity_Release(sec);
85 }
86
87 static void test_CreateBody(void)
88 {
89     HRESULT hr;
90     IMimeBody *body;
91     HBODY handle = (void *)0xdeadbeef;
92     IStream *in;
93     LARGE_INTEGER off;
94     ULARGE_INTEGER pos;
95     ENCODINGTYPE enc;
96     ULONG count, found_param, i;
97     MIMEPARAMINFO *param_info;
98     IMimeAllocator *alloc;
99     BODYOFFSETS offsets;
100
101     hr = CoCreateInstance(&CLSID_IMimeBody, NULL, CLSCTX_INPROC_SERVER, &IID_IMimeBody, (void**)&body);
102     ok(hr == S_OK, "ret %08x\n", hr);
103
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);
107
108     hr = CreateStreamOnHGlobal(NULL, TRUE, &in);
109     ok(hr == S_OK, "ret %08x\n", hr);
110     IStream_Write(in, msg1, sizeof(msg1) - 1, NULL);
111     off.QuadPart = 0;
112     IStream_Seek(in, off, STREAM_SEEK_SET, NULL);
113
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);
117
118     hr = IMimeBody_GetCurrentEncoding(body, &enc);
119     ok(hr == S_OK, "ret %08x\n", hr);
120     ok(enc == IET_7BIT, "encoding %d\n", enc);
121
122     hr = IMimeBody_Load(body, in);
123     ok(hr == S_OK, "ret %08x\n", hr);
124     off.QuadPart = 0;
125     IStream_Seek(in, off, STREAM_SEEK_CUR, &pos);
126     ok(pos.u.LowPart == 359, "pos %u\n", pos.u.LowPart);
127
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);
134
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");
138     todo_wine
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);
143
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);
151
152     hr = MimeOleGetAllocator(&alloc);
153     ok(hr == S_OK, "ret %08x\n", hr);
154
155     hr = IMimeBody_GetParameters(body, "nothere", &count, &param_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);
159
160     hr = IMimeBody_GetParameters(body, "bar", &count, &param_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);
164
165     hr = IMimeBody_GetParameters(body, "Content-Type", &count, &param_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);
170
171     found_param = 0;
172     for(i = 0; i < count; i++)
173     {
174         if(!strcmp(param_info[i].pszName, "morestuff"))
175         {
176             found_param++;
177             ok(!strcmp(param_info[i].pszData, "so\\me\"thing\""),
178                "got %s\n", param_info[i].pszData);
179         }
180         else if(!strcmp(param_info[i].pszName, "stuff"))
181         {
182             found_param++;
183             ok(!strcmp(param_info[i].pszData, "du;nno"),
184                "got %s\n", param_info[i].pszData);
185         }
186     }
187     ok(found_param == 2, "matched %d params\n", found_param);
188
189     hr = IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
190     ok(hr == S_OK, "ret %08x\n", hr);
191     IMimeAllocator_Release(alloc);
192
193     IStream_Release(in);
194     IMimeBody_Release(body);
195 }
196
197 static void test_Allocator(void)
198 {
199     HRESULT hr;
200     IMimeAllocator *alloc;
201
202     hr = MimeOleGetAllocator(&alloc);
203     ok(hr == S_OK, "ret %08x\n", hr);
204     IMimeAllocator_Release(alloc);
205 }
206
207 static void test_CreateMessage(void)
208 {
209     HRESULT hr;
210     IMimeMessage *msg;
211     IStream *stream;
212     LARGE_INTEGER pos;
213     LONG ref;
214     HBODY hbody;
215     IMimeBody *body;
216     BODYOFFSETS offsets;
217     ULONG count;
218     FINDBODY find_struct;
219     HCHARSET hcs;
220
221     char text[] = "text";
222     HBODY *body_list;
223     PROPVARIANT prop;
224     static char att_pritype[] = "att:pri-content-type";
225
226     hr = MimeOleCreateMessage(NULL, &msg);
227     ok(hr == S_OK, "ret %08x\n", hr);
228
229     CreateStreamOnHGlobal(NULL, TRUE, &stream);
230     IStream_Write(stream, msg1, sizeof(msg1) - 1, NULL);
231     pos.QuadPart = 0;
232     IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
233
234     hr = IMimeMessage_Load(msg, stream);
235     ok(hr == S_OK, "ret %08x\n", hr);
236
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);
240
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);
244
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);
254
255     hr = IMimeMessage_GetBody(msg, IBL_ROOT, NULL, &hbody);
256
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);
263
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);
274
275     hr = IMimeBody_GetCharset(body, &hcs);
276     ok(hr == S_OK, "ret %08x\n", hr);
277     todo_wine
278     {
279         ok(hcs != NULL, "Expected non-NULL charset\n");
280     }
281
282     IMimeBody_Release(body);
283
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);
295
296     find_struct.pszPriType = text;
297     find_struct.pszSubType = NULL;
298
299     hr = IMimeMessage_FindFirst(msg, &find_struct, &hbody);
300     ok(hr == S_OK, "ret %08x\n", hr);
301
302     hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
303     ok(hr == S_OK, "ret %08x\n", hr);
304
305     hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
306     ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
307
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);
312
313     hr = IMimeMessage_GetCharset(body, &hcs);
314     ok(hr == S_OK, "ret %08x\n", hr);
315     todo_wine
316     {
317         ok(hcs != NULL, "Expected non-NULL charset\n");
318     }
319
320     IMimeMessage_Release(msg);
321
322     ref = IStream_AddRef(stream);
323     ok(ref == 2, "ref %d\n", ref);
324     IStream_Release(stream);
325
326     IStream_Release(stream);
327 }
328
329 START_TEST(mimeole)
330 {
331     OleInitialize(NULL);
332     test_CreateVirtualStream();
333     test_CreateSecurity();
334     test_CreateBody();
335     test_Allocator();
336     test_CreateMessage();
337     OleUninitialize();
338 }