urlmon/tests: Avoid size_t in a trace.
[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 #define NONAMELESSUNION
22
23 #include <wine/test.h>
24 #include <stdarg.h>
25 #include <stddef.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "ole2.h"
30 #include "urlmon.h"
31
32 #include "initguid.h"
33
34 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
35
36 #define DEFINE_EXPECT(func) \
37     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
38
39 #define SET_EXPECT(func) \
40     expect_ ## func = TRUE
41
42 #define CHECK_EXPECT(func) \
43     do { \
44         ok(expect_ ##func, "unexpected call " #func "\n"); \
45         expect_ ## func = FALSE; \
46         called_ ## func = TRUE; \
47     }while(0)
48
49 #define CHECK_EXPECT2(func) \
50     do { \
51         ok(expect_ ##func, "unexpected call " #func "\n"); \
52         called_ ## func = TRUE; \
53     }while(0)
54
55 #define CHECK_CALLED(func) \
56     do { \
57         ok(called_ ## func, "expected " #func "\n"); \
58         expect_ ## func = called_ ## func = FALSE; \
59     }while(0)
60
61 DEFINE_EXPECT(ParseUrl);
62 DEFINE_EXPECT(QI_IInternetProtocolInfo);
63 DEFINE_EXPECT(CreateInstance);
64 DEFINE_EXPECT(unk_Release);
65
66 static void test_CreateFormatEnum(void)
67 {
68     IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
69     FORMATETC fetc[5];
70     ULONG ul;
71     HRESULT hres;
72
73     static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
74     static FORMATETC formatetc[] = {
75         {0,&dev,0,0,0},
76         {0,&dev,0,1,0},
77         {0,NULL,0,2,0},
78         {0,NULL,0,3,0},
79         {0,NULL,0,4,0}
80     };
81
82     hres = CreateFormatEnumerator(0, formatetc, &fenum);
83     ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
84     hres = CreateFormatEnumerator(0, formatetc, NULL);
85     ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
86     hres = CreateFormatEnumerator(5, formatetc, NULL);
87     ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
88
89
90     hres = CreateFormatEnumerator(5, formatetc, &fenum);
91     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
92     if(FAILED(hres))
93         return;
94
95     hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
96     ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
97     ul = 100;
98     hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
99     ok(hres == S_OK, "Next failed: %08x\n", hres);
100     ok(ul == 0, "ul=%d, expected 0\n", ul);
101
102     hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
103     ok(hres == S_OK, "Next failed: %08x\n", hres);
104     ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
105     ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
106     ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
107     ok(ul == 2, "ul=%d, expected 2\n", ul);
108
109     hres = IEnumFORMATETC_Skip(fenum, 1);
110     ok(hres == S_OK, "Skip failed: %08x\n", hres);
111
112     hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
113     ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
114     ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
115     ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
116     ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
117     ok(ul == 2, "ul=%d, expected 2\n", ul);
118
119     hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
120     ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
121     ok(ul == 0, "ul=%d, expected 0\n", ul);
122     ul = 100;
123     hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
124     ok(hres == S_OK, "Next failed: %08x\n", hres);
125     ok(ul == 0, "ul=%d, expected 0\n", ul);
126
127     hres = IEnumFORMATETC_Skip(fenum, 3);
128     ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
129
130     hres = IEnumFORMATETC_Reset(fenum);
131     ok(hres == S_OK, "Reset failed: %08x\n", hres);
132
133     hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
134     ok(hres == S_OK, "Next failed: %08x\n", hres);
135     ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
136
137     hres = IEnumFORMATETC_Reset(fenum);
138     ok(hres == S_OK, "Reset failed: %08x\n", hres);
139
140     hres = IEnumFORMATETC_Skip(fenum, 2);
141     ok(hres == S_OK, "Skip failed: %08x\n", hres);
142
143     hres = IEnumFORMATETC_Clone(fenum, NULL);
144     ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
145
146     hres = IEnumFORMATETC_Clone(fenum, &fenum2);
147     ok(hres == S_OK, "Clone failed: %08x\n", hres);
148
149     if(SUCCEEDED(hres)) {
150         ok(fenum != fenum2, "fenum == fenum2\n");
151
152         hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
153         ok(hres == S_OK, "Next failed: %08x\n", hres);
154         ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
155
156         IEnumFORMATETC_Release(fenum2);
157     }
158
159     hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
160     ok(hres == S_OK, "Next failed: %08x\n", hres);
161     ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
162
163     hres = IEnumFORMATETC_Skip(fenum, 1);
164     ok(hres == S_OK, "Skip failed: %08x\n", hres);
165     
166     IEnumFORMATETC_Release(fenum);
167 }
168
169 static void test_RegisterFormatEnumerator(void)
170 {
171     IBindCtx *bctx = NULL;
172     IEnumFORMATETC *format = NULL, *format2 = NULL;
173     IUnknown *unk = NULL;
174     HRESULT hres;
175
176     static FORMATETC formatetc = {0,NULL,0,0,0};
177     static WCHAR wszEnumFORMATETC[] =
178         {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
179
180     CreateBindCtx(0, &bctx);
181
182     hres = CreateFormatEnumerator(1, &formatetc, &format);
183     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
184     if(FAILED(hres))
185         return;
186
187     hres = RegisterFormatEnumerator(NULL, format, 0);
188     ok(hres == E_INVALIDARG,
189             "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
190     hres = RegisterFormatEnumerator(bctx, NULL, 0);
191     ok(hres == E_INVALIDARG,
192             "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
193
194     hres = RegisterFormatEnumerator(bctx, format, 0);
195     ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
196
197     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
198     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
199     ok(unk == (IUnknown*)format, "unk != format\n");
200
201     hres = RevokeFormatEnumerator(NULL, format);
202     ok(hres == E_INVALIDARG,
203             "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
204
205     hres = RevokeFormatEnumerator(bctx, format);
206     ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
207
208     hres = RevokeFormatEnumerator(bctx, format);
209     ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
210
211     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
212     ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
213
214     hres = RegisterFormatEnumerator(bctx, format, 0);
215     ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
216
217     hres = CreateFormatEnumerator(1, &formatetc, &format2);
218     ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
219
220     if(SUCCEEDED(hres)) {
221         hres = RevokeFormatEnumerator(bctx, format);
222         ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
223
224         IEnumFORMATETC_Release(format2);
225     }
226
227     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
228     ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
229
230     IEnumFORMATETC_Release(format);
231
232     hres = RegisterFormatEnumerator(bctx, format, 0);
233     ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
234     hres = RevokeFormatEnumerator(bctx, NULL);
235     ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
236     hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
237     ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
238
239     IEnumFORMATETC_Release(format);
240     IBindCtx_Release(bctx);
241 }
242
243 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
244         '/','b','l','a','n','k','.','h','t','m',0};
245 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
246 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
247 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
248         '%','2','e','j','p','g',0};
249 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
250         '.','o','r','g',0};
251 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
252 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
253         'f','i','l','e','.','t','e','s','t',0};
254 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
255 static const WCHAR url9[] =
256     {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',
257      '/','s','i','t','e','/','a','b','o','u','t',0};
258 static const WCHAR url10[] = {'f','i','l','e',':','/','/','s','o','m','e','%','2','0','f','i','l','e',
259         '.','j','p','g',0};
260
261 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
262         '.','j','p','g',0};
263
264 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
265 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
266
267 static const WCHAR wszRes[] = {'r','e','s',0};
268 static const WCHAR wszFile[] = {'f','i','l','e',0};
269 static const WCHAR wszHttp[] = {'h','t','t','p',0};
270 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
271 static const WCHAR wszEmpty[] = {0};
272
273 static const WCHAR wszWineHQ[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
274 static const WCHAR wszHttpWineHQ[] = {'h','t','t','p',':','/','/','w','w','w','.',
275     'w','i','n','e','h','q','.','o','r','g',0};
276
277 struct parse_test {
278     LPCWSTR url;
279     HRESULT secur_hres;
280     LPCWSTR encoded_url;
281     HRESULT path_hres;
282     LPCWSTR path;
283     LPCWSTR schema;
284     LPCWSTR domain;
285     HRESULT domain_hres;
286     LPCWSTR rootdocument;
287     HRESULT rootdocument_hres;
288 };
289
290 static const struct parse_test parse_tests[] = {
291     {url1, S_OK,   url1,  E_INVALIDARG, NULL, wszRes, NULL, E_FAIL, NULL, E_FAIL},
292     {url2, E_FAIL, url2,  E_INVALIDARG, NULL, wszEmpty, NULL, E_FAIL, NULL, E_FAIL},
293     {url3, E_FAIL, url3,  S_OK, path3,        wszFile, wszEmpty, S_OK, NULL, E_FAIL},
294     {url4, E_FAIL, url4e, S_OK, path4,        wszFile, wszEmpty, S_OK, NULL, E_FAIL},
295     {url5, E_FAIL, url5,  E_INVALIDARG, NULL, wszHttp, wszWineHQ, S_OK, wszHttpWineHQ, S_OK},
296     {url6, S_OK,   url6,  E_INVALIDARG, NULL, wszAbout, NULL, E_FAIL, NULL, E_FAIL},
297 };
298
299 static void test_CoInternetParseUrl(void)
300 {
301     HRESULT hres;
302     DWORD size;
303     int i;
304
305     static WCHAR buf[4096];
306
307     memset(buf, 0xf0, sizeof(buf));
308     hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
309             3, &size, 0);
310     ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
311
312     for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
313         memset(buf, 0xf0, sizeof(buf));
314         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
315                 sizeof(buf)/sizeof(WCHAR), &size, 0);
316         ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
317                 i, hres, parse_tests[i].secur_hres);
318
319         memset(buf, 0xf0, sizeof(buf));
320         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
321                 sizeof(buf)/sizeof(WCHAR), &size, 0);
322         ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
323         ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
324         ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
325
326         memset(buf, 0xf0, sizeof(buf));
327         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
328                 sizeof(buf)/sizeof(WCHAR), &size, 0);
329         ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
330                 i, hres, parse_tests[i].path_hres);
331         if(parse_tests[i].path) {
332             ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
333             ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
334         }
335
336         memset(buf, 0xf0, sizeof(buf));
337         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
338                 sizeof(buf)/sizeof(WCHAR), &size, 0);
339         ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
340         ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
341         ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
342
343         if(memcmp(parse_tests[i].url, wszRes, 3*sizeof(WCHAR))
344                 && memcmp(parse_tests[i].url, wszAbout, 5*sizeof(WCHAR))) {
345             memset(buf, 0xf0, sizeof(buf));
346             hres = CoInternetParseUrl(parse_tests[i].url, PARSE_DOMAIN, 0, buf,
347                     sizeof(buf)/sizeof(WCHAR), &size, 0);
348             ok(hres == parse_tests[i].domain_hres, "[%d] domain failed: %08x\n", i, hres);
349             if(parse_tests[i].domain)
350                 ok(!lstrcmpW(parse_tests[i].domain, buf), "[%d] wrong domain, received %s\n", i, wine_dbgstr_w(buf));
351         }
352
353         memset(buf, 0xf0, sizeof(buf));
354         hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ROOTDOCUMENT, 0, buf,
355                 sizeof(buf)/sizeof(WCHAR), &size, 0);
356         ok(hres == parse_tests[i].rootdocument_hres, "[%d] rootdocument failed: %08x\n", i, hres);
357         if(parse_tests[i].rootdocument)
358             ok(!lstrcmpW(parse_tests[i].rootdocument, buf), "[%d] wrong rootdocument, received %s\n", i, wine_dbgstr_w(buf));
359     }
360 }
361
362 static void test_CoInternetCompareUrl(void)
363 {
364     HRESULT hres;
365
366     hres = CoInternetCompareUrl(url1, url1, 0);
367     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
368
369     hres = CoInternetCompareUrl(url1, url3, 0);
370     ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
371
372     hres = CoInternetCompareUrl(url3, url1, 0);
373     ok(hres == S_FALSE, "CoInternetParseUrl failed: %08x\n", hres);
374 }
375
376 static const struct {
377     LPCWSTR url;
378     DWORD uses_net;
379 } query_info_tests[] = {
380     {url1, 0},
381     {url2, 0},
382     {url3, 0},
383     {url4, 0},
384     {url5, 0},
385     {url6, 0},
386     {url7, 0},
387     {url8, 0}
388 };
389
390 static void test_CoInternetQueryInfo(void)
391 {
392     BYTE buf[100];
393     DWORD cb, i;
394     HRESULT hres;
395
396     for(i=0; i < sizeof(query_info_tests)/sizeof(query_info_tests[0]); i++) {
397         cb = 0xdeadbeef;
398         memset(buf, '?', sizeof(buf));
399         hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), &cb, 0);
400         ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
401         ok(cb == sizeof(DWORD), "[%d] cb = %d\n", i, cb);
402         ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
403            i, *(DWORD*)buf, query_info_tests[i].uses_net);
404
405         hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, 3, &cb, 0);
406         ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
407         hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, NULL, sizeof(buf), &cb, 0);
408         ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
409
410         memset(buf, '?', sizeof(buf));
411         hres = CoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), NULL, 0);
412         ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
413         ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
414            i, *(DWORD*)buf, query_info_tests[i].uses_net);
415     }
416 }
417
418 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
419 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
420 static const WCHAR mimeTextRichtext[] = {'t','e','x','t','/','r','i','c','h','t','e','x','t',0};
421 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
422     'o','c','t','e','t','-','s','t','r','e','a','m',0};
423 static const WCHAR mimeImagePjpeg[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
424 static const WCHAR mimeImageGif[] = {'i','m','a','g','e','/','g','i','f',0};
425 static const WCHAR mimeImageBmp[] = {'i','m','a','g','e','/','b','m','p',0};
426 static const WCHAR mimeImageXPng[] = {'i','m','a','g','e','/','x','-','p','n','g',0};
427 static const WCHAR mimeImageTiff[] = {'i','m','a','g','e','/','t','i','f','f',0};
428 static const WCHAR mimeVideoAvi[] = {'v','i','d','e','o','/','a','v','i',0};
429 static const WCHAR mimeVideoMpeg[] = {'v','i','d','e','o','/','m','p','e','g',0};
430 static const WCHAR mimeAppPostscript[] =
431     {'a','p','p','l','i','c','a','t','i','o','n','/','p','o','s','t','s','c','r','i','p','t',0};
432 static const WCHAR mimeAppXCompressed[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
433                                     'x','-','c','o','m','p','r','e','s','s','e','d',0};
434 static const WCHAR mimeAppXZip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
435                                     'x','-','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
436 static const WCHAR mimeAppXGzip[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
437                                     'x','-','g','z','i','p','-','c','o','m','p','r','e','s','s','e','d',0};
438 static const WCHAR mimeAppJava[] = {'a','p','p','l','i','c','a','t','i','o','n','/','j','a','v','a',0};
439 static const WCHAR mimeAppPdf[] = {'a','p','p','l','i','c','a','t','i','o','n','/','p','d','f',0};
440 static const WCHAR mimeAppXMSDownload[] =
441     {'a','p','p','l','i','c','a','t','i','o','n','/','x','-','m','s','d','o','w','n','l','o','a','d',0};
442 static const WCHAR mimeAudioWav[] = {'a','u','d','i','o','/','w','a','v',0};
443 static const WCHAR mimeAudioBasic[] = {'a','u','d','i','o','/','b','a','s','i','c',0};
444
445 static const struct {
446     LPCWSTR url;
447     LPCWSTR mime;
448     HRESULT hres;
449 } mime_tests[] = {
450     {url1, mimeTextHtml, S_OK},
451     {url2, mimeTextHtml, S_OK},
452     {url3, mimeTextHtml, S_OK},
453     {url4, NULL, E_FAIL},
454     {url5, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)},
455     {url6, NULL, E_FAIL},
456     {url7, NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)}
457 };
458
459 static BYTE data1[] = "test data\n";
460 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
461 static BYTE data3[] = {0,0,0};
462 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
463 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
464 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
465 static BYTE data7[] = "<html>blahblah";
466 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
467 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
468 static BYTE data10[] = "<HtmL>blahblah";
469 static BYTE data11[] = "blah<HTML>blahblah";
470 static BYTE data12[] = "blah<HTMLblahblah";
471 static BYTE data13[] = "blahHTML>blahblah";
472 static BYTE data14[] = "blah<HTMblahblah";
473 static BYTE data15[] = {0xff,0xd8};
474 static BYTE data16[] = {0xff,0xd8,'h'};
475 static BYTE data17[] = {0,0xff,0xd8};
476 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
477 static BYTE data19[] = {'G','I','F','8','7','a'};
478 static BYTE data20[] = {'G','I','F','8','9','a'};
479 static BYTE data21[] = {'G','I','F','8','7'};
480 static BYTE data22[] = {'G','i','F','8','7','a'};
481 static BYTE data23[] = {'G','i','F','8','8','a'};
482 static BYTE data24[] = {'g','i','f','8','7','a'};
483 static BYTE data25[] = {'G','i','F','8','7','A'};
484 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
485 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
486 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
487 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
488 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
489 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
490 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
491 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
492 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
493 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
494 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
495 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
496 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
497 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a};
498 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
499 static BYTE data41[] = {0x4d,0x4d,0xff};
500 static BYTE data42[] = {0x4d,0x4d};
501 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
502 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
503 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
504 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
505 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
506 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
507 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
508 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
509 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
510 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
511 static BYTE data53[] = {0x00,0x00,0x01,0xba};
512 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
513 static BYTE data55[] = {0x1f,0x8b,'x'};
514 static BYTE data56[] = {0x1f};
515 static BYTE data57[] = {0x1f,0x8b,'<','h','t','m','l','>','t','e','s','t',0};
516 static BYTE data58[] = {0x1f,0x8b};
517 static BYTE data59[] = {0x50,0x4b,'x'};
518 static BYTE data60[] = {0x50,0x4b};
519 static BYTE data61[] = {0x50,0x4b,'<','h','t','m','l','>',0};
520 static BYTE data62[] = {0xca,0xfe,0xba,0xbe,'x'};
521 static BYTE data63[] = {0xca,0xfe,0xba,0xbe};
522 static BYTE data64[] = {0xca,0xfe,0xba,0xbe,'<','h','t','m','l','>',0};
523 static BYTE data65[] = {0x25,0x50,0x44,0x46,'x'};
524 static BYTE data66[] = {0x25,0x50,0x44,0x46};
525 static BYTE data67[] = {0x25,0x50,0x44,0x46,'x','<','h','t','m','l','>'};
526 static BYTE data68[] = {'M','Z','x'};
527 static BYTE data69[] = {'M','Z'};
528 static BYTE data70[] = {'M','Z','<','h','t','m','l','>',0xff};
529 static BYTE data71[] = {'{','\\','r','t','f',0};
530 static BYTE data72[] = {'{','\\','r','t','f'};
531 static BYTE data73[] = {' ','{','\\','r','t','f',' '};
532 static BYTE data74[] = {'{','\\','r','t','f','<','h','t','m','l','>',' '};
533 static BYTE data75[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E',0xff};
534 static BYTE data76[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E'};
535 static BYTE data77[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V',0xff,0xff};
536 static BYTE data78[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'<','h','t','m','l','>',0xff};
537 static BYTE data79[] = {'%','!',0xff};
538 static BYTE data80[] = {'%','!'};
539 static BYTE data81[] = {'%','!','P','S','<','h','t','m','l','>'};
540 static BYTE data82[] = {'.','s','n','d',0};
541 static BYTE data83[] = {'.','s','n','d'};
542 static BYTE data84[] = {'.','s','n','d',0,'<','h','t','m','l','>',1,1};
543 static BYTE data85[] = {'.','S','N','D',0};
544
545 static const struct {
546     BYTE *data;
547     DWORD size;
548     LPCWSTR mime, mime_alt;
549 } mime_tests2[] = {
550     {data1, sizeof(data1), mimeTextPlain},
551     {data2, sizeof(data2), mimeAppOctetStream},
552     {data3, sizeof(data3), mimeAppOctetStream},
553     {data4, sizeof(data4), mimeAppOctetStream},
554     {data5, sizeof(data5), mimeTextPlain},
555     {data6, sizeof(data6), mimeTextPlain},
556     {data7, sizeof(data7), mimeTextHtml, mimeTextPlain /* IE8 */},
557     {data8, sizeof(data8), mimeTextHtml, mimeTextPlain /* IE8 */},
558     {data9, sizeof(data9), mimeTextHtml, mimeImagePjpeg /* IE8 */},
559     {data10, sizeof(data10), mimeTextHtml, mimeTextPlain /* IE8 */},
560     {data11, sizeof(data11), mimeTextHtml, mimeTextPlain /* IE8 */},
561     {data12, sizeof(data12), mimeTextHtml, mimeTextPlain /* IE8 */},
562     {data13, sizeof(data13), mimeTextPlain},
563     {data14, sizeof(data14), mimeTextPlain},
564     {data15, sizeof(data15), mimeTextPlain},
565     {data16, sizeof(data16), mimeImagePjpeg},
566     {data17, sizeof(data17), mimeAppOctetStream},
567     {data18, sizeof(data18), mimeTextHtml},
568     {data19, sizeof(data19), mimeImageGif},
569     {data20, sizeof(data20), mimeImageGif},
570     {data21, sizeof(data21), mimeTextPlain},
571     {data22, sizeof(data22), mimeImageGif},
572     {data23, sizeof(data23), mimeTextPlain},
573     {data24, sizeof(data24), mimeImageGif},
574     {data25, sizeof(data25), mimeImageGif},
575     {data26, sizeof(data26), mimeTextHtml, mimeImageGif /* IE8 */},
576     {data27, sizeof(data27), mimeTextPlain},
577     {data28, sizeof(data28), mimeImageBmp},
578     {data29, sizeof(data29), mimeImageBmp},
579     {data30, sizeof(data30), mimeAppOctetStream},
580     {data31, sizeof(data31), mimeTextHtml, mimeImageBmp /* IE8 */},
581     {data32, sizeof(data32), mimeAppOctetStream},
582     {data33, sizeof(data33), mimeAppOctetStream},
583     {data34, sizeof(data34), mimeImageXPng},
584     {data35, sizeof(data35), mimeImageXPng},
585     {data36, sizeof(data36), mimeAppOctetStream},
586     {data37, sizeof(data37), mimeTextHtml, mimeImageXPng /* IE8 */},
587     {data38, sizeof(data38), mimeAppOctetStream},
588     {data39, sizeof(data39), mimeImageTiff},
589     {data40, sizeof(data40), mimeTextHtml, mimeImageTiff /* IE8 */},
590     {data41, sizeof(data41), mimeImageTiff},
591     {data42, sizeof(data42), mimeTextPlain},
592     {data43, sizeof(data43), mimeAppOctetStream},
593     {data44, sizeof(data44), mimeVideoAvi},
594     {data45, sizeof(data45), mimeTextPlain},
595     {data46, sizeof(data46), mimeTextPlain},
596     {data47, sizeof(data47), mimeTextPlain},
597     {data48, sizeof(data48), mimeTextHtml, mimeVideoAvi /* IE8 */},
598     {data49, sizeof(data49), mimeVideoAvi},
599     {data50, sizeof(data50), mimeVideoMpeg},
600     {data51, sizeof(data51), mimeVideoMpeg},
601     {data52, sizeof(data52), mimeAppOctetStream},
602     {data53, sizeof(data53), mimeAppOctetStream},
603     {data54, sizeof(data54), mimeTextHtml, mimeVideoMpeg /* IE8 */},
604     {data55, sizeof(data55), mimeAppXGzip},
605     {data56, sizeof(data56), mimeTextPlain},
606     {data57, sizeof(data57), mimeTextHtml, mimeAppXGzip /* IE8 */},
607     {data58, sizeof(data58), mimeAppOctetStream},
608     {data59, sizeof(data59), mimeAppXZip},
609     {data60, sizeof(data60), mimeTextPlain},
610     {data61, sizeof(data61), mimeTextHtml, mimeAppXZip /* IE8 */},
611     {data62, sizeof(data62), mimeAppJava},
612     {data63, sizeof(data63), mimeTextPlain},
613     {data64, sizeof(data64), mimeTextHtml, mimeAppJava /* IE8 */},
614     {data65, sizeof(data65), mimeAppPdf},
615     {data66, sizeof(data66), mimeTextPlain},
616     {data67, sizeof(data67), mimeTextHtml, mimeAppPdf /* IE8 */},
617     {data68, sizeof(data68), mimeAppXMSDownload},
618     {data69, sizeof(data69), mimeTextPlain},
619     {data70, sizeof(data70), mimeTextHtml, mimeAppXMSDownload /* IE8 */},
620     {data71, sizeof(data71), mimeTextRichtext},
621     {data72, sizeof(data72), mimeTextPlain},
622     {data73, sizeof(data73), mimeTextPlain},
623     {data74, sizeof(data74), mimeTextHtml, mimeTextRichtext /* IE8 */},
624     {data75, sizeof(data75), mimeAudioWav},
625     {data76, sizeof(data76), mimeTextPlain},
626     {data77, sizeof(data77), mimeTextPlain},
627     {data78, sizeof(data78), mimeTextHtml, mimeTextPlain /* IE8 */},
628     {data79, sizeof(data79), mimeAppPostscript},
629     {data80, sizeof(data80), mimeTextPlain},
630     {data81, sizeof(data81), mimeTextHtml, mimeAppPostscript /* IE8 */},
631     {data82, sizeof(data82), mimeAudioBasic},
632     {data83, sizeof(data83), mimeTextPlain},
633     {data84, sizeof(data84), mimeTextHtml, mimeAudioBasic /* IE8 */},
634     {data85, sizeof(data85), mimeTextPlain}
635 };
636
637 static void test_FindMimeFromData(void)
638 {
639     HRESULT hres;
640     LPWSTR mime;
641     int i;
642
643     for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
644         mime = (LPWSTR)0xf0f0f0f0;
645         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
646         if(mime_tests[i].mime) {
647             ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
648             ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
649             CoTaskMemFree(mime);
650         }else {
651             ok(hres == E_FAIL || hres == mime_tests[i].hres,
652                "[%d] FindMimeFromData failed: %08x, expected %08x\n",
653                i, hres, mime_tests[i].hres);
654             ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
655         }
656
657         mime = (LPWSTR)0xf0f0f0f0;
658         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
659         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
660         ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
661         CoTaskMemFree(mime);
662
663         mime = (LPWSTR)0xf0f0f0f0;
664         hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
665         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
666         ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
667         CoTaskMemFree(mime);
668     }
669
670     for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
671         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
672                 NULL, 0, &mime, 0);
673         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
674         ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
675         CoTaskMemFree(mime);
676
677         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
678                 mimeTextHtml, 0, &mime, 0);
679         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
680         if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime)
681            || !lstrcmpW(mimeTextPlain, mime_tests2[i].mime))
682             ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
683         else
684             ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
685         CoTaskMemFree(mime);
686
687         hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
688                 mimeImagePjpeg, 0, &mime, 0);
689         ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
690         if(!lstrcmpW(mimeAppOctetStream, mime_tests2[i].mime) || i == 17)
691             ok(!lstrcmpW(mime, mimeImagePjpeg), "[%d] wrong mime\n", i);
692         else
693             ok(!lstrcmpW(mime, mime_tests2[i].mime) ||
694                     (mime_tests2[i].mime_alt && !lstrcmpW(mime, mime_tests2[i].mime_alt)),
695                     "[%d] wrong mime, got %s\n", i, wine_dbgstr_w(mime));
696
697         CoTaskMemFree(mime);
698     }
699
700     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
701     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
702     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
703     CoTaskMemFree(mime);
704
705     hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
706     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
707     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
708     CoTaskMemFree(mime);
709
710     hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
711     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
712     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
713     CoTaskMemFree(mime);
714
715     hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
716     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, excepted E_INVALIDARG\n", hres);
717
718     hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
719     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
720
721     hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
722     ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
723
724     hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
725     ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
726
727     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
728     ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
729     ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
730     CoTaskMemFree(mime);
731
732     hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
733     ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
734 }
735
736 static void register_protocols(void)
737 {
738     IInternetSession *session;
739     IClassFactory *factory;
740     HRESULT hres;
741
742     static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
743
744     hres = CoInternetGetSession(0, &session, 0);
745     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
746     if(FAILED(hres))
747         return;
748
749     hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
750             &IID_IClassFactory, (void**)&factory);
751     ok(hres == S_OK, "Coud not get AboutProtocol factory: %08x\n", hres);
752     if(FAILED(hres))
753         return;
754
755     IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
756                                        wszAbout, 0, NULL, 0);
757     IClassFactory_Release(factory);
758
759     IInternetSession_Release(session);
760 }
761
762 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
763                                                           REFIID riid, void **ppv)
764 {
765     ok(0, "unexpected call\n");
766     return E_NOINTERFACE;
767 }
768
769 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
770 {
771     return 2;
772 }
773
774 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
775 {
776     return 1;
777 }
778
779 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
780         PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
781         DWORD *pcchResult, DWORD dwReserved)
782 {
783     CHECK_EXPECT2(ParseUrl);
784
785     if(ParseAction == PARSE_SECURITY_URL) {
786         if(pcchResult)
787             *pcchResult = sizeof(url1)/sizeof(WCHAR);
788
789         if(cchResult<sizeof(url1)/sizeof(WCHAR))
790             return S_FALSE;
791
792         memcpy(pwzResult, url1, sizeof(url1));
793         return S_OK;
794     }
795
796     return E_NOTIMPL;
797 }
798
799 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
800         LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
801         LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
802 {
803     ok(0, "unexpected call\n");
804     return E_NOTIMPL;
805 }
806
807 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
808         LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
809 {
810     ok(0, "unexpected call\n");
811     return E_NOTIMPL;
812 }
813
814 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
815         LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
816         DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
817 {
818     ok(0, "unexpected call\n");
819     return E_NOTIMPL;
820 }
821
822 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
823     InternetProtocolInfo_QueryInterface,
824     InternetProtocolInfo_AddRef,
825     InternetProtocolInfo_Release,
826     InternetProtocolInfo_ParseUrl,
827     InternetProtocolInfo_CombineUrl,
828     InternetProtocolInfo_CompareUrl,
829     InternetProtocolInfo_QueryInfo
830 };
831
832 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
833
834 static HRESULT qiret;
835 static IClassFactory *expect_cf;
836
837 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
838 {
839     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
840         CHECK_EXPECT2(QI_IInternetProtocolInfo);
841         ok(iface == expect_cf, "unexpected iface\n");
842         *ppv = &protocol_info;
843         return qiret;
844     }
845
846     ok(0, "unexpected call\n");
847     return E_NOINTERFACE;
848 }
849
850 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
851 {
852     return 2;
853 }
854
855 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
856 {
857     return 1;
858 }
859
860 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
861                                         REFIID riid, void **ppv)
862 {
863     ok(0, "unexpected call\n");
864     return E_NOTIMPL;
865 }
866
867 static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
868                                         REFIID riid, void **ppv)
869 {
870     CHECK_EXPECT(CreateInstance);
871
872     ok(iface == expect_cf, "unexpected iface\n");
873     ok(pOuter == NULL, "pOuter = %p\n", pOuter);
874     ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
875     ok(ppv != NULL, "ppv == NULL\n");
876
877     *ppv = &protocol_info;
878     return S_OK;
879 }
880
881 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
882 {
883     ok(0, "unexpected call\n");
884     return S_OK;
885 }
886
887 static const IClassFactoryVtbl ClassFactoryVtbl = {
888     ClassFactory_QueryInterface,
889     ClassFactory_AddRef,
890     ClassFactory_Release,
891     ClassFactory_CreateInstance,
892     ClassFactory_LockServer
893 };
894
895 static const IClassFactoryVtbl ProtocolCFVtbl = {
896     ClassFactory_QueryInterface,
897     ClassFactory_AddRef,
898     ClassFactory_Release,
899     ProtocolCF_CreateInstance,
900     ClassFactory_LockServer
901 };
902
903 static IClassFactory test_protocol_cf = { &ProtocolCFVtbl };
904 static IClassFactory test_protocol_cf2 = { &ProtocolCFVtbl };
905 static IClassFactory test_cf = { &ClassFactoryVtbl };
906
907 static void test_NameSpace(void)
908 {
909     IInternetSession *session;
910     WCHAR buf[200];
911     LPWSTR sec_url;
912     DWORD size;
913     HRESULT hres;
914
915     static const WCHAR wszTest[] = {'t','e','s','t',0};
916
917     hres = CoInternetGetSession(0, &session, 0);
918     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
919     if(FAILED(hres))
920         return;
921
922     hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
923                                               wszTest, 0, NULL, 0);
924     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
925
926     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
927                                               NULL, 0, NULL, 0);
928     ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
929
930     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
931                                               wszTest, 0, NULL, 0);
932     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
933
934     qiret = E_NOINTERFACE;
935     expect_cf = &test_protocol_cf;
936     SET_EXPECT(QI_IInternetProtocolInfo);
937     SET_EXPECT(CreateInstance);
938     SET_EXPECT(ParseUrl);
939
940     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
941                               &size, 0);
942     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
943
944     CHECK_CALLED(QI_IInternetProtocolInfo);
945     CHECK_CALLED(CreateInstance);
946     CHECK_CALLED(ParseUrl);
947
948     qiret = S_OK;
949     SET_EXPECT(QI_IInternetProtocolInfo);
950     SET_EXPECT(ParseUrl);
951
952     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
953                               &size, 0);
954     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
955
956     CHECK_CALLED(QI_IInternetProtocolInfo);
957     CHECK_CALLED(ParseUrl);
958
959     SET_EXPECT(QI_IInternetProtocolInfo);
960     SET_EXPECT(ParseUrl);
961
962     hres = CoInternetParseUrl(url8, PARSE_SECURITY_URL, 0, buf,
963             sizeof(buf)/sizeof(WCHAR), &size, 0);
964     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
965     ok(size == sizeof(url1)/sizeof(WCHAR), "Size = %d\n", size);
966     if(size == sizeof(url1)/sizeof(WCHAR))
967         ok(!memcmp(buf, url1, sizeof(url1)), "Encoded url = %s\n", wine_dbgstr_w(buf));
968
969     CHECK_CALLED(QI_IInternetProtocolInfo);
970     CHECK_CALLED(ParseUrl);
971
972     SET_EXPECT(QI_IInternetProtocolInfo);
973     SET_EXPECT(ParseUrl);
974
975     hres = CoInternetGetSecurityUrl(url8, &sec_url, PSU_SECURITY_URL_ONLY, 0);
976     ok(hres == S_OK, "CoInternetGetSecurityUrl failed: %08x\n", hres);
977     if(hres == S_OK) {
978         ok(lstrlenW(sec_url)>sizeof(wszFile)/sizeof(WCHAR) &&
979                 !memcmp(sec_url, wszFile, sizeof(wszFile)-sizeof(WCHAR)),
980                 "Encoded url = %s\n", wine_dbgstr_w(sec_url));
981         CoTaskMemFree(sec_url);
982     }
983
984     CHECK_CALLED(QI_IInternetProtocolInfo);
985     CHECK_CALLED(ParseUrl);
986
987     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
988     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
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     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
995                                               wszTest, 0, NULL, 0);
996     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
997
998     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
999                                               wszTest, 0, NULL, 0);
1000     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1001
1002     hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1003                                               wszTest, 0, NULL, 0);
1004     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1005
1006     SET_EXPECT(QI_IInternetProtocolInfo);
1007     SET_EXPECT(ParseUrl);
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     CHECK_CALLED(QI_IInternetProtocolInfo);
1014     CHECK_CALLED(ParseUrl);
1015
1016     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1017     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1018
1019     SET_EXPECT(QI_IInternetProtocolInfo);
1020     SET_EXPECT(ParseUrl);
1021
1022     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1023                               &size, 0);
1024     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1025
1026     CHECK_CALLED(QI_IInternetProtocolInfo);
1027     CHECK_CALLED(ParseUrl);
1028
1029     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1030     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1031
1032     expect_cf = &test_protocol_cf2;
1033     SET_EXPECT(QI_IInternetProtocolInfo);
1034     SET_EXPECT(ParseUrl);
1035
1036     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1037                               &size, 0);
1038     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1039
1040     CHECK_CALLED(QI_IInternetProtocolInfo);
1041     CHECK_CALLED(ParseUrl);
1042
1043     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1044     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1045     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1046     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1047     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
1048     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1049     hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
1050     ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1051
1052     hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
1053     ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1054
1055     hres = CoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1056                               &size, 0);
1057     ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1058
1059     IInternetSession_Release(session);
1060 }
1061
1062 static void test_MimeFilter(void)
1063 {
1064     IInternetSession *session;
1065     HRESULT hres;
1066
1067     static const WCHAR mimeW[] = {'t','e','s','t','/','m','i','m','e',0};
1068
1069     hres = CoInternetGetSession(0, &session, 0);
1070     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1071     if(FAILED(hres))
1072         return;
1073
1074     hres = IInternetSession_RegisterMimeFilter(session, &test_cf, &IID_NULL, mimeW);
1075     ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
1076
1077     hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1078     ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1079
1080     hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1081     ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1082
1083     hres = IInternetSession_UnregisterMimeFilter(session, (void*)0xdeadbeef, mimeW);
1084     ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1085
1086     IInternetSession_Release(session);
1087 }
1088
1089 static ULONG WINAPI unk_Release(IUnknown *iface)
1090 {
1091     CHECK_EXPECT(unk_Release);
1092     return 0;
1093 }
1094
1095 static const IUnknownVtbl unk_vtbl = {
1096     (void*)0xdeadbeef,
1097     (void*)0xdeadbeef,
1098     unk_Release
1099 };
1100
1101 static void test_ReleaseBindInfo(void)
1102 {
1103     BINDINFO bi;
1104     IUnknown unk = { &unk_vtbl };
1105
1106     ReleaseBindInfo(NULL); /* shouldn't crash */
1107
1108     memset(&bi, 0, sizeof(bi));
1109     bi.cbSize = sizeof(BINDINFO);
1110     bi.pUnk = &unk;
1111     SET_EXPECT(unk_Release);
1112     ReleaseBindInfo(&bi);
1113     ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
1114     ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
1115     CHECK_CALLED(unk_Release);
1116
1117     memset(&bi, 0, sizeof(bi));
1118     bi.cbSize = offsetof(BINDINFO, pUnk);
1119     bi.pUnk = &unk;
1120     ReleaseBindInfo(&bi);
1121     ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
1122     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1123
1124     memset(&bi, 0, sizeof(bi));
1125     bi.pUnk = &unk;
1126     ReleaseBindInfo(&bi);
1127     ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
1128     ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1129 }
1130
1131 static void test_CopyStgMedium(void)
1132 {
1133     STGMEDIUM src, dst;
1134     HGLOBAL empty;
1135     HRESULT hres;
1136
1137     static WCHAR fileW[] = {'f','i','l','e',0};
1138
1139     memset(&src, 0xf0, sizeof(src));
1140     memset(&dst, 0xe0, sizeof(dst));
1141     memset(&empty, 0xf0, sizeof(empty));
1142     src.tymed = TYMED_NULL;
1143     src.pUnkForRelease = NULL;
1144     hres = CopyStgMedium(&src, &dst);
1145     ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1146     ok(dst.tymed == TYMED_NULL, "tymed=%d\n", dst.tymed);
1147     ok(dst.u.hGlobal == empty, "u=%p\n", dst.u.hGlobal);
1148     ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1149
1150     memset(&dst, 0xe0, sizeof(dst));
1151     src.tymed = TYMED_ISTREAM;
1152     src.u.pstm = NULL;
1153     src.pUnkForRelease = NULL;
1154     hres = CopyStgMedium(&src, &dst);
1155     ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1156     ok(dst.tymed == TYMED_ISTREAM, "tymed=%d\n", dst.tymed);
1157     ok(!dst.u.pstm, "pstm=%p\n", dst.u.pstm);
1158     ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1159
1160     memset(&dst, 0xe0, sizeof(dst));
1161     src.tymed = TYMED_FILE;
1162     src.u.lpszFileName = fileW;
1163     src.pUnkForRelease = NULL;
1164     hres = CopyStgMedium(&src, &dst);
1165     ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1166     ok(dst.tymed == TYMED_FILE, "tymed=%d\n", dst.tymed);
1167     ok(dst.u.lpszFileName && dst.u.lpszFileName != fileW, "lpszFileName=%p\n", dst.u.lpszFileName);
1168     ok(!lstrcmpW(dst.u.lpszFileName, fileW), "wrong file name\n");
1169     ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1170
1171     hres = CopyStgMedium(&src, NULL);
1172     ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1173     hres = CopyStgMedium(NULL, &dst);
1174     ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1175 }
1176
1177 static void test_UrlMkGetSessionOption(void)
1178 {
1179     DWORD encoding, size;
1180     HRESULT hres;
1181
1182     size = encoding = 0xdeadbeef;
1183     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1184                                  sizeof(encoding), &size, 0);
1185     ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1186     ok(encoding != 0xdeadbeef, "encoding not changed\n");
1187     ok(size == sizeof(encoding), "size=%d\n", size);
1188
1189     size = encoding = 0xdeadbeef;
1190     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1191                                  sizeof(encoding)+1, &size, 0);
1192     ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1193     ok(encoding != 0xdeadbeef, "encoding not changed\n");
1194     ok(size == sizeof(encoding), "size=%d\n", size);
1195
1196     size = encoding = 0xdeadbeef;
1197     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1198                                  sizeof(encoding)-1, &size, 0);
1199     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1200     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1201     ok(size == 0xdeadbeef, "size=%d\n", size);
1202
1203     size = encoding = 0xdeadbeef;
1204     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1205                                  sizeof(encoding)-1, &size, 0);
1206     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1207     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1208     ok(size == 0xdeadbeef, "size=%d\n", size);
1209
1210     encoding = 0xdeadbeef;
1211     hres = UrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1212                                  sizeof(encoding)-1, NULL, 0);
1213     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1214     ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1215 }
1216
1217 static void test_user_agent(void)
1218 {
1219     static const CHAR expected[] = "Mozilla/4.0 (compatible; MSIE ";
1220     static char test_str[] = "test";
1221     static char test2_str[] = "test\0test";
1222     static CHAR str[3];
1223     LPSTR str2 = NULL;
1224     HRESULT hres;
1225     DWORD size, saved;
1226
1227     hres = ObtainUserAgentString(0, NULL, NULL);
1228     ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1229
1230     size = 100;
1231     hres = ObtainUserAgentString(0, NULL, &size);
1232     ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1233     ok(size == 100, "size=%d, expected %d\n", size, 100);
1234
1235     size = 0;
1236     hres = ObtainUserAgentString(0, str, &size);
1237     ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1238     ok(size > 0, "size=%d, expected non-zero\n", size);
1239
1240     size = 2;
1241     str[0] = 'a';
1242     hres = ObtainUserAgentString(0, str, &size);
1243     ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1244     ok(size > 0, "size=%d, expected non-zero\n", size);
1245     ok(str[0] == 'a', "str[0]=%c, expected 'a'\n", str[0]);
1246
1247     size = 0;
1248     hres = ObtainUserAgentString(1, str, &size);
1249     ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1250     ok(size > 0, "size=%d, expected non-zero\n", size);
1251
1252     str2 = HeapAlloc(GetProcessHeap(), 0, (size+20)*sizeof(CHAR));
1253     saved = size;
1254     hres = ObtainUserAgentString(0, str2, &size);
1255     ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1256     ok(size == saved, "size=%d, expected %d\n", size, saved);
1257     ok(strlen(expected) <= strlen(str2) &&
1258        !memcmp(expected, str2, strlen(expected)*sizeof(CHAR)),
1259        "user agent was \"%s\", expected to start with \"%s\"\n",
1260        str2, expected);
1261
1262     size = saved+10;
1263     hres = ObtainUserAgentString(0, str2, &size);
1264     ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1265     ok(size == saved, "size=%d, expected %d\n", size, saved);
1266
1267     size = 0;
1268     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, NULL, 0, &size, 0);
1269     ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1270     ok(size, "size == 0\n");
1271
1272     size = 0xdeadbeef;
1273     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, NULL, 1000, &size, 0);
1274     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1275     ok(size, "size == 0\n");
1276
1277     saved = size;
1278     size = 0;
1279     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved+10, &size, 0);
1280     ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1281     ok(size == saved, "size = %d, expected %d\n", size, saved);
1282     ok(sizeof(expected) <= strlen(str2) && !memcmp(expected, str2, sizeof(expected)-1),
1283        "user agent was \"%s\", expected to start with \"%s\"\n",
1284        str2, expected);
1285
1286     size = 0;
1287     str2[0] = 0;
1288     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1289     ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1290     ok(size == saved, "size = %d, expected %d\n", size, saved);
1291     ok(sizeof(expected) <= strlen(str2) && !memcmp(expected, str2, sizeof(expected)-1),
1292        "user agent was \"%s\", expected to start with \"%s\"\n",
1293        str2, expected);
1294
1295     size = saved;
1296     str2[0] = 0;
1297     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved-1, &size, 0);
1298     ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1299     ok(size == saved, "size = %d, expected %d\n", size, saved);
1300     ok(!str2[0], "buf changed\n");
1301
1302     size = saved;
1303     str2[0] = 0;
1304     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, NULL, 0);
1305     ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1306     ok(!str2[0], "buf changed\n");
1307
1308     hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, sizeof(test_str), 0);
1309     ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1310
1311     size = 0;
1312     str2[0] = 0;
1313     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1314     ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1315     ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");
1316
1317     hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test2_str, sizeof(test2_str), 0);
1318     ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1319
1320     size = 0;
1321     str2[0] = 0;
1322     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1323     ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1324     ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");
1325
1326     hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, 2, 0);
1327     ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1328
1329     size = 0;
1330     str2[0] = 0;
1331     hres = UrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1332     ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1333     ok(size == 3 && !strcmp(str2, "te"), "wrong user agent\n");
1334
1335     hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, 0, 0);
1336     ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1337
1338     hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, NULL, sizeof(test_str), 0);
1339     ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1340
1341     hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, NULL, 0, 0);
1342     ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1343
1344     HeapFree(GetProcessHeap(), 0, str2);
1345 }
1346
1347 static void test_MkParseDisplayNameEx(void)
1348 {
1349     IMoniker *mon = NULL;
1350     LPWSTR name;
1351     DWORD issys;
1352     ULONG eaten = 0;
1353     IBindCtx *bctx;
1354     HRESULT hres;
1355
1356     static const WCHAR clsid_nameW[] = {'c','l','s','i','d',':',
1357             '2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8',
1358             '-','0','8','0','0','2','B','3','0','3','0','9','D',':',0};
1359
1360     CreateBindCtx(0, &bctx);
1361
1362     hres = MkParseDisplayNameEx(bctx, url9, &eaten, &mon);
1363     ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1364     ok(eaten == sizeof(url9)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1365     ok(mon != NULL, "mon == NULL\n");
1366
1367     hres = IMoniker_GetDisplayName(mon, NULL, 0, &name);
1368     ok(hres == S_OK, "GetDiasplayName failed: %08x\n", hres);
1369     ok(!lstrcmpW(name, url9), "wrong display name %s\n", wine_dbgstr_w(name));
1370     CoTaskMemFree(name);
1371
1372     hres = IMoniker_IsSystemMoniker(mon, &issys);
1373     ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1374     ok(issys == MKSYS_URLMONIKER, "issys=%x\n", issys);
1375
1376     IMoniker_Release(mon);
1377
1378     hres = MkParseDisplayNameEx(bctx, clsid_nameW, &eaten, &mon);
1379     ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1380     ok(eaten == sizeof(clsid_nameW)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1381     ok(mon != NULL, "mon == NULL\n");
1382
1383     hres = IMoniker_IsSystemMoniker(mon, &issys);
1384     ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1385     ok(issys == MKSYS_CLASSMONIKER, "issys=%x\n", issys);
1386
1387     IMoniker_Release(mon);
1388
1389     hres = MkParseDisplayNameEx(bctx, url8, &eaten, &mon);
1390     ok(FAILED(hres), "MkParseDisplayNameEx succeeded: %08x\n", hres);
1391
1392     IBindCtx_Release(bctx);
1393 }
1394
1395 static void test_IsValidURL(void)
1396 {
1397     HRESULT hr;
1398
1399     hr = IsValidURL(NULL, 0, 0);
1400     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
1401 }
1402
1403 START_TEST(misc)
1404 {
1405     OleInitialize(NULL);
1406
1407     register_protocols();
1408
1409     test_CreateFormatEnum();
1410     test_RegisterFormatEnumerator();
1411     test_CoInternetParseUrl();
1412     test_CoInternetCompareUrl();
1413     test_CoInternetQueryInfo();
1414     test_FindMimeFromData();
1415     test_NameSpace();
1416     test_MimeFilter();
1417     test_ReleaseBindInfo();
1418     test_CopyStgMedium();
1419     test_UrlMkGetSessionOption();
1420     test_user_agent();
1421     test_MkParseDisplayNameEx();
1422     test_IsValidURL();
1423
1424     OleUninitialize();
1425 }