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
24 #include "wine/test.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
{
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
{
97 const char *expecturl
;
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/tests/../tests", 0, S_OK
, "http://www.winehq.org/tests", FALSE
},
104 {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY
|URL_ESCAPE_SPACES_ONLY
|URL_ESCAPE_UNSAFE
, S_OK
, "http://www.winehq.org/tests", FALSE
},
105 {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY
|URL_ESCAPE_SPACES_ONLY
|URL_ESCAPE_UNSAFE
, S_OK
, "http://www.winehq.org/tests", FALSE
},
106 {"http://www.winehq.org/tests\r", 0, S_OK
, "http://www.winehq.org/tests", FALSE
},
107 {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY
, S_OK
, "http://www.winehq.org/tests", FALSE
},
108 {"http://www.winehq.org/tests/../tests/", 0, S_OK
, "http://www.winehq.org/tests/", FALSE
},
109 {"http://www.winehq.org/tests/../tests/..", 0, S_OK
, "http://www.winehq.org/", FALSE
},
110 {"http://www.winehq.org/tests/../tests/../", 0, S_OK
, "http://www.winehq.org/", FALSE
},
111 {"http://www.winehq.org/tests/..", 0, S_OK
, "http://www.winehq.org/", FALSE
},
112 {"http://www.winehq.org/tests/../", 0, S_OK
, "http://www.winehq.org/", FALSE
},
113 {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK
, "http://www.winehq.org/?query=x&return=y", FALSE
},
114 {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK
, "http://www.winehq.org/?query=x&return=y", FALSE
},
115 {"http://www.winehq.org/tests/..#example", 0, S_OK
, "http://www.winehq.org/#example", FALSE
},
116 {"http://www.winehq.org/tests/../#example", 0, S_OK
, "http://www.winehq.org/#example", 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", URL_DONT_SIMPLIFY
, S_OK
, "http://www.winehq.org/tests/../#example", FALSE
},
121 {"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
},
122 {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE
, S_OK
, "http://www.winehq.org/tests/foo bar", FALSE
},
123 {"file:///c:/tests/foo%20bar", URL_UNESCAPE
, S_OK
, "file:///c:/tests/foo bar", FALSE
},
124 {"file:///c:/tests\\foo%20bar", URL_UNESCAPE
, S_OK
, "file:///c:/tests/foo bar", FALSE
},
125 {"file:///c:/tests/foo%20bar", 0, S_OK
, "file:///c:/tests/foo%20bar", FALSE
},
126 {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "file://c:\\tests\\foo bar", FALSE
},
127 {"file://localhost/c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "file://c:\\tests\\foo bar", FALSE
},
128 {"file://localhost\\c:/tests/../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://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "file://c:\\tests\\foo bar", FALSE
},
132 {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "file://c:\\tests\\foo bar", FALSE
},
133 {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "file://c:\\tests\\foo bar", FALSE
},
134 {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "file://c:\\\\tests\\foo bar", FALSE
},
135 {"file:///c:\\tests\\foo bar", 0, S_OK
, "file:///c:/tests/foo bar", FALSE
},
136 {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY
, S_OK
, "file:///c:/tests/foo bar", FALSE
},
137 {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL
, S_OK
, "http://www.winehq.org/site/about", FALSE
},
138 {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL
, S_OK
, "file_://www.winehq.org/site/about", FALSE
},
139 {"c:\\dir\\file", 0, S_OK
, "file:///c:/dir/file", FALSE
},
140 {"file:///c:\\dir\\file", 0, S_OK
, "file:///c:/dir/file", FALSE
},
141 {"c:dir\\file", 0, S_OK
, "file:///c:dir/file", FALSE
},
142 {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL
, S_OK
, "file://c:\\tests\\foo bar", FALSE
},
143 {"c:\\tests\\foo bar", 0, S_OK
, "file:///c:/tests/foo%20bar", FALSE
},
144 {"res://file", 0, S_OK
, "res://file/", FALSE
},
145 {"res://file", URL_FILE_USE_PATHURL
, S_OK
, "res://file/", FALSE
},
146 {"res:///c:/tests/foo%20bar", URL_UNESCAPE
, S_OK
, "res:///c:/tests/foo bar", FALSE
},
147 {"res:///c:/tests\\foo%20bar", URL_UNESCAPE
, S_OK
, "res:///c:/tests\\foo bar", FALSE
},
148 {"res:///c:/tests/foo%20bar", 0, S_OK
, "res:///c:/tests/foo%20bar", FALSE
},
149 {"res:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "res:///c:/tests/foo%20bar", FALSE
},
150 {"res://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "res://c:/tests/foo%20bar", FALSE
},
151 {"res://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "res://c:/tests/foo%20bar", FALSE
},
152 {"res://c:/tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "res://c:/tests/foo%20bar", FALSE
},
153 {"res:///c://tests/foo%20bar", URL_FILE_USE_PATHURL
, S_OK
, "res:///c://tests/foo%20bar", FALSE
},
154 {"res:///c:\\tests\\foo bar", 0, S_OK
, "res:///c:\\tests\\foo bar", FALSE
},
155 {"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY
, S_OK
, "res:///c:\\tests\\foo bar", FALSE
},
156 {"res://c:\\tests\\foo bar/res", URL_FILE_USE_PATHURL
, S_OK
, "res://c:\\tests\\foo bar/res", FALSE
},
157 {"res://c:\\tests/res\\foo%20bar/strange\\sth", 0, S_OK
, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE
},
158 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_FILE_USE_PATHURL
, S_OK
, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE
},
159 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_UNESCAPE
, S_OK
, "res://c:\\tests/res\\foo bar/strange\\sth", FALSE
},
160 {"A", 0, S_OK
, "A", FALSE
},
161 {"/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*/,
162 {"http:www.winehq.org/dir/../index.html", 0, S_OK
, "http:www.winehq.org/index.html"},
163 {"http://localhost/test.html", URL_FILE_USE_PATHURL
, S_OK
, "http://localhost/test.html"}
166 /* ################ */
168 typedef struct _TEST_URL_ESCAPE
{
173 const char *expecturl
;
176 static const TEST_URL_ESCAPE TEST_ESCAPE
[] = {
177 {"http://www.winehq.org/tests0", 0, 0, S_OK
, "http://www.winehq.org/tests0"},
178 {"http://www.winehq.org/tests1\n", 0, 0, S_OK
, "http://www.winehq.org/tests1%0A"},
179 {"http://www.winehq.org/tests2\r", 0, 0, S_OK
, "http://www.winehq.org/tests2%0D"},
180 {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY
|URL_ESCAPE_UNSAFE
, 0, S_OK
, "http://www.winehq.org/tests3\r"},
181 {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY
, 0, S_OK
, "http://www.winehq.org/tests4\r"},
182 {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY
|URL_ESCAPE_SPACES_ONLY
, 0, S_OK
, "http://www.winehq.org/tests5\r"},
183 {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY
, 0, S_OK
, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
185 {"file://////foo/bar\\baz", 0, 0, S_OK
, "file://foo/bar/baz"},
186 {"file://///foo/bar\\baz", 0, 0, S_OK
, "file://foo/bar/baz"},
187 {"file:////foo/bar\\baz", 0, 0, S_OK
, "file://foo/bar/baz"},
188 {"file:///localhost/foo/bar\\baz", 0, 0, S_OK
, "file:///localhost/foo/bar/baz"},
189 {"file:///foo/bar\\baz", 0, 0, S_OK
, "file:///foo/bar/baz"},
190 {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK
, "file:///foo/bar/baz"},
191 {"file://foo/bar\\baz", 0, 0, S_OK
, "file://foo/bar/baz"},
192 {"file:/localhost/foo/bar\\baz", 0, 0, S_OK
, "file:///localhost/foo/bar/baz"},
193 {"file:/foo/bar\\baz", 0, 0, S_OK
, "file:///foo/bar/baz"},
194 {"file:foo/bar\\baz", 0, 0, S_OK
, "file:foo/bar/baz"},
195 {"file:\\foo/bar\\baz", 0, 0, S_OK
, "file:///foo/bar/baz"},
196 {"file:\\\\foo/bar\\baz", 0, 0, S_OK
, "file://foo/bar/baz"},
197 {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK
, "file:///foo/bar/baz"},
198 {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK
, "file:///foo/bar/baz"},
199 {"file:///f oo/b?a r\\baz", 0, 0, S_OK
, "file:///f%20oo/b?a r\\baz"},
200 {"file:///foo/b#a r\\baz", 0, 0, S_OK
, "file:///foo/b%23a%20r/baz"},
201 {"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"},
202 {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT
, 0, S_OK
, "file:///f%20o%25o/b?a r\\b%az"},
203 {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY
, 0, S_OK
, "file:%2Ffoo%2Fbar%5Cbaz"},
205 {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY
, 0, S_OK
, "foo%2Fb%ar%5Cba%3Fz%5C"},
206 {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT
| URL_ESCAPE_SEGMENT_ONLY
, 0, S_OK
, "foo%2Fb%25ar%5Cba%3Fz%5C"},
207 {"foo/bar\\ba?z\\", 0, 0, S_OK
, "foo/bar%5Cba?z\\"},
208 {"/foo/bar\\ba?z\\", 0, 0, S_OK
, "/foo/bar%5Cba?z\\"},
209 {"/foo/bar\\ba#z\\", 0, 0, S_OK
, "/foo/bar%5Cba#z\\"},
210 {"/foo/%5C", 0, 0, S_OK
, "/foo/%5C"},
211 {"/foo/%5C", URL_ESCAPE_PERCENT
, 0, S_OK
, "/foo/%255C"},
213 {"http://////foo/bar\\baz", 0, 0, S_OK
, "http://////foo/bar/baz"},
214 {"http://///foo/bar\\baz", 0, 0, S_OK
, "http://///foo/bar/baz"},
215 {"http:////foo/bar\\baz", 0, 0, S_OK
, "http:////foo/bar/baz"},
216 {"http:///foo/bar\\baz", 0, 0, S_OK
, "http:///foo/bar/baz"},
217 {"http://localhost/foo/bar\\baz", 0, 0, S_OK
, "http://localhost/foo/bar/baz"},
218 {"http://foo/bar\\baz", 0, 0, S_OK
, "http://foo/bar/baz"},
219 {"http:/foo/bar\\baz", 0, 0, S_OK
, "http:/foo/bar/baz"},
220 {"http:foo/bar\\ba?z\\", 0, 0, S_OK
, "http:foo%2Fbar%2Fba?z\\"},
221 {"http:foo/bar\\ba#z\\", 0, 0, S_OK
, "http:foo%2Fbar%2Fba#z\\"},
222 {"http:\\foo/bar\\baz", 0, 0, S_OK
, "http:/foo/bar/baz"},
223 {"http:\\\\foo/bar\\baz", 0, 0, S_OK
, "http://foo/bar/baz"},
224 {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK
, "http:///foo/bar/baz"},
225 {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK
, "http:////foo/bar/baz"},
226 {"http:/fo ?o/b ar\\baz", 0, 0, S_OK
, "http:/fo%20?o/b ar\\baz"},
227 {"http:fo ?o/b ar\\baz", 0, 0, S_OK
, "http:fo%20?o/b ar\\baz"},
228 {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY
, 0, S_OK
, "http:%2Ffoo%2Fbar%5Cbaz"},
230 {"https://foo/bar\\baz", 0, 0, S_OK
, "https://foo/bar/baz"},
231 {"https:/foo/bar\\baz", 0, 0, S_OK
, "https:/foo/bar/baz"},
232 {"https:\\foo/bar\\baz", 0, 0, S_OK
, "https:/foo/bar/baz"},
234 {"foo:////foo/bar\\baz", 0, 0, S_OK
, "foo:////foo/bar%5Cbaz"},
235 {"foo:///foo/bar\\baz", 0, 0, S_OK
, "foo:///foo/bar%5Cbaz"},
236 {"foo://localhost/foo/bar\\baz", 0, 0, S_OK
, "foo://localhost/foo/bar%5Cbaz"},
237 {"foo://foo/bar\\baz", 0, 0, S_OK
, "foo://foo/bar%5Cbaz"},
238 {"foo:/foo/bar\\baz", 0, 0, S_OK
, "foo:/foo/bar%5Cbaz"},
239 {"foo:foo/bar\\baz", 0, 0, S_OK
, "foo:foo%2Fbar%5Cbaz"},
240 {"foo:\\foo/bar\\baz", 0, 0, S_OK
, "foo:%5Cfoo%2Fbar%5Cbaz"},
241 {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK
, "foo:/foo/bar%5Cba?\\z"},
242 {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK
, "foo:/foo/bar%5Cba#\\z"},
244 {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK
, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
245 {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK
, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
246 {"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"},
248 {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK
, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
249 {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK
, "ftp:/fo/o@bar.baz/foo/bar"},
250 {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK
, "ftp://fo/o@bar.baz/fo?o\\bar"},
251 {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK
, "ftp://fo/o@bar.baz/fo#o\\bar"},
252 {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK
, "ftp://localhost/o@bar.baz/fo#o\\bar"},
253 {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK
, "ftp:///fo/o@bar.baz/foo/bar"},
254 {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK
, "ftp:////fo/o@bar.baz/foo/bar"}
257 /* ################ */
259 typedef struct _TEST_URL_COMBINE
{
264 const char *expecturl
;
267 static const TEST_URL_COMBINE TEST_COMBINE
[] = {
268 {"http://www.winehq.org/tests", "tests1", 0, S_OK
, "http://www.winehq.org/tests1"},
269 {"http://www.%77inehq.org/tests", "tests1", 0, S_OK
, "http://www.%77inehq.org/tests1"},
270 /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
271 {"http://www.winehq.org/tests/", "../tests3", 0, S_OK
, "http://www.winehq.org/tests3"},
272 {"http://www.winehq.org/tests/test1", "test2", 0, S_OK
, "http://www.winehq.org/tests/test2"},
273 {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK
, "http://www.winehq.org/tests4"},
274 {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK
, "http://www.winehq.org/tests/tests5"},
275 {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK
, "http://www.winehq.org/"},
276 {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK
, "http://www.winehq.org/"},
277 {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK
, "http://www.winehq.org/tests/tests8"},
278 {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK
, "http://www.winehq.org/tests/tests9"},
279 {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY
, S_OK
, "http://www.winehq.org/tests10/.."},
280 {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY
, S_OK
, "http://www.winehq.org/tests/../tests11"},
281 {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK
, "file:///C:/dir/test.txt"},
282 {"file:///C:\\dir\\file.txt#hash\\hash", "test.txt", 0, S_OK
, "file:///C:/dir/file.txt#hash/test.txt"},
283 {"file:///C:\\dir\\file.html#hash\\hash", "test.html", 0, S_OK
, "file:///C:/dir/test.html"},
284 {"file:///C:\\dir\\file.htm#hash\\hash", "test.htm", 0, S_OK
, "file:///C:/dir/test.htm"},
285 {"file:///C:\\dir\\file.hTmL#hash\\hash", "test.hTmL", 0, S_OK
, "file:///C:/dir/test.hTmL"},
286 {"file:///C:\\dir.html\\file.txt#hash\\hash", "test.txt", 0, S_OK
, "file:///C:/dir.html/file.txt#hash/test.txt"},
287 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK
, "file:///C:/Test/test.txt"},
288 {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK
, "http://www.winehq.org/test/test%20file.txt"},
289 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL
, S_OK
, "http://www.winehq.org/test/test%20file.txt"},
290 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL
, S_OK
, "http://www.winehq.org%2ftest/test%20file.txt"},
291 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK
, "xxx:dir/file"},
292 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK
, "mk:@MSITStore:file.chm::/dir/file"},
293 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK
, "mk:@MSITStore:file.chm::/dir/file"},
294 {"foo:today", "foo:calendar", 0, S_OK
, "foo:calendar"},
295 {"foo:today", "bar:calendar", 0, S_OK
, "bar:calendar"},
296 {"foo:/today", "foo:calendar", 0, S_OK
, "foo:/calendar"},
297 {"foo:/today/", "foo:calendar", 0, S_OK
, "foo:/today/calendar"},
298 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK
, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
299 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK
, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
300 /* UrlCombine case 2 tests. Schemes do not match */
301 {"outbind://xxxxxxxxx","http://wine1/dir",0, S_OK
,"http://wine1/dir"},
302 {"xxxx://xxxxxxxxx","http://wine2/dir",0, S_OK
,"http://wine2/dir"},
303 {"ftp://xxxxxxxxx/","http://wine3/dir",0, S_OK
,"http://wine3/dir"},
304 {"outbind://xxxxxxxxx","http://wine4/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"http://wine4/dir"},
305 {"xxx://xxxxxxxxx","http://wine5/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"http://wine5/dir"},
306 {"ftp://xxxxxxxxx/","http://wine6/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"http://wine6/dir"},
307 {"http://xxxxxxxxx","outbind://wine7/dir",0, S_OK
,"outbind://wine7/dir"},
308 {"xxx://xxxxxxxxx","ftp://wine8/dir",0, S_OK
,"ftp://wine8/dir"},
309 {"ftp://xxxxxxxxx/","xxx://wine9/dir",0, S_OK
,"xxx://wine9/dir"},
310 {"http://xxxxxxxxx","outbind://wine10/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"outbind://wine10/dir"},
311 {"xxx://xxxxxxxxx","ftp://wine11/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"ftp://wine11/dir"},
312 {"ftp://xxxxxxxxx/","xxx://wine12/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"xxx://wine12/dir"},
313 {"http://xxxxxxxxx","outbind:wine13/dir",0, S_OK
,"outbind:wine13/dir"},
314 {"xxx://xxxxxxxxx","ftp:wine14/dir",0, S_OK
,"ftp:wine14/dir"},
315 {"ftp://xxxxxxxxx/","xxx:wine15/dir",0, S_OK
,"xxx:wine15/dir"},
316 {"outbind://xxxxxxxxx/","http:wine16/dir",0, S_OK
,"http:wine16/dir"},
317 {"http://xxxxxxxxx","outbind:wine17/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"outbind:wine17/dir"},
318 {"xxx://xxxxxxxxx","ftp:wine18/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"ftp:wine18/dir"},
319 {"ftp://xxxxxxxxx/","xxx:wine19/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"xxx:wine19/dir"},
320 {"outbind://xxxxxxxxx/","http:wine20/dir",URL_PLUGGABLE_PROTOCOL
, S_OK
,"http:wine20/dir"},
321 {"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"}
324 /* ################ */
326 static const struct {
330 } TEST_URLFROMPATH
[] = {
331 {"foo", "file:foo", S_OK
},
332 {"foo\\bar", "file:foo/bar", S_OK
},
333 {"\\foo\\bar", "file:///foo/bar", S_OK
},
334 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK
},
335 {"c:foo\\bar", "file:///c:foo/bar", S_OK
},
336 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK
},
337 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK
},
339 /* The following test fails on native shlwapi as distributed with Win95/98.
340 * Wine matches the behaviour of later versions.
342 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE
}
346 /* ################ */
351 } TEST_URL_UNESCAPE
[] = {
352 {"file://foo/bar", "file://foo/bar"},
353 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
354 {"file://%24%25foobar", "file://$%foobar"}
357 /* ################ */
359 static const struct {
362 } TEST_PATH_IS_URL
[] = {
363 {"http://foo/bar", TRUE
},
364 {"c:\\foo\\bar", FALSE
},
365 {"foo://foo/bar", TRUE
},
368 {"bogusscheme:", TRUE
},
369 {"http:partial", TRUE
}
372 /* ################ */
374 static const struct {
378 } TEST_URLIS_ATTRIBS
[] = {
379 { "ftp:", FALSE
, FALSE
},
380 { "http:", FALSE
, FALSE
},
381 { "gopher:", FALSE
, FALSE
},
382 { "mailto:", TRUE
, FALSE
},
383 { "news:", FALSE
, FALSE
},
384 { "nntp:", FALSE
, FALSE
},
385 { "telnet:", FALSE
, FALSE
},
386 { "wais:", FALSE
, FALSE
},
387 { "file:", FALSE
, TRUE
},
388 { "mk:", FALSE
, FALSE
},
389 { "https:", FALSE
, FALSE
},
390 { "shell:", TRUE
, FALSE
},
391 { "https:", FALSE
, FALSE
},
392 { "snews:", FALSE
, FALSE
},
393 { "local:", FALSE
, FALSE
},
394 { "javascript:", TRUE
, FALSE
},
395 { "vbscript:", TRUE
, FALSE
},
396 { "about:", TRUE
, FALSE
},
397 { "res:", FALSE
, FALSE
},
398 { "bogusscheme:", FALSE
, FALSE
},
399 { "file:\\\\e:\\b\\c", FALSE
, TRUE
},
400 { "file://e:/b/c", FALSE
, TRUE
},
401 { "http:partial", FALSE
, FALSE
},
402 { "mailto://www.winehq.org/test.html", TRUE
, FALSE
},
403 { "file:partial", FALSE
, TRUE
}
406 /* ########################### */
408 static LPWSTR
GetWideString(const char* szString
)
410 LPWSTR wszString
= HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH
) * sizeof(WCHAR
));
412 MultiByteToWideChar(0, 0, szString
, -1, wszString
, INTERNET_MAX_URL_LENGTH
);
418 static void FreeWideString(LPWSTR wszString
)
420 HeapFree(GetProcessHeap(), 0, wszString
);
423 /* ########################### */
425 static void test_UrlApplyScheme(void)
427 CHAR newurl
[TEST_APPLY_MAX_LENGTH
];
428 WCHAR urlW
[TEST_APPLY_MAX_LENGTH
];
429 WCHAR newurlW
[TEST_APPLY_MAX_LENGTH
];
434 if (!pUrlApplySchemeA
) {
435 win_skip("UrlApplySchemeA not found\n");
439 for(i
= 0; i
< sizeof(TEST_APPLY
)/sizeof(TEST_APPLY
[0]); i
++) {
440 len
= TEST_APPLY_MAX_LENGTH
;
441 lstrcpyA(newurl
, untouchedA
);
442 res
= pUrlApplySchemeA(TEST_APPLY
[i
].url
, newurl
, &len
, TEST_APPLY
[i
].flags
);
443 ok( res
== TEST_APPLY
[i
].res
,
444 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i
, res
, TEST_APPLY
[i
].res
);
446 ok( len
== TEST_APPLY
[i
].newlen
,
447 "#%dA: got len %d (expected %d)\n", i
, len
, TEST_APPLY
[i
].newlen
);
449 ok( !lstrcmpA(newurl
, TEST_APPLY
[i
].newurl
),
450 "#%dA: got '%s' (expected '%s')\n", i
, newurl
, TEST_APPLY
[i
].newurl
);
452 /* returned length is in character */
453 len
= TEST_APPLY_MAX_LENGTH
;
454 lstrcpyA(newurl
, untouchedA
);
455 MultiByteToWideChar(CP_ACP
, 0, newurl
, -1, newurlW
, len
);
456 MultiByteToWideChar(CP_ACP
, 0, TEST_APPLY
[i
].url
, -1, urlW
, len
);
458 res
= pUrlApplySchemeW(urlW
, newurlW
, &len
, TEST_APPLY
[i
].flags
);
459 WideCharToMultiByte(CP_ACP
, 0, newurlW
, -1, newurl
, TEST_APPLY_MAX_LENGTH
, NULL
, NULL
);
460 ok( res
== TEST_APPLY
[i
].res
,
461 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i
, res
, TEST_APPLY
[i
].res
);
463 ok( len
== TEST_APPLY
[i
].newlen
,
464 "#%dW: got len %d (expected %d)\n", i
, len
, TEST_APPLY
[i
].newlen
);
466 ok( !lstrcmpA(newurl
, TEST_APPLY
[i
].newurl
),
467 "#%dW: got '%s' (expected '%s')\n", i
, newurl
, TEST_APPLY
[i
].newurl
);
471 /* buffer too small */
472 lstrcpyA(newurl
, untouchedA
);
473 len
= lstrlenA(TEST_APPLY
[0].newurl
);
474 res
= pUrlApplySchemeA(TEST_APPLY
[0].url
, newurl
, &len
, TEST_APPLY
[0].flags
);
475 ok(res
== E_POINTER
, "got HRESULT 0x%x (expected E_POINTER)\n", res
);
476 /* The returned length include the space for the terminating 0 */
477 i
= lstrlenA(TEST_APPLY
[0].newurl
)+1;
478 ok(len
== i
, "got len %d (expected %d)\n", len
, i
);
479 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
481 /* NULL as parameter. The length and the buffer are not modified */
482 lstrcpyA(newurl
, untouchedA
);
483 len
= TEST_APPLY_MAX_LENGTH
;
484 res
= pUrlApplySchemeA(NULL
, newurl
, &len
, TEST_APPLY
[0].flags
);
485 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
486 ok(len
== TEST_APPLY_MAX_LENGTH
, "got len %d\n", len
);
487 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
489 len
= TEST_APPLY_MAX_LENGTH
;
490 res
= pUrlApplySchemeA(TEST_APPLY
[0].url
, NULL
, &len
, TEST_APPLY
[0].flags
);
491 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
492 ok(len
== TEST_APPLY_MAX_LENGTH
, "got len %d\n", len
);
494 lstrcpyA(newurl
, untouchedA
);
495 res
= pUrlApplySchemeA(TEST_APPLY
[0].url
, newurl
, NULL
, TEST_APPLY
[0].flags
);
496 ok(res
== E_INVALIDARG
, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res
);
497 ok(!lstrcmpA(newurl
, untouchedA
), "got '%s' (expected '%s')\n", newurl
, untouchedA
);
501 /* ########################### */
503 static void hash_url(const char* szUrl
)
505 LPCSTR szTestUrl
= szUrl
;
506 LPWSTR wszTestUrl
= GetWideString(szTestUrl
);
509 DWORD cbSize
= sizeof(DWORD
);
510 DWORD dwHash1
, dwHash2
;
511 res
= pUrlHashA(szTestUrl
, (LPBYTE
)&dwHash1
, cbSize
);
512 ok(res
== S_OK
, "UrlHashA returned 0x%x (expected S_OK) for %s\n", res
, szUrl
);
514 res
= pUrlHashW(wszTestUrl
, (LPBYTE
)&dwHash2
, cbSize
);
515 ok(res
== S_OK
, "UrlHashW returned 0x%x (expected S_OK) for %s\n", res
, szUrl
);
516 ok(dwHash1
== dwHash2
,
517 "Hashes didn't match (A: 0x%x, W: 0x%x) for %s\n", dwHash1
, dwHash2
, szUrl
);
519 FreeWideString(wszTestUrl
);
523 static void test_UrlHash(void)
526 win_skip("UrlHashA not found\n");
530 hash_url(TEST_URL_1
);
531 hash_url(TEST_URL_2
);
532 hash_url(TEST_URL_3
);
535 /* ########################### */
537 static void test_url_part(const char* szUrl
, DWORD dwPart
, DWORD dwFlags
, const char* szExpected
)
539 CHAR szPart
[INTERNET_MAX_URL_LENGTH
];
540 WCHAR wszPart
[INTERNET_MAX_URL_LENGTH
];
541 LPWSTR wszUrl
= GetWideString(szUrl
);
542 LPWSTR wszConvertedPart
;
547 res
= pUrlGetPartA(szUrl
, szPart
, &dwSize
, dwPart
, dwFlags
);
548 ok(res
== E_POINTER
, "UrlGetPart for \"%s\" gave: 0x%08x\n", szUrl
, res
);
549 ok(dwSize
== strlen(szExpected
)+1 ||
550 (*szExpected
== '?' && dwSize
== strlen(szExpected
)),
551 "UrlGetPart for \"%s\" gave size: %u\n", szUrl
, dwSize
);
553 dwSize
= INTERNET_MAX_URL_LENGTH
;
554 res
= pUrlGetPartA(szUrl
, szPart
, &dwSize
, dwPart
, dwFlags
);
556 "UrlGetPartA for \"%s\" part 0x%08x returned 0x%x and \"%s\"\n",
557 szUrl
, dwPart
, res
, szPart
);
559 dwSize
= INTERNET_MAX_URL_LENGTH
;
560 res
= pUrlGetPartW(wszUrl
, wszPart
, &dwSize
, dwPart
, dwFlags
);
562 "UrlGetPartW for \"%s\" part 0x%08x returned 0x%x\n",
565 wszConvertedPart
= GetWideString(szPart
);
567 ok(lstrcmpW(wszPart
,wszConvertedPart
)==0,
568 "Strings didn't match between ascii and unicode UrlGetPart!\n");
570 FreeWideString(wszConvertedPart
);
572 FreeWideString(wszUrl
);
574 /* Note that v6.0 and later don't return '?' with the query */
575 ok(strcmp(szPart
,szExpected
)==0 ||
576 (*szExpected
=='?' && !strcmp(szPart
,szExpected
+1)),
577 "Expected %s, but got %s\n", szExpected
, szPart
);
580 /* ########################### */
582 static void test_UrlGetPart(void)
584 const char* file_url
= "file://h o s t/c:/windows/file";
585 const char* http_url
= "http://user:pass 123@www.wine hq.org";
586 const char* res_url
= "res://some.dll/find.dlg";
587 const char* about_url
= "about:blank";
589 CHAR szPart
[INTERNET_MAX_URL_LENGTH
];
594 win_skip("UrlGetPartA not found\n");
598 res
= pUrlGetPartA(NULL
, NULL
, NULL
, URL_PART_SCHEME
, 0);
599 ok(res
== E_INVALIDARG
, "null params gave: 0x%08x\n", res
);
601 res
= pUrlGetPartA(NULL
, szPart
, &dwSize
, URL_PART_SCHEME
, 0);
602 ok(res
== E_INVALIDARG
, "null URL gave: 0x%08x\n", res
);
604 res
= pUrlGetPartA(res_url
, NULL
, &dwSize
, URL_PART_SCHEME
, 0);
605 ok(res
== E_INVALIDARG
, "null szPart gave: 0x%08x\n", res
);
607 res
= pUrlGetPartA(res_url
, szPart
, NULL
, URL_PART_SCHEME
, 0);
608 ok(res
== E_INVALIDARG
, "null URL gave: 0x%08x\n", res
);
611 szPart
[0]='x'; szPart
[1]=0;
612 res
= pUrlGetPartA("hi", szPart
, &dwSize
, URL_PART_SCHEME
, 0);
613 ok(res
== E_INVALIDARG
, "UrlGetPartA(*pcchOut = 0) returned %08X\n", res
);
614 ok(szPart
[0] == 'x' && szPart
[1] == 0, "UrlGetPartA(*pcchOut = 0) modified szPart: \"%s\"\n", szPart
);
615 ok(dwSize
== 0, "dwSize = %d\n", dwSize
);
617 dwSize
= sizeof szPart
;
618 szPart
[0]='x'; szPart
[1]=0;
619 res
= pUrlGetPartA("hi", szPart
, &dwSize
, URL_PART_SCHEME
, 0);
620 ok (res
==S_FALSE
, "UrlGetPartA(\"hi\") returned %08X\n", res
);
621 ok(szPart
[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart
);
622 ok(dwSize
== 0, "dwSize = %d\n", dwSize
);
624 dwSize
= sizeof szPart
;
625 szPart
[0]='x'; szPart
[1]=0;
626 res
= pUrlGetPartA("hi", szPart
, &dwSize
, URL_PART_QUERY
, 0);
627 ok (res
==S_FALSE
, "UrlGetPartA(\"hi\") returned %08X\n", res
);
628 ok(szPart
[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart
);
629 ok(dwSize
== 0, "dwSize = %d\n", dwSize
);
631 test_url_part(TEST_URL_3
, URL_PART_HOSTNAME
, 0, "localhost");
632 test_url_part(TEST_URL_3
, URL_PART_PORT
, 0, "21");
633 test_url_part(TEST_URL_3
, URL_PART_USERNAME
, 0, "foo");
634 test_url_part(TEST_URL_3
, URL_PART_PASSWORD
, 0, "bar");
635 test_url_part(TEST_URL_3
, URL_PART_SCHEME
, 0, "http");
636 test_url_part(TEST_URL_3
, URL_PART_QUERY
, 0, "?query=x&return=y");
638 test_url_part(file_url
, URL_PART_HOSTNAME
, 0, "h o s t");
640 test_url_part(http_url
, URL_PART_HOSTNAME
, 0, "www.wine hq.org");
641 test_url_part(http_url
, URL_PART_PASSWORD
, 0, "pass 123");
643 test_url_part(about_url
, URL_PART_SCHEME
, 0, "about");
645 dwSize
= sizeof(szPart
);
646 res
= pUrlGetPartA(about_url
, szPart
, &dwSize
, URL_PART_HOSTNAME
, 0);
647 ok(res
==E_FAIL
, "returned %08x\n", res
);
649 test_url_part(res_url
, URL_PART_SCHEME
, 0, "res");
650 test_url_part("http://www.winehq.org", URL_PART_HOSTNAME
, URL_PARTFLAG_KEEPSCHEME
, "http:www.winehq.org");
652 dwSize
= sizeof szPart
;
653 szPart
[0]='x'; szPart
[1]=0;
654 res
= pUrlGetPartA(res_url
, szPart
, &dwSize
, URL_PART_QUERY
, 0);
655 ok(res
==S_FALSE
, "UrlGetPartA returned %08X\n", res
);
656 ok(szPart
[0]==0, "UrlGetPartA gave \"%s\" instead of \"\"\n", szPart
);
657 ok(dwSize
== 0, "dwSize = %d\n", dwSize
);
659 dwSize
= sizeof(szPart
);
660 res
= pUrlGetPartA("file://c:\\index.htm", szPart
, &dwSize
, URL_PART_HOSTNAME
, 0);
661 ok(res
==S_FALSE
, "returned %08x\n", res
);
662 ok(dwSize
== 0, "dwSize = %d\n", dwSize
);
664 dwSize
= sizeof(szPart
);
665 szPart
[0] = 'x'; szPart
[1] = '\0';
666 res
= pUrlGetPartA("file:some text", szPart
, &dwSize
, URL_PART_HOSTNAME
, 0);
667 ok(res
==S_FALSE
, "returned %08x\n", res
);
668 ok(szPart
[0] == '\0', "szPart[0] = %c\n", szPart
[0]);
669 ok(dwSize
== 0, "dwSize = %d\n", dwSize
);
671 dwSize
= sizeof(szPart
);
672 szPart
[0] = 'x'; szPart
[1] = '\0';
673 res
= pUrlGetPartA("index.htm", szPart
, &dwSize
, URL_PART_HOSTNAME
, 0);
674 ok(res
==E_FAIL
, "returned %08x\n", res
);
677 /* ########################### */
679 static void test_url_escape(const char *szUrl
, DWORD dwFlags
, HRESULT dwExpectReturn
, const char *szExpectUrl
)
681 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
683 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
684 WCHAR
*urlW
, *expected_urlW
;
685 dwEscaped
=INTERNET_MAX_URL_LENGTH
;
687 ok(pUrlEscapeA(szUrl
, szReturnUrl
, &dwEscaped
, dwFlags
) == dwExpectReturn
,
688 "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn
, szUrl
);
689 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl
, szReturnUrl
, szUrl
);
692 dwEscaped
= INTERNET_MAX_URL_LENGTH
;
693 urlW
= GetWideString(szUrl
);
694 expected_urlW
= GetWideString(szExpectUrl
);
695 ok(pUrlEscapeW(urlW
, ret_urlW
, &dwEscaped
, dwFlags
) == dwExpectReturn
,
696 "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn
, szUrl
);
697 WideCharToMultiByte(CP_ACP
,0,ret_urlW
,-1,szReturnUrl
,INTERNET_MAX_URL_LENGTH
,0,0);
698 ok(lstrcmpW(ret_urlW
, expected_urlW
)==0,
699 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n",
700 szExpectUrl
, szReturnUrl
, szUrl
, dwFlags
);
701 FreeWideString(urlW
);
702 FreeWideString(expected_urlW
);
706 static void test_url_canonicalize(int index
, const char *szUrl
, DWORD dwFlags
, HRESULT dwExpectReturn
, HRESULT dwExpectReturnAlt
, const char *szExpectUrl
, BOOL todo
)
708 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
709 WCHAR wszReturnUrl
[INTERNET_MAX_URL_LENGTH
];
710 LPWSTR wszUrl
= GetWideString(szUrl
);
711 LPWSTR wszExpectUrl
= GetWideString(szExpectUrl
);
712 LPWSTR wszConvertedUrl
;
717 dwSize
= INTERNET_MAX_URL_LENGTH
;
718 ret
= pUrlCanonicalizeA(szUrl
, NULL
, &dwSize
, dwFlags
);
719 ok(ret
!= dwExpectReturn
, "got 0s%x: Unexpected return for NULL buffer, index %d\n", ret
, index
);
720 ret
= pUrlCanonicalizeA(szUrl
, szReturnUrl
, &dwSize
, dwFlags
);
721 ok(ret
== dwExpectReturn
|| ret
== dwExpectReturnAlt
,
722 "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
723 dwExpectReturn
, dwExpectReturnAlt
, ret
, index
);
726 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags
, szUrl
, szExpectUrl
, szReturnUrl
, index
);
728 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags
, szUrl
, szExpectUrl
, szReturnUrl
, index
);
730 if (pUrlCanonicalizeW
) {
731 dwSize
= INTERNET_MAX_URL_LENGTH
;
732 ret
= pUrlCanonicalizeW(wszUrl
, NULL
, &dwSize
, dwFlags
);
733 ok(ret
!= dwExpectReturn
, "got 0x%x: Unexpected return for NULL buffer, index %d\n", ret
, index
);
734 ret
= pUrlCanonicalizeW(wszUrl
, wszReturnUrl
, &dwSize
, dwFlags
);
735 ok(ret
== dwExpectReturn
, "UrlCanonicalizeW failed: expected 0x%08x, got 0x%x, index %d\n",
736 dwExpectReturn
, ret
, index
);
738 wszConvertedUrl
= GetWideString(szReturnUrl
);
739 ok(lstrcmpW(wszReturnUrl
, wszConvertedUrl
)==0,
740 "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index
);
741 FreeWideString(wszConvertedUrl
);
744 FreeWideString(wszUrl
);
745 FreeWideString(wszExpectUrl
);
749 static void test_UrlEscape(void)
754 char empty_string
[] = "";
757 win_skip("UrlEscapeA noz found\n");
761 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL
, &size
, URL_ESCAPE_SPACES_ONLY
);
762 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
763 ok(size
== 0, "got %d, expected %d\n", size
, 0);
766 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
767 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
768 ok(size
== 0, "got %d, expected %d\n", size
, 0);
771 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL
, &size
, URL_ESCAPE_SPACES_ONLY
);
772 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
773 ok(size
== 1, "got %d, expected %d\n", size
, 1);
776 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, NULL
, URL_ESCAPE_SPACES_ONLY
);
777 ok(ret
== E_INVALIDARG
, "got %x, expected %x\n", ret
, E_INVALIDARG
);
778 ok(size
== 1, "got %d, expected %d\n", size
, 1);
781 ret
= pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string
, &size
, URL_ESCAPE_SPACES_ONLY
);
782 ok(ret
== E_POINTER
, "got %x, expected %x\n", ret
, E_POINTER
);
783 ok(size
== 34, "got %d, expected %d\n", size
, 34);
785 for(i
=0; i
<sizeof(TEST_ESCAPE
)/sizeof(TEST_ESCAPE
[0]); i
++) {
786 test_url_escape(TEST_ESCAPE
[i
].url
, TEST_ESCAPE
[i
].flags
,
787 TEST_ESCAPE
[i
].expectret
, TEST_ESCAPE
[i
].expecturl
);
791 /* ########################### */
793 static void test_UrlCanonicalizeA(void)
796 CHAR szReturnUrl
[4*INTERNET_MAX_URL_LENGTH
];
797 CHAR longurl
[4*INTERNET_MAX_URL_LENGTH
];
802 if (!pUrlCanonicalizeA
) {
803 win_skip("UrlCanonicalizeA not found\n");
807 urllen
= lstrlenA(winehqA
);
809 /* buffer has no space for the result */
811 memset(szReturnUrl
, '#', urllen
+4);
812 szReturnUrl
[urllen
+4] = '\0';
813 SetLastError(0xdeadbeef);
814 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
815 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
816 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
817 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
+1);
819 /* buffer has no space for the terminating '\0' */
821 memset(szReturnUrl
, '#', urllen
+4);
822 szReturnUrl
[urllen
+4] = '\0';
823 SetLastError(0xdeadbeef);
824 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
825 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
826 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
827 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
+1);
829 /* buffer has the required size */
831 memset(szReturnUrl
, '#', urllen
+4);
832 szReturnUrl
[urllen
+4] = '\0';
833 SetLastError(0xdeadbeef);
834 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
835 ok( (hr
== S_OK
) && (dwSize
== urllen
),
836 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
837 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
);
839 /* buffer is larger as the required size */
841 memset(szReturnUrl
, '#', urllen
+4);
842 szReturnUrl
[urllen
+4] = '\0';
843 SetLastError(0xdeadbeef);
844 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
845 ok( (hr
== S_OK
) && (dwSize
== urllen
),
846 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
847 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), urllen
);
849 /* length is set to 0 */
851 memset(szReturnUrl
, '#', urllen
+4);
852 szReturnUrl
[urllen
+4] = '\0';
853 SetLastError(0xdeadbeef);
854 hr
= pUrlCanonicalizeA(winehqA
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
855 ok( (hr
== E_INVALIDARG
) && (dwSize
== 0),
856 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_INVALIDARG' and size %u)\n",
857 hr
, GetLastError(), dwSize
, szReturnUrl
, lstrlenA(szReturnUrl
), 0);
859 /* url length > INTERNET_MAX_URL_SIZE */
860 dwSize
=sizeof(szReturnUrl
);
861 memset(longurl
, 'a', sizeof(longurl
));
862 memcpy(longurl
, winehqA
, sizeof(winehqA
)-1);
863 longurl
[sizeof(longurl
)-1] = '\0';
864 hr
= pUrlCanonicalizeA(longurl
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
865 ok(hr
== S_OK
, "hr = %x\n", hr
);
867 test_url_canonicalize(-1, "", 0, S_OK
, S_FALSE
/* Vista/win2k8 */, "", FALSE
);
869 /* test url-modification */
870 for(i
=0; i
<sizeof(TEST_CANONICALIZE
)/sizeof(TEST_CANONICALIZE
[0]); i
++) {
871 test_url_canonicalize(i
, TEST_CANONICALIZE
[i
].url
, TEST_CANONICALIZE
[i
].flags
,
872 TEST_CANONICALIZE
[i
].expectret
, TEST_CANONICALIZE
[i
].expectret
, TEST_CANONICALIZE
[i
].expecturl
,
873 TEST_CANONICALIZE
[i
].todo
);
877 /* ########################### */
879 static void test_UrlCanonicalizeW(void)
881 WCHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
888 if (!pUrlCanonicalizeW
) {
889 win_skip("UrlCanonicalizeW not found\n");
892 urllen
= lstrlenW(winehqW
);
894 /* buffer has no space for the result */
896 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
897 szReturnUrl
[urllen
+4] = '\0';
898 SetLastError(0xdeadbeef);
899 hr
= pUrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
900 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
901 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
902 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
+1);
905 /* buffer has no space for the terminating '\0' */
907 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
908 szReturnUrl
[urllen
+4] = '\0';
909 SetLastError(0xdeadbeef);
910 hr
= pUrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
911 ok( (hr
== E_POINTER
) && (dwSize
== (urllen
+ 1)),
912 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
913 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
+1);
915 /* buffer has the required size */
917 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
918 szReturnUrl
[urllen
+4] = '\0';
919 SetLastError(0xdeadbeef);
920 hr
= pUrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
921 ok( (hr
== S_OK
) && (dwSize
== urllen
),
922 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
923 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
);
925 /* buffer is larger as the required size */
927 memset(szReturnUrl
, '#', (urllen
+4) * sizeof(WCHAR
));
928 szReturnUrl
[urllen
+4] = '\0';
929 SetLastError(0xdeadbeef);
930 hr
= pUrlCanonicalizeW(winehqW
, szReturnUrl
, &dwSize
, URL_WININET_COMPATIBILITY
| URL_ESCAPE_UNSAFE
);
931 ok( (hr
== S_OK
) && (dwSize
== urllen
),
932 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
933 hr
, GetLastError(), dwSize
, lstrlenW(szReturnUrl
), urllen
);
935 /* check that the characters 1..32 are chopped from the end of the string */
936 for (i
= 1; i
< 65536; i
++)
942 MultiByteToWideChar(CP_ACP
, 0, "http://www.winehq.org/X", -1, szUrl
, 128);
943 pos
= lstrlenW(szUrl
) - 1;
945 urllen
= INTERNET_MAX_URL_LENGTH
;
946 pUrlCanonicalizeW(szUrl
, szReturnUrl
, &urllen
, 0);
947 choped
= lstrlenW(szReturnUrl
) < lstrlenW(szUrl
);
948 ok(choped
== (i
<= 32), "Incorrect char chopping for char %d\n", i
);
952 /* ########################### */
954 static void test_url_combine(const char *szUrl1
, const char *szUrl2
, DWORD dwFlags
, HRESULT dwExpectReturn
, const char *szExpectUrl
)
957 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
958 WCHAR wszReturnUrl
[INTERNET_MAX_URL_LENGTH
];
959 LPWSTR wszUrl1
= GetWideString(szUrl1
);
960 LPWSTR wszUrl2
= GetWideString(szUrl2
);
961 LPWSTR wszExpectUrl
= GetWideString(szExpectUrl
);
962 LPWSTR wszConvertedUrl
;
965 DWORD dwExpectLen
= lstrlen(szExpectUrl
);
968 win_skip("UrlCombineA not found\n");
972 hr
= pUrlCombineA(szUrl1
, szUrl2
, NULL
, NULL
, dwFlags
);
973 ok(hr
== E_INVALIDARG
, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr
, E_INVALIDARG
);
976 hr
= pUrlCombineA(szUrl1
, szUrl2
, NULL
, &dwSize
, dwFlags
);
977 ok(hr
== E_POINTER
, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
978 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
981 hr
= pUrlCombineA(szUrl1
, szUrl2
, szReturnUrl
, &dwSize
, dwFlags
);
982 ok(hr
== E_POINTER
, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
983 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
985 hr
= pUrlCombineA(szUrl1
, szUrl2
, szReturnUrl
, &dwSize
, dwFlags
);
986 ok(hr
== dwExpectReturn
, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr
, dwExpectReturn
);
987 ok(dwSize
== dwExpectLen
, "Got length %d, expected %d\n", dwSize
, dwExpectLen
);
989 ok(strcmp(szReturnUrl
,szExpectUrl
)==0, "Expected %s, but got %s\n", szExpectUrl
, szReturnUrl
);
994 hr
= pUrlCombineW(wszUrl1
, wszUrl2
, NULL
, &dwSize
, dwFlags
);
995 ok(hr
== E_POINTER
, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
996 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
999 hr
= pUrlCombineW(wszUrl1
, wszUrl2
, wszReturnUrl
, &dwSize
, dwFlags
);
1000 ok(hr
== E_POINTER
, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr
, E_POINTER
);
1001 ok(dwSize
== dwExpectLen
+1, "Got length %d, expected %d\n", dwSize
, dwExpectLen
+1);
1003 hr
= pUrlCombineW(wszUrl1
, wszUrl2
, wszReturnUrl
, &dwSize
, dwFlags
);
1004 ok(hr
== dwExpectReturn
, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr
, dwExpectReturn
);
1005 ok(dwSize
== dwExpectLen
, "Got length %d, expected %d\n", dwSize
, dwExpectLen
);
1007 wszConvertedUrl
= GetWideString(szReturnUrl
);
1008 ok(lstrcmpW(wszReturnUrl
, wszConvertedUrl
)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
1009 FreeWideString(wszConvertedUrl
);
1013 FreeWideString(wszUrl1
);
1014 FreeWideString(wszUrl2
);
1015 FreeWideString(wszExpectUrl
);
1018 /* ########################### */
1020 static void test_UrlCombine(void)
1023 for(i
=0; i
<sizeof(TEST_COMBINE
)/sizeof(TEST_COMBINE
[0]); i
++) {
1024 test_url_combine(TEST_COMBINE
[i
].url1
, TEST_COMBINE
[i
].url2
, TEST_COMBINE
[i
].flags
,
1025 TEST_COMBINE
[i
].expectret
, TEST_COMBINE
[i
].expecturl
);
1029 /* ########################### */
1031 static void test_UrlCreateFromPath(void)
1034 char ret_url
[INTERNET_MAX_URL_LENGTH
];
1036 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
1037 WCHAR
*pathW
, *urlW
;
1039 if (!pUrlCreateFromPathA
) {
1040 win_skip("UrlCreateFromPathA not found\n");
1044 for(i
= 0; i
< sizeof(TEST_URLFROMPATH
) / sizeof(TEST_URLFROMPATH
[0]); i
++) {
1045 len
= INTERNET_MAX_URL_LENGTH
;
1046 ret
= pUrlCreateFromPathA(TEST_URLFROMPATH
[i
].path
, ret_url
, &len
, 0);
1047 ok(ret
== TEST_URLFROMPATH
[i
].ret
, "ret %08x from path %s\n", ret
, TEST_URLFROMPATH
[i
].path
);
1048 ok(!lstrcmpi(ret_url
, TEST_URLFROMPATH
[i
].url
), "url %s from path %s\n", ret_url
, TEST_URLFROMPATH
[i
].path
);
1049 ok(len
== strlen(ret_url
), "ret len %d from path %s\n", len
, TEST_URLFROMPATH
[i
].path
);
1051 if (pUrlCreateFromPathW
) {
1052 len
= INTERNET_MAX_URL_LENGTH
;
1053 pathW
= GetWideString(TEST_URLFROMPATH
[i
].path
);
1054 urlW
= GetWideString(TEST_URLFROMPATH
[i
].url
);
1055 ret
= pUrlCreateFromPathW(pathW
, ret_urlW
, &len
, 0);
1056 WideCharToMultiByte(CP_ACP
, 0, ret_urlW
, -1, ret_url
, sizeof(ret_url
),0,0);
1057 ok(ret
== TEST_URLFROMPATH
[i
].ret
, "ret %08x from path L\"%s\", expected %08x\n",
1058 ret
, TEST_URLFROMPATH
[i
].path
, TEST_URLFROMPATH
[i
].ret
);
1059 ok(!lstrcmpiW(ret_urlW
, urlW
), "got %s expected %s from path L\"%s\"\n",
1060 ret_url
, TEST_URLFROMPATH
[i
].url
, TEST_URLFROMPATH
[i
].path
);
1061 ok(len
== lstrlenW(ret_urlW
), "ret len %d from path L\"%s\"\n", len
, TEST_URLFROMPATH
[i
].path
);
1062 FreeWideString(urlW
);
1063 FreeWideString(pathW
);
1068 /* ########################### */
1070 static void test_UrlIs_null(DWORD flag
)
1073 ret
= pUrlIsA(NULL
, flag
);
1074 ok(ret
== FALSE
, "pUrlIsA(NULL, %d) failed\n", flag
);
1075 ret
= pUrlIsW(NULL
, flag
);
1076 ok(ret
== FALSE
, "pUrlIsW(NULL, %d) failed\n", flag
);
1079 static void test_UrlIs(void)
1086 win_skip("UrlIsA not found\n");
1090 test_UrlIs_null(URLIS_APPLIABLE
);
1091 test_UrlIs_null(URLIS_DIRECTORY
);
1092 test_UrlIs_null(URLIS_FILEURL
);
1093 test_UrlIs_null(URLIS_HASQUERY
);
1094 test_UrlIs_null(URLIS_NOHISTORY
);
1095 test_UrlIs_null(URLIS_OPAQUE
);
1096 test_UrlIs_null(URLIS_URL
);
1098 for(i
= 0; i
< sizeof(TEST_PATH_IS_URL
) / sizeof(TEST_PATH_IS_URL
[0]); i
++) {
1099 MultiByteToWideChar(CP_ACP
, 0, TEST_PATH_IS_URL
[i
].path
, -1, wurl
, 80);
1101 ret
= pUrlIsA( TEST_PATH_IS_URL
[i
].path
, URLIS_URL
);
1102 ok( ret
== TEST_PATH_IS_URL
[i
].expect
,
1103 "returned %d from path %s, expected %d\n", ret
, TEST_PATH_IS_URL
[i
].path
,
1104 TEST_PATH_IS_URL
[i
].expect
);
1107 ret
= pUrlIsW( wurl
, URLIS_URL
);
1108 ok( ret
== TEST_PATH_IS_URL
[i
].expect
,
1109 "returned %d from path (UrlIsW) %s, expected %d\n", ret
,
1110 TEST_PATH_IS_URL
[i
].path
, TEST_PATH_IS_URL
[i
].expect
);
1113 for(i
= 0; i
< sizeof(TEST_URLIS_ATTRIBS
) / sizeof(TEST_URLIS_ATTRIBS
[0]); i
++) {
1114 MultiByteToWideChar(CP_ACP
, 0, TEST_URLIS_ATTRIBS
[i
].url
, -1, wurl
, 80);
1116 ret
= pUrlIsA( TEST_URLIS_ATTRIBS
[i
].url
, URLIS_OPAQUE
);
1117 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectOpaque
,
1118 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret
, TEST_URLIS_ATTRIBS
[i
].url
,
1119 TEST_URLIS_ATTRIBS
[i
].expectOpaque
);
1120 ret
= pUrlIsA( TEST_URLIS_ATTRIBS
[i
].url
, URLIS_FILEURL
);
1121 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectFile
,
1122 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret
, TEST_URLIS_ATTRIBS
[i
].url
,
1123 TEST_URLIS_ATTRIBS
[i
].expectFile
);
1126 ret
= pUrlIsW( wurl
, URLIS_OPAQUE
);
1127 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectOpaque
,
1128 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n",
1129 ret
, TEST_URLIS_ATTRIBS
[i
].url
, TEST_URLIS_ATTRIBS
[i
].expectOpaque
);
1130 ret
= pUrlIsW( wurl
, URLIS_FILEURL
);
1131 ok( ret
== TEST_URLIS_ATTRIBS
[i
].expectFile
,
1132 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n",
1133 ret
, TEST_URLIS_ATTRIBS
[i
].url
, TEST_URLIS_ATTRIBS
[i
].expectFile
);
1138 /* ########################### */
1140 static void test_UrlUnescape(void)
1142 CHAR szReturnUrl
[INTERNET_MAX_URL_LENGTH
];
1143 WCHAR ret_urlW
[INTERNET_MAX_URL_LENGTH
];
1144 WCHAR
*urlW
, *expected_urlW
;
1147 static char inplace
[] = "file:///C:/Program%20Files";
1148 static char another_inplace
[] = "file:///C:/Program%20Files";
1149 static const char expected
[] = "file:///C:/Program Files";
1150 static WCHAR inplaceW
[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
1151 static WCHAR another_inplaceW
[] ={'f','i','l','e',':','/','/','/',
1152 'C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
1155 if (!pUrlUnescapeA
) {
1156 win_skip("UrlUnescapeA not found\n");
1159 for(i
=0; i
<sizeof(TEST_URL_UNESCAPE
)/sizeof(TEST_URL_UNESCAPE
[0]); i
++) {
1160 dwEscaped
=INTERNET_MAX_URL_LENGTH
;
1161 res
= pUrlUnescapeA(TEST_URL_UNESCAPE
[i
].url
, szReturnUrl
, &dwEscaped
, 0);
1163 "UrlUnescapeA returned 0x%x (expected S_OK) for \"%s\"\n",
1164 res
, TEST_URL_UNESCAPE
[i
].url
);
1165 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
);
1167 ZeroMemory(szReturnUrl
, sizeof(szReturnUrl
));
1168 /* if we set the bufferpointer to NULL here UrlUnescape fails and string gets not converted */
1169 res
= pUrlUnescapeA(TEST_URL_UNESCAPE
[i
].url
, szReturnUrl
, NULL
, 0);
1170 ok(res
== E_INVALIDARG
,
1171 "UrlUnescapeA returned 0x%x (expected E_INVALIDARG) for \"%s\"\n",
1172 res
, TEST_URL_UNESCAPE
[i
].url
);
1173 ok(strcmp(szReturnUrl
,"")==0, "Expected empty string\n");
1175 if (pUrlUnescapeW
) {
1176 dwEscaped
= INTERNET_MAX_URL_LENGTH
;
1177 urlW
= GetWideString(TEST_URL_UNESCAPE
[i
].url
);
1178 expected_urlW
= GetWideString(TEST_URL_UNESCAPE
[i
].expect
);
1179 res
= pUrlUnescapeW(urlW
, ret_urlW
, &dwEscaped
, 0);
1181 "UrlUnescapeW returned 0x%x (expected S_OK) for \"%s\"\n",
1182 res
, TEST_URL_UNESCAPE
[i
].url
);
1184 WideCharToMultiByte(CP_ACP
,0,ret_urlW
,-1,szReturnUrl
,INTERNET_MAX_URL_LENGTH
,0,0);
1185 ok(lstrcmpW(ret_urlW
, expected_urlW
)==0,
1186 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n",
1187 TEST_URL_UNESCAPE
[i
].expect
, szReturnUrl
, TEST_URL_UNESCAPE
[i
].url
, 0L);
1188 FreeWideString(urlW
);
1189 FreeWideString(expected_urlW
);
1193 dwEscaped
= sizeof(inplace
);
1194 res
= pUrlUnescapeA(inplace
, NULL
, &dwEscaped
, URL_UNESCAPE_INPLACE
);
1195 ok(res
== S_OK
, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res
);
1196 ok(!strcmp(inplace
, expected
), "got %s expected %s\n", inplace
, expected
);
1197 ok(dwEscaped
== 27, "got %d expected 27\n", dwEscaped
);
1199 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1200 res
= pUrlUnescapeA(another_inplace
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1201 ok(res
== S_OK
, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res
);
1202 ok(!strcmp(another_inplace
, expected
), "got %s expected %s\n", another_inplace
, expected
);
1204 if (pUrlUnescapeW
) {
1205 dwEscaped
= sizeof(inplaceW
);
1206 res
= pUrlUnescapeW(inplaceW
, NULL
, &dwEscaped
, URL_UNESCAPE_INPLACE
);
1207 ok(res
== S_OK
, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res
);
1208 ok(dwEscaped
== 50, "got %d expected 50\n", dwEscaped
);
1210 /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1211 res
= pUrlUnescapeW(another_inplaceW
, NULL
, NULL
, URL_UNESCAPE_INPLACE
);
1212 ok(res
== S_OK
, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res
);
1214 ok(lstrlenW(another_inplaceW
) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW
));
1218 static const struct parse_url_test_t
{
1223 } parse_url_tests
[] = {
1224 {"http://www.winehq.org/",S_OK
,4,URL_SCHEME_HTTP
},
1225 {"https://www.winehq.org/",S_OK
,5,URL_SCHEME_HTTPS
},
1226 {"ftp://www.winehq.org/",S_OK
,3,URL_SCHEME_FTP
},
1227 {"test.txt?test=c:/dir",URL_E_INVALID_SYNTAX
},
1228 {"test.txt",URL_E_INVALID_SYNTAX
},
1229 {"xxx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1230 {"1xx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1231 {"-xx://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1232 {"xx0://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1233 {"x://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1234 {"xx$://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1235 {"htt?p://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1236 {"ab-://www.winehq.org/",S_OK
,3,URL_SCHEME_UNKNOWN
},
1237 {" http://www.winehq.org/",URL_E_INVALID_SYNTAX
},
1240 static void test_ParseURL(void)
1242 const struct parse_url_test_t
*test
;
1243 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
1248 for(test
= parse_url_tests
; test
< parse_url_tests
+ sizeof(parse_url_tests
)/sizeof(*parse_url_tests
); test
++) {
1249 memset(&parseda
, 0xd0, sizeof(parseda
));
1250 parseda
.cbSize
= sizeof(parseda
);
1251 hres
= pParseURLA(test
->url
, &parseda
);
1252 ok(hres
== test
->hres
, "ParseURL failed: %08x, expected %08x\n", hres
, test
->hres
);
1254 ok(parseda
.pszProtocol
== test
->url
, "parseda.pszProtocol = %s, expected %s\n",
1255 parseda
.pszProtocol
, test
->url
);
1256 ok(parseda
.cchProtocol
== test
->protocol_len
, "parseda.cchProtocol = %d, expected %d\n",
1257 parseda
.cchProtocol
, test
->protocol_len
);
1258 ok(parseda
.pszSuffix
== test
->url
+test
->protocol_len
+1, "parseda.pszSuffix = %s, expected %s\n",
1259 parseda
.pszSuffix
, test
->url
+test
->protocol_len
+1);
1260 ok(parseda
.cchSuffix
== strlen(test
->url
+test
->protocol_len
+1),
1261 "parseda.pszSuffix = %d, expected %d\n",
1262 parseda
.cchSuffix
, lstrlenA(test
->url
+test
->protocol_len
+1));
1263 ok(parseda
.nScheme
== test
->scheme
, "parseda.nScheme = %d, expected %d\n",
1264 parseda
.nScheme
, test
->scheme
);
1266 ok(!parseda
.pszProtocol
, "parseda.pszProtocol = %p\n", parseda
.pszProtocol
);
1267 ok(parseda
.nScheme
== 0xd0d0d0d0, "nScheme = %d\n", parseda
.nScheme
);
1270 MultiByteToWideChar(CP_ACP
, 0, test
->url
, -1, url
, sizeof(url
)/sizeof(WCHAR
));
1272 memset(&parsedw
, 0xd0, sizeof(parsedw
));
1273 parsedw
.cbSize
= sizeof(parsedw
);
1274 hres
= pParseURLW(url
, &parsedw
);
1275 ok(hres
== test
->hres
, "ParseURL failed: %08x, expected %08x\n", hres
, test
->hres
);
1277 ok(parsedw
.pszProtocol
== url
, "parsedw.pszProtocol = %s, expected %s\n",
1278 wine_dbgstr_w(parsedw
.pszProtocol
), wine_dbgstr_w(url
));
1279 ok(parsedw
.cchProtocol
== test
->protocol_len
, "parsedw.cchProtocol = %d, expected %d\n",
1280 parsedw
.cchProtocol
, test
->protocol_len
);
1281 ok(parsedw
.pszSuffix
== url
+test
->protocol_len
+1, "parsedw.pszSuffix = %s, expected %s\n",
1282 wine_dbgstr_w(parsedw
.pszSuffix
), wine_dbgstr_w(url
+test
->protocol_len
+1));
1283 ok(parsedw
.cchSuffix
== strlen(test
->url
+test
->protocol_len
+1),
1284 "parsedw.pszSuffix = %d, expected %d\n",
1285 parsedw
.cchSuffix
, lstrlenA(test
->url
+test
->protocol_len
+1));
1286 ok(parsedw
.nScheme
== test
->scheme
, "parsedw.nScheme = %d, expected %d\n",
1287 parsedw
.nScheme
, test
->scheme
);
1289 ok(!parsedw
.pszProtocol
, "parsedw.pszProtocol = %p\n", parseda
.pszProtocol
);
1290 ok(parsedw
.nScheme
== 0xd0d0d0d0, "nScheme = %d\n", parsedw
.nScheme
);
1295 static void test_HashData(void)
1298 BYTE input
[16] = {0x51, 0x33, 0x4F, 0xA7, 0x45, 0x15, 0xF0, 0x52, 0x90,
1299 0x2B, 0xE7, 0xF5, 0xFD, 0xE1, 0xA6, 0xA7};
1301 static const BYTE expected
[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1302 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1304 static const BYTE expected2
[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1305 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1306 0xE3, 0x2D, 0x47, 0xFC, 0x80, 0xB8, 0xD0,
1307 0x49, 0xE6, 0x13, 0x2A, 0x30, 0x51, 0x8D,
1308 0xF9, 0x4B, 0x07, 0xA6};
1309 static const BYTE expected3
[] = {0x2B, 0xDC, 0x9A, 0x1B, 0xF0, 0x5A, 0xF9,
1310 0xC6, 0xBE, 0x94, 0x6D, 0xF3, 0x33, 0xC1,
1314 /* Test hashing with identically sized input/output buffers. */
1315 res
= pHashData(input
, 16, output
, 16);
1316 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1318 ok(!memcmp(output
, expected
, sizeof(expected
)),
1319 "Output buffer did not match expected contents\n");
1321 /* Test hashing with larger output buffer. */
1322 res
= pHashData(input
, 16, output
, 32);
1323 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1325 ok(!memcmp(output
, expected2
, sizeof(expected2
)),
1326 "Output buffer did not match expected contents\n");
1328 /* Test hashing with smaller input buffer. */
1329 res
= pHashData(input
, 8, output
, 16);
1330 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1332 ok(!memcmp(output
, expected3
, sizeof(expected3
)),
1333 "Output buffer did not match expected contents\n");
1335 /* Test passing NULL pointers for input/output parameters. */
1336 res
= pHashData(NULL
, 0, NULL
, 0);
1337 ok(res
== E_INVALIDARG
|| broken(res
== S_OK
), /* Windows 2000 */
1338 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res
);
1340 res
= pHashData(input
, 0, NULL
, 0);
1341 ok(res
== E_INVALIDARG
|| broken(res
== S_OK
), /* Windows 2000 */
1342 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res
);
1344 res
= pHashData(NULL
, 0, output
, 0);
1345 ok(res
== E_INVALIDARG
|| broken(res
== S_OK
), /* Windows 2000 */
1346 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res
);
1348 /* Test passing valid pointers with sizes of zero. */
1349 for (i
= 0; i
< sizeof(input
)/sizeof(BYTE
); i
++)
1352 for (i
= 0; i
< sizeof(output
)/sizeof(BYTE
); i
++)
1355 res
= pHashData(input
, 0, output
, 0);
1356 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1358 /* The buffers should be unchanged. */
1359 for (i
= 0; i
< sizeof(input
)/sizeof(BYTE
); i
++)
1361 ok(input
[i
] == 0x00, "Expected the input buffer to be unchanged\n");
1362 if(input
[i
] != 0x00) break;
1365 for (i
= 0; i
< sizeof(output
)/sizeof(BYTE
); i
++)
1367 ok(output
[i
] == 0xFF, "Expected the output buffer to be unchanged\n");
1368 if(output
[i
] != 0xFF) break;
1371 /* Input/output parameters are not validated. */
1372 res
= pHashData((BYTE
*)0xdeadbeef, 0, (BYTE
*)0xdeadbeef, 0);
1373 ok(res
== S_OK
, "Expected HashData to return S_OK, got 0x%08x\n", res
);
1377 res
= pHashData((BYTE
*)0xdeadbeef, 1, (BYTE
*)0xdeadbeef, 1);
1378 trace("HashData returned 0x%08x\n", res
);
1382 /* ########################### */
1387 hShlwapi
= GetModuleHandleA("shlwapi.dll");
1388 pUrlUnescapeA
= (void *) GetProcAddress(hShlwapi
, "UrlUnescapeA");
1389 pUrlUnescapeW
= (void *) GetProcAddress(hShlwapi
, "UrlUnescapeW");
1390 pUrlIsA
= (void *) GetProcAddress(hShlwapi
, "UrlIsA");
1391 pUrlIsW
= (void *) GetProcAddress(hShlwapi
, "UrlIsW");
1392 pUrlHashA
= (void *) GetProcAddress(hShlwapi
, "UrlHashA");
1393 pUrlHashW
= (void *) GetProcAddress(hShlwapi
, "UrlHashW");
1394 pUrlGetPartA
= (void *) GetProcAddress(hShlwapi
, "UrlGetPartA");
1395 pUrlGetPartW
= (void *) GetProcAddress(hShlwapi
, "UrlGetPartW");
1396 pUrlEscapeA
= (void *) GetProcAddress(hShlwapi
, "UrlEscapeA");
1397 pUrlEscapeW
= (void *) GetProcAddress(hShlwapi
, "UrlEscapeW");
1398 pUrlCreateFromPathA
= (void *) GetProcAddress(hShlwapi
, "UrlCreateFromPathA");
1399 pUrlCreateFromPathW
= (void *) GetProcAddress(hShlwapi
, "UrlCreateFromPathW");
1400 pUrlCombineA
= (void *) GetProcAddress(hShlwapi
, "UrlCombineA");
1401 pUrlCombineW
= (void *) GetProcAddress(hShlwapi
, "UrlCombineW");
1402 pUrlCanonicalizeA
= (void *) GetProcAddress(hShlwapi
, "UrlCanonicalizeA");
1403 pUrlCanonicalizeW
= (void *) GetProcAddress(hShlwapi
, "UrlCanonicalizeW");
1404 pUrlApplySchemeA
= (void *) GetProcAddress(hShlwapi
, "UrlApplySchemeA");
1405 pUrlApplySchemeW
= (void *) GetProcAddress(hShlwapi
, "UrlApplySchemeW");
1406 pParseURLA
= (void*)GetProcAddress(hShlwapi
, (LPCSTR
)1);
1407 pParseURLW
= (void*)GetProcAddress(hShlwapi
, (LPCSTR
)2);
1408 pHashData
= (void*)GetProcAddress(hShlwapi
, "HashData");
1410 test_UrlApplyScheme();
1413 test_UrlCanonicalizeA();
1414 test_UrlCanonicalizeW();
1417 test_UrlCreateFromPath();