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);
33 static BOOL expect_GetBindInfo = FALSE, called_GetBindInfo = FALSE;
34 static BOOL expect_ReportProgress = FALSE, called_ReportProgress = FALSE;
35 static BOOL expect_ReportData = FALSE, called_ReportData = FALSE;
36 static BOOL expect_ReportResult = FALSE, called_ReportResult = FALSE;
38 static HRESULT expect_hrResult;
39 static BOOL expect_hr_win32err = FALSE;
41 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
43 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
50 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
55 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
60 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
62 ok(0, "unexpected call\n");
66 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
69 static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
71 ok(expect_ReportProgress, "unexpected call\n");
72 ok(ulStatusCode == BINDSTATUS_MIMETYPEAVAILABLE,
73 "ulStatusCode=%ld expected BINDSTATUS_MIMETYPEAVAILABLE\n", ulStatusCode);
74 ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
75 expect_ReportProgress = FALSE;
76 called_ReportProgress = TRUE;
80 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
83 ok(expect_ReportData, "unexpected call\n");
84 ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
85 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE),
86 "grcf = %08lx\n", grfBSCF);
87 expect_ReportData = FALSE;
88 called_ReportData = TRUE;
92 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult, DWORD dwError,
95 ok(expect_ReportResult, "unexpected call\n");
96 if(expect_hr_win32err)
97 ok((hrResult&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000),
98 "expected win32 err got: %08lx\n", hrResult);
100 ok(hrResult == expect_hrResult, "expected: %08lx got: %08lx\n", expect_hrResult, hrResult);
101 ok(dwError == 0, "dwError = %ld\n", dwError);
102 ok(!szResult, "szResult != NULL\n");
103 called_ReportResult = TRUE;
104 expect_ReportResult = FALSE;
108 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
109 ProtocolSink_QueryInterface,
111 ProtocolSink_Release,
113 ProtocolSink_ReportProgress,
114 ProtocolSink_ReportData,
115 ProtocolSink_ReportResult
118 static IInternetProtocolSink protocol_sink = {
122 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
124 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
128 return E_NOINTERFACE;
131 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
136 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
141 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
143 ok(expect_GetBindInfo, "unexpected call\n");
144 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
146 ok(!*grfBINDF, "*grfBINDF != 0\n");
147 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
148 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %ld\n", pbindinfo->cbSize);
149 called_GetBindInfo = TRUE;
150 expect_GetBindInfo = FALSE;
154 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
155 ULONG cEl, ULONG *pcElFetched)
157 ok(0, "unexpected call\n");
161 static IInternetBindInfoVtbl bind_info_vtbl = {
162 BindInfo_QueryInterface,
165 BindInfo_GetBindInfo,
166 BindInfo_GetBindString
169 static IInternetBindInfo bind_info = {
173 static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres,
174 BOOL expect_win32err)
178 expect_ReportResult = TRUE;
179 expect_GetBindInfo = TRUE;
180 expect_hrResult = expected_hres;
181 expect_hr_win32err = expect_win32err;
182 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
184 ok((hres&0xffff0000) == ((FACILITY_WIN32 << 16)|0x80000000), "expected win32 err got: %08lx\n", hres);
186 ok(hres == expected_hres, "expected: %08lx got: %08lx\n", expected_hres, hres);
187 ok(called_ReportResult, "expected ReportResult\n");
188 ok(called_GetBindInfo, "expected GetBindInfo\n");
189 expect_ReportResult = called_ReportResult = FALSE;
190 expect_GetBindInfo = called_GetBindInfo = FALSE;
193 static void protocol_start(IInternetProtocol *protocol, LPCWSTR url)
197 expect_GetBindInfo = TRUE;
198 expect_ReportResult = TRUE;
199 expect_ReportProgress = TRUE;
200 expect_ReportData = TRUE;
201 expect_hrResult = S_OK;
202 expect_hr_win32err = FALSE;
203 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
204 ok(hres == S_OK, "Start failed: %08lx\n", hres);
205 ok(called_GetBindInfo, "expected GetBindInfo\n");
207 ok(called_ReportProgress, "expected ReportProgress\n");
209 ok(called_ReportData, "expected ReportData\n");
210 ok(called_ReportResult, "expected ReportResult\n");
211 called_GetBindInfo = expect_GetBindInfo = FALSE;
212 called_ReportProgress = expect_ReportProgress = FALSE;
213 called_ReportData = expect_ReportData = FALSE;
214 called_ReportResult = expect_ReportResult = FALSE;
217 static void test_res_protocol(void)
219 IInternetProtocolInfo *protocol_info;
221 IClassFactory *factory;
224 static const WCHAR blank_url[] =
225 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
226 static const WCHAR wrong_url1[] =
227 {'m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','m','t','h',0};
228 static const WCHAR wrong_url2[] =
229 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',0};
230 static const WCHAR wrong_url3[] =
231 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','x','x','.','h','t','m',0};
232 static const WCHAR wrong_url4[] =
233 {'r','e','s',':','/','/','x','x','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
236 hres = CoGetClassObject(&CLSID_ResProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
237 ok(hres == S_OK, "CoGetClassObject failed: %08lx\n", hres);
239 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
240 ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08lx\n", hres);
241 if(SUCCEEDED(hres)) {
242 /* TODO: test IInternetProtocol interface */
243 IInternetProtocol_Release(protocol_info);
246 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
247 ok(hres == S_OK, "Could not get IClassFactory interface\n");
248 if(SUCCEEDED(hres)) {
249 IInternetProtocol *protocol;
252 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
253 ok(hres == S_OK, "Could not get IInternetProtocol: %08lx\n", hres);
255 if(SUCCEEDED(hres)) {
256 test_protocol_fail(protocol, wrong_url1, MK_E_SYNTAX, FALSE);
257 test_protocol_fail(protocol, wrong_url2, MK_E_SYNTAX, FALSE);
258 test_protocol_fail(protocol, wrong_url3, E_FAIL, TRUE);
259 test_protocol_fail(protocol, wrong_url4, E_FAIL, TRUE);
262 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
263 ok(hres == E_FAIL, "Read returned %08lx expected E_FAIL\n", hres);
264 ok(cb == 0xdeadbeef, "cb=%lu expected 0xdeadbeef\n", cb);
266 protocol_start(protocol, blank_url);
267 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
268 ok(hres == S_OK, "Read failed: %08lx\n", hres);
269 ok(cb == 2, "cb=%lu expected 2\n", cb);
270 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
271 ok(hres == S_OK, "Read failed: %08lx\n", hres);
272 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
273 ok(hres == S_FALSE, "Read failed: %08lx expected S_FALSE\n", hres);
274 ok(cb == 0, "cb=%lu expected 0\n", cb);
275 hres = IInternetProtocol_UnlockRequest(protocol);
276 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
278 protocol_start(protocol, blank_url);
279 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
280 ok(hres == S_OK, "Read failed: %08lx\n", hres);
281 hres = IInternetProtocol_LockRequest(protocol, 0);
282 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
283 hres = IInternetProtocol_UnlockRequest(protocol);
284 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
285 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
286 ok(hres == S_OK, "Read failed: %08lx\n", hres);
288 protocol_start(protocol, blank_url);
289 hres = IInternetProtocol_LockRequest(protocol, 0);
290 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
291 hres = IInternetProtocol_Terminate(protocol, 0);
292 ok(hres == S_OK, "Terminate failed: %08lx\n", hres);
293 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
294 ok(hres == S_OK, "Read failed: %08lx\n\n", hres);
295 hres = IInternetProtocol_UnlockRequest(protocol);
296 ok(hres == S_OK, "UnlockRequest failed: %08lx\n", hres);
297 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
298 ok(hres == S_OK, "Read 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", hres);
303 ok(cb == 2, "cb=%lu expected 2\n", cb);
305 protocol_start(protocol, blank_url);
306 hres = IInternetProtocol_LockRequest(protocol, 0);
307 ok(hres == S_OK, "LockRequest failed: %08lx\n", hres);
308 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
309 ok(hres == S_OK, "Read failed: %08lx\n", hres);
310 protocol_start(protocol, blank_url);
311 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
312 ok(hres == S_OK, "Read failed: %08lx\n", hres);
314 IInternetProtocol_Release(protocol);
317 IClassFactory_Release(factory);
320 IUnknown_Release(unk);