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>
32 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
38 #define CHECK_EXPECT(func) \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 expect_ ## func = FALSE; \
42 called_ ## func = TRUE; \
45 #define CHECK_EXPECT2(func) \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
51 #define CHECK_CALLED(func) \
53 ok(called_ ## func, "expected " #func "\n"); \
54 expect_ ## func = called_ ## func = FALSE; \
57 DEFINE_GUID(CLSID_ITSProtocol,0x9d148291,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
59 DEFINE_EXPECT(GetBindInfo);
60 DEFINE_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
61 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
62 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
63 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAIABLE);
64 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
65 DEFINE_EXPECT(ReportData);
66 DEFINE_EXPECT(ReportResult);
68 static HRESULT expect_hrResult;
69 static IInternetProtocol *read_protocol = NULL;
71 static const WCHAR blank_url1[] = {'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_url2[] = {'m','S','-','i','T','s',':',
74 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
75 static const WCHAR blank_url3[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
76 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
77 static const WCHAR blank_url4[] = {'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_url5[] = {'i','t','s',':',
80 't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
81 static const WCHAR blank_url6[] = {'i','t','s',':',
82 't','e','s','t','.','c','h','m',':',':','/','%','6','2','l','a','n','k','.','h','t','m','l',0};
83 static const WCHAR blank_url7[] = {'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_url8[] = {'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};
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_CACHEFILENAMEAVAIABLE);
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);
247 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
248 ULONG cEl, ULONG *pcElFetched)
250 ok(0, "unexpected call\n");
254 static IInternetBindInfoVtbl bind_info_vtbl = {
255 BindInfo_QueryInterface,
258 BindInfo_GetBindInfo,
259 BindInfo_GetBindString
262 static IInternetBindInfo bind_info = {
266 static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres)
270 SET_EXPECT(GetBindInfo);
271 SET_EXPECT(ReportResult);
273 expect_hrResult = expected_hres;
274 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
275 ok(hres == expected_hres, "expected: %08x got: %08x\n", expected_hres, hres);
277 CHECK_CALLED(GetBindInfo);
278 CHECK_CALLED(ReportResult);
281 static void protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL expect_mime)
285 SET_EXPECT(GetBindInfo);
286 if(test_protocol == MK_PROTOCOL)
287 SET_EXPECT(ReportProgress_DIRECTBIND);
288 SET_EXPECT(ReportProgress_SENDINGREQUEST);
290 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
291 if(test_protocol == MK_PROTOCOL)
292 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAIABLE);
293 SET_EXPECT(ReportData);
294 if(test_protocol == ITS_PROTOCOL)
295 SET_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
296 SET_EXPECT(ReportResult);
297 expect_hrResult = S_OK;
299 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
300 ok(hres == S_OK, "Start failed: %08x\n", hres);
302 CHECK_CALLED(GetBindInfo);
303 if(test_protocol == MK_PROTOCOL)
304 CHECK_CALLED(ReportProgress_DIRECTBIND);
305 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
307 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
308 if(test_protocol == MK_PROTOCOL)
309 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAIABLE);
310 CHECK_CALLED(ReportData);
311 if(test_protocol == ITS_PROTOCOL)
312 CHECK_CALLED(ReportProgress_BEGINDOWNLOADDATA);
313 CHECK_CALLED(ReportResult);
316 static void test_protocol_url(IClassFactory *factory, LPCWSTR url, BOOL expect_mime)
318 IInternetProtocol *protocol;
323 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
324 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
328 protocol_start(protocol, url, expect_mime);
329 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
330 ok(hres == S_OK, "Read failed: %08x\n", hres);
331 ok(cb == 13, "cb=%u expected 13\n", cb);
332 ok(!memcmp(buf, "<html></html>", 13), "unexpected data\n");
333 ref = IInternetProtocol_Release(protocol);
334 ok(!ref, "protocol ref=%d\n", ref);
336 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
337 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
342 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
343 ok(hres == (test_protocol == ITS_PROTOCOL ? INET_E_DATA_NOT_AVAILABLE : E_FAIL),
344 "Read returned %08x\n", hres);
345 ok(cb == 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb);
347 protocol_start(protocol, url, expect_mime);
348 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
349 ok(hres == S_OK, "Read failed: %08x\n", hres);
350 ok(cb == 2, "cb=%u expected 2\n", cb);
351 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
352 ok(hres == S_OK, "Read failed: %08x\n", hres);
353 ok(cb == 11, "cb=%u, expected 11\n", cb);
354 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
355 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
356 ok(cb == 0, "cb=%u expected 0\n", cb);
357 hres = IInternetProtocol_UnlockRequest(protocol);
358 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
359 ref = IInternetProtocol_Release(protocol);
360 ok(!ref, "protocol ref=%d\n", ref);
362 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
363 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
367 protocol_start(protocol, url, expect_mime);
368 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
369 ok(hres == S_OK, "Read failed: %08x\n", hres);
370 hres = IInternetProtocol_LockRequest(protocol, 0);
371 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
372 hres = IInternetProtocol_UnlockRequest(protocol);
373 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
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 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);
385 protocol_start(protocol, url, expect_mime);
386 hres = IInternetProtocol_LockRequest(protocol, 0);
387 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
388 hres = IInternetProtocol_Terminate(protocol, 0);
389 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
390 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
391 ok(hres == S_OK, "Read failed: %08x\n", hres);
392 ok(cb == 2, "cb=%u, expected 2\n", cb);
393 hres = IInternetProtocol_UnlockRequest(protocol);
394 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
395 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
396 ok(hres == S_OK, "Read failed: %08x\n", hres);
397 ok(cb == 2, "cb=%u, expected 2\n", cb);
398 hres = IInternetProtocol_Terminate(protocol, 0);
399 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
400 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
401 ok(hres == S_OK, "Read failed: %08x\n", hres);
402 ok(cb == 2, "cb=%u expected 2\n", cb);
403 ref = IInternetProtocol_Release(protocol);
404 ok(!ref, "protocol ref=%d\n", ref);
406 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&read_protocol);
407 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
411 protocol_start(read_protocol, url, expect_mime);
412 ref = IInternetProtocol_Release(read_protocol);
413 ok(!ref, "protocol ref=%d\n", ref);
414 read_protocol = NULL;
417 static const WCHAR rel_url1[] =
418 {'t','e','s','t','.','h','t','m','l',0};
419 static const WCHAR rel_url2[] =
420 {'t','e','s','t','.','c','h','m',':',':','/','t','e','s','t','.','h','t','m','l',0};
421 static const WCHAR rel_url3[] =
422 {'/','t','e','s','t','.','h','t','m','l',0};
423 static const WCHAR rel_url4[] =
424 {'t','e',':','t','.','h','t','m','l',0};
425 static const WCHAR rel_url5[] =
426 {'d','i','r','/','t','e','s','t','.','h','t','m','l',0};
428 static const WCHAR base_url1[] = {'i','t','s',':',
429 't','e','s','t',':','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
430 static const WCHAR base_url2[] = {'i','t','s',':','t','e','s','t','.','c','h','m',
431 ':',':','/','d','i','r','/','b','l','a','n','k','.','h','t','m','l',0};
432 static const WCHAR base_url3[] = {'m','s','-','i','t','s',':','t','e','s','t','.','c','h','m',
433 ':',':','/','d','i','r','/','b','l','a','n','k','.','h','t','m','l',0};
434 static const WCHAR base_url4[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
435 't','e','s','t','.','c','h','m',':',':','/','d','i','r','/',
436 'b','l','a','n','k','.','h','t','m','l',0};
437 static const WCHAR base_url5[] = {'x','x','x',':','t','e','s','t','.','c','h','m',
438 ':',':','/','d','i','r','/','b','l','a','n','k','.','h','t','m','l',0};
440 static const WCHAR combined_url1[] = {'i','t','s',':',
441 't','e','s','t','.','c','h','m',':',':','/','t','e','s','t','.','h','t','m','l',0};
442 static const WCHAR combined_url2[] = {'i','t','s',':',
443 't','e','s','t','.','c','h','m',':',':','/','d','i','r','/','t','e','s','t','.','h','t','m','l',0};
444 static const WCHAR combined_url3[] = {'i','t','s',':',
445 't','e','s','t',':','.','c','h','m',':',':','/','t','e','s','t','.','h','t','m','l',0};
446 static const WCHAR combined_url4[] = {'i','t','s',':','t','e','s','t','.','c','h','m',
447 ':',':','b','l','a','n','k','.','h','t','m','l','t','e','s','t','.','h','t','m','l',0};
448 static const WCHAR combined_url5[] = {'m','s','-','i','t','s',':',
449 't','e','s','t','.','c','h','m',':',':','/','d','i','r','/','t','e','s','t','.','h','t','m','l',0};
450 static const WCHAR combined_url6[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
451 't','e','s','t','.','c','h','m',':',':','/','d','i','r','/','t','e','s','t','.','h','t','m','l',0};
453 static const struct {
458 LPCWSTR combined_url;
459 } combine_tests[] = {
460 {blank_url1, blank_url1, 0, STG_E_INVALIDNAME, NULL},
461 {blank_url2, blank_url2, 0, STG_E_INVALIDNAME, NULL},
462 {blank_url1, rel_url1, 0, S_OK, combined_url1},
463 {blank_url1, rel_url2, 0, STG_E_INVALIDNAME, NULL},
464 {blank_url1, rel_url3, 0, S_OK, combined_url1},
465 {blank_url1, rel_url4, 0, STG_E_INVALIDNAME, NULL},
466 {blank_url1, rel_url3, URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, S_OK, combined_url1},
467 {blank_url1, rel_url5, 0, S_OK, combined_url2},
468 {rel_url1, rel_url2, 0, 0x80041001, NULL},
469 {base_url1, rel_url1, 0, S_OK, combined_url3},
470 {base_url2, rel_url1, 0, S_OK, combined_url2},
471 {blank_url4, rel_url1, 0, S_OK, combined_url4},
472 {base_url3, rel_url1, 0, S_OK, combined_url5},
473 {base_url4, rel_url1, 0, S_OK, combined_url6},
474 {base_url5, rel_url1, 0, INET_E_USE_DEFAULT_PROTOCOLHANDLER, NULL},
475 {base_url2, rel_url3, 0, S_OK, combined_url1},
478 static void test_its_protocol_info(IInternetProtocol *protocol)
480 IInternetProtocolInfo *info;
485 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolInfo, (void**)&info);
486 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08x\n", hres);
490 for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
491 if(i != PARSE_CANONICALIZE && i != PARSE_SECURITY_URL) {
492 hres = IInternetProtocolInfo_ParseUrl(info, blank_url1, i, 0, buf,
493 sizeof(buf)/sizeof(buf[0]), &size, 0);
494 ok(hres == INET_E_DEFAULT_ACTION,
495 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i, hres);
499 for(i=0; i < sizeof(combine_tests)/sizeof(combine_tests[0]); i++) {
501 memset(buf, 0xfe, sizeof(buf));
502 hres = IInternetProtocolInfo_CombineUrl(info, combine_tests[i].base_url,
503 combine_tests[i].rel_url, combine_tests[i].flags, buf,
504 sizeof(buf)/sizeof(WCHAR), &size, 0);
505 ok(hres == combine_tests[i].hres, "[%d] CombineUrl returned %08x, expected %08x\n",
506 i, hres, combine_tests[i].hres);
507 ok(size == (combine_tests[i].combined_url ? lstrlenW(combine_tests[i].combined_url)+1
508 : 0xdeadbeef), "[%d] unexpected size=%d\n", i, size);
509 if(combine_tests[i].combined_url)
510 ok(!lstrcmpW(combine_tests[i].combined_url, buf), "[%d] unexpected result\n", i);
512 ok(buf[0] == 0xfefe, "buf changed\n");
516 memset(buf, 0xfe, sizeof(buf));
517 hres = IInternetProtocolInfo_CombineUrl(info, blank_url1, rel_url1, 0, buf,
519 ok(hres == E_OUTOFMEMORY, "CombineUrl failed: %08x\n", hres);
520 ok(size == sizeof(combined_url1)/sizeof(WCHAR), "size=%d\n", size);
521 ok(buf[0] == 0xfefe, "buf changed\n");
523 IInternetProtocolInfo_Release(info);
526 static void test_its_protocol(void)
528 IInternetProtocolInfo *info;
529 IClassFactory *factory;
534 static const WCHAR wrong_url1[] =
535 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','.','h','t','m','l',0};
536 static const WCHAR wrong_url2[] =
537 {'i','t','s',':','t','e','s','.','c','h','m',':',':','b','/','l','a','n','k','.','h','t','m','l',0};
538 static const WCHAR wrong_url3[] =
539 {'i','t','s',':','t','e','s','t','.','c','h','m','/','b','l','a','n','k','.','h','t','m','l',0};
540 static const WCHAR wrong_url4[] = {'m','k',':','@','M','S','I','T','S','t','o','r',':',
541 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
542 static const WCHAR wrong_url5[] = {'f','i','l','e',':',
543 't','e','s','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
545 test_protocol = ITS_PROTOCOL;
547 hres = CoGetClassObject(&CLSID_ITSProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
548 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
552 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&info);
553 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo: %08x\n", hres);
555 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
556 ok(hres == S_OK, "Could not get IClassFactory interface\n");
557 if(SUCCEEDED(hres)) {
558 IInternetProtocol *protocol;
560 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
561 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
562 if(SUCCEEDED(hres)) {
563 test_its_protocol_info(protocol);
565 test_protocol_fail(protocol, wrong_url1, STG_E_FILENOTFOUND);
566 test_protocol_fail(protocol, wrong_url2, STG_E_FILENOTFOUND);
567 test_protocol_fail(protocol, wrong_url3, STG_E_FILENOTFOUND);
569 hres = IInternetProtocol_Start(protocol, wrong_url4, &protocol_sink, &bind_info, 0, 0);
570 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
571 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
573 hres = IInternetProtocol_Start(protocol, wrong_url5, &protocol_sink, &bind_info, 0, 0);
574 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
575 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
577 ref = IInternetProtocol_Release(protocol);
578 ok(!ref, "protocol ref=%d\n", ref);
580 test_protocol_url(factory, blank_url1, TRUE);
581 test_protocol_url(factory, blank_url2, TRUE);
582 test_protocol_url(factory, blank_url3, TRUE);
583 test_protocol_url(factory, blank_url4, TRUE);
584 test_protocol_url(factory, blank_url5, TRUE);
585 test_protocol_url(factory, blank_url6, TRUE);
586 test_protocol_url(factory, blank_url8, TRUE);
589 IClassFactory_Release(factory);
592 IUnknown_Release(unk);
595 static void test_mk_protocol(void)
600 test_protocol = MK_PROTOCOL;
602 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory,
604 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
608 cache_file = cache_file1;
609 test_protocol_url(cf, blank_url3, TRUE);
610 cache_file = cache_file2;
611 test_protocol_url(cf, blank_url7, TRUE);
612 cache_file = cache_file3;
613 test_protocol_url(cf, blank_url8, FALSE);
615 IClassFactory_Release(cf);
618 static BOOL create_chm(void)
624 file = CreateFileA("test.chm", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
625 FILE_ATTRIBUTE_NORMAL, NULL);
626 ok(file != INVALID_HANDLE_VALUE, "Could not create test.chm file\n");
627 if(file == INVALID_HANDLE_VALUE)
630 src = FindResourceA(NULL, MAKEINTRESOURCEA(60), MAKEINTRESOURCEA(60));
632 WriteFile(file, LoadResource(NULL, src), SizeofResource(NULL, src), &size, NULL);
638 static void delete_chm(void)
642 ret = DeleteFileA("test.chm");
643 ok(ret, "DeleteFileA failed: %d\n", GetLastError());