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
22 #include <wine/test.h>
32 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
34 #define DEFINE_EXPECT(func) \
35 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
37 #define SET_EXPECT(func) \
38 expect_ ## func = TRUE
40 #define CHECK_EXPECT(func) \
42 ok(expect_ ##func, "unexpected call " #func "\n"); \
43 expect_ ## func = FALSE; \
44 called_ ## func = TRUE; \
47 #define CHECK_EXPECT2(func) \
49 ok(expect_ ##func, "unexpected call " #func "\n"); \
50 called_ ## func = TRUE; \
53 #define CHECK_CALLED(func) \
55 ok(called_ ## func, "expected " #func "\n"); \
56 expect_ ## func = called_ ## func = FALSE; \
59 DEFINE_EXPECT(ParseUrl);
60 DEFINE_EXPECT(QI_IInternetProtocolInfo);
61 DEFINE_EXPECT(CreateInstance);
62 DEFINE_EXPECT(unk_Release);
64 static void test_CreateFormatEnum(void)
66 IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
71 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
72 static FORMATETC formatetc[] = {
80 hres = CreateFormatEnumerator(0, formatetc, &fenum);
81 ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
82 hres = CreateFormatEnumerator(0, formatetc, NULL);
83 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
84 hres = CreateFormatEnumerator(5, formatetc, NULL);
85 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
88 hres = CreateFormatEnumerator(5, formatetc, &fenum);
89 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
93 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
94 ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
96 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
97 ok(hres == S_OK, "Next failed: %08x\n", hres);
98 ok(ul == 0, "ul=%d, expected 0\n", ul);
100 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
101 ok(hres == S_OK, "Next failed: %08x\n", hres);
102 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
103 ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
104 ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
105 ok(ul == 2, "ul=%d, expected 2\n", ul);
107 hres = IEnumFORMATETC_Skip(fenum, 1);
108 ok(hres == S_OK, "Skip failed: %08x\n", hres);
110 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
111 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
112 ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
113 ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
114 ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
115 ok(ul == 2, "ul=%d, expected 2\n", ul);
117 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
118 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
119 ok(ul == 0, "ul=%d, expected 0\n", ul);
121 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
122 ok(hres == S_OK, "Next failed: %08x\n", hres);
123 ok(ul == 0, "ul=%d, expected 0\n", ul);
125 hres = IEnumFORMATETC_Skip(fenum, 3);
126 ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
128 hres = IEnumFORMATETC_Reset(fenum);
129 ok(hres == S_OK, "Reset failed: %08x\n", hres);
131 hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
132 ok(hres == S_OK, "Next failed: %08x\n", hres);
133 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
135 hres = IEnumFORMATETC_Reset(fenum);
136 ok(hres == S_OK, "Reset failed: %08x\n", hres);
138 hres = IEnumFORMATETC_Skip(fenum, 2);
139 ok(hres == S_OK, "Skip failed: %08x\n", hres);
141 hres = IEnumFORMATETC_Clone(fenum, NULL);
142 ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
144 hres = IEnumFORMATETC_Clone(fenum, &fenum2);
145 ok(hres == S_OK, "Clone failed: %08x\n", hres);
147 if(SUCCEEDED(hres)) {
148 ok(fenum != fenum2, "fenum == fenum2\n");
150 hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
151 ok(hres == S_OK, "Next failed: %08x\n", hres);
152 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
154 IEnumFORMATETC_Release(fenum2);
157 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
158 ok(hres == S_OK, "Next failed: %08x\n", hres);
159 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
161 hres = IEnumFORMATETC_Skip(fenum, 1);
162 ok(hres == S_OK, "Skip failed: %08x\n", hres);
164 IEnumFORMATETC_Release(fenum);
167 static void test_RegisterFormatEnumerator(void)
169 IBindCtx *bctx = NULL;
170 IEnumFORMATETC *format = NULL, *format2 = NULL;
171 IUnknown *unk = NULL;
174 static FORMATETC formatetc = {0,NULL,0,0,0};
175 static WCHAR wszEnumFORMATETC[] =
176 {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
178 CreateBindCtx(0, &bctx);
180 hres = CreateFormatEnumerator(1, &formatetc, &format);
181 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
185 hres = RegisterFormatEnumerator(NULL, format, 0);
186 ok(hres == E_INVALIDARG,
187 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
188 hres = RegisterFormatEnumerator(bctx, NULL, 0);
189 ok(hres == E_INVALIDARG,
190 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
192 hres = RegisterFormatEnumerator(bctx, format, 0);
193 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
195 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
196 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
197 ok(unk == (IUnknown*)format, "unk != format\n");
199 hres = RevokeFormatEnumerator(NULL, format);
200 ok(hres == E_INVALIDARG,
201 "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
203 hres = RevokeFormatEnumerator(bctx, format);
204 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
206 hres = RevokeFormatEnumerator(bctx, format);
207 ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
209 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
210 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
212 hres = RegisterFormatEnumerator(bctx, format, 0);
213 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
215 hres = CreateFormatEnumerator(1, &formatetc, &format2);
216 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
218 if(SUCCEEDED(hres)) {
219 hres = RevokeFormatEnumerator(bctx, format);
220 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
222 IEnumFORMATETC_Release(format2);
225 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
226 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
228 IEnumFORMATETC_Release(format);
230 hres = RegisterFormatEnumerator(bctx, format, 0);
231 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
232 hres = RevokeFormatEnumerator(bctx, NULL);
233 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
234 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
235 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
237 IBindCtx_Release(bctx);
240 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
241 '/','b','l','a','n','k','.','h','t','m',0};
242 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
243 static const WCHAR url3[] = {'f','i','l','e',':','c',':','\\','I','n','d','e','x','.','h','t','m',0};
244 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
245 '%','2','e','j','p','g',0};
246 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
248 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
249 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
250 'f','i','l','e','.','t','e','s','t',0};
251 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
254 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
257 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
258 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
260 static const WCHAR wszRes[] = {'r','e','s',0};
261 static const WCHAR wszFile[] = {'f','i','l','e',0};
262 static const WCHAR wszHttp[] = {'h','t','t','p',0};
263 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
264 static const WCHAR wszEmpty[] = {0};
275 static const struct parse_test parse_tests[] = {
276 {url1, S_OK, url1, E_INVALIDARG, NULL, wszRes},
277 {url2, E_FAIL, url2, E_INVALIDARG, NULL, wszEmpty},
278 {url3, E_FAIL, url3, S_OK, path3, wszFile},
279 {url4, E_FAIL, url4e, S_OK, path4, wszFile},
280 {url5, E_FAIL, url5, E_INVALIDARG, NULL, wszHttp},
281 {url6, S_OK, url6, E_INVALIDARG, NULL, wszAbout}
284 static void test_CoInternetParseUrl(void)
290 static WCHAR buf[4096];
292 memset(buf, 0xf0, sizeof(buf));
293 hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
295 ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
297 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
298 memset(buf, 0xf0, sizeof(buf));
299 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
300 sizeof(buf)/sizeof(WCHAR), &size, 0);
301 ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
302 i, hres, parse_tests[i].secur_hres);
304 memset(buf, 0xf0, sizeof(buf));
305 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
306 sizeof(buf)/sizeof(WCHAR), &size, 0);
307 ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
308 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
309 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
311 memset(buf, 0xf0, sizeof(buf));
312 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
313 sizeof(buf)/sizeof(WCHAR), &size, 0);
314 ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
315 i, hres, parse_tests[i].path_hres);
316 if(parse_tests[i].path) {
317 ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
318 ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
321 memset(buf, 0xf0, sizeof(buf));
322 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
323 sizeof(buf)/sizeof(WCHAR), &size, 0);
324 ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
325 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
326 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
330 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
331 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
332 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
333 'o','c','t','e','t','-','s','t','r','e','a','m',0};
334 static const WCHAR mimeImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
335 static const WCHAR mimeImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
336 static const WCHAR mimeImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
337 static const WCHAR mimeImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
339 static const struct {
343 {url1, mimeTextHtml},
344 {url2, mimeTextHtml},
345 {url3, mimeTextHtml},
352 static BYTE data1[] = "test data\n";
353 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
354 static BYTE data3[] = {0,0,0};
355 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
356 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
357 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
358 static BYTE data7[] = "<html>blahblah";
359 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
360 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
361 static BYTE data10[] = "<HtmL>blahblah";
362 static BYTE data11[] = "blah<HTML>blahblah";
363 static BYTE data12[] = "blah<HTMLblahblah";
364 static BYTE data13[] = "blahHTML>blahblah";
365 static BYTE data14[] = "blah<HTMblahblah";
366 static BYTE data15[] = {0xff,0xd8};
367 static BYTE data16[] = {0xff,0xd8,'h'};
368 static BYTE data17[] = {0,0xff,0xd8};
369 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
370 static BYTE data19[] = {'G','I','F','8','7','a'};
371 static BYTE data20[] = {'G','I','F','8','9','a'};
372 static BYTE data21[] = {'G','I','F','8','7'};
373 static BYTE data22[] = {'G','i','F','8','7','a'};
374 static BYTE data23[] = {'G','i','F','8','8','a'};
375 static BYTE data24[] = {'g','i','f','8','7','a'};
376 static BYTE data25[] = {'G','i','F','8','7','A'};
377 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
378 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
379 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
380 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
381 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
382 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
383 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
384 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
385 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
386 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
387 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
388 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
389 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
391 static const struct {
396 {data1, sizeof(data1), mimeTextPlain},
397 {data2, sizeof(data2), mimeAppOctetStream},
398 {data3, sizeof(data3), mimeAppOctetStream},
399 {data4, sizeof(data4), mimeAppOctetStream},
400 {data5, sizeof(data5), mimeTextPlain},
401 {data6, sizeof(data6), mimeTextPlain},
402 {data7, sizeof(data7), mimeTextHtml},
403 {data8, sizeof(data8), mimeTextHtml},
404 {data9, sizeof(data9), mimeTextHtml},
405 {data10, sizeof(data10), mimeTextHtml},
406 {data11, sizeof(data11), mimeTextHtml},
407 {data12, sizeof(data12), mimeTextHtml},
408 {data13, sizeof(data13), mimeTextPlain},
409 {data14, sizeof(data14), mimeTextPlain},
410 {data15, sizeof(data15), mimeTextPlain},
411 {data16, sizeof(data16), mimeImagePjpeg},
412 {data17, sizeof(data17), mimeAppOctetStream},
413 {data18, sizeof(data18), mimeTextHtml},
414 {data19, sizeof(data19), mimeImageGif},
415 {data20, sizeof(data20), mimeImageGif},
416 {data21, sizeof(data21), mimeTextPlain},
417 {data22, sizeof(data22), mimeImageGif},
418 {data23, sizeof(data23), mimeTextPlain},
419 {data24, sizeof(data24), mimeImageGif},
420 {data25, sizeof(data25), mimeImageGif},
421 {data26, sizeof(data26), mimeTextHtml},
422 {data27, sizeof(data27), mimeTextPlain},
423 {data28, sizeof(data28), mimeImageBmp},
424 {data29, sizeof(data29), mimeImageBmp},
425 {data30, sizeof(data30), mimeAppOctetStream},
426 {data31, sizeof(data31), mimeTextHtml},
427 {data32, sizeof(data32), mimeAppOctetStream},
428 {data33, sizeof(data33), mimeAppOctetStream},
429 {data34, sizeof(data34), mimeImageXPng},
430 {data35, sizeof(data35), mimeImageXPng},
431 {data36, sizeof(data36), mimeAppOctetStream},
432 {data37, sizeof(data37), mimeTextHtml},
433 {data38, sizeof(data38), mimeAppOctetStream}
436 static void test_FindMimeFromData(void)
442 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
443 mime = (LPWSTR)0xf0f0f0f0;
444 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
445 if(mime_tests[i].mime) {
446 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
447 ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
450 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
451 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
454 mime = (LPWSTR)0xf0f0f0f0;
455 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
456 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
457 ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
460 mime = (LPWSTR)0xf0f0f0f0;
461 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
462 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
463 ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
467 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
468 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
470 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
471 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
474 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
475 mimeTextHtml, 0, &mime, 0);
476 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
477 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
478 || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
479 ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
481 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
483 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
484 mimeImagePjpeg, 0, &mime, 0);
485 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
486 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
487 ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
489 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
494 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
495 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
496 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
499 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
500 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
501 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
504 hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
505 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
506 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
509 hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
510 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, excepted E_INVALIDARG\n", hres);
512 hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
513 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
515 hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
516 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
518 hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
519 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
521 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
522 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
523 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
526 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
527 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
530 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
531 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
532 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
533 '.','o','r','g',3,0,0,0};
534 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
535 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
538 static struct secmgr_test {
546 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
547 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
548 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
549 {url4, 3, S_OK, sizeof(secid4), secid4, S_OK},
550 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
551 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
552 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
555 static void test_SecurityManager(void)
558 IInternetSecurityManager *secmgr = NULL;
563 hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
564 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
568 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
570 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
572 ok(hres == secmgr_tests[i].zone_hres,
573 "[%d] MapUrlToZone failed: %08x, expected %08x\n",
574 i, hres, secmgr_tests[i].zone_hres);
575 ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
576 secmgr_tests[i].zone);
579 memset(buf, 0xf0, sizeof(buf));
580 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
582 ok(hres == secmgr_tests[i].secid_hres,
583 "[%d] GetSecurityId failed: %08x, expected %08x\n",
584 i, hres, secmgr_tests[i].secid_hres);
585 if(secmgr_tests[i].secid) {
586 ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
587 i, size, secmgr_tests[i].secid_size);
588 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
593 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
594 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
597 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
598 ok(hres == E_INVALIDARG,
599 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
600 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
602 ok(hres == E_INVALIDARG,
603 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
604 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
606 ok(hres == E_INVALIDARG,
607 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
609 IInternetSecurityManager_Release(secmgr);
612 static void test_ZoneManager(void)
614 IInternetZoneManager *zonemgr = NULL;
618 hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
619 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
623 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
624 sizeof(DWORD), URLZONEREG_DEFAULT);
625 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
626 ok(*(DWORD*)buf == 1, "policy=%d, expected 1\n", *(DWORD*)buf);
628 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
629 sizeof(DWORD), URLZONEREG_DEFAULT);
630 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
632 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
633 2, URLZONEREG_DEFAULT);
634 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
636 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
637 sizeof(DWORD), URLZONEREG_DEFAULT);
638 ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08x, expected E_FAIL\n", hres);
640 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
641 sizeof(DWORD), URLZONEREG_DEFAULT);
642 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
644 IInternetZoneManager_Release(zonemgr);
647 static void register_protocols(void)
649 IInternetSession *session;
650 IClassFactory *factory;
653 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
655 hres = CoInternetGetSession(0, &session, 0);
656 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
660 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
661 &IID_IClassFactory, (void**)&factory);
662 ok(hres == S_OK, "Coud not get AboutProtocol factory: %08x\n", hres);
666 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
667 wszAbout, 0, NULL, 0);
668 IClassFactory_Release(factory);
672 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
673 REFIID riid, void **ppv)
675 ok(0, "unexpected call\n");
676 return E_NOINTERFACE;
679 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
684 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
689 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
690 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
691 DWORD *pcchResult, DWORD dwReserved)
693 CHECK_EXPECT(ParseUrl);
697 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
698 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
699 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
701 ok(0, "unexpected call\n");
705 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
706 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
708 ok(0, "unexpected call\n");
712 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
713 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
714 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
716 ok(0, "unexpected call\n");
720 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
721 InternetProtocolInfo_QueryInterface,
722 InternetProtocolInfo_AddRef,
723 InternetProtocolInfo_Release,
724 InternetProtocolInfo_ParseUrl,
725 InternetProtocolInfo_CombineUrl,
726 InternetProtocolInfo_CompareUrl,
727 InternetProtocolInfo_QueryInfo
730 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
732 static HRESULT qiret;
733 static IClassFactory *expect_cf;
735 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
737 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
738 CHECK_EXPECT(QI_IInternetProtocolInfo);
739 ok(iface == expect_cf, "unexpected iface\n");
740 *ppv = &protocol_info;
744 ok(0, "unexpected call\n");
745 return E_NOINTERFACE;
748 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
753 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
758 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
759 REFIID riid, void **ppv)
761 CHECK_EXPECT(CreateInstance);
763 ok(iface == expect_cf, "unexpected iface\n");
764 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
765 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
766 ok(ppv != NULL, "ppv == NULL\n");
768 *ppv = &protocol_info;
772 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
774 ok(0, "unexpected call\n");
778 static const IClassFactoryVtbl ClassFactoryVtbl = {
779 ClassFactory_QueryInterface,
781 ClassFactory_Release,
782 ClassFactory_CreateInstance,
783 ClassFactory_LockServer
786 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
787 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
789 static void test_NameSpace(void)
791 IInternetSession *session;
796 static const WCHAR wszTest[] = {'t','e','s','t',0};
798 hres = CoInternetGetSession(0, &session, 0);
799 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
803 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
804 wszTest, 0, NULL, 0);
805 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
807 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
809 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
811 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
812 wszTest, 0, NULL, 0);
813 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
815 qiret = E_NOINTERFACE;
816 expect_cf = &test_protocol_cf;
817 SET_EXPECT(QI_IInternetProtocolInfo);
818 SET_EXPECT(CreateInstance);
819 SET_EXPECT(ParseUrl);
821 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
823 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
825 CHECK_CALLED(QI_IInternetProtocolInfo);
826 CHECK_CALLED(CreateInstance);
827 CHECK_CALLED(ParseUrl);
830 SET_EXPECT(QI_IInternetProtocolInfo);
831 SET_EXPECT(ParseUrl);
833 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
835 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
837 CHECK_CALLED(QI_IInternetProtocolInfo);
838 CHECK_CALLED(ParseUrl);
840 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
841 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
843 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
845 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
847 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
848 wszTest, 0, NULL, 0);
849 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
851 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
852 wszTest, 0, NULL, 0);
853 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
855 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
856 wszTest, 0, NULL, 0);
857 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
859 SET_EXPECT(QI_IInternetProtocolInfo);
860 SET_EXPECT(ParseUrl);
862 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
864 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
866 CHECK_CALLED(QI_IInternetProtocolInfo);
867 CHECK_CALLED(ParseUrl);
869 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
870 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
872 SET_EXPECT(QI_IInternetProtocolInfo);
873 SET_EXPECT(ParseUrl);
875 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
877 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
879 CHECK_CALLED(QI_IInternetProtocolInfo);
880 CHECK_CALLED(ParseUrl);
882 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
883 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
885 expect_cf = &test_protocol_cf2;
886 SET_EXPECT(QI_IInternetProtocolInfo);
887 SET_EXPECT(ParseUrl);
889 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
891 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
893 CHECK_CALLED(QI_IInternetProtocolInfo);
894 CHECK_CALLED(ParseUrl);
896 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
897 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
898 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
899 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
900 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
901 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
902 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
903 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
905 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
906 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
908 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
910 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
912 IInternetSession_Release(session);
915 static ULONG WINAPI unk_Release(IUnknown *iface)
917 CHECK_EXPECT(unk_Release);
921 static const IUnknownVtbl unk_vtbl = {
927 static void test_ReleaseBindInfo(void)
930 IUnknown unk = { &unk_vtbl };
932 ReleaseBindInfo(NULL); /* shouldn't crash */
934 memset(&bi, 0, sizeof(bi));
935 bi.cbSize = sizeof(BINDINFO);
937 SET_EXPECT(unk_Release);
938 ReleaseBindInfo(&bi);
939 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
940 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
941 CHECK_CALLED(unk_Release);
943 memset(&bi, 0, sizeof(bi));
944 bi.cbSize = offsetof(BINDINFO, pUnk);
946 ReleaseBindInfo(&bi);
947 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
948 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
950 memset(&bi, 0, sizeof(bi));
952 ReleaseBindInfo(&bi);
953 ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
954 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
957 static void test_UrlMkGetSessionOption(void)
959 DWORD encoding, size;
962 size = encoding = 0xdeadbeef;
963 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
964 sizeof(encoding), &size, 0);
965 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
966 ok(encoding != 0xdeadbeef, "encoding not changed\n");
967 ok(size == sizeof(encoding), "size=%d\n", size);
969 size = encoding = 0xdeadbeef;
970 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
971 sizeof(encoding)+1, &size, 0);
972 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
973 ok(encoding != 0xdeadbeef, "encoding not changed\n");
974 ok(size == sizeof(encoding), "size=%d\n", size);
976 size = encoding = 0xdeadbeef;
977 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
978 sizeof(encoding)-1, &size, 0);
979 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
980 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
981 ok(size == 0xdeadbeef, "size=%d\n", size);
983 size = encoding = 0xdeadbeef;
984 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
985 sizeof(encoding)-1, &size, 0);
986 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
987 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
988 ok(size == 0xdeadbeef, "size=%d\n", size);
990 encoding = 0xdeadbeef;
991 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
992 sizeof(encoding)-1, NULL, 0);
993 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
994 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1001 register_protocols();
1003 test_CreateFormatEnum();
1004 test_RegisterFormatEnumerator();
1005 test_CoInternetParseUrl();
1006 test_FindMimeFromData();
1007 test_SecurityManager();
1010 test_ReleaseBindInfo();
1011 test_UrlMkGetSessionOption();