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