2 * Copyright 2005-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
21 #include <wine/test.h>
31 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
33 #define DEFINE_EXPECT(func) \
34 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
36 #define SET_EXPECT(func) \
37 expect_ ## func = TRUE
39 #define CHECK_EXPECT(func) \
41 ok(expect_ ##func, "unexpected call " #func "\n"); \
42 expect_ ## func = FALSE; \
43 called_ ## func = TRUE; \
46 #define CHECK_EXPECT2(func) \
48 ok(expect_ ##func, "unexpected call " #func "\n"); \
49 called_ ## func = TRUE; \
52 #define CHECK_CALLED(func) \
54 ok(called_ ## func, "expected " #func "\n"); \
55 expect_ ## func = called_ ## func = FALSE; \
58 DEFINE_EXPECT(ParseUrl);
59 DEFINE_EXPECT(QI_IInternetProtocolInfo);
60 DEFINE_EXPECT(CreateInstance);
61 DEFINE_EXPECT(unk_Release);
63 static void test_CreateFormatEnum(void)
65 IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
70 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
71 static FORMATETC formatetc[] = {
79 hres = CreateFormatEnumerator(0, formatetc, &fenum);
80 ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08lx, expected E_FAIL\n", hres);
81 hres = CreateFormatEnumerator(0, formatetc, NULL);
82 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
83 hres = CreateFormatEnumerator(5, formatetc, NULL);
84 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
87 hres = CreateFormatEnumerator(5, formatetc, &fenum);
88 ok(hres == S_OK, "CreateFormatEnumerator failed: %08lx\n", hres);
92 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
93 ok(hres == E_INVALIDARG, "Next failed: %08lx, expected E_INVALIDARG\n", hres);
95 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
96 ok(hres == S_OK, "Next failed: %08lx\n", hres);
97 ok(ul == 0, "ul=%ld, expected 0\n", ul);
99 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
100 ok(hres == S_OK, "Next failed: %08lx\n", hres);
101 ok(fetc[0].lindex == 0, "fetc[0].lindex=%ld, expected 0\n", fetc[0].lindex);
102 ok(fetc[1].lindex == 1, "fetc[1].lindex=%ld, expected 1\n", fetc[1].lindex);
103 ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
104 ok(ul == 2, "ul=%ld, expected 2\n", ul);
106 hres = IEnumFORMATETC_Skip(fenum, 1);
107 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
109 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
110 ok(hres == S_FALSE, "Next failed: %08lx, expected S_FALSE\n", hres);
111 ok(fetc[0].lindex == 3, "fetc[0].lindex=%ld, expected 3\n", fetc[0].lindex);
112 ok(fetc[1].lindex == 4, "fetc[1].lindex=%ld, expected 4\n", fetc[1].lindex);
113 ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
114 ok(ul == 2, "ul=%ld, expected 2\n", ul);
116 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
117 ok(hres == S_FALSE, "Next failed: %08lx, expected S_FALSE\n", hres);
118 ok(ul == 0, "ul=%ld, expected 0\n", ul);
120 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
121 ok(hres == S_OK, "Next failed: %08lx\n", hres);
122 ok(ul == 0, "ul=%ld, expected 0\n", ul);
124 hres = IEnumFORMATETC_Skip(fenum, 3);
125 ok(hres == S_FALSE, "Skip failed: %08lx, expected S_FALSE\n", hres);
127 hres = IEnumFORMATETC_Reset(fenum);
128 ok(hres == S_OK, "Reset failed: %08lx\n", hres);
130 hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
131 ok(hres == S_OK, "Next failed: %08lx\n", hres);
132 ok(fetc[0].lindex == 0, "fetc[0].lindex=%ld, expected 0\n", fetc[0].lindex);
134 hres = IEnumFORMATETC_Reset(fenum);
135 ok(hres == S_OK, "Reset failed: %08lx\n", hres);
137 hres = IEnumFORMATETC_Skip(fenum, 2);
138 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
140 hres = IEnumFORMATETC_Clone(fenum, NULL);
141 ok(hres == E_INVALIDARG, "Clone failed: %08lx, expected E_INVALIDARG\n", hres);
143 hres = IEnumFORMATETC_Clone(fenum, &fenum2);
144 ok(hres == S_OK, "Clone failed: %08lx\n", hres);
146 if(SUCCEEDED(hres)) {
147 ok(fenum != fenum2, "fenum == fenum2\n");
149 hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
150 ok(hres == S_OK, "Next failed: %08lx\n", hres);
151 ok(fetc[0].lindex == 2, "fetc[0].lindex=%ld, expected 2\n", fetc[0].lindex);
153 IEnumFORMATETC_Release(fenum2);
156 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
157 ok(hres == S_OK, "Next failed: %08lx\n", hres);
158 ok(fetc[0].lindex == 2, "fetc[0].lindex=%ld, expected 2\n", fetc[0].lindex);
160 hres = IEnumFORMATETC_Skip(fenum, 1);
161 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
163 IEnumFORMATETC_Release(fenum);
166 static void test_RegisterFormatEnumerator(void)
168 IBindCtx *bctx = NULL;
169 IEnumFORMATETC *format = NULL, *format2 = NULL;
170 IUnknown *unk = NULL;
173 static FORMATETC formatetc = {0,NULL,0,0,0};
174 static WCHAR wszEnumFORMATETC[] =
175 {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
177 CreateBindCtx(0, &bctx);
179 hres = CreateFormatEnumerator(1, &formatetc, &format);
180 ok(hres == S_OK, "CreateFormatEnumerator failed: %08lx\n", hres);
184 hres = RegisterFormatEnumerator(NULL, format, 0);
185 ok(hres == E_INVALIDARG,
186 "RegisterFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
187 hres = RegisterFormatEnumerator(bctx, NULL, 0);
188 ok(hres == E_INVALIDARG,
189 "RegisterFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
191 hres = RegisterFormatEnumerator(bctx, format, 0);
192 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08lx\n", hres);
194 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
195 ok(hres == S_OK, "GetObjectParam failed: %08lx\n", hres);
196 ok(unk == (IUnknown*)format, "unk != format\n");
198 hres = RevokeFormatEnumerator(NULL, format);
199 ok(hres == E_INVALIDARG,
200 "RevokeFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
202 hres = RevokeFormatEnumerator(bctx, format);
203 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08lx\n", hres);
205 hres = RevokeFormatEnumerator(bctx, format);
206 ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08lx, expected E_FAIL\n", hres);
208 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
209 ok(hres == E_FAIL, "GetObjectParam failed: %08lx, expected E_FAIL\n", hres);
211 hres = RegisterFormatEnumerator(bctx, format, 0);
212 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08lx\n", hres);
214 hres = CreateFormatEnumerator(1, &formatetc, &format2);
215 ok(hres == S_OK, "CreateFormatEnumerator failed: %08lx\n", hres);
217 if(SUCCEEDED(hres)) {
218 hres = RevokeFormatEnumerator(bctx, format);
219 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08lx\n", hres);
221 IEnumFORMATETC_Release(format2);
224 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
225 ok(hres == E_FAIL, "GetObjectParam failed: %08lx, expected E_FAIL\n", hres);
227 IEnumFORMATETC_Release(format);
229 hres = RegisterFormatEnumerator(bctx, format, 0);
230 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08lx\n", hres);
231 hres = RevokeFormatEnumerator(bctx, NULL);
232 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08lx\n", hres);
233 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
234 ok(hres == E_FAIL, "GetObjectParam failed: %08lx, expected E_FAIL\n", hres);
236 IBindCtx_Release(bctx);
239 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
240 '/','b','l','a','n','k','.','h','t','m',0};
241 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
242 static const WCHAR url3[] = {'f','i','l','e',':','c',':','\\','I','n','d','e','x','.','h','t','m',0};
243 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
244 '%','2','e','j','p','g',0};
245 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
247 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
248 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
249 'f','i','l','e','.','t','e','s','t',0};
250 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
253 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
256 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
257 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
259 static const WCHAR wszRes[] = {'r','e','s',0};
260 static const WCHAR wszFile[] = {'f','i','l','e',0};
261 static const WCHAR wszHttp[] = {'h','t','t','p',0};
262 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
263 static const WCHAR wszEmpty[] = {0};
274 static const struct parse_test parse_tests[] = {
275 {url1, S_OK, url1, E_INVALIDARG, NULL, wszRes},
276 {url2, E_FAIL, url2, E_INVALIDARG, NULL, wszEmpty},
277 {url3, E_FAIL, url3, S_OK, path3, wszFile},
278 {url4, E_FAIL, url4e, S_OK, path4, wszFile},
279 {url5, E_FAIL, url5, E_INVALIDARG, NULL, wszHttp},
280 {url6, S_OK, url6, E_INVALIDARG, NULL, wszAbout}
283 static void test_CoInternetParseUrl(void)
289 static WCHAR buf[4096];
291 memset(buf, 0xf0, sizeof(buf));
292 hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
294 ok(hres == E_POINTER, "schema failed: %08lx, expected E_POINTER\n", hres);
296 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
297 memset(buf, 0xf0, sizeof(buf));
298 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
299 sizeof(buf)/sizeof(WCHAR), &size, 0);
300 ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08lx, expected %08lx\n",
301 i, hres, parse_tests[i].secur_hres);
303 memset(buf, 0xf0, sizeof(buf));
304 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
305 sizeof(buf)/sizeof(WCHAR), &size, 0);
306 ok(hres == S_OK, "[%d] encoding failed: %08lx\n", i, hres);
307 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
308 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
310 memset(buf, 0xf0, sizeof(buf));
311 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
312 sizeof(buf)/sizeof(WCHAR), &size, 0);
313 ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08lx, expected %08lx\n",
314 i, hres, parse_tests[i].path_hres);
315 if(parse_tests[i].path) {
316 ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
317 ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
320 memset(buf, 0xf0, sizeof(buf));
321 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
322 sizeof(buf)/sizeof(WCHAR), &size, 0);
323 ok(hres == S_OK, "[%d] schema failed: %08lx\n", i, hres);
324 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
325 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
329 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
330 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
331 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
332 'o','c','t','e','t','-','s','t','r','e','a','m',0};
334 static const struct {
338 {url1, mimeTextHtml},
339 {url2, mimeTextHtml},
340 {url3, mimeTextHtml},
347 static BYTE data1[] = "test data\n";
348 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
349 static BYTE data3[] = {0,0,0};
350 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
351 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
352 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
353 static BYTE data7[] = "<html>blahblah";
354 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
355 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
356 static BYTE data10[] = "<HtmL>blahblah";
357 static BYTE data11[] = "blah<HTML>blahblah";
358 static BYTE data12[] = "blah<HTMLblahblah";
359 static BYTE data13[] = "blahHTML>blahblah";
360 static BYTE data14[] = "blah<HTMblahblah";
362 static const struct {
367 {data1, sizeof(data1), mimeTextPlain},
368 {data2, sizeof(data2), mimeAppOctetStream},
369 {data3, sizeof(data3), mimeAppOctetStream},
370 {data4, sizeof(data4), mimeAppOctetStream},
371 {data5, sizeof(data5), mimeTextPlain},
372 {data6, sizeof(data6), mimeTextPlain},
373 {data7, sizeof(data7), mimeTextHtml},
374 {data8, sizeof(data8), mimeTextHtml},
375 {data9, sizeof(data9), mimeTextHtml},
376 {data10, sizeof(data10), mimeTextHtml},
377 {data11, sizeof(data11), mimeTextHtml},
378 {data12, sizeof(data12), mimeTextHtml},
379 {data13, sizeof(data13), mimeTextPlain},
380 {data14, sizeof(data14), mimeTextPlain}
383 static void test_FindMimeFromData(void)
389 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
390 mime = (LPWSTR)0xf0f0f0f0;
391 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
392 if(mime_tests[i].mime) {
393 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
394 ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
397 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
398 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
401 mime = (LPWSTR)0xf0f0f0f0;
402 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
403 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
404 ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
407 mime = (LPWSTR)0xf0f0f0f0;
408 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
409 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
410 ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
414 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
415 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
417 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
418 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
421 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
422 mimeTextHtml, 0, &mime, 0);
423 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
424 ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
428 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
429 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
430 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
433 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
434 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
435 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
438 hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
439 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
440 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
443 hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
444 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, excepted E_INVALIDARG\n", hres);
446 hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
447 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
449 hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
450 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
452 hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
453 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
455 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
456 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
457 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
460 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
461 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
464 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
465 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
466 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
467 '.','o','r','g',3,0,0,0};
468 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
469 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
472 static struct secmgr_test {
480 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
481 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
482 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
483 {url4, 3, S_OK, sizeof(secid4), secid4, S_OK},
484 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
485 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
486 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
489 static void test_SecurityManager(void)
492 IInternetSecurityManager *secmgr = NULL;
497 hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
498 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08lx\n", hres);
502 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
504 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
506 ok(hres == secmgr_tests[i].zone_hres,
507 "[%d] MapUrlToZone failed: %08lx, expected %08lx\n",
508 i, hres, secmgr_tests[i].zone_hres);
509 ok(zone == secmgr_tests[i].zone, "[%d] zone=%ld, expected %ld\n", i, zone,
510 secmgr_tests[i].zone);
513 memset(buf, 0xf0, sizeof(buf));
514 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
516 ok(hres == secmgr_tests[i].secid_hres,
517 "[%d] GetSecurityId failed: %08lx, expected %08lx\n",
518 i, hres, secmgr_tests[i].secid_hres);
519 if(secmgr_tests[i].secid) {
520 ok(size == secmgr_tests[i].secid_size, "[%d] size=%ld, expected %ld\n",
521 i, size, secmgr_tests[i].secid_size);
522 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
527 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
528 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08lx, expected E_INVALIDARG\n", hres);
531 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
532 ok(hres == E_INVALIDARG,
533 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
534 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
536 ok(hres == E_INVALIDARG,
537 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
538 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
540 ok(hres == E_INVALIDARG,
541 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
543 IInternetSecurityManager_Release(secmgr);
546 static void test_ZoneManager(void)
548 IInternetZoneManager *zonemgr = NULL;
552 hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
553 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08lx\n", hres);
557 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
558 sizeof(DWORD), URLZONEREG_DEFAULT);
559 ok(hres == S_OK, "GetZoneActionPolicy failed: %08lx\n", hres);
560 ok(*(DWORD*)buf == 1, "policy=%ld, expected 1\n", *(DWORD*)buf);
562 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
563 sizeof(DWORD), URLZONEREG_DEFAULT);
564 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
566 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
567 2, URLZONEREG_DEFAULT);
568 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
570 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
571 sizeof(DWORD), URLZONEREG_DEFAULT);
572 ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08lx, expected E_FAIL\n", hres);
574 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
575 sizeof(DWORD), URLZONEREG_DEFAULT);
576 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
578 IInternetZoneManager_Release(zonemgr);
581 static void register_protocols(void)
583 IInternetSession *session;
584 IClassFactory *factory;
587 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
589 hres = CoInternetGetSession(0, &session, 0);
590 ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
594 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
595 &IID_IClassFactory, (void**)&factory);
596 ok(hres == S_OK, "Coud not get AboutProtocol factory: %08lx\n", hres);
600 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
601 wszAbout, 0, NULL, 0);
602 IClassFactory_Release(factory);
606 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
607 REFIID riid, void **ppv)
609 ok(0, "unexpected call\n");
610 return E_NOINTERFACE;
613 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
618 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
623 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
624 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
625 DWORD *pcchResult, DWORD dwReserved)
627 CHECK_EXPECT(ParseUrl);
631 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
632 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
633 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
635 ok(0, "unexpected call\n");
639 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
640 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
642 ok(0, "unexpected call\n");
646 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
647 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
648 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
650 ok(0, "unexpected call\n");
654 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
655 InternetProtocolInfo_QueryInterface,
656 InternetProtocolInfo_AddRef,
657 InternetProtocolInfo_Release,
658 InternetProtocolInfo_ParseUrl,
659 InternetProtocolInfo_CombineUrl,
660 InternetProtocolInfo_CompareUrl,
661 InternetProtocolInfo_QueryInfo
664 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
666 static HRESULT qiret;
667 static IClassFactory *expect_cf;
669 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
671 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
672 CHECK_EXPECT(QI_IInternetProtocolInfo);
673 ok(iface == expect_cf, "unexpected iface\n");
674 *ppv = &protocol_info;
678 ok(0, "unexpected call\n");
679 return E_NOINTERFACE;
682 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
687 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
692 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
693 REFIID riid, void **ppv)
695 CHECK_EXPECT(CreateInstance);
697 ok(iface == expect_cf, "unexpected iface\n");
698 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
699 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
700 ok(ppv != NULL, "ppv == NULL\n");
702 *ppv = &protocol_info;
706 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
708 ok(0, "unexpected call\n");
712 static const IClassFactoryVtbl ClassFactoryVtbl = {
713 ClassFactory_QueryInterface,
715 ClassFactory_Release,
716 ClassFactory_CreateInstance,
717 ClassFactory_LockServer
720 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
721 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
723 static void test_NameSpace(void)
725 IInternetSession *session;
730 static const WCHAR wszTest[] = {'t','e','s','t',0};
732 hres = CoInternetGetSession(0, &session, 0);
733 ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
737 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
738 wszTest, 0, NULL, 0);
739 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08lx\n", hres);
741 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
743 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08lx\n", hres);
745 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
746 wszTest, 0, NULL, 0);
747 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
749 qiret = E_NOINTERFACE;
750 expect_cf = &test_protocol_cf;
751 SET_EXPECT(QI_IInternetProtocolInfo);
752 SET_EXPECT(CreateInstance);
753 SET_EXPECT(ParseUrl);
755 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
757 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
759 CHECK_CALLED(QI_IInternetProtocolInfo);
760 CHECK_CALLED(CreateInstance);
761 CHECK_CALLED(ParseUrl);
764 SET_EXPECT(QI_IInternetProtocolInfo);
765 SET_EXPECT(ParseUrl);
767 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
769 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
771 CHECK_CALLED(QI_IInternetProtocolInfo);
772 CHECK_CALLED(ParseUrl);
774 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
775 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
777 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
779 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
781 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
782 wszTest, 0, NULL, 0);
783 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
785 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
786 wszTest, 0, NULL, 0);
787 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
789 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
790 wszTest, 0, NULL, 0);
791 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
793 SET_EXPECT(QI_IInternetProtocolInfo);
794 SET_EXPECT(ParseUrl);
796 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
798 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
800 CHECK_CALLED(QI_IInternetProtocolInfo);
801 CHECK_CALLED(ParseUrl);
803 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
804 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
806 SET_EXPECT(QI_IInternetProtocolInfo);
807 SET_EXPECT(ParseUrl);
809 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
811 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
813 CHECK_CALLED(QI_IInternetProtocolInfo);
814 CHECK_CALLED(ParseUrl);
816 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
817 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
819 expect_cf = &test_protocol_cf2;
820 SET_EXPECT(QI_IInternetProtocolInfo);
821 SET_EXPECT(ParseUrl);
823 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
825 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
827 CHECK_CALLED(QI_IInternetProtocolInfo);
828 CHECK_CALLED(ParseUrl);
830 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
831 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
832 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
833 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
834 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
835 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08lx\n", hres);
836 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
837 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08lx\n", hres);
839 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
840 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
842 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
844 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
846 IInternetSession_Release(session);
849 static ULONG WINAPI unk_Release(IUnknown *iface)
851 CHECK_EXPECT(unk_Release);
855 static const IUnknownVtbl unk_vtbl = {
861 static void test_ReleaseBindInfo(void)
864 IUnknown unk = { &unk_vtbl };
866 ReleaseBindInfo(NULL); /* shouldn't crash */
868 memset(&bi, 0, sizeof(bi));
869 bi.cbSize = sizeof(BINDINFO);
871 SET_EXPECT(unk_Release);
872 ReleaseBindInfo(&bi);
873 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%ld\n", bi.cbSize);
874 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
875 CHECK_CALLED(unk_Release);
877 memset(&bi, 0, sizeof(bi));
878 bi.cbSize = offsetof(BINDINFO, pUnk);
880 ReleaseBindInfo(&bi);
881 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%ld\n", bi.cbSize);
882 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
884 memset(&bi, 0, sizeof(bi));
886 ReleaseBindInfo(&bi);
887 ok(!bi.cbSize, "bi.cbSize=%ld, expected 0\n", bi.cbSize);
888 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
895 register_protocols();
897 test_CreateFormatEnum();
898 test_RegisterFormatEnumerator();
899 test_CoInternetParseUrl();
900 test_FindMimeFromData();
901 test_SecurityManager();
904 test_ReleaseBindInfo();