4 * Copyright 2004 Kevin Koltzau
5 * Copyright 2004 Jacek Caban
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 #define DEFINE_EXPECT(func) \
35 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
37 #define SET_EXPECT(func) \
38 expect_ ## func = TRUE
40 #define CHECK_EXPECT(func) \
42 ok(expect_ ##func, "unexpected call " #func "\n"); \
43 expect_ ## func = FALSE; \
44 called_ ## func = TRUE; \
47 #define CHECK_EXPECT2(func) \
49 ok(expect_ ##func, "unexpected call " #func "\n"); \
50 called_ ## func = TRUE; \
53 #define CHECK_CALLED(func) \
55 ok(called_ ## func, "expected " #func "\n"); \
56 expect_ ## func = called_ ## func = FALSE; \
59 DEFINE_EXPECT(GetBindInfo
);
60 DEFINE_EXPECT(OnStartBinding
);
61 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE
);
62 DEFINE_EXPECT(OnProgress_CONNECTING
);
63 DEFINE_EXPECT(OnProgress_SENDINGREQUEST
);
64 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE
);
65 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA
);
66 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA
);
67 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA
);
68 DEFINE_EXPECT(OnStopBinding
);
69 DEFINE_EXPECT(OnDataAvailable
);
72 DEFINE_EXPECT(LockRequest
);
73 DEFINE_EXPECT(Terminate
);
74 DEFINE_EXPECT(UnlockRequest
);
76 static const WCHAR TEST_URL_1
[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
77 static const WCHAR TEST_PART_URL_1
[] = {'/','t','e','s','t','/','\0'};
79 static const WCHAR WINE_ABOUT_URL
[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
80 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
81 static const WCHAR ABOUT_BLANK
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
82 static WCHAR INDEX_HTML
[MAX_PATH
];
83 static const WCHAR ITS_URL
[] =
84 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
85 static const WCHAR MK_URL
[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
86 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
90 static const WCHAR wszIndexHtml
[] = {'i','n','d','e','x','.','h','t','m','l',0};
92 static BOOL stopped_binding
= FALSE
, emulate_protocol
= FALSE
;
93 static DWORD read
= 0;
95 static const LPCWSTR urls
[] = {
111 static void test_CreateURLMoniker(LPCWSTR url1
, LPCWSTR url2
)
114 IMoniker
*mon1
= NULL
;
115 IMoniker
*mon2
= NULL
;
117 hr
= CreateURLMoniker(NULL
, url1
, &mon1
);
118 ok(SUCCEEDED(hr
), "failed to create moniker: 0x%08x\n", hr
);
120 hr
= CreateURLMoniker(mon1
, url2
, &mon2
);
121 ok(SUCCEEDED(hr
), "failed to create moniker: 0x%08x\n", hr
);
123 if(mon1
) IMoniker_Release(mon1
);
124 if(mon2
) IMoniker_Release(mon2
);
127 static void test_create(void)
129 test_CreateURLMoniker(TEST_URL_1
, TEST_PART_URL_1
);
132 static HRESULT WINAPI
Protocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
134 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
140 return E_NOINTERFACE
;
143 static ULONG WINAPI
Protocol_AddRef(IInternetProtocol
*iface
)
148 static ULONG WINAPI
Protocol_Release(IInternetProtocol
*iface
)
153 static HRESULT WINAPI
Protocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
154 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
155 DWORD grfPI
, DWORD dwReserved
)
157 BINDINFO bindinfo
, bi
= {sizeof(bi
), 0};
158 DWORD bindf
, bscf
= BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
;
162 static const WCHAR wszTextHtml
[] = {'t','e','x','t','/','h','t','m','l',0};
168 ok(szUrl
&& !lstrcmpW(szUrl
, urls
[test_protocol
]), "wrong url\n");
169 ok(pOIProtSink
!= NULL
, "pOIProtSink == NULL\n");
170 ok(pOIBindInfo
!= NULL
, "pOIBindInfo == NULL\n");
171 ok(grfPI
== 0, "grfPI=%d, expected 0\n", grfPI
);
172 ok(dwReserved
== 0, "dwReserved=%d, expected 0\n", dwReserved
);
174 memset(&bindinfo
, 0, sizeof(bindinfo
));
175 bindinfo
.cbSize
= sizeof(bindinfo
);
176 hres
= IInternetBindInfo_GetBindInfo(pOIBindInfo
, &bindf
, &bindinfo
);
177 ok(hres
== S_OK
, "GetBindInfo failed: %08x\n", hres
);
179 if(test_protocol
== FILE_TEST
|| test_protocol
== MK_TEST
) {
180 ok(bindf
== (BINDF_ASYNCHRONOUS
|BINDF_ASYNCSTORAGE
|BINDF_PULLDATA
182 "bindf=%08x\n", bindf
);
184 ok(bindf
== (BINDF_ASYNCHRONOUS
|BINDF_ASYNCSTORAGE
|BINDF_PULLDATA
|
185 BINDF_FROMURLMON
|BINDF_NEEDFILE
),
186 "bindf=%08x\n", bindf
);
189 ok(!memcmp(&bindinfo
, &bi
, sizeof(bindinfo
)), "wrong bindinfo\n");
191 switch(test_protocol
) {
193 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
,
194 BINDSTATUS_DIRECTBIND
, NULL
);
196 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres
);
200 SET_EXPECT(OnProgress_SENDINGREQUEST
);
201 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
,
202 BINDSTATUS_SENDINGREQUEST
, &null_char
);
204 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres
);
205 CHECK_CALLED(OnProgress_SENDINGREQUEST
);
210 if(test_protocol
== FILE_TEST
) {
211 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
,
212 BINDSTATUS_CACHEFILENAMEAVAILABLE
, &null_char
);
214 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres
);
216 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE
);
217 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
,
218 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
, wszTextHtml
);
220 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres
);
221 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE
);
223 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
,
224 BINDSTATUS_MIMETYPEAVAILABLE
, wszTextHtml
);
226 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres
);
229 if(test_protocol
== ABOUT_TEST
)
230 bscf
|= BSCF_DATAFULLYAVAILABLE
;
231 if(test_protocol
== ITS_TEST
)
232 bscf
= BSCF_FIRSTDATANOTIFICATION
|BSCF_DATAFULLYAVAILABLE
;
235 if(test_protocol
!= FILE_TEST
&& test_protocol
!= MK_TEST
)
236 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE
);
237 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA
);
238 SET_EXPECT(OnProgress_ENDDOWNLOADDATA
);
239 SET_EXPECT(LockRequest
);
240 SET_EXPECT(OnDataAvailable
);
241 SET_EXPECT(OnStopBinding
);
243 hres
= IInternetProtocolSink_ReportData(pOIProtSink
, bscf
, 13, 13);
244 ok(hres
== S_OK
, "ReportData failed: %08x\n", hres
);
247 if(test_protocol
!= FILE_TEST
&& test_protocol
!= MK_TEST
)
248 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE
);
249 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA
);
250 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA
);
251 CHECK_CALLED(LockRequest
);
252 CHECK_CALLED(OnDataAvailable
);
253 CHECK_CALLED(OnStopBinding
);
255 if(test_protocol
== ITS_TEST
) {
257 hres
= IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_BEGINDOWNLOADDATA
, NULL
);
258 ok(hres
== S_OK
, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres
);
262 SET_EXPECT(Terminate
);
263 hres
= IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
264 ok(hres
== S_OK
, "ReportResult failed: %08x\n", hres
);
265 CHECK_CALLED(Terminate
);
270 static HRESULT WINAPI
Protocol_Continue(IInternetProtocol
*iface
,
271 PROTOCOLDATA
*pProtocolData
)
273 ok(0, "unexpected call\n");
277 static HRESULT WINAPI
Protocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
280 ok(0, "unexpected call\n");
284 static HRESULT WINAPI
Protocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
286 CHECK_EXPECT(Terminate
);
287 ok(dwOptions
== 0, "dwOptions=%d, expected 0\n", dwOptions
);
291 static HRESULT WINAPI
Protocol_Suspend(IInternetProtocol
*iface
)
293 ok(0, "unexpected call\n");
297 static HRESULT WINAPI
Protocol_Resume(IInternetProtocol
*iface
)
299 ok(0, "unexpected call\n");
303 static HRESULT WINAPI
Protocol_Read(IInternetProtocol
*iface
, void *pv
,
304 ULONG cb
, ULONG
*pcbRead
)
306 static const char data
[] = "<HTML></HTML>";
315 ok(pv
!= NULL
, "pv == NULL\n");
316 ok(cb
!= 0, "cb == 0\n");
317 ok(pcbRead
!= NULL
, "pcbRead == NULL\n");
319 ok(*pcbRead
== 0, "*pcbRead=%d, expected 0\n", *pcbRead
);
320 read
+= *pcbRead
= sizeof(data
)-1;
323 memcpy(pv
, data
, sizeof(data
));
328 static HRESULT WINAPI
Protocol_Seek(IInternetProtocol
*iface
,
329 LARGE_INTEGER dlibMove
, DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
331 ok(0, "unexpected call\n");
335 static HRESULT WINAPI
Protocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
337 CHECK_EXPECT(LockRequest
);
341 static HRESULT WINAPI
Protocol_UnlockRequest(IInternetProtocol
*iface
)
343 CHECK_EXPECT(UnlockRequest
);
347 static const IInternetProtocolVtbl ProtocolVtbl
= {
348 Protocol_QueryInterface
,
359 Protocol_LockRequest
,
360 Protocol_UnlockRequest
363 static IInternetProtocol Protocol
= { &ProtocolVtbl
};
365 static HRESULT WINAPI
statusclb_QueryInterface(IBindStatusCallback
*iface
, REFIID riid
, void **ppv
)
367 if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
368 if(emulate_protocol
) {
372 return E_NOINTERFACE
;
376 return E_NOINTERFACE
;
379 static ULONG WINAPI
statusclb_AddRef(IBindStatusCallback
*iface
)
384 static ULONG WINAPI
statusclb_Release(IBindStatusCallback
*iface
)
389 static HRESULT WINAPI
statusclb_OnStartBinding(IBindStatusCallback
*iface
, DWORD dwReserved
,
395 CHECK_EXPECT(OnStartBinding
);
397 ok(pib
!= NULL
, "pib should not be NULL\n");
399 hres
= IBinding_QueryInterface(pib
, &IID_IMoniker
, (void**)&mon
);
400 ok(hres
== E_NOINTERFACE
, "IBinding should not have IMoniker interface\n");
402 IMoniker_Release(mon
);
407 static HRESULT WINAPI
statusclb_GetPriority(IBindStatusCallback
*iface
, LONG
*pnPriority
)
409 ok(0, "unexpected call\n");
413 static HRESULT WINAPI
statusclb_OnLowResource(IBindStatusCallback
*iface
, DWORD reserved
)
415 ok(0, "unexpected call\n");
419 static HRESULT WINAPI
statusclb_OnProgress(IBindStatusCallback
*iface
, ULONG ulProgress
,
420 ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR szStatusText
)
422 switch(ulStatusCode
) {
423 case BINDSTATUS_FINDINGRESOURCE
:
424 CHECK_EXPECT(OnProgress_FINDINGRESOURCE
);
426 case BINDSTATUS_CONNECTING
:
427 CHECK_EXPECT(OnProgress_CONNECTING
);
429 case BINDSTATUS_SENDINGREQUEST
:
430 CHECK_EXPECT(OnProgress_SENDINGREQUEST
);
432 case BINDSTATUS_MIMETYPEAVAILABLE
:
433 CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE
);
435 case BINDSTATUS_BEGINDOWNLOADDATA
:
436 CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA
);
437 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
439 ok(!lstrcmpW(szStatusText
, urls
[test_protocol
]), "wrong szStatusText\n");
441 case BINDSTATUS_DOWNLOADINGDATA
:
442 CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA
);
444 case BINDSTATUS_ENDDOWNLOADDATA
:
445 CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA
);
446 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
448 ok(!lstrcmpW(szStatusText
, urls
[test_protocol
]), "wrong szStatusText\n");
450 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
451 ok(szStatusText
!= NULL
, "szStatusText == NULL\n");
452 if(szStatusText
&& test_protocol
== FILE_TEST
)
453 ok(!lstrcmpW(INDEX_HTML
+7, szStatusText
), "wrong szStatusText\n");
456 todo_wine
{ ok(0, "unexpexted code %d\n", ulStatusCode
); }
461 static HRESULT WINAPI
statusclb_OnStopBinding(IBindStatusCallback
*iface
, HRESULT hresult
, LPCWSTR szError
)
463 CHECK_EXPECT(OnStopBinding
);
465 /* ignore DNS failure */
466 if (hresult
!= HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED
))
468 ok(SUCCEEDED(hresult
), "Download failed: %08x\n", hresult
);
469 ok(szError
== NULL
, "szError should be NULL\n");
471 stopped_binding
= TRUE
;
476 static HRESULT WINAPI
statusclb_GetBindInfo(IBindStatusCallback
*iface
, DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
480 CHECK_EXPECT(GetBindInfo
);
482 *grfBINDF
= BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
;
483 cbSize
= pbindinfo
->cbSize
;
484 memset(pbindinfo
, 0, cbSize
);
485 pbindinfo
->cbSize
= cbSize
;
490 static HRESULT WINAPI
statusclb_OnDataAvailable(IBindStatusCallback
*iface
, DWORD grfBSCF
,
491 DWORD dwSize
, FORMATETC
* pformatetc
, STGMEDIUM
* pstgmed
)
497 CHECK_EXPECT2(OnDataAvailable
);
501 /* FIXME: Uncomment after removing BindToStorage hack. */
502 ok(pformatetc
!= NULL
, "pformatetx == NULL\n");
504 ok(pformatetc
->cfFormat
== 0xc02d, "clipformat=%x\n", pformatetc
->cfFormat
);
505 ok(pformatetc
->ptd
== NULL
, "ptd = %p\n", pformatetc
->ptd
);
506 ok(pformatetc
->dwAspect
== 1, "dwAspect=%u\n", pformatetc
->dwAspect
);
507 ok(pformatetc
->lindex
== -1, "lindex=%d\n", pformatetc
->lindex
);
508 ok(pformatetc
->tymed
== TYMED_ISTREAM
, "tymed=%u\n", pformatetc
->tymed
);
511 ok(pstgmed
!= NULL
, "stgmeg == NULL\n");
513 ok(pstgmed
->tymed
== TYMED_ISTREAM
, "tymed=%u\n", pstgmed
->tymed
);
514 ok(U(*pstgmed
).pstm
!= NULL
, "pstm == NULL\n");
515 ok(pstgmed
->pUnkForRelease
!= NULL
, "pUnkForRelease == NULL\n");
519 if(U(*pstgmed
).pstm
) {
520 do hres
= IStream_Read(U(*pstgmed
).pstm
, buf
, 512, &readed
);
522 ok(hres
== S_FALSE
|| hres
== E_PENDING
, "IStream_Read returned %08x\n", hres
);
528 static HRESULT WINAPI
statusclb_OnObjectAvailable(IBindStatusCallback
*iface
, REFIID riid
, IUnknown
*punk
)
530 ok(0, "unexpected call\n");
534 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl
= {
535 statusclb_QueryInterface
,
538 statusclb_OnStartBinding
,
539 statusclb_GetPriority
,
540 statusclb_OnLowResource
,
541 statusclb_OnProgress
,
542 statusclb_OnStopBinding
,
543 statusclb_GetBindInfo
,
544 statusclb_OnDataAvailable
,
545 statusclb_OnObjectAvailable
548 static IBindStatusCallback bsc
= { &BindStatusCallbackVtbl
};
550 static void test_CreateAsyncBindCtx(void)
552 IBindCtx
*bctx
= (IBindCtx
*)0x0ff00ff0;
557 hres
= CreateAsyncBindCtx(0, NULL
, NULL
, &bctx
);
558 ok(hres
== E_INVALIDARG
, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres
);
559 ok(bctx
== (IBindCtx
*)0x0ff00ff0, "bctx should not be changed\n");
561 hres
= CreateAsyncBindCtx(0, NULL
, NULL
, NULL
);
562 ok(hres
== E_INVALIDARG
, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres
);
564 hres
= CreateAsyncBindCtx(0, &bsc
, NULL
, &bctx
);
565 ok(SUCCEEDED(hres
), "CreateAsyncBindCtx failed: %08x\n", hres
);
567 bindopts
.cbStruct
= sizeof(bindopts
);
568 hres
= IBindCtx_GetBindOptions(bctx
, &bindopts
);
569 ok(SUCCEEDED(hres
), "IBindCtx_GetBindOptions failed: %08x\n", hres
);
570 ok(bindopts
.grfFlags
== BIND_MAYBOTHERUSER
,
571 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts
.grfFlags
);
572 ok(bindopts
.grfMode
== (STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
),
573 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
575 ok(bindopts
.dwTickCountDeadline
== 0,
576 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts
.dwTickCountDeadline
);
578 ref
= IBindCtx_Release(bctx
);
579 ok(ref
== 0, "bctx should be destroyed here\n");
582 static void test_CreateAsyncBindCtxEx(void)
584 IBindCtx
*bctx
= NULL
, *bctx_arg
= NULL
;
588 hres
= CreateAsyncBindCtxEx(NULL
, 0, NULL
, NULL
, NULL
, 0);
589 ok(hres
== E_INVALIDARG
, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres
);
591 hres
= CreateAsyncBindCtxEx(NULL
, 0, NULL
, NULL
, &bctx
, 0);
592 ok(hres
== S_OK
, "CreateAsyncBindCtxEx failed: %08x\n", hres
);
594 if(SUCCEEDED(hres
)) {
595 bindopts
.cbStruct
= sizeof(bindopts
);
596 hres
= IBindCtx_GetBindOptions(bctx
, &bindopts
);
597 ok(SUCCEEDED(hres
), "IBindCtx_GetBindOptions failed: %08x\n", hres
);
598 ok(bindopts
.grfFlags
== BIND_MAYBOTHERUSER
,
599 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts
.grfFlags
);
600 ok(bindopts
.grfMode
== (STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
),
601 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
603 ok(bindopts
.dwTickCountDeadline
== 0,
604 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts
.dwTickCountDeadline
);
606 IBindCtx_Release(bctx
);
609 CreateBindCtx(0, &bctx_arg
);
610 hres
= CreateAsyncBindCtxEx(NULL
, 0, NULL
, NULL
, &bctx
, 0);
611 ok(hres
== S_OK
, "CreateAsyncBindCtxEx failed: %08x\n", hres
);
613 if(SUCCEEDED(hres
)) {
614 bindopts
.cbStruct
= sizeof(bindopts
);
615 hres
= IBindCtx_GetBindOptions(bctx
, &bindopts
);
616 ok(SUCCEEDED(hres
), "IBindCtx_GetBindOptions failed: %08x\n", hres
);
617 ok(bindopts
.grfFlags
== BIND_MAYBOTHERUSER
,
618 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts
.grfFlags
);
619 ok(bindopts
.grfMode
== (STGM_READWRITE
| STGM_SHARE_EXCLUSIVE
),
620 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
622 ok(bindopts
.dwTickCountDeadline
== 0,
623 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts
.dwTickCountDeadline
);
625 IBindCtx_Release(bctx
);
628 IBindCtx_Release(bctx_arg
);
630 hres
= CreateAsyncBindCtxEx(NULL
, 0, &bsc
, NULL
, &bctx
, 0);
631 ok(hres
== S_OK
, "CreateAsyncBindCtxEx failed: %08x\n", hres
);
634 IBindCtx_Release(bctx
);
637 static void test_BindToStorage(int protocol
, BOOL emul
)
641 LPOLESTR display_name
;
644 IBindStatusCallback
*previousclb
;
645 IUnknown
*unk
= (IUnknown
*)0x00ff00ff;
648 test_protocol
= protocol
;
649 emulate_protocol
= emul
;
651 hres
= CreateAsyncBindCtx(0, &bsc
, NULL
, &bctx
);
652 ok(SUCCEEDED(hres
), "CreateAsyncBindCtx failed: %08x\n\n", hres
);
656 hres
= RegisterBindStatusCallback(bctx
, &bsc
, &previousclb
, 0);
657 ok(SUCCEEDED(hres
), "RegisterBindStatusCallback failed: %08x\n", hres
);
658 ok(previousclb
== &bsc
, "previousclb(%p) != sclb(%p)\n", previousclb
, &bsc
);
660 IBindStatusCallback_Release(previousclb
);
662 hres
= CreateURLMoniker(NULL
, urls
[test_protocol
], &mon
);
663 ok(SUCCEEDED(hres
), "failed to create moniker: %08x\n", hres
);
665 IBindCtx_Release(bctx
);
669 if(test_protocol
== FILE_TEST
&& INDEX_HTML
[7] == '/')
670 memmove(INDEX_HTML
+7, INDEX_HTML
+8, lstrlenW(INDEX_HTML
+7)*sizeof(WCHAR
));
672 hres
= IMoniker_QueryInterface(mon
, &IID_IBinding
, (void**)&bind
);
673 ok(hres
== E_NOINTERFACE
, "IMoniker should not have IBinding interface\n");
675 IBinding_Release(bind
);
677 hres
= IMoniker_GetDisplayName(mon
, bctx
, NULL
, &display_name
);
678 ok(hres
== S_OK
, "GetDisplayName failed %08x\n", hres
);
679 ok(!lstrcmpW(display_name
, urls
[test_protocol
]), "GetDisplayName got wrong name\n");
681 SET_EXPECT(GetBindInfo
);
682 SET_EXPECT(OnStartBinding
);
683 if(emulate_protocol
) {
685 SET_EXPECT(UnlockRequest
);
687 if(test_protocol
== HTTP_TEST
) {
688 SET_EXPECT(OnProgress_FINDINGRESOURCE
);
689 SET_EXPECT(OnProgress_CONNECTING
);
691 if(test_protocol
== HTTP_TEST
|| test_protocol
== FILE_TEST
)
692 SET_EXPECT(OnProgress_SENDINGREQUEST
);
693 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE
);
694 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA
);
695 if(test_protocol
== HTTP_TEST
)
696 SET_EXPECT(OnProgress_DOWNLOADINGDATA
);
697 SET_EXPECT(OnProgress_ENDDOWNLOADDATA
);
698 SET_EXPECT(OnDataAvailable
);
699 SET_EXPECT(OnStopBinding
);
702 hres
= IMoniker_BindToStorage(mon
, bctx
, NULL
, &IID_IStream
, (void**)&unk
);
703 if (test_protocol
== HTTP_TEST
&& hres
== HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED
))
705 trace( "Network unreachable, skipping tests\n" );
708 ok(SUCCEEDED(hres
), "IMoniker_BindToStorage failed: %08x\n", hres
);
709 if (!SUCCEEDED(hres
)) return;
711 if(test_protocol
== HTTP_TEST
) {
713 ok(unk
== NULL
, "istr should be NULL\n");
716 ok(unk
!= NULL
, "unk == NULL\n");
719 IUnknown_Release(unk
);
721 while(!stopped_binding
&& GetMessage(&msg
,NULL
,0,0)) {
722 TranslateMessage(&msg
);
723 DispatchMessage(&msg
);
726 CHECK_CALLED(GetBindInfo
);
727 CHECK_CALLED(OnStartBinding
);
728 if(emulate_protocol
) {
730 CHECK_CALLED(UnlockRequest
);
732 if(test_protocol
== HTTP_TEST
) {
733 CHECK_CALLED(OnProgress_FINDINGRESOURCE
);
734 CHECK_CALLED(OnProgress_CONNECTING
);
735 CHECK_CALLED(OnProgress_SENDINGREQUEST
);
736 todo_wine
{ CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE
); }
738 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE
);
740 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA
);
741 if(test_protocol
== HTTP_TEST
)
742 CHECK_CALLED(OnProgress_DOWNLOADINGDATA
);
743 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA
);
744 CHECK_CALLED(OnDataAvailable
);
745 CHECK_CALLED(OnStopBinding
);
748 ok(IMoniker_Release(mon
) == 0, "mon should be destroyed here\n");
749 ok(IBindCtx_Release(bctx
) == 0, "bctx should be destroyed here\n");
752 static void set_file_url(void)
756 static const WCHAR wszFile
[] = {'f','i','l','e',':','/','/'};
758 memcpy(INDEX_HTML
, wszFile
, sizeof(wszFile
));
759 len
= sizeof(wszFile
)/sizeof(WCHAR
);
760 INDEX_HTML
[len
++] = '/';
761 len
+= GetCurrentDirectoryW(sizeof(INDEX_HTML
)/sizeof(WCHAR
)-len
, INDEX_HTML
+len
);
762 INDEX_HTML
[len
++] = '\\';
763 memcpy(INDEX_HTML
+len
, wszIndexHtml
, sizeof(wszIndexHtml
));
766 static void create_file(void)
771 static const char html_doc
[] = "<HTML></HTML>";
773 file
= CreateFileW(wszIndexHtml
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
774 FILE_ATTRIBUTE_NORMAL
, NULL
);
775 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
776 if(file
== INVALID_HANDLE_VALUE
)
779 WriteFile(file
, html_doc
, sizeof(html_doc
)-1, &size
, NULL
);
785 static void test_BindToStorage_fail(void)
787 IMoniker
*mon
= NULL
;
788 IBindCtx
*bctx
= NULL
;
792 hres
= CreateURLMoniker(NULL
, ABOUT_BLANK
, &mon
);
793 ok(hres
== S_OK
, "CreateURLMoniker failed: %08x\n", hres
);
797 hres
= CreateAsyncBindCtxEx(NULL
, 0, NULL
, NULL
, &bctx
, 0);
798 ok(hres
== S_OK
, "CreateAsyncBindCtxEx failed: %08x\n", hres
);
800 hres
= IMoniker_BindToStorage(mon
, bctx
, NULL
, &IID_IStream
, (void**)&unk
);
801 ok(hres
== MK_E_SYNTAX
, "hres=%08x, expected INET_E_SYNTAX\n", hres
);
803 IBindCtx_Release(bctx
);
805 IMoniker_Release(mon
);
811 test_CreateAsyncBindCtx();
812 test_CreateAsyncBindCtxEx();
814 trace("http test...\n");
815 test_BindToStorage(HTTP_TEST
, FALSE
);
817 trace("about test...\n");
819 test_BindToStorage(ABOUT_TEST
, FALSE
);
822 trace("emulated about test...\n");
823 test_BindToStorage(ABOUT_TEST
, TRUE
);
825 trace("file test...\n");
827 test_BindToStorage(FILE_TEST
, FALSE
);
828 DeleteFileW(wszIndexHtml
);
830 trace("emulated file test...\n");
832 test_BindToStorage(FILE_TEST
, TRUE
);
834 trace("emulated its test...\n");
835 test_BindToStorage(ITS_TEST
, TRUE
);
837 trace("emulated mk test...\n");
838 test_BindToStorage(MK_TEST
, TRUE
);
840 test_BindToStorage_fail();