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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <wine/test.h>
31 DEFINE_GUID(CLSID_ResProtocol, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
32 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
34 static BOOL expect_GetBindInfo = FALSE, called_GetBindInfo = FALSE;
35 static BOOL expect_ReportProgress = FALSE, called_ReportProgress = FALSE;
36 static BOOL expect_ReportData = FALSE, called_ReportData = FALSE;
37 static BOOL expect_ReportResult = FALSE, called_ReportResult = FALSE;
39 static HRESULT expect_hrResult;
40 static BOOL expect_hr_win32err = FALSE;
42 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
44 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
51 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
56 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
61 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
63 ok(0, "unexpected call\n");
67 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
70 static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
72 ok(expect_ReportProgress, "unexpected call\n");
73 ok(ulStatusCode == BINDSTATUS_MIMETYPEAVAILABLE
74 || ulStatusCode == BINDSTATUS_VERFIEDMIMETYPEAVAILABLE, "ulStatusCode=%ld\n", ulStatusCode);
75 ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
76 expect_ReportProgress = FALSE;
77 called_ReportProgress = TRUE;
81 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
84 ok(expect_ReportData, "unexpected call\n");
85 ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
86 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE),
87 "grcf = %08lx\n", grfBSCF);
88 expect_ReportData = FALSE;
89 called_ReportData = TRUE;
93 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult, DWORD dwError,
96 ok(expect_ReportResult, "unexpected call\n");
97 if(expect_hr_win32err)
98 ok((hrResult&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000) || expect_hrResult,
99 "expected win32 err or %08lx got: %08lx\n", expect_hrResult, hrResult);
101 ok(hrResult == expect_hrResult, "expected: %08lx got: %08lx\n", expect_hrResult, hrResult);
102 ok(dwError == 0, "dwError = %ld\n", dwError);
103 ok(!szResult, "szResult != NULL\n");
104 called_ReportResult = TRUE;
105 expect_ReportResult = FALSE;
109 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
110 ProtocolSink_QueryInterface,
112 ProtocolSink_Release,
114 ProtocolSink_ReportProgress,
115 ProtocolSink_ReportData,
116 ProtocolSink_ReportResult
119 static IInternetProtocolSink protocol_sink = {
123 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
125 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
129 return E_NOINTERFACE;
132 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
137 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
142 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
144 ok(expect_GetBindInfo, "unexpected call\n");
145 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
147 ok(!*grfBINDF, "*grfBINDF != 0\n");
148 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
149 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %ld\n", pbindinfo->cbSize);
150 called_GetBindInfo = TRUE;
151 expect_GetBindInfo = FALSE;
155 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
156 ULONG cEl, ULONG *pcElFetched)
158 ok(0, "unexpected call\n");
162 static IInternetBindInfoVtbl bind_info_vtbl = {
163 BindInfo_QueryInterface,
166 BindInfo_GetBindInfo,
167 BindInfo_GetBindString
170 static IInternetBindInfo bind_info = {
174 static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres,
175 BOOL expect_win32err)
179 expect_ReportResult = TRUE;
180 expect_GetBindInfo = TRUE;
181 expect_hrResult = expected_hres;
182 expect_hr_win32err = expect_win32err;
183 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
185 ok((hres&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000) || hres == expect_hrResult,
186 "expected win32 err or %08lx got: %08lx\n", expected_hres, hres);
188 ok(hres == expected_hres, "expected: %08lx got: %08lx\n", expected_hres, hres);
189 ok(called_ReportResult, "expected ReportResult\n");
190 ok(called_GetBindInfo, "expected GetBindInfo\n");
191 expect_ReportResult = called_ReportResult = FALSE;
192 expect_GetBindInfo = called_GetBindInfo = FALSE;
195 static void protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_mime_todo)
199 expect_GetBindInfo = TRUE;
200 expect_ReportResult = TRUE;
201 expect_ReportProgress = TRUE;
202 expect_ReportData = TRUE;
203 expect_hrResult = S_OK;
204 expect_hr_win32err = FALSE;
205 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
206 ok(hres == S_OK, "Start failed: %08lx\n", hres);
207 ok(called_GetBindInfo, "expected GetBindInfo\n");
210 ok(called_ReportProgress, "expected ReportProgress\n");
213 ok(called_ReportProgress, "expected ReportProgress\n");
215 ok(called_ReportData, "expected ReportData\n");
216 ok(called_ReportResult, "expected ReportResult\n");
217 called_GetBindInfo = expect_GetBindInfo = FALSE;
218 called_ReportProgress = expect_ReportProgress = FALSE;
219 called_ReportData = expect_ReportData = FALSE;
220 called_ReportResult = expect_ReportResult = FALSE;
223 static void test_res_protocol(void)
225 IInternetProtocolInfo *protocol_info;
227 IClassFactory *factory;
230 static const WCHAR blank_url[] =
231 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
232 static const WCHAR wrong_url1[] =
233 {'m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','m','t','h',0};
234 static const WCHAR wrong_url2[] =
235 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',0};
236 static const WCHAR wrong_url3[] =
237 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','x','x','.','h','t','m',0};
238 static const WCHAR wrong_url4[] =
239 {'r','e','s',':','/','/','x','x','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
242 hres = CoGetClassObject(&CLSID_ResProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
243 ok(hres == S_OK, "CoGetClassObject failed: %08lx\n", hres);
247 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
248 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08lx\n", hres);
249 if(SUCCEEDED(hres)) {
250 /* TODO: test IInternetProtocol interface */
251 IInternetProtocol_Release(protocol_info);
254 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
255 ok(hres == S_OK, "Could not get IClassFactory interface\n");
256 if(SUCCEEDED(hres)) {
257 IInternetProtocol *protocol;
260 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
261 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
263 if(SUCCEEDED(hres)) {
264 test_protocol_fail(protocol, wrong_url1, MK_E_SYNTAX, FALSE);
265 test_protocol_fail(protocol, wrong_url2, MK_E_SYNTAX, FALSE);
266 test_protocol_fail(protocol, wrong_url3, E_FAIL, TRUE);
267 test_protocol_fail(protocol, wrong_url4, E_FAIL, TRUE);
270 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
271 ok(hres == E_FAIL, "Read returned %08lx expected E_FAIL\n", hres);
272 ok(cb == 0xdeadbeef, "cb=%lu expected 0xdeadbeef\n", cb);
274 protocol_start(protocol, blank_url, TRUE);
275 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
276 ok(hres == S_OK, "Read failed: %08lx\n", hres);
277 ok(cb == 2, "cb=%lu expected 2\n", cb);
278 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
279 ok(hres == S_OK, "Read failed: %08lx\n", hres);
280 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
281 ok(hres == S_FALSE, "Read failed: %08lx expected S_FALSE\n", hres);
282 ok(cb == 0, "cb=%lu expected 0\n", cb);
283 hres = IInternetProtocol_UnlockRequest(protocol);
284 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
286 protocol_start(protocol, blank_url, TRUE);
287 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
288 ok(hres == S_OK, "Read failed: %08lx\n", hres);
289 hres = IInternetProtocol_LockRequest(protocol, 0);
290 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
291 hres = IInternetProtocol_UnlockRequest(protocol);
292 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
293 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
294 ok(hres == S_OK, "Read failed: %08lx\n", hres);
296 protocol_start(protocol, blank_url, TRUE);
297 hres = IInternetProtocol_LockRequest(protocol, 0);
298 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
299 hres = IInternetProtocol_Terminate(protocol, 0);
300 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
301 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
302 ok(hres == S_OK, "Read failed: %08lx\n\n", hres);
303 hres = IInternetProtocol_UnlockRequest(protocol);
304 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
305 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
306 ok(hres == S_OK, "Read failed: %08lx\n", hres);
307 hres = IInternetProtocol_Terminate(protocol, 0);
308 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
309 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
310 ok(hres == S_OK, "Read failed: %08lx\n", hres);
311 ok(cb == 2, "cb=%lu expected 2\n", cb);
313 protocol_start(protocol, blank_url, TRUE);
314 hres = IInternetProtocol_LockRequest(protocol, 0);
315 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
316 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
317 ok(hres == S_OK, "Read failed: %08lx\n", hres);
318 protocol_start(protocol, blank_url, TRUE);
319 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
320 ok(hres == S_OK, "Read failed: %08lx\n", hres);
321 hres = IInternetProtocol_Terminate(protocol, 0);
322 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
324 IInternetProtocol_Release(protocol);
327 IClassFactory_Release(factory);
330 IUnknown_Release(unk);
333 static void test_about_protocol(void)
335 IInternetProtocolInfo *protocol_info;
337 IClassFactory *factory;
340 static const WCHAR blank_url[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
341 static const WCHAR test_url[] = {'a','b','o','u','t',':','t','e','s','t',0};
342 static const WCHAR res_url[] = {'r','e','s',':','b','l','a','n','k',0};
343 static const WCHAR blank_html[] = {0xfeff,'<','H','T','M','L','>','<','/','H','T','M','L','>',0};
344 static const WCHAR test_html[] =
345 {0xfeff,'<','H','T','M','L','>','t','e','s','t','<','/','H','T','M','L','>',0};
347 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
348 ok(hres == S_OK, "CoGetClassObject failed: %08lx\n", hres);
352 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
353 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08lx\n", hres);
354 if(SUCCEEDED(hres)) {
355 /* TODO: test IInternetProtocol interface */
356 IInternetProtocol_Release(protocol_info);
359 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
360 ok(hres == S_OK, "Could not get IClassFactory interface\n");
361 if(SUCCEEDED(hres)) {
362 IInternetProtocol *protocol;
365 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
366 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
368 if(SUCCEEDED(hres)) {
369 protocol_start(protocol, blank_url, FALSE);
370 hres = IInternetProtocol_LockRequest(protocol, 0);
371 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
372 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
373 ok(hres == S_OK, "Read failed: %08lx\n", hres);
374 ok(cb == sizeof(blank_html), "cb=%ld, expected %d\n", cb, sizeof(blank_html));
375 ok(!memcmp(buf, blank_html, cb), "Readed wrong data\n");
376 hres = IInternetProtocol_UnlockRequest(protocol);
377 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
379 protocol_start(protocol, test_url, FALSE);
380 hres = IInternetProtocol_LockRequest(protocol, 0);
381 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
382 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
383 ok(hres == S_OK, "Read failed: %08lx\n", hres);
384 ok(cb == sizeof(test_html), "cb=%ld, expected %d\n", cb, sizeof(test_html));
385 ok(!memcmp(buf, test_html, cb), "Readed wrong data\n");
386 hres = IInternetProtocol_UnlockRequest(protocol);
387 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
389 protocol_start(protocol, res_url, FALSE);
390 hres = IInternetProtocol_LockRequest(protocol, 0);
391 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
392 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
393 ok(hres == S_OK, "Read failed: %08lx\n", hres);
394 ok(cb == sizeof(blank_html), "cb=%ld, expected %d\n", cb, sizeof(blank_html));
395 ok(!memcmp(buf, blank_html, cb), "Readed wrong data\n");
396 hres = IInternetProtocol_UnlockRequest(protocol);
397 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
399 IInternetProtocol_Release(protocol);
402 IClassFactory_Release(factory);
405 IUnknown_Release(unk);
413 test_about_protocol();