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