wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / shlwapi / tests / url.c
blobadaba9f0a3168c07136667548a1777568a08de86
1 /* Unit test suite for Path functions
3 * Copyright 2002 Matthew Mastracci
4 * Copyright 2007-2010 Detlef Riekenberg
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.
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.
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "wine/test.h"
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "shlwapi.h"
29 #include "wininet.h"
30 #include "intshcut.h"
32 /* ################ */
33 static HMODULE hShlwapi;
34 static HRESULT (WINAPI *pUrlUnescapeA)(LPSTR,LPSTR,LPDWORD,DWORD);
35 static HRESULT (WINAPI *pUrlUnescapeW)(LPWSTR,LPWSTR,LPDWORD,DWORD);
36 static BOOL (WINAPI *pUrlIsA)(LPCSTR,URLIS);
37 static BOOL (WINAPI *pUrlIsW)(LPCWSTR,URLIS);
38 static HRESULT (WINAPI *pUrlHashA)(LPCSTR,LPBYTE,DWORD);
39 static HRESULT (WINAPI *pUrlHashW)(LPCWSTR,LPBYTE,DWORD);
40 static HRESULT (WINAPI *pUrlGetPartA)(LPCSTR,LPSTR,LPDWORD,DWORD,DWORD);
41 static HRESULT (WINAPI *pUrlGetPartW)(LPCWSTR,LPWSTR,LPDWORD,DWORD,DWORD);
42 static HRESULT (WINAPI *pUrlEscapeA)(LPCSTR,LPSTR,LPDWORD,DWORD);
43 static HRESULT (WINAPI *pUrlEscapeW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
44 static HRESULT (WINAPI *pUrlCreateFromPathA)(LPCSTR,LPSTR,LPDWORD,DWORD);
45 static HRESULT (WINAPI *pUrlCreateFromPathW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
46 static HRESULT (WINAPI *pUrlCombineA)(LPCSTR,LPCSTR,LPSTR,LPDWORD,DWORD);
47 static HRESULT (WINAPI *pUrlCombineW)(LPCWSTR,LPCWSTR,LPWSTR,LPDWORD,DWORD);
48 static HRESULT (WINAPI *pUrlCanonicalizeA)(LPCSTR, LPSTR, LPDWORD, DWORD);
49 static HRESULT (WINAPI *pUrlCanonicalizeW)(LPCWSTR, LPWSTR, LPDWORD, DWORD);
50 static HRESULT (WINAPI *pUrlApplySchemeA)(LPCSTR,LPSTR,LPDWORD,DWORD);
51 static HRESULT (WINAPI *pUrlApplySchemeW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
52 static HRESULT (WINAPI *pParseURLA)(LPCSTR,PARSEDURLA*);
53 static HRESULT (WINAPI *pParseURLW)(LPCWSTR,PARSEDURLW*);
54 static HRESULT (WINAPI *pHashData)(LPBYTE, DWORD, LPBYTE, DWORD);
56 static const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
57 static const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
58 static const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
59 static const WCHAR winehqW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
60 static const CHAR winehqA[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
62 /* ################ */
64 static const CHAR untouchedA[] = "untouched";
66 #define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
68 typedef struct _TEST_URL_APPLY {
69 const char * url;
70 DWORD flags;
71 HRESULT res;
72 DWORD newlen;
73 const char * newurl;
74 } TEST_URL_APPLY;
76 static const TEST_URL_APPLY TEST_APPLY[] = {
77 {"www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
78 {"www.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 21, "http://www.winehq.org"},
79 {"www.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
80 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 20, "ftp://ftp.winehq.org"},
81 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 20, "ftp://ftp.winehq.org"},
82 {"ftp.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://ftp.winehq.org"},
83 {"winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
84 {"winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
85 {"winehq.org", URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
86 {"", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 7, "http://"},
87 {"", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
88 {"", URL_APPLY_DEFAULT, S_OK, 7, "http://"}
91 /* ################ */
93 typedef struct _TEST_URL_CANONICALIZE {
94 const char *url;
95 DWORD flags;
96 HRESULT expectret;
97 const char *expecturl;
98 BOOL todo;
99 } TEST_URL_CANONICALIZE;
101 static const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
102 {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/", TRUE},
103 {"http://www.winehq.org/..", 0, S_OK, "http://www.winehq.org/..", FALSE},
104 {"http://www.winehq.org/tests/tests2/../../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
105 {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
106 {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
107 {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
108 {"http://www.winehq.org/tests\r", 0, S_OK, "http://www.winehq.org/tests", FALSE},
109 {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests", FALSE},
110 {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/", FALSE},
111 {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
112 {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
113 {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
114 {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
115 {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
116 {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
117 {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
118 {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
119 {"http://www.winehq.org/tests\\../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
120 {"http://www.winehq.org/tests/..\\#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
121 {"http://www.winehq.org\\tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
122 {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example", FALSE},
123 {"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},
124 {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE , S_OK, "http://www.winehq.org/tests/foo bar", FALSE},
125 {"file:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
126 {"file:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
127 {"file:///c:/tests/foo%20bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
128 {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
129 {"file://localhost/c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
130 {"file://localhost\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
131 {"file://localhost\\\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
132 {"file://localhost\\c:\\tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
133 {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
134 {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
135 {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
136 {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar", FALSE},
137 {"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar", FALSE},
138 {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar", FALSE},
139 {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about", FALSE},
140 {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about", FALSE},
141 {"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
142 {"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
143 {"c:dir\\file", 0, S_OK, "file:///c:dir/file", FALSE},
144 {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
145 {"c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
146 {"res://file", 0, S_OK, "res://file/", FALSE},
147 {"res://file", URL_FILE_USE_PATHURL, S_OK, "res://file/", FALSE},
148 {"res:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests/foo bar", FALSE},
149 {"res:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests\\foo bar", FALSE},
150 {"res:///c:/tests/foo%20bar", 0, S_OK, "res:///c:/tests/foo%20bar", FALSE},
151 {"res:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c:/tests/foo%20bar", FALSE},
152 {"res://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
153 {"res://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
154 {"res://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
155 {"res:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c://tests/foo%20bar", FALSE},
156 {"res:///c:\\tests\\foo bar", 0, S_OK, "res:///c:\\tests\\foo bar", FALSE},
157 {"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "res:///c:\\tests\\foo bar", FALSE},
158 {"res://c:\\tests\\foo bar/res", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests\\foo bar/res", FALSE},
159 {"res://c:\\tests/res\\foo%20bar/strange\\sth", 0, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
160 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
161 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_UNESCAPE, S_OK, "res://c:\\tests/res\\foo bar/strange\\sth", FALSE},
162 {"A", 0, S_OK, "A", FALSE},
163 {"../A", 0, S_OK, "../A", FALSE},
164 {"A/../B", 0, S_OK, "B", TRUE},
165 {"/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*/,
166 {"http:www.winehq.org/dir/../index.html", 0, S_OK, "http:www.winehq.org/index.html"},
167 {"http://localhost/test.html", URL_FILE_USE_PATHURL, S_OK, "http://localhost/test.html"},
168 {"http://localhost/te%20st.html", URL_FILE_USE_PATHURL, S_OK, "http://localhost/te%20st.html"},
169 {"http://www.winehq.org/%E6%A1%9C.html", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/%E6%A1%9C.html"},
170 {"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"},
171 {"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"},
172 {"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"},
173 {"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"},
174 {"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"},
175 {"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"},
178 /* ################ */
180 typedef struct _TEST_URL_ESCAPE {
181 const char *url;
182 DWORD flags;
183 DWORD expectescaped;
184 HRESULT expectret;
185 const char *expecturl;
186 } TEST_URL_ESCAPE;
188 static const TEST_URL_ESCAPE TEST_ESCAPE[] = {
189 {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"},
190 {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"},
191 {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"},
192 {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"},
193 {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"},
194 {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"},
195 {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
197 {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
198 {"file://///foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
199 {"file:////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
200 {"file:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
201 {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
202 {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
203 {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
204 {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
205 {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
206 {"file:foo/bar\\baz", 0, 0, S_OK, "file:foo/bar/baz"},
207 {"file:\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
208 {"file:\\\\foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
209 {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
210 {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
211 {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"},
212 {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"},
213 {"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"},
214 {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"},
215 {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"},
217 {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"},
218 {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"},
219 {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"},
220 {"/foo/bar\\ba?z\\", 0, 0, S_OK, "/foo/bar%5Cba?z\\"},
221 {"/foo/bar\\ba#z\\", 0, 0, S_OK, "/foo/bar%5Cba#z\\"},
222 {"/foo/%5C", 0, 0, S_OK, "/foo/%5C"},
223 {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"},
225 {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"},
226 {"http://///foo/bar\\baz", 0, 0, S_OK, "http://///foo/bar/baz"},
227 {"http:////foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
228 {"http:///foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
229 {"http://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"},
230 {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
231 {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
232 {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"},
233 {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"},
234 {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
235 {"http:\\\\foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
236 {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
237 {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
238 {"http:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"},
239 {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"},
240 {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"},
242 {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"},
243 {"https:/foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
244 {"https:\\foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
246 {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"},
247 {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"},
248 {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"},
249 {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://foo/bar%5Cbaz"},
250 {"foo:/foo/bar\\baz", 0, 0, S_OK, "foo:/foo/bar%5Cbaz"},
251 {"foo:foo/bar\\baz", 0, 0, S_OK, "foo:foo%2Fbar%5Cbaz"},
252 {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"},
253 {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"},
254 {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"},
256 {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
257 {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
258 {"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"},
260 {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
261 {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"},
262 {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"},
263 {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"},
264 {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"},
265 {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"},
266 {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"}
269 /* ################ */
271 typedef struct _TEST_URL_COMBINE {
272 const char *url1;
273 const char *url2;
274 DWORD flags;
275 HRESULT expectret;
276 const char *expecturl;
277 } TEST_URL_COMBINE;
279 static const TEST_URL_COMBINE TEST_COMBINE[] = {
280 {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
281 {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
282 /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
283 {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"},
284 {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"},
285 {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"},
286 {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"},
287 {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"},
288 {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"},
289 {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"},
290 {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"},
291 {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."},
292 {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"},
293 {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"},
294 {"file:///C:\\dir\\file.txt#hash\\hash", "test.txt", 0, S_OK, "file:///C:/dir/file.txt#hash/test.txt"},
295 {"file:///C:\\dir\\file.html#hash\\hash", "test.html", 0, S_OK, "file:///C:/dir/test.html"},
296 {"file:///C:\\dir\\file.htm#hash\\hash", "test.htm", 0, S_OK, "file:///C:/dir/test.htm"},
297 {"file:///C:\\dir\\file.hTmL#hash\\hash", "test.hTmL", 0, S_OK, "file:///C:/dir/test.hTmL"},
298 {"file:///C:\\dir.html\\file.txt#hash\\hash", "test.txt", 0, S_OK, "file:///C:/dir.html/file.txt#hash/test.txt"},
299 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK, "file:///C:/Test/test.txt"},
300 {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"},
301 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"},
302 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"},
303 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"},
304 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
305 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
306 {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"},
307 {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"},
308 {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"},
309 {"foo:/today/", "foo:calendar", 0, S_OK, "foo:/today/calendar"},
310 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
311 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
312 /* UrlCombine case 2 tests. Schemes do not match */
313 {"outbind://xxxxxxxxx","http://wine1/dir",0, S_OK,"http://wine1/dir"},
314 {"xxxx://xxxxxxxxx","http://wine2/dir",0, S_OK,"http://wine2/dir"},
315 {"ftp://xxxxxxxxx/","http://wine3/dir",0, S_OK,"http://wine3/dir"},
316 {"outbind://xxxxxxxxx","http://wine4/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine4/dir"},
317 {"xxx://xxxxxxxxx","http://wine5/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine5/dir"},
318 {"ftp://xxxxxxxxx/","http://wine6/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine6/dir"},
319 {"http://xxxxxxxxx","outbind://wine7/dir",0, S_OK,"outbind://wine7/dir"},
320 {"xxx://xxxxxxxxx","ftp://wine8/dir",0, S_OK,"ftp://wine8/dir"},
321 {"ftp://xxxxxxxxx/","xxx://wine9/dir",0, S_OK,"xxx://wine9/dir"},
322 {"http://xxxxxxxxx","outbind://wine10/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind://wine10/dir"},
323 {"xxx://xxxxxxxxx","ftp://wine11/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp://wine11/dir"},
324 {"ftp://xxxxxxxxx/","xxx://wine12/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx://wine12/dir"},
325 {"http://xxxxxxxxx","outbind:wine13/dir",0, S_OK,"outbind:wine13/dir"},
326 {"xxx://xxxxxxxxx","ftp:wine14/dir",0, S_OK,"ftp:wine14/dir"},
327 {"ftp://xxxxxxxxx/","xxx:wine15/dir",0, S_OK,"xxx:wine15/dir"},
328 {"outbind://xxxxxxxxx/","http:wine16/dir",0, S_OK,"http:wine16/dir"},
329 {"http://xxxxxxxxx","outbind:wine17/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind:wine17/dir"},
330 {"xxx://xxxxxxxxx","ftp:wine18/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp:wine18/dir"},
331 {"ftp://xxxxxxxxx/","xxx:wine19/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx:wine19/dir"},
332 {"outbind://xxxxxxxxx/","http:wine20/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http:wine20/dir"},
333 {"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"}
336 /* ################ */
338 static const struct {
339 const char *path;
340 const char *url;
341 DWORD ret;
342 } TEST_URLFROMPATH [] = {
343 {"foo", "file:foo", S_OK},
344 {"foo\\bar", "file:foo/bar", S_OK},
345 {"\\foo\\bar", "file:///foo/bar", S_OK},
346 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK},
347 {"c:foo\\bar", "file:///c:foo/bar", S_OK},
348 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK},
349 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK},
350 #if 0
351 /* The following test fails on native shlwapi as distributed with Win95/98.
352 * Wine matches the behaviour of later versions.
354 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE}
355 #endif
358 /* ################ */
360 static struct {
361 char url[30];
362 const char *expect;
363 } TEST_URL_UNESCAPE[] = {
364 {"file://foo/bar", "file://foo/bar"},
365 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
366 {"file://%24%25foobar", "file://$%foobar"}
369 /* ################ */
371 static const struct {
372 const char *path;
373 BOOL expect;
374 } TEST_PATH_IS_URL[] = {
375 {"http://foo/bar", TRUE},
376 {"c:\\foo\\bar", FALSE},
377 {"foo://foo/bar", TRUE},
378 {"foo\\bar", FALSE},
379 {"foo.bar", FALSE},
380 {"bogusscheme:", TRUE},
381 {"http:partial", TRUE}
384 /* ################ */
386 static const struct {
387 const char *url;
388 BOOL expectOpaque;
389 BOOL expectFile;
390 } TEST_URLIS_ATTRIBS[] = {
391 { "ftp:", FALSE, FALSE },
392 { "http:", FALSE, FALSE },
393 { "gopher:", FALSE, FALSE },
394 { "mailto:", TRUE, FALSE },
395 { "news:", FALSE, FALSE },
396 { "nntp:", FALSE, FALSE },
397 { "telnet:", FALSE, FALSE },
398 { "wais:", FALSE, FALSE },
399 { "file:", FALSE, TRUE },
400 { "mk:", FALSE, FALSE },
401 { "https:", FALSE, FALSE },
402 { "shell:", TRUE, FALSE },
403 { "https:", FALSE, FALSE },
404 { "snews:", FALSE, FALSE },
405 { "local:", FALSE, FALSE },
406 { "javascript:", TRUE, FALSE },
407 { "vbscript:", TRUE, FALSE },
408 { "about:", TRUE, FALSE },
409 { "res:", FALSE, FALSE },
410 { "bogusscheme:", FALSE, FALSE },
411 { "file:\\\\e:\\b\\c", FALSE, TRUE },
412 { "file://e:/b/c", FALSE, TRUE },
413 { "http:partial", FALSE, FALSE },
414 { "mailto://www.winehq.org/test.html", TRUE, FALSE },
415 { "file:partial", FALSE, TRUE }
418 /* ########################### */
420 static LPWSTR GetWideString(const char* szString)
422 LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
424 MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
426 return wszString;
430 static void FreeWideString(LPWSTR wszString)
432 HeapFree(GetProcessHeap(), 0, wszString);
435 /* ########################### */
437 static void test_UrlApplyScheme(void)
439 CHAR newurl[TEST_APPLY_MAX_LENGTH];
440 WCHAR urlW[TEST_APPLY_MAX_LENGTH];
441 WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
442 HRESULT res;
443 DWORD len;
444 DWORD i;
446 if (!pUrlApplySchemeA) {
447 win_skip("UrlApplySchemeA not found\n");
448 return;
451 for(i = 0; i < sizeof(TEST_APPLY)/sizeof(TEST_APPLY[0]); i++) {
452 len = TEST_APPLY_MAX_LENGTH;
453 lstrcpyA(newurl, untouchedA);
454 res = pUrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
455 ok( res == TEST_APPLY[i].res,
456 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
458 ok( len == TEST_APPLY[i].newlen,
459 "#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
461 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
462 "#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
464 /* returned length is in character */
465 len = TEST_APPLY_MAX_LENGTH;
466 lstrcpyA(newurl, untouchedA);
467 MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
468 MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
470 res = pUrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
471 WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
472 ok( res == TEST_APPLY[i].res,
473 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
475 ok( len == TEST_APPLY[i].newlen,
476 "#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
478 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
479 "#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
483 /* buffer too small */
484 lstrcpyA(newurl, untouchedA);
485 len = lstrlenA(TEST_APPLY[0].newurl);
486 res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, &len, TEST_APPLY[0].flags);
487 ok(res == E_POINTER, "got HRESULT 0x%x (expected E_POINTER)\n", res);
488 /* The returned length include the space for the terminating 0 */
489 i = lstrlenA(TEST_APPLY[0].newurl)+1;
490 ok(len == i, "got len %d (expected %d)\n", len, i);
491 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
493 /* NULL as parameter. The length and the buffer are not modified */
494 lstrcpyA(newurl, untouchedA);
495 len = TEST_APPLY_MAX_LENGTH;
496 res = pUrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
497 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
498 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
499 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
501 len = TEST_APPLY_MAX_LENGTH;
502 res = pUrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
503 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
504 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
506 lstrcpyA(newurl, untouchedA);
507 res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
508 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
509 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
513 /* ########################### */
515 static void hash_url(const char* szUrl)
517 LPCSTR szTestUrl = szUrl;
518 LPWSTR wszTestUrl = GetWideString(szTestUrl);
519 HRESULT res;
521 DWORD cbSize = sizeof(DWORD);
522 DWORD dwHash1, dwHash2;
523 res = pUrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize);
524 ok(res == S_OK, "UrlHashA returned 0x%x (expected S_OK) for %s\n", res, szUrl);
525 if (pUrlHashW) {
526 res = pUrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize);
527 ok(res == S_OK, "UrlHashW returned 0x%x (expected S_OK) for %s\n", res, szUrl);
528 ok(dwHash1 == dwHash2,
529 "Hashes didn't match (A: 0x%x, W: 0x%x) for %s\n", dwHash1, dwHash2, szUrl);
531 FreeWideString(wszTestUrl);
535 static void test_UrlHash(void)
537 if (!pUrlHashA) {
538 win_skip("UrlHashA not found\n");
539 return;
542 hash_url(TEST_URL_1);
543 hash_url(TEST_URL_2);
544 hash_url(TEST_URL_3);
547 /* ########################### */
549 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
551 CHAR szPart[INTERNET_MAX_URL_LENGTH];
552 WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
553 LPWSTR wszUrl = GetWideString(szUrl);
554 LPWSTR wszConvertedPart;
555 HRESULT res;
556 DWORD dwSize;
558 dwSize = 1;
559 res = pUrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags);
560 ok(res == E_POINTER, "UrlGetPart for \"%s\" gave: 0x%08x\n", szUrl, res);
561 ok(dwSize == strlen(szExpected)+1 ||
562 (*szExpected == '?' && dwSize == strlen(szExpected)),
563 "UrlGetPart for \"%s\" gave size: %u\n", szUrl, dwSize);
565 dwSize = INTERNET_MAX_URL_LENGTH;
566 res = pUrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags);
567 ok(res == S_OK,
568 "UrlGetPartA for \"%s\" part 0x%08x returned 0x%x and \"%s\"\n",
569 szUrl, dwPart, res, szPart);
570 if (pUrlGetPartW) {
571 dwSize = INTERNET_MAX_URL_LENGTH;
572 res = pUrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags);
573 ok(res == S_OK,
574 "UrlGetPartW for \"%s\" part 0x%08x returned 0x%x\n",
575 szUrl, dwPart, res);
577 wszConvertedPart = GetWideString(szPart);
579 ok(lstrcmpW(wszPart,wszConvertedPart)==0,
580 "Strings didn't match between ascii and unicode UrlGetPart!\n");
582 FreeWideString(wszConvertedPart);
584 FreeWideString(wszUrl);
586 /* Note that v6.0 and later don't return '?' with the query */
587 ok(strcmp(szPart,szExpected)==0 ||
588 (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
589 "Expected %s, but got %s\n", szExpected, szPart);
592 /* ########################### */
594 static void test_UrlGetPart(void)
596 const char* file_url = "file://h o s t/c:/windows/file";
597 const char* http_url = "http://user:pass 123@www.wine hq.org";
598 const char* res_url = "res://some.dll/find.dlg";
599 const char* about_url = "about:blank";
601 CHAR szPart[INTERNET_MAX_URL_LENGTH];
602 DWORD dwSize;
603 HRESULT res;
605 if (!pUrlGetPartA) {
606 win_skip("UrlGetPartA not found\n");
607 return;
610 res = pUrlGetPartA(NULL, NULL, NULL, URL_PART_SCHEME, 0);
611 ok(res == E_INVALIDARG, "null params gave: 0x%08x\n", res);
613 res = pUrlGetPartA(NULL, szPart, &dwSize, URL_PART_SCHEME, 0);
614 ok(res == E_INVALIDARG, "null URL gave: 0x%08x\n", res);
616 res = pUrlGetPartA(res_url, NULL, &dwSize, URL_PART_SCHEME, 0);
617 ok(res == E_INVALIDARG, "null szPart gave: 0x%08x\n", res);
619 res = pUrlGetPartA(res_url, szPart, NULL, URL_PART_SCHEME, 0);
620 ok(res == E_INVALIDARG, "null URL gave: 0x%08x\n", res);
622 dwSize = 0;
623 szPart[0]='x'; szPart[1]=0;
624 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
625 ok(res == E_INVALIDARG, "UrlGetPartA(*pcchOut = 0) returned %08X\n", res);
626 ok(szPart[0] == 'x' && szPart[1] == 0, "UrlGetPartA(*pcchOut = 0) modified szPart: \"%s\"\n", szPart);
627 ok(dwSize == 0, "dwSize = %d\n", dwSize);
629 dwSize = sizeof szPart;
630 szPart[0]='x'; szPart[1]=0;
631 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
632 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
633 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
634 ok(dwSize == 0, "dwSize = %d\n", dwSize);
636 dwSize = sizeof szPart;
637 szPart[0]='x'; szPart[1]=0;
638 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0);
639 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
640 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
641 ok(dwSize == 0, "dwSize = %d\n", dwSize);
643 test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
644 test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
645 test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
646 test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
647 test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
648 test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
650 test_url_part(file_url, URL_PART_HOSTNAME, 0, "h o s t");
652 test_url_part(http_url, URL_PART_HOSTNAME, 0, "www.wine hq.org");
653 test_url_part(http_url, URL_PART_PASSWORD, 0, "pass 123");
655 test_url_part(about_url, URL_PART_SCHEME, 0, "about");
657 dwSize = sizeof(szPart);
658 res = pUrlGetPartA(about_url, szPart, &dwSize, URL_PART_HOSTNAME, 0);
659 ok(res==E_FAIL, "returned %08x\n", res);
661 test_url_part(res_url, URL_PART_SCHEME, 0, "res");
662 test_url_part("http://www.winehq.org", URL_PART_HOSTNAME, URL_PARTFLAG_KEEPSCHEME, "http:www.winehq.org");
664 dwSize = sizeof szPart;
665 szPart[0]='x'; szPart[1]=0;
666 res = pUrlGetPartA(res_url, szPart, &dwSize, URL_PART_QUERY, 0);
667 ok(res==S_FALSE, "UrlGetPartA returned %08X\n", res);
668 ok(szPart[0]==0, "UrlGetPartA gave \"%s\" instead of \"\"\n", szPart);
669 ok(dwSize == 0, "dwSize = %d\n", dwSize);
671 dwSize = sizeof(szPart);
672 res = pUrlGetPartA("file://c:\\index.htm", szPart, &dwSize, URL_PART_HOSTNAME, 0);
673 ok(res==S_FALSE, "returned %08x\n", res);
674 ok(dwSize == 0, "dwSize = %d\n", dwSize);
676 dwSize = sizeof(szPart);
677 szPart[0] = 'x'; szPart[1] = '\0';
678 res = pUrlGetPartA("file:some text", szPart, &dwSize, URL_PART_HOSTNAME, 0);
679 ok(res==S_FALSE, "returned %08x\n", res);
680 ok(szPart[0] == '\0', "szPart[0] = %c\n", szPart[0]);
681 ok(dwSize == 0, "dwSize = %d\n", dwSize);
683 dwSize = sizeof(szPart);
684 szPart[0] = 'x'; szPart[1] = '\0';
685 res = pUrlGetPartA("index.htm", szPart, &dwSize, URL_PART_HOSTNAME, 0);
686 ok(res==E_FAIL, "returned %08x\n", res);
689 /* ########################### */
691 static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
693 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
694 DWORD dwEscaped;
695 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
696 WCHAR *urlW, *expected_urlW;
697 dwEscaped=INTERNET_MAX_URL_LENGTH;
699 ok(pUrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn,
700 "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
701 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);
703 if (pUrlEscapeW) {
704 dwEscaped = INTERNET_MAX_URL_LENGTH;
705 urlW = GetWideString(szUrl);
706 expected_urlW = GetWideString(szExpectUrl);
707 ok(pUrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn,
708 "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
709 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
710 ok(lstrcmpW(ret_urlW, expected_urlW)==0,
711 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n",
712 szExpectUrl, szReturnUrl, szUrl, dwFlags);
713 FreeWideString(urlW);
714 FreeWideString(expected_urlW);
718 static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, HRESULT dwExpectReturnAlt, const char *szExpectUrl, BOOL todo)
720 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
721 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
722 LPWSTR wszUrl = GetWideString(szUrl);
723 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
724 LPWSTR wszConvertedUrl;
725 HRESULT ret;
727 DWORD dwSize;
729 dwSize = INTERNET_MAX_URL_LENGTH;
730 ret = pUrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags);
731 ok(ret != dwExpectReturn, "got 0s%x: Unexpected return for NULL buffer, index %d\n", ret, index);
732 ret = pUrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags);
733 ok(ret == dwExpectReturn || ret == dwExpectReturnAlt,
734 "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
735 dwExpectReturn, dwExpectReturnAlt, ret, index);
736 if (todo)
737 todo_wine
738 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
739 else
740 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
742 if (pUrlCanonicalizeW) {
743 dwSize = INTERNET_MAX_URL_LENGTH;
744 ret = pUrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags);
745 ok(ret != dwExpectReturn, "got 0x%x: Unexpected return for NULL buffer, index %d\n", ret, index);
746 ret = pUrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags);
747 ok(ret == dwExpectReturn, "UrlCanonicalizeW failed: expected 0x%08x, got 0x%x, index %d\n",
748 dwExpectReturn, ret, index);
750 wszConvertedUrl = GetWideString(szReturnUrl);
751 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0,
752 "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
753 FreeWideString(wszConvertedUrl);
756 FreeWideString(wszUrl);
757 FreeWideString(wszExpectUrl);
761 static void test_UrlEscape(void)
763 DWORD size = 0;
764 HRESULT ret;
765 unsigned int i;
766 char empty_string[] = "";
768 if (!pUrlEscapeA) {
769 win_skip("UrlEscapeA noz found\n");
770 return;
773 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
774 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
775 ok(size == 0, "got %d, expected %d\n", size, 0);
777 size = 0;
778 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
779 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
780 ok(size == 0, "got %d, expected %d\n", size, 0);
782 size = 1;
783 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
784 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
785 ok(size == 1, "got %d, expected %d\n", size, 1);
787 size = 1;
788 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
789 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
790 ok(size == 1, "got %d, expected %d\n", size, 1);
792 size = 1;
793 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
794 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
795 ok(size == 34, "got %d, expected %d\n", size, 34);
797 for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
798 test_url_escape(TEST_ESCAPE[i].url, TEST_ESCAPE[i].flags,
799 TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].expecturl);
803 /* ########################### */
805 static void test_UrlCanonicalizeA(void)
807 unsigned int i;
808 CHAR szReturnUrl[4*INTERNET_MAX_URL_LENGTH];
809 CHAR longurl[4*INTERNET_MAX_URL_LENGTH];
810 DWORD dwSize;
811 DWORD urllen;
812 HRESULT hr;
814 if (!pUrlCanonicalizeA) {
815 win_skip("UrlCanonicalizeA not found\n");
816 return;
819 urllen = lstrlenA(winehqA);
821 /* buffer has no space for the result */
822 dwSize=urllen-1;
823 memset(szReturnUrl, '#', urllen+4);
824 szReturnUrl[urllen+4] = '\0';
825 SetLastError(0xdeadbeef);
826 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
827 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
828 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
829 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
831 /* buffer has no space for the terminating '\0' */
832 dwSize=urllen;
833 memset(szReturnUrl, '#', urllen+4);
834 szReturnUrl[urllen+4] = '\0';
835 SetLastError(0xdeadbeef);
836 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
837 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
838 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
839 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
841 /* buffer has the required size */
842 dwSize=urllen+1;
843 memset(szReturnUrl, '#', urllen+4);
844 szReturnUrl[urllen+4] = '\0';
845 SetLastError(0xdeadbeef);
846 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
847 ok( (hr == S_OK) && (dwSize == urllen),
848 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
849 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
851 /* buffer is larger as the required size */
852 dwSize=urllen+2;
853 memset(szReturnUrl, '#', urllen+4);
854 szReturnUrl[urllen+4] = '\0';
855 SetLastError(0xdeadbeef);
856 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
857 ok( (hr == S_OK) && (dwSize == urllen),
858 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
859 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
861 /* length is set to 0 */
862 dwSize=0;
863 memset(szReturnUrl, '#', urllen+4);
864 szReturnUrl[urllen+4] = '\0';
865 SetLastError(0xdeadbeef);
866 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
867 ok( (hr == E_INVALIDARG) && (dwSize == 0),
868 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_INVALIDARG' and size %u)\n",
869 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), 0);
871 /* url length > INTERNET_MAX_URL_SIZE */
872 dwSize=sizeof(szReturnUrl);
873 memset(longurl, 'a', sizeof(longurl));
874 memcpy(longurl, winehqA, sizeof(winehqA)-1);
875 longurl[sizeof(longurl)-1] = '\0';
876 hr = pUrlCanonicalizeA(longurl, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
877 ok(hr == S_OK, "hr = %x\n", hr);
879 test_url_canonicalize(-1, "", 0, S_OK, S_FALSE /* Vista/win2k8 */, "", FALSE);
881 /* test url-modification */
882 for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
883 test_url_canonicalize(i, TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
884 TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl,
885 TEST_CANONICALIZE[i].todo);
889 /* ########################### */
891 static void test_UrlCanonicalizeW(void)
893 WCHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
894 DWORD dwSize;
895 DWORD urllen;
896 HRESULT hr;
897 int i;
900 if (!pUrlCanonicalizeW) {
901 win_skip("UrlCanonicalizeW not found\n");
902 return;
904 urllen = lstrlenW(winehqW);
906 /* buffer has no space for the result */
907 dwSize = (urllen-1);
908 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
909 szReturnUrl[urllen+4] = '\0';
910 SetLastError(0xdeadbeef);
911 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
912 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
913 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
914 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
917 /* buffer has no space for the terminating '\0' */
918 dwSize = urllen;
919 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
920 szReturnUrl[urllen+4] = '\0';
921 SetLastError(0xdeadbeef);
922 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
923 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
924 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
925 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
927 /* buffer has the required size */
928 dwSize = urllen +1;
929 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
930 szReturnUrl[urllen+4] = '\0';
931 SetLastError(0xdeadbeef);
932 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
933 ok( (hr == S_OK) && (dwSize == urllen),
934 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
935 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
937 /* buffer is larger as the required size */
938 dwSize = (urllen+2);
939 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
940 szReturnUrl[urllen+4] = '\0';
941 SetLastError(0xdeadbeef);
942 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
943 ok( (hr == S_OK) && (dwSize == urllen),
944 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
945 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
947 /* check that the characters 1..32 are chopped from the end of the string */
948 for (i = 1; i < 65536; i++)
950 WCHAR szUrl[128];
951 BOOL choped;
952 int pos;
954 MultiByteToWideChar(CP_ACP, 0, "http://www.winehq.org/X", -1, szUrl, 128);
955 pos = lstrlenW(szUrl) - 1;
956 szUrl[pos] = i;
957 urllen = INTERNET_MAX_URL_LENGTH;
958 pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
959 choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
960 ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
964 /* ########################### */
966 static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
968 HRESULT hr;
969 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
970 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
971 LPWSTR wszUrl1 = GetWideString(szUrl1);
972 LPWSTR wszUrl2 = GetWideString(szUrl2);
973 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
974 LPWSTR wszConvertedUrl;
976 DWORD dwSize;
977 DWORD dwExpectLen = lstrlen(szExpectUrl);
979 if (!pUrlCombineA) {
980 win_skip("UrlCombineA not found\n");
981 return;
984 hr = pUrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
985 ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
987 dwSize = 0;
988 hr = pUrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
989 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
990 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
992 dwSize--;
993 hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
994 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
995 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
997 hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
998 ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
999 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
1000 if(SUCCEEDED(hr)) {
1001 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
1004 if (pUrlCombineW) {
1005 dwSize = 0;
1006 hr = pUrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
1007 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1008 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1010 dwSize--;
1011 hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
1012 ok(hr == E_POINTER, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1013 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1015 hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
1016 ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
1017 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
1018 if(SUCCEEDED(hr)) {
1019 wszConvertedUrl = GetWideString(szReturnUrl);
1020 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
1021 FreeWideString(wszConvertedUrl);
1025 FreeWideString(wszUrl1);
1026 FreeWideString(wszUrl2);
1027 FreeWideString(wszExpectUrl);
1030 /* ########################### */
1032 static void test_UrlCombine(void)
1034 unsigned int i;
1035 for(i=0; i<sizeof(TEST_COMBINE)/sizeof(TEST_COMBINE[0]); i++) {
1036 test_url_combine(TEST_COMBINE[i].url1, TEST_COMBINE[i].url2, TEST_COMBINE[i].flags,
1037 TEST_COMBINE[i].expectret, TEST_COMBINE[i].expecturl);
1041 /* ########################### */
1043 static void test_UrlCreateFromPath(void)
1045 size_t i;
1046 char ret_url[INTERNET_MAX_URL_LENGTH];
1047 DWORD len, ret;
1048 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
1049 WCHAR *pathW, *urlW;
1051 if (!pUrlCreateFromPathA) {
1052 win_skip("UrlCreateFromPathA not found\n");
1053 return;
1056 for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
1057 len = INTERNET_MAX_URL_LENGTH;
1058 ret = pUrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
1059 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
1060 ok(!lstrcmpi(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
1061 ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);
1063 if (pUrlCreateFromPathW) {
1064 len = INTERNET_MAX_URL_LENGTH;
1065 pathW = GetWideString(TEST_URLFROMPATH[i].path);
1066 urlW = GetWideString(TEST_URLFROMPATH[i].url);
1067 ret = pUrlCreateFromPathW(pathW, ret_urlW, &len, 0);
1068 WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
1069 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
1070 ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
1071 ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n",
1072 ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
1073 ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
1074 FreeWideString(urlW);
1075 FreeWideString(pathW);
1080 /* ########################### */
1082 static void test_UrlIs_null(DWORD flag)
1084 BOOL ret;
1085 ret = pUrlIsA(NULL, flag);
1086 ok(ret == FALSE, "pUrlIsA(NULL, %d) failed\n", flag);
1087 ret = pUrlIsW(NULL, flag);
1088 ok(ret == FALSE, "pUrlIsW(NULL, %d) failed\n", flag);
1091 static void test_UrlIs(void)
1093 BOOL ret;
1094 size_t i;
1095 WCHAR wurl[80];
1097 if (!pUrlIsA) {
1098 win_skip("UrlIsA not found\n");
1099 return;
1102 test_UrlIs_null(URLIS_APPLIABLE);
1103 test_UrlIs_null(URLIS_DIRECTORY);
1104 test_UrlIs_null(URLIS_FILEURL);
1105 test_UrlIs_null(URLIS_HASQUERY);
1106 test_UrlIs_null(URLIS_NOHISTORY);
1107 test_UrlIs_null(URLIS_OPAQUE);
1108 test_UrlIs_null(URLIS_URL);
1110 for(i = 0; i < sizeof(TEST_PATH_IS_URL) / sizeof(TEST_PATH_IS_URL[0]); i++) {
1111 MultiByteToWideChar(CP_ACP, 0, TEST_PATH_IS_URL[i].path, -1, wurl, 80);
1113 ret = pUrlIsA( TEST_PATH_IS_URL[i].path, URLIS_URL );
1114 ok( ret == TEST_PATH_IS_URL[i].expect,
1115 "returned %d from path %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
1116 TEST_PATH_IS_URL[i].expect );
1118 if (pUrlIsW) {
1119 ret = pUrlIsW( wurl, URLIS_URL );
1120 ok( ret == TEST_PATH_IS_URL[i].expect,
1121 "returned %d from path (UrlIsW) %s, expected %d\n", ret,
1122 TEST_PATH_IS_URL[i].path, TEST_PATH_IS_URL[i].expect );
1125 for(i = 0; i < sizeof(TEST_URLIS_ATTRIBS) / sizeof(TEST_URLIS_ATTRIBS[0]); i++) {
1126 MultiByteToWideChar(CP_ACP, 0, TEST_URLIS_ATTRIBS[i].url, -1, wurl, 80);
1128 ret = pUrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_OPAQUE);
1129 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
1130 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1131 TEST_URLIS_ATTRIBS[i].expectOpaque );
1132 ret = pUrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_FILEURL);
1133 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1134 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1135 TEST_URLIS_ATTRIBS[i].expectFile );
1137 if (pUrlIsW) {
1138 ret = pUrlIsW( wurl, URLIS_OPAQUE);
1139 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
1140 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n",
1141 ret, TEST_URLIS_ATTRIBS[i].url, TEST_URLIS_ATTRIBS[i].expectOpaque );
1142 ret = pUrlIsW( wurl, URLIS_FILEURL);
1143 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1144 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n",
1145 ret, TEST_URLIS_ATTRIBS[i].url, TEST_URLIS_ATTRIBS[i].expectFile );
1150 /* ########################### */
1152 static void test_UrlUnescape(void)
1154 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1155 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
1156 WCHAR *urlW, *expected_urlW;
1157 DWORD dwEscaped;
1158 size_t i;
1159 static char inplace[] = "file:///C:/Program%20Files";
1160 static char another_inplace[] = "file:///C:/Program%20Files";
1161 static const char expected[] = "file:///C:/Program Files";
1162 static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
1163 static WCHAR another_inplaceW[] ={'f','i','l','e',':','/','/','/',
1164 'C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
1165 HRESULT res;
1167 if (!pUrlUnescapeA) {
1168 win_skip("UrlUnescapeA not found\n");
1169 return;
1171 for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
1172 dwEscaped=INTERNET_MAX_URL_LENGTH;
1173 res = pUrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, &dwEscaped, 0);
1174 ok(res == S_OK,
1175 "UrlUnescapeA returned 0x%x (expected S_OK) for \"%s\"\n",
1176 res, TEST_URL_UNESCAPE[i].url);
1177 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);
1179 ZeroMemory(szReturnUrl, sizeof(szReturnUrl));
1180 /* if we set the bufferpointer to NULL here UrlUnescape fails and string gets not converted */
1181 res = pUrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, NULL, 0);
1182 ok(res == E_INVALIDARG,
1183 "UrlUnescapeA returned 0x%x (expected E_INVALIDARG) for \"%s\"\n",
1184 res, TEST_URL_UNESCAPE[i].url);
1185 ok(strcmp(szReturnUrl,"")==0, "Expected empty string\n");
1187 if (pUrlUnescapeW) {
1188 dwEscaped = INTERNET_MAX_URL_LENGTH;
1189 urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
1190 expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
1191 res = pUrlUnescapeW(urlW, ret_urlW, &dwEscaped, 0);
1192 ok(res == S_OK,
1193 "UrlUnescapeW returned 0x%x (expected S_OK) for \"%s\"\n",
1194 res, TEST_URL_UNESCAPE[i].url);
1196 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
1197 ok(lstrcmpW(ret_urlW, expected_urlW)==0,
1198 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n",
1199 TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url, 0L);
1200 FreeWideString(urlW);
1201 FreeWideString(expected_urlW);
1205 dwEscaped = sizeof(inplace);
1206 res = pUrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE);
1207 ok(res == S_OK, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res);
1208 ok(!strcmp(inplace, expected), "got %s expected %s\n", inplace, expected);
1209 ok(dwEscaped == 27, "got %d expected 27\n", dwEscaped);
1211 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1212 res = pUrlUnescapeA(another_inplace, NULL, NULL, URL_UNESCAPE_INPLACE);
1213 ok(res == S_OK, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res);
1214 ok(!strcmp(another_inplace, expected), "got %s expected %s\n", another_inplace, expected);
1216 if (pUrlUnescapeW) {
1217 dwEscaped = sizeof(inplaceW);
1218 res = pUrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE);
1219 ok(res == S_OK, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res);
1220 ok(dwEscaped == 50, "got %d expected 50\n", dwEscaped);
1222 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1223 res = pUrlUnescapeW(another_inplaceW, NULL, NULL, URL_UNESCAPE_INPLACE);
1224 ok(res == S_OK, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res);
1226 ok(lstrlenW(another_inplaceW) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW));
1230 static const struct parse_url_test_t {
1231 const char *url;
1232 HRESULT hres;
1233 UINT protocol_len;
1234 UINT scheme;
1235 } parse_url_tests[] = {
1236 {"http://www.winehq.org/",S_OK,4,URL_SCHEME_HTTP},
1237 {"https://www.winehq.org/",S_OK,5,URL_SCHEME_HTTPS},
1238 {"ftp://www.winehq.org/",S_OK,3,URL_SCHEME_FTP},
1239 {"test.txt?test=c:/dir",URL_E_INVALID_SYNTAX},
1240 {"test.txt",URL_E_INVALID_SYNTAX},
1241 {"xxx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1242 {"1xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1243 {"-xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1244 {"xx0://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1245 {"x://www.winehq.org/",URL_E_INVALID_SYNTAX},
1246 {"xx$://www.winehq.org/",URL_E_INVALID_SYNTAX},
1247 {"htt?p://www.winehq.org/",URL_E_INVALID_SYNTAX},
1248 {"ab-://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1249 {" http://www.winehq.org/",URL_E_INVALID_SYNTAX},
1252 static void test_ParseURL(void)
1254 const struct parse_url_test_t *test;
1255 WCHAR url[INTERNET_MAX_URL_LENGTH];
1256 PARSEDURLA parseda;
1257 PARSEDURLW parsedw;
1258 HRESULT hres;
1260 for(test = parse_url_tests; test < parse_url_tests + sizeof(parse_url_tests)/sizeof(*parse_url_tests); test++) {
1261 memset(&parseda, 0xd0, sizeof(parseda));
1262 parseda.cbSize = sizeof(parseda);
1263 hres = pParseURLA(test->url, &parseda);
1264 ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1265 if(hres == S_OK) {
1266 ok(parseda.pszProtocol == test->url, "parseda.pszProtocol = %s, expected %s\n",
1267 parseda.pszProtocol, test->url);
1268 ok(parseda.cchProtocol == test->protocol_len, "parseda.cchProtocol = %d, expected %d\n",
1269 parseda.cchProtocol, test->protocol_len);
1270 ok(parseda.pszSuffix == test->url+test->protocol_len+1, "parseda.pszSuffix = %s, expected %s\n",
1271 parseda.pszSuffix, test->url+test->protocol_len+1);
1272 ok(parseda.cchSuffix == strlen(test->url+test->protocol_len+1),
1273 "parseda.pszSuffix = %d, expected %d\n",
1274 parseda.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1275 ok(parseda.nScheme == test->scheme, "parseda.nScheme = %d, expected %d\n",
1276 parseda.nScheme, test->scheme);
1277 }else {
1278 ok(!parseda.pszProtocol, "parseda.pszProtocol = %p\n", parseda.pszProtocol);
1279 ok(parseda.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parseda.nScheme);
1282 MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, sizeof(url)/sizeof(WCHAR));
1284 memset(&parsedw, 0xd0, sizeof(parsedw));
1285 parsedw.cbSize = sizeof(parsedw);
1286 hres = pParseURLW(url, &parsedw);
1287 ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1288 if(hres == S_OK) {
1289 ok(parsedw.pszProtocol == url, "parsedw.pszProtocol = %s, expected %s\n",
1290 wine_dbgstr_w(parsedw.pszProtocol), wine_dbgstr_w(url));
1291 ok(parsedw.cchProtocol == test->protocol_len, "parsedw.cchProtocol = %d, expected %d\n",
1292 parsedw.cchProtocol, test->protocol_len);
1293 ok(parsedw.pszSuffix == url+test->protocol_len+1, "parsedw.pszSuffix = %s, expected %s\n",
1294 wine_dbgstr_w(parsedw.pszSuffix), wine_dbgstr_w(url+test->protocol_len+1));
1295 ok(parsedw.cchSuffix == strlen(test->url+test->protocol_len+1),
1296 "parsedw.pszSuffix = %d, expected %d\n",
1297 parsedw.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1298 ok(parsedw.nScheme == test->scheme, "parsedw.nScheme = %d, expected %d\n",
1299 parsedw.nScheme, test->scheme);
1300 }else {
1301 ok(!parsedw.pszProtocol, "parsedw.pszProtocol = %p\n", parseda.pszProtocol);
1302 ok(parsedw.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parsedw.nScheme);
1307 static void test_HashData(void)
1309 HRESULT res;
1310 BYTE input[16] = {0x51, 0x33, 0x4F, 0xA7, 0x45, 0x15, 0xF0, 0x52, 0x90,
1311 0x2B, 0xE7, 0xF5, 0xFD, 0xE1, 0xA6, 0xA7};
1312 BYTE output[32];
1313 static const BYTE expected[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1314 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1315 0xE3, 0x2D};
1316 static const BYTE expected2[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1317 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1318 0xE3, 0x2D, 0x47, 0xFC, 0x80, 0xB8, 0xD0,
1319 0x49, 0xE6, 0x13, 0x2A, 0x30, 0x51, 0x8D,
1320 0xF9, 0x4B, 0x07, 0xA6};
1321 static const BYTE expected3[] = {0x2B, 0xDC, 0x9A, 0x1B, 0xF0, 0x5A, 0xF9,
1322 0xC6, 0xBE, 0x94, 0x6D, 0xF3, 0x33, 0xC1,
1323 0x36, 0x07};
1324 int i;
1326 /* Test hashing with identically sized input/output buffers. */
1327 res = pHashData(input, 16, output, 16);
1328 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1329 if(res == S_OK)
1330 ok(!memcmp(output, expected, sizeof(expected)),
1331 "Output buffer did not match expected contents\n");
1333 /* Test hashing with larger output buffer. */
1334 res = pHashData(input, 16, output, 32);
1335 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1336 if(res == S_OK)
1337 ok(!memcmp(output, expected2, sizeof(expected2)),
1338 "Output buffer did not match expected contents\n");
1340 /* Test hashing with smaller input buffer. */
1341 res = pHashData(input, 8, output, 16);
1342 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1343 if(res == S_OK)
1344 ok(!memcmp(output, expected3, sizeof(expected3)),
1345 "Output buffer did not match expected contents\n");
1347 /* Test passing NULL pointers for input/output parameters. */
1348 res = pHashData(NULL, 0, NULL, 0);
1349 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1350 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1352 res = pHashData(input, 0, NULL, 0);
1353 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1354 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1356 res = pHashData(NULL, 0, output, 0);
1357 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1358 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1360 /* Test passing valid pointers with sizes of zero. */
1361 for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1362 input[i] = 0x00;
1364 for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1365 output[i] = 0xFF;
1367 res = pHashData(input, 0, output, 0);
1368 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1370 /* The buffers should be unchanged. */
1371 for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1373 ok(input[i] == 0x00, "Expected the input buffer to be unchanged\n");
1374 if(input[i] != 0x00) break;
1377 for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1379 ok(output[i] == 0xFF, "Expected the output buffer to be unchanged\n");
1380 if(output[i] != 0xFF) break;
1383 /* Input/output parameters are not validated. */
1384 res = pHashData((BYTE *)0xdeadbeef, 0, (BYTE *)0xdeadbeef, 0);
1385 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1387 if (0)
1389 res = pHashData((BYTE *)0xdeadbeef, 1, (BYTE *)0xdeadbeef, 1);
1390 trace("HashData returned 0x%08x\n", res);
1394 /* ########################### */
1396 START_TEST(url)
1399 hShlwapi = GetModuleHandleA("shlwapi.dll");
1400 pUrlUnescapeA = (void *) GetProcAddress(hShlwapi, "UrlUnescapeA");
1401 pUrlUnescapeW = (void *) GetProcAddress(hShlwapi, "UrlUnescapeW");
1402 pUrlIsA = (void *) GetProcAddress(hShlwapi, "UrlIsA");
1403 pUrlIsW = (void *) GetProcAddress(hShlwapi, "UrlIsW");
1404 pUrlHashA = (void *) GetProcAddress(hShlwapi, "UrlHashA");
1405 pUrlHashW = (void *) GetProcAddress(hShlwapi, "UrlHashW");
1406 pUrlGetPartA = (void *) GetProcAddress(hShlwapi, "UrlGetPartA");
1407 pUrlGetPartW = (void *) GetProcAddress(hShlwapi, "UrlGetPartW");
1408 pUrlEscapeA = (void *) GetProcAddress(hShlwapi, "UrlEscapeA");
1409 pUrlEscapeW = (void *) GetProcAddress(hShlwapi, "UrlEscapeW");
1410 pUrlCreateFromPathA = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathA");
1411 pUrlCreateFromPathW = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathW");
1412 pUrlCombineA = (void *) GetProcAddress(hShlwapi, "UrlCombineA");
1413 pUrlCombineW = (void *) GetProcAddress(hShlwapi, "UrlCombineW");
1414 pUrlCanonicalizeA = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeA");
1415 pUrlCanonicalizeW = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeW");
1416 pUrlApplySchemeA = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeA");
1417 pUrlApplySchemeW = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeW");
1418 pParseURLA = (void*)GetProcAddress(hShlwapi, (LPCSTR)1);
1419 pParseURLW = (void*)GetProcAddress(hShlwapi, (LPCSTR)2);
1420 pHashData = (void*)GetProcAddress(hShlwapi, "HashData");
1422 test_UrlApplyScheme();
1423 test_UrlHash();
1424 test_UrlGetPart();
1425 test_UrlCanonicalizeA();
1426 test_UrlCanonicalizeW();
1427 test_UrlEscape();
1428 test_UrlCombine();
1429 test_UrlCreateFromPath();
1430 test_UrlIs();
1431 test_UrlUnescape();
1432 test_ParseURL();
1433 test_HashData();