[INETCOMM_WINETEST] Sync with Wine Staging 2.2. CORE-12823
[reactos.git] / rostests / winetests / inetcomm / 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 "mimeole.h"
30 #include "wininet.h"
31
32 #include <stdio.h>
33
34 #include "wine/test.h"
35
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
38
39 #define SET_EXPECT(func) \
40 expect_ ## func = TRUE
41
42 #define CHECK_EXPECT(func) \
43 do { \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 expect_ ## func = FALSE; \
46 called_ ## func = TRUE; \
47 }while(0)
48
49 #define CHECK_EXPECT2(func) \
50 do { \
51 ok(expect_ ##func, "unexpected call " #func "\n"); \
52 called_ ## func = TRUE; \
53 }while(0)
54
55 #define CHECK_CALLED(func) \
56 do { \
57 ok(called_ ## func, "expected " #func "\n"); \
58 expect_ ## func = called_ ## func = FALSE; \
59 }while(0)
60
61 DEFINE_EXPECT(Stream_Read);
62 DEFINE_EXPECT(Stream_Stat);
63 DEFINE_EXPECT(Stream_Seek);
64 DEFINE_EXPECT(Stream_Seek_END);
65 DEFINE_EXPECT(GetBindInfo);
66 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
67 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
68 DEFINE_EXPECT(ReportData);
69 DEFINE_EXPECT(ReportResult);
70
71 static const char msg1[] =
72 "MIME-Version: 1.0\r\n"
73 "Content-Type: multipart/mixed;\r\n"
74 " boundary=\"------------1.5.0.6\";\r\n"
75 " stuff=\"du;nno\";\r\n"
76 " morestuff=\"so\\\\me\\\"thing\\\"\"\r\n"
77 "foo: bar\r\n"
78 "From: Huw Davies <huw@codeweavers.com>\r\n"
79 "From: Me <xxx@codeweavers.com>\r\n"
80 "To: wine-patches <wine-patches@winehq.org>\r\n"
81 "Cc: Huw Davies <huw@codeweavers.com>,\r\n"
82 " \"Fred Bloggs\" <fred@bloggs.com>\r\n"
83 "foo: baz\r\n"
84 "bar: fum\r\n"
85 "\r\n"
86 "This is a multi-part message in MIME format.\r\n"
87 "--------------1.5.0.6\r\n"
88 "Content-Type: text/plain; format=fixed; charset=UTF-8\r\n"
89 "Content-Transfer-Encoding: 8bit\r\n"
90 "\r\n"
91 "Stuff\r\n"
92 "--------------1.5.0.6\r\n"
93 "Content-Type: text/plain; charset=\"us-ascii\"\r\n"
94 "Content-Transfer-Encoding: 7bit\r\n"
95 "\r\n"
96 "More stuff\r\n"
97 "--------------1.5.0.6--\r\n";
98
99 static const char mhtml_page1[] =
100 "MIME-Version: 1.0\r\n"
101 "Content-Type: multipart/related; type:=\"text/html\"; boundary=\"----=_NextPart_000_00\"\r\n"
102 "\r\n"
103 "------=_NextPart_000_00\r\n"
104 "Content-Type: text/html; charset=\"Windows-1252\"\r\n"
105 "Content-Transfer-Encoding: quoted-printable\r\n"
106 "\r\n"
107 "<HTML></HTML>\r\n"
108 "------=_NextPart_000_00\r\n"
109 "Content-Type: Image/Jpeg\r\n"
110 "Content-Transfer-Encoding: base64\r\n"
111 "Content-Location: http://winehq.org/mhtmltest.html\r\n"
112 "\r\n\t\t\t\tVGVzdA==\r\n\r\n"
113 "------=_NextPart_000_00--";
114
115 static WCHAR *a2w(const char *str)
116 {
117 WCHAR *ret;
118 int len;
119
120 if(!str)
121 return NULL;
122
123 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
124 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
125 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
126 return ret;
127 }
128
129 static int strcmp_wa(const WCHAR *strw, const char *stra)
130 {
131 WCHAR buf[512];
132 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
133 return lstrcmpW(strw, buf);
134 }
135
136 static void test_CreateVirtualStream(void)
137 {
138 HRESULT hr;
139 IStream *pstm;
140
141 hr = MimeOleCreateVirtualStream(&pstm);
142 ok(hr == S_OK, "ret %08x\n", hr);
143
144 IStream_Release(pstm);
145 }
146
147 static void test_CreateSecurity(void)
148 {
149 HRESULT hr;
150 IMimeSecurity *sec;
151
152 hr = MimeOleCreateSecurity(&sec);
153 ok(hr == S_OK, "ret %08x\n", hr);
154
155 IMimeSecurity_Release(sec);
156 }
157
158 static IStream *create_stream_from_string(const char *data)
159 {
160 LARGE_INTEGER off;
161 IStream *stream;
162 HRESULT hr;
163
164 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
165 ok(hr == S_OK, "ret %08x\n", hr);
166
167 hr = IStream_Write(stream, data, strlen(data), NULL);
168 ok(hr == S_OK, "Write failed: %08x\n", hr);
169
170 off.QuadPart = 0;
171 hr = IStream_Seek(stream, off, STREAM_SEEK_SET, NULL);
172 ok(hr == S_OK, "Seek failed: %08x\n", hr);
173
174 return stream;
175 }
176
177 #define test_current_encoding(a,b) _test_current_encoding(__LINE__,a,b)
178 static void _test_current_encoding(unsigned line, IMimeBody *mime_body, ENCODINGTYPE encoding)
179 {
180 ENCODINGTYPE current_encoding;
181 HRESULT hres;
182
183 hres = IMimeBody_GetCurrentEncoding(mime_body, &current_encoding);
184 ok_(__FILE__,line)(hres == S_OK, "GetCurrentEncoding failed: %08x\n", hres);
185 ok_(__FILE__,line)(current_encoding == encoding, "encoding = %d, expected %d\n", current_encoding, encoding);
186 }
187
188 static void test_CreateBody(void)
189 {
190 HRESULT hr;
191 IMimeBody *body;
192 HBODY handle = (void *)0xdeadbeef;
193 IStream *in;
194 LARGE_INTEGER off;
195 ULARGE_INTEGER pos;
196 ULONG count, found_param, i;
197 MIMEPARAMINFO *param_info;
198 IMimeAllocator *alloc;
199 BODYOFFSETS offsets;
200
201 hr = CoCreateInstance(&CLSID_IMimeBody, NULL, CLSCTX_INPROC_SERVER, &IID_IMimeBody, (void**)&body);
202 ok(hr == S_OK, "ret %08x\n", hr);
203
204 hr = IMimeBody_GetHandle(body, &handle);
205 ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
206 ok(handle == NULL, "handle %p\n", handle);
207
208 in = create_stream_from_string(msg1);
209
210 /* Need to call InitNew before Load otherwise Load crashes with native inetcomm */
211 hr = IMimeBody_InitNew(body);
212 ok(hr == S_OK, "ret %08x\n", hr);
213
214 test_current_encoding(body, IET_7BIT);
215
216 hr = IMimeBody_Load(body, in);
217 ok(hr == S_OK, "ret %08x\n", hr);
218 off.QuadPart = 0;
219 IStream_Seek(in, off, STREAM_SEEK_CUR, &pos);
220 ok(pos.u.LowPart == 359, "pos %u\n", pos.u.LowPart);
221
222 hr = IMimeBody_IsContentType(body, "multipart", "mixed");
223 ok(hr == S_OK, "ret %08x\n", hr);
224 hr = IMimeBody_IsContentType(body, "text", "plain");
225 ok(hr == S_FALSE, "ret %08x\n", hr);
226 hr = IMimeBody_IsContentType(body, NULL, "mixed");
227 ok(hr == S_OK, "ret %08x\n", hr);
228 hr = IMimeBody_IsType(body, IBT_EMPTY);
229 ok(hr == S_OK, "got %08x\n", hr);
230
231 hr = IMimeBody_SetData(body, IET_8BIT, "text", "plain", &IID_IStream, in);
232 ok(hr == S_OK, "ret %08x\n", hr);
233 hr = IMimeBody_IsContentType(body, "text", "plain");
234 todo_wine
235 ok(hr == S_OK, "ret %08x\n", hr);
236 test_current_encoding(body, IET_8BIT);
237
238 memset(&offsets, 0xcc, sizeof(offsets));
239 hr = IMimeBody_GetOffsets(body, &offsets);
240 ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
241 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
242 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
243 ok(offsets.cbBodyStart == 0, "got %d\n", offsets.cbBodyStart);
244 ok(offsets.cbBodyEnd == 0, "got %d\n", offsets.cbBodyEnd);
245
246 hr = IMimeBody_IsType(body, IBT_EMPTY);
247 ok(hr == S_FALSE, "got %08x\n", hr);
248
249 hr = MimeOleGetAllocator(&alloc);
250 ok(hr == S_OK, "ret %08x\n", hr);
251
252 hr = IMimeBody_GetParameters(body, "nothere", &count, &param_info);
253 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
254 ok(count == 0, "got %d\n", count);
255 ok(!param_info, "got %p\n", param_info);
256
257 hr = IMimeBody_GetParameters(body, "bar", &count, &param_info);
258 ok(hr == S_OK, "ret %08x\n", hr);
259 ok(count == 0, "got %d\n", count);
260 ok(!param_info, "got %p\n", param_info);
261
262 hr = IMimeBody_GetParameters(body, "Content-Type", &count, &param_info);
263 ok(hr == S_OK, "ret %08x\n", hr);
264 todo_wine /* native adds a charset parameter */
265 ok(count == 4, "got %d\n", count);
266 ok(param_info != NULL, "got %p\n", param_info);
267
268 found_param = 0;
269 for(i = 0; i < count; i++)
270 {
271 if(!strcmp(param_info[i].pszName, "morestuff"))
272 {
273 found_param++;
274 ok(!strcmp(param_info[i].pszData, "so\\me\"thing\""),
275 "got %s\n", param_info[i].pszData);
276 }
277 else if(!strcmp(param_info[i].pszName, "stuff"))
278 {
279 found_param++;
280 ok(!strcmp(param_info[i].pszData, "du;nno"),
281 "got %s\n", param_info[i].pszData);
282 }
283 }
284 ok(found_param == 2, "matched %d params\n", found_param);
285
286 hr = IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
287 ok(hr == S_OK, "ret %08x\n", hr);
288 IMimeAllocator_Release(alloc);
289
290 IStream_Release(in);
291 IMimeBody_Release(body);
292 }
293
294 typedef struct {
295 IStream IStream_iface;
296 LONG ref;
297 unsigned pos;
298 } TestStream;
299
300 static inline TestStream *impl_from_IStream(IStream *iface)
301 {
302 return CONTAINING_RECORD(iface, TestStream, IStream_iface);
303 }
304
305 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
306 {
307 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ISequentialStream, riid) || IsEqualGUID(&IID_IStream, riid)) {
308 *ppv = iface;
309 return S_OK;
310 }
311
312 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
313 *ppv = NULL;
314 return E_NOINTERFACE;
315 }
316
317 static ULONG WINAPI Stream_AddRef(IStream *iface)
318 {
319 TestStream *This = impl_from_IStream(iface);
320 return InterlockedIncrement(&This->ref);
321 }
322
323 static ULONG WINAPI Stream_Release(IStream *iface)
324 {
325 TestStream *This = impl_from_IStream(iface);
326 return InterlockedDecrement(&This->ref);
327 }
328
329 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv, ULONG cb, ULONG *pcbRead)
330 {
331 TestStream *This = impl_from_IStream(iface);
332 BYTE *output = pv;
333 unsigned i;
334
335 CHECK_EXPECT(Stream_Read);
336
337 for(i = 0; i < cb; i++)
338 output[i] = '0' + This->pos++;
339 *pcbRead = i;
340 return S_OK;
341 }
342
343 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv, ULONG cb, ULONG *pcbWritten)
344 {
345 ok(0, "unexpected call\n");
346 return E_NOTIMPL;
347 }
348
349 static DWORD expect_seek_pos;
350
351 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove, DWORD dwOrigin,
352 ULARGE_INTEGER *plibNewPosition)
353 {
354 TestStream *This = impl_from_IStream(iface);
355
356 if(dwOrigin == STREAM_SEEK_END) {
357 CHECK_EXPECT(Stream_Seek_END);
358 ok(dlibMove.QuadPart == expect_seek_pos, "unexpected seek pos %u\n", dlibMove.u.LowPart);
359 if(plibNewPosition)
360 plibNewPosition->QuadPart = 10;
361 return S_OK;
362 }
363
364 CHECK_EXPECT(Stream_Seek);
365
366 ok(dlibMove.QuadPart == expect_seek_pos, "unexpected seek pos %u\n", dlibMove.u.LowPart);
367 ok(dwOrigin == STREAM_SEEK_SET, "dwOrigin = %d\n", dwOrigin);
368 This->pos = dlibMove.QuadPart;
369 if(plibNewPosition)
370 plibNewPosition->QuadPart = This->pos;
371 return S_OK;
372 }
373
374 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
375 {
376 ok(0, "unexpected call\n");
377 return E_NOTIMPL;
378 }
379
380 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm, ULARGE_INTEGER cb,
381 ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
382 {
383 ok(0, "unexpected call\n");
384 return E_NOTIMPL;
385 }
386
387 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
388 {
389 ok(0, "unexpected call\n");
390 return E_NOTIMPL;
391 }
392
393 static HRESULT WINAPI Stream_Revert(IStream *iface)
394 {
395 ok(0, "unexpected call\n");
396 return E_NOTIMPL;
397 }
398
399 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
400 ULARGE_INTEGER cb, DWORD dwLockType)
401 {
402 ok(0, "unexpected call\n");
403 return E_NOTIMPL;
404 }
405
406 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
407 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
408 {
409 ok(0, "unexpected call\n");
410 return E_NOTIMPL;
411 }
412
413 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg, DWORD dwStatFlag)
414 {
415 CHECK_EXPECT(Stream_Stat);
416 ok(dwStatFlag == STATFLAG_NONAME, "dwStatFlag = %x\n", dwStatFlag);
417 return E_NOTIMPL;
418 }
419
420 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
421 {
422 ok(0, "unexpected call\n");
423 return E_NOTIMPL;
424 }
425
426 static /* const */ IStreamVtbl StreamVtbl = {
427 Stream_QueryInterface,
428 Stream_AddRef,
429 Stream_Release,
430 Stream_Read,
431 Stream_Write,
432 Stream_Seek,
433 Stream_SetSize,
434 Stream_CopyTo,
435 Stream_Commit,
436 Stream_Revert,
437 Stream_LockRegion,
438 Stream_UnlockRegion,
439 Stream_Stat,
440 Stream_Clone
441 };
442
443 static TestStream *create_test_stream(void)
444 {
445 TestStream *stream;
446 stream = HeapAlloc(GetProcessHeap(), 0, sizeof(*stream));
447 stream->IStream_iface.lpVtbl = &StreamVtbl;
448 stream->ref = 1;
449 stream->pos = 0;
450 return stream;
451 }
452
453 #define test_stream_read(a,b,c,d) _test_stream_read(__LINE__,a,b,c,d)
454 static void _test_stream_read(unsigned line, IStream *stream, HRESULT exhres, const char *exdata, unsigned read_size)
455 {
456 ULONG read = 0xdeadbeed, exread = strlen(exdata);
457 char buf[1024];
458 HRESULT hres;
459
460 if(read_size == -1)
461 read_size = sizeof(buf)-1;
462
463 hres = IStream_Read(stream, buf, read_size, &read);
464 ok_(__FILE__,line)(hres == exhres, "Read returned %08x, expected %08x\n", hres, exhres);
465 ok_(__FILE__,line)(read == exread, "unexpected read size %u, expected %u\n", read, exread);
466 buf[read] = 0;
467 ok_(__FILE__,line)(read == exread && !memcmp(buf, exdata, read), "unexpected data %s\n", buf);
468 }
469
470 static void test_SetData(void)
471 {
472 IStream *stream, *stream2;
473 TestStream *test_stream;
474 IMimeBody *body;
475 HRESULT hr;
476
477 hr = CoCreateInstance(&CLSID_IMimeBody, NULL, CLSCTX_INPROC_SERVER, &IID_IMimeBody, (void**)&body);
478 ok(hr == S_OK, "ret %08x\n", hr);
479
480 /* Need to call InitNew before Load otherwise Load crashes with native inetcomm */
481 hr = IMimeBody_InitNew(body);
482 ok(hr == S_OK, "ret %08x\n", hr);
483
484 stream = create_stream_from_string(msg1);
485 hr = IMimeBody_Load(body, stream);
486 ok(hr == S_OK, "ret %08x\n", hr);
487 IStream_Release(stream);
488
489 test_stream = create_test_stream();
490 hr = IMimeBody_SetData(body, IET_BINARY, "text", "plain", &IID_IStream, &test_stream->IStream_iface);
491
492 ok(hr == S_OK, "ret %08x\n", hr);
493 hr = IMimeBody_IsContentType(body, "text", "plain");
494 todo_wine
495 ok(hr == S_OK, "ret %08x\n", hr);
496
497 test_current_encoding(body, IET_BINARY);
498
499 SET_EXPECT(Stream_Stat);
500 SET_EXPECT(Stream_Seek_END);
501 hr = IMimeBody_GetData(body, IET_BINARY, &stream);
502 CHECK_CALLED(Stream_Stat);
503 CHECK_CALLED(Stream_Seek_END);
504 ok(hr == S_OK, "GetData failed %08x\n", hr);
505 ok(stream != &test_stream->IStream_iface, "unexpected stream\n");
506
507 SET_EXPECT(Stream_Seek);
508 SET_EXPECT(Stream_Read);
509 test_stream_read(stream, S_OK, "012", 3);
510 CHECK_CALLED(Stream_Seek);
511 CHECK_CALLED(Stream_Read);
512
513 SET_EXPECT(Stream_Stat);
514 SET_EXPECT(Stream_Seek_END);
515 hr = IMimeBody_GetData(body, IET_BINARY, &stream2);
516 CHECK_CALLED(Stream_Stat);
517 CHECK_CALLED(Stream_Seek_END);
518 ok(hr == S_OK, "GetData failed %08x\n", hr);
519 ok(stream2 != stream, "unexpected stream\n");
520
521 SET_EXPECT(Stream_Seek);
522 SET_EXPECT(Stream_Read);
523 test_stream_read(stream2, S_OK, "01", 2);
524 CHECK_CALLED(Stream_Seek);
525 CHECK_CALLED(Stream_Read);
526
527 expect_seek_pos = 3;
528 SET_EXPECT(Stream_Seek);
529 SET_EXPECT(Stream_Read);
530 test_stream_read(stream, S_OK, "345", 3);
531 CHECK_CALLED(Stream_Seek);
532 CHECK_CALLED(Stream_Read);
533
534 IStream_Release(stream);
535 IStream_Release(stream2);
536 IStream_Release(&test_stream->IStream_iface);
537
538 stream = create_stream_from_string(" \t\r\n|}~YWJj ZGV|}~mZw== \t"); /* "abcdefg" in base64 obscured by invalid chars */
539 hr = IMimeBody_SetData(body, IET_BASE64, "text", "plain", &IID_IStream, stream);
540 IStream_Release(stream);
541 ok(hr == S_OK, "SetData failed: %08x\n", hr);
542
543 test_current_encoding(body, IET_BASE64);
544
545 hr = IMimeBody_GetData(body, IET_BINARY, &stream);
546 ok(hr == S_OK, "GetData failed %08x\n", hr);
547
548 test_stream_read(stream, S_OK, "abc", 3);
549 test_stream_read(stream, S_OK, "defg", -1);
550
551 IStream_Release(stream);
552
553 hr = IMimeBody_GetData(body, IET_BASE64, &stream);
554 ok(hr == S_OK, "GetData failed %08x\n", hr);
555
556 test_stream_read(stream, S_OK, " \t\r", 3);
557 IStream_Release(stream);
558
559 stream = create_stream_from_string(" =3d=3D\"one\" \t=\r\ntw= o=\nx3\n=34\r\n5");
560 hr = IMimeBody_SetData(body, IET_QP, "text", "plain", &IID_IStream, stream);
561 IStream_Release(stream);
562 ok(hr == S_OK, "SetData failed: %08x\n", hr);
563
564 test_current_encoding(body, IET_QP);
565
566 hr = IMimeBody_GetData(body, IET_BINARY, &stream);
567 ok(hr == S_OK, "GetData failed %08x\n", hr);
568
569 test_stream_read(stream, S_OK, " ==\"one\" \ttw=o=3\n4\r\n5", -1);
570
571 IStream_Release(stream);
572
573 IMimeBody_Release(body);
574 }
575
576 static void test_Allocator(void)
577 {
578 HRESULT hr;
579 IMimeAllocator *alloc;
580
581 hr = MimeOleGetAllocator(&alloc);
582 ok(hr == S_OK, "ret %08x\n", hr);
583 IMimeAllocator_Release(alloc);
584 }
585
586 static void test_CreateMessage(void)
587 {
588 HRESULT hr;
589 IMimeMessage *msg;
590 IStream *stream;
591 LONG ref;
592 HBODY hbody, hbody2;
593 IMimeBody *body;
594 BODYOFFSETS offsets;
595 ULONG count;
596 FINDBODY find_struct;
597 HCHARSET hcs;
598 HBODY handle = NULL;
599
600 char text[] = "text";
601 HBODY *body_list;
602 PROPVARIANT prop;
603 static const char att_pritype[] = "att:pri-content-type";
604
605 hr = MimeOleCreateMessage(NULL, &msg);
606 ok(hr == S_OK, "ret %08x\n", hr);
607
608 stream = create_stream_from_string(msg1);
609
610 hr = IMimeMessage_Load(msg, stream);
611 ok(hr == S_OK, "ret %08x\n", hr);
612
613 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, TRUE, &count);
614 ok(hr == S_OK, "ret %08x\n", hr);
615 ok(count == 3, "got %d\n", count);
616
617 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, FALSE, &count);
618 ok(hr == S_OK, "ret %08x\n", hr);
619 ok(count == 3, "got %d\n", count);
620
621 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
622 ok(hr == S_OK, "ret %08x\n", hr);
623 hr = IMimeBody_GetOffsets(body, &offsets);
624 ok(hr == S_OK, "ret %08x\n", hr);
625 ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
626 ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
627 ok(offsets.cbBodyStart == 359, "got %d\n", offsets.cbBodyStart);
628 ok(offsets.cbBodyEnd == 666, "got %d\n", offsets.cbBodyEnd);
629 IMimeBody_Release(body);
630
631 hr = IMimeMessage_GetBody(msg, IBL_ROOT, NULL, &hbody);
632 ok(hr == S_OK, "ret %08x\n", hr);
633
634 hr = IMimeBody_GetHandle(body, NULL);
635 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
636
637 hr = IMimeBody_GetHandle(body, &handle);
638 ok(hr == S_OK, "ret %08x\n", hr);
639 ok(handle != NULL, "handle %p\n", handle);
640
641 hr = IMimeMessage_GetBody(msg, IBL_PARENT, hbody, NULL);
642 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
643
644 hbody2 = (HBODY)0xdeadbeef;
645 hr = IMimeMessage_GetBody(msg, IBL_PARENT, hbody, &hbody2);
646 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
647 ok(hbody2 == NULL, "hbody2 %p\n", hbody2);
648
649 PropVariantInit(&prop);
650 hr = IMimeMessage_GetBodyProp(msg, hbody, att_pritype, 0, &prop);
651 ok(hr == S_OK, "ret %08x\n", hr);
652 ok(prop.vt == VT_LPSTR, "vt %08x\n", prop.vt);
653 ok(!strcasecmp(prop.u.pszVal, "multipart"), "got %s\n", prop.u.pszVal);
654 PropVariantClear(&prop);
655
656 hr = IMimeMessage_GetBody(msg, IBL_FIRST, hbody, &hbody);
657 ok(hr == S_OK, "ret %08x\n", hr);
658 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
659 ok(hr == S_OK, "ret %08x\n", hr);
660
661 hr = IMimeBody_GetHandle(body, &handle);
662 ok(hr == S_OK, "ret %08x\n", hr);
663 ok(handle == hbody, "handle %p\n", handle);
664
665 hr = IMimeBody_GetOffsets(body, &offsets);
666 ok(hr == S_OK, "ret %08x\n", hr);
667 ok(offsets.cbBoundaryStart == 405, "got %d\n", offsets.cbBoundaryStart);
668 ok(offsets.cbHeaderStart == 428, "got %d\n", offsets.cbHeaderStart);
669 ok(offsets.cbBodyStart == 518, "got %d\n", offsets.cbBodyStart);
670 ok(offsets.cbBodyEnd == 523, "got %d\n", offsets.cbBodyEnd);
671
672 hr = IMimeBody_GetCharset(body, &hcs);
673 ok(hr == S_OK, "ret %08x\n", hr);
674 todo_wine
675 {
676 ok(hcs != NULL, "Expected non-NULL charset\n");
677 }
678
679 IMimeBody_Release(body);
680
681 hr = IMimeMessage_GetBody(msg, IBL_NEXT, hbody, &hbody);
682 ok(hr == S_OK, "ret %08x\n", hr);
683 hr = IMimeMessage_BindToObject(msg, hbody, &IID_IMimeBody, (void**)&body);
684 ok(hr == S_OK, "ret %08x\n", hr);
685
686 hr = IMimeBody_GetHandle(body, &handle);
687 ok(hr == S_OK, "ret %08x\n", hr);
688 ok(handle == hbody, "handle %p\n", handle);
689
690 hr = IMimeBody_GetOffsets(body, &offsets);
691 ok(hr == S_OK, "ret %08x\n", hr);
692 ok(offsets.cbBoundaryStart == 525, "got %d\n", offsets.cbBoundaryStart);
693 ok(offsets.cbHeaderStart == 548, "got %d\n", offsets.cbHeaderStart);
694 ok(offsets.cbBodyStart == 629, "got %d\n", offsets.cbBodyStart);
695 ok(offsets.cbBodyEnd == 639, "got %d\n", offsets.cbBodyEnd);
696 IMimeBody_Release(body);
697
698 find_struct.pszPriType = text;
699 find_struct.pszSubType = NULL;
700
701 hr = IMimeMessage_FindFirst(msg, &find_struct, &hbody);
702 ok(hr == S_OK, "ret %08x\n", hr);
703
704 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
705 ok(hr == S_OK, "ret %08x\n", hr);
706
707 hr = IMimeMessage_FindNext(msg, &find_struct, &hbody);
708 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
709
710 hr = IMimeMessage_GetAttachments(msg, &count, &body_list);
711 ok(hr == S_OK, "ret %08x\n", hr);
712 ok(count == 2, "got %d\n", count);
713 if(count == 2)
714 {
715 IMimeBody *attachment;
716 PROPVARIANT prop;
717
718 PropVariantInit(&prop);
719
720 hr = IMimeMessage_BindToObject(msg, body_list[0], &IID_IMimeBody, (void**)&attachment);
721 ok(hr == S_OK, "ret %08x\n", hr);
722
723 hr = IMimeBody_IsContentType(attachment, "multipart", NULL);
724 ok(hr == S_FALSE, "ret %08x\n", hr);
725
726 test_current_encoding(attachment, IET_8BIT);
727
728 prop.vt = VT_LPSTR;
729 hr = IMimeBody_GetProp(attachment, "Content-Transfer-Encoding", 0, &prop);
730 ok(hr == S_OK, "ret %08x\n", hr);
731
732 ok(prop.vt == VT_LPSTR, "type %d\n", prop.vt);
733 ok(!strcmp(prop.u.pszVal, "8bit"), "got %s\n", prop.u.pszVal);
734 PropVariantClear(&prop);
735
736 hr = IMimeBody_IsType(attachment, IBT_ATTACHMENT);
737 todo_wine ok(hr == S_FALSE, "ret %08x\n", hr);
738
739 IMimeBody_Release(attachment);
740
741 hr = IMimeMessage_BindToObject(msg, body_list[1], &IID_IMimeBody, (void**)&attachment);
742 ok(hr == S_OK, "ret %08x\n", hr);
743
744 hr = IMimeBody_IsContentType(attachment, "multipart", NULL);
745 ok(hr == S_FALSE, "ret %08x\n", hr);
746
747 test_current_encoding(attachment, IET_7BIT);
748
749 prop.vt = VT_LPSTR;
750 hr = IMimeBody_GetProp(attachment, "Content-Transfer-Encoding", 0, &prop);
751 ok(hr == S_OK, "ret %08x\n", hr);
752 ok(prop.vt == VT_LPSTR, "type %d\n", prop.vt);
753 ok(!strcmp(prop.u.pszVal, "7bit"), "got %s\n", prop.u.pszVal);
754 PropVariantClear(&prop);
755
756 hr = IMimeBody_IsType(attachment, IBT_ATTACHMENT);
757 ok(hr == S_OK, "ret %08x\n", hr);
758
759 IMimeBody_Release(attachment);
760 }
761 CoTaskMemFree(body_list);
762
763 hr = IMimeBody_GetCharset(body, &hcs);
764 ok(hr == S_OK, "ret %08x\n", hr);
765 todo_wine
766 {
767 ok(hcs != NULL, "Expected non-NULL charset\n");
768 }
769
770 IMimeMessage_Release(msg);
771
772 ref = IStream_AddRef(stream);
773 ok(ref == 2 ||
774 broken(ref == 1), /* win95 */
775 "ref %d\n", ref);
776 IStream_Release(stream);
777
778 IStream_Release(stream);
779 }
780
781 static void test_mhtml_message(void)
782 {
783 IMimeMessage *mime_message;
784 IMimeBody *mime_body;
785 HBODY *body_list;
786 IStream *stream;
787 ULONG count;
788 HRESULT hres;
789
790 hres = MimeOleCreateMessage(NULL, &mime_message);
791 ok(hres == S_OK, "MimeOleCreateMessage failed: %08x\n", hres);
792
793 stream = create_stream_from_string(mhtml_page1);
794 hres = IMimeMessage_Load(mime_message, stream);
795 IStream_Release(stream);
796 ok(hres == S_OK, "Load failed: %08x\n", hres);
797
798 hres = IMimeMessage_CountBodies(mime_message, HBODY_ROOT, TRUE, &count);
799 ok(hres == S_OK, "CountBodies failed: %08x\n", hres);
800 ok(count == 3, "got %d\n", count);
801
802 hres = IMimeMessage_GetAttachments(mime_message, &count, &body_list);
803 ok(hres == S_OK, "GetAttachments failed: %08x\n", hres);
804 ok(count == 2, "count = %u\n", count);
805
806 hres = IMimeMessage_BindToObject(mime_message, body_list[0], &IID_IMimeBody, (void**)&mime_body);
807 ok(hres == S_OK, "BindToObject failed: %08x\n", hres);
808
809 hres = IMimeBody_GetData(mime_body, IET_BINARY, &stream);
810 ok(hres == S_OK, "GetData failed: %08x\n", hres);
811 test_stream_read(stream, S_OK, "<HTML></HTML>", -1);
812 IStream_Release(stream);
813
814 test_current_encoding(mime_body, IET_QP);
815
816 IMimeBody_Release(mime_body);
817
818 hres = IMimeMessage_BindToObject(mime_message, body_list[1], &IID_IMimeBody, (void**)&mime_body);
819 ok(hres == S_OK, "BindToObject failed: %08x\n", hres);
820
821 test_current_encoding(mime_body, IET_BASE64);
822
823 hres = IMimeBody_GetData(mime_body, IET_BINARY, &stream);
824 ok(hres == S_OK, "GetData failed: %08x\n", hres);
825 test_stream_read(stream, S_OK, "Test", -1);
826 IStream_Release(stream);
827
828 IMimeBody_Release(mime_body);
829
830 CoTaskMemFree(body_list);
831
832 IMimeMessage_Release(mime_message);
833 }
834
835 static void test_MessageSetProp(void)
836 {
837 static const char topic[] = "wine topic";
838 static const WCHAR topicW[] = {'w','i','n','e',' ','t','o','p','i','c',0};
839 HRESULT hr;
840 IMimeMessage *msg;
841 IMimeBody *body;
842 PROPVARIANT prop;
843
844 hr = MimeOleCreateMessage(NULL, &msg);
845 ok(hr == S_OK, "ret %08x\n", hr);
846
847 PropVariantInit(&prop);
848
849 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
850 ok(hr == S_OK, "ret %08x\n", hr);
851
852 hr = IMimeBody_SetProp(body, NULL, 0, &prop);
853 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
854
855 hr = IMimeBody_SetProp(body, "Thread-Topic", 0, NULL);
856 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
857
858 prop.vt = VT_LPSTR;
859 prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
860 strcpy(prop.u.pszVal, topic);
861 hr = IMimeBody_SetProp(body, "Thread-Topic", 0, &prop);
862 ok(hr == S_OK, "ret %08x\n", hr);
863 PropVariantClear(&prop);
864
865 hr = IMimeBody_GetProp(body, NULL, 0, &prop);
866 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
867
868 hr = IMimeBody_GetProp(body, "Thread-Topic", 0, NULL);
869 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
870
871 hr = IMimeBody_GetProp(body, "Wine-Topic", 0, &prop);
872 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
873
874 prop.vt = VT_LPSTR;
875 hr = IMimeBody_GetProp(body, "Thread-Topic", 0, &prop);
876 ok(hr == S_OK, "ret %08x\n", hr);
877 if(hr == S_OK)
878 {
879 ok(prop.vt == VT_LPSTR, "type %d\n", prop.vt);
880 ok(!strcmp(prop.u.pszVal, topic), "got %s\n", prop.u.pszVal);
881 PropVariantClear(&prop);
882 }
883
884 prop.vt = VT_LPSTR;
885 prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
886 strcpy(prop.u.pszVal, topic);
887 hr = IMimeBody_SetProp(body, PIDTOSTR(PID_HDR_SUBJECT), 0, &prop);
888 ok(hr == S_OK, "ret %08x\n", hr);
889 PropVariantClear(&prop);
890
891 prop.vt = VT_LPSTR;
892 hr = IMimeBody_GetProp(body, PIDTOSTR(PID_HDR_SUBJECT), 0, &prop);
893 ok(hr == S_OK, "ret %08x\n", hr);
894 if(hr == S_OK)
895 {
896 ok(prop.vt == VT_LPSTR, "type %d\n", prop.vt);
897 ok(!strcmp(prop.u.pszVal, topic), "got %s\n", prop.u.pszVal);
898 PropVariantClear(&prop);
899 }
900
901 /* Using the name or PID returns the same result. */
902 prop.vt = VT_LPSTR;
903 hr = IMimeBody_GetProp(body, "Subject", 0, &prop);
904 ok(hr == S_OK, "ret %08x\n", hr);
905 if(hr == S_OK)
906 {
907 ok(prop.vt == VT_LPSTR, "type %d\n", prop.vt);
908 ok(!strcmp(prop.u.pszVal, topic), "got %s\n", prop.u.pszVal);
909 PropVariantClear(&prop);
910 }
911
912 prop.vt = VT_LPWSTR;
913 hr = IMimeBody_GetProp(body, "Subject", 0, &prop);
914 ok(hr == S_OK, "ret %08x\n", hr);
915 if(hr == S_OK)
916 {
917 ok(prop.vt == VT_LPWSTR, "type %d\n", prop.vt);
918 ok(!lstrcmpW(prop.u.pwszVal, topicW), "got %s\n", wine_dbgstr_w(prop.u.pwszVal));
919 PropVariantClear(&prop);
920 }
921
922 prop.vt = VT_LPSTR;
923 prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
924 strcpy(prop.u.pszVal, topic);
925 hr = IMimeBody_SetProp(body, PIDTOSTR(PID_HDR_TO), 0, &prop);
926 ok(hr == S_OK, "ret %08x\n", hr);
927 PropVariantClear(&prop);
928
929 /* Out of Range PID */
930 prop.vt = VT_LPSTR;
931 prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
932 strcpy(prop.u.pszVal, topic);
933 hr = IMimeBody_SetProp(body, PIDTOSTR(124), 0, &prop);
934 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
935 PropVariantClear(&prop);
936
937 IMimeBody_Release(body);
938 IMimeMessage_Release(msg);
939 }
940
941 static void test_MessageGetPropInfo(void)
942 {
943 static const char topic[] = "wine topic";
944 static const char subject[] = "wine testing";
945 HRESULT hr;
946 IMimeMessage *msg;
947 IMimeBody *body;
948 PROPVARIANT prop;
949 MIMEPROPINFO info;
950
951 hr = MimeOleCreateMessage(NULL, &msg);
952 ok(hr == S_OK, "ret %08x\n", hr);
953
954 PropVariantInit(&prop);
955
956 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
957 ok(hr == S_OK, "ret %08x\n", hr);
958
959 prop.vt = VT_LPSTR;
960 prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
961 strcpy(prop.u.pszVal, topic);
962 hr = IMimeBody_SetProp(body, "Thread-Topic", 0, &prop);
963 ok(hr == S_OK, "ret %08x\n", hr);
964 PropVariantClear(&prop);
965
966 prop.vt = VT_LPSTR;
967 prop.u.pszVal = CoTaskMemAlloc(strlen(subject)+1);
968 strcpy(prop.u.pszVal, subject);
969 hr = IMimeBody_SetProp(body, PIDTOSTR(PID_HDR_SUBJECT), 0, &prop);
970 ok(hr == S_OK, "ret %08x\n", hr);
971 PropVariantClear(&prop);
972
973 memset(&info, 0, sizeof(info));
974 info.dwMask = PIM_ENCODINGTYPE | PIM_FLAGS | PIM_PROPID;
975 hr = IMimeBody_GetPropInfo(body, NULL, &info);
976 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
977
978 memset(&info, 0, sizeof(info));
979 info.dwMask = PIM_ENCODINGTYPE | PIM_FLAGS | PIM_PROPID;
980 hr = IMimeBody_GetPropInfo(body, "Subject", NULL);
981 ok(hr == E_INVALIDARG, "ret %08x\n", hr);
982
983 memset(&info, 0xfe, sizeof(info));
984 info.dwMask = PIM_ENCODINGTYPE | PIM_FLAGS | PIM_PROPID;
985 hr = IMimeBody_GetPropInfo(body, "Subject", &info);
986 ok(hr == S_OK, "ret %08x\n", hr);
987 if(hr == S_OK)
988 {
989 ok(info.dwMask & (PIM_ENCODINGTYPE | PIM_FLAGS| PIM_PROPID), "Invalid mask 0x%08x\n", info.dwFlags);
990 todo_wine ok(info.dwFlags & 0x10000000, "Invalid flags 0x%08x\n", info.dwFlags);
991 ok(info.ietEncoding == 0, "Invalid encoding %d\n", info.ietEncoding);
992 ok(info.dwPropId == PID_HDR_SUBJECT, "Invalid propid %d\n", info.dwPropId);
993 ok(info.cValues == 0xfefefefe, "Invalid cValues %d\n", info.cValues);
994 }
995
996 memset(&info, 0xfe, sizeof(info));
997 info.dwMask = 0;
998 hr = IMimeBody_GetPropInfo(body, "Subject", &info);
999 ok(hr == S_OK, "ret %08x\n", hr);
1000 if(hr == S_OK)
1001 {
1002 ok(info.dwMask == 0, "Invalid mask 0x%08x\n", info.dwFlags);
1003 ok(info.dwFlags == 0xfefefefe, "Invalid flags 0x%08x\n", info.dwFlags);
1004 ok(info.ietEncoding == -16843010, "Invalid encoding %d\n", info.ietEncoding);
1005 ok(info.dwPropId == -16843010, "Invalid propid %d\n", info.dwPropId);
1006 }
1007
1008 memset(&info, 0xfe, sizeof(info));
1009 info.dwMask = 0;
1010 info.dwPropId = 1024;
1011 info.ietEncoding = 99;
1012 hr = IMimeBody_GetPropInfo(body, "Subject", &info);
1013 ok(hr == S_OK, "ret %08x\n", hr);
1014 if(hr == S_OK)
1015 {
1016 ok(info.dwMask == 0, "Invalid mask 0x%08x\n", info.dwFlags);
1017 ok(info.dwFlags == 0xfefefefe, "Invalid flags 0x%08x\n", info.dwFlags);
1018 ok(info.ietEncoding == 99, "Invalid encoding %d\n", info.ietEncoding);
1019 ok(info.dwPropId == 1024, "Invalid propid %d\n", info.dwPropId);
1020 }
1021
1022 memset(&info, 0, sizeof(info));
1023 info.dwMask = PIM_ENCODINGTYPE | PIM_FLAGS | PIM_PROPID;
1024 hr = IMimeBody_GetPropInfo(body, "Invalid Property", &info);
1025 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
1026
1027 IMimeBody_Release(body);
1028 IMimeMessage_Release(msg);
1029 }
1030
1031 static void test_MessageOptions(void)
1032 {
1033 static const char string[] = "XXXXX";
1034 static const char zero[] = "0";
1035 HRESULT hr;
1036 IMimeMessage *msg;
1037 PROPVARIANT prop;
1038
1039 hr = MimeOleCreateMessage(NULL, &msg);
1040 ok(hr == S_OK, "ret %08x\n", hr);
1041
1042 PropVariantInit(&prop);
1043
1044 prop.vt = VT_BOOL;
1045 prop.u.boolVal = TRUE;
1046 hr = IMimeMessage_SetOption(msg, OID_HIDE_TNEF_ATTACHMENTS, &prop);
1047 ok(hr == S_OK, "ret %08x\n", hr);
1048 PropVariantClear(&prop);
1049
1050 hr = IMimeMessage_GetOption(msg, OID_HIDE_TNEF_ATTACHMENTS, &prop);
1051 todo_wine ok(hr == S_OK, "ret %08x\n", hr);
1052 todo_wine ok(prop.vt == VT_BOOL, "vt %08x\n", prop.vt);
1053 todo_wine ok(prop.u.boolVal == TRUE, "Hide Attachments got %d\n", prop.u.boolVal);
1054 PropVariantClear(&prop);
1055
1056 prop.vt = VT_LPSTR;
1057 prop.u.pszVal = CoTaskMemAlloc(strlen(string)+1);
1058 strcpy(prop.u.pszVal, string);
1059 hr = IMimeMessage_SetOption(msg, OID_HIDE_TNEF_ATTACHMENTS, &prop);
1060 ok(hr == S_OK, "ret %08x\n", hr);
1061 PropVariantClear(&prop);
1062
1063 hr = IMimeMessage_GetOption(msg, OID_HIDE_TNEF_ATTACHMENTS, &prop);
1064 todo_wine ok(hr == S_OK, "ret %08x\n", hr);
1065 todo_wine ok(prop.vt == VT_BOOL, "vt %08x\n", prop.vt);
1066 todo_wine ok(prop.u.boolVal == TRUE, "Hide Attachments got %d\n", prop.u.boolVal);
1067 PropVariantClear(&prop);
1068
1069 /* Invalid property type doesn't change the value */
1070 prop.vt = VT_LPSTR;
1071 prop.u.pszVal = CoTaskMemAlloc(strlen(zero)+1);
1072 strcpy(prop.u.pszVal, zero);
1073 hr = IMimeMessage_SetOption(msg, OID_HIDE_TNEF_ATTACHMENTS, &prop);
1074 ok(hr == S_OK, "ret %08x\n", hr);
1075 PropVariantClear(&prop);
1076
1077 hr = IMimeMessage_GetOption(msg, OID_HIDE_TNEF_ATTACHMENTS, &prop);
1078 todo_wine ok(hr == S_OK, "ret %08x\n", hr);
1079 todo_wine ok(prop.vt == VT_BOOL, "vt %08x\n", prop.vt);
1080 todo_wine ok(prop.u.boolVal == TRUE, "Hide Attachments got %d\n", prop.u.boolVal);
1081 PropVariantClear(&prop);
1082
1083 /* Invalid OID */
1084 prop.vt = VT_BOOL;
1085 prop.u.boolVal = TRUE;
1086 hr = IMimeMessage_SetOption(msg, 0xff00000a, &prop);
1087 ok(hr == MIME_E_INVALID_OPTION_ID, "ret %08x\n", hr);
1088 PropVariantClear(&prop);
1089
1090 /* Out of range before type. */
1091 prop.vt = VT_I4;
1092 prop.u.lVal = 1;
1093 hr = IMimeMessage_SetOption(msg, 0xff00000a, &prop);
1094 ok(hr == MIME_E_INVALID_OPTION_ID, "ret %08x\n", hr);
1095 PropVariantClear(&prop);
1096
1097 IMimeMessage_Release(msg);
1098 }
1099
1100 static void test_BindToObject(void)
1101 {
1102 HRESULT hr;
1103 IMimeMessage *msg;
1104 IMimeBody *body;
1105 ULONG count;
1106
1107 hr = MimeOleCreateMessage(NULL, &msg);
1108 ok(hr == S_OK, "ret %08x\n", hr);
1109
1110 hr = IMimeMessage_CountBodies(msg, HBODY_ROOT, TRUE, &count);
1111 ok(hr == S_OK, "ret %08x\n", hr);
1112 ok(count == 1, "got %d\n", count);
1113
1114 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
1115 ok(hr == S_OK, "ret %08x\n", hr);
1116 IMimeBody_Release(body);
1117
1118 IMimeMessage_Release(msg);
1119 }
1120
1121 static void test_BodyDeleteProp(void)
1122 {
1123 static const char topic[] = "wine topic";
1124 HRESULT hr;
1125 IMimeMessage *msg;
1126 IMimeBody *body;
1127 PROPVARIANT prop;
1128
1129 hr = MimeOleCreateMessage(NULL, &msg);
1130 ok(hr == S_OK, "ret %08x\n", hr);
1131
1132 PropVariantInit(&prop);
1133
1134 hr = IMimeMessage_BindToObject(msg, HBODY_ROOT, &IID_IMimeBody, (void**)&body);
1135 ok(hr == S_OK, "ret %08x\n", hr);
1136
1137 hr = IMimeBody_DeleteProp(body, "Subject");
1138 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
1139
1140 hr = IMimeBody_DeleteProp(body, PIDTOSTR(PID_HDR_SUBJECT));
1141 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
1142
1143 prop.vt = VT_LPSTR;
1144 prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
1145 strcpy(prop.u.pszVal, topic);
1146 hr = IMimeBody_SetProp(body, "Subject", 0, &prop);
1147 ok(hr == S_OK, "ret %08x\n", hr);
1148 PropVariantClear(&prop);
1149
1150 hr = IMimeBody_DeleteProp(body, "Subject");
1151 ok(hr == S_OK, "ret %08x\n", hr);
1152
1153 hr = IMimeBody_GetProp(body, "Subject", 0, &prop);
1154 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
1155
1156 prop.vt = VT_LPSTR;
1157 prop.u.pszVal = CoTaskMemAlloc(strlen(topic)+1);
1158 strcpy(prop.u.pszVal, topic);
1159 hr = IMimeBody_SetProp(body, PIDTOSTR(PID_HDR_SUBJECT), 0, &prop);
1160 ok(hr == S_OK, "ret %08x\n", hr);
1161 PropVariantClear(&prop);
1162
1163 hr = IMimeBody_DeleteProp(body, PIDTOSTR(PID_HDR_SUBJECT));
1164 ok(hr == S_OK, "ret %08x\n", hr);
1165
1166 hr = IMimeBody_GetProp(body, PIDTOSTR(PID_HDR_SUBJECT), 0, &prop);
1167 ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
1168
1169 IMimeBody_Release(body);
1170 IMimeMessage_Release(msg);
1171 }
1172
1173 static void test_MimeOleGetPropertySchema(void)
1174 {
1175 HRESULT hr;
1176 IMimePropertySchema *schema = NULL;
1177
1178 hr = MimeOleGetPropertySchema(&schema);
1179 ok(hr == S_OK, "ret %08x\n", hr);
1180
1181 IMimePropertySchema_Release(schema);
1182 }
1183
1184 typedef struct {
1185 const char *url;
1186 const char *content;
1187 const char *mime;
1188 const char *data;
1189 } mhtml_binding_test_t;
1190
1191 static const mhtml_binding_test_t binding_tests[] = {
1192 {
1193 "mhtml:file://%s",
1194 mhtml_page1,
1195 "text/html",
1196 "<HTML></HTML>"
1197 },
1198 {
1199 "mhtml:file://%s!http://winehq.org/mhtmltest.html",
1200 mhtml_page1,
1201 "Image/Jpeg",
1202 "Test"
1203 }
1204 };
1205
1206 static const mhtml_binding_test_t *current_binding_test;
1207 static IInternetProtocol *current_binding_protocol;
1208
1209 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
1210 {
1211 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1212 *ppv = iface;
1213 return S_OK;
1214 }
1215
1216 *ppv = NULL;
1217 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
1218 return E_NOINTERFACE;
1219 }
1220
1221 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
1222 {
1223 return 2;
1224 }
1225
1226 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
1227 {
1228 return 1;
1229 }
1230
1231 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1232 {
1233 CHECK_EXPECT(GetBindInfo);
1234
1235 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1236 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1237 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1238
1239 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
1240 return S_OK;
1241 }
1242
1243 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
1244 ULONG cEl, ULONG *pcElFetched)
1245 {
1246 ok(0, "unexpected call\n");
1247 return E_NOTIMPL;
1248 }
1249
1250 static IInternetBindInfoVtbl InternetBindInfoVtbl = {
1251 BindInfo_QueryInterface,
1252 BindInfo_AddRef,
1253 BindInfo_Release,
1254 BindInfo_GetBindInfo,
1255 BindInfo_GetBindString
1256 };
1257
1258 static IInternetBindInfo bind_info = {
1259 &InternetBindInfoVtbl
1260 };
1261
1262 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1263 {
1264 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
1265 *ppv = NULL;
1266 return E_NOINTERFACE;
1267 }
1268
1269 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
1270 {
1271 return 2;
1272 }
1273
1274 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
1275 {
1276 return 1;
1277 }
1278
1279 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
1280 REFIID riid, void **ppv)
1281 {
1282 if(IsEqualGUID(&CLSID_MimeEdit, guidService)) {
1283 *ppv = NULL;
1284 return E_NOINTERFACE;
1285 }
1286
1287 ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService));
1288 return E_FAIL;
1289 }
1290
1291 static /* const */ IServiceProviderVtbl ServiceProviderVtbl = {
1292 ServiceProvider_QueryInterface,
1293 ServiceProvider_AddRef,
1294 ServiceProvider_Release,
1295 ServiceProvider_QueryService
1296 };
1297
1298 static IServiceProvider service_provider = { &ServiceProviderVtbl };
1299
1300 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
1301 {
1302 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1303 *ppv = iface;
1304 return S_OK;
1305 }
1306
1307 if(IsEqualGUID(&IID_IServiceProvider, riid)) {
1308 *ppv = &service_provider;
1309 return S_OK;
1310 }
1311
1312 *ppv = NULL;
1313 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
1314 return E_NOINTERFACE;
1315 }
1316
1317 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
1318 {
1319 return 2;
1320 }
1321
1322 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
1323 {
1324 return 1;
1325 }
1326
1327 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
1328 {
1329 ok(0, "unexpected call\n");
1330 return E_NOTIMPL;
1331 }
1332
1333 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
1334 const WCHAR *szStatusText)
1335 {
1336 switch(ulStatusCode) {
1337 case BINDSTATUS_MIMETYPEAVAILABLE:
1338 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1339 ok(!strcmp_wa(szStatusText, current_binding_test->mime), "status text %s\n", wine_dbgstr_w(szStatusText));
1340 return S_OK;
1341 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1342 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1343 return S_OK;
1344 default:
1345 ok(0, "unexpected call %u %s\n", ulStatusCode, wine_dbgstr_w(szStatusText));
1346 }
1347
1348 return E_NOTIMPL;
1349 }
1350
1351 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
1352 ULONG ulProgressMax)
1353 {
1354 char buf[1024];
1355 DWORD read;
1356 HRESULT hres;
1357
1358 CHECK_EXPECT(ReportData);
1359
1360 ok(!ulProgress, "ulProgress = %u\n", ulProgress);
1361 ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
1362 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_INTERMEDIATEDATANOTIFICATION
1363 | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE | BSCF_AVAILABLEDATASIZEUNKNOWN),
1364 "grcf = %08x\n", grfBSCF);
1365
1366 hres = IInternetProtocol_Read(current_binding_protocol, buf, sizeof(buf), &read);
1367 ok(hres == S_OK, "Read failed: %08x\n", hres);
1368 buf[read] = 0;
1369 ok(!strcmp(buf, current_binding_test->data), "unexpected data: %s\n", buf);
1370
1371 hres = IInternetProtocol_Read(current_binding_protocol, buf, sizeof(buf), &read);
1372 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
1373 return S_OK;
1374 }
1375
1376 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult, DWORD dwError,
1377 LPCWSTR szResult)
1378 {
1379 CHECK_EXPECT(ReportResult);
1380 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
1381 ok(!dwError, "dwError = %u\n", dwError);
1382 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
1383 return S_OK;
1384 }
1385
1386 static IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
1387 ProtocolSink_QueryInterface,
1388 ProtocolSink_AddRef,
1389 ProtocolSink_Release,
1390 ProtocolSink_Switch,
1391 ProtocolSink_ReportProgress,
1392 ProtocolSink_ReportData,
1393 ProtocolSink_ReportResult
1394 };
1395
1396 static IInternetProtocolSink protocol_sink = { &InternetProtocolSinkVtbl };
1397
1398 static void test_mhtml_protocol_binding(const mhtml_binding_test_t *test)
1399 {
1400 char file_name[MAX_PATH+32], *p, urla[INTERNET_MAX_URL_LENGTH];
1401 WCHAR test_url[INTERNET_MAX_URL_LENGTH];
1402 IInternetProtocol *protocol;
1403 IUnknown *unk;
1404 HRESULT hres;
1405 HANDLE file;
1406 DWORD size;
1407
1408 p = file_name + GetCurrentDirectoryA(sizeof(file_name), file_name);
1409 *p++ = '\\';
1410 strcpy(p, "winetest.mht");
1411
1412 file = CreateFileA(file_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
1413 FILE_ATTRIBUTE_NORMAL, NULL);
1414 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1415
1416 WriteFile(file, test->content, strlen(test->content), &size, NULL);
1417 CloseHandle(file);
1418
1419 sprintf(urla, test->url, file_name);
1420 MultiByteToWideChar(CP_ACP, 0, urla, -1, test_url, sizeof(test_url)/sizeof(WCHAR));
1421
1422 hres = CoCreateInstance(&CLSID_IMimeHtmlProtocol, NULL, CLSCTX_INPROC_SERVER, &IID_IInternetProtocol, (void**)&protocol);
1423 ok(hres == S_OK, "Could not create protocol handler: %08x\n", hres);
1424
1425 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolEx, (void**)&unk);
1426 ok(hres == E_NOINTERFACE, "Could get IInternetProtocolEx\n");
1427
1428 current_binding_test = test;
1429 current_binding_protocol = protocol;
1430
1431 SET_EXPECT(GetBindInfo);
1432 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1433 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1434 SET_EXPECT(ReportData);
1435 SET_EXPECT(ReportResult);
1436 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
1437 ok(hres == S_OK, "Start failed: %08x\n", hres);
1438 CHECK_CALLED(GetBindInfo);
1439 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1440 todo_wine CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1441 CHECK_CALLED(ReportData);
1442 CHECK_CALLED(ReportResult);
1443
1444 IInternetProtocol_Release(protocol);
1445 ok(DeleteFileA("winetest.mht"), "DeleteFile failed: %u\n", GetLastError());
1446 }
1447
1448 static const struct {
1449 const char *base_url;
1450 const char *relative_url;
1451 const char *expected_result;
1452 BOOL todo;
1453 } combine_tests[] = {
1454 {
1455 "mhtml:file:///c:/dir/test.mht", "http://test.org",
1456 "mhtml:file:///c:/dir/test.mht!x-usc:http://test.org"
1457 }, {
1458 "mhtml:file:///c:/dir/test.mht", "3D\"http://test.org\"",
1459 "mhtml:file:///c:/dir/test.mht!x-usc:3D\"http://test.org\""
1460 }, {
1461 "mhtml:file:///c:/dir/test.mht", "123abc",
1462 "mhtml:file:///c:/dir/test.mht!x-usc:123abc"
1463 }, {
1464 "mhtml:file:///c:/dir/test.mht!x-usc:http://test.org", "123abc",
1465 "mhtml:file:///c:/dir/test.mht!x-usc:123abc"
1466 }, {
1467 "MhtMl:file:///c:/dir/test.mht!x-usc:http://test.org/dir/dir2/file.html", "../..",
1468 "mhtml:file:///c:/dir/test.mht!x-usc:../.."
1469 }, {"mhtml:file:///c:/dir/test.mht!x-usc:file:///c:/dir/dir2/file.html", "../..",
1470 "mhtml:file:///c:/dir/test.mht!x-usc:../.."
1471 }, {
1472 "mhtml:file:///c:/dir/test.mht!x-usc:http://test.org", "",
1473 "mhtml:file:///c:/dir/test.mht"
1474 }, {
1475 "mhtml:file:///c:/dir/test.mht!x-usc:http://test.org", "mhtml:file:///d:/file.html",
1476 "file:///d:/file.html", TRUE
1477 }, {
1478 "mhtml:file:///c:/dir/test.mht!x-usc:http://test.org", "mhtml:file:///c:/dir2/test.mht!x-usc:http://test.org",
1479 "mhtml:file:///c:/dir2/test.mht!x-usc:http://test.org", TRUE
1480 }, {
1481 "mhtml:file:///c:/dir/test.mht!http://test.org", "123abc",
1482 "mhtml:file:///c:/dir/test.mht!x-usc:123abc"
1483 }, {
1484 "mhtml:file:///c:/dir/test.mht!http://test.org", "",
1485 "mhtml:file:///c:/dir/test.mht"
1486 }
1487 };
1488
1489 static void test_mhtml_protocol_info(void)
1490 {
1491 WCHAR *base_url, *relative_url, combined_url[INTERNET_MAX_URL_LENGTH];
1492 IInternetProtocolInfo *protocol_info;
1493 DWORD combined_len;
1494 unsigned i, exlen;
1495 HRESULT hres;
1496
1497 static const WCHAR http_url[] = {'h','t','t','p',':','/','/','t','e','s','t','.','o','r','g',0};
1498
1499 hres = CoCreateInstance(&CLSID_IMimeHtmlProtocol, NULL, CLSCTX_INPROC_SERVER,
1500 &IID_IInternetProtocolInfo, (void**)&protocol_info);
1501 ok(hres == S_OK, "Could not create protocol info: %08x\n", hres);
1502
1503 for(i = 0; i < sizeof(combine_tests)/sizeof(*combine_tests); i++) {
1504 base_url = a2w(combine_tests[i].base_url);
1505 relative_url = a2w(combine_tests[i].relative_url);
1506
1507 combined_len = 0xdeadbeef;
1508 hres = IInternetProtocolInfo_CombineUrl(protocol_info, base_url, relative_url, ICU_BROWSER_MODE,
1509 combined_url, sizeof(combined_url)/sizeof(WCHAR), &combined_len, 0);
1510 todo_wine_if(combine_tests[i].todo)
1511 ok(hres == S_OK, "[%u] CombineUrl failed: %08x\n", i, hres);
1512 if(SUCCEEDED(hres)) {
1513 exlen = strlen(combine_tests[i].expected_result);
1514 ok(combined_len == exlen, "[%u] combined len is %u, expected %u\n", i, combined_len, exlen);
1515 ok(!strcmp_wa(combined_url, combine_tests[i].expected_result), "[%u] combined URL is %s, expected %s\n",
1516 i, wine_dbgstr_w(combined_url), combine_tests[i].expected_result);
1517
1518 combined_len = 0xdeadbeef;
1519 hres = IInternetProtocolInfo_CombineUrl(protocol_info, base_url, relative_url, ICU_BROWSER_MODE,
1520 combined_url, exlen, &combined_len, 0);
1521 ok(hres == E_FAIL, "[%u] CombineUrl returned: %08x\n", i, hres);
1522 ok(!combined_len, "[%u] combined_len = %u\n", i, combined_len);
1523 }
1524
1525 HeapFree(GetProcessHeap(), 0, base_url);
1526 HeapFree(GetProcessHeap(), 0, relative_url);
1527 }
1528
1529 hres = IInternetProtocolInfo_CombineUrl(protocol_info, http_url, http_url, ICU_BROWSER_MODE,
1530 combined_url, sizeof(combined_url)/sizeof(WCHAR), &combined_len, 0);
1531 ok(hres == E_FAIL, "CombineUrl failed: %08x\n", hres);
1532
1533 IInternetProtocolInfo_Release(protocol_info);
1534 }
1535
1536 static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
1537 {
1538 ok(0, "unexpected call\n");
1539 return E_NOINTERFACE;
1540 }
1541
1542 static ULONG WINAPI outer_AddRef(IUnknown *iface)
1543 {
1544 return 2;
1545 }
1546
1547 static ULONG WINAPI outer_Release(IUnknown *iface)
1548 {
1549 return 1;
1550 }
1551
1552 static /* const */ IUnknownVtbl outer_vtbl = {
1553 outer_QueryInterface,
1554 outer_AddRef,
1555 outer_Release
1556 };
1557
1558 static BOOL broken_mhtml_resolver;
1559
1560 static void test_mhtml_protocol(void)
1561 {
1562 IUnknown outer = { &outer_vtbl };
1563 IClassFactory *class_factory;
1564 IUnknown *unk, *unk2;
1565 unsigned i;
1566 HRESULT hres;
1567
1568 /* test class factory */
1569 hres = CoGetClassObject(&CLSID_IMimeHtmlProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
1570 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
1571
1572 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&unk2);
1573 ok(hres == E_NOINTERFACE, "IInternetProtocolInfo supported\n");
1574
1575 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&class_factory);
1576 ok(hres == S_OK, "Could not get IClassFactory iface: %08x\n", hres);
1577 IUnknown_Release(unk);
1578
1579 hres = IClassFactory_CreateInstance(class_factory, &outer, &IID_IUnknown, (void**)&unk);
1580 ok(hres == S_OK, "CreateInstance returned: %08x\n", hres);
1581 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocol, (void**)&unk2);
1582 ok(hres == S_OK, "Could not get IInternetProtocol iface: %08x\n", hres);
1583 IUnknown_Release(unk2);
1584 IUnknown_Release(unk);
1585
1586 hres = IClassFactory_CreateInstance(class_factory, (IUnknown*)0xdeadbeef, &IID_IInternetProtocol, (void**)&unk2);
1587 ok(hres == CLASS_E_NOAGGREGATION, "CreateInstance returned: %08x\n", hres);
1588
1589 IClassFactory_Release(class_factory);
1590
1591 if(!broken_mhtml_resolver)
1592 test_mhtml_protocol_info();
1593
1594 for(i = 0; i < sizeof(binding_tests)/sizeof(*binding_tests); i++)
1595 test_mhtml_protocol_binding(binding_tests + i);
1596 }
1597
1598 static void test_MimeOleObjectFromMoniker(void)
1599 {
1600 IMoniker *mon, *new_mon;
1601 WCHAR *mhtml_url, *url;
1602 IBindCtx *bind_ctx;
1603 IUnknown *unk;
1604 unsigned i;
1605 HRESULT hres;
1606
1607 static const struct {
1608 const char *url;
1609 const char *mhtml_url;
1610 } tests[] = {
1611 {"file:///x:\\dir\\file.mht", "mhtml:file://x:\\dir\\file.mht"},
1612 {"file:///x:/dir/file.mht", "mhtml:file://x:\\dir\\file.mht"},
1613 {"http://www.winehq.org/index.html?query#hash", "mhtml:http://www.winehq.org/index.html?query#hash"},
1614 {"../test.mht", "mhtml:../test.mht"}
1615 };
1616
1617 for(i = 0; i < sizeof(tests)/sizeof(*tests); i++) {
1618 url = a2w(tests[i].url);
1619 hres = CreateURLMoniker(NULL, url, &mon);
1620 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
1621 HeapFree(GetProcessHeap(), 0, url);
1622
1623 hres = CreateBindCtx(0, &bind_ctx);
1624 ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
1625
1626 hres = MimeOleObjectFromMoniker(0, mon, bind_ctx, &IID_IUnknown, (void**)&unk, &new_mon);
1627 ok(hres == S_OK || broken(!i && hres == INET_E_RESOURCE_NOT_FOUND), "MimeOleObjectFromMoniker failed: %08x\n", hres);
1628 IBindCtx_Release(bind_ctx);
1629 if(hres == INET_E_RESOURCE_NOT_FOUND) { /* winxp */
1630 win_skip("Broken MHTML behaviour found. Skipping some tests.\n");
1631 broken_mhtml_resolver = TRUE;
1632 return;
1633 }
1634
1635 hres = IMoniker_GetDisplayName(new_mon, NULL, NULL, &mhtml_url);
1636 ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
1637 ok(!strcmp_wa(mhtml_url, tests[i].mhtml_url), "[%d] unexpected mhtml URL: %s\n", i, wine_dbgstr_w(mhtml_url));
1638 CoTaskMemFree(mhtml_url);
1639
1640 IUnknown_Release(unk);
1641 IMoniker_Release(new_mon);
1642 IMoniker_Release(mon);
1643 }
1644 }
1645
1646 START_TEST(mimeole)
1647 {
1648 OleInitialize(NULL);
1649 test_CreateVirtualStream();
1650 test_CreateSecurity();
1651 test_CreateBody();
1652 test_SetData();
1653 test_Allocator();
1654 test_CreateMessage();
1655 test_MessageSetProp();
1656 test_MessageGetPropInfo();
1657 test_MessageOptions();
1658 test_BindToObject();
1659 test_BodyDeleteProp();
1660 test_MimeOleGetPropertySchema();
1661 test_mhtml_message();
1662 test_MimeOleObjectFromMoniker();
1663 test_mhtml_protocol();
1664 OleUninitialize();
1665 }