winemenubuilder: silence an err
[wine/multimedia.git] / dlls / itss / tests / protocol.c
blob663411f2e92e23bdb7796d862d12d72e7390c063
1 /*
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
19 #define COBJMACROS
21 #include <wine/test.h>
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "initguid.h"
27 #include "ole2.h"
28 #include "urlmon.h"
29 #include "shlwapi.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) \
38 do { \
39 ok(expect_ ##func, "unexpected call " #func "\n"); \
40 expect_ ## func = FALSE; \
41 called_ ## func = TRUE; \
42 }while(0)
44 #define SET_CALLED(func) \
45 expect_ ## func = called_ ## func = FALSE
47 #define CHECK_CALLED(func) \
48 do { \
49 ok(called_ ## func, "expected " #func "\n"); \
50 SET_CALLED(func); \
51 }while(0)
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);
64 static HRESULT expect_hrResult;
65 static IInternetProtocol *read_protocol = NULL;
66 static DWORD bindf;
68 static const WCHAR blank_url1[] = {'i','t','s',':',
69 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
70 static const WCHAR blank_url2[] = {'m','S','-','i','T','s',':',
71 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
72 static const WCHAR blank_url3[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
73 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
74 static const WCHAR blank_url4[] = {'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_url5[] = {'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_url6[] = {'i','t','s',':',
79 't','e','s','t','.','c','h','m',':',':','/','%','6','2','l','a','n','k','.','h','t','m','l',0};
80 static const WCHAR blank_url7[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
81 't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
82 static const WCHAR blank_url8[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
83 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
84 static const WCHAR blank_url9[] = {'i','t','s',':',
85 't','e','s','t','.','c','h','m',':',':','/','d','i','r','/','.','.','/','b','l','a','n','k','.','h','t','m','l',0};
87 static enum {
88 ITS_PROTOCOL,
89 MK_PROTOCOL
90 } test_protocol;
92 static const WCHAR cache_file1[] =
93 {'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
94 static const WCHAR cache_file2[] =
95 {'t','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
96 static const WCHAR cache_file3[] =
97 {'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
98 static const WCHAR *cache_file = cache_file1;
100 static const WCHAR *a2w(const char *str)
102 static WCHAR bufs[8][128];
103 static int i;
105 if(!str)
106 return NULL;
108 i = (i+1) % 8;
109 MultiByteToWideChar(CP_ACP, 0, str, -1, bufs[i], 128);
110 return bufs[i];
113 static int strcmp_wa(const WCHAR *str1, const char *str2)
115 return lstrcmpW(str1, a2w(str2));
118 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
120 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
121 *ppv = iface;
122 return S_OK;
124 return E_NOINTERFACE;
127 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
129 return 2;
132 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
134 return 1;
137 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
139 ok(0, "unexpected call\n");
140 return E_NOTIMPL;
143 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
144 LPCWSTR szStatusText)
146 static const WCHAR blank_html[] = {'b','l','a','n','k','.','h','t','m','l',0};
147 static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
149 switch(ulStatusCode) {
150 case BINDSTATUS_BEGINDOWNLOADDATA:
151 CHECK_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
152 ok(!szStatusText, "szStatusText != NULL\n");
153 break;
154 case BINDSTATUS_SENDINGREQUEST:
155 CHECK_EXPECT(ReportProgress_SENDINGREQUEST);
156 if(test_protocol == ITS_PROTOCOL)
157 ok(!lstrcmpW(szStatusText, blank_html), "unexpected szStatusText\n");
158 else
159 ok(szStatusText == NULL, "szStatusText != NULL\n");
160 break;
161 case BINDSTATUS_MIMETYPEAVAILABLE:
162 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
163 ok(!lstrcmpW(szStatusText, text_html), "unexpected szStatusText\n");
164 break;
165 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
166 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
167 ok(!lstrcmpW(szStatusText, cache_file), "unexpected szStatusText\n");
168 break;
169 case BINDSTATUS_DIRECTBIND:
170 CHECK_EXPECT(ReportProgress_DIRECTBIND);
171 ok(!szStatusText, "szStatusText != NULL\n");
172 break;
173 default:
174 ok(0, "unexpected ulStatusCode %d\n", ulStatusCode);
175 break;
178 return S_OK;
181 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
182 ULONG ulProgressMax)
184 CHECK_EXPECT(ReportData);
186 ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
187 if(test_protocol == ITS_PROTOCOL)
188 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE), "grcf = %08x\n", grfBSCF);
189 else
190 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION), "grcf = %08x\n", grfBSCF);
192 if(read_protocol) {
193 BYTE buf[100];
194 DWORD cb = 0xdeadbeef;
195 HRESULT hres;
197 hres = IInternetProtocol_Read(read_protocol, buf, sizeof(buf), &cb);
198 ok(hres == S_OK, "Read failed: %08x\n", hres);
199 ok(cb == 13, "cb=%u expected 13\n", cb);
200 ok(!memcmp(buf, "<html></html>", 13), "unexpected data\n");
203 return S_OK;
206 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
207 DWORD dwError, LPCWSTR szResult)
209 CHECK_EXPECT(ReportResult);
211 ok(hrResult == expect_hrResult, "expected: %08x got: %08x\n", expect_hrResult, hrResult);
212 ok(dwError == 0, "dwError = %d\n", dwError);
213 ok(!szResult, "szResult != NULL\n");
215 return S_OK;
218 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
219 ProtocolSink_QueryInterface,
220 ProtocolSink_AddRef,
221 ProtocolSink_Release,
222 ProtocolSink_Switch,
223 ProtocolSink_ReportProgress,
224 ProtocolSink_ReportData,
225 ProtocolSink_ReportResult
228 static IInternetProtocolSink protocol_sink = {
229 &protocol_sink_vtbl
232 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
234 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
235 *ppv = iface;
236 return S_OK;
238 return E_NOINTERFACE;
241 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
243 return 2;
246 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
248 return 1;
251 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
253 CHECK_EXPECT(GetBindInfo);
255 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
256 if(grfBINDF)
257 ok(!*grfBINDF, "*grfBINDF != 0\n");
258 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
259 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
261 *grfBINDF = bindf;
262 return S_OK;
265 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
266 ULONG cEl, ULONG *pcElFetched)
268 ok(0, "unexpected call\n");
269 return E_NOTIMPL;
272 static IInternetBindInfoVtbl bind_info_vtbl = {
273 BindInfo_QueryInterface,
274 BindInfo_AddRef,
275 BindInfo_Release,
276 BindInfo_GetBindInfo,
277 BindInfo_GetBindString
280 static IInternetBindInfo bind_info = {
281 &bind_info_vtbl
284 static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres)
286 HRESULT hres;
288 SET_EXPECT(GetBindInfo);
289 SET_EXPECT(ReportResult);
291 expect_hrResult = expected_hres;
292 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
293 ok(hres == expected_hres, "expected: %08x got: %08x\n", expected_hres, hres);
295 CHECK_CALLED(GetBindInfo);
296 CHECK_CALLED(ReportResult);
299 #define protocol_start(p,u,e) _protocol_start(__LINE__,p,u,e)
300 static HRESULT _protocol_start(unsigned line, IInternetProtocol *protocol, LPCWSTR url, BOOL expect_mime)
302 HRESULT hres;
304 SET_EXPECT(GetBindInfo);
305 if(test_protocol == MK_PROTOCOL)
306 SET_EXPECT(ReportProgress_DIRECTBIND);
307 SET_EXPECT(ReportProgress_SENDINGREQUEST);
308 if(expect_mime)
309 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
310 if(test_protocol == MK_PROTOCOL)
311 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
312 SET_EXPECT(ReportData);
313 if(test_protocol == ITS_PROTOCOL)
314 SET_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
315 SET_EXPECT(ReportResult);
316 expect_hrResult = S_OK;
318 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
320 if(FAILED(hres)) {
321 SET_CALLED(GetBindInfo);
322 if(test_protocol == MK_PROTOCOL)
323 SET_CALLED(ReportProgress_DIRECTBIND);
324 SET_CALLED(ReportProgress_SENDINGREQUEST);
325 if(expect_mime)
326 SET_CALLED(ReportProgress_MIMETYPEAVAILABLE);
327 if(test_protocol == MK_PROTOCOL)
328 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
329 SET_CALLED(ReportData);
330 if(test_protocol == ITS_PROTOCOL)
331 SET_CALLED(ReportProgress_BEGINDOWNLOADDATA);
332 SET_CALLED(ReportResult);
333 }else {
334 CHECK_CALLED(GetBindInfo);
335 if(test_protocol == MK_PROTOCOL)
336 SET_CALLED(ReportProgress_DIRECTBIND);
337 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
338 if(expect_mime)
339 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
340 if(test_protocol == MK_PROTOCOL)
341 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
342 CHECK_CALLED(ReportData);
343 if(test_protocol == ITS_PROTOCOL)
344 CHECK_CALLED(ReportProgress_BEGINDOWNLOADDATA);
345 CHECK_CALLED(ReportResult);
348 return hres;
351 static void test_protocol_url(IClassFactory *factory, LPCWSTR url, BOOL expect_mime)
353 IInternetProtocol *protocol;
354 BYTE buf[512];
355 ULONG cb, ref;
356 HRESULT hres;
358 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
359 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
360 if(FAILED(hres))
361 return;
363 hres = protocol_start(protocol, url, expect_mime);
364 if(FAILED(hres)) {
365 IInternetProtocol_Release(protocol);
366 return;
369 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
370 ok(hres == S_OK, "Read failed: %08x\n", hres);
371 ok(cb == 13, "cb=%u expected 13\n", cb);
372 ok(!memcmp(buf, "<html></html>", 13), "unexpected data\n");
373 ref = IInternetProtocol_Release(protocol);
374 ok(!ref, "protocol ref=%d\n", ref);
376 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
377 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
378 if(FAILED(hres))
379 return;
381 cb = 0xdeadbeef;
382 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
383 ok(hres == (test_protocol == ITS_PROTOCOL ? INET_E_DATA_NOT_AVAILABLE : E_FAIL),
384 "Read returned %08x\n", hres);
385 ok(cb == 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb);
387 protocol_start(protocol, url, expect_mime);
388 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
389 ok(hres == S_OK, "Read failed: %08x\n", hres);
390 ok(cb == 2, "cb=%u expected 2\n", cb);
391 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
392 ok(hres == S_OK, "Read failed: %08x\n", hres);
393 ok(cb == 11, "cb=%u, expected 11\n", cb);
394 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
395 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
396 ok(cb == 0, "cb=%u expected 0\n", cb);
397 hres = IInternetProtocol_UnlockRequest(protocol);
398 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
399 ref = IInternetProtocol_Release(protocol);
400 ok(!ref, "protocol ref=%d\n", ref);
402 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
403 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
404 if(FAILED(hres))
405 return;
407 protocol_start(protocol, url, expect_mime);
408 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
409 ok(hres == S_OK, "Read failed: %08x\n", hres);
410 hres = IInternetProtocol_LockRequest(protocol, 0);
411 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
412 hres = IInternetProtocol_UnlockRequest(protocol);
413 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
414 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
415 ok(hres == S_OK, "Read failed: %08x\n", hres);
416 ok(cb == 11, "cb=%u, expected 11\n", cb);
417 ref = IInternetProtocol_Release(protocol);
418 ok(!ref, "protocol ref=%d\n", ref);
420 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
421 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
422 if(FAILED(hres))
423 return;
425 protocol_start(protocol, url, expect_mime);
426 hres = IInternetProtocol_LockRequest(protocol, 0);
427 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
428 hres = IInternetProtocol_Terminate(protocol, 0);
429 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
430 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
431 ok(hres == S_OK, "Read failed: %08x\n", hres);
432 ok(cb == 2, "cb=%u, expected 2\n", cb);
433 hres = IInternetProtocol_UnlockRequest(protocol);
434 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
435 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
436 ok(hres == S_OK, "Read failed: %08x\n", hres);
437 ok(cb == 2, "cb=%u, expected 2\n", cb);
438 hres = IInternetProtocol_Terminate(protocol, 0);
439 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
440 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
441 ok(hres == S_OK, "Read failed: %08x\n", hres);
442 ok(cb == 2, "cb=%u expected 2\n", cb);
443 ref = IInternetProtocol_Release(protocol);
444 ok(!ref, "protocol ref=%d\n", ref);
446 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&read_protocol);
447 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
448 if(FAILED(hres))
449 return;
451 protocol_start(read_protocol, url, expect_mime);
452 ref = IInternetProtocol_Release(read_protocol);
453 ok(!ref, "protocol ref=%d\n", ref);
454 read_protocol = NULL;
457 static const struct {
458 const char *base_url;
459 const char *rel_url;
460 DWORD flags;
461 HRESULT hres;
462 const char *combined_url;
463 } combine_tests[] = {
464 {"its:test.chm::/blank.html", "its:test.chm::/blank.html", 0, STG_E_INVALIDNAME, NULL},
465 {"mS-iTs:test.chm::/blank.html", "mS-iTs:test.chm::/blank.html", 0, STG_E_INVALIDNAME, NULL},
466 {"its:test.chm::/blank.html", "test.html", 0, S_OK, "its:test.chm::/test.html"},
467 {"its:test.chm::/blank.html", "test.chm::/test.html", 0, STG_E_INVALIDNAME, NULL},
468 {"its:test.chm::/blank.html", "/test.html", 0, S_OK, "its:test.chm::/test.html"},
469 {"its:test.chm::/blank.html", "te:t.html", 0, STG_E_INVALIDNAME, NULL},
470 {"its:test.chm::/blank.html", "/test.html", URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, S_OK, "its:test.chm::/test.html"},
471 {"its:test.chm::/blank.html", "dir/test.html", 0, S_OK, "its:test.chm::/dir/test.html"},
472 {"test.html", "test.chm::/test.html", 0, 0x80041001, NULL},
473 {"its:test:.chm::/blank.html", "test.html", 0, S_OK, "its:test:.chm::/test.html"},
474 {"its:test.chm::/dir/blank.html", "test.html", 0, S_OK, "its:test.chm::/dir/test.html"},
475 {"its:test.chm::blank.html", "test.html", 0, S_OK, "its:test.chm::blank.htmltest.html"},
476 {"ms-its:test.chm::/dir/blank.html", "test.html", 0, S_OK, "ms-its:test.chm::/dir/test.html"},
477 {"mk:@MSITStore:test.chm::/dir/blank.html", "test.html", 0, S_OK, "mk:@MSITStore:test.chm::/dir/test.html"},
478 {"xxx:test.chm::/dir/blank.html", "test.html", 0, INET_E_USE_DEFAULT_PROTOCOLHANDLER, NULL},
479 {"its:test.chm::/dir/blank.html", "/test.html", 0, S_OK, "its:test.chm::/test.html"},
480 {"its:test.chm::/blank.html", "#frag", 0, S_OK, "its:test.chm::/blank.html#frag"},
481 {"its:test.chm::/blank.html#hash", "#frag", 0, S_OK, "its:test.chm::/blank.html#hash#frag"},
482 {"its:test.chm::/blank.html", "test.html#frag", 0, S_OK, "its:test.chm::/test.html#frag"},
483 {"its:test.chm::/blank.html", "/test.html#frag", 0, S_OK, "its:test.chm::/test.html#frag"},
484 {"its:test.chm::/blank.html", "?query", 0, S_OK, "its:test.chm::/?query"},
485 {"its:test.chm::/blank.html#frag/blank", "test.html", 0, S_OK, "its:test.chm::/blank.html#frag/test.html"},
488 static void test_its_protocol_info(IInternetProtocol *protocol)
490 IInternetProtocolInfo *info;
491 WCHAR buf[1024];
492 DWORD size, i;
493 HRESULT hres;
495 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolInfo, (void**)&info);
496 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08x\n", hres);
497 if(FAILED(hres))
498 return;
500 for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
501 if(i != PARSE_CANONICALIZE && i != PARSE_SECURITY_URL) {
502 hres = IInternetProtocolInfo_ParseUrl(info, blank_url1, i, 0, buf,
503 sizeof(buf)/sizeof(buf[0]), &size, 0);
504 ok(hres == INET_E_DEFAULT_ACTION,
505 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i, hres);
509 for(i=0; i < sizeof(combine_tests)/sizeof(combine_tests[0]); i++) {
510 size = 0xdeadbeef;
511 memset(buf, 0xfe, sizeof(buf));
512 hres = IInternetProtocolInfo_CombineUrl(info, a2w(combine_tests[i].base_url),
513 a2w(combine_tests[i].rel_url), combine_tests[i].flags, buf,
514 sizeof(buf)/sizeof(WCHAR), &size, 0);
515 ok(hres == combine_tests[i].hres, "[%d] CombineUrl returned %08x, expected %08x\n",
516 i, hres, combine_tests[i].hres);
517 ok(size == (combine_tests[i].combined_url ? strlen(combine_tests[i].combined_url)+1
518 : 0xdeadbeef), "[%d] unexpected size=%d\n", i, size);
519 if(combine_tests[i].combined_url)
520 ok(!strcmp_wa(buf, combine_tests[i].combined_url), "[%d] unexpected result: %s\n", i, wine_dbgstr_w(buf));
521 else
522 ok(buf[0] == 0xfefe, "buf changed\n");
525 size = 0xdeadbeef;
526 memset(buf, 0xfe, sizeof(buf));
527 hres = IInternetProtocolInfo_CombineUrl(info, a2w("its:test.chm::/blank.html"), a2w("test.html"), 0, buf,
528 1, &size, 0);
529 ok(hres == E_OUTOFMEMORY, "CombineUrl failed: %08x\n", hres);
530 ok(size == 25, "size=%d\n", size);
531 ok(buf[0] == 0xfefe, "buf changed\n");
533 IInternetProtocolInfo_Release(info);
536 static void test_its_protocol(void)
538 IInternetProtocolInfo *info;
539 IClassFactory *factory;
540 IUnknown *unk;
541 ULONG ref;
542 HRESULT hres;
544 static const WCHAR wrong_url1[] =
545 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','.','h','t','m','l',0};
546 static const WCHAR wrong_url2[] =
547 {'i','t','s',':','t','e','s','.','c','h','m',':',':','b','/','l','a','n','k','.','h','t','m','l',0};
548 static const WCHAR wrong_url3[] =
549 {'i','t','s',':','t','e','s','t','.','c','h','m','/','b','l','a','n','k','.','h','t','m','l',0};
550 static const WCHAR wrong_url4[] = {'m','k',':','@','M','S','I','T','S','t','o','r',':',
551 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
552 static const WCHAR wrong_url5[] = {'f','i','l','e',':',
553 't','e','s','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
555 test_protocol = ITS_PROTOCOL;
557 hres = CoGetClassObject(&CLSID_ITSProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
558 ok(hres == S_OK ||
559 broken(hres == REGDB_E_CLASSNOTREG), /* Some W95 and NT4 */
560 "CoGetClassObject failed: %08x\n", hres);
561 if(FAILED(hres))
562 return;
564 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&info);
565 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo: %08x\n", hres);
567 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
568 ok(hres == S_OK, "Could not get IClassFactory interface\n");
569 if(SUCCEEDED(hres)) {
570 IInternetProtocol *protocol;
572 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
573 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
574 if(SUCCEEDED(hres)) {
575 test_its_protocol_info(protocol);
577 test_protocol_fail(protocol, wrong_url1, STG_E_FILENOTFOUND);
578 test_protocol_fail(protocol, wrong_url2, STG_E_FILENOTFOUND);
579 test_protocol_fail(protocol, wrong_url3, STG_E_FILENOTFOUND);
581 hres = IInternetProtocol_Start(protocol, wrong_url4, &protocol_sink, &bind_info, 0, 0);
582 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
583 "Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
585 hres = IInternetProtocol_Start(protocol, wrong_url5, &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 ref = IInternetProtocol_Release(protocol);
590 ok(!ref, "protocol ref=%d\n", ref);
592 test_protocol_url(factory, blank_url1, TRUE);
593 test_protocol_url(factory, blank_url2, TRUE);
594 test_protocol_url(factory, blank_url3, TRUE);
595 test_protocol_url(factory, blank_url4, TRUE);
596 test_protocol_url(factory, blank_url5, TRUE);
597 test_protocol_url(factory, blank_url6, TRUE);
598 test_protocol_url(factory, blank_url8, TRUE);
599 test_protocol_url(factory, blank_url9, TRUE);
600 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
601 test_protocol_url(factory, blank_url1, TRUE);
604 IClassFactory_Release(factory);
607 IUnknown_Release(unk);
610 static void test_mk_protocol(void)
612 IClassFactory *cf;
613 HRESULT hres;
615 test_protocol = MK_PROTOCOL;
617 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory,
618 (void**)&cf);
619 ok(hres == S_OK ||
620 broken(hres == REGDB_E_CLASSNOTREG), /* Some W95 and NT4 */
621 "CoGetClassObject failed: %08x\n", hres);
622 if(FAILED(hres))
623 return;
625 cache_file = cache_file1;
626 test_protocol_url(cf, blank_url3, TRUE);
627 cache_file = cache_file2;
628 test_protocol_url(cf, blank_url7, TRUE);
629 cache_file = cache_file3;
630 test_protocol_url(cf, blank_url8, FALSE);
632 IClassFactory_Release(cf);
635 static BOOL create_chm(void)
637 HANDLE file;
638 HRSRC src;
639 DWORD size;
641 file = CreateFileA("test.chm", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
642 FILE_ATTRIBUTE_NORMAL, NULL);
643 ok(file != INVALID_HANDLE_VALUE, "Could not create test.chm file\n");
644 if(file == INVALID_HANDLE_VALUE)
645 return FALSE;
647 src = FindResourceA(NULL, MAKEINTRESOURCEA(60), MAKEINTRESOURCEA(60));
649 WriteFile(file, LoadResource(NULL, src), SizeofResource(NULL, src), &size, NULL);
650 CloseHandle(file);
652 return TRUE;
655 static void delete_chm(void)
657 BOOL ret;
659 ret = DeleteFileA("test.chm");
660 ok(ret, "DeleteFileA failed: %d\n", GetLastError());
663 START_TEST(protocol)
665 OleInitialize(NULL);
667 if(!create_chm())
668 return;
670 test_its_protocol();
671 test_mk_protocol();
673 delete_chm();
674 OleUninitialize();