oleaut32: Add VarBstrCmp binary comparison for LCID==0.
[wine] / dlls / urlmon / tests / misc.c
1 /*
2  * Copyright 2005-2006 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stddef.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "urlmon.h"
30
31 #include "initguid.h"
32
33 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
34
35 #define DEFINE_EXPECT(func) \
36     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
37
38 #define SET_EXPECT(func) \
39     expect_ ## func = TRUE
40
41 #define CHECK_EXPECT(func) \
42     do { \
43         ok(expect_ ##func, "unexpected call " #func "\n"); \
44         expect_ ## func = FALSE; \
45         called_ ## func = TRUE; \
46     }while(0)
47
48 #define CHECK_EXPECT2(func) \
49     do { \
50         ok(expect_ ##func, "unexpected call " #func "\n"); \
51         called_ ## func = TRUE; \
52     }while(0)
53
54 #define CHECK_CALLED(func) \
55     do { \
56         ok(called_ ## func, "expected " #func "\n"); \
57         expect_ ## func = called_ ## func = FALSE; \
58     }while(0)
59
60 DEFINE_EXPECT(ParseUrl);
61 DEFINE_EXPECT(QI_IInternetProtocolInfo);
62 DEFINE_EXPECT(CreateInstance);
63 DEFINE_EXPECT(unk_Release);
64
65 static void test_CreateFormatEnum(void)
66 {
67     IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
68     FORMATETC fetc[5];
69     ULONG ul;
70     HRESULT hres;
71
72     static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
73     static FORMATETC formatetc[] = {
74         {0,&dev,0,0,0},
75         {0,&dev,0,1,0},
76         {0,NULL,0,2,0},
77         {0,NULL,0,3,0},
78         {0,NULL,0,4,0}
79     };
80
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);
87
88
89     hres = CreateFormatEnumerator(5, formatetc, &fenum);
90     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
91     if(FAILED(hres))
92         return;
93
94     hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
95     ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
96     ul = 100;
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);
100
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);
107
108     hres = IEnumFORMATETC_Skip(fenum, 1);
109     ok(hres == S_OK, "Skip failed: %08x\n", hres);
110
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);
117
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);
121     ul = 100;
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);
125
126     hres = IEnumFORMATETC_Skip(fenum, 3);
127     ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
128
129     hres = IEnumFORMATETC_Reset(fenum);
130     ok(hres == S_OK, "Reset failed: %08x\n", hres);
131
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);
135
136     hres = IEnumFORMATETC_Reset(fenum);
137     ok(hres == S_OK, "Reset failed: %08x\n", hres);
138
139     hres = IEnumFORMATETC_Skip(fenum, 2);
140     ok(hres == S_OK, "Skip failed: %08x\n", hres);
141
142     hres = IEnumFORMATETC_Clone(fenum, NULL);
143     ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
144
145     hres = IEnumFORMATETC_Clone(fenum, &fenum2);
146     ok(hres == S_OK, "Clone failed: %08x\n", hres);
147
148     if(SUCCEEDED(hres)) {
149         ok(fenum != fenum2, "fenum == fenum2\n");
150
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);
154
155         IEnumFORMATETC_Release(fenum2);
156     }
157
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);
161
162     hres = IEnumFORMATETC_Skip(fenum, 1);
163     ok(hres == S_OK, "Skip failed: %08x\n", hres);
164     
165     IEnumFORMATETC_Release(fenum);
166 }
167
168 static void test_RegisterFormatEnumerator(void)
169 {
170     IBindCtx *bctx = NULL;
171     IEnumFORMATETC *format = NULL, *format2 = NULL;
172     IUnknown *unk = NULL;
173     HRESULT hres;
174
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};
178
179     CreateBindCtx(0, &bctx);
180
181     hres = CreateFormatEnumerator(1, &formatetc, &format);
182     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
183     if(FAILED(hres))
184         return;
185
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);
192
193     hres = RegisterFormatEnumerator(bctx, format, 0);
194     ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
195
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");
199
200     hres = RevokeFormatEnumerator(NULL, format);
201     ok(hres == E_INVALIDARG,
202             "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
203
204     hres = RevokeFormatEnumerator(bctx, format);
205     ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
206
207     hres = RevokeFormatEnumerator(bctx, format);
208     ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
209
210     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
211     ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
212
213     hres = RegisterFormatEnumerator(bctx, format, 0);
214     ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
215
216     hres = CreateFormatEnumerator(1, &formatetc, &format2);
217     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
218
219     if(SUCCEEDED(hres)) {
220         hres = RevokeFormatEnumerator(bctx, format);
221         ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
222
223         IEnumFORMATETC_Release(format2);
224     }
225
226     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
227     ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
228
229     IEnumFORMATETC_Release(format);
230
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);
237
238     IBindCtx_Release(bctx);
239 }
240
241 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
242         '/','b','l','a','n','k','.','h','t','m',0};
243 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
244 static const WCHAR url3[] = {'f','i','l','e',':','c',':','\\','I','n','d','e','x','.','h','t','m',0};
245 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
246         '%','2','e','j','p','g',0};
247 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
248         '.','o','r','g',0};
249 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
250 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
251         'f','i','l','e','.','t','e','s','t',0};
252 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
253
254
255 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
256         '.','j','p','g',0};
257
258 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
259 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
260
261 static const WCHAR wszRes[] = {'r','e','s',0};
262 static const WCHAR wszFile[] = {'f','i','l','e',0};
263 static const WCHAR wszHttp[] = {'h','t','t','p',0};
264 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
265 static const WCHAR wszEmpty[] = {0};
266
267 struct parse_test {
268     LPCWSTR url;
269     HRESULT secur_hres;
270     LPCWSTR encoded_url;
271     HRESULT path_hres;
272     LPCWSTR path;
273     LPCWSTR schema;
274 };
275
276 static const struct parse_test parse_tests[] = {
277     {url1, S_OK,   url1,  E_INVALIDARG, NULL, wszRes},
278     {url2, E_FAIL, url2,  E_INVALIDARG, NULL, wszEmpty},
279     {url3, E_FAIL, url3,  S_OK, path3,        wszFile},
280     {url4, E_FAIL, url4e, S_OK, path4,        wszFile},
281     {url5, E_FAIL, url5,  E_INVALIDARG, NULL, wszHttp},
282     {url6, S_OK,   url6,  E_INVALIDARG, NULL, wszAbout}
283 };
284
285 static void test_CoInternetParseUrl(void)
286 {
287     HRESULT hres;
288     DWORD size;
289     int i;
290
291     static WCHAR buf[4096];
292
293     memset(buf, 0xf0, sizeof(buf));
294     hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
295             3, &size, 0);
296     ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
297
298     for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
299         memset(buf, 0xf0, sizeof(buf));
300         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
301                 sizeof(buf)/sizeof(WCHAR), &size, 0);
302         ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
303                 i, hres, parse_tests[i].secur_hres);
304
305         memset(buf, 0xf0, sizeof(buf));
306         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
307                 sizeof(buf)/sizeof(WCHAR), &size, 0);
308         ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
309         ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
310         ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
311
312         memset(buf, 0xf0, sizeof(buf));
313         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
314                 sizeof(buf)/sizeof(WCHAR), &size, 0);
315         ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
316                 i, hres, parse_tests[i].path_hres);
317         if(parse_tests[i].path) {
318             ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
319             ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
320         }
321
322         memset(buf, 0xf0, sizeof(buf));
323         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
324                 sizeof(buf)/sizeof(WCHAR), &size, 0);
325         ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
326         ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
327         ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
328     }
329 }
330
331 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
332 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
333 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
334     'o','c','t','e','t','-','s','t','r','e','a','m',0};
335 static const WCHAR mimeImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
336 static const WCHAR mimeImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
337 static const WCHAR mimeImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
338 static const WCHAR mimeImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
339 static const WCHAR mimeImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
340 static const WCHAR mimeVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
341 static const WCHAR mimeVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
342
343 static const struct {
344     LPCWSTR url;
345     LPCWSTR mime;
346 } mime_tests[] = {
347     {url1, mimeTextHtml},
348     {url2, mimeTextHtml},
349     {url3, mimeTextHtml},
350     {url4, NULL},
351     {url5, NULL},
352     {url6, NULL},
353     {url7, NULL}
354 };
355
356 static BYTE data1[] = "test data\n";
357 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
358 static BYTE data3[] = {0,0,0};
359 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
360 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
361 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
362 static BYTE data7[] = "<html>blahblah";
363 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
364 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
365 static BYTE data10[] = "<HtmL>blahblah";
366 static BYTE data11[] = "blah<HTML>blahblah";
367 static BYTE data12[] = "blah<HTMLblahblah";
368 static BYTE data13[] = "blahHTML>blahblah";
369 static BYTE data14[] = "blah<HTMblahblah";
370 static BYTE data15[] = {0xff,0xd8};
371 static BYTE data16[] = {0xff,0xd8,'h'};
372 static BYTE data17[] = {0,0xff,0xd8};
373 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
374 static BYTE data19[] = {'G','I','F','8','7','a'};
375 static BYTE data20[] = {'G','I','F','8','9','a'};
376 static BYTE data21[] = {'G','I','F','8','7'};
377 static BYTE data22[] = {'G','i','F','8','7','a'};
378 static BYTE data23[] = {'G','i','F','8','8','a'};
379 static BYTE data24[] = {'g','i','f','8','7','a'};
380 static BYTE data25[] = {'G','i','F','8','7','A'};
381 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
382 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
383 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
384 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
385 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
386 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
387 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
388 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
389 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
390 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
391 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
392 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
393 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
394 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a};
395 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
396 static BYTE data41[] = {0x4d,0x4d,0xff};
397 static BYTE data42[] = {0x4d,0x4d};
398 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
399 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
400 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
401 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
402 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
403 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
404 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
405 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
406 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
407 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
408 static BYTE data53[] = {0x00,0x00,0x01,0xba};
409 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
410
411 static const struct {
412     BYTE *data;
413     DWORD size;
414     LPCWSTR mime;
415 } mime_tests2[] = {
416     {data1, sizeof(data1), mimeTextPlain},
417     {data2, sizeof(data2), mimeAppOctetStream},
418     {data3, sizeof(data3), mimeAppOctetStream},
419     {data4, sizeof(data4), mimeAppOctetStream},
420     {data5, sizeof(data5), mimeTextPlain},
421     {data6, sizeof(data6), mimeTextPlain},
422     {data7, sizeof(data7), mimeTextHtml},
423     {data8, sizeof(data8), mimeTextHtml},
424     {data9, sizeof(data9), mimeTextHtml},
425     {data10, sizeof(data10), mimeTextHtml},
426     {data11, sizeof(data11), mimeTextHtml},
427     {data12, sizeof(data12), mimeTextHtml},
428     {data13, sizeof(data13), mimeTextPlain},
429     {data14, sizeof(data14), mimeTextPlain},
430     {data15, sizeof(data15), mimeTextPlain},
431     {data16, sizeof(data16), mimeImagePjpeg},
432     {data17, sizeof(data17), mimeAppOctetStream},
433     {data18, sizeof(data18), mimeTextHtml},
434     {data19, sizeof(data19), mimeImageGif},
435     {data20, sizeof(data20), mimeImageGif},
436     {data21, sizeof(data21), mimeTextPlain},
437     {data22, sizeof(data22), mimeImageGif},
438     {data23, sizeof(data23), mimeTextPlain},
439     {data24, sizeof(data24), mimeImageGif},
440     {data25, sizeof(data25), mimeImageGif},
441     {data26, sizeof(data26), mimeTextHtml},
442     {data27, sizeof(data27), mimeTextPlain},
443     {data28, sizeof(data28), mimeImageBmp},
444     {data29, sizeof(data29), mimeImageBmp},
445     {data30, sizeof(data30), mimeAppOctetStream},
446     {data31, sizeof(data31), mimeTextHtml},
447     {data32, sizeof(data32), mimeAppOctetStream},
448     {data33, sizeof(data33), mimeAppOctetStream},
449     {data34, sizeof(data34), mimeImageXPng},
450     {data35, sizeof(data35), mimeImageXPng},
451     {data36, sizeof(data36), mimeAppOctetStream},
452     {data37, sizeof(data37), mimeTextHtml},
453     {data38, sizeof(data38), mimeAppOctetStream},
454     {data39, sizeof(data39), mimeImageTiff},
455     {data40, sizeof(data40), mimeTextHtml},
456     {data41, sizeof(data41), mimeImageTiff},
457     {data42, sizeof(data42), mimeTextPlain},
458     {data43, sizeof(data43), mimeAppOctetStream},
459     {data44, sizeof(data44), mimeVideoAvi},
460     {data45, sizeof(data45), mimeTextPlain},
461     {data46, sizeof(data46), mimeTextPlain},
462     {data47, sizeof(data47), mimeTextPlain},
463     {data48, sizeof(data48), mimeTextHtml},
464     {data49, sizeof(data49), mimeVideoAvi},
465     {data50, sizeof(data50), mimeVideoMpeg},
466     {data51, sizeof(data51), mimeVideoMpeg},
467     {data52, sizeof(data52), mimeAppOctetStream},
468     {data53, sizeof(data53), mimeAppOctetStream},
469     {data54, sizeof(data54), mimeTextHtml}
470 };
471
472 static void test_FindMimeFromData(void)
473 {
474     HRESULT hres;
475     LPWSTR mime;
476     int i;
477
478     for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
479         mime = (LPWSTR)0xf0f0f0f0;
480         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
481         if(mime_tests[i].mime) {
482             ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
483             ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
484             CoTaskMemFree(mime);
485         }else {
486             ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
487             ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
488         }
489
490         mime = (LPWSTR)0xf0f0f0f0;
491         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
492         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
493         ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
494         CoTaskMemFree(mime);
495
496         mime = (LPWSTR)0xf0f0f0f0;
497         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
498         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
499         ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
500         CoTaskMemFree(mime);
501     }
502
503     for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
504         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
505                 NULL, 0, &mime, 0);
506         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
507         ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
508         CoTaskMemFree(mime);
509
510         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
511                 mimeTextHtml, 0, &mime, 0);
512         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
513         if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
514            || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
515             ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
516         else
517             ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
518
519         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
520                 mimeImagePjpeg, 0, &mime, 0);
521         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
522         if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
523             ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
524         else
525             ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
526
527         CoTaskMemFree(mime);
528     }
529
530     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
531     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
532     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
533     CoTaskMemFree(mime);
534
535     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
536     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
537     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
538     CoTaskMemFree(mime);
539
540     hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
541     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
542     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
543     CoTaskMemFree(mime);
544
545     hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
546     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, excepted E_INVALIDARG\n", hres);
547
548     hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
549     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
550
551     hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
552     ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
553
554     hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
555     ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
556
557     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
558     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
559     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
560     CoTaskMemFree(mime);
561
562     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
563     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
564 }
565
566 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
567 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
568 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
569     '.','o','r','g',3,0,0,0};
570 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
571 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
572                               3,0,0,0};
573
574 static struct secmgr_test {
575     LPCWSTR url;
576     DWORD zone;
577     HRESULT zone_hres;
578     DWORD secid_size;
579     const BYTE *secid;
580     HRESULT secid_hres;
581 } secmgr_tests[] = {
582     {url1, 0,   S_OK, sizeof(secid1), secid1, S_OK},
583     {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
584     {url3, 0,   S_OK, sizeof(secid1), secid1, S_OK},
585     {url4, 3,   S_OK, sizeof(secid4), secid4, S_OK},
586     {url5, 3,   S_OK, sizeof(secid5), secid5, S_OK},
587     {url6, 3,   S_OK, sizeof(secid6), secid6, S_OK},
588     {url7, 3,   S_OK, sizeof(secid7), secid7, S_OK}
589 };
590
591 static void test_SecurityManager(void)
592 {
593     int i;
594     IInternetSecurityManager *secmgr = NULL;
595     BYTE buf[512];
596     DWORD zone, size;
597     HRESULT hres;
598
599     hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
600     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
601     if(FAILED(hres))
602         return;
603
604     for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
605         zone = 100;
606         hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
607                                                      &zone, 0);
608         ok(hres == secmgr_tests[i].zone_hres,
609            "[%d] MapUrlToZone failed: %08x, expected %08x\n",
610                 i, hres, secmgr_tests[i].zone_hres);
611         ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
612                 secmgr_tests[i].zone);
613
614         size = sizeof(buf);
615         memset(buf, 0xf0, sizeof(buf));
616         hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
617                 buf, &size, 0);
618         ok(hres == secmgr_tests[i].secid_hres,
619            "[%d] GetSecurityId failed: %08x, expected %08x\n",
620            i, hres, secmgr_tests[i].secid_hres);
621         if(secmgr_tests[i].secid) {
622             ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
623                     i, size, secmgr_tests[i].secid_size);
624             ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
625         }
626     }
627
628     zone = 100;
629     hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
630     ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
631
632     size = sizeof(buf);
633     hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
634     ok(hres == E_INVALIDARG,
635        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
636     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
637                                                   NULL, &size, 0);
638     ok(hres == E_INVALIDARG,
639        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
640     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
641                                                   buf, NULL, 0);
642     ok(hres == E_INVALIDARG,
643        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
644
645     IInternetSecurityManager_Release(secmgr);
646 }
647
648 static void test_ZoneManager(void)
649 {
650     IInternetZoneManager *zonemgr = NULL;
651     BYTE buf[32];
652     HRESULT hres;
653
654     hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
655     ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
656     if(FAILED(hres))
657         return;
658
659     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
660             sizeof(DWORD), URLZONEREG_DEFAULT);
661     ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
662     ok(*(DWORD*)buf == 1, "policy=%d, expected 1\n", *(DWORD*)buf);
663
664     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
665             sizeof(DWORD), URLZONEREG_DEFAULT);
666     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
667
668     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
669             2, URLZONEREG_DEFAULT);
670     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
671
672     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
673             sizeof(DWORD), URLZONEREG_DEFAULT);
674     ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08x, expected E_FAIL\n", hres);
675
676     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
677             sizeof(DWORD), URLZONEREG_DEFAULT);
678     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
679
680     IInternetZoneManager_Release(zonemgr);
681 }
682
683 static void register_protocols(void)
684 {
685     IInternetSession *session;
686     IClassFactory *factory;
687     HRESULT hres;
688
689     static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
690
691     hres = CoInternetGetSession(0, &session, 0);
692     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
693     if(FAILED(hres))
694         return;
695
696     hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
697             &IID_IClassFactory, (void**)&factory);
698     ok(hres == S_OK, "Coud not get AboutProtocol factory: %08x\n", hres);
699     if(FAILED(hres))
700         return;
701
702     IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
703                                        wszAbout, 0, NULL, 0);
704     IClassFactory_Release(factory);
705
706 }
707
708 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
709                                                           REFIID riid, void **ppv)
710 {
711     ok(0, "unexpected call\n");
712     return E_NOINTERFACE;
713 }
714
715 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
716 {
717     return 2;
718 }
719
720 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
721 {
722     return 1;
723 }
724
725 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
726         PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
727         DWORD *pcchResult, DWORD dwReserved)
728 {
729     CHECK_EXPECT(ParseUrl);
730     return E_NOTIMPL;
731 }
732
733 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
734         LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
735         LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
736 {
737     ok(0, "unexpected call\n");
738     return E_NOTIMPL;
739 }
740
741 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
742         LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
743 {
744     ok(0, "unexpected call\n");
745     return E_NOTIMPL;
746 }
747
748 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
749         LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
750         DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
751 {
752     ok(0, "unexpected call\n");
753     return E_NOTIMPL;
754 }
755
756 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
757     InternetProtocolInfo_QueryInterface,
758     InternetProtocolInfo_AddRef,
759     InternetProtocolInfo_Release,
760     InternetProtocolInfo_ParseUrl,
761     InternetProtocolInfo_CombineUrl,
762     InternetProtocolInfo_CompareUrl,
763     InternetProtocolInfo_QueryInfo
764 };
765
766 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
767
768 static HRESULT qiret;
769 static IClassFactory *expect_cf;
770
771 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
772 {
773     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
774         CHECK_EXPECT(QI_IInternetProtocolInfo);
775         ok(iface == expect_cf, "unexpected iface\n");
776         *ppv = &protocol_info;
777         return qiret;
778     }
779
780     ok(0, "unexpected call\n");
781     return E_NOINTERFACE;
782 }
783
784 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
785 {
786     return 2;
787 }
788
789 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
790 {
791     return 1;
792 }
793
794 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
795                                         REFIID riid, void **ppv)
796 {
797     CHECK_EXPECT(CreateInstance);
798
799     ok(iface == expect_cf, "unexpected iface\n");
800     ok(pOuter == NULL, "pOuter = %p\n", pOuter);
801     ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
802     ok(ppv != NULL, "ppv == NULL\n");
803
804     *ppv = &protocol_info;
805     return S_OK;
806 }
807
808 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
809 {
810     ok(0, "unexpected call\n");
811     return S_OK;
812 }
813
814 static const IClassFactoryVtbl ClassFactoryVtbl = {
815     ClassFactory_QueryInterface,
816     ClassFactory_AddRef,
817     ClassFactory_Release,
818     ClassFactory_CreateInstance,
819     ClassFactory_LockServer
820 };
821
822 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
823 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
824
825 static void test_NameSpace(void)
826 {
827     IInternetSession *session;
828     WCHAR buf[200];
829     DWORD size;
830     HRESULT hres;
831
832     static const WCHAR wszTest[] = {'t','e','s','t',0};
833
834     hres = CoInternetGetSession(0, &session, 0);
835     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
836     if(FAILED(hres))
837         return;
838
839     hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
840                                               wszTest, 0, NULL, 0);
841     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
842
843     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
844                                               NULL, 0, NULL, 0);
845     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
846
847     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
848                                               wszTest, 0, NULL, 0);
849     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
850
851     qiret = E_NOINTERFACE;
852     expect_cf = &test_protocol_cf;
853     SET_EXPECT(QI_IInternetProtocolInfo);
854     SET_EXPECT(CreateInstance);
855     SET_EXPECT(ParseUrl);
856
857     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
858                               &size, 0);
859     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
860
861     CHECK_CALLED(QI_IInternetProtocolInfo);
862     CHECK_CALLED(CreateInstance);
863     CHECK_CALLED(ParseUrl);
864
865     qiret = S_OK;
866     SET_EXPECT(QI_IInternetProtocolInfo);
867     SET_EXPECT(ParseUrl);
868
869     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
870                               &size, 0);
871     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
872
873     CHECK_CALLED(QI_IInternetProtocolInfo);
874     CHECK_CALLED(ParseUrl);
875
876     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
877     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
878
879     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
880                               &size, 0);
881     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
882
883     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
884                                               wszTest, 0, NULL, 0);
885     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
886
887     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
888                                               wszTest, 0, NULL, 0);
889     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
890
891     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
892                                               wszTest, 0, NULL, 0);
893     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
894
895     SET_EXPECT(QI_IInternetProtocolInfo);
896     SET_EXPECT(ParseUrl);
897
898     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
899                               &size, 0);
900     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
901
902     CHECK_CALLED(QI_IInternetProtocolInfo);
903     CHECK_CALLED(ParseUrl);
904
905     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
906     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
907
908     SET_EXPECT(QI_IInternetProtocolInfo);
909     SET_EXPECT(ParseUrl);
910
911     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
912                               &size, 0);
913     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
914
915     CHECK_CALLED(QI_IInternetProtocolInfo);
916     CHECK_CALLED(ParseUrl);
917
918     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
919     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
920
921     expect_cf = &test_protocol_cf2;
922     SET_EXPECT(QI_IInternetProtocolInfo);
923     SET_EXPECT(ParseUrl);
924
925     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
926                               &size, 0);
927     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
928
929     CHECK_CALLED(QI_IInternetProtocolInfo);
930     CHECK_CALLED(ParseUrl);
931
932     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
933     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
934     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
935     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
936     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
937     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
938     hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
939     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
940
941     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
942     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
943
944     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
945                               &size, 0);
946     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
947
948     IInternetSession_Release(session);
949 }
950
951 static ULONG WINAPI unk_Release(IUnknown *iface)
952 {
953     CHECK_EXPECT(unk_Release);
954     return 0;
955 }
956
957 static const IUnknownVtbl unk_vtbl = {
958     (void*)0xdeadbeef,
959     (void*)0xdeadbeef,
960     unk_Release
961 };
962
963 static void test_ReleaseBindInfo(void)
964 {
965     BINDINFO bi;
966     IUnknown unk = { &unk_vtbl };
967
968     ReleaseBindInfo(NULL); /* shouldn't crash */
969
970     memset(&bi, 0, sizeof(bi));
971     bi.cbSize = sizeof(BINDINFO);
972     bi.pUnk = &unk;
973     SET_EXPECT(unk_Release);
974     ReleaseBindInfo(&bi);
975     ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
976     ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
977     CHECK_CALLED(unk_Release);
978
979     memset(&bi, 0, sizeof(bi));
980     bi.cbSize = offsetof(BINDINFO, pUnk);
981     bi.pUnk = &unk;
982     ReleaseBindInfo(&bi);
983     ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
984     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
985
986     memset(&bi, 0, sizeof(bi));
987     bi.pUnk = &unk;
988     ReleaseBindInfo(&bi);
989     ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
990     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
991 }
992
993 static void test_UrlMkGetSessionOption(void)
994 {
995     DWORD encoding, size;
996     HRESULT hres;
997
998     size = encoding = 0xdeadbeef;
999     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1000                                  sizeof(encoding), &size, 0);
1001     ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1002     ok(encoding != 0xdeadbeef, "encoding not changed\n");
1003     ok(size == sizeof(encoding), "size=%d\n", size);
1004
1005     size = encoding = 0xdeadbeef;
1006     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1007                                  sizeof(encoding)+1, &size, 0);
1008     ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1009     ok(encoding != 0xdeadbeef, "encoding not changed\n");
1010     ok(size == sizeof(encoding), "size=%d\n", size);
1011
1012     size = encoding = 0xdeadbeef;
1013     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1014                                  sizeof(encoding)-1, &size, 0);
1015     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1016     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1017     ok(size == 0xdeadbeef, "size=%d\n", size);
1018
1019     size = encoding = 0xdeadbeef;
1020     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1021                                  sizeof(encoding)-1, &size, 0);
1022     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1023     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1024     ok(size == 0xdeadbeef, "size=%d\n", size);
1025
1026     encoding = 0xdeadbeef;
1027     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1028                                  sizeof(encoding)-1, NULL, 0);
1029     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1030     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1031 }
1032
1033 START_TEST(misc)
1034 {
1035     OleInitialize(NULL);
1036
1037     register_protocols();
1038
1039     test_CreateFormatEnum();
1040     test_RegisterFormatEnumerator();
1041     test_CoInternetParseUrl();
1042     test_FindMimeFromData();
1043     test_SecurityManager();
1044     test_ZoneManager();
1045     test_NameSpace();
1046     test_ReleaseBindInfo();
1047     test_UrlMkGetSessionOption();
1048
1049     OleUninitialize();
1050 }