f135f2a1e19b20a261de9bccc7817e15d19ac87a
[reactos.git] / rostests / winetests / shlwapi / url.c
1 /* Unit test suite for Path functions
2 *
3 * Copyright 2002 Matthew Mastracci
4 * Copyright 2007,2008 Detlef Riekenberg
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "wine/test.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "shlwapi.h"
29 #include "wininet.h"
30
31 /* ################ */
32 static HMODULE hShlwapi;
33 static HRESULT (WINAPI *pUrlCanonicalizeW)(LPCWSTR, LPWSTR, LPDWORD, DWORD);
34
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};
40
41 /* ################ */
42
43 static const CHAR untouchedA[] = "untouched";
44
45 #define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
46
47 typedef struct _TEST_URL_APPLY {
48 const char * url;
49 DWORD flags;
50 HRESULT res;
51 DWORD newlen;
52 const char * newurl;
53 } TEST_URL_APPLY;
54
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://"}
68 };
69
70 /* ################ */
71
72 typedef struct _TEST_URL_CANONICALIZE {
73 const char *url;
74 DWORD flags;
75 HRESULT expectret;
76 const char *expecturl;
77 BOOL todo;
78 } TEST_URL_CANONICALIZE;
79
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 };
137
138 /* ################ */
139
140 typedef struct _TEST_URL_ESCAPE {
141 const char *url;
142 DWORD flags;
143 DWORD expectescaped;
144 HRESULT expectret;
145 const char *expecturl;
146 } TEST_URL_ESCAPE;
147
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"},
156
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"},
176
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"},
184
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"},
201
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"},
205
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"},
215
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"},
219
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"}
227 };
228
229 /* ################ */
230
231 typedef struct _TEST_URL_COMBINE {
232 const char *url1;
233 const char *url2;
234 DWORD flags;
235 HRESULT expectret;
236 const char *expecturl;
237 } TEST_URL_COMBINE;
238
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"},
267 /* UrlCombine case 2 tests. Schemes do not match */
268 {"outbind://xxxxxxxxx","http://wine1/dir",0, S_OK,"http://wine1/dir"},
269 {"xxxx://xxxxxxxxx","http://wine2/dir",0, S_OK,"http://wine2/dir"},
270 {"ftp://xxxxxxxxx/","http://wine3/dir",0, S_OK,"http://wine3/dir"},
271 {"outbind://xxxxxxxxx","http://wine4/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine4/dir"},
272 {"xxx://xxxxxxxxx","http://wine5/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine5/dir"},
273 {"ftp://xxxxxxxxx/","http://wine6/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine6/dir"},
274 {"http://xxxxxxxxx","outbind://wine7/dir",0, S_OK,"outbind://wine7/dir"},
275 {"xxx://xxxxxxxxx","ftp://wine8/dir",0, S_OK,"ftp://wine8/dir"},
276 {"ftp://xxxxxxxxx/","xxx://wine9/dir",0, S_OK,"xxx://wine9/dir"},
277 {"http://xxxxxxxxx","outbind://wine10/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind://wine10/dir"},
278 {"xxx://xxxxxxxxx","ftp://wine11/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp://wine11/dir"},
279 {"ftp://xxxxxxxxx/","xxx://wine12/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx://wine12/dir"},
280 {"http://xxxxxxxxx","outbind:wine13/dir",0, S_OK,"outbind:wine13/dir"},
281 {"xxx://xxxxxxxxx","ftp:wine14/dir",0, S_OK,"ftp:wine14/dir"},
282 {"ftp://xxxxxxxxx/","xxx:wine15/dir",0, S_OK,"xxx:wine15/dir"},
283 {"outbind://xxxxxxxxx/","http:wine16/dir",0, S_OK,"http:wine16/dir"},
284 {"http://xxxxxxxxx","outbind:wine17/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind:wine17/dir"},
285 {"xxx://xxxxxxxxx","ftp:wine18/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp:wine18/dir"},
286 {"ftp://xxxxxxxxx/","xxx:wine19/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx:wine19/dir"},
287 {"outbind://xxxxxxxxx/","http:wine20/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http:wine20/dir"}
288 };
289
290 /* ################ */
291
292 static const struct {
293 const char *path;
294 const char *url;
295 DWORD ret;
296 } TEST_URLFROMPATH [] = {
297 {"foo", "file:foo", S_OK},
298 {"foo\\bar", "file:foo/bar", S_OK},
299 {"\\foo\\bar", "file:///foo/bar", S_OK},
300 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK},
301 {"c:foo\\bar", "file:///c:foo/bar", S_OK},
302 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK},
303 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK},
304 #if 0
305 /* The following test fails on native shlwapi as distributed with Win95/98.
306 * Wine matches the behaviour of later versions.
307 */
308 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE}
309 #endif
310 };
311
312 /* ################ */
313
314 static struct {
315 char url[30];
316 const char *expect;
317 } TEST_URL_UNESCAPE[] = {
318 {"file://foo/bar", "file://foo/bar"},
319 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
320 {"file://%24%25foobar", "file://$%foobar"}
321 };
322
323 /* ################ */
324
325 static const struct {
326 const char *path;
327 BOOL expect;
328 } TEST_PATH_IS_URL[] = {
329 {"http://foo/bar", TRUE},
330 {"c:\\foo\\bar", FALSE},
331 {"foo://foo/bar", TRUE},
332 {"foo\\bar", FALSE},
333 {"foo.bar", FALSE},
334 {"bogusscheme:", TRUE},
335 {"http:partial", TRUE}
336 };
337
338 /* ################ */
339
340 static const struct {
341 const char *url;
342 BOOL expectOpaque;
343 BOOL expectFile;
344 } TEST_URLIS_ATTRIBS[] = {
345 { "ftp:", FALSE, FALSE },
346 { "http:", FALSE, FALSE },
347 { "gopher:", FALSE, FALSE },
348 { "mailto:", TRUE, FALSE },
349 { "news:", FALSE, FALSE },
350 { "nntp:", FALSE, FALSE },
351 { "telnet:", FALSE, FALSE },
352 { "wais:", FALSE, FALSE },
353 { "file:", FALSE, TRUE },
354 { "mk:", FALSE, FALSE },
355 { "https:", FALSE, FALSE },
356 { "shell:", TRUE, FALSE },
357 { "https:", FALSE, FALSE },
358 { "snews:", FALSE, FALSE },
359 { "local:", FALSE, FALSE },
360 { "javascript:", TRUE, FALSE },
361 { "vbscript:", TRUE, FALSE },
362 { "about:", TRUE, FALSE },
363 { "res:", FALSE, FALSE },
364 { "bogusscheme:", FALSE, FALSE },
365 { "file:\\\\e:\\b\\c", FALSE, TRUE },
366 { "file://e:/b/c", FALSE, TRUE },
367 { "http:partial", FALSE, FALSE },
368 { "mailto://www.winehq.org/test.html", TRUE, FALSE },
369 { "file:partial", FALSE, TRUE }
370 };
371
372 /* ########################### */
373
374 static LPWSTR GetWideString(const char* szString)
375 {
376 LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
377
378 MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
379
380 return wszString;
381 }
382
383
384 static void FreeWideString(LPWSTR wszString)
385 {
386 HeapFree(GetProcessHeap(), 0, wszString);
387 }
388
389 /* ########################### */
390
391 static void test_UrlApplyScheme(void)
392 {
393 CHAR newurl[TEST_APPLY_MAX_LENGTH];
394 WCHAR urlW[TEST_APPLY_MAX_LENGTH];
395 WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
396 HRESULT res;
397 DWORD len;
398 DWORD i;
399
400 for(i = 0; i < sizeof(TEST_APPLY)/sizeof(TEST_APPLY[0]); i++) {
401 len = TEST_APPLY_MAX_LENGTH;
402 lstrcpyA(newurl, untouchedA);
403 res = UrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
404 ok( res == TEST_APPLY[i].res,
405 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
406
407 ok( len == TEST_APPLY[i].newlen,
408 "#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
409
410 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
411 "#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
412
413 /* returned length is in character */
414 len = TEST_APPLY_MAX_LENGTH;
415 lstrcpyA(newurl, untouchedA);
416 MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
417 MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
418
419 res = UrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
420 WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
421 ok( res == TEST_APPLY[i].res,
422 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
423
424 ok( len == TEST_APPLY[i].newlen,
425 "#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
426
427 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
428 "#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
429
430 }
431
432 /* buffer too small */
433 lstrcpyA(newurl, untouchedA);
434 len = lstrlenA(TEST_APPLY[0].newurl);
435 res = UrlApplySchemeA(TEST_APPLY[0].url, newurl, &len, TEST_APPLY[0].flags);
436 ok(res == E_POINTER, "got HRESULT 0x%x (expected E_POINTER)\n", res);
437 /* The returned length include the space for the terminating 0 */
438 i = lstrlenA(TEST_APPLY[0].newurl)+1;
439 ok(len == i, "got len %d (expected %d)\n", len, i);
440 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
441
442 /* NULL as parameter. The length and the buffer are not modified */
443 lstrcpyA(newurl, untouchedA);
444 len = TEST_APPLY_MAX_LENGTH;
445 res = UrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
446 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
447 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
448 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
449
450 len = TEST_APPLY_MAX_LENGTH;
451 res = UrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
452 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
453 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
454
455 lstrcpyA(newurl, untouchedA);
456 res = UrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
457 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
458 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
459
460 }
461
462 /* ########################### */
463
464 static void hash_url(const char* szUrl)
465 {
466 LPCSTR szTestUrl = szUrl;
467 LPWSTR wszTestUrl = GetWideString(szTestUrl);
468
469 DWORD cbSize = sizeof(DWORD);
470 DWORD dwHash1, dwHash2;
471 ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK\n");
472 ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK\n");
473
474 FreeWideString(wszTestUrl);
475
476 ok(dwHash1 == dwHash2, "Hashes didn't compare\n");
477 }
478
479 static void test_UrlHash(void)
480 {
481 hash_url(TEST_URL_1);
482 hash_url(TEST_URL_2);
483 hash_url(TEST_URL_3);
484 }
485
486 /* ########################### */
487
488 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
489 {
490 CHAR szPart[INTERNET_MAX_URL_LENGTH];
491 WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
492 LPWSTR wszUrl = GetWideString(szUrl);
493 LPWSTR wszConvertedPart;
494
495 DWORD dwSize;
496
497 dwSize = INTERNET_MAX_URL_LENGTH;
498 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);
499 dwSize = INTERNET_MAX_URL_LENGTH;
500 ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK\n" );
501
502 wszConvertedPart = GetWideString(szPart);
503
504 ok(lstrcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!\n");
505
506 FreeWideString(wszUrl);
507 FreeWideString(wszConvertedPart);
508
509 /* Note that v6.0 and later don't return '?' with the query */
510 ok(strcmp(szPart,szExpected)==0 ||
511 (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
512 "Expected %s, but got %s\n", szExpected, szPart);
513 }
514
515 /* ########################### */
516
517 static void test_UrlGetPart(void)
518 {
519 CHAR szPart[INTERNET_MAX_URL_LENGTH];
520 DWORD dwSize;
521 HRESULT res;
522
523 dwSize = sizeof szPart;
524 szPart[0]='x'; szPart[1]=0;
525 res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
526 todo_wine {
527 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
528 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
529 }
530 dwSize = sizeof szPart;
531 szPart[0]='x'; szPart[1]=0;
532 res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0);
533 todo_wine {
534 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
535 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
536 }
537
538 test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
539 test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
540 test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
541 test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
542 test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
543 test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
544 }
545
546 /* ########################### */
547
548 static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
549 {
550 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
551 DWORD dwEscaped;
552 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
553 WCHAR *urlW, *expected_urlW;
554 dwEscaped=INTERNET_MAX_URL_LENGTH;
555
556 ok(UrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
557 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);
558
559 dwEscaped = INTERNET_MAX_URL_LENGTH;
560 urlW = GetWideString(szUrl);
561 expected_urlW = GetWideString(szExpectUrl);
562 ok(UrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn, "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
563 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
564 ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n", szExpectUrl, szReturnUrl, szUrl, dwFlags);
565 FreeWideString(urlW);
566 FreeWideString(expected_urlW);
567
568 }
569
570 static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, HRESULT dwExpectReturnAlt, const char *szExpectUrl, BOOL todo)
571 {
572 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
573 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
574 LPWSTR wszUrl = GetWideString(szUrl);
575 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
576 LPWSTR wszConvertedUrl;
577 HRESULT ret;
578
579 DWORD dwSize;
580
581 dwSize = INTERNET_MAX_URL_LENGTH;
582 ok(UrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer, index %d\n", index);
583 ret = UrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags);
584 ok(ret == dwExpectReturn || ret == dwExpectReturnAlt,
585 "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
586 dwExpectReturn, dwExpectReturnAlt, ret, index);
587 if (todo)
588 todo_wine
589 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
590 else
591 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
592
593 dwSize = INTERNET_MAX_URL_LENGTH;
594 ok(UrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags) != dwExpectReturn, "Unexpected return for NULL buffer, index %d\n", index);
595 ok(UrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags) == dwExpectReturn, "UrlCanonicalizeW didn't return 0x%08x, index %d\n", dwExpectReturn, index);
596 wszConvertedUrl = GetWideString(szReturnUrl);
597 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
598 FreeWideString(wszConvertedUrl);
599
600
601 FreeWideString(wszUrl);
602 FreeWideString(wszExpectUrl);
603 }
604
605
606 static void test_UrlEscape(void)
607 {
608 DWORD size = 0;
609 HRESULT ret;
610 unsigned int i;
611 char empty_string[] = "";
612
613 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
614 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
615 ok(size == 0, "got %d, expected %d\n", size, 0);
616
617 size = 0;
618 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
619 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
620 ok(size == 0, "got %d, expected %d\n", size, 0);
621
622 size = 1;
623 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
624 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
625 ok(size == 1, "got %d, expected %d\n", size, 1);
626
627 size = 1;
628 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
629 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
630 ok(size == 1, "got %d, expected %d\n", size, 1);
631
632 size = 1;
633 ret = UrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
634 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
635 ok(size == 34, "got %d, expected %d\n", size, 34);
636
637 for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
638 test_url_escape(TEST_ESCAPE[i].url, TEST_ESCAPE[i].flags,
639 TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].expecturl);
640 }
641 }
642
643 /* ########################### */
644
645 static void test_UrlCanonicalizeA(void)
646 {
647 unsigned int i;
648 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
649 DWORD dwSize;
650 DWORD urllen;
651 HRESULT hr;
652
653 urllen = lstrlenA(winehqA);
654
655 /* buffer has no space for the result */
656 dwSize=urllen-1;
657 memset(szReturnUrl, '#', urllen+4);
658 szReturnUrl[urllen+4] = '\0';
659 SetLastError(0xdeadbeef);
660 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
661 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
662 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
663 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
664
665 /* buffer has no space for the terminating '\0' */
666 dwSize=urllen;
667 memset(szReturnUrl, '#', urllen+4);
668 szReturnUrl[urllen+4] = '\0';
669 SetLastError(0xdeadbeef);
670 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
671 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
672 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
673 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
674
675 /* buffer has the required size */
676 dwSize=urllen+1;
677 memset(szReturnUrl, '#', urllen+4);
678 szReturnUrl[urllen+4] = '\0';
679 SetLastError(0xdeadbeef);
680 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
681 ok( (hr == S_OK) && (dwSize == urllen),
682 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
683 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
684
685 /* buffer is larger as the required size */
686 dwSize=urllen+2;
687 memset(szReturnUrl, '#', urllen+4);
688 szReturnUrl[urllen+4] = '\0';
689 SetLastError(0xdeadbeef);
690 hr = UrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
691 ok( (hr == S_OK) && (dwSize == urllen),
692 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
693 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
694
695 test_url_canonicalize(-1, "", 0, S_OK, S_FALSE /* Vista/win2k8 */, "", FALSE);
696
697 /* test url-modification */
698 for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
699 test_url_canonicalize(i, TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
700 TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl,
701 TEST_CANONICALIZE[i].todo);
702 }
703 }
704
705 /* ########################### */
706
707 static void test_UrlCanonicalizeW(void)
708 {
709 WCHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
710 DWORD dwSize;
711 DWORD urllen;
712 HRESULT hr;
713 int i;
714
715
716 if (!pUrlCanonicalizeW) {
717 skip("UrlCanonicalizeW\n");
718 return;
719 }
720 urllen = lstrlenW(winehqW);
721
722 /* buffer has no space for the result */
723 dwSize = (urllen-1);
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 == E_POINTER) && (dwSize == (urllen + 1)),
729 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
730 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
731
732
733 /* buffer has no space for the terminating '\0' */
734 dwSize = urllen;
735 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
736 szReturnUrl[urllen+4] = '\0';
737 SetLastError(0xdeadbeef);
738 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
739 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
740 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
741 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
742
743 /* buffer has the required size */
744 dwSize = urllen +1;
745 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
746 szReturnUrl[urllen+4] = '\0';
747 SetLastError(0xdeadbeef);
748 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
749 ok( (hr == S_OK) && (dwSize == urllen),
750 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
751 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
752
753 /* buffer is larger as the required size */
754 dwSize = (urllen+2);
755 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
756 szReturnUrl[urllen+4] = '\0';
757 SetLastError(0xdeadbeef);
758 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
759 ok( (hr == S_OK) && (dwSize == urllen),
760 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
761 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
762
763 /* check that the characters 1..32 are chopped from the end of the string */
764 for (i = 1; i < 65536; i++)
765 {
766 WCHAR szUrl[128];
767 BOOL choped;
768 int pos;
769
770 MultiByteToWideChar(CP_ACP, 0, "http://www.winehq.org/X", -1, szUrl, 128);
771 pos = lstrlenW(szUrl) - 1;
772 szUrl[pos] = i;
773 urllen = INTERNET_MAX_URL_LENGTH;
774 pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
775 choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
776 ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
777 }
778 }
779
780 /* ########################### */
781
782 static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
783 {
784 HRESULT hr;
785 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
786 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
787 LPWSTR wszUrl1 = GetWideString(szUrl1);
788 LPWSTR wszUrl2 = GetWideString(szUrl2);
789 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
790 LPWSTR wszConvertedUrl;
791
792 DWORD dwSize;
793 DWORD dwExpectLen = lstrlen(szExpectUrl);
794
795 hr = UrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
796 ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
797
798 dwSize = 0;
799 hr = UrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
800 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
801 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
802
803 dwSize--;
804 hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
805 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
806 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
807
808 hr = UrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
809 ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
810 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
811 if(SUCCEEDED(hr)) {
812 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
813 }
814
815 dwSize = 0;
816 hr = UrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
817 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
818 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
819
820 dwSize--;
821 hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
822 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
823 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
824
825 hr = UrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
826 ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
827 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
828 if(SUCCEEDED(hr)) {
829 wszConvertedUrl = GetWideString(szReturnUrl);
830 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
831 FreeWideString(wszConvertedUrl);
832 }
833
834 FreeWideString(wszUrl1);
835 FreeWideString(wszUrl2);
836 FreeWideString(wszExpectUrl);
837 }
838
839 /* ########################### */
840
841 static void test_UrlCombine(void)
842 {
843 unsigned int i;
844 for(i=0; i<sizeof(TEST_COMBINE)/sizeof(TEST_COMBINE[0]); i++) {
845 test_url_combine(TEST_COMBINE[i].url1, TEST_COMBINE[i].url2, TEST_COMBINE[i].flags,
846 TEST_COMBINE[i].expectret, TEST_COMBINE[i].expecturl);
847 }
848 }
849
850 /* ########################### */
851
852 static void test_UrlCreateFromPath(void)
853 {
854 size_t i;
855 char ret_url[INTERNET_MAX_URL_LENGTH];
856 DWORD len, ret;
857 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
858 WCHAR *pathW, *urlW;
859
860 for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
861 len = INTERNET_MAX_URL_LENGTH;
862 ret = UrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
863 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
864 ok(!lstrcmpi(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
865 ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);
866
867 len = INTERNET_MAX_URL_LENGTH;
868 pathW = GetWideString(TEST_URLFROMPATH[i].path);
869 urlW = GetWideString(TEST_URLFROMPATH[i].url);
870 ret = UrlCreateFromPathW(pathW, ret_urlW, &len, 0);
871 WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
872 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
873 ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
874 ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n", ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
875 ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
876 FreeWideString(urlW);
877 FreeWideString(pathW);
878 }
879 }
880
881 /* ########################### */
882
883 static void test_UrlIs(void)
884 {
885 BOOL ret;
886 size_t i;
887 WCHAR wurl[80];
888
889 for(i = 0; i < sizeof(TEST_PATH_IS_URL) / sizeof(TEST_PATH_IS_URL[0]); i++) {
890 MultiByteToWideChar(CP_ACP, 0, TEST_PATH_IS_URL[i].path, -1, wurl, 80);
891
892 ret = UrlIsA( TEST_PATH_IS_URL[i].path, URLIS_URL );
893 ok( ret == TEST_PATH_IS_URL[i].expect,
894 "returned %d from path %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
895 TEST_PATH_IS_URL[i].expect );
896
897 ret = UrlIsW( wurl, URLIS_URL );
898 ok( ret == TEST_PATH_IS_URL[i].expect,
899 "returned %d from path (UrlIsW) %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
900 TEST_PATH_IS_URL[i].expect );
901 }
902 for(i = 0; i < sizeof(TEST_URLIS_ATTRIBS) / sizeof(TEST_URLIS_ATTRIBS[0]); i++) {
903 MultiByteToWideChar(CP_ACP, 0, TEST_URLIS_ATTRIBS[i].url, -1, wurl, 80);
904
905 ret = UrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_OPAQUE);
906 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
907 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
908 TEST_URLIS_ATTRIBS[i].expectOpaque );
909 ret = UrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_FILEURL);
910 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
911 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
912 TEST_URLIS_ATTRIBS[i].expectFile );
913
914 ret = UrlIsW( wurl, URLIS_OPAQUE);
915 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
916 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
917 TEST_URLIS_ATTRIBS[i].expectOpaque );
918 ret = UrlIsW( wurl, URLIS_FILEURL);
919 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
920 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
921 TEST_URLIS_ATTRIBS[i].expectFile );
922 }
923 }
924
925 /* ########################### */
926
927 static void test_UrlUnescape(void)
928 {
929 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
930 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
931 WCHAR *urlW, *expected_urlW;
932 DWORD dwEscaped;
933 size_t i;
934 static char inplace[] = "file:///C:/Program%20Files";
935 static char another_inplace[] = "file:///C:/Program%20Files";
936 static const char expected[] = "file:///C:/Program Files";
937 static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
938 static WCHAR another_inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
939
940 for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
941 dwEscaped=INTERNET_MAX_URL_LENGTH;
942 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);
943 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);
944
945 ZeroMemory(szReturnUrl, sizeof(szReturnUrl));
946 /* if we set the bufferpointer to NULL here UrlUnescape fails and string gets not converted */
947 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);
948 ok(strcmp(szReturnUrl,"")==0, "Expected empty string\n");
949
950 dwEscaped = INTERNET_MAX_URL_LENGTH;
951 urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
952 expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
953 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);
954 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
955 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);
956 FreeWideString(urlW);
957 FreeWideString(expected_urlW);
958 }
959
960 dwEscaped = sizeof(inplace);
961 ok(UrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");
962 ok(!strcmp(inplace, expected), "got %s expected %s\n", inplace, expected);
963 ok(dwEscaped == 27, "got %d expected 27\n", dwEscaped);
964
965 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
966 ok(UrlUnescapeA(another_inplace, NULL, NULL, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");
967 ok(!strcmp(another_inplace, expected), "got %s expected %s\n", another_inplace, expected);
968
969 dwEscaped = sizeof(inplaceW);
970 ok(UrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
971 ok(dwEscaped == 50, "got %d expected 50\n", dwEscaped);
972
973 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
974 ok(UrlUnescapeW(another_inplaceW, NULL, NULL, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
975 ok(lstrlenW(another_inplaceW) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW));
976
977 }
978
979 /* ########################### */
980
981 START_TEST(url)
982 {
983
984 hShlwapi = GetModuleHandleA("shlwapi.dll");
985 pUrlCanonicalizeW = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeW");
986
987 test_UrlApplyScheme();
988 test_UrlHash();
989 test_UrlGetPart();
990 test_UrlCanonicalizeA();
991 test_UrlCanonicalizeW();
992 test_UrlEscape();
993 test_UrlCombine();
994 test_UrlCreateFromPath();
995 test_UrlIs();
996 test_UrlUnescape();
997
998 }