misc.c 111 KB
Newer Older
1
/*
2
 * Copyright 2005-2006 Jacek Caban for CodeWeavers
3 4 5 6 7 8 9 10 11 12 13 14 15
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 18 19
 */

#define COBJMACROS
20
#define CONST_VTABLE
21
#define NONAMELESSUNION
22 23 24

#include <wine/test.h>
#include <stdarg.h>
25
#include <stddef.h>
26
#include <stdio.h>
27 28 29 30 31 32

#include "windef.h"
#include "winbase.h"
#include "ole2.h"
#include "urlmon.h"

33 34 35 36
#include "initguid.h"

DEFINE_GUID(CLSID_AboutProtocol, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#define DEFINE_EXPECT(func) \
    static BOOL expect_ ## func = FALSE, called_ ## func = FALSE

#define SET_EXPECT(func) \
    expect_ ## func = TRUE

#define CHECK_EXPECT(func) \
    do { \
        ok(expect_ ##func, "unexpected call " #func "\n"); \
        expect_ ## func = FALSE; \
        called_ ## func = TRUE; \
    }while(0)

#define CHECK_EXPECT2(func) \
    do { \
        ok(expect_ ##func, "unexpected call " #func "\n"); \
        called_ ## func = TRUE; \
    }while(0)

#define CHECK_CALLED(func) \
    do { \
        ok(called_ ## func, "expected " #func "\n"); \
        expect_ ## func = called_ ## func = FALSE; \
    }while(0)

DEFINE_EXPECT(ParseUrl);
DEFINE_EXPECT(QI_IInternetProtocolInfo);
DEFINE_EXPECT(CreateInstance);
65
DEFINE_EXPECT(unk_Release);
66

67
static HRESULT (WINAPI *pCoInternetCompareUrl)(LPCWSTR, LPCWSTR, DWORD);
68 69 70
static HRESULT (WINAPI *pCoInternetGetSecurityUrl)(LPCWSTR, LPWSTR*, PSUACTION, DWORD);
static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession **, DWORD);
static HRESULT (WINAPI *pCoInternetParseUrl)(LPCWSTR, PARSEACTION, DWORD, LPWSTR, DWORD, DWORD *, DWORD);
71 72
static HRESULT (WINAPI *pCoInternetQueryInfo)(LPCWSTR, QUERYOPTION, DWORD, LPVOID, DWORD, DWORD *, DWORD);
static HRESULT (WINAPI *pCopyStgMedium)(const STGMEDIUM *, STGMEDIUM *);
73
static HRESULT (WINAPI *pCopyBindInfo)(const BINDINFO *, BINDINFO *);
74 75
static HRESULT (WINAPI *pFindMimeFromData)(LPBC, LPCWSTR, LPVOID, DWORD, LPCWSTR,
                        DWORD, LPWSTR*, DWORD);
76 77 78
static HRESULT (WINAPI *pObtainUserAgentString)(DWORD, LPSTR, DWORD*);
static HRESULT (WINAPI *pReleaseBindInfo)(BINDINFO*);
static HRESULT (WINAPI *pUrlMkGetSessionOption)(DWORD, LPVOID, DWORD, DWORD *, DWORD);
79
static HRESULT (WINAPI *pCompareSecurityIds)(BYTE*,DWORD,BYTE*,DWORD,DWORD);
80
static HRESULT (WINAPI *pCoInternetIsFeatureEnabled)(INTERNETFEATURELIST,DWORD);
81
static HRESULT (WINAPI *pCoInternetSetFeatureEnabled)(INTERNETFEATURELIST,DWORD,BOOL);
82
static HRESULT (WINAPI *pIEInstallScope)(DWORD*);
83

84 85 86
static int strcmp_wa(const WCHAR *strw, const char *stra)
{
    WCHAR buf[512];
87
    MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
88 89 90
    return lstrcmpW(strw, buf);
}

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
static void heap_free(void *mem)
{
    HeapFree(GetProcessHeap(), 0, mem);
}

static WCHAR *a2w(const char *str)
{
    WCHAR *ret;
    int len;

    if(!str)
        return NULL;

    len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
    ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
    MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);

    return ret;
}

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
static WCHAR *a2co(const char *str)
{
    WCHAR *ret;
    int len;

    if(!str)
        return NULL;

    len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
    ret = CoTaskMemAlloc(len*sizeof(WCHAR));
    MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);

    return ret;
}

126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
static void test_CreateFormatEnum(void)
{
    IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
    FORMATETC fetc[5];
    ULONG ul;
    HRESULT hres;

    static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
    static FORMATETC formatetc[] = {
        {0,&dev,0,0,0},
        {0,&dev,0,1,0},
        {0,NULL,0,2,0},
        {0,NULL,0,3,0},
        {0,NULL,0,4,0}
    };

    hres = CreateFormatEnumerator(0, formatetc, &fenum);
143
    ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
144
    hres = CreateFormatEnumerator(0, formatetc, NULL);
145
    ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
146
    hres = CreateFormatEnumerator(5, formatetc, NULL);
147
    ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
148 149 150


    hres = CreateFormatEnumerator(5, formatetc, &fenum);
151
    ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
152 153 154 155
    if(FAILED(hres))
        return;

    hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
156
    ok(hres == E_INVALIDARG, "Next failed: %08x, expected E_INVALIDARG\n", hres);
157 158
    ul = 100;
    hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
159 160
    ok(hres == S_OK, "Next failed: %08x\n", hres);
    ok(ul == 0, "ul=%d, expected 0\n", ul);
161 162

    hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
163 164 165
    ok(hres == S_OK, "Next failed: %08x\n", hres);
    ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
    ok(fetc[1].lindex == 1, "fetc[1].lindex=%d, expected 1\n", fetc[1].lindex);
166
    ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
167
    ok(ul == 2, "ul=%d, expected 2\n", ul);
168 169

    hres = IEnumFORMATETC_Skip(fenum, 1);
170
    ok(hres == S_OK, "Skip failed: %08x\n", hres);
171 172

    hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
173 174 175
    ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
    ok(fetc[0].lindex == 3, "fetc[0].lindex=%d, expected 3\n", fetc[0].lindex);
    ok(fetc[1].lindex == 4, "fetc[1].lindex=%d, expected 4\n", fetc[1].lindex);
176
    ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
177
    ok(ul == 2, "ul=%d, expected 2\n", ul);
178 179

    hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
180 181
    ok(hres == S_FALSE, "Next failed: %08x, expected S_FALSE\n", hres);
    ok(ul == 0, "ul=%d, expected 0\n", ul);
182 183
    ul = 100;
    hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
184 185
    ok(hres == S_OK, "Next failed: %08x\n", hres);
    ok(ul == 0, "ul=%d, expected 0\n", ul);
186 187

    hres = IEnumFORMATETC_Skip(fenum, 3);
188
    ok(hres == S_FALSE, "Skip failed: %08x, expected S_FALSE\n", hres);
189 190

    hres = IEnumFORMATETC_Reset(fenum);
191
    ok(hres == S_OK, "Reset failed: %08x\n", hres);
192 193

    hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
194 195
    ok(hres == S_OK, "Next failed: %08x\n", hres);
    ok(fetc[0].lindex == 0, "fetc[0].lindex=%d, expected 0\n", fetc[0].lindex);
196 197

    hres = IEnumFORMATETC_Reset(fenum);
198
    ok(hres == S_OK, "Reset failed: %08x\n", hres);
199 200

    hres = IEnumFORMATETC_Skip(fenum, 2);
201
    ok(hres == S_OK, "Skip failed: %08x\n", hres);
202 203

    hres = IEnumFORMATETC_Clone(fenum, NULL);
204
    ok(hres == E_INVALIDARG, "Clone failed: %08x, expected E_INVALIDARG\n", hres);
205 206

    hres = IEnumFORMATETC_Clone(fenum, &fenum2);
207
    ok(hres == S_OK, "Clone failed: %08x\n", hres);
208 209 210 211 212

    if(SUCCEEDED(hres)) {
        ok(fenum != fenum2, "fenum == fenum2\n");

        hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
213 214
        ok(hres == S_OK, "Next failed: %08x\n", hres);
        ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
215 216 217 218 219

        IEnumFORMATETC_Release(fenum2);
    }

    hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
220 221
    ok(hres == S_OK, "Next failed: %08x\n", hres);
    ok(fetc[0].lindex == 2, "fetc[0].lindex=%d, expected 2\n", fetc[0].lindex);
222 223

    hres = IEnumFORMATETC_Skip(fenum, 1);
224
    ok(hres == S_OK, "Skip failed: %08x\n", hres);
225 226 227 228
    
    IEnumFORMATETC_Release(fenum);
}

229 230 231 232 233 234 235 236 237 238 239 240 241 242
static void test_RegisterFormatEnumerator(void)
{
    IBindCtx *bctx = NULL;
    IEnumFORMATETC *format = NULL, *format2 = NULL;
    IUnknown *unk = NULL;
    HRESULT hres;

    static FORMATETC formatetc = {0,NULL,0,0,0};
    static WCHAR wszEnumFORMATETC[] =
        {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};

    CreateBindCtx(0, &bctx);

    hres = CreateFormatEnumerator(1, &formatetc, &format);
243
    ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
244 245 246 247 248
    if(FAILED(hres))
        return;

    hres = RegisterFormatEnumerator(NULL, format, 0);
    ok(hres == E_INVALIDARG,
249
            "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
250 251
    hres = RegisterFormatEnumerator(bctx, NULL, 0);
    ok(hres == E_INVALIDARG,
252
            "RegisterFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
253 254

    hres = RegisterFormatEnumerator(bctx, format, 0);
255
    ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
256 257

    hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
258
    ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
259 260 261 262
    ok(unk == (IUnknown*)format, "unk != format\n");

    hres = RevokeFormatEnumerator(NULL, format);
    ok(hres == E_INVALIDARG,
263
            "RevokeFormatEnumerator failed: %08x, expected E_INVALIDARG\n", hres);
264 265

    hres = RevokeFormatEnumerator(bctx, format);
266
    ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
267 268

    hres = RevokeFormatEnumerator(bctx, format);
269
    ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08x, expected E_FAIL\n", hres);
270 271

    hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
272
    ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
273 274

    hres = RegisterFormatEnumerator(bctx, format, 0);
275
    ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
276 277

    hres = CreateFormatEnumerator(1, &formatetc, &format2);
278
    ok(hres == S_OK, "CreateFormatEnumerator failed: %08x\n", hres);
279 280 281

    if(SUCCEEDED(hres)) {
        hres = RevokeFormatEnumerator(bctx, format);
282
        ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
283 284 285 286 287

        IEnumFORMATETC_Release(format2);
    }

    hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
288
    ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
289 290 291 292

    IEnumFORMATETC_Release(format);

    hres = RegisterFormatEnumerator(bctx, format, 0);
293
    ok(hres == S_OK, "RegisterFormatEnumerator failed: %08x\n", hres);
294
    hres = RevokeFormatEnumerator(bctx, NULL);
295
    ok(hres == S_OK, "RevokeFormatEnumerator failed: %08x\n", hres);
296
    hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
297
    ok(hres == E_FAIL, "GetObjectParam failed: %08x, expected E_FAIL\n", hres);
298

299
    IEnumFORMATETC_Release(format);
300 301
    IBindCtx_Release(bctx);
}
302 303 304
static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
        '/','b','l','a','n','k','.','h','t','m',0};
static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
305
static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
306
static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
307
        '%','2','e','j','p','g',0};
308 309
static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
        '.','o','r','g',0};
310 311 312
static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
        'f','i','l','e','.','t','e','s','t',0};
313
static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
314 315 316
static const WCHAR url9[] =
    {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',
     '/','s','i','t','e','/','a','b','o','u','t',0};
317
static const WCHAR url10[] = {'h','t','t','p',':','/','/','g','o','o','g','l','e','.','*','.',
318
        'c','o','m',0};
319 320 321
static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
        '.','j','p','g',0};

322 323 324
static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};

325 326
static const WCHAR wszRes[] = {'r','e','s',0};
static const WCHAR wszFile[] = {'f','i','l','e',0};
327 328
static const WCHAR wszHttp[] = {'h','t','t','p',0};
static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
329
static const WCHAR wszEmpty[] = {0};
330
static const WCHAR wszGoogle[] = {'g','o','o','g','l','e','.','*','.','c','o','m',0};
331

332
static const WCHAR wszWineHQ[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
333 334
static const WCHAR wszHttpWineHQ[] = {'h','t','t','p',':','/','/','w','w','w','.',
    'w','i','n','e','h','q','.','o','r','g',0};
335 336
static const WCHAR wszHttpGoogle[] = {'h','t','t','p',':','/','/','g','o','o','g','l','e',
    '.','*','.','c','o','m',0};
337

338 339
struct parse_test {
    LPCWSTR url;
340
    HRESULT secur_hres;
341
    LPCWSTR encoded_url;
342 343
    HRESULT path_hres;
    LPCWSTR path;
344
    LPCWSTR schema;
345 346
    LPCWSTR domain;
    HRESULT domain_hres;
347 348
    LPCWSTR rootdocument;
    HRESULT rootdocument_hres;
349 350 351
};

static const struct parse_test parse_tests[] = {
352 353 354 355 356 357
    {url1, S_OK,   url1,  E_INVALIDARG, NULL, wszRes, NULL, E_FAIL, NULL, E_FAIL},
    {url2, E_FAIL, url2,  E_INVALIDARG, NULL, wszEmpty, NULL, E_FAIL, NULL, E_FAIL},
    {url3, E_FAIL, url3,  S_OK, path3,        wszFile, wszEmpty, S_OK, NULL, E_FAIL},
    {url4, E_FAIL, url4e, S_OK, path4,        wszFile, wszEmpty, S_OK, NULL, E_FAIL},
    {url5, E_FAIL, url5,  E_INVALIDARG, NULL, wszHttp, wszWineHQ, S_OK, wszHttpWineHQ, S_OK},
    {url6, S_OK,   url6,  E_INVALIDARG, NULL, wszAbout, NULL, E_FAIL, NULL, E_FAIL},
358
    {url10, E_FAIL, url10, E_INVALIDARG,NULL, wszHttp, wszGoogle, S_OK, wszHttpGoogle, S_OK}
359 360 361 362 363 364 365 366 367 368 369
};

static void test_CoInternetParseUrl(void)
{
    HRESULT hres;
    DWORD size;
    int i;

    static WCHAR buf[4096];

    memset(buf, 0xf0, sizeof(buf));
370
    hres = pCoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
371
            3, &size, 0);
372
    ok(hres == E_POINTER, "schema failed: %08x, expected E_POINTER\n", hres);
373 374

    for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
375
        memset(buf, 0xf0, sizeof(buf));
376
        hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
377
                sizeof(buf)/sizeof(WCHAR), &size, 0);
378
        ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08x, expected %08x\n",
379 380
                i, hres, parse_tests[i].secur_hres);

381
        memset(buf, 0xf0, sizeof(buf));
382
        hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
383
                sizeof(buf)/sizeof(WCHAR), &size, 0);
384
        ok(hres == S_OK, "[%d] encoding failed: %08x\n", i, hres);
385 386 387
        ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
        ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);

388
        memset(buf, 0xf0, sizeof(buf));
389
        hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
390
                sizeof(buf)/sizeof(WCHAR), &size, 0);
391
        ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08x, expected %08x\n",
392
                i, hres, parse_tests[i].path_hres);
393 394 395 396 397
        if(parse_tests[i].path) {
            ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
            ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
        }

398
        memset(buf, 0xf0, sizeof(buf));
399
        hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
400
                sizeof(buf)/sizeof(WCHAR), &size, 0);
401
        ok(hres == S_OK, "[%d] schema failed: %08x\n", i, hres);
402 403
        ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
        ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
404

405 406 407
        if(memcmp(parse_tests[i].url, wszRes, 3*sizeof(WCHAR))
                && memcmp(parse_tests[i].url, wszAbout, 5*sizeof(WCHAR))) {
            memset(buf, 0xf0, sizeof(buf));
408
            hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_DOMAIN, 0, buf,
409 410 411 412 413
                    sizeof(buf)/sizeof(WCHAR), &size, 0);
            ok(hres == parse_tests[i].domain_hres, "[%d] domain failed: %08x\n", i, hres);
            if(parse_tests[i].domain)
                ok(!lstrcmpW(parse_tests[i].domain, buf), "[%d] wrong domain, received %s\n", i, wine_dbgstr_w(buf));
        }
414 415

        memset(buf, 0xf0, sizeof(buf));
416
        hres = pCoInternetParseUrl(parse_tests[i].url, PARSE_ROOTDOCUMENT, 0, buf,
417 418 419 420
                sizeof(buf)/sizeof(WCHAR), &size, 0);
        ok(hres == parse_tests[i].rootdocument_hres, "[%d] rootdocument failed: %08x\n", i, hres);
        if(parse_tests[i].rootdocument)
            ok(!lstrcmpW(parse_tests[i].rootdocument, buf), "[%d] wrong rootdocument, received %s\n", i, wine_dbgstr_w(buf));
421 422 423
    }
}

424 425 426 427
static void test_CoInternetCompareUrl(void)
{
    HRESULT hres;

428
    hres = pCoInternetCompareUrl(url1, url1, 0);
429
    ok(hres == S_OK, "CoInternetCompareUrl failed: %08x\n", hres);
430

431
    hres = pCoInternetCompareUrl(url1, url3, 0);
432
    ok(hres == S_FALSE, "CoInternetCompareUrl failed: %08x\n", hres);
433

434
    hres = pCoInternetCompareUrl(url3, url1, 0);
435
    ok(hres == S_FALSE, "CoInternetCompareUrl failed: %08x\n", hres);
436 437
}

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
static const struct {
    LPCWSTR url;
    DWORD uses_net;
} query_info_tests[] = {
    {url1, 0},
    {url2, 0},
    {url3, 0},
    {url4, 0},
    {url5, 0},
    {url6, 0},
    {url7, 0},
    {url8, 0}
};

static void test_CoInternetQueryInfo(void)
{
    BYTE buf[100];
    DWORD cb, i;
    HRESULT hres;

    for(i=0; i < sizeof(query_info_tests)/sizeof(query_info_tests[0]); i++) {
        cb = 0xdeadbeef;
        memset(buf, '?', sizeof(buf));
461
        hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), &cb, 0);
462 463 464 465 466
        ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
        ok(cb == sizeof(DWORD), "[%d] cb = %d\n", i, cb);
        ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
           i, *(DWORD*)buf, query_info_tests[i].uses_net);

467
        hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, 3, &cb, 0);
468
        ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);
469
        hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, NULL, sizeof(buf), &cb, 0);
470 471 472
        ok(hres == E_FAIL, "[%d] CoInternetQueryInfo failed: %08x, expected E_FAIL\n", i, hres);

        memset(buf, '?', sizeof(buf));
473
        hres = pCoInternetQueryInfo(query_info_tests[0].url, QUERY_USES_NETWORK, 0, buf, sizeof(buf), NULL, 0);
474 475 476 477 478 479
        ok(hres == S_OK, "[%d] CoInternetQueryInfo failed: %08x\n", i, hres);
        ok(*(DWORD*)buf == query_info_tests[i].uses_net, "[%d] ret %x, expected %x\n",
           i, *(DWORD*)buf, query_info_tests[i].uses_net);
    }
}

480
static const struct {
481
    const char *url;
482
    const char *mime;
483
    HRESULT hres;
484 485
    BOOL broken_failure;
    const char *broken_mime;
486
} mime_tests[] = {
487 488 489
    {"res://mshtml.dll/blank.htm", "text/html", S_OK},
    {"index.htm", "text/html", S_OK},
    {"file://c:\\Index.htm", "text/html", S_OK},
490 491 492
    {"file://c:\\Index.htm?q=test", "text/html", S_OK, TRUE},
    {"file://c:\\Index.htm#hash_part", "text/html", S_OK, TRUE},
    {"file://c:\\Index.htm#hash_part.txt", "text/html", S_OK, FALSE, "text/plain"},
493 494 495 496
    {"file://some%20file%2ejpg", NULL, E_FAIL},
    {"http://www.winehq.org", NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)},
    {"about:blank", NULL, E_FAIL},
    {"ftp://winehq.org/file.test", NULL, __HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)}
497 498 499 500 501 502 503 504
};

static BYTE data1[] = "test data\n";
static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
static BYTE data3[] = {0,0,0};
static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
505 506 507 508 509 510 511 512
static BYTE data7[] = "<html>blahblah";
static BYTE data8[] = {'t','e','s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
static BYTE data9[] = {'t','e',0,'s',0xfa,'t',' ','<','h','t','m','l','>','d','a','t','a','\n',0,0};
static BYTE data10[] = "<HtmL>blahblah";
static BYTE data11[] = "blah<HTML>blahblah";
static BYTE data12[] = "blah<HTMLblahblah";
static BYTE data13[] = "blahHTML>blahblah";
static BYTE data14[] = "blah<HTMblahblah";
513 514 515 516
static BYTE data15[] = {0xff,0xd8};
static BYTE data16[] = {0xff,0xd8,'h'};
static BYTE data17[] = {0,0xff,0xd8};
static BYTE data18[] = {0xff,0xd8,'<','h','t','m','l','>'};
517 518 519 520 521 522 523 524 525
static BYTE data19[] = {'G','I','F','8','7','a'};
static BYTE data20[] = {'G','I','F','8','9','a'};
static BYTE data21[] = {'G','I','F','8','7'};
static BYTE data22[] = {'G','i','F','8','7','a'};
static BYTE data23[] = {'G','i','F','8','8','a'};
static BYTE data24[] = {'g','i','f','8','7','a'};
static BYTE data25[] = {'G','i','F','8','7','A'};
static BYTE data26[] = {'G','i','F','8','7','a','<','h','t','m','l','>'};
static BYTE data27[] = {0x30,'G','i','F','8','7','A'};
526 527 528 529 530 531
static BYTE data28[] = {0x42,0x4d,0x6e,0x42,0x1c,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00};
static BYTE data29[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x','x'};
static BYTE data30[] = {0x42,0x4d,'x','x','x','x',0x00,0x01,0x00,0x00,'x','x','x','x'};
static BYTE data31[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'<','h','t','m','l','>'};
static BYTE data32[] = {0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
static BYTE data33[] = {0x00,0x42,0x4d,'x','x','x','x',0x00,0x00,0x00,0x00,'x','x','x'};
532 533 534 535 536
static BYTE data34[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
static BYTE data35[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x','x','x','x',0};
static BYTE data36[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,'x','x'};
static BYTE data37[] = {0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'<','h','t','m','l','>'};
static BYTE data38[] = {0x00,0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a,'x'};
537
static BYTE data39[] = {0x4d,0x4d,0x00,0x2a,0xff};
538 539 540 541
static BYTE data40[] = {0x4d,0x4d,0x00,0x2a,'<','h','t','m','l','>',0};
static BYTE data41[] = {0x4d,0x4d,0xff};
static BYTE data42[] = {0x4d,0x4d};
static BYTE data43[] = {0x00,0x4d,0x4d,0x00};
542 543 544 545 546 547
static BYTE data44[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
static BYTE data45[] = {'R','I','F','f',0xff,0xff,0xff,0xff,'A','V','I',0x20,0xff};
static BYTE data46[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20};
static BYTE data47[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x21,0xff};
static BYTE data48[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'A','V','I',0x20,'<','h','t','m','l','>'};
static BYTE data49[] = {'R','I','F','F',0x0f,0x0f,0xf0,0xf0,'A','V','I',0x20,0xf0,0x00};
548 549 550 551 552
static BYTE data50[] = {0x00,0x00,0x01,0xb3,0xff};
static BYTE data51[] = {0x00,0x00,0x01,0xba,0xff};
static BYTE data52[] = {0x00,0x00,0x01,0xb8,0xff};
static BYTE data53[] = {0x00,0x00,0x01,0xba};
static BYTE data54[] = {0x00,0x00,0x01,0xba,'<','h','t','m','l','>'};
553 554 555 556
static BYTE data55[] = {0x1f,0x8b,'x'};
static BYTE data56[] = {0x1f};
static BYTE data57[] = {0x1f,0x8b,'<','h','t','m','l','>','t','e','s','t',0};
static BYTE data58[] = {0x1f,0x8b};
557 558 559
static BYTE data59[] = {0x50,0x4b,'x'};
static BYTE data60[] = {0x50,0x4b};
static BYTE data61[] = {0x50,0x4b,'<','h','t','m','l','>',0};
560 561 562
static BYTE data62[] = {0xca,0xfe,0xba,0xbe,'x'};
static BYTE data63[] = {0xca,0xfe,0xba,0xbe};
static BYTE data64[] = {0xca,0xfe,0xba,0xbe,'<','h','t','m','l','>',0};
563 564 565
static BYTE data65[] = {0x25,0x50,0x44,0x46,'x'};
static BYTE data66[] = {0x25,0x50,0x44,0x46};
static BYTE data67[] = {0x25,0x50,0x44,0x46,'x','<','h','t','m','l','>'};
566 567 568
static BYTE data68[] = {'M','Z','x'};
static BYTE data69[] = {'M','Z'};
static BYTE data70[] = {'M','Z','<','h','t','m','l','>',0xff};
569 570 571 572
static BYTE data71[] = {'{','\\','r','t','f',0};
static BYTE data72[] = {'{','\\','r','t','f'};
static BYTE data73[] = {' ','{','\\','r','t','f',' '};
static BYTE data74[] = {'{','\\','r','t','f','<','h','t','m','l','>',' '};
573 574 575 576
static BYTE data75[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E',0xff};
static BYTE data76[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V','E'};
static BYTE data77[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'W','A','V',0xff,0xff};
static BYTE data78[] = {'R','I','F','F',0xff,0xff,0xff,0xff,'<','h','t','m','l','>',0xff};
577 578 579
static BYTE data79[] = {'%','!',0xff};
static BYTE data80[] = {'%','!'};
static BYTE data81[] = {'%','!','P','S','<','h','t','m','l','>'};
580 581 582 583
static BYTE data82[] = {'.','s','n','d',0};
static BYTE data83[] = {'.','s','n','d'};
static BYTE data84[] = {'.','s','n','d',0,'<','h','t','m','l','>',1,1};
static BYTE data85[] = {'.','S','N','D',0};
584
static BYTE data86[] = {0x49,0x49,0x2a,0xff};
585 586 587
static BYTE data87[] = {' ','<','h','e','a','d'};
static BYTE data88[] = {' ','<','h','e','a','d','>'};
static BYTE data89[] = {'\t','\r','<','h','e','a','d','>'};
588
static BYTE data90[] = {'<','H','e','A','d',' '};
589 590 591 592 593 594
static BYTE data91[] = {'<','?','x','m','l',' ',0};
static BYTE data92[] = {'a','b','c','<','?','x','m','l',' ',' '};
static BYTE data93[] = {'<','?','x','m','l',' ',' ','<','h','t','m','l','>'};
static BYTE data94[] = {'<','h','t','m','l','>','<','?','x','m','l',' ',' '};
static BYTE data95[] = {'{','\\','r','t','f','<','?','x','m','l',' ',' '};
static BYTE data96[] = {'<','?','x','m','l',' '};
595 596
static BYTE data97[] = "<body";
static BYTE data98[] = "blah<BoDyblahblah";
597 598 599 600

static const struct {
    BYTE *data;
    DWORD size;
601 602 603
    const char *mime;
    const char *mime_pjpeg;
    const char *broken_mime;
604 605
    const char *url;
    const char *proposed_mime;
606
} mime_tests2[] = {
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
    {data1, sizeof(data1), "text/plain"},
    {data2, sizeof(data2), "application/octet-stream", "image/pjpeg"},
    {data3, sizeof(data3), "application/octet-stream", "image/pjpeg"},
    {data4, sizeof(data4), "application/octet-stream", "image/pjpeg"},
    {data5, sizeof(data5), "text/plain"},
    {data6, sizeof(data6), "text/plain"},
    {data7, sizeof(data7), "text/html", "text/plain"},
    {data8, sizeof(data8), "text/html", "text/plain"},
    {data9, sizeof(data9), "text/html", "image/pjpeg"},
    {data10, sizeof(data10), "text/html", "text/plain"},
    {data11, sizeof(data11), "text/html", "text/plain"},
    {data12, sizeof(data12), "text/html", "text/plain"},
    {data13, sizeof(data13), "text/plain"},
    {data14, sizeof(data14), "text/plain"},
    {data15, sizeof(data15), "text/plain"},
    {data16, sizeof(data16), "image/pjpeg"},
    {data17, sizeof(data17), "application/octet-stream", "image/pjpeg"},
    {data18, sizeof(data18), "text/html", "image/pjpeg"},
    {data19, sizeof(data19), "image/gif"},
    {data20, sizeof(data20), "image/gif"},
    {data21, sizeof(data21), "text/plain"},
    {data22, sizeof(data22), "image/gif"},
    {data23, sizeof(data23), "text/plain"},
    {data24, sizeof(data24), "image/gif"},
    {data25, sizeof(data25), "image/gif"},
    {data26, sizeof(data26), "text/html", "image/gif"},
    {data27, sizeof(data27), "text/plain"},
    {data28, sizeof(data28), "image/bmp"},
    {data29, sizeof(data29), "image/bmp"},
    {data30, sizeof(data30), "application/octet-stream", "image/pjpeg"},
    {data31, sizeof(data31), "text/html", "image/bmp"},
    {data32, sizeof(data32), "application/octet-stream", "image/pjpeg"},
    {data33, sizeof(data33), "application/octet-stream", "image/pjpeg"},
    {data34, sizeof(data34), "image/x-png"},
    {data35, sizeof(data35), "image/x-png"},
    {data36, sizeof(data36), "application/octet-stream", "image/pjpeg"},
    {data37, sizeof(data37), "text/html", "image/x-png"},
    {data38, sizeof(data38), "application/octet-stream", "image/pjpeg"},
    {data39, sizeof(data39), "image/tiff"},
    {data40, sizeof(data40), "text/html", "image/tiff"},
    {data41, sizeof(data41), "text/plain", NULL, "image/tiff"},
    {data42, sizeof(data42), "text/plain"},
    {data43, sizeof(data43), "application/octet-stream", "image/pjpeg"},
    {data44, sizeof(data44), "video/avi"},
    {data45, sizeof(data45), "text/plain"},
    {data46, sizeof(data46), "text/plain"},
    {data47, sizeof(data47), "text/plain"},
    {data48, sizeof(data48), "text/html", "video/avi"},
    {data49, sizeof(data49), "video/avi"},
    {data50, sizeof(data50), "video/mpeg"},
    {data51, sizeof(data51), "video/mpeg"},
    {data52, sizeof(data52), "application/octet-stream", "image/pjpeg"},
659
    {data53, sizeof(data53), "application/octet-stream", "image/pjpeg", "image/x-icon"},
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
    {data54, sizeof(data54), "text/html", "video/mpeg"},
    {data55, sizeof(data55), "application/x-gzip-compressed"},
    {data56, sizeof(data56), "text/plain"},
    {data57, sizeof(data57), "text/html", "application/x-gzip-compressed"},
    {data58, sizeof(data58), "application/octet-stream", "image/pjpeg"},
    {data59, sizeof(data59), "application/x-zip-compressed"},
    {data60, sizeof(data60), "text/plain"},
    {data61, sizeof(data61), "text/html", "application/x-zip-compressed"},
    {data62, sizeof(data62), "application/java"},
    {data63, sizeof(data63), "text/plain"},
    {data64, sizeof(data64), "text/html", "application/java"},
    {data65, sizeof(data65), "application/pdf"},
    {data66, sizeof(data66), "text/plain"},
    {data67, sizeof(data67), "text/html", "application/pdf"},
    {data68, sizeof(data68), "application/x-msdownload"},
    {data69, sizeof(data69), "text/plain"},
    {data70, sizeof(data70), "text/html", "application/x-msdownload"},
    {data71, sizeof(data71), "text/richtext"},
    {data72, sizeof(data72), "text/plain"},
    {data73, sizeof(data73), "text/plain"},
    {data74, sizeof(data74), "text/html", "text/richtext"},
    {data75, sizeof(data75), "audio/wav"},
    {data76, sizeof(data76), "text/plain"},
    {data77, sizeof(data77), "text/plain"},
    {data78, sizeof(data78), "text/html", "text/plain"},
    {data79, sizeof(data79), "application/postscript"},
    {data80, sizeof(data80), "text/plain"},
    {data81, sizeof(data81), "text/html", "application/postscript"},
    {data82, sizeof(data82), "audio/basic"},
    {data83, sizeof(data83), "text/plain"},
    {data84, sizeof(data84), "text/html", "audio/basic"},
    {data85, sizeof(data85), "text/plain"},
    {data86, sizeof(data86), "image/tiff", NULL, "text/plain"},
    {data87, sizeof(data87), "text/plain"},
    {data88, sizeof(data88), "text/html", "text/plain"},
    {data89, sizeof(data89), "text/html", "text/plain"},
    {data90, sizeof(data90), "text/html", "text/plain"},
    {data91, sizeof(data91), "text/xml", "text/plain"},
    {data92, sizeof(data92), "text/xml", "text/plain"},
    {data93, sizeof(data93), "text/xml", "text/plain"},
    {data94, sizeof(data94), "text/html", "text/plain"},
    {data95, sizeof(data95), "text/xml", "text/richtext"},
702
    {data96, sizeof(data96), "text/plain"},
703 704
    {data97, sizeof(data97), "text/html", "text/plain"},
    {data98, sizeof(data98), "text/html", "text/plain"},
705 706 707 708 709
    {data1, sizeof(data1), "text/plain", NULL, NULL, "res://mshtml.dll/blank.htm"},
    {NULL, 0, "text/html", NULL, NULL, "res://mshtml.dll/blank.htm"},
    {data1, sizeof(data1), "text/plain", NULL, NULL, "res://mshtml.dll/blank.htm", "application/octet-stream"},
    {data1, sizeof(data1), "text/plain", NULL, NULL, "file:some%20file%2ejpg", "application/octet-stream"},
    {NULL, sizeof(data1), "text/html", NULL, NULL, "res://mshtml.dll/blank.htm"},
710 711 712 713 714 715
    {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css"},
    {data2, sizeof(data2), "text/css", NULL, NULL, "http://www.winehq.org/test.css"},
    {data10, sizeof(data10), "text/html", NULL, NULL, "http://www.winehq.org/test.css"},
    {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css", "text/plain"},
    {data1, sizeof(data1), "text/css", NULL, NULL, "http://www.winehq.org/test.css", "application/octet-stream"},
    {data1, sizeof(data1), "text/test", NULL, NULL, "http://www.winehq.org/test.css", "text/test"}
716 717 718 719
};

static void test_FindMimeFromData(void)
{
720
    WCHAR *mime, *proposed_mime, *url;
721
    HRESULT hres;
722
    BYTE b;
723 724
    int i;

725 726 727 728 729 730
    static const WCHAR app_octet_streamW[] =
        {'a','p','p','l','i','c','a','t','i','o','n','/','o','c','t','e','t','-','s','t','r','e','a','m',0};
    static const WCHAR image_pjpegW[] = {'i','m','a','g','e','/','p','j','p','e','g',0};
    static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
    static const WCHAR text_plainW[] = {'t','e','x','t','/','p','l','a','i','n',0};

731 732
    for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
        mime = (LPWSTR)0xf0f0f0f0;
733 734
        url = a2w(mime_tests[i].url);
        hres = pFindMimeFromData(NULL, url, NULL, 0, NULL, 0, &mime, 0);
735
        if(mime_tests[i].mime) {
736 737 738 739 740 741 742
            ok(hres == S_OK || broken(mime_tests[i].broken_failure), "[%d] FindMimeFromData failed: %08x\n", i, hres);
            if(hres == S_OK) {
                ok(!strcmp_wa(mime, mime_tests[i].mime)
                   || broken(mime_tests[i].broken_mime && !strcmp_wa(mime, mime_tests[i].broken_mime)),
                   "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
                CoTaskMemFree(mime);
            }
743
        }else {
744 745 746
            ok(hres == E_FAIL || hres == mime_tests[i].hres,
               "[%d] FindMimeFromData failed: %08x, expected %08x\n",
               i, hres, mime_tests[i].hres);
747 748 749 750
            ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
        }

        mime = (LPWSTR)0xf0f0f0f0;
751
        hres = pFindMimeFromData(NULL, url, NULL, 0, text_plainW, 0, &mime, 0);
752
        ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
753
        ok(!strcmp_wa(mime, "text/plain"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
754 755 756
        CoTaskMemFree(mime);

        mime = (LPWSTR)0xf0f0f0f0;
757
        hres = pFindMimeFromData(NULL, url, NULL, 0, app_octet_streamW, 0, &mime, 0);
758
        ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
759
        ok(!strcmp_wa(mime, "application/octet-stream"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
760
        CoTaskMemFree(mime);
761
        heap_free(url);
762 763 764
    }

    for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
765 766 767 768
        url = a2w(mime_tests2[i].url);
        proposed_mime = a2w(mime_tests2[i].proposed_mime);
        hres = pFindMimeFromData(NULL, url, mime_tests2[i].data, mime_tests2[i].size,
                proposed_mime, 0, &mime, 0);
769
        ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
770 771
        b = !strcmp_wa(mime, mime_tests2[i].mime);
        ok(b || broken(mime_tests2[i].broken_mime && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
772
            "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
773 774
        heap_free(proposed_mime);
        heap_free(url);
775
        CoTaskMemFree(mime);
776
        if(!b || url || proposed_mime)
777
            continue;
778

779
        hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
780
                app_octet_streamW, 0, &mime, 0);
781
        ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
782 783
        ok(!strcmp_wa(mime, mime_tests2[i].mime) || broken(mime_tests2[i].broken_mime
                        && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
784 785 786 787
                    "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
        CoTaskMemFree(mime);

        hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
788
                text_plainW, 0, &mime, 0);
789
        ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
790 791
        ok(!strcmp_wa(mime, mime_tests2[i].mime) || broken(mime_tests2[i].broken_mime
                    && !strcmp_wa(mime, mime_tests2[i].broken_mime)),
792 793 794
                "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
        CoTaskMemFree(mime);

795
        hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
796
                text_htmlW, 0, &mime, 0);
797
        ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
798 799 800
        if(!strcmp("application/octet-stream", mime_tests2[i].mime)
           || !strcmp("text/plain", mime_tests2[i].mime) || i==92)
            ok(!strcmp_wa(mime, "text/html"), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
801
        else
802
            ok(!strcmp_wa(mime, mime_tests2[i].mime), "[%d] wrong mime: %s\n", i, wine_dbgstr_w(mime));
803
        CoTaskMemFree(mime);
804

805
        hres = pFindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
806
                image_pjpegW, 0, &mime, 0);
807
        ok(hres == S_OK, "[%d] FindMimeFromData failed: %08x\n", i, hres);
808 809 810
        ok(!strcmp_wa(mime, mime_tests2[i].mime_pjpeg ? mime_tests2[i].mime_pjpeg : mime_tests2[i].mime)
           || broken(!strcmp_wa(mime, mime_tests2[i].mime)),
           "[%d] wrong mime, got %s\n", i, wine_dbgstr_w(mime));
811 812 813
        CoTaskMemFree(mime);
    }

814
    hres = pFindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
815
    ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
816

817
    hres = pFindMimeFromData(NULL, NULL, NULL, 0, text_plainW, 0, &mime, 0);
818
    ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
819

820
    hres = pFindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
821
    ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
822

823
    hres = pFindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
824
    ok(hres == E_FAIL, "FindMimeFromData failed: %08x, expected E_FAIL\n", hres);
825

826
    hres = pFindMimeFromData(NULL, NULL, data1, 0, text_plainW, 0, &mime, 0);
827
    ok(hres == S_OK, "FindMimeFromData failed: %08x\n", hres);
828
    ok(!strcmp_wa(mime, "text/plain"), "wrong mime: %s\n", wine_dbgstr_w(mime));
829 830
    CoTaskMemFree(mime);

831
    hres = pFindMimeFromData(NULL, NULL, data1, 0, text_plainW, 0, NULL, 0);
832
    ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08x, expected E_INVALIDARG\n", hres);
833 834
}

835 836 837 838 839 840 841 842
static void register_protocols(void)
{
    IInternetSession *session;
    IClassFactory *factory;
    HRESULT hres;

    static const WCHAR wszAbout[] = {'a','b','o','u','t',0};

843
    hres = pCoInternetGetSession(0, &session, 0);
844
    ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
845 846 847 848 849
    if(FAILED(hres))
        return;

    hres = CoGetClassObject(&CLSID_AboutProtocol, CLSCTX_INPROC_SERVER, NULL,
            &IID_IClassFactory, (void**)&factory);
850
    ok(hres == S_OK, "Could not get AboutProtocol factory: %08x\n", hres);
851 852 853 854 855 856 857
    if(FAILED(hres))
        return;

    IInternetSession_RegisterNameSpace(session, factory, &CLSID_AboutProtocol,
                                       wszAbout, 0, NULL, 0);
    IClassFactory_Release(factory);

858
    IInternetSession_Release(session);
859 860
}

861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881
static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
                                                          REFIID riid, void **ppv)
{
    ok(0, "unexpected call\n");
    return E_NOINTERFACE;
}

static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
{
    return 2;
}

static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
{
    return 1;
}

static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
        PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
        DWORD *pcchResult, DWORD dwReserved)
{
882 883 884 885 886 887 888 889 890 891 892 893 894
    CHECK_EXPECT2(ParseUrl);

    if(ParseAction == PARSE_SECURITY_URL) {
        if(pcchResult)
            *pcchResult = sizeof(url1)/sizeof(WCHAR);

        if(cchResult<sizeof(url1)/sizeof(WCHAR))
            return S_FALSE;

        memcpy(pwzResult, url1, sizeof(url1));
        return S_OK;
    }

895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
    return E_NOTIMPL;
}

static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
        LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
        LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
        LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
        LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
        DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
    InternetProtocolInfo_QueryInterface,
    InternetProtocolInfo_AddRef,
    InternetProtocolInfo_Release,
    InternetProtocolInfo_ParseUrl,
    InternetProtocolInfo_CombineUrl,
    InternetProtocolInfo_CompareUrl,
    InternetProtocolInfo_QueryInfo
};

static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };

static HRESULT qiret;
static IClassFactory *expect_cf;

static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
    if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
939
        CHECK_EXPECT2(QI_IInternetProtocolInfo);
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
        ok(iface == expect_cf, "unexpected iface\n");
        *ppv = &protocol_info;
        return qiret;
    }

    ok(0, "unexpected call\n");
    return E_NOINTERFACE;
}

static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
    return 2;
}

static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
    return 1;
}

static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
                                        REFIID riid, void **ppv)
961 962 963 964 965 966 967
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
                                        REFIID riid, void **ppv)
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993
{
    CHECK_EXPECT(CreateInstance);

    ok(iface == expect_cf, "unexpected iface\n");
    ok(pOuter == NULL, "pOuter = %p\n", pOuter);
    ok(IsEqualGUID(&IID_IInternetProtocolInfo, riid), "unexpected riid\n");
    ok(ppv != NULL, "ppv == NULL\n");

    *ppv = &protocol_info;
    return S_OK;
}

static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
{
    ok(0, "unexpected call\n");
    return S_OK;
}

static const IClassFactoryVtbl ClassFactoryVtbl = {
    ClassFactory_QueryInterface,
    ClassFactory_AddRef,
    ClassFactory_Release,
    ClassFactory_CreateInstance,
    ClassFactory_LockServer
};

994 995 996 997 998 999 1000 1001 1002 1003 1004
static const IClassFactoryVtbl ProtocolCFVtbl = {
    ClassFactory_QueryInterface,
    ClassFactory_AddRef,
    ClassFactory_Release,
    ProtocolCF_CreateInstance,
    ClassFactory_LockServer
};

static IClassFactory test_protocol_cf = { &ProtocolCFVtbl };
static IClassFactory test_protocol_cf2 = { &ProtocolCFVtbl };
static IClassFactory test_cf = { &ClassFactoryVtbl };
1005 1006 1007 1008 1009

static void test_NameSpace(void)
{
    IInternetSession *session;
    WCHAR buf[200];
1010
    LPWSTR sec_url;
1011 1012 1013 1014 1015
    DWORD size;
    HRESULT hres;

    static const WCHAR wszTest[] = {'t','e','s','t',0};

1016
    hres = pCoInternetGetSession(0, &session, 0);
1017
    ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1018 1019 1020 1021 1022
    if(FAILED(hres))
        return;

    hres = IInternetSession_RegisterNameSpace(session, NULL, &IID_NULL,
                                              wszTest, 0, NULL, 0);
1023
    ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
1024 1025 1026

    hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
                                              NULL, 0, NULL, 0);
1027
    ok(hres == E_INVALIDARG, "RegisterNameSpace failed: %08x\n", hres);
1028 1029 1030

    hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
                                              wszTest, 0, NULL, 0);
1031
    ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1032 1033 1034 1035 1036 1037 1038

    qiret = E_NOINTERFACE;
    expect_cf = &test_protocol_cf;
    SET_EXPECT(QI_IInternetProtocolInfo);
    SET_EXPECT(CreateInstance);
    SET_EXPECT(ParseUrl);

1039
    hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1040
                              &size, 0);
1041
    ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1042 1043 1044 1045 1046 1047 1048 1049 1050

    CHECK_CALLED(QI_IInternetProtocolInfo);
    CHECK_CALLED(CreateInstance);
    CHECK_CALLED(ParseUrl);

    qiret = S_OK;
    SET_EXPECT(QI_IInternetProtocolInfo);
    SET_EXPECT(ParseUrl);

1051
    hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1052
                              &size, 0);
1053
    ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1054 1055 1056 1057

    CHECK_CALLED(QI_IInternetProtocolInfo);
    CHECK_CALLED(ParseUrl);

1058 1059 1060
    SET_EXPECT(QI_IInternetProtocolInfo);
    SET_EXPECT(ParseUrl);

1061
    hres = pCoInternetParseUrl(url8, PARSE_SECURITY_URL, 0, buf,
1062 1063
            sizeof(buf)/sizeof(WCHAR), &size, 0);
    ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1064
    ok(size == sizeof(url1)/sizeof(WCHAR), "Size = %d\n", size);
1065 1066 1067 1068 1069 1070 1071 1072 1073
    if(size == sizeof(url1)/sizeof(WCHAR))
        ok(!memcmp(buf, url1, sizeof(url1)), "Encoded url = %s\n", wine_dbgstr_w(buf));

    CHECK_CALLED(QI_IInternetProtocolInfo);
    CHECK_CALLED(ParseUrl);

    SET_EXPECT(QI_IInternetProtocolInfo);
    SET_EXPECT(ParseUrl);

1074 1075 1076 1077 1078 1079 1080 1081 1082
    if (pCoInternetGetSecurityUrl) {
        hres = pCoInternetGetSecurityUrl(url8, &sec_url, PSU_SECURITY_URL_ONLY, 0);
        ok(hres == S_OK, "CoInternetGetSecurityUrl failed: %08x\n", hres);
        if(hres == S_OK) {
            ok(lstrlenW(sec_url)>sizeof(wszFile)/sizeof(WCHAR) &&
                    !memcmp(sec_url, wszFile, sizeof(wszFile)-sizeof(WCHAR)),
                    "Encoded url = %s\n", wine_dbgstr_w(sec_url));
            CoTaskMemFree(sec_url);
        }
1083

1084 1085 1086
        CHECK_CALLED(QI_IInternetProtocolInfo);
        CHECK_CALLED(ParseUrl);
    }
1087

1088
    hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1089
    ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1090

1091
    hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1092
                              &size, 0);
1093
    ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1094 1095 1096

    hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf2, &IID_NULL,
                                              wszTest, 0, NULL, 0);
1097
    ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1098 1099 1100

    hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
                                              wszTest, 0, NULL, 0);
1101
    ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1102 1103 1104

    hres = IInternetSession_RegisterNameSpace(session, &test_protocol_cf, &IID_NULL,
                                              wszTest, 0, NULL, 0);
1105
    ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1106 1107 1108 1109

    SET_EXPECT(QI_IInternetProtocolInfo);
    SET_EXPECT(ParseUrl);

1110
    hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1111
                              &size, 0);
1112
    ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1113 1114 1115 1116 1117

    CHECK_CALLED(QI_IInternetProtocolInfo);
    CHECK_CALLED(ParseUrl);

    hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1118
    ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1119 1120 1121 1122

    SET_EXPECT(QI_IInternetProtocolInfo);
    SET_EXPECT(ParseUrl);

1123
    hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1124
                              &size, 0);
1125
    ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1126 1127 1128 1129 1130

    CHECK_CALLED(QI_IInternetProtocolInfo);
    CHECK_CALLED(ParseUrl);

    hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1131
    ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1132 1133 1134 1135 1136

    expect_cf = &test_protocol_cf2;
    SET_EXPECT(QI_IInternetProtocolInfo);
    SET_EXPECT(ParseUrl);

1137
    hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1138
                              &size, 0);
1139
    ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1140 1141 1142 1143 1144

    CHECK_CALLED(QI_IInternetProtocolInfo);
    CHECK_CALLED(ParseUrl);

    hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1145
    ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1146
    hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, wszTest);
1147
    ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1148
    hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf, NULL);
1149
    ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1150
    hres = IInternetSession_UnregisterNameSpace(session, NULL, wszTest);
1151
    ok(hres == E_INVALIDARG, "UnregisterNameSpace failed: %08x\n", hres);
1152 1153

    hres = IInternetSession_UnregisterNameSpace(session, &test_protocol_cf2, wszTest);
1154
    ok(hres == S_OK, "UnregisterNameSpace failed: %08x\n", hres);
1155

1156
    hres = pCoInternetParseUrl(url8, PARSE_ENCODE, 0, buf, sizeof(buf)/sizeof(WCHAR),
1157
                              &size, 0);
1158
    ok(hres == S_OK, "CoInternetParseUrl failed: %08x\n", hres);
1159 1160 1161 1162

    IInternetSession_Release(session);
}

1163 1164 1165 1166 1167 1168 1169
static void test_MimeFilter(void)
{
    IInternetSession *session;
    HRESULT hres;

    static const WCHAR mimeW[] = {'t','e','s','t','/','m','i','m','e',0};

1170
    hres = pCoInternetGetSession(0, &session, 0);
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
    ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
    if(FAILED(hres))
        return;

    hres = IInternetSession_RegisterMimeFilter(session, &test_cf, &IID_NULL, mimeW);
    ok(hres == S_OK, "RegisterMimeFilter failed: %08x\n", hres);

    hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
    ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);

    hres = IInternetSession_UnregisterMimeFilter(session, &test_cf, mimeW);
    ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);

    hres = IInternetSession_UnregisterMimeFilter(session, (void*)0xdeadbeef, mimeW);
    ok(hres == S_OK, "UnregisterMimeFilter failed: %08x\n", hres);

    IInternetSession_Release(session);
}

1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
static ULONG WINAPI unk_Release(IUnknown *iface)
{
    CHECK_EXPECT(unk_Release);
    return 0;
}

static const IUnknownVtbl unk_vtbl = {
    (void*)0xdeadbeef,
    (void*)0xdeadbeef,
    unk_Release
};

static void test_ReleaseBindInfo(void)
{
    BINDINFO bi;
    IUnknown unk = { &unk_vtbl };

1207
    pReleaseBindInfo(NULL); /* shouldn't crash */
1208 1209 1210 1211 1212

    memset(&bi, 0, sizeof(bi));
    bi.cbSize = sizeof(BINDINFO);
    bi.pUnk = &unk;
    SET_EXPECT(unk_Release);
1213
    pReleaseBindInfo(&bi);
1214
    ok(bi.cbSize == sizeof(BINDINFO), "bi.cbSize=%d\n", bi.cbSize);
1215 1216 1217 1218 1219 1220
    ok(bi.pUnk == NULL, "bi.pUnk=%p, expected NULL\n", bi.pUnk);
    CHECK_CALLED(unk_Release);

    memset(&bi, 0, sizeof(bi));
    bi.cbSize = offsetof(BINDINFO, pUnk);
    bi.pUnk = &unk;
1221
    pReleaseBindInfo(&bi);
1222
    ok(bi.cbSize == offsetof(BINDINFO, pUnk), "bi.cbSize=%d\n", bi.cbSize);
1223 1224 1225 1226
    ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);

    memset(&bi, 0, sizeof(bi));
    bi.pUnk = &unk;
1227
    pReleaseBindInfo(&bi);
1228
    ok(!bi.cbSize, "bi.cbSize=%d, expected 0\n", bi.cbSize);
1229 1230 1231
    ok(bi.pUnk == &unk, "bi.pUnk=%p, expected %p\n", bi.pUnk, &unk);
}

1232 1233 1234
static void test_CopyStgMedium(void)
{
    STGMEDIUM src, dst;
1235 1236
    HGLOBAL empty, hg;
    char *ptr1, *ptr2;
1237
    HRESULT hres;
1238
    int size;
1239

1240 1241
    static WCHAR fileW[] = {'f','i','l','e',0};

1242 1243
    memset(&src, 0xf0, sizeof(src));
    memset(&dst, 0xe0, sizeof(dst));
1244
    memset(&empty, 0xf0, sizeof(empty));
1245 1246
    src.tymed = TYMED_NULL;
    src.pUnkForRelease = NULL;
1247
    hres = pCopyStgMedium(&src, &dst);
1248 1249
    ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
    ok(dst.tymed == TYMED_NULL, "tymed=%d\n", dst.tymed);
1250
    ok(dst.u.hGlobal == empty, "u=%p\n", dst.u.hGlobal);
1251 1252 1253 1254 1255 1256
    ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);

    memset(&dst, 0xe0, sizeof(dst));
    src.tymed = TYMED_ISTREAM;
    src.u.pstm = NULL;
    src.pUnkForRelease = NULL;
1257
    hres = pCopyStgMedium(&src, &dst);
1258 1259 1260 1261 1262
    ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
    ok(dst.tymed == TYMED_ISTREAM, "tymed=%d\n", dst.tymed);
    ok(!dst.u.pstm, "pstm=%p\n", dst.u.pstm);
    ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);

1263 1264 1265 1266
    memset(&dst, 0xe0, sizeof(dst));
    src.tymed = TYMED_FILE;
    src.u.lpszFileName = fileW;
    src.pUnkForRelease = NULL;
1267
    hres = pCopyStgMedium(&src, &dst);
1268 1269 1270 1271 1272
    ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
    ok(dst.tymed == TYMED_FILE, "tymed=%d\n", dst.tymed);
    ok(dst.u.lpszFileName && dst.u.lpszFileName != fileW, "lpszFileName=%p\n", dst.u.lpszFileName);
    ok(!lstrcmpW(dst.u.lpszFileName, fileW), "wrong file name\n");
    ok(!dst.pUnkForRelease, "pUnkForRelease=%p, expected NULL\n", dst.pUnkForRelease);
1273
    ReleaseStgMedium(&dst);
1274

1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
    /* TYMED_HGLOBAL */
    hg = GlobalAlloc(GMEM_MOVEABLE, 10);
    ptr1 = GlobalLock(hg);
    memset(ptr1, 0xfa, 10);
    memset(&dst, 0xe0, sizeof(dst));
    src.tymed = TYMED_HGLOBAL;
    src.u.hGlobal = hg;
    hres = pCopyStgMedium(&src, &dst);
    ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
    ok(dst.tymed == TYMED_HGLOBAL, "tymed=%d\n", dst.tymed);
    ok(dst.u.hGlobal != hg, "got %p, %p\n", dst.u.hGlobal, hg);
    size = GlobalSize(dst.u.hGlobal);
    ok(size == 10, "got size %d\n", size);
    /* compare contents */
    ptr2 = GlobalLock(dst.u.hGlobal);
    ok(!memcmp(ptr1, ptr2, 10), "got wrong data\n");
    GlobalUnlock(ptr2);
    GlobalUnlock(ptr1);
    ok(GlobalFlags(dst.u.hGlobal) == 0, "got 0x%08x\n", GlobalFlags(dst.u.hGlobal));
    GlobalFree(hg);
    ReleaseStgMedium(&dst);

    memset(&dst, 0xe0, sizeof(dst));
    src.tymed = TYMED_HGLOBAL;
    src.u.hGlobal = NULL;
    hres = pCopyStgMedium(&src, &dst);
    ok(hres == S_OK, "CopyStgMedium failed: %08x\n", hres);
    ok(dst.u.hGlobal == NULL, "got %p\n", dst.u.hGlobal);

1304
    hres = pCopyStgMedium(&src, NULL);
1305
    ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
1306
    hres = pCopyStgMedium(NULL, &dst);
1307 1308 1309
    ok(hres == E_POINTER, "CopyStgMedium failed: %08x, expected E_POINTER\n", hres);
}

1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
static void test_CopyBindInfo(void)
{
    BINDINFO src[2], dest[2];
    SECURITY_DESCRIPTOR sec_desc;
    HRESULT hres;
    int i;

    hres = pCopyBindInfo(NULL, NULL);
    ok(hres == E_POINTER, "CopyBindInfo returned %08x, expected E_POINTER\n", hres);

    memset(src, 0, sizeof(BINDINFO[2]));
    memset(dest, 0xde, sizeof(BINDINFO[2]));
    hres = pCopyBindInfo(src, dest);
Andrey Gusev's avatar
Andrey Gusev committed
1323
    ok(hres == E_INVALIDARG, "CopyBindInfo returned: %08x, expected E_INVALIDARG\n", hres);
1324 1325 1326 1327 1328 1329

    memset(src, 0, sizeof(BINDINFO[2]));
    memset(dest, 0xde, sizeof(BINDINFO[2]));
    src[0].cbSize = sizeof(BINDINFO);
    dest[0].cbSize = 0;
    hres = pCopyBindInfo(src, dest);
Andrey Gusev's avatar
Andrey Gusev committed
1330
    ok(hres == E_INVALIDARG, "CopyBindInfo returned: %08x, expected E_INVALIDARG\n", hres);
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420

    memset(src, 0, sizeof(BINDINFO[2]));
    memset(dest, 0xde, sizeof(BINDINFO[2]));
    src[0].cbSize = 1;
    dest[0].cbSize = sizeof(BINDINFO)+sizeof(DWORD);
    hres = pCopyBindInfo(src, dest);
    ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
    ok(dest[0].cbSize == sizeof(BINDINFO)+sizeof(DWORD), "incorrect cbSize: %d\n", dest[0].cbSize);
    for(i=1; i<dest[0].cbSize/sizeof(int); i++)
        ok(((int*)dest)[i] == 0, "unset values should be set to 0, got %d on %d\n", ((int*)dest)[i], i);

    memset(src, 0, sizeof(BINDINFO[2]));
    memset(dest, 0xde, sizeof(BINDINFO[2]));
    src[0].cbSize = sizeof(BINDINFO)+2*sizeof(DWORD);
    dest[0].cbSize = sizeof(BINDINFO)+sizeof(DWORD);
    hres = pCopyBindInfo(src, dest);
    ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
    ok(dest[1].cbSize == src[1].cbSize, "additional data should be copied\n");
    ok(dest[1].szExtraInfo != src[1].szExtraInfo,
            "data not fitting in destination buffer should not be copied\n");

    memset(src, 0xf0, sizeof(BINDINFO[2]));
    memset(dest, 0xde, sizeof(BINDINFO[2]));
    src[0].cbSize = sizeof(BINDINFO);
    src[0].szExtraInfo = CoTaskMemAlloc(sizeof(WCHAR));
    src[0].szExtraInfo[0] = 0;
    src[0].szCustomVerb = NULL;
    src[0].pUnk = NULL;
    src[0].stgmedData.tymed = TYMED_NULL;
    src[0].stgmedData.pUnkForRelease = NULL;
    dest[0].cbSize = sizeof(BINDINFO);
    hres = pCopyBindInfo(src, dest);
    ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);

    ok(dest[0].cbSize == sizeof(BINDINFO), "incorrect cbSize: %d\n", dest[0].cbSize);
    ok(dest[0].szExtraInfo && !dest[0].szExtraInfo[0] && dest[0].szExtraInfo!=src[0].szExtraInfo,
            "incorrect szExtraInfo: (%p!=%p) %d\n", dest[0].szExtraInfo,
            src[0].szExtraInfo, dest[0].szExtraInfo[0]);
    ok(!memcmp(&dest[0].stgmedData, &src[0].stgmedData, sizeof(STGMEDIUM)),
            "incorrect stgmedData value\n");
    ok(src[0].grfBindInfoF == dest[0].grfBindInfoF, "grfBindInfoF = %x, expected %x\n",
            dest[0].grfBindInfoF, src[0].grfBindInfoF);
    ok(src[0].dwBindVerb == dest[0].dwBindVerb, "dwBindVerb = %x, expected %x\n",
            dest[0].dwBindVerb, src[0].dwBindVerb);
    ok(!dest[0].szCustomVerb, "szCustmoVerb != NULL\n");
    ok(src[0].cbstgmedData == dest[0].cbstgmedData, "cbstgmedData = %x, expected %x\n",
            dest[0].cbstgmedData, src[0].cbstgmedData);
    ok(src[0].dwOptions == dest[0].dwOptions, "dwOptions = %x, expected %x\n",
            dest[0].dwOptions, src[0].dwOptions);
    ok(src[0].dwOptionsFlags == dest[0].dwOptionsFlags, "dwOptionsFlags = %x, expected %x\n",
            dest[0].dwOptionsFlags, src[0].dwOptionsFlags);
    ok(src[0].dwCodePage == dest[0].dwCodePage, "dwCodePage = %x, expected %x\n",
            dest[0].dwCodePage, src[0].dwCodePage);
    ok(!dest[0].securityAttributes.nLength,
            "unexpected securityAttributes.nLength value: %d\n",
            dest[0].securityAttributes.nLength);
    ok(!dest[0].securityAttributes.lpSecurityDescriptor,
            "unexpected securityAttributes.lpSecurityDescriptor value: %p\n",
            dest[0].securityAttributes.lpSecurityDescriptor);
    ok(!dest[0].securityAttributes.bInheritHandle,
            "unexpected securityAttributes.bInheritHandle value: %d\n",
            dest[0].securityAttributes.bInheritHandle);
    ok(!memcmp(&dest[0].iid, &src[0].iid, sizeof(IID)),
            "incorrect iid value\n");
    ok(!dest[0].pUnk, "pUnk != NULL\n");
    ok(src[0].dwReserved == dest[0].dwReserved, "dwReserved = %x, expected %x\n",
            dest[0].dwReserved, src[0].dwReserved);

    CoTaskMemFree(src[0].szExtraInfo);
    CoTaskMemFree(dest[0].szExtraInfo);

    src[0].szExtraInfo = NULL;
    src[0].securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
    ok(InitializeSecurityDescriptor(&sec_desc, SECURITY_DESCRIPTOR_REVISION),
            "InitializeSecurityDescriptor failed\n");
    src[0].securityAttributes.lpSecurityDescriptor = (void*)&sec_desc;
    src[0].securityAttributes.bInheritHandle = TRUE;
    hres = pCopyBindInfo(src, dest);
    ok(hres == S_OK, "CopyBindInfo failed: %08x\n", hres);
    ok(!dest[0].securityAttributes.nLength,
            "unexpected securityAttributes.nLength value: %d\n",
            dest[0].securityAttributes.nLength);
    ok(!dest[0].securityAttributes.lpSecurityDescriptor,
            "unexpected securityAttributes.lpSecurityDescriptor value: %p\n",
            dest[0].securityAttributes.lpSecurityDescriptor);
    ok(!dest[0].securityAttributes.bInheritHandle,
            "unexpected securityAttributes.bInheritHandle value: %d\n",
            dest[0].securityAttributes.bInheritHandle);
}

1421 1422 1423 1424 1425 1426
static void test_UrlMkGetSessionOption(void)
{
    DWORD encoding, size;
    HRESULT hres;

    size = encoding = 0xdeadbeef;
1427
    hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1428
                                 sizeof(encoding), &size, 0);
1429
    ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1430
    ok(encoding != 0xdeadbeef, "encoding not changed\n");
1431
    ok(size == sizeof(encoding), "size=%d\n", size);
1432 1433

    size = encoding = 0xdeadbeef;
1434
    hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1435
                                 sizeof(encoding)+1, &size, 0);
1436
    ok(hres == S_OK, "UrlMkGetSessionOption failed: %08x\n", hres);
1437
    ok(encoding != 0xdeadbeef, "encoding not changed\n");
1438
    ok(size == sizeof(encoding), "size=%d\n", size);
1439 1440

    size = encoding = 0xdeadbeef;
1441
    hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1442
                                 sizeof(encoding)-1, &size, 0);
1443 1444 1445
    ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
    ok(size == 0xdeadbeef, "size=%d\n", size);
1446 1447

    size = encoding = 0xdeadbeef;
1448
    hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, NULL,
1449
                                 sizeof(encoding)-1, &size, 0);
1450 1451 1452
    ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
    ok(size == 0xdeadbeef, "size=%d\n", size);
1453 1454

    encoding = 0xdeadbeef;
1455
    hres = pUrlMkGetSessionOption(URLMON_OPTION_URL_ENCODING, &encoding,
1456
                                 sizeof(encoding)-1, NULL, 0);
1457 1458
    ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(encoding == 0xdeadbeef, "encoding = %08x, exepcted 0xdeadbeef\n", encoding);
1459 1460
}

1461
static void test_user_agent(void)
1462 1463
{
    static const CHAR expected[] = "Mozilla/4.0 (compatible; MSIE ";
1464 1465
    static char test_str[] = "test";
    static char test2_str[] = "test\0test";
1466 1467 1468 1469 1470
    static CHAR str[3];
    LPSTR str2 = NULL;
    HRESULT hres;
    DWORD size, saved;

1471
    hres = pObtainUserAgentString(0, NULL, NULL);
1472 1473 1474
    ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);

    size = 100;
1475
    hres = pObtainUserAgentString(0, NULL, &size);
1476 1477 1478 1479
    ok(hres == E_INVALIDARG, "ObtainUserAgentString failed: %08x\n", hres);
    ok(size == 100, "size=%d, expected %d\n", size, 100);

    size = 0;
1480
    hres = pObtainUserAgentString(0, str, &size);
1481 1482 1483 1484 1485
    ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
    ok(size > 0, "size=%d, expected non-zero\n", size);

    size = 2;
    str[0] = 'a';
1486
    hres = pObtainUserAgentString(0, str, &size);
1487 1488 1489 1490 1491
    ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
    ok(size > 0, "size=%d, expected non-zero\n", size);
    ok(str[0] == 'a', "str[0]=%c, expected 'a'\n", str[0]);

    size = 0;
1492
    hres = pObtainUserAgentString(1, str, &size);
1493 1494 1495 1496
    ok(hres == E_OUTOFMEMORY, "ObtainUserAgentString failed: %08x\n", hres);
    ok(size > 0, "size=%d, expected non-zero\n", size);

    str2 = HeapAlloc(GetProcessHeap(), 0, (size+20)*sizeof(CHAR));
1497
    saved = size;
1498
    hres = pObtainUserAgentString(0, str2, &size);
1499 1500 1501 1502 1503 1504 1505 1506
    ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
    ok(size == saved, "size=%d, expected %d\n", size, saved);
    ok(strlen(expected) <= strlen(str2) &&
       !memcmp(expected, str2, strlen(expected)*sizeof(CHAR)),
       "user agent was \"%s\", expected to start with \"%s\"\n",
       str2, expected);

    size = saved+10;
1507
    hres = pObtainUserAgentString(0, str2, &size);
1508 1509
    ok(hres == S_OK, "ObtainUserAgentString failed: %08x\n", hres);
    ok(size == saved, "size=%d, expected %d\n", size, saved);
1510 1511

    size = 0;
1512
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, NULL, 0, &size, 0);
1513 1514 1515 1516
    ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(size, "size == 0\n");

    size = 0xdeadbeef;
1517
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, NULL, 1000, &size, 0);
1518 1519 1520 1521 1522
    ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(size, "size == 0\n");

    saved = size;
    size = 0;
1523
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved+10, &size, 0);
1524 1525 1526 1527 1528 1529 1530 1531
    ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(size == saved, "size = %d, expected %d\n", size, saved);
    ok(sizeof(expected) <= strlen(str2) && !memcmp(expected, str2, sizeof(expected)-1),
       "user agent was \"%s\", expected to start with \"%s\"\n",
       str2, expected);

    size = 0;
    str2[0] = 0;
1532
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1533 1534 1535 1536 1537 1538 1539 1540
    ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(size == saved, "size = %d, expected %d\n", size, saved);
    ok(sizeof(expected) <= strlen(str2) && !memcmp(expected, str2, sizeof(expected)-1),
       "user agent was \"%s\", expected to start with \"%s\"\n",
       str2, expected);

    size = saved;
    str2[0] = 0;
1541
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved-1, &size, 0);
1542 1543 1544 1545 1546 1547
    ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(size == saved, "size = %d, expected %d\n", size, saved);
    ok(!str2[0], "buf changed\n");

    size = saved;
    str2[0] = 0;
1548
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, NULL, 0);
1549 1550 1551 1552 1553 1554 1555 1556
    ok(hres == E_INVALIDARG, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(!str2[0], "buf changed\n");

    hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, sizeof(test_str), 0);
    ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);

    size = 0;
    str2[0] = 0;
1557
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1558 1559 1560 1561 1562 1563 1564 1565
    ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");

    hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test2_str, sizeof(test2_str), 0);
    ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);

    size = 0;
    str2[0] = 0;
1566
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1567 1568 1569 1570 1571 1572 1573 1574
    ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(size == sizeof(test_str) && !memcmp(str2, test_str, sizeof(test_str)), "wrong user agent\n");

    hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, 2, 0);
    ok(hres == S_OK, "UrlMkSetSessionOption failed: %08x\n", hres);

    size = 0;
    str2[0] = 0;
1575
    hres = pUrlMkGetSessionOption(URLMON_OPTION_USERAGENT, str2, saved, &size, 0);
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
    ok(hres == E_OUTOFMEMORY, "UrlMkGetSessionOption failed: %08x\n", hres);
    ok(size == 3 && !strcmp(str2, "te"), "wrong user agent\n");

    hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, test_str, 0, 0);
    ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);

    hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, NULL, sizeof(test_str), 0);
    ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);

    hres = UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, NULL, 0, 0);
    ok(hres == E_INVALIDARG, "UrlMkSetSessionOption failed: %08x\n", hres);

1588 1589 1590
    HeapFree(GetProcessHeap(), 0, str2);
}

1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603
static void test_MkParseDisplayNameEx(void)
{
    IMoniker *mon = NULL;
    LPWSTR name;
    DWORD issys;
    ULONG eaten = 0;
    IBindCtx *bctx;
    HRESULT hres;

    static const WCHAR clsid_nameW[] = {'c','l','s','i','d',':',
            '2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8',
            '-','0','8','0','0','2','B','3','0','3','0','9','D',':',0};

1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
    const struct
    {
        LPBC *ppbc;
        LPCWSTR szDisplayName;
        ULONG *pchEaten;
        LPMONIKER *ppmk;
    } invalid_parameters[] =
    {
        {NULL,  NULL,     NULL,   NULL},
        {NULL,  NULL,     NULL,   &mon},
        {NULL,  NULL,     &eaten, NULL},
        {NULL,  NULL,     &eaten, &mon},
        {NULL,  wszEmpty, NULL,   NULL},
        {NULL,  wszEmpty, NULL,   &mon},
        {NULL,  wszEmpty, &eaten, NULL},
        {NULL,  wszEmpty, &eaten, &mon},
        {&bctx, NULL,     NULL,   NULL},
        {&bctx, NULL,     NULL,   &mon},
        {&bctx, NULL,     &eaten, NULL},
        {&bctx, NULL,     &eaten, &mon},
        {&bctx, wszEmpty, NULL,   NULL},
        {&bctx, wszEmpty, NULL,   &mon},
        {&bctx, wszEmpty, &eaten, NULL},
        {&bctx, wszEmpty, &eaten, &mon},
    };

    int i;

1632 1633
    CreateBindCtx(0, &bctx);

1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647
    for (i = 0; i < sizeof(invalid_parameters)/sizeof(invalid_parameters[0]); i++)
    {
        eaten = 0xdeadbeef;
        mon = (IMoniker *)0xdeadbeef;
        hres = MkParseDisplayNameEx(invalid_parameters[i].ppbc ? *invalid_parameters[i].ppbc : NULL,
                                    invalid_parameters[i].szDisplayName,
                                    invalid_parameters[i].pchEaten,
                                    invalid_parameters[i].ppmk);
        ok(hres == E_INVALIDARG,
            "[%d] Expected MkParseDisplayNameEx to return E_INVALIDARG, got %08x\n", i, hres);
        ok(eaten == 0xdeadbeef, "[%d] Expected eaten to be 0xdeadbeef, got %u\n", i, eaten);
        ok(mon == (IMoniker *)0xdeadbeef, "[%d] Expected mon to be 0xdeadbeef, got %p\n", i, mon);
    }

1648 1649 1650 1651 1652 1653
    hres = MkParseDisplayNameEx(bctx, url9, &eaten, &mon);
    ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
    ok(eaten == sizeof(url9)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
    ok(mon != NULL, "mon == NULL\n");

    hres = IMoniker_GetDisplayName(mon, NULL, 0, &name);
1654
    ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
1655
    ok(!lstrcmpW(name, url9), "wrong display name %s\n", wine_dbgstr_w(name));
1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680
    CoTaskMemFree(name);

    hres = IMoniker_IsSystemMoniker(mon, &issys);
    ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
    ok(issys == MKSYS_URLMONIKER, "issys=%x\n", issys);

    IMoniker_Release(mon);

    hres = MkParseDisplayNameEx(bctx, clsid_nameW, &eaten, &mon);
    ok(hres == S_OK, "MkParseDisplayNameEx failed: %08x\n", hres);
    ok(eaten == sizeof(clsid_nameW)/sizeof(WCHAR)-1, "eaten=%d\n", eaten);
    ok(mon != NULL, "mon == NULL\n");

    hres = IMoniker_IsSystemMoniker(mon, &issys);
    ok(hres == S_OK, "IsSystemMoniker failed: %08x\n", hres);
    ok(issys == MKSYS_CLASSMONIKER, "issys=%x\n", issys);

    IMoniker_Release(mon);

    hres = MkParseDisplayNameEx(bctx, url8, &eaten, &mon);
    ok(FAILED(hres), "MkParseDisplayNameEx succeeded: %08x\n", hres);

    IBindCtx_Release(bctx);
}

1681 1682 1683
static void test_IsValidURL(void)
{
    HRESULT hr;
1684
    IBindCtx *bctx = NULL;
1685 1686 1687

    hr = IsValidURL(NULL, 0, 0);
    ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
1688 1689 1690 1691 1692 1693 1694 1695 1696 1697

    hr = IsValidURL(NULL, wszHttpWineHQ, 0);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    CreateBindCtx(0, &bctx);

    hr = IsValidURL(bctx, wszHttpWineHQ, 0);
    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);

    IBindCtx_Release(bctx);
1698 1699
}

1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
static const struct {
    INTERNETFEATURELIST feature;
    DWORD               get_flags;
    HRESULT             expected;
    BOOL                todo;
} default_feature_tests[] = {
    {FEATURE_OBJECT_CACHING,GET_FEATURE_FROM_PROCESS,S_OK},
    {FEATURE_ZONE_ELEVATION,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_MIME_HANDLING,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_MIME_SNIFFING,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_WINDOW_RESTRICTIONS,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_WEBOC_POPUPMANAGEMENT,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_BEHAVIORS,GET_FEATURE_FROM_PROCESS,S_OK},
    {FEATURE_DISABLE_MK_PROTOCOL,GET_FEATURE_FROM_PROCESS,S_OK},
    {FEATURE_LOCALMACHINE_LOCKDOWN,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_SECURITYBAND,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_RESTRICT_ACTIVEXINSTALL,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_VALIDATE_NAVIGATE_URL,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_RESTRICT_FILEDOWNLOAD,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_ADDON_MANAGEMENT,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_PROTOCOL_LOCKDOWN,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_HTTP_USERNAME_PASSWORD_DISABLE,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_SAFE_BINDTOOBJECT,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_UNC_SAVEDFILECHECK,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_GET_URL_DOM_FILEPATH_UNENCODED,GET_FEATURE_FROM_PROCESS,S_OK},
    {FEATURE_TABBED_BROWSING,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_SSLUX,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_DISABLE_NAVIGATION_SOUNDS,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_DISABLE_LEGACY_COMPRESSION,GET_FEATURE_FROM_PROCESS,S_OK},
    {FEATURE_FORCE_ADDR_AND_STATUS,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_XMLHTTP,GET_FEATURE_FROM_PROCESS,S_OK},
    {FEATURE_DISABLE_TELNET_PROTOCOL,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_FEEDS,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_BLOCK_INPUT_PROMPTS,GET_FEATURE_FROM_PROCESS,S_FALSE}
};

static void test_internet_feature_defaults(void) {
    HRESULT hres;
    DWORD i;

    for(i = 0; i < sizeof(default_feature_tests)/sizeof(default_feature_tests[0]); ++i) {
        hres = pCoInternetIsFeatureEnabled(default_feature_tests[i].feature, default_feature_tests[i].get_flags);
1742
        todo_wine_if (default_feature_tests[i].todo)
1743 1744 1745 1746 1747
            ok(hres == default_feature_tests[i].expected, "CoInternetIsFeatureEnabled returned %08x, expected %08x on test %d\n",
                hres, default_feature_tests[i].expected, i);
    }
}

1748 1749 1750 1751 1752 1753 1754 1755
/* With older versions of IE (IE 7 and earlier), urlmon caches
 * the FeatureControl values from the registry when it's loaded
 * into memory. Newer versions of IE conditionally cache the
 * the FeatureControl registry values (i.e. When a call to
 * CoInternetIsFeatureEnabled and a corresponding CoInternetSetFeatureEnabled
 * call hasn't already been made for the specified Feature). Because of
 * this we skip these tests on IE 7 and earlier.
 */
1756 1757
static const char* szFeatureControlKey = "Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl";

1758 1759 1760 1761 1762 1763 1764
static void test_internet_features_registry(void) {
    HRESULT hres;
    DWORD res;
    char module[MAX_PATH];
    char *name;
    HKEY feature_control;
    HKEY feature;
1765 1766
    DWORD value;
    BOOL skip_zone;
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783
    BOOL delete_feature_key = TRUE;

    static const char* szFeatureBehaviorsKey = "FEATURE_BEHAVIORS";
    static const char* szFeatureZoneElevationKey = "FEATURE_ZONE_ELEVATION";

    if(!pIEInstallScope) {
        win_skip("Skipping internet feature registry tests, IE is too old...\n");
        return;
    }

    res = GetModuleFileNameA(NULL, module, sizeof(module));
    ok(res, "GetModuleFileName failed: %d\n", GetLastError());

    name = strrchr(module, '\\')+1;

    /* Some Windows machines don't have a FeatureControl key in HKCU. */
    res = RegOpenKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &feature_control);
1784
    ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
1785 1786

    res = RegOpenKeyA(feature_control, szFeatureBehaviorsKey, &feature);
1787
    if(res == ERROR_SUCCESS) {
1788 1789
        /* FEATURE_BEHAVIORS already existed, so don't delete it when we're done. */
        delete_feature_key = FALSE;
1790
    }else {
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
        res = RegCreateKeyA(feature_control, szFeatureBehaviorsKey, &feature);
        ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
    }

    value = 0;
    res = RegSetValueExA(feature, name, 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
    ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);

    hres = pCoInternetIsFeatureEnabled(FEATURE_BEHAVIORS, GET_FEATURE_FROM_PROCESS);
    ok(hres == S_FALSE, "CoInternetIsFeatureEnabled returned %08x, expected S_FALSE\n", hres);

    if(delete_feature_key) {
        RegCloseKey(feature);
        RegDeleteKeyA(feature_control, szFeatureBehaviorsKey);
    } else {
1806
        RegDeleteValueA(feature, name);
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827
        RegCloseKey(feature);
    }

    /* IE's feature control cached the value it got from the registry earlier. */
    hres = pCoInternetIsFeatureEnabled(FEATURE_BEHAVIORS, GET_FEATURE_FROM_PROCESS);
    ok(hres == S_FALSE, "CoInternetIsFeatureEnabled returned %08x, expected S_FALSE\n", hres);

    /* Restore this feature back to its default value. */
    hres = pCoInternetSetFeatureEnabled(FEATURE_BEHAVIORS, SET_FEATURE_ON_PROCESS, TRUE);
    ok(hres == S_OK, "CoInternetSetFeatureEnabled failed: %08x\n", hres);

    RegCloseKey(feature_control);

    res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szFeatureControlKey, &feature_control);
    ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);

    res = RegOpenKeyA(feature_control, szFeatureZoneElevationKey, &feature);
    ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);

    value = 1;
    res = RegSetValueExA(feature, "*", 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD));
1828 1829 1830
    if (res == ERROR_ACCESS_DENIED)
    {
        skip("Not allowed to modify zone elevation\n");
1831
        skip_zone = TRUE;
1832 1833 1834
    }
    else
    {
1835
        skip_zone = FALSE;
1836
        ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
1837

1838 1839 1840
        hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
        ok(hres == S_OK, "CoInternetIsFeatureEnabled returned %08x, expected S_OK\n", hres);
    }
1841 1842 1843 1844 1845
    RegDeleteValueA(feature, "*");
    RegCloseKey(feature);
    RegCloseKey(feature_control);

    /* Value is still cached from last time. */
1846 1847 1848 1849
    if (!skip_zone)
    {
        hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
        ok(hres == S_OK, "CoInternetIsFeatureEnabled returned %08x, expected S_OK\n", hres);
1850

1851 1852 1853
        hres = pCoInternetSetFeatureEnabled(FEATURE_ZONE_ELEVATION, SET_FEATURE_ON_PROCESS, FALSE);
        ok(hres == S_OK, "CoInternetSetFeatureEnabled failed: %08x\n", hres);
    }
1854

1855
    test_internet_feature_defaults();
1856 1857 1858 1859 1860 1861 1862 1863 1864
}

static void test_CoInternetIsFeatureEnabled(void) {
    HRESULT hres;

    hres = pCoInternetIsFeatureEnabled(FEATURE_ENTRY_COUNT, GET_FEATURE_FROM_PROCESS);
    ok(hres == E_FAIL, "CoInternetIsFeatureEnabled returned %08x, expected E_FAIL\n", hres);
}

1865 1866 1867 1868 1869 1870 1871 1872 1873 1874
static const struct {
    INTERNETFEATURELIST feature;
    DWORD               set_flags;
    BOOL                enable;
    HRESULT             set_expected;
    BOOL                set_todo;
    DWORD               get_flags;
    HRESULT             get_expected;
    BOOL                get_todo;
} internet_feature_tests[] = {
1875 1876 1877
    {FEATURE_OBJECT_CACHING,SET_FEATURE_ON_PROCESS,FALSE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_FALSE},
    {FEATURE_WEBOC_POPUPMANAGEMENT,SET_FEATURE_ON_PROCESS,TRUE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_OK},
    {FEATURE_LOCALMACHINE_LOCKDOWN,SET_FEATURE_ON_PROCESS,TRUE,S_OK,FALSE,GET_FEATURE_FROM_PROCESS,S_OK}
1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889
};

static void test_CoInternetSetFeatureEnabled(void) {
    HRESULT hres;
    DWORD i;

    hres = pCoInternetSetFeatureEnabled(FEATURE_ENTRY_COUNT,SET_FEATURE_ON_PROCESS,TRUE);
    ok(hres == E_FAIL, "CoInternetSetFeatureEnabled returned %08x, expected E_FAIL\n", hres);

    for(i = 0; i < sizeof(internet_feature_tests)/sizeof(internet_feature_tests[0]); ++i) {
        hres = pCoInternetSetFeatureEnabled(internet_feature_tests[i].feature, internet_feature_tests[i].set_flags,
                                            internet_feature_tests[i].enable);
1890
        todo_wine_if (internet_feature_tests[i].set_todo)
1891 1892 1893 1894
            ok(hres == internet_feature_tests[i].set_expected, "CoInternetSetFeatureEnabled returned %08x, expected %08x on test %d\n",
                hres, internet_feature_tests[i].set_expected, i);

        hres = pCoInternetIsFeatureEnabled(internet_feature_tests[i].feature, internet_feature_tests[i].set_flags);
1895
        todo_wine_if (internet_feature_tests[i].get_todo)
1896 1897
            ok(hres == internet_feature_tests[i].get_expected, "CoInternetIsFeatureEnabled returned %08x, expected %08x on test %d\n",
                hres, internet_feature_tests[i].get_expected, i);
1898

1899 1900 1901
    }
}

1902
static void test_internet_features(void) {
1903 1904 1905
    HKEY key;
    DWORD res;

1906
    if(!pCoInternetIsFeatureEnabled || !pCoInternetSetFeatureEnabled) {
1907 1908 1909 1910
        win_skip("Skipping internet feature tests, IE is too old\n");
        return;
    }

1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936
    /* IE10 takes FeatureControl key into account only if it's available upon process start. */
    res = RegOpenKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &key);
    if(res != ERROR_SUCCESS) {
        PROCESS_INFORMATION pi;
        STARTUPINFOA si = { 0 };
        char cmdline[MAX_PATH];
        char **argv;
        BOOL ret;

        res = RegCreateKeyA(HKEY_CURRENT_USER, szFeatureControlKey, &key);
        ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);

        trace("Running features tests in a separated process.\n");

        winetest_get_mainargs( &argv );
        sprintf(cmdline, "\"%s\" %s internet_features", argv[0], argv[1]);
        ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
        ok(ret, "Could not create process: %u\n", GetLastError());
        winetest_wait_child_process( pi.hProcess );
        CloseHandle(pi.hThread);
        CloseHandle(pi.hProcess);

        RegDeleteKeyA(HKEY_CURRENT_USER, szFeatureControlKey);
        return;
    }

1937
    test_internet_features_registry();
1938
    test_CoInternetIsFeatureEnabled();
1939
    test_CoInternetSetFeatureEnabled();
1940 1941
}

1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648
static BINDINFO rem_bindinfo = { sizeof(rem_bindinfo) }, in_bindinfo;
static DWORD rem_bindf;

static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv)
{
    if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid)
       || IsEqualGUID(&IID_IBindStatusCallback, riid)
       || IsEqualGUID(&IID_IUnknown, riid)) {
        *ppv = iface;
        return S_OK;
    }

    *ppv = NULL;
    return E_NOINTERFACE;
}

static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallbackEx *iface)
{
    return 2;
}

static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallbackEx *iface)
{
    return 1;
}

static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallbackEx *iface,
        DWORD dwReserved, IBinding *pib)
{
    ok(0, "unexpected call\n");
    return S_OK;
}

static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
        ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
{
    ok(0, "unexpected call\n");
    return S_OK;
}

static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError)
{
    ok(0, "unexpected call\n");
    return S_OK;
}

static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
{
    in_bindinfo = *pbindinfo;
    *grfBINDF = rem_bindf;
    *pbindinfo = rem_bindinfo;
    return S_OK;
}

static STGMEDIUM in_stgmed, rem_stgmed;

static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF,
        DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
{
    in_stgmed = *pstgmed;
    *pstgmed = rem_stgmed;
    return S_OK;
}

static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk)
{
    ok(0, "unexpected call\n");
    return S_OK;
}

static HRESULT WINAPI BindStatusCallbackEx_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF,
        BINDINFO *pbindinfo, DWORD *grfBINDF2, DWORD *pdwReserved)
{
    in_bindinfo = *pbindinfo;
    *grfBINDF = rem_bindf;
    *pbindinfo = rem_bindinfo;
    *grfBINDF2 = 11;
    *pdwReserved = 12;
    return S_OK;
}

static const IBindStatusCallbackExVtbl BindStatusCallbackExVtbl = {
    BindStatusCallback_QueryInterface,
    BindStatusCallback_AddRef,
    BindStatusCallback_Release,
    BindStatusCallback_OnStartBinding,
    BindStatusCallback_GetPriority,
    BindStatusCallback_OnLowResource,
    BindStatusCallback_OnProgress,
    BindStatusCallback_OnStopBinding,
    BindStatusCallback_GetBindInfo,
    BindStatusCallback_OnDataAvailable,
    BindStatusCallback_OnObjectAvailable,
    BindStatusCallbackEx_GetBindInfoEx
};

static IBindStatusCallbackEx BindStatusCallback = { &BindStatusCallbackExVtbl };

typedef struct {
    IUnknown IUnknown_iface;
    LONG ref;
} RefUnk;

static inline RefUnk *impl_from_IUnknown(IUnknown *iface)
{
    return CONTAINING_RECORD(iface, RefUnk, IUnknown_iface);
}

static HRESULT WINAPI RefUnk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
{
    if(!IsEqualGUID(&IID_IUnknown, riid)) {
        *ppv = NULL;
        return E_NOINTERFACE;
    }

    IUnknown_AddRef(iface);
    *ppv = iface;
    return S_OK;
}

static ULONG WINAPI RefUnk_AddRef(IUnknown *iface)
{
    RefUnk *This = impl_from_IUnknown(iface);
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI RefUnk_Release(IUnknown *iface)
{
    RefUnk *This = impl_from_IUnknown(iface);
    return InterlockedDecrement(&This->ref);
}

static const IUnknownVtbl RefUnkVtbl = {
    RefUnk_QueryInterface,
    RefUnk_AddRef,
    RefUnk_Release
};

static RefUnk unk_in = {{&RefUnkVtbl}}, unk_out = {{&RefUnkVtbl}};

static HANDLE thread_ready;

static DWORD WINAPI bsc_thread(void *arg)
{
    IStream *stream = arg;
    LARGE_INTEGER zero;
    MSG msg;
    HRESULT hres;

    CoInitialize(NULL);

    hres = CoMarshalInterface(stream, &IID_IBindStatusCallback, (IUnknown*)&BindStatusCallback,
                              MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
    ok(hres == S_OK, "CoMarshalInterface failed: %08x\n", hres);

    zero.QuadPart = 0;
    hres = IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
    ok(hres == S_OK, "Seek failed: 0x%08x\n", hres);

    SetEvent(thread_ready);

    while(GetMessageW(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessageW(&msg);
    }

    CoUninitialize();
    return 0;
}

static void test_bsc_marshaling(void)
{
    FORMATETC formatetc = {0, NULL, 1, -1, TYMED_ISTREAM};
    IBindStatusCallbackEx *callbackex;
    IBindStatusCallback *bsc;
    BINDINFO bindinfo;
    IStream *stream, *binding_stream;
    HANDLE thread;
    WCHAR *extra_info_out;
    WCHAR *verb_out;
    LARGE_INTEGER zero;
    STGMEDIUM stgmed;
    void *buf;
    DWORD bindf;
    HRESULT hres;

    hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
    ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);

    thread_ready = CreateEventW(NULL, TRUE, FALSE, NULL);
    thread = CreateThread(NULL, 0, bsc_thread, stream, 0, NULL);
    WaitForSingleObject(thread_ready, INFINITE);

    hres = CoUnmarshalInterface(stream, &IID_IBindStatusCallback, (void**)&bsc);
    ok(hres == S_OK, "CoUnmarshalInterface failed: %08x\n", hres);

    hres = CreateStreamOnHGlobal(NULL, TRUE, &binding_stream);
    ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);
    hres = IStream_Write(binding_stream, "xxx", 3, NULL);
    ok(hres == S_OK, "Write failed: %08x\n", hres);

    rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
    bindf = 0xdeadbeef;

    memset(&bindinfo, 0, sizeof(bindinfo));
    bindinfo.cbSize = sizeof(bindinfo);
    bindinfo.grfBindInfoF = 12;
    bindinfo.dwBindVerb = 13;
    bindinfo.cbstgmedData = 19;
    bindinfo.dwOptions = 14;
    bindinfo.dwOptionsFlags = 15;
    bindinfo.dwCodePage = 16;
    bindinfo.securityAttributes.nLength = 30;
    bindinfo.securityAttributes.lpSecurityDescriptor = (void*)0xdead0001;
    bindinfo.securityAttributes.bInheritHandle = 31;
    bindinfo.iid.Data1 = 17;
    bindinfo.pUnk = (IUnknown*)0xdeadbeef;
    bindinfo.dwReserved = 18;
    bindinfo.stgmedData.pUnkForRelease = &unk_in.IUnknown_iface;
    unk_in.ref = 1;

    memset(&rem_bindinfo, 0, sizeof(bindinfo));
    rem_bindinfo.cbSize = sizeof(rem_bindinfo);
    rem_bindinfo.szExtraInfo = extra_info_out = a2co("extra info out");
    rem_bindinfo.grfBindInfoF = 22;
    rem_bindinfo.dwBindVerb = 23;
    rem_bindinfo.szCustomVerb = verb_out = a2co("custom verb out");
    rem_bindinfo.cbstgmedData = 29;
    rem_bindinfo.dwOptions = 24;
    rem_bindinfo.dwOptionsFlags = 25;
    rem_bindinfo.dwCodePage = 16;
    rem_bindinfo.securityAttributes.nLength = 40;
    rem_bindinfo.securityAttributes.lpSecurityDescriptor = (void*)0xdead0002;
    rem_bindinfo.securityAttributes.bInheritHandle = 41;
    rem_bindinfo.iid.Data1 = 27;
    rem_bindinfo.pUnk = (IUnknown*)0xdeadbeef;
    rem_bindinfo.dwReserved = 18;
    rem_bindinfo.stgmedData.pUnkForRelease = &unk_out.IUnknown_iface;
    unk_out.ref = 1;

    hres = IBindStatusCallback_GetBindInfo(bsc, &bindf, &bindinfo);
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
    ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);

    ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
    ok(!in_bindinfo.szExtraInfo, "szExtraInfo = %s\n", wine_dbgstr_w(in_bindinfo.szExtraInfo));
    ok(in_bindinfo.grfBindInfoF == 12, "cbSize = %u\n", in_bindinfo.grfBindInfoF);
    ok(in_bindinfo.dwBindVerb == 13, "dwBindVerb = %u\n", in_bindinfo.dwBindVerb);
    ok(!in_bindinfo.szCustomVerb, "szCustomVerb = %s\n", wine_dbgstr_w(in_bindinfo.szCustomVerb));
    ok(in_bindinfo.cbstgmedData == 19, "cbstgmedData = %u\n", in_bindinfo.cbstgmedData);
    ok(!in_bindinfo.dwOptions, "dwOptions = %u\n", in_bindinfo.dwOptions);
    ok(!in_bindinfo.dwOptionsFlags, "dwOptionsFlags = %u\n", in_bindinfo.dwOptionsFlags);
    ok(!in_bindinfo.dwCodePage, "dwCodePage = %u\n", in_bindinfo.dwCodePage);
    ok(!in_bindinfo.iid.Data1, "iid.Data1 = %u\n", in_bindinfo.iid.Data1);
    ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
    ok(!in_bindinfo.dwReserved, "dwReserved = %u\n", in_bindinfo.dwReserved);
    ok(!in_bindinfo.securityAttributes.nLength, "securityAttributes.nLength = %u\n",
       in_bindinfo.securityAttributes.nLength);
    ok(!in_bindinfo.securityAttributes.lpSecurityDescriptor,
       "securityAttributes.lpSecurityDescriptor = %p\n",
       in_bindinfo.securityAttributes.lpSecurityDescriptor);
    ok(!in_bindinfo.securityAttributes.bInheritHandle, "securityAttributes.bInheritHandle = %u\n",
       in_bindinfo.securityAttributes.bInheritHandle);
    ok(!in_bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
       in_bindinfo.stgmedData.pUnkForRelease);

    ok(bindinfo.cbSize == sizeof(rem_bindinfo), "cbSize = %u\n", rem_bindinfo.cbSize);
    ok(!strcmp_wa(bindinfo.szExtraInfo, "extra info out"),
       "szExtraInfo = %s\n", wine_dbgstr_w(bindinfo.szExtraInfo));
    ok(bindinfo.grfBindInfoF == 22, "grfBindInfoF = %u\n", rem_bindinfo.grfBindInfoF);
    ok(bindinfo.dwBindVerb == 23, "dwBindVerb = %u\n", bindinfo.dwBindVerb);
    ok(bindinfo.szCustomVerb != verb_out, "szCustomVerb == inbuf\n");
    ok(!strcmp_wa(bindinfo.szCustomVerb, "custom verb out"), "szCustomVerb = %s\n",
       wine_dbgstr_w(bindinfo.szCustomVerb));
    ok(bindinfo.cbstgmedData == 29, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
    ok(bindinfo.dwOptions == 24, "dwOptions = %u\n", bindinfo.dwOptions);
    ok(bindinfo.dwOptionsFlags == 25, "dwOptionsFlags = %u\n", bindinfo.dwOptionsFlags);
    ok(bindinfo.dwCodePage, "dwCodePage = %u\n", bindinfo.dwCodePage);
    ok(!bindinfo.iid.Data1, "iid.Data1 = %u\n", bindinfo.iid.Data1);
    ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
    ok(bindinfo.dwReserved == 18, "dwReserved = %u\n", bindinfo.dwReserved);
    ok(bindinfo.securityAttributes.nLength == 30, "securityAttributes.nLength = %u\n",
       bindinfo.securityAttributes.nLength);
    ok(bindinfo.securityAttributes.lpSecurityDescriptor == (void*)0xdead0001,
       "securityAttributes.lpSecurityDescriptor = %p\n",
       bindinfo.securityAttributes.lpSecurityDescriptor);
    ok(bindinfo.securityAttributes.bInheritHandle == 31, "securityAttributes.bInheritHandle = %u\n",
       bindinfo.securityAttributes.bInheritHandle);
    ok(bindinfo.stgmedData.pUnkForRelease == &unk_in.IUnknown_iface, "pUnkForRelease = %p\n",
       bindinfo.stgmedData.pUnkForRelease);
    ok(unk_out.ref == 1, "unk_out.ref = %u\n", unk_out.ref);

    bindinfo.stgmedData.pUnkForRelease = NULL;
    ReleaseBindInfo(&bindinfo);

    zero.QuadPart = 0;
    hres = IStream_Seek(binding_stream, zero, STREAM_SEEK_SET, NULL);
    ok(hres == S_OK, "Seek failed: 0x%08x\n", hres);

    /* Return IStream stgmed from GetBindInfo, it's not marshaled back */
    rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
    bindf = 0xdeadbeef;

    memset(&bindinfo, 0, sizeof(bindinfo));
    bindinfo.cbSize = sizeof(bindinfo);

    memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
    rem_bindinfo.cbSize = sizeof(rem_bindinfo);

    rem_bindinfo.stgmedData.tymed = TYMED_ISTREAM;
    rem_bindinfo.stgmedData.u.pstm = binding_stream;
    rem_bindinfo.cbstgmedData = 3;
    IStream_AddRef(binding_stream);

    hres = IBindStatusCallback_GetBindInfo(bsc, &bindf, &bindinfo);
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
    ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);

    ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
    ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
    ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
       in_bindinfo.stgmedData.tymed);

    ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
    ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
    ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
       bindinfo.stgmedData.tymed);
    ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
       bindinfo.stgmedData.u.pstm);
    ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
       bindinfo.stgmedData.pUnkForRelease);
    ok(bindinfo.cbstgmedData == 3, "cbstgmedData = %u\n", bindinfo.cbstgmedData);

    ReleaseBindInfo(&bindinfo);

    /* Same, but with pUnkForRelease, it's not marshaled back */
    rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
    bindf = 0xdeadbeef;

    memset(&bindinfo, 0, sizeof(bindinfo));
    bindinfo.cbSize = sizeof(bindinfo);

    memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
    rem_bindinfo.cbSize = sizeof(rem_bindinfo);

    rem_bindinfo.stgmedData.tymed = TYMED_ISTREAM;
    rem_bindinfo.stgmedData.u.pstm = binding_stream;
    rem_bindinfo.stgmedData.pUnkForRelease = &unk_out.IUnknown_iface;
    unk_out.ref = 1;
    rem_bindinfo.cbstgmedData = 3;
    IStream_AddRef(binding_stream);

    hres = IBindStatusCallback_GetBindInfo(bsc, &bindf, &bindinfo);
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
    ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);

    ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
    ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
    ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
       in_bindinfo.stgmedData.tymed);

    ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
    ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
    ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
       bindinfo.stgmedData.tymed);
    ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
       bindinfo.stgmedData.u.pstm);
    ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
       bindinfo.stgmedData.pUnkForRelease);
    ok(bindinfo.cbstgmedData == 3, "cbstgmedData = %u\n", bindinfo.cbstgmedData);

    ReleaseBindInfo(&bindinfo);

    /* Return HGLOBAL stgmed from GetBindInfo, it's not marshaled back */
    rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
    bindf = 0xdeadbeef;

    memset(&bindinfo, 0, sizeof(bindinfo));
    bindinfo.cbSize = sizeof(bindinfo);

    memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
    rem_bindinfo.cbSize = sizeof(rem_bindinfo);

    rem_bindinfo.stgmedData.tymed = TYMED_HGLOBAL;

    buf = GlobalAlloc(0, sizeof(5));
    strcpy(buf, "test");
    rem_bindinfo.stgmedData.u.hGlobal = buf;
    rem_bindinfo.cbstgmedData = 5;

    hres = IBindStatusCallback_GetBindInfo(bsc, &bindf, &bindinfo);
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
    ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);

    ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
    ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
    ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
       in_bindinfo.stgmedData.tymed);

    ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
    ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
    ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
       bindinfo.stgmedData.tymed);
    ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
       bindinfo.stgmedData.u.pstm);
    ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
       bindinfo.stgmedData.pUnkForRelease);
    ok(bindinfo.cbstgmedData == 5, "cbstgmedData = %u\n", bindinfo.cbstgmedData);

    ReleaseBindInfo(&bindinfo);

    /* Same with GetBindInfoEx */
    hres = IBindStatusCallback_QueryInterface(bsc, &IID_IBindStatusCallbackEx, (void**)&callbackex);
    if(SUCCEEDED(hres)) {
        DWORD bindf2, reserved;

        rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
        bindf = bindf2 = reserved = 0xdeadbeef;

        memset(&bindinfo, 0, sizeof(bindinfo));
        bindinfo.cbSize = sizeof(bindinfo);
        bindinfo.grfBindInfoF = 12;
        bindinfo.dwBindVerb = 13;
        bindinfo.cbstgmedData = 19;
        bindinfo.dwOptions = 14;
        bindinfo.dwOptionsFlags = 15;
        bindinfo.dwCodePage = 16;
        bindinfo.securityAttributes.nLength = 30;
        bindinfo.securityAttributes.lpSecurityDescriptor = (void*)0xdead0001;
        bindinfo.securityAttributes.bInheritHandle = 31;
        bindinfo.iid.Data1 = 17;
        bindinfo.pUnk = (IUnknown*)0xdeadbeef;
        bindinfo.dwReserved = 18;
        bindinfo.stgmedData.pUnkForRelease = &unk_in.IUnknown_iface;
        unk_in.ref = 1;

        memset(&rem_bindinfo, 0, sizeof(bindinfo));
        rem_bindinfo.cbSize = sizeof(rem_bindinfo);
        rem_bindinfo.szExtraInfo = extra_info_out = a2co("extra info out");
        rem_bindinfo.grfBindInfoF = 22;
        rem_bindinfo.dwBindVerb = 23;
        rem_bindinfo.szCustomVerb = verb_out = a2co("custom verb out");
        rem_bindinfo.cbstgmedData = 29;
        rem_bindinfo.dwOptions = 24;
        rem_bindinfo.dwOptionsFlags = 25;
        rem_bindinfo.dwCodePage = 16;
        rem_bindinfo.securityAttributes.nLength = 40;
        rem_bindinfo.securityAttributes.lpSecurityDescriptor = (void*)0xdead0002;
        rem_bindinfo.securityAttributes.bInheritHandle = 41;
        rem_bindinfo.iid.Data1 = 27;
        rem_bindinfo.pUnk = (IUnknown*)0xdeadbeef;
        rem_bindinfo.dwReserved = 18;
        rem_bindinfo.stgmedData.pUnkForRelease = &unk_out.IUnknown_iface;
        unk_out.ref = 1;

        hres = IBindStatusCallbackEx_GetBindInfoEx(callbackex, &bindf, &bindinfo, &bindf2, &reserved);
        ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
        ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);
        ok(bindf2 == 11, "bindf2 = %x\n", bindf);
        ok(reserved == 12, "reserved = %x\n", reserved);

        ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
        ok(!in_bindinfo.szExtraInfo, "szExtraInfo = %s\n", wine_dbgstr_w(in_bindinfo.szExtraInfo));
        ok(in_bindinfo.grfBindInfoF == 12, "cbSize = %u\n", in_bindinfo.grfBindInfoF);
        ok(in_bindinfo.dwBindVerb == 13, "dwBindVerb = %u\n", in_bindinfo.dwBindVerb);
        ok(!in_bindinfo.szCustomVerb, "szCustomVerb = %s\n", wine_dbgstr_w(in_bindinfo.szCustomVerb));
        ok(in_bindinfo.cbstgmedData == 19, "cbstgmedData = %u\n", in_bindinfo.cbstgmedData);
        ok(!in_bindinfo.dwOptions, "dwOptions = %u\n", in_bindinfo.dwOptions);
        ok(!in_bindinfo.dwOptionsFlags, "dwOptionsFlags = %u\n", in_bindinfo.dwOptionsFlags);
        ok(!in_bindinfo.dwCodePage, "dwCodePage = %u\n", in_bindinfo.dwCodePage);
        ok(!in_bindinfo.iid.Data1, "iid.Data1 = %u\n", in_bindinfo.iid.Data1);
        ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
        ok(!in_bindinfo.dwReserved, "dwReserved = %u\n", in_bindinfo.dwReserved);
        ok(!in_bindinfo.securityAttributes.nLength, "securityAttributes.nLength = %u\n",
           in_bindinfo.securityAttributes.nLength);
        ok(!in_bindinfo.securityAttributes.lpSecurityDescriptor,
           "securityAttributes.lpSecurityDescriptor = %p\n",
           in_bindinfo.securityAttributes.lpSecurityDescriptor);
        ok(!in_bindinfo.securityAttributes.bInheritHandle, "securityAttributes.bInheritHandle = %u\n",
           in_bindinfo.securityAttributes.bInheritHandle);
        ok(!in_bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
           in_bindinfo.stgmedData.pUnkForRelease);

        ok(bindinfo.cbSize == sizeof(rem_bindinfo), "cbSize = %u\n", rem_bindinfo.cbSize);
        ok(!strcmp_wa(bindinfo.szExtraInfo, "extra info out"),
           "szExtraInfo = %s\n", wine_dbgstr_w(bindinfo.szExtraInfo));
        ok(bindinfo.grfBindInfoF == 22, "grfBindInfoF = %u\n", rem_bindinfo.grfBindInfoF);
        ok(bindinfo.dwBindVerb == 23, "dwBindVerb = %u\n", bindinfo.dwBindVerb);
        ok(bindinfo.szCustomVerb != verb_out, "szCustomVerb == inbuf\n");
        ok(!strcmp_wa(bindinfo.szCustomVerb, "custom verb out"), "szCustomVerb = %s\n",
           wine_dbgstr_w(bindinfo.szCustomVerb));
        ok(bindinfo.cbstgmedData == 29, "cbstgmedData = %u\n", bindinfo.cbstgmedData);
        ok(bindinfo.dwOptions == 24, "dwOptions = %u\n", bindinfo.dwOptions);
        ok(bindinfo.dwOptionsFlags == 25, "dwOptionsFlags = %u\n", bindinfo.dwOptionsFlags);
        ok(bindinfo.dwCodePage, "dwCodePage = %u\n", bindinfo.dwCodePage);
        ok(!bindinfo.iid.Data1, "iid.Data1 = %u\n", bindinfo.iid.Data1);
        ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
        ok(bindinfo.dwReserved == 18, "dwReserved = %u\n", bindinfo.dwReserved);
        ok(bindinfo.securityAttributes.nLength == 30, "securityAttributes.nLength = %u\n",
           bindinfo.securityAttributes.nLength);
        ok(bindinfo.securityAttributes.lpSecurityDescriptor == (void*)0xdead0001,
           "securityAttributes.lpSecurityDescriptor = %p\n",
           bindinfo.securityAttributes.lpSecurityDescriptor);
        ok(bindinfo.securityAttributes.bInheritHandle == 31, "securityAttributes.bInheritHandle = %u\n",
           bindinfo.securityAttributes.bInheritHandle);
        ok(bindinfo.stgmedData.pUnkForRelease == &unk_in.IUnknown_iface, "pUnkForRelease = %p\n",
           bindinfo.stgmedData.pUnkForRelease);
        ok(unk_out.ref == 1, "unk_out.ref = %u\n", unk_out.ref);

        bindinfo.stgmedData.pUnkForRelease = NULL;
        ReleaseBindInfo(&bindinfo);

        zero.QuadPart = 0;
        hres = IStream_Seek(binding_stream, zero, STREAM_SEEK_SET, NULL);
        ok(hres == S_OK, "Seek failed: 0x%08x\n", hres);

        /* Return IStream stgmed from GetBindInfoEx, it's not marshaled back */
        rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
        bindf = bindf2 = reserved = 0xdeadbeef;

        memset(&bindinfo, 0, sizeof(bindinfo));
        bindinfo.cbSize = sizeof(bindinfo);

        memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
        rem_bindinfo.cbSize = sizeof(rem_bindinfo);

        rem_bindinfo.stgmedData.tymed = TYMED_ISTREAM;
        rem_bindinfo.stgmedData.u.pstm = binding_stream;
        rem_bindinfo.cbstgmedData = 3;
        IStream_AddRef(binding_stream);

        hres = IBindStatusCallbackEx_GetBindInfoEx(callbackex, &bindf, &bindinfo, &bindf2, &reserved);
        ok(hres == S_OK, "GetBindInfoEx failed: %08x\n", hres);
        ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);

        ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
        ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
        ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
           in_bindinfo.stgmedData.tymed);

        ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
        ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
        ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
           bindinfo.stgmedData.tymed);
        ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
           bindinfo.stgmedData.u.pstm);
        ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
           bindinfo.stgmedData.pUnkForRelease);
        ok(bindinfo.cbstgmedData == 3, "cbstgmedData = %u\n", bindinfo.cbstgmedData);

        ReleaseBindInfo(&bindinfo);

        /* Same, but with pUnkForRelease, it's not marshaled back */
        rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
        bindf = bindf2 = reserved = 0xdeadbeef;

        memset(&bindinfo, 0, sizeof(bindinfo));
        bindinfo.cbSize = sizeof(bindinfo);

        memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
        rem_bindinfo.cbSize = sizeof(rem_bindinfo);

        rem_bindinfo.stgmedData.tymed = TYMED_ISTREAM;
        rem_bindinfo.stgmedData.u.pstm = binding_stream;
        rem_bindinfo.stgmedData.pUnkForRelease = &unk_out.IUnknown_iface;
        unk_out.ref = 1;
        rem_bindinfo.cbstgmedData = 3;
        IStream_AddRef(binding_stream);

        hres = IBindStatusCallbackEx_GetBindInfoEx(callbackex, &bindf, &bindinfo, &bindf2, &reserved);
        ok(hres == S_OK, "GetBindInfoEx failed: %08x\n", hres);
        ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);

        ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
        ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
        ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
           in_bindinfo.stgmedData.tymed);

        ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
        ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
        ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
           bindinfo.stgmedData.tymed);
        ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
           bindinfo.stgmedData.u.pstm);
        ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
           bindinfo.stgmedData.pUnkForRelease);
        ok(bindinfo.cbstgmedData == 3, "cbstgmedData = %u\n", bindinfo.cbstgmedData);

        ReleaseBindInfo(&bindinfo);

        /* Return HGLOBAL stgmed from GetBindInfoEx, it's not marshaled back */
        rem_bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
        bindf = bindf2 = reserved = 0xdeadbeef;

        memset(&bindinfo, 0, sizeof(bindinfo));
        bindinfo.cbSize = sizeof(bindinfo);

        memset(&rem_bindinfo, 0, sizeof(rem_bindinfo));
        rem_bindinfo.cbSize = sizeof(rem_bindinfo);

        rem_bindinfo.stgmedData.tymed = TYMED_HGLOBAL;

        buf = GlobalAlloc(0, sizeof(5));
        strcpy(buf, "test");
        rem_bindinfo.stgmedData.u.hGlobal = buf;
        rem_bindinfo.cbstgmedData = 5;

        hres = IBindStatusCallbackEx_GetBindInfoEx(callbackex, &bindf, &bindinfo, &bindf2, &reserved);
        ok(hres == S_OK, "GetBindInfoEx failed: %08x\n", hres);
        ok(bindf == rem_bindf, "bindf = %x, expected %x\n", bindf, rem_bindf);

        ok(in_bindinfo.cbSize == sizeof(in_bindinfo), "cbSize = %u\n", in_bindinfo.cbSize);
        ok(!in_bindinfo.pUnk, "pUnk = %p\n", in_bindinfo.pUnk);
        ok(in_bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
           in_bindinfo.stgmedData.tymed);

        ok(bindinfo.cbSize == sizeof(bindinfo), "cbSize = %u\n", bindinfo.cbSize);
        ok(!bindinfo.pUnk, "pUnk = %p\n", bindinfo.pUnk);
        ok(bindinfo.stgmedData.tymed == TYMED_NULL, "tymed = %u\n",
           bindinfo.stgmedData.tymed);
        ok(!bindinfo.stgmedData.u.pstm, "stm = %p\n",
           bindinfo.stgmedData.u.pstm);
        ok(!bindinfo.stgmedData.pUnkForRelease, "pUnkForRelease = %p\n",
           bindinfo.stgmedData.pUnkForRelease);
        ok(bindinfo.cbstgmedData == 5, "cbstgmedData = %u\n", bindinfo.cbstgmedData);

        ReleaseBindInfo(&bindinfo);

        IBindStatusCallbackEx_Release(callbackex);
    }else {
        win_skip("IBindStatusCallbackEx not supported\n");
    }

    /* Test marshaling stgmed from OnDataAvailable */
    memset(&in_stgmed, 0xcc, sizeof(in_stgmed));
    stgmed.tymed = TYMED_ISTREAM;
    stgmed.u.pstm = binding_stream;
    stgmed.pUnkForRelease = NULL;

    hres = IBindStatusCallback_OnDataAvailable(bsc, 1, 10, &formatetc, &stgmed);
    ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);

    ok(in_stgmed.tymed == TYMED_ISTREAM, "tymed = %u\n", in_stgmed.tymed);
    ok(in_stgmed.u.pstm != NULL, "pstm = NULL\n");
    ok(!in_stgmed.pUnkForRelease, "pUnkForRelease = %p\n", in_stgmed.pUnkForRelease);

    /* OnDataAvailable with both IStream and pUnkForRelease */
    memset(&in_stgmed, 0xcc, sizeof(in_stgmed));
    stgmed.tymed = TYMED_ISTREAM;
    stgmed.u.pstm = binding_stream;
    stgmed.pUnkForRelease = &unk_in.IUnknown_iface;
    unk_in.ref = 1;

    hres = IBindStatusCallback_OnDataAvailable(bsc, 1, 10, &formatetc, &stgmed);
    ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);

    ok(in_stgmed.tymed == TYMED_ISTREAM, "tymed = %u\n", in_stgmed.tymed);
    ok(in_stgmed.u.pstm != NULL, "pstm = NULL\n");
    ok(in_stgmed.pUnkForRelease != NULL, "pUnkForRelease = %p\n", in_stgmed.pUnkForRelease);
    ok(unk_in.ref > 1, "ref = %u\n", unk_in.ref);

    /* OnDataAvailable with TYMED_ISTREAM, but NULL stream */
    memset(&in_stgmed, 0xcc, sizeof(in_stgmed));
    stgmed.tymed = TYMED_ISTREAM;
    stgmed.u.pstm = binding_stream;
    stgmed.pUnkForRelease = NULL;

    hres = IBindStatusCallback_OnDataAvailable(bsc, 1, 10, &formatetc, &stgmed);
    ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);

    ok(in_stgmed.tymed == TYMED_ISTREAM, "tymed = %u\n", in_stgmed.tymed);
    ok(in_stgmed.u.pstm != NULL, "pstm = NULL\n");
    ok(!in_stgmed.pUnkForRelease, "pUnkForRelease = %p\n", in_stgmed.pUnkForRelease);

    /* OnDataAvailable with TYMED_NULL and pUnkForRelease */
    memset(&in_stgmed, 0xcc, sizeof(in_stgmed));
    stgmed.tymed = TYMED_NULL;
    stgmed.u.pstm = binding_stream;
    stgmed.pUnkForRelease = &unk_in.IUnknown_iface;
    unk_in.ref = 1;

    hres = IBindStatusCallback_OnDataAvailable(bsc, 1, 10, &formatetc, &stgmed);
    ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);

    ok(in_stgmed.tymed == TYMED_NULL, "tymed = %u\n", in_stgmed.tymed);
    ok(!in_stgmed.u.pstm, "pstm != NULL\n");
    ok(in_stgmed.pUnkForRelease != NULL, "pUnkForRelease = %p\n", in_stgmed.pUnkForRelease);
    ok(unk_in.ref == 1, "ref = %u\n", unk_in.ref);

    IStream_Release(binding_stream);
    IBindStatusCallback_Release(bsc);

    TerminateThread(thread, 0);
}

2649 2650
START_TEST(misc)
{
2651
    HMODULE hurlmon;
2652 2653 2654 2655
    int argc;
    char **argv;

    argc = winetest_get_mainargs(&argv);
2656

2657
    hurlmon = GetModuleHandleA("urlmon.dll");
2658
    pCoInternetCompareUrl = (void *) GetProcAddress(hurlmon, "CoInternetCompareUrl");
2659 2660 2661
    pCoInternetGetSecurityUrl = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrl");
    pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
    pCoInternetParseUrl = (void*) GetProcAddress(hurlmon, "CoInternetParseUrl");
2662 2663
    pCoInternetQueryInfo = (void*) GetProcAddress(hurlmon, "CoInternetQueryInfo");
    pCopyStgMedium = (void*) GetProcAddress(hurlmon, "CopyStgMedium");
2664
    pCopyBindInfo = (void*) GetProcAddress(hurlmon, "CopyBindInfo");
2665
    pFindMimeFromData = (void*) GetProcAddress(hurlmon, "FindMimeFromData");
2666 2667 2668
    pObtainUserAgentString = (void*) GetProcAddress(hurlmon, "ObtainUserAgentString");
    pReleaseBindInfo = (void*) GetProcAddress(hurlmon, "ReleaseBindInfo");
    pUrlMkGetSessionOption = (void*) GetProcAddress(hurlmon, "UrlMkGetSessionOption");
2669
    pCompareSecurityIds = (void*) GetProcAddress(hurlmon, "CompareSecurityIds");
2670
    pCoInternetIsFeatureEnabled = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureEnabled");
2671
    pCoInternetSetFeatureEnabled = (void*) GetProcAddress(hurlmon, "CoInternetSetFeatureEnabled");
2672
    pIEInstallScope = (void*) GetProcAddress(hurlmon, "IEInstallScope");
2673 2674

    if (!pCoInternetCompareUrl || !pCoInternetGetSecurityUrl ||
2675 2676
        !pCoInternetGetSession || !pCoInternetParseUrl || !pCompareSecurityIds) {
        win_skip("Various needed functions not present, too old IE\n");
2677
        return;
2678 2679
    }

2680 2681
    OleInitialize(NULL);

2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699
    if(argc <= 2 || strcmp(argv[2], "internet_features")) {
        register_protocols();

        test_CreateFormatEnum();
        test_RegisterFormatEnumerator();
        test_CoInternetParseUrl();
        test_CoInternetCompareUrl();
        test_CoInternetQueryInfo();
        test_FindMimeFromData();
        test_NameSpace();
        test_MimeFilter();
        test_ReleaseBindInfo();
        test_CopyStgMedium();
        test_CopyBindInfo();
        test_UrlMkGetSessionOption();
        test_user_agent();
        test_MkParseDisplayNameEx();
        test_IsValidURL();
2700
        test_bsc_marshaling();
2701 2702
    }

2703
    test_internet_features();
2704 2705

    OleUninitialize();
2706
}