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