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