1e7679f33981c9ced2525fe78217335e67d38929
[reactos.git] / modules / rostests / winetests / shlwapi / url.c
1 /* Unit test suite for Path functions
2 *
3 * Copyright 2002 Matthew Mastracci
4 * Copyright 2007-2010 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 "precomp.h"
22
23 #include <intshcut.h>
24
25 /* ################ */
26 static HMODULE hShlwapi;
27 static HRESULT (WINAPI *pUrlUnescapeA)(LPSTR,LPSTR,LPDWORD,DWORD);
28 static HRESULT (WINAPI *pUrlUnescapeW)(LPWSTR,LPWSTR,LPDWORD,DWORD);
29 static BOOL (WINAPI *pUrlIsA)(LPCSTR,URLIS);
30 static BOOL (WINAPI *pUrlIsW)(LPCWSTR,URLIS);
31 static HRESULT (WINAPI *pUrlHashA)(LPCSTR,LPBYTE,DWORD);
32 static HRESULT (WINAPI *pUrlHashW)(LPCWSTR,LPBYTE,DWORD);
33 static HRESULT (WINAPI *pUrlGetPartA)(LPCSTR,LPSTR,LPDWORD,DWORD,DWORD);
34 static HRESULT (WINAPI *pUrlGetPartW)(LPCWSTR,LPWSTR,LPDWORD,DWORD,DWORD);
35 static HRESULT (WINAPI *pUrlEscapeA)(LPCSTR,LPSTR,LPDWORD,DWORD);
36 static HRESULT (WINAPI *pUrlEscapeW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
37 static HRESULT (WINAPI *pUrlCreateFromPathA)(LPCSTR,LPSTR,LPDWORD,DWORD);
38 static HRESULT (WINAPI *pUrlCreateFromPathW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
39 static HRESULT (WINAPI *pUrlCombineA)(LPCSTR,LPCSTR,LPSTR,LPDWORD,DWORD);
40 static HRESULT (WINAPI *pUrlCombineW)(LPCWSTR,LPCWSTR,LPWSTR,LPDWORD,DWORD);
41 static HRESULT (WINAPI *pUrlCanonicalizeA)(LPCSTR, LPSTR, LPDWORD, DWORD);
42 static HRESULT (WINAPI *pUrlCanonicalizeW)(LPCWSTR, LPWSTR, LPDWORD, DWORD);
43 static HRESULT (WINAPI *pUrlApplySchemeA)(LPCSTR,LPSTR,LPDWORD,DWORD);
44 static HRESULT (WINAPI *pUrlApplySchemeW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
45 static HRESULT (WINAPI *pParseURLA)(LPCSTR,PARSEDURLA*);
46 static HRESULT (WINAPI *pParseURLW)(LPCWSTR,PARSEDURLW*);
47 static HRESULT (WINAPI *pHashData)(LPBYTE, DWORD, LPBYTE, DWORD);
48
49 static const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
50 static const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
51 static const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
52 static const char* TEST_URL_4 = "http://foo:bar@google.*.com:21/internal.php?query=x&return=y";
53
54 static const WCHAR winehqW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
55 static const CHAR winehqA[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
56
57 /* ################ */
58
59 static const CHAR untouchedA[] = "untouched";
60
61 #define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
62
63 typedef struct _TEST_URL_APPLY {
64 const char * url;
65 DWORD flags;
66 HRESULT res;
67 DWORD newlen;
68 const char * newurl;
69 } TEST_URL_APPLY;
70
71 static const TEST_URL_APPLY TEST_APPLY[] = {
72 {"www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
73 {"www.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 21, "http://www.winehq.org"},
74 {"www.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
75 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 20, "ftp://ftp.winehq.org"},
76 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 20, "ftp://ftp.winehq.org"},
77 {"ftp.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://ftp.winehq.org"},
78 {"winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
79 {"winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
80 {"winehq.org", URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
81 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
82 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_FORCEAPPLY, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
83 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_FORCEAPPLY | URL_APPLY_DEFAULT, S_OK, 28, "http://http://www.winehq.org"},
84 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
85 {"", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 7, "http://"},
86 {"", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
87 {"", URL_APPLY_DEFAULT, S_OK, 7, "http://"},
88 {"u:\\windows", URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT, S_OK, 18, "file:///u:/windows"},
89 {"u:\\windows", URL_APPLY_GUESSFILE, S_OK, 18, "file:///u:/windows"},
90 {"u:\\windows", URL_APPLY_DEFAULT, S_OK, 17, "http://u:\\windows"},
91 {"file:///c:/windows", URL_APPLY_GUESSFILE , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
92 {"aa:\\windows", URL_APPLY_GUESSFILE , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
93 };
94
95 /* ################ */
96
97 typedef struct _TEST_URL_CANONICALIZE {
98 const char *url;
99 DWORD flags;
100 HRESULT expectret;
101 const char *expecturl;
102 BOOL todo;
103 } TEST_URL_CANONICALIZE;
104
105 static const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
106 {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/", TRUE},
107 {"http://www.winehq.org/..", 0, S_OK, "http://www.winehq.org/..", FALSE},
108 {"http://www.winehq.org/tests/tests2/../../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
109 {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
110 {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
111 {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
112 {"http://www.winehq.org/tests\r", 0, S_OK, "http://www.winehq.org/tests", FALSE},
113 {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests", FALSE},
114 {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/", FALSE},
115 {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
116 {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
117 {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
118 {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
119 {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
120 {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
121 {"\tht\ttp\t://www\t.w\tineh\t\tq.or\tg\t/\ttests/..\t?\tquer\ty=x\t\t&re\tturn=y\t\t", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
122 {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
123 {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
124 {"http://www.winehq.org/tests\\../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
125 {"http://www.winehq.org/tests/..\\#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
126 {"http://www.winehq.org\\tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
127 {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example", FALSE},
128 {"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},
129 {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE , S_OK, "http://www.winehq.org/tests/foo bar", FALSE},
130 {"http://www.winehq.org", 0, S_OK, "http://www.winehq.org/", FALSE},
131 {"http:///www.winehq.org", 0, S_OK, "http:///www.winehq.org", FALSE},
132 {"http:////www.winehq.org", 0, S_OK, "http:////www.winehq.org", FALSE},
133 {"file:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
134 {"file:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
135 {"file:///c:/tests/foo%20bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
136 {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
137 {"file://localhost/c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
138 {"file://localhost\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
139 {"file://localhost\\\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
140 {"file://localhost\\c:\\tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
141 {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
142 {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
143 {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
144 {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar", FALSE},
145 {"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar", FALSE},
146 {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar", FALSE},
147 {"file:///c:\\tests\\foobar", 0, S_OK, "file:///c:/tests/foobar", FALSE},
148 {"file:///c:\\tests\\foobar", URL_WININET_COMPATIBILITY, S_OK, "file://c:\\tests\\foobar", FALSE},
149 {"file://home/user/file", 0, S_OK, "file://home/user/file", FALSE},
150 {"file:///home/user/file", 0, S_OK, "file:///home/user/file", FALSE},
151 {"file:////home/user/file", 0, S_OK, "file://home/user/file", FALSE},
152 {"file://home/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://\\\\home\\user\\file", FALSE},
153 {"file:///home/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://\\home\\user\\file", FALSE},
154 {"file:////home/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://\\\\home\\user\\file", FALSE},
155 {"file://///home/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://\\\\home\\user\\file", FALSE},
156 {"file://C:/user/file", 0, S_OK, "file:///C:/user/file", FALSE},
157 {"file://C:/user/file/../asdf", 0, S_OK, "file:///C:/user/asdf", FALSE},
158 {"file:///C:/user/file", 0, S_OK, "file:///C:/user/file", FALSE},
159 {"file:////C:/user/file", 0, S_OK, "file:///C:/user/file", FALSE},
160 {"file://C:/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://C:\\user\\file", FALSE},
161 {"file:///C:/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://C:\\user\\file", FALSE},
162 {"file:////C:/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://C:\\user\\file", FALSE},
163 {"http:///www.winehq.org", 0, S_OK, "http:///www.winehq.org", FALSE},
164 {"http:///www.winehq.org", URL_WININET_COMPATIBILITY, S_OK, "http:///www.winehq.org", FALSE},
165 {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about", FALSE},
166 {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about", FALSE},
167 {"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
168 {"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
169 {"c:dir\\file", 0, S_OK, "file:///c:dir/file", FALSE},
170 {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
171 {"c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
172 {"c\t:\t\\te\tsts\\fo\to \tbar\t", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
173 {"res://file", 0, S_OK, "res://file/", FALSE},
174 {"res://file", URL_FILE_USE_PATHURL, S_OK, "res://file/", FALSE},
175 {"res:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests/foo bar", FALSE},
176 {"res:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests\\foo bar", FALSE},
177 {"res:///c:/tests/foo%20bar", 0, S_OK, "res:///c:/tests/foo%20bar", FALSE},
178 {"res:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c:/tests/foo%20bar", FALSE},
179 {"res://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
180 {"res://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
181 {"res://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
182 {"res:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c://tests/foo%20bar", FALSE},
183 {"res:///c:\\tests\\foo bar", 0, S_OK, "res:///c:\\tests\\foo bar", FALSE},
184 {"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "res:///c:\\tests\\foo bar", FALSE},
185 {"res://c:\\tests\\foo bar/res", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests\\foo bar/res", FALSE},
186 {"res://c:\\tests/res\\foo%20bar/strange\\sth", 0, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
187 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
188 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_UNESCAPE, S_OK, "res://c:\\tests/res\\foo bar/strange\\sth", FALSE},
189 {"/A/../B/./C/../../test_remove_dot_segments", 0, S_OK, "/test_remove_dot_segments", FALSE},
190 {"/A/../B/./C/../../test_remove_dot_segments", URL_FILE_USE_PATHURL, S_OK, "/test_remove_dot_segments", FALSE},
191 {"/A/../B/./C/../../test_remove_dot_segments", URL_WININET_COMPATIBILITY, S_OK, "/test_remove_dot_segments", FALSE},
192 {"/A/B\\C/D\\E", 0, S_OK, "/A/B\\C/D\\E", FALSE},
193 {"/A/B\\C/D\\E", URL_FILE_USE_PATHURL, S_OK, "/A/B\\C/D\\E", FALSE},
194 {"/A/B\\C/D\\E", URL_WININET_COMPATIBILITY, S_OK, "/A/B\\C/D\\E", FALSE},
195 {"///A/../B", 0, S_OK, "///B", FALSE},
196 {"///A/../B", URL_FILE_USE_PATHURL, S_OK, "///B", FALSE},
197 {"///A/../B", URL_WININET_COMPATIBILITY, S_OK, "///B", FALSE},
198 {"A", 0, S_OK, "A", FALSE},
199 {"../A", 0, S_OK, "../A", FALSE},
200 {".\\A", 0, S_OK, ".\\A", FALSE},
201 {"A\\.\\B", 0, S_OK, "A\\.\\B", FALSE},
202 {"A/../B", 0, S_OK, "B", TRUE},
203 {"A/../B/./../C", 0, S_OK, "C", TRUE},
204 {"A/../B/./../C", URL_DONT_SIMPLIFY, S_OK, "A/../B/./../C", FALSE},
205 {".", 0, S_OK, "/", TRUE},
206 {"./A", 0, S_OK, "A", TRUE},
207 {"A/./B", 0, S_OK, "A/B", TRUE},
208 {"/:test\\", 0, S_OK, "/:test\\", TRUE},
209 {"/uri-res/N2R?urn:sha1:B3K", URL_DONT_ESCAPE_EXTRA_INFO | URL_WININET_COMPATIBILITY /*0x82000000*/, S_OK, "/uri-res/N2R?urn:sha1:B3K", FALSE} /*LimeWire online installer calls this*/,
210 {"http:www.winehq.org/dir/../index.html", 0, S_OK, "http:www.winehq.org/index.html"},
211 {"http://localhost/test.html", URL_FILE_USE_PATHURL, S_OK, "http://localhost/test.html"},
212 {"http://localhost/te%20st.html", URL_FILE_USE_PATHURL, S_OK, "http://localhost/te%20st.html"},
213 {"http://www.winehq.org/%E6%A1%9C.html", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/%E6%A1%9C.html"},
214 {"mk:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", 0, S_OK, "mk:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
215 {"ftp:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", 0, S_OK, "ftp:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
216 {"file:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", 0, S_OK, "file:@MSITStore:C:/Program Files/AutoCAD 2008/Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
217 {"http:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", 0, S_OK, "http:@MSITStore:C:/Program Files/AutoCAD 2008/Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
218 {"http:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", URL_FILE_USE_PATHURL, S_OK, "http:@MSITStore:C:/Program Files/AutoCAD 2008/Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
219 {"mk:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm", URL_FILE_USE_PATHURL, S_OK, "mk:@MSITStore:C:\\Program Files/AutoCAD 2008\\Help/acad_acg.chm::/WSfacf1429558a55de1a7524c1004e616f8b-322b.htm"},
220 };
221
222 /* ################ */
223
224 typedef struct _TEST_URL_ESCAPE {
225 const char *url;
226 DWORD flags;
227 DWORD expectescaped;
228 HRESULT expectret;
229 const char *expecturl;
230 } TEST_URL_ESCAPE;
231
232 static const TEST_URL_ESCAPE TEST_ESCAPE[] = {
233 {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"},
234 {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"},
235 {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"},
236 {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"},
237 {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"},
238 {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"},
239 {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
240
241 {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
242 {"file://///foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
243 {"file:////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
244 {"file:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
245 {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
246 {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
247 {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
248 {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
249 {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
250 {"file:foo/bar\\baz", 0, 0, S_OK, "file:foo/bar/baz"},
251 {"file:\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
252 {"file:\\\\foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
253 {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
254 {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
255 {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"},
256 {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"},
257 {"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"},
258 {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"},
259 {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"},
260
261 {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"},
262 {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"},
263 {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"},
264 {"/foo/bar\\ba?z\\", 0, 0, S_OK, "/foo/bar%5Cba?z\\"},
265 {"/foo/bar\\ba#z\\", 0, 0, S_OK, "/foo/bar%5Cba#z\\"},
266 {"/foo/%5C", 0, 0, S_OK, "/foo/%5C"},
267 {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"},
268
269 {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"},
270 {"http://///foo/bar\\baz", 0, 0, S_OK, "http://///foo/bar/baz"},
271 {"http:////foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
272 {"http:///foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
273 {"http://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"},
274 {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
275 {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
276 {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"},
277 {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"},
278 {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
279 {"http:\\\\foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
280 {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
281 {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
282 {"http:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"},
283 {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"},
284 {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"},
285
286 {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"},
287 {"https:/foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
288 {"https:\\foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
289
290 {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"},
291 {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"},
292 {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"},
293 {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://foo/bar%5Cbaz"},
294 {"foo:/foo/bar\\baz", 0, 0, S_OK, "foo:/foo/bar%5Cbaz"},
295 {"foo:foo/bar\\baz", 0, 0, S_OK, "foo:foo%2Fbar%5Cbaz"},
296 {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"},
297 {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"},
298 {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"},
299
300 {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
301 {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
302 {"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"},
303
304 {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
305 {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"},
306 {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"},
307 {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"},
308 {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"},
309 {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"},
310 {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"},
311
312 {"ftp\x1f\1end/", 0, 0, S_OK, "ftp%1F%01end/"}
313 };
314
315 typedef struct _TEST_URL_ESCAPEW {
316 const WCHAR url[INTERNET_MAX_URL_LENGTH];
317 DWORD flags;
318 HRESULT expectret;
319 const WCHAR expecturl[INTERNET_MAX_URL_LENGTH];
320 const WCHAR win7url[INTERNET_MAX_URL_LENGTH]; /* <= Win7 */
321 const WCHAR vistaurl[INTERNET_MAX_URL_LENGTH]; /* <= Vista/2k8 */
322 } TEST_URL_ESCAPEW;
323
324 static const TEST_URL_ESCAPEW TEST_ESCAPEW[] = {
325 {{' ','<','>','"',0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','2','0','%','3','C','%','3','E','%','2','2',0}},
326 {{'{','}','|','\\',0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','7','B','%','7','D','%','7','C','%','5','C',0}},
327 {{'^',']','[','`',0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','5','E','%','5','D','%','5','B','%','6','0',0}},
328 {{'&','/','?','#',0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','2','6','/','?','#',0}},
329 {{'M','a','s','s',0}, URL_ESCAPE_AS_UTF8, S_OK, {'M','a','s','s',0}},
330
331 /* broken < Win8/10 */
332
333 {{'M','a',0xdf,0}, URL_ESCAPE_AS_UTF8, S_OK, {'M','a','%','C','3','%','9','F',0},
334 {'M','a','%','D','F',0}},
335 /* 0x2070E */
336 {{0xd841,0xdf0e,0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','F','0','%','A','0','%','9','C','%','8','E',0},
337 {'%','E','F','%','B','F','%','B','D','%','E','F','%','B','F','%','B','D',0},
338 {0xd841,0xdf0e,0}},
339 /* 0x27A3E */
340 {{0xd85e,0xde3e,0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','F','0','%','A','7','%','A','8','%','B','E',0},
341 {'%','E','F','%','B','F','%','B','D','%','E','F','%','B','F','%','B','D',0},
342 {0xd85e,0xde3e,0}},
343
344 {{0xd85e,0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','E','F','%','B','F','%','B','D',0},
345 {0xd85e,0}},
346 {{0xd85e,0x41}, URL_ESCAPE_AS_UTF8, S_OK, {'%','E','F','%','B','F','%','B','D','A',0},
347 {0xd85e,'A',0}},
348 {{0xdc00,0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','E','F','%','B','F','%','B','D',0},
349 {0xdc00,0}},
350 {{0xffff,0}, URL_ESCAPE_AS_UTF8, S_OK, {'%','E','F','%','B','F','%','B','F',0},
351 {0xffff,0}},
352 };
353
354 /* ################ */
355
356 typedef struct _TEST_URL_COMBINE {
357 const char *url1;
358 const char *url2;
359 DWORD flags;
360 HRESULT expectret;
361 const char *expecturl;
362 BOOL todo;
363 } TEST_URL_COMBINE;
364
365 static const TEST_URL_COMBINE TEST_COMBINE[] = {
366 {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
367 {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
368 /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
369 {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"},
370 {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"},
371 {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"},
372 {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"},
373 {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"},
374 {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"},
375 {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"},
376 {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"},
377 {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."},
378 {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"},
379 {"http://www.winehq.org/test12", "#", 0, S_OK, "http://www.winehq.org/test12#"},
380 {"http://www.winehq.org/test13#aaa", "#bbb", 0, S_OK, "http://www.winehq.org/test13#bbb"},
381 {"http://www.winehq.org/test14#aaa/bbb#ccc", "#", 0, S_OK, "http://www.winehq.org/test14#"},
382 {"http://www.winehq.org/tests/?query=x/y/z", "tests15", 0, S_OK, "http://www.winehq.org/tests/tests15"},
383 {"http://www.winehq.org/tests/?query=x/y/z#example", "tests16", 0, S_OK, "http://www.winehq.org/tests/tests16"},
384 {"http://www.winehq.org/tests17", ".", 0, S_OK, "http://www.winehq.org/"},
385 {"http://www.winehq.org/tests18/test", ".", 0, S_OK, "http://www.winehq.org/tests18/"},
386 {"http://www.winehq.org/tests19/test", "./", 0, S_OK, "http://www.winehq.org/tests19/", FALSE},
387 {"http://www.winehq.org/tests20/test", "/", 0, S_OK, "http://www.winehq.org/", FALSE},
388 {"http://www.winehq.org/tests/test", "./test21", 0, S_OK, "http://www.winehq.org/tests/test21", FALSE},
389 {"http://www.winehq.org/tests/test", "./test22/../test", 0, S_OK, "http://www.winehq.org/tests/test", FALSE},
390 {"http://www.winehq.org/tests/", "http://www.winehq.org:80/tests23", 0, S_OK, "http://www.winehq.org/tests23", TRUE},
391 {"http://www.winehq.org/tests/", "tests24/./test/../test", 0, S_OK, "http://www.winehq.org/tests/tests24/test", FALSE},
392 {"http://www.winehq.org/tests/./tests25", "./", 0, S_OK, "http://www.winehq.org/tests/", FALSE},
393 {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"},
394 {"file:///C:\\dir\\file.txt#hash\\hash", "test.txt", 0, S_OK, "file:///C:/dir/file.txt#hash/test.txt"},
395 {"file:///C:\\dir\\file.html#hash\\hash", "test.html", 0, S_OK, "file:///C:/dir/test.html"},
396 {"file:///C:\\dir\\file.htm#hash\\hash", "test.htm", 0, S_OK, "file:///C:/dir/test.htm"},
397 {"file:///C:\\dir\\file.hTmL#hash\\hash", "test.hTmL", 0, S_OK, "file:///C:/dir/test.hTmL"},
398 {"file:///C:\\dir.html\\file.txt#hash\\hash", "test.txt", 0, S_OK, "file:///C:/dir.html/file.txt#hash/test.txt"},
399 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK, "file:///C:/Test/test.txt"},
400 {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"},
401 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"},
402 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"},
403 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"},
404 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
405 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
406 {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"},
407 {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"},
408 {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"},
409 {"Foo:/today/", "fOo:calendar", 0, S_OK, "foo:/today/calendar"},
410 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
411 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
412 /* UrlCombine case 2 tests. Schemes do not match */
413 {"outbind://xxxxxxxxx","http://wine1/dir",0, S_OK,"http://wine1/dir"},
414 {"xxxx://xxxxxxxxx","http://wine2/dir",0, S_OK,"http://wine2/dir"},
415 {"ftp://xxxxxxxxx/","http://wine3/dir",0, S_OK,"http://wine3/dir"},
416 {"outbind://xxxxxxxxx","http://wine4/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine4/dir"},
417 {"xxx://xxxxxxxxx","http://wine5/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine5/dir"},
418 {"ftp://xxxxxxxxx/","http://wine6/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine6/dir"},
419 {"http://xxxxxxxxx","outbind://wine7/dir",0, S_OK,"outbind://wine7/dir"},
420 {"xxx://xxxxxxxxx","ftp://wine8/dir",0, S_OK,"ftp://wine8/dir"},
421 {"ftp://xxxxxxxxx/","xxx://wine9/dir",0, S_OK,"xxx://wine9/dir"},
422 {"http://xxxxxxxxx","outbind://wine10/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind://wine10/dir"},
423 {"xxx://xxxxxxxxx","ftp://wine11/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp://wine11/dir"},
424 {"ftp://xxxxxxxxx/","xxx://wine12/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx://wine12/dir"},
425 {"http://xxxxxxxxx","outbind:wine13/dir",0, S_OK,"outbind:wine13/dir"},
426 {"xxx://xxxxxxxxx","ftp:wine14/dir",0, S_OK,"ftp:wine14/dir"},
427 {"ftp://xxxxxxxxx/","xxx:wine15/dir",0, S_OK,"xxx:wine15/dir"},
428 {"outbind://xxxxxxxxx/","http:wine16/dir",0, S_OK,"http:wine16/dir"},
429 {"http://xxxxxxxxx","outbind:wine17/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind:wine17/dir"},
430 {"xxx://xxxxxxxxx","ftp:wine18/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp:wine18/dir"},
431 {"ftp://xxxxxxxxx/","xXx:wine19/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx:wine19/dir"},
432 {"outbind://xxxxxxxxx/","http:wine20/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http:wine20/dir"},
433 {"file:///c:/dir/file.txt","index.html?test=c:/abc",URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,S_OK,"file:///c:/dir/index.html?test=c:/abc"}
434 };
435
436 /* ################ */
437
438 static const struct {
439 const char *path;
440 const char *url;
441 DWORD ret;
442 } TEST_URLFROMPATH [] = {
443 {"foo", "file:foo", S_OK},
444 {"foo\\bar", "file:foo/bar", S_OK},
445 {"\\foo\\bar", "file:///foo/bar", S_OK},
446 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK},
447 {"c:foo\\bar", "file:///c:foo/bar", S_OK},
448 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK},
449 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK},
450 {"file:///c:/foo/bar", "file:///c:/foo/bar", S_FALSE},
451 #if 0
452 /* The following test fails on native shlwapi as distributed with Win95/98.
453 * Wine matches the behaviour of later versions.
454 */
455 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE}
456 #endif
457 };
458
459 /* ################ */
460
461 static struct {
462 char url[30];
463 const char *expect;
464 } TEST_URL_UNESCAPE[] = {
465 {"file://foo/bar", "file://foo/bar"},
466 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
467 {"file://%24%25foobar", "file://$%foobar"}
468 };
469
470 /* ################ */
471
472 static const struct {
473 const char *path;
474 BOOL expect;
475 } TEST_PATH_IS_URL[] = {
476 {"http://foo/bar", TRUE},
477 {"c:\\foo\\bar", FALSE},
478 {"foo://foo/bar", TRUE},
479 {"foo\\bar", FALSE},
480 {"foo.bar", FALSE},
481 {"bogusscheme:", TRUE},
482 {"http:partial", TRUE}
483 };
484
485 /* ################ */
486
487 static const struct {
488 const char *url;
489 BOOL expectOpaque;
490 BOOL expectFile;
491 } TEST_URLIS_ATTRIBS[] = {
492 { "ftp:", FALSE, FALSE },
493 { "http:", FALSE, FALSE },
494 { "gopher:", FALSE, FALSE },
495 { "mailto:", TRUE, FALSE },
496 { "news:", FALSE, FALSE },
497 { "nntp:", FALSE, FALSE },
498 { "telnet:", FALSE, FALSE },
499 { "wais:", FALSE, FALSE },
500 { "file:", FALSE, TRUE },
501 { "mk:", FALSE, FALSE },
502 { "https:", FALSE, FALSE },
503 { "shell:", TRUE, FALSE },
504 { "https:", FALSE, FALSE },
505 { "snews:", FALSE, FALSE },
506 { "local:", FALSE, FALSE },
507 { "javascript:", TRUE, FALSE },
508 { "vbscript:", TRUE, FALSE },
509 { "about:", TRUE, FALSE },
510 { "res:", FALSE, FALSE },
511 { "bogusscheme:", FALSE, FALSE },
512 { "file:\\\\e:\\b\\c", FALSE, TRUE },
513 { "file://e:/b/c", FALSE, TRUE },
514 { "http:partial", FALSE, FALSE },
515 { "mailto://www.winehq.org/test.html", TRUE, FALSE },
516 { "file:partial", FALSE, TRUE },
517 { "File:partial", FALSE, TRUE },
518 };
519
520 /* ########################### */
521
522 static LPWSTR GetWideString(const char* szString)
523 {
524 LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
525
526 MultiByteToWideChar(CP_ACP, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
527
528 return wszString;
529 }
530
531
532 static void FreeWideString(LPWSTR wszString)
533 {
534 HeapFree(GetProcessHeap(), 0, wszString);
535 }
536
537 /* ########################### */
538
539 static void test_UrlApplyScheme(void)
540 {
541 CHAR newurl[TEST_APPLY_MAX_LENGTH];
542 WCHAR urlW[TEST_APPLY_MAX_LENGTH];
543 WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
544 HRESULT res;
545 DWORD len;
546 DWORD i;
547
548 if (!pUrlApplySchemeA) {
549 win_skip("UrlApplySchemeA not found\n");
550 return;
551 }
552
553 for(i = 0; i < sizeof(TEST_APPLY)/sizeof(TEST_APPLY[0]); i++) {
554 len = TEST_APPLY_MAX_LENGTH;
555 lstrcpyA(newurl, untouchedA);
556 res = pUrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
557 ok( res == TEST_APPLY[i].res,
558 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
559
560 ok( len == TEST_APPLY[i].newlen,
561 "#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
562
563 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
564 "#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
565
566 /* returned length is in character */
567 len = TEST_APPLY_MAX_LENGTH;
568 lstrcpyA(newurl, untouchedA);
569 MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
570 MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
571
572 res = pUrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
573 WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
574 ok( res == TEST_APPLY[i].res,
575 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
576
577 ok( len == TEST_APPLY[i].newlen,
578 "#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
579
580 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
581 "#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
582
583 }
584
585 /* buffer too small */
586 lstrcpyA(newurl, untouchedA);
587 len = lstrlenA(TEST_APPLY[0].newurl);
588 res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, &len, TEST_APPLY[0].flags);
589 ok(res == E_POINTER, "got HRESULT 0x%x (expected E_POINTER)\n", res);
590 /* The returned length include the space for the terminating 0 */
591 i = lstrlenA(TEST_APPLY[0].newurl)+1;
592 ok(len == i, "got len %d (expected %d)\n", len, i);
593 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
594
595 /* NULL as parameter. The length and the buffer are not modified */
596 lstrcpyA(newurl, untouchedA);
597 len = TEST_APPLY_MAX_LENGTH;
598 res = pUrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
599 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
600 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
601 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
602
603 len = TEST_APPLY_MAX_LENGTH;
604 res = pUrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
605 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
606 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
607
608 lstrcpyA(newurl, untouchedA);
609 res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
610 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
611 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
612
613 }
614
615 /* ########################### */
616
617 static void hash_url(const char* szUrl)
618 {
619 LPCSTR szTestUrl = szUrl;
620 LPWSTR wszTestUrl = GetWideString(szTestUrl);
621 HRESULT res;
622
623 DWORD cbSize = sizeof(DWORD);
624 DWORD dwHash1, dwHash2;
625 res = pUrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize);
626 ok(res == S_OK, "UrlHashA returned 0x%x (expected S_OK) for %s\n", res, szUrl);
627 if (pUrlHashW) {
628 res = pUrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize);
629 ok(res == S_OK, "UrlHashW returned 0x%x (expected S_OK) for %s\n", res, szUrl);
630 ok(dwHash1 == dwHash2,
631 "Hashes didn't match (A: 0x%x, W: 0x%x) for %s\n", dwHash1, dwHash2, szUrl);
632 }
633 FreeWideString(wszTestUrl);
634
635 }
636
637 static void test_UrlHash(void)
638 {
639 if (!pUrlHashA) {
640 win_skip("UrlHashA not found\n");
641 return;
642 }
643
644 hash_url(TEST_URL_1);
645 hash_url(TEST_URL_2);
646 hash_url(TEST_URL_3);
647 }
648
649 /* ########################### */
650
651 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
652 {
653 CHAR szPart[INTERNET_MAX_URL_LENGTH];
654 WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
655 LPWSTR wszUrl = GetWideString(szUrl);
656 LPWSTR wszConvertedPart;
657 HRESULT res;
658 DWORD dwSize;
659
660 dwSize = 1;
661 res = pUrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags);
662 ok(res == E_POINTER, "UrlGetPart for \"%s\" gave: 0x%08x\n", szUrl, res);
663 ok(dwSize == strlen(szExpected)+1 ||
664 (*szExpected == '?' && dwSize == strlen(szExpected)),
665 "UrlGetPart for \"%s\" gave size: %u\n", szUrl, dwSize);
666
667 dwSize = INTERNET_MAX_URL_LENGTH;
668 res = pUrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags);
669 ok(res == S_OK,
670 "UrlGetPartA for \"%s\" part 0x%08x returned 0x%x and \"%s\"\n",
671 szUrl, dwPart, res, szPart);
672 if (pUrlGetPartW) {
673 dwSize = INTERNET_MAX_URL_LENGTH;
674 res = pUrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags);
675 ok(res == S_OK,
676 "UrlGetPartW for \"%s\" part 0x%08x returned 0x%x\n",
677 szUrl, dwPart, res);
678
679 wszConvertedPart = GetWideString(szPart);
680
681 ok(lstrcmpW(wszPart,wszConvertedPart)==0,
682 "Strings didn't match between ascii and unicode UrlGetPart!\n");
683
684 FreeWideString(wszConvertedPart);
685 }
686 FreeWideString(wszUrl);
687
688 /* Note that v6.0 and later don't return '?' with the query */
689 ok(strcmp(szPart,szExpected)==0 ||
690 (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
691 "Expected %s, but got %s\n", szExpected, szPart);
692 }
693
694 /* ########################### */
695
696 static void test_UrlGetPart(void)
697 {
698 const char* file_url = "file://h o s t/c:/windows/file";
699 const char* http_url = "http://user:pass 123@www.wine hq.org";
700 const char* res_url = "res://some.dll/find.dlg";
701 const char* about_url = "about:blank";
702 const char* excid_url = "x-excid://36C00000/guid:{048B4E89-2E92-496F-A837-33BA02FF6D32}/Message.htm";
703 const char* foo_url = "foo://bar-url/test";
704 const char* short_url = "ascheme:";
705
706 CHAR szPart[INTERNET_MAX_URL_LENGTH];
707 DWORD dwSize;
708 HRESULT res;
709
710 if (!pUrlGetPartA) {
711 win_skip("UrlGetPartA not found\n");
712 return;
713 }
714
715 res = pUrlGetPartA(NULL, NULL, NULL, URL_PART_SCHEME, 0);
716 ok(res == E_INVALIDARG, "null params gave: 0x%08x\n", res);
717
718 res = pUrlGetPartA(NULL, szPart, &dwSize, URL_PART_SCHEME, 0);
719 ok(res == E_INVALIDARG, "null URL gave: 0x%08x\n", res);
720
721 res = pUrlGetPartA(res_url, NULL, &dwSize, URL_PART_SCHEME, 0);
722 ok(res == E_INVALIDARG, "null szPart gave: 0x%08x\n", res);
723
724 res = pUrlGetPartA(res_url, szPart, NULL, URL_PART_SCHEME, 0);
725 ok(res == E_INVALIDARG, "null URL gave: 0x%08x\n", res);
726
727 dwSize = 0;
728 szPart[0]='x'; szPart[1]=0;
729 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
730 ok(res == E_INVALIDARG, "UrlGetPartA(*pcchOut = 0) returned %08X\n", res);
731 ok(szPart[0] == 'x' && szPart[1] == 0, "UrlGetPartA(*pcchOut = 0) modified szPart: \"%s\"\n", szPart);
732 ok(dwSize == 0, "dwSize = %d\n", dwSize);
733
734 dwSize = sizeof szPart;
735 szPart[0]='x'; szPart[1]=0;
736 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
737 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
738 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
739 ok(dwSize == 0, "dwSize = %d\n", dwSize);
740
741 if(pUrlGetPartW)
742 {
743 const WCHAR hiW[] = {'h','i',0};
744 WCHAR bufW[5];
745
746 /* UrlGetPartW returns S_OK instead of S_FALSE */
747 dwSize = sizeof szPart;
748 bufW[0]='x'; bufW[1]=0;
749 res = pUrlGetPartW(hiW, bufW, &dwSize, URL_PART_SCHEME, 0);
750 todo_wine ok(res==S_OK, "UrlGetPartW(\"hi\") returned %08X\n", res);
751 ok(bufW[0] == 0, "UrlGetPartW(\"hi\") return \"%c\"\n", bufW[0]);
752 ok(dwSize == 0, "dwSize = %d\n", dwSize);
753 }
754
755 dwSize = sizeof szPart;
756 szPart[0]='x'; szPart[1]=0;
757 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0);
758 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
759 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
760 ok(dwSize == 0, "dwSize = %d\n", dwSize);
761
762 test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
763 test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
764 test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
765 test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
766 test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
767 test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
768
769 test_url_part(TEST_URL_4, URL_PART_HOSTNAME, 0, "google.*.com");
770
771 test_url_part(file_url, URL_PART_HOSTNAME, 0, "h o s t");
772
773 test_url_part(http_url, URL_PART_HOSTNAME, 0, "www.wine hq.org");
774 test_url_part(http_url, URL_PART_PASSWORD, 0, "pass 123");
775
776 test_url_part(about_url, URL_PART_SCHEME, 0, "about");
777
778 test_url_part(excid_url, URL_PART_SCHEME, 0, "x-excid");
779 test_url_part(foo_url, URL_PART_SCHEME, 0, "foo");
780 test_url_part(short_url, URL_PART_SCHEME, 0, "ascheme");
781
782 dwSize = sizeof(szPart);
783 res = pUrlGetPartA(about_url, szPart, &dwSize, URL_PART_HOSTNAME, 0);
784 ok(res==E_FAIL, "returned %08x\n", res);
785
786 test_url_part(res_url, URL_PART_SCHEME, 0, "res");
787 test_url_part("http://www.winehq.org", URL_PART_HOSTNAME, URL_PARTFLAG_KEEPSCHEME, "http:www.winehq.org");
788
789 dwSize = sizeof szPart;
790 szPart[0]='x'; szPart[1]=0;
791 res = pUrlGetPartA(res_url, szPart, &dwSize, URL_PART_QUERY, 0);
792 ok(res==S_FALSE, "UrlGetPartA returned %08X\n", res);
793 ok(szPart[0]==0, "UrlGetPartA gave \"%s\" instead of \"\"\n", szPart);
794 ok(dwSize == 0, "dwSize = %d\n", dwSize);
795
796 dwSize = sizeof(szPart);
797 res = pUrlGetPartA("file://c:\\index.htm", szPart, &dwSize, URL_PART_HOSTNAME, 0);
798 ok(res==S_FALSE, "returned %08x\n", res);
799 ok(dwSize == 0, "dwSize = %d\n", dwSize);
800
801 dwSize = sizeof(szPart);
802 szPart[0] = 'x'; szPart[1] = '\0';
803 res = pUrlGetPartA("file:some text", szPart, &dwSize, URL_PART_HOSTNAME, 0);
804 ok(res==S_FALSE, "returned %08x\n", res);
805 ok(szPart[0] == '\0', "szPart[0] = %c\n", szPart[0]);
806 ok(dwSize == 0, "dwSize = %d\n", dwSize);
807
808 dwSize = sizeof(szPart);
809 szPart[0] = 'x'; szPart[1] = '\0';
810 res = pUrlGetPartA("index.htm", szPart, &dwSize, URL_PART_HOSTNAME, 0);
811 ok(res==E_FAIL, "returned %08x\n", res);
812
813 dwSize = sizeof(szPart);
814 szPart[0] = 'x'; szPart[1] = '\0';
815 res = pUrlGetPartA(excid_url, szPart, &dwSize, URL_PART_HOSTNAME, 0);
816 ok(res==E_FAIL, "returned %08x\n", res);
817 ok(szPart[0] == 'x', "szPart[0] = %c\n", szPart[0]);
818 ok(dwSize == sizeof(szPart), "dwSize = %d\n", dwSize);
819
820 dwSize = sizeof(szPart);
821 szPart[0] = 'x'; szPart[1] = '\0';
822 res = pUrlGetPartA(excid_url, szPart, &dwSize, URL_PART_QUERY, 0);
823 ok(res==S_FALSE, "returned %08x\n", res);
824 ok(szPart[0] == 0, "szPart[0] = %c\n", szPart[0]);
825 ok(dwSize == 0, "dwSize = %d\n", dwSize);
826
827 dwSize = sizeof(szPart);
828 szPart[0] = 'x'; szPart[1] = '\0';
829 res = pUrlGetPartA(foo_url, szPart, &dwSize, URL_PART_HOSTNAME, 0);
830 ok(res==E_FAIL, "returned %08x\n", res);
831 ok(szPart[0] == 'x', "szPart[0] = %c\n", szPart[0]);
832 ok(dwSize == sizeof(szPart), "dwSize = %d\n", dwSize);
833
834 dwSize = sizeof(szPart);
835 szPart[0] = 'x'; szPart[1] = '\0';
836 res = pUrlGetPartA(foo_url, szPart, &dwSize, URL_PART_QUERY, 0);
837 ok(res==S_FALSE, "returned %08x\n", res);
838 ok(szPart[0] == 0, "szPart[0] = %c\n", szPart[0]);
839 ok(dwSize == 0, "dwSize = %d\n", dwSize);
840 }
841
842 /* ########################### */
843 static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, HRESULT dwExpectReturnAlt, const char *szExpectUrl, BOOL todo)
844 {
845 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
846 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
847 LPWSTR wszUrl = GetWideString(szUrl);
848 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
849 LPWSTR wszConvertedUrl;
850 HRESULT ret;
851
852 DWORD dwSize;
853
854 dwSize = INTERNET_MAX_URL_LENGTH;
855 ret = pUrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags);
856 ok(ret != dwExpectReturn, "got 0s%x: Unexpected return for NULL buffer, index %d\n", ret, index);
857 ret = pUrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags);
858 ok(ret == dwExpectReturn || ret == dwExpectReturnAlt,
859 "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
860 dwExpectReturn, dwExpectReturnAlt, ret, index);
861 todo_wine_if (todo)
862 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
863
864 if (pUrlCanonicalizeW) {
865 dwSize = INTERNET_MAX_URL_LENGTH;
866 ret = pUrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags);
867 ok(ret != dwExpectReturn, "got 0x%x: Unexpected return for NULL buffer, index %d\n", ret, index);
868 ret = pUrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags);
869 ok(ret == dwExpectReturn, "UrlCanonicalizeW failed: expected 0x%08x, got 0x%x, index %d\n",
870 dwExpectReturn, ret, index);
871
872 wszConvertedUrl = GetWideString(szReturnUrl);
873 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0,
874 "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
875 FreeWideString(wszConvertedUrl);
876 }
877
878 FreeWideString(wszUrl);
879 FreeWideString(wszExpectUrl);
880 }
881
882
883 static void test_UrlEscapeA(void)
884 {
885 DWORD size = 0;
886 HRESULT ret;
887 unsigned int i;
888 char empty_string[] = "";
889
890 if (!pUrlEscapeA) {
891 win_skip("UrlEscapeA not found\n");
892 return;
893 }
894
895 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
896 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
897 ok(size == 0, "got %d, expected %d\n", size, 0);
898
899 size = 0;
900 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
901 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
902 ok(size == 0, "got %d, expected %d\n", size, 0);
903
904 size = 1;
905 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
906 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
907 ok(size == 1, "got %d, expected %d\n", size, 1);
908
909 size = 1;
910 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
911 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
912 ok(size == 1, "got %d, expected %d\n", size, 1);
913
914 size = 1;
915 empty_string[0] = 127;
916 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
917 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
918 ok(size == 34, "got %d, expected %d\n", size, 34);
919 ok(empty_string[0] == 127, "String has changed, empty_string[0] = %d\n", empty_string[0]);
920
921 size = 1;
922 empty_string[0] = 127;
923 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_AS_UTF8);
924 ok(ret == E_NOTIMPL || broken(ret == E_POINTER), /* < Win7/Win2k8 */
925 "got %x, expected %x\n", ret, E_NOTIMPL);
926 ok(size == 1 || broken(size == 34), /* < Win7/Win2k8 */
927 "got %d, expected %d\n", size, 1);
928 ok(empty_string[0] == 127, "String has changed, empty_string[0] = %d\n", empty_string[0]);
929
930 for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
931 CHAR ret_url[INTERNET_MAX_URL_LENGTH];
932
933 size = INTERNET_MAX_URL_LENGTH;
934 ret = pUrlEscapeA(TEST_ESCAPE[i].url, ret_url, &size, TEST_ESCAPE[i].flags);
935 ok(ret == TEST_ESCAPE[i].expectret, "UrlEscapeA returned 0x%08x instead of 0x%08x for \"%s\"\n",
936 ret, TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].url);
937 ok(!strcmp(ret_url, TEST_ESCAPE[i].expecturl), "Expected \"%s\", but got \"%s\" for \"%s\"\n",
938 TEST_ESCAPE[i].expecturl, ret_url, TEST_ESCAPE[i].url);
939 }
940 }
941
942 static void test_UrlEscapeW(void)
943 {
944 static const WCHAR path_test[] = {'/','t','e','s','t',0};
945 static const WCHAR naW[] = {'f','t','p',31,255,250,0x2122,'e','n','d','/',0};
946 static const WCHAR naescapedW[] = {'f','t','p','%','1','F','%','F','F','%','F','A',0x2122,'e','n','d','/',0};
947 static const WCHAR out[] = {'f','o','o','%','2','0','b','a','r',0};
948 WCHAR overwrite[] = {'f','o','o',' ','b','a','r',0,0,0};
949 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
950 WCHAR empty_string[] = {0};
951 DWORD size;
952 HRESULT ret;
953 WCHAR wc;
954 int i;
955
956 if (!pUrlEscapeW) {
957 win_skip("UrlEscapeW not found\n");
958 return;
959 }
960
961 /* Check error paths */
962
963 ret = UrlEscapeW(path_test, NULL, NULL, URL_ESCAPE_SPACES_ONLY);
964 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
965
966 size = 0;
967 ret = UrlEscapeW(path_test, NULL, &size, URL_ESCAPE_SPACES_ONLY);
968 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
969 ok(size == 0, "got %d, expected %d\n", size, 0);
970
971 ret = UrlEscapeW(path_test, empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
972 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
973
974 size = 0;
975 ret = UrlEscapeW(path_test, empty_string, &size, URL_ESCAPE_SPACES_ONLY);
976 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
977 ok(size == 0, "got %d, expected %d\n", size, 0);
978
979 ret = UrlEscapeW(path_test, NULL, NULL, URL_ESCAPE_SPACES_ONLY);
980 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
981
982 size = 1;
983 ret = UrlEscapeW(path_test, NULL, &size, URL_ESCAPE_SPACES_ONLY);
984 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
985 ok(size == 1, "got %d, expected %d\n", size, 1);
986
987 ret = UrlEscapeW(path_test, empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
988 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
989
990 size = 1;
991 ret = UrlEscapeW(path_test, empty_string, &size, URL_ESCAPE_SPACES_ONLY);
992 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
993 ok(size == 6, "got %d, expected %d\n", size, 6);
994
995 /* Check actual escaping */
996
997 size = sizeof(overwrite)/sizeof(WCHAR);
998 ret = pUrlEscapeW(overwrite, overwrite, &size, URL_ESCAPE_SPACES_ONLY);
999 ok(ret == S_OK, "got %x, expected S_OK\n", ret);
1000 ok(size == 9, "got %d, expected 9\n", size);
1001 ok(!lstrcmpW(overwrite, out), "got %s, expected %s\n", wine_dbgstr_w(overwrite), wine_dbgstr_w(out));
1002
1003 size = 1;
1004 wc = 127;
1005 ret = pUrlEscapeW(overwrite, &wc, &size, URL_ESCAPE_SPACES_ONLY);
1006 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
1007 ok(size == 10, "got %d, expected 10\n", size);
1008 ok(wc == 127, "String has changed, wc = %d\n", wc);
1009
1010 /* non-ASCII range */
1011 size = sizeof(ret_urlW)/sizeof(WCHAR);
1012 ret = pUrlEscapeW(naW, ret_urlW, &size, 0);
1013 ok(ret == S_OK, "got %x, expected S_OK\n", ret);
1014 ok(!lstrcmpW(naescapedW, ret_urlW), "got %s, expected %s\n", wine_dbgstr_w(ret_urlW), wine_dbgstr_w(naescapedW));
1015
1016 for (i = 0; i < sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
1017
1018 WCHAR *urlW, *expected_urlW;
1019
1020 size = INTERNET_MAX_URL_LENGTH;
1021 urlW = GetWideString(TEST_ESCAPE[i].url);
1022 expected_urlW = GetWideString(TEST_ESCAPE[i].expecturl);
1023 ret = pUrlEscapeW(urlW, ret_urlW, &size, TEST_ESCAPE[i].flags);
1024 ok(ret == TEST_ESCAPE[i].expectret, "UrlEscapeW returned 0x%08x instead of 0x%08x for %s\n",
1025 ret, TEST_ESCAPE[i].expectret, wine_dbgstr_w(urlW));
1026 ok(!lstrcmpW(ret_urlW, expected_urlW), "Expected %s, but got %s for %s flags %08x\n",
1027 wine_dbgstr_w(expected_urlW), wine_dbgstr_w(ret_urlW), wine_dbgstr_w(urlW), TEST_ESCAPE[i].flags);
1028 FreeWideString(urlW);
1029 FreeWideString(expected_urlW);
1030 }
1031
1032 for(i=0; i<sizeof(TEST_ESCAPEW)/sizeof(TEST_ESCAPEW[0]); i++) {
1033 WCHAR ret_url[INTERNET_MAX_URL_LENGTH];
1034
1035 size = INTERNET_MAX_URL_LENGTH;
1036 ret = pUrlEscapeW(TEST_ESCAPEW[i].url, ret_url, &size, TEST_ESCAPEW[i].flags);
1037 ok(ret == TEST_ESCAPEW[i].expectret, "UrlEscapeW returned 0x%08x instead of 0x%08x for \"%s\"\n",
1038 ret, TEST_ESCAPEW[i].expectret, wine_dbgstr_w(TEST_ESCAPEW[i].url));
1039 ok(!lstrcmpW(ret_url, TEST_ESCAPEW[i].expecturl) ||
1040 broken(!lstrcmpW(ret_url, TEST_ESCAPEW[i].vistaurl)) ||
1041 broken(!lstrcmpW(ret_url, TEST_ESCAPEW[i].win7url)),
1042 "Expected \"%s\" or \"%s\" or \"%s\", but got \"%s\" for \"%s\"\n",
1043 wine_dbgstr_w(TEST_ESCAPEW[i].expecturl), wine_dbgstr_w(TEST_ESCAPEW[i].vistaurl),
1044 wine_dbgstr_w(TEST_ESCAPEW[i].win7url), wine_dbgstr_w(ret_url), wine_dbgstr_w(TEST_ESCAPEW[i].url));
1045 }
1046 }
1047
1048 /* ########################### */
1049
1050 static void test_UrlCanonicalizeA(void)
1051 {
1052 unsigned int i;
1053 CHAR szReturnUrl[4*INTERNET_MAX_URL_LENGTH];
1054 CHAR longurl[4*INTERNET_MAX_URL_LENGTH];
1055 DWORD dwSize;
1056 DWORD urllen;
1057 HRESULT hr;
1058
1059 if (!pUrlCanonicalizeA) {
1060 win_skip("UrlCanonicalizeA not found\n");
1061 return;
1062 }
1063
1064 urllen = lstrlenA(winehqA);
1065
1066 /* buffer has no space for the result */
1067 dwSize=urllen-1;
1068 memset(szReturnUrl, '#', urllen+4);
1069 szReturnUrl[urllen+4] = '\0';
1070 SetLastError(0xdeadbeef);
1071 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1072 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
1073 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
1074 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
1075
1076 /* buffer has no space for the terminating '\0' */
1077 dwSize=urllen;
1078 memset(szReturnUrl, '#', urllen+4);
1079 szReturnUrl[urllen+4] = '\0';
1080 SetLastError(0xdeadbeef);
1081 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1082 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
1083 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
1084 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
1085
1086 /* buffer has the required size */
1087 dwSize=urllen+1;
1088 memset(szReturnUrl, '#', urllen+4);
1089 szReturnUrl[urllen+4] = '\0';
1090 SetLastError(0xdeadbeef);
1091 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1092 ok( (hr == S_OK) && (dwSize == urllen),
1093 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
1094 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
1095
1096 /* buffer is larger as the required size */
1097 dwSize=urllen+2;
1098 memset(szReturnUrl, '#', urllen+4);
1099 szReturnUrl[urllen+4] = '\0';
1100 SetLastError(0xdeadbeef);
1101 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1102 ok( (hr == S_OK) && (dwSize == urllen),
1103 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
1104 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
1105
1106 /* length is set to 0 */
1107 dwSize=0;
1108 memset(szReturnUrl, '#', urllen+4);
1109 szReturnUrl[urllen+4] = '\0';
1110 SetLastError(0xdeadbeef);
1111 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1112 ok( (hr == E_INVALIDARG) && (dwSize == 0),
1113 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_INVALIDARG' and size %u)\n",
1114 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), 0);
1115
1116 /* url length > INTERNET_MAX_URL_SIZE */
1117 dwSize=sizeof(szReturnUrl);
1118 memset(longurl, 'a', sizeof(longurl));
1119 memcpy(longurl, winehqA, sizeof(winehqA)-1);
1120 longurl[sizeof(longurl)-1] = '\0';
1121 hr = pUrlCanonicalizeA(longurl, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1122 ok(hr == S_OK, "hr = %x\n", hr);
1123
1124 test_url_canonicalize(-1, "", 0, S_OK, S_FALSE /* Vista/win2k8 */, "", FALSE);
1125
1126 /* test url-modification */
1127 for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
1128 test_url_canonicalize(i, TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
1129 TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl,
1130 TEST_CANONICALIZE[i].todo);
1131 }
1132 }
1133
1134 /* ########################### */
1135
1136 static void test_UrlCanonicalizeW(void)
1137 {
1138 WCHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1139 DWORD dwSize;
1140 DWORD urllen;
1141 HRESULT hr;
1142 int i;
1143
1144
1145 if (!pUrlCanonicalizeW) {
1146 win_skip("UrlCanonicalizeW not found\n");
1147 return;
1148 }
1149 urllen = lstrlenW(winehqW);
1150
1151 /* buffer has no space for the result */
1152 dwSize = (urllen-1);
1153 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
1154 szReturnUrl[urllen+4] = '\0';
1155 SetLastError(0xdeadbeef);
1156 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1157 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
1158 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
1159 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
1160
1161
1162 /* buffer has no space for the terminating '\0' */
1163 dwSize = urllen;
1164 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
1165 szReturnUrl[urllen+4] = '\0';
1166 SetLastError(0xdeadbeef);
1167 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1168 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
1169 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
1170 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
1171
1172 /* buffer has the required size */
1173 dwSize = urllen +1;
1174 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
1175 szReturnUrl[urllen+4] = '\0';
1176 SetLastError(0xdeadbeef);
1177 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1178 ok( (hr == S_OK) && (dwSize == urllen),
1179 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
1180 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
1181
1182 /* buffer is larger as the required size */
1183 dwSize = (urllen+2);
1184 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
1185 szReturnUrl[urllen+4] = '\0';
1186 SetLastError(0xdeadbeef);
1187 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1188 ok( (hr == S_OK) && (dwSize == urllen),
1189 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
1190 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
1191
1192 /* check that the characters 1..32 are chopped from the end of the string */
1193 for (i = 1; i < 65536; i++)
1194 {
1195 WCHAR szUrl[128];
1196 BOOL choped;
1197 int pos;
1198
1199 MultiByteToWideChar(CP_ACP, 0, "http://www.winehq.org/X", -1, szUrl, sizeof(szUrl)/sizeof(szUrl[0]));
1200 pos = lstrlenW(szUrl) - 1;
1201 szUrl[pos] = i;
1202 urllen = INTERNET_MAX_URL_LENGTH;
1203 pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
1204 choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
1205 ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
1206 }
1207 }
1208
1209 /* ########################### */
1210
1211 static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl, BOOL todo)
1212 {
1213 HRESULT hr;
1214 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1215 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
1216 LPWSTR wszUrl1, wszUrl2, wszExpectUrl, wszConvertedUrl;
1217
1218 DWORD dwSize;
1219 DWORD dwExpectLen = lstrlenA(szExpectUrl);
1220
1221 if (!pUrlCombineA) {
1222 win_skip("UrlCombineA not found\n");
1223 return;
1224 }
1225
1226 wszUrl1 = GetWideString(szUrl1);
1227 wszUrl2 = GetWideString(szUrl2);
1228 wszExpectUrl = GetWideString(szExpectUrl);
1229
1230 hr = pUrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
1231 ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
1232
1233 dwSize = 0;
1234 hr = pUrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
1235 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1236 ok(todo || dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1237
1238 dwSize--;
1239 hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
1240 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1241 ok(todo || dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1242
1243 hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
1244 ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
1245
1246 if (todo)
1247 {
1248 todo_wine ok(dwSize == dwExpectLen && (FAILED(hr) || strcmp(szReturnUrl, szExpectUrl)==0),
1249 "Expected %s (len=%d), but got %s (len=%d)\n", szExpectUrl, dwExpectLen, SUCCEEDED(hr) ? szReturnUrl : "(null)", dwSize);
1250 }
1251 else
1252 {
1253 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
1254 if (SUCCEEDED(hr))
1255 ok(strcmp(szReturnUrl, szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
1256 }
1257
1258 if (pUrlCombineW) {
1259 dwSize = 0;
1260 hr = pUrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
1261 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1262 ok(todo || dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1263
1264 dwSize--;
1265 hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
1266 ok(hr == E_POINTER, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1267 ok(todo || dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1268
1269 hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
1270 ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
1271 ok(todo || dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
1272 if(SUCCEEDED(hr)) {
1273 wszConvertedUrl = GetWideString(szReturnUrl);
1274 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
1275 FreeWideString(wszConvertedUrl);
1276 }
1277 }
1278
1279 FreeWideString(wszUrl1);
1280 FreeWideString(wszUrl2);
1281 FreeWideString(wszExpectUrl);
1282 }
1283
1284 /* ########################### */
1285
1286 static void test_UrlCombine(void)
1287 {
1288 unsigned int i;
1289 for(i=0; i<sizeof(TEST_COMBINE)/sizeof(TEST_COMBINE[0]); i++) {
1290 test_url_combine(TEST_COMBINE[i].url1, TEST_COMBINE[i].url2, TEST_COMBINE[i].flags,
1291 TEST_COMBINE[i].expectret, TEST_COMBINE[i].expecturl, TEST_COMBINE[i].todo);
1292 }
1293 }
1294
1295 /* ########################### */
1296
1297 static void test_UrlCreateFromPath(void)
1298 {
1299 size_t i;
1300 char ret_url[INTERNET_MAX_URL_LENGTH];
1301 DWORD len, ret;
1302 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
1303 WCHAR *pathW, *urlW;
1304
1305 if (!pUrlCreateFromPathA) {
1306 win_skip("UrlCreateFromPathA not found\n");
1307 return;
1308 }
1309
1310 for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
1311 len = INTERNET_MAX_URL_LENGTH;
1312 ret = pUrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
1313 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
1314 ok(!lstrcmpiA(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
1315 ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);
1316
1317 if (pUrlCreateFromPathW) {
1318 len = INTERNET_MAX_URL_LENGTH;
1319 pathW = GetWideString(TEST_URLFROMPATH[i].path);
1320 urlW = GetWideString(TEST_URLFROMPATH[i].url);
1321 ret = pUrlCreateFromPathW(pathW, ret_urlW, &len, 0);
1322 WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
1323 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
1324 ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
1325 ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n",
1326 ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
1327 ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
1328 FreeWideString(urlW);
1329 FreeWideString(pathW);
1330 }
1331 }
1332 }
1333
1334 /* ########################### */
1335
1336 static void test_UrlIs_null(DWORD flag)
1337 {
1338 BOOL ret;
1339 ret = pUrlIsA(NULL, flag);
1340 ok(ret == FALSE, "pUrlIsA(NULL, %d) failed\n", flag);
1341 ret = pUrlIsW(NULL, flag);
1342 ok(ret == FALSE, "pUrlIsW(NULL, %d) failed\n", flag);
1343 }
1344
1345 static void test_UrlIs(void)
1346 {
1347 BOOL ret;
1348 size_t i;
1349 WCHAR wurl[80];
1350
1351 if (!pUrlIsA) {
1352 win_skip("UrlIsA not found\n");
1353 return;
1354 }
1355
1356 test_UrlIs_null(URLIS_APPLIABLE);
1357 test_UrlIs_null(URLIS_DIRECTORY);
1358 test_UrlIs_null(URLIS_FILEURL);
1359 test_UrlIs_null(URLIS_HASQUERY);
1360 test_UrlIs_null(URLIS_NOHISTORY);
1361 test_UrlIs_null(URLIS_OPAQUE);
1362 test_UrlIs_null(URLIS_URL);
1363
1364 for(i = 0; i < sizeof(TEST_PATH_IS_URL) / sizeof(TEST_PATH_IS_URL[0]); i++) {
1365 MultiByteToWideChar(CP_ACP, 0, TEST_PATH_IS_URL[i].path, -1, wurl, sizeof(wurl)/sizeof(*wurl));
1366
1367 ret = pUrlIsA( TEST_PATH_IS_URL[i].path, URLIS_URL );
1368 ok( ret == TEST_PATH_IS_URL[i].expect,
1369 "returned %d from path %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
1370 TEST_PATH_IS_URL[i].expect );
1371
1372 if (pUrlIsW) {
1373 ret = pUrlIsW( wurl, URLIS_URL );
1374 ok( ret == TEST_PATH_IS_URL[i].expect,
1375 "returned %d from path (UrlIsW) %s, expected %d\n", ret,
1376 TEST_PATH_IS_URL[i].path, TEST_PATH_IS_URL[i].expect );
1377 }
1378 }
1379 for(i = 0; i < sizeof(TEST_URLIS_ATTRIBS) / sizeof(TEST_URLIS_ATTRIBS[0]); i++) {
1380 MultiByteToWideChar(CP_ACP, 0, TEST_URLIS_ATTRIBS[i].url, -1, wurl, sizeof(wurl)/sizeof(*wurl));
1381
1382 ret = pUrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_OPAQUE);
1383 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
1384 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1385 TEST_URLIS_ATTRIBS[i].expectOpaque );
1386 ret = pUrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_FILEURL);
1387 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1388 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1389 TEST_URLIS_ATTRIBS[i].expectFile );
1390
1391 if (pUrlIsW) {
1392 ret = pUrlIsW( wurl, URLIS_OPAQUE);
1393 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
1394 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n",
1395 ret, TEST_URLIS_ATTRIBS[i].url, TEST_URLIS_ATTRIBS[i].expectOpaque );
1396 ret = pUrlIsW( wurl, URLIS_FILEURL);
1397 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1398 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n",
1399 ret, TEST_URLIS_ATTRIBS[i].url, TEST_URLIS_ATTRIBS[i].expectFile );
1400 }
1401 }
1402 }
1403
1404 /* ########################### */
1405
1406 static void test_UrlUnescape(void)
1407 {
1408 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1409 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
1410 WCHAR *urlW, *expected_urlW;
1411 DWORD dwEscaped;
1412 size_t i;
1413 static char inplace[] = "file:///C:/Program%20Files";
1414 static char another_inplace[] = "file:///C:/Program%20Files";
1415 static const char expected[] = "file:///C:/Program Files";
1416 static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
1417 static WCHAR another_inplaceW[] ={'f','i','l','e',':','/','/','/',
1418 'C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
1419 HRESULT res;
1420
1421 if (!pUrlUnescapeA) {
1422 win_skip("UrlUnescapeA not found\n");
1423 return;
1424 }
1425 for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
1426 dwEscaped=INTERNET_MAX_URL_LENGTH;
1427 res = pUrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, &dwEscaped, 0);
1428 ok(res == S_OK,
1429 "UrlUnescapeA returned 0x%x (expected S_OK) for \"%s\"\n",
1430 res, TEST_URL_UNESCAPE[i].url);
1431 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);
1432
1433 ZeroMemory(szReturnUrl, sizeof(szReturnUrl));
1434 /* if we set the buffer pointer to NULL here, UrlUnescape fails and the string is not converted */
1435 res = pUrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, NULL, 0);
1436 ok(res == E_INVALIDARG,
1437 "UrlUnescapeA returned 0x%x (expected E_INVALIDARG) for \"%s\"\n",
1438 res, TEST_URL_UNESCAPE[i].url);
1439 ok(strcmp(szReturnUrl,"")==0, "Expected empty string\n");
1440
1441 if (pUrlUnescapeW) {
1442 dwEscaped = INTERNET_MAX_URL_LENGTH;
1443 urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
1444 expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
1445 res = pUrlUnescapeW(urlW, ret_urlW, &dwEscaped, 0);
1446 ok(res == S_OK,
1447 "UrlUnescapeW returned 0x%x (expected S_OK) for \"%s\"\n",
1448 res, TEST_URL_UNESCAPE[i].url);
1449
1450 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
1451 ok(lstrcmpW(ret_urlW, expected_urlW)==0,
1452 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n",
1453 TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url, 0L);
1454 FreeWideString(urlW);
1455 FreeWideString(expected_urlW);
1456 }
1457 }
1458
1459 dwEscaped = sizeof(inplace);
1460 res = pUrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE);
1461 ok(res == S_OK, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res);
1462 ok(!strcmp(inplace, expected), "got %s expected %s\n", inplace, expected);
1463 ok(dwEscaped == 27, "got %d expected 27\n", dwEscaped);
1464
1465 /* if we set the buffer pointer to NULL, the string apparently still gets converted (Google Lively does this) */
1466 res = pUrlUnescapeA(another_inplace, NULL, NULL, URL_UNESCAPE_INPLACE);
1467 ok(res == S_OK, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res);
1468 ok(!strcmp(another_inplace, expected), "got %s expected %s\n", another_inplace, expected);
1469
1470 if (pUrlUnescapeW) {
1471 dwEscaped = sizeof(inplaceW);
1472 res = pUrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE);
1473 ok(res == S_OK, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res);
1474 ok(dwEscaped == 50, "got %d expected 50\n", dwEscaped);
1475
1476 /* if we set the buffer pointer to NULL, the string apparently still gets converted (Google Lively does this) */
1477 res = pUrlUnescapeW(another_inplaceW, NULL, NULL, URL_UNESCAPE_INPLACE);
1478 ok(res == S_OK, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res);
1479
1480 ok(lstrlenW(another_inplaceW) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW));
1481 }
1482 }
1483
1484 static const struct parse_url_test_t {
1485 const char *url;
1486 HRESULT hres;
1487 UINT protocol_len;
1488 UINT scheme;
1489 } parse_url_tests[] = {
1490 {"http://www.winehq.org/",S_OK,4,URL_SCHEME_HTTP},
1491 {"https://www.winehq.org/",S_OK,5,URL_SCHEME_HTTPS},
1492 {"ftp://www.winehq.org/",S_OK,3,URL_SCHEME_FTP},
1493 {"test.txt?test=c:/dir",URL_E_INVALID_SYNTAX},
1494 {"test.txt",URL_E_INVALID_SYNTAX},
1495 {"xxx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1496 {"1xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1497 {"-xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1498 {"xx0://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1499 {"x://www.winehq.org/",URL_E_INVALID_SYNTAX},
1500 {"xx$://www.winehq.org/",URL_E_INVALID_SYNTAX},
1501 {"htt?p://www.winehq.org/",URL_E_INVALID_SYNTAX},
1502 {"ab-://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1503 {" http://www.winehq.org/",URL_E_INVALID_SYNTAX},
1504 {"HTTP://www.winehq.org/",S_OK,4,URL_SCHEME_HTTP},
1505 };
1506
1507 static void test_ParseURL(void)
1508 {
1509 const struct parse_url_test_t *test;
1510 WCHAR url[INTERNET_MAX_URL_LENGTH];
1511 PARSEDURLA parseda;
1512 PARSEDURLW parsedw;
1513 HRESULT hres;
1514
1515 for(test = parse_url_tests; test < parse_url_tests + sizeof(parse_url_tests)/sizeof(*parse_url_tests); test++) {
1516 memset(&parseda, 0xd0, sizeof(parseda));
1517 parseda.cbSize = sizeof(parseda);
1518 hres = pParseURLA(test->url, &parseda);
1519 ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1520 if(hres == S_OK) {
1521 ok(parseda.pszProtocol == test->url, "parseda.pszProtocol = %s, expected %s\n",
1522 parseda.pszProtocol, test->url);
1523 ok(parseda.cchProtocol == test->protocol_len, "parseda.cchProtocol = %d, expected %d\n",
1524 parseda.cchProtocol, test->protocol_len);
1525 ok(parseda.pszSuffix == test->url+test->protocol_len+1, "parseda.pszSuffix = %s, expected %s\n",
1526 parseda.pszSuffix, test->url+test->protocol_len+1);
1527 ok(parseda.cchSuffix == strlen(test->url+test->protocol_len+1),
1528 "parseda.pszSuffix = %d, expected %d\n",
1529 parseda.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1530 ok(parseda.nScheme == test->scheme, "parseda.nScheme = %d, expected %d\n",
1531 parseda.nScheme, test->scheme);
1532 }else {
1533 ok(!parseda.pszProtocol, "parseda.pszProtocol = %p\n", parseda.pszProtocol);
1534 ok(parseda.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parseda.nScheme);
1535 }
1536
1537 MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, sizeof(url)/sizeof(WCHAR));
1538
1539 memset(&parsedw, 0xd0, sizeof(parsedw));
1540 parsedw.cbSize = sizeof(parsedw);
1541 hres = pParseURLW(url, &parsedw);
1542 ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1543 if(hres == S_OK) {
1544 ok(parsedw.pszProtocol == url, "parsedw.pszProtocol = %s, expected %s\n",
1545 wine_dbgstr_w(parsedw.pszProtocol), wine_dbgstr_w(url));
1546 ok(parsedw.cchProtocol == test->protocol_len, "parsedw.cchProtocol = %d, expected %d\n",
1547 parsedw.cchProtocol, test->protocol_len);
1548 ok(parsedw.pszSuffix == url+test->protocol_len+1, "parsedw.pszSuffix = %s, expected %s\n",
1549 wine_dbgstr_w(parsedw.pszSuffix), wine_dbgstr_w(url+test->protocol_len+1));
1550 ok(parsedw.cchSuffix == strlen(test->url+test->protocol_len+1),
1551 "parsedw.pszSuffix = %d, expected %d\n",
1552 parsedw.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1553 ok(parsedw.nScheme == test->scheme, "parsedw.nScheme = %d, expected %d\n",
1554 parsedw.nScheme, test->scheme);
1555 }else {
1556 ok(!parsedw.pszProtocol, "parsedw.pszProtocol = %p\n", parseda.pszProtocol);
1557 ok(parsedw.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parsedw.nScheme);
1558 }
1559 }
1560 }
1561
1562 static void test_HashData(void)
1563 {
1564 HRESULT res;
1565 BYTE input[16] = {0x51, 0x33, 0x4F, 0xA7, 0x45, 0x15, 0xF0, 0x52, 0x90,
1566 0x2B, 0xE7, 0xF5, 0xFD, 0xE1, 0xA6, 0xA7};
1567 BYTE output[32];
1568 static const BYTE expected[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1569 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1570 0xE3, 0x2D};
1571 static const BYTE expected2[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1572 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1573 0xE3, 0x2D, 0x47, 0xFC, 0x80, 0xB8, 0xD0,
1574 0x49, 0xE6, 0x13, 0x2A, 0x30, 0x51, 0x8D,
1575 0xF9, 0x4B, 0x07, 0xA6};
1576 static const BYTE expected3[] = {0x2B, 0xDC, 0x9A, 0x1B, 0xF0, 0x5A, 0xF9,
1577 0xC6, 0xBE, 0x94, 0x6D, 0xF3, 0x33, 0xC1,
1578 0x36, 0x07};
1579 int i;
1580
1581 /* Test hashing with identically sized input/output buffers. */
1582 res = pHashData(input, 16, output, 16);
1583 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1584 if(res == S_OK)
1585 ok(!memcmp(output, expected, sizeof(expected)),
1586 "Output buffer did not match expected contents\n");
1587
1588 /* Test hashing with larger output buffer. */
1589 res = pHashData(input, 16, output, 32);
1590 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1591 if(res == S_OK)
1592 ok(!memcmp(output, expected2, sizeof(expected2)),
1593 "Output buffer did not match expected contents\n");
1594
1595 /* Test hashing with smaller input buffer. */
1596 res = pHashData(input, 8, output, 16);
1597 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1598 if(res == S_OK)
1599 ok(!memcmp(output, expected3, sizeof(expected3)),
1600 "Output buffer did not match expected contents\n");
1601
1602 /* Test passing NULL pointers for input/output parameters. */
1603 res = pHashData(NULL, 0, NULL, 0);
1604 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1605 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1606
1607 res = pHashData(input, 0, NULL, 0);
1608 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1609 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1610
1611 res = pHashData(NULL, 0, output, 0);
1612 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1613 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1614
1615 /* Test passing valid pointers with sizes of zero. */
1616 for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1617 input[i] = 0x00;
1618
1619 for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1620 output[i] = 0xFF;
1621
1622 res = pHashData(input, 0, output, 0);
1623 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1624
1625 /* The buffers should be unchanged. */
1626 for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1627 {
1628 ok(input[i] == 0x00, "Expected the input buffer to be unchanged\n");
1629 if(input[i] != 0x00) break;
1630 }
1631
1632 for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1633 {
1634 ok(output[i] == 0xFF, "Expected the output buffer to be unchanged\n");
1635 if(output[i] != 0xFF) break;
1636 }
1637
1638 /* Input/output parameters are not validated. */
1639 res = pHashData((BYTE *)0xdeadbeef, 0, (BYTE *)0xdeadbeef, 0);
1640 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1641
1642 if (0)
1643 {
1644 res = pHashData((BYTE *)0xdeadbeef, 1, (BYTE *)0xdeadbeef, 1);
1645 trace("HashData returned 0x%08x\n", res);
1646 }
1647 }
1648
1649 /* ########################### */
1650
1651 START_TEST(url)
1652 {
1653 char *pFunc;
1654
1655 hShlwapi = GetModuleHandleA("shlwapi.dll");
1656
1657 /* SHCreateStreamOnFileEx was introduced in shlwapi v6.0 */
1658 pFunc = (void*)GetProcAddress(hShlwapi, "SHCreateStreamOnFileEx");
1659 if(!pFunc){
1660 win_skip("Too old shlwapi version\n");
1661 return;
1662 }
1663
1664 pUrlUnescapeA = (void *) GetProcAddress(hShlwapi, "UrlUnescapeA");
1665 pUrlUnescapeW = (void *) GetProcAddress(hShlwapi, "UrlUnescapeW");
1666 pUrlIsA = (void *) GetProcAddress(hShlwapi, "UrlIsA");
1667 pUrlIsW = (void *) GetProcAddress(hShlwapi, "UrlIsW");
1668 pUrlHashA = (void *) GetProcAddress(hShlwapi, "UrlHashA");
1669 pUrlHashW = (void *) GetProcAddress(hShlwapi, "UrlHashW");
1670 pUrlGetPartA = (void *) GetProcAddress(hShlwapi, "UrlGetPartA");
1671 pUrlGetPartW = (void *) GetProcAddress(hShlwapi, "UrlGetPartW");
1672 pUrlEscapeA = (void *) GetProcAddress(hShlwapi, "UrlEscapeA");
1673 pUrlEscapeW = (void *) GetProcAddress(hShlwapi, "UrlEscapeW");
1674 pUrlCreateFromPathA = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathA");
1675 pUrlCreateFromPathW = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathW");
1676 pUrlCombineA = (void *) GetProcAddress(hShlwapi, "UrlCombineA");
1677 pUrlCombineW = (void *) GetProcAddress(hShlwapi, "UrlCombineW");
1678 pUrlCanonicalizeA = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeA");
1679 pUrlCanonicalizeW = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeW");
1680 pUrlApplySchemeA = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeA");
1681 pUrlApplySchemeW = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeW");
1682 pParseURLA = (void*)GetProcAddress(hShlwapi, (LPCSTR)1);
1683 pParseURLW = (void*)GetProcAddress(hShlwapi, (LPCSTR)2);
1684 pHashData = (void*)GetProcAddress(hShlwapi, "HashData");
1685
1686 test_UrlApplyScheme();
1687 test_UrlHash();
1688 test_UrlGetPart();
1689 test_UrlCanonicalizeA();
1690 test_UrlCanonicalizeW();
1691 test_UrlEscapeA();
1692 test_UrlEscapeW();
1693 test_UrlCombine();
1694 test_UrlCreateFromPath();
1695 test_UrlIs();
1696 test_UrlUnescape();
1697 test_ParseURL();
1698 test_HashData();
1699 }