programs/wcmd: Rename to programs/cmd.
[wine.git] / dlls / mshtml / tests / protocol.c
blob65078198772fe38e1576ef4ea7ad72bd46948abb
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;
68 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
70 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
71 *ppv = iface;
72 return S_OK;
74 return E_NOINTERFACE;
77 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
79 return 2;
82 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
84 return 1;
87 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
89 ok(0, "unexpected call\n");
90 return E_NOTIMPL;
93 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
94 LPCWSTR szStatusText)
96 static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
98 CHECK_EXPECT(ReportProgress);
100 ok(ulStatusCode == BINDSTATUS_MIMETYPEAVAILABLE
101 || ulStatusCode == BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
102 "ulStatusCode=%ld\n", ulStatusCode);
103 ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
105 return S_OK;
108 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
109 ULONG ulProgressMax)
111 CHECK_EXPECT(ReportData);
113 ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
114 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE),
115 "grcf = %08lx\n", grfBSCF);
117 return S_OK;
120 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult, DWORD dwError,
121 LPCWSTR szResult)
123 CHECK_EXPECT(ReportResult);
125 if(expect_hr_win32err)
126 ok((hrResult&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000) || expect_hrResult,
127 "expected win32 err or %08lx got: %08lx\n", expect_hrResult, hrResult);
128 else
129 ok(hrResult == expect_hrResult, "expected: %08lx got: %08lx\n", expect_hrResult, hrResult);
130 ok(dwError == 0, "dwError = %ld\n", dwError);
131 ok(!szResult, "szResult != NULL\n");
133 return S_OK;
136 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
137 ProtocolSink_QueryInterface,
138 ProtocolSink_AddRef,
139 ProtocolSink_Release,
140 ProtocolSink_Switch,
141 ProtocolSink_ReportProgress,
142 ProtocolSink_ReportData,
143 ProtocolSink_ReportResult
146 static IInternetProtocolSink protocol_sink = {
147 &protocol_sink_vtbl
150 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
152 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
153 *ppv = iface;
154 return S_OK;
156 return E_NOINTERFACE;
159 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
161 return 2;
164 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
166 return 1;
169 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
171 CHECK_EXPECT(GetBindInfo);
173 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
174 if(grfBINDF)
175 ok(!*grfBINDF, "*grfBINDF != 0\n");
176 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
177 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %ld\n", pbindinfo->cbSize);
179 return S_OK;
182 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
183 ULONG cEl, ULONG *pcElFetched)
185 ok(0, "unexpected call\n");
186 return E_NOTIMPL;
189 static IInternetBindInfoVtbl bind_info_vtbl = {
190 BindInfo_QueryInterface,
191 BindInfo_AddRef,
192 BindInfo_Release,
193 BindInfo_GetBindInfo,
194 BindInfo_GetBindString
197 static IInternetBindInfo bind_info = {
198 &bind_info_vtbl
201 static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres,
202 BOOL expect_win32err)
204 HRESULT hres;
206 SET_EXPECT(GetBindInfo);
207 SET_EXPECT(ReportResult);
209 expect_hrResult = expected_hres;
210 expect_hr_win32err = expect_win32err;
211 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
212 if(expect_win32err)
213 ok((hres&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000) || hres == expect_hrResult,
214 "expected win32 err or %08lx got: %08lx\n", expected_hres, hres);
215 else
216 ok(hres == expected_hres, "expected: %08lx got: %08lx\n", expected_hres, hres);
218 CHECK_CALLED(GetBindInfo);
219 CHECK_CALLED(ReportResult);
222 static void protocol_start(IInternetProtocol *protocol, LPCWSTR url)
224 HRESULT hres;
226 SET_EXPECT(GetBindInfo);
227 SET_EXPECT(ReportResult);
228 SET_EXPECT(ReportProgress);
229 SET_EXPECT(ReportData);
230 expect_hrResult = S_OK;
231 expect_hr_win32err = FALSE;
233 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
234 ok(hres == S_OK, "Start failed: %08lx\n", hres);
236 CHECK_CALLED(GetBindInfo);
237 CHECK_CALLED(ReportProgress);
238 CHECK_CALLED(ReportData);
239 CHECK_CALLED(ReportResult);
242 static void test_res_protocol(void)
244 IInternetProtocolInfo *protocol_info;
245 IUnknown *unk;
246 IClassFactory *factory;
247 HRESULT hres;
249 static const WCHAR blank_url[] =
250 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
251 static const WCHAR test_part_url[] = {'r','e','s',':','/','/','C','S','S','/','t','e','s','t',0};
252 static const WCHAR wrong_url1[] =
253 {'m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','m','t','h',0};
254 static const WCHAR wrong_url2[] =
255 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',0};
256 static const WCHAR wrong_url3[] =
257 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','x','x','.','h','t','m',0};
258 static const WCHAR wrong_url4[] =
259 {'r','e','s',':','/','/','x','x','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
262 hres = CoGetClassObject(&CLSID_ResProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
263 ok(hres == S_OK, "CoGetClassObject failed: %08lx\n", hres);
264 if(!SUCCEEDED(hres))
265 return;
267 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
268 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08lx\n", hres);
269 if(SUCCEEDED(hres)) {
270 WCHAR buf[128];
271 DWORD size;
272 int i;
274 for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
275 if(i != PARSE_SECURITY_URL && i != PARSE_DOMAIN) {
276 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, i, 0, buf,
277 sizeof(buf)/sizeof(buf[0]), &size, 0);
278 ok(hres == INET_E_DEFAULT_ACTION,
279 "[%d] failed: %08lx, expected INET_E_DEFAULT_ACTION\n", i, hres);
283 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_SECURITY_URL, 0, buf,
284 sizeof(buf)/sizeof(buf[0]), &size, 0);
285 ok(hres == S_OK, "ParseUrl failed: %08lx\n", hres);
287 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_SECURITY_URL, 0, buf,
288 3, &size, 0);
289 ok(hres == S_FALSE, "ParseUrl failed: %08lx, expected S_FALSE\n", hres);
291 hres = IInternetProtocolInfo_ParseUrl(protocol_info, wrong_url1, PARSE_SECURITY_URL, 0, buf,
292 sizeof(buf)/sizeof(buf[0]), &size, 0);
293 ok(hres == MK_E_SYNTAX, "ParseUrl failed: %08lx, expected MK_E_SYNTAX\n", hres);
295 size = 0xdeadbeef;
296 buf[0] = '?';
297 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_DOMAIN, 0, buf,
298 sizeof(buf)/sizeof(buf[0]), &size, 0);
299 ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08lx\n", hres);
300 ok(buf[0] == '?', "buf changed\n");
301 ok(size == sizeof(blank_url)/sizeof(WCHAR), "size=%ld\n", size);
303 size = 0xdeadbeef;
304 hres = IInternetProtocolInfo_ParseUrl(protocol_info, wrong_url1, PARSE_DOMAIN, 0, buf,
305 sizeof(buf)/sizeof(buf[0]), &size, 0);
306 ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08lx\n", hres);
307 ok(buf[0] == '?', "buf changed\n");
308 ok(size == sizeof(wrong_url1)/sizeof(WCHAR), "size=%ld\n", size);
310 #if 0 /* Crashes on win9x */
311 size = 0xdeadbeef;
312 buf[0] = '?';
313 hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
314 sizeof(buf)/sizeof(buf[0]), &size, 0);
315 ok(hres == E_FAIL, "ParseUrl failed: %08lx\n", hres);
316 ok(buf[0] == '?', "buf changed\n");
317 ok(size == 1, "size=%ld, ezpected 1\n", size);
319 buf[0] = '?';
320 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_DOMAIN, 0, buf,
321 sizeof(buf)/sizeof(buf[0]), NULL, 0);
322 ok(hres == E_POINTER, "ParseUrl failed: %08lx\n", hres);
323 ok(buf[0] == '?', "buf changed\n");
325 buf[0] = '?';
326 hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
327 sizeof(buf)/sizeof(buf[0]), NULL, 0);
328 ok(hres == E_POINTER, "ParseUrl failed: %08lx\n", hres);
329 ok(buf[0] == '?', "buf changed\n");
330 #endif
332 buf[0] = '?';
333 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_UNESCAPE+1, 0, buf,
334 sizeof(buf)/sizeof(buf[0]), &size, 0);
335 ok(hres == INET_E_DEFAULT_ACTION,
336 "ParseUrl failed: %08lx, expected INET_E_DEFAULT_ACTION\n", hres);
337 ok(buf[0] == '?', "buf changed\n");
339 size = 0xdeadbeef;
340 hres = IInternetProtocolInfo_CombineUrl(protocol_info, blank_url, test_part_url,
341 0, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
342 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08lx\n", hres);
343 ok(size == 0xdeadbeef, "size=%ld\n", size);
345 size = 0xdeadbeef;
346 hres = IInternetProtocolInfo_CombineUrl(protocol_info, blank_url, test_part_url,
347 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
348 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08lx\n", hres);
349 ok(size == 0xdeadbeef, "size=%ld\n", size);
351 size = 0xdeadbeef;
352 hres = IInternetProtocolInfo_CombineUrl(protocol_info, NULL, NULL,
353 URL_FILE_USE_PATHURL, NULL, 0xdeadbeef, NULL, 0);
354 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08lx\n", hres);
355 ok(size == 0xdeadbeef, "size=%ld\n", size);
357 IInternetProtocolInfo_Release(protocol_info);
360 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
361 ok(hres == S_OK, "Could not get IClassFactory interface\n");
362 if(SUCCEEDED(hres)) {
363 IInternetProtocol *protocol;
364 BYTE buf[512];
365 ULONG cb;
366 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
367 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
369 if(SUCCEEDED(hres)) {
370 test_protocol_fail(protocol, wrong_url1, MK_E_SYNTAX, FALSE);
371 test_protocol_fail(protocol, wrong_url2, MK_E_SYNTAX, FALSE);
372 test_protocol_fail(protocol, wrong_url3, E_FAIL, TRUE);
373 test_protocol_fail(protocol, wrong_url4, E_FAIL, TRUE);
375 cb = 0xdeadbeef;
376 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
377 ok(hres == E_FAIL, "Read returned %08lx expected E_FAIL\n", hres);
378 ok(cb == 0xdeadbeef, "cb=%lu expected 0xdeadbeef\n", cb);
380 protocol_start(protocol, blank_url);
381 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
382 ok(hres == S_OK, "Read failed: %08lx\n", hres);
383 ok(cb == 2, "cb=%lu expected 2\n", cb);
384 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
385 ok(hres == S_OK, "Read failed: %08lx\n", hres);
386 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
387 ok(hres == S_FALSE, "Read failed: %08lx expected S_FALSE\n", hres);
388 ok(cb == 0, "cb=%lu expected 0\n", cb);
389 hres = IInternetProtocol_UnlockRequest(protocol);
390 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
392 protocol_start(protocol, blank_url);
393 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
394 ok(hres == S_OK, "Read failed: %08lx\n", hres);
395 hres = IInternetProtocol_LockRequest(protocol, 0);
396 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
397 hres = IInternetProtocol_UnlockRequest(protocol);
398 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
399 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
400 ok(hres == S_OK, "Read failed: %08lx\n", hres);
402 protocol_start(protocol, blank_url);
403 hres = IInternetProtocol_LockRequest(protocol, 0);
404 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
405 hres = IInternetProtocol_Terminate(protocol, 0);
406 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
407 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
408 ok(hres == S_OK, "Read failed: %08lx\n\n", hres);
409 hres = IInternetProtocol_UnlockRequest(protocol);
410 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
411 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
412 ok(hres == S_OK, "Read failed: %08lx\n", hres);
413 hres = IInternetProtocol_Terminate(protocol, 0);
414 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
415 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
416 ok(hres == S_OK, "Read failed: %08lx\n", hres);
417 ok(cb == 2, "cb=%lu expected 2\n", cb);
419 protocol_start(protocol, blank_url);
420 hres = IInternetProtocol_LockRequest(protocol, 0);
421 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
422 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
423 ok(hres == S_OK, "Read failed: %08lx\n", hres);
424 protocol_start(protocol, blank_url);
425 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
426 ok(hres == S_OK, "Read failed: %08lx\n", hres);
427 hres = IInternetProtocol_Terminate(protocol, 0);
428 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
430 IInternetProtocol_Release(protocol);
433 IClassFactory_Release(factory);
436 IUnknown_Release(unk);
439 static void test_about_protocol(void)
441 IInternetProtocolInfo *protocol_info;
442 IUnknown *unk;
443 IClassFactory *factory;
444 HRESULT hres;
446 static const WCHAR blank_url[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
447 static const WCHAR test_url[] = {'a','b','o','u','t',':','t','e','s','t',0};
448 static const WCHAR res_url[] = {'r','e','s',':','b','l','a','n','k',0};
449 static const WCHAR blank_html[] = {0xfeff,'<','H','T','M','L','>','<','/','H','T','M','L','>',0};
450 static const WCHAR test_html[] =
451 {0xfeff,'<','H','T','M','L','>','t','e','s','t','<','/','H','T','M','L','>',0};
453 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
454 ok(hres == S_OK, "CoGetClassObject failed: %08lx\n", hres);
455 if(!SUCCEEDED(hres))
456 return;
458 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
459 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08lx\n", hres);
460 if(SUCCEEDED(hres)) {
461 WCHAR buf[128];
462 DWORD size;
463 int i;
465 for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
466 if(i != PARSE_SECURITY_URL && i != PARSE_DOMAIN) {
467 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, i, 0, buf,
468 sizeof(buf)/sizeof(buf[0]), &size, 0);
469 ok(hres == INET_E_DEFAULT_ACTION,
470 "[%d] failed: %08lx, expected INET_E_DEFAULT_ACTION\n", i, hres);
474 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_SECURITY_URL, 0, buf,
475 sizeof(buf)/sizeof(buf[0]), &size, 0);
476 ok(hres == S_OK, "ParseUrl failed: %08lx\n", hres);
477 ok(!lstrcmpW(blank_url, buf), "buf != blank_url\n");
479 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_SECURITY_URL, 0, buf,
480 3, &size, 0);
481 ok(hres == S_FALSE, "ParseUrl failed: %08lx, expected S_FALSE\n", hres);
483 hres = IInternetProtocolInfo_ParseUrl(protocol_info, test_url, PARSE_SECURITY_URL, 0, buf,
484 sizeof(buf)/sizeof(buf[0]), &size, 0);
485 ok(hres == S_OK, "ParseUrl failed: %08lx\n", hres);
486 ok(!lstrcmpW(test_url, buf), "buf != test_url\n");
488 size = 0xdeadbeef;
489 buf[0] = '?';
490 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_DOMAIN, 0, buf,
491 sizeof(buf)/sizeof(buf[0]), &size, 0);
492 ok(hres == S_OK || hres == E_FAIL, "ParseUrl failed: %08lx\n", hres);
493 ok(buf[0] == '?', "buf changed\n");
494 ok(size == sizeof(blank_url)/sizeof(WCHAR), "size=%ld\n", size);
496 #if 0 /* Crashes on win9x */
497 size = 0xdeadbeef;
498 buf[0] = '?';
499 hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
500 sizeof(buf)/sizeof(buf[0]), &size, 0);
501 ok(hres == E_FAIL, "ParseUrl failed: %08lx\n", hres);
502 ok(buf[0] == '?', "buf changed\n");
503 ok(size == 1, "size=%ld, ezpected 1\n", size);
505 buf[0] = '?';
506 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_DOMAIN, 0, buf,
507 sizeof(buf)/sizeof(buf[0]), NULL, 0);
508 ok(hres == E_POINTER, "ParseUrl failed: %08lx\n", hres);
509 ok(buf[0] == '?', "buf changed\n");
511 buf[0] = '?';
512 hres = IInternetProtocolInfo_ParseUrl(protocol_info, NULL, PARSE_DOMAIN, 0, buf,
513 sizeof(buf)/sizeof(buf[0]), NULL, 0);
514 ok(hres == E_POINTER, "ParseUrl failed: %08lx\n", hres);
515 ok(buf[0] == '?', "buf changed\n");
516 #endif
518 hres = IInternetProtocolInfo_ParseUrl(protocol_info, blank_url, PARSE_UNESCAPE+1, 0, buf,
519 sizeof(buf)/sizeof(buf[0]), &size, 0);
520 ok(hres == INET_E_DEFAULT_ACTION,
521 "ParseUrl failed: %08lx, expected INET_E_DEFAULT_ACTION\n", hres);
523 size = 0xdeadbeef;
524 hres = IInternetProtocolInfo_CombineUrl(protocol_info, blank_url, test_url,
525 0, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
526 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08lx\n", hres);
527 ok(size == 0xdeadbeef, "size=%ld\n", size);
529 size = 0xdeadbeef;
530 hres = IInternetProtocolInfo_CombineUrl(protocol_info, blank_url, test_url,
531 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
532 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08lx\n", hres);
533 ok(size == 0xdeadbeef, "size=%ld\n", size);
535 size = 0xdeadbeef;
536 hres = IInternetProtocolInfo_CombineUrl(protocol_info, NULL, NULL,
537 URL_FILE_USE_PATHURL, buf, sizeof(buf)/sizeof(buf[0]), &size, 0);
538 ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER, "CombineUrl failed: %08lx\n", hres);
539 ok(size == 0xdeadbeef, "size=%ld\n", size);
541 IInternetProtocolInfo_Release(protocol_info);
544 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
545 ok(hres == S_OK, "Could not get IClassFactory interface\n");
546 if(SUCCEEDED(hres)) {
547 IInternetProtocol *protocol;
548 BYTE buf[512];
549 ULONG cb;
550 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
551 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
553 if(SUCCEEDED(hres)) {
554 protocol_start(protocol, blank_url);
555 hres = IInternetProtocol_LockRequest(protocol, 0);
556 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
557 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
558 ok(hres == S_OK, "Read failed: %08lx\n", hres);
559 ok(cb == sizeof(blank_html), "cb=%ld\n", cb);
560 ok(!memcmp(buf, blank_html, cb), "Readed wrong data\n");
561 hres = IInternetProtocol_UnlockRequest(protocol);
562 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
564 protocol_start(protocol, test_url);
565 hres = IInternetProtocol_LockRequest(protocol, 0);
566 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
567 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
568 ok(hres == S_OK, "Read failed: %08lx\n", hres);
569 ok(cb == sizeof(test_html), "cb=%ld\n", cb);
570 ok(!memcmp(buf, test_html, cb), "Readed wrong data\n");
571 hres = IInternetProtocol_UnlockRequest(protocol);
572 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
574 protocol_start(protocol, res_url);
575 hres = IInternetProtocol_LockRequest(protocol, 0);
576 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
577 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
578 ok(hres == S_OK, "Read failed: %08lx\n", hres);
579 ok(cb == sizeof(blank_html), "cb=%ld\n", cb);
580 ok(!memcmp(buf, blank_html, cb), "Readed wrong data\n");
581 hres = IInternetProtocol_UnlockRequest(protocol);
582 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
584 IInternetProtocol_Release(protocol);
587 IClassFactory_Release(factory);
590 IUnknown_Release(unk);
593 START_TEST(protocol)
595 OleInitialize(NULL);
597 test_res_protocol();
598 test_about_protocol();
600 OleUninitialize();