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>
33 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
35 #define DEFINE_EXPECT(func) \
36 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
38 #define SET_EXPECT(func) \
39 expect_ ## func = TRUE
41 #define CHECK_EXPECT(func) \
43 ok(expect_ ##func, "unexpected call " #func "\n"); \
44 expect_ ## func = FALSE; \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT2(func) \
50 ok(expect_ ##func, "unexpected call " #func "\n"); \
51 called_ ## func = TRUE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 DEFINE_EXPECT(ParseUrl);
61 DEFINE_EXPECT(QI_IInternetProtocolInfo);
62 DEFINE_EXPECT(CreateInstance);
63 DEFINE_EXPECT(unk_Release);
65 static void test_CreateFormatEnum(void)
67 IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
72 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
73 static FORMATETC formatetc[] = {
81 hres = CreateFormatEnumerator(0, formatetc, &fenum);
82 ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
83 hres = CreateFormatEnumerator(0, formatetc, NULL);
84 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
85 hres = CreateFormatEnumerator(5, formatetc, NULL);
86 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
89 hres = CreateFormatEnumerator(5, formatetc, &fenum);
90 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
94 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
95 ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
97 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
98 ok(hres == S_OK, "Next failed: %08x\n", hres);
99 ok(ul == 0, "ul=%d, expected 0\n", ul);
101 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
102 ok(hres == S_OK, "Next failed: %08x\n", hres);
103 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
104 ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
105 ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
106 ok(ul == 2, "ul=%d, expected 2\n", ul);
108 hres = IEnumFORMATETC_Skip(fenum, 1);
109 ok(hres == S_OK, "Skip failed: %08x\n", hres);
111 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
112 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
113 ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
114 ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
115 ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
116 ok(ul == 2, "ul=%d, expected 2\n", ul);
118 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
119 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
120 ok(ul == 0, "ul=%d, expected 0\n", ul);
122 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
123 ok(hres == S_OK, "Next failed: %08x\n", hres);
124 ok(ul == 0, "ul=%d, expected 0\n", ul);
126 hres = IEnumFORMATETC_Skip(fenum, 3);
127 ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
129 hres = IEnumFORMATETC_Reset(fenum);
130 ok(hres == S_OK, "Reset failed: %08x\n", hres);
132 hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
133 ok(hres == S_OK, "Next failed: %08x\n", hres);
134 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
136 hres = IEnumFORMATETC_Reset(fenum);
137 ok(hres == S_OK, "Reset failed: %08x\n", hres);
139 hres = IEnumFORMATETC_Skip(fenum, 2);
140 ok(hres == S_OK, "Skip failed: %08x\n", hres);
142 hres = IEnumFORMATETC_Clone(fenum, NULL);
143 ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
145 hres = IEnumFORMATETC_Clone(fenum, &fenum2);
146 ok(hres == S_OK, "Clone failed: %08x\n", hres);
148 if(SUCCEEDED(hres)) {
149 ok(fenum != fenum2, "fenum == fenum2\n");
151 hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
152 ok(hres == S_OK, "Next failed: %08x\n", hres);
153 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
155 IEnumFORMATETC_Release(fenum2);
158 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
159 ok(hres == S_OK, "Next failed: %08x\n", hres);
160 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
162 hres = IEnumFORMATETC_Skip(fenum, 1);
163 ok(hres == S_OK, "Skip failed: %08x\n", hres);
165 IEnumFORMATETC_Release(fenum);
168 static void test_RegisterFormatEnumerator(void)
170 IBindCtx *bctx = NULL;
171 IEnumFORMATETC *format = NULL, *format2 = NULL;
172 IUnknown *unk = NULL;
175 static FORMATETC formatetc = {0,NULL,0,0,0};
176 static WCHAR wszEnumFORMATETC[] =
177 {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
179 CreateBindCtx(0, &bctx);
181 hres = CreateFormatEnumerator(1, &formatetc, &format);
182 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
186 hres = RegisterFormatEnumerator(NULL, format, 0);
187 ok(hres == E_INVALIDARG,
188 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
189 hres = RegisterFormatEnumerator(bctx, NULL, 0);
190 ok(hres == E_INVALIDARG,
191 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
193 hres = RegisterFormatEnumerator(bctx, format, 0);
194 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
196 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
197 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
198 ok(unk == (IUnknown*)format, "unk != format\n");
200 hres = RevokeFormatEnumerator(NULL, format);
201 ok(hres == E_INVALIDARG,
202 "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
204 hres = RevokeFormatEnumerator(bctx, format);
205 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
207 hres = RevokeFormatEnumerator(bctx, format);
208 ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
210 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
211 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
213 hres = RegisterFormatEnumerator(bctx, format, 0);
214 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
216 hres = CreateFormatEnumerator(1, &formatetc, &format2);
217 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
219 if(SUCCEEDED(hres)) {
220 hres = RevokeFormatEnumerator(bctx, format);
221 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
223 IEnumFORMATETC_Release(format2);
226 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
227 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
229 IEnumFORMATETC_Release(format);
231 hres = RegisterFormatEnumerator(bctx, format, 0);
232 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
233 hres = RevokeFormatEnumerator(bctx, NULL);
234 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
235 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
236 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
238 IEnumFORMATETC_Release(format);
239 IBindCtx_Release(bctx);
242 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
243 '/','b','l','a','n','k','.','h','t','m',0};
244 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
245 static const WCHAR url3[] = {'f','i','l','e',':','c',':','\\','I','n','d','e','x','.','h','t','m',0};
246 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
247 '%','2','e','j','p','g',0};
248 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
250 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
251 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
252 'f','i','l','e','.','t','e','s','t',0};
253 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
256 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
259 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
260 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
262 static const WCHAR wszRes[] = {'r','e','s',0};
263 static const WCHAR wszFile[] = {'f','i','l','e',0};
264 static const WCHAR wszHttp[] = {'h','t','t','p',0};
265 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
266 static const WCHAR wszEmpty[] = {0};
277 static const struct parse_test parse_tests[] = {
278 {url1, S_OK, url1, E_INVALIDARG, NULL, wszRes},
279 {url2, E_FAIL, url2, E_INVALIDARG, NULL, wszEmpty},
280 {url3, E_FAIL, url3, S_OK, path3, wszFile},
281 {url4, E_FAIL, url4e, S_OK, path4, wszFile},
282 {url5, E_FAIL, url5, E_INVALIDARG, NULL, wszHttp},
283 {url6, S_OK, url6, E_INVALIDARG, NULL, wszAbout}
286 static void test_CoInternetParseUrl(void)
292 static WCHAR buf[4096];
294 memset(buf, 0xf0, sizeof(buf));
295 hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
297 ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
299 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
300 memset(buf, 0xf0, sizeof(buf));
301 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
302 sizeof(buf)/sizeof(WCHAR), &size, 0);
303 ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
304 i, hres, parse_tests[i].secur_hres);
306 memset(buf, 0xf0, sizeof(buf));
307 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
308 sizeof(buf)/sizeof(WCHAR), &size, 0);
309 ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
310 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
311 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
313 memset(buf, 0xf0, sizeof(buf));
314 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
315 sizeof(buf)/sizeof(WCHAR), &size, 0);
316 ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
317 i, hres, parse_tests[i].path_hres);
318 if(parse_tests[i].path) {
319 ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
320 ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
323 memset(buf, 0xf0, sizeof(buf));
324 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
325 sizeof(buf)/sizeof(WCHAR), &size, 0);
326 ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
327 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
328 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
332 static void test_CoInternetCompareUrl(void)
336 hres = CoInternetCompareUrl(url1, url1, 0);
337 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
339 hres = CoInternetCompareUrl(url1, url3, 0);
340 ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
342 hres = CoInternetCompareUrl(url3, url1, 0);
343 ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
346 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
347 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
348 static const WCHAR mimeTextRichtext[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
349 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
350 'o','c','t','e','t','-','s','t','r','e','a','m',0};
351 static const WCHAR mimeImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
352 static const WCHAR mimeImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
353 static const WCHAR mimeImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
354 static const WCHAR mimeImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
355 static const WCHAR mimeImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
356 static const WCHAR mimeVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
357 static const WCHAR mimeVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
358 static const WCHAR mimeAppXCompressed[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
359 'x','-','c','o','m','p','r','e','s','s','e','d',0};
360 static const WCHAR mimeAppXZip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
361 'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
362 static const WCHAR mimeAppXGzip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
363 'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
364 static const WCHAR mimeAppJava[] = {'a','p','p','l','i','c','a','t','i','o','n','/','j','a','v','a',0};
365 static const WCHAR mimeAppPdf[] = {'a','p','p','l','i','c','a','t','i','o','n','/','p','d','f',0};
366 static const WCHAR mimeAppXMSDownload[] =
367 {'a','p','p','l','i','c','a','t','i','o','n','/','x','-','m','s','d','o','w','n','l','o','a','d',0};
369 static const struct {
374 {url1, mimeTextHtml, S_OK},
375 {url2, mimeTextHtml, S_OK},
376 {url3, mimeTextHtml, S_OK},
377 {url4, NULL, E_FAIL},
378 {url5, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)},
379 {url6, NULL, E_FAIL},
380 {url7, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)}
383 static BYTE data1[] = "test data\n";
384 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
385 static BYTE data3[] = {0,0,0};
386 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
387 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
388 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
389 static BYTE data7[] = "<html>blahblah";
390 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
391 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
392 static BYTE data10[] = "<HtmL>blahblah";
393 static BYTE data11[] = "blah<HTML>blahblah";
394 static BYTE data12[] = "blah<HTMLblahblah";
395 static BYTE data13[] = "blahHTML>blahblah";
396 static BYTE data14[] = "blah<HTMblahblah";
397 static BYTE data15[] = {0xff,0xd8};
398 static BYTE data16[] = {0xff,0xd8,'h'};
399 static BYTE data17[] = {0,0xff,0xd8};
400 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
401 static BYTE data19[] = {'G','I','F','8','7','a'};
402 static BYTE data20[] = {'G','I','F','8','9','a'};
403 static BYTE data21[] = {'G','I','F','8','7'};
404 static BYTE data22[] = {'G','i','F','8','7','a'};
405 static BYTE data23[] = {'G','i','F','8','8','a'};
406 static BYTE data24[] = {'g','i','f','8','7','a'};
407 static BYTE data25[] = {'G','i','F','8','7','A'};
408 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
409 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
410 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
411 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
412 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
413 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
414 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
415 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
416 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
417 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
418 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
419 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
420 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
421 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a};
422 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
423 static BYTE data41[] = {0x4d,0x4d,0xff};
424 static BYTE data42[] = {0x4d,0x4d};
425 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
426 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
427 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
428 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
429 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
430 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
431 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
432 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
433 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
434 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
435 static BYTE data53[] = {0x00,0x00,0x01,0xba};
436 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
437 static BYTE data55[] = {0x1f,0x8b,'x'};
438 static BYTE data56[] = {0x1f};
439 static BYTE data57[] = {0x1f,0x8b,'<','h','t','m','l','>','t','e','s','t',0};
440 static BYTE data58[] = {0x1f,0x8b};
441 static BYTE data59[] = {0x50,0x4b,'x'};
442 static BYTE data60[] = {0x50,0x4b};
443 static BYTE data61[] = {0x50,0x4b,'<','h','t','m','l','>',0};
444 static BYTE data62[] = {0xca,0xfe,0xba,0xbe,'x'};
445 static BYTE data63[] = {0xca,0xfe,0xba,0xbe};
446 static BYTE data64[] = {0xca,0xfe,0xba,0xbe,'<','h','t','m','l','>',0};
447 static BYTE data65[] = {0x25,0x50,0x44,0x46,'x'};
448 static BYTE data66[] = {0x25,0x50,0x44,0x46};
449 static BYTE data67[] = {0x25,0x50,0x44,0x46,'x','<','h','t','m','l','>'};
450 static BYTE data68[] = {'M','Z','x'};
451 static BYTE data69[] = {'M','Z'};
452 static BYTE data70[] = {'M','Z','<','h','t','m','l','>',0xff};
453 static BYTE data71[] = {'{','\\','r','t','f',0};
454 static BYTE data72[] = {'{','\\','r','t','f'};
455 static BYTE data73[] = {' ','{','\\','r','t','f',' '};
456 static BYTE data74[] = {'{','\\','r','t','f','<','h','t','m','l','>',' '};
458 static const struct {
463 {data1, sizeof(data1), mimeTextPlain},
464 {data2, sizeof(data2), mimeAppOctetStream},
465 {data3, sizeof(data3), mimeAppOctetStream},
466 {data4, sizeof(data4), mimeAppOctetStream},
467 {data5, sizeof(data5), mimeTextPlain},
468 {data6, sizeof(data6), mimeTextPlain},
469 {data7, sizeof(data7), mimeTextHtml},
470 {data8, sizeof(data8), mimeTextHtml},
471 {data9, sizeof(data9), mimeTextHtml},
472 {data10, sizeof(data10), mimeTextHtml},
473 {data11, sizeof(data11), mimeTextHtml},
474 {data12, sizeof(data12), mimeTextHtml},
475 {data13, sizeof(data13), mimeTextPlain},
476 {data14, sizeof(data14), mimeTextPlain},
477 {data15, sizeof(data15), mimeTextPlain},
478 {data16, sizeof(data16), mimeImagePjpeg},
479 {data17, sizeof(data17), mimeAppOctetStream},
480 {data18, sizeof(data18), mimeTextHtml},
481 {data19, sizeof(data19), mimeImageGif},
482 {data20, sizeof(data20), mimeImageGif},
483 {data21, sizeof(data21), mimeTextPlain},
484 {data22, sizeof(data22), mimeImageGif},
485 {data23, sizeof(data23), mimeTextPlain},
486 {data24, sizeof(data24), mimeImageGif},
487 {data25, sizeof(data25), mimeImageGif},
488 {data26, sizeof(data26), mimeTextHtml},
489 {data27, sizeof(data27), mimeTextPlain},
490 {data28, sizeof(data28), mimeImageBmp},
491 {data29, sizeof(data29), mimeImageBmp},
492 {data30, sizeof(data30), mimeAppOctetStream},
493 {data31, sizeof(data31), mimeTextHtml},
494 {data32, sizeof(data32), mimeAppOctetStream},
495 {data33, sizeof(data33), mimeAppOctetStream},
496 {data34, sizeof(data34), mimeImageXPng},
497 {data35, sizeof(data35), mimeImageXPng},
498 {data36, sizeof(data36), mimeAppOctetStream},
499 {data37, sizeof(data37), mimeTextHtml},
500 {data38, sizeof(data38), mimeAppOctetStream},
501 {data39, sizeof(data39), mimeImageTiff},
502 {data40, sizeof(data40), mimeTextHtml},
503 {data41, sizeof(data41), mimeImageTiff},
504 {data42, sizeof(data42), mimeTextPlain},
505 {data43, sizeof(data43), mimeAppOctetStream},
506 {data44, sizeof(data44), mimeVideoAvi},
507 {data45, sizeof(data45), mimeTextPlain},
508 {data46, sizeof(data46), mimeTextPlain},
509 {data47, sizeof(data47), mimeTextPlain},
510 {data48, sizeof(data48), mimeTextHtml},
511 {data49, sizeof(data49), mimeVideoAvi},
512 {data50, sizeof(data50), mimeVideoMpeg},
513 {data51, sizeof(data51), mimeVideoMpeg},
514 {data52, sizeof(data52), mimeAppOctetStream},
515 {data53, sizeof(data53), mimeAppOctetStream},
516 {data54, sizeof(data54), mimeTextHtml},
517 {data55, sizeof(data55), mimeAppXGzip},
518 {data56, sizeof(data56), mimeTextPlain},
519 {data57, sizeof(data57), mimeTextHtml},
520 {data58, sizeof(data58), mimeAppOctetStream},
521 {data59, sizeof(data59), mimeAppXZip},
522 {data60, sizeof(data60), mimeTextPlain},
523 {data61, sizeof(data61), mimeTextHtml},
524 {data62, sizeof(data62), mimeAppJava},
525 {data63, sizeof(data63), mimeTextPlain},
526 {data64, sizeof(data64), mimeTextHtml},
527 {data65, sizeof(data65), mimeAppPdf},
528 {data66, sizeof(data66), mimeTextPlain},
529 {data67, sizeof(data67), mimeTextHtml},
530 {data68, sizeof(data68), mimeAppXMSDownload},
531 {data69, sizeof(data69), mimeTextPlain},
532 {data70, sizeof(data70), mimeTextHtml},
533 {data71, sizeof(data71), mimeTextRichtext},
534 {data72, sizeof(data72), mimeTextPlain},
535 {data73, sizeof(data73), mimeTextPlain},
536 {data74, sizeof(data74), mimeTextHtml}
539 static void test_FindMimeFromData(void)
545 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
546 mime = (LPWSTR)0xf0f0f0f0;
547 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
548 if(mime_tests[i].mime) {
549 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
550 ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
553 ok(hres == E_FAIL || hres == mime_tests[i].hres,
554 "[%d] FindMimeFromData failed: %08x, expected %08x\n",
555 i, hres, mime_tests[i].hres);
556 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
559 mime = (LPWSTR)0xf0f0f0f0;
560 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
561 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
562 ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
565 mime = (LPWSTR)0xf0f0f0f0;
566 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
567 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
568 ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
572 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
573 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
575 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
576 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
579 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
580 mimeTextHtml, 0, &mime, 0);
581 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
582 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
583 || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
584 ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
586 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
588 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
589 mimeImagePjpeg, 0, &mime, 0);
590 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
591 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
592 ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
594 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
599 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
600 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
601 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
604 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
605 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
606 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
609 hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
610 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
611 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
614 hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
615 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, excepted E_INVALIDARG\n", hres);
617 hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
618 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
620 hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
621 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
623 hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
624 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
626 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
627 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
628 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
631 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
632 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
635 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
636 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
637 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
638 '.','o','r','g',3,0,0,0};
639 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
640 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
643 static struct secmgr_test {
651 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
652 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
653 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
654 {url4, 3, S_OK, sizeof(secid4), secid4, S_OK},
655 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
656 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
657 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
660 static void test_SecurityManager(void)
663 IInternetSecurityManager *secmgr = NULL;
668 hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
669 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
673 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
675 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
677 ok(hres == secmgr_tests[i].zone_hres,
678 "[%d] MapUrlToZone failed: %08x, expected %08x\n",
679 i, hres, secmgr_tests[i].zone_hres);
681 ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
682 secmgr_tests[i].zone);
684 ok(zone == secmgr_tests[i].zone || zone == -1, "[%d] zone=%d\n", i, zone);
687 memset(buf, 0xf0, sizeof(buf));
688 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
690 ok(hres == secmgr_tests[i].secid_hres,
691 "[%d] GetSecurityId failed: %08x, expected %08x\n",
692 i, hres, secmgr_tests[i].secid_hres);
693 if(secmgr_tests[i].secid) {
694 ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
695 i, size, secmgr_tests[i].secid_size);
696 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
701 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
702 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
703 ok(zone == 100 || zone == -1, "zone=%d\n", zone);
706 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
707 ok(hres == E_INVALIDARG,
708 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
709 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
711 ok(hres == E_INVALIDARG,
712 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
713 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
715 ok(hres == E_INVALIDARG,
716 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
718 IInternetSecurityManager_Release(secmgr);
721 static void test_ZoneManager(void)
723 IInternetZoneManager *zonemgr = NULL;
727 hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
728 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
732 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
733 sizeof(DWORD), URLZONEREG_DEFAULT);
734 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
735 ok(*(DWORD*)buf == 1, "policy=%d, expected 1\n", *(DWORD*)buf);
737 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
738 sizeof(DWORD), URLZONEREG_DEFAULT);
739 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
741 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
742 2, URLZONEREG_DEFAULT);
743 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
745 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
746 sizeof(DWORD), URLZONEREG_DEFAULT);
747 ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08x, expected E_FAIL\n", hres);
749 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
750 sizeof(DWORD), URLZONEREG_DEFAULT);
751 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
753 IInternetZoneManager_Release(zonemgr);
756 static void register_protocols(void)
758 IInternetSession *session;
759 IClassFactory *factory;
762 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
764 hres = CoInternetGetSession(0, &session, 0);
765 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
769 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
770 &IID_IClassFactory, (void**)&factory);
771 ok(hres == S_OK, "Coud not get AboutProtocol factory: %08x\n", hres);
775 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
776 wszAbout, 0, NULL, 0);
777 IClassFactory_Release(factory);
779 IInternetSession_Release(session);
782 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
783 REFIID riid, void **ppv)
785 ok(0, "unexpected call\n");
786 return E_NOINTERFACE;
789 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
794 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
799 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
800 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
801 DWORD *pcchResult, DWORD dwReserved)
803 CHECK_EXPECT(ParseUrl);
807 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
808 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
809 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
811 ok(0, "unexpected call\n");
815 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
816 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
818 ok(0, "unexpected call\n");
822 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
823 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
824 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
826 ok(0, "unexpected call\n");
830 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
831 InternetProtocolInfo_QueryInterface,
832 InternetProtocolInfo_AddRef,
833 InternetProtocolInfo_Release,
834 InternetProtocolInfo_ParseUrl,
835 InternetProtocolInfo_CombineUrl,
836 InternetProtocolInfo_CompareUrl,
837 InternetProtocolInfo_QueryInfo
840 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
842 static HRESULT qiret;
843 static IClassFactory *expect_cf;
845 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
847 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
848 CHECK_EXPECT(QI_IInternetProtocolInfo);
849 ok(iface == expect_cf, "unexpected iface\n");
850 *ppv = &protocol_info;
854 ok(0, "unexpected call\n");
855 return E_NOINTERFACE;
858 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
863 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
868 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
869 REFIID riid, void **ppv)
871 CHECK_EXPECT(CreateInstance);
873 ok(iface == expect_cf, "unexpected iface\n");
874 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
875 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
876 ok(ppv != NULL, "ppv == NULL\n");
878 *ppv = &protocol_info;
882 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
884 ok(0, "unexpected call\n");
888 static const IClassFactoryVtbl ClassFactoryVtbl = {
889 ClassFactory_QueryInterface,
891 ClassFactory_Release,
892 ClassFactory_CreateInstance,
893 ClassFactory_LockServer
896 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
897 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
899 static void test_NameSpace(void)
901 IInternetSession *session;
906 static const WCHAR wszTest[] = {'t','e','s','t',0};
908 hres = CoInternetGetSession(0, &session, 0);
909 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
913 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
914 wszTest, 0, NULL, 0);
915 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
917 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
919 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
921 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
922 wszTest, 0, NULL, 0);
923 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
925 qiret = E_NOINTERFACE;
926 expect_cf = &test_protocol_cf;
927 SET_EXPECT(QI_IInternetProtocolInfo);
928 SET_EXPECT(CreateInstance);
929 SET_EXPECT(ParseUrl);
931 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
933 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
935 CHECK_CALLED(QI_IInternetProtocolInfo);
936 CHECK_CALLED(CreateInstance);
937 CHECK_CALLED(ParseUrl);
940 SET_EXPECT(QI_IInternetProtocolInfo);
941 SET_EXPECT(ParseUrl);
943 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
945 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
947 CHECK_CALLED(QI_IInternetProtocolInfo);
948 CHECK_CALLED(ParseUrl);
950 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
951 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
953 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
955 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
957 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
958 wszTest, 0, NULL, 0);
959 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
961 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
962 wszTest, 0, NULL, 0);
963 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
965 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
966 wszTest, 0, NULL, 0);
967 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
969 SET_EXPECT(QI_IInternetProtocolInfo);
970 SET_EXPECT(ParseUrl);
972 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
974 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
976 CHECK_CALLED(QI_IInternetProtocolInfo);
977 CHECK_CALLED(ParseUrl);
979 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
980 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
982 SET_EXPECT(QI_IInternetProtocolInfo);
983 SET_EXPECT(ParseUrl);
985 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
987 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
989 CHECK_CALLED(QI_IInternetProtocolInfo);
990 CHECK_CALLED(ParseUrl);
992 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
993 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
995 expect_cf = &test_protocol_cf2;
996 SET_EXPECT(QI_IInternetProtocolInfo);
997 SET_EXPECT(ParseUrl);
999 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1001 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1003 CHECK_CALLED(QI_IInternetProtocolInfo);
1004 CHECK_CALLED(ParseUrl);
1006 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1007 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1008 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1009 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1010 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
1011 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1012 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
1013 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1015 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
1016 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1018 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1020 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1022 IInternetSession_Release(session);
1025 static ULONG WINAPI unk_Release(IUnknown *iface)
1027 CHECK_EXPECT(unk_Release);
1031 static const IUnknownVtbl unk_vtbl = {
1037 static void test_ReleaseBindInfo(void)
1040 IUnknown unk = { &unk_vtbl };
1042 ReleaseBindInfo(NULL); /* shouldn't crash */
1044 memset(&bi, 0, sizeof(bi));
1045 bi.cbSize = sizeof(BINDINFO);
1047 SET_EXPECT(unk_Release);
1048 ReleaseBindInfo(&bi);
1049 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
1050 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
1051 CHECK_CALLED(unk_Release);
1053 memset(&bi, 0, sizeof(bi));
1054 bi.cbSize = offsetof(BINDINFO, pUnk);
1056 ReleaseBindInfo(&bi);
1057 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
1058 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1060 memset(&bi, 0, sizeof(bi));
1062 ReleaseBindInfo(&bi);
1063 ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
1064 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1067 static void test_UrlMkGetSessionOption(void)
1069 DWORD encoding, size;
1072 size = encoding = 0xdeadbeef;
1073 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1074 sizeof(encoding), &size, 0);
1075 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1076 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1077 ok(size == sizeof(encoding), "size=%d\n", size);
1079 size = encoding = 0xdeadbeef;
1080 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1081 sizeof(encoding)+1, &size, 0);
1082 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1083 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1084 ok(size == sizeof(encoding), "size=%d\n", size);
1086 size = encoding = 0xdeadbeef;
1087 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1088 sizeof(encoding)-1, &size, 0);
1089 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1090 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1091 ok(size == 0xdeadbeef, "size=%d\n", size);
1093 size = encoding = 0xdeadbeef;
1094 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1095 sizeof(encoding)-1, &size, 0);
1096 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1097 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1098 ok(size == 0xdeadbeef, "size=%d\n", size);
1100 encoding = 0xdeadbeef;
1101 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1102 sizeof(encoding)-1, NULL, 0);
1103 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1104 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1107 static void test_ObtainUserAgentString(void)
1109 static const CHAR expected[] = "Mozilla/4.0 (compatible; MSIE ";
1115 hres = ObtainUserAgentString(0, NULL, NULL);
1116 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1119 hres = ObtainUserAgentString(0, NULL, &size);
1120 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1121 ok(size == 100, "size=%d, expected %d\n", size, 100);
1124 hres = ObtainUserAgentString(0, str, &size);
1125 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1126 ok(size > 0, "size=%d, expected non-zero\n", size);
1130 hres = ObtainUserAgentString(0, str, &size);
1131 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1132 ok(size > 0, "size=%d, expected non-zero\n", size);
1133 ok(str[0] == 'a', "str[0]=%c, expected 'a'\n", str[0]);
1136 hres = ObtainUserAgentString(1, str, &size);
1137 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1138 ok(size > 0, "size=%d, expected non-zero\n", size);
1140 str2 = HeapAlloc(GetProcessHeap(), 0, (size+20)*sizeof(CHAR));
1143 skip("skipping rest of ObtainUserAgent tests, out of memory\n");
1148 hres = ObtainUserAgentString(0, str2, &size);
1149 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1150 ok(size == saved, "size=%d, expected %d\n", size, saved);
1151 ok(strlen(expected) <= strlen(str2) &&
1152 !memcmp(expected, str2, strlen(expected)*sizeof(CHAR)),
1153 "user agent was \"%s\", expected to start with \"%s\"\n",
1157 hres = ObtainUserAgentString(0, str2, &size);
1158 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1159 ok(size == saved, "size=%d, expected %d\n", size, saved);
1161 HeapFree(GetProcessHeap(), 0, str2);
1166 OleInitialize(NULL);
1168 register_protocols();
1170 test_CreateFormatEnum();
1171 test_RegisterFormatEnumerator();
1172 test_CoInternetParseUrl();
1173 test_CoInternetCompareUrl();
1174 test_FindMimeFromData();
1175 test_SecurityManager();
1178 test_ReleaseBindInfo();
1179 test_UrlMkGetSessionOption();
1180 test_ObtainUserAgentString();