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 #define NONAMELESSUNION
23 #include <wine/test.h>
34 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39 #define SET_EXPECT(func) \
40 expect_ ## func = TRUE
42 #define CHECK_EXPECT(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 expect_ ## func = FALSE; \
46 called_ ## func = TRUE; \
49 #define CHECK_EXPECT2(func) \
51 ok(expect_ ##func, "unexpected call " #func "\n"); \
52 called_ ## func = TRUE; \
55 #define CHECK_CALLED(func) \
57 ok(called_ ## func, "expected " #func "\n"); \
58 expect_ ## func = called_ ## func = FALSE; \
61 DEFINE_EXPECT(ParseUrl);
62 DEFINE_EXPECT(QI_IInternetProtocolInfo);
63 DEFINE_EXPECT(CreateInstance);
64 DEFINE_EXPECT(unk_Release);
66 static const char *debugstr_w(LPCWSTR str)
68 static char buf[1024];
69 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
73 static void test_CreateFormatEnum(void)
75 IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
80 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
81 static FORMATETC formatetc[] = {
89 hres = CreateFormatEnumerator(0, formatetc, &fenum);
90 ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
91 hres = CreateFormatEnumerator(0, formatetc, NULL);
92 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
93 hres = CreateFormatEnumerator(5, formatetc, NULL);
94 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
97 hres = CreateFormatEnumerator(5, formatetc, &fenum);
98 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
102 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
103 ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
105 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
106 ok(hres == S_OK, "Next failed: %08x\n", hres);
107 ok(ul == 0, "ul=%d, expected 0\n", ul);
109 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
110 ok(hres == S_OK, "Next failed: %08x\n", hres);
111 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
112 ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
113 ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
114 ok(ul == 2, "ul=%d, expected 2\n", ul);
116 hres = IEnumFORMATETC_Skip(fenum, 1);
117 ok(hres == S_OK, "Skip failed: %08x\n", hres);
119 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
120 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
121 ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
122 ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
123 ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
124 ok(ul == 2, "ul=%d, expected 2\n", ul);
126 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
127 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
128 ok(ul == 0, "ul=%d, expected 0\n", ul);
130 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
131 ok(hres == S_OK, "Next failed: %08x\n", hres);
132 ok(ul == 0, "ul=%d, expected 0\n", ul);
134 hres = IEnumFORMATETC_Skip(fenum, 3);
135 ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
137 hres = IEnumFORMATETC_Reset(fenum);
138 ok(hres == S_OK, "Reset failed: %08x\n", hres);
140 hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
141 ok(hres == S_OK, "Next failed: %08x\n", hres);
142 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
144 hres = IEnumFORMATETC_Reset(fenum);
145 ok(hres == S_OK, "Reset failed: %08x\n", hres);
147 hres = IEnumFORMATETC_Skip(fenum, 2);
148 ok(hres == S_OK, "Skip failed: %08x\n", hres);
150 hres = IEnumFORMATETC_Clone(fenum, NULL);
151 ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
153 hres = IEnumFORMATETC_Clone(fenum, &fenum2);
154 ok(hres == S_OK, "Clone failed: %08x\n", hres);
156 if(SUCCEEDED(hres)) {
157 ok(fenum != fenum2, "fenum == fenum2\n");
159 hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
160 ok(hres == S_OK, "Next failed: %08x\n", hres);
161 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
163 IEnumFORMATETC_Release(fenum2);
166 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
167 ok(hres == S_OK, "Next failed: %08x\n", hres);
168 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
170 hres = IEnumFORMATETC_Skip(fenum, 1);
171 ok(hres == S_OK, "Skip failed: %08x\n", hres);
173 IEnumFORMATETC_Release(fenum);
176 static void test_RegisterFormatEnumerator(void)
178 IBindCtx *bctx = NULL;
179 IEnumFORMATETC *format = NULL, *format2 = NULL;
180 IUnknown *unk = NULL;
183 static FORMATETC formatetc = {0,NULL,0,0,0};
184 static WCHAR wszEnumFORMATETC[] =
185 {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
187 CreateBindCtx(0, &bctx);
189 hres = CreateFormatEnumerator(1, &formatetc, &format);
190 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
194 hres = RegisterFormatEnumerator(NULL, format, 0);
195 ok(hres == E_INVALIDARG,
196 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
197 hres = RegisterFormatEnumerator(bctx, NULL, 0);
198 ok(hres == E_INVALIDARG,
199 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
201 hres = RegisterFormatEnumerator(bctx, format, 0);
202 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
204 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
205 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
206 ok(unk == (IUnknown*)format, "unk != format\n");
208 hres = RevokeFormatEnumerator(NULL, format);
209 ok(hres == E_INVALIDARG,
210 "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
212 hres = RevokeFormatEnumerator(bctx, format);
213 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
215 hres = RevokeFormatEnumerator(bctx, format);
216 ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
218 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
219 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
221 hres = RegisterFormatEnumerator(bctx, format, 0);
222 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
224 hres = CreateFormatEnumerator(1, &formatetc, &format2);
225 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
227 if(SUCCEEDED(hres)) {
228 hres = RevokeFormatEnumerator(bctx, format);
229 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
231 IEnumFORMATETC_Release(format2);
234 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
235 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
237 IEnumFORMATETC_Release(format);
239 hres = RegisterFormatEnumerator(bctx, format, 0);
240 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
241 hres = RevokeFormatEnumerator(bctx, NULL);
242 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
243 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
244 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
246 IEnumFORMATETC_Release(format);
247 IBindCtx_Release(bctx);
250 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
251 '/','b','l','a','n','k','.','h','t','m',0};
252 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
253 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
254 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
255 '%','2','e','j','p','g',0};
256 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
258 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
259 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
260 'f','i','l','e','.','t','e','s','t',0};
261 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
262 static const WCHAR url9[] =
263 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',
264 '/','s','i','t','e','/','a','b','o','u','t',0};
265 static const WCHAR url10[] = {'f','i','l','e',':','/','/','s','o','m','e','%','2','0','f','i','l','e',
268 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
271 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
272 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
274 static const WCHAR wszRes[] = {'r','e','s',0};
275 static const WCHAR wszFile[] = {'f','i','l','e',0};
276 static const WCHAR wszHttp[] = {'h','t','t','p',0};
277 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
278 static const WCHAR wszEmpty[] = {0};
289 static const struct parse_test parse_tests[] = {
290 {url1, S_OK, url1, E_INVALIDARG, NULL, wszRes},
291 {url2, E_FAIL, url2, E_INVALIDARG, NULL, wszEmpty},
292 {url3, E_FAIL, url3, S_OK, path3, wszFile},
293 {url4, E_FAIL, url4e, S_OK, path4, wszFile},
294 {url5, E_FAIL, url5, E_INVALIDARG, NULL, wszHttp},
295 {url6, S_OK, url6, E_INVALIDARG, NULL, wszAbout}
298 static void test_CoInternetParseUrl(void)
304 static WCHAR buf[4096];
306 memset(buf, 0xf0, sizeof(buf));
307 hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
309 ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
311 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
312 memset(buf, 0xf0, sizeof(buf));
313 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
314 sizeof(buf)/sizeof(WCHAR), &size, 0);
315 ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
316 i, hres, parse_tests[i].secur_hres);
318 memset(buf, 0xf0, sizeof(buf));
319 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
320 sizeof(buf)/sizeof(WCHAR), &size, 0);
321 ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
322 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
323 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
325 memset(buf, 0xf0, sizeof(buf));
326 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
327 sizeof(buf)/sizeof(WCHAR), &size, 0);
328 ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
329 i, hres, parse_tests[i].path_hres);
330 if(parse_tests[i].path) {
331 ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
332 ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
335 memset(buf, 0xf0, sizeof(buf));
336 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
337 sizeof(buf)/sizeof(WCHAR), &size, 0);
338 ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
339 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
340 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
344 static void test_CoInternetCompareUrl(void)
348 hres = CoInternetCompareUrl(url1, url1, 0);
349 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
351 hres = CoInternetCompareUrl(url1, url3, 0);
352 ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
354 hres = CoInternetCompareUrl(url3, url1, 0);
355 ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
358 static const struct {
361 } query_info_tests[] = {
372 static void test_CoInternetQueryInfo(void)
378 for(i=0; i < sizeof(query_info_tests)/sizeof(query_info_tests[0]); i++) {
380 memset(buf, '?', sizeof(buf));
381 hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), &cb, 0);
382 ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
383 ok(cb == sizeof(DWORD), "[%d] cb = %d\n", i, cb);
384 ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
385 i, *(DWORD*)buf, query_info_tests[i].uses_net);
387 hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, 3, &cb, 0);
388 ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
389 hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, NULL, sizeof(buf), &cb, 0);
390 ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
392 memset(buf, '?', sizeof(buf));
393 hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), NULL, 0);
394 ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
395 ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
396 i, *(DWORD*)buf, query_info_tests[i].uses_net);
400 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
401 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
402 static const WCHAR mimeTextRichtext[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
403 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
404 'o','c','t','e','t','-','s','t','r','e','a','m',0};
405 static const WCHAR mimeImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
406 static const WCHAR mimeImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
407 static const WCHAR mimeImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
408 static const WCHAR mimeImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
409 static const WCHAR mimeImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
410 static const WCHAR mimeVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
411 static const WCHAR mimeVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
412 static const WCHAR mimeAppPostscript[] =
413 {'a','p','p','l','i','c','a','t','i','o','n','/','p','o','s','t','s','c','r','i','p','t',0};
414 static const WCHAR mimeAppXCompressed[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
415 'x','-','c','o','m','p','r','e','s','s','e','d',0};
416 static const WCHAR mimeAppXZip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
417 'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
418 static const WCHAR mimeAppXGzip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
419 'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
420 static const WCHAR mimeAppJava[] = {'a','p','p','l','i','c','a','t','i','o','n','/','j','a','v','a',0};
421 static const WCHAR mimeAppPdf[] = {'a','p','p','l','i','c','a','t','i','o','n','/','p','d','f',0};
422 static const WCHAR mimeAppXMSDownload[] =
423 {'a','p','p','l','i','c','a','t','i','o','n','/','x','-','m','s','d','o','w','n','l','o','a','d',0};
424 static const WCHAR mimeAudioWav[] = {'a','u','d','i','o','/','w','a','v',0};
425 static const WCHAR mimeAudioBasic[] = {'a','u','d','i','o','/','b','a','s','i','c',0};
427 static const struct {
432 {url1, mimeTextHtml, S_OK},
433 {url2, mimeTextHtml, S_OK},
434 {url3, mimeTextHtml, S_OK},
435 {url4, NULL, E_FAIL},
436 {url5, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)},
437 {url6, NULL, E_FAIL},
438 {url7, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)}
441 static BYTE data1[] = "test data\n";
442 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
443 static BYTE data3[] = {0,0,0};
444 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
445 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
446 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
447 static BYTE data7[] = "<html>blahblah";
448 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
449 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
450 static BYTE data10[] = "<HtmL>blahblah";
451 static BYTE data11[] = "blah<HTML>blahblah";
452 static BYTE data12[] = "blah<HTMLblahblah";
453 static BYTE data13[] = "blahHTML>blahblah";
454 static BYTE data14[] = "blah<HTMblahblah";
455 static BYTE data15[] = {0xff,0xd8};
456 static BYTE data16[] = {0xff,0xd8,'h'};
457 static BYTE data17[] = {0,0xff,0xd8};
458 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
459 static BYTE data19[] = {'G','I','F','8','7','a'};
460 static BYTE data20[] = {'G','I','F','8','9','a'};
461 static BYTE data21[] = {'G','I','F','8','7'};
462 static BYTE data22[] = {'G','i','F','8','7','a'};
463 static BYTE data23[] = {'G','i','F','8','8','a'};
464 static BYTE data24[] = {'g','i','f','8','7','a'};
465 static BYTE data25[] = {'G','i','F','8','7','A'};
466 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
467 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
468 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
469 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
470 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
471 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
472 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
473 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
474 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
475 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
476 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
477 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
478 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
479 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a};
480 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
481 static BYTE data41[] = {0x4d,0x4d,0xff};
482 static BYTE data42[] = {0x4d,0x4d};
483 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
484 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
485 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
486 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
487 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
488 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
489 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
490 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
491 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
492 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
493 static BYTE data53[] = {0x00,0x00,0x01,0xba};
494 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
495 static BYTE data55[] = {0x1f,0x8b,'x'};
496 static BYTE data56[] = {0x1f};
497 static BYTE data57[] = {0x1f,0x8b,'<','h','t','m','l','>','t','e','s','t',0};
498 static BYTE data58[] = {0x1f,0x8b};
499 static BYTE data59[] = {0x50,0x4b,'x'};
500 static BYTE data60[] = {0x50,0x4b};
501 static BYTE data61[] = {0x50,0x4b,'<','h','t','m','l','>',0};
502 static BYTE data62[] = {0xca,0xfe,0xba,0xbe,'x'};
503 static BYTE data63[] = {0xca,0xfe,0xba,0xbe};
504 static BYTE data64[] = {0xca,0xfe,0xba,0xbe,'<','h','t','m','l','>',0};
505 static BYTE data65[] = {0x25,0x50,0x44,0x46,'x'};
506 static BYTE data66[] = {0x25,0x50,0x44,0x46};
507 static BYTE data67[] = {0x25,0x50,0x44,0x46,'x','<','h','t','m','l','>'};
508 static BYTE data68[] = {'M','Z','x'};
509 static BYTE data69[] = {'M','Z'};
510 static BYTE data70[] = {'M','Z','<','h','t','m','l','>',0xff};
511 static BYTE data71[] = {'{','\\','r','t','f',0};
512 static BYTE data72[] = {'{','\\','r','t','f'};
513 static BYTE data73[] = {' ','{','\\','r','t','f',' '};
514 static BYTE data74[] = {'{','\\','r','t','f','<','h','t','m','l','>',' '};
515 static BYTE data75[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E',0xff};
516 static BYTE data76[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E'};
517 static BYTE data77[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V',0xff,0xff};
518 static BYTE data78[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'<','h','t','m','l','>',0xff};
519 static BYTE data79[] = {'%','!',0xff};
520 static BYTE data80[] = {'%','!'};
521 static BYTE data81[] = {'%','!','P','S','<','h','t','m','l','>'};
522 static BYTE data82[] = {'.','s','n','d',0};
523 static BYTE data83[] = {'.','s','n','d'};
524 static BYTE data84[] = {'.','s','n','d',0,'<','h','t','m','l','>',1,1};
525 static BYTE data85[] = {'.','S','N','D',0};
527 static const struct {
530 LPCWSTR mime, mime_alt;
532 {data1, sizeof(data1), mimeTextPlain},
533 {data2, sizeof(data2), mimeAppOctetStream},
534 {data3, sizeof(data3), mimeAppOctetStream},
535 {data4, sizeof(data4), mimeAppOctetStream},
536 {data5, sizeof(data5), mimeTextPlain},
537 {data6, sizeof(data6), mimeTextPlain},
538 {data7, sizeof(data7), mimeTextHtml, mimeTextPlain /* IE8 */},
539 {data8, sizeof(data8), mimeTextHtml, mimeTextPlain /* IE8 */},
540 {data9, sizeof(data9), mimeTextHtml, mimeImagePjpeg /* IE8 */},
541 {data10, sizeof(data10), mimeTextHtml, mimeTextPlain /* IE8 */},
542 {data11, sizeof(data11), mimeTextHtml, mimeTextPlain /* IE8 */},
543 {data12, sizeof(data12), mimeTextHtml, mimeTextPlain /* IE8 */},
544 {data13, sizeof(data13), mimeTextPlain},
545 {data14, sizeof(data14), mimeTextPlain},
546 {data15, sizeof(data15), mimeTextPlain},
547 {data16, sizeof(data16), mimeImagePjpeg},
548 {data17, sizeof(data17), mimeAppOctetStream},
549 {data18, sizeof(data18), mimeTextHtml},
550 {data19, sizeof(data19), mimeImageGif},
551 {data20, sizeof(data20), mimeImageGif},
552 {data21, sizeof(data21), mimeTextPlain},
553 {data22, sizeof(data22), mimeImageGif},
554 {data23, sizeof(data23), mimeTextPlain},
555 {data24, sizeof(data24), mimeImageGif},
556 {data25, sizeof(data25), mimeImageGif},
557 {data26, sizeof(data26), mimeTextHtml, mimeImageGif /* IE8 */},
558 {data27, sizeof(data27), mimeTextPlain},
559 {data28, sizeof(data28), mimeImageBmp},
560 {data29, sizeof(data29), mimeImageBmp},
561 {data30, sizeof(data30), mimeAppOctetStream},
562 {data31, sizeof(data31), mimeTextHtml, mimeImageBmp /* IE8 */},
563 {data32, sizeof(data32), mimeAppOctetStream},
564 {data33, sizeof(data33), mimeAppOctetStream},
565 {data34, sizeof(data34), mimeImageXPng},
566 {data35, sizeof(data35), mimeImageXPng},
567 {data36, sizeof(data36), mimeAppOctetStream},
568 {data37, sizeof(data37), mimeTextHtml, mimeImageXPng /* IE8 */},
569 {data38, sizeof(data38), mimeAppOctetStream},
570 {data39, sizeof(data39), mimeImageTiff},
571 {data40, sizeof(data40), mimeTextHtml, mimeImageTiff /* IE8 */},
572 {data41, sizeof(data41), mimeImageTiff},
573 {data42, sizeof(data42), mimeTextPlain},
574 {data43, sizeof(data43), mimeAppOctetStream},
575 {data44, sizeof(data44), mimeVideoAvi},
576 {data45, sizeof(data45), mimeTextPlain},
577 {data46, sizeof(data46), mimeTextPlain},
578 {data47, sizeof(data47), mimeTextPlain},
579 {data48, sizeof(data48), mimeTextHtml, mimeVideoAvi /* IE8 */},
580 {data49, sizeof(data49), mimeVideoAvi},
581 {data50, sizeof(data50), mimeVideoMpeg},
582 {data51, sizeof(data51), mimeVideoMpeg},
583 {data52, sizeof(data52), mimeAppOctetStream},
584 {data53, sizeof(data53), mimeAppOctetStream},
585 {data54, sizeof(data54), mimeTextHtml, mimeVideoMpeg /* IE8 */},
586 {data55, sizeof(data55), mimeAppXGzip},
587 {data56, sizeof(data56), mimeTextPlain},
588 {data57, sizeof(data57), mimeTextHtml, mimeAppXGzip /* IE8 */},
589 {data58, sizeof(data58), mimeAppOctetStream},
590 {data59, sizeof(data59), mimeAppXZip},
591 {data60, sizeof(data60), mimeTextPlain},
592 {data61, sizeof(data61), mimeTextHtml, mimeAppXZip /* IE8 */},
593 {data62, sizeof(data62), mimeAppJava},
594 {data63, sizeof(data63), mimeTextPlain},
595 {data64, sizeof(data64), mimeTextHtml, mimeAppJava /* IE8 */},
596 {data65, sizeof(data65), mimeAppPdf},
597 {data66, sizeof(data66), mimeTextPlain},
598 {data67, sizeof(data67), mimeTextHtml, mimeAppPdf /* IE8 */},
599 {data68, sizeof(data68), mimeAppXMSDownload},
600 {data69, sizeof(data69), mimeTextPlain},
601 {data70, sizeof(data70), mimeTextHtml, mimeAppXMSDownload /* IE8 */},
602 {data71, sizeof(data71), mimeTextRichtext},
603 {data72, sizeof(data72), mimeTextPlain},
604 {data73, sizeof(data73), mimeTextPlain},
605 {data74, sizeof(data74), mimeTextHtml, mimeTextRichtext /* IE8 */},
606 {data75, sizeof(data75), mimeAudioWav},
607 {data76, sizeof(data76), mimeTextPlain},
608 {data77, sizeof(data77), mimeTextPlain},
609 {data78, sizeof(data78), mimeTextHtml, mimeTextPlain /* IE8 */},
610 {data79, sizeof(data79), mimeAppPostscript},
611 {data80, sizeof(data80), mimeTextPlain},
612 {data81, sizeof(data81), mimeTextHtml, mimeAppPostscript /* IE8 */},
613 {data82, sizeof(data82), mimeAudioBasic},
614 {data83, sizeof(data83), mimeTextPlain},
615 {data84, sizeof(data84), mimeTextHtml, mimeAudioBasic /* IE8 */},
616 {data85, sizeof(data85), mimeTextPlain}
619 static void test_FindMimeFromData(void)
625 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
626 mime = (LPWSTR)0xf0f0f0f0;
627 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
628 if(mime_tests[i].mime) {
629 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
630 ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
633 ok(hres == E_FAIL || hres == mime_tests[i].hres,
634 "[%d] FindMimeFromData failed: %08x, expected %08x\n",
635 i, hres, mime_tests[i].hres);
636 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
639 mime = (LPWSTR)0xf0f0f0f0;
640 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
641 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
642 ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
645 mime = (LPWSTR)0xf0f0f0f0;
646 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
647 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
648 ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
652 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
653 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
655 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
656 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime: %s\n", i, debugstr_w(mime));
659 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
660 mimeTextHtml, 0, &mime, 0);
661 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
662 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
663 || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
664 ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
666 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
669 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
670 mimeImagePjpeg, 0, &mime, 0);
671 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
672 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
673 ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
675 ok(!lstrcmpW(mime, mime_tests2[i].mime) ||
676 (mime_tests2[i].mime_alt && !lstrcmpW(mime, mime_tests2[i].mime_alt)),
677 "[%d] wrong mime, got '%s'\n", i, debugstr_w(mime));
682 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
683 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
684 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
687 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
688 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
689 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
692 hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
693 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
694 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
697 hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
698 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, excepted E_INVALIDARG\n", hres);
700 hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
701 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
703 hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
704 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
706 hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
707 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
709 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
710 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
711 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
714 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
715 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
718 static void register_protocols(void)
720 IInternetSession *session;
721 IClassFactory *factory;
724 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
726 hres = CoInternetGetSession(0, &session, 0);
727 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
731 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
732 &IID_IClassFactory, (void**)&factory);
733 ok(hres == S_OK, "Coud not get AboutProtocol factory: %08x\n", hres);
737 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
738 wszAbout, 0, NULL, 0);
739 IClassFactory_Release(factory);
741 IInternetSession_Release(session);
744 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
745 REFIID riid, void **ppv)
747 ok(0, "unexpected call\n");
748 return E_NOINTERFACE;
751 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
756 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
761 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
762 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
763 DWORD *pcchResult, DWORD dwReserved)
765 CHECK_EXPECT(ParseUrl);
769 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
770 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
771 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
773 ok(0, "unexpected call\n");
777 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
778 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
780 ok(0, "unexpected call\n");
784 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
785 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
786 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
788 ok(0, "unexpected call\n");
792 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
793 InternetProtocolInfo_QueryInterface,
794 InternetProtocolInfo_AddRef,
795 InternetProtocolInfo_Release,
796 InternetProtocolInfo_ParseUrl,
797 InternetProtocolInfo_CombineUrl,
798 InternetProtocolInfo_CompareUrl,
799 InternetProtocolInfo_QueryInfo
802 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
804 static HRESULT qiret;
805 static IClassFactory *expect_cf;
807 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
809 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
810 CHECK_EXPECT(QI_IInternetProtocolInfo);
811 ok(iface == expect_cf, "unexpected iface\n");
812 *ppv = &protocol_info;
816 ok(0, "unexpected call\n");
817 return E_NOINTERFACE;
820 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
825 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
830 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
831 REFIID riid, void **ppv)
833 ok(0, "unexpected call\n");
837 static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
838 REFIID riid, void **ppv)
840 CHECK_EXPECT(CreateInstance);
842 ok(iface == expect_cf, "unexpected iface\n");
843 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
844 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
845 ok(ppv != NULL, "ppv == NULL\n");
847 *ppv = &protocol_info;
851 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
853 ok(0, "unexpected call\n");
857 static const IClassFactoryVtbl ClassFactoryVtbl = {
858 ClassFactory_QueryInterface,
860 ClassFactory_Release,
861 ClassFactory_CreateInstance,
862 ClassFactory_LockServer
865 static const IClassFactoryVtbl ProtocolCFVtbl = {
866 ClassFactory_QueryInterface,
868 ClassFactory_Release,
869 ProtocolCF_CreateInstance,
870 ClassFactory_LockServer
873 static IClassFactory test_protocol_cf = { &ProtocolCFVtbl };
874 static IClassFactory test_protocol_cf2 = { &ProtocolCFVtbl };
875 static IClassFactory test_cf = { &ClassFactoryVtbl };
877 static void test_NameSpace(void)
879 IInternetSession *session;
884 static const WCHAR wszTest[] = {'t','e','s','t',0};
886 hres = CoInternetGetSession(0, &session, 0);
887 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
891 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
892 wszTest, 0, NULL, 0);
893 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
895 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
897 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
899 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
900 wszTest, 0, NULL, 0);
901 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
903 qiret = E_NOINTERFACE;
904 expect_cf = &test_protocol_cf;
905 SET_EXPECT(QI_IInternetProtocolInfo);
906 SET_EXPECT(CreateInstance);
907 SET_EXPECT(ParseUrl);
909 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
911 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
913 CHECK_CALLED(QI_IInternetProtocolInfo);
914 CHECK_CALLED(CreateInstance);
915 CHECK_CALLED(ParseUrl);
918 SET_EXPECT(QI_IInternetProtocolInfo);
919 SET_EXPECT(ParseUrl);
921 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
923 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
925 CHECK_CALLED(QI_IInternetProtocolInfo);
926 CHECK_CALLED(ParseUrl);
928 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
929 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
931 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
933 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
935 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
936 wszTest, 0, NULL, 0);
937 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
939 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
940 wszTest, 0, NULL, 0);
941 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
943 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
944 wszTest, 0, NULL, 0);
945 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
947 SET_EXPECT(QI_IInternetProtocolInfo);
948 SET_EXPECT(ParseUrl);
950 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
952 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
954 CHECK_CALLED(QI_IInternetProtocolInfo);
955 CHECK_CALLED(ParseUrl);
957 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
958 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
960 SET_EXPECT(QI_IInternetProtocolInfo);
961 SET_EXPECT(ParseUrl);
963 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
965 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
967 CHECK_CALLED(QI_IInternetProtocolInfo);
968 CHECK_CALLED(ParseUrl);
970 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
971 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
973 expect_cf = &test_protocol_cf2;
974 SET_EXPECT(QI_IInternetProtocolInfo);
975 SET_EXPECT(ParseUrl);
977 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
979 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
981 CHECK_CALLED(QI_IInternetProtocolInfo);
982 CHECK_CALLED(ParseUrl);
984 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
985 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
986 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
987 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
988 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
989 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
990 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
991 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
993 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
994 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
996 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
998 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1000 IInternetSession_Release(session);
1003 static void test_MimeFilter(void)
1005 IInternetSession *session;
1008 static const WCHAR mimeW[] = {'t','e','s','t','/','m','i','m','e',0};
1010 hres = CoInternetGetSession(0, &session, 0);
1011 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1015 hres = IInternetSession_RegisterMimeFilter(session, &test_cf, &IID_NULL, mimeW);
1016 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
1018 hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1019 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1021 hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1022 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1024 hres = IInternetSession_UnregisterMimeFilter(session, (void*)0xdeadbeef, mimeW);
1025 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1027 IInternetSession_Release(session);
1030 static ULONG WINAPI unk_Release(IUnknown *iface)
1032 CHECK_EXPECT(unk_Release);
1036 static const IUnknownVtbl unk_vtbl = {
1042 static void test_ReleaseBindInfo(void)
1045 IUnknown unk = { &unk_vtbl };
1047 ReleaseBindInfo(NULL); /* shouldn't crash */
1049 memset(&bi, 0, sizeof(bi));
1050 bi.cbSize = sizeof(BINDINFO);
1052 SET_EXPECT(unk_Release);
1053 ReleaseBindInfo(&bi);
1054 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
1055 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
1056 CHECK_CALLED(unk_Release);
1058 memset(&bi, 0, sizeof(bi));
1059 bi.cbSize = offsetof(BINDINFO, pUnk);
1061 ReleaseBindInfo(&bi);
1062 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
1063 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1065 memset(&bi, 0, sizeof(bi));
1067 ReleaseBindInfo(&bi);
1068 ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
1069 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1072 static void test_CopyStgMedium(void)
1078 static WCHAR fileW[] = {'f','i','l','e',0};
1080 memset(&src, 0xf0, sizeof(src));
1081 memset(&dst, 0xe0, sizeof(dst));
1082 memset(&empty, 0xf0, sizeof(empty));
1083 src.tymed = TYMED_NULL;
1084 src.pUnkForRelease = NULL;
1085 hres = CopyStgMedium(&src, &dst);
1086 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1087 ok(dst.tymed == TYMED_NULL, "tymed=%d\n", dst.tymed);
1088 ok(dst.u.hGlobal == empty, "u=%p\n", dst.u.hGlobal);
1089 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1091 memset(&dst, 0xe0, sizeof(dst));
1092 src.tymed = TYMED_ISTREAM;
1094 src.pUnkForRelease = NULL;
1095 hres = CopyStgMedium(&src, &dst);
1096 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1097 ok(dst.tymed == TYMED_ISTREAM, "tymed=%d\n", dst.tymed);
1098 ok(!dst.u.pstm, "pstm=%p\n", dst.u.pstm);
1099 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1101 memset(&dst, 0xe0, sizeof(dst));
1102 src.tymed = TYMED_FILE;
1103 src.u.lpszFileName = fileW;
1104 src.pUnkForRelease = NULL;
1105 hres = CopyStgMedium(&src, &dst);
1106 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1107 ok(dst.tymed == TYMED_FILE, "tymed=%d\n", dst.tymed);
1108 ok(dst.u.lpszFileName && dst.u.lpszFileName != fileW, "lpszFileName=%p\n", dst.u.lpszFileName);
1109 ok(!lstrcmpW(dst.u.lpszFileName, fileW), "wrong file name\n");
1110 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1112 hres = CopyStgMedium(&src, NULL);
1113 ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1114 hres = CopyStgMedium(NULL, &dst);
1115 ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1118 static void test_UrlMkGetSessionOption(void)
1120 DWORD encoding, size;
1123 size = encoding = 0xdeadbeef;
1124 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1125 sizeof(encoding), &size, 0);
1126 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1127 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1128 ok(size == sizeof(encoding), "size=%d\n", size);
1130 size = encoding = 0xdeadbeef;
1131 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1132 sizeof(encoding)+1, &size, 0);
1133 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1134 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1135 ok(size == sizeof(encoding), "size=%d\n", size);
1137 size = encoding = 0xdeadbeef;
1138 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1139 sizeof(encoding)-1, &size, 0);
1140 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1141 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1142 ok(size == 0xdeadbeef, "size=%d\n", size);
1144 size = encoding = 0xdeadbeef;
1145 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1146 sizeof(encoding)-1, &size, 0);
1147 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1148 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1149 ok(size == 0xdeadbeef, "size=%d\n", size);
1151 encoding = 0xdeadbeef;
1152 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1153 sizeof(encoding)-1, NULL, 0);
1154 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1155 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1158 static void test_ObtainUserAgentString(void)
1160 static const CHAR expected[] = "Mozilla/4.0 (compatible; MSIE ";
1166 hres = ObtainUserAgentString(0, NULL, NULL);
1167 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1170 hres = ObtainUserAgentString(0, NULL, &size);
1171 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1172 ok(size == 100, "size=%d, expected %d\n", size, 100);
1175 hres = ObtainUserAgentString(0, str, &size);
1176 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1177 ok(size > 0, "size=%d, expected non-zero\n", size);
1181 hres = ObtainUserAgentString(0, str, &size);
1182 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1183 ok(size > 0, "size=%d, expected non-zero\n", size);
1184 ok(str[0] == 'a', "str[0]=%c, expected 'a'\n", str[0]);
1187 hres = ObtainUserAgentString(1, str, &size);
1188 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1189 ok(size > 0, "size=%d, expected non-zero\n", size);
1191 str2 = HeapAlloc(GetProcessHeap(), 0, (size+20)*sizeof(CHAR));
1194 skip("skipping rest of ObtainUserAgent tests, out of memory\n");
1199 hres = ObtainUserAgentString(0, str2, &size);
1200 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1201 ok(size == saved, "size=%d, expected %d\n", size, saved);
1202 ok(strlen(expected) <= strlen(str2) &&
1203 !memcmp(expected, str2, strlen(expected)*sizeof(CHAR)),
1204 "user agent was \"%s\", expected to start with \"%s\"\n",
1208 hres = ObtainUserAgentString(0, str2, &size);
1209 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1210 ok(size == saved, "size=%d, expected %d\n", size, saved);
1212 HeapFree(GetProcessHeap(), 0, str2);
1215 static void test_MkParseDisplayNameEx(void)
1217 IMoniker *mon = NULL;
1224 static const WCHAR clsid_nameW[] = {'c','l','s','i','d',':',
1225 '2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8',
1226 '-','0','8','0','0','2','B','3','0','3','0','9','D',':',0};
1228 CreateBindCtx(0, &bctx);
1230 hres = MkParseDisplayNameEx(bctx, url9, &eaten, &mon);
1231 ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1232 ok(eaten == sizeof(url9)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1233 ok(mon != NULL, "mon == NULL\n");
1235 hres = IMoniker_GetDisplayName(mon, NULL, 0, &name);
1236 ok(hres == S_OK, "GetDiasplayName failed: %08x\n", hres);
1237 ok(!lstrcmpW(name, url9), "wrong display name %s\n", debugstr_w(name));
1238 CoTaskMemFree(name);
1240 hres = IMoniker_IsSystemMoniker(mon, &issys);
1241 ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1242 ok(issys == MKSYS_URLMONIKER, "issys=%x\n", issys);
1244 IMoniker_Release(mon);
1246 hres = MkParseDisplayNameEx(bctx, clsid_nameW, &eaten, &mon);
1247 ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1248 ok(eaten == sizeof(clsid_nameW)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1249 ok(mon != NULL, "mon == NULL\n");
1251 hres = IMoniker_IsSystemMoniker(mon, &issys);
1252 ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1253 ok(issys == MKSYS_CLASSMONIKER, "issys=%x\n", issys);
1255 IMoniker_Release(mon);
1257 hres = MkParseDisplayNameEx(bctx, url8, &eaten, &mon);
1258 ok(FAILED(hres), "MkParseDisplayNameEx succeeded: %08x\n", hres);
1260 IBindCtx_Release(bctx);
1265 OleInitialize(NULL);
1267 register_protocols();
1269 test_CreateFormatEnum();
1270 test_RegisterFormatEnumerator();
1271 test_CoInternetParseUrl();
1272 test_CoInternetCompareUrl();
1273 test_CoInternetQueryInfo();
1274 test_FindMimeFromData();
1277 test_ReleaseBindInfo();
1278 test_CopyStgMedium();
1279 test_UrlMkGetSessionOption();
1280 test_ObtainUserAgentString();
1281 test_MkParseDisplayNameEx();