2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <wine/test.h>
29 static void test_CreateFormatEnum(void)
31 IEnumFORMATETC *fenum = NULL, *fenum2 = NULL;
36 static DVTARGETDEVICE dev = {sizeof(dev),0,0,0,0,{0}};
37 static FORMATETC formatetc[] = {
45 hres = CreateFormatEnumerator(0, formatetc, &fenum);
46 ok(hres == E_FAIL, "CreateFormatEnumerator failed: %08lx, expected E_FAIL\n", hres);
47 hres = CreateFormatEnumerator(0, formatetc, NULL);
48 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
49 hres = CreateFormatEnumerator(5, formatetc, NULL);
50 ok(hres == E_INVALIDARG, "CreateFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
53 hres = CreateFormatEnumerator(5, formatetc, &fenum);
54 ok(hres == S_OK, "CreateFormatEnumerator failed: %08lx\n", hres);
58 hres = IEnumFORMATETC_Next(fenum, 2, NULL, &ul);
59 ok(hres == E_INVALIDARG, "Next failed: %08lx, expected E_INVALIDARG\n", hres);
61 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
62 ok(hres == S_OK, "Next failed: %08lx\n", hres);
63 ok(ul == 0, "ul=%ld, expected 0\n", ul);
65 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
66 ok(hres == S_OK, "Next failed: %08lx\n", hres);
67 ok(fetc[0].lindex == 0, "fetc[0].lindex=%ld, expected 0\n", fetc[0].lindex);
68 ok(fetc[1].lindex == 1, "fetc[1].lindex=%ld, expected 1\n", fetc[1].lindex);
69 ok(fetc[0].ptd == &dev, "fetc[0].ptd=%p, expected %p\n", fetc[0].ptd, &dev);
70 ok(ul == 2, "ul=%ld, expected 2\n", ul);
72 hres = IEnumFORMATETC_Skip(fenum, 1);
73 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
75 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
76 ok(hres == S_FALSE, "Next failed: %08lx, expected S_FALSE\n", hres);
77 ok(fetc[0].lindex == 3, "fetc[0].lindex=%ld, expected 3\n", fetc[0].lindex);
78 ok(fetc[1].lindex == 4, "fetc[1].lindex=%ld, expected 4\n", fetc[1].lindex);
79 ok(fetc[0].ptd == NULL, "fetc[0].ptd=%p, expected NULL\n", fetc[0].ptd);
80 ok(ul == 2, "ul=%ld, expected 2\n", ul);
82 hres = IEnumFORMATETC_Next(fenum, 4, fetc, &ul);
83 ok(hres == S_FALSE, "Next failed: %08lx, expected S_FALSE\n", hres);
84 ok(ul == 0, "ul=%ld, expected 0\n", ul);
86 hres = IEnumFORMATETC_Next(fenum, 0, fetc, &ul);
87 ok(hres == S_OK, "Next failed: %08lx\n", hres);
88 ok(ul == 0, "ul=%ld, expected 0\n", ul);
90 hres = IEnumFORMATETC_Skip(fenum, 3);
91 ok(hres == S_FALSE, "Skip failed: %08lx, expected S_FALSE\n", hres);
93 hres = IEnumFORMATETC_Reset(fenum);
94 ok(hres == S_OK, "Reset failed: %08lx\n", hres);
96 hres = IEnumFORMATETC_Next(fenum, 5, fetc, NULL);
97 ok(hres == S_OK, "Next failed: %08lx\n", hres);
98 ok(fetc[0].lindex == 0, "fetc[0].lindex=%ld, expected 0\n", fetc[0].lindex);
100 hres = IEnumFORMATETC_Reset(fenum);
101 ok(hres == S_OK, "Reset failed: %08lx\n", hres);
103 hres = IEnumFORMATETC_Skip(fenum, 2);
104 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
106 hres = IEnumFORMATETC_Clone(fenum, NULL);
107 ok(hres == E_INVALIDARG, "Clone failed: %08lx, expected E_INVALIDARG\n", hres);
109 hres = IEnumFORMATETC_Clone(fenum, &fenum2);
110 ok(hres == S_OK, "Clone failed: %08lx\n", hres);
112 if(SUCCEEDED(hres)) {
113 ok(fenum != fenum2, "fenum == fenum2\n");
115 hres = IEnumFORMATETC_Next(fenum2, 2, fetc, &ul);
116 ok(hres == S_OK, "Next failed: %08lx\n", hres);
117 ok(fetc[0].lindex == 2, "fetc[0].lindex=%ld, expected 2\n", fetc[0].lindex);
119 IEnumFORMATETC_Release(fenum2);
122 hres = IEnumFORMATETC_Next(fenum, 2, fetc, &ul);
123 ok(hres == S_OK, "Next failed: %08lx\n", hres);
124 ok(fetc[0].lindex == 2, "fetc[0].lindex=%ld, expected 2\n", fetc[0].lindex);
126 hres = IEnumFORMATETC_Skip(fenum, 1);
127 ok(hres == S_OK, "Skip failed: %08lx\n", hres);
129 IEnumFORMATETC_Release(fenum);
132 static void test_RegisterFormatEnumerator(void)
134 IBindCtx *bctx = NULL;
135 IEnumFORMATETC *format = NULL, *format2 = NULL;
136 IUnknown *unk = NULL;
139 static FORMATETC formatetc = {0,NULL,0,0,0};
140 static WCHAR wszEnumFORMATETC[] =
141 {'_','E','n','u','m','F','O','R','M','A','T','E','T','C','_',0};
143 CreateBindCtx(0, &bctx);
145 hres = CreateFormatEnumerator(1, &formatetc, &format);
146 ok(hres == S_OK, "CreateFormatEnumerator failed: %08lx\n", hres);
150 hres = RegisterFormatEnumerator(NULL, format, 0);
151 ok(hres == E_INVALIDARG,
152 "RegisterFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
153 hres = RegisterFormatEnumerator(bctx, NULL, 0);
154 ok(hres == E_INVALIDARG,
155 "RegisterFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
157 hres = RegisterFormatEnumerator(bctx, format, 0);
158 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08lx\n", hres);
160 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
161 ok(hres == S_OK, "GetObjectParam failed: %08lx\n", hres);
162 ok(unk == (IUnknown*)format, "unk != format\n");
164 hres = RevokeFormatEnumerator(NULL, format);
165 ok(hres == E_INVALIDARG,
166 "RevokeFormatEnumerator failed: %08lx, expected E_INVALIDARG\n", hres);
168 hres = RevokeFormatEnumerator(bctx, format);
169 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08lx\n", hres);
171 hres = RevokeFormatEnumerator(bctx, format);
172 ok(hres == E_FAIL, "RevokeFormatEnumerator failed: %08lx, expected E_FAIL\n", hres);
174 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
175 ok(hres == E_FAIL, "GetObjectParam failed: %08lx, expected E_FAIL\n", hres);
177 hres = RegisterFormatEnumerator(bctx, format, 0);
178 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08lx\n", hres);
180 hres = CreateFormatEnumerator(1, &formatetc, &format2);
181 ok(hres == S_OK, "CreateFormatEnumerator failed: %08lx\n", hres);
183 if(SUCCEEDED(hres)) {
184 hres = RevokeFormatEnumerator(bctx, format);
185 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08lx\n", hres);
187 IEnumFORMATETC_Release(format2);
190 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
191 ok(hres == E_FAIL, "GetObjectParam failed: %08lx, expected E_FAIL\n", hres);
193 IEnumFORMATETC_Release(format);
195 hres = RegisterFormatEnumerator(bctx, format, 0);
196 ok(hres == S_OK, "RegisterFormatEnumerator failed: %08lx\n", hres);
197 hres = RevokeFormatEnumerator(bctx, NULL);
198 ok(hres == S_OK, "RevokeFormatEnumerator failed: %08lx\n", hres);
199 hres = IBindCtx_GetObjectParam(bctx, wszEnumFORMATETC, &unk);
200 ok(hres == E_FAIL, "GetObjectParam failed: %08lx, expected E_FAIL\n", hres);
202 IBindCtx_Release(bctx);
205 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
206 '/','b','l','a','n','k','.','h','t','m',0};
207 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
208 static const WCHAR url3[] = {'f','i','l','e',':','c',':','\\','I','n','d','e','x','.','h','t','m',0};
209 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
210 '%','2','e','j','p','g',0};
211 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q',
213 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
214 static const WCHAR url7[] = {'f','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g','/',
215 'f','i','l','e','.','t','e','s','t',0};
217 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
220 static const WCHAR path3[] = {'c',':','\\','I','n','d','e','x','.','h','t','m',0};
221 static const WCHAR path4[] = {'s','o','m','e',' ','f','i','l','e','.','j','p','g',0};
223 static const WCHAR wszRes[] = {'r','e','s',0};
224 static const WCHAR wszFile[] = {'f','i','l','e',0};
225 static const WCHAR wszHttp[] = {'h','t','t','p',0};
226 static const WCHAR wszAbout[] = {'a','b','o','u','t',0};
227 static const WCHAR wszEmpty[] = {0};
238 static const struct parse_test parse_tests[] = {
239 {url1, S_OK, url1, E_INVALIDARG, NULL, wszRes},
240 {url2, E_FAIL, url2, E_INVALIDARG, NULL, wszEmpty},
241 {url3, E_FAIL, url3, S_OK, path3, wszFile},
242 {url4, E_FAIL, url4e, S_OK, path4, wszFile},
243 {url5, E_FAIL, url5, E_INVALIDARG, NULL, wszHttp},
244 {url6, S_OK, url6, E_INVALIDARG, NULL, wszAbout}
247 static void test_CoInternetParseUrl(void)
253 static WCHAR buf[4096];
255 memset(buf, 0xf0, sizeof(buf));
256 hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
258 ok(hres == E_POINTER, "schema failed: %08lx, expected E_POINTER\n", hres);
260 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
261 memset(buf, 0xf0, sizeof(buf));
262 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SECURITY_URL, 0, buf,
263 sizeof(buf)/sizeof(WCHAR), &size, 0);
264 ok(hres == parse_tests[i].secur_hres, "[%d] security url failed: %08lx, expected %08lx\n",
265 i, hres, parse_tests[i].secur_hres);
267 memset(buf, 0xf0, sizeof(buf));
268 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
269 sizeof(buf)/sizeof(WCHAR), &size, 0);
270 ok(hres == S_OK, "[%d] encoding failed: %08lx\n", i, hres);
271 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
272 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
274 memset(buf, 0xf0, sizeof(buf));
275 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_PATH_FROM_URL, 0, buf,
276 sizeof(buf)/sizeof(WCHAR), &size, 0);
277 ok(hres == parse_tests[i].path_hres, "[%d] path failed: %08lx, expected %08lx\n",
278 i, hres, parse_tests[i].path_hres);
279 if(parse_tests[i].path) {
280 ok(size == lstrlenW(parse_tests[i].path), "[%d] wrong size\n", i);
281 ok(!lstrcmpW(parse_tests[i].path, buf), "[%d] wrong path\n", i);
284 memset(buf, 0xf0, sizeof(buf));
285 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
286 sizeof(buf)/sizeof(WCHAR), &size, 0);
287 ok(hres == S_OK, "[%d] schema failed: %08lx\n", i, hres);
288 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
289 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
293 static const WCHAR mimeTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
294 static const WCHAR mimeTextPlain[] = {'t','e','x','t','/','p','l','a','i','n',0};
295 static const WCHAR mimeAppOctetStream[] = {'a','p','p','l','i','c','a','t','i','o','n','/',
296 'o','c','t','e','t','-','s','t','r','e','a','m',0};
298 static const struct {
302 {url1, mimeTextHtml},
303 {url2, mimeTextHtml},
304 {url3, mimeTextHtml},
311 static BYTE data1[] = "test data\n";
312 static BYTE data2[] = {31,'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0};
313 static BYTE data3[] = {0,0,0};
314 static BYTE data4[] = {'t','e','s',0xfa,'t',' ','d','a','t','a','\n',0,0};
315 static BYTE data5[] = {0xa,0xa,0xa,'x',32,'x',0};
316 static BYTE data6[] = {0xfa,0xfa,0xfa,0xfa,'\n','\r','\t','x','x','x',1};
318 static const struct {
323 {data1, sizeof(data1), mimeTextPlain},
324 {data2, sizeof(data2), mimeAppOctetStream},
325 {data3, sizeof(data3), mimeAppOctetStream},
326 {data4, sizeof(data4), mimeAppOctetStream},
327 {data5, sizeof(data5), mimeTextPlain},
328 {data6, sizeof(data6), mimeTextPlain}
331 static void test_FindMimeFromData(void)
337 for(i=0; i<sizeof(mime_tests)/sizeof(mime_tests[0]); i++) {
338 mime = (LPWSTR)0xf0f0f0f0;
339 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, NULL, 0, &mime, 0);
340 if(mime_tests[i].mime) {
341 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
342 ok(!lstrcmpW(mime, mime_tests[i].mime), "[%d] wrong mime\n", i);
345 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
346 ok(mime == (LPWSTR)0xf0f0f0f0, "[%d] mime != 0xf0f0f0f0\n", i);
349 mime = (LPWSTR)0xf0f0f0f0;
350 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeTextPlain, 0, &mime, 0);
351 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
352 ok(!lstrcmpW(mime, mimeTextPlain), "[%d] wrong mime\n", i);
355 mime = (LPWSTR)0xf0f0f0f0;
356 hres = FindMimeFromData(NULL, mime_tests[i].url, NULL, 0, mimeAppOctetStream, 0, &mime, 0);
357 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
358 ok(!lstrcmpW(mime, mimeAppOctetStream), "[%d] wrong mime\n", i);
362 for(i=0; i < sizeof(mime_tests2)/sizeof(mime_tests2[0]); i++) {
363 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
365 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
366 ok(!lstrcmpW(mime, mime_tests2[i].mime), "[%d] wrong mime\n", i);
369 hres = FindMimeFromData(NULL, NULL, mime_tests2[i].data, mime_tests2[i].size,
370 mimeTextHtml, 0, &mime, 0);
371 ok(hres == S_OK, "[%d] FindMimeFromData failed: %08lx\n", i, hres);
372 ok(!lstrcmpW(mime, mimeTextHtml), "[%d] wrong mime\n", i);
376 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), NULL, 0, &mime, 0);
377 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
378 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
381 hres = FindMimeFromData(NULL, url1, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
382 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
383 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
386 hres = FindMimeFromData(NULL, url4, data1, sizeof(data1), mimeAppOctetStream, 0, &mime, 0);
387 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
388 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
391 hres = FindMimeFromData(NULL, NULL, NULL, 0, NULL, 0, &mime, 0);
392 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, excepted E_INVALIDARG\n", hres);
394 hres = FindMimeFromData(NULL, NULL, NULL, 0, mimeTextPlain, 0, &mime, 0);
395 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
397 hres = FindMimeFromData(NULL, NULL, data1, 0, NULL, 0, &mime, 0);
398 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
400 hres = FindMimeFromData(NULL, url1, data1, 0, NULL, 0, &mime, 0);
401 ok(hres == E_FAIL, "FindMimeFromData failed: %08lx, expected E_FAIL\n", hres);
403 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, &mime, 0);
404 ok(hres == S_OK, "FindMimeFromData failed: %08lx\n", hres);
405 ok(!lstrcmpW(mime, mimeTextPlain), "wrong mime\n");
408 hres = FindMimeFromData(NULL, NULL, data1, 0, mimeTextPlain, 0, NULL, 0);
409 ok(hres == E_INVALIDARG, "FindMimeFromData failed: %08lx, expected E_INVALIDARG\n", hres);
412 static struct secmgr_test {
418 {url2, 100, 0x80041001},
426 static void test_SecurityManager(void)
429 IInternetSecurityManager *secmgr = NULL;
433 hres = CoInternetCreateSecurityManager(NULL, &secmgr, 0);
434 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08lx\n", hres);
438 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
440 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url, &zone, 0);
441 ok(hres == secmgr_tests[i].zone_hres, "[%d] MapUrlToZone failed: %08lx, expected %08lx\n",
442 i, hres, secmgr_tests[i].zone_hres);
443 ok(zone == secmgr_tests[i].zone, "[%d] zone=%ld, expected %ld\n", i, zone,
444 secmgr_tests[i].zone);
448 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
449 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08lx, expected E_INVALIDARG\n", hres);
451 IInternetSecurityManager_Release(secmgr);
454 static void test_ZoneManager(void)
456 IInternetZoneManager *zonemgr = NULL;
460 hres = CoInternetCreateZoneManager(NULL, &zonemgr, 0);
461 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08lx\n", hres);
465 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
466 sizeof(DWORD), URLZONEREG_DEFAULT);
467 ok(hres == S_OK, "GetZoneActionPolicy failed: %08lx\n", hres);
468 ok(*(DWORD*)buf == 1, "policy=%ld, expected 1\n", *(DWORD*)buf);
470 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, NULL,
471 sizeof(DWORD), URLZONEREG_DEFAULT);
472 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
474 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1a10, buf,
475 2, URLZONEREG_DEFAULT);
476 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
478 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
479 sizeof(DWORD), URLZONEREG_DEFAULT);
480 ok(hres == E_FAIL, "GetZoneActionPolicy failed: %08lx, expected E_FAIL\n", hres);
482 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, 0x1a10, buf,
483 sizeof(DWORD), URLZONEREG_DEFAULT);
484 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08lx, expected E_INVALIDARG\n", hres);
486 IInternetZoneManager_Release(zonemgr);
491 test_CreateFormatEnum();
492 test_RegisterFormatEnumerator();
493 test_CoInternetParseUrl();
494 test_FindMimeFromData();
495 test_SecurityManager();