2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <wine/test.h>
31 #define DEFINE_EXPECT(func) \
32 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
34 #define SET_EXPECT(func) \
35 expect_ ## func = TRUE
37 #define CHECK_EXPECT(func) \
39 ok(expect_ ##func, "unexpected call " #func "\n"); \
40 expect_ ## func = FALSE; \
41 called_ ## func = TRUE; \
44 #define SET_CALLED(func) \
45 expect_ ## func = called_ ## func = FALSE
47 #define CHECK_CALLED(func) \
49 ok(called_ ## func, "expected " #func "\n"); \
53 DEFINE_GUID(CLSID_ITSProtocol
,0x9d148291,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
55 DEFINE_EXPECT(GetBindInfo
);
56 DEFINE_EXPECT(ReportProgress_BEGINDOWNLOADDATA
);
57 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST
);
58 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
59 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
60 DEFINE_EXPECT(ReportProgress_DIRECTBIND
);
61 DEFINE_EXPECT(ReportData
);
62 DEFINE_EXPECT(ReportResult
);
63 DEFINE_EXPECT(outer_QI_test
);
65 static HRESULT expect_hrResult
;
66 static IInternetProtocol
*read_protocol
= NULL
;
69 static const WCHAR blank_url1
[] = {'i','t','s',':',
70 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
71 static const WCHAR blank_url2
[] = {'m','S','-','i','T','s',':',
72 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
73 static const WCHAR blank_url3
[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
74 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
75 static const WCHAR blank_url4
[] = {'i','t','s',':',
76 't','e','s','t','.','c','h','m',':',':','b','l','a','n','k','.','h','t','m','l',0};
77 static const WCHAR blank_url5
[] = {'i','t','s',':',
78 't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
79 static const WCHAR blank_url6
[] = {'i','t','s',':',
80 't','e','s','t','.','c','h','m',':',':','/','%','6','2','l','a','n','k','.','h','t','m','l',0};
81 static const WCHAR blank_url7
[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
82 't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
83 static const WCHAR blank_url8
[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
84 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
85 static const WCHAR blank_url9
[] = {'i','t','s',':',
86 't','e','s','t','.','c','h','m',':',':','/','d','i','r','/','.','.','/','b','l','a','n','k','.','h','t','m','l',0};
93 static const WCHAR cache_file1
[] =
94 {'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
95 static const WCHAR cache_file2
[] =
96 {'t','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
97 static const WCHAR cache_file3
[] =
98 {'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
99 static const WCHAR
*cache_file
= cache_file1
;
101 static HRESULT WINAPI
ProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
103 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
107 return E_NOINTERFACE
;
110 static ULONG WINAPI
ProtocolSink_AddRef(IInternetProtocolSink
*iface
)
115 static ULONG WINAPI
ProtocolSink_Release(IInternetProtocolSink
*iface
)
120 static HRESULT WINAPI
ProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
122 ok(0, "unexpected call\n");
126 static HRESULT WINAPI
ProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
127 LPCWSTR szStatusText
)
129 static const WCHAR blank_html
[] = {'b','l','a','n','k','.','h','t','m','l',0};
130 static const WCHAR text_html
[] = {'t','e','x','t','/','h','t','m','l',0};
132 switch(ulStatusCode
) {
133 case BINDSTATUS_BEGINDOWNLOADDATA
:
134 CHECK_EXPECT(ReportProgress_BEGINDOWNLOADDATA
);
135 ok(!szStatusText
, "szStatusText != NULL\n");
137 case BINDSTATUS_SENDINGREQUEST
:
138 CHECK_EXPECT(ReportProgress_SENDINGREQUEST
);
139 if(test_protocol
== ITS_PROTOCOL
)
140 ok(!lstrcmpW(szStatusText
, blank_html
), "unexpected szStatusText\n");
142 ok(szStatusText
== NULL
, "szStatusText != NULL\n");
144 case BINDSTATUS_MIMETYPEAVAILABLE
:
145 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
146 ok(!lstrcmpW(szStatusText
, text_html
), "unexpected szStatusText\n");
148 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
149 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
150 ok(!lstrcmpW(szStatusText
, cache_file
), "unexpected szStatusText\n");
152 case BINDSTATUS_DIRECTBIND
:
153 CHECK_EXPECT(ReportProgress_DIRECTBIND
);
154 ok(!szStatusText
, "szStatusText != NULL\n");
157 ok(0, "unexpected ulStatusCode %d\n", ulStatusCode
);
164 static HRESULT WINAPI
ProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
, ULONG ulProgress
,
167 CHECK_EXPECT(ReportData
);
169 ok(ulProgress
== ulProgressMax
, "ulProgress != ulProgressMax\n");
170 if(test_protocol
== ITS_PROTOCOL
)
171 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
), "grcf = %08x\n", grfBSCF
);
173 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
), "grcf = %08x\n", grfBSCF
);
177 DWORD cb
= 0xdeadbeef;
180 hres
= IInternetProtocol_Read(read_protocol
, buf
, sizeof(buf
), &cb
);
181 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
182 ok(cb
== 13, "cb=%u expected 13\n", cb
);
183 ok(!memcmp(buf
, "<html></html>", 13), "unexpected data\n");
189 static HRESULT WINAPI
ProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
,
190 DWORD dwError
, LPCWSTR szResult
)
192 CHECK_EXPECT(ReportResult
);
194 ok(hrResult
== expect_hrResult
, "expected: %08x got: %08x\n", expect_hrResult
, hrResult
);
195 ok(dwError
== 0, "dwError = %d\n", dwError
);
196 ok(!szResult
, "szResult != NULL\n");
201 static IInternetProtocolSinkVtbl protocol_sink_vtbl
= {
202 ProtocolSink_QueryInterface
,
204 ProtocolSink_Release
,
206 ProtocolSink_ReportProgress
,
207 ProtocolSink_ReportData
,
208 ProtocolSink_ReportResult
211 static IInternetProtocolSink protocol_sink
= {
215 static HRESULT WINAPI
BindInfo_QueryInterface(IInternetBindInfo
*iface
, REFIID riid
, void **ppv
)
217 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
221 return E_NOINTERFACE
;
224 static ULONG WINAPI
BindInfo_AddRef(IInternetBindInfo
*iface
)
229 static ULONG WINAPI
BindInfo_Release(IInternetBindInfo
*iface
)
234 static HRESULT WINAPI
BindInfo_GetBindInfo(IInternetBindInfo
*iface
, DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
236 CHECK_EXPECT(GetBindInfo
);
238 ok(grfBINDF
!= NULL
, "grfBINDF == NULL\n");
240 ok(!*grfBINDF
, "*grfBINDF != 0\n");
241 ok(pbindinfo
!= NULL
, "pbindinfo == NULL\n");
242 ok(pbindinfo
->cbSize
== sizeof(BINDINFO
), "wrong size of pbindinfo: %d\n", pbindinfo
->cbSize
);
248 static HRESULT WINAPI
BindInfo_GetBindString(IInternetBindInfo
*iface
, ULONG ulStringType
, LPOLESTR
*ppwzStr
,
249 ULONG cEl
, ULONG
*pcElFetched
)
251 ok(0, "unexpected call\n");
255 static IInternetBindInfoVtbl bind_info_vtbl
= {
256 BindInfo_QueryInterface
,
259 BindInfo_GetBindInfo
,
260 BindInfo_GetBindString
263 static IInternetBindInfo bind_info
= {
267 static void test_protocol_fail(IInternetProtocol
*protocol
, LPCWSTR url
, HRESULT expected_hres
)
271 SET_EXPECT(GetBindInfo
);
272 SET_EXPECT(ReportResult
);
274 expect_hrResult
= expected_hres
;
275 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
276 ok(hres
== expected_hres
, "expected: %08x got: %08x\n", expected_hres
, hres
);
278 CHECK_CALLED(GetBindInfo
);
279 CHECK_CALLED(ReportResult
);
282 #define protocol_start(p,u,e) _protocol_start(__LINE__,p,u,e)
283 static HRESULT
_protocol_start(unsigned line
, IInternetProtocol
*protocol
, LPCWSTR url
, BOOL expect_mime
)
287 SET_EXPECT(GetBindInfo
);
288 if(test_protocol
== MK_PROTOCOL
)
289 SET_EXPECT(ReportProgress_DIRECTBIND
);
290 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
292 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
293 if(test_protocol
== MK_PROTOCOL
)
294 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
295 SET_EXPECT(ReportData
);
296 if(test_protocol
== ITS_PROTOCOL
)
297 SET_EXPECT(ReportProgress_BEGINDOWNLOADDATA
);
298 SET_EXPECT(ReportResult
);
299 expect_hrResult
= S_OK
;
301 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
304 SET_CALLED(GetBindInfo
);
305 if(test_protocol
== MK_PROTOCOL
)
306 SET_CALLED(ReportProgress_DIRECTBIND
);
307 SET_CALLED(ReportProgress_SENDINGREQUEST
);
309 SET_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
310 if(test_protocol
== MK_PROTOCOL
)
311 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
312 SET_CALLED(ReportData
);
313 if(test_protocol
== ITS_PROTOCOL
)
314 SET_CALLED(ReportProgress_BEGINDOWNLOADDATA
);
315 SET_CALLED(ReportResult
);
317 CHECK_CALLED(GetBindInfo
);
318 if(test_protocol
== MK_PROTOCOL
)
319 SET_CALLED(ReportProgress_DIRECTBIND
);
320 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
322 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
323 if(test_protocol
== MK_PROTOCOL
)
324 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
325 CHECK_CALLED(ReportData
);
326 if(test_protocol
== ITS_PROTOCOL
)
327 CHECK_CALLED(ReportProgress_BEGINDOWNLOADDATA
);
328 CHECK_CALLED(ReportResult
);
334 static void test_protocol_url(IClassFactory
*factory
, LPCWSTR url
, BOOL expect_mime
)
336 IInternetProtocol
*protocol
;
341 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
342 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
346 hres
= protocol_start(protocol
, url
, expect_mime
);
348 IInternetProtocol_Release(protocol
);
352 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
353 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
354 ok(cb
== 13, "cb=%u expected 13\n", cb
);
355 ok(!memcmp(buf
, "<html></html>", 13), "unexpected data\n");
356 ref
= IInternetProtocol_Release(protocol
);
357 ok(!ref
, "protocol ref=%d\n", ref
);
359 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
360 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
365 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
366 ok(hres
== (test_protocol
== ITS_PROTOCOL
? INET_E_DATA_NOT_AVAILABLE
: E_FAIL
),
367 "Read returned %08x\n", hres
);
368 ok(cb
== 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb
);
370 protocol_start(protocol
, url
, expect_mime
);
371 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
372 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
373 ok(cb
== 2, "cb=%u expected 2\n", cb
);
374 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
375 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
376 ok(cb
== 11, "cb=%u, expected 11\n", cb
);
377 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
378 ok(hres
== S_FALSE
, "Read failed: %08x expected S_FALSE\n", hres
);
379 ok(cb
== 0, "cb=%u expected 0\n", cb
);
380 hres
= IInternetProtocol_UnlockRequest(protocol
);
381 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
382 ref
= IInternetProtocol_Release(protocol
);
383 ok(!ref
, "protocol ref=%d\n", ref
);
385 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
386 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
390 protocol_start(protocol
, url
, expect_mime
);
391 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
392 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
393 hres
= IInternetProtocol_LockRequest(protocol
, 0);
394 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
395 hres
= IInternetProtocol_UnlockRequest(protocol
);
396 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
397 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
398 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
399 ok(cb
== 11, "cb=%u, expected 11\n", cb
);
400 ref
= IInternetProtocol_Release(protocol
);
401 ok(!ref
, "protocol ref=%d\n", ref
);
403 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
404 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
408 protocol_start(protocol
, url
, expect_mime
);
409 hres
= IInternetProtocol_LockRequest(protocol
, 0);
410 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
411 hres
= IInternetProtocol_Terminate(protocol
, 0);
412 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
413 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
414 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
415 ok(cb
== 2, "cb=%u, expected 2\n", cb
);
416 hres
= IInternetProtocol_UnlockRequest(protocol
);
417 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
418 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
419 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
420 ok(cb
== 2, "cb=%u, expected 2\n", cb
);
421 hres
= IInternetProtocol_Terminate(protocol
, 0);
422 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
423 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
424 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
425 ok(cb
== 2, "cb=%u expected 2\n", cb
);
426 ref
= IInternetProtocol_Release(protocol
);
427 ok(!ref
, "protocol ref=%d\n", ref
);
429 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&read_protocol
);
430 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
434 protocol_start(read_protocol
, url
, expect_mime
);
435 ref
= IInternetProtocol_Release(read_protocol
);
436 ok(!ref
, "protocol ref=%d\n", ref
);
437 read_protocol
= NULL
;
440 static const struct {
441 const WCHAR
*base_url
;
442 const WCHAR
*rel_url
;
445 const WCHAR
*combined_url
;
446 } combine_tests
[] = {
447 {L
"its:test.chm::/blank.html", L
"its:test.chm::/blank.html", 0, STG_E_INVALIDNAME
, NULL
},
448 {L
"mS-iTs:test.chm::/blank.html", L
"mS-iTs:test.chm::/blank.html", 0, STG_E_INVALIDNAME
, NULL
},
449 {L
"its:test.chm::/blank.html", L
"test.html", 0, S_OK
, L
"its:test.chm::/test.html"},
450 {L
"its:test.chm::/blank.html", L
"test.chm::/test.html", 0, STG_E_INVALIDNAME
, NULL
},
451 {L
"its:test.chm::/blank.html", L
"/test.html", 0, S_OK
, L
"its:test.chm::/test.html"},
452 {L
"its:test.chm::/blank.html", L
"te:t.html", 0, STG_E_INVALIDNAME
, NULL
},
453 {L
"its:test.chm::/blank.html", L
"/test.html", URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, S_OK
, L
"its:test.chm::/test.html"},
454 {L
"its:test.chm::/blank.html", L
"dir/test.html", 0, S_OK
, L
"its:test.chm::/dir/test.html"},
455 {L
"test.html", L
"test.chm::/test.html", 0, 0x80041001, NULL
},
456 {L
"its:test:.chm::/blank.html", L
"test.html", 0, S_OK
, L
"its:test:.chm::/test.html"},
457 {L
"its:test.chm::/dir/blank.html", L
"test.html", 0, S_OK
, L
"its:test.chm::/dir/test.html"},
458 {L
"its:test.chm::blank.html", L
"test.html", 0, S_OK
, L
"its:test.chm::blank.htmltest.html"},
459 {L
"ms-its:test.chm::/dir/blank.html", L
"test.html", 0, S_OK
, L
"ms-its:test.chm::/dir/test.html"},
460 {L
"mk:@MSITStore:test.chm::/dir/blank.html", L
"test.html", 0, S_OK
, L
"mk:@MSITStore:test.chm::/dir/test.html"},
461 {L
"xxx:test.chm::/dir/blank.html", L
"test.html", 0, INET_E_USE_DEFAULT_PROTOCOLHANDLER
, NULL
},
462 {L
"its:test.chm::/dir/blank.html", L
"/test.html", 0, S_OK
, L
"its:test.chm::/test.html"},
463 {L
"its:test.chm::/blank.html", L
"#frag", 0, S_OK
, L
"its:test.chm::/blank.html#frag"},
464 {L
"its:test.chm::/blank.html#hash", L
"#frag", 0, S_OK
, L
"its:test.chm::/blank.html#hash#frag"},
465 {L
"its:test.chm::/blank.html", L
"test.html#frag", 0, S_OK
, L
"its:test.chm::/test.html#frag"},
466 {L
"its:test.chm::/blank.html", L
"/test.html#frag", 0, S_OK
, L
"its:test.chm::/test.html#frag"},
467 {L
"its:test.chm::/blank.html", L
"?query", 0, S_OK
, L
"its:test.chm::/?query"},
468 {L
"its:test.chm::/blank.html#frag/blank", L
"test.html", 0, S_OK
, L
"its:test.chm::/blank.html#frag/test.html"},
471 static void test_its_protocol_info(IInternetProtocol
*protocol
)
473 IInternetProtocolInfo
*info
;
478 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolInfo
, (void**)&info
);
479 ok(hres
== S_OK
, "Could not get IInternetProtocolInfo interface: %08x\n", hres
);
483 for(i
= PARSE_CANONICALIZE
; i
<= PARSE_UNESCAPE
; i
++) {
484 if(i
!= PARSE_CANONICALIZE
&& i
!= PARSE_SECURITY_URL
) {
485 hres
= IInternetProtocolInfo_ParseUrl(info
, blank_url1
, i
, 0, buf
,
486 ARRAY_SIZE(buf
), &size
, 0);
487 ok(hres
== INET_E_DEFAULT_ACTION
,
488 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i
, hres
);
492 for(i
=0; i
< ARRAY_SIZE(combine_tests
); i
++) {
494 memset(buf
, 0xfe, sizeof(buf
));
495 hres
= IInternetProtocolInfo_CombineUrl(info
, combine_tests
[i
].base_url
,
496 combine_tests
[i
].rel_url
, combine_tests
[i
].flags
, buf
, ARRAY_SIZE(buf
), &size
, 0);
497 ok(hres
== combine_tests
[i
].hres
, "[%d] CombineUrl returned %08x, expected %08x\n",
498 i
, hres
, combine_tests
[i
].hres
);
499 ok(size
== (combine_tests
[i
].combined_url
? lstrlenW(combine_tests
[i
].combined_url
)+1
500 : 0xdeadbeef), "[%d] unexpected size=%d\n", i
, size
);
501 if(combine_tests
[i
].combined_url
)
502 ok(!lstrcmpW(buf
, combine_tests
[i
].combined_url
), "[%d] unexpected result: %s\n", i
, wine_dbgstr_w(buf
));
504 ok(buf
[0] == 0xfefe, "buf changed\n");
508 memset(buf
, 0xfe, sizeof(buf
));
509 hres
= IInternetProtocolInfo_CombineUrl(info
, L
"its:test.chm::/blank.html", L
"test.html", 0, buf
,
511 ok(hres
== E_OUTOFMEMORY
, "CombineUrl failed: %08x\n", hres
);
512 ok(size
== 25, "size=%d\n", size
);
513 ok(buf
[0] == 0xfefe, "buf changed\n");
515 IInternetProtocolInfo_Release(info
);
518 static void test_its_protocol(void)
520 IInternetProtocolInfo
*info
;
521 IClassFactory
*factory
;
526 static const WCHAR wrong_url1
[] =
527 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','.','h','t','m','l',0};
528 static const WCHAR wrong_url2
[] =
529 {'i','t','s',':','t','e','s','.','c','h','m',':',':','b','/','l','a','n','k','.','h','t','m','l',0};
530 static const WCHAR wrong_url3
[] =
531 {'i','t','s',':','t','e','s','t','.','c','h','m','/','b','l','a','n','k','.','h','t','m','l',0};
532 static const WCHAR wrong_url4
[] = {'m','k',':','@','M','S','I','T','S','t','o','r',':',
533 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
534 static const WCHAR wrong_url5
[] = {'f','i','l','e',':',
535 't','e','s','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
537 test_protocol
= ITS_PROTOCOL
;
539 hres
= CoGetClassObject(&CLSID_ITSProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
541 broken(hres
== REGDB_E_CLASSNOTREG
), /* Some W95 and NT4 */
542 "CoGetClassObject failed: %08x\n", hres
);
546 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&info
);
547 ok(hres
== E_NOINTERFACE
, "Could not get IInternetProtocolInfo: %08x\n", hres
);
549 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
550 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
551 if(SUCCEEDED(hres
)) {
552 IInternetProtocol
*protocol
;
554 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
555 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
556 if(SUCCEEDED(hres
)) {
557 test_its_protocol_info(protocol
);
559 test_protocol_fail(protocol
, wrong_url1
, STG_E_FILENOTFOUND
);
560 test_protocol_fail(protocol
, wrong_url2
, STG_E_FILENOTFOUND
);
561 test_protocol_fail(protocol
, wrong_url3
, STG_E_FILENOTFOUND
);
563 hres
= IInternetProtocol_Start(protocol
, wrong_url4
, &protocol_sink
, &bind_info
, 0, 0);
564 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
565 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres
);
567 hres
= IInternetProtocol_Start(protocol
, wrong_url5
, &protocol_sink
, &bind_info
, 0, 0);
568 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
569 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres
);
571 ref
= IInternetProtocol_Release(protocol
);
572 ok(!ref
, "protocol ref=%d\n", ref
);
574 test_protocol_url(factory
, blank_url1
, TRUE
);
575 test_protocol_url(factory
, blank_url2
, TRUE
);
576 test_protocol_url(factory
, blank_url3
, TRUE
);
577 test_protocol_url(factory
, blank_url4
, TRUE
);
578 test_protocol_url(factory
, blank_url5
, TRUE
);
579 test_protocol_url(factory
, blank_url6
, TRUE
);
580 test_protocol_url(factory
, blank_url8
, TRUE
);
581 test_protocol_url(factory
, blank_url9
, TRUE
);
582 bindf
= BINDF_FROMURLMON
| BINDF_NEEDFILE
;
583 test_protocol_url(factory
, blank_url1
, TRUE
);
586 IClassFactory_Release(factory
);
589 IUnknown_Release(unk
);
592 static void test_mk_protocol(void)
597 test_protocol
= MK_PROTOCOL
;
599 hres
= CoGetClassObject(&CLSID_MkProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
,
602 broken(hres
== REGDB_E_CLASSNOTREG
), /* Some W95 and NT4 */
603 "CoGetClassObject failed: %08x\n", hres
);
607 cache_file
= cache_file1
;
608 test_protocol_url(cf
, blank_url3
, TRUE
);
609 cache_file
= cache_file2
;
610 test_protocol_url(cf
, blank_url7
, TRUE
);
611 cache_file
= cache_file3
;
612 test_protocol_url(cf
, blank_url8
, FALSE
);
614 IClassFactory_Release(cf
);
617 static BOOL
create_chm(void)
623 file
= CreateFileA("test.chm", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
624 FILE_ATTRIBUTE_NORMAL
, NULL
);
625 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create test.chm file\n");
626 if(file
== INVALID_HANDLE_VALUE
)
629 src
= FindResourceA(NULL
, MAKEINTRESOURCEA(60), MAKEINTRESOURCEA(60));
631 WriteFile(file
, LoadResource(NULL
, src
), SizeofResource(NULL
, src
), &size
, NULL
);
637 static void delete_chm(void)
641 ret
= DeleteFileA("test.chm");
642 ok(ret
, "DeleteFileA failed: %d\n", GetLastError());
645 static const IID outer_test_iid
= {0xabcabc00,0,0,{0,0,0,0,0,0,0,0x66}};
647 static HRESULT WINAPI
outer_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
649 if(IsEqualGUID(riid
, &outer_test_iid
)) {
650 CHECK_EXPECT(outer_QI_test
);
651 *ppv
= (IUnknown
*)0xdeadbeef;
654 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
655 return E_NOINTERFACE
;
658 static ULONG WINAPI
outer_AddRef(IUnknown
*iface
)
663 static ULONG WINAPI
outer_Release(IUnknown
*iface
)
668 static const IUnknownVtbl outer_vtbl
= {
669 outer_QueryInterface
,
674 static void test_com_aggregation(const CLSID
*clsid
)
676 IUnknown outer
= { &outer_vtbl
};
677 IClassFactory
*class_factory
;
678 IUnknown
*unk
, *unk2
, *unk3
;
681 hres
= CoGetClassObject(clsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&class_factory
);
682 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
684 hres
= IClassFactory_CreateInstance(class_factory
, &outer
, &IID_IUnknown
, (void**)&unk
);
685 ok(hres
== S_OK
, "CreateInstance returned: %08x\n", hres
);
687 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocol
, (void**)&unk2
);
688 ok(hres
== S_OK
, "Could not get IInternetProtocol iface: %08x\n", hres
);
690 SET_EXPECT(outer_QI_test
);
691 hres
= IUnknown_QueryInterface(unk2
, &outer_test_iid
, (void**)&unk3
);
692 CHECK_CALLED(outer_QI_test
);
693 ok(hres
== S_OK
, "Could not get IInternetProtocol iface: %08x\n", hres
);
694 ok(unk3
== (IUnknown
*)0xdeadbeef, "unexpected unk2\n");
696 IUnknown_Release(unk2
);
697 IUnknown_Release(unk
);
699 unk
= (void*)0xdeadbeef;
700 hres
= IClassFactory_CreateInstance(class_factory
, &outer
, &IID_IInternetProtocol
, (void**)&unk
);
701 ok(hres
== CLASS_E_NOAGGREGATION
, "CreateInstance returned: %08x\n", hres
);
702 ok(!unk
, "unk = %p\n", unk
);
704 IClassFactory_Release(class_factory
);
716 test_com_aggregation(&CLSID_ITSProtocol
);