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"},
138 /* ################ */
140 typedef struct _TEST_URL_ESCAPE {
145 const char *expecturl;
148 static const TEST_URL_ESCAPE TEST_ESCAPE[] = {
149 {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"},
150 {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"},
151 {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"},
152 {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"},
153 {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"},
154 {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"},
155 {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
157 {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
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:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
161 {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
162 {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
163 {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
164 {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
165 {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///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:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
171 {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"},
172 {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"},
173 {"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"},
174 {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"},
175 {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"},
177 {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"},
178 {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"},
179 {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"},
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/%5C", 0, 0, S_OK, "/foo/%5C"},
183 {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"},
185 {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"},
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://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"},
190 {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
191 {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
192 {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"},
193 {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"},
194 {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
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:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"},
199 {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"},
200 {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"},
202 {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"},
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"},
206 {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"},
207 {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"},
208 {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"},
209 {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://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%2Fbar%5Cbaz"},
212 {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"},
213 {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"},
214 {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"},
216 {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
217 {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
218 {"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"},
220 {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
221 {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"},
222 {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"},
223 {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"},
224 {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"},
225 {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"},
226 {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"}
229 /* ################ */
231 typedef struct _TEST_URL_COMBINE {
236 const char *expecturl;
239 static const TEST_URL_COMBINE TEST_COMBINE[] = {
240 {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
241 {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
242 /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
243 {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"},
244 {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"},
245 {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"},
246 {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"},
247 {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"},
248 {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"},
249 {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"},
250 {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"},
251 {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."},
252 {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"},
253 {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"},
254 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK, "file:///C:/Test/test.txt"},
255 {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"},
256 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"},
257 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"},
258 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"},
259 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
260 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
261 {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"},
262 {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"},
263 {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"},
264 {"foo:/today/", "foo:calendar", 0, S_OK, "foo:/today/calendar"},
265 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
266 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"}
269 /* ################ */
271 static const struct {
275 } TEST_URLFROMPATH [] = {
276 {"foo", "file:foo", S_OK},
277 {"foo\\bar", "file:foo/bar", S_OK},
278 {"\\foo\\bar", "file:///foo/bar", S_OK},
279 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK},
280 {"c:foo\\bar", "file:///c:foo/bar", S_OK},
281 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK},
282 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK},
284 /* The following test fails on native shlwapi as distributed with Win95/98.
285 * Wine matches the behaviour of later versions.
287 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE}
291 /* ################ */
296 } TEST_URL_UNESCAPE[] = {
297 {"file://foo/bar", "file://foo/bar"},
298 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
299 {"file://%24%25foobar", "file://$%foobar"}
302 /* ################ */
304 static const struct {
307 } TEST_PATH_IS_URL[] = {
308 {"http://foo/bar", TRUE},
309 {"c:\\foo\\bar", FALSE},
310 {"foo://foo/bar", TRUE},
313 {"bogusscheme:", TRUE},
314 {"http:partial", TRUE}
317 /* ################ */
319 static const struct {
323 } TEST_URLIS_ATTRIBS[] = {
324 { "ftp:", FALSE, FALSE },
325 { "http:", FALSE, FALSE },
326 { "gopher:", FALSE, FALSE },
327 { "mailto:", TRUE, FALSE },
328 { "news:", FALSE, FALSE },
329 { "nntp:", FALSE, FALSE },
330 { "telnet:", FALSE, FALSE },
331 { "wais:", FALSE, FALSE },
332 { "file:", FALSE, TRUE },
333 { "mk:", FALSE, FALSE },
334 { "https:", FALSE, FALSE },
335 { "shell:", TRUE, FALSE },
336 { "https:", FALSE, FALSE },
337 { "snews:", FALSE, FALSE },
338 { "local:", FALSE, FALSE },
339 { "javascript:", TRUE, FALSE },
340 { "vbscript:", TRUE, FALSE },
341 { "about:", TRUE, FALSE },
342 { "res:", FALSE, FALSE },
343 { "bogusscheme:", FALSE, FALSE },
344 { "file:\\\\e:\\b\\c", FALSE, TRUE },
345 { "file://e:/b/c", FALSE, TRUE },
346 { "http:partial", FALSE, FALSE },
347 { "mailto://www.winehq.org/test.html", TRUE, FALSE },
348 { "file:partial", FALSE, TRUE }
351 /* ########################### */
353 static LPWSTR GetWideString(const char* szString)
355 LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
357 MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
363 static void FreeWideString(LPWSTR wszString)
365 HeapFree(GetProcessHeap(), 0, wszString);
368 /* ########################### */
370 static void test_UrlApplyScheme(void)
372 CHAR newurl[TEST_APPLY_MAX_LENGTH];
373 WCHAR urlW[TEST_APPLY_MAX_LENGTH];
374 WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
379 for(i = 0; i < sizeof(TEST_APPLY)/sizeof(TEST_APPLY[0]); i++) {
380 len = TEST_APPLY_MAX_LENGTH;
381 lstrcpyA(newurl, untouchedA);
382 res = UrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
383 ok( res == TEST_APPLY[i].res,
384 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
386 ok( len == TEST_APPLY[i].newlen,
387 "#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
389 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
390 "#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
392 /* returned length is in character */
393 len = TEST_APPLY_MAX_LENGTH;
394 lstrcpyA(newurl, untouchedA);
395 MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
396 MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
398 res = UrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
399 WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
400 ok( res == TEST_APPLY[i].res,
401 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
403 ok( len == TEST_APPLY[i].newlen,
404 "#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
406 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
407 "#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
411 /* buffer too small */
412 lstrcpyA(newurl, untouchedA);
413 len = lstrlenA(TEST_APPLY[0].newurl);
414 res = UrlApplySchemeA(TEST_APPLY[0].url, newurl, &len, TEST_APPLY[0].flags);
415 ok(res == E_POINTER, "got HRESULT 0x%x (expected E_POINTER)\n", res);
416 /* The returned length include the space for the terminating 0 */
417 i = lstrlenA(TEST_APPLY[0].newurl)+1;
418 ok(len == i, "got len %d (expected %d)\n", len, i);
419 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
421 /* NULL as parameter. The length and the buffer are not modified */
422 lstrcpyA(newurl, untouchedA);
423 len = TEST_APPLY_MAX_LENGTH;
424 res = UrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
425 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
426 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
427 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
429 len = TEST_APPLY_MAX_LENGTH;
430 res = UrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
431 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
432 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
434 lstrcpyA(newurl, untouchedA);
435 res = UrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
436 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
437 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
441 /* ########################### */
443 static void hash_url(const char* szUrl)
445 LPCSTR szTestUrl = szUrl;
446 LPWSTR wszTestUrl = GetWideString(szTestUrl);
448 DWORD cbSize = sizeof(DWORD);
449 DWORD dwHash1, dwHash2;
450 ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK\n");
451 ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK\n");
453 FreeWideString(wszTestUrl);
455 ok(dwHash1 == dwHash2, "Hashes didn't compare\n");
458 static void test_UrlHash(void)
460 hash_url(TEST_URL_1);
461 hash_url(TEST_URL_2);
462 hash_url(TEST_URL_3);
465 /* ########################### */
467 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
469 CHAR szPart[INTERNET_MAX_URL_LENGTH];
470 WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
471 LPWSTR wszUrl = GetWideString(szUrl);
472 LPWSTR wszConvertedPart;
476 dwSize = INTERNET_MAX_URL_LENGTH;
477 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);
478 dwSize = INTERNET_MAX_URL_LENGTH;
479 ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK\n" );
481 wszConvertedPart = GetWideString(szPart);
483 ok(lstrcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!\n");
485 FreeWideString(wszUrl);
486 FreeWideString(wszConvertedPart);
488 /* Note that v6.0 and later don't return '?' with the query */
489 ok(strcmp(szPart,szExpected)==0 ||
490 (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
491 "Expected %s, but got %s\n", szExpected, szPart);
494 /* ########################### */
496 static void test_UrlGetPart(void)
498 CHAR szPart[INTERNET_MAX_URL_LENGTH];
502 dwSize = sizeof szPart;
503 szPart[0]='x'; szPart[1]=0;
504 res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
506 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
507 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
509 dwSize = sizeof szPart;
510 szPart[0]='x'; szPart[1]=0;
511 res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0);
513 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
514 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
517 test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
518 test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
519 test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
520 test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
521 test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
522 test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
525 /* ########################### */
527 static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
529 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
531 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
532 WCHAR *urlW, *expected_urlW;
533 dwEscaped=INTERNET_MAX_URL_LENGTH;
535 ok(UrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
536 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);
538 dwEscaped = INTERNET_MAX_URL_LENGTH;
539 urlW = GetWideString(szUrl);
540 expected_urlW = GetWideString(szExpectUrl);
541 ok(UrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
542 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
543 ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n", szExpectUrl, szReturnUrl, szUrl, dwFlags);
544 FreeWideString(urlW);
545 FreeWideString(expected_urlW);
549 static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, HRESULT dwExpectReturnAlt, const char *szExpectUrl, BOOL todo)
551 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
552 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
553 LPWSTR wszUrl = GetWideString(szUrl);
554 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
555 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 ret = UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags);
563 ok(ret == dwExpectReturn || ret == dwExpectReturnAlt,
564 "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
565 dwExpectReturn, dwExpectReturnAlt, ret, index);
568 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
570 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
572 dwSize = INTERNET_MAX_URL_LENGTH;
573 ok(UrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer, index %d\n", index);
574 ok(UrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeW didn't return 0x%08x, index %d\n", dwExpectReturn, index);
575 wszConvertedUrl = GetWideString(szReturnUrl);
576 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
577 FreeWideString(wszConvertedUrl);
580 FreeWideString(wszUrl);
581 FreeWideString(wszExpectUrl);
585 static void test_UrlEscape(void)
590 char empty_string[] = "";
592 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
593 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
594 ok(size == 0, "got %d, expected %d\n", size, 0);
597 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
598 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
599 ok(size == 0, "got %d, expected %d\n", size, 0);
602 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
603 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
604 ok(size == 1, "got %d, expected %d\n", size, 1);
607 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
608 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
609 ok(size == 1, "got %d, expected %d\n", size, 1);
612 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
613 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
614 ok(size == 34, "got %d, expected %d\n", size, 34);
616 for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
617 test_url_escape(TEST_ESCAPE[i].url, TEST_ESCAPE[i].flags,
618 TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].expecturl);
622 /* ########################### */
624 static void test_UrlCanonicalizeA(void)
627 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
632 urllen = lstrlenA(winehqA);
634 /* buffer has no space for the result */
636 memset(szReturnUrl, '#', urllen+4);
637 szReturnUrl[urllen+4] = '\0';
638 SetLastError(0xdeadbeef);
639 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
640 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
641 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
642 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
644 /* buffer has no space for the terminating '\0' */
646 memset(szReturnUrl, '#', urllen+4);
647 szReturnUrl[urllen+4] = '\0';
648 SetLastError(0xdeadbeef);
649 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
650 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
651 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
652 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
654 /* buffer has the required size */
656 memset(szReturnUrl, '#', urllen+4);
657 szReturnUrl[urllen+4] = '\0';
658 SetLastError(0xdeadbeef);
659 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
660 ok( (hr == S_OK) && (dwSize == urllen),
661 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
662 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
664 /* buffer is larger as the required size */
666 memset(szReturnUrl, '#', urllen+4);
667 szReturnUrl[urllen+4] = '\0';
668 SetLastError(0xdeadbeef);
669 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
670 ok( (hr == S_OK) && (dwSize == urllen),
671 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
672 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
674 test_url_canonicalize(-1, "", 0, S_OK, S_FALSE /* Vista/win2k8 */, "", FALSE);
676 /* test url-modification */
677 for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
678 test_url_canonicalize(i, TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
679 TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl,
680 TEST_CANONICALIZE[i].todo);
684 /* ########################### */
686 static void test_UrlCanonicalizeW(void)
688 WCHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
695 if (!pUrlCanonicalizeW) {
696 skip("UrlCanonicalizeW\n");
699 urllen = lstrlenW(winehqW);
701 /* buffer has no space for the result */
703 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
704 szReturnUrl[urllen+4] = '\0';
705 SetLastError(0xdeadbeef);
706 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
707 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
708 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
709 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
712 /* buffer has no space for the terminating '\0' */
714 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
715 szReturnUrl[urllen+4] = '\0';
716 SetLastError(0xdeadbeef);
717 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
718 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
719 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
720 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
722 /* buffer has the required size */
724 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
725 szReturnUrl[urllen+4] = '\0';
726 SetLastError(0xdeadbeef);
727 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
728 ok( (hr == S_OK) && (dwSize == urllen),
729 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
730 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
732 /* buffer is larger as the required size */
734 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
735 szReturnUrl[urllen+4] = '\0';
736 SetLastError(0xdeadbeef);
737 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
738 ok( (hr == S_OK) && (dwSize == urllen),
739 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
740 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
742 /* check that the characters 1..32 are chopped from the end of the string */
743 for (i = 1; i < 65536; i++)
749 MultiByteToWideChar(CP_UTF8, 0, "http://www.winehq.org/X", -1, szUrl, 128);
750 pos = lstrlenW(szUrl) - 1;
752 urllen = INTERNET_MAX_URL_LENGTH;
753 pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
754 choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
755 ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
759 /* ########################### */
761 static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
764 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
765 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
766 LPWSTR wszUrl1 = GetWideString(szUrl1);
767 LPWSTR wszUrl2 = GetWideString(szUrl2);
768 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
769 LPWSTR wszConvertedUrl;
772 DWORD dwExpectLen = lstrlen(szExpectUrl);
774 hr = UrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
775 ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
778 hr = UrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
779 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
780 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
783 hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
784 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
785 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
787 hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
788 ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
789 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
791 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
795 hr = UrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
796 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
797 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
800 hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
801 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
802 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
804 hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
805 ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
806 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
808 wszConvertedUrl = GetWideString(szReturnUrl);
809 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
810 FreeWideString(wszConvertedUrl);
813 FreeWideString(wszUrl1);
814 FreeWideString(wszUrl2);
815 FreeWideString(wszExpectUrl);
818 /* ########################### */
820 static void test_UrlCombine(void)
823 for(i=0; i<sizeof(TEST_COMBINE)/sizeof(TEST_COMBINE[0]); i++) {
824 test_url_combine(TEST_COMBINE[i].url1, TEST_COMBINE[i].url2, TEST_COMBINE[i].flags,
825 TEST_COMBINE[i].expectret, TEST_COMBINE[i].expecturl);
829 /* ########################### */
831 static void test_UrlCreateFromPath(void)
834 char ret_url[INTERNET_MAX_URL_LENGTH];
836 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
839 for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
840 len = INTERNET_MAX_URL_LENGTH;
841 ret = UrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
842 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
843 ok(!lstrcmpi(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
844 ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);
846 len = INTERNET_MAX_URL_LENGTH;
847 pathW = GetWideString(TEST_URLFROMPATH[i].path);
848 urlW = GetWideString(TEST_URLFROMPATH[i].url);
849 ret = UrlCreateFromPathW(pathW, ret_urlW, &len, 0);
850 WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
851 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
852 ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
853 ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n", ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
854 ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
855 FreeWideString(urlW);
856 FreeWideString(pathW);
860 /* ########################### */
862 static void test_UrlIs(void)
868 for(i = 0; i < sizeof(TEST_PATH_IS_URL) / sizeof(TEST_PATH_IS_URL[0]); i++) {
869 MultiByteToWideChar(CP_ACP, 0, TEST_PATH_IS_URL[i].path, -1, wurl, 80);
871 ret = UrlIsA( TEST_PATH_IS_URL[i].path, URLIS_URL );
872 ok( ret == TEST_PATH_IS_URL[i].expect,
873 "returned %d from path %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
874 TEST_PATH_IS_URL[i].expect );
876 ret = UrlIsW( wurl, URLIS_URL );
877 ok( ret == TEST_PATH_IS_URL[i].expect,
878 "returned %d from path (UrlIsW) %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
879 TEST_PATH_IS_URL[i].expect );
881 for(i = 0; i < sizeof(TEST_URLIS_ATTRIBS) / sizeof(TEST_URLIS_ATTRIBS[0]); i++) {
882 MultiByteToWideChar(CP_ACP, 0, TEST_URLIS_ATTRIBS[i].url, -1, wurl, 80);
884 ret = UrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_OPAQUE);
885 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
886 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
887 TEST_URLIS_ATTRIBS[i].expectOpaque );
888 ret = UrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_FILEURL);
889 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
890 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
891 TEST_URLIS_ATTRIBS[i].expectFile );
893 ret = UrlIsW( wurl, URLIS_OPAQUE);
894 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
895 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
896 TEST_URLIS_ATTRIBS[i].expectOpaque );
897 ret = UrlIsW( wurl, URLIS_FILEURL);
898 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
899 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
900 TEST_URLIS_ATTRIBS[i].expectFile );
904 /* ########################### */
906 static void test_UrlUnescape(void)
908 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
909 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
910 WCHAR *urlW, *expected_urlW;
913 static char inplace[] = "file:///C:/Program%20Files";
914 static char another_inplace[] = "file:///C:/Program%20Files";
915 static const char expected[] = "file:///C:/Program Files";
916 static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
917 static WCHAR another_inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
919 for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
920 dwEscaped=INTERNET_MAX_URL_LENGTH;
921 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);
922 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);
924 ZeroMemory(szReturnUrl, sizeof(szReturnUrl));
925 /* if we set the bufferpointer to NULL here UrlUnescape fails and string gets not converted */
926 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);
927 ok(strcmp(szReturnUrl,"")==0, "Expected empty string\n");
929 dwEscaped = INTERNET_MAX_URL_LENGTH;
930 urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
931 expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
932 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);
933 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
934 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);
935 FreeWideString(urlW);
936 FreeWideString(expected_urlW);
939 dwEscaped = sizeof(inplace);
940 ok(UrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");
941 ok(!strcmp(inplace, expected), "got %s expected %s\n", inplace, expected);
942 ok(dwEscaped == 27, "got %d expected 27\n", dwEscaped);
944 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
945 ok(UrlUnescapeA(another_inplace, NULL, NULL, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");
946 ok(!strcmp(another_inplace, expected), "got %s expected %s\n", another_inplace, expected);
948 dwEscaped = sizeof(inplaceW);
949 ok(UrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
950 ok(dwEscaped == 50, "got %d expected 50\n", dwEscaped);
952 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
953 ok(UrlUnescapeW(another_inplaceW, NULL, NULL, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
954 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();