push 73336d9f381967eae40f391d78198b916ed9848d
[wine/hacks.git] / dlls / mshtml / tests / protocol.c
blobdf3c33715101c26514aa1305a41a2d68e009feef
1 /*
2 * Copyright 2005 Jacek Caban
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 "ole2.h"
27 #include "urlmon.h"
28 #include "shlwapi.h"
30 #include "initguid.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) \
39 do { \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 expect_ ## func = FALSE; \
42 called_ ## func = TRUE; \
43 }while(0)
45 #define CHECK_EXPECT2(func) \
46 do { \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
49 }while(0)
51 #define CHECK_CALLED(func) \
52 do { \
53 ok(called_ ## func, "expected " #func "\n"); \
54 expect_ ## func = called_ ## func = FALSE; \
55 }while(0)
57 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
58 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
60 DEFINE_EXPECT(GetBindInfo);
61 DEFINE_EXPECT(ReportProgress);
62 DEFINE_EXPECT(ReportData);
63 DEFINE_EXPECT(ReportResult);
65 static HRESULT expect_hrResult;
66 static BOOL expect_hr_win32err = FALSE;
67 static DWORD bindf;
69 static const WCHAR about_blank_url[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
70 static const WCHAR about_test_url[] = {'a','b','o','u','t',':','t','e','s','t',0};
71 static const WCHAR about_res_url[] = {'r','e','s',':','b','l','a','n','k',0};
73 static const char *debugstr_w(LPCWSTR str)
75 static char buf[1024];
76 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
77 return buf;
80 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
82 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
83 *ppv = iface;
84 return S_OK;
86 return E_NOINTERFACE;
89 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
91 return 2;
94 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
96 return 1;
99 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
101 ok(0, "unexpected call\n");
102 return E_NOTIMPL;
105 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
106 LPCWSTR szStatusText)
108 static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
110 CHECK_EXPECT(ReportProgress);
112 ok(ulStatusCode == BINDSTATUS_MIMETYPEAVAILABLE
113 || ulStatusCode == BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
114 "ulStatusCode=%d\n", ulStatusCode);
115 ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
117 return S_OK;
120 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
121 ULONG ulProgressMax)
123 CHECK_EXPECT(ReportData);
125 ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
126 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE),
127 "grcf = %08x\n", grfBSCF);
129 return S_OK;
132 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult, DWORD dwError,
133 LPCWSTR szResult)
135 CHECK_EXPECT(ReportResult);
137 if(expect_hr_win32err)
138 ok((hrResult&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000) || expect_hrResult,
139 "expected win32 err or %08x got: %08x\n", expect_hrResult, hrResult);
140 else
141 ok(hrResult == expect_hrResult || ((expect_hrResult == E_INVALIDARG ||
142 expect_hrResult == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND)) &&
143 hrResult == MK_E_SYNTAX), "expected: %08x got: %08x\n", expect_hrResult, hrResult);
144 ok(dwError == 0, "dwError = %d\n", dwError);
145 ok(!szResult, "szResult != NULL\n");
147 return S_OK;
150 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
151 ProtocolSink_QueryInterface,
152 ProtocolSink_AddRef,
153 ProtocolSink_Release,
154 ProtocolSink_Switch,
155 ProtocolSink_ReportProgress,
156 ProtocolSink_ReportData,
157 ProtocolSink_ReportResult
160 static IInternetProtocolSink protocol_sink = {
161 &protocol_sink_vtbl
164 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
166 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
167 *ppv = iface;
168 return S_OK;
170 return E_NOINTERFACE;
173 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
175 return 2;
178 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
180 return 1;
183 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
185 CHECK_EXPECT(GetBindInfo);
187 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
188 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
189 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
191 *grfBINDF = bindf;
192 return S_OK;
195 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
196 ULONG cEl, ULONG *pcElFetched)
198 ok(0, "unexpected call\n");
199 return E_NOTIMPL;
202 static IInternetBindInfoVtbl bind_info_vtbl = {
203 BindInfo_QueryInterface,
204 BindInfo_AddRef,
205 BindInfo_Release,
206 BindInfo_GetBindInfo,
207 BindInfo_GetBindString
210 static IInternetBindInfo bind_info = {
211 &bind_info_vtbl
214 static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres,
215 BOOL expect_win32err)
217 HRESULT hres;
219 SET_EXPECT(GetBindInfo);
220 SET_EXPECT(ReportResult);
222 expect_hrResult = expected_hres;
223 expect_hr_win32err = expect_win32err;
224 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
225 if(expect_win32err)
226 ok((hres&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000) || hres == expect_hrResult,
227 "expected win32 err or %08x got: %08x\n", expected_hres, hres);
228 else
229 ok(hres == expected_hres || ((expected_hres == E_INVALIDARG ||
230 expected_hres == HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND)) && hres == MK_E_SYNTAX),
231 "expected: %08x got: %08x\n", expected_hres, hres);
233 CHECK_CALLED(GetBindInfo);
234 CHECK_CALLED(ReportResult);
237 static void protocol_start(IInternetProtocol *protocol, LPCWSTR url)
239 HRESULT hres;
241 SET_EXPECT(GetBindInfo);
242 SET_EXPECT(ReportResult);
243 SET_EXPECT(ReportProgress);
244 SET_EXPECT(ReportData);
245 expect_hrResult = S_OK;
246 expect_hr_win32err = FALSE;
248 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
249 ok(hres == S_OK, "Start failed: %08x\n", hres);
251 CHECK_CALLED(GetBindInfo);
252 CHECK_CALLED(ReportProgress);
253 CHECK_CALLED(ReportData);
254 CHECK_CALLED(ReportResult);
257 static void res_sec_url_cmp(LPCWSTR url, DWORD size, LPCWSTR file)
259 WCHAR buf[MAX_PATH];
260 DWORD len;
262 static const WCHAR fileW[] = {'f','i','l','e',':','/','/'};
264 if(size < sizeof(fileW)/sizeof(WCHAR) || memcmp(url, fileW, sizeof(fileW))) {
265 ok(0, "wrong URL protocol\n");
266 return;
269 len = SearchPathW(NULL, file, NULL, sizeof(buf)/sizeof(WCHAR), buf, NULL);
270 if(!len) {
271 ok(0, "SearchPath failed: %u\n", GetLastError());
272 return;
275 len += sizeof(fileW)/sizeof(WCHAR)+1;
276 ok(len == size, "wrong size %u, expected %u\n", size, len);
277 ok(!lstrcmpW(url + sizeof(fileW)/sizeof(WCHAR), buf), "wrong file part %s\n", debugstr_w(url));
280 static void test_res_protocol(void)
282 IInternetProtocolInfo *protocol_info;
283 IUnknown *unk;
284 IClassFactory *factory;
285 HRESULT hres;
287 static const WCHAR blank_url[] =
288 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
289 static const WCHAR test_part_url[] = {'r','e','s',':','/','/','C','S','S','/','t','e','s','t',0};
290 static const WCHAR wrong_url1[] =
291 {'m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','m','t','h',0};
292 static const WCHAR wrong_url2[] =
293 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',0};
294 static const WCHAR wrong_url3[] =
295 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','x','x','.','h','t','m',0};
296 static const WCHAR wrong_url4[] =
297 {'r','e','s',':','/','/','x','x','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
298 static const WCHAR wrong_url5[] =
299 {'r','e','s',':','/','/','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
300 static const WCHAR mshtml_dllW[] = {'m','s','h','t','m','l','.','d','l','l',0};
302 hres = CoGetClassObject(&CLSID_ResProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
303 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
304 if(!SUCCEEDED(hres))
305 return;
307 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
308 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08x\n", hres);
309 if(SUCCEEDED(hres)) {
310 WCHAR buf[128];
311 DWORD size;
312 int i;
314 for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
315 if(i != PARSE_SECURITY_URL && i != PARSE_DOMAIN) {
316 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, i, 0, buf,
317 sizeof(buf)/sizeof(buf[0]), &size, 0);
318 ok(hres == INET_E_DEFAULT_ACTION,
319 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i, hres);
323 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_SECURITY_URL, 0, buf,
324 sizeof(buf)/sizeof(buf[0]), &size, 0);
325 ok(hres == S_OK, "ParseUrl failed: %08x\n", hres);
326 res_sec_url_cmp(buf, size, mshtml_dllW);
328 size = 0;
329 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_SECURITY_URL, 0, buf,
330 3, &size, 0);
331 ok(hres == S_FALSE, "ParseUrl failed: %08x, expected S_FALSE\n", hres);
332 ok(size, "size=0\n");
334 hres = IInternetProtocolInfo_ParseUrl(protocol_info, wrong_url1, PARSE_SECURITY_URL, 0, buf,
335 sizeof(buf)/sizeof(buf[0]), &size, 0);
336 ok(hres == MK_E_SYNTAX || hres == E_INVALIDARG,
337 "ParseUrl failed: %08x, expected MK_E_SYNTAX\n", hres);
339 hres = IInternetProtocolInfo_ParseUrl(protocol_info, wrong_url5, PARSE_SECURITY_URL, 0, buf,
340 sizeof(buf)/sizeof(buf[0]), &size, 0);
341 ok(hres == MK_E_SYNTAX, "ParseUrl failed: %08x, expected MK_E_SYNTAX\n", hres);
343 size = 0xdeadbeef;
344 buf[0] = '?';
345 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_DOMAIN, 0, buf,
346 sizeof(buf)/sizeof(buf[0]), &size, 0);
347 ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
348 ok(buf[0] == '?', "buf changed\n");
349 ok(size == sizeof(blank_url)/sizeof(WCHAR), "size=%d\n", size);
351 size = 0xdeadbeef;
352 hres = IInternetProtocolInfo_ParseUrl(protocol_info, wrong_url1, PARSE_DOMAIN, 0, buf,
353 sizeof(buf)/sizeof(buf[0]), &size, 0);
354 ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
355 ok(buf[0] == '?', "buf changed\n");
356 ok(size == sizeof(wrong_url1)/sizeof(WCHAR), "size=%d\n", size);
358 if (0)
360 /* Crashes on win9x */
361 size = 0xdeadbeef;
362 buf[0] = '?';
363 hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
364 sizeof(buf)/sizeof(buf[0]), &size, 0);
365 ok(hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
366 ok(buf[0] == '?', "buf changed\n");
367 ok(size == 1, "size=%u, ezpected 1\n", size);
369 buf[0] = '?';
370 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_DOMAIN, 0, buf,
371 sizeof(buf)/sizeof(buf[0]), NULL, 0);
372 ok(hres == E_POINTER, "ParseUrl failed: %08x\n", hres);
373 ok(buf[0] == '?', "buf changed\n");
375 buf[0] = '?';
376 hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
377 sizeof(buf)/sizeof(buf[0]), NULL, 0);
378 ok(hres == E_POINTER, "ParseUrl failed: %08x\n", hres);
379 ok(buf[0] == '?', "buf changed\n");
382 buf[0] = '?';
383 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_UNESCAPE+1, 0, buf,
384 sizeof(buf)/sizeof(buf[0]), &size, 0);
385 ok(hres == INET_E_DEFAULT_ACTION,
386 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres);
387 ok(buf[0] == '?', "buf changed\n");
389 size = 0xdeadbeef;
390 hres = IInternetProtocolInfo_CombineUrl(protocol_info, blank_url, test_part_url,
391 0, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
392 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
393 ok(size == 0xdeadbeef, "size=%d\n", size);
395 size = 0xdeadbeef;
396 hres = IInternetProtocolInfo_CombineUrl(protocol_info, blank_url, test_part_url,
397 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
398 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
399 ok(size == 0xdeadbeef, "size=%d\n", size);
401 size = 0xdeadbeef;
402 hres = IInternetProtocolInfo_CombineUrl(protocol_info, NULL, NULL,
403 URL_FILE_USE_PATHURL, NULL, 0xdeadbeef, NULL, 0);
404 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
405 ok(size == 0xdeadbeef, "size=%d\n", size);
407 hres = IInternetProtocolInfo_CompareUrl(protocol_info, blank_url, blank_url, 0);
408 ok(hres == E_NOTIMPL, "CompareUrl failed: %08x\n", hres);
410 hres = IInternetProtocolInfo_CompareUrl(protocol_info, NULL, NULL, 0xdeadbeef);
411 ok(hres == E_NOTIMPL, "CompareUrl failed: %08x\n", hres);
413 for(i=0; i<30; i++) {
414 if(i == QUERY_USES_NETWORK || i == QUERY_IS_SECURE || i == QUERY_IS_SAFE)
415 continue;
417 hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, i, 0,
418 buf, sizeof(buf), &size, 0);
419 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
420 "QueryInfo(%d) returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", i, hres);
423 size = 0xdeadbeef;
424 memset(buf, '?', sizeof(buf));
425 hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, QUERY_USES_NETWORK, 0,
426 buf, sizeof(buf), &size, 0);
427 ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
428 ok(size == sizeof(DWORD), "size=%d\n", size);
429 ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
431 memset(buf, '?', sizeof(buf));
432 hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, QUERY_USES_NETWORK, 0,
433 buf, sizeof(buf), NULL, 0);
434 ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
435 ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
437 hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, QUERY_USES_NETWORK, 0,
438 buf, 3, &size, 0);
439 ok(hres == E_FAIL, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
441 size = 0xdeadbeef;
442 memset(buf, '?', sizeof(buf));
443 hres = IInternetProtocolInfo_QueryInfo(protocol_info, NULL, QUERY_USES_NETWORK, 0,
444 buf, sizeof(buf), &size, 0);
445 ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
446 ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
447 ok(size == sizeof(DWORD), "size=%d\n", size);
448 ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
450 hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, QUERY_USES_NETWORK, 0,
451 NULL, sizeof(buf), &size, 0);
452 ok(hres == E_FAIL, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
454 hres = IInternetProtocolInfo_QueryInfo(protocol_info, blank_url, 60, 0,
455 NULL, sizeof(buf), &size, 0);
456 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
457 "QueryInfo failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
459 IInternetProtocolInfo_Release(protocol_info);
462 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
463 ok(hres == S_OK, "Could not get IClassFactory interface\n");
464 if(SUCCEEDED(hres)) {
465 IInternetProtocol *protocol;
466 BYTE buf[512];
467 ULONG cb;
468 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
469 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
471 if(SUCCEEDED(hres)) {
472 IInternetPriority *priority;
474 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
475 ok(hres == E_NOINTERFACE,
476 "QueryInterface(IInternetPriority) returned %08x, expected E_NOINTEFACE\n", hres);
478 test_protocol_fail(protocol, wrong_url1, E_INVALIDARG, FALSE);
479 test_protocol_fail(protocol, wrong_url2,
480 HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND), FALSE);
481 test_protocol_fail(protocol, wrong_url3, E_FAIL, TRUE);
482 test_protocol_fail(protocol, wrong_url4, E_FAIL, TRUE);
484 cb = 0xdeadbeef;
485 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
486 ok(hres == E_FAIL, "Read returned %08x expected E_FAIL\n", hres);
487 ok(cb == 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb);
489 protocol_start(protocol, blank_url);
490 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
491 ok(hres == S_OK, "Read failed: %08x\n", hres);
492 ok(cb == 2, "cb=%u expected 2\n", cb);
493 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
494 ok(hres == S_OK, "Read failed: %08x\n", hres);
495 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
496 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
497 ok(cb == 0, "cb=%u expected 0\n", cb);
498 hres = IInternetProtocol_UnlockRequest(protocol);
499 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
501 protocol_start(protocol, blank_url);
502 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
503 ok(hres == S_OK, "Read failed: %08x\n", hres);
504 hres = IInternetProtocol_LockRequest(protocol, 0);
505 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
506 hres = IInternetProtocol_UnlockRequest(protocol);
507 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
508 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
509 ok(hres == S_OK, "Read failed: %08x\n", hres);
511 protocol_start(protocol, blank_url);
512 hres = IInternetProtocol_LockRequest(protocol, 0);
513 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
514 hres = IInternetProtocol_Terminate(protocol, 0);
515 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
516 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
517 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
518 hres = IInternetProtocol_UnlockRequest(protocol);
519 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
520 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
521 ok(hres == S_OK, "Read failed: %08x\n", hres);
522 hres = IInternetProtocol_Terminate(protocol, 0);
523 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
524 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
525 ok(hres == S_OK, "Read failed: %08x\n", hres);
526 ok(cb == 2, "cb=%u expected 2\n", cb);
528 protocol_start(protocol, blank_url);
529 hres = IInternetProtocol_LockRequest(protocol, 0);
530 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
531 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
532 ok(hres == S_OK, "Read failed: %08x\n", hres);
533 protocol_start(protocol, blank_url);
534 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
535 ok(hres == S_OK, "Read failed: %08x\n", hres);
536 hres = IInternetProtocol_Terminate(protocol, 0);
537 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
539 IInternetProtocol_Release(protocol);
542 IClassFactory_Release(factory);
545 IUnknown_Release(unk);
548 static void do_test_about_protocol(IClassFactory *factory, DWORD bf)
550 IInternetProtocol *protocol;
551 IInternetPriority *priority;
552 BYTE buf[512];
553 ULONG cb;
554 HRESULT hres;
556 static const WCHAR blank_html[] = {0xfeff,'<','H','T','M','L','>','<','/','H','T','M','L','>',0};
557 static const WCHAR test_html[] =
558 {0xfeff,'<','H','T','M','L','>','t','e','s','t','<','/','H','T','M','L','>',0};
560 bindf = bf;
562 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
563 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
564 if(FAILED(hres))
565 return;
567 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
568 ok(hres == E_NOINTERFACE,
569 "QueryInterface(IInternetPriority) returned %08x, expected E_NOINTEFACE\n", hres);
571 protocol_start(protocol, about_blank_url);
572 hres = IInternetProtocol_LockRequest(protocol, 0);
573 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
574 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
575 ok(hres == S_OK, "Read failed: %08x\n", hres);
576 ok(cb == sizeof(blank_html), "cb=%d\n", cb);
577 ok(!memcmp(buf, blank_html, cb), "Readed wrong data\n");
578 hres = IInternetProtocol_UnlockRequest(protocol);
579 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
581 protocol_start(protocol, about_test_url);
582 hres = IInternetProtocol_LockRequest(protocol, 0);
583 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
584 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
585 ok(hres == S_OK, "Read failed: %08x\n", hres);
586 ok(cb == sizeof(test_html), "cb=%d\n", cb);
587 ok(!memcmp(buf, test_html, cb), "Readed wrong data\n");
588 hres = IInternetProtocol_UnlockRequest(protocol);
589 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
591 protocol_start(protocol, about_res_url);
592 hres = IInternetProtocol_LockRequest(protocol, 0);
593 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
594 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
595 ok(hres == S_OK, "Read failed: %08x\n", hres);
596 ok(cb == sizeof(blank_html), "cb=%d\n", cb);
597 ok(!memcmp(buf, blank_html, cb), "Readed wrong data\n");
598 hres = IInternetProtocol_UnlockRequest(protocol);
599 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
601 IInternetProtocol_Release(protocol);
604 static void test_about_protocol(void)
606 IInternetProtocolInfo *protocol_info;
607 IUnknown *unk;
608 IClassFactory *factory;
609 HRESULT hres;
611 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
612 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
613 if(!SUCCEEDED(hres))
614 return;
616 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
617 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08x\n", hres);
618 if(SUCCEEDED(hres)) {
619 WCHAR buf[128];
620 DWORD size;
621 int i;
623 for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
624 if(i != PARSE_SECURITY_URL && i != PARSE_DOMAIN) {
625 hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, i, 0, buf,
626 sizeof(buf)/sizeof(buf[0]), &size, 0);
627 ok(hres == INET_E_DEFAULT_ACTION,
628 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i, hres);
632 hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_SECURITY_URL, 0, buf,
633 sizeof(buf)/sizeof(buf[0]), &size, 0);
634 ok(hres == S_OK, "ParseUrl failed: %08x\n", hres);
635 ok(!lstrcmpW(about_blank_url, buf), "buf != blank_url\n");
637 hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_SECURITY_URL, 0, buf,
638 3, &size, 0);
639 ok(hres == S_FALSE, "ParseUrl failed: %08x, expected S_FALSE\n", hres);
641 hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_test_url, PARSE_SECURITY_URL, 0, buf,
642 sizeof(buf)/sizeof(buf[0]), &size, 0);
643 ok(hres == S_OK, "ParseUrl failed: %08x\n", hres);
644 ok(!lstrcmpW(about_test_url, buf), "buf != test_url\n");
646 size = 0xdeadbeef;
647 buf[0] = '?';
648 hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_DOMAIN, 0, buf,
649 sizeof(buf)/sizeof(buf[0]), &size, 0);
650 ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
651 ok(buf[0] == '?', "buf changed\n");
652 ok(size == sizeof(about_blank_url)/sizeof(WCHAR), "size=%d\n", size);
654 if (0)
656 /* Crashes on win9x */
657 size = 0xdeadbeef;
658 buf[0] = '?';
659 hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
660 sizeof(buf)/sizeof(buf[0]), &size, 0);
661 ok(hres == E_FAIL, "ParseUrl failed: %08x\n", hres);
662 ok(buf[0] == '?', "buf changed\n");
663 ok(size == 1, "size=%u, ezpected 1\n", size);
665 buf[0] = '?';
666 hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_DOMAIN, 0, buf,
667 sizeof(buf)/sizeof(buf[0]), NULL, 0);
668 ok(hres == E_POINTER, "ParseUrl failed: %08x\n", hres);
669 ok(buf[0] == '?', "buf changed\n");
671 buf[0] = '?';
672 hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
673 sizeof(buf)/sizeof(buf[0]), NULL, 0);
674 ok(hres == E_POINTER, "ParseUrl failed: %08x\n", hres);
675 ok(buf[0] == '?', "buf changed\n");
678 hres = IInternetProtocolInfo_ParseUrl(protocol_info, about_blank_url, PARSE_UNESCAPE+1, 0, buf,
679 sizeof(buf)/sizeof(buf[0]), &size, 0);
680 ok(hres == INET_E_DEFAULT_ACTION,
681 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres);
683 size = 0xdeadbeef;
684 hres = IInternetProtocolInfo_CombineUrl(protocol_info, about_blank_url, about_test_url,
685 0, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
686 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
687 ok(size == 0xdeadbeef, "size=%d\n", size);
689 size = 0xdeadbeef;
690 hres = IInternetProtocolInfo_CombineUrl(protocol_info, about_blank_url, about_test_url,
691 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
692 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
693 ok(size == 0xdeadbeef, "size=%d\n", size);
695 size = 0xdeadbeef;
696 hres = IInternetProtocolInfo_CombineUrl(protocol_info, NULL, NULL,
697 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
698 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08x\n", hres);
699 ok(size == 0xdeadbeef, "size=%d\n", size);
701 hres = IInternetProtocolInfo_CompareUrl(protocol_info, about_blank_url, about_blank_url, 0);
702 ok(hres == E_NOTIMPL, "CompareUrl failed: %08x\n", hres);
704 hres = IInternetProtocolInfo_CompareUrl(protocol_info, NULL, NULL, 0xdeadbeef);
705 ok(hres == E_NOTIMPL, "CompareUrl failed: %08x\n", hres);
707 for(i=0; i<30; i++) {
708 switch(i) {
709 case QUERY_CAN_NAVIGATE:
710 case QUERY_USES_NETWORK:
711 case QUERY_IS_CACHED:
712 case QUERY_IS_INSTALLEDENTRY:
713 case QUERY_IS_CACHED_OR_MAPPED:
714 case QUERY_IS_SECURE:
715 case QUERY_IS_SAFE:
716 break;
717 default:
718 hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, i, 0,
719 buf, sizeof(buf), &size, 0);
720 ok(hres == E_FAIL, "QueryInfo(%d) returned: %08x, expected E_FAIL\n", i, hres);
724 hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_CAN_NAVIGATE, 0,
725 buf, sizeof(buf), &size, 0);
726 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
727 "QueryInfo returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
729 size = 0xdeadbeef;
730 memset(buf, '?', sizeof(buf));
731 hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_USES_NETWORK, 0,
732 buf, sizeof(buf), &size, 0);
733 ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
734 ok(size == sizeof(DWORD), "size=%d\n", size);
735 ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
737 memset(buf, '?', sizeof(buf));
738 hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_USES_NETWORK, 0,
739 buf, sizeof(buf), NULL, 0);
740 ok(hres == S_OK, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres);
741 ok(!*(DWORD*)buf, "buf=%d\n", *(DWORD*)buf);
743 hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_USES_NETWORK, 0,
744 buf, 3, &size, 0);
745 ok(hres == E_FAIL, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
747 hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, QUERY_USES_NETWORK, 0,
748 NULL, sizeof(buf), &size, 0);
749 ok(hres == E_FAIL, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres);
751 hres = IInternetProtocolInfo_QueryInfo(protocol_info, about_blank_url, 60, 0,
752 NULL, sizeof(buf), &size, 0);
753 ok(hres == E_FAIL, "QueryInfo failed: %08x, expected E_FAIL\n", hres);
755 IInternetProtocolInfo_Release(protocol_info);
758 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
759 ok(hres == S_OK, "Could not get IClassFactory interface\n");
760 if(SUCCEEDED(hres)) {
761 do_test_about_protocol(factory, 0);
762 do_test_about_protocol(factory,
763 BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE);
765 IClassFactory_Release(factory);
768 IUnknown_Release(unk);
771 START_TEST(protocol)
773 OleInitialize(NULL);
775 test_res_protocol();
776 test_about_protocol();
778 OleUninitialize();