urlmon: Added image/gif filter.
[wine.git] / dlls / urlmon / tests / misc.c
blob24b703a9e499624f01c58de95f326b68f95ecb14
1 /*
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
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"
29 #include "initguid.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) \
40 do { \
41 ok(expect_ ##func, "unexpected call " #func "\n"); \
42 expect_ ## func = FALSE; \
43 called_ ## func = TRUE; \
44 }while(0)
46 #define CHECK_EXPECT2(func) \
47 do { \
48 ok(expect_ ##func, "unexpected call " #func "\n"); \
49 called_ ## func = TRUE; \
50 }while(0)
52 #define CHECK_CALLED(func) \
53 do { \
54 ok(called_ ## func, "expected " #func "\n"); \
55 expect_ ## func = called_ ## func = FALSE; \
56 }while(0)
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;
66 FORMATETC fetc[5];
67 ULONG ul;
68 HRESULT hres;
70 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
71 static FORMATETC formatetc[] = {
72 {0,&dev,0,0,0},
73 {0,&dev,0,1,0},
74 {0,NULL,0,2,0},
75 {0,NULL,0,3,0},
76 {0,NULL,0,4,0}
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);
89 if(FAILED(hres))
90 return;
92 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
93 ok(hres == E_INVALIDARG, "Next failed: %08lx, expected E_INVALIDARG\n", hres);
94 ul = 100;
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);
119 ul = 100;
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;
171 HRESULT hres;
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);
181 if(FAILED(hres))
182 return;
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',
246 '.','o','r','g',0};
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',
254 '.','j','p','g',0};
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};
265 struct parse_test {
266 LPCWSTR url;
267 HRESULT secur_hres;
268 LPCWSTR encoded_url;
269 HRESULT path_hres;
270 LPCWSTR path;
271 LPCWSTR schema;
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)
285 HRESULT hres;
286 DWORD size;
287 int i;
289 static WCHAR buf[4096];
291 memset(buf, 0xf0, sizeof(buf));
292 hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
293 3, &size, 0);
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};
336 static const struct {
337 LPCWSTR url;
338 LPCWSTR mime;
339 } mime_tests[] = {
340 {url1, mimeTextHtml},
341 {url2, mimeTextHtml},
342 {url3, mimeTextHtml},
343 {url4, NULL},
344 {url5, NULL},
345 {url6, NULL},
346 {url7, NULL}
349 static BYTE data1[] = "test data\n";
350 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
351 static BYTE data3[] = {0,0,0};
352 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
353 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
354 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
355 static BYTE data7[] = "<html>blahblah";
356 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
357 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
358 static BYTE data10[] = "<HtmL>blahblah";
359 static BYTE data11[] = "blah<HTML>blahblah";
360 static BYTE data12[] = "blah<HTMLblahblah";
361 static BYTE data13[] = "blahHTML>blahblah";
362 static BYTE data14[] = "blah<HTMblahblah";
363 static BYTE data15[] = {0xff,0xd8};
364 static BYTE data16[] = {0xff,0xd8,'h'};
365 static BYTE data17[] = {0,0xff,0xd8};
366 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
367 static BYTE data19[] = {'G','I','F','8','7','a'};
368 static BYTE data20[] = {'G','I','F','8','9','a'};
369 static BYTE data21[] = {'G','I','F','8','7'};
370 static BYTE data22[] = {'G','i','F','8','7','a'};
371 static BYTE data23[] = {'G','i','F','8','8','a'};
372 static BYTE data24[] = {'g','i','f','8','7','a'};
373 static BYTE data25[] = {'G','i','F','8','7','A'};
374 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
375 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
378 static const struct {
379 BYTE *data;
380 DWORD size;
381 LPCWSTR mime;
382 } mime_tests2[] = {
383 {data1, sizeof(data1), mimeTextPlain},
384 {data2, sizeof(data2), mimeAppOctetStream},
385 {data3, sizeof(data3), mimeAppOctetStream},
386 {data4, sizeof(data4), mimeAppOctetStream},
387 {data5, sizeof(data5), mimeTextPlain},
388 {data6, sizeof(data6), mimeTextPlain},
389 {data7, sizeof(data7), mimeTextHtml},
390 {data8, sizeof(data8), mimeTextHtml},
391 {data9, sizeof(data9), mimeTextHtml},
392 {data10, sizeof(data10), mimeTextHtml},
393 {data11, sizeof(data11), mimeTextHtml},
394 {data12, sizeof(data12), mimeTextHtml},
395 {data13, sizeof(data13), mimeTextPlain},
396 {data14, sizeof(data14), mimeTextPlain},
397 {data15, sizeof(data15), mimeTextPlain},
398 {data16, sizeof(data16), mimeImagePjpeg},
399 {data17, sizeof(data17), mimeAppOctetStream},
400 {data18, sizeof(data18), mimeTextHtml},
401 {data19, sizeof(data19), mimeImageGif},
402 {data20, sizeof(data20), mimeImageGif},
403 {data21, sizeof(data21), mimeTextPlain},
404 {data22, sizeof(data22), mimeImageGif},
405 {data23, sizeof(data23), mimeTextPlain},
406 {data24, sizeof(data24), mimeImageGif},
407 {data25, sizeof(data25), mimeImageGif},
408 {data26, sizeof(data26), mimeTextHtml},
409 {data27, sizeof(data27), mimeTextPlain}
412 static void test_FindMimeFromData(void)
414 HRESULT hres;
415 LPWSTR mime;
416 int i;
418 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
419 mime = (LPWSTR)0xf0f0f0f0;
420 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
421 if(mime_tests[i].mime) {
422 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
423 ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
424 CoTaskMemFree(mime);
425 }else {
426 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
427 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
430 mime = (LPWSTR)0xf0f0f0f0;
431 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
432 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
433 ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
434 CoTaskMemFree(mime);
436 mime = (LPWSTR)0xf0f0f0f0;
437 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
438 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
439 ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
440 CoTaskMemFree(mime);
443 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
444 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
445 NULL, 0, &mime, 0);
446 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
447 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
448 CoTaskMemFree(mime);
450 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
451 mimeTextHtml, 0, &mime, 0);
452 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
453 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
454 || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
455 ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
456 else
457 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
459 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
460 mimeImagePjpeg, 0, &mime, 0);
461 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
462 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
463 ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
464 else
465 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
467 CoTaskMemFree(mime);
470 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
471 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
472 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
473 CoTaskMemFree(mime);
475 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
476 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
477 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
478 CoTaskMemFree(mime);
480 hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
481 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
482 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
483 CoTaskMemFree(mime);
485 hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
486 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, excepted E_INVALIDARG\n", hres);
488 hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
489 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
491 hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
492 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
494 hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
495 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
497 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
498 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
499 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
500 CoTaskMemFree(mime);
502 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
503 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
506 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
507 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
508 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
509 '.','o','r','g',3,0,0,0};
510 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
511 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
512 3,0,0,0};
514 static struct secmgr_test {
515 LPCWSTR url;
516 DWORD zone;
517 HRESULT zone_hres;
518 DWORD secid_size;
519 const BYTE *secid;
520 HRESULT secid_hres;
521 } secmgr_tests[] = {
522 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
523 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
524 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
525 {url4, 3, S_OK, sizeof(secid4), secid4, S_OK},
526 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
527 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
528 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
531 static void test_SecurityManager(void)
533 int i;
534 IInternetSecurityManager *secmgr = NULL;
535 BYTE buf[512];
536 DWORD zone, size;
537 HRESULT hres;
539 hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
540 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08lx\n", hres);
541 if(FAILED(hres))
542 return;
544 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
545 zone = 100;
546 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
547 &zone, 0);
548 ok(hres == secmgr_tests[i].zone_hres,
549 "[%d] MapUrlToZone failed: %08lx, expected %08lx\n",
550 i, hres, secmgr_tests[i].zone_hres);
551 ok(zone == secmgr_tests[i].zone, "[%d] zone=%ld, expected %ld\n", i, zone,
552 secmgr_tests[i].zone);
554 size = sizeof(buf);
555 memset(buf, 0xf0, sizeof(buf));
556 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
557 buf, &size, 0);
558 ok(hres == secmgr_tests[i].secid_hres,
559 "[%d] GetSecurityId failed: %08lx, expected %08lx\n",
560 i, hres, secmgr_tests[i].secid_hres);
561 if(secmgr_tests[i].secid) {
562 ok(size == secmgr_tests[i].secid_size, "[%d] size=%ld, expected %ld\n",
563 i, size, secmgr_tests[i].secid_size);
564 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
568 zone = 100;
569 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
570 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08lx, expected E_INVALIDARG\n", hres);
572 size = sizeof(buf);
573 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
574 ok(hres == E_INVALIDARG,
575 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
576 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
577 NULL, &size, 0);
578 ok(hres == E_INVALIDARG,
579 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
580 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
581 buf, NULL, 0);
582 ok(hres == E_INVALIDARG,
583 "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
585 IInternetSecurityManager_Release(secmgr);
588 static void test_ZoneManager(void)
590 IInternetZoneManager *zonemgr = NULL;
591 BYTE buf[32];
592 HRESULT hres;
594 hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
595 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08lx\n", hres);
596 if(FAILED(hres))
597 return;
599 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
600 sizeof(DWORD), URLZONEREG_DEFAULT);
601 ok(hres == S_OK, "GetZoneActionPolicy failed: %08lx\n", hres);
602 ok(*(DWORD*)buf == 1, "policy=%ld, expected 1\n", *(DWORD*)buf);
604 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
605 sizeof(DWORD), URLZONEREG_DEFAULT);
606 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
608 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
609 2, URLZONEREG_DEFAULT);
610 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
612 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
613 sizeof(DWORD), URLZONEREG_DEFAULT);
614 ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08lx, expected E_FAIL\n", hres);
616 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
617 sizeof(DWORD), URLZONEREG_DEFAULT);
618 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
620 IInternetZoneManager_Release(zonemgr);
623 static void register_protocols(void)
625 IInternetSession *session;
626 IClassFactory *factory;
627 HRESULT hres;
629 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
631 hres = CoInternetGetSession(0, &session, 0);
632 ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
633 if(FAILED(hres))
634 return;
636 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
637 &IID_IClassFactory, (void**)&factory);
638 ok(hres == S_OK, "Coud not get AboutProtocol factory: %08lx\n", hres);
639 if(FAILED(hres))
640 return;
642 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
643 wszAbout, 0, NULL, 0);
644 IClassFactory_Release(factory);
648 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
649 REFIID riid, void **ppv)
651 ok(0, "unexpected call\n");
652 return E_NOINTERFACE;
655 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
657 return 2;
660 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
662 return 1;
665 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
666 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
667 DWORD *pcchResult, DWORD dwReserved)
669 CHECK_EXPECT(ParseUrl);
670 return E_NOTIMPL;
673 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
674 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
675 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
677 ok(0, "unexpected call\n");
678 return E_NOTIMPL;
681 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
682 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
684 ok(0, "unexpected call\n");
685 return E_NOTIMPL;
688 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
689 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
690 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
692 ok(0, "unexpected call\n");
693 return E_NOTIMPL;
696 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
697 InternetProtocolInfo_QueryInterface,
698 InternetProtocolInfo_AddRef,
699 InternetProtocolInfo_Release,
700 InternetProtocolInfo_ParseUrl,
701 InternetProtocolInfo_CombineUrl,
702 InternetProtocolInfo_CompareUrl,
703 InternetProtocolInfo_QueryInfo
706 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
708 static HRESULT qiret;
709 static IClassFactory *expect_cf;
711 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
713 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
714 CHECK_EXPECT(QI_IInternetProtocolInfo);
715 ok(iface == expect_cf, "unexpected iface\n");
716 *ppv = &protocol_info;
717 return qiret;
720 ok(0, "unexpected call\n");
721 return E_NOINTERFACE;
724 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
726 return 2;
729 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
731 return 1;
734 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
735 REFIID riid, void **ppv)
737 CHECK_EXPECT(CreateInstance);
739 ok(iface == expect_cf, "unexpected iface\n");
740 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
741 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
742 ok(ppv != NULL, "ppv == NULL\n");
744 *ppv = &protocol_info;
745 return S_OK;
748 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
750 ok(0, "unexpected call\n");
751 return S_OK;
754 static const IClassFactoryVtbl ClassFactoryVtbl = {
755 ClassFactory_QueryInterface,
756 ClassFactory_AddRef,
757 ClassFactory_Release,
758 ClassFactory_CreateInstance,
759 ClassFactory_LockServer
762 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
763 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
765 static void test_NameSpace(void)
767 IInternetSession *session;
768 WCHAR buf[200];
769 DWORD size;
770 HRESULT hres;
772 static const WCHAR wszTest[] = {'t','e','s','t',0};
774 hres = CoInternetGetSession(0, &session, 0);
775 ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
776 if(FAILED(hres))
777 return;
779 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
780 wszTest, 0, NULL, 0);
781 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08lx\n", hres);
783 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
784 NULL, 0, NULL, 0);
785 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08lx\n", hres);
787 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
788 wszTest, 0, NULL, 0);
789 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
791 qiret = E_NOINTERFACE;
792 expect_cf = &test_protocol_cf;
793 SET_EXPECT(QI_IInternetProtocolInfo);
794 SET_EXPECT(CreateInstance);
795 SET_EXPECT(ParseUrl);
797 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
798 &size, 0);
799 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
801 CHECK_CALLED(QI_IInternetProtocolInfo);
802 CHECK_CALLED(CreateInstance);
803 CHECK_CALLED(ParseUrl);
805 qiret = S_OK;
806 SET_EXPECT(QI_IInternetProtocolInfo);
807 SET_EXPECT(ParseUrl);
809 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
810 &size, 0);
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 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
820 &size, 0);
821 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
823 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
824 wszTest, 0, NULL, 0);
825 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
827 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
828 wszTest, 0, NULL, 0);
829 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
831 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
832 wszTest, 0, NULL, 0);
833 ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
835 SET_EXPECT(QI_IInternetProtocolInfo);
836 SET_EXPECT(ParseUrl);
838 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
839 &size, 0);
840 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
842 CHECK_CALLED(QI_IInternetProtocolInfo);
843 CHECK_CALLED(ParseUrl);
845 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
846 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
848 SET_EXPECT(QI_IInternetProtocolInfo);
849 SET_EXPECT(ParseUrl);
851 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
852 &size, 0);
853 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
855 CHECK_CALLED(QI_IInternetProtocolInfo);
856 CHECK_CALLED(ParseUrl);
858 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
859 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
861 expect_cf = &test_protocol_cf2;
862 SET_EXPECT(QI_IInternetProtocolInfo);
863 SET_EXPECT(ParseUrl);
865 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
866 &size, 0);
867 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
869 CHECK_CALLED(QI_IInternetProtocolInfo);
870 CHECK_CALLED(ParseUrl);
872 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
873 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
874 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
875 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
876 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
877 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08lx\n", hres);
878 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
879 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08lx\n", hres);
881 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
882 ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
884 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
885 &size, 0);
886 ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
888 IInternetSession_Release(session);
891 static ULONG WINAPI unk_Release(IUnknown *iface)
893 CHECK_EXPECT(unk_Release);
894 return 0;
897 static const IUnknownVtbl unk_vtbl = {
898 (void*)0xdeadbeef,
899 (void*)0xdeadbeef,
900 unk_Release
903 static void test_ReleaseBindInfo(void)
905 BINDINFO bi;
906 IUnknown unk = { &unk_vtbl };
908 ReleaseBindInfo(NULL); /* shouldn't crash */
910 memset(&bi, 0, sizeof(bi));
911 bi.cbSize = sizeof(BINDINFO);
912 bi.pUnk = &unk;
913 SET_EXPECT(unk_Release);
914 ReleaseBindInfo(&bi);
915 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%ld\n", bi.cbSize);
916 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
917 CHECK_CALLED(unk_Release);
919 memset(&bi, 0, sizeof(bi));
920 bi.cbSize = offsetof(BINDINFO, pUnk);
921 bi.pUnk = &unk;
922 ReleaseBindInfo(&bi);
923 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%ld\n", bi.cbSize);
924 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
926 memset(&bi, 0, sizeof(bi));
927 bi.pUnk = &unk;
928 ReleaseBindInfo(&bi);
929 ok(!bi.cbSize, "bi.cbSize=%ld, expected 0\n", bi.cbSize);
930 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
933 START_TEST(misc)
935 OleInitialize(NULL);
937 register_protocols();
939 test_CreateFormatEnum();
940 test_RegisterFormatEnumerator();
941 test_CoInternetParseUrl();
942 test_FindMimeFromData();
943 test_SecurityManager();
944 test_ZoneManager();
945 test_NameSpace();
946 test_ReleaseBindInfo();
948 OleUninitialize();