1 /* Unit test suite for Path functions
3 * Copyright 2002 Matthew Mastracci
4 * Copyright 2007,2008 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"
31 /* ################ */
32 static HMODULE hShlwapi;
33 static HRESULT (WINAPI *pUrlCanonicalizeW)(LPCWSTR, LPWSTR, LPDWORD, DWORD);
35 static const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
36 static const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
37 static const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
38 static const WCHAR winehqW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
39 static const CHAR winehqA[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
41 /* ################ */
43 static const CHAR untouchedA[] = "untouched";
45 #define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
47 typedef struct _TEST_URL_APPLY {
55 static const TEST_URL_APPLY TEST_APPLY[] = {
56 {"www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
57 {"www.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 21, "http://www.winehq.org"},
58 {"www.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
59 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 20, "ftp://ftp.winehq.org"},
60 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 20, "ftp://ftp.winehq.org"},
61 {"ftp.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://ftp.winehq.org"},
62 {"winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
63 {"winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
64 {"winehq.org", URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
65 {"", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 7, "http://"},
66 {"", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
67 {"", URL_APPLY_DEFAULT, S_OK, 7, "http://"}
70 /* ################ */
72 typedef struct _TEST_URL_CANONICALIZE {
76 const char *expecturl;
78 } TEST_URL_CANONICALIZE;
80 static const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
81 {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/", TRUE},
82 {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
83 {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
84 {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
85 {"http://www.winehq.org/tests\r", 0, S_OK, "http://www.winehq.org/tests", FALSE},
86 {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests", FALSE},
87 {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/", FALSE},
88 {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
89 {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
90 {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
91 {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
92 {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
93 {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
94 {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
95 {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
96 {"http://www.winehq.org/tests\\../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
97 {"http://www.winehq.org/tests/..\\#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
98 {"http://www.winehq.org\\tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
99 {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example", FALSE},
100 {"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},
101 {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE , S_OK, "http://www.winehq.org/tests/foo bar", FALSE},
102 {"file:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
103 {"file:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
104 {"file:///c:/tests/foo%20bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
105 {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
106 {"file://localhost/c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
107 {"file://localhost\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
108 {"file://localhost\\\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
109 {"file://localhost\\c:\\tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
110 {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
111 {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
112 {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
113 {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar", FALSE},
114 {"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar", FALSE},
115 {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar", FALSE},
116 {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about", FALSE},
117 {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about", FALSE},
118 {"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
119 {"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
120 {"c:dir\\file", 0, S_OK, "file:///c:dir/file", FALSE},
121 {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
122 {"c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
123 {"res:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests/foo bar", FALSE},
124 {"res:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests\\foo bar", TRUE},
125 {"res:///c:/tests/foo%20bar", 0, S_OK, "res:///c:/tests/foo%20bar", FALSE},
126 {"res:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c:/tests/foo%20bar", TRUE},
127 {"res://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", TRUE},
128 {"res://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", TRUE},
129 {"res://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", TRUE},
130 {"res:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c://tests/foo%20bar", TRUE},
131 {"res:///c:\\tests\\foo bar", 0, S_OK, "res:///c:\\tests\\foo bar", TRUE},
132 {"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "res:///c:\\tests\\foo bar", TRUE},
133 {"A", 0, S_OK, "A", FALSE},
134 {"/uri-res/N2R?urn:sha1:B3K", URL_DONT_ESCAPE_EXTRA_INFO | URL_WININET_COMPATIBILITY /*0x82000000*/, S_OK, "/uri-res/N2R?urn:sha1:B3K", TRUE} /*LimeWire online installer calls this*/,
135 {"http:www.winehq.org/dir/../index.html", 0, S_OK, "http:www.winehq.org/index.html"},
136 {"", 0, S_OK, "", FALSE}
139 /* ################ */
141 typedef struct _TEST_URL_ESCAPE {
146 const char *expecturl;
149 static const TEST_URL_ESCAPE TEST_ESCAPE[] = {
150 {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"},
151 {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"},
152 {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"},
153 {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"},
154 {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"},
155 {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"},
156 {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
158 {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
159 {"file://///foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
160 {"file:////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
161 {"file:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
162 {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
163 {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
164 {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
165 {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
166 {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
167 {"file:foo/bar\\baz", 0, 0, S_OK, "file:foo/bar/baz"},
168 {"file:\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
169 {"file:\\\\foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
170 {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
171 {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
172 {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"},
173 {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"},
174 {"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"},
175 {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"},
176 {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"},
178 {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"},
179 {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"},
180 {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"},
181 {"/foo/bar\\ba?z\\", 0, 0, S_OK, "/foo/bar%5Cba?z\\"},
182 {"/foo/bar\\ba#z\\", 0, 0, S_OK, "/foo/bar%5Cba#z\\"},
183 {"/foo/%5C", 0, 0, S_OK, "/foo/%5C"},
184 {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"},
186 {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"},
187 {"http://///foo/bar\\baz", 0, 0, S_OK, "http://///foo/bar/baz"},
188 {"http:////foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
189 {"http:///foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
190 {"http://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"},
191 {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
192 {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
193 {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"},
194 {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"},
195 {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
196 {"http:\\\\foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
197 {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
198 {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
199 {"http:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"},
200 {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"},
201 {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"},
203 {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"},
204 {"https:/foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
205 {"https:\\foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
207 {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"},
208 {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"},
209 {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"},
210 {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://foo/bar%5Cbaz"},
211 {"foo:/foo/bar\\baz", 0, 0, S_OK, "foo:/foo/bar%5Cbaz"},
212 {"foo:foo/bar\\baz", 0, 0, S_OK, "foo:foo%2Fbar%5Cbaz"},
213 {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"},
214 {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"},
215 {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"},
217 {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
218 {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
219 {"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"},
221 {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
222 {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"},
223 {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"},
224 {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"},
225 {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"},
226 {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"},
227 {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"}
230 /* ################ */
232 typedef struct _TEST_URL_COMBINE {
237 const char *expecturl;
240 static const TEST_URL_COMBINE TEST_COMBINE[] = {
241 {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
242 {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
243 /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
244 {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"},
245 {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"},
246 {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"},
247 {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"},
248 {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"},
249 {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"},
250 {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"},
251 {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"},
252 {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."},
253 {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"},
254 {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"},
255 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK, "file:///C:/Test/test.txt"},
256 {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"},
257 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"},
258 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"},
259 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"},
260 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
261 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
262 {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"},
263 {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"},
264 {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"},
265 {"foo:/today/", "foo:calendar", 0, S_OK, "foo:/today/calendar"},
266 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
267 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"}
270 /* ################ */
272 static const struct {
276 } TEST_URLFROMPATH [] = {
277 {"foo", "file:foo", S_OK},
278 {"foo\\bar", "file:foo/bar", S_OK},
279 {"\\foo\\bar", "file:///foo/bar", S_OK},
280 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK},
281 {"c:foo\\bar", "file:///c:foo/bar", S_OK},
282 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK},
283 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK},
285 /* The following test fails on native shlwapi as distributed with Win95/98.
286 * Wine matches the behaviour of later versions.
288 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE}
292 /* ################ */
297 } TEST_URL_UNESCAPE[] = {
298 {"file://foo/bar", "file://foo/bar"},
299 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
300 {"file://%24%25foobar", "file://$%foobar"}
303 /* ################ */
305 static const struct {
308 } TEST_PATH_IS_URL[] = {
309 {"http://foo/bar", TRUE},
310 {"c:\\foo\\bar", FALSE},
311 {"foo://foo/bar", TRUE},
314 {"bogusscheme:", TRUE},
315 {"http:partial", TRUE}
318 /* ################ */
320 static const struct {
324 } TEST_URLIS_ATTRIBS[] = {
325 { "ftp:", FALSE, FALSE },
326 { "http:", FALSE, FALSE },
327 { "gopher:", FALSE, FALSE },
328 { "mailto:", TRUE, FALSE },
329 { "news:", FALSE, FALSE },
330 { "nntp:", FALSE, FALSE },
331 { "telnet:", FALSE, FALSE },
332 { "wais:", FALSE, FALSE },
333 { "file:", FALSE, TRUE },
334 { "mk:", FALSE, FALSE },
335 { "https:", FALSE, FALSE },
336 { "shell:", TRUE, FALSE },
337 { "https:", FALSE, FALSE },
338 { "snews:", FALSE, FALSE },
339 { "local:", FALSE, FALSE },
340 { "javascript:", TRUE, FALSE },
341 { "vbscript:", TRUE, FALSE },
342 { "about:", TRUE, FALSE },
343 { "res:", FALSE, FALSE },
344 { "bogusscheme:", FALSE, FALSE },
345 { "file:\\\\e:\\b\\c", FALSE, TRUE },
346 { "file://e:/b/c", FALSE, TRUE },
347 { "http:partial", FALSE, FALSE },
348 { "mailto://www.winehq.org/test.html", TRUE, FALSE },
349 { "file:partial", FALSE, TRUE }
352 /* ########################### */
354 static LPWSTR GetWideString(const char* szString)
356 LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
358 MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
364 static void FreeWideString(LPWSTR wszString)
366 HeapFree(GetProcessHeap(), 0, wszString);
369 /* ########################### */
371 static void test_UrlApplyScheme(void)
373 CHAR newurl[TEST_APPLY_MAX_LENGTH];
374 WCHAR urlW[TEST_APPLY_MAX_LENGTH];
375 WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
380 for(i = 0; i < sizeof(TEST_APPLY)/sizeof(TEST_APPLY[0]); i++) {
381 len = TEST_APPLY_MAX_LENGTH;
382 lstrcpyA(newurl, untouchedA);
383 res = UrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
384 ok( res == TEST_APPLY[i].res,
385 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
387 ok( len == TEST_APPLY[i].newlen,
388 "#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
390 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
391 "#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
393 /* returned length is in character */
394 len = TEST_APPLY_MAX_LENGTH;
395 lstrcpyA(newurl, untouchedA);
396 MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
397 MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
399 res = UrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
400 WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
401 ok( res == TEST_APPLY[i].res,
402 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
404 ok( len == TEST_APPLY[i].newlen,
405 "#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
407 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
408 "#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
412 /* buffer too small */
413 lstrcpyA(newurl, untouchedA);
414 len = lstrlenA(TEST_APPLY[0].newurl);
415 res = UrlApplySchemeA(TEST_APPLY[0].url, newurl, &len, TEST_APPLY[0].flags);
416 ok(res == E_POINTER, "got HRESULT 0x%x (expected E_POINTER)\n", res);
417 /* The returned length include the space for the terminating 0 */
418 i = lstrlenA(TEST_APPLY[0].newurl)+1;
419 ok(len == i, "got len %d (expected %d)\n", len, i);
420 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
422 /* NULL as parameter. The length and the buffer are not modified */
423 lstrcpyA(newurl, untouchedA);
424 len = TEST_APPLY_MAX_LENGTH;
425 res = UrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
426 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
427 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d (expected %d)\n", len, TEST_APPLY_MAX_LENGTH);
428 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
430 len = TEST_APPLY_MAX_LENGTH;
431 res = UrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
432 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
433 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d (expected %d)\n", len, TEST_APPLY_MAX_LENGTH);
435 lstrcpyA(newurl, untouchedA);
436 res = UrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
437 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
438 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
442 /* ########################### */
444 static void hash_url(const char* szUrl)
446 LPCSTR szTestUrl = szUrl;
447 LPWSTR wszTestUrl = GetWideString(szTestUrl);
449 DWORD cbSize = sizeof(DWORD);
450 DWORD dwHash1, dwHash2;
451 ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK\n");
452 ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK\n");
454 FreeWideString(wszTestUrl);
456 ok(dwHash1 == dwHash2, "Hashes didn't compare\n");
459 static void test_UrlHash(void)
461 hash_url(TEST_URL_1);
462 hash_url(TEST_URL_2);
463 hash_url(TEST_URL_3);
466 /* ########################### */
468 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
470 CHAR szPart[INTERNET_MAX_URL_LENGTH];
471 WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
472 LPWSTR wszUrl = GetWideString(szUrl);
473 LPWSTR wszConvertedPart;
477 dwSize = INTERNET_MAX_URL_LENGTH;
478 ok( UrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartA for \"%s\" part 0x%08x didn't return S_OK but \"%s\"\n", szUrl, dwPart, szPart);
479 dwSize = INTERNET_MAX_URL_LENGTH;
480 ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK\n" );
482 wszConvertedPart = GetWideString(szPart);
484 ok(lstrcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!\n");
486 FreeWideString(wszUrl);
487 FreeWideString(wszConvertedPart);
489 /* Note that v6.0 and later don't return '?' with the query */
490 ok(strcmp(szPart,szExpected)==0 ||
491 (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
492 "Expected %s, but got %s\n", szExpected, szPart);
495 /* ########################### */
497 static void test_UrlGetPart(void)
499 CHAR szPart[INTERNET_MAX_URL_LENGTH];
503 dwSize = sizeof szPart;
504 szPart[0]='x'; szPart[1]=0;
505 res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
507 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
508 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
510 dwSize = sizeof szPart;
511 szPart[0]='x'; szPart[1]=0;
512 res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0);
514 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
515 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
518 test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
519 test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
520 test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
521 test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
522 test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
523 test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
526 /* ########################### */
528 static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
530 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
532 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
533 WCHAR *urlW, *expected_urlW;
534 dwEscaped=INTERNET_MAX_URL_LENGTH;
536 ok(UrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
537 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);
539 dwEscaped = INTERNET_MAX_URL_LENGTH;
540 urlW = GetWideString(szUrl);
541 expected_urlW = GetWideString(szExpectUrl);
542 ok(UrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
543 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
544 ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n", szExpectUrl, szReturnUrl, szUrl, dwFlags);
545 FreeWideString(urlW);
546 FreeWideString(expected_urlW);
550 static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl, BOOL todo)
552 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
553 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
554 LPWSTR wszUrl = GetWideString(szUrl);
555 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
556 LPWSTR wszConvertedUrl;
560 dwSize = INTERNET_MAX_URL_LENGTH;
561 ok(UrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer, index %d\n", index);
562 ok(UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeA didn't return 0x%08x, index %d\n", dwExpectReturn, index);
565 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
567 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
569 dwSize = INTERNET_MAX_URL_LENGTH;
570 ok(UrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer, index %d\n", index);
571 ok(UrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeW didn't return 0x%08x, index %d\n", dwExpectReturn, index);
572 wszConvertedUrl = GetWideString(szReturnUrl);
573 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
574 FreeWideString(wszConvertedUrl);
577 FreeWideString(wszUrl);
578 FreeWideString(wszExpectUrl);
582 static void test_UrlEscape(void)
587 char empty_string[] = "";
589 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
590 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
591 ok(size == 0, "got %d, expected %d\n", size, 0);
594 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
595 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
596 ok(size == 0, "got %d, expected %d\n", size, 0);
599 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
600 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
601 ok(size == 1, "got %d, expected %d\n", size, 1);
604 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
605 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
606 ok(size == 1, "got %d, expected %d\n", size, 1);
609 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
610 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
611 ok(size == 34, "got %d, expected %d\n", size, 34);
613 for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
614 test_url_escape(TEST_ESCAPE[i].url, TEST_ESCAPE[i].flags,
615 TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].expecturl);
619 /* ########################### */
621 static void test_UrlCanonicalizeA(void)
624 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
629 urllen = lstrlenA(winehqA);
631 /* buffer has no space for the result */
633 memset(szReturnUrl, '#', urllen+4);
634 szReturnUrl[urllen+4] = '\0';
635 SetLastError(0xdeadbeef);
636 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
637 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
638 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
639 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
641 /* buffer has no space for the terminating '\0' */
643 memset(szReturnUrl, '#', urllen+4);
644 szReturnUrl[urllen+4] = '\0';
645 SetLastError(0xdeadbeef);
646 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
647 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
648 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
649 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
651 /* buffer has the required size */
653 memset(szReturnUrl, '#', urllen+4);
654 szReturnUrl[urllen+4] = '\0';
655 SetLastError(0xdeadbeef);
656 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
657 ok( (hr == S_OK) && (dwSize == urllen),
658 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
659 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
661 /* buffer is larger as the required size */
663 memset(szReturnUrl, '#', urllen+4);
664 szReturnUrl[urllen+4] = '\0';
665 SetLastError(0xdeadbeef);
666 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
667 ok( (hr == S_OK) && (dwSize == urllen),
668 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
669 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
672 /* test url-modification */
673 for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
674 test_url_canonicalize(i, TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
675 TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl,
676 TEST_CANONICALIZE[i].todo);
680 /* ########################### */
682 static void test_UrlCanonicalizeW(void)
684 WCHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
691 if (!pUrlCanonicalizeW) {
692 skip("UrlCanonicalizeW\n");
695 urllen = lstrlenW(winehqW);
697 /* buffer has no space for the result */
699 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
700 szReturnUrl[urllen+4] = '\0';
701 SetLastError(0xdeadbeef);
702 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
703 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
704 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
705 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
708 /* buffer has no space for the terminating '\0' */
710 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
711 szReturnUrl[urllen+4] = '\0';
712 SetLastError(0xdeadbeef);
713 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
714 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
715 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
716 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
718 /* buffer has the required size */
720 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
721 szReturnUrl[urllen+4] = '\0';
722 SetLastError(0xdeadbeef);
723 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
724 ok( (hr == S_OK) && (dwSize == urllen),
725 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
726 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
728 /* buffer is larger as the required size */
730 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
731 szReturnUrl[urllen+4] = '\0';
732 SetLastError(0xdeadbeef);
733 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
734 ok( (hr == S_OK) && (dwSize == urllen),
735 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
736 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
738 /* check that the characters 1..32 are chopped from the end of the string */
739 for (i = 1; i < 65536; i++)
745 MultiByteToWideChar(CP_UTF8, 0, "http://www.winehq.org/X", -1, szUrl, 128);
746 pos = lstrlenW(szUrl) - 1;
748 urllen = INTERNET_MAX_URL_LENGTH;
749 pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
750 choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
751 ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
755 /* ########################### */
757 static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
760 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
761 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
762 LPWSTR wszUrl1 = GetWideString(szUrl1);
763 LPWSTR wszUrl2 = GetWideString(szUrl2);
764 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
765 LPWSTR wszConvertedUrl;
768 DWORD dwExpectLen = lstrlen(szExpectUrl);
770 hr = UrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
771 ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
774 hr = UrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
775 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
776 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
779 hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
780 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
781 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
783 hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
784 ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
785 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
787 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
791 hr = UrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
792 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
793 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
796 hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
797 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
798 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
800 hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
801 ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
802 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
804 wszConvertedUrl = GetWideString(szReturnUrl);
805 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
806 FreeWideString(wszConvertedUrl);
809 FreeWideString(wszUrl1);
810 FreeWideString(wszUrl2);
811 FreeWideString(wszExpectUrl);
814 /* ########################### */
816 static void test_UrlCombine(void)
819 for(i=0; i<sizeof(TEST_COMBINE)/sizeof(TEST_COMBINE[0]); i++) {
820 test_url_combine(TEST_COMBINE[i].url1, TEST_COMBINE[i].url2, TEST_COMBINE[i].flags,
821 TEST_COMBINE[i].expectret, TEST_COMBINE[i].expecturl);
825 /* ########################### */
827 static void test_UrlCreateFromPath(void)
830 char ret_url[INTERNET_MAX_URL_LENGTH];
832 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
835 for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
836 len = INTERNET_MAX_URL_LENGTH;
837 ret = UrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
838 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
839 ok(!lstrcmpi(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
840 ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);
842 len = INTERNET_MAX_URL_LENGTH;
843 pathW = GetWideString(TEST_URLFROMPATH[i].path);
844 urlW = GetWideString(TEST_URLFROMPATH[i].url);
845 ret = UrlCreateFromPathW(pathW, ret_urlW, &len, 0);
846 WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
847 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
848 ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
849 ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n", ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
850 ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
851 FreeWideString(urlW);
852 FreeWideString(pathW);
856 /* ########################### */
858 static void test_UrlIs(void)
864 for(i = 0; i < sizeof(TEST_PATH_IS_URL) / sizeof(TEST_PATH_IS_URL[0]); i++) {
865 MultiByteToWideChar(CP_ACP, 0, TEST_PATH_IS_URL[i].path, -1, wurl, 80);
867 ret = UrlIsA( TEST_PATH_IS_URL[i].path, URLIS_URL );
868 ok( ret == TEST_PATH_IS_URL[i].expect,
869 "returned %d from path %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
870 TEST_PATH_IS_URL[i].expect );
872 ret = UrlIsW( wurl, URLIS_URL );
873 ok( ret == TEST_PATH_IS_URL[i].expect,
874 "returned %d from path (UrlIsW) %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
875 TEST_PATH_IS_URL[i].expect );
877 for(i = 0; i < sizeof(TEST_URLIS_ATTRIBS) / sizeof(TEST_URLIS_ATTRIBS[0]); i++) {
878 MultiByteToWideChar(CP_ACP, 0, TEST_URLIS_ATTRIBS[i].url, -1, wurl, 80);
880 ret = UrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_OPAQUE);
881 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
882 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
883 TEST_URLIS_ATTRIBS[i].expectOpaque );
884 ret = UrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_FILEURL);
885 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
886 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
887 TEST_URLIS_ATTRIBS[i].expectFile );
889 ret = UrlIsW( wurl, URLIS_OPAQUE);
890 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
891 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
892 TEST_URLIS_ATTRIBS[i].expectOpaque );
893 ret = UrlIsW( wurl, URLIS_FILEURL);
894 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
895 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
896 TEST_URLIS_ATTRIBS[i].expectFile );
900 /* ########################### */
902 static void test_UrlUnescape(void)
904 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
905 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
906 WCHAR *urlW, *expected_urlW;
909 static char inplace[] = "file:///C:/Program%20Files";
910 static char another_inplace[] = "file:///C:/Program%20Files";
911 static const char expected[] = "file:///C:/Program Files";
912 static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
913 static WCHAR another_inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
915 for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
916 dwEscaped=INTERNET_MAX_URL_LENGTH;
917 ok(UrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, &dwEscaped, 0) == S_OK, "UrlUnescapeA didn't return 0x%08x from \"%s\"\n", S_OK, TEST_URL_UNESCAPE[i].url);
918 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);
920 ZeroMemory(szReturnUrl, sizeof(szReturnUrl));
921 /* if we set the bufferpointer to NULL here UrlUnescape fails and string gets not converted */
922 ok(UrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, NULL, 0) == E_INVALIDARG, "UrlUnescapeA didn't return 0x%08x from \"%s\"\n", E_INVALIDARG ,TEST_URL_UNESCAPE[i].url);
923 ok(strcmp(szReturnUrl,"")==0, "Expected empty string\n");
925 dwEscaped = INTERNET_MAX_URL_LENGTH;
926 urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
927 expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
928 ok(UrlUnescapeW(urlW, ret_urlW, &dwEscaped, 0) == S_OK, "UrlUnescapeW didn't return 0x%08x from \"%s\"\n", S_OK, TEST_URL_UNESCAPE[i].url);
929 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
930 ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n", TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url, 0L);
931 FreeWideString(urlW);
932 FreeWideString(expected_urlW);
935 dwEscaped = sizeof(inplace);
936 ok(UrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");
937 ok(!strcmp(inplace, expected), "got %s expected %s\n", inplace, expected);
938 ok(dwEscaped == 27, "got %d expected 27\n", dwEscaped);
941 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
942 ok(UrlUnescapeA(another_inplace, NULL, NULL, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");
943 ok(!strcmp(another_inplace, expected), "got %s expected %s\n", another_inplace, expected);
946 dwEscaped = sizeof(inplaceW);
947 ok(UrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
948 ok(dwEscaped == 50, "got %d expected 50\n", dwEscaped);
951 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
952 ok(UrlUnescapeW(another_inplaceW, NULL, NULL, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
953 ok(lstrlenW(another_inplaceW) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW));
958 /* ########################### */
963 hShlwapi = GetModuleHandleA("shlwapi.dll");
964 pUrlCanonicalizeW = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeW");
966 test_UrlApplyScheme();
969 test_UrlCanonicalizeA();
970 test_UrlCanonicalizeW();
973 test_UrlCreateFromPath();