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
24 #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 SET_CALLED(func) \
48 expect_ ## func = called_ ## func = FALSE
50 #define CHECK_CALLED(func) \
52 ok(called_ ## func, "expected " #func "\n"); \
56 DEFINE_GUID(CLSID_ITSProtocol
,0x9d148291,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
58 DEFINE_EXPECT(GetBindInfo
);
59 DEFINE_EXPECT(ReportProgress_BEGINDOWNLOADDATA
);
60 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST
);
61 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
62 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
63 DEFINE_EXPECT(ReportProgress_DIRECTBIND
);
64 DEFINE_EXPECT(ReportData
);
65 DEFINE_EXPECT(ReportResult
);
66 DEFINE_EXPECT(outer_QI_test
);
68 static HRESULT expect_hrResult
;
69 static IInternetProtocol
*read_protocol
= NULL
;
72 static const WCHAR blank_url1
[] = {'i','t','s',':',
73 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
74 static const WCHAR blank_url2
[] = {'m','S','-','i','T','s',':',
75 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
76 static const WCHAR blank_url3
[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
77 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
78 static const WCHAR blank_url4
[] = {'i','t','s',':',
79 't','e','s','t','.','c','h','m',':',':','b','l','a','n','k','.','h','t','m','l',0};
80 static const WCHAR blank_url5
[] = {'i','t','s',':',
81 't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
82 static const WCHAR blank_url6
[] = {'i','t','s',':',
83 't','e','s','t','.','c','h','m',':',':','/','%','6','2','l','a','n','k','.','h','t','m','l',0};
84 static const WCHAR blank_url7
[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
85 't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
86 static const WCHAR blank_url8
[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
87 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
88 static const WCHAR blank_url9
[] = {'i','t','s',':',
89 't','e','s','t','.','c','h','m',':',':','/','d','i','r','/','.','.','/','b','l','a','n','k','.','h','t','m','l',0};
96 static const WCHAR cache_file1
[] =
97 {'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
98 static const WCHAR cache_file2
[] =
99 {'t','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
100 static const WCHAR cache_file3
[] =
101 {'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
102 static const WCHAR
*cache_file
= cache_file1
;
104 static const WCHAR
*a2w(const char *str
)
106 static WCHAR bufs
[8][128];
113 MultiByteToWideChar(CP_ACP
, 0, str
, -1, bufs
[i
], 128);
117 static int strcmp_wa(const WCHAR
*str1
, const char *str2
)
119 return lstrcmpW(str1
, a2w(str2
));
122 static HRESULT WINAPI
ProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
124 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
128 return E_NOINTERFACE
;
131 static ULONG WINAPI
ProtocolSink_AddRef(IInternetProtocolSink
*iface
)
136 static ULONG WINAPI
ProtocolSink_Release(IInternetProtocolSink
*iface
)
141 static HRESULT WINAPI
ProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
143 ok(0, "unexpected call\n");
147 static HRESULT WINAPI
ProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
148 LPCWSTR szStatusText
)
150 static const WCHAR blank_html
[] = {'b','l','a','n','k','.','h','t','m','l',0};
151 static const WCHAR text_html
[] = {'t','e','x','t','/','h','t','m','l',0};
153 switch(ulStatusCode
) {
154 case BINDSTATUS_BEGINDOWNLOADDATA
:
155 CHECK_EXPECT(ReportProgress_BEGINDOWNLOADDATA
);
156 ok(!szStatusText
, "szStatusText != NULL\n");
158 case BINDSTATUS_SENDINGREQUEST
:
159 CHECK_EXPECT(ReportProgress_SENDINGREQUEST
);
160 if(test_protocol
== ITS_PROTOCOL
)
161 ok(!lstrcmpW(szStatusText
, blank_html
), "unexpected szStatusText\n");
163 ok(szStatusText
== NULL
, "szStatusText != NULL\n");
165 case BINDSTATUS_MIMETYPEAVAILABLE
:
166 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
167 ok(!lstrcmpW(szStatusText
, text_html
), "unexpected szStatusText\n");
169 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
170 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
171 ok(!lstrcmpW(szStatusText
, cache_file
), "unexpected szStatusText\n");
173 case BINDSTATUS_DIRECTBIND
:
174 CHECK_EXPECT(ReportProgress_DIRECTBIND
);
175 ok(!szStatusText
, "szStatusText != NULL\n");
178 ok(0, "unexpected ulStatusCode %d\n", ulStatusCode
);
185 static HRESULT WINAPI
ProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
, ULONG ulProgress
,
188 CHECK_EXPECT(ReportData
);
190 ok(ulProgress
== ulProgressMax
, "ulProgress != ulProgressMax\n");
191 if(test_protocol
== ITS_PROTOCOL
)
192 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
), "grcf = %08x\n", grfBSCF
);
194 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
), "grcf = %08x\n", grfBSCF
);
198 DWORD cb
= 0xdeadbeef;
201 hres
= IInternetProtocol_Read(read_protocol
, buf
, sizeof(buf
), &cb
);
202 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
203 ok(cb
== 13, "cb=%u expected 13\n", cb
);
204 ok(!memcmp(buf
, "<html></html>", 13), "unexpected data\n");
210 static HRESULT WINAPI
ProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
,
211 DWORD dwError
, LPCWSTR szResult
)
213 CHECK_EXPECT(ReportResult
);
215 ok(hrResult
== expect_hrResult
, "expected: %08x got: %08x\n", expect_hrResult
, hrResult
);
216 ok(dwError
== 0, "dwError = %d\n", dwError
);
217 ok(!szResult
, "szResult != NULL\n");
222 static IInternetProtocolSinkVtbl protocol_sink_vtbl
= {
223 ProtocolSink_QueryInterface
,
225 ProtocolSink_Release
,
227 ProtocolSink_ReportProgress
,
228 ProtocolSink_ReportData
,
229 ProtocolSink_ReportResult
232 static IInternetProtocolSink protocol_sink
= {
236 static HRESULT WINAPI
BindInfo_QueryInterface(IInternetBindInfo
*iface
, REFIID riid
, void **ppv
)
238 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
242 return E_NOINTERFACE
;
245 static ULONG WINAPI
BindInfo_AddRef(IInternetBindInfo
*iface
)
250 static ULONG WINAPI
BindInfo_Release(IInternetBindInfo
*iface
)
255 static HRESULT WINAPI
BindInfo_GetBindInfo(IInternetBindInfo
*iface
, DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
257 CHECK_EXPECT(GetBindInfo
);
259 ok(grfBINDF
!= NULL
, "grfBINDF == NULL\n");
261 ok(!*grfBINDF
, "*grfBINDF != 0\n");
262 ok(pbindinfo
!= NULL
, "pbindinfo == NULL\n");
263 ok(pbindinfo
->cbSize
== sizeof(BINDINFO
), "wrong size of pbindinfo: %d\n", pbindinfo
->cbSize
);
269 static HRESULT WINAPI
BindInfo_GetBindString(IInternetBindInfo
*iface
, ULONG ulStringType
, LPOLESTR
*ppwzStr
,
270 ULONG cEl
, ULONG
*pcElFetched
)
272 ok(0, "unexpected call\n");
276 static IInternetBindInfoVtbl bind_info_vtbl
= {
277 BindInfo_QueryInterface
,
280 BindInfo_GetBindInfo
,
281 BindInfo_GetBindString
284 static IInternetBindInfo bind_info
= {
288 static void test_protocol_fail(IInternetProtocol
*protocol
, LPCWSTR url
, HRESULT expected_hres
)
292 SET_EXPECT(GetBindInfo
);
293 SET_EXPECT(ReportResult
);
295 expect_hrResult
= expected_hres
;
296 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
297 ok(hres
== expected_hres
, "expected: %08x got: %08x\n", expected_hres
, hres
);
299 CHECK_CALLED(GetBindInfo
);
300 CHECK_CALLED(ReportResult
);
303 #define protocol_start(p,u,e) _protocol_start(__LINE__,p,u,e)
304 static HRESULT
_protocol_start(unsigned line
, IInternetProtocol
*protocol
, LPCWSTR url
, BOOL expect_mime
)
308 SET_EXPECT(GetBindInfo
);
309 if(test_protocol
== MK_PROTOCOL
)
310 SET_EXPECT(ReportProgress_DIRECTBIND
);
311 SET_EXPECT(ReportProgress_SENDINGREQUEST
);
313 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE
);
314 if(test_protocol
== MK_PROTOCOL
)
315 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
316 SET_EXPECT(ReportData
);
317 if(test_protocol
== ITS_PROTOCOL
)
318 SET_EXPECT(ReportProgress_BEGINDOWNLOADDATA
);
319 SET_EXPECT(ReportResult
);
320 expect_hrResult
= S_OK
;
322 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
325 SET_CALLED(GetBindInfo
);
326 if(test_protocol
== MK_PROTOCOL
)
327 SET_CALLED(ReportProgress_DIRECTBIND
);
328 SET_CALLED(ReportProgress_SENDINGREQUEST
);
330 SET_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
331 if(test_protocol
== MK_PROTOCOL
)
332 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
333 SET_CALLED(ReportData
);
334 if(test_protocol
== ITS_PROTOCOL
)
335 SET_CALLED(ReportProgress_BEGINDOWNLOADDATA
);
336 SET_CALLED(ReportResult
);
338 CHECK_CALLED(GetBindInfo
);
339 if(test_protocol
== MK_PROTOCOL
)
340 SET_CALLED(ReportProgress_DIRECTBIND
);
341 CHECK_CALLED(ReportProgress_SENDINGREQUEST
);
343 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE
);
344 if(test_protocol
== MK_PROTOCOL
)
345 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE
);
346 CHECK_CALLED(ReportData
);
347 if(test_protocol
== ITS_PROTOCOL
)
348 CHECK_CALLED(ReportProgress_BEGINDOWNLOADDATA
);
349 CHECK_CALLED(ReportResult
);
355 static void test_protocol_url(IClassFactory
*factory
, LPCWSTR url
, BOOL expect_mime
)
357 IInternetProtocol
*protocol
;
362 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
363 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
367 hres
= protocol_start(protocol
, url
, expect_mime
);
369 IInternetProtocol_Release(protocol
);
373 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
374 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
375 ok(cb
== 13, "cb=%u expected 13\n", cb
);
376 ok(!memcmp(buf
, "<html></html>", 13), "unexpected data\n");
377 ref
= IInternetProtocol_Release(protocol
);
378 ok(!ref
, "protocol ref=%d\n", ref
);
380 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
381 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
386 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
387 ok(hres
== (test_protocol
== ITS_PROTOCOL
? INET_E_DATA_NOT_AVAILABLE
: E_FAIL
),
388 "Read returned %08x\n", hres
);
389 ok(cb
== 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb
);
391 protocol_start(protocol
, url
, expect_mime
);
392 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
393 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
394 ok(cb
== 2, "cb=%u expected 2\n", cb
);
395 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
396 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
397 ok(cb
== 11, "cb=%u, expected 11\n", cb
);
398 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
399 ok(hres
== S_FALSE
, "Read failed: %08x expected S_FALSE\n", hres
);
400 ok(cb
== 0, "cb=%u expected 0\n", cb
);
401 hres
= IInternetProtocol_UnlockRequest(protocol
);
402 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
403 ref
= IInternetProtocol_Release(protocol
);
404 ok(!ref
, "protocol ref=%d\n", ref
);
406 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
407 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
411 protocol_start(protocol
, url
, expect_mime
);
412 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
413 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
414 hres
= IInternetProtocol_LockRequest(protocol
, 0);
415 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
416 hres
= IInternetProtocol_UnlockRequest(protocol
);
417 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
418 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
419 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
420 ok(cb
== 11, "cb=%u, expected 11\n", cb
);
421 ref
= IInternetProtocol_Release(protocol
);
422 ok(!ref
, "protocol ref=%d\n", ref
);
424 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
425 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
429 protocol_start(protocol
, url
, expect_mime
);
430 hres
= IInternetProtocol_LockRequest(protocol
, 0);
431 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
432 hres
= IInternetProtocol_Terminate(protocol
, 0);
433 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
434 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
435 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
436 ok(cb
== 2, "cb=%u, expected 2\n", cb
);
437 hres
= IInternetProtocol_UnlockRequest(protocol
);
438 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
439 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
440 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
441 ok(cb
== 2, "cb=%u, expected 2\n", cb
);
442 hres
= IInternetProtocol_Terminate(protocol
, 0);
443 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
444 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
445 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
446 ok(cb
== 2, "cb=%u expected 2\n", cb
);
447 ref
= IInternetProtocol_Release(protocol
);
448 ok(!ref
, "protocol ref=%d\n", ref
);
450 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&read_protocol
);
451 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
455 protocol_start(read_protocol
, url
, expect_mime
);
456 ref
= IInternetProtocol_Release(read_protocol
);
457 ok(!ref
, "protocol ref=%d\n", ref
);
458 read_protocol
= NULL
;
461 static const struct {
462 const char *base_url
;
466 const char *combined_url
;
467 } combine_tests
[] = {
468 {"its:test.chm::/blank.html", "its:test.chm::/blank.html", 0, STG_E_INVALIDNAME
, NULL
},
469 {"mS-iTs:test.chm::/blank.html", "mS-iTs:test.chm::/blank.html", 0, STG_E_INVALIDNAME
, NULL
},
470 {"its:test.chm::/blank.html", "test.html", 0, S_OK
, "its:test.chm::/test.html"},
471 {"its:test.chm::/blank.html", "test.chm::/test.html", 0, STG_E_INVALIDNAME
, NULL
},
472 {"its:test.chm::/blank.html", "/test.html", 0, S_OK
, "its:test.chm::/test.html"},
473 {"its:test.chm::/blank.html", "te:t.html", 0, STG_E_INVALIDNAME
, NULL
},
474 {"its:test.chm::/blank.html", "/test.html", URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, S_OK
, "its:test.chm::/test.html"},
475 {"its:test.chm::/blank.html", "dir/test.html", 0, S_OK
, "its:test.chm::/dir/test.html"},
476 {"test.html", "test.chm::/test.html", 0, 0x80041001, NULL
},
477 {"its:test:.chm::/blank.html", "test.html", 0, S_OK
, "its:test:.chm::/test.html"},
478 {"its:test.chm::/dir/blank.html", "test.html", 0, S_OK
, "its:test.chm::/dir/test.html"},
479 {"its:test.chm::blank.html", "test.html", 0, S_OK
, "its:test.chm::blank.htmltest.html"},
480 {"ms-its:test.chm::/dir/blank.html", "test.html", 0, S_OK
, "ms-its:test.chm::/dir/test.html"},
481 {"mk:@MSITStore:test.chm::/dir/blank.html", "test.html", 0, S_OK
, "mk:@MSITStore:test.chm::/dir/test.html"},
482 {"xxx:test.chm::/dir/blank.html", "test.html", 0, INET_E_USE_DEFAULT_PROTOCOLHANDLER
, NULL
},
483 {"its:test.chm::/dir/blank.html", "/test.html", 0, S_OK
, "its:test.chm::/test.html"},
484 {"its:test.chm::/blank.html", "#frag", 0, S_OK
, "its:test.chm::/blank.html#frag"},
485 {"its:test.chm::/blank.html#hash", "#frag", 0, S_OK
, "its:test.chm::/blank.html#hash#frag"},
486 {"its:test.chm::/blank.html", "test.html#frag", 0, S_OK
, "its:test.chm::/test.html#frag"},
487 {"its:test.chm::/blank.html", "/test.html#frag", 0, S_OK
, "its:test.chm::/test.html#frag"},
488 {"its:test.chm::/blank.html", "?query", 0, S_OK
, "its:test.chm::/?query"},
489 {"its:test.chm::/blank.html#frag/blank", "test.html", 0, S_OK
, "its:test.chm::/blank.html#frag/test.html"},
492 static void test_its_protocol_info(IInternetProtocol
*protocol
)
494 IInternetProtocolInfo
*info
;
499 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetProtocolInfo
, (void**)&info
);
500 ok(hres
== S_OK
, "Could not get IInternetProtocolInfo interface: %08x\n", hres
);
504 for(i
= PARSE_CANONICALIZE
; i
<= PARSE_UNESCAPE
; i
++) {
505 if(i
!= PARSE_CANONICALIZE
&& i
!= PARSE_SECURITY_URL
) {
506 hres
= IInternetProtocolInfo_ParseUrl(info
, blank_url1
, i
, 0, buf
,
507 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
508 ok(hres
== INET_E_DEFAULT_ACTION
,
509 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i
, hres
);
513 for(i
=0; i
< sizeof(combine_tests
)/sizeof(combine_tests
[0]); i
++) {
515 memset(buf
, 0xfe, sizeof(buf
));
516 hres
= IInternetProtocolInfo_CombineUrl(info
, a2w(combine_tests
[i
].base_url
),
517 a2w(combine_tests
[i
].rel_url
), combine_tests
[i
].flags
, buf
,
518 sizeof(buf
)/sizeof(WCHAR
), &size
, 0);
519 ok(hres
== combine_tests
[i
].hres
, "[%d] CombineUrl returned %08x, expected %08x\n",
520 i
, hres
, combine_tests
[i
].hres
);
521 ok(size
== (combine_tests
[i
].combined_url
? strlen(combine_tests
[i
].combined_url
)+1
522 : 0xdeadbeef), "[%d] unexpected size=%d\n", i
, size
);
523 if(combine_tests
[i
].combined_url
)
524 ok(!strcmp_wa(buf
, combine_tests
[i
].combined_url
), "[%d] unexpected result: %s\n", i
, wine_dbgstr_w(buf
));
526 ok(buf
[0] == 0xfefe, "buf changed\n");
530 memset(buf
, 0xfe, sizeof(buf
));
531 hres
= IInternetProtocolInfo_CombineUrl(info
, a2w("its:test.chm::/blank.html"), a2w("test.html"), 0, buf
,
533 ok(hres
== E_OUTOFMEMORY
, "CombineUrl failed: %08x\n", hres
);
534 ok(size
== 25, "size=%d\n", size
);
535 ok(buf
[0] == 0xfefe, "buf changed\n");
537 IInternetProtocolInfo_Release(info
);
540 static void test_its_protocol(void)
542 IInternetProtocolInfo
*info
;
543 IClassFactory
*factory
;
548 static const WCHAR wrong_url1
[] =
549 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','.','h','t','m','l',0};
550 static const WCHAR wrong_url2
[] =
551 {'i','t','s',':','t','e','s','.','c','h','m',':',':','b','/','l','a','n','k','.','h','t','m','l',0};
552 static const WCHAR wrong_url3
[] =
553 {'i','t','s',':','t','e','s','t','.','c','h','m','/','b','l','a','n','k','.','h','t','m','l',0};
554 static const WCHAR wrong_url4
[] = {'m','k',':','@','M','S','I','T','S','t','o','r',':',
555 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
556 static const WCHAR wrong_url5
[] = {'f','i','l','e',':',
557 't','e','s','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
559 test_protocol
= ITS_PROTOCOL
;
561 hres
= CoGetClassObject(&CLSID_ITSProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
563 broken(hres
== REGDB_E_CLASSNOTREG
), /* Some W95 and NT4 */
564 "CoGetClassObject failed: %08x\n", hres
);
568 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&info
);
569 ok(hres
== E_NOINTERFACE
, "Could not get IInternetProtocolInfo: %08x\n", hres
);
571 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
572 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
573 if(SUCCEEDED(hres
)) {
574 IInternetProtocol
*protocol
;
576 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
577 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
578 if(SUCCEEDED(hres
)) {
579 test_its_protocol_info(protocol
);
581 test_protocol_fail(protocol
, wrong_url1
, STG_E_FILENOTFOUND
);
582 test_protocol_fail(protocol
, wrong_url2
, STG_E_FILENOTFOUND
);
583 test_protocol_fail(protocol
, wrong_url3
, STG_E_FILENOTFOUND
);
585 hres
= IInternetProtocol_Start(protocol
, wrong_url4
, &protocol_sink
, &bind_info
, 0, 0);
586 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
587 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres
);
589 hres
= IInternetProtocol_Start(protocol
, wrong_url5
, &protocol_sink
, &bind_info
, 0, 0);
590 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
591 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres
);
593 ref
= IInternetProtocol_Release(protocol
);
594 ok(!ref
, "protocol ref=%d\n", ref
);
596 test_protocol_url(factory
, blank_url1
, TRUE
);
597 test_protocol_url(factory
, blank_url2
, TRUE
);
598 test_protocol_url(factory
, blank_url3
, TRUE
);
599 test_protocol_url(factory
, blank_url4
, TRUE
);
600 test_protocol_url(factory
, blank_url5
, TRUE
);
601 test_protocol_url(factory
, blank_url6
, TRUE
);
602 test_protocol_url(factory
, blank_url8
, TRUE
);
603 test_protocol_url(factory
, blank_url9
, TRUE
);
604 bindf
= BINDF_FROMURLMON
| BINDF_NEEDFILE
;
605 test_protocol_url(factory
, blank_url1
, TRUE
);
608 IClassFactory_Release(factory
);
611 IUnknown_Release(unk
);
614 static void test_mk_protocol(void)
619 test_protocol
= MK_PROTOCOL
;
621 hres
= CoGetClassObject(&CLSID_MkProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
,
624 broken(hres
== REGDB_E_CLASSNOTREG
), /* Some W95 and NT4 */
625 "CoGetClassObject failed: %08x\n", hres
);
629 cache_file
= cache_file1
;
630 test_protocol_url(cf
, blank_url3
, TRUE
);
631 cache_file
= cache_file2
;
632 test_protocol_url(cf
, blank_url7
, TRUE
);
633 cache_file
= cache_file3
;
634 test_protocol_url(cf
, blank_url8
, FALSE
);
636 IClassFactory_Release(cf
);
639 static BOOL
create_chm(void)
645 file
= CreateFileA("test.chm", GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
646 FILE_ATTRIBUTE_NORMAL
, NULL
);
647 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create test.chm file\n");
648 if(file
== INVALID_HANDLE_VALUE
)
651 src
= FindResourceA(NULL
, MAKEINTRESOURCEA(60), MAKEINTRESOURCEA(60));
653 WriteFile(file
, LoadResource(NULL
, src
), SizeofResource(NULL
, src
), &size
, NULL
);
659 static void delete_chm(void)
663 ret
= DeleteFileA("test.chm");
664 ok(ret
, "DeleteFileA failed: %d\n", GetLastError());
667 static const IID outer_test_iid
= {0xabcabc00,0,0,{0,0,0,0,0,0,0,0x66}};
669 static HRESULT WINAPI
outer_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
671 if(IsEqualGUID(riid
, &outer_test_iid
)) {
672 CHECK_EXPECT(outer_QI_test
);
673 *ppv
= (IUnknown
*)0xdeadbeef;
676 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid
));
677 return E_NOINTERFACE
;
680 static ULONG WINAPI
outer_AddRef(IUnknown
*iface
)
685 static ULONG WINAPI
outer_Release(IUnknown
*iface
)
690 static const IUnknownVtbl outer_vtbl
= {
691 outer_QueryInterface
,
696 static void test_com_aggregation(const CLSID
*clsid
)
698 IUnknown outer
= { &outer_vtbl
};
699 IClassFactory
*class_factory
;
700 IUnknown
*unk
, *unk2
, *unk3
;
703 hres
= CoGetClassObject(clsid
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IClassFactory
, (void**)&class_factory
);
704 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
706 hres
= IClassFactory_CreateInstance(class_factory
, &outer
, &IID_IUnknown
, (void**)&unk
);
707 ok(hres
== S_OK
, "CreateInstance returned: %08x\n", hres
);
709 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocol
, (void**)&unk2
);
710 ok(hres
== S_OK
, "Could not get IInternetProtocol iface: %08x\n", hres
);
712 SET_EXPECT(outer_QI_test
);
713 hres
= IUnknown_QueryInterface(unk2
, &outer_test_iid
, (void**)&unk3
);
714 CHECK_CALLED(outer_QI_test
);
715 ok(hres
== S_OK
, "Could not get IInternetProtocol iface: %08x\n", hres
);
716 ok(unk3
== (IUnknown
*)0xdeadbeef, "unexpected unk2\n");
718 IUnknown_Release(unk2
);
719 IUnknown_Release(unk
);
721 unk
= (void*)0xdeadbeef;
722 hres
= IClassFactory_CreateInstance(class_factory
, &outer
, &IID_IInternetProtocol
, (void**)&unk
);
723 ok(hres
== CLASS_E_NOAGGREGATION
, "CreateInstance returned: %08x\n", hres
);
724 ok(!unk
, "unk = %p\n", unk
);
726 IClassFactory_Release(class_factory
);
738 test_com_aggregation(&CLSID_ITSProtocol
);