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 const char *debugstr_w(LPCWSTR str)
67 static char buf[1024];
68 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
72 static void test_CreateFormatEnum(void)
74 IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
79 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
80 static FORMATETC formatetc[] = {
88 hres = CreateFormatEnumerator(0, formatetc, &fenum);
89 ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
90 hres = CreateFormatEnumerator(0, formatetc, NULL);
91 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
92 hres = CreateFormatEnumerator(5, formatetc, NULL);
93 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
96 hres = CreateFormatEnumerator(5, formatetc, &fenum);
97 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
101 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
102 ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
104 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
105 ok(hres == S_OK, "Next failed: %08x\n", hres);
106 ok(ul == 0, "ul=%d, expected 0\n", ul);
108 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
109 ok(hres == S_OK, "Next failed: %08x\n", hres);
110 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
111 ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
112 ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
113 ok(ul == 2, "ul=%d, expected 2\n", ul);
115 hres = IEnumFORMATETC_Skip(fenum, 1);
116 ok(hres == S_OK, "Skip failed: %08x\n", hres);
118 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
119 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
120 ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
121 ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
122 ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
123 ok(ul == 2, "ul=%d, expected 2\n", ul);
125 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
126 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
127 ok(ul == 0, "ul=%d, expected 0\n", ul);
129 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
130 ok(hres == S_OK, "Next failed: %08x\n", hres);
131 ok(ul == 0, "ul=%d, expected 0\n", ul);
133 hres = IEnumFORMATETC_Skip(fenum, 3);
134 ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
136 hres = IEnumFORMATETC_Reset(fenum);
137 ok(hres == S_OK, "Reset failed: %08x\n", hres);
139 hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
140 ok(hres == S_OK, "Next failed: %08x\n", hres);
141 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
143 hres = IEnumFORMATETC_Reset(fenum);
144 ok(hres == S_OK, "Reset failed: %08x\n", hres);
146 hres = IEnumFORMATETC_Skip(fenum, 2);
147 ok(hres == S_OK, "Skip failed: %08x\n", hres);
149 hres = IEnumFORMATETC_Clone(fenum, NULL);
150 ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
152 hres = IEnumFORMATETC_Clone(fenum, &fenum2);
153 ok(hres == S_OK, "Clone failed: %08x\n", hres);
155 if(SUCCEEDED(hres)) {
156 ok(fenum != fenum2, "fenum == fenum2\n");
158 hres = IEnumFORMATETC_Next(fenum2, 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 IEnumFORMATETC_Release(fenum2);
165 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
166 ok(hres == S_OK, "Next failed: %08x\n", hres);
167 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
169 hres = IEnumFORMATETC_Skip(fenum, 1);
170 ok(hres == S_OK, "Skip failed: %08x\n", hres);
172 IEnumFORMATETC_Release(fenum);
175 static void test_RegisterFormatEnumerator(void)
177 IBindCtx *bctx = NULL;
178 IEnumFORMATETC *format = NULL, *format2 = NULL;
179 IUnknown *unk = NULL;
182 static FORMATETC formatetc = {0,NULL,0,0,0};
183 static WCHAR wszEnumFORMATETC[] =
184 {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
186 CreateBindCtx(0, &bctx);
188 hres = CreateFormatEnumerator(1, &formatetc, &format);
189 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
193 hres = RegisterFormatEnumerator(NULL, format, 0);
194 ok(hres == E_INVALIDARG,
195 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
196 hres = RegisterFormatEnumerator(bctx, NULL, 0);
197 ok(hres == E_INVALIDARG,
198 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
200 hres = RegisterFormatEnumerator(bctx, format, 0);
201 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
203 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
204 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
205 ok(unk == (IUnknown*)format, "unk != format\n");
207 hres = RevokeFormatEnumerator(NULL, format);
208 ok(hres == E_INVALIDARG,
209 "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
211 hres = RevokeFormatEnumerator(bctx, format);
212 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
214 hres = RevokeFormatEnumerator(bctx, format);
215 ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
217 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
218 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
220 hres = RegisterFormatEnumerator(bctx, format, 0);
221 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
223 hres = CreateFormatEnumerator(1, &formatetc, &format2);
224 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
226 if(SUCCEEDED(hres)) {
227 hres = RevokeFormatEnumerator(bctx, format);
228 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
230 IEnumFORMATETC_Release(format2);
233 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
234 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
236 IEnumFORMATETC_Release(format);
238 hres = RegisterFormatEnumerator(bctx, format, 0);
239 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
240 hres = RevokeFormatEnumerator(bctx, NULL);
241 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
242 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
243 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
245 IEnumFORMATETC_Release(format);
246 IBindCtx_Release(bctx);
249 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
250 '/','b','l','a','n','k','.','h','t','m',0};
251 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
252 static const WCHAR url3[] = {'f','i','l','e',':','c',':','\\','I','n','d','e','x','.','h','t','m',0};
253 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
254 '%','2','e','j','p','g',0};
255 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
257 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
258 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
259 'f','i','l','e','.','t','e','s','t',0};
260 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
263 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
266 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
267 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
269 static const WCHAR wszRes[] = {'r','e','s',0};
270 static const WCHAR wszFile[] = {'f','i','l','e',0};
271 static const WCHAR wszHttp[] = {'h','t','t','p',0};
272 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
273 static const WCHAR wszEmpty[] = {0};
284 static const struct parse_test parse_tests[] = {
285 {url1, S_OK, url1, E_INVALIDARG, NULL, wszRes},
286 {url2, E_FAIL, url2, E_INVALIDARG, NULL, wszEmpty},
287 {url3, E_FAIL, url3, S_OK, path3, wszFile},
288 {url4, E_FAIL, url4e, S_OK, path4, wszFile},
289 {url5, E_FAIL, url5, E_INVALIDARG, NULL, wszHttp},
290 {url6, S_OK, url6, E_INVALIDARG, NULL, wszAbout}
293 static void test_CoInternetParseUrl(void)
299 static WCHAR buf[4096];
301 memset(buf, 0xf0, sizeof(buf));
302 hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
304 ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
306 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
307 memset(buf, 0xf0, sizeof(buf));
308 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
309 sizeof(buf)/sizeof(WCHAR), &size, 0);
310 ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
311 i, hres, parse_tests[i].secur_hres);
313 memset(buf, 0xf0, sizeof(buf));
314 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
315 sizeof(buf)/sizeof(WCHAR), &size, 0);
316 ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
317 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
318 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
320 memset(buf, 0xf0, sizeof(buf));
321 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
322 sizeof(buf)/sizeof(WCHAR), &size, 0);
323 ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
324 i, hres, parse_tests[i].path_hres);
325 if(parse_tests[i].path) {
326 ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
327 ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
330 memset(buf, 0xf0, sizeof(buf));
331 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
332 sizeof(buf)/sizeof(WCHAR), &size, 0);
333 ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
334 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
335 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
339 static void test_CoInternetCompareUrl(void)
343 hres = CoInternetCompareUrl(url1, url1, 0);
344 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
346 hres = CoInternetCompareUrl(url1, url3, 0);
347 ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
349 hres = CoInternetCompareUrl(url3, url1, 0);
350 ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
353 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
354 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
355 static const WCHAR mimeTextRichtext[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
356 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
357 'o','c','t','e','t','-','s','t','r','e','a','m',0};
358 static const WCHAR mimeImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
359 static const WCHAR mimeImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
360 static const WCHAR mimeImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
361 static const WCHAR mimeImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
362 static const WCHAR mimeImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
363 static const WCHAR mimeVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
364 static const WCHAR mimeVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
365 static const WCHAR mimeAppPostscript[] =
366 {'a','p','p','l','i','c','a','t','i','o','n','/','p','o','s','t','s','c','r','i','p','t',0};
367 static const WCHAR mimeAppXCompressed[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
368 'x','-','c','o','m','p','r','e','s','s','e','d',0};
369 static const WCHAR mimeAppXZip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
370 'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
371 static const WCHAR mimeAppXGzip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
372 'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
373 static const WCHAR mimeAppJava[] = {'a','p','p','l','i','c','a','t','i','o','n','/','j','a','v','a',0};
374 static const WCHAR mimeAppPdf[] = {'a','p','p','l','i','c','a','t','i','o','n','/','p','d','f',0};
375 static const WCHAR mimeAppXMSDownload[] =
376 {'a','p','p','l','i','c','a','t','i','o','n','/','x','-','m','s','d','o','w','n','l','o','a','d',0};
377 static const WCHAR mimeAudioWav[] = {'a','u','d','i','o','/','w','a','v',0};
379 static const struct {
384 {url1, mimeTextHtml, S_OK},
385 {url2, mimeTextHtml, S_OK},
386 {url3, mimeTextHtml, S_OK},
387 {url4, NULL, E_FAIL},
388 {url5, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)},
389 {url6, NULL, E_FAIL},
390 {url7, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)}
393 static BYTE data1[] = "test data\n";
394 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
395 static BYTE data3[] = {0,0,0};
396 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
397 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
398 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
399 static BYTE data7[] = "<html>blahblah";
400 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
401 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
402 static BYTE data10[] = "<HtmL>blahblah";
403 static BYTE data11[] = "blah<HTML>blahblah";
404 static BYTE data12[] = "blah<HTMLblahblah";
405 static BYTE data13[] = "blahHTML>blahblah";
406 static BYTE data14[] = "blah<HTMblahblah";
407 static BYTE data15[] = {0xff,0xd8};
408 static BYTE data16[] = {0xff,0xd8,'h'};
409 static BYTE data17[] = {0,0xff,0xd8};
410 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
411 static BYTE data19[] = {'G','I','F','8','7','a'};
412 static BYTE data20[] = {'G','I','F','8','9','a'};
413 static BYTE data21[] = {'G','I','F','8','7'};
414 static BYTE data22[] = {'G','i','F','8','7','a'};
415 static BYTE data23[] = {'G','i','F','8','8','a'};
416 static BYTE data24[] = {'g','i','f','8','7','a'};
417 static BYTE data25[] = {'G','i','F','8','7','A'};
418 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
419 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
420 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
421 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
422 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
423 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
424 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
425 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
426 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
427 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
428 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
429 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
430 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
431 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a};
432 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
433 static BYTE data41[] = {0x4d,0x4d,0xff};
434 static BYTE data42[] = {0x4d,0x4d};
435 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
436 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
437 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
438 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
439 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
440 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
441 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
442 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
443 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
444 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
445 static BYTE data53[] = {0x00,0x00,0x01,0xba};
446 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
447 static BYTE data55[] = {0x1f,0x8b,'x'};
448 static BYTE data56[] = {0x1f};
449 static BYTE data57[] = {0x1f,0x8b,'<','h','t','m','l','>','t','e','s','t',0};
450 static BYTE data58[] = {0x1f,0x8b};
451 static BYTE data59[] = {0x50,0x4b,'x'};
452 static BYTE data60[] = {0x50,0x4b};
453 static BYTE data61[] = {0x50,0x4b,'<','h','t','m','l','>',0};
454 static BYTE data62[] = {0xca,0xfe,0xba,0xbe,'x'};
455 static BYTE data63[] = {0xca,0xfe,0xba,0xbe};
456 static BYTE data64[] = {0xca,0xfe,0xba,0xbe,'<','h','t','m','l','>',0};
457 static BYTE data65[] = {0x25,0x50,0x44,0x46,'x'};
458 static BYTE data66[] = {0x25,0x50,0x44,0x46};
459 static BYTE data67[] = {0x25,0x50,0x44,0x46,'x','<','h','t','m','l','>'};
460 static BYTE data68[] = {'M','Z','x'};
461 static BYTE data69[] = {'M','Z'};
462 static BYTE data70[] = {'M','Z','<','h','t','m','l','>',0xff};
463 static BYTE data71[] = {'{','\\','r','t','f',0};
464 static BYTE data72[] = {'{','\\','r','t','f'};
465 static BYTE data73[] = {' ','{','\\','r','t','f',' '};
466 static BYTE data74[] = {'{','\\','r','t','f','<','h','t','m','l','>',' '};
467 static BYTE data75[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E',0xff};
468 static BYTE data76[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E'};
469 static BYTE data77[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V',0xff,0xff};
470 static BYTE data78[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'<','h','t','m','l','>',0xff};
471 static BYTE data79[] = {'%','!',0xff};
472 static BYTE data80[] = {'%','!'};
473 static BYTE data81[] = {'%','!','P','S','<','h','t','m','l','>'};
475 static const struct {
480 {data1, sizeof(data1), mimeTextPlain},
481 {data2, sizeof(data2), mimeAppOctetStream},
482 {data3, sizeof(data3), mimeAppOctetStream},
483 {data4, sizeof(data4), mimeAppOctetStream},
484 {data5, sizeof(data5), mimeTextPlain},
485 {data6, sizeof(data6), mimeTextPlain},
486 {data7, sizeof(data7), mimeTextHtml},
487 {data8, sizeof(data8), mimeTextHtml},
488 {data9, sizeof(data9), mimeTextHtml},
489 {data10, sizeof(data10), mimeTextHtml},
490 {data11, sizeof(data11), mimeTextHtml},
491 {data12, sizeof(data12), mimeTextHtml},
492 {data13, sizeof(data13), mimeTextPlain},
493 {data14, sizeof(data14), mimeTextPlain},
494 {data15, sizeof(data15), mimeTextPlain},
495 {data16, sizeof(data16), mimeImagePjpeg},
496 {data17, sizeof(data17), mimeAppOctetStream},
497 {data18, sizeof(data18), mimeTextHtml},
498 {data19, sizeof(data19), mimeImageGif},
499 {data20, sizeof(data20), mimeImageGif},
500 {data21, sizeof(data21), mimeTextPlain},
501 {data22, sizeof(data22), mimeImageGif},
502 {data23, sizeof(data23), mimeTextPlain},
503 {data24, sizeof(data24), mimeImageGif},
504 {data25, sizeof(data25), mimeImageGif},
505 {data26, sizeof(data26), mimeTextHtml},
506 {data27, sizeof(data27), mimeTextPlain},
507 {data28, sizeof(data28), mimeImageBmp},
508 {data29, sizeof(data29), mimeImageBmp},
509 {data30, sizeof(data30), mimeAppOctetStream},
510 {data31, sizeof(data31), mimeTextHtml},
511 {data32, sizeof(data32), mimeAppOctetStream},
512 {data33, sizeof(data33), mimeAppOctetStream},
513 {data34, sizeof(data34), mimeImageXPng},
514 {data35, sizeof(data35), mimeImageXPng},
515 {data36, sizeof(data36), mimeAppOctetStream},
516 {data37, sizeof(data37), mimeTextHtml},
517 {data38, sizeof(data38), mimeAppOctetStream},
518 {data39, sizeof(data39), mimeImageTiff},
519 {data40, sizeof(data40), mimeTextHtml},
520 {data41, sizeof(data41), mimeImageTiff},
521 {data42, sizeof(data42), mimeTextPlain},
522 {data43, sizeof(data43), mimeAppOctetStream},
523 {data44, sizeof(data44), mimeVideoAvi},
524 {data45, sizeof(data45), mimeTextPlain},
525 {data46, sizeof(data46), mimeTextPlain},
526 {data47, sizeof(data47), mimeTextPlain},
527 {data48, sizeof(data48), mimeTextHtml},
528 {data49, sizeof(data49), mimeVideoAvi},
529 {data50, sizeof(data50), mimeVideoMpeg},
530 {data51, sizeof(data51), mimeVideoMpeg},
531 {data52, sizeof(data52), mimeAppOctetStream},
532 {data53, sizeof(data53), mimeAppOctetStream},
533 {data54, sizeof(data54), mimeTextHtml},
534 {data55, sizeof(data55), mimeAppXGzip},
535 {data56, sizeof(data56), mimeTextPlain},
536 {data57, sizeof(data57), mimeTextHtml},
537 {data58, sizeof(data58), mimeAppOctetStream},
538 {data59, sizeof(data59), mimeAppXZip},
539 {data60, sizeof(data60), mimeTextPlain},
540 {data61, sizeof(data61), mimeTextHtml},
541 {data62, sizeof(data62), mimeAppJava},
542 {data63, sizeof(data63), mimeTextPlain},
543 {data64, sizeof(data64), mimeTextHtml},
544 {data65, sizeof(data65), mimeAppPdf},
545 {data66, sizeof(data66), mimeTextPlain},
546 {data67, sizeof(data67), mimeTextHtml},
547 {data68, sizeof(data68), mimeAppXMSDownload},
548 {data69, sizeof(data69), mimeTextPlain},
549 {data70, sizeof(data70), mimeTextHtml},
550 {data71, sizeof(data71), mimeTextRichtext},
551 {data72, sizeof(data72), mimeTextPlain},
552 {data73, sizeof(data73), mimeTextPlain},
553 {data74, sizeof(data74), mimeTextHtml},
554 {data75, sizeof(data75), mimeAudioWav},
555 {data76, sizeof(data76), mimeTextPlain},
556 {data77, sizeof(data77), mimeTextPlain},
557 {data78, sizeof(data78), mimeTextHtml},
558 {data79, sizeof(data79), mimeAppPostscript},
559 {data80, sizeof(data80), mimeTextPlain},
560 {data81, sizeof(data81), mimeTextHtml}
563 static void test_FindMimeFromData(void)
569 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
570 mime = (LPWSTR)0xf0f0f0f0;
571 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
572 if(mime_tests[i].mime) {
573 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
574 ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
577 ok(hres == E_FAIL || hres == mime_tests[i].hres,
578 "[%d] FindMimeFromData failed: %08x, expected %08x\n",
579 i, hres, mime_tests[i].hres);
580 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
583 mime = (LPWSTR)0xf0f0f0f0;
584 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
585 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
586 ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
589 mime = (LPWSTR)0xf0f0f0f0;
590 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
591 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
592 ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
596 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
597 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
599 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
600 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime: %s\n", i, debugstr_w(mime));
603 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
604 mimeTextHtml, 0, &mime, 0);
605 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
606 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
607 || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
608 ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
610 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
613 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
614 mimeImagePjpeg, 0, &mime, 0);
615 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
616 if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
617 ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
619 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
624 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
625 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
626 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
629 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
630 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
631 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
634 hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
635 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
636 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
639 hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
640 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, excepted E_INVALIDARG\n", hres);
642 hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
643 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
645 hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
646 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
648 hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
649 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
651 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
652 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
653 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
656 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
657 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
660 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
661 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
662 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
663 '.','o','r','g',3,0,0,0};
664 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
665 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
668 static struct secmgr_test {
676 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
677 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
678 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
679 {url4, 3, S_OK, sizeof(secid4), secid4, S_OK},
680 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
681 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
682 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
685 static void test_SecurityManager(void)
688 IInternetSecurityManager *secmgr = NULL;
693 hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
694 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
698 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
700 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
702 ok(hres == secmgr_tests[i].zone_hres,
703 "[%d] MapUrlToZone failed: %08x, expected %08x\n",
704 i, hres, secmgr_tests[i].zone_hres);
706 ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
707 secmgr_tests[i].zone);
709 ok(zone == secmgr_tests[i].zone || zone == -1, "[%d] zone=%d\n", i, zone);
712 memset(buf, 0xf0, sizeof(buf));
713 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
715 ok(hres == secmgr_tests[i].secid_hres,
716 "[%d] GetSecurityId failed: %08x, expected %08x\n",
717 i, hres, secmgr_tests[i].secid_hres);
718 if(secmgr_tests[i].secid) {
719 ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
720 i, size, secmgr_tests[i].secid_size);
721 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
726 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
727 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
728 ok(zone == 100 || zone == -1, "zone=%d\n", zone);
731 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
732 ok(hres == E_INVALIDARG,
733 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
734 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
736 ok(hres == E_INVALIDARG,
737 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
738 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
740 ok(hres == E_INVALIDARG,
741 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
743 IInternetSecurityManager_Release(secmgr);
746 static void test_ZoneManager(void)
748 IInternetZoneManager *zonemgr = NULL;
752 hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
753 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
757 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
758 sizeof(DWORD), URLZONEREG_DEFAULT);
759 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
760 ok(*(DWORD*)buf == 1, "policy=%d, expected 1\n", *(DWORD*)buf);
762 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
763 sizeof(DWORD), URLZONEREG_DEFAULT);
764 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
766 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
767 2, URLZONEREG_DEFAULT);
768 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
770 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
771 sizeof(DWORD), URLZONEREG_DEFAULT);
772 ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08x, expected E_FAIL\n", hres);
774 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
775 sizeof(DWORD), URLZONEREG_DEFAULT);
776 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
778 IInternetZoneManager_Release(zonemgr);
781 static void register_protocols(void)
783 IInternetSession *session;
784 IClassFactory *factory;
787 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
789 hres = CoInternetGetSession(0, &session, 0);
790 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
794 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
795 &IID_IClassFactory, (void**)&factory);
796 ok(hres == S_OK, "Coud not get AboutProtocol factory: %08x\n", hres);
800 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
801 wszAbout, 0, NULL, 0);
802 IClassFactory_Release(factory);
804 IInternetSession_Release(session);
807 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
808 REFIID riid, void **ppv)
810 ok(0, "unexpected call\n");
811 return E_NOINTERFACE;
814 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
819 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
824 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
825 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
826 DWORD *pcchResult, DWORD dwReserved)
828 CHECK_EXPECT(ParseUrl);
832 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
833 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
834 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
836 ok(0, "unexpected call\n");
840 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
841 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
843 ok(0, "unexpected call\n");
847 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
848 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
849 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
851 ok(0, "unexpected call\n");
855 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
856 InternetProtocolInfo_QueryInterface,
857 InternetProtocolInfo_AddRef,
858 InternetProtocolInfo_Release,
859 InternetProtocolInfo_ParseUrl,
860 InternetProtocolInfo_CombineUrl,
861 InternetProtocolInfo_CompareUrl,
862 InternetProtocolInfo_QueryInfo
865 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
867 static HRESULT qiret;
868 static IClassFactory *expect_cf;
870 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
872 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
873 CHECK_EXPECT(QI_IInternetProtocolInfo);
874 ok(iface == expect_cf, "unexpected iface\n");
875 *ppv = &protocol_info;
879 ok(0, "unexpected call\n");
880 return E_NOINTERFACE;
883 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
888 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
893 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
894 REFIID riid, void **ppv)
896 CHECK_EXPECT(CreateInstance);
898 ok(iface == expect_cf, "unexpected iface\n");
899 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
900 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
901 ok(ppv != NULL, "ppv == NULL\n");
903 *ppv = &protocol_info;
907 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
909 ok(0, "unexpected call\n");
913 static const IClassFactoryVtbl ClassFactoryVtbl = {
914 ClassFactory_QueryInterface,
916 ClassFactory_Release,
917 ClassFactory_CreateInstance,
918 ClassFactory_LockServer
921 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
922 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
924 static void test_NameSpace(void)
926 IInternetSession *session;
931 static const WCHAR wszTest[] = {'t','e','s','t',0};
933 hres = CoInternetGetSession(0, &session, 0);
934 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
938 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
939 wszTest, 0, NULL, 0);
940 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
942 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
944 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
946 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
947 wszTest, 0, NULL, 0);
948 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
950 qiret = E_NOINTERFACE;
951 expect_cf = &test_protocol_cf;
952 SET_EXPECT(QI_IInternetProtocolInfo);
953 SET_EXPECT(CreateInstance);
954 SET_EXPECT(ParseUrl);
956 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
958 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
960 CHECK_CALLED(QI_IInternetProtocolInfo);
961 CHECK_CALLED(CreateInstance);
962 CHECK_CALLED(ParseUrl);
965 SET_EXPECT(QI_IInternetProtocolInfo);
966 SET_EXPECT(ParseUrl);
968 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
970 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
972 CHECK_CALLED(QI_IInternetProtocolInfo);
973 CHECK_CALLED(ParseUrl);
975 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
976 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
978 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
980 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
982 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
983 wszTest, 0, NULL, 0);
984 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
986 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
987 wszTest, 0, NULL, 0);
988 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
990 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
991 wszTest, 0, NULL, 0);
992 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
994 SET_EXPECT(QI_IInternetProtocolInfo);
995 SET_EXPECT(ParseUrl);
997 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
999 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1001 CHECK_CALLED(QI_IInternetProtocolInfo);
1002 CHECK_CALLED(ParseUrl);
1004 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1005 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1007 SET_EXPECT(QI_IInternetProtocolInfo);
1008 SET_EXPECT(ParseUrl);
1010 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1012 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1014 CHECK_CALLED(QI_IInternetProtocolInfo);
1015 CHECK_CALLED(ParseUrl);
1017 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1018 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1020 expect_cf = &test_protocol_cf2;
1021 SET_EXPECT(QI_IInternetProtocolInfo);
1022 SET_EXPECT(ParseUrl);
1024 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1026 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1028 CHECK_CALLED(QI_IInternetProtocolInfo);
1029 CHECK_CALLED(ParseUrl);
1031 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1032 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1033 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1034 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1035 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
1036 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1037 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
1038 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1040 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
1041 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1043 hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1045 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1047 IInternetSession_Release(session);
1050 static ULONG WINAPI unk_Release(IUnknown *iface)
1052 CHECK_EXPECT(unk_Release);
1056 static const IUnknownVtbl unk_vtbl = {
1062 static void test_ReleaseBindInfo(void)
1065 IUnknown unk = { &unk_vtbl };
1067 ReleaseBindInfo(NULL); /* shouldn't crash */
1069 memset(&bi, 0, sizeof(bi));
1070 bi.cbSize = sizeof(BINDINFO);
1072 SET_EXPECT(unk_Release);
1073 ReleaseBindInfo(&bi);
1074 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
1075 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
1076 CHECK_CALLED(unk_Release);
1078 memset(&bi, 0, sizeof(bi));
1079 bi.cbSize = offsetof(BINDINFO, pUnk);
1081 ReleaseBindInfo(&bi);
1082 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
1083 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1085 memset(&bi, 0, sizeof(bi));
1087 ReleaseBindInfo(&bi);
1088 ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
1089 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1092 static void test_UrlMkGetSessionOption(void)
1094 DWORD encoding, size;
1097 size = encoding = 0xdeadbeef;
1098 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1099 sizeof(encoding), &size, 0);
1100 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1101 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1102 ok(size == sizeof(encoding), "size=%d\n", size);
1104 size = encoding = 0xdeadbeef;
1105 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1106 sizeof(encoding)+1, &size, 0);
1107 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1108 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1109 ok(size == sizeof(encoding), "size=%d\n", size);
1111 size = encoding = 0xdeadbeef;
1112 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1113 sizeof(encoding)-1, &size, 0);
1114 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1115 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1116 ok(size == 0xdeadbeef, "size=%d\n", size);
1118 size = encoding = 0xdeadbeef;
1119 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1120 sizeof(encoding)-1, &size, 0);
1121 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1122 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1123 ok(size == 0xdeadbeef, "size=%d\n", size);
1125 encoding = 0xdeadbeef;
1126 hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1127 sizeof(encoding)-1, NULL, 0);
1128 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1129 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1132 static void test_ObtainUserAgentString(void)
1134 static const CHAR expected[] = "Mozilla/4.0 (compatible; MSIE ";
1140 hres = ObtainUserAgentString(0, NULL, NULL);
1141 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1144 hres = ObtainUserAgentString(0, NULL, &size);
1145 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1146 ok(size == 100, "size=%d, expected %d\n", size, 100);
1149 hres = ObtainUserAgentString(0, str, &size);
1150 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1151 ok(size > 0, "size=%d, expected non-zero\n", size);
1155 hres = ObtainUserAgentString(0, str, &size);
1156 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1157 ok(size > 0, "size=%d, expected non-zero\n", size);
1158 ok(str[0] == 'a', "str[0]=%c, expected 'a'\n", str[0]);
1161 hres = ObtainUserAgentString(1, str, &size);
1162 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1163 ok(size > 0, "size=%d, expected non-zero\n", size);
1165 str2 = HeapAlloc(GetProcessHeap(), 0, (size+20)*sizeof(CHAR));
1168 skip("skipping rest of ObtainUserAgent tests, out of memory\n");
1173 hres = ObtainUserAgentString(0, str2, &size);
1174 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1175 ok(size == saved, "size=%d, expected %d\n", size, saved);
1176 ok(strlen(expected) <= strlen(str2) &&
1177 !memcmp(expected, str2, strlen(expected)*sizeof(CHAR)),
1178 "user agent was \"%s\", expected to start with \"%s\"\n",
1182 hres = ObtainUserAgentString(0, str2, &size);
1183 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1184 ok(size == saved, "size=%d, expected %d\n", size, saved);
1186 HeapFree(GetProcessHeap(), 0, str2);
1191 OleInitialize(NULL);
1193 register_protocols();
1195 test_CreateFormatEnum();
1196 test_RegisterFormatEnumerator();
1197 test_CoInternetParseUrl();
1198 test_CoInternetCompareUrl();
1199 test_FindMimeFromData();
1200 test_SecurityManager();
1203 test_ReleaseBindInfo();
1204 test_UrlMkGetSessionOption();
1205 test_ObtainUserAgentString();