[SHLWAPI_WINETEST]
[reactos.git] / rostests / winetests / shlwapi / url.c
1 /* Unit test suite for Path functions
2 *
3 * Copyright 2002 Matthew Mastracci
4 * Copyright 2007-2010 Detlef Riekenberg
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "wine/test.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "shlwapi.h"
29 #include "wininet.h"
30 #include "intshcut.h"
31
32 /* ################ */
33 static HMODULE hShlwapi;
34 static HRESULT (WINAPI *pUrlUnescapeA)(LPSTR,LPSTR,LPDWORD,DWORD);
35 static HRESULT (WINAPI *pUrlUnescapeW)(LPWSTR,LPWSTR,LPDWORD,DWORD);
36 static BOOL (WINAPI *pUrlIsA)(LPCSTR,URLIS);
37 static BOOL (WINAPI *pUrlIsW)(LPCWSTR,URLIS);
38 static HRESULT (WINAPI *pUrlHashA)(LPCSTR,LPBYTE,DWORD);
39 static HRESULT (WINAPI *pUrlHashW)(LPCWSTR,LPBYTE,DWORD);
40 static HRESULT (WINAPI *pUrlGetPartA)(LPCSTR,LPSTR,LPDWORD,DWORD,DWORD);
41 static HRESULT (WINAPI *pUrlGetPartW)(LPCWSTR,LPWSTR,LPDWORD,DWORD,DWORD);
42 static HRESULT (WINAPI *pUrlEscapeA)(LPCSTR,LPSTR,LPDWORD,DWORD);
43 static HRESULT (WINAPI *pUrlEscapeW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
44 static HRESULT (WINAPI *pUrlCreateFromPathA)(LPCSTR,LPSTR,LPDWORD,DWORD);
45 static HRESULT (WINAPI *pUrlCreateFromPathW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
46 static HRESULT (WINAPI *pUrlCombineA)(LPCSTR,LPCSTR,LPSTR,LPDWORD,DWORD);
47 static HRESULT (WINAPI *pUrlCombineW)(LPCWSTR,LPCWSTR,LPWSTR,LPDWORD,DWORD);
48 static HRESULT (WINAPI *pUrlCanonicalizeA)(LPCSTR, LPSTR, LPDWORD, DWORD);
49 static HRESULT (WINAPI *pUrlCanonicalizeW)(LPCWSTR, LPWSTR, LPDWORD, DWORD);
50 static HRESULT (WINAPI *pUrlApplySchemeA)(LPCSTR,LPSTR,LPDWORD,DWORD);
51 static HRESULT (WINAPI *pUrlApplySchemeW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
52 static HRESULT (WINAPI *pParseURLA)(LPCSTR,PARSEDURLA*);
53 static HRESULT (WINAPI *pParseURLW)(LPCWSTR,PARSEDURLW*);
54 static HRESULT (WINAPI *pHashData)(LPBYTE, DWORD, LPBYTE, DWORD);
55
56 static const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
57 static const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
58 static const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
59 static const WCHAR winehqW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
60 static const CHAR winehqA[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
61
62 /* ################ */
63
64 static const CHAR untouchedA[] = "untouched";
65
66 #define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
67
68 typedef struct _TEST_URL_APPLY {
69 const char * url;
70 DWORD flags;
71 HRESULT res;
72 DWORD newlen;
73 const char * newurl;
74 } TEST_URL_APPLY;
75
76 static const TEST_URL_APPLY TEST_APPLY[] = {
77 {"www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
78 {"www.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 21, "http://www.winehq.org"},
79 {"www.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
80 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 20, "ftp://ftp.winehq.org"},
81 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 20, "ftp://ftp.winehq.org"},
82 {"ftp.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://ftp.winehq.org"},
83 {"winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
84 {"winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
85 {"winehq.org", URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
86 {"", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 7, "http://"},
87 {"", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
88 {"", URL_APPLY_DEFAULT, S_OK, 7, "http://"}
89 };
90
91 /* ################ */
92
93 typedef struct _TEST_URL_CANONICALIZE {
94 const char *url;
95 DWORD flags;
96 HRESULT expectret;
97 const char *expecturl;
98 BOOL todo;
99 } TEST_URL_CANONICALIZE;
100
101 static const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
102 {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/", TRUE},
103 {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
104 {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
105 {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
106 {"http://www.winehq.org/tests\r", 0, S_OK, "http://www.winehq.org/tests", FALSE},
107 {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests", FALSE},
108 {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/", FALSE},
109 {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
110 {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
111 {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
112 {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
113 {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
114 {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
115 {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
116 {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
117 {"http://www.winehq.org/tests\\../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
118 {"http://www.winehq.org/tests/..\\#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
119 {"http://www.winehq.org\\tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
120 {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example", FALSE},
121 {"http://www.winehq.org/tests/foo bar", URL_ESCAPE_SPACES_ONLY| URL_DONT_ESCAPE_EXTRA_INFO , S_OK, "http://www.winehq.org/tests/foo%20bar", FALSE},
122 {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE , S_OK, "http://www.winehq.org/tests/foo bar", FALSE},
123 {"file:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
124 {"file:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
125 {"file:///c:/tests/foo%20bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
126 {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
127 {"file://localhost/c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
128 {"file://localhost\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
129 {"file://localhost\\\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
130 {"file://localhost\\c:\\tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
131 {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
132 {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
133 {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
134 {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar", FALSE},
135 {"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar", FALSE},
136 {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar", FALSE},
137 {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about", FALSE},
138 {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about", FALSE},
139 {"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
140 {"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
141 {"c:dir\\file", 0, S_OK, "file:///c:dir/file", FALSE},
142 {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
143 {"c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
144 {"res://file", 0, S_OK, "res://file/", FALSE},
145 {"res://file", URL_FILE_USE_PATHURL, S_OK, "res://file/", FALSE},
146 {"res:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests/foo bar", FALSE},
147 {"res:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests\\foo bar", FALSE},
148 {"res:///c:/tests/foo%20bar", 0, S_OK, "res:///c:/tests/foo%20bar", FALSE},
149 {"res:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c:/tests/foo%20bar", FALSE},
150 {"res://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
151 {"res://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
152 {"res://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
153 {"res:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c://tests/foo%20bar", FALSE},
154 {"res:///c:\\tests\\foo bar", 0, S_OK, "res:///c:\\tests\\foo bar", FALSE},
155 {"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "res:///c:\\tests\\foo bar", FALSE},
156 {"res://c:\\tests\\foo bar/res", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests\\foo bar/res", FALSE},
157 {"res://c:\\tests/res\\foo%20bar/strange\\sth", 0, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
158 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
159 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_UNESCAPE, S_OK, "res://c:\\tests/res\\foo bar/strange\\sth", FALSE},
160 {"A", 0, S_OK, "A", FALSE},
161 {"/uri-res/N2R?urn:sha1:B3K", URL_DONT_ESCAPE_EXTRA_INFO | URL_WININET_COMPATIBILITY /*0x82000000*/, S_OK, "/uri-res/N2R?urn:sha1:B3K", FALSE} /*LimeWire online installer calls this*/,
162 {"http:www.winehq.org/dir/../index.html", 0, S_OK, "http:www.winehq.org/index.html"},
163 };
164
165 /* ################ */
166
167 typedef struct _TEST_URL_ESCAPE {
168 const char *url;
169 DWORD flags;
170 DWORD expectescaped;
171 HRESULT expectret;
172 const char *expecturl;
173 } TEST_URL_ESCAPE;
174
175 static const TEST_URL_ESCAPE TEST_ESCAPE[] = {
176 {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"},
177 {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"},
178 {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"},
179 {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"},
180 {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"},
181 {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"},
182 {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
183
184 {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
185 {"file://///foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
186 {"file:////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
187 {"file:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
188 {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
189 {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
190 {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
191 {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
192 {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
193 {"file:foo/bar\\baz", 0, 0, S_OK, "file:foo/bar/baz"},
194 {"file:\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
195 {"file:\\\\foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
196 {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
197 {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
198 {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"},
199 {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"},
200 {"file:///f o^&`{}|][\"<>\\%o/b#a r\\baz", 0, 0, S_OK, "file:///f%20o%5E%26%60%7B%7D%7C%5D%5B%22%3C%3E/%o/b%23a%20r/baz"},
201 {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"},
202 {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"},
203
204 {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"},
205 {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"},
206 {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"},
207 {"/foo/bar\\ba?z\\", 0, 0, S_OK, "/foo/bar%5Cba?z\\"},
208 {"/foo/bar\\ba#z\\", 0, 0, S_OK, "/foo/bar%5Cba#z\\"},
209 {"/foo/%5C", 0, 0, S_OK, "/foo/%5C"},
210 {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"},
211
212 {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"},
213 {"http://///foo/bar\\baz", 0, 0, S_OK, "http://///foo/bar/baz"},
214 {"http:////foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
215 {"http:///foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
216 {"http://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"},
217 {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
218 {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
219 {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"},
220 {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"},
221 {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
222 {"http:\\\\foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
223 {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
224 {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
225 {"http:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"},
226 {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"},
227 {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"},
228
229 {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"},
230 {"https:/foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
231 {"https:\\foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
232
233 {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"},
234 {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"},
235 {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"},
236 {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://foo/bar%5Cbaz"},
237 {"foo:/foo/bar\\baz", 0, 0, S_OK, "foo:/foo/bar%5Cbaz"},
238 {"foo:foo/bar\\baz", 0, 0, S_OK, "foo:foo%2Fbar%5Cbaz"},
239 {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"},
240 {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"},
241 {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"},
242
243 {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
244 {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
245 {"mailto:fo/o@b\\%a?\\r.b#\\az", URL_ESCAPE_PERCENT, 0, S_OK, "mailto:fo%2Fo@b%5C%25a%3F%5Cr.b%23%5Caz"},
246
247 {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
248 {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"},
249 {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"},
250 {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"},
251 {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"},
252 {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"},
253 {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"}
254 };
255
256 /* ################ */
257
258 typedef struct _TEST_URL_COMBINE {
259 const char *url1;
260 const char *url2;
261 DWORD flags;
262 HRESULT expectret;
263 const char *expecturl;
264 } TEST_URL_COMBINE;
265
266 static const TEST_URL_COMBINE TEST_COMBINE[] = {
267 {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
268 {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
269 /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
270 {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"},
271 {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"},
272 {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"},
273 {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"},
274 {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"},
275 {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"},
276 {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"},
277 {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"},
278 {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."},
279 {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"},
280 {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"},
281 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK, "file:///C:/Test/test.txt"},
282 {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"},
283 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"},
284 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"},
285 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"},
286 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
287 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
288 {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"},
289 {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"},
290 {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"},
291 {"foo:/today/", "foo:calendar", 0, S_OK, "foo:/today/calendar"},
292 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
293 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
294 /* UrlCombine case 2 tests. Schemes do not match */
295 {"outbind://xxxxxxxxx","http://wine1/dir",0, S_OK,"http://wine1/dir"},
296 {"xxxx://xxxxxxxxx","http://wine2/dir",0, S_OK,"http://wine2/dir"},
297 {"ftp://xxxxxxxxx/","http://wine3/dir",0, S_OK,"http://wine3/dir"},
298 {"outbind://xxxxxxxxx","http://wine4/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine4/dir"},
299 {"xxx://xxxxxxxxx","http://wine5/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine5/dir"},
300 {"ftp://xxxxxxxxx/","http://wine6/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine6/dir"},
301 {"http://xxxxxxxxx","outbind://wine7/dir",0, S_OK,"outbind://wine7/dir"},
302 {"xxx://xxxxxxxxx","ftp://wine8/dir",0, S_OK,"ftp://wine8/dir"},
303 {"ftp://xxxxxxxxx/","xxx://wine9/dir",0, S_OK,"xxx://wine9/dir"},
304 {"http://xxxxxxxxx","outbind://wine10/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind://wine10/dir"},
305 {"xxx://xxxxxxxxx","ftp://wine11/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp://wine11/dir"},
306 {"ftp://xxxxxxxxx/","xxx://wine12/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx://wine12/dir"},
307 {"http://xxxxxxxxx","outbind:wine13/dir",0, S_OK,"outbind:wine13/dir"},
308 {"xxx://xxxxxxxxx","ftp:wine14/dir",0, S_OK,"ftp:wine14/dir"},
309 {"ftp://xxxxxxxxx/","xxx:wine15/dir",0, S_OK,"xxx:wine15/dir"},
310 {"outbind://xxxxxxxxx/","http:wine16/dir",0, S_OK,"http:wine16/dir"},
311 {"http://xxxxxxxxx","outbind:wine17/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind:wine17/dir"},
312 {"xxx://xxxxxxxxx","ftp:wine18/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp:wine18/dir"},
313 {"ftp://xxxxxxxxx/","xxx:wine19/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx:wine19/dir"},
314 {"outbind://xxxxxxxxx/","http:wine20/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http:wine20/dir"},
315 {"file:///c:/dir/file.txt","index.html?test=c:/abc",URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,S_OK,"file:///c:/dir/index.html?test=c:/abc"}
316 };
317
318 /* ################ */
319
320 static const struct {
321 const char *path;
322 const char *url;
323 DWORD ret;
324 } TEST_URLFROMPATH [] = {
325 {"foo", "file:foo", S_OK},
326 {"foo\\bar", "file:foo/bar", S_OK},
327 {"\\foo\\bar", "file:///foo/bar", S_OK},
328 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK},
329 {"c:foo\\bar", "file:///c:foo/bar", S_OK},
330 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK},
331 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK},
332 #if 0
333 /* The following test fails on native shlwapi as distributed with Win95/98.
334 * Wine matches the behaviour of later versions.
335 */
336 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE}
337 #endif
338 };
339
340 /* ################ */
341
342 static struct {
343 char url[30];
344 const char *expect;
345 } TEST_URL_UNESCAPE[] = {
346 {"file://foo/bar", "file://foo/bar"},
347 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
348 {"file://%24%25foobar", "file://$%foobar"}
349 };
350
351 /* ################ */
352
353 static const struct {
354 const char *path;
355 BOOL expect;
356 } TEST_PATH_IS_URL[] = {
357 {"http://foo/bar", TRUE},
358 {"c:\\foo\\bar", FALSE},
359 {"foo://foo/bar", TRUE},
360 {"foo\\bar", FALSE},
361 {"foo.bar", FALSE},
362 {"bogusscheme:", TRUE},
363 {"http:partial", TRUE}
364 };
365
366 /* ################ */
367
368 static const struct {
369 const char *url;
370 BOOL expectOpaque;
371 BOOL expectFile;
372 } TEST_URLIS_ATTRIBS[] = {
373 { "ftp:", FALSE, FALSE },
374 { "http:", FALSE, FALSE },
375 { "gopher:", FALSE, FALSE },
376 { "mailto:", TRUE, FALSE },
377 { "news:", FALSE, FALSE },
378 { "nntp:", FALSE, FALSE },
379 { "telnet:", FALSE, FALSE },
380 { "wais:", FALSE, FALSE },
381 { "file:", FALSE, TRUE },
382 { "mk:", FALSE, FALSE },
383 { "https:", FALSE, FALSE },
384 { "shell:", TRUE, FALSE },
385 { "https:", FALSE, FALSE },
386 { "snews:", FALSE, FALSE },
387 { "local:", FALSE, FALSE },
388 { "javascript:", TRUE, FALSE },
389 { "vbscript:", TRUE, FALSE },
390 { "about:", TRUE, FALSE },
391 { "res:", FALSE, FALSE },
392 { "bogusscheme:", FALSE, FALSE },
393 { "file:\\\\e:\\b\\c", FALSE, TRUE },
394 { "file://e:/b/c", FALSE, TRUE },
395 { "http:partial", FALSE, FALSE },
396 { "mailto://www.winehq.org/test.html", TRUE, FALSE },
397 { "file:partial", FALSE, TRUE }
398 };
399
400 /* ########################### */
401
402 static LPWSTR GetWideString(const char* szString)
403 {
404 LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
405
406 MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
407
408 return wszString;
409 }
410
411
412 static void FreeWideString(LPWSTR wszString)
413 {
414 HeapFree(GetProcessHeap(), 0, wszString);
415 }
416
417 /* ########################### */
418
419 static void test_UrlApplyScheme(void)
420 {
421 CHAR newurl[TEST_APPLY_MAX_LENGTH];
422 WCHAR urlW[TEST_APPLY_MAX_LENGTH];
423 WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
424 HRESULT res;
425 DWORD len;
426 DWORD i;
427
428 if (!pUrlApplySchemeA) {
429 win_skip("UrlApplySchemeA not found\n");
430 return;
431 }
432
433 for(i = 0; i < sizeof(TEST_APPLY)/sizeof(TEST_APPLY[0]); i++) {
434 len = TEST_APPLY_MAX_LENGTH;
435 lstrcpyA(newurl, untouchedA);
436 res = pUrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
437 ok( res == TEST_APPLY[i].res,
438 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
439
440 ok( len == TEST_APPLY[i].newlen,
441 "#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
442
443 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
444 "#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
445
446 /* returned length is in character */
447 len = TEST_APPLY_MAX_LENGTH;
448 lstrcpyA(newurl, untouchedA);
449 MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
450 MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
451
452 res = pUrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
453 WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
454 ok( res == TEST_APPLY[i].res,
455 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
456
457 ok( len == TEST_APPLY[i].newlen,
458 "#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
459
460 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
461 "#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
462
463 }
464
465 /* buffer too small */
466 lstrcpyA(newurl, untouchedA);
467 len = lstrlenA(TEST_APPLY[0].newurl);
468 res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, &len, TEST_APPLY[0].flags);
469 ok(res == E_POINTER, "got HRESULT 0x%x (expected E_POINTER)\n", res);
470 /* The returned length include the space for the terminating 0 */
471 i = lstrlenA(TEST_APPLY[0].newurl)+1;
472 ok(len == i, "got len %d (expected %d)\n", len, i);
473 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
474
475 /* NULL as parameter. The length and the buffer are not modified */
476 lstrcpyA(newurl, untouchedA);
477 len = TEST_APPLY_MAX_LENGTH;
478 res = pUrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
479 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
480 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
481 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
482
483 len = TEST_APPLY_MAX_LENGTH;
484 res = pUrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
485 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
486 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
487
488 lstrcpyA(newurl, untouchedA);
489 res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
490 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
491 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
492
493 }
494
495 /* ########################### */
496
497 static void hash_url(const char* szUrl)
498 {
499 LPCSTR szTestUrl = szUrl;
500 LPWSTR wszTestUrl = GetWideString(szTestUrl);
501 HRESULT res;
502
503 DWORD cbSize = sizeof(DWORD);
504 DWORD dwHash1, dwHash2;
505 res = pUrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize);
506 ok(res == S_OK, "UrlHashA returned 0x%x (expected S_OK) for %s\n", res, szUrl);
507 if (pUrlHashW) {
508 res = pUrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize);
509 ok(res == S_OK, "UrlHashW returned 0x%x (expected S_OK) for %s\n", res, szUrl);
510 ok(dwHash1 == dwHash2,
511 "Hashes didn't match (A: 0x%x, W: 0x%x) for %s\n", dwHash1, dwHash2, szUrl);
512 }
513 FreeWideString(wszTestUrl);
514
515 }
516
517 static void test_UrlHash(void)
518 {
519 if (!pUrlHashA) {
520 win_skip("UrlHashA not found\n");
521 return;
522 }
523
524 hash_url(TEST_URL_1);
525 hash_url(TEST_URL_2);
526 hash_url(TEST_URL_3);
527 }
528
529 /* ########################### */
530
531 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
532 {
533 CHAR szPart[INTERNET_MAX_URL_LENGTH];
534 WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
535 LPWSTR wszUrl = GetWideString(szUrl);
536 LPWSTR wszConvertedPart;
537 HRESULT res;
538 DWORD dwSize;
539
540 dwSize = INTERNET_MAX_URL_LENGTH;
541 res = pUrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags);
542 ok(res == S_OK,
543 "UrlGetPartA for \"%s\" part 0x%08x returned 0x%x and \"%s\"\n",
544 szUrl, dwPart, res, szPart);
545 if (pUrlGetPartW) {
546 dwSize = INTERNET_MAX_URL_LENGTH;
547 res = pUrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags);
548 ok(res == S_OK,
549 "UrlGetPartW for \"%s\" part 0x%08x returned 0x%x\n",
550 szUrl, dwPart, res);
551
552 wszConvertedPart = GetWideString(szPart);
553
554 ok(lstrcmpW(wszPart,wszConvertedPart)==0,
555 "Strings didn't match between ascii and unicode UrlGetPart!\n");
556
557 FreeWideString(wszConvertedPart);
558 }
559 FreeWideString(wszUrl);
560
561 /* Note that v6.0 and later don't return '?' with the query */
562 ok(strcmp(szPart,szExpected)==0 ||
563 (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
564 "Expected %s, but got %s\n", szExpected, szPart);
565 }
566
567 /* ########################### */
568
569 static void test_UrlGetPart(void)
570 {
571 const char* file_url = "file://h o s t/c:/windows/file";
572 const char* http_url = "http://user:pass 123@www.wine hq.org";
573 const char* about_url = "about:blank";
574
575 CHAR szPart[INTERNET_MAX_URL_LENGTH];
576 DWORD dwSize;
577 HRESULT res;
578
579 if (!pUrlGetPartA) {
580 win_skip("UrlGetPartA not found\n");
581 return;
582 }
583
584 dwSize = sizeof szPart;
585 szPart[0]='x'; szPart[1]=0;
586 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
587 todo_wine {
588 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
589 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
590 }
591 dwSize = sizeof szPart;
592 szPart[0]='x'; szPart[1]=0;
593 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0);
594 todo_wine {
595 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
596 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
597 }
598
599 test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
600 test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
601 test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
602 test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
603 test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
604 test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
605
606 test_url_part(file_url, URL_PART_HOSTNAME, 0, "h o s t");
607
608 test_url_part(http_url, URL_PART_HOSTNAME, 0, "www.wine hq.org");
609 test_url_part(http_url, URL_PART_PASSWORD, 0, "pass 123");
610
611 test_url_part(about_url, URL_PART_SCHEME, 0, "about");
612
613 dwSize = sizeof(szPart);
614 res = pUrlGetPartA(about_url, szPart, &dwSize, URL_PART_HOSTNAME, 0);
615 ok(res==E_FAIL, "returned %08x\n", res);
616
617 dwSize = sizeof(szPart);
618 res = pUrlGetPartA("file://c:\\index.htm", szPart, &dwSize, URL_PART_HOSTNAME, 0);
619 ok(res==S_FALSE, "returned %08x\n", res);
620
621 dwSize = sizeof(szPart);
622 szPart[0] = 'x'; szPart[1] = '\0';
623 res = pUrlGetPartA("file:some text", szPart, &dwSize, URL_PART_HOSTNAME, 0);
624 ok(res==S_FALSE, "returned %08x\n", res);
625 ok(szPart[0] == '\0', "szPart[0] = %c\n", szPart[0]);
626 ok(dwSize == 0, "dwSize = %d\n", dwSize);
627 }
628
629 /* ########################### */
630
631 static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
632 {
633 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
634 DWORD dwEscaped;
635 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
636 WCHAR *urlW, *expected_urlW;
637 dwEscaped=INTERNET_MAX_URL_LENGTH;
638
639 ok(pUrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn,
640 "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
641 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);
642
643 if (pUrlEscapeW) {
644 dwEscaped = INTERNET_MAX_URL_LENGTH;
645 urlW = GetWideString(szUrl);
646 expected_urlW = GetWideString(szExpectUrl);
647 ok(pUrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn,
648 "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
649 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
650 ok(lstrcmpW(ret_urlW, expected_urlW)==0,
651 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n",
652 szExpectUrl, szReturnUrl, szUrl, dwFlags);
653 FreeWideString(urlW);
654 FreeWideString(expected_urlW);
655 }
656 }
657
658 static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, HRESULT dwExpectReturnAlt, const char *szExpectUrl, BOOL todo)
659 {
660 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
661 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
662 LPWSTR wszUrl = GetWideString(szUrl);
663 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
664 LPWSTR wszConvertedUrl;
665 HRESULT ret;
666
667 DWORD dwSize;
668
669 dwSize = INTERNET_MAX_URL_LENGTH;
670 ret = pUrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags);
671 ok(ret != dwExpectReturn, "got 0s%x: Unexpected return for NULL buffer, index %d\n", ret, index);
672 ret = pUrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags);
673 ok(ret == dwExpectReturn || ret == dwExpectReturnAlt,
674 "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
675 dwExpectReturn, dwExpectReturnAlt, ret, index);
676 if (todo)
677 todo_wine
678 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
679 else
680 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
681
682 if (pUrlCanonicalizeW) {
683 dwSize = INTERNET_MAX_URL_LENGTH;
684 ret = pUrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags);
685 ok(ret != dwExpectReturn, "got 0x%x: Unexpected return for NULL buffer, index %d\n", ret, index);
686 ret = pUrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags);
687 ok(ret == dwExpectReturn, "UrlCanonicalizeW failed: expected 0x%08x, got 0x%x, index %d\n",
688 dwExpectReturn, ret, index);
689
690 wszConvertedUrl = GetWideString(szReturnUrl);
691 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0,
692 "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
693 FreeWideString(wszConvertedUrl);
694 }
695
696 FreeWideString(wszUrl);
697 FreeWideString(wszExpectUrl);
698 }
699
700
701 static void test_UrlEscape(void)
702 {
703 DWORD size = 0;
704 HRESULT ret;
705 unsigned int i;
706 char empty_string[] = "";
707
708 if (!pUrlEscapeA) {
709 win_skip("UrlEscapeA noz found\n");
710 return;
711 }
712
713 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
714 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
715 ok(size == 0, "got %d, expected %d\n", size, 0);
716
717 size = 0;
718 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
719 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
720 ok(size == 0, "got %d, expected %d\n", size, 0);
721
722 size = 1;
723 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
724 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
725 ok(size == 1, "got %d, expected %d\n", size, 1);
726
727 size = 1;
728 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
729 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
730 ok(size == 1, "got %d, expected %d\n", size, 1);
731
732 size = 1;
733 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
734 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
735 ok(size == 34, "got %d, expected %d\n", size, 34);
736
737 for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
738 test_url_escape(TEST_ESCAPE[i].url, TEST_ESCAPE[i].flags,
739 TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].expecturl);
740 }
741 }
742
743 /* ########################### */
744
745 static void test_UrlCanonicalizeA(void)
746 {
747 unsigned int i;
748 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
749 DWORD dwSize;
750 DWORD urllen;
751 HRESULT hr;
752
753 if (!pUrlCanonicalizeA) {
754 win_skip("UrlCanonicalizeA not found\n");
755 return;
756 }
757
758 urllen = lstrlenA(winehqA);
759
760 /* buffer has no space for the result */
761 dwSize=urllen-1;
762 memset(szReturnUrl, '#', urllen+4);
763 szReturnUrl[urllen+4] = '\0';
764 SetLastError(0xdeadbeef);
765 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
766 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
767 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
768 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
769
770 /* buffer has no space for the terminating '\0' */
771 dwSize=urllen;
772 memset(szReturnUrl, '#', urllen+4);
773 szReturnUrl[urllen+4] = '\0';
774 SetLastError(0xdeadbeef);
775 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
776 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
777 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
778 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
779
780 /* buffer has the required size */
781 dwSize=urllen+1;
782 memset(szReturnUrl, '#', urllen+4);
783 szReturnUrl[urllen+4] = '\0';
784 SetLastError(0xdeadbeef);
785 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
786 ok( (hr == S_OK) && (dwSize == urllen),
787 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
788 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
789
790 /* buffer is larger as the required size */
791 dwSize=urllen+2;
792 memset(szReturnUrl, '#', urllen+4);
793 szReturnUrl[urllen+4] = '\0';
794 SetLastError(0xdeadbeef);
795 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
796 ok( (hr == S_OK) && (dwSize == urllen),
797 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
798 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
799
800 test_url_canonicalize(-1, "", 0, S_OK, S_FALSE /* Vista/win2k8 */, "", FALSE);
801
802 /* test url-modification */
803 for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
804 test_url_canonicalize(i, TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
805 TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl,
806 TEST_CANONICALIZE[i].todo);
807 }
808 }
809
810 /* ########################### */
811
812 static void test_UrlCanonicalizeW(void)
813 {
814 WCHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
815 DWORD dwSize;
816 DWORD urllen;
817 HRESULT hr;
818 int i;
819
820
821 if (!pUrlCanonicalizeW) {
822 win_skip("UrlCanonicalizeW not found\n");
823 return;
824 }
825 urllen = lstrlenW(winehqW);
826
827 /* buffer has no space for the result */
828 dwSize = (urllen-1);
829 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
830 szReturnUrl[urllen+4] = '\0';
831 SetLastError(0xdeadbeef);
832 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
833 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
834 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
835 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
836
837
838 /* buffer has no space for the terminating '\0' */
839 dwSize = urllen;
840 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
841 szReturnUrl[urllen+4] = '\0';
842 SetLastError(0xdeadbeef);
843 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
844 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
845 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
846 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
847
848 /* buffer has the required size */
849 dwSize = urllen +1;
850 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
851 szReturnUrl[urllen+4] = '\0';
852 SetLastError(0xdeadbeef);
853 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
854 ok( (hr == S_OK) && (dwSize == urllen),
855 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
856 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
857
858 /* buffer is larger as the required size */
859 dwSize = (urllen+2);
860 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
861 szReturnUrl[urllen+4] = '\0';
862 SetLastError(0xdeadbeef);
863 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
864 ok( (hr == S_OK) && (dwSize == urllen),
865 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
866 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
867
868 /* check that the characters 1..32 are chopped from the end of the string */
869 for (i = 1; i < 65536; i++)
870 {
871 WCHAR szUrl[128];
872 BOOL choped;
873 int pos;
874
875 MultiByteToWideChar(CP_ACP, 0, "http://www.winehq.org/X", -1, szUrl, 128);
876 pos = lstrlenW(szUrl) - 1;
877 szUrl[pos] = i;
878 urllen = INTERNET_MAX_URL_LENGTH;
879 pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
880 choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
881 ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
882 }
883 }
884
885 /* ########################### */
886
887 static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
888 {
889 HRESULT hr;
890 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
891 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
892 LPWSTR wszUrl1 = GetWideString(szUrl1);
893 LPWSTR wszUrl2 = GetWideString(szUrl2);
894 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
895 LPWSTR wszConvertedUrl;
896
897 DWORD dwSize;
898 DWORD dwExpectLen = lstrlen(szExpectUrl);
899
900 if (!pUrlCombineA) {
901 win_skip("UrlCombineA not found\n");
902 return;
903 }
904
905 hr = pUrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
906 ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
907
908 dwSize = 0;
909 hr = pUrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
910 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
911 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
912
913 dwSize--;
914 hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
915 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
916 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
917
918 hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
919 ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
920 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
921 if(SUCCEEDED(hr)) {
922 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
923 }
924
925 if (pUrlCombineW) {
926 dwSize = 0;
927 hr = pUrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
928 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
929 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
930
931 dwSize--;
932 hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
933 ok(hr == E_POINTER, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
934 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
935
936 hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
937 ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
938 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
939 if(SUCCEEDED(hr)) {
940 wszConvertedUrl = GetWideString(szReturnUrl);
941 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
942 FreeWideString(wszConvertedUrl);
943 }
944 }
945
946 FreeWideString(wszUrl1);
947 FreeWideString(wszUrl2);
948 FreeWideString(wszExpectUrl);
949 }
950
951 /* ########################### */
952
953 static void test_UrlCombine(void)
954 {
955 unsigned int i;
956 for(i=0; i<sizeof(TEST_COMBINE)/sizeof(TEST_COMBINE[0]); i++) {
957 test_url_combine(TEST_COMBINE[i].url1, TEST_COMBINE[i].url2, TEST_COMBINE[i].flags,
958 TEST_COMBINE[i].expectret, TEST_COMBINE[i].expecturl);
959 }
960 }
961
962 /* ########################### */
963
964 static void test_UrlCreateFromPath(void)
965 {
966 size_t i;
967 char ret_url[INTERNET_MAX_URL_LENGTH];
968 DWORD len, ret;
969 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
970 WCHAR *pathW, *urlW;
971
972 if (!pUrlCreateFromPathA) {
973 win_skip("UrlCreateFromPathA not found\n");
974 return;
975 }
976
977 for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
978 len = INTERNET_MAX_URL_LENGTH;
979 ret = pUrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
980 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
981 ok(!lstrcmpi(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
982 ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);
983
984 if (pUrlCreateFromPathW) {
985 len = INTERNET_MAX_URL_LENGTH;
986 pathW = GetWideString(TEST_URLFROMPATH[i].path);
987 urlW = GetWideString(TEST_URLFROMPATH[i].url);
988 ret = pUrlCreateFromPathW(pathW, ret_urlW, &len, 0);
989 WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
990 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
991 ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
992 ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n",
993 ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
994 ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
995 FreeWideString(urlW);
996 FreeWideString(pathW);
997 }
998 }
999 }
1000
1001 /* ########################### */
1002
1003 static void test_UrlIs(void)
1004 {
1005 BOOL ret;
1006 size_t i;
1007 WCHAR wurl[80];
1008
1009 if (!pUrlIsA) {
1010 win_skip("UrlIsA not found\n");
1011 return;
1012 }
1013
1014 for(i = 0; i < sizeof(TEST_PATH_IS_URL) / sizeof(TEST_PATH_IS_URL[0]); i++) {
1015 MultiByteToWideChar(CP_ACP, 0, TEST_PATH_IS_URL[i].path, -1, wurl, 80);
1016
1017 ret = pUrlIsA( TEST_PATH_IS_URL[i].path, URLIS_URL );
1018 ok( ret == TEST_PATH_IS_URL[i].expect,
1019 "returned %d from path %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
1020 TEST_PATH_IS_URL[i].expect );
1021
1022 if (pUrlIsW) {
1023 ret = pUrlIsW( wurl, URLIS_URL );
1024 ok( ret == TEST_PATH_IS_URL[i].expect,
1025 "returned %d from path (UrlIsW) %s, expected %d\n", ret,
1026 TEST_PATH_IS_URL[i].path, TEST_PATH_IS_URL[i].expect );
1027 }
1028 }
1029 for(i = 0; i < sizeof(TEST_URLIS_ATTRIBS) / sizeof(TEST_URLIS_ATTRIBS[0]); i++) {
1030 MultiByteToWideChar(CP_ACP, 0, TEST_URLIS_ATTRIBS[i].url, -1, wurl, 80);
1031
1032 ret = pUrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_OPAQUE);
1033 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
1034 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1035 TEST_URLIS_ATTRIBS[i].expectOpaque );
1036 ret = pUrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_FILEURL);
1037 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1038 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1039 TEST_URLIS_ATTRIBS[i].expectFile );
1040
1041 if (pUrlIsW) {
1042 ret = pUrlIsW( wurl, URLIS_OPAQUE);
1043 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
1044 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n",
1045 ret, TEST_URLIS_ATTRIBS[i].url, TEST_URLIS_ATTRIBS[i].expectOpaque );
1046 ret = pUrlIsW( wurl, URLIS_FILEURL);
1047 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1048 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n",
1049 ret, TEST_URLIS_ATTRIBS[i].url, TEST_URLIS_ATTRIBS[i].expectFile );
1050 }
1051 }
1052 }
1053
1054 /* ########################### */
1055
1056 static void test_UrlUnescape(void)
1057 {
1058 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1059 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
1060 WCHAR *urlW, *expected_urlW;
1061 DWORD dwEscaped;
1062 size_t i;
1063 static char inplace[] = "file:///C:/Program%20Files";
1064 static char another_inplace[] = "file:///C:/Program%20Files";
1065 static const char expected[] = "file:///C:/Program Files";
1066 static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
1067 static WCHAR another_inplaceW[] ={'f','i','l','e',':','/','/','/',
1068 'C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
1069 HRESULT res;
1070
1071 if (!pUrlUnescapeA) {
1072 win_skip("UrlUnescapeA not found\n");
1073 return;
1074 }
1075 for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
1076 dwEscaped=INTERNET_MAX_URL_LENGTH;
1077 res = pUrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, &dwEscaped, 0);
1078 ok(res == S_OK,
1079 "UrlUnescapeA returned 0x%x (expected S_OK) for \"%s\"\n",
1080 res, TEST_URL_UNESCAPE[i].url);
1081 ok(strcmp(szReturnUrl,TEST_URL_UNESCAPE[i].expect)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url);
1082
1083 ZeroMemory(szReturnUrl, sizeof(szReturnUrl));
1084 /* if we set the bufferpointer to NULL here UrlUnescape fails and string gets not converted */
1085 res = pUrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, NULL, 0);
1086 ok(res == E_INVALIDARG,
1087 "UrlUnescapeA returned 0x%x (expected E_INVALIDARG) for \"%s\"\n",
1088 res, TEST_URL_UNESCAPE[i].url);
1089 ok(strcmp(szReturnUrl,"")==0, "Expected empty string\n");
1090
1091 if (pUrlUnescapeW) {
1092 dwEscaped = INTERNET_MAX_URL_LENGTH;
1093 urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
1094 expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
1095 res = pUrlUnescapeW(urlW, ret_urlW, &dwEscaped, 0);
1096 ok(res == S_OK,
1097 "UrlUnescapeW returned 0x%x (expected S_OK) for \"%s\"\n",
1098 res, TEST_URL_UNESCAPE[i].url);
1099
1100 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
1101 ok(lstrcmpW(ret_urlW, expected_urlW)==0,
1102 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n",
1103 TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url, 0L);
1104 FreeWideString(urlW);
1105 FreeWideString(expected_urlW);
1106 }
1107 }
1108
1109 dwEscaped = sizeof(inplace);
1110 res = pUrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE);
1111 ok(res == S_OK, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res);
1112 ok(!strcmp(inplace, expected), "got %s expected %s\n", inplace, expected);
1113 ok(dwEscaped == 27, "got %d expected 27\n", dwEscaped);
1114
1115 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1116 res = pUrlUnescapeA(another_inplace, NULL, NULL, URL_UNESCAPE_INPLACE);
1117 ok(res == S_OK, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res);
1118 ok(!strcmp(another_inplace, expected), "got %s expected %s\n", another_inplace, expected);
1119
1120 if (pUrlUnescapeW) {
1121 dwEscaped = sizeof(inplaceW);
1122 res = pUrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE);
1123 ok(res == S_OK, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res);
1124 ok(dwEscaped == 50, "got %d expected 50\n", dwEscaped);
1125
1126 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1127 res = pUrlUnescapeW(another_inplaceW, NULL, NULL, URL_UNESCAPE_INPLACE);
1128 ok(res == S_OK, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res);
1129
1130 ok(lstrlenW(another_inplaceW) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW));
1131 }
1132 }
1133
1134 static const struct parse_url_test_t {
1135 const char *url;
1136 HRESULT hres;
1137 UINT protocol_len;
1138 UINT scheme;
1139 } parse_url_tests[] = {
1140 {"http://www.winehq.org/",S_OK,4,URL_SCHEME_HTTP},
1141 {"https://www.winehq.org/",S_OK,5,URL_SCHEME_HTTPS},
1142 {"ftp://www.winehq.org/",S_OK,3,URL_SCHEME_FTP},
1143 {"test.txt?test=c:/dir",URL_E_INVALID_SYNTAX},
1144 {"test.txt",URL_E_INVALID_SYNTAX},
1145 {"xxx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1146 {"1xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1147 {"-xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1148 {"xx0://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1149 {"x://www.winehq.org/",URL_E_INVALID_SYNTAX},
1150 {"xx$://www.winehq.org/",URL_E_INVALID_SYNTAX},
1151 {"htt?p://www.winehq.org/",URL_E_INVALID_SYNTAX},
1152 {"ab-://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1153 {" http://www.winehq.org/",URL_E_INVALID_SYNTAX},
1154 };
1155
1156 static void test_ParseURL(void)
1157 {
1158 const struct parse_url_test_t *test;
1159 WCHAR url[INTERNET_MAX_URL_LENGTH];
1160 PARSEDURLA parseda;
1161 PARSEDURLW parsedw;
1162 HRESULT hres;
1163
1164 for(test = parse_url_tests; test < parse_url_tests + sizeof(parse_url_tests)/sizeof(*parse_url_tests); test++) {
1165 memset(&parseda, 0xd0, sizeof(parseda));
1166 parseda.cbSize = sizeof(parseda);
1167 hres = pParseURLA(test->url, &parseda);
1168 ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1169 if(hres == S_OK) {
1170 ok(parseda.pszProtocol == test->url, "parseda.pszProtocol = %s, expected %s\n",
1171 parseda.pszProtocol, test->url);
1172 ok(parseda.cchProtocol == test->protocol_len, "parseda.cchProtocol = %d, expected %d\n",
1173 parseda.cchProtocol, test->protocol_len);
1174 ok(parseda.pszSuffix == test->url+test->protocol_len+1, "parseda.pszSuffix = %s, expected %s\n",
1175 parseda.pszSuffix, test->url+test->protocol_len+1);
1176 ok(parseda.cchSuffix == strlen(test->url+test->protocol_len+1),
1177 "parseda.pszSuffix = %d, expected %d\n",
1178 parseda.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1179 ok(parseda.nScheme == test->scheme, "parseda.nScheme = %d, expected %d\n",
1180 parseda.nScheme, test->scheme);
1181 }else {
1182 ok(!parseda.pszProtocol, "parseda.pszProtocol = %p\n", parseda.pszProtocol);
1183 ok(parseda.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parseda.nScheme);
1184 }
1185
1186 MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, sizeof(url)/sizeof(WCHAR));
1187
1188 memset(&parsedw, 0xd0, sizeof(parsedw));
1189 parsedw.cbSize = sizeof(parsedw);
1190 hres = pParseURLW(url, &parsedw);
1191 ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1192 if(hres == S_OK) {
1193 ok(parsedw.pszProtocol == url, "parsedw.pszProtocol = %s, expected %s\n",
1194 wine_dbgstr_w(parsedw.pszProtocol), wine_dbgstr_w(url));
1195 ok(parsedw.cchProtocol == test->protocol_len, "parsedw.cchProtocol = %d, expected %d\n",
1196 parsedw.cchProtocol, test->protocol_len);
1197 ok(parsedw.pszSuffix == url+test->protocol_len+1, "parsedw.pszSuffix = %s, expected %s\n",
1198 wine_dbgstr_w(parsedw.pszSuffix), wine_dbgstr_w(url+test->protocol_len+1));
1199 ok(parsedw.cchSuffix == strlen(test->url+test->protocol_len+1),
1200 "parsedw.pszSuffix = %d, expected %d\n",
1201 parsedw.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1202 ok(parsedw.nScheme == test->scheme, "parsedw.nScheme = %d, expected %d\n",
1203 parsedw.nScheme, test->scheme);
1204 }else {
1205 ok(!parsedw.pszProtocol, "parsedw.pszProtocol = %p\n", parseda.pszProtocol);
1206 ok(parsedw.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parsedw.nScheme);
1207 }
1208 }
1209 }
1210
1211 static void test_HashData(void)
1212 {
1213 HRESULT res;
1214 BYTE input[16] = {0x51, 0x33, 0x4F, 0xA7, 0x45, 0x15, 0xF0, 0x52, 0x90,
1215 0x2B, 0xE7, 0xF5, 0xFD, 0xE1, 0xA6, 0xA7};
1216 BYTE output[32];
1217 static const BYTE expected[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1218 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1219 0xE3, 0x2D};
1220 static const BYTE expected2[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1221 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1222 0xE3, 0x2D, 0x47, 0xFC, 0x80, 0xB8, 0xD0,
1223 0x49, 0xE6, 0x13, 0x2A, 0x30, 0x51, 0x8D,
1224 0xF9, 0x4B, 0x07, 0xA6};
1225 static const BYTE expected3[] = {0x2B, 0xDC, 0x9A, 0x1B, 0xF0, 0x5A, 0xF9,
1226 0xC6, 0xBE, 0x94, 0x6D, 0xF3, 0x33, 0xC1,
1227 0x36, 0x07};
1228 int i;
1229
1230 /* Test hashing with identically sized input/output buffers. */
1231 res = pHashData(input, 16, output, 16);
1232 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1233 if(res == S_OK)
1234 ok(!memcmp(output, expected, sizeof(expected)),
1235 "Output buffer did not match expected contents\n");
1236
1237 /* Test hashing with larger output buffer. */
1238 res = pHashData(input, 16, output, 32);
1239 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1240 if(res == S_OK)
1241 ok(!memcmp(output, expected2, sizeof(expected2)),
1242 "Output buffer did not match expected contents\n");
1243
1244 /* Test hashing with smaller input buffer. */
1245 res = pHashData(input, 8, output, 16);
1246 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1247 if(res == S_OK)
1248 ok(!memcmp(output, expected3, sizeof(expected3)),
1249 "Output buffer did not match expected contents\n");
1250
1251 /* Test passing NULL pointers for input/output parameters. */
1252 res = pHashData(NULL, 0, NULL, 0);
1253 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1254 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1255
1256 res = pHashData(input, 0, NULL, 0);
1257 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1258 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1259
1260 res = pHashData(NULL, 0, output, 0);
1261 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1262 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1263
1264 /* Test passing valid pointers with sizes of zero. */
1265 for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1266 input[i] = 0x00;
1267
1268 for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1269 output[i] = 0xFF;
1270
1271 res = pHashData(input, 0, output, 0);
1272 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1273
1274 /* The buffers should be unchanged. */
1275 for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1276 {
1277 ok(input[i] == 0x00, "Expected the input buffer to be unchanged\n");
1278 if(input[i] != 0x00) break;
1279 }
1280
1281 for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1282 {
1283 ok(output[i] == 0xFF, "Expected the output buffer to be unchanged\n");
1284 if(output[i] != 0xFF) break;
1285 }
1286
1287 /* Input/output parameters are not validated. */
1288 res = pHashData((BYTE *)0xdeadbeef, 0, (BYTE *)0xdeadbeef, 0);
1289 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1290
1291 if (0)
1292 {
1293 res = pHashData((BYTE *)0xdeadbeef, 1, (BYTE *)0xdeadbeef, 1);
1294 trace("HashData returned 0x%08x\n", res);
1295 }
1296 }
1297
1298 /* ########################### */
1299
1300 START_TEST(url)
1301 {
1302
1303 hShlwapi = GetModuleHandleA("shlwapi.dll");
1304 pUrlUnescapeA = (void *) GetProcAddress(hShlwapi, "UrlUnescapeA");
1305 pUrlUnescapeW = (void *) GetProcAddress(hShlwapi, "UrlUnescapeW");
1306 pUrlIsA = (void *) GetProcAddress(hShlwapi, "UrlIsA");
1307 pUrlIsW = (void *) GetProcAddress(hShlwapi, "UrlIsW");
1308 pUrlHashA = (void *) GetProcAddress(hShlwapi, "UrlHashA");
1309 pUrlHashW = (void *) GetProcAddress(hShlwapi, "UrlHashW");
1310 pUrlGetPartA = (void *) GetProcAddress(hShlwapi, "UrlGetPartA");
1311 pUrlGetPartW = (void *) GetProcAddress(hShlwapi, "UrlGetPartW");
1312 pUrlEscapeA = (void *) GetProcAddress(hShlwapi, "UrlEscapeA");
1313 pUrlEscapeW = (void *) GetProcAddress(hShlwapi, "UrlEscapeW");
1314 pUrlCreateFromPathA = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathA");
1315 pUrlCreateFromPathW = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathW");
1316 pUrlCombineA = (void *) GetProcAddress(hShlwapi, "UrlCombineA");
1317 pUrlCombineW = (void *) GetProcAddress(hShlwapi, "UrlCombineW");
1318 pUrlCanonicalizeA = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeA");
1319 pUrlCanonicalizeW = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeW");
1320 pUrlApplySchemeA = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeA");
1321 pUrlApplySchemeW = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeW");
1322 pParseURLA = (void*)GetProcAddress(hShlwapi, (LPCSTR)1);
1323 pParseURLW = (void*)GetProcAddress(hShlwapi, (LPCSTR)2);
1324 pHashData = (void*)GetProcAddress(hShlwapi, "HashData");
1325
1326 test_UrlApplyScheme();
1327 test_UrlHash();
1328 test_UrlGetPart();
1329 test_UrlCanonicalizeA();
1330 test_UrlCanonicalizeW();
1331 test_UrlEscape();
1332 test_UrlCombine();
1333 test_UrlCreateFromPath();
1334 test_UrlIs();
1335 test_UrlUnescape();
1336 test_ParseURL();
1337 test_HashData();
1338 }