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};
333 static const WCHAR mimeImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
334 static const WCHAR mimeImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
335 static const WCHAR mimeImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
336 static const WCHAR mimeImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
338 static const struct {
342 {url1, mimeTextHtml},
343 {url2, mimeTextHtml},
344 {url3, mimeTextHtml},
351 static BYTE data1[] = "test data\n";
352 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
353 static BYTE data3[] = {0,0,0};
354 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
355 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
356 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
357 static BYTE data7[] = "<html>blahblah";
358 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
359 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
360 static BYTE data10[] = "<HtmL>blahblah";
361 static BYTE data11[] = "blah<HTML>blahblah";
362 static BYTE data12[] = "blah<HTMLblahblah";
363 static BYTE data13[] = "blahHTML>blahblah";
364 static BYTE data14[] = "blah<HTMblahblah";
365 static BYTE data15[] = {0xff,0xd8};
366 static BYTE data16[] = {0xff,0xd8,'h'};
367 static BYTE data17[] = {0,0xff,0xd8};
368 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
369 static BYTE data19[] = {'G','I','F','8','7','a'};
370 static BYTE data20[] = {'G','I','F','8','9','a'};
371 static BYTE data21[] = {'G','I','F','8','7'};
372 static BYTE data22[] = {'G','i','F','8','7','a'};
373 static BYTE data23[] = {'G','i','F','8','8','a'};
374 static BYTE data24[] = {'g','i','f','8','7','a'};
375 static BYTE data25[] = {'G','i','F','8','7','A'};
376 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
377 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
378 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
379 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
380 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
381 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
382 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
383 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
384 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
385 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
386 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
387 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
388 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
390 static const struct {
395 {data1, sizeof(data1), mimeTextPlain},
396 {data2, sizeof(data2), mimeAppOctetStream},
397 {data3, sizeof(data3), mimeAppOctetStream},
398 {data4, sizeof(data4), mimeAppOctetStream},
399 {data5, sizeof(data5), mimeTextPlain},
400 {data6, sizeof(data6), mimeTextPlain},
401 {data7, sizeof(data7), mimeTextHtml},
402 {data8, sizeof(data8), mimeTextHtml},
403 {data9, sizeof(data9), mimeTextHtml},
404 {data10, sizeof(data10), mimeTextHtml},
405 {data11, sizeof(data11), mimeTextHtml},
406 {data12, sizeof(data12), mimeTextHtml},
407 {data13, sizeof(data13), mimeTextPlain},
408 {data14, sizeof(data14), mimeTextPlain},
409 {data15, sizeof(data15), mimeTextPlain},
410 {data16, sizeof(data16), mimeImagePjpeg},
411 {data17, sizeof(data17), mimeAppOctetStream},
412 {data18, sizeof(data18), mimeTextHtml},
413 {data19, sizeof(data19), mimeImageGif},
414 {data20, sizeof(data20), mimeImageGif},
415 {data21, sizeof(data21), mimeTextPlain},
416 {data22, sizeof(data22), mimeImageGif},
417 {data23, sizeof(data23), mimeTextPlain},
418 {data24, sizeof(data24), mimeImageGif},
419 {data25, sizeof(data25), mimeImageGif},
420 {data26, sizeof(data26), mimeTextHtml},
421 {data27, sizeof(data27), mimeTextPlain},
422 {data28, sizeof(data28), mimeImageBmp},
423 {data29, sizeof(data29), mimeImageBmp},
424 {data30, sizeof(data30), mimeAppOctetStream},
425 {data31, sizeof(data31), mimeTextHtml},
426 {data32, sizeof(data32), mimeAppOctetStream},
427 {data33, sizeof(data33), mimeAppOctetStream},
428 {data34, sizeof(data34), mimeImageXPng},
429 {data35, sizeof(data35), mimeImageXPng},
430 {data36, sizeof(data36), mimeAppOctetStream},
431 {data37, sizeof(data37), mimeTextHtml},
432 {data38, sizeof(data38), mimeAppOctetStream}
435 static void test_FindMimeFromData(void)
441 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
442 mime = (LPWSTR)0xf0f0f0f0;
443 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
444 if(mime_tests[i].mime) {
445 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
446 ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
449 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
450 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
453 mime = (LPWSTR)0xf0f0f0f0;
454 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
455 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
456 ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
459 mime = (LPWSTR)0xf0f0f0f0;
460 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
461 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
462 ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
466 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
467 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
469 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
470 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
473 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
474 mimeTextHtml, 0, &mime, 0);
475 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
476 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
477 || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
478 ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
480 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
482 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
483 mimeImagePjpeg, 0, &mime, 0);
484 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
485 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
486 ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
488 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
493 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
494 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
495 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
498 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
499 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
500 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
503 hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
504 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
505 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
508 hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
509 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, excepted E_INVALIDARG\n", hres);
511 hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
512 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
514 hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
515 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
517 hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
518 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
520 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
521 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
522 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
525 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
526 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
529 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
530 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
531 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
532 '.','o','r','g',3,0,0,0};
533 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
534 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
537 static struct secmgr_test {
545 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
546 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
547 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
548 {url4, 3, S_OK, sizeof(secid4), secid4, S_OK},
549 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
550 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
551 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
554 static void test_SecurityManager(void)
557 IInternetSecurityManager *secmgr = NULL;
562 hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
563 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08lx\n", hres);
567 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
569 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
571 ok(hres == secmgr_tests[i].zone_hres,
572 "[%d] MapUrlToZone failed: %08lx, expected %08lx\n",
573 i, hres, secmgr_tests[i].zone_hres);
574 ok(zone == secmgr_tests[i].zone, "[%d] zone=%ld, expected %ld\n", i, zone,
575 secmgr_tests[i].zone);
578 memset(buf, 0xf0, sizeof(buf));
579 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
581 ok(hres == secmgr_tests[i].secid_hres,
582 "[%d] GetSecurityId failed: %08lx, expected %08lx\n",
583 i, hres, secmgr_tests[i].secid_hres);
584 if(secmgr_tests[i].secid) {
585 ok(size == secmgr_tests[i].secid_size, "[%d] size=%ld, expected %ld\n",
586 i, size, secmgr_tests[i].secid_size);
587 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
592 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
593 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08lx, expected E_INVALIDARG\n", hres);
596 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
597 ok(hres == E_INVALIDARG,
598 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
599 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
601 ok(hres == E_INVALIDARG,
602 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
603 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
605 ok(hres == E_INVALIDARG,
606 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
608 IInternetSecurityManager_Release(secmgr);
611 static void test_ZoneManager(void)
613 IInternetZoneManager *zonemgr = NULL;
617 hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
618 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08lx\n", hres);
622 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
623 sizeof(DWORD), URLZONEREG_DEFAULT);
624 ok(hres == S_OK, "GetZoneActionPolicy failed: %08lx\n", hres);
625 ok(*(DWORD*)buf == 1, "policy=%ld, expected 1\n", *(DWORD*)buf);
627 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
628 sizeof(DWORD), URLZONEREG_DEFAULT);
629 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
631 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
632 2, URLZONEREG_DEFAULT);
633 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
635 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
636 sizeof(DWORD), URLZONEREG_DEFAULT);
637 ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08lx, expected E_FAIL\n", hres);
639 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
640 sizeof(DWORD), URLZONEREG_DEFAULT);
641 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
643 IInternetZoneManager_Release(zonemgr);
646 static void register_protocols(void)
648 IInternetSession *session;
649 IClassFactory *factory;
652 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
654 hres = CoInternetGetSession(0, &session, 0);
655 ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
659 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
660 &IID_IClassFactory, (void**)&factory);
661 ok(hres == S_OK, "Coud not get AboutProtocol factory: %08lx\n", hres);
665 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
666 wszAbout, 0, NULL, 0);
667 IClassFactory_Release(factory);
671 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
672 REFIID riid, void **ppv)
674 ok(0, "unexpected call\n");
675 return E_NOINTERFACE;
678 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
683 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
688 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
689 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
690 DWORD *pcchResult, DWORD dwReserved)
692 CHECK_EXPECT(ParseUrl);
696 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
697 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
698 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
700 ok(0, "unexpected call\n");
704 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
705 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
707 ok(0, "unexpected call\n");
711 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
712 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
713 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
715 ok(0, "unexpected call\n");
719 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
720 InternetProtocolInfo_QueryInterface,
721 InternetProtocolInfo_AddRef,
722 InternetProtocolInfo_Release,
723 InternetProtocolInfo_ParseUrl,
724 InternetProtocolInfo_CombineUrl,
725 InternetProtocolInfo_CompareUrl,
726 InternetProtocolInfo_QueryInfo
729 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
731 static HRESULT qiret;
732 static IClassFactory *expect_cf;
734 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
736 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
737 CHECK_EXPECT(QI_IInternetProtocolInfo);
738 ok(iface == expect_cf, "unexpected iface\n");
739 *ppv = &protocol_info;
743 ok(0, "unexpected call\n");
744 return E_NOINTERFACE;
747 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
752 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
757 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
758 REFIID riid, void **ppv)
760 CHECK_EXPECT(CreateInstance);
762 ok(iface == expect_cf, "unexpected iface\n");
763 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
764 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
765 ok(ppv != NULL, "ppv == NULL\n");
767 *ppv = &protocol_info;
771 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
773 ok(0, "unexpected call\n");
777 static const IClassFactoryVtbl ClassFactoryVtbl = {
778 ClassFactory_QueryInterface,
780 ClassFactory_Release,
781 ClassFactory_CreateInstance,
782 ClassFactory_LockServer
785 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
786 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
788 static void test_NameSpace(void)
790 IInternetSession *session;
795 static const WCHAR wszTest[] = {'t','e','s','t',0};
797 hres = CoInternetGetSession(0, &session, 0);
798 ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
802 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
803 wszTest, 0, NULL, 0);
804 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08lx\n", hres);
806 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
808 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08lx\n", hres);
810 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
811 wszTest, 0, NULL, 0);
812 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
814 qiret = E_NOINTERFACE;
815 expect_cf = &test_protocol_cf;
816 SET_EXPECT(QI_IInternetProtocolInfo);
817 SET_EXPECT(CreateInstance);
818 SET_EXPECT(ParseUrl);
820 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
822 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
824 CHECK_CALLED(QI_IInternetProtocolInfo);
825 CHECK_CALLED(CreateInstance);
826 CHECK_CALLED(ParseUrl);
829 SET_EXPECT(QI_IInternetProtocolInfo);
830 SET_EXPECT(ParseUrl);
832 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
834 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
836 CHECK_CALLED(QI_IInternetProtocolInfo);
837 CHECK_CALLED(ParseUrl);
839 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, 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 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
847 wszTest, 0, NULL, 0);
848 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
850 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
851 wszTest, 0, NULL, 0);
852 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
854 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
855 wszTest, 0, NULL, 0);
856 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
858 SET_EXPECT(QI_IInternetProtocolInfo);
859 SET_EXPECT(ParseUrl);
861 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
863 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
865 CHECK_CALLED(QI_IInternetProtocolInfo);
866 CHECK_CALLED(ParseUrl);
868 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
869 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
871 SET_EXPECT(QI_IInternetProtocolInfo);
872 SET_EXPECT(ParseUrl);
874 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
876 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
878 CHECK_CALLED(QI_IInternetProtocolInfo);
879 CHECK_CALLED(ParseUrl);
881 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
882 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
884 expect_cf = &test_protocol_cf2;
885 SET_EXPECT(QI_IInternetProtocolInfo);
886 SET_EXPECT(ParseUrl);
888 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
890 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
892 CHECK_CALLED(QI_IInternetProtocolInfo);
893 CHECK_CALLED(ParseUrl);
895 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
896 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
897 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
898 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
899 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
900 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08lx\n", hres);
901 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
902 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08lx\n", hres);
904 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
905 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
907 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
909 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
911 IInternetSession_Release(session);
914 static ULONG WINAPI unk_Release(IUnknown *iface)
916 CHECK_EXPECT(unk_Release);
920 static const IUnknownVtbl unk_vtbl = {
926 static void test_ReleaseBindInfo(void)
929 IUnknown unk = { &unk_vtbl };
931 ReleaseBindInfo(NULL); /* shouldn't crash */
933 memset(&bi, 0, sizeof(bi));
934 bi.cbSize = sizeof(BINDINFO);
936 SET_EXPECT(unk_Release);
937 ReleaseBindInfo(&bi);
938 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%ld\n", bi.cbSize);
939 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
940 CHECK_CALLED(unk_Release);
942 memset(&bi, 0, sizeof(bi));
943 bi.cbSize = offsetof(BINDINFO, pUnk);
945 ReleaseBindInfo(&bi);
946 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%ld\n", bi.cbSize);
947 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
949 memset(&bi, 0, sizeof(bi));
951 ReleaseBindInfo(&bi);
952 ok(!bi.cbSize, "bi.cbSize=%ld, expected 0\n", bi.cbSize);
953 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
956 static void test_UrlMkGetSessionOption(void)
958 DWORD encoding, size;
961 size = encoding = 0xdeadbeef;
962 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
963 sizeof(encoding), &size, 0);
964 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08lx\n", hres);
965 ok(encoding != 0xdeadbeef, "encoding not changed\n");
966 ok(size == sizeof(encoding), "size=%ld\n", size);
968 size = encoding = 0xdeadbeef;
969 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
970 sizeof(encoding)+1, &size, 0);
971 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08lx\n", hres);
972 ok(encoding != 0xdeadbeef, "encoding not changed\n");
973 ok(size == sizeof(encoding), "size=%ld\n", size);
975 size = encoding = 0xdeadbeef;
976 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
977 sizeof(encoding)-1, &size, 0);
978 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08lx\n", hres);
979 ok(encoding == 0xdeadbeef, "encoding = %08lx, exepcted 0xdeadbeef\n", encoding);
980 ok(size == 0xdeadbeef, "size=%ld\n", size);
982 size = encoding = 0xdeadbeef;
983 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
984 sizeof(encoding)-1, &size, 0);
985 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08lx\n", hres);
986 ok(encoding == 0xdeadbeef, "encoding = %08lx, exepcted 0xdeadbeef\n", encoding);
987 ok(size == 0xdeadbeef, "size=%ld\n", size);
989 encoding = 0xdeadbeef;
990 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
991 sizeof(encoding)-1, NULL, 0);
992 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08lx\n", hres);
993 ok(encoding == 0xdeadbeef, "encoding = %08lx, exepcted 0xdeadbeef\n", encoding);
1000 register_protocols();
1002 test_CreateFormatEnum();
1003 test_RegisterFormatEnumerator();
1004 test_CoInternetParseUrl();
1005 test_FindMimeFromData();
1006 test_SecurityManager();
1009 test_ReleaseBindInfo();
1010 test_UrlMkGetSessionOption();