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