875334d68f17cb751940edb8f9dca0b5571a4a08
[reactos.git] / modules / rostests / winetests / urlmon / 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 WIN32_NO_STATUS
20 #define _INC_WINDOWS
21 #define COM_NO_WINDOWS_H
22
23 #define COBJMACROS
24 #define CONST_VTABLE
25 #define NONAMELESSUNION
26
27 #include <wine/test.h>
28 //#include <stdarg.h>
29 //#include <stddef.h>
30 #include <stdio.h>
31
32 //#include "windef.h"
33 //#include "winbase.h"
34 #include <winreg.h>
35 #include <winnls.h>
36 #include <ole2.h>
37 //#include "urlmon.h"
38
39 #include <initguid.h>
40
41 DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
42
43 #define DEFINE_EXPECT(func) \
44 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
45
46 #define SET_EXPECT(func) \
47 expect_ ## func = TRUE
48
49 #define CHECK_EXPECT(func) \
50 do { \
51 ok(expect_ ##func, "unexpected call " #func "\n"); \
52 expect_ ## func = FALSE; \
53 called_ ## func = TRUE; \
54 }while(0)
55
56 #define CHECK_EXPECT2(func) \
57 do { \
58 ok(expect_ ##func, "unexpected call " #func "\n"); \
59 called_ ## func = TRUE; \
60 }while(0)
61
62 #define CHECK_CALLED(func) \
63 do { \
64 ok(called_ ## func, "expected " #func "\n"); \
65 expect_ ## func = called_ ## func = FALSE; \
66 }while(0)
67
68 DEFINE_EXPECT(ParseUrl);
69 DEFINE_EXPECT(QI_IInternetProtocolInfo);
70 DEFINE_EXPECT(CreateInstance);
71 DEFINE_EXPECT(unk_Release);
72
73 static HRESULT (WINAPI *pCoInternetCompareUrl)(LPCWSTR, LPCWSTR, DWORD);
74 static HRESULT (WINAPI *pCoInternetGetSecurityUrl)(LPCWSTR, LPWSTR*, PSUACTION, DWORD);
75 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession **, DWORD);
76 static HRESULT (WINAPI *pCoInternetParseUrl)(LPCWSTR, PARSEACTION, DWORD, LPWSTR, DWORD, DWORD *, DWORD);
77 static HRESULT (WINAPI *pCoInternetQueryInfo)(LPCWSTR, QUERYOPTION, DWORD, LPVOID, DWORD, DWORD *, DWORD);
78 static HRESULT (WINAPI *pCopyStgMedium)(const STGMEDIUM *, STGMEDIUM *);
79 static HRESULT (WINAPI *pCopyBindInfo)(const BINDINFO *, BINDINFO *);
80 static HRESULT (WINAPI *pFindMimeFromData)(LPBC, LPCWSTR, LPVOID, DWORD, LPCWSTR,
81 DWORD, LPWSTR*, DWORD);
82 static HRESULT (WINAPI *pObtainUserAgentString)(DWORD, LPSTR, DWORD*);
83 static HRESULT (WINAPI *pReleaseBindInfo)(BINDINFO*);
84 static HRESULT (WINAPI *pUrlMkGetSessionOption)(DWORD, LPVOID, DWORD, DWORD *, DWORD);
85 static HRESULT (WINAPI *pCompareSecurityIds)(BYTE*,DWORD,BYTE*,DWORD,DWORD);
86 static HRESULT (WINAPI *pCoInternetIsFeatureEnabled)(INTERNETFEATURELIST,DWORD);
87 static HRESULT (WINAPI *pCoInternetSetFeatureEnabled)(INTERNETFEATURELIST,DWORD,BOOL);
88 static HRESULT (WINAPI *pIEInstallScope)(DWORD*);
89
90 static int strcmp_wa(const WCHAR *strw, const char *stra)
91 {
92 WCHAR buf[512];
93 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
94 return lstrcmpW(strw, buf);
95 }
96
97 static void heap_free(void *mem)
98 {
99 HeapFree(GetProcessHeap(), 0, mem);
100 }
101
102 static WCHAR *a2w(const char *str)
103 {
104 WCHAR *ret;
105 int len;
106
107 if(!str)
108 return NULL;
109
110 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
111 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
112 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
113
114 return ret;
115 }
116
117 static WCHAR *a2co(const char *str)
118 {
119 WCHAR *ret;
120 int len;
121
122 if(!str)
123 return NULL;
124
125 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
126 ret = CoTaskMemAlloc(len*sizeof(WCHAR));
127 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
128
129 return ret;
130 }
131
132 static void test_CreateFormatEnum(void)
133 {
134 IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
135 FORMATETC fetc[5];
136 ULONG ul;
137 HRESULT hres;
138
139 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
140 static FORMATETC formatetc[] = {
141 {0,&dev,0,0,0},
142 {0,&dev,0,1,0},
143 {0,NULL,0,2,0},
144 {0,NULL,0,3,0},
145 {0,NULL,0,4,0}
146 };
147
148 hres = CreateFormatEnumerator(0, formatetc, &fenum);
149 ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
150 hres = CreateFormatEnumerator(0, formatetc, NULL);
151 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
152 hres = CreateFormatEnumerator(5, formatetc, NULL);
153 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
154
155
156 hres = CreateFormatEnumerator(5, formatetc, &fenum);
157 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
158 if(FAILED(hres))
159 return;
160
161 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
162 ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
163 ul = 100;
164 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
165 ok(hres == S_OK, "Next failed: %08x\n", hres);
166 ok(ul == 0, "ul=%d, expected 0\n", ul);
167
168 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
169 ok(hres == S_OK, "Next failed: %08x\n", hres);
170 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
171 ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
172 ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
173 ok(ul == 2, "ul=%d, expected 2\n", ul);
174
175 hres = IEnumFORMATETC_Skip(fenum, 1);
176 ok(hres == S_OK, "Skip failed: %08x\n", hres);
177
178 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
179 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
180 ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
181 ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
182 ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
183 ok(ul == 2, "ul=%d, expected 2\n", ul);
184
185 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
186 ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
187 ok(ul == 0, "ul=%d, expected 0\n", ul);
188 ul = 100;
189 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
190 ok(hres == S_OK, "Next failed: %08x\n", hres);
191 ok(ul == 0, "ul=%d, expected 0\n", ul);
192
193 hres = IEnumFORMATETC_Skip(fenum, 3);
194 ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
195
196 hres = IEnumFORMATETC_Reset(fenum);
197 ok(hres == S_OK, "Reset failed: %08x\n", hres);
198
199 hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
200 ok(hres == S_OK, "Next failed: %08x\n", hres);
201 ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
202
203 hres = IEnumFORMATETC_Reset(fenum);
204 ok(hres == S_OK, "Reset failed: %08x\n", hres);
205
206 hres = IEnumFORMATETC_Skip(fenum, 2);
207 ok(hres == S_OK, "Skip failed: %08x\n", hres);
208
209 hres = IEnumFORMATETC_Clone(fenum, NULL);
210 ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
211
212 hres = IEnumFORMATETC_Clone(fenum, &fenum2);
213 ok(hres == S_OK, "Clone failed: %08x\n", hres);
214
215 if(SUCCEEDED(hres)) {
216 ok(fenum != fenum2, "fenum == fenum2\n");
217
218 hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
219 ok(hres == S_OK, "Next failed: %08x\n", hres);
220 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
221
222 IEnumFORMATETC_Release(fenum2);
223 }
224
225 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
226 ok(hres == S_OK, "Next failed: %08x\n", hres);
227 ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
228
229 hres = IEnumFORMATETC_Skip(fenum, 1);
230 ok(hres == S_OK, "Skip failed: %08x\n", hres);
231
232 IEnumFORMATETC_Release(fenum);
233 }
234
235 static void test_RegisterFormatEnumerator(void)
236 {
237 IBindCtx *bctx = NULL;
238 IEnumFORMATETC *format = NULL, *format2 = NULL;
239 IUnknown *unk = NULL;
240 HRESULT hres;
241
242 static FORMATETC formatetc = {0,NULL,0,0,0};
243 static WCHAR wszEnumFORMATETC[] =
244 {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
245
246 CreateBindCtx(0, &bctx);
247
248 hres = CreateFormatEnumerator(1, &formatetc, &format);
249 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
250 if(FAILED(hres))
251 return;
252
253 hres = RegisterFormatEnumerator(NULL, format, 0);
254 ok(hres == E_INVALIDARG,
255 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
256 hres = RegisterFormatEnumerator(bctx, NULL, 0);
257 ok(hres == E_INVALIDARG,
258 "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
259
260 hres = RegisterFormatEnumerator(bctx, format, 0);
261 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
262
263 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
264 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
265 ok(unk == (IUnknown*)format, "unk != format\n");
266
267 hres = RevokeFormatEnumerator(NULL, format);
268 ok(hres == E_INVALIDARG,
269 "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
270
271 hres = RevokeFormatEnumerator(bctx, format);
272 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
273
274 hres = RevokeFormatEnumerator(bctx, format);
275 ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
276
277 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
278 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
279
280 hres = RegisterFormatEnumerator(bctx, format, 0);
281 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
282
283 hres = CreateFormatEnumerator(1, &formatetc, &format2);
284 ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
285
286 if(SUCCEEDED(hres)) {
287 hres = RevokeFormatEnumerator(bctx, format);
288 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
289
290 IEnumFORMATETC_Release(format2);
291 }
292
293 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
294 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
295
296 IEnumFORMATETC_Release(format);
297
298 hres = RegisterFormatEnumerator(bctx, format, 0);
299 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
300 hres = RevokeFormatEnumerator(bctx, NULL);
301 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
302 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
303 ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
304
305 IEnumFORMATETC_Release(format);
306 IBindCtx_Release(bctx);
307 }
308 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
309 '/','b','l','a','n','k','.','h','t','m',0};
310 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
311 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
312 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
313 '%','2','e','j','p','g',0};
314 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
315 '.','o','r','g',0};
316 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
317 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
318 'f','i','l','e','.','t','e','s','t',0};
319 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
320 static const WCHAR url9[] =
321 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',
322 '/','s','i','t','e','/','a','b','o','u','t',0};
323 static const WCHAR url10[] = {'h','t','t','p',':','/','/','g','o','o','g','l','e','.','*','.',
324 'c','o','m',0};
325 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
326 '.','j','p','g',0};
327
328 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
329 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
330
331 static const WCHAR wszRes[] = {'r','e','s',0};
332 static const WCHAR wszFile[] = {'f','i','l','e',0};
333 static const WCHAR wszHttp[] = {'h','t','t','p',0};
334 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
335 static const WCHAR wszEmpty[] = {0};
336 static const WCHAR wszGoogle[] = {'g','o','o','g','l','e','.','*','.','c','o','m',0};
337
338 static const WCHAR wszWineHQ[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
339 static const WCHAR wszHttpWineHQ[] = {'h','t','t','p',':','/','/','w','w','w','.',
340 'w','i','n','e','h','q','.','o','r','g',0};
341 static const WCHAR wszHttpGoogle[] = {'h','t','t','p',':','/','/','g','o','o','g','l','e',
342 '.','*','.','c','o','m',0};
343
344 struct parse_test {
345 LPCWSTR url;
346 HRESULT secur_hres;
347 LPCWSTR encoded_url;
348 HRESULT path_hres;
349 LPCWSTR path;
350 LPCWSTR schema;
351 LPCWSTR domain;
352 HRESULT domain_hres;
353 LPCWSTR rootdocument;
354 HRESULT rootdocument_hres;
355 };
356
357 static const struct parse_test parse_tests[] = {
358 {url1, S_OK, url1, E_INVALIDARG, NULL, wszRes, NULL, E_FAIL, NULL, E_FAIL},
359 {url2, E_FAIL, url2, E_INVALIDARG, NULL, wszEmpty, NULL, E_FAIL, NULL, E_FAIL},
360 {url3, E_FAIL, url3, S_OK, path3, wszFile, wszEmpty, S_OK, NULL, E_FAIL},
361 {url4, E_FAIL, url4e, S_OK, path4, wszFile, wszEmpty, S_OK, NULL, E_FAIL},
362 {url5, E_FAIL, url5, E_INVALIDARG, NULL, wszHttp, wszWineHQ, S_OK, wszHttpWineHQ, S_OK},
363 {url6, S_OK, url6, E_INVALIDARG, NULL, wszAbout, NULL, E_FAIL, NULL, E_FAIL},
364 {url10, E_FAIL, url10, E_INVALIDARG,NULL, wszHttp, wszGoogle, S_OK, wszHttpGoogle, S_OK}
365 };
366
367 static void test_CoInternetParseUrl(void)
368 {
369 HRESULT hres;
370 DWORD size;
371 int i;
372
373 static WCHAR buf[4096];
374
375 memset(buf, 0xf0, sizeof(buf));
376 hres = pCoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
377 3, &size, 0);
378 ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
379
380 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
381 memset(buf, 0xf0, sizeof(buf));
382 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
383 sizeof(buf)/sizeof(WCHAR), &size, 0);
384 ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
385 i, hres, parse_tests[i].secur_hres);
386
387 memset(buf, 0xf0, sizeof(buf));
388 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
389 sizeof(buf)/sizeof(WCHAR), &size, 0);
390 ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
391 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
392 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
393
394 memset(buf, 0xf0, sizeof(buf));
395 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
396 sizeof(buf)/sizeof(WCHAR), &size, 0);
397 ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
398 i, hres, parse_tests[i].path_hres);
399 if(parse_tests[i].path) {
400 ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
401 ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
402 }
403
404 memset(buf, 0xf0, sizeof(buf));
405 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
406 sizeof(buf)/sizeof(WCHAR), &size, 0);
407 ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
408 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
409 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
410
411 if(memcmp(parse_tests[i].url, wszRes, 3*sizeof(WCHAR))
412 && memcmp(parse_tests[i].url, wszAbout, 5*sizeof(WCHAR))) {
413 memset(buf, 0xf0, sizeof(buf));
414 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_DOMAIN, 0, buf,
415 sizeof(buf)/sizeof(WCHAR), &size, 0);
416 ok(hres == parse_tests[i].domain_hres, "[%d] domain failed: %08x\n", i, hres);
417 if(parse_tests[i].domain)
418 ok(!lstrcmpW(parse_tests[i].domain, buf), "[%d] wrong domain, received %s\n", i, wine_dbgstr_w(buf));
419 }
420
421 memset(buf, 0xf0, sizeof(buf));
422 hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_ROOTDOCUMENT, 0, buf,
423 sizeof(buf)/sizeof(WCHAR), &size, 0);
424 ok(hres == parse_tests[i].rootdocument_hres, "[%d] rootdocument failed: %08x\n", i, hres);
425 if(parse_tests[i].rootdocument)
426 ok(!lstrcmpW(parse_tests[i].rootdocument, buf), "[%d] wrong rootdocument, received %s\n", i, wine_dbgstr_w(buf));
427 }
428 }
429
430 static void test_CoInternetCompareUrl(void)
431 {
432 HRESULT hres;
433
434 hres = pCoInternetCompareUrl(url1, url1, 0);
435 ok(hres == S_OK, "CoInternetCompareUrl failed: %08x\n", hres);
436
437 hres = pCoInternetCompareUrl(url1, url3, 0);
438 ok(hres == S_FALSE, "CoInternetCompareUrl failed: %08x\n", hres);
439
440 hres = pCoInternetCompareUrl(url3, url1, 0);
441 ok(hres == S_FALSE, "CoInternetCompareUrl failed: %08x\n", hres);
442 }
443
444 static const struct {
445 LPCWSTR url;
446 DWORD uses_net;
447 } query_info_tests[] = {
448 {url1, 0},
449 {url2, 0},
450 {url3, 0},
451 {url4, 0},
452 {url5, 0},
453 {url6, 0},
454 {url7, 0},
455 {url8, 0}
456 };
457
458 static void test_CoInternetQueryInfo(void)
459 {
460 BYTE buf[100];
461 DWORD cb, i;
462 HRESULT hres;
463
464 for(i=0; i < sizeof(query_info_tests)/sizeof(query_info_tests[0]); i++) {
465 cb = 0xdeadbeef;
466 memset(buf, '?', sizeof(buf));
467 hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), &cb, 0);
468 ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
469 ok(cb == sizeof(DWORD), "[%d] cb = %d\n", i, cb);
470 ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
471 i, *(DWORD*)buf, query_info_tests[i].uses_net);
472
473 hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, 3, &cb, 0);
474 ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
475 hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, NULL, sizeof(buf), &cb, 0);
476 ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
477
478 memset(buf, '?', sizeof(buf));
479 hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), NULL, 0);
480 ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
481 ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
482 i, *(DWORD*)buf, query_info_tests[i].uses_net);
483 }
484 }
485
486 static const struct {
487 const char *url;
488 const char *mime;
489 HRESULT hres;
490 BOOL broken_failure;
491 const char *broken_mime;
492 } mime_tests[] = {
493 {"res://mshtml.dll/blank.htm", "text/html", S_OK},
494 {"index.htm", "text/html", S_OK},
495 {"file://c:\\Index.htm", "text/html", S_OK},
496 {"file://c:\\Index.htm?q=test", "text/html", S_OK, TRUE},
497 {"file://c:\\Index.htm#hash_part", "text/html", S_OK, TRUE},
498 {"file://c:\\Index.htm#hash_part.txt", "text/html", S_OK, FALSE, "text/plain"},
499 {"file://some%20file%2ejpg", NULL, E_FAIL},
500 {"http://www.winehq.org", NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)},
501 {"about:blank", NULL, E_FAIL},
502 {"ftp://winehq.org/file.test", NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)}
503 };
504
505 static BYTE data1[] = "test data\n";
506 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
507 static BYTE data3[] = {0,0,0};
508 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
509 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
510 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
511 static BYTE data7[] = "<html>blahblah";
512 static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
513 static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
514 static BYTE data10[] = "<HtmL>blahblah";
515 static BYTE data11[] = "blah<HTML>blahblah";
516 static BYTE data12[] = "blah<HTMLblahblah";
517 static BYTE data13[] = "blahHTML>blahblah";
518 static BYTE data14[] = "blah<HTMblahblah";
519 static BYTE data15[] = {0xff,0xd8};
520 static BYTE data16[] = {0xff,0xd8,'h'};
521 static BYTE data17[] = {0,0xff,0xd8};
522 static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
523 static BYTE data19[] = {'G','I','F','8','7','a'};
524 static BYTE data20[] = {'G','I','F','8','9','a'};
525 static BYTE data21[] = {'G','I','F','8','7'};
526 static BYTE data22[] = {'G','i','F','8','7','a'};
527 static BYTE data23[] = {'G','i','F','8','8','a'};
528 static BYTE data24[] = {'g','i','f','8','7','a'};
529 static BYTE data25[] = {'G','i','F','8','7','A'};
530 static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
531 static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
532 static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
533 static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
534 static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
535 static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
536 static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
537 static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
538 static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
539 static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
540 static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
541 static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
542 static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
543 static BYTE data39[] = {0x4d,0x4d,0x00,0x2a,0xff};
544 static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
545 static BYTE data41[] = {0x4d,0x4d,0xff};
546 static BYTE data42[] = {0x4d,0x4d};
547 static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
548 static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
549 static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
550 static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
551 static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
552 static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
553 static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
554 static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
555 static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
556 static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
557 static BYTE data53[] = {0x00,0x00,0x01,0xba};
558 static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
559 static BYTE data55[] = {0x1f,0x8b,'x'};
560 static BYTE data56[] = {0x1f};
561 static BYTE data57[] = {0x1f,0x8b,'<','h','t','m','l','>','t','e','s','t',0};
562 static BYTE data58[] = {0x1f,0x8b};
563 static BYTE data59[] = {0x50,0x4b,'x'};
564 static BYTE data60[] = {0x50,0x4b};
565 static BYTE data61[] = {0x50,0x4b,'<','h','t','m','l','>',0};
566 static BYTE data62[] = {0xca,0xfe,0xba,0xbe,'x'};
567 static BYTE data63[] = {0xca,0xfe,0xba,0xbe};
568 static BYTE data64[] = {0xca,0xfe,0xba,0xbe,'<','h','t','m','l','>',0};
569 static BYTE data65[] = {0x25,0x50,0x44,0x46,'x'};
570 static BYTE data66[] = {0x25,0x50,0x44,0x46};
571 static BYTE data67[] = {0x25,0x50,0x44,0x46,'x','<','h','t','m','l','>'};
572 static BYTE data68[] = {'M','Z','x'};
573 static BYTE data69[] = {'M','Z'};
574 static BYTE data70[] = {'M','Z','<','h','t','m','l','>',0xff};
575 static BYTE data71[] = {'{','\\','r','t','f',0};
576 static BYTE data72[] = {'{','\\','r','t','f'};
577 static BYTE data73[] = {' ','{','\\','r','t','f',' '};
578 static BYTE data74[] = {'{','\\','r','t','f','<','h','t','m','l','>',' '};
579 static BYTE data75[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E',0xff};
580 static BYTE data76[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E'};
581 static BYTE data77[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V',0xff,0xff};
582 static BYTE data78[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'<','h','t','m','l','>',0xff};
583 static BYTE data79[] = {'%','!',0xff};
584 static BYTE data80[] = {'%','!'};
585 static BYTE data81[] = {'%','!','P','S','<','h','t','m','l','>'};
586 static BYTE data82[] = {'.','s','n','d',0};
587 static BYTE data83[] = {'.','s','n','d'};
588 static BYTE data84[] = {'.','s','n','d',0,'<','h','t','m','l','>',1,1};
589 static BYTE data85[] = {'.','S','N','D',0};
590 static BYTE data86[] = {0x49,0x49,0x2a,0xff};
591 static BYTE data87[] = {' ','<','h','e','a','d'};
592 static BYTE data88[] = {' ','<','h','e','a','d','>'};
593 static BYTE data89[] = {'\t','\r','<','h','e','a','d','>'};
594 static BYTE data90[] = {'<','H','e','A','d',' '};
595 static BYTE data91[] = {'<','?','x','m','l',' ',0};
596 static BYTE data92[] = {'a','b','c','<','?','x','m','l',' ',' '};
597 static BYTE data93[] = {'<','?','x','m','l',' ',' ','<','h','t','m','l','>'};
598 static BYTE data94[] = {'<','h','t','m','l','>','<','?','x','m','l',' ',' '};
599 static BYTE data95[] = {'{','\\','r','t','f','<','?','x','m','l',' ',' '};
600 static BYTE data96[] = {'<','?','x','m','l',' '};
601 static BYTE data97[] = "<body";
602 static BYTE data98[] = "blah<BoDyblahblah";
603
604 static const struct {
605 BYTE *data;
606 DWORD size;
607 const char *mime;
608 const char *mime_pjpeg;
609 const char *broken_mime;
610 const char *url;
611 const char *proposed_mime;
612 } mime_tests2[] = {
613 {data1, sizeof(data1), "text/plain"},
614 {data2, sizeof(data2), "application/octet-stream", "image/pjpeg"},
615 {data3, sizeof(data3), "application/octet-stream", "image/pjpeg"},
616 {data4, sizeof(data4), "application/octet-stream", "image/pjpeg"},
617 {data5, sizeof(data5), "text/plain"},
618 {data6, sizeof(data6), "text/plain"},
619 {data7, sizeof(data7), "text/html", "text/plain"},
620 {data8, sizeof(data8), "text/html", "text/plain"},
621 {data9, sizeof(data9), "text/html", "image/pjpeg"},
622 {data10, sizeof(data10), "text/html", "text/plain"},
623 {data11, sizeof(data11), "text/html", "text/plain"},
624 {data12, sizeof(data12), "text/html", "text/plain"},
625 {data13, sizeof(data13), "text/plain"},
626 {data14, sizeof(data14), "text/plain"},
627 {data15, sizeof(data15), "text/plain"},
628 {data16, sizeof(data16), "image/pjpeg"},
629 {data17, sizeof(data17), "application/octet-stream", "image/pjpeg"},
630 {data18, sizeof(data18), "text/html", "image/pjpeg"},
631 {data19, sizeof(data19), "image/gif"},
632 {data20, sizeof(data20), "image/gif"},
633 {data21, sizeof(data21), "text/plain"},
634 {data22, sizeof(data22), "image/gif"},
635 {data23, sizeof(data23), "text/plain"},
636 {data24, sizeof(data24), "image/gif"},
637 {data25, sizeof(data25), "image/gif"},
638 {data26, sizeof(data26), "text/html", "image/gif"},
639 {data27, sizeof(data27), "text/plain"},
640 {data28, sizeof(data28), "image/bmp"},
641 {data29, sizeof(data29), "image/bmp"},
642 {data30, sizeof(data30), "application/octet-stream", "image/pjpeg"},
643 {data31, sizeof(data31), "text/html", "image/bmp"},
644 {data32, sizeof(data32), "application/octet-stream", "image/pjpeg"},
645 {data33, sizeof(data33), "application/octet-stream", "image/pjpeg"},
646 {data34, sizeof(data34), "image/x-png"},
647 {data35, sizeof(data35), "image/x-png"},
648 {data36, sizeof(data36), "application/octet-stream", "image/pjpeg"},
649 {data37, sizeof(data37), "text/html", "image/x-png"},
650 {data38, sizeof(data38), "application/octet-stream", "image/pjpeg"},
651 {data39, sizeof(data39), "image/tiff"},
652 {data40, sizeof(data40), "text/html", "image/tiff"},
653 {data41, sizeof(data41), "text/plain", NULL, "image/tiff"},
654 {data42, sizeof(data42), "text/plain"},
655 {data43, sizeof(data43), "application/octet-stream", "image/pjpeg"},
656 {data44, sizeof(data44), "video/avi"},
657 {data45, sizeof(data45), "text/plain"},
658 {data46, sizeof(data46), "text/plain"},
659 {data47, sizeof(data47), "text/plain"},
660 {data48, sizeof(data48), "text/html", "video/avi"},
661 {data49, sizeof(data49), "video/avi"},
662 {data50, sizeof(data50), "video/mpeg"},
663 {data51, sizeof(data51), "video/mpeg"},
664 {data52, sizeof(data52), "application/octet-stream", "image/pjpeg"},
665 {data53, sizeof(data53), "application/octet-stream", "image/pjpeg", "image/x-icon"},
666 {data54, sizeof(data54), "text/html", "video/mpeg"},
667 {data55, sizeof(data55), "application/x-gzip-compressed"},
668 {data56, sizeof(data56), "text/plain"},
669 {data57, sizeof(data57), "text/html", "application/x-gzip-compressed"},
670 {data58, sizeof(data58), "application/octet-stream", "image/pjpeg"},
671 {data59, sizeof(data59), "application/x-zip-compressed"},
672 {data60, sizeof(data60), "text/plain"},
673 {data61, sizeof(data61), "text/html", "application/x-zip-compressed"},
674 {data62, sizeof(data62), "application/java"},
675 {data63, sizeof(data63), "text/plain"},
676 {data64, sizeof(data64), "text/html", "application/java"},
677 {data65, sizeof(data65), "application/pdf"},
678 {data66, sizeof(data66), "text/plain"},
679 {data67, sizeof(data67), "text/html", "application/pdf"},
680 {data68, sizeof(data68), "application/x-msdownload"},
681 {data69, sizeof(data69), "text/plain"},
682 {data70, sizeof(data70), "text/html", "application/x-msdownload"},
683 {data71, sizeof(data71), "text/richtext"},
684 {data72, sizeof(data72), "text/plain"},
685 {data73, sizeof(data73), "text/plain"},
686 {data74, sizeof(data74), "text/html", "text/richtext"},
687 {data75, sizeof(data75), "audio/wav"},
688 {data76, sizeof(data76), "text/plain"},
689 {data77, sizeof(data77), "text/plain"},
690 {data78, sizeof(data78), "text/html", "text/plain"},
691 {data79, sizeof(data79), "application/postscript"},
692 {data80, sizeof(data80), "text/plain"},
693 {data81, sizeof(data81), "text/html", "application/postscript"},
694 {data82, sizeof(data82), "audio/basic"},
695 {data83, sizeof(data83), "text/plain"},
696 {data84, sizeof(data84), "text/html", "audio/basic"},
697 {data85, sizeof(data85), "text/plain"},
698 {data86, sizeof(data86), "image/tiff", NULL, "text/plain"},
699 {data87, sizeof(data87), "text/plain"},
700 {data88, sizeof(data88), "text/html", "text/plain"},
701 {data89, sizeof(data89), "text/html", "text/plain"},
702 {data90, sizeof(data90), "text/html", "text/plain"},
703 {data91, sizeof(data91), "text/xml", "text/plain"},
704 {data92, sizeof(data92), "text/xml", "text/plain"},
705 {data93, sizeof(data93), "text/xml", "text/plain"},
706 {data94, sizeof(data94), "text/html", "text/plain"},
707 {data95, sizeof(data95), "text/xml", "text/richtext"},
708 {data96, sizeof(data96), "text/plain"},
709 {data97, sizeof(data97), "text/html", "text/plain"},
710 {data98, sizeof(data98), "text/html", "text/plain"},
711 {data1, sizeof(data1), "text/plain", NULL, NULL, "res://mshtml.dll/blank.htm"},
712 {NULL, 0, "text/html", NULL, NULL, "res://mshtml.dll/blank.htm"},
713 {data1, sizeof(data1), "text/plain", NULL, NULL, "res://mshtml.dll/blank.htm", "application/octet-stream"},
714 {data1, sizeof(data1), "text/plain", NULL, NULL, "file:some%20file%2ejpg", "application/octet-stream"},
715 {NULL, sizeof(data1), "text/html", NULL, NULL, "res://mshtml.dll/blank.htm"},
716 {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css"},
717 {data2, sizeof(data2), "text/css", NULL, NULL, "http://www.winehq.org/test.css"},
718 {data10, sizeof(data10), "text/html", NULL, NULL, "http://www.winehq.org/test.css"},
719 {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css", "text/plain"},
720 {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css", "application/octet-stream"},
721 {data1, sizeof(data1), "text/test", NULL, NULL, "http://www.winehq.org/test.css", "text/test"}
722 };
723
724 static void test_FindMimeFromData(void)
725 {
726 WCHAR *mime, *proposed_mime, *url;
727 HRESULT hres;
728 BYTE b;
729 int i;
730
731 static const WCHAR app_octet_streamW[] =
732 {'a','p','p','l','i','c','a','t','i','o','n','/','o','c','t','e','t','-','s','t','r','e','a','m',0};
733 static const WCHAR image_pjpegW[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
734 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
735 static const WCHAR text_plainW[] = {'t','e','x','t','/','p','l','a','i','n',0};
736
737 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
738 mime = (LPWSTR)0xf0f0f0f0;
739 url = a2w(mime_tests[i].url);
740 hres = pFindMimeFromData(NULL, url, NULL, 0, NULL, 0, &mime, 0);
741 if(mime_tests[i].mime) {
742 ok(hres == S_OK || broken(mime_tests[i].broken_failure), "[%d] FindMimeFromData failed: %08x\n", i, hres);
743 if(hres == S_OK) {
744 ok(!strcmp_wa(mime, mime_tests[i].mime)
745 || broken(mime_tests[i].broken_mime && !strcmp_wa(mime, mime_tests[i].broken_mime)),
746 "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
747 CoTaskMemFree(mime);
748 }
749 }else {
750 ok(hres == E_FAIL || hres == mime_tests[i].hres,
751 "[%d] FindMimeFromData failed: %08x, expected %08x\n",
752 i, hres, mime_tests[i].hres);
753 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
754 }
755
756 mime = (LPWSTR)0xf0f0f0f0;
757 hres = pFindMimeFromData(NULL, url, NULL, 0, text_plainW, 0, &mime, 0);
758 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
759 ok(!strcmp_wa(mime, "text/plain"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
760 CoTaskMemFree(mime);
761
762 mime = (LPWSTR)0xf0f0f0f0;
763 hres = pFindMimeFromData(NULL, url, NULL, 0, app_octet_streamW, 0, &mime, 0);
764 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
765 ok(!strcmp_wa(mime, "application/octet-stream"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
766 CoTaskMemFree(mime);
767 heap_free(url);
768 }
769
770 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
771 url = a2w(mime_tests2[i].url);
772 proposed_mime = a2w(mime_tests2[i].proposed_mime);
773 hres = pFindMimeFromData(NULL, url, mime_tests2[i].data, mime_tests2[i].size,
774 proposed_mime, 0, &mime, 0);
775 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
776 b = !strcmp_wa(mime, mime_tests2[i].mime);
777 ok(b || broken(mime_tests2[i].broken_mime && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
778 "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
779 heap_free(proposed_mime);
780 heap_free(url);
781 CoTaskMemFree(mime);
782 if(!b || url || proposed_mime)
783 continue;
784
785 hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
786 app_octet_streamW, 0, &mime, 0);
787 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
788 ok(!strcmp_wa(mime, mime_tests2[i].mime) || broken(mime_tests2[i].broken_mime
789 && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
790 "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
791 CoTaskMemFree(mime);
792
793 hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
794 text_plainW, 0, &mime, 0);
795 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
796 ok(!strcmp_wa(mime, mime_tests2[i].mime) || broken(mime_tests2[i].broken_mime
797 && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
798 "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
799 CoTaskMemFree(mime);
800
801 hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
802 text_htmlW, 0, &mime, 0);
803 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
804 if(!strcmp("application/octet-stream", mime_tests2[i].mime)
805 || !strcmp("text/plain", mime_tests2[i].mime) || i==92)
806 ok(!strcmp_wa(mime, "text/html"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
807 else
808 ok(!strcmp_wa(mime, mime_tests2[i].mime), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
809 CoTaskMemFree(mime);
810
811 hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
812 image_pjpegW, 0, &mime, 0);
813 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
814 ok(!strcmp_wa(mime, mime_tests2[i].mime_pjpeg ? mime_tests2[i].mime_pjpeg : mime_tests2[i].mime)
815 || broken(!strcmp_wa(mime, mime_tests2[i].mime)),
816 "[%d] wrong mime, got %s\n", i, wine_dbgstr_w(mime));
817 CoTaskMemFree(mime);
818 }
819
820 hres = pFindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
821 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
822
823 hres = pFindMimeFromData(NULL, NULL, NULL, 0, text_plainW, 0, &mime, 0);
824 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
825
826 hres = pFindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
827 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
828
829 hres = pFindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
830 ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
831
832 hres = pFindMimeFromData(NULL, NULL, data1, 0, text_plainW, 0, &mime, 0);
833 ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
834 ok(!strcmp_wa(mime, "text/plain"), "wrong mime: %s\n", wine_dbgstr_w(mime));
835 CoTaskMemFree(mime);
836
837 hres = pFindMimeFromData(NULL, NULL, data1, 0, text_plainW, 0, NULL, 0);
838 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
839 }
840
841 static void register_protocols(void)
842 {
843 IInternetSession *session;
844 IClassFactory *factory;
845 HRESULT hres;
846
847 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
848
849 hres = pCoInternetGetSession(0, &session, 0);
850 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
851 if(FAILED(hres))
852 return;
853
854 hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
855 &IID_IClassFactory, (void**)&factory);
856 ok(hres == S_OK, "Could not get AboutProtocol factory: %08x\n", hres);
857 if(FAILED(hres))
858 return;
859
860 IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
861 wszAbout, 0, NULL, 0);
862 IClassFactory_Release(factory);
863
864 IInternetSession_Release(session);
865 }
866
867 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
868 REFIID riid, void **ppv)
869 {
870 ok(0, "unexpected call\n");
871 return E_NOINTERFACE;
872 }
873
874 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
875 {
876 return 2;
877 }
878
879 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
880 {
881 return 1;
882 }
883
884 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
885 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
886 DWORD *pcchResult, DWORD dwReserved)
887 {
888 CHECK_EXPECT2(ParseUrl);
889
890 if(ParseAction == PARSE_SECURITY_URL) {
891 if(pcchResult)
892 *pcchResult = sizeof(url1)/sizeof(WCHAR);
893
894 if(cchResult<sizeof(url1)/sizeof(WCHAR))
895 return S_FALSE;
896
897 memcpy(pwzResult, url1, sizeof(url1));
898 return S_OK;
899 }
900
901 return E_NOTIMPL;
902 }
903
904 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
905 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
906 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
907 {
908 ok(0, "unexpected call\n");
909 return E_NOTIMPL;
910 }
911
912 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
913 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
914 {
915 ok(0, "unexpected call\n");
916 return E_NOTIMPL;
917 }
918
919 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
920 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
921 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
922 {
923 ok(0, "unexpected call\n");
924 return E_NOTIMPL;
925 }
926
927 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
928 InternetProtocolInfo_QueryInterface,
929 InternetProtocolInfo_AddRef,
930 InternetProtocolInfo_Release,
931 InternetProtocolInfo_ParseUrl,
932 InternetProtocolInfo_CombineUrl,
933 InternetProtocolInfo_CompareUrl,
934 InternetProtocolInfo_QueryInfo
935 };
936
937 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
938
939 static HRESULT qiret;
940 static IClassFactory *expect_cf;
941
942 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
943 {
944 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
945 CHECK_EXPECT2(QI_IInternetProtocolInfo);
946 ok(iface == expect_cf, "unexpected iface\n");
947 *ppv = &protocol_info;
948 return qiret;
949 }
950
951 ok(0, "unexpected call\n");
952 return E_NOINTERFACE;
953 }
954
955 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
956 {
957 return 2;
958 }
959
960 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
961 {
962 return 1;
963 }
964
965 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
966 REFIID riid, void **ppv)
967 {
968 ok(0, "unexpected call\n");
969 return E_NOTIMPL;
970 }
971
972 static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
973 REFIID riid, void **ppv)
974 {
975 CHECK_EXPECT(CreateInstance);
976
977 ok(iface == expect_cf, "unexpected iface\n");
978 ok(pOuter == NULL, "pOuter = %p\n", pOuter);
979 ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
980 ok(ppv != NULL, "ppv == NULL\n");
981
982 *ppv = &protocol_info;
983 return S_OK;
984 }
985
986 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
987 {
988 ok(0, "unexpected call\n");
989 return S_OK;
990 }
991
992 static const IClassFactoryVtbl ClassFactoryVtbl = {
993 ClassFactory_QueryInterface,
994 ClassFactory_AddRef,
995 ClassFactory_Release,
996 ClassFactory_CreateInstance,
997 ClassFactory_LockServer
998 };
999
1000 static const IClassFactoryVtbl ProtocolCFVtbl = {
1001 ClassFactory_QueryInterface,
1002 ClassFactory_AddRef,
1003 ClassFactory_Release,
1004 ProtocolCF_CreateInstance,
1005 ClassFactory_LockServer
1006 };
1007
1008 static IClassFactory test_protocol_cf = { &ProtocolCFVtbl };
1009 static IClassFactory test_protocol_cf2 = { &ProtocolCFVtbl };
1010 static IClassFactory test_cf = { &ClassFactoryVtbl };
1011
1012 static void test_NameSpace(void)
1013 {
1014 IInternetSession *session;
1015 WCHAR buf[200];
1016 LPWSTR sec_url;
1017 DWORD size;
1018 HRESULT hres;
1019
1020 static const WCHAR wszTest[] = {'t','e','s','t',0};
1021
1022 hres = pCoInternetGetSession(0, &session, 0);
1023 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1024 if(FAILED(hres))
1025 return;
1026
1027 hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
1028 wszTest, 0, NULL, 0);
1029 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
1030
1031 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1032 NULL, 0, NULL, 0);
1033 ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
1034
1035 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1036 wszTest, 0, NULL, 0);
1037 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1038
1039 qiret = E_NOINTERFACE;
1040 expect_cf = &test_protocol_cf;
1041 SET_EXPECT(QI_IInternetProtocolInfo);
1042 SET_EXPECT(CreateInstance);
1043 SET_EXPECT(ParseUrl);
1044
1045 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1046 &size, 0);
1047 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1048
1049 CHECK_CALLED(QI_IInternetProtocolInfo);
1050 CHECK_CALLED(CreateInstance);
1051 CHECK_CALLED(ParseUrl);
1052
1053 qiret = S_OK;
1054 SET_EXPECT(QI_IInternetProtocolInfo);
1055 SET_EXPECT(ParseUrl);
1056
1057 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1058 &size, 0);
1059 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1060
1061 CHECK_CALLED(QI_IInternetProtocolInfo);
1062 CHECK_CALLED(ParseUrl);
1063
1064 SET_EXPECT(QI_IInternetProtocolInfo);
1065 SET_EXPECT(ParseUrl);
1066
1067 hres = pCoInternetParseUrl(url8, PARSE_SECURITY_URL, 0, buf,
1068 sizeof(buf)/sizeof(WCHAR), &size, 0);
1069 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1070 ok(size == sizeof(url1)/sizeof(WCHAR), "Size = %d\n", size);
1071 if(size == sizeof(url1)/sizeof(WCHAR))
1072 ok(!memcmp(buf, url1, sizeof(url1)), "Encoded url = %s\n", wine_dbgstr_w(buf));
1073
1074 CHECK_CALLED(QI_IInternetProtocolInfo);
1075 CHECK_CALLED(ParseUrl);
1076
1077 SET_EXPECT(QI_IInternetProtocolInfo);
1078 SET_EXPECT(ParseUrl);
1079
1080 if (pCoInternetGetSecurityUrl) {
1081 hres = pCoInternetGetSecurityUrl(url8, &sec_url, PSU_SECURITY_URL_ONLY, 0);
1082 ok(hres == S_OK, "CoInternetGetSecurityUrl failed: %08x\n", hres);
1083 if(hres == S_OK) {
1084 ok(lstrlenW(sec_url)>sizeof(wszFile)/sizeof(WCHAR) &&
1085 !memcmp(sec_url, wszFile, sizeof(wszFile)-sizeof(WCHAR)),
1086 "Encoded url = %s\n", wine_dbgstr_w(sec_url));
1087 CoTaskMemFree(sec_url);
1088 }
1089
1090 CHECK_CALLED(QI_IInternetProtocolInfo);
1091 CHECK_CALLED(ParseUrl);
1092 }
1093
1094 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1095 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1096
1097 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1098 &size, 0);
1099 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1100
1101 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
1102 wszTest, 0, NULL, 0);
1103 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1104
1105 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1106 wszTest, 0, NULL, 0);
1107 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1108
1109 hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
1110 wszTest, 0, NULL, 0);
1111 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1112
1113 SET_EXPECT(QI_IInternetProtocolInfo);
1114 SET_EXPECT(ParseUrl);
1115
1116 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1117 &size, 0);
1118 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1119
1120 CHECK_CALLED(QI_IInternetProtocolInfo);
1121 CHECK_CALLED(ParseUrl);
1122
1123 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1124 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1125
1126 SET_EXPECT(QI_IInternetProtocolInfo);
1127 SET_EXPECT(ParseUrl);
1128
1129 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1130 &size, 0);
1131 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1132
1133 CHECK_CALLED(QI_IInternetProtocolInfo);
1134 CHECK_CALLED(ParseUrl);
1135
1136 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1137 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1138
1139 expect_cf = &test_protocol_cf2;
1140 SET_EXPECT(QI_IInternetProtocolInfo);
1141 SET_EXPECT(ParseUrl);
1142
1143 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1144 &size, 0);
1145 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1146
1147 CHECK_CALLED(QI_IInternetProtocolInfo);
1148 CHECK_CALLED(ParseUrl);
1149
1150 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1151 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1152 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1153 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1154 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
1155 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1156 hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
1157 ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1158
1159 hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
1160 ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1161
1162 hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1163 &size, 0);
1164 ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1165
1166 IInternetSession_Release(session);
1167 }
1168
1169 static void test_MimeFilter(void)
1170 {
1171 IInternetSession *session;
1172 HRESULT hres;
1173
1174 static const WCHAR mimeW[] = {'t','e','s','t','/','m','i','m','e',0};
1175
1176 hres = pCoInternetGetSession(0, &session, 0);
1177 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1178 if(FAILED(hres))
1179 return;
1180
1181 hres = IInternetSession_RegisterMimeFilter(session, &test_cf, &IID_NULL, mimeW);
1182 ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);
1183
1184 hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1185 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1186
1187 hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
1188 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1189
1190 hres = IInternetSession_UnregisterMimeFilter(session, (void*)0xdeadbeef, mimeW);
1191 ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);
1192
1193 IInternetSession_Release(session);
1194 }
1195
1196 static ULONG WINAPI unk_Release(IUnknown *iface)
1197 {
1198 CHECK_EXPECT(unk_Release);
1199 return 0;
1200 }
1201
1202 static const IUnknownVtbl unk_vtbl = {
1203 (void*)0xdeadbeef,
1204 (void*)0xdeadbeef,
1205 unk_Release
1206 };
1207
1208 static void test_ReleaseBindInfo(void)
1209 {
1210 BINDINFO bi;
1211 IUnknown unk = { &unk_vtbl };
1212
1213 pReleaseBindInfo(NULL); /* shouldn't crash */
1214
1215 memset(&bi, 0, sizeof(bi));
1216 bi.cbSize = sizeof(BINDINFO);
1217 bi.pUnk = &unk;
1218 SET_EXPECT(unk_Release);
1219 pReleaseBindInfo(&bi);
1220 ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
1221 ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
1222 CHECK_CALLED(unk_Release);
1223
1224 memset(&bi, 0, sizeof(bi));
1225 bi.cbSize = offsetof(BINDINFO, pUnk);
1226 bi.pUnk = &unk;
1227 pReleaseBindInfo(&bi);
1228 ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
1229 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1230
1231 memset(&bi, 0, sizeof(bi));
1232 bi.pUnk = &unk;
1233 pReleaseBindInfo(&bi);
1234 ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
1235 ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
1236 }
1237
1238 static void test_CopyStgMedium(void)
1239 {
1240 STGMEDIUM src, dst;
1241 HGLOBAL empty, hg;
1242 char *ptr1, *ptr2;
1243 HRESULT hres;
1244 int size;
1245
1246 static WCHAR fileW[] = {'f','i','l','e',0};
1247
1248 memset(&src, 0xf0, sizeof(src));
1249 memset(&dst, 0xe0, sizeof(dst));
1250 memset(&empty, 0xf0, sizeof(empty));
1251 src.tymed = TYMED_NULL;
1252 src.pUnkForRelease = NULL;
1253 hres = pCopyStgMedium(&src, &dst);
1254 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1255 ok(dst.tymed == TYMED_NULL, "tymed=%d\n", dst.tymed);
1256 ok(dst.u.hGlobal == empty, "u=%p\n", dst.u.hGlobal);
1257 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1258
1259 memset(&dst, 0xe0, sizeof(dst));
1260 src.tymed = TYMED_ISTREAM;
1261 src.u.pstm = NULL;
1262 src.pUnkForRelease = NULL;
1263 hres = pCopyStgMedium(&src, &dst);
1264 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1265 ok(dst.tymed == TYMED_ISTREAM, "tymed=%d\n", dst.tymed);
1266 ok(!dst.u.pstm, "pstm=%p\n", dst.u.pstm);
1267 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1268
1269 memset(&dst, 0xe0, sizeof(dst));
1270 src.tymed = TYMED_FILE;
1271 src.u.lpszFileName = fileW;
1272 src.pUnkForRelease = NULL;
1273 hres = pCopyStgMedium(&src, &dst);
1274 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1275 ok(dst.tymed == TYMED_FILE, "tymed=%d\n", dst.tymed);
1276 ok(dst.u.lpszFileName && dst.u.lpszFileName != fileW, "lpszFileName=%p\n", dst.u.lpszFileName);
1277 ok(!lstrcmpW(dst.u.lpszFileName, fileW), "wrong file name\n");
1278 ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1279 ReleaseStgMedium(&dst);
1280
1281 /* TYMED_HGLOBAL */
1282 hg = GlobalAlloc(GMEM_MOVEABLE, 10);
1283 ptr1 = GlobalLock(hg);
1284 memset(ptr1, 0xfa, 10);
1285 memset(&dst, 0xe0, sizeof(dst));
1286 src.tymed = TYMED_HGLOBAL;
1287 src.u.hGlobal = hg;
1288 hres = pCopyStgMedium(&src, &dst);
1289 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1290 ok(dst.tymed == TYMED_HGLOBAL, "tymed=%d\n", dst.tymed);
1291 ok(dst.u.hGlobal != hg, "got %p, %p\n", dst.u.hGlobal, hg);
1292 size = GlobalSize(dst.u.hGlobal);
1293 ok(size == 10, "got size %d\n", size);
1294 /* compare contents */
1295 ptr2 = GlobalLock(dst.u.hGlobal);
1296 ok(!memcmp(ptr1, ptr2, 10), "got wrong data\n");
1297 GlobalUnlock(ptr2);
1298 GlobalUnlock(ptr1);
1299 ok(GlobalFlags(dst.u.hGlobal) == 0, "got 0x%08x\n", GlobalFlags(dst.u.hGlobal));
1300 GlobalFree(hg);
1301 ReleaseStgMedium(&dst);
1302
1303 memset(&dst, 0xe0, sizeof(dst));
1304 src.tymed = TYMED_HGLOBAL;
1305 src.u.hGlobal = NULL;
1306 hres = pCopyStgMedium(&src, &dst);
1307 ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
1308 ok(dst.u.hGlobal == NULL, "got %p\n", dst.u.hGlobal);
1309
1310 hres = pCopyStgMedium(&src, NULL);
1311 ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1312 hres = pCopyStgMedium(NULL, &dst);
1313 ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1314 }
1315
1316 static void test_CopyBindInfo(void)
1317 {
1318 BINDINFO src[2], dest[2];
1319 SECURITY_DESCRIPTOR sec_desc;
1320 HRESULT hres;
1321 int i;
1322
1323 hres = pCopyBindInfo(NULL, NULL);
1324 ok(hres == E_POINTER, "CopyBindInfo returned %08x, expected E_POINTER\n", hres);
1325
1326 memset(src, 0, sizeof(BINDINFO[2]));
1327 memset(dest, 0xde, sizeof(BINDINFO[2]));
1328 hres = pCopyBindInfo(src, dest);
1329 ok(hres == E_INVALIDARG, "CopyBindInfo returned: %08x, expected E_INVALIDARG\n", hres);
1330
1331 memset(src, 0, sizeof(BINDINFO[2]));
1332 memset(dest, 0xde, sizeof(BINDINFO[2]));
1333 src[0].cbSize = sizeof(BINDINFO);
1334 dest[0].cbSize = 0;
1335 hres = pCopyBindInfo(src, dest);
1336 ok(hres == E_INVALIDARG, "CopyBindInfo returned: %08x, expected E_INVALIDARG\n", hres);
1337
1338 memset(src, 0, sizeof(BINDINFO[2]));
1339 memset(dest, 0xde, sizeof(BINDINFO[2]));
1340 src[0].cbSize = 1;
1341 dest[0].cbSize = sizeof(BINDINFO)+sizeof(DWORD);
1342 hres = pCopyBindInfo(src, dest);
1343 ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
1344 ok(dest[0].cbSize == sizeof(BINDINFO)+sizeof(DWORD), "incorrect cbSize: %d\n", dest[0].cbSize);
1345 for(i=1; i<dest[0].cbSize/sizeof(int); i++)
1346 ok(((int*)dest)[i] == 0, "unset values should be set to 0, got %d on %d\n", ((int*)dest)[i], i);
1347
1348 memset(src, 0, sizeof(BINDINFO[2]));
1349 memset(dest, 0xde, sizeof(BINDINFO[2]));
1350 src[0].cbSize = sizeof(BINDINFO)+2*sizeof(DWORD);
1351 dest[0].cbSize = sizeof(BINDINFO)+sizeof(DWORD);
1352 hres = pCopyBindInfo(src, dest);
1353 ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
1354 ok(dest[1].cbSize == src[1].cbSize, "additional data should be copied\n");
1355 ok(dest[1].szExtraInfo != src[1].szExtraInfo,
1356 "data not fitting in destination buffer should not be copied\n");
1357
1358 memset(src, 0xf0, sizeof(BINDINFO[2]));
1359 memset(dest, 0xde, sizeof(BINDINFO[2]));
1360 src[0].cbSize = sizeof(BINDINFO);
1361 src[0].szExtraInfo = CoTaskMemAlloc(sizeof(WCHAR));
1362 src[0].szExtraInfo[0] = 0;
1363 src[0].szCustomVerb = NULL;
1364 src[0].pUnk = NULL;
1365 src[0].stgmedData.tymed = TYMED_NULL;
1366 src[0].stgmedData.pUnkForRelease = NULL;
1367 dest[0].cbSize = sizeof(BINDINFO);
1368 hres = pCopyBindInfo(src, dest);
1369 ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
1370
1371 ok(dest[0].cbSize == sizeof(BINDINFO), "incorrect cbSize: %d\n", dest[0].cbSize);
1372 ok(dest[0].szExtraInfo && !dest[0].szExtraInfo[0] && dest[0].szExtraInfo!=src[0].szExtraInfo,
1373 "incorrect szExtraInfo: (%p!=%p) %d\n", dest[0].szExtraInfo,
1374 src[0].szExtraInfo, dest[0].szExtraInfo[0]);
1375 ok(!memcmp(&dest[0].stgmedData, &src[0].stgmedData, sizeof(STGMEDIUM)),
1376 "incorrect stgmedData value\n");
1377 ok(src[0].grfBindInfoF == dest[0].grfBindInfoF, "grfBindInfoF = %x, expected %x\n",
1378 dest[0].grfBindInfoF, src[0].grfBindInfoF);
1379 ok(src[0].dwBindVerb == dest[0].dwBindVerb, "dwBindVerb = %x, expected %x\n",
1380 dest[0].dwBindVerb, src[0].dwBindVerb);
1381 ok(!dest[0].szCustomVerb, "szCustmoVerb != NULL\n");
1382 ok(src[0].cbstgmedData == dest[0].cbstgmedData, "cbstgmedData = %x, expected %x\n",
1383 dest[0].cbstgmedData, src[0].cbstgmedData);
1384 ok(src[0].dwOptions == dest[0].dwOptions, "dwOptions = %x, expected %x\n",
1385 dest[0].dwOptions, src[0].dwOptions);
1386 ok(src[0].dwOptionsFlags == dest[0].dwOptionsFlags, "dwOptionsFlags = %x, expected %x\n",
1387 dest[0].dwOptionsFlags, src[0].dwOptionsFlags);
1388 ok(src[0].dwCodePage == dest[0].dwCodePage, "dwCodePage = %x, expected %x\n",
1389 dest[0].dwCodePage, src[0].dwCodePage);
1390 ok(!dest[0].securityAttributes.nLength,
1391 "unexpected securityAttributes.nLength value: %d\n",
1392 dest[0].securityAttributes.nLength);
1393 ok(!dest[0].securityAttributes.lpSecurityDescriptor,
1394 "unexpected securityAttributes.lpSecurityDescriptor value: %p\n",
1395 dest[0].securityAttributes.lpSecurityDescriptor);
1396 ok(!dest[0].securityAttributes.bInheritHandle,
1397 "unexpected securityAttributes.bInheritHandle value: %d\n",
1398 dest[0].securityAttributes.bInheritHandle);
1399 ok(!memcmp(&dest[0].iid, &src[0].iid, sizeof(IID)),
1400 "incorrect iid value\n");
1401 ok(!dest[0].pUnk, "pUnk != NULL\n");
1402 ok(src[0].dwReserved == dest[0].dwReserved, "dwReserved = %x, expected %x\n",
1403 dest[0].dwReserved, src[0].dwReserved);
1404
1405 CoTaskMemFree(src[0].szExtraInfo);
1406 CoTaskMemFree(dest[0].szExtraInfo);
1407
1408 src[0].szExtraInfo = NULL;
1409 src[0].securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
1410 ok(InitializeSecurityDescriptor(&sec_desc, SECURITY_DESCRIPTOR_REVISION),
1411 "InitializeSecurityDescriptor failed\n");
1412 src[0].securityAttributes.lpSecurityDescriptor = (void*)&sec_desc;
1413 src[0].securityAttributes.bInheritHandle = TRUE;
1414 hres = pCopyBindInfo(src, dest);
1415 ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
1416 ok(!dest[0].securityAttributes.nLength,
1417 "unexpected securityAttributes.nLength value: %d\n",
1418 dest[0].securityAttributes.nLength);
1419 ok(!dest[0].securityAttributes.lpSecurityDescriptor,
1420 "unexpected securityAttributes.lpSecurityDescriptor value: %p\n",
1421 dest[0].securityAttributes.lpSecurityDescriptor);
1422 ok(!dest[0].securityAttributes.bInheritHandle,
1423 "unexpected securityAttributes.bInheritHandle value: %d\n",
1424 dest[0].securityAttributes.bInheritHandle);
1425 }
1426
1427 static void test_UrlMkGetSessionOption(void)
1428 {
1429 DWORD encoding, size;
1430 HRESULT hres;
1431
1432 size = encoding = 0xdeadbeef;
1433 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1434 sizeof(encoding), &size, 0);
1435 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1436 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1437 ok(size == sizeof(encoding), "size=%d\n", size);
1438
1439 size = encoding = 0xdeadbeef;
1440 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1441 sizeof(encoding)+1, &size, 0);
1442 ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1443 ok(encoding != 0xdeadbeef, "encoding not changed\n");
1444 ok(size == sizeof(encoding), "size=%d\n", size);
1445
1446 size = encoding = 0xdeadbeef;
1447 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1448 sizeof(encoding)-1, &size, 0);
1449 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1450 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1451 ok(size == 0xdeadbeef, "size=%d\n", size);
1452
1453 size = encoding = 0xdeadbeef;
1454 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1455 sizeof(encoding)-1, &size, 0);
1456 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1457 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1458 ok(size == 0xdeadbeef, "size=%d\n", size);
1459
1460 encoding = 0xdeadbeef;
1461 hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1462 sizeof(encoding)-1, NULL, 0);
1463 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1464 ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1465 }
1466
1467 static void test_user_agent(void)
1468 {
1469 static const CHAR expected[] = "Mozilla/4.0 (compatible; MSIE ";
1470 static char test_str[] = "test";
1471 static char test2_str[] = "test\0test";
1472 static CHAR str[3];
1473 LPSTR str2 = NULL;
1474 HRESULT hres;
1475 DWORD size, saved;
1476
1477 hres = pObtainUserAgentString(0, NULL, NULL);
1478 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1479
1480 size = 100;
1481 hres = pObtainUserAgentString(0, NULL, &size);
1482 ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
1483 ok(size == 100, "size=%d, expected %d\n", size, 100);
1484
1485 size = 0;
1486 hres = pObtainUserAgentString(0, str, &size);
1487 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1488 ok(size > 0, "size=%d, expected non-zero\n", size);
1489
1490 size = 2;
1491 str[0] = 'a';
1492 hres = pObtainUserAgentString(0, str, &size);
1493 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1494 ok(size > 0, "size=%d, expected non-zero\n", size);
1495 ok(str[0] == 'a', "str[0]=%c, expected 'a'\n", str[0]);
1496
1497 size = 0;
1498 hres = pObtainUserAgentString(1, str, &size);
1499 ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
1500 ok(size > 0, "size=%d, expected non-zero\n", size);
1501
1502 str2 = HeapAlloc(GetProcessHeap(), 0, (size+20)*sizeof(CHAR));
1503 saved = size;
1504 hres = pObtainUserAgentString(0, str2, &size);
1505 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1506 ok(size == saved, "size=%d, expected %d\n", size, saved);
1507 ok(strlen(expected) <= strlen(str2) &&
1508 !memcmp(expected, str2, strlen(expected)*sizeof(CHAR)),
1509 "user agent was \"%s\", expected to start with \"%s\"\n",
1510 str2, expected);
1511
1512 size = saved+10;
1513 hres = pObtainUserAgentString(0, str2, &size);
1514 ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
1515 ok(size == saved, "size=%d, expected %d\n", size, saved);
1516
1517 size = 0;
1518 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, NULL, 0, &size, 0);
1519 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1520 ok(size, "size == 0\n");
1521
1522 size = 0xdeadbeef;
1523 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, NULL, 1000, &size, 0);
1524 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1525 ok(size, "size == 0\n");
1526
1527 saved = size;
1528 size = 0;
1529 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved+10, &size, 0);
1530 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1531 ok(size == saved, "size = %d, expected %d\n", size, saved);
1532 ok(sizeof(expected) <= strlen(str2) && !memcmp(expected, str2, sizeof(expected)-1),
1533 "user agent was \"%s\", expected to start with \"%s\"\n",
1534 str2, expected);
1535
1536 size = 0;
1537 str2[0] = 0;
1538 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1539 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1540 ok(size == saved, "size = %d, expected %d\n", size, saved);
1541 ok(sizeof(expected) <= strlen(str2) && !memcmp(expected, str2, sizeof(expected)-1),
1542 "user agent was \"%s\", expected to start with \"%s\"\n",
1543 str2, expected);
1544
1545 size = saved;
1546 str2[0] = 0;
1547 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved-1, &size, 0);
1548 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1549 ok(size == saved, "size = %d, expected %d\n", size, saved);
1550 ok(!str2[0], "buf changed\n");
1551
1552 size = saved;
1553 str2[0] = 0;
1554 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, NULL, 0);
1555 ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
1556 ok(!str2[0], "buf changed\n");
1557
1558 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, sizeof(test_str), 0);
1559 ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1560
1561 size = 0;
1562 str2[0] = 0;
1563 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1564 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1565 ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");
1566
1567 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test2_str, sizeof(test2_str), 0);
1568 ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1569
1570 size = 0;
1571 str2[0] = 0;
1572 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1573 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1574 ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");
1575
1576 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, 2, 0);
1577 ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);
1578
1579 size = 0;
1580 str2[0] = 0;
1581 hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1582 ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
1583 ok(size == 3 && !strcmp(str2, "te"), "wrong user agent\n");
1584
1585 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, 0, 0);
1586 ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1587
1588 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, NULL, sizeof(test_str), 0);
1589 ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1590
1591 hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, NULL, 0, 0);
1592 ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);
1593
1594 HeapFree(GetProcessHeap(), 0, str2);
1595 }
1596
1597 static void test_MkParseDisplayNameEx(void)
1598 {
1599 IMoniker *mon = NULL;
1600 LPWSTR name;
1601 DWORD issys;
1602 ULONG eaten = 0;
1603 IBindCtx *bctx;
1604 HRESULT hres;
1605
1606 static const WCHAR clsid_nameW[] = {'c','l','s','i','d',':',
1607 '2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8',
1608 '-','0','8','0','0','2','B','3','0','3','0','9','D',':',0};
1609
1610 const struct
1611 {
1612 LPBC *ppbc;
1613 LPCWSTR szDisplayName;
1614 ULONG *pchEaten;
1615 LPMONIKER *ppmk;
1616 } invalid_parameters[] =
1617 {
1618 {NULL, NULL, NULL, NULL},
1619 {NULL, NULL, NULL, &mon},
1620 {NULL, NULL, &eaten, NULL},
1621 {NULL, NULL, &eaten, &mon},
1622 {NULL, wszEmpty, NULL, NULL},
1623 {NULL, wszEmpty, NULL, &mon},
1624 {NULL, wszEmpty, &eaten, NULL},
1625 {NULL, wszEmpty, &eaten, &mon},
1626 {&bctx, NULL, NULL, NULL},
1627 {&bctx, NULL, NULL, &mon},
1628 {&bctx, NULL, &eaten, NULL},
1629 {&bctx, NULL, &eaten, &mon},
1630 {&bctx, wszEmpty, NULL, NULL},
1631 {&bctx, wszEmpty, NULL, &mon},
1632 {&bctx, wszEmpty, &eaten, NULL},
1633 {&bctx, wszEmpty, &eaten, &mon},
1634 };
1635
1636 int i;
1637
1638 CreateBindCtx(0, &bctx);
1639
1640 for (i = 0; i < sizeof(invalid_parameters)/sizeof(invalid_parameters[0]); i++)
1641 {
1642 eaten = 0xdeadbeef;
1643 mon = (IMoniker *)0xdeadbeef;
1644 hres = MkParseDisplayNameEx(invalid_parameters[i].ppbc ? *invalid_parameters[i].ppbc : NULL,
1645 invalid_parameters[i].szDisplayName,
1646 invalid_parameters[i].pchEaten,
1647 invalid_parameters[i].ppmk);
1648 ok(hres == E_INVALIDARG,
1649 "[%d] Expected MkParseDisplayNameEx to return E_INVALIDARG, got %08x\n", i, hres);
1650 ok(eaten == 0xdeadbeef, "[%d] Expected eaten to be 0xdeadbeef, got %u\n", i, eaten);
1651 ok(mon == (IMoniker *)0xdeadbeef, "[%d] Expected mon to be 0xdeadbeef, got %p\n", i, mon);
1652 }
1653
1654 hres = MkParseDisplayNameEx(bctx, url9, &eaten, &mon);
1655 ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1656 ok(eaten == sizeof(url9)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1657 ok(mon != NULL, "mon == NULL\n");
1658
1659 hres = IMoniker_GetDisplayName(mon, NULL, 0, &name);
1660 ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
1661 ok(!lstrcmpW(name, url9), "wrong display name %s\n", wine_dbgstr_w(name));
1662 CoTaskMemFree(name);
1663
1664 hres = IMoniker_IsSystemMoniker(mon, &issys);
1665 ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1666 ok(issys == MKSYS_URLMONIKER, "issys=%x\n", issys);
1667
1668 IMoniker_Release(mon);
1669
1670 hres = MkParseDisplayNameEx(bctx, clsid_nameW, &eaten, &mon);
1671 ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
1672 ok(eaten == sizeof(clsid_nameW)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
1673 ok(mon != NULL, "mon == NULL\n");
1674
1675 hres = IMoniker_IsSystemMoniker(mon, &issys);
1676 ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
1677 ok(issys == MKSYS_CLASSMONIKER, "issys=%x\n", issys);
1678
1679 IMoniker_Release(mon);
1680
1681 hres = MkParseDisplayNameEx(bctx, url8, &eaten, &mon);
1682 ok(FAILED(hres), "MkParseDisplayNameEx succeeded: %08x\n", hres);
1683
1684 IBindCtx_Release(bctx);
1685 }
1686
1687 static void test_IsValidURL(void)
1688 {
1689 HRESULT hr;
1690 IBindCtx *bctx = NULL;
1691
1692 hr = IsValidURL(NULL, 0, 0);
1693 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
1694
1695 hr = IsValidURL(NULL, wszHttpWineHQ, 0);
1696 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1697
1698 CreateBindCtx(0, &bctx);
1699
1700 hr = IsValidURL(bctx, wszHttpWineHQ, 0);
1701 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
1702
1703 IBindCtx_Release(bctx);
1704 }
1705
1706 static const struct {
1707 INTERNETFEATURELIST feature;
1708 DWORD get_flags;
1709 HRESULT expected;
1710 BOOL todo;
1711 } default_feature_tests[] = {
1712 {FEATURE_OBJECT_CACHING,GET_FEATURE_FROM_PROCESS,S_OK},
1713 {FEATURE_ZONE_ELEVATION,GET_FEATURE_FROM_PROCESS,S_FALSE},
1714 {FEATURE_MIME_HANDLING,GET_FEATURE_FROM_PROCESS,S_FALSE},
1715 {FEATURE_MIME_SNIFFING,GET_FEATURE_FROM_PROCESS,S_FALSE},
1716 {FEATURE_WINDOW_RESTRICTIONS,GET_FEATURE_FROM_PROCESS,S_FALSE},
1717 {FEATURE_WEBOC_POPUPMANAGEMENT,GET_FEATURE_FROM_PROCESS,S_FALSE},
1718 {FEATURE_BEHAVIORS,GET_FEATURE_FROM_PROCESS,S_OK},
1719 {FEATURE_DISABLE_MK_PROTOCOL,GET_FEATURE_FROM_PROCESS,S_OK},
1720 {FEATURE_LOCALMACHINE_LOCKDOWN,GET_FEATURE_FROM_PROCESS,S_FALSE},
1721 {FEATURE_SECURITYBAND,GET_FEATURE_FROM_PROCESS,S_FALSE},
1722 {FEATURE_RESTRICT_ACTIVEXINSTALL,GET_FEATURE_FROM_PROCESS,S_FALSE},
1723 {FEATURE_VALIDATE_NAVIGATE_URL,GET_FEATURE_FROM_PROCESS,S_FALSE},
1724 {FEATURE_RESTRICT_FILEDOWNLOAD,GET_FEATURE_FROM_PROCESS,S_FALSE},
1725 {FEATURE_ADDON_MANAGEMENT,GET_FEATURE_FROM_PROCESS,S_FALSE},
1726 {FEATURE_PROTOCOL_LOCKDOWN,GET_FEATURE_FROM_PROCESS,S_FALSE},
1727 {FEATURE_HTTP_USERNAME_PASSWORD_DISABLE,GET_FEATURE_FROM_PROCESS,S_FALSE},
1728 {FEATURE_SAFE_BINDTOOBJECT,GET_FEATURE_FROM_PROCESS,S_FALSE},
1729 {FEATURE_UNC_SAVEDFILECHECK,GET_FEATURE_FROM_PROCESS,S_FALSE},
1730 {FEATURE_GET_URL_DOM_FILEPATH_UNENCODED,GET_FEATURE_FROM_PROCESS,S_OK},
1731 {FEATURE_TABBED_BROWSING,GET_FEATURE_FROM_PROCESS,S_FALSE},
1732 {FEATURE_SSLUX,GET_FEATURE_FROM_PROCESS,S_FALSE},
1733 {FEATURE_DISABLE_NAVIGATION_SOUNDS,GET_FEATURE_FROM_PROCESS,S_FALSE},
1734 {FEATURE_DISABLE_LEGACY_COMPRESSION,GET_FEATURE_FROM_PROCESS,S_OK},
1735 {FEATURE_FORCE_ADDR_AND_STATUS,GET_FEATURE_FROM_PROCESS,S_FALSE},
1736 {FEATURE_XMLHTTP,GET_FEATURE_FROM_PROCESS,S_OK},
1737 {FEATURE_DISABLE_TELNET_PROTOCOL,GET_FEATURE_FROM_PROCESS,S_FALSE},
1738 {FEATURE_FEEDS,GET_FEATURE_FROM_PROCESS,S_FALSE},
1739 {FEATURE_BLOCK_INPUT_PROMPTS,GET_FEATURE_FROM_PROCESS,S_FALSE}
1740 };
1741
1742 static void test_internet_feature_defaults(void) {
1743 HRESULT hres;
1744 DWORD i;
1745
1746 for(i = 0; i < sizeof(default_feature_tests)/sizeof(default_feature_tests[0]); ++i) {
1747 hres = pCoInternetIsFeatureEnabled(default_feature_tests[i].feature, default_feature_tests[i].get_flags);
1748 todo_wine_if (default_feature_tests[i].todo)
1749 ok(hres == default_feature_tests[i].expected, "CoInternetIsFeatureEnabled returned %08x, expected %08x on test %d\n",
1750 hres, default_feature_tests[i].expected, i);
1751 }
1752 }
1753
1754 /* With older versions of IE (IE 7 and earlier), urlmon caches
1755 * the FeatureControl values from the registry when it's loaded
1756 * into memory. Newer versions of IE conditionally cache the
1757 * the FeatureControl registry values (i.e. When a call to
1758 * CoInternetIsFeatureEnabled and a corresponding CoInternetSetFeatureEnabled
1759 * call hasn't already been made for the specified Feature). Because of
1760 * this we skip these tests on IE 7 and earlier.
1761 */
1762 static const char* szFeatureControlKey = "Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl";
1763
1764 static void test_internet_features_registry(void) {
1765 HRESULT hres;
1766 DWORD res;
1767 char module[MAX_PATH];
1768 char *name;
1769 HKEY feature_control;
1770 HKEY feature;
1771 DWORD value;
1772 BOOL skip_zone;
1773 BOOL delete_feature_key = TRUE;
1774
1775 static const char* szFeatureBehaviorsKey = "FEATURE_BEHAVIORS";
1776 static const char* szFeatureZoneElevationKey = "FEATURE_ZONE_ELEVATION";
1777
1778 if(!pIEInstallScope) {
1779 win_skip("Skipping internet feature registry tests, IE is too old...\n");
1780 return;
1781 }
1782
1783 res = GetModuleFileNameA(NULL, module, sizeof(module));
1784 ok(res, "GetModuleFileName failed: %d\n", GetLastError());
1785
1786 name = strrchr(module, '\\')+1;
1787
1788 /* Some Windows machines don't have a FeatureControl key in HKCU. */
1789 res = RegOpenKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &feature_control);
1790 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
1791
1792 res = RegOpenKeyA(feature_control, szFeatureBehaviorsKey, &feature);
1793 if(res == ERROR_SUCCESS) {
1794 /* FEATURE_BEHAVIORS already existed, so don't delete it when we're done. */
1795 delete_feature_key = FALSE;
1796 }else {
1797 res = RegCreateKeyA(feature_control, szFeatureBehaviorsKey, &feature);
1798 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
1799 }
1800
1801 value = 0;
1802 res = RegSetValueExA(feature, name, 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
1803 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
1804
1805 hres = pCoInternetIsFeatureEnabled(FEATURE_BEHAVIORS, GET_FEATURE_FROM_PROCESS);
1806 ok(hres == S_FALSE, "CoInternetIsFeatureEnabled returned %08x, expected S_FALSE\n", hres);
1807
1808 if(delete_feature_key) {
1809 RegCloseKey(feature);
1810 RegDeleteKeyA(feature_control, szFeatureBehaviorsKey);
1811 } else {
1812 RegDeleteValueA(feature, name);
1813 RegCloseKey(feature);
1814 }
1815
1816 /* IE's feature control cached the value it got from the registry earlier. */
1817 hres = pCoInternetIsFeatureEnabled(FEATURE_BEHAVIORS, GET_FEATURE_FROM_PROCESS);
1818 ok(hres == S_FALSE, "CoInternetIsFeatureEnabled returned %08x, expected S_FALSE\n", hres);
1819
1820 /* Restore this feature back to its default value. */
1821 hres = pCoInternetSetFeatureEnabled(FEATURE_BEHAVIORS, SET_FEATURE_ON_PROCESS, TRUE);
1822 ok(hres == S_OK, "CoInternetSetFeatureEnabled failed: %08x\n", hres);
1823
1824 RegCloseKey(feature_control);
1825
1826 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szFeatureControlKey, &feature_control);
1827 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
1828
1829 res = RegOpenKeyA(feature_control, szFeatureZoneElevationKey, &feature);
1830 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
1831
1832 value = 1;
1833 res = RegSetValueExA(feature, "*", 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
1834 if (res == ERROR_ACCESS_DENIED)
1835 {
1836 skip("Not allowed to modify zone elevation\n");
1837 skip_zone = TRUE;
1838 }
1839 else
1840 {
1841 skip_zone = FALSE;
1842 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
1843
1844 hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
1845 ok(hres == S_OK, "CoInternetIsFeatureEnabled returned %08x, expected S_OK\n", hres);
1846 }
1847 RegDeleteValueA(feature, "*");
1848 RegCloseKey(feature);
1849 RegCloseKey(feature_control);
1850
1851 /* Value is still cached from last time. */
1852 if (!skip_zone)
1853 {
1854 hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
1855 ok(hres == S_OK, "CoInternetIsFeatureEnabled returned %08x, expected S_OK\n", hres);
1856
1857 hres = pCoInternetSetFeatureEnabled(FEATURE_ZONE_ELEVATION, SET_FEATURE_ON_PROCESS, FALSE);
1858 ok(hres == S_OK, "CoInternetSetFeatureEnabled failed: %08x\n", hres);
1859 }
1860
1861 test_internet_feature_defaults();
1862 }
1863
1864 static void test_CoInternetIsFeatureEnabled(void) {
1865 HRESULT hres;
1866
1867 hres = pCoInternetIsFeatureEnabled(FEATURE_ENTRY_COUNT, GET_FEATURE_FROM_PROCESS);
1868 ok(hres == E_FAIL, "CoInternetIsFeatureEnabled returned %08x, expected E_FAIL\n", hres);
1869 }
1870
1871 static const struct {
1872 INTERNETFEATURELIST feature;
1873 DWORD set_flags;
1874 BOOL enable;
1875 HRESULT set_expected;
1876 BOOL set_todo;
1877 DWORD get_flags;
1878 HRESULT get_expected;
1879 BOOL get_todo;
1880 } internet_feature_tests[] = {
1881 {FEATURE_OBJECT_CACHING,SET_FEATURE_ON_PROCESS,FALSE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_FALSE},
1882 {FEATURE_WEBOC_POPUPMANAGEMENT,SET_FEATURE_ON_PROCESS,TRUE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_OK},
1883 {FEATURE_LOCALMACHINE_LOCKDOWN,SET_FEATURE_ON_PROCESS,TRUE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_OK}
1884 };
1885
1886 static void test_CoInternetSetFeatureEnabled(void) {
1887 HRESULT hres;
1888 DWORD i;
1889
1890 hres = pCoInternetSetFeatureEnabled(FEATURE_ENTRY_COUNT,SET_FEATURE_ON_PROCESS,TRUE);
1891 ok(hres == E_FAIL, "CoInternetSetFeatureEnabled returned %08x, expected E_FAIL\n", hres);
1892
1893 for(i = 0; i < sizeof(internet_feature_tests)/sizeof(internet_feature_tests[0]); ++i) {
1894 hres = pCoInternetSetFeatureEnabled(internet_feature_tests[i].feature, internet_feature_tests[i].set_flags,
1895 internet_feature_tests[i].enable);
1896 todo_wine_if (internet_feature_tests[i].set_todo)
1897 ok(hres == internet_feature_tests[i].set_expected, "CoInternetSetFeatureEnabled returned %08x, expected %08x on test %d\n",
1898 hres, internet_feature_tests[i].set_expected, i);
1899
1900 hres = pCoInternetIsFeatureEnabled(internet_feature_tests[i].feature, internet_feature_tests[i].set_flags);
1901 todo_wine_if (internet_feature_tests[i].get_todo)
1902 ok(hres == internet_feature_tests[i].get_expected, "CoInternetIsFeatureEnabled returned %08x, expected %08x on test %d\n",
1903 hres, internet_feature_tests[i].get_expected, i);
1904
1905 }
1906 }
1907
1908 static void test_internet_features(void) {
1909 HKEY key;
1910 DWORD res;
1911
1912 if(!pCoInternetIsFeatureEnabled || !pCoInternetSetFeatureEnabled) {
1913 win_skip("Skipping internet feature tests, IE is too old\n");
1914 return;
1915 }
1916
1917 /* IE10 takes FeatureControl key into account only if it's available upon process start. */
1918 res = RegOpenKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &key);
1919 if(res != ERROR_SUCCESS) {
1920 PROCESS_INFORMATION pi;
1921 STARTUPINFOA si = { 0 };
1922 char cmdline[MAX_PATH];
1923 char **argv;
1924 BOOL ret;
1925
1926 res = RegCreateKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &key);
1927 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
1928
1929 trace("Running features tests in a separated process.\n");
1930
1931 winetest_get_mainargs( &argv );
1932 sprintf(cmdline, "\"%s\" %s internet_features", argv[0], argv[1]);
1933 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
1934 ok(ret, "Could not create process: %u\n", GetLastError());
1935 winetest_wait_child_process( pi.hProcess );
1936 CloseHandle(pi.hThread);
1937 CloseHandle(pi.hProcess);
1938
1939 RegDeleteKeyA(HKEY_CURRENT_USER, szFeatureControlKey);
1940 return;
1941 }
1942
1943 test_internet_features_registry();
1944 test_CoInternetIsFeatureEnabled();
1945 test_CoInternetSetFeatureEnabled();
1946 }
1947
1948 static BINDINFO rem_bindinfo = { sizeof(rem_bindinfo) }, in_bindinfo;
1949 static DWORD rem_bindf;
1950
1951 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv)
1952 {
1953 if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid)
1954 || IsEqualGUID(&IID_IBindStatusCallback, riid)
1955 || IsEqualGUID(&IID_IUnknown, riid)) {
1956 *ppv = iface;
1957 return S_OK;
1958 }
1959
1960 *ppv = NULL;
1961 return E_NOINTERFACE;
1962 }
1963
1964 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallbackEx *iface)
1965 {
1966 return 2;
1967 }
1968
1969 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallbackEx *iface)
1970 {
1971 return 1;
1972 }
1973
1974 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallbackEx *iface,
1975 DWORD dwReserved, IBinding *pib)
1976 {
1977 ok(0, "unexpected call\n");
1978 return S_OK;
1979 }
1980
1981 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
1982 {
1983 ok(0, "unexpected call\n");
1984 return E_NOTIMPL;
1985 }
1986
1987 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
1988 {
1989 ok(0, "unexpected call\n");
1990 return E_NOTIMPL;
1991 }
1992
1993 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
1994 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1995 {
1996 ok(0, "unexpected call\n");
1997 return S_OK;
1998 }
1999
2000 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError)
2001 {
2002 ok(0, "unexpected call\n");
2003 return S_OK;
2004 }
2005
2006 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
2007 {
2008 in_bindinfo = *pbindinfo;
2009 *grfBINDF = rem_bindf;
2010 *pbindinfo = rem_bindinfo;
2011 return S_OK;
2012 }
2013
2014 static STGMEDIUM in_stgmed, rem_stgmed;
2015
2016 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF,
2017 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
2018 {
2019 in_stgmed = *pstgmed;
2020 *pstgmed = rem_stgmed;
2021 return S_OK;
2022 }
2023
2024 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk)
2025 {
2026 ok(0, "unexpected call\n");
2027 return S_OK;
2028 }
2029
2030 static HRESULT WINAPI BindStatusCallbackEx_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF,
2031 BINDINFO *pbindinfo, DWORD *grfBINDF2, DWORD *pdwReserved)
2032 {
2033 in_bindinfo = *pbindinfo;
2034 *grfBINDF = rem_bindf;
2035 *pbindinfo = rem_bindinfo;
2036 *grfBINDF2 = 11;
2037 *pdwReserved = 12;
2038 return S_OK;
2039 }
2040
2041 static const IBindStatusCallbackExVtbl BindStatusCallbackExVtbl = {
2042 BindStatusCallback_QueryInterface,
2043 BindStatusCallback_AddRef,
2044 BindStatusCallback_Release,
2045 BindStatusCallback_OnStartBinding,
2046 BindStatusCallback_GetPriority,
2047 BindStatusCallback_OnLowResource,
2048 BindStatusCallback_OnProgress,
2049 BindStatusCallback_OnStopBinding,
2050 BindStatusCallback_GetBindInfo,
2051 BindStatusCallback_OnDataAvailable,
2052 BindStatusCallback_OnObjectAvailable,
2053 BindStatusCallbackEx_GetBindInfoEx
2054 };
2055
2056 static IBindStatusCallbackEx BindStatusCallback = { &BindStatusCallbackExVtbl };
2057
2058 typedef struct {
2059 IUnknown IUnknown_iface;
2060 LONG ref;
2061 } RefUnk;
2062
2063 static inline RefUnk *impl_from_IUnknown(IUnknown *iface)
2064 {
2065 return CONTAINING_RECORD(iface, RefUnk, IUnknown_iface);
2066 }
2067
2068 static HRESULT WINAPI RefUnk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
2069 {
2070 if(!IsEqualGUID(&IID_IUnknown, riid)) {
2071 *ppv = NULL;
2072 return E_NOINTERFACE;
2073 }
2074
2075 IUnknown_AddRef(iface);
2076 *ppv = iface;
2077 return S_OK;
2078 }
2079
2080 static ULONG WINAPI RefUnk_AddRef(IUnknown *iface)
2081 {
2082 RefUnk *This = impl_from_IUnknown(iface);
2083 return InterlockedIncrement(&This->ref);
2084 }
2085
2086 static ULONG WINAPI RefUnk_Release(IUnknown *iface)
2087 {
2088 RefUnk *This = impl_from_IUnknown(iface);
2089 return InterlockedDecrement(&This->ref);
2090 }
2091
2092 static const IUnknownVtbl RefUnkVtbl = {
2093 RefUnk_QueryInterface,
2094 RefUnk_AddRef,
2095 RefUnk_Release
2096 };
2097
2098 static RefUnk unk_in = {{&RefUnkVtbl}}, unk_out = {{&RefUnkVtbl}};
2099
2100 static HANDLE thread_ready;
2101
2102 static DWORD WINAPI bsc_thread(void *arg)
2103 {
2104 IStream *stream = arg;
2105 LARGE_INTEGER zero;
2106 MSG msg;
2107 HRESULT hres;
2108
2109 CoInitialize(NULL);
2110
2111 hres = CoMarshalInterface(stream, &IID_IBindStatusCallback, (IUnknown*)&BindStatusCallback,
2112 MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
2113 ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);
2114
2115 zero.QuadPart = 0;
2116 hres = IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
2117 ok(hres == S_OK, "Seek failed: 0x%08x\n", hres);
2118
2119 SetEvent(thread_ready);
2120
2121 while(GetMessageW(&msg, NULL, 0, 0)) {
2122 TranslateMessage(&msg);
2123 DispatchMessageW(&msg);
2124 }
2125
2126 CoUninitialize();
2127 return 0;
2128 }
2129
2130 static void test_bsc_marshaling(void)
2131 {
2132 FORMATETC formatetc = {0, NULL, 1, -1, TYMED_ISTREAM};
2133 IBindStatusCallbackEx *callbackex;
2134 IBindStatusCallback *bsc;
2135 BINDINFO bindinfo;
2136 IStream *stream, *binding_stream;
2137 HANDLE thread;
2138 WCHAR *extra_info_out;
2139 WCHAR *verb_out;
2140 LARGE_INTEGER zero;
2141 STGMEDIUM stgmed;
2142 void *buf;
2143 DWORD bindf;
2144 HRESULT hres;
2145
2146 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2147 ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);
2148
2149 thread_ready = CreateEventW(NULL, TRUE, FALSE, NULL);
2150 thread = CreateThread(NULL, 0, bsc_thread, stream, 0, NULL);
2151 WaitForSingleObject(thread_ready, INFINITE);
2152
2153 hres = CoUnmarshalInterface(stream, &IID_IBindStatusCallback, (void**)&bsc);
2154 ok(hres == S_OK, "CoUnmarshalInterface failed: %08x\n", hres);
2155
2156 hres = CreateStreamOnHGlobal(NULL, TRUE, &binding_stream);
2157 ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);
2158 hres = IStream_Write(binding_stream, "xxx", 3, NULL);
2159 ok(hres == S_OK, "Write failed: %08x\n", hres);
2160
2161 rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2162 bindf = 0xdeadbeef;
2163
2164 memset(&bindinfo, 0, sizeof(bindinfo));
2165 bindinfo.cbSize = sizeof(bindinfo);
2166 bindinfo.grfBindInfoF = 12;
2167 bindinfo.dwBindVerb = 13;
2168 bindinfo.cbstgmedData = 19;
2169 bindinfo.dwOptions = 14;
2170 bindinfo.dwOptionsFlags = 15;
2171 bindinfo.dwCodePage = 16;
2172 bindinfo.securityAttributes.nLength = 30;
2173 bindinfo.securityAttributes.lpSecurityDescriptor = (void*)0xdead0001;
2174 bindinfo.securityAttributes.bInheritHandle = 31;
2175 bindinfo.iid.Data1 = 17;
2176 bindinfo.pUnk = (IUnknown*)0xdeadbeef;
2177 bindinfo.dwReserved = 18;
2178 bindinfo.stgmedData.pUnkForRelease = &unk_in.IUnknown_iface;
2179 unk_in.ref = 1;
2180
2181 memset(&rem_bindinfo, 0, sizeof(bindinfo));
2182 rem_bindinfo.cbSize = sizeof(rem_bindinfo);
2183 rem_bindinfo.szExtraInfo = extra_info_out = a2co("extra info out");
2184 rem_bindinfo.grfBindInfoF = 22;
2185 rem_bindinfo.dwBindVerb = 23;
2186 rem_bindinfo.szCustomVerb = verb_out = a2co("custom verb out");
2187 rem_bindinfo.cbstgmedData = 29;
2188 rem_bindinfo.dwOptions = 24;
2189 rem_bindinfo.dwOptionsFlags = 25;
2190 rem_bindinfo.dwCodePage = 16;
2191 rem_bindinfo.securityAttributes.nLength = 40;
2192 rem_bindinfo.securityAttributes.lpSecurityDescriptor = (void*)0xdead0002;
2193 rem_bindinfo.securityAttributes.bInheritHandle = 41;
2194 rem_bindinfo.iid.Data1 = 27;
2195 rem_bindinfo.pUnk = (IUnknown*)0xdeadbeef;
2196 rem_bindinfo.dwReserved = 18;
2197 rem_bindinfo.stgmedData.pUnkForRelease = &unk_out.IUnknown_iface;
2198 unk_out.ref = 1;
2199
2200 hres = IBindStatusCallback_GetBindInfo(bsc, &bindf, &bindinfo);
2201 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2202 ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
2203
2204 ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
2205 ok(!in_bindinfo.szExtraInfo, "szExtraInfo = %s\n", wine_dbgstr_w(in_bindinfo.szExtraInfo));
2206 ok(in_bindinfo.grfBindInfoF == 12, "cbSize = %u\n", in_bindinfo.grfBindInfoF);
2207 ok(in_bindinfo.dwBindVerb == 13, "dwBindVerb = %u\n", in_bindinfo.dwBindVerb);
2208 ok(!in_bindinfo.szCustomVerb, "szCustomVerb = %s\n", wine_dbgstr_w(in_bindinfo.szCustomVerb));
2209 ok(in_bindinfo.cbstgmedData == 19, "cbstgmedData = %u\n", in_bindinfo.cbstgmedData);
2210 ok(!in_bindinfo.dwOptions, "dwOptions = %u\n", in_bindinfo.dwOptions);
2211 ok(!in_bindinfo.dwOptionsFlags, "dwOptionsFlags = %u\n", in_bindinfo.dwOptionsFlags);
2212 ok(!in_bindinfo.dwCodePage, "dwCodePage = %u\n", in_bindinfo.dwCodePage);
2213 ok(!in_bindinfo.iid.Data1, "iid.Data1 = %u\n", in_bindinfo.iid.Data1);
2214 ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
2215 ok(!in_bindinfo.dwReserved, "dwReserved = %u\n", in_bindinfo.dwReserved);
2216 ok(!in_bindinfo.securityAttributes.nLength, "securityAttributes.nLength = %u\n",
2217 in_bindinfo.securityAttributes.nLength);
2218 ok(!in_bindinfo.securityAttributes.lpSecurityDescriptor,
2219 "securityAttributes.lpSecurityDescriptor = %p\n",
2220 in_bindinfo.securityAttributes.lpSecurityDescriptor);
2221 ok(!in_bindinfo.securityAttributes.bInheritHandle, "securityAttributes.bInheritHandle = %u\n",
2222 in_bindinfo.securityAttributes.bInheritHandle);
2223 ok(!in_bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
2224 in_bindinfo.stgmedData.pUnkForRelease);
2225
2226 ok(bindinfo.cbSize == sizeof(rem_bindinfo), "cbSize = %u\n", rem_bindinfo.cbSize);
2227 ok(!strcmp_wa(bindinfo.szExtraInfo, "extra info out"),
2228 "szExtraInfo = %s\n", wine_dbgstr_w(bindinfo.szExtraInfo));
2229 ok(bindinfo.grfBindInfoF == 22, "grfBindInfoF = %u\n", rem_bindinfo.grfBindInfoF);
2230 ok(bindinfo.dwBindVerb == 23, "dwBindVerb = %u\n", bindinfo.dwBindVerb);
2231 ok(bindinfo.szCustomVerb != verb_out, "szCustomVerb == inbuf\n");
2232 ok(!strcmp_wa(bindinfo.szCustomVerb, "custom verb out"), "szCustomVerb = %s\n",
2233 wine_dbgstr_w(bindinfo.szCustomVerb));
2234 ok(bindinfo.cbstgmedData == 29, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
2235 ok(bindinfo.dwOptions == 24, "dwOptions = %u\n", bindinfo.dwOptions);
2236 ok(bindinfo.dwOptionsFlags == 25, "dwOptionsFlags = %u\n", bindinfo.dwOptionsFlags);
2237 ok(bindinfo.dwCodePage, "dwCodePage = %u\n", bindinfo.dwCodePage);
2238 ok(!bindinfo.iid.Data1, "iid.Data1 = %u\n", bindinfo.iid.Data1);
2239 ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
2240 ok(bindinfo.dwReserved == 18, "dwReserved = %u\n", bindinfo.dwReserved);
2241 ok(bindinfo.securityAttributes.nLength == 30, "securityAttributes.nLength = %u\n",
2242 bindinfo.securityAttributes.nLength);
2243 ok(bindinfo.securityAttributes.lpSecurityDescriptor == (void*)0xdead0001,
2244 "securityAttributes.lpSecurityDescriptor = %p\n",
2245 bindinfo.securityAttributes.lpSecurityDescriptor);
2246 ok(bindinfo.securityAttributes.bInheritHandle == 31, "securityAttributes.bInheritHandle = %u\n",
2247 bindinfo.securityAttributes.bInheritHandle);
2248 ok(bindinfo.stgmedData.pUnkForRelease == &unk_in.IUnknown_iface, "pUnkForRelease = %p\n",
2249 bindinfo.stgmedData.pUnkForRelease);
2250 ok(unk_out.ref == 1, "unk_out.ref = %u\n", unk_out.ref);
2251
2252 bindinfo.stgmedData.pUnkForRelease = NULL;
2253 ReleaseBindInfo(&bindinfo);
2254
2255 zero.QuadPart = 0;
2256 hres = IStream_Seek(binding_stream, zero, STREAM_SEEK_SET, NULL);
2257 ok(hres == S_OK, "Seek failed: 0x%08x\n", hres);
2258
2259 /* Return IStream stgmed from GetBindInfo, it's not marshaled back */
2260 rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2261 bindf = 0xdeadbeef;
2262
2263 memset(&bindinfo, 0, sizeof(bindinfo));
2264 bindinfo.cbSize = sizeof(bindinfo);
2265
2266 memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
2267 rem_bindinfo.cbSize = sizeof(rem_bindinfo);
2268
2269 rem_bindinfo.stgmedData.tymed = TYMED_ISTREAM;
2270 rem_bindinfo.stgmedData.u.pstm = binding_stream;
2271 rem_bindinfo.cbstgmedData = 3;
2272 IStream_AddRef(binding_stream);
2273
2274 hres = IBindStatusCallback_GetBindInfo(bsc, &bindf, &bindinfo);
2275 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2276 ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
2277
2278 ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
2279 ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
2280 ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2281 in_bindinfo.stgmedData.tymed);
2282
2283 ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
2284 ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
2285 ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2286 bindinfo.stgmedData.tymed);
2287 ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
2288 bindinfo.stgmedData.u.pstm);
2289 ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
2290 bindinfo.stgmedData.pUnkForRelease);
2291 ok(bindinfo.cbstgmedData == 3, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
2292
2293 ReleaseBindInfo(&bindinfo);
2294
2295 /* Same, but with pUnkForRelease, it's not marshaled back */
2296 rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2297 bindf = 0xdeadbeef;
2298
2299 memset(&bindinfo, 0, sizeof(bindinfo));
2300 bindinfo.cbSize = sizeof(bindinfo);
2301
2302 memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
2303 rem_bindinfo.cbSize = sizeof(rem_bindinfo);
2304
2305 rem_bindinfo.stgmedData.tymed = TYMED_ISTREAM;
2306 rem_bindinfo.stgmedData.u.pstm = binding_stream;
2307 rem_bindinfo.stgmedData.pUnkForRelease = &unk_out.IUnknown_iface;
2308 unk_out.ref = 1;
2309 rem_bindinfo.cbstgmedData = 3;
2310 IStream_AddRef(binding_stream);
2311
2312 hres = IBindStatusCallback_GetBindInfo(bsc, &bindf, &bindinfo);
2313 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2314 ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
2315
2316 ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
2317 ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
2318 ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2319 in_bindinfo.stgmedData.tymed);
2320
2321 ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
2322 ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
2323 ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2324 bindinfo.stgmedData.tymed);
2325 ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
2326 bindinfo.stgmedData.u.pstm);
2327 ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
2328 bindinfo.stgmedData.pUnkForRelease);
2329 ok(bindinfo.cbstgmedData == 3, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
2330
2331 ReleaseBindInfo(&bindinfo);
2332
2333 /* Return HGLOBAL stgmed from GetBindInfo, it's not marshaled back */
2334 rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2335 bindf = 0xdeadbeef;
2336
2337 memset(&bindinfo, 0, sizeof(bindinfo));
2338 bindinfo.cbSize = sizeof(bindinfo);
2339
2340 memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
2341 rem_bindinfo.cbSize = sizeof(rem_bindinfo);
2342
2343 rem_bindinfo.stgmedData.tymed = TYMED_HGLOBAL;
2344
2345 buf = GlobalAlloc(0, sizeof(5));
2346 strcpy(buf, "test");
2347 rem_bindinfo.stgmedData.u.hGlobal = buf;
2348 rem_bindinfo.cbstgmedData = 5;
2349
2350 hres = IBindStatusCallback_GetBindInfo(bsc, &bindf, &bindinfo);
2351 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2352 ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
2353
2354 ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
2355 ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
2356 ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2357 in_bindinfo.stgmedData.tymed);
2358
2359 ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
2360 ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
2361 ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2362 bindinfo.stgmedData.tymed);
2363 ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
2364 bindinfo.stgmedData.u.pstm);
2365 ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
2366 bindinfo.stgmedData.pUnkForRelease);
2367 ok(bindinfo.cbstgmedData == 5, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
2368
2369 ReleaseBindInfo(&bindinfo);
2370
2371 /* Same with GetBindInfoEx */
2372 hres = IBindStatusCallback_QueryInterface(bsc, &IID_IBindStatusCallbackEx, (void**)&callbackex);
2373 if(SUCCEEDED(hres)) {
2374 DWORD bindf2, reserved;
2375
2376 rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2377 bindf = bindf2 = reserved = 0xdeadbeef;
2378
2379 memset(&bindinfo, 0, sizeof(bindinfo));
2380 bindinfo.cbSize = sizeof(bindinfo);
2381 bindinfo.grfBindInfoF = 12;
2382 bindinfo.dwBindVerb = 13;
2383 bindinfo.cbstgmedData = 19;
2384 bindinfo.dwOptions = 14;
2385 bindinfo.dwOptionsFlags = 15;
2386 bindinfo.dwCodePage = 16;
2387 bindinfo.securityAttributes.nLength = 30;
2388 bindinfo.securityAttributes.lpSecurityDescriptor = (void*)0xdead0001;
2389 bindinfo.securityAttributes.bInheritHandle = 31;
2390 bindinfo.iid.Data1 = 17;
2391 bindinfo.pUnk = (IUnknown*)0xdeadbeef;
2392 bindinfo.dwReserved = 18;
2393 bindinfo.stgmedData.pUnkForRelease = &unk_in.IUnknown_iface;
2394 unk_in.ref = 1;
2395
2396 memset(&rem_bindinfo, 0, sizeof(bindinfo));
2397 rem_bindinfo.cbSize = sizeof(rem_bindinfo);
2398 rem_bindinfo.szExtraInfo = extra_info_out = a2co("extra info out");
2399 rem_bindinfo.grfBindInfoF = 22;
2400 rem_bindinfo.dwBindVerb = 23;
2401 rem_bindinfo.szCustomVerb = verb_out = a2co("custom verb out");
2402 rem_bindinfo.cbstgmedData = 29;
2403 rem_bindinfo.dwOptions = 24;
2404 rem_bindinfo.dwOptionsFlags = 25;
2405 rem_bindinfo.dwCodePage = 16;
2406 rem_bindinfo.securityAttributes.nLength = 40;
2407 rem_bindinfo.securityAttributes.lpSecurityDescriptor = (void*)0xdead0002;
2408 rem_bindinfo.securityAttributes.bInheritHandle = 41;
2409 rem_bindinfo.iid.Data1 = 27;
2410 rem_bindinfo.pUnk = (IUnknown*)0xdeadbeef;
2411 rem_bindinfo.dwReserved = 18;
2412 rem_bindinfo.stgmedData.pUnkForRelease = &unk_out.IUnknown_iface;
2413 unk_out.ref = 1;
2414
2415 hres = IBindStatusCallbackEx_GetBindInfoEx(callbackex, &bindf, &bindinfo, &bindf2, &reserved);
2416 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2417 ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
2418 ok(bindf2 == 11, "bindf2 = %x\n", bindf);
2419 ok(reserved == 12, "reserved = %x\n", reserved);
2420
2421 ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
2422 ok(!in_bindinfo.szExtraInfo, "szExtraInfo = %s\n", wine_dbgstr_w(in_bindinfo.szExtraInfo));
2423 ok(in_bindinfo.grfBindInfoF == 12, "cbSize = %u\n", in_bindinfo.grfBindInfoF);
2424 ok(in_bindinfo.dwBindVerb == 13, "dwBindVerb = %u\n", in_bindinfo.dwBindVerb);
2425 ok(!in_bindinfo.szCustomVerb, "szCustomVerb = %s\n", wine_dbgstr_w(in_bindinfo.szCustomVerb));
2426 ok(in_bindinfo.cbstgmedData == 19, "cbstgmedData = %u\n", in_bindinfo.cbstgmedData);
2427 ok(!in_bindinfo.dwOptions, "dwOptions = %u\n", in_bindinfo.dwOptions);
2428 ok(!in_bindinfo.dwOptionsFlags, "dwOptionsFlags = %u\n", in_bindinfo.dwOptionsFlags);
2429 ok(!in_bindinfo.dwCodePage, "dwCodePage = %u\n", in_bindinfo.dwCodePage);
2430 ok(!in_bindinfo.iid.Data1, "iid.Data1 = %u\n", in_bindinfo.iid.Data1);
2431 ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
2432 ok(!in_bindinfo.dwReserved, "dwReserved = %u\n", in_bindinfo.dwReserved);
2433 ok(!in_bindinfo.securityAttributes.nLength, "securityAttributes.nLength = %u\n",
2434 in_bindinfo.securityAttributes.nLength);
2435 ok(!in_bindinfo.securityAttributes.lpSecurityDescriptor,
2436 "securityAttributes.lpSecurityDescriptor = %p\n",
2437 in_bindinfo.securityAttributes.lpSecurityDescriptor);
2438 ok(!in_bindinfo.securityAttributes.bInheritHandle, "securityAttributes.bInheritHandle = %u\n",
2439 in_bindinfo.securityAttributes.bInheritHandle);
2440 ok(!in_bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
2441 in_bindinfo.stgmedData.pUnkForRelease);
2442
2443 ok(bindinfo.cbSize == sizeof(rem_bindinfo), "cbSize = %u\n", rem_bindinfo.cbSize);
2444 ok(!strcmp_wa(bindinfo.szExtraInfo, "extra info out"),
2445 "szExtraInfo = %s\n", wine_dbgstr_w(bindinfo.szExtraInfo));
2446 ok(bindinfo.grfBindInfoF == 22, "grfBindInfoF = %u\n", rem_bindinfo.grfBindInfoF);
2447 ok(bindinfo.dwBindVerb == 23, "dwBindVerb = %u\n", bindinfo.dwBindVerb);
2448 ok(bindinfo.szCustomVerb != verb_out, "szCustomVerb == inbuf\n");
2449 ok(!strcmp_wa(bindinfo.szCustomVerb, "custom verb out"), "szCustomVerb = %s\n",
2450 wine_dbgstr_w(bindinfo.szCustomVerb));
2451 ok(bindinfo.cbstgmedData == 29, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
2452 ok(bindinfo.dwOptions == 24, "dwOptions = %u\n", bindinfo.dwOptions);
2453 ok(bindinfo.dwOptionsFlags == 25, "dwOptionsFlags = %u\n", bindinfo.dwOptionsFlags);
2454 ok(bindinfo.dwCodePage, "dwCodePage = %u\n", bindinfo.dwCodePage);
2455 ok(!bindinfo.iid.Data1, "iid.Data1 = %u\n", bindinfo.iid.Data1);
2456 ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
2457 ok(bindinfo.dwReserved == 18, "dwReserved = %u\n", bindinfo.dwReserved);
2458 ok(bindinfo.securityAttributes.nLength == 30, "securityAttributes.nLength = %u\n",
2459 bindinfo.securityAttributes.nLength);
2460 ok(bindinfo.securityAttributes.lpSecurityDescriptor == (void*)0xdead0001,
2461 "securityAttributes.lpSecurityDescriptor = %p\n",
2462 bindinfo.securityAttributes.lpSecurityDescriptor);
2463 ok(bindinfo.securityAttributes.bInheritHandle == 31, "securityAttributes.bInheritHandle = %u\n",
2464 bindinfo.securityAttributes.bInheritHandle);
2465 ok(bindinfo.stgmedData.pUnkForRelease == &unk_in.IUnknown_iface, "pUnkForRelease = %p\n",
2466 bindinfo.stgmedData.pUnkForRelease);
2467 ok(unk_out.ref == 1, "unk_out.ref = %u\n", unk_out.ref);
2468
2469 bindinfo.stgmedData.pUnkForRelease = NULL;
2470 ReleaseBindInfo(&bindinfo);
2471
2472 zero.QuadPart = 0;
2473 hres = IStream_Seek(binding_stream, zero, STREAM_SEEK_SET, NULL);
2474 ok(hres == S_OK, "Seek failed: 0x%08x\n", hres);
2475
2476 /* Return IStream stgmed from GetBindInfoEx, it's not marshaled back */
2477 rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2478 bindf = bindf2 = reserved = 0xdeadbeef;
2479
2480 memset(&bindinfo, 0, sizeof(bindinfo));
2481 bindinfo.cbSize = sizeof(bindinfo);
2482
2483 memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
2484 rem_bindinfo.cbSize = sizeof(rem_bindinfo);
2485
2486 rem_bindinfo.stgmedData.tymed = TYMED_ISTREAM;
2487 rem_bindinfo.stgmedData.u.pstm = binding_stream;
2488 rem_bindinfo.cbstgmedData = 3;
2489 IStream_AddRef(binding_stream);
2490
2491 hres = IBindStatusCallbackEx_GetBindInfoEx(callbackex, &bindf, &bindinfo, &bindf2, &reserved);
2492 ok(hres == S_OK, "GetBindInfoEx failed: %08x\n", hres);
2493 ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
2494
2495 ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
2496 ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
2497 ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2498 in_bindinfo.stgmedData.tymed);
2499
2500 ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
2501 ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
2502 ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2503 bindinfo.stgmedData.tymed);
2504 ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
2505 bindinfo.stgmedData.u.pstm);
2506 ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
2507 bindinfo.stgmedData.pUnkForRelease);
2508 ok(bindinfo.cbstgmedData == 3, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
2509
2510 ReleaseBindInfo(&bindinfo);
2511
2512 /* Same, but with pUnkForRelease, it's not marshaled back */
2513 rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2514 bindf = bindf2 = reserved = 0xdeadbeef;
2515
2516 memset(&bindinfo, 0, sizeof(bindinfo));
2517 bindinfo.cbSize = sizeof(bindinfo);
2518
2519 memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
2520 rem_bindinfo.cbSize = sizeof(rem_bindinfo);
2521
2522 rem_bindinfo.stgmedData.tymed = TYMED_ISTREAM;
2523 rem_bindinfo.stgmedData.u.pstm = binding_stream;
2524 rem_bindinfo.stgmedData.pUnkForRelease = &unk_out.IUnknown_iface;
2525 unk_out.ref = 1;
2526 rem_bindinfo.cbstgmedData = 3;
2527 IStream_AddRef(binding_stream);
2528
2529 hres = IBindStatusCallbackEx_GetBindInfoEx(callbackex, &bindf, &bindinfo, &bindf2, &reserved);
2530 ok(hres == S_OK, "GetBindInfoEx failed: %08x\n", hres);
2531 ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
2532
2533 ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
2534 ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
2535 ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2536 in_bindinfo.stgmedData.tymed);
2537
2538 ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
2539 ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
2540 ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2541 bindinfo.stgmedData.tymed);
2542 ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
2543 bindinfo.stgmedData.u.pstm);
2544 ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
2545 bindinfo.stgmedData.pUnkForRelease);
2546 ok(bindinfo.cbstgmedData == 3, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
2547
2548 ReleaseBindInfo(&bindinfo);
2549
2550 /* Return HGLOBAL stgmed from GetBindInfoEx, it's not marshaled back */
2551 rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2552 bindf = bindf2 = reserved = 0xdeadbeef;
2553
2554 memset(&bindinfo, 0, sizeof(bindinfo));
2555 bindinfo.cbSize = sizeof(bindinfo);
2556
2557 memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
2558 rem_bindinfo.cbSize = sizeof(rem_bindinfo);
2559
2560 rem_bindinfo.stgmedData.tymed = TYMED_HGLOBAL;
2561
2562 buf = GlobalAlloc(0, sizeof(5));
2563 strcpy(buf, "test");
2564 rem_bindinfo.stgmedData.u.hGlobal = buf;
2565 rem_bindinfo.cbstgmedData = 5;
2566
2567 hres = IBindStatusCallbackEx_GetBindInfoEx(callbackex, &bindf, &bindinfo, &bindf2, &reserved);
2568 ok(hres == S_OK, "GetBindInfoEx failed: %08x\n", hres);
2569 ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
2570
2571 ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
2572 ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
2573 ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2574 in_bindinfo.stgmedData.tymed);
2575
2576 ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
2577 ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
2578 ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
2579 bindinfo.stgmedData.tymed);
2580 ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
2581 bindinfo.stgmedData.u.pstm);
2582 ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
2583 bindinfo.stgmedData.pUnkForRelease);
2584 ok(bindinfo.cbstgmedData == 5, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
2585
2586 ReleaseBindInfo(&bindinfo);
2587
2588 IBindStatusCallbackEx_Release(callbackex);
2589 }else {
2590 win_skip("IBindStatusCallbackEx not supported\n");
2591 }
2592
2593 /* Test marshaling stgmed from OnDataAvailable */
2594 memset(&in_stgmed, 0xcc, sizeof(in_stgmed));
2595 stgmed.tymed = TYMED_ISTREAM;
2596 stgmed.u.pstm = binding_stream;
2597 stgmed.pUnkForRelease = NULL;
2598
2599 hres = IBindStatusCallback_OnDataAvailable(bsc, 1, 10, &formatetc, &stgmed);
2600 ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);
2601
2602 ok(in_stgmed.tymed == TYMED_ISTREAM, "tymed = %u\n", in_stgmed.tymed);
2603 ok(in_stgmed.u.pstm != NULL, "pstm = NULL\n");
2604 ok(!in_stgmed.pUnkForRelease, "pUnkForRelease = %p\n", in_stgmed.pUnkForRelease);
2605
2606 /* OnDataAvailable with both IStream and pUnkForRelease */
2607 memset(&in_stgmed, 0xcc, sizeof(in_stgmed));
2608 stgmed.tymed = TYMED_ISTREAM;
2609 stgmed.u.pstm = binding_stream;
2610 stgmed.pUnkForRelease = &unk_in.IUnknown_iface;
2611 unk_in.ref = 1;
2612
2613 hres = IBindStatusCallback_OnDataAvailable(bsc, 1, 10, &formatetc, &stgmed);
2614 ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);
2615
2616 ok(in_stgmed.tymed == TYMED_ISTREAM, "tymed = %u\n", in_stgmed.tymed);
2617 ok(in_stgmed.u.pstm != NULL, "pstm = NULL\n");
2618 ok(in_stgmed.pUnkForRelease != NULL, "pUnkForRelease = %p\n", in_stgmed.pUnkForRelease);
2619 ok(unk_in.ref > 1, "ref = %u\n", unk_in.ref);
2620
2621 /* OnDataAvailable with TYMED_ISTREAM, but NULL stream */
2622 memset(&in_stgmed, 0xcc, sizeof(in_stgmed));
2623 stgmed.tymed = TYMED_ISTREAM;
2624 stgmed.u.pstm = binding_stream;
2625 stgmed.pUnkForRelease = NULL;
2626
2627 hres = IBindStatusCallback_OnDataAvailable(bsc, 1, 10, &formatetc, &stgmed);
2628 ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);
2629
2630 ok(in_stgmed.tymed == TYMED_ISTREAM, "tymed = %u\n", in_stgmed.tymed);
2631 ok(in_stgmed.u.pstm != NULL, "pstm = NULL\n");
2632 ok(!in_stgmed.pUnkForRelease, "pUnkForRelease = %p\n", in_stgmed.pUnkForRelease);
2633
2634 /* OnDataAvailable with TYMED_NULL and pUnkForRelease */
2635 memset(&in_stgmed, 0xcc, sizeof(in_stgmed));
2636 stgmed.tymed = TYMED_NULL;
2637 stgmed.u.pstm = binding_stream;
2638 stgmed.pUnkForRelease = &unk_in.IUnknown_iface;
2639 unk_in.ref = 1;
2640
2641 hres = IBindStatusCallback_OnDataAvailable(bsc, 1, 10, &formatetc, &stgmed);
2642 ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);
2643
2644 ok(in_stgmed.tymed == TYMED_NULL, "tymed = %u\n", in_stgmed.tymed);
2645 ok(!in_stgmed.u.pstm, "pstm != NULL\n");
2646 ok(in_stgmed.pUnkForRelease != NULL, "pUnkForRelease = %p\n", in_stgmed.pUnkForRelease);
2647 ok(unk_in.ref == 1, "ref = %u\n", unk_in.ref);
2648
2649 IStream_Release(binding_stream);
2650 IBindStatusCallback_Release(bsc);
2651
2652 TerminateThread(thread, 0);
2653 }
2654
2655 START_TEST(misc)
2656 {
2657 HMODULE hurlmon;
2658 int argc;
2659 char **argv;
2660
2661 argc = winetest_get_mainargs(&argv);
2662
2663 hurlmon = GetModuleHandleA("urlmon.dll");
2664 pCoInternetCompareUrl = (void *) GetProcAddress(hurlmon, "CoInternetCompareUrl");
2665 pCoInternetGetSecurityUrl = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrl");
2666 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
2667 pCoInternetParseUrl = (void*) GetProcAddress(hurlmon, "CoInternetParseUrl");
2668 pCoInternetQueryInfo = (void*) GetProcAddress(hurlmon, "CoInternetQueryInfo");
2669 pCopyStgMedium = (void*) GetProcAddress(hurlmon, "CopyStgMedium");
2670 pCopyBindInfo = (void*) GetProcAddress(hurlmon, "CopyBindInfo");
2671 pFindMimeFromData = (void*) GetProcAddress(hurlmon, "FindMimeFromData");
2672 pObtainUserAgentString = (void*) GetProcAddress(hurlmon, "ObtainUserAgentString");
2673 pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
2674 pUrlMkGetSessionOption = (void*) GetProcAddress(hurlmon, "UrlMkGetSessionOption");
2675 pCompar