1 /* Unit test suite for Path functions
3 * Copyright 2002 Matthew Mastracci
4 * Copyright 2007-2010 Detlef Riekenberg
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.
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.
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
24 #include "wine/test.h"
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
);
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};
62 /* ################ */
64 static const CHAR untouchedA
[] = "untouched";
66 #define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
68 typedef struct _TEST_URL_APPLY
{
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://"}
91 /* ################ */
93 typedef struct _TEST_URL_CANONICALIZE
{
97 const char *expecturl
;
99 } TEST_URL_CANONICALIZE
;
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"},
165 /* ################ */
167 typedef struct _TEST_URL_ESCAPE
{
172 const char *expecturl
;
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"},
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"},
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"},
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"},
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"},
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"},
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"},
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"}
256 /* ################ */
258 typedef struct _TEST_URL_COMBINE
{
263 const char *expecturl
;
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 {"file:///C:\\dir\\file.txt#hash\\hash", "test.txt", 0, S_OK
, "file:///C:/dir/file.txt#hash/test.txt"},
282 {"file:///C:\\dir\\file.html#hash\\hash", "test.html", 0, S_OK
, "file:///C:/dir/test.html"},
283 {"file:///C:\\dir\\file.htm#hash\\hash", "test.htm", 0, S_OK
, "file:///C:/dir/test.htm"},
284 {"file:///C:\\dir\\file.hTmL#hash\\hash", "test.hTmL", 0, S_OK
, "file:///C:/dir/test.hTmL"},
285 {"file:///C:\\dir.html\\file.txt#hash\\hash", "test.txt", 0, S_OK
, "file:///C:/dir.html/file.txt#hash/test.txt"},
286 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK
, "file:///C:/Test/test.txt"},
287 {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK
, "http://www.winehq.org/test/test%20file.txt"},
288 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL
, S_OK
, "http://www.winehq.org/test/test%20file.txt"},
289 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL
, S_OK
, "http://www.winehq.org%2ftest/test%20file.txt"},
290 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK
, "xxx:dir/file"},
291 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK
, "mk:@MSITStore:file.chm::/dir/file"},
292 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK
, "mk:@MSITStore:file.chm::/dir/file"},
293 {"foo:today", "foo:calendar", 0, S_OK
, "foo:calendar"},
294 {"foo:today", "bar:calendar", 0, S_OK
, "bar:calendar"},
295 {"foo:/today", "foo:calendar", 0, S_OK
, "foo:/calendar"},
296 {"foo:/today/", "foo:calendar", 0, S_OK
, "foo:/today/calendar"},
297 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK
, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
298 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK
, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
299 /* UrlCombine case 2 tests. Schemes do not match */
300 {"outbind://xxxxxxxxx","http://wine1/dir",0, S_OK
,"http://wine1/dir"},
301 {"xxxx://xxxxxxxxx","http://wine2/dir",0, S_OK
,"http://wine2/dir"},
302 {"ftp://xxxxxxxxx/","http://wine3/dir",0, S_OK
,"http://wine3/dir"},
303 {"outbind://xxxxxxxxx","http://wine4/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"http://wine4/dir"},
304 {"xxx://xxxxxxxxx","http://wine5/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"http://wine5/dir"},
305 {"ftp://xxxxxxxxx/","http://wine6/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"http://wine6/dir"},
306 {"http://xxxxxxxxx","outbind://wine7/dir",0, S_OK
,"outbind://wine7/dir"},
307 {"xxx://xxxxxxxxx","ftp://wine8/dir",0, S_OK
,"ftp://wine8/dir"},
308 {"ftp://xxxxxxxxx/","xxx://wine9/dir",0, S_OK
,"xxx://wine9/dir"},
309 {"http://xxxxxxxxx","outbind://wine10/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"outbind://wine10/dir"},
310 {"xxx://xxxxxxxxx","ftp://wine11/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"ftp://wine11/dir"},
311 {"ftp://xxxxxxxxx/","xxx://wine12/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"xxx://wine12/dir"},
312 {"http://xxxxxxxxx","outbind:wine13/dir",0, S_OK
,"outbind:wine13/dir"},
313 {"xxx://xxxxxxxxx","ftp:wine14/dir",0, S_OK
,"ftp:wine14/dir"},
314 {"ftp://xxxxxxxxx/","xxx:wine15/dir",0, S_OK
,"xxx:wine15/dir"},
315 {"outbind://xxxxxxxxx/","http:wine16/dir",0, S_OK
,"http:wine16/dir"},
316 {"http://xxxxxxxxx","outbind:wine17/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"outbind:wine17/dir"},
317 {"xxx://xxxxxxxxx","ftp:wine18/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"ftp:wine18/dir"},
318 {"ftp://xxxxxxxxx/","xxx:wine19/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"xxx:wine19/dir"},
319 {"outbind://xxxxxxxxx/","http:wine20/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"http:wine20/dir"},
320 {"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"}
323 /* ################ */
325 static const struct {
329 } TEST_URLFROMPATH
[] = {
330 {"foo", "file:foo", S_OK
},
331 {"foo\\bar", "file:foo/bar", S_OK
},
332 {"\\foo\\bar", "file:///foo/bar", S_OK
},
333 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK
},
334 {"c:foo\\bar", "file:///c:foo/bar", S_OK
},
335 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK
},
336 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK
},
338 /* The following test fails on native shlwapi as distributed with Win95/98.
339 * Wine matches the behaviour of later versions.
341 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE
}
345 /* ################ */
350 } TEST_URL_UNESCAPE
[] = {
351 {"file://foo/bar", "file://foo/bar"},
352 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
353 {"file://%24%25foobar", "file://$%foobar"}
356 /* ################ */
358 static const struct {
361 } TEST_PATH_IS_URL
[] = {
362 {"http://foo/bar", TRUE
},
363 {"c:\\foo\\bar", FALSE
},
364 {"foo://foo/bar", TRUE
},
367 {"bogusscheme:", TRUE
},
368 {"http:partial", TRUE
}
371 /* ################ */
373 static const struct {
377 } TEST_URLIS_ATTRIBS
[] = {
378 { "ftp:", FALSE
, FALSE
},
379 { "http:", FALSE
, FALSE
},
380 { "gopher:", FALSE
, FALSE
},
381 { "mailto:", TRUE
, FALSE
},
382 { "news:", FALSE
, FALSE
},
383 { "nntp:", FALSE
, FALSE
},
384 { "telnet:", FALSE
, FALSE
},
385 { "wais:", FALSE
, FALSE
},
386 { "file:", FALSE
, TRUE
},
387 { "mk:", FALSE
, FALSE
},
388 { "https:", FALSE
, FALSE
},
389 { "shell:", TRUE
, FALSE
},
390 { "https:", FALSE
, FALSE
},
391 { "snews:", FALSE
, FALSE
},
392 { "local:", FALSE
, FALSE
},
393 { "javascript:", TRUE
, FALSE
},
394 { "vbscript:", TRUE
, FALSE
},
395 { "about:", TRUE
, FALSE
},
396 { "res:", FALSE
, FALSE
},
397 { "bogusscheme:", FALSE
, FALSE
},
398 { "file:\\\\e:\\b\\c", FALSE
, TRUE
},
399 { "file://e:/b/c", FALSE
, TRUE
},
400 { "http:partial", FALSE
, FALSE
},
401 { "mailto://www.winehq.org/test.html", TRUE
, FALSE
},
402 { "file:partial", FALSE
, TRUE
}
405 /* ########################### */
407 static LPWSTR
GetWideString(const char* szString
)
409 LPWSTR wszString
= HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH
) * sizeof(WCHAR
));
411 MultiByteToWideChar(0, 0, szString
, -1, wszString
, INTERNET_MAX_URL_LENGTH
);
417 static void FreeWideString(LPWSTR wszString
)
419 HeapFree(GetProcessHeap(), 0, wszString
);
422 /* ########################### */
424 static void test_UrlApplyScheme(void)
426 CHAR newurl
[TEST_APPLY_MAX_LENGTH
];
427 WCHAR urlW
[TEST_APPLY_MAX_LENGTH
];
428 WCHAR newurlW
[TEST_APPLY_MAX_LENGTH
];
433 if (!pUrlApplySchemeA
) {
434 win_skip("UrlApplySchemeA not found\n");
438 for(i
= 0; i
< sizeof(TEST_APPLY
)/sizeof(TEST_APPLY
[0]); i
++) {
439 len
= TEST_APPLY_MAX_LENGTH
;
440 lstrcpyA(newurl
, untouchedA
);
441 res
= pUrlApplySchemeA(TEST_APPLY
[i
].url
, newurl
, &len
, TEST_APPLY
[i
].flags
);
442 ok( res
== TEST_APPLY
[i
].res
,
443 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i
, res
, TEST_APPLY
[i
].res
);
445 ok( len
== TEST_APPLY
[i
].newlen
,
446 "#%dA: got len %d (expected %d)\n", i
, len
, TEST_APPLY
[i
].newlen
);
448 ok( !lstrcmpA(newurl
, TEST_APPLY
[i
].newurl
),
449 "#%dA: got '%s' (expected '%s')\n", i
, newurl
, TEST_APPLY
[i
].newurl
);
451 /* returned length is in character */
452 len
= TEST_APPLY_MAX_LENGTH
;
453 lstrcpyA(newurl
, untouchedA
);
454 MultiByteToWideChar(CP_ACP
, 0, newurl
, -1, newurlW
, len
);
455 MultiByteToWideChar(CP_ACP
, 0, TEST_APPLY
[i
].url
, -1, urlW
, len
);
457 res
= pUrlApplySchemeW(urlW
, newurlW
, &len
, TEST_APPLY
[i
].flags
);
458 WideCharToMultiByte(CP_ACP
, 0, newurlW
, -1, newurl
, TEST_APPLY_MAX_LENGTH
, NULL
, NULL
);
459 ok( res
== TEST_APPLY
[i
].res
,
460 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i
, res
, TEST_APPLY
[i
].res
);
462 ok( len
== TEST_APPLY
[i
].newlen
,
463 "#%dW: got len %d (expected %d)\n", i
, len
, TEST_APPLY
[i
].newlen
);
465 ok( !lstrcmpA(newurl
, TEST_APPLY
[i
].newurl
),
466 "#%dW: got '%s' (expected '%s')\n", i
, newurl
, TEST_APPLY
[i
].newurl
);
470 /* buffer too small */
471 lstrcpyA(newurl
, untouchedA
);
472 len
= lstrlenA(TEST_APPLY
[0].newurl
);
473 res
= pUrlApplySchemeA(TEST_APPLY
[0].url
, newurl
, &len
, TEST_APPLY
[0].flags
);
474 ok(res
== E_POINTER
, "got HRESULT 0x%x (expected E_POINTER)\n", res
);
475 /* The returned length include the space for the terminating 0 */
476 i
= lstrlenA(TEST_APPLY
[0].newurl
)+1;
477 ok(len
== i
, "got len %d (expected %d)\n", len
, i
);
478 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
480 /* NULL as parameter. The length and the buffer are not modified */
481 lstrcpyA(newurl
, untouchedA
);
482 len
= TEST_APPLY_MAX_LENGTH
;
483 res
= pUrlApplySchemeA(NULL
, newurl
, &len
, TEST_APPLY
[0].flags
);
484 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
485 ok(len
== TEST_APPLY_MAX_LENGTH
, "got len %d\n", len
);
486 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
488 len
= TEST_APPLY_MAX_LENGTH
;
489 res
= pUrlApplySchemeA(TEST_APPLY
[0].url
, NULL
, &len
, TEST_APPLY
[0].flags
);
490 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
491 ok(len
== TEST_APPLY_MAX_LENGTH
, "got len %d\n", len
);
493 lstrcpyA(newurl
, untouchedA
);
494 res
= pUrlApplySchemeA(TEST_APPLY
[0].url
, newurl
, NULL
, TEST_APPLY
[0].flags
);
495 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
496 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
500 /* ########################### */
502 static void hash_url(const char* szUrl
)
504 LPCSTR szTestUrl
= szUrl
;
505 LPWSTR wszTestUrl
= GetWideString(szTestUrl
);
508 DWORD cbSize
= sizeof(DWORD
);
509 DWORD dwHash1
, dwHash2
;
510 res
= pUrlHashA(szTestUrl
, (LPBYTE
)&dwHash1
, cbSize
);
511 ok(res
== S_OK
, "UrlHashA returned 0x%x (expected S_OK) for %s\n", res
, szUrl
);
513 res
= pUrlHashW(wszTestUrl
, (LPBYTE
)&dwHash2
, cbSize
);
514 ok(res
== S_OK
, "UrlHashW returned 0x%x (expected S_OK) for %s\n", res
, szUrl
);
515 ok(dwHash1
== dwHash2
,
516 "Hashes didn't match (A: 0x%x, W: 0x%x) for %s\n", dwHash1
, dwHash2
, szUrl
);
518 FreeWideString(wszTestUrl
);
522 static void test_UrlHash(void)
525 win_skip("UrlHashA not found\n");
529 hash_url(TEST_URL_1
);
530 hash_url(TEST_URL_2
);
531 hash_url(TEST_URL_3
);
534 /* ########################### */
536 static void test_url_part(const char* szUrl
, DWORD dwPart
, DWORD dwFlags
, const char* szExpected
)
538 CHAR szPart
[INTERNET_MAX_URL_LENGTH
];
539 WCHAR wszPart
[INTERNET_MAX_URL_LENGTH
];
540 LPWSTR wszUrl
= GetWideString(szUrl
);
541 LPWSTR wszConvertedPart
;
545 dwSize
= INTERNET_MAX_URL_LENGTH
;
546 res
= pUrlGetPartA(szUrl
, szPart
, &dwSize
, dwPart
, dwFlags
);
548 "UrlGetPartA for \"%s\" part 0x%08x returned 0x%x and \"%s\"\n",
549 szUrl
, dwPart
, res
, szPart
);
551 dwSize
= INTERNET_MAX_URL_LENGTH
;
552 res
= pUrlGetPartW(wszUrl
, wszPart
, &dwSize
, dwPart
, dwFlags
);
554 "UrlGetPartW for \"%s\" part 0x%08x returned 0x%x\n",
557 wszConvertedPart
= GetWideString(szPart
);
559 ok(lstrcmpW(wszPart
,wszConvertedPart
)==0,
560 "Strings didn't match between ascii and unicode UrlGetPart!\n");
562 FreeWideString(wszConvertedPart
);
564 FreeWideString(wszUrl
);
566 /* Note that v6.0 and later don't return '?' with the query */
567 ok(strcmp(szPart
,szExpected
)==0 ||
568 (*szExpected
=='?' && !strcmp(szPart
,szExpected
+1)),
569 "Expected %s, but got %s\n", szExpected
, szPart
);
572 /* ########################### */
574 static void test_UrlGetPart(void)
576 const char* file_url
= "file://h o s t/c:/windows/file";
577 const char* http_url
= "http://user:pass 123@www.wine hq.org";
578 const char* about_url
= "about:blank";
580 CHAR szPart
[INTERNET_MAX_URL_LENGTH
];
585 win_skip("UrlGetPartA not found\n");
589 dwSize
= sizeof szPart
;
590 szPart
[0]='x'; szPart
[1]=0;
591 res
= pUrlGetPartA("hi", szPart
, &dwSize
, URL_PART_SCHEME
, 0);
593 ok (res
==S_FALSE
, "UrlGetPartA(\"hi\") returned %08X\n", res
);
594 ok(szPart
[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart
);
596 dwSize
= sizeof szPart
;
597 szPart
[0]='x'; szPart
[1]=0;
598 res
= pUrlGetPartA("hi", szPart
, &dwSize
, URL_PART_QUERY
, 0);
600 ok (res
==S_FALSE
, "UrlGetPartA(\"hi\") returned %08X\n", res
);
601 ok(szPart
[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart
);
604 test_url_part(TEST_URL_3
, URL_PART_HOSTNAME
, 0, "localhost");
605 test_url_part(TEST_URL_3
, URL_PART_PORT
, 0, "21");
606 test_url_part(TEST_URL_3
, URL_PART_USERNAME
, 0, "foo");
607 test_url_part(TEST_URL_3
, URL_PART_PASSWORD
, 0, "bar");
608 test_url_part(TEST_URL_3
, URL_PART_SCHEME
, 0, "http");
609 test_url_part(TEST_URL_3
, URL_PART_QUERY
, 0, "?query=x&return=y");
611 test_url_part(file_url
, URL_PART_HOSTNAME
, 0, "h o s t");
613 test_url_part(http_url
, URL_PART_HOSTNAME
, 0, "www.wine hq.org");
614 test_url_part(http_url
, URL_PART_PASSWORD
, 0, "pass 123");
616 test_url_part(about_url
, URL_PART_SCHEME
, 0, "about");
618 dwSize
= sizeof(szPart
);
619 res
= pUrlGetPartA(about_url
, szPart
, &dwSize
, URL_PART_HOSTNAME
, 0);
620 ok(res
==E_FAIL
, "returned %08x\n", res
);
622 dwSize
= sizeof(szPart
);
623 res
= pUrlGetPartA("file://c:\\index.htm", szPart
, &dwSize
, URL_PART_HOSTNAME
, 0);
624 ok(res
==S_FALSE
, "returned %08x\n", res
);
626 dwSize
= sizeof(szPart
);
627 szPart
[0] = 'x'; szPart
[1] = '\0';
628 res
= pUrlGetPartA("file:some text", szPart
, &dwSize
, URL_PART_HOSTNAME
, 0);
629 ok(res
==S_FALSE
, "returned %08x\n", res
);
630 ok(szPart
[0] == '\0', "szPart[0] = %c\n", szPart
[0]);
631 ok(dwSize
== 0, "dwSize = %d\n", dwSize
);
634 /* ########################### */
636 static void test_url_escape(const char *szUrl
, DWORD dwFlags
, HRESULT dwExpectReturn
, const char *szExpectUrl
)
638 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
640 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
641 WCHAR
*urlW
, *expected_urlW
;
642 dwEscaped
=INTERNET_MAX_URL_LENGTH
;
644 ok(pUrlEscapeA(szUrl
, szReturnUrl
, &dwEscaped
, dwFlags
) == dwExpectReturn
,
645 "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn
, szUrl
);
646 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl
, szReturnUrl
, szUrl
);
649 dwEscaped
= INTERNET_MAX_URL_LENGTH
;
650 urlW
= GetWideString(szUrl
);
651 expected_urlW
= GetWideString(szExpectUrl
);
652 ok(pUrlEscapeW(urlW
, ret_urlW
, &dwEscaped
, dwFlags
) == dwExpectReturn
,
653 "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn
, szUrl
);
654 WideCharToMultiByte(CP_ACP
,0,ret_urlW
,-1,szReturnUrl
,INTERNET_MAX_URL_LENGTH
,0,0);
655 ok(lstrcmpW(ret_urlW
, expected_urlW
)==0,
656 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n",
657 szExpectUrl
, szReturnUrl
, szUrl
, dwFlags
);
658 FreeWideString(urlW
);
659 FreeWideString(expected_urlW
);
663 static void test_url_canonicalize(int index
, const char *szUrl
, DWORD dwFlags
, HRESULT dwExpectReturn
, HRESULT dwExpectReturnAlt
, const char *szExpectUrl
, BOOL todo
)
665 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
666 WCHAR wszReturnUrl
[INTERNET_MAX_URL_LENGTH
];
667 LPWSTR wszUrl
= GetWideString(szUrl
);
668 LPWSTR wszExpectUrl
= GetWideString(szExpectUrl
);
669 LPWSTR wszConvertedUrl
;
674 dwSize
= INTERNET_MAX_URL_LENGTH
;
675 ret
= pUrlCanonicalizeA(szUrl
, NULL
, &dwSize
, dwFlags
);
676 ok(ret
!= dwExpectReturn
, "got 0s%x: Unexpected return for NULL buffer, index %d\n", ret
, index
);
677 ret
= pUrlCanonicalizeA(szUrl
, szReturnUrl
, &dwSize
, dwFlags
);
678 ok(ret
== dwExpectReturn
|| ret
== dwExpectReturnAlt
,
679 "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
680 dwExpectReturn
, dwExpectReturnAlt
, ret
, index
);
683 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags
, szUrl
, szExpectUrl
, szReturnUrl
, index
);
685 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags
, szUrl
, szExpectUrl
, szReturnUrl
, index
);
687 if (pUrlCanonicalizeW
) {
688 dwSize
= INTERNET_MAX_URL_LENGTH
;
689 ret
= pUrlCanonicalizeW(wszUrl
, NULL
, &dwSize
, dwFlags
);
690 ok(ret
!= dwExpectReturn
, "got 0x%x: Unexpected return for NULL buffer, index %d\n", ret
, index
);
691 ret
= pUrlCanonicalizeW(wszUrl
, wszReturnUrl
, &dwSize
, dwFlags
);
692 ok(ret
== dwExpectReturn
, "UrlCanonicalizeW failed: expected 0x%08x, got 0x%x, index %d\n",
693 dwExpectReturn
, ret
, index
);
695 wszConvertedUrl
= GetWideString(szReturnUrl
);
696 ok(lstrcmpW(wszReturnUrl
, wszConvertedUrl
)==0,
697 "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index
);
698 FreeWideString(wszConvertedUrl
);
701 FreeWideString(wszUrl
);
702 FreeWideString(wszExpectUrl
);
706 static void test_UrlEscape(void)
711 char empty_string
[] = "";
714 win_skip("UrlEscapeA noz found\n");
718 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL
, &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);
723 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
724 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
725 ok(size
== 0, "got %d, expected %d\n", size
, 0);
728 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL
, &size
, 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);
733 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, NULL
, URL_ESCAPE_SPACES_ONLY
);
734 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
735 ok(size
== 1, "got %d, expected %d\n", size
, 1);
738 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
739 ok(ret
== E_POINTER
, "got %x, expected %x\n", ret
, E_POINTER
);
740 ok(size
== 34, "got %d, expected %d\n", size
, 34);
742 for(i
=0; i
<sizeof(TEST_ESCAPE
)/sizeof(TEST_ESCAPE
[0]); i
++) {
743 test_url_escape(TEST_ESCAPE
[i
].url
, TEST_ESCAPE
[i
].flags
,
744 TEST_ESCAPE
[i
].expectret
, TEST_ESCAPE
[i
].expecturl
);
748 /* ########################### */
750 static void test_UrlCanonicalizeA(void)
753 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
758 if (!pUrlCanonicalizeA
) {
759 win_skip("UrlCanonicalizeA not found\n");
763 urllen
= lstrlenA(winehqA
);
765 /* buffer has no space for the result */
767 memset(szReturnUrl
, '#', urllen
+4);
768 szReturnUrl
[urllen
+4] = '\0';
769 SetLastError(0xdeadbeef);
770 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
771 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
772 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
773 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
+1);
775 /* buffer has no space for the terminating '\0' */
777 memset(szReturnUrl
, '#', urllen
+4);
778 szReturnUrl
[urllen
+4] = '\0';
779 SetLastError(0xdeadbeef);
780 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
781 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
782 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
783 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
+1);
785 /* buffer has the required size */
787 memset(szReturnUrl
, '#', urllen
+4);
788 szReturnUrl
[urllen
+4] = '\0';
789 SetLastError(0xdeadbeef);
790 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
791 ok( (hr
== S_OK
) && (dwSize
== urllen
),
792 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
793 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
);
795 /* buffer is larger as the required size */
797 memset(szReturnUrl
, '#', urllen
+4);
798 szReturnUrl
[urllen
+4] = '\0';
799 SetLastError(0xdeadbeef);
800 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
801 ok( (hr
== S_OK
) && (dwSize
== urllen
),
802 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
803 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
);
805 test_url_canonicalize(-1, "", 0, S_OK
, S_FALSE
/* Vista/win2k8 */, "", FALSE
);
807 /* test url-modification */
808 for(i
=0; i
<sizeof(TEST_CANONICALIZE
)/sizeof(TEST_CANONICALIZE
[0]); i
++) {
809 test_url_canonicalize(i
, TEST_CANONICALIZE
[i
].url
, TEST_CANONICALIZE
[i
].flags
,
810 TEST_CANONICALIZE
[i
].expectret
, TEST_CANONICALIZE
[i
].expectret
, TEST_CANONICALIZE
[i
].expecturl
,
811 TEST_CANONICALIZE
[i
].todo
);
815 /* ########################### */
817 static void test_UrlCanonicalizeW(void)
819 WCHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
826 if (!pUrlCanonicalizeW
) {
827 win_skip("UrlCanonicalizeW not found\n");
830 urllen
= lstrlenW(winehqW
);
832 /* buffer has no space for the result */
834 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
835 szReturnUrl
[urllen
+4] = '\0';
836 SetLastError(0xdeadbeef);
837 hr
= pUrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
838 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
839 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
840 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
+1);
843 /* buffer has no space for the terminating '\0' */
845 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
846 szReturnUrl
[urllen
+4] = '\0';
847 SetLastError(0xdeadbeef);
848 hr
= pUrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
849 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
850 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
851 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
+1);
853 /* buffer has the required size */
855 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
856 szReturnUrl
[urllen
+4] = '\0';
857 SetLastError(0xdeadbeef);
858 hr
= pUrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
859 ok( (hr
== S_OK
) && (dwSize
== urllen
),
860 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
861 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
);
863 /* buffer is larger as the required size */
865 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
866 szReturnUrl
[urllen
+4] = '\0';
867 SetLastError(0xdeadbeef);
868 hr
= pUrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
869 ok( (hr
== S_OK
) && (dwSize
== urllen
),
870 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
871 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
);
873 /* check that the characters 1..32 are chopped from the end of the string */
874 for (i
= 1; i
< 65536; i
++)
880 MultiByteToWideChar(CP_ACP
, 0, "http://www.winehq.org/X", -1, szUrl
, 128);
881 pos
= lstrlenW(szUrl
) - 1;
883 urllen
= INTERNET_MAX_URL_LENGTH
;
884 pUrlCanonicalizeW(szUrl
, szReturnUrl
, &urllen
, 0);
885 choped
= lstrlenW(szReturnUrl
) < lstrlenW(szUrl
);
886 ok(choped
== (i
<= 32), "Incorrect char chopping for char %d\n", i
);
890 /* ########################### */
892 static void test_url_combine(const char *szUrl1
, const char *szUrl2
, DWORD dwFlags
, HRESULT dwExpectReturn
, const char *szExpectUrl
)
895 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
896 WCHAR wszReturnUrl
[INTERNET_MAX_URL_LENGTH
];
897 LPWSTR wszUrl1
= GetWideString(szUrl1
);
898 LPWSTR wszUrl2
= GetWideString(szUrl2
);
899 LPWSTR wszExpectUrl
= GetWideString(szExpectUrl
);
900 LPWSTR wszConvertedUrl
;
903 DWORD dwExpectLen
= lstrlen(szExpectUrl
);
906 win_skip("UrlCombineA not found\n");
910 hr
= pUrlCombineA(szUrl1
, szUrl2
, NULL
, NULL
, dwFlags
);
911 ok(hr
== E_INVALIDARG
, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr
, E_INVALIDARG
);
914 hr
= pUrlCombineA(szUrl1
, szUrl2
, NULL
, &dwSize
, dwFlags
);
915 ok(hr
== E_POINTER
, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
916 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
919 hr
= pUrlCombineA(szUrl1
, szUrl2
, szReturnUrl
, &dwSize
, dwFlags
);
920 ok(hr
== E_POINTER
, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
921 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
923 hr
= pUrlCombineA(szUrl1
, szUrl2
, szReturnUrl
, &dwSize
, dwFlags
);
924 ok(hr
== dwExpectReturn
, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr
, dwExpectReturn
);
925 ok(dwSize
== dwExpectLen
, "Got length %d, expected %d\n", dwSize
, dwExpectLen
);
927 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "Expected %s, but got %s\n", szExpectUrl
, szReturnUrl
);
932 hr
= pUrlCombineW(wszUrl1
, wszUrl2
, NULL
, &dwSize
, dwFlags
);
933 ok(hr
== E_POINTER
, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
934 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
937 hr
= pUrlCombineW(wszUrl1
, wszUrl2
, wszReturnUrl
, &dwSize
, dwFlags
);
938 ok(hr
== E_POINTER
, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
939 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
941 hr
= pUrlCombineW(wszUrl1
, wszUrl2
, wszReturnUrl
, &dwSize
, dwFlags
);
942 ok(hr
== dwExpectReturn
, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr
, dwExpectReturn
);
943 ok(dwSize
== dwExpectLen
, "Got length %d, expected %d\n", dwSize
, dwExpectLen
);
945 wszConvertedUrl
= GetWideString(szReturnUrl
);
946 ok(lstrcmpW(wszReturnUrl
, wszConvertedUrl
)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
947 FreeWideString(wszConvertedUrl
);
951 FreeWideString(wszUrl1
);
952 FreeWideString(wszUrl2
);
953 FreeWideString(wszExpectUrl
);
956 /* ########################### */
958 static void test_UrlCombine(void)
961 for(i
=0; i
<sizeof(TEST_COMBINE
)/sizeof(TEST_COMBINE
[0]); i
++) {
962 test_url_combine(TEST_COMBINE
[i
].url1
, TEST_COMBINE
[i
].url2
, TEST_COMBINE
[i
].flags
,
963 TEST_COMBINE
[i
].expectret
, TEST_COMBINE
[i
].expecturl
);
967 /* ########################### */
969 static void test_UrlCreateFromPath(void)
972 char ret_url
[INTERNET_MAX_URL_LENGTH
];
974 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
977 if (!pUrlCreateFromPathA
) {
978 win_skip("UrlCreateFromPathA not found\n");
982 for(i
= 0; i
< sizeof(TEST_URLFROMPATH
) / sizeof(TEST_URLFROMPATH
[0]); i
++) {
983 len
= INTERNET_MAX_URL_LENGTH
;
984 ret
= pUrlCreateFromPathA(TEST_URLFROMPATH
[i
].path
, ret_url
, &len
, 0);
985 ok(ret
== TEST_URLFROMPATH
[i
].ret
, "ret %08x from path %s\n", ret
, TEST_URLFROMPATH
[i
].path
);
986 ok(!lstrcmpi(ret_url
, TEST_URLFROMPATH
[i
].url
), "url %s from path %s\n", ret_url
, TEST_URLFROMPATH
[i
].path
);
987 ok(len
== strlen(ret_url
), "ret len %d from path %s\n", len
, TEST_URLFROMPATH
[i
].path
);
989 if (pUrlCreateFromPathW
) {
990 len
= INTERNET_MAX_URL_LENGTH
;
991 pathW
= GetWideString(TEST_URLFROMPATH
[i
].path
);
992 urlW
= GetWideString(TEST_URLFROMPATH
[i
].url
);
993 ret
= pUrlCreateFromPathW(pathW
, ret_urlW
, &len
, 0);
994 WideCharToMultiByte(CP_ACP
, 0, ret_urlW
, -1, ret_url
, sizeof(ret_url
),0,0);
995 ok(ret
== TEST_URLFROMPATH
[i
].ret
, "ret %08x from path L\"%s\", expected %08x\n",
996 ret
, TEST_URLFROMPATH
[i
].path
, TEST_URLFROMPATH
[i
].ret
);
997 ok(!lstrcmpiW(ret_urlW
, urlW
), "got %s expected %s from path L\"%s\"\n",
998 ret_url
, TEST_URLFROMPATH
[i
].url
, TEST_URLFROMPATH
[i
].path
);
999 ok(len
== lstrlenW(ret_urlW
), "ret len %d from path L\"%s\"\n", len
, TEST_URLFROMPATH
[i
].path
);
1000 FreeWideString(urlW
);
1001 FreeWideString(pathW
);
1006 /* ########################### */
1008 static void test_UrlIs(void)
1015 win_skip("UrlIsA not found\n");
1019 for(i
= 0; i
< sizeof(TEST_PATH_IS_URL
) / sizeof(TEST_PATH_IS_URL
[0]); i
++) {
1020 MultiByteToWideChar(CP_ACP
, 0, TEST_PATH_IS_URL
[i
].path
, -1, wurl
, 80);
1022 ret
= pUrlIsA( TEST_PATH_IS_URL
[i
].path
, URLIS_URL
);
1023 ok( ret
== TEST_PATH_IS_URL
[i
].expect
,
1024 "returned %d from path %s, expected %d\n", ret
, TEST_PATH_IS_URL
[i
].path
,
1025 TEST_PATH_IS_URL
[i
].expect
);
1028 ret
= pUrlIsW( wurl
, URLIS_URL
);
1029 ok( ret
== TEST_PATH_IS_URL
[i
].expect
,
1030 "returned %d from path (UrlIsW) %s, expected %d\n", ret
,
1031 TEST_PATH_IS_URL
[i
].path
, TEST_PATH_IS_URL
[i
].expect
);
1034 for(i
= 0; i
< sizeof(TEST_URLIS_ATTRIBS
) / sizeof(TEST_URLIS_ATTRIBS
[0]); i
++) {
1035 MultiByteToWideChar(CP_ACP
, 0, TEST_URLIS_ATTRIBS
[i
].url
, -1, wurl
, 80);
1037 ret
= pUrlIsA( TEST_URLIS_ATTRIBS
[i
].url
, URLIS_OPAQUE
);
1038 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectOpaque
,
1039 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret
, TEST_URLIS_ATTRIBS
[i
].url
,
1040 TEST_URLIS_ATTRIBS
[i
].expectOpaque
);
1041 ret
= pUrlIsA( TEST_URLIS_ATTRIBS
[i
].url
, URLIS_FILEURL
);
1042 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectFile
,
1043 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret
, TEST_URLIS_ATTRIBS
[i
].url
,
1044 TEST_URLIS_ATTRIBS
[i
].expectFile
);
1047 ret
= pUrlIsW( wurl
, URLIS_OPAQUE
);
1048 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectOpaque
,
1049 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n",
1050 ret
, TEST_URLIS_ATTRIBS
[i
].url
, TEST_URLIS_ATTRIBS
[i
].expectOpaque
);
1051 ret
= pUrlIsW( wurl
, URLIS_FILEURL
);
1052 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectFile
,
1053 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n",
1054 ret
, TEST_URLIS_ATTRIBS
[i
].url
, TEST_URLIS_ATTRIBS
[i
].expectFile
);
1059 /* ########################### */
1061 static void test_UrlUnescape(void)
1063 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
1064 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
1065 WCHAR
*urlW
, *expected_urlW
;
1068 static char inplace
[] = "file:///C:/Program%20Files";
1069 static char another_inplace
[] = "file:///C:/Program%20Files";
1070 static const char expected
[] = "file:///C:/Program Files";
1071 static WCHAR inplaceW
[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
1072 static WCHAR another_inplaceW
[] ={'f','i','l','e',':','/','/','/',
1073 'C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
1076 if (!pUrlUnescapeA
) {
1077 win_skip("UrlUnescapeA not found\n");
1080 for(i
=0; i
<sizeof(TEST_URL_UNESCAPE
)/sizeof(TEST_URL_UNESCAPE
[0]); i
++) {
1081 dwEscaped
=INTERNET_MAX_URL_LENGTH
;
1082 res
= pUrlUnescapeA(TEST_URL_UNESCAPE
[i
].url
, szReturnUrl
, &dwEscaped
, 0);
1084 "UrlUnescapeA returned 0x%x (expected S_OK) for \"%s\"\n",
1085 res
, TEST_URL_UNESCAPE
[i
].url
);
1086 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
);
1088 ZeroMemory(szReturnUrl
, sizeof(szReturnUrl
));
1089 /* if we set the bufferpointer to NULL here UrlUnescape fails and string gets not converted */
1090 res
= pUrlUnescapeA(TEST_URL_UNESCAPE
[i
].url
, szReturnUrl
, NULL
, 0);
1091 ok(res
== E_INVALIDARG
,
1092 "UrlUnescapeA returned 0x%x (expected E_INVALIDARG) for \"%s\"\n",
1093 res
, TEST_URL_UNESCAPE
[i
].url
);
1094 ok(strcmp(szReturnUrl
,"")==0, "Expected empty string\n");
1096 if (pUrlUnescapeW
) {
1097 dwEscaped
= INTERNET_MAX_URL_LENGTH
;
1098 urlW
= GetWideString(TEST_URL_UNESCAPE
[i
].url
);
1099 expected_urlW
= GetWideString(TEST_URL_UNESCAPE
[i
].expect
);
1100 res
= pUrlUnescapeW(urlW
, ret_urlW
, &dwEscaped
, 0);
1102 "UrlUnescapeW returned 0x%x (expected S_OK) for \"%s\"\n",
1103 res
, TEST_URL_UNESCAPE
[i
].url
);
1105 WideCharToMultiByte(CP_ACP
,0,ret_urlW
,-1,szReturnUrl
,INTERNET_MAX_URL_LENGTH
,0,0);
1106 ok(lstrcmpW(ret_urlW
, expected_urlW
)==0,
1107 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n",
1108 TEST_URL_UNESCAPE
[i
].expect
, szReturnUrl
, TEST_URL_UNESCAPE
[i
].url
, 0L);
1109 FreeWideString(urlW
);
1110 FreeWideString(expected_urlW
);
1114 dwEscaped
= sizeof(inplace
);
1115 res
= pUrlUnescapeA(inplace
, NULL
, &dwEscaped
, URL_UNESCAPE_INPLACE
);
1116 ok(res
== S_OK
, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res
);
1117 ok(!strcmp(inplace
, expected
), "got %s expected %s\n", inplace
, expected
);
1118 ok(dwEscaped
== 27, "got %d expected 27\n", dwEscaped
);
1120 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1121 res
= pUrlUnescapeA(another_inplace
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1122 ok(res
== S_OK
, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res
);
1123 ok(!strcmp(another_inplace
, expected
), "got %s expected %s\n", another_inplace
, expected
);
1125 if (pUrlUnescapeW
) {
1126 dwEscaped
= sizeof(inplaceW
);
1127 res
= pUrlUnescapeW(inplaceW
, NULL
, &dwEscaped
, URL_UNESCAPE_INPLACE
);
1128 ok(res
== S_OK
, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res
);
1129 ok(dwEscaped
== 50, "got %d expected 50\n", dwEscaped
);
1131 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1132 res
= pUrlUnescapeW(another_inplaceW
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1133 ok(res
== S_OK
, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res
);
1135 ok(lstrlenW(another_inplaceW
) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW
));
1139 static const struct parse_url_test_t
{
1144 } parse_url_tests
[] = {
1145 {"http://www.winehq.org/",S_OK
,4,URL_SCHEME_HTTP
},
1146 {"https://www.winehq.org/",S_OK
,5,URL_SCHEME_HTTPS
},
1147 {"ftp://www.winehq.org/",S_OK
,3,URL_SCHEME_FTP
},
1148 {"test.txt?test=c:/dir",URL_E_INVALID_SYNTAX
},
1149 {"test.txt",URL_E_INVALID_SYNTAX
},
1150 {"xxx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1151 {"1xx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1152 {"-xx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1153 {"xx0://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1154 {"x://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1155 {"xx$://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1156 {"htt?p://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1157 {"ab-://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1158 {" http://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1161 static void test_ParseURL(void)
1163 const struct parse_url_test_t
*test
;
1164 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
1169 for(test
= parse_url_tests
; test
< parse_url_tests
+ sizeof(parse_url_tests
)/sizeof(*parse_url_tests
); test
++) {
1170 memset(&parseda
, 0xd0, sizeof(parseda
));
1171 parseda
.cbSize
= sizeof(parseda
);
1172 hres
= pParseURLA(test
->url
, &parseda
);
1173 ok(hres
== test
->hres
, "ParseURL failed: %08x, expected %08x\n", hres
, test
->hres
);
1175 ok(parseda
.pszProtocol
== test
->url
, "parseda.pszProtocol = %s, expected %s\n",
1176 parseda
.pszProtocol
, test
->url
);
1177 ok(parseda
.cchProtocol
== test
->protocol_len
, "parseda.cchProtocol = %d, expected %d\n",
1178 parseda
.cchProtocol
, test
->protocol_len
);
1179 ok(parseda
.pszSuffix
== test
->url
+test
->protocol_len
+1, "parseda.pszSuffix = %s, expected %s\n",
1180 parseda
.pszSuffix
, test
->url
+test
->protocol_len
+1);
1181 ok(parseda
.cchSuffix
== strlen(test
->url
+test
->protocol_len
+1),
1182 "parseda.pszSuffix = %d, expected %d\n",
1183 parseda
.cchSuffix
, lstrlenA(test
->url
+test
->protocol_len
+1));
1184 ok(parseda
.nScheme
== test
->scheme
, "parseda.nScheme = %d, expected %d\n",
1185 parseda
.nScheme
, test
->scheme
);
1187 ok(!parseda
.pszProtocol
, "parseda.pszProtocol = %p\n", parseda
.pszProtocol
);
1188 ok(parseda
.nScheme
== 0xd0d0d0d0, "nScheme = %d\n", parseda
.nScheme
);
1191 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
1193 memset(&parsedw
, 0xd0, sizeof(parsedw
));
1194 parsedw
.cbSize
= sizeof(parsedw
);
1195 hres
= pParseURLW(url
, &parsedw
);
1196 ok(hres
== test
->hres
, "ParseURL failed: %08x, expected %08x\n", hres
, test
->hres
);
1198 ok(parsedw
.pszProtocol
== url
, "parsedw.pszProtocol = %s, expected %s\n",
1199 wine_dbgstr_w(parsedw
.pszProtocol
), wine_dbgstr_w(url
));
1200 ok(parsedw
.cchProtocol
== test
->protocol_len
, "parsedw.cchProtocol = %d, expected %d\n",
1201 parsedw
.cchProtocol
, test
->protocol_len
);
1202 ok(parsedw
.pszSuffix
== url
+test
->protocol_len
+1, "parsedw.pszSuffix = %s, expected %s\n",
1203 wine_dbgstr_w(parsedw
.pszSuffix
), wine_dbgstr_w(url
+test
->protocol_len
+1));
1204 ok(parsedw
.cchSuffix
== strlen(test
->url
+test
->protocol_len
+1),
1205 "parsedw.pszSuffix = %d, expected %d\n",
1206 parsedw
.cchSuffix
, lstrlenA(test
->url
+test
->protocol_len
+1));
1207 ok(parsedw
.nScheme
== test
->scheme
, "parsedw.nScheme = %d, expected %d\n",
1208 parsedw
.nScheme
, test
->scheme
);
1210 ok(!parsedw
.pszProtocol
, "parsedw.pszProtocol = %p\n", parseda
.pszProtocol
);
1211 ok(parsedw
.nScheme
== 0xd0d0d0d0, "nScheme = %d\n", parsedw
.nScheme
);
1216 static void test_HashData(void)
1219 BYTE input
[16] = {0x51, 0x33, 0x4F, 0xA7, 0x45, 0x15, 0xF0, 0x52, 0x90,
1220 0x2B, 0xE7, 0xF5, 0xFD, 0xE1, 0xA6, 0xA7};
1222 static const BYTE expected
[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1223 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1225 static const BYTE expected2
[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1226 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1227 0xE3, 0x2D, 0x47, 0xFC, 0x80, 0xB8, 0xD0,
1228 0x49, 0xE6, 0x13, 0x2A, 0x30, 0x51, 0x8D,
1229 0xF9, 0x4B, 0x07, 0xA6};
1230 static const BYTE expected3
[] = {0x2B, 0xDC, 0x9A, 0x1B, 0xF0, 0x5A, 0xF9,
1231 0xC6, 0xBE, 0x94, 0x6D, 0xF3, 0x33, 0xC1,
1235 /* Test hashing with identically sized input/output buffers. */
1236 res
= pHashData(input
, 16, output
, 16);
1237 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1239 ok(!memcmp(output
, expected
, sizeof(expected
)),
1240 "Output buffer did not match expected contents\n");
1242 /* Test hashing with larger output buffer. */
1243 res
= pHashData(input
, 16, output
, 32);
1244 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1246 ok(!memcmp(output
, expected2
, sizeof(expected2
)),
1247 "Output buffer did not match expected contents\n");
1249 /* Test hashing with smaller input buffer. */
1250 res
= pHashData(input
, 8, output
, 16);
1251 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1253 ok(!memcmp(output
, expected3
, sizeof(expected3
)),
1254 "Output buffer did not match expected contents\n");
1256 /* Test passing NULL pointers for input/output parameters. */
1257 res
= pHashData(NULL
, 0, NULL
, 0);
1258 ok(res
== E_INVALIDARG
|| broken(res
== S_OK
), /* Windows 2000 */
1259 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res
);
1261 res
= pHashData(input
, 0, NULL
, 0);
1262 ok(res
== E_INVALIDARG
|| broken(res
== S_OK
), /* Windows 2000 */
1263 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res
);
1265 res
= pHashData(NULL
, 0, output
, 0);
1266 ok(res
== E_INVALIDARG
|| broken(res
== S_OK
), /* Windows 2000 */
1267 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res
);
1269 /* Test passing valid pointers with sizes of zero. */
1270 for (i
= 0; i
< sizeof(input
)/sizeof(BYTE
); i
++)
1273 for (i
= 0; i
< sizeof(output
)/sizeof(BYTE
); i
++)
1276 res
= pHashData(input
, 0, output
, 0);
1277 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1279 /* The buffers should be unchanged. */
1280 for (i
= 0; i
< sizeof(input
)/sizeof(BYTE
); i
++)
1282 ok(input
[i
] == 0x00, "Expected the input buffer to be unchanged\n");
1283 if(input
[i
] != 0x00) break;
1286 for (i
= 0; i
< sizeof(output
)/sizeof(BYTE
); i
++)
1288 ok(output
[i
] == 0xFF, "Expected the output buffer to be unchanged\n");
1289 if(output
[i
] != 0xFF) break;
1292 /* Input/output parameters are not validated. */
1293 res
= pHashData((BYTE
*)0xdeadbeef, 0, (BYTE
*)0xdeadbeef, 0);
1294 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1298 res
= pHashData((BYTE
*)0xdeadbeef, 1, (BYTE
*)0xdeadbeef, 1);
1299 trace("HashData returned 0x%08x\n", res
);
1303 /* ########################### */
1308 hShlwapi
= GetModuleHandleA("shlwapi.dll");
1309 pUrlUnescapeA
= (void *) GetProcAddress(hShlwapi
, "UrlUnescapeA");
1310 pUrlUnescapeW
= (void *) GetProcAddress(hShlwapi
, "UrlUnescapeW");
1311 pUrlIsA
= (void *) GetProcAddress(hShlwapi
, "UrlIsA");
1312 pUrlIsW
= (void *) GetProcAddress(hShlwapi
, "UrlIsW");
1313 pUrlHashA
= (void *) GetProcAddress(hShlwapi
, "UrlHashA");
1314 pUrlHashW
= (void *) GetProcAddress(hShlwapi
, "UrlHashW");
1315 pUrlGetPartA
= (void *) GetProcAddress(hShlwapi
, "UrlGetPartA");
1316 pUrlGetPartW
= (void *) GetProcAddress(hShlwapi
, "UrlGetPartW");
1317 pUrlEscapeA
= (void *) GetProcAddress(hShlwapi
, "UrlEscapeA");
1318 pUrlEscapeW
= (void *) GetProcAddress(hShlwapi
, "UrlEscapeW");
1319 pUrlCreateFromPathA
= (void *) GetProcAddress(hShlwapi
, "UrlCreateFromPathA");
1320 pUrlCreateFromPathW
= (void *) GetProcAddress(hShlwapi
, "UrlCreateFromPathW");
1321 pUrlCombineA
= (void *) GetProcAddress(hShlwapi
, "UrlCombineA");
1322 pUrlCombineW
= (void *) GetProcAddress(hShlwapi
, "UrlCombineW");
1323 pUrlCanonicalizeA
= (void *) GetProcAddress(hShlwapi
, "UrlCanonicalizeA");
1324 pUrlCanonicalizeW
= (void *) GetProcAddress(hShlwapi
, "UrlCanonicalizeW");
1325 pUrlApplySchemeA
= (void *) GetProcAddress(hShlwapi
, "UrlApplySchemeA");
1326 pUrlApplySchemeW
= (void *) GetProcAddress(hShlwapi
, "UrlApplySchemeW");
1327 pParseURLA
= (void*)GetProcAddress(hShlwapi
, (LPCSTR
)1);
1328 pParseURLW
= (void*)GetProcAddress(hShlwapi
, (LPCSTR
)2);
1329 pHashData
= (void*)GetProcAddress(hShlwapi
, "HashData");
1331 test_UrlApplyScheme();
1334 test_UrlCanonicalizeA();
1335 test_UrlCanonicalizeW();
1338 test_UrlCreateFromPath();