wined3d: Implement more GLSL instructions and a little cleanup.
[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
334 static const struct {
335     LPCWSTR url;
336     LPCWSTR mime;
337 } mime_tests[] = {
338     {url1, mimeTextHtml},
339     {url2, mimeTextHtml},
340     {url3, mimeTextHtml},
341     {url4, NULL},
342     {url5, NULL},
343     {url6, NULL},
344     {url7, NULL}
345 };
346
347 static BYTE data1[] = "test data\n";
348 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
349 static BYTE data3[] = {0,0,0};
350 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
351 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
352 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
353 static BYTE data7[] = "<html>blahblah";
354 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
355 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
356 static BYTE data10[] = "<HtmL>blahblah";
357 static BYTE data11[] = "blah<HTML>blahblah";
358 static BYTE data12[] = "blah<HTMLblahblah";
359 static BYTE data13[] = "blahHTML>blahblah";
360 static BYTE data14[] = "blah<HTMblahblah";
361
362 static const struct {
363     BYTE *data;
364     DWORD size;
365     LPCWSTR mime;
366 } mime_tests2[] = {
367     {data1, sizeof(data1), mimeTextPlain},
368     {data2, sizeof(data2), mimeAppOctetStream},
369     {data3, sizeof(data3), mimeAppOctetStream},
370     {data4, sizeof(data4), mimeAppOctetStream},
371     {data5, sizeof(data5), mimeTextPlain},
372     {data6, sizeof(data6), mimeTextPlain},
373     {data7, sizeof(data7), mimeTextHtml},
374     {data8, sizeof(data8), mimeTextHtml},
375     {data9, sizeof(data9), mimeTextHtml},
376     {data10, sizeof(data10), mimeTextHtml},
377     {data11, sizeof(data11), mimeTextHtml},
378     {data12, sizeof(data12), mimeTextHtml},
379     {data13, sizeof(data13), mimeTextPlain},
380     {data14, sizeof(data14), mimeTextPlain}
381 };
382
383 static void test_FindMimeFromData(void)
384 {
385     HRESULT hres;
386     LPWSTR mime;
387     int i;
388
389     for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
390         mime = (LPWSTR)0xf0f0f0f0;
391         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
392         if(mime_tests[i].mime) {
393             ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
394             ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
395             CoTaskMemFree(mime);
396         }else {
397             ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
398             ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
399         }
400
401         mime = (LPWSTR)0xf0f0f0f0;
402         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
403         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
404         ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
405         CoTaskMemFree(mime);
406
407         mime = (LPWSTR)0xf0f0f0f0;
408         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
409         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
410         ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
411         CoTaskMemFree(mime);
412     }
413
414     for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
415         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
416                 NULL, 0, &mime, 0);
417         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
418         ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
419         CoTaskMemFree(mime);
420
421         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
422                 mimeTextHtml, 0, &mime, 0);
423         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
424         ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
425         CoTaskMemFree(mime);
426     }
427
428     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
429     ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
430     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
431     CoTaskMemFree(mime);
432
433     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
434     ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
435     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
436     CoTaskMemFree(mime);
437
438     hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
439     ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
440     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
441     CoTaskMemFree(mime);
442
443     hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
444     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, excepted E_INVALIDARG\n", hres);
445
446     hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
447     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
448
449     hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
450     ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
451
452     hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
453     ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
454
455     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
456     ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
457     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
458     CoTaskMemFree(mime);
459
460     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
461     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
462 }
463
464 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
465 static const BYTE secid4[] ={'f','i','l','e',':',3,0,0,0};
466 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','w','i','n','e','h','q',
467     '.','o','r','g',3,0,0,0};
468 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
469 static const BYTE secid7[] = {'f','t','p',':','w','i','n','e','h','q','.','o','r','g',
470                               3,0,0,0};
471
472 static struct secmgr_test {
473     LPCWSTR url;
474     DWORD zone;
475     HRESULT zone_hres;
476     DWORD secid_size;
477     const BYTE *secid;
478     HRESULT secid_hres;
479 } secmgr_tests[] = {
480     {url1, 0,   S_OK, sizeof(secid1), secid1, S_OK},
481     {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
482     {url3, 0,   S_OK, sizeof(secid1), secid1, S_OK},
483     {url4, 3,   S_OK, sizeof(secid4), secid4, S_OK},
484     {url5, 3,   S_OK, sizeof(secid5), secid5, S_OK},
485     {url6, 3,   S_OK, sizeof(secid6), secid6, S_OK},
486     {url7, 3,   S_OK, sizeof(secid7), secid7, S_OK}
487 };
488
489 static void test_SecurityManager(void)
490 {
491     int i;
492     IInternetSecurityManager *secmgr = NULL;
493     BYTE buf[512];
494     DWORD zone, size;
495     HRESULT hres;
496
497     hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
498     ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08lx\n", hres);
499     if(FAILED(hres))
500         return;
501
502     for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
503         zone = 100;
504         hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
505                                                      &zone, 0);
506         ok(hres == secmgr_tests[i].zone_hres,
507            "[%d] MapUrlToZone failed: %08lx, expected %08lx\n",
508                 i, hres, secmgr_tests[i].zone_hres);
509         ok(zone == secmgr_tests[i].zone, "[%d] zone=%ld, expected %ld\n", i, zone,
510                 secmgr_tests[i].zone);
511
512         size = sizeof(buf);
513         memset(buf, 0xf0, sizeof(buf));
514         hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
515                 buf, &size, 0);
516         ok(hres == secmgr_tests[i].secid_hres,
517            "[%d] GetSecurityId failed: %08lx, expected %08lx\n",
518            i, hres, secmgr_tests[i].secid_hres);
519         if(secmgr_tests[i].secid) {
520             ok(size == secmgr_tests[i].secid_size, "[%d] size=%ld, expected %ld\n",
521                     i, size, secmgr_tests[i].secid_size);
522             ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
523         }
524     }
525
526     zone = 100;
527     hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
528     ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08lx, expected E_INVALIDARG\n", hres);
529
530     size = sizeof(buf);
531     hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
532     ok(hres == E_INVALIDARG,
533        "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
534     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
535                                                   NULL, &size, 0);
536     ok(hres == E_INVALIDARG,
537        "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
538     hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
539                                                   buf, NULL, 0);
540     ok(hres == E_INVALIDARG,
541        "GetSecurityId failed: %08lx, expected E_INVALIDARG\n", hres);
542
543     IInternetSecurityManager_Release(secmgr);
544 }
545
546 static void test_ZoneManager(void)
547 {
548     IInternetZoneManager *zonemgr = NULL;
549     BYTE buf[32];
550     HRESULT hres;
551
552     hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
553     ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08lx\n", hres);
554     if(FAILED(hres))
555         return;
556
557     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
558             sizeof(DWORD), URLZONEREG_DEFAULT);
559     ok(hres == S_OK, "GetZoneActionPolicy failed: %08lx\n", hres);
560     ok(*(DWORD*)buf == 1, "policy=%ld, expected 1\n", *(DWORD*)buf);
561
562     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
563             sizeof(DWORD), URLZONEREG_DEFAULT);
564     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
565
566     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
567             2, URLZONEREG_DEFAULT);
568     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
569
570     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
571             sizeof(DWORD), URLZONEREG_DEFAULT);
572     ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08lx, expected E_FAIL\n", hres);
573
574     hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
575             sizeof(DWORD), URLZONEREG_DEFAULT);
576     ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
577
578     IInternetZoneManager_Release(zonemgr);
579 }
580
581 static void register_protocols(void)
582 {
583     IInternetSession *session;
584     IClassFactory *factory;
585     HRESULT hres;
586
587     static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
588
589     hres = CoInternetGetSession(0, &session, 0);
590     ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
591     if(FAILED(hres))
592         return;
593
594     hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
595             &IID_IClassFactory, (void**)&factory);
596     ok(hres == S_OK, "Coud not get AboutProtocol factory: %08lx\n", hres);
597     if(FAILED(hres))
598         return;
599
600     IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
601                                        wszAbout, 0, NULL, 0);
602     IClassFactory_Release(factory);
603
604 }
605
606 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
607                                                           REFIID riid, void **ppv)
608 {
609     ok(0, "unexpected call\n");
610     return E_NOINTERFACE;
611 }
612
613 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
614 {
615     return 2;
616 }
617
618 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
619 {
620     return 1;
621 }
622
623 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
624         PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
625         DWORD *pcchResult, DWORD dwReserved)
626 {
627     CHECK_EXPECT(ParseUrl);
628     return E_NOTIMPL;
629 }
630
631 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
632         LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
633         LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
634 {
635     ok(0, "unexpected call\n");
636     return E_NOTIMPL;
637 }
638
639 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
640         LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
641 {
642     ok(0, "unexpected call\n");
643     return E_NOTIMPL;
644 }
645
646 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
647         LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
648         DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
649 {
650     ok(0, "unexpected call\n");
651     return E_NOTIMPL;
652 }
653
654 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
655     InternetProtocolInfo_QueryInterface,
656     InternetProtocolInfo_AddRef,
657     InternetProtocolInfo_Release,
658     InternetProtocolInfo_ParseUrl,
659     InternetProtocolInfo_CombineUrl,
660     InternetProtocolInfo_CompareUrl,
661     InternetProtocolInfo_QueryInfo
662 };
663
664 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
665
666 static HRESULT qiret;
667 static IClassFactory *expect_cf;
668
669 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
670 {
671     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
672         CHECK_EXPECT(QI_IInternetProtocolInfo);
673         ok(iface == expect_cf, "unexpected iface\n");
674         *ppv = &protocol_info;
675         return qiret;
676     }
677
678     ok(0, "unexpected call\n");
679     return E_NOINTERFACE;
680 }
681
682 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
683 {
684     return 2;
685 }
686
687 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
688 {
689     return 1;
690 }
691
692 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
693                                         REFIID riid, void **ppv)
694 {
695     CHECK_EXPECT(CreateInstance);
696
697     ok(iface == expect_cf, "unexpected iface\n");
698     ok(pOuter == NULL, "pOuter = %p\n", pOuter);
699     ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
700     ok(ppv != NULL, "ppv == NULL\n");
701
702     *ppv = &protocol_info;
703     return S_OK;
704 }
705
706 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
707 {
708     ok(0, "unexpected call\n");
709     return S_OK;
710 }
711
712 static const IClassFactoryVtbl ClassFactoryVtbl = {
713     ClassFactory_QueryInterface,
714     ClassFactory_AddRef,
715     ClassFactory_Release,
716     ClassFactory_CreateInstance,
717     ClassFactory_LockServer
718 };
719
720 static IClassFactory test_protocol_cf = { &ClassFactoryVtbl };
721 static IClassFactory test_protocol_cf2 = { &ClassFactoryVtbl };
722
723 static void test_NameSpace(void)
724 {
725     IInternetSession *session;
726     WCHAR buf[200];
727     DWORD size;
728     HRESULT hres;
729
730     static const WCHAR wszTest[] = {'t','e','s','t',0};
731
732     hres = CoInternetGetSession(0, &session, 0);
733     ok(hres == S_OK, "CoInternetGetSession failed: %08lx\n", hres);
734     if(FAILED(hres))
735         return;
736
737     hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
738                                               wszTest, 0, NULL, 0);
739     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08lx\n", hres);
740
741     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
742                                               NULL, 0, NULL, 0);
743     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08lx\n", hres);
744
745     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
746                                               wszTest, 0, NULL, 0);
747     ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
748
749     qiret = E_NOINTERFACE;
750     expect_cf = &test_protocol_cf;
751     SET_EXPECT(QI_IInternetProtocolInfo);
752     SET_EXPECT(CreateInstance);
753     SET_EXPECT(ParseUrl);
754
755     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
756                               &size, 0);
757     ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
758
759     CHECK_CALLED(QI_IInternetProtocolInfo);
760     CHECK_CALLED(CreateInstance);
761     CHECK_CALLED(ParseUrl);
762
763     qiret = S_OK;
764     SET_EXPECT(QI_IInternetProtocolInfo);
765     SET_EXPECT(ParseUrl);
766
767     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
768                               &size, 0);
769     ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
770
771     CHECK_CALLED(QI_IInternetProtocolInfo);
772     CHECK_CALLED(ParseUrl);
773
774     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
775     ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
776
777     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
778                               &size, 0);
779     ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
780
781     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
782                                               wszTest, 0, NULL, 0);
783     ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
784
785     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
786                                               wszTest, 0, NULL, 0);
787     ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
788
789     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
790                                               wszTest, 0, NULL, 0);
791     ok(hres == S_OK, "RegisterNameSpace failed: %08lx\n", hres);
792
793     SET_EXPECT(QI_IInternetProtocolInfo);
794     SET_EXPECT(ParseUrl);
795
796     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
797                               &size, 0);
798     ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
799
800     CHECK_CALLED(QI_IInternetProtocolInfo);
801     CHECK_CALLED(ParseUrl);
802
803     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
804     ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
805
806     SET_EXPECT(QI_IInternetProtocolInfo);
807     SET_EXPECT(ParseUrl);
808
809     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
810                               &size, 0);
811     ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
812
813     CHECK_CALLED(QI_IInternetProtocolInfo);
814     CHECK_CALLED(ParseUrl);
815
816     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
817     ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
818
819     expect_cf = &test_protocol_cf2;
820     SET_EXPECT(QI_IInternetProtocolInfo);
821     SET_EXPECT(ParseUrl);
822
823     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
824                               &size, 0);
825     ok(hres == S_OK, "CoInternetParseUrl failed: %08lx\n", hres);
826
827     CHECK_CALLED(QI_IInternetProtocolInfo);
828     CHECK_CALLED(ParseUrl);
829
830     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
831     ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
832     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
833     ok(hres == S_OK, "UnregisterNameSpace failed: %08lx\n", hres);
834     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
835     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08lx\n", hres);
836     hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
837     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08lx\n", hres);
838
839     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, 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     IInternetSession_Release(session);
847 }
848
849 static ULONG WINAPI unk_Release(IUnknown *iface)
850 {
851     CHECK_EXPECT(unk_Release);
852     return 0;
853 }
854
855 static const IUnknownVtbl unk_vtbl = {
856     (void*)0xdeadbeef,
857     (void*)0xdeadbeef,
858     unk_Release
859 };
860
861 static void test_ReleaseBindInfo(void)
862 {
863     BINDINFO bi;
864     IUnknown unk = { &unk_vtbl };
865
866     ReleaseBindInfo(NULL); /* shouldn't crash */
867
868     memset(&bi, 0, sizeof(bi));
869     bi.cbSize = sizeof(BINDINFO);
870     bi.pUnk = &unk;
871     SET_EXPECT(unk_Release);
872     ReleaseBindInfo(&bi);
873     ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%ld\n", bi.cbSize);
874     ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
875     CHECK_CALLED(unk_Release);
876
877     memset(&bi, 0, sizeof(bi));
878     bi.cbSize = offsetof(BINDINFO, pUnk);
879     bi.pUnk = &unk;
880     ReleaseBindInfo(&bi);
881     ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%ld\n", bi.cbSize);
882     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
883
884     memset(&bi, 0, sizeof(bi));
885     bi.pUnk = &unk;
886     ReleaseBindInfo(&bi);
887     ok(!bi.cbSize, "bi.cbSize=%ld, expected 0\n", bi.cbSize);
888     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
889 }
890
891 START_TEST(misc)
892 {
893     OleInitialize(NULL);
894
895     register_protocols();
896
897     test_CreateFormatEnum();
898     test_RegisterFormatEnumerator();
899     test_CoInternetParseUrl();
900     test_FindMimeFromData();
901     test_SecurityManager();
902     test_ZoneManager();
903     test_NameSpace();
904     test_ReleaseBindInfo();
905
906     OleUninitialize();
907 }