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