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 static const char* TEST_URL_1
= "http://www.winehq.org/tests?date=10/10/1923";
33 static const char* TEST_URL_2
= "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
34 static const char* TEST_URL_3
= "http://foo:bar@localhost:21/internal.php?query=x&return=y";
36 static const WCHAR winehqW
[] = L
"http://www.winehq.org/";
37 static const char winehqA
[] = "http://www.winehq.org/";
38 static const CHAR untouchedA
[] = "untouched";
40 typedef struct _TEST_URL_APPLY
{
47 static const TEST_URL_APPLY TEST_APPLY
[] = {
48 {"www.winehq.org", URL_APPLY_GUESSSCHEME
| URL_APPLY_DEFAULT
, S_OK
, "http://www.winehq.org"},
49 {"www.winehq.org", URL_APPLY_GUESSSCHEME
, S_OK
, "http://www.winehq.org"},
50 {"www.winehq.org", URL_APPLY_DEFAULT
, S_OK
, "http://www.winehq.org"},
51 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME
| URL_APPLY_DEFAULT
, S_OK
, "ftp://ftp.winehq.org"},
52 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME
, S_OK
, "ftp://ftp.winehq.org"},
53 {"ftp.winehq.org", URL_APPLY_DEFAULT
, S_OK
, "http://ftp.winehq.org"},
54 {"winehq.org", URL_APPLY_GUESSSCHEME
| URL_APPLY_DEFAULT
, S_OK
, "http://winehq.org"},
55 {"winehq.org", URL_APPLY_GUESSSCHEME
, S_FALSE
},
56 {"winehq.org", URL_APPLY_DEFAULT
, S_OK
, "http://winehq.org"},
57 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME
, S_FALSE
},
58 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME
| URL_APPLY_FORCEAPPLY
, S_FALSE
},
59 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME
| URL_APPLY_FORCEAPPLY
| URL_APPLY_DEFAULT
, S_OK
, "http://http://www.winehq.org"},
60 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME
| URL_APPLY_DEFAULT
, S_FALSE
},
61 {"", URL_APPLY_GUESSSCHEME
| URL_APPLY_DEFAULT
, S_OK
, "http://"},
62 {"", URL_APPLY_GUESSSCHEME
, S_FALSE
},
63 {"", URL_APPLY_DEFAULT
, S_OK
, "http://"},
64 {"u:\\windows", URL_APPLY_GUESSFILE
| URL_APPLY_DEFAULT
, S_OK
, "file:///u:/windows"},
65 {"u:\\windows", URL_APPLY_GUESSFILE
, S_OK
, "file:///u:/windows"},
66 {"u:\\windows", URL_APPLY_DEFAULT
, S_OK
, "http://u:\\windows"},
67 {"file:///c:/windows", URL_APPLY_GUESSFILE
, S_FALSE
},
68 {"aa:\\windows", URL_APPLY_GUESSFILE
, S_FALSE
},
69 {"\\\\server\\share", URL_APPLY_DEFAULT
, S_OK
, "http://\\\\server\\share"},
70 {"\\\\server\\share", URL_APPLY_GUESSFILE
, S_OK
, "file://server/share"},
71 {"\\\\server\\share", URL_APPLY_GUESSSCHEME
, S_FALSE
},
72 {"file://server/share", URL_APPLY_GUESSFILE
, S_FALSE
},
73 {"file://server/share", URL_APPLY_GUESSSCHEME
, S_FALSE
},
76 /* ################ */
78 typedef struct _TEST_URL_CANONICALIZE
{
81 const char *expecturl
;
83 } TEST_URL_CANONICALIZE
;
85 static const TEST_URL_CANONICALIZE TEST_CANONICALIZE
[] = {
87 {"http://www.winehq.org/tests/../tests/../..", 0, "http://www.winehq.org/", TRUE
},
88 {"http://www.winehq.org/..", 0, "http://www.winehq.org/..", FALSE
},
89 {"http://www.winehq.org/tests/tests2/../../tests", 0, "http://www.winehq.org/tests", FALSE
},
90 {"http://www.winehq.org/tests/../tests", 0, "http://www.winehq.org/tests", FALSE
},
91 {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY
|URL_ESCAPE_SPACES_ONLY
|URL_ESCAPE_UNSAFE
, "http://www.winehq.org/tests", FALSE
},
92 {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY
|URL_ESCAPE_SPACES_ONLY
|URL_ESCAPE_UNSAFE
, "http://www.winehq.org/tests", FALSE
},
93 {"http://www.winehq.org/tests\r", 0, "http://www.winehq.org/tests", FALSE
},
94 {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY
, "http://www.winehq.org/tests", FALSE
},
95 {"http://www.winehq.org/tests/../tests/", 0, "http://www.winehq.org/tests/", FALSE
},
96 {"http://www.winehq.org/tests/../tests/..", 0, "http://www.winehq.org/", FALSE
},
97 {"http://www.winehq.org/tests/../tests/../", 0, "http://www.winehq.org/", FALSE
},
98 {"http://www.winehq.org/tests/..", 0, "http://www.winehq.org/", FALSE
},
99 {"http://www.winehq.org/tests/../", 0, "http://www.winehq.org/", FALSE
},
100 {"http://www.winehq.org/tests/..?query=x&return=y", 0, "http://www.winehq.org/?query=x&return=y", FALSE
},
101 {"http://www.winehq.org/tests/../?query=x&return=y", 0, "http://www.winehq.org/?query=x&return=y", FALSE
},
102 {"\tht\ttp\t://www\t.w\tineh\t\tq.or\tg\t/\ttests/..\t?\tquer\ty=x\t\t&re\tturn=y\t\t", 0, "http://www.winehq.org/?query=x&return=y", FALSE
},
103 {"http://www.winehq.org/tests/..#example", 0, "http://www.winehq.org/#example", FALSE
},
104 {"http://www.winehq.org/tests/../#example", 0, "http://www.winehq.org/#example", FALSE
},
105 {"http://www.winehq.org/tests\\../#example", 0, "http://www.winehq.org/#example", FALSE
},
106 {"http://www.winehq.org/tests/..\\#example", 0, "http://www.winehq.org/#example", FALSE
},
107 {"http://www.winehq.org\\tests/../#example", 0, "http://www.winehq.org/#example", FALSE
},
108 {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY
, "http://www.winehq.org/tests/../#example", FALSE
},
109 {"http://www.winehq.org/tests/foo bar", URL_ESCAPE_SPACES_ONLY
| URL_DONT_ESCAPE_EXTRA_INFO
, "http://www.winehq.org/tests/foo%20bar", FALSE
},
110 {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE
, "http://www.winehq.org/tests/foo bar", FALSE
},
111 {"http://www.winehq.org", 0, "http://www.winehq.org/", FALSE
},
112 {"http:///www.winehq.org", 0, "http:///www.winehq.org", FALSE
},
113 {"http:////www.winehq.org", 0, "http:////www.winehq.org", FALSE
},
114 {"file:///c:/tests/foo%20bar", URL_UNESCAPE
, "file:///c:/tests/foo bar", FALSE
},
115 {"file:///c:/tests\\foo%20bar", URL_UNESCAPE
, "file:///c:/tests/foo bar", FALSE
},
116 {"file:///c:/tests/foo%20bar", 0, "file:///c:/tests/foo%20bar", FALSE
},
117 {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
118 {"file://localhost/c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
119 {"file://localhost\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
120 {"file://localhost\\\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
121 {"file://localhost\\c:\\tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
122 {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
123 {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
124 {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
125 {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL
, "file://c:\\\\tests\\foo bar", FALSE
},
126 {"file:///c:\\tests\\foo bar", 0, "file:///c:/tests/foo bar", FALSE
},
127 {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY
, "file:///c:/tests/foo bar", FALSE
},
128 {"file:///c:\\tests\\foobar", 0, "file:///c:/tests/foobar", FALSE
},
129 {"file:///c:\\tests\\foobar", URL_WININET_COMPATIBILITY
, "file://c:\\tests\\foobar", FALSE
},
130 {"file://home/user/file", 0, "file://home/user/file", FALSE
},
131 {"file:///home/user/file", 0, "file:///home/user/file", FALSE
},
132 {"file:////home/user/file", 0, "file://home/user/file", FALSE
},
133 {"file://home/user/file", URL_WININET_COMPATIBILITY
, "file://\\\\home\\user\\file", FALSE
},
134 {"file:///home/user/file", URL_WININET_COMPATIBILITY
, "file://\\home\\user\\file", FALSE
},
135 {"file:////home/user/file", URL_WININET_COMPATIBILITY
, "file://\\\\home\\user\\file", FALSE
},
136 {"file://///home/user/file", URL_WININET_COMPATIBILITY
, "file://\\\\home\\user\\file", FALSE
},
137 {"file://C:/user/file", 0, "file:///C:/user/file", FALSE
},
138 {"file://C:/user/file/../asdf", 0, "file:///C:/user/asdf", FALSE
},
139 {"file:///C:/user/file", 0, "file:///C:/user/file", FALSE
},
140 {"file:////C:/user/file", 0, "file:///C:/user/file", FALSE
},
141 {"file://C:/user/file", URL_WININET_COMPATIBILITY
, "file://C:\\user\\file", FALSE
},
142 {"file:///C:/user/file", URL_WININET_COMPATIBILITY
, "file://C:\\user\\file", FALSE
},
143 {"file:////C:/user/file", URL_WININET_COMPATIBILITY
, "file://C:\\user\\file", FALSE
},
144 {"http:///www.winehq.org", 0, "http:///www.winehq.org", FALSE
},
145 {"http:///www.winehq.org", URL_WININET_COMPATIBILITY
, "http:///www.winehq.org", FALSE
},
146 {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL
, "http://www.winehq.org/site/about", FALSE
},
147 {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL
, "file_://www.winehq.org/site/about", FALSE
},
148 {"c:\\dir\\file", 0, "file:///c:/dir/file", FALSE
},
149 {"file:///c:\\dir\\file", 0, "file:///c:/dir/file", FALSE
},
150 {"c:dir\\file", 0, "file:///c:dir/file", FALSE
},
151 {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL
, "file://c:\\tests\\foo bar", FALSE
},
152 {"c:\\tests\\foo bar", 0, "file:///c:/tests/foo%20bar", FALSE
},
153 {"c\t:\t\\te\tsts\\fo\to \tbar\t", 0, "file:///c:/tests/foo%20bar", FALSE
},
154 {"res://file", 0, "res://file/", FALSE
},
155 {"res://file", URL_FILE_USE_PATHURL
, "res://file/", FALSE
},
156 {"res:///c:/tests/foo%20bar", URL_UNESCAPE
, "res:///c:/tests/foo bar", FALSE
},
157 {"res:///c:/tests\\foo%20bar", URL_UNESCAPE
, "res:///c:/tests\\foo bar", FALSE
},
158 {"res:///c:/tests/foo%20bar", 0, "res:///c:/tests/foo%20bar", FALSE
},
159 {"res:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL
, "res:///c:/tests/foo%20bar", FALSE
},
160 {"res://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, "res://c:/tests/foo%20bar", FALSE
},
161 {"res://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL
, "res://c:/tests/foo%20bar", FALSE
},
162 {"res://c:/tests/foo%20bar", URL_FILE_USE_PATHURL
, "res://c:/tests/foo%20bar", FALSE
},
163 {"res:///c://tests/foo%20bar", URL_FILE_USE_PATHURL
, "res:///c://tests/foo%20bar", FALSE
},
164 {"res:///c:\\tests\\foo bar", 0, "res:///c:\\tests\\foo bar", FALSE
},
165 {"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY
, "res:///c:\\tests\\foo bar", FALSE
},
166 {"res://c:\\tests\\foo bar/res", URL_FILE_USE_PATHURL
, "res://c:\\tests\\foo bar/res", FALSE
},
167 {"res://c:\\tests/res\\foo%20bar/strange\\sth", 0, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE
},
168 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_FILE_USE_PATHURL
, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE
},
169 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_UNESCAPE
, "res://c:\\tests/res\\foo bar/strange\\sth", FALSE
},
170 {"/A/../B/./C/../../test_remove_dot_segments", 0, "/test_remove_dot_segments", FALSE
},
171 {"/A/../B/./C/../../test_remove_dot_segments", URL_FILE_USE_PATHURL
, "/test_remove_dot_segments", FALSE
},
172 {"/A/../B/./C/../../test_remove_dot_segments", URL_WININET_COMPATIBILITY
, "/test_remove_dot_segments", FALSE
},
173 {"/A/B\\C/D\\E", 0, "/A/B\\C/D\\E", FALSE
},
174 {"/A/B\\C/D\\E", URL_FILE_USE_PATHURL
, "/A/B\\C/D\\E", FALSE
},
175 {"/A/B\\C/D\\E", URL_WININET_COMPATIBILITY
, "/A/B\\C/D\\E", FALSE
},
176 {"///A/../B", 0, "///B", FALSE
},
177 {"///A/../B", URL_FILE_USE_PATHURL
, "///B", FALSE
},
178 {"///A/../B", URL_WININET_COMPATIBILITY
, "///B", FALSE
},
179 {"A", 0, "A", FALSE
},
180 {"../A", 0, "../A", FALSE
},
181 {"A/../B", 0, "B", TRUE
},
182 {"/uri-res/N2R?urn:sha1:B3K", URL_DONT_ESCAPE_EXTRA_INFO
| URL_WININET_COMPATIBILITY
/*0x82000000*/, "/uri-res/N2R?urn:sha1:B3K", FALSE
} /*LimeWire online installer calls this*/,
183 {"http:www.winehq.org/dir/../index.html", 0, "http:www.winehq.org/index.html"},
184 {"http://localhost/test.html", URL_FILE_USE_PATHURL
, "http://localhost/test.html"},
185 {"http://localhost/te%20st.html", URL_FILE_USE_PATHURL
, "http://localhost/te%20st.html"},
186 {"http://www.winehq.org/%E6%A1%9C.html", URL_FILE_USE_PATHURL
, "http://www.winehq.org/%E6%A1%9C.html"},
187 {"mk:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", 0, "mk:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
188 {"ftp:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", 0, "ftp:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
189 {"file:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", 0, "file:@MSITStore:C:/Program Files/AutoCAD 2008/Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
190 {"http:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", 0, "http:@MSITStore:C:/Program Files/AutoCAD 2008/Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
191 {"http:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", URL_FILE_USE_PATHURL
, "http:@MSITStore:C:/Program Files/AutoCAD 2008/Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
192 {"mk:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", URL_FILE_USE_PATHURL
, "mk:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
195 /* ################ */
197 typedef struct _TEST_URL_ESCAPE
{
200 const char *expecturl
;
203 static const TEST_URL_ESCAPE TEST_ESCAPE
[] = {
204 {"http://www.winehq.org/tests0", 0, "http://www.winehq.org/tests0"},
205 {"http://www.winehq.org/tests1\n", 0, "http://www.winehq.org/tests1%0A"},
206 {"http://www.winehq.org/tests2\r", 0, "http://www.winehq.org/tests2%0D"},
207 {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY
|URL_ESCAPE_UNSAFE
, "http://www.winehq.org/tests3\r"},
208 {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY
, "http://www.winehq.org/tests4\r"},
209 {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY
|URL_ESCAPE_SPACES_ONLY
, "http://www.winehq.org/tests5\r"},
210 {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY
, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
212 {"file://////foo/bar\\baz", 0, "file://foo/bar/baz"},
213 {"file://///foo/bar\\baz", 0, "file://foo/bar/baz"},
214 {"file:////foo/bar\\baz", 0, "file://foo/bar/baz"},
215 {"file:///localhost/foo/bar\\baz", 0, "file:///localhost/foo/bar/baz"},
216 {"file:///foo/bar\\baz", 0, "file:///foo/bar/baz"},
217 {"file://loCalHost/foo/bar\\baz", 0, "file:///foo/bar/baz"},
218 {"file://foo/bar\\baz", 0, "file://foo/bar/baz"},
219 {"file:/localhost/foo/bar\\baz", 0, "file:///localhost/foo/bar/baz"},
220 {"file:/foo/bar\\baz", 0, "file:///foo/bar/baz"},
221 {"file:foo/bar\\baz", 0, "file:foo/bar/baz"},
222 {"file:\\foo/bar\\baz", 0, "file:///foo/bar/baz"},
223 {"file:\\\\foo/bar\\baz", 0, "file://foo/bar/baz"},
224 {"file:\\\\\\foo/bar\\baz", 0, "file:///foo/bar/baz"},
225 {"file:\\\\localhost\\foo/bar\\baz", 0, "file:///foo/bar/baz"},
226 {"file:///f oo/b?a r\\baz", 0, "file:///f%20oo/b?a r\\baz"},
227 {"file:///foo/b#a r\\baz", 0, "file:///foo/b%23a%20r/baz"},
228 {"file:///f o^&`{}|][\"<>\\%o/b#a r\\baz", 0, "file:///f%20o%5E%26%60%7B%7D%7C%5D%5B%22%3C%3E/%o/b%23a%20r/baz"},
229 {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT
, "file:///f%20o%25o/b?a r\\b%az"},
230 {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY
, "file:%2Ffoo%2Fbar%5Cbaz"},
232 {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY
, "foo%2Fb%ar%5Cba%3Fz%5C"},
233 {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT
| URL_ESCAPE_SEGMENT_ONLY
, "foo%2Fb%25ar%5Cba%3Fz%5C"},
234 {"foo/bar\\ba?z\\", 0, "foo/bar%5Cba?z\\"},
235 {"/foo/bar\\ba?z\\", 0, "/foo/bar%5Cba?z\\"},
236 {"/foo/bar\\ba#z\\", 0, "/foo/bar%5Cba#z\\"},
237 {"/foo/%5C", 0, "/foo/%5C"},
238 {"/foo/%5C", URL_ESCAPE_PERCENT
, "/foo/%255C"},
240 {"http://////foo/bar\\baz", 0, "http://////foo/bar/baz"},
241 {"http://///foo/bar\\baz", 0, "http://///foo/bar/baz"},
242 {"http:////foo/bar\\baz", 0, "http:////foo/bar/baz"},
243 {"http:///foo/bar\\baz", 0, "http:///foo/bar/baz"},
244 {"http://localhost/foo/bar\\baz", 0, "http://localhost/foo/bar/baz"},
245 {"http://foo/bar\\baz", 0, "http://foo/bar/baz"},
246 {"http:/foo/bar\\baz", 0, "http:/foo/bar/baz"},
247 {"http:foo/bar\\ba?z\\", 0, "http:foo%2Fbar%2Fba?z\\"},
248 {"http:foo/bar\\ba#z\\", 0, "http:foo%2Fbar%2Fba#z\\"},
249 {"http:\\foo/bar\\baz", 0, "http:/foo/bar/baz"},
250 {"http:\\\\foo/bar\\baz", 0, "http://foo/bar/baz"},
251 {"http:\\\\\\foo/bar\\baz", 0, "http:///foo/bar/baz"},
252 {"http:\\\\\\\\foo/bar\\baz", 0, "http:////foo/bar/baz"},
253 {"http:/fo ?o/b ar\\baz", 0, "http:/fo%20?o/b ar\\baz"},
254 {"http:fo ?o/b ar\\baz", 0, "http:fo%20?o/b ar\\baz"},
255 {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY
, "http:%2Ffoo%2Fbar%5Cbaz"},
257 {"https://foo/bar\\baz", 0, "https://foo/bar/baz"},
258 {"https:/foo/bar\\baz", 0, "https:/foo/bar/baz"},
259 {"https:\\foo/bar\\baz", 0, "https:/foo/bar/baz"},
261 {"foo:////foo/bar\\baz", 0, "foo:////foo/bar%5Cbaz"},
262 {"foo:///foo/bar\\baz", 0, "foo:///foo/bar%5Cbaz"},
263 {"foo://localhost/foo/bar\\baz", 0, "foo://localhost/foo/bar%5Cbaz"},
264 {"foo://foo/bar\\baz", 0, "foo://foo/bar%5Cbaz"},
265 {"foo:/foo/bar\\baz", 0, "foo:/foo/bar%5Cbaz"},
266 {"foo:foo/bar\\baz", 0, "foo:foo%2Fbar%5Cbaz"},
267 {"foo:\\foo/bar\\baz", 0, "foo:%5Cfoo%2Fbar%5Cbaz"},
268 {"foo:/foo/bar\\ba?\\z", 0, "foo:/foo/bar%5Cba?\\z"},
269 {"foo:/foo/bar\\ba#\\z", 0, "foo:/foo/bar%5Cba#\\z"},
271 {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
272 {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
273 {"mailto:fo/o@b\\%a?\\r.b#\\az", URL_ESCAPE_PERCENT
, "mailto:fo%2Fo@b%5C%25a%3F%5Cr.b%23%5Caz"},
275 {"ftp:fo/o@bar.baz/foo/bar", 0, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
276 {"ftp:/fo/o@bar.baz/foo/bar", 0, "ftp:/fo/o@bar.baz/foo/bar"},
277 {"ftp://fo/o@bar.baz/fo?o\\bar", 0, "ftp://fo/o@bar.baz/fo?o\\bar"},
278 {"ftp://fo/o@bar.baz/fo#o\\bar", 0, "ftp://fo/o@bar.baz/fo#o\\bar"},
279 {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, "ftp://localhost/o@bar.baz/fo#o\\bar"},
280 {"ftp:///fo/o@bar.baz/foo/bar", 0, "ftp:///fo/o@bar.baz/foo/bar"},
281 {"ftp:////fo/o@bar.baz/foo/bar", 0, "ftp:////fo/o@bar.baz/foo/bar"},
283 {"ftp\x1f\1end/", 0, "ftp%1F%01end/"}
286 typedef struct _TEST_URL_ESCAPEW
{
287 const WCHAR url
[INTERNET_MAX_URL_LENGTH
];
289 const WCHAR expecturl
[INTERNET_MAX_URL_LENGTH
];
290 const WCHAR win7url
[INTERNET_MAX_URL_LENGTH
]; /* <= Win7 */
293 static const TEST_URL_ESCAPEW TEST_ESCAPEW
[] = {
294 {L
" <>\"", URL_ESCAPE_AS_UTF8
, L
"%20%3C%3E%22"},
295 {L
"{}|\\", URL_ESCAPE_AS_UTF8
, L
"%7B%7D%7C%5C"},
296 {L
"^][`", URL_ESCAPE_AS_UTF8
, L
"%5E%5D%5B%60"},
297 {L
"&/?#", URL_ESCAPE_AS_UTF8
, L
"%26/?#"},
298 {L
"Mass", URL_ESCAPE_AS_UTF8
, L
"Mass"},
300 /* broken < Win8/10 */
301 {L
"Ma\xdf", URL_ESCAPE_AS_UTF8
, L
"Ma%C3%9F", L
"Ma%DF"},
302 {L
"\xd841\xdf0e", URL_ESCAPE_AS_UTF8
, L
"%F0%A0%9C%8E", L
"%EF%BF%BD%EF%BF%BD"}, /* 0x2070E */
303 {L
"\xd85e\xde3e", URL_ESCAPE_AS_UTF8
, L
"%F0%A7%A8%BE", L
"%EF%BF%BD%EF%BF%BD"}, /* 0x27A3E */
304 {L
"\xd85e", URL_ESCAPE_AS_UTF8
, L
"%EF%BF%BD", L
"\xd85e"},
305 {L
"\xd85eQ", URL_ESCAPE_AS_UTF8
, L
"%EF%BF%BDQ", L
"\xd85eQ"},
306 {L
"\xdc00", URL_ESCAPE_AS_UTF8
, L
"%EF%BF%BD", L
"\xdc00"},
307 {L
"\xffff", URL_ESCAPE_AS_UTF8
, L
"%EF%BF%BF", L
"\xffff"},
310 /* ################ */
312 typedef struct _TEST_URL_COMBINE
{
316 const char *expecturl
;
319 static const TEST_URL_COMBINE TEST_COMBINE
[] = {
320 {"http://www.winehq.org/tests", "tests1", 0, "http://www.winehq.org/tests1"},
321 {"http://www.%77inehq.org/tests", "tests1", 0, "http://www.%77inehq.org/tests1"},
322 /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, "http://www.winehq.org/tests2"},*/
323 {"http://www.winehq.org/tests/", "../tests3", 0, "http://www.winehq.org/tests3"},
324 {"http://www.winehq.org/tests/test1", "test2", 0, "http://www.winehq.org/tests/test2"},
325 {"http://www.winehq.org/tests/../tests", "tests4", 0, "http://www.winehq.org/tests4"},
326 {"http://www.winehq.org/tests/../tests/", "tests5", 0, "http://www.winehq.org/tests/tests5"},
327 {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, "http://www.winehq.org/"},
328 {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, "http://www.winehq.org/"},
329 {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, "http://www.winehq.org/tests/tests8"},
330 {"http://www.winehq.org/tests/#example", "tests9", 0, "http://www.winehq.org/tests/tests9"},
331 {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY
, "http://www.winehq.org/tests10/.."},
332 {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY
, "http://www.winehq.org/tests/../tests11"},
333 {"http://www.winehq.org/test12", "#", 0, "http://www.winehq.org/test12#"},
334 {"http://www.winehq.org/test13#aaa", "#bbb", 0, "http://www.winehq.org/test13#bbb"},
335 {"http://www.winehq.org/test14#aaa/bbb#ccc", "#", 0, "http://www.winehq.org/test14#"},
336 {"http://www.winehq.org/tests/?query=x/y/z", "tests15", 0, "http://www.winehq.org/tests/tests15"},
337 {"http://www.winehq.org/tests/?query=x/y/z#example", "tests16", 0, "http://www.winehq.org/tests/tests16"},
338 {"file:///C:\\dir\\file.txt", "test.txt", 0, "file:///C:/dir/test.txt"},
339 {"file:///C:\\dir\\file.txt#hash\\hash", "test.txt", 0, "file:///C:/dir/file.txt#hash/test.txt"},
340 {"file:///C:\\dir\\file.html#hash\\hash", "test.html", 0, "file:///C:/dir/test.html"},
341 {"file:///C:\\dir\\file.htm#hash\\hash", "test.htm", 0, "file:///C:/dir/test.htm"},
342 {"file:///C:\\dir\\file.hTmL#hash\\hash", "test.hTmL", 0, "file:///C:/dir/test.hTmL"},
343 {"file:///C:\\dir.html\\file.txt#hash\\hash", "test.txt", 0, "file:///C:/dir.html/file.txt#hash/test.txt"},
344 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, "file:///C:/Test/test.txt"},
345 {"http://www.winehq.org/test/", "test%20file.txt", 0, "http://www.winehq.org/test/test%20file.txt"},
346 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL
, "http://www.winehq.org/test/test%20file.txt"},
347 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL
, "http://www.winehq.org%2ftest/test%20file.txt"},
348 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, "xxx:dir/file"},
349 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, "mk:@MSITStore:file.chm::/dir/file"},
350 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, "mk:@MSITStore:file.chm::/dir/file"},
351 {"foo:today", "foo:calendar", 0, "foo:calendar"},
352 {"foo:today", "bar:calendar", 0, "bar:calendar"},
353 {"foo:/today", "foo:calendar", 0, "foo:/calendar"},
354 {"Foo:/today/", "fOo:calendar", 0, "foo:/today/calendar"},
355 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
356 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
357 /* UrlCombine case 2 tests. Schemes do not match */
358 {"outbind://xxxxxxxxx", "http://wine1/dir", 0, "http://wine1/dir"},
359 {"xxxx://xxxxxxxxx", "http://wine2/dir", 0, "http://wine2/dir"},
360 {"ftp://xxxxxxxxx/", "http://wine3/dir", 0, "http://wine3/dir"},
361 {"outbind://xxxxxxxxx", "http://wine4/dir", URL_PLUGGABLE_PROTOCOL
, "http://wine4/dir"},
362 {"xxx://xxxxxxxxx", "http://wine5/dir", URL_PLUGGABLE_PROTOCOL
, "http://wine5/dir"},
363 {"ftp://xxxxxxxxx/", "http://wine6/dir", URL_PLUGGABLE_PROTOCOL
, "http://wine6/dir"},
364 {"http://xxxxxxxxx", "outbind://wine7/dir", 0, "outbind://wine7/dir"},
365 {"xxx://xxxxxxxxx", "ftp://wine8/dir", 0, "ftp://wine8/dir"},
366 {"ftp://xxxxxxxxx/", "xxx://wine9/dir", 0, "xxx://wine9/dir"},
367 {"http://xxxxxxxxx", "outbind://wine10/dir", URL_PLUGGABLE_PROTOCOL
, "outbind://wine10/dir"},
368 {"xxx://xxxxxxxxx", "ftp://wine11/dir", URL_PLUGGABLE_PROTOCOL
, "ftp://wine11/dir"},
369 {"ftp://xxxxxxxxx/", "xxx://wine12/dir", URL_PLUGGABLE_PROTOCOL
, "xxx://wine12/dir"},
370 {"http://xxxxxxxxx", "outbind:wine13/dir", 0, "outbind:wine13/dir"},
371 {"xxx://xxxxxxxxx", "ftp:wine14/dir", 0, "ftp:wine14/dir"},
372 {"ftp://xxxxxxxxx/", "xxx:wine15/dir", 0, "xxx:wine15/dir"},
373 {"outbind://xxxxxxxxx/", "http:wine16/dir", 0, "http:wine16/dir"},
374 {"http://xxxxxxxxx", "outbind:wine17/dir", URL_PLUGGABLE_PROTOCOL
, "outbind:wine17/dir"},
375 {"xxx://xxxxxxxxx", "ftp:wine18/dir", URL_PLUGGABLE_PROTOCOL
, "ftp:wine18/dir"},
376 {"ftp://xxxxxxxxx/", "xXx:wine19/dir", URL_PLUGGABLE_PROTOCOL
, "xxx:wine19/dir"},
377 {"outbind://xxxxxxxxx/", "http:wine20/dir", URL_PLUGGABLE_PROTOCOL
, "http:wine20/dir"},
378 {"file:///c:/dir/file.txt", "index.html?test=c:/abc", URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
, "file:///c:/dir/index.html?test=c:/abc"}
381 /* ################ */
383 static const struct {
387 } TEST_URLFROMPATH
[] = {
388 {"foo", "file:foo", S_OK
},
389 {"foo\\bar", "file:foo/bar", S_OK
},
390 {"\\foo\\bar", "file:///foo/bar", S_OK
},
391 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK
},
392 {"c:foo\\bar", "file:///c:foo/bar", S_OK
},
393 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK
},
394 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK
},
395 {"file:///c:/foo/bar", "file:///c:/foo/bar", S_FALSE
},
396 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE
}
399 /* ################ */
404 } TEST_URL_UNESCAPE
[] = {
405 {"file://foo/bar", "file://foo/bar"},
406 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
407 {"file://%24%25foobar", "file://$%foobar"}
410 /* ################ */
412 static const struct {
415 } TEST_PATH_IS_URL
[] = {
416 {"http://foo/bar", TRUE
},
417 {"c:\\foo\\bar", FALSE
},
418 {"foo://foo/bar", TRUE
},
421 {"bogusscheme:", TRUE
},
422 {"http:partial", TRUE
}
425 /* ################ */
427 static const struct {
431 } TEST_URLIS_ATTRIBS
[] = {
432 { "ftp:", FALSE
, FALSE
},
433 { "http:", FALSE
, FALSE
},
434 { "gopher:", FALSE
, FALSE
},
435 { "mailto:", TRUE
, FALSE
},
436 { "news:", FALSE
, FALSE
},
437 { "nntp:", FALSE
, FALSE
},
438 { "telnet:", FALSE
, FALSE
},
439 { "wais:", FALSE
, FALSE
},
440 { "file:", FALSE
, TRUE
},
441 { "mk:", FALSE
, FALSE
},
442 { "https:", FALSE
, FALSE
},
443 { "shell:", TRUE
, FALSE
},
444 { "https:", FALSE
, FALSE
},
445 { "snews:", FALSE
, FALSE
},
446 { "local:", FALSE
, FALSE
},
447 { "javascript:", TRUE
, FALSE
},
448 { "vbscript:", TRUE
, FALSE
},
449 { "about:", TRUE
, FALSE
},
450 { "res:", FALSE
, FALSE
},
451 { "bogusscheme:", FALSE
, FALSE
},
452 { "file:\\\\e:\\b\\c", FALSE
, TRUE
},
453 { "file://e:/b/c", FALSE
, TRUE
},
454 { "http:partial", FALSE
, FALSE
},
455 { "mailto://www.winehq.org/test.html", TRUE
, FALSE
},
456 { "file:partial", FALSE
, TRUE
},
457 { "File:partial", FALSE
, TRUE
},
460 /* ########################### */
462 static LPWSTR
GetWideString(const char* szString
)
464 LPWSTR wszString
= HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH
) * sizeof(WCHAR
));
466 MultiByteToWideChar(CP_ACP
, 0, szString
, -1, wszString
, INTERNET_MAX_URL_LENGTH
);
472 static void FreeWideString(LPWSTR wszString
)
474 HeapFree(GetProcessHeap(), 0, wszString
);
477 /* ########################### */
479 static void test_UrlApplyScheme(void)
481 WCHAR urlW
[INTERNET_MAX_URL_LENGTH
], newurlW
[INTERNET_MAX_URL_LENGTH
], expectW
[INTERNET_MAX_URL_LENGTH
];
482 char newurl
[INTERNET_MAX_URL_LENGTH
];
487 for (i
= 0; i
< ARRAY_SIZE(TEST_APPLY
); i
++) {
488 len
= ARRAY_SIZE(newurl
);
489 strcpy(newurl
, "untouched");
490 res
= UrlApplySchemeA(TEST_APPLY
[i
].url
, newurl
, &len
, TEST_APPLY
[i
].flags
);
491 ok( res
== TEST_APPLY
[i
].res
,
492 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i
, res
, TEST_APPLY
[i
].res
);
495 ok(len
== strlen(newurl
), "Test %u: Expected length %u, got %u.\n", i
, strlen(newurl
), len
);
496 ok(!strcmp(newurl
, TEST_APPLY
[i
].newurl
), "Test %u: Expected %s, got %s.\n",
497 i
, debugstr_a(TEST_APPLY
[i
].newurl
), debugstr_a(newurl
));
501 ok(len
== ARRAY_SIZE(newurl
), "Test %u: Got length %u.\n", i
, len
);
502 ok(!strcmp(newurl
, "untouched"), "Test %u: Got %s.\n", i
, debugstr_a(newurl
));
505 /* returned length is in character */
506 MultiByteToWideChar(CP_ACP
, 0, TEST_APPLY
[i
].url
, -1, urlW
, ARRAY_SIZE(urlW
));
507 MultiByteToWideChar(CP_ACP
, 0, TEST_APPLY
[i
].newurl
, -1, expectW
, ARRAY_SIZE(expectW
));
509 len
= ARRAY_SIZE(newurlW
);
510 wcscpy(newurlW
, L
"untouched");
511 res
= UrlApplySchemeW(urlW
, newurlW
, &len
, TEST_APPLY
[i
].flags
);
512 ok( res
== TEST_APPLY
[i
].res
,
513 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i
, res
, TEST_APPLY
[i
].res
);
516 ok(len
== wcslen(newurlW
), "Test %u: Expected length %u, got %u.\n", i
, wcslen(newurlW
), len
);
517 ok(!wcscmp(newurlW
, expectW
), "Test %u: Expected %s, got %s.\n",
518 i
, debugstr_w(expectW
), debugstr_w(newurlW
));
522 ok(len
== ARRAY_SIZE(newurlW
), "Test %u: Got length %u.\n", i
, len
);
523 ok(!wcscmp(newurlW
, L
"untouched"), "Test %u: Got %s.\n", i
, debugstr_w(newurlW
));
527 /* buffer too small */
528 lstrcpyA(newurl
, untouchedA
);
529 len
= lstrlenA(TEST_APPLY
[0].newurl
);
530 res
= UrlApplySchemeA(TEST_APPLY
[0].url
, newurl
, &len
, TEST_APPLY
[0].flags
);
531 ok(res
== E_POINTER
, "got HRESULT 0x%x (expected E_POINTER)\n", res
);
532 /* The returned length include the space for the terminating 0 */
533 i
= lstrlenA(TEST_APPLY
[0].newurl
)+1;
534 ok(len
== i
, "got len %d (expected %d)\n", len
, i
);
535 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
537 /* NULL as parameter. The length and the buffer are not modified */
538 lstrcpyA(newurl
, untouchedA
);
539 len
= ARRAY_SIZE(newurl
);
540 res
= UrlApplySchemeA(NULL
, newurl
, &len
, TEST_APPLY
[0].flags
);
541 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
542 ok(len
== ARRAY_SIZE(newurl
), "got len %d\n", len
);
543 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
545 len
= ARRAY_SIZE(newurl
);
546 res
= UrlApplySchemeA(TEST_APPLY
[0].url
, NULL
, &len
, TEST_APPLY
[0].flags
);
547 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
548 ok(len
== ARRAY_SIZE(newurl
), "got len %d\n", len
);
550 lstrcpyA(newurl
, untouchedA
);
551 res
= UrlApplySchemeA(TEST_APPLY
[0].url
, newurl
, NULL
, TEST_APPLY
[0].flags
);
552 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
553 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
557 /* ########################### */
559 static void hash_url(const char* szUrl
)
561 LPCSTR szTestUrl
= szUrl
;
562 LPWSTR wszTestUrl
= GetWideString(szTestUrl
);
565 DWORD cbSize
= sizeof(DWORD
);
566 DWORD dwHash1
, dwHash2
;
567 res
= UrlHashA(szTestUrl
, (LPBYTE
)&dwHash1
, cbSize
);
568 ok(res
== S_OK
, "UrlHashA returned 0x%x (expected S_OK) for %s\n", res
, szUrl
);
570 res
= UrlHashW(wszTestUrl
, (LPBYTE
)&dwHash2
, cbSize
);
571 ok(res
== S_OK
, "UrlHashW returned 0x%x (expected S_OK) for %s\n", res
, szUrl
);
572 ok(dwHash1
== dwHash2
,
573 "Hashes didn't match (A: 0x%x, W: 0x%x) for %s\n", dwHash1
, dwHash2
, szUrl
);
574 FreeWideString(wszTestUrl
);
577 static void test_UrlHash(void)
579 hash_url(TEST_URL_1
);
580 hash_url(TEST_URL_2
);
581 hash_url(TEST_URL_3
);
584 static void test_UrlGetPart(void)
599 BOOL todo_hr
, todo_result
;
603 {"hi", URL_PART_SCHEME
, 0, S_FALSE
, ""},
604 {"hi", URL_PART_USERNAME
, 0, E_FAIL
},
605 {"hi", URL_PART_PASSWORD
, 0, E_FAIL
},
606 {"hi", URL_PART_HOSTNAME
, 0, E_FAIL
},
607 {"hi", URL_PART_PORT
, 0, E_FAIL
},
608 {"hi", URL_PART_QUERY
, 0, S_FALSE
, ""},
610 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_SCHEME
, 0, S_OK
, "http"},
611 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_USERNAME
, 0, S_OK
, "foo"},
612 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_PASSWORD
, 0, S_OK
, "bar"},
613 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_HOSTNAME
, 0, S_OK
, "localhost"},
614 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_PORT
, 0, S_OK
, "21"},
615 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_QUERY
, 0, S_OK
, "query=x&return=y"},
616 {"http://foo:bar@localhost:21/internal.php#anchor", URL_PART_QUERY
, 0, S_FALSE
, ""},
617 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_SCHEME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "http"},
618 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_USERNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "http:foo"},
619 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_PASSWORD
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "http:bar"},
620 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "http:localhost"},
621 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_PORT
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "http:21"},
622 {"http://foo:bar@localhost:21/internal.php?query=x&return=y", URL_PART_QUERY
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "query=x&return=y"},
624 {"http://localhost/", URL_PART_USERNAME
, 0, E_INVALIDARG
},
625 {"http://localhost/", URL_PART_PASSWORD
, 0, E_INVALIDARG
},
626 {"http://localhost/", URL_PART_HOSTNAME
, 0, S_OK
, "localhost"},
627 {"http://localhost/", URL_PART_PORT
, 0, E_INVALIDARG
, .todo_hr
= TRUE
},
628 {"http://localhost/", URL_PART_QUERY
, 0, S_FALSE
, ""},
630 {"http://localhost:port/", URL_PART_USERNAME
, 0, E_INVALIDARG
},
631 {"http://localhost:port/", URL_PART_PASSWORD
, 0, E_INVALIDARG
},
632 {"http://localhost:port/", URL_PART_HOSTNAME
, 0, S_OK
, "localhost"},
633 {"http://localhost:port/", URL_PART_PORT
, 0, S_OK
, "port"},
634 {"http://:", URL_PART_HOSTNAME
, 0, S_FALSE
, ""},
635 {"http://:", URL_PART_PORT
, 0, S_FALSE
, ""},
637 {"http://user@localhost", URL_PART_USERNAME
, 0, S_OK
, "user"},
638 {"http://user@localhost", URL_PART_PASSWORD
, 0, E_INVALIDARG
},
639 {"http://user@localhost", URL_PART_HOSTNAME
, 0, S_OK
, "localhost"},
640 {"http://user@localhost", URL_PART_PORT
, 0, E_INVALIDARG
, .todo_hr
= TRUE
},
641 {"http://@", URL_PART_USERNAME
, 0, S_FALSE
, ""},
642 {"http://@", URL_PART_PASSWORD
, 0, E_INVALIDARG
},
643 {"http://@", URL_PART_HOSTNAME
, 0, S_FALSE
, ""},
645 {"http://user:pass@localhost", URL_PART_USERNAME
, 0, S_OK
, "user"},
646 {"http://user:pass@localhost", URL_PART_PASSWORD
, 0, S_OK
, "pass"},
647 {"http://user:pass@localhost", URL_PART_HOSTNAME
, 0, S_OK
, "localhost"},
648 {"http://user:pass@localhost", URL_PART_PORT
, 0, E_INVALIDARG
, .todo_hr
= TRUE
},
649 {"http://:@", URL_PART_USERNAME
, 0, S_FALSE
, ""},
650 {"http://:@", URL_PART_PASSWORD
, 0, S_FALSE
, ""},
651 {"http://:@", URL_PART_HOSTNAME
, 0, S_FALSE
, ""},
653 {"http://host:port:q", URL_PART_HOSTNAME
, 0, S_OK
, "host"},
654 {"http://host:port:q", URL_PART_PORT
, 0, S_OK
, "port:q"},
655 {"http://user:pass:q@host", URL_PART_USERNAME
, 0, S_OK
, "user"},
656 {"http://user:pass:q@host", URL_PART_PASSWORD
, 0, S_OK
, "pass:q"},
657 {"http://user@host@q", URL_PART_USERNAME
, 0, S_OK
, "user"},
658 {"http://user@host@q", URL_PART_HOSTNAME
, 0, S_OK
, "host@q"},
660 {"http:localhost/index.html", URL_PART_HOSTNAME
, 0, E_FAIL
, .todo_hr
= TRUE
},
661 {"http:/localhost/index.html", URL_PART_HOSTNAME
, 0, E_FAIL
, .todo_hr
= TRUE
},
663 {"http://localhost\\index.html", URL_PART_HOSTNAME
, 0, S_OK
, "localhost"},
664 {"http:/\\localhost/index.html", URL_PART_HOSTNAME
, 0, S_OK
, "localhost", .todo_hr
= TRUE
},
665 {"http:\\/localhost/index.html", URL_PART_HOSTNAME
, 0, S_OK
, "localhost", .todo_hr
= TRUE
},
667 {"ftp://localhost\\index.html", URL_PART_HOSTNAME
, 0, S_OK
, "localhost"},
668 {"ftp:/\\localhost/index.html", URL_PART_HOSTNAME
, 0, S_OK
, "localhost", .todo_hr
= TRUE
},
669 {"ftp:\\/localhost/index.html", URL_PART_HOSTNAME
, 0, S_OK
, "localhost", .todo_hr
= TRUE
},
671 {"http://host?a:b@c:d", URL_PART_HOSTNAME
, 0, S_OK
, "host"},
672 {"http://host?a:b@c:d", URL_PART_QUERY
, 0, S_OK
, "a:b@c:d"},
673 {"http://host#a:b@c:d", URL_PART_HOSTNAME
, 0, S_OK
, "host"},
674 {"http://host#a:b@c:d", URL_PART_QUERY
, 0, S_FALSE
, ""},
676 /* All characters, other than those with special meaning, are allowed. */
677 {"http://foo:bar@google.*.com:21/internal.php?query=x&return=y", URL_PART_HOSTNAME
, 0, S_OK
, "google.*.com"},
678 {"http:// !\"$%&'()*+,-.;<=>[]^_`{|~}\x01\x7f\xff:pass@host", URL_PART_USERNAME
, 0, S_OK
, " !\"$%&'()*+,-.;<=>[]^_`{|~}\x01\x7f\xff"},
679 {"http://user: !\"$%&'()*+,-.;<=>[]^_`{|~}\x01\x7f\xff@host", URL_PART_PASSWORD
, 0, S_OK
, " !\"$%&'()*+,-.;<=>[]^_`{|~}\x01\x7f\xff"},
680 {"http:// !\"$%&'()*+,-.;<=>[]^_`{|~}\x01\x7f\xff", URL_PART_HOSTNAME
, 0, S_OK
, " !\"$%&'()*+,-.;<=>[]^_`{|~}\x01\x7f\xff"},
681 {"http://host: !\"$%&'()*+,-.;<=>[]^_`{|~}\x01\x7f\xff", URL_PART_PORT
, 0, S_OK
, " !\"$%&'()*+,-.;<=>[]^_`{|~}\x01\x7f\xff"},
683 {"http:///index.html", URL_PART_HOSTNAME
, 0, S_FALSE
, ""},
684 {"http:///index.html", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "http:", .todo_hr
= TRUE
},
685 {"file://h o s t/c:/windows/file", URL_PART_HOSTNAME
, 0, S_OK
, "h o s t"},
686 {"file://h o s t/c:/windows/file", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "h o s t"},
687 {"file://foo:bar@localhost:21/file?query=x", URL_PART_USERNAME
, 0, E_FAIL
, .todo_hr
= TRUE
},
688 {"file://foo:bar@localhost:21/file?query=x", URL_PART_PASSWORD
, 0, E_FAIL
, .todo_hr
= TRUE
},
689 {"file://foo:bar@localhost:21/file?query=x", URL_PART_HOSTNAME
, 0, S_OK
, "foo:bar@localhost:21", .todo_result
= TRUE
},
690 {"file://foo:bar@localhost:21/file?query=x", URL_PART_PORT
, 0, E_FAIL
, .todo_hr
= TRUE
},
691 {"file://foo:bar@localhost:21/file?query=x", URL_PART_QUERY
, 0, S_OK
, "query=x"},
692 {"http://user:pass 123@www.wine hq.org", URL_PART_HOSTNAME
, 0, S_OK
, "www.wine hq.org"},
693 {"http://user:pass 123@www.wine hq.org", URL_PART_PASSWORD
, 0, S_OK
, "pass 123"},
694 {"about:blank", URL_PART_SCHEME
, 0, S_OK
, "about"},
695 {"about:blank", URL_PART_HOSTNAME
, 0, E_FAIL
},
696 {"x-excid://36C00000/guid:{048B4E89-2E92-496F-A837-33BA02FF6D32}/Message.htm", URL_PART_SCHEME
, 0, S_OK
, "x-excid"},
697 {"x-excid://36C00000/guid:{048B4E89-2E92-496F-A837-33BA02FF6D32}/Message.htm", URL_PART_HOSTNAME
, 0, E_FAIL
},
698 {"x-excid://36C00000/guid:{048B4E89-2E92-496F-A837-33BA02FF6D32}/Message.htm", URL_PART_QUERY
, 0, S_FALSE
, ""},
699 {"foo://bar-url/test", URL_PART_SCHEME
, 0, S_OK
, "foo"},
700 {"foo://bar-url/test", URL_PART_HOSTNAME
, 0, E_FAIL
},
701 {"foo://bar-url/test", URL_PART_QUERY
, 0, S_FALSE
, ""},
702 {"ascheme:", URL_PART_SCHEME
, 0, S_OK
, "ascheme"},
703 {"res://some.dll/find.dlg", URL_PART_SCHEME
, 0, S_OK
, "res"},
704 {"res://some.dll/find.dlg", URL_PART_QUERY
, 0, S_FALSE
, ""},
705 {"http://www.winehq.org", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "http:www.winehq.org"},
706 {"file:///index.html", URL_PART_HOSTNAME
, 0, S_FALSE
, ""},
707 {"file:///index.html", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_FALSE
, ""},
708 {"file://c:\\index.htm", URL_PART_HOSTNAME
, 0, S_FALSE
, ""},
709 {"file://c:\\index.htm", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_FALSE
, ""},
710 {"file:some text", URL_PART_HOSTNAME
, 0, S_FALSE
, ""},
711 {"index.htm", URL_PART_HOSTNAME
, 0, E_FAIL
},
712 {"sChEmE-.+:", URL_PART_SCHEME
, 0, S_OK
, "scheme-.+", .todo_hr
= TRUE
},
713 {"scheme_:", URL_PART_SCHEME
, 0, S_FALSE
, ""},
714 {"scheme :", URL_PART_SCHEME
, 0, S_FALSE
, ""},
715 {"sch eme:", URL_PART_SCHEME
, 0, S_FALSE
, ""},
716 {":", URL_PART_SCHEME
, 0, S_FALSE
, ""},
717 {"a:", URL_PART_SCHEME
, 0, S_FALSE
, "", .todo_hr
= TRUE
},
718 {"0:", URL_PART_SCHEME
, 0, S_FALSE
, "", .todo_hr
= TRUE
},
719 {"ab:", URL_PART_SCHEME
, 0, S_OK
, "ab"},
721 {"about://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
722 {"file://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
723 {"ftp://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
724 {"gopher://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
725 {"http://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
726 {"https://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
727 {"javascript://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
728 {"local://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
729 {"mailto://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
730 {"mk://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
731 {"news://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
732 {"nntp://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
733 {"res://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
734 {"shell://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
735 {"snews://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
736 {"telnet://hostname/", URL_PART_HOSTNAME
, 0, S_OK
, "hostname"},
737 {"vbscript://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
738 {"wais://hostname/", URL_PART_HOSTNAME
, 0, E_FAIL
},
740 {"file://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "hostname"},
741 {"ftp://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "ftp:hostname"},
742 {"gopher://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "gopher:hostname"},
743 {"http://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "http:hostname"},
744 {"https://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "https:hostname"},
745 {"news://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "news:hostname"},
746 {"nntp://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "nntp:hostname"},
747 {"snews://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "snews:hostname"},
748 {"telnet://hostname/", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, S_OK
, "telnet:hostname"},
751 winetest_mute_threshold
= 5;
753 hr
= UrlGetPartA(NULL
, NULL
, NULL
, URL_PART_SCHEME
, 0);
754 ok(hr
== E_INVALIDARG
, "Got hr %#x.\n", hr
);
756 hr
= UrlGetPartA(NULL
, buffer
, &size
, URL_PART_SCHEME
, 0);
757 ok(hr
== E_INVALIDARG
, "Got hr %#x.\n", hr
);
759 hr
= UrlGetPartA("res://some.dll/find.dlg", NULL
, &size
, URL_PART_SCHEME
, 0);
760 ok(hr
== E_INVALIDARG
, "Got hr %#x.\n", hr
);
762 hr
= UrlGetPartA("res://some.dll/find.dlg", buffer
, NULL
, URL_PART_SCHEME
, 0);
763 ok(hr
== E_INVALIDARG
, "Got hr %#x.\n", hr
);
767 hr
= UrlGetPartA("hi", buffer
, &size
, URL_PART_SCHEME
, 0);
768 ok(hr
== E_INVALIDARG
, "Got hr %#x.\n", hr
);
769 ok(!strcmp(buffer
, "x"), "Got result %s.\n", debugstr_a(buffer
));
770 ok(!size
, "Got size %u.\n", size
);
772 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
)
774 WCHAR urlW
[200], expectW
[200];
775 const char *expect
= tests
[i
].expect
;
776 const char *url
= tests
[i
].url
;
777 DWORD flags
= tests
[i
].flags
;
778 DWORD part
= tests
[i
].part
;
780 winetest_push_context("URL %s, part %#x, flags %#x", debugstr_a(url
), part
, flags
);
784 hr
= UrlGetPartA(url
, buffer
, &size
, part
, flags
);
785 todo_wine_if (tests
[i
].todo_hr
)
787 if (tests
[i
].hr
== S_OK
)
788 ok(hr
== E_POINTER
, "Got hr %#x.\n", hr
);
790 ok(hr
== tests
[i
].hr
, "Got hr %#x.\n", hr
);
795 ok(!size
, "Got size %u.\n", size
);
796 ok(!buffer
[0], "Got result %s.\n", debugstr_a(buffer
));
804 todo_wine_if (tests
[i
].todo_hr
|| tests
[i
].todo_result
)
805 ok(size
== strlen(expect
) + 1, "Got size %u.\n", size
);
810 ok(size
== 1, "Got size %u.\n", size
);
812 ok(!strcmp(buffer
, "x"), "Got result %s.\n", debugstr_a(buffer
));
815 size
= sizeof(buffer
);
817 hr
= UrlGetPartA(url
, buffer
, &size
, part
, flags
);
818 todo_wine_if (tests
[i
].todo_hr
)
819 ok(hr
== tests
[i
].hr
, "Got hr %#x.\n", hr
);
822 ok(size
== strlen(buffer
), "Got size %u.\n", size
);
825 todo_wine_if (tests
[i
].todo_hr
|| tests
[i
].todo_result
)
826 ok(!strcmp(buffer
, expect
), "Got result %s.\n", debugstr_a(buffer
));
831 ok(size
== sizeof(buffer
), "Got size %u.\n", size
);
832 ok(!strcmp(buffer
, "x"), "Got result %s.\n", debugstr_a(buffer
));
835 MultiByteToWideChar(CP_ACP
, 0, url
, -1, urlW
, ARRAY_SIZE(urlW
));
838 wcscpy(bufferW
, L
"x");
839 hr
= UrlGetPartW(urlW
, bufferW
, &size
, part
, flags
);
840 todo_wine_if (tests
[i
].todo_hr
|| tests
[i
].hr
== S_FALSE
)
842 if (tests
[i
].hr
== S_OK
)
843 ok(hr
== E_POINTER
, "Got hr %#x.\n", hr
);
845 ok(hr
== (tests
[i
].hr
== S_FALSE
? S_OK
: tests
[i
].hr
), "Got hr %#x.\n", hr
);
850 ok(!size
, "Got size %u.\n", size
);
851 ok(!buffer
[0], "Got result %s.\n", debugstr_a(buffer
));
859 todo_wine_if (tests
[i
].todo_hr
|| tests
[i
].todo_result
)
860 ok(size
== strlen(expect
) + 1, "Got size %u.\n", size
);
865 ok(size
== 1, "Got size %u.\n", size
);
867 ok(!wcscmp(bufferW
, L
"x"), "Got result %s.\n", debugstr_w(bufferW
));
870 size
= ARRAY_SIZE(bufferW
);
871 wcscpy(bufferW
, L
"x");
872 hr
= UrlGetPartW(urlW
, bufferW
, &size
, part
, flags
);
873 todo_wine_if ((tests
[i
].hr
== S_FALSE
|| tests
[i
].todo_hr
) && strcmp(url
, "a:") && strcmp(url
, "0:"))
874 ok(hr
== (tests
[i
].hr
== S_FALSE
? S_OK
: tests
[i
].hr
), "Got hr %#x.\n", hr
);
877 ok(size
== wcslen(bufferW
), "Got size %u.\n", size
);
878 MultiByteToWideChar(CP_ACP
, 0, buffer
, -1, expectW
, ARRAY_SIZE(expectW
));
879 ok(!wcscmp(bufferW
, expectW
), "Got result %s.\n", debugstr_w(bufferW
));
883 ok(size
== ARRAY_SIZE(bufferW
), "Got size %u.\n", size
);
884 ok(!wcscmp(bufferW
, L
"x"), "Got result %s.\n", debugstr_w(bufferW
));
887 winetest_pop_context();
890 winetest_mute_threshold
= 42;
893 /* ########################### */
894 static void check_url_canonicalize(int index
, const char *szUrl
, DWORD dwFlags
, const char *szExpectUrl
, BOOL todo
)
896 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
897 WCHAR wszReturnUrl
[INTERNET_MAX_URL_LENGTH
];
898 LPWSTR wszUrl
= GetWideString(szUrl
);
899 LPWSTR wszExpectUrl
= GetWideString(szExpectUrl
);
900 LPWSTR wszConvertedUrl
;
905 dwSize
= INTERNET_MAX_URL_LENGTH
;
906 ret
= UrlCanonicalizeA(szUrl
, NULL
, &dwSize
, dwFlags
);
907 ok(ret
== E_INVALIDARG
, "Got unexpected hr %#x for index %d.\n", ret
, index
);
908 ret
= UrlCanonicalizeA(szUrl
, szReturnUrl
, &dwSize
, dwFlags
);
909 ok(ret
== S_OK
|| (!szUrl
[0] && ret
== S_FALSE
) /* Vista+ */,
910 "Got unexpected hr %#x for index %d.\n", ret
, index
);
912 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags
, szUrl
, szExpectUrl
, szReturnUrl
, index
);
914 dwSize
= INTERNET_MAX_URL_LENGTH
;
915 ret
= UrlCanonicalizeW(wszUrl
, NULL
, &dwSize
, dwFlags
);
916 ok(ret
== E_INVALIDARG
, "Got unexpected hr %#x for index %d.\n", ret
, index
);
917 ret
= UrlCanonicalizeW(wszUrl
, wszReturnUrl
, &dwSize
, dwFlags
);
918 ok(ret
== S_OK
, "Got unexpected hr %#x for index %d.\n", ret
, index
);
920 wszConvertedUrl
= GetWideString(szReturnUrl
);
921 ok(lstrcmpW(wszReturnUrl
, wszConvertedUrl
)==0,
922 "Strings didn't match between ansi and unicode UrlCanonicalize, index %d!\n", index
);
923 FreeWideString(wszConvertedUrl
);
925 FreeWideString(wszUrl
);
926 FreeWideString(wszExpectUrl
);
930 static void test_UrlEscapeA(void)
935 char empty_string
[] = "";
937 ret
= UrlEscapeA("/woningplan/woonkamer basis.swf", NULL
, &size
, URL_ESCAPE_SPACES_ONLY
);
938 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
939 ok(size
== 0, "got %d, expected %d\n", size
, 0);
942 ret
= UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
943 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
944 ok(size
== 0, "got %d, expected %d\n", size
, 0);
947 ret
= UrlEscapeA("/woningplan/woonkamer basis.swf", NULL
, &size
, URL_ESCAPE_SPACES_ONLY
);
948 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
949 ok(size
== 1, "got %d, expected %d\n", size
, 1);
952 ret
= UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, NULL
, URL_ESCAPE_SPACES_ONLY
);
953 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
954 ok(size
== 1, "got %d, expected %d\n", size
, 1);
957 empty_string
[0] = 127;
958 ret
= UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
959 ok(ret
== E_POINTER
, "got %x, expected %x\n", ret
, E_POINTER
);
960 ok(size
== 34, "got %d, expected %d\n", size
, 34);
961 ok(empty_string
[0] == 127, "String has changed, empty_string[0] = %d\n", empty_string
[0]);
964 empty_string
[0] = 127;
965 ret
= UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, &size
, URL_ESCAPE_AS_UTF8
);
966 ok(ret
== E_NOTIMPL
, "Got unexpected hr %#x.\n", ret
);
967 ok(size
== 1, "Got unexpected size %u.\n", size
);
968 ok(empty_string
[0] == 127, "String has changed, empty_string[0] = %d\n", empty_string
[0]);
970 for (i
= 0; i
< ARRAY_SIZE(TEST_ESCAPE
); i
++) {
971 CHAR ret_url
[INTERNET_MAX_URL_LENGTH
];
973 size
= INTERNET_MAX_URL_LENGTH
;
974 ret
= UrlEscapeA(TEST_ESCAPE
[i
].url
, ret_url
, &size
, TEST_ESCAPE
[i
].flags
);
975 ok(ret
== S_OK
, "Got unexpected hr %#x for %s.\n", ret
, debugstr_a(TEST_ESCAPE
[i
].url
));
976 ok(!strcmp(ret_url
, TEST_ESCAPE
[i
].expecturl
), "Expected \"%s\", but got \"%s\" for \"%s\"\n",
977 TEST_ESCAPE
[i
].expecturl
, ret_url
, TEST_ESCAPE
[i
].url
);
981 static void test_UrlEscapeW(void)
983 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
984 WCHAR overwrite
[10] = L
"foo bar";
985 WCHAR empty_string
[] = {0};
991 /* Check error paths */
993 ret
= UrlEscapeW(L
"/test", NULL
, NULL
, URL_ESCAPE_SPACES_ONLY
);
994 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
997 ret
= UrlEscapeW(L
"/test", NULL
, &size
, URL_ESCAPE_SPACES_ONLY
);
998 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
999 ok(size
== 0, "got %d, expected %d\n", size
, 0);
1001 ret
= UrlEscapeW(L
"/test", empty_string
, NULL
, URL_ESCAPE_SPACES_ONLY
);
1002 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
1005 ret
= UrlEscapeW(L
"/test", empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
1006 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
1007 ok(size
== 0, "got %d, expected %d\n", size
, 0);
1009 ret
= UrlEscapeW(L
"/test", NULL
, NULL
, URL_ESCAPE_SPACES_ONLY
);
1010 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
1013 ret
= UrlEscapeW(L
"/test", NULL
, &size
, URL_ESCAPE_SPACES_ONLY
);
1014 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
1015 ok(size
== 1, "got %d, expected %d\n", size
, 1);
1017 ret
= UrlEscapeW(L
"/test", empty_string
, NULL
, URL_ESCAPE_SPACES_ONLY
);
1018 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
1021 ret
= UrlEscapeW(L
"/test", empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
1022 ok(ret
== E_POINTER
, "got %x, expected %x\n", ret
, E_POINTER
);
1023 ok(size
== 6, "got %d, expected %d\n", size
, 6);
1025 /* Check actual escaping */
1027 size
= ARRAY_SIZE(overwrite
);
1028 ret
= UrlEscapeW(overwrite
, overwrite
, &size
, URL_ESCAPE_SPACES_ONLY
);
1029 ok(ret
== S_OK
, "got %x, expected S_OK\n", ret
);
1030 ok(size
== 9, "got %d, expected 9\n", size
);
1031 ok(!wcscmp(overwrite
, L
"foo%20bar"), "Got unexpected string %s.\n", debugstr_w(overwrite
));
1035 ret
= UrlEscapeW(overwrite
, &wc
, &size
, URL_ESCAPE_SPACES_ONLY
);
1036 ok(ret
== E_POINTER
, "got %x, expected %x\n", ret
, E_POINTER
);
1037 ok(size
== 10, "got %d, expected 10\n", size
);
1038 ok(wc
== 127, "String has changed, wc = %d\n", wc
);
1040 /* non-ASCII range */
1041 size
= ARRAY_SIZE(ret_urlW
);
1042 ret
= UrlEscapeW(L
"ftp\x1f\xff\xfa\x2122q/", ret_urlW
, &size
, 0);
1043 ok(ret
== S_OK
, "got %x, expected S_OK\n", ret
);
1044 ok(!wcscmp(ret_urlW
, L
"ftp%1F%FF%FA\x2122q/"), "Got unexpected string %s.\n", debugstr_w(ret_urlW
));
1046 for (i
= 0; i
< ARRAY_SIZE(TEST_ESCAPE
); i
++) {
1048 WCHAR
*urlW
, *expected_urlW
;
1050 size
= INTERNET_MAX_URL_LENGTH
;
1051 urlW
= GetWideString(TEST_ESCAPE
[i
].url
);
1052 expected_urlW
= GetWideString(TEST_ESCAPE
[i
].expecturl
);
1053 ret
= UrlEscapeW(urlW
, ret_urlW
, &size
, TEST_ESCAPE
[i
].flags
);
1054 ok(ret
== S_OK
, "Got unexpected hr %#x for %s.\n", ret
, debugstr_w(urlW
));
1055 ok(!lstrcmpW(ret_urlW
, expected_urlW
), "Expected %s, but got %s for %s flags %08x\n",
1056 wine_dbgstr_w(expected_urlW
), wine_dbgstr_w(ret_urlW
), wine_dbgstr_w(urlW
), TEST_ESCAPE
[i
].flags
);
1057 FreeWideString(urlW
);
1058 FreeWideString(expected_urlW
);
1061 for (i
= 0; i
< ARRAY_SIZE(TEST_ESCAPEW
); i
++) {
1062 WCHAR ret_url
[INTERNET_MAX_URL_LENGTH
];
1064 size
= INTERNET_MAX_URL_LENGTH
;
1065 ret
= UrlEscapeW(TEST_ESCAPEW
[i
].url
, ret_url
, &size
, TEST_ESCAPEW
[i
].flags
);
1066 ok(ret
== S_OK
, "Got unexpected hr %#x for %s.\n", ret
, debugstr_w(TEST_ESCAPEW
[i
].url
));
1067 ok(!wcscmp(ret_url
, TEST_ESCAPEW
[i
].expecturl
)
1068 || broken(!wcscmp(ret_url
, TEST_ESCAPEW
[i
].win7url
)),
1069 "Expected %s, but got %s for %s.\n", debugstr_w(TEST_ESCAPEW
[i
].expecturl
),
1070 debugstr_w(ret_url
), debugstr_w(TEST_ESCAPEW
[i
].url
));
1074 /* ########################### */
1076 static void test_UrlCanonicalizeA(void)
1079 CHAR szReturnUrl
[4*INTERNET_MAX_URL_LENGTH
];
1080 CHAR longurl
[4*INTERNET_MAX_URL_LENGTH
];
1085 urllen
= lstrlenA(winehqA
);
1087 /* Parameter checks */
1088 dwSize
= ARRAY_SIZE(szReturnUrl
);
1089 hr
= UrlCanonicalizeA(NULL
, szReturnUrl
, &dwSize
, URL_UNESCAPE
);
1090 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1092 dwSize
= ARRAY_SIZE(szReturnUrl
);
1093 hr
= UrlCanonicalizeA(winehqA
, NULL
, &dwSize
, URL_UNESCAPE
);
1094 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1096 hr
= UrlCanonicalizeA(winehqA
, szReturnUrl
, NULL
, URL_UNESCAPE
);
1097 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1100 hr
= UrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_UNESCAPE
);
1101 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1103 /* buffer has no space for the result */
1105 memset(szReturnUrl
, '#', urllen
+4);
1106 szReturnUrl
[urllen
+4] = '\0';
1107 SetLastError(0xdeadbeef);
1108 hr
= UrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1109 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
1110 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
1111 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
+1);
1113 /* buffer has no space for the terminating '\0' */
1115 memset(szReturnUrl
, '#', urllen
+4);
1116 szReturnUrl
[urllen
+4] = '\0';
1117 SetLastError(0xdeadbeef);
1118 hr
= UrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1119 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
1120 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
1121 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
+1);
1123 /* buffer has the required size */
1125 memset(szReturnUrl
, '#', urllen
+4);
1126 szReturnUrl
[urllen
+4] = '\0';
1127 SetLastError(0xdeadbeef);
1128 hr
= UrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1129 ok( (hr
== S_OK
) && (dwSize
== urllen
),
1130 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
1131 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
);
1133 /* buffer is larger as the required size */
1135 memset(szReturnUrl
, '#', urllen
+4);
1136 szReturnUrl
[urllen
+4] = '\0';
1137 SetLastError(0xdeadbeef);
1138 hr
= UrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1139 ok( (hr
== S_OK
) && (dwSize
== urllen
),
1140 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
1141 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
);
1143 /* length is set to 0 */
1145 memset(szReturnUrl
, '#', urllen
+4);
1146 szReturnUrl
[urllen
+4] = '\0';
1147 SetLastError(0xdeadbeef);
1148 hr
= UrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1149 ok( (hr
== E_INVALIDARG
) && (dwSize
== 0),
1150 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_INVALIDARG' and size %u)\n",
1151 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), 0);
1153 /* url length > INTERNET_MAX_URL_SIZE */
1154 dwSize
=sizeof(szReturnUrl
);
1155 memset(longurl
, 'a', sizeof(longurl
));
1156 memcpy(longurl
, winehqA
, sizeof(winehqA
)-1);
1157 longurl
[sizeof(longurl
)-1] = '\0';
1158 hr
= UrlCanonicalizeA(longurl
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1159 ok(hr
== S_OK
, "hr = %x\n", hr
);
1161 /* test url-modification */
1162 for (i
= 0; i
< ARRAY_SIZE(TEST_CANONICALIZE
); i
++) {
1163 check_url_canonicalize(i
, TEST_CANONICALIZE
[i
].url
, TEST_CANONICALIZE
[i
].flags
,
1164 TEST_CANONICALIZE
[i
].expecturl
, TEST_CANONICALIZE
[i
].todo
);
1168 /* ########################### */
1170 static void test_UrlCanonicalizeW(void)
1172 WCHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
1178 urllen
= lstrlenW(winehqW
);
1180 /* Parameter checks */
1181 dwSize
= ARRAY_SIZE(szReturnUrl
);
1182 hr
= UrlCanonicalizeW(NULL
, szReturnUrl
, &dwSize
, URL_UNESCAPE
);
1183 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1185 dwSize
= ARRAY_SIZE(szReturnUrl
);
1186 hr
= UrlCanonicalizeW(winehqW
, NULL
, &dwSize
, URL_UNESCAPE
);
1187 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1189 hr
= UrlCanonicalizeW(winehqW
, szReturnUrl
, NULL
, URL_UNESCAPE
);
1190 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1193 hr
= UrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_UNESCAPE
);
1194 ok(hr
== E_INVALIDARG
, "Got unexpected hr %#x.\n", hr
);
1196 /* buffer has no space for the result */
1197 dwSize
= (urllen
-1);
1198 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
1199 szReturnUrl
[urllen
+4] = '\0';
1200 SetLastError(0xdeadbeef);
1201 hr
= UrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1202 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
1203 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
1204 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
+1);
1207 /* buffer has no space for the terminating '\0' */
1209 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
1210 szReturnUrl
[urllen
+4] = '\0';
1211 SetLastError(0xdeadbeef);
1212 hr
= UrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1213 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
1214 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
1215 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
+1);
1217 /* buffer has the required size */
1219 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
1220 szReturnUrl
[urllen
+4] = '\0';
1221 SetLastError(0xdeadbeef);
1222 hr
= UrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1223 ok( (hr
== S_OK
) && (dwSize
== urllen
),
1224 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
1225 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
);
1227 /* buffer is larger as the required size */
1228 dwSize
= (urllen
+2);
1229 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
1230 szReturnUrl
[urllen
+4] = '\0';
1231 SetLastError(0xdeadbeef);
1232 hr
= UrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
1233 ok( (hr
== S_OK
) && (dwSize
== urllen
),
1234 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
1235 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
);
1237 /* check that the characters 1..32 are chopped from the end of the string */
1238 for (i
= 1; i
< 65536; i
++)
1244 wcscpy(szUrl
, L
"http://www.winehq.org/X");
1245 pos
= lstrlenW(szUrl
) - 1;
1247 urllen
= INTERNET_MAX_URL_LENGTH
;
1248 UrlCanonicalizeW(szUrl
, szReturnUrl
, &urllen
, 0);
1249 choped
= lstrlenW(szReturnUrl
) < lstrlenW(szUrl
);
1250 ok(choped
== (i
<= 32), "Incorrect char chopping for char %d\n", i
);
1254 /* ########################### */
1256 static void check_url_combine(const char *szUrl1
, const char *szUrl2
, DWORD dwFlags
, const char *szExpectUrl
)
1259 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
1260 WCHAR wszReturnUrl
[INTERNET_MAX_URL_LENGTH
];
1261 LPWSTR wszUrl1
, wszUrl2
, wszExpectUrl
, wszConvertedUrl
;
1264 DWORD dwExpectLen
= lstrlenA(szExpectUrl
);
1266 wszUrl1
= GetWideString(szUrl1
);
1267 wszUrl2
= GetWideString(szUrl2
);
1268 wszExpectUrl
= GetWideString(szExpectUrl
);
1270 hr
= UrlCombineA(szUrl1
, szUrl2
, NULL
, NULL
, dwFlags
);
1271 ok(hr
== E_INVALIDARG
, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr
, E_INVALIDARG
);
1274 hr
= UrlCombineA(szUrl1
, szUrl2
, NULL
, &dwSize
, dwFlags
);
1275 ok(hr
== E_POINTER
, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
1276 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
1279 hr
= UrlCombineA(szUrl1
, szUrl2
, szReturnUrl
, &dwSize
, dwFlags
);
1280 ok(hr
== E_POINTER
, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
1281 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
1283 hr
= UrlCombineA(szUrl1
, szUrl2
, szReturnUrl
, &dwSize
, dwFlags
);
1284 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
1285 ok(dwSize
== dwExpectLen
, "Got length %d, expected %d\n", dwSize
, dwExpectLen
);
1286 ok(!strcmp(szReturnUrl
, szExpectUrl
), "Expected %s, got %s.\n", szExpectUrl
, szReturnUrl
);
1289 hr
= UrlCombineW(wszUrl1
, wszUrl2
, NULL
, &dwSize
, dwFlags
);
1290 ok(hr
== E_POINTER
, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
1291 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
1294 hr
= UrlCombineW(wszUrl1
, wszUrl2
, wszReturnUrl
, &dwSize
, dwFlags
);
1295 ok(hr
== E_POINTER
, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
1296 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
1298 hr
= UrlCombineW(wszUrl1
, wszUrl2
, wszReturnUrl
, &dwSize
, dwFlags
);
1299 ok(hr
== S_OK
, "Got unexpected hr %#x.\n", hr
);
1300 ok(dwSize
== dwExpectLen
, "Got length %d, expected %d\n", dwSize
, dwExpectLen
);
1301 wszConvertedUrl
= GetWideString(szReturnUrl
);
1302 ok(!wcscmp(wszReturnUrl
, wszConvertedUrl
), "Expected %s, got %s.\n",
1303 debugstr_w(wszConvertedUrl
), debugstr_w(wszReturnUrl
));
1304 FreeWideString(wszConvertedUrl
);
1306 FreeWideString(wszUrl1
);
1307 FreeWideString(wszUrl2
);
1308 FreeWideString(wszExpectUrl
);
1311 /* ########################### */
1313 static void test_UrlCombine(void)
1316 for (i
= 0; i
< ARRAY_SIZE(TEST_COMBINE
); i
++) {
1317 check_url_combine(TEST_COMBINE
[i
].url1
, TEST_COMBINE
[i
].url2
, TEST_COMBINE
[i
].flags
, TEST_COMBINE
[i
].expecturl
);
1321 /* ########################### */
1323 static void test_UrlCreateFromPath(void)
1326 char ret_url
[INTERNET_MAX_URL_LENGTH
];
1328 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
1329 WCHAR
*pathW
, *urlW
;
1331 for (i
= 0; i
< ARRAY_SIZE(TEST_URLFROMPATH
); i
++) {
1332 len
= INTERNET_MAX_URL_LENGTH
;
1333 ret
= UrlCreateFromPathA(TEST_URLFROMPATH
[i
].path
, ret_url
, &len
, 0);
1334 ok(ret
== TEST_URLFROMPATH
[i
].ret
, "ret %08x from path %s\n", ret
, TEST_URLFROMPATH
[i
].path
);
1335 ok(!lstrcmpiA(ret_url
, TEST_URLFROMPATH
[i
].url
), "url %s from path %s\n", ret_url
, TEST_URLFROMPATH
[i
].path
);
1336 ok(len
== strlen(ret_url
), "ret len %d from path %s\n", len
, TEST_URLFROMPATH
[i
].path
);
1338 len
= INTERNET_MAX_URL_LENGTH
;
1339 pathW
= GetWideString(TEST_URLFROMPATH
[i
].path
);
1340 urlW
= GetWideString(TEST_URLFROMPATH
[i
].url
);
1341 ret
= UrlCreateFromPathW(pathW
, ret_urlW
, &len
, 0);
1342 WideCharToMultiByte(CP_ACP
, 0, ret_urlW
, -1, ret_url
, sizeof(ret_url
),0,0);
1343 ok(ret
== TEST_URLFROMPATH
[i
].ret
, "ret %08x from path L\"%s\", expected %08x\n",
1344 ret
, TEST_URLFROMPATH
[i
].path
, TEST_URLFROMPATH
[i
].ret
);
1345 ok(!lstrcmpiW(ret_urlW
, urlW
), "got %s expected %s from path L\"%s\"\n",
1346 ret_url
, TEST_URLFROMPATH
[i
].url
, TEST_URLFROMPATH
[i
].path
);
1347 ok(len
== lstrlenW(ret_urlW
), "ret len %d from path L\"%s\"\n", len
, TEST_URLFROMPATH
[i
].path
);
1348 FreeWideString(urlW
);
1349 FreeWideString(pathW
);
1353 /* ########################### */
1355 static void test_UrlIs_null(DWORD flag
)
1358 ret
= UrlIsA(NULL
, flag
);
1359 ok(ret
== FALSE
, "pUrlIsA(NULL, %d) failed\n", flag
);
1360 ret
= UrlIsW(NULL
, flag
);
1361 ok(ret
== FALSE
, "pUrlIsW(NULL, %d) failed\n", flag
);
1364 static void test_UrlIs(void)
1370 test_UrlIs_null(URLIS_APPLIABLE
);
1371 test_UrlIs_null(URLIS_DIRECTORY
);
1372 test_UrlIs_null(URLIS_FILEURL
);
1373 test_UrlIs_null(URLIS_HASQUERY
);
1374 test_UrlIs_null(URLIS_NOHISTORY
);
1375 test_UrlIs_null(URLIS_OPAQUE
);
1376 test_UrlIs_null(URLIS_URL
);
1378 for (i
= 0; i
< ARRAY_SIZE(TEST_PATH_IS_URL
); i
++) {
1379 MultiByteToWideChar(CP_ACP
, 0, TEST_PATH_IS_URL
[i
].path
, -1, wurl
, ARRAY_SIZE(wurl
));
1381 ret
= UrlIsA( TEST_PATH_IS_URL
[i
].path
, URLIS_URL
);
1382 ok( ret
== TEST_PATH_IS_URL
[i
].expect
,
1383 "returned %d from path %s, expected %d\n", ret
, TEST_PATH_IS_URL
[i
].path
,
1384 TEST_PATH_IS_URL
[i
].expect
);
1386 ret
= UrlIsW( wurl
, URLIS_URL
);
1387 ok( ret
== TEST_PATH_IS_URL
[i
].expect
,
1388 "returned %d from path (UrlIsW) %s, expected %d\n", ret
,
1389 TEST_PATH_IS_URL
[i
].path
, TEST_PATH_IS_URL
[i
].expect
);
1391 for (i
= 0; i
< ARRAY_SIZE(TEST_URLIS_ATTRIBS
); i
++) {
1392 MultiByteToWideChar(CP_ACP
, 0, TEST_URLIS_ATTRIBS
[i
].url
, -1, wurl
, ARRAY_SIZE(wurl
));
1394 ret
= UrlIsA( TEST_URLIS_ATTRIBS
[i
].url
, URLIS_OPAQUE
);
1395 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectOpaque
,
1396 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret
, TEST_URLIS_ATTRIBS
[i
].url
,
1397 TEST_URLIS_ATTRIBS
[i
].expectOpaque
);
1398 ret
= UrlIsA( TEST_URLIS_ATTRIBS
[i
].url
, URLIS_FILEURL
);
1399 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectFile
,
1400 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret
, TEST_URLIS_ATTRIBS
[i
].url
,
1401 TEST_URLIS_ATTRIBS
[i
].expectFile
);
1403 ret
= UrlIsW( wurl
, URLIS_OPAQUE
);
1404 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectOpaque
,
1405 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n",
1406 ret
, TEST_URLIS_ATTRIBS
[i
].url
, TEST_URLIS_ATTRIBS
[i
].expectOpaque
);
1407 ret
= UrlIsW( wurl
, URLIS_FILEURL
);
1408 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectFile
,
1409 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n",
1410 ret
, TEST_URLIS_ATTRIBS
[i
].url
, TEST_URLIS_ATTRIBS
[i
].expectFile
);
1414 /* ########################### */
1416 static void test_UrlUnescape(void)
1418 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
1419 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
1420 WCHAR
*urlW
, *expected_urlW
;
1423 static char inplace
[] = "file:///C:/Program%20Files";
1424 static char another_inplace
[] = "file:///C:/Program%20Files";
1425 static const char expected
[] = "file:///C:/Program Files";
1426 static WCHAR inplaceW
[] = L
"file:///C:/Program Files";
1427 static WCHAR another_inplaceW
[] = L
"file:///C:/Program%20Files";
1430 for (i
= 0; i
< ARRAY_SIZE(TEST_URL_UNESCAPE
); i
++) {
1431 dwEscaped
=INTERNET_MAX_URL_LENGTH
;
1432 res
= UrlUnescapeA(TEST_URL_UNESCAPE
[i
].url
, szReturnUrl
, &dwEscaped
, 0);
1434 "UrlUnescapeA returned 0x%x (expected S_OK) for \"%s\"\n",
1435 res
, TEST_URL_UNESCAPE
[i
].url
);
1436 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
);
1438 ZeroMemory(szReturnUrl
, sizeof(szReturnUrl
));
1439 /* if we set the buffer pointer to NULL here, UrlUnescape fails and the string is not converted */
1440 res
= UrlUnescapeA(TEST_URL_UNESCAPE
[i
].url
, szReturnUrl
, NULL
, 0);
1441 ok(res
== E_INVALIDARG
,
1442 "UrlUnescapeA returned 0x%x (expected E_INVALIDARG) for \"%s\"\n",
1443 res
, TEST_URL_UNESCAPE
[i
].url
);
1444 ok(strcmp(szReturnUrl
,"")==0, "Expected empty string\n");
1446 dwEscaped
= INTERNET_MAX_URL_LENGTH
;
1447 urlW
= GetWideString(TEST_URL_UNESCAPE
[i
].url
);
1448 expected_urlW
= GetWideString(TEST_URL_UNESCAPE
[i
].expect
);
1449 res
= UrlUnescapeW(urlW
, ret_urlW
, &dwEscaped
, 0);
1451 "UrlUnescapeW returned 0x%x (expected S_OK) for \"%s\"\n",
1452 res
, TEST_URL_UNESCAPE
[i
].url
);
1454 WideCharToMultiByte(CP_ACP
,0,ret_urlW
,-1,szReturnUrl
,INTERNET_MAX_URL_LENGTH
,0,0);
1455 ok(lstrcmpW(ret_urlW
, expected_urlW
)==0,
1456 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n",
1457 TEST_URL_UNESCAPE
[i
].expect
, szReturnUrl
, TEST_URL_UNESCAPE
[i
].url
, 0L);
1458 FreeWideString(urlW
);
1459 FreeWideString(expected_urlW
);
1462 dwEscaped
= sizeof(inplace
);
1463 res
= UrlUnescapeA(inplace
, NULL
, &dwEscaped
, URL_UNESCAPE_INPLACE
);
1464 ok(res
== S_OK
, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res
);
1465 ok(!strcmp(inplace
, expected
), "got %s expected %s\n", inplace
, expected
);
1466 ok(dwEscaped
== 27, "got %d expected 27\n", dwEscaped
);
1468 /* if we set the buffer pointer to NULL, the string apparently still gets converted (Google Lively does this) */
1469 res
= UrlUnescapeA(another_inplace
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1470 ok(res
== S_OK
, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res
);
1471 ok(!strcmp(another_inplace
, expected
), "got %s expected %s\n", another_inplace
, expected
);
1473 dwEscaped
= sizeof(inplaceW
);
1474 res
= UrlUnescapeW(inplaceW
, NULL
, &dwEscaped
, URL_UNESCAPE_INPLACE
);
1475 ok(res
== S_OK
, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res
);
1476 ok(dwEscaped
== 50, "got %d expected 50\n", dwEscaped
);
1478 /* if we set the buffer pointer to NULL, the string apparently still gets converted (Google Lively does this) */
1479 res
= UrlUnescapeW(another_inplaceW
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1480 ok(res
== S_OK
, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res
);
1482 ok(lstrlenW(another_inplaceW
) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW
));
1485 static const struct parse_url_test_t
{
1490 } parse_url_tests
[] = {
1491 {"http://www.winehq.org/",S_OK
,4,URL_SCHEME_HTTP
},
1492 {"https://www.winehq.org/",S_OK
,5,URL_SCHEME_HTTPS
},
1493 {"ftp://www.winehq.org/",S_OK
,3,URL_SCHEME_FTP
},
1494 {"test.txt?test=c:/dir",URL_E_INVALID_SYNTAX
},
1495 {"test.txt",URL_E_INVALID_SYNTAX
},
1496 {"xxx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1497 {"1xx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1498 {"-xx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1499 {"xx0://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1500 {"x://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1501 {"xx$://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1502 {"htt?p://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1503 {"ab-://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1504 {" http://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1505 {"HTTP://www.winehq.org/",S_OK
,4,URL_SCHEME_HTTP
},
1506 {"a+-.://www.winehq.org/",S_OK
,4,URL_SCHEME_UNKNOWN
},
1509 static void test_ParseURL(void)
1511 const struct parse_url_test_t
*test
;
1512 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
1517 for (test
= parse_url_tests
; test
< parse_url_tests
+ ARRAY_SIZE(parse_url_tests
); test
++) {
1518 memset(&parseda
, 0xd0, sizeof(parseda
));
1519 parseda
.cbSize
= sizeof(parseda
);
1520 hres
= ParseURLA(test
->url
, &parseda
);
1521 ok(hres
== test
->hres
, "ParseURL failed: %08x, expected %08x\n", hres
, test
->hres
);
1523 ok(parseda
.pszProtocol
== test
->url
, "parseda.pszProtocol = %s, expected %s\n",
1524 parseda
.pszProtocol
, test
->url
);
1525 ok(parseda
.cchProtocol
== test
->protocol_len
, "parseda.cchProtocol = %d, expected %d\n",
1526 parseda
.cchProtocol
, test
->protocol_len
);
1527 ok(parseda
.pszSuffix
== test
->url
+test
->protocol_len
+1, "parseda.pszSuffix = %s, expected %s\n",
1528 parseda
.pszSuffix
, test
->url
+test
->protocol_len
+1);
1529 ok(parseda
.cchSuffix
== strlen(test
->url
+test
->protocol_len
+1),
1530 "parseda.pszSuffix = %d, expected %d\n",
1531 parseda
.cchSuffix
, lstrlenA(test
->url
+test
->protocol_len
+1));
1532 ok(parseda
.nScheme
== test
->scheme
, "parseda.nScheme = %d, expected %d\n",
1533 parseda
.nScheme
, test
->scheme
);
1535 ok(!parseda
.pszProtocol
, "parseda.pszProtocol = %p\n", parseda
.pszProtocol
);
1536 ok(parseda
.nScheme
== 0xd0d0d0d0, "nScheme = %d\n", parseda
.nScheme
);
1539 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, url
, ARRAY_SIZE(url
));
1541 memset(&parsedw
, 0xd0, sizeof(parsedw
));
1542 parsedw
.cbSize
= sizeof(parsedw
);
1543 hres
= ParseURLW(url
, &parsedw
);
1544 ok(hres
== test
->hres
, "ParseURL failed: %08x, expected %08x\n", hres
, test
->hres
);
1546 ok(parsedw
.pszProtocol
== url
, "parsedw.pszProtocol = %s, expected %s\n",
1547 wine_dbgstr_w(parsedw
.pszProtocol
), wine_dbgstr_w(url
));
1548 ok(parsedw
.cchProtocol
== test
->protocol_len
, "parsedw.cchProtocol = %d, expected %d\n",
1549 parsedw
.cchProtocol
, test
->protocol_len
);
1550 ok(parsedw
.pszSuffix
== url
+test
->protocol_len
+1, "parsedw.pszSuffix = %s, expected %s\n",
1551 wine_dbgstr_w(parsedw
.pszSuffix
), wine_dbgstr_w(url
+test
->protocol_len
+1));
1552 ok(parsedw
.cchSuffix
== strlen(test
->url
+test
->protocol_len
+1),
1553 "parsedw.pszSuffix = %d, expected %d\n",
1554 parsedw
.cchSuffix
, lstrlenA(test
->url
+test
->protocol_len
+1));
1555 ok(parsedw
.nScheme
== test
->scheme
, "parsedw.nScheme = %d, expected %d\n",
1556 parsedw
.nScheme
, test
->scheme
);
1558 ok(!parsedw
.pszProtocol
, "parsedw.pszProtocol = %p\n", parseda
.pszProtocol
);
1559 ok(parsedw
.nScheme
== 0xd0d0d0d0, "nScheme = %d\n", parsedw
.nScheme
);
1564 static void test_HashData(void)
1567 BYTE input
[16] = {0x51, 0x33, 0x4F, 0xA7, 0x45, 0x15, 0xF0, 0x52, 0x90,
1568 0x2B, 0xE7, 0xF5, 0xFD, 0xE1, 0xA6, 0xA7};
1570 static const BYTE expected
[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1571 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1573 static const BYTE expected2
[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1574 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1575 0xE3, 0x2D, 0x47, 0xFC, 0x80, 0xB8, 0xD0,
1576 0x49, 0xE6, 0x13, 0x2A, 0x30, 0x51, 0x8D,
1577 0xF9, 0x4B, 0x07, 0xA6};
1578 static const BYTE expected3
[] = {0x2B, 0xDC, 0x9A, 0x1B, 0xF0, 0x5A, 0xF9,
1579 0xC6, 0xBE, 0x94, 0x6D, 0xF3, 0x33, 0xC1,
1583 /* Test hashing with identically sized input/output buffers. */
1584 res
= HashData(input
, 16, output
, 16);
1585 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1586 ok(!memcmp(output
, expected
, sizeof(expected
)), "data didn't match\n");
1588 /* Test hashing with larger output buffer. */
1589 res
= HashData(input
, 16, output
, 32);
1590 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1591 ok(!memcmp(output
, expected2
, sizeof(expected2
)), "data didn't match\n");
1593 /* Test hashing with smaller input buffer. */
1594 res
= HashData(input
, 8, output
, 16);
1595 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1596 ok(!memcmp(output
, expected3
, sizeof(expected3
)), "data didn't match\n");
1598 /* Test passing NULL pointers for input/output parameters. */
1599 res
= HashData(NULL
, 0, NULL
, 0);
1600 ok(res
== E_INVALIDARG
, "Got unexpected hr %#x.\n", res
);
1602 res
= HashData(input
, 0, NULL
, 0);
1603 ok(res
== E_INVALIDARG
, "Got unexpected hr %#x.\n", res
);
1605 res
= HashData(NULL
, 0, output
, 0);
1606 ok(res
== E_INVALIDARG
, "Got unexpected hr %#x.\n", res
);
1608 /* Test passing valid pointers with sizes of zero. */
1609 for (i
= 0; i
< ARRAY_SIZE(input
); i
++)
1612 for (i
= 0; i
< ARRAY_SIZE(output
); i
++)
1615 res
= HashData(input
, 0, output
, 0);
1616 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1618 /* The buffers should be unchanged. */
1619 for (i
= 0; i
< ARRAY_SIZE(input
); i
++)
1620 ok(input
[i
] == 0x00, "Expected the input buffer to be unchanged\n");
1622 for (i
= 0; i
< ARRAY_SIZE(output
); i
++)
1623 ok(output
[i
] == 0xFF, "Expected the output buffer to be unchanged\n");
1625 /* Input/output parameters are not validated. */
1626 res
= HashData((BYTE
*)0xdeadbeef, 0, (BYTE
*)0xdeadbeef, 0);
1627 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1631 res
= HashData((BYTE
*)0xdeadbeef, 1, (BYTE
*)0xdeadbeef, 1);
1632 trace("HashData returned 0x%08x\n", res
);
1636 /* ########################### */
1640 test_UrlApplyScheme();
1643 test_UrlCanonicalizeA();
1644 test_UrlCanonicalizeW();
1648 test_UrlCreateFromPath();