riched20: Fix one more memory leak.
[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 static const WCHAR mimeImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
339 static const WCHAR mimeVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
340 static const WCHAR mimeVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
341
342 static const struct {
343     LPCWSTR url;
344     LPCWSTR mime;
345 } mime_tests[] = {
346     {url1, mimeTextHtml},
347     {url2, mimeTextHtml},
348     {url3, mimeTextHtml},
349     {url4, NULL},
350     {url5, NULL},
351     {url6, NULL},
352     {url7, NULL}
353 };
354
355 static BYTE data1[] = "test data\n";
356 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
357 static BYTE data3[] = {0,0,0};
358 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
359 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
360 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
361 static BYTE data7[] = "<html>blahblah";
362 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
363 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
364 static BYTE data10[] = "<HtmL>blahblah";
365 static BYTE data11[] = "blah<HTML>blahblah";
366 static BYTE data12[] = "blah<HTMLblahblah";
367 static BYTE data13[] = "blahHTML>blahblah";
368 static BYTE data14[] = "blah<HTMblahblah";
369 static BYTE data15[] = {0xff,0xd8};
370 static BYTE data16[] = {0xff,0xd8,'h'};
371 static BYTE data17[] = {0,0xff,0xd8};
372 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
373 static BYTE data19[] = {'G','I','F','8','7','a'};
374 static BYTE data20[] = {'G','I','F','8','9','a'};
375 static BYTE data21[] = {'G','I','F','8','7'};
376 static BYTE data22[] = {'G','i','F','8','7','a'};
377 static BYTE data23[] = {'G','i','F','8','8','a'};
378 static BYTE data24[] = {'g','i','f','8','7','a'};
379 static BYTE data25[] = {'G','i','F','8','7','A'};
380 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
381 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
382 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
383 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
384 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
385 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
386 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
387 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
388 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
389 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
390 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
391 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
392 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
393 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a};
394 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
395 static BYTE data41[] = {0x4d,0x4d,0xff};
396 static BYTE data42[] = {0x4d,0x4d};
397 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
398 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
399 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
400 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
401 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
402 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
403 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
404 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
405 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
406 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
407 static BYTE data53[] = {0x00,0x00,0x01,0xba};
408 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
409
410 static const struct {
411     BYTE *data;
412     DWORD size;
413     LPCWSTR mime;
414 } mime_tests2[] = {
415     {data1, sizeof(data1), mimeTextPlain},
416     {data2, sizeof(data2), mimeAppOctetStream},
417     {data3, sizeof(data3), mimeAppOctetStream},
418     {data4, sizeof(data4), mimeAppOctetStream},
419     {data5, sizeof(data5), mimeTextPlain},
420     {data6, sizeof(data6), mimeTextPlain},
421     {data7, sizeof(data7), mimeTextHtml},
422     {data8, sizeof(data8), mimeTextHtml},
423     {data9, sizeof(data9), mimeTextHtml},
424     {data10, sizeof(data10), mimeTextHtml},
425     {data11, sizeof(data11), mimeTextHtml},
426     {data12, sizeof(data12), mimeTextHtml},
427     {data13, sizeof(data13), mimeTextPlain},
428     {data14, sizeof(data14), mimeTextPlain},
429     {data15, sizeof(data15), mimeTextPlain},
430     {data16, sizeof(data16), mimeImagePjpeg},
431     {data17, sizeof(data17), mimeAppOctetStream},
432     {data18, sizeof(data18), mimeTextHtml},
433     {data19, sizeof(data19), mimeImageGif},
434     {data20, sizeof(data20), mimeImageGif},
435     {data21, sizeof(data21), mimeTextPlain},
436     {data22, sizeof(data22), mimeImageGif},
437     {data23, sizeof(data23), mimeTextPlain},
438     {data24, sizeof(data24), mimeImageGif},
439     {data25, sizeof(data25), mimeImageGif},
440     {data26, sizeof(data26), mimeTextHtml},
441     {data27, sizeof(data27), mimeTextPlain},
442     {data28, sizeof(data28), mimeImageBmp},
443     {data29, sizeof(data29), mimeImageBmp},
444     {data30, sizeof(data30), mimeAppOctetStream},
445     {data31, sizeof(data31), mimeTextHtml},
446     {data32, sizeof(data32), mimeAppOctetStream},
447     {data33, sizeof(data33), mimeAppOctetStream},
448     {data34, sizeof(data34), mimeImageXPng},
449     {data35, sizeof(data35), mimeImageXPng},
450     {data36, sizeof(data36), mimeAppOctetStream},
451     {data37, sizeof(data37), mimeTextHtml},
452     {data38, sizeof(data38), mimeAppOctetStream},
453     {data39, sizeof(data39), mimeImageTiff},
454     {data40, sizeof(data40), mimeTextHtml},
455     {data41, sizeof(data41), mimeImageTiff},
456     {data42, sizeof(data42), mimeTextPlain},
457     {data43, sizeof(data43), mimeAppOctetStream},
458     {data44, sizeof(data44), mimeVideoAvi},
459     {data45, sizeof(data45), mimeTextPlain},
460     {data46, sizeof(data46), mimeTextPlain},
461     {data47, sizeof(data47), mimeTextPlain},
462     {data48, sizeof(data48), mimeTextHtml},
463     {data49, sizeof(data49), mimeVideoAvi},
464     {data50, sizeof(data50), mimeVideoMpeg},
465     {data51, sizeof(data51), mimeVideoMpeg},
466     {data52, sizeof(data52), mimeAppOctetStream},
467     {data53, sizeof(data53), mimeAppOctetStream},
468     {data54, sizeof(data54), mimeTextHtml}
469 };
470
471 static void test_FindMimeFromData(void)
472 {
473     HRESULT hres;
474     LPWSTR mime;
475     int i;
476
477     for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
478         mime = (LPWSTR)0xf0f0f0f0;
479         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
480         if(mime_tests[i].mime) {
481             ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
482             ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
483             CoTaskMemFree(mime);
484         }else {
485             ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
486             ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
487         }
488
489         mime = (LPWSTR)0xf0f0f0f0;
490         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
491         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
492         ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
493         CoTaskMemFree(mime);
494
495         mime = (LPWSTR)0xf0f0f0f0;
496         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
497         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
498         ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
499         CoTaskMemFree(mime);
500     }
501
502     for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
503         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
504                 NULL, 0, &mime, 0);
505         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
506         ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
507         CoTaskMemFree(mime);
508
509         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
510                 mimeTextHtml, 0, &mime, 0);
511         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
512         if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
513            || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
514             ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
515         else
516             ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
517
518         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
519                 mimeImagePjpeg, 0, &mime, 0);
520         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
521         if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
522             ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
523         else
524             ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
525
526         CoTaskMemFree(mime);
527     }
528
529     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
530     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
531     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
532     CoTaskMemFree(mime);
533
534     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
535     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
536     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
537     CoTaskMemFree(mime);
538
539     hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
540     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
541     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
542     CoTaskMemFree(mime);
543
544     hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
545     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, excepted E_INVALIDARG\n", hres);
546
547     hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
548     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
549
550     hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
551     ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
552
553     hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
554     ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
555
556     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
557     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
558     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
559     CoTaskMemFree(mime);
560
561     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
562     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
563 }
564
565 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
566 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
567 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
568     '.','o','r','g',3,0,0,0};
569 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
570 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
571                               3,0,0,0};
572
573 static struct secmgr_test {
574     LPCWSTR url;
575     DWORD zone;
576     HRESULT zone_hres;
577     DWORD secid_size;
578     const BYTE *secid;
579     HRESULT secid_hres;
580 } secmgr_tests[] = {
581     {url1, 0,   S_OK, sizeof(secid1), secid1, S_OK},
582     {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
583     {url3, 0,   S_OK, sizeof(secid1), secid1, S_OK},
584     {url4, 3,   S_OK, sizeof(secid4), secid4, S_OK},
585     {url5, 3,   S_OK, sizeof(secid5), secid5, S_OK},
586     {url6, 3,   S_OK, sizeof(secid6), secid6, S_OK},
587     {url7, 3,   S_OK, sizeof(secid7), secid7, S_OK}
588 };
589
590 static void test_SecurityManager(void)
591 {
592     int i;
593     IInternetSecurityManager *secmgr = NULL;
594     BYTE buf[512];
595     DWORD zone, size;
596     HRESULT hres;
597
598     hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
599     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
600     if(FAILED(hres))
601         return;
602
603     for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
604         zone = 100;
605         hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
606                                                      &zone, 0);
607         ok(hres == secmgr_tests[i].zone_hres,
608            "[%d] MapUrlToZone failed: %08x, expected %08x\n",
609                 i, hres, secmgr_tests[i].zone_hres);
610         ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
611                 secmgr_tests[i].zone);
612
613         size = sizeof(buf);
614         memset(buf, 0xf0, sizeof(buf));
615         hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
616                 buf, &size, 0);
617         ok(hres == secmgr_tests[i].secid_hres,
618            "[%d] GetSecurityId failed: %08x, expected %08x\n",
619            i, hres, secmgr_tests[i].secid_hres);
620         if(secmgr_tests[i].secid) {
621             ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
622                     i, size, secmgr_tests[i].secid_size);
623             ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
624         }
625     }
626
627     zone = 100;
628     hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
629     ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
630
631     size = sizeof(buf);
632     hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
633     ok(hres == E_INVALIDARG,
634        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
635     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
636                                                   NULL, &size, 0);
637     ok(hres == E_INVALIDARG,
638        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
639     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
640                                                   buf, NULL, 0);
641     ok(hres == E_INVALIDARG,
642        "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
643
644     IInternetSecurityManager_Release(secmgr);
645 }
646
647 static void test_ZoneManager(void)
648 {
649     IInternetZoneManager *zonemgr = NULL;
650     BYTE buf[32];
651     HRESULT hres;
652
653     hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
654     ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
655     if(FAILED(hres))
656         return;
657
658     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
659             sizeof(DWORD), URLZONEREG_DEFAULT);
660     ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
661     ok(*(DWORD*)buf == 1, "policy=%d, expected 1\n", *(DWORD*)buf);
662
663     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
664             sizeof(DWORD), URLZONEREG_DEFAULT);
665     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
666
667     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
668             2, URLZONEREG_DEFAULT);
669     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
670
671     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
672             sizeof(DWORD), URLZONEREG_DEFAULT);
673     ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08x, expected E_FAIL\n", hres);
674
675     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
676             sizeof(DWORD), URLZONEREG_DEFAULT);
677     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
678
679     IInternetZoneManager_Release(zonemgr);
680 }
681
682 static void register_protocols(void)
683 {
684     IInternetSession *session;
685     IClassFactory *factory;
686     HRESULT hres;
687
688     static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
689
690     hres = CoInternetGetSession(0, &session, 0);
691     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
692     if(FAILED(hres))
693         return;
694
695     hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
696             &IID_IClassFactory, (void**)&factory);
697     ok(hres == S_OK, "Coud not get AboutProtocol factory: %08x\n", hres);
698     if(FAILED(hres))
699         return;
700
701     IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
702                                        wszAbout, 0, NULL, 0);
703     IClassFactory_Release(factory);
704
705 }
706
707 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
708                                                           REFIID riid, void **ppv)
709 {
710     ok(0, "unexpected call\n");
711     return E_NOINTERFACE;
712 }
713
714 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
715 {
716     return 2;
717 }
718
719 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
720 {
721     return 1;
722 }
723
724 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
725         PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
726         DWORD *pcchResult, DWORD dwReserved)
727 {
728     CHECK_EXPECT(ParseUrl);
729     return E_NOTIMPL;
730 }
731
732 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
733         LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
734         LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
735 {
736     ok(0, "unexpected call\n");
737     return E_NOTIMPL;
738 }
739
740 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
741         LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
742 {
743     ok(0, "unexpected call\n");
744     return E_NOTIMPL;
745 }
746
747 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
748         LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
749         DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
750 {
751     ok(0, "unexpected call\n");
752     return E_NOTIMPL;
753 }
754
755 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
756     InternetProtocolInfo_QueryInterface,
757     InternetProtocolInfo_AddRef,
758     InternetProtocolInfo_Release,
759     InternetProtocolInfo_ParseUrl,
760     InternetProtocolInfo_CombineUrl,
761     InternetProtocolInfo_CompareUrl,
762     InternetProtocolInfo_QueryInfo
763 };
764
765 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
766
767 static HRESULT qiret;
768 static IClassFactory *expect_cf;
769
770 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
771 {
772     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
773         CHECK_EXPECT(QI_IInternetProtocolInfo);
774         ok(iface == expect_cf, "unexpected iface\n");
775         *ppv = &protocol_info;
776         return qiret;
777     }
778
779     ok(0, "unexpected call\n");
780     return E_NOINTERFACE;
781 }
782
783 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
784 {
785     return 2;
786 }
787
788 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
789 {
790     return 1;
791 }
792
793 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
794                                         REFIID riid, void **ppv)
795 {
796     CHECK_EXPECT(CreateInstance);
797
798     ok(iface == expect_cf, "unexpected iface\n");
799     ok(pOuter == NULL, "pOuter = %p\n", pOuter);
800     ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
801     ok(ppv != NULL, "ppv == NULL\n");
802
803     *ppv = &protocol_info;
804     return S_OK;
805 }
806
807 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
808 {
809     ok(0, "unexpected call\n");
810     return S_OK;
811 }
812
813 static const IClassFactoryVtbl ClassFactoryVtbl = {
814     ClassFactory_QueryInterface,
815     ClassFactory_AddRef,
816     ClassFactory_Release,
817     ClassFactory_CreateInstance,
818     ClassFactory_LockServer
819 };
820
821 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
822 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
823
824 static void test_NameSpace(void)
825 {
826     IInternetSession *session;
827     WCHAR buf[200];
828     DWORD size;
829     HRESULT hres;
830
831     static const WCHAR wszTest[] = {'t','e','s','t',0};
832
833     hres = CoInternetGetSession(0, &session, 0);
834     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
835     if(FAILED(hres))
836         return;
837
838     hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
839                                               wszTest, 0, NULL, 0);
840     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
841
842     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
843                                               NULL, 0, NULL, 0);
844     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
845
846     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
847                                               wszTest, 0, NULL, 0);
848     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
849
850     qiret = E_NOINTERFACE;
851     expect_cf = &test_protocol_cf;
852     SET_EXPECT(QI_IInternetProtocolInfo);
853     SET_EXPECT(CreateInstance);
854     SET_EXPECT(ParseUrl);
855
856     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
857                               &size, 0);
858     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
859
860     CHECK_CALLED(QI_IInternetProtocolInfo);
861     CHECK_CALLED(CreateInstance);
862     CHECK_CALLED(ParseUrl);
863
864     qiret = S_OK;
865     SET_EXPECT(QI_IInternetProtocolInfo);
866     SET_EXPECT(ParseUrl);
867
868     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
869                               &size, 0);
870     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
871
872     CHECK_CALLED(QI_IInternetProtocolInfo);
873     CHECK_CALLED(ParseUrl);
874
875     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
876     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
877
878     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
879                               &size, 0);
880     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
881
882     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
883                                               wszTest, 0, NULL, 0);
884     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
885
886     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
887                                               wszTest, 0, NULL, 0);
888     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
889
890     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
891                                               wszTest, 0, NULL, 0);
892     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
893
894     SET_EXPECT(QI_IInternetProtocolInfo);
895     SET_EXPECT(ParseUrl);
896
897     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
898                               &size, 0);
899     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
900
901     CHECK_CALLED(QI_IInternetProtocolInfo);
902     CHECK_CALLED(ParseUrl);
903
904     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
905     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
906
907     SET_EXPECT(QI_IInternetProtocolInfo);
908     SET_EXPECT(ParseUrl);
909
910     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
911                               &size, 0);
912     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
913
914     CHECK_CALLED(QI_IInternetProtocolInfo);
915     CHECK_CALLED(ParseUrl);
916
917     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
918     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
919
920     expect_cf = &test_protocol_cf2;
921     SET_EXPECT(QI_IInternetProtocolInfo);
922     SET_EXPECT(ParseUrl);
923
924     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
925                               &size, 0);
926     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
927
928     CHECK_CALLED(QI_IInternetProtocolInfo);
929     CHECK_CALLED(ParseUrl);
930
931     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
932     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
933     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
934     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
935     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
936     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
937     hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
938     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
939
940     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
941     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
942
943     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
944                               &size, 0);
945     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
946
947     IInternetSession_Release(session);
948 }
949
950 static ULONG WINAPI unk_Release(IUnknown *iface)
951 {
952     CHECK_EXPECT(unk_Release);
953     return 0;
954 }
955
956 static const IUnknownVtbl unk_vtbl = {
957     (void*)0xdeadbeef,
958     (void*)0xdeadbeef,
959     unk_Release
960 };
961
962 static void test_ReleaseBindInfo(void)
963 {
964     BINDINFO bi;
965     IUnknown unk = { &unk_vtbl };
966
967     ReleaseBindInfo(NULL); /* shouldn't crash */
968
969     memset(&bi, 0, sizeof(bi));
970     bi.cbSize = sizeof(BINDINFO);
971     bi.pUnk = &unk;
972     SET_EXPECT(unk_Release);
973     ReleaseBindInfo(&bi);
974     ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
975     ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
976     CHECK_CALLED(unk_Release);
977
978     memset(&bi, 0, sizeof(bi));
979     bi.cbSize = offsetof(BINDINFO, pUnk);
980     bi.pUnk = &unk;
981     ReleaseBindInfo(&bi);
982     ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
983     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
984
985     memset(&bi, 0, sizeof(bi));
986     bi.pUnk = &unk;
987     ReleaseBindInfo(&bi);
988     ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
989     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
990 }
991
992 static void test_UrlMkGetSessionOption(void)
993 {
994     DWORD encoding, size;
995     HRESULT hres;
996
997     size = encoding = 0xdeadbeef;
998     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
999                                  sizeof(encoding), &size, 0);
1000     ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1001     ok(encoding != 0xdeadbeef, "encoding not changed\n");
1002     ok(size == sizeof(encoding), "size=%d\n", size);
1003
1004     size = encoding = 0xdeadbeef;
1005     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1006                                  sizeof(encoding)+1, &size, 0);
1007     ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1008     ok(encoding != 0xdeadbeef, "encoding not changed\n");
1009     ok(size == sizeof(encoding), "size=%d\n", size);
1010
1011     size = encoding = 0xdeadbeef;
1012     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1013                                  sizeof(encoding)-1, &size, 0);
1014     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1015     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1016     ok(size == 0xdeadbeef, "size=%d\n", size);
1017
1018     size = encoding = 0xdeadbeef;
1019     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1020                                  sizeof(encoding)-1, &size, 0);
1021     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1022     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1023     ok(size == 0xdeadbeef, "size=%d\n", size);
1024
1025     encoding = 0xdeadbeef;
1026     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1027                                  sizeof(encoding)-1, NULL, 0);
1028     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1029     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1030 }
1031
1032 START_TEST(misc)
1033 {
1034     OleInitialize(NULL);
1035
1036     register_protocols();
1037
1038     test_CreateFormatEnum();
1039     test_RegisterFormatEnumerator();
1040     test_CoInternetParseUrl();
1041     test_FindMimeFromData();
1042     test_SecurityManager();
1043     test_ZoneManager();
1044     test_NameSpace();
1045     test_ReleaseBindInfo();
1046     test_UrlMkGetSessionOption();
1047
1048     OleUninitialize();
1049 }