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