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 CHECK_EXPECT2(func) \
46 ok(expect_ ##func, "unexpected call " #func "\n"); \
47 called_ ## func = TRUE; \
50 #define SET_CALLED(func) \
51 expect_ ## func = called_ ## func = FALSE
53 #define CHECK_CALLED(func) \
55 ok(called_ ## func, "expected " #func "\n"); \
59 DEFINE_GUID(CLSID_ITSProtocol,0x9d148291,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
61 DEFINE_EXPECT(GetBindInfo);
62 DEFINE_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
63 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
64 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
65 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
66 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
67 DEFINE_EXPECT(ReportData);
68 DEFINE_EXPECT(ReportResult);
70 static HRESULT expect_hrResult;
71 static IInternetProtocol *read_protocol = NULL;
74 static const WCHAR blank_url1[] = {'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_url2[] = {'m','S','-','i','T','s',':',
77 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
78 static const WCHAR blank_url3[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
79 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
80 static const WCHAR blank_url4[] = {'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_url5[] = {'i','t','s',':',
83 't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
84 static const WCHAR blank_url6[] = {'i','t','s',':',
85 't','e','s','t','.','c','h','m',':',':','/','%','6','2','l','a','n','k','.','h','t','m','l',0};
86 static const WCHAR blank_url7[] = {'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_url8[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
89 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
90 static const WCHAR blank_url9[] = {'i','t','s',':',
91 't','e','s','t','.','c','h','m',':',':','/','d','i','r','/','.','.','/','b','l','a','n','k','.','h','t','m','l',0};
98 static const WCHAR cache_file1[] =
99 {'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
100 static const WCHAR cache_file2[] =
101 {'t','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
102 static const WCHAR cache_file3[] =
103 {'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
104 static const WCHAR *cache_file = cache_file1;
106 static const WCHAR *a2w(const char *str)
108 static WCHAR bufs[8][128];
115 MultiByteToWideChar(CP_ACP, 0, str, -1, bufs[i], 128);
119 static int strcmp_wa(const WCHAR *str1, const char *str2)
121 return lstrcmpW(str1, a2w(str2));
124 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
126 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
130 return E_NOINTERFACE;
133 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
138 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
143 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
145 ok(0, "unexpected call\n");
149 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
150 LPCWSTR szStatusText)
152 static const WCHAR blank_html[] = {'b','l','a','n','k','.','h','t','m','l',0};
153 static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
155 switch(ulStatusCode) {
156 case BINDSTATUS_BEGINDOWNLOADDATA:
157 CHECK_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
158 ok(!szStatusText, "szStatusText != NULL\n");
160 case BINDSTATUS_SENDINGREQUEST:
161 CHECK_EXPECT(ReportProgress_SENDINGREQUEST);
162 if(test_protocol == ITS_PROTOCOL)
163 ok(!lstrcmpW(szStatusText, blank_html), "unexpected szStatusText\n");
165 ok(szStatusText == NULL, "szStatusText != NULL\n");
167 case BINDSTATUS_MIMETYPEAVAILABLE:
168 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
169 ok(!lstrcmpW(szStatusText, text_html), "unexpected szStatusText\n");
171 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
172 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
173 ok(!lstrcmpW(szStatusText, cache_file), "unexpected szStatusText\n");
175 case BINDSTATUS_DIRECTBIND:
176 CHECK_EXPECT(ReportProgress_DIRECTBIND);
177 ok(!szStatusText, "szStatusText != NULL\n");
180 ok(0, "unexpected ulStatusCode %d\n", ulStatusCode);
187 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
190 CHECK_EXPECT(ReportData);
192 ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
193 if(test_protocol == ITS_PROTOCOL)
194 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE), "grcf = %08x\n", grfBSCF);
196 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION), "grcf = %08x\n", grfBSCF);
200 DWORD cb = 0xdeadbeef;
203 hres = IInternetProtocol_Read(read_protocol, buf, sizeof(buf), &cb);
204 ok(hres == S_OK, "Read failed: %08x\n", hres);
205 ok(cb == 13, "cb=%u expected 13\n", cb);
206 ok(!memcmp(buf, "<html></html>", 13), "unexpected data\n");
212 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
213 DWORD dwError, LPCWSTR szResult)
215 CHECK_EXPECT(ReportResult);
217 ok(hrResult == expect_hrResult, "expected: %08x got: %08x\n", expect_hrResult, hrResult);
218 ok(dwError == 0, "dwError = %d\n", dwError);
219 ok(!szResult, "szResult != NULL\n");
224 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
225 ProtocolSink_QueryInterface,
227 ProtocolSink_Release,
229 ProtocolSink_ReportProgress,
230 ProtocolSink_ReportData,
231 ProtocolSink_ReportResult
234 static IInternetProtocolSink protocol_sink = {
238 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
240 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
244 return E_NOINTERFACE;
247 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
252 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
257 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
259 CHECK_EXPECT(GetBindInfo);
261 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
263 ok(!*grfBINDF, "*grfBINDF != 0\n");
264 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
265 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
271 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
272 ULONG cEl, ULONG *pcElFetched)
274 ok(0, "unexpected call\n");
278 static IInternetBindInfoVtbl bind_info_vtbl = {
279 BindInfo_QueryInterface,
282 BindInfo_GetBindInfo,
283 BindInfo_GetBindString
286 static IInternetBindInfo bind_info = {
290 static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres)
294 SET_EXPECT(GetBindInfo);
295 SET_EXPECT(ReportResult);
297 expect_hrResult = expected_hres;
298 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
299 ok(hres == expected_hres, "expected: %08x got: %08x\n", expected_hres, hres);
301 CHECK_CALLED(GetBindInfo);
302 CHECK_CALLED(ReportResult);
305 #define protocol_start(p,u,e) _protocol_start(__LINE__,p,u,e)
306 static HRESULT _protocol_start(unsigned line, IInternetProtocol *protocol, LPCWSTR url, BOOL expect_mime)
310 SET_EXPECT(GetBindInfo);
311 if(test_protocol == MK_PROTOCOL)
312 SET_EXPECT(ReportProgress_DIRECTBIND);
313 SET_EXPECT(ReportProgress_SENDINGREQUEST);
315 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
316 if(test_protocol == MK_PROTOCOL)
317 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
318 SET_EXPECT(ReportData);
319 if(test_protocol == ITS_PROTOCOL)
320 SET_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
321 SET_EXPECT(ReportResult);
322 expect_hrResult = S_OK;
324 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
327 SET_CALLED(GetBindInfo);
328 if(test_protocol == MK_PROTOCOL)
329 SET_CALLED(ReportProgress_DIRECTBIND);
330 SET_CALLED(ReportProgress_SENDINGREQUEST);
332 SET_CALLED(ReportProgress_MIMETYPEAVAILABLE);
333 if(test_protocol == MK_PROTOCOL)
334 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
335 SET_CALLED(ReportData);
336 if(test_protocol == ITS_PROTOCOL)
337 SET_CALLED(ReportProgress_BEGINDOWNLOADDATA);
338 SET_CALLED(ReportResult);
340 CHECK_CALLED(GetBindInfo);
341 if(test_protocol == MK_PROTOCOL)
342 SET_CALLED(ReportProgress_DIRECTBIND);
343 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
345 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
346 if(test_protocol == MK_PROTOCOL)
347 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
348 CHECK_CALLED(ReportData);
349 if(test_protocol == ITS_PROTOCOL)
350 CHECK_CALLED(ReportProgress_BEGINDOWNLOADDATA);
351 CHECK_CALLED(ReportResult);
357 static void test_protocol_url(IClassFactory *factory, LPCWSTR url, BOOL expect_mime)
359 IInternetProtocol *protocol;
364 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
365 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
369 hres = protocol_start(protocol, url, expect_mime);
371 IInternetProtocol_Release(protocol);
375 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
376 ok(hres == S_OK, "Read failed: %08x\n", hres);
377 ok(cb == 13, "cb=%u expected 13\n", cb);
378 ok(!memcmp(buf, "<html></html>", 13), "unexpected data\n");
379 ref = IInternetProtocol_Release(protocol);
380 ok(!ref, "protocol ref=%d\n", ref);
382 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
383 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
388 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
389 ok(hres == (test_protocol == ITS_PROTOCOL ? INET_E_DATA_NOT_AVAILABLE : E_FAIL),
390 "Read returned %08x\n", hres);
391 ok(cb == 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb);
393 protocol_start(protocol, url, expect_mime);
394 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
395 ok(hres == S_OK, "Read failed: %08x\n", hres);
396 ok(cb == 2, "cb=%u expected 2\n", cb);
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 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
401 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
402 ok(cb == 0, "cb=%u expected 0\n", cb);
403 hres = IInternetProtocol_UnlockRequest(protocol);
404 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
405 ref = IInternetProtocol_Release(protocol);
406 ok(!ref, "protocol ref=%d\n", ref);
408 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
409 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
413 protocol_start(protocol, url, expect_mime);
414 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
415 ok(hres == S_OK, "Read failed: %08x\n", hres);
416 hres = IInternetProtocol_LockRequest(protocol, 0);
417 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
418 hres = IInternetProtocol_UnlockRequest(protocol);
419 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
420 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
421 ok(hres == S_OK, "Read failed: %08x\n", hres);
422 ok(cb == 11, "cb=%u, expected 11\n", cb);
423 ref = IInternetProtocol_Release(protocol);
424 ok(!ref, "protocol ref=%d\n", ref);
426 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
427 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
431 protocol_start(protocol, url, expect_mime);
432 hres = IInternetProtocol_LockRequest(protocol, 0);
433 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
434 hres = IInternetProtocol_Terminate(protocol, 0);
435 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
436 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
437 ok(hres == S_OK, "Read failed: %08x\n", hres);
438 ok(cb == 2, "cb=%u, expected 2\n", cb);
439 hres = IInternetProtocol_UnlockRequest(protocol);
440 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
441 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
442 ok(hres == S_OK, "Read failed: %08x\n", hres);
443 ok(cb == 2, "cb=%u, expected 2\n", cb);
444 hres = IInternetProtocol_Terminate(protocol, 0);
445 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
446 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
447 ok(hres == S_OK, "Read failed: %08x\n", hres);
448 ok(cb == 2, "cb=%u expected 2\n", cb);
449 ref = IInternetProtocol_Release(protocol);
450 ok(!ref, "protocol ref=%d\n", ref);
452 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&read_protocol);
453 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
457 protocol_start(read_protocol, url, expect_mime);
458 ref = IInternetProtocol_Release(read_protocol);
459 ok(!ref, "protocol ref=%d\n", ref);
460 read_protocol = NULL;
463 static const struct {
464 const char *base_url;
468 const char *combined_url;
469 } combine_tests[] = {
470 {"its:test.chm::/blank.html", "its:test.chm::/blank.html", 0, STG_E_INVALIDNAME, NULL},
471 {"mS-iTs:test.chm::/blank.html", "mS-iTs:test.chm::/blank.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", "test.chm::/test.html", 0, STG_E_INVALIDNAME, NULL},
474 {"its:test.chm::/blank.html", "/test.html", 0, S_OK, "its:test.chm::/test.html"},
475 {"its:test.chm::/blank.html", "te:t.html", 0, STG_E_INVALIDNAME, NULL},
476 {"its:test.chm::/blank.html", "/test.html", URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, S_OK, "its:test.chm::/test.html"},
477 {"its:test.chm::/blank.html", "dir/test.html", 0, S_OK, "its:test.chm::/dir/test.html"},
478 {"test.html", "test.chm::/test.html", 0, 0x80041001, NULL},
479 {"its:test:.chm::/blank.html", "test.html", 0, S_OK, "its:test:.chm::/test.html"},
480 {"its:test.chm::/dir/blank.html", "test.html", 0, S_OK, "its:test.chm::/dir/test.html"},
481 {"its:test.chm::blank.html", "test.html", 0, S_OK, "its:test.chm::blank.htmltest.html"},
482 {"ms-its:test.chm::/dir/blank.html", "test.html", 0, S_OK, "ms-its:test.chm::/dir/test.html"},
483 {"mk:@MSITStore:test.chm::/dir/blank.html", "test.html", 0, S_OK, "mk:@MSITStore:test.chm::/dir/test.html"},
484 {"xxx:test.chm::/dir/blank.html", "test.html", 0, INET_E_USE_DEFAULT_PROTOCOLHANDLER, NULL},
485 {"its:test.chm::/dir/blank.html", "/test.html", 0, S_OK, "its:test.chm::/test.html"},
486 {"its:test.chm::/blank.html", "#frag", 0, S_OK, "its:test.chm::/blank.html#frag"},
487 {"its:test.chm::/blank.html#hash", "#frag", 0, S_OK, "its:test.chm::/blank.html#hash#frag"},
488 {"its:test.chm::/blank.html", "test.html#frag", 0, S_OK, "its:test.chm::/test.html#frag"},
489 {"its:test.chm::/blank.html", "/test.html#frag", 0, S_OK, "its:test.chm::/test.html#frag"},
490 {"its:test.chm::/blank.html", "?query", 0, S_OK, "its:test.chm::/?query"},
491 {"its:test.chm::/blank.html#frag/blank", "test.html", 0, S_OK, "its:test.chm::/blank.html#frag/test.html"},
494 static void test_its_protocol_info(IInternetProtocol *protocol)
496 IInternetProtocolInfo *info;
501 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolInfo, (void**)&info);
502 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08x\n", hres);
506 for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
507 if(i != PARSE_CANONICALIZE && i != PARSE_SECURITY_URL) {
508 hres = IInternetProtocolInfo_ParseUrl(info, blank_url1, i, 0, buf,
509 sizeof(buf)/sizeof(buf[0]), &size, 0);
510 ok(hres == INET_E_DEFAULT_ACTION,
511 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i, hres);
515 for(i=0; i < sizeof(combine_tests)/sizeof(combine_tests[0]); i++) {
517 memset(buf, 0xfe, sizeof(buf));
518 hres = IInternetProtocolInfo_CombineUrl(info, a2w(combine_tests[i].base_url),
519 a2w(combine_tests[i].rel_url), combine_tests[i].flags, buf,
520 sizeof(buf)/sizeof(WCHAR), &size, 0);
521 ok(hres == combine_tests[i].hres, "[%d] CombineUrl returned %08x, expected %08x\n",
522 i, hres, combine_tests[i].hres);
523 ok(size == (combine_tests[i].combined_url ? strlen(combine_tests[i].combined_url)+1
524 : 0xdeadbeef), "[%d] unexpected size=%d\n", i, size);
525 if(combine_tests[i].combined_url)
526 ok(!strcmp_wa(buf, combine_tests[i].combined_url), "[%d] unexpected result: %s\n", i, wine_dbgstr_w(buf));
528 ok(buf[0] == 0xfefe, "buf changed\n");
532 memset(buf, 0xfe, sizeof(buf));
533 hres = IInternetProtocolInfo_CombineUrl(info, a2w("its:test.chm::/blank.html"), a2w("test.html"), 0, buf,
535 ok(hres == E_OUTOFMEMORY, "CombineUrl failed: %08x\n", hres);
536 ok(size == 25, "size=%d\n", size);
537 ok(buf[0] == 0xfefe, "buf changed\n");
539 IInternetProtocolInfo_Release(info);
542 static void test_its_protocol(void)
544 IInternetProtocolInfo *info;
545 IClassFactory *factory;
550 static const WCHAR wrong_url1[] =
551 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','.','h','t','m','l',0};
552 static const WCHAR wrong_url2[] =
553 {'i','t','s',':','t','e','s','.','c','h','m',':',':','b','/','l','a','n','k','.','h','t','m','l',0};
554 static const WCHAR wrong_url3[] =
555 {'i','t','s',':','t','e','s','t','.','c','h','m','/','b','l','a','n','k','.','h','t','m','l',0};
556 static const WCHAR wrong_url4[] = {'m','k',':','@','M','S','I','T','S','t','o','r',':',
557 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
558 static const WCHAR wrong_url5[] = {'f','i','l','e',':',
559 't','e','s','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
561 test_protocol = ITS_PROTOCOL;
563 hres = CoGetClassObject(&CLSID_ITSProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
565 broken(hres == REGDB_E_CLASSNOTREG), /* Some W95 and NT4 */
566 "CoGetClassObject failed: %08x\n", hres);
570 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&info);
571 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo: %08x\n", hres);
573 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
574 ok(hres == S_OK, "Could not get IClassFactory interface\n");
575 if(SUCCEEDED(hres)) {
576 IInternetProtocol *protocol;
578 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
579 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
580 if(SUCCEEDED(hres)) {
581 test_its_protocol_info(protocol);
583 test_protocol_fail(protocol, wrong_url1, STG_E_FILENOTFOUND);
584 test_protocol_fail(protocol, wrong_url2, STG_E_FILENOTFOUND);
585 test_protocol_fail(protocol, wrong_url3, STG_E_FILENOTFOUND);
587 hres = IInternetProtocol_Start(protocol, wrong_url4, &protocol_sink, &bind_info, 0, 0);
588 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
589 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
591 hres = IInternetProtocol_Start(protocol, wrong_url5, &protocol_sink, &bind_info, 0, 0);
592 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
593 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
595 ref = IInternetProtocol_Release(protocol);
596 ok(!ref, "protocol ref=%d\n", ref);
598 test_protocol_url(factory, blank_url1, TRUE);
599 test_protocol_url(factory, blank_url2, TRUE);
600 test_protocol_url(factory, blank_url3, TRUE);
601 test_protocol_url(factory, blank_url4, TRUE);
602 test_protocol_url(factory, blank_url5, TRUE);
603 test_protocol_url(factory, blank_url6, TRUE);
604 test_protocol_url(factory, blank_url8, TRUE);
605 test_protocol_url(factory, blank_url9, TRUE);
606 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
607 test_protocol_url(factory, blank_url1, TRUE);
610 IClassFactory_Release(factory);
613 IUnknown_Release(unk);
616 static void test_mk_protocol(void)
621 test_protocol = MK_PROTOCOL;
623 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory,
626 broken(hres == REGDB_E_CLASSNOTREG), /* Some W95 and NT4 */
627 "CoGetClassObject failed: %08x\n", hres);
631 cache_file = cache_file1;
632 test_protocol_url(cf, blank_url3, TRUE);
633 cache_file = cache_file2;
634 test_protocol_url(cf, blank_url7, TRUE);
635 cache_file = cache_file3;
636 test_protocol_url(cf, blank_url8, FALSE);
638 IClassFactory_Release(cf);
641 static BOOL create_chm(void)
647 file = CreateFileA("test.chm", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
648 FILE_ATTRIBUTE_NORMAL, NULL);
649 ok(file != INVALID_HANDLE_VALUE, "Could not create test.chm file\n");
650 if(file == INVALID_HANDLE_VALUE)
653 src = FindResourceA(NULL, MAKEINTRESOURCEA(60), MAKEINTRESOURCEA(60));
655 WriteFile(file, LoadResource(NULL, src), SizeofResource(NULL, src), &size, NULL);
661 static void delete_chm(void)
665 ret = DeleteFileA("test.chm");
666 ok(ret, "DeleteFileA failed: %d\n", GetLastError());