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};
212 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
215 static const WCHAR wszRes[] = {'r','e','s',0};
216 static const WCHAR wszFile[] = {'f','i','l','e',0};
217 static const WCHAR wszEmpty[] = {0};
225 static const struct parse_test parse_tests[] = {
226 {url1, url1, wszRes},
227 {url2, url2, wszEmpty},
228 {url3, url3, wszFile},
229 {url4, url4e, wszFile}
232 static void test_CoInternetParseUrl(void)
238 static WCHAR buf[4096];
240 memset(buf, 0xf0, sizeof(buf));
241 hres = CoInternetParseUrl(parse_tests[0].url, PARSE_SCHEMA, 0, buf,
243 ok(hres == E_POINTER, "schema failed: %08lx, expected E_POINTER\n", hres);
245 for(i=0; i < sizeof(parse_tests)/sizeof(parse_tests[0]); i++) {
246 memset(buf, 0xf0, sizeof(buf));
247 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_ENCODE, 0, buf,
248 sizeof(buf)/sizeof(WCHAR), &size, 0);
249 ok(hres == S_OK, "[%d] encoding failed: %08lx\n", i, hres);
250 ok(size == lstrlenW(parse_tests[i].encoded_url), "[%d] wrong size\n", i);
251 ok(!lstrcmpW(parse_tests[i].encoded_url, buf), "[%d] wrong encoded url\n", i);
253 memset(buf, 0xf0, sizeof(buf));
254 hres = CoInternetParseUrl(parse_tests[i].url, PARSE_SCHEMA, 0, buf,
255 sizeof(buf)/sizeof(WCHAR), &size, 0);
256 ok(hres == S_OK, "[%d] schema failed: %08lx\n", i, hres);
257 ok(size == lstrlenW(parse_tests[i].schema), "[%d] wrong size\n", i);
258 ok(!lstrcmpW(parse_tests[i].schema, buf), "[%d] wrong schema\n", i);
264 test_CreateFormatEnum();
265 test_RegisterFormatEnumerator();
266 test_CoInternetParseUrl();