winemac: Don't unminimize a window for SetFocus().
[wine.git] / dlls / shlwapi / tests / url.c
blob6cef9d62d954c58b447ce8beb29f0970671001c0
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 char* TEST_URL_4 = "http://foo:bar@google.*.com:21/internal.php?query=x&return=y";
61 static const WCHAR winehqW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
62 static const CHAR winehqA[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
64 /* ################ */
66 static const CHAR untouchedA[] = "untouched";
68 #define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
70 typedef struct _TEST_URL_APPLY {
71 const char * url;
72 DWORD flags;
73 HRESULT res;
74 DWORD newlen;
75 const char * newurl;
76 } TEST_URL_APPLY;
78 static const TEST_URL_APPLY TEST_APPLY[] = {
79 {"www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
80 {"www.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 21, "http://www.winehq.org"},
81 {"www.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
82 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 20, "ftp://ftp.winehq.org"},
83 {"ftp.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 20, "ftp://ftp.winehq.org"},
84 {"ftp.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://ftp.winehq.org"},
85 {"winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
86 {"winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
87 {"winehq.org", URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
88 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
89 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_FORCEAPPLY, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
90 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_FORCEAPPLY | URL_APPLY_DEFAULT, S_OK, 28, "http://http://www.winehq.org"},
91 {"http://www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
92 {"", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 7, "http://"},
93 {"", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
94 {"", URL_APPLY_DEFAULT, S_OK, 7, "http://"},
95 {"u:\\windows", URL_APPLY_GUESSFILE | URL_APPLY_DEFAULT, S_OK, 18, "file:///u:/windows"},
96 {"u:\\windows", URL_APPLY_GUESSFILE, S_OK, 18, "file:///u:/windows"},
97 {"u:\\windows", URL_APPLY_DEFAULT, S_OK, 17, "http://u:\\windows"},
98 {"file:///c:/windows", URL_APPLY_GUESSFILE , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
99 {"aa:\\windows", URL_APPLY_GUESSFILE , S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
102 /* ################ */
104 typedef struct _TEST_URL_CANONICALIZE {
105 const char *url;
106 DWORD flags;
107 HRESULT expectret;
108 const char *expecturl;
109 BOOL todo;
110 } TEST_URL_CANONICALIZE;
112 static const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
113 {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/", TRUE},
114 {"http://www.winehq.org/..", 0, S_OK, "http://www.winehq.org/..", FALSE},
115 {"http://www.winehq.org/tests/tests2/../../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
116 {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
117 {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
118 {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
119 {"http://www.winehq.org/tests\r", 0, S_OK, "http://www.winehq.org/tests", FALSE},
120 {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests", FALSE},
121 {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/", FALSE},
122 {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
123 {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
124 {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
125 {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
126 {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
127 {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
128 {"\tht\ttp\t://www\t.w\tineh\t\tq.or\tg\t/\ttests/..\t?\tquer\ty=x\t\t&re\tturn=y\t\t", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
129 {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
130 {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
131 {"http://www.winehq.org/tests\\../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
132 {"http://www.winehq.org/tests/..\\#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
133 {"http://www.winehq.org\\tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
134 {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example", FALSE},
135 {"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},
136 {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE , S_OK, "http://www.winehq.org/tests/foo bar", FALSE},
137 {"http://www.winehq.org", 0, S_OK, "http://www.winehq.org/", FALSE},
138 {"http:///www.winehq.org", 0, S_OK, "http:///www.winehq.org", FALSE},
139 {"http:////www.winehq.org", 0, S_OK, "http:////www.winehq.org", FALSE},
140 {"file:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
141 {"file:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
142 {"file:///c:/tests/foo%20bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
143 {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
144 {"file://localhost/c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
145 {"file://localhost\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
146 {"file://localhost\\\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
147 {"file://localhost\\c:\\tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
148 {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
149 {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
150 {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
151 {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar", FALSE},
152 {"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar", FALSE},
153 {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar", FALSE},
154 {"file:///c:\\tests\\foobar", 0, S_OK, "file:///c:/tests/foobar", FALSE},
155 {"file:///c:\\tests\\foobar", URL_WININET_COMPATIBILITY, S_OK, "file://c:\\tests\\foobar", FALSE},
156 {"file://home/user/file", 0, S_OK, "file://home/user/file", FALSE},
157 {"file:///home/user/file", 0, S_OK, "file:///home/user/file", FALSE},
158 {"file:////home/user/file", 0, S_OK, "file://home/user/file", FALSE},
159 {"file://home/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://\\\\home\\user\\file", FALSE},
160 {"file:///home/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://\\home\\user\\file", FALSE},
161 {"file:////home/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://\\\\home\\user\\file", FALSE},
162 {"file://///home/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://\\\\home\\user\\file", FALSE},
163 {"file://C:/user/file", 0, S_OK, "file:///C:/user/file", FALSE},
164 {"file://C:/user/file/../asdf", 0, S_OK, "file:///C:/user/asdf", FALSE},
165 {"file:///C:/user/file", 0, S_OK, "file:///C:/user/file", FALSE},
166 {"file:////C:/user/file", 0, S_OK, "file:///C:/user/file", FALSE},
167 {"file://C:/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://C:\\user\\file", FALSE},
168 {"file:///C:/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://C:\\user\\file", FALSE},
169 {"file:////C:/user/file", URL_WININET_COMPATIBILITY, S_OK, "file://C:\\user\\file", FALSE},
170 {"http:///www.winehq.org", 0, S_OK, "http:///www.winehq.org", FALSE},
171 {"http:///www.winehq.org", URL_WININET_COMPATIBILITY, S_OK, "http:///www.winehq.org", FALSE},
172 {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about", FALSE},
173 {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about", FALSE},
174 {"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
175 {"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
176 {"c:dir\\file", 0, S_OK, "file:///c:dir/file", FALSE},
177 {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
178 {"c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
179 {"c\t:\t\\te\tsts\\fo\to \tbar\t", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
180 {"res://file", 0, S_OK, "res://file/", FALSE},
181 {"res://file", URL_FILE_USE_PATHURL, S_OK, "res://file/", FALSE},
182 {"res:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests/foo bar", FALSE},
183 {"res:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests\\foo bar", FALSE},
184 {"res:///c:/tests/foo%20bar", 0, S_OK, "res:///c:/tests/foo%20bar", FALSE},
185 {"res:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c:/tests/foo%20bar", FALSE},
186 {"res://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
187 {"res://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
188 {"res://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
189 {"res:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c://tests/foo%20bar", FALSE},
190 {"res:///c:\\tests\\foo bar", 0, S_OK, "res:///c:\\tests\\foo bar", FALSE},
191 {"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "res:///c:\\tests\\foo bar", FALSE},
192 {"res://c:\\tests\\foo bar/res", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests\\foo bar/res", FALSE},
193 {"res://c:\\tests/res\\foo%20bar/strange\\sth", 0, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
194 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
195 {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_UNESCAPE, S_OK, "res://c:\\tests/res\\foo bar/strange\\sth", FALSE},
196 {"A", 0, S_OK, "A", FALSE},
197 {"../A", 0, S_OK, "../A", FALSE},
198 {"A/../B", 0, S_OK, "B", TRUE},
199 {"/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*/,
200 {"http:www.winehq.org/dir/../index.html", 0, S_OK, "http:www.winehq.org/index.html"},
201 {"http://localhost/test.html", URL_FILE_USE_PATHURL, S_OK, "http://localhost/test.html"},
202 {"http://localhost/te%20st.html", URL_FILE_USE_PATHURL, S_OK, "http://localhost/te%20st.html"},
203 {"http://www.winehq.org/%E6%A1%9C.html", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/%E6%A1%9C.html"},
204 {"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"},
205 {"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"},
206 {"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"},
207 {"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"},
208 {"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"},
209 {"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"},
212 /* ################ */
214 typedef struct _TEST_URL_ESCAPE {
215 const char *url;
216 DWORD flags;
217 DWORD expectescaped;
218 HRESULT expectret;
219 const char *expecturl;
220 } TEST_URL_ESCAPE;
222 static const TEST_URL_ESCAPE TEST_ESCAPE[] = {
223 {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"},
224 {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"},
225 {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"},
226 {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"},
227 {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"},
228 {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"},
229 {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
231 {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
232 {"file://///foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
233 {"file:////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
234 {"file:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
235 {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
236 {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
237 {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
238 {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
239 {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
240 {"file:foo/bar\\baz", 0, 0, S_OK, "file:foo/bar/baz"},
241 {"file:\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
242 {"file:\\\\foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
243 {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
244 {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
245 {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"},
246 {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"},
247 {"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"},
248 {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"},
249 {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"},
251 {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"},
252 {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"},
253 {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"},
254 {"/foo/bar\\ba?z\\", 0, 0, S_OK, "/foo/bar%5Cba?z\\"},
255 {"/foo/bar\\ba#z\\", 0, 0, S_OK, "/foo/bar%5Cba#z\\"},
256 {"/foo/%5C", 0, 0, S_OK, "/foo/%5C"},
257 {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"},
259 {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"},
260 {"http://///foo/bar\\baz", 0, 0, S_OK, "http://///foo/bar/baz"},
261 {"http:////foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
262 {"http:///foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
263 {"http://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"},
264 {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
265 {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
266 {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"},
267 {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"},
268 {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
269 {"http:\\\\foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
270 {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
271 {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
272 {"http:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"},
273 {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"},
274 {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"},
276 {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"},
277 {"https:/foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
278 {"https:\\foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
280 {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"},
281 {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"},
282 {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"},
283 {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://foo/bar%5Cbaz"},
284 {"foo:/foo/bar\\baz", 0, 0, S_OK, "foo:/foo/bar%5Cbaz"},
285 {"foo:foo/bar\\baz", 0, 0, S_OK, "foo:foo%2Fbar%5Cbaz"},
286 {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"},
287 {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"},
288 {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"},
290 {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
291 {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
292 {"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"},
294 {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
295 {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"},
296 {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"},
297 {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"},
298 {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"},
299 {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"},
300 {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"}
303 /* ################ */
305 typedef struct _TEST_URL_COMBINE {
306 const char *url1;
307 const char *url2;
308 DWORD flags;
309 HRESULT expectret;
310 const char *expecturl;
311 } TEST_URL_COMBINE;
313 static const TEST_URL_COMBINE TEST_COMBINE[] = {
314 {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
315 {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
316 /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
317 {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"},
318 {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"},
319 {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"},
320 {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"},
321 {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"},
322 {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"},
323 {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"},
324 {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"},
325 {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."},
326 {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"},
327 {"http://www.winehq.org/test12", "#", 0, S_OK, "http://www.winehq.org/test12#"},
328 {"http://www.winehq.org/test13#aaa", "#bbb", 0, S_OK, "http://www.winehq.org/test13#bbb"},
329 {"http://www.winehq.org/test14#aaa/bbb#ccc", "#", 0, S_OK, "http://www.winehq.org/test14#"},
330 {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"},
331 {"file:///C:\\dir\\file.txt#hash\\hash", "test.txt", 0, S_OK, "file:///C:/dir/file.txt#hash/test.txt"},
332 {"file:///C:\\dir\\file.html#hash\\hash", "test.html", 0, S_OK, "file:///C:/dir/test.html"},
333 {"file:///C:\\dir\\file.htm#hash\\hash", "test.htm", 0, S_OK, "file:///C:/dir/test.htm"},
334 {"file:///C:\\dir\\file.hTmL#hash\\hash", "test.hTmL", 0, S_OK, "file:///C:/dir/test.hTmL"},
335 {"file:///C:\\dir.html\\file.txt#hash\\hash", "test.txt", 0, S_OK, "file:///C:/dir.html/file.txt#hash/test.txt"},
336 {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK, "file:///C:/Test/test.txt"},
337 {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"},
338 {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"},
339 {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"},
340 {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"},
341 {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
342 {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
343 {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"},
344 {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"},
345 {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"},
346 {"Foo:/today/", "fOo:calendar", 0, S_OK, "foo:/today/calendar"},
347 {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
348 {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
349 /* UrlCombine case 2 tests. Schemes do not match */
350 {"outbind://xxxxxxxxx","http://wine1/dir",0, S_OK,"http://wine1/dir"},
351 {"xxxx://xxxxxxxxx","http://wine2/dir",0, S_OK,"http://wine2/dir"},
352 {"ftp://xxxxxxxxx/","http://wine3/dir",0, S_OK,"http://wine3/dir"},
353 {"outbind://xxxxxxxxx","http://wine4/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine4/dir"},
354 {"xxx://xxxxxxxxx","http://wine5/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine5/dir"},
355 {"ftp://xxxxxxxxx/","http://wine6/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine6/dir"},
356 {"http://xxxxxxxxx","outbind://wine7/dir",0, S_OK,"outbind://wine7/dir"},
357 {"xxx://xxxxxxxxx","ftp://wine8/dir",0, S_OK,"ftp://wine8/dir"},
358 {"ftp://xxxxxxxxx/","xxx://wine9/dir",0, S_OK,"xxx://wine9/dir"},
359 {"http://xxxxxxxxx","outbind://wine10/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind://wine10/dir"},
360 {"xxx://xxxxxxxxx","ftp://wine11/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp://wine11/dir"},
361 {"ftp://xxxxxxxxx/","xxx://wine12/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx://wine12/dir"},
362 {"http://xxxxxxxxx","outbind:wine13/dir",0, S_OK,"outbind:wine13/dir"},
363 {"xxx://xxxxxxxxx","ftp:wine14/dir",0, S_OK,"ftp:wine14/dir"},
364 {"ftp://xxxxxxxxx/","xxx:wine15/dir",0, S_OK,"xxx:wine15/dir"},
365 {"outbind://xxxxxxxxx/","http:wine16/dir",0, S_OK,"http:wine16/dir"},
366 {"http://xxxxxxxxx","outbind:wine17/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind:wine17/dir"},
367 {"xxx://xxxxxxxxx","ftp:wine18/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp:wine18/dir"},
368 {"ftp://xxxxxxxxx/","xXx:wine19/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx:wine19/dir"},
369 {"outbind://xxxxxxxxx/","http:wine20/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http:wine20/dir"},
370 {"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"}
373 /* ################ */
375 static const struct {
376 const char *path;
377 const char *url;
378 DWORD ret;
379 } TEST_URLFROMPATH [] = {
380 {"foo", "file:foo", S_OK},
381 {"foo\\bar", "file:foo/bar", S_OK},
382 {"\\foo\\bar", "file:///foo/bar", S_OK},
383 {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK},
384 {"c:foo\\bar", "file:///c:foo/bar", S_OK},
385 {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK},
386 {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK},
387 {"file:///c:/foo/bar", "file:///c:/foo/bar", S_FALSE},
388 #if 0
389 /* The following test fails on native shlwapi as distributed with Win95/98.
390 * Wine matches the behaviour of later versions.
392 {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE}
393 #endif
396 /* ################ */
398 static struct {
399 char url[30];
400 const char *expect;
401 } TEST_URL_UNESCAPE[] = {
402 {"file://foo/bar", "file://foo/bar"},
403 {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
404 {"file://%24%25foobar", "file://$%foobar"}
407 /* ################ */
409 static const struct {
410 const char *path;
411 BOOL expect;
412 } TEST_PATH_IS_URL[] = {
413 {"http://foo/bar", TRUE},
414 {"c:\\foo\\bar", FALSE},
415 {"foo://foo/bar", TRUE},
416 {"foo\\bar", FALSE},
417 {"foo.bar", FALSE},
418 {"bogusscheme:", TRUE},
419 {"http:partial", TRUE}
422 /* ################ */
424 static const struct {
425 const char *url;
426 BOOL expectOpaque;
427 BOOL expectFile;
428 } TEST_URLIS_ATTRIBS[] = {
429 { "ftp:", FALSE, FALSE },
430 { "http:", FALSE, FALSE },
431 { "gopher:", FALSE, FALSE },
432 { "mailto:", TRUE, FALSE },
433 { "news:", FALSE, FALSE },
434 { "nntp:", FALSE, FALSE },
435 { "telnet:", FALSE, FALSE },
436 { "wais:", FALSE, FALSE },
437 { "file:", FALSE, TRUE },
438 { "mk:", FALSE, FALSE },
439 { "https:", FALSE, FALSE },
440 { "shell:", TRUE, FALSE },
441 { "https:", FALSE, FALSE },
442 { "snews:", FALSE, FALSE },
443 { "local:", FALSE, FALSE },
444 { "javascript:", TRUE, FALSE },
445 { "vbscript:", TRUE, FALSE },
446 { "about:", TRUE, FALSE },
447 { "res:", FALSE, FALSE },
448 { "bogusscheme:", FALSE, FALSE },
449 { "file:\\\\e:\\b\\c", FALSE, TRUE },
450 { "file://e:/b/c", FALSE, TRUE },
451 { "http:partial", FALSE, FALSE },
452 { "mailto://www.winehq.org/test.html", TRUE, FALSE },
453 { "file:partial", FALSE, TRUE },
454 { "File:partial", FALSE, TRUE },
457 /* ########################### */
459 static LPWSTR GetWideString(const char* szString)
461 LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
463 MultiByteToWideChar(CP_ACP, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
465 return wszString;
469 static void FreeWideString(LPWSTR wszString)
471 HeapFree(GetProcessHeap(), 0, wszString);
474 /* ########################### */
476 static void test_UrlApplyScheme(void)
478 CHAR newurl[TEST_APPLY_MAX_LENGTH];
479 WCHAR urlW[TEST_APPLY_MAX_LENGTH];
480 WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
481 HRESULT res;
482 DWORD len;
483 DWORD i;
485 if (!pUrlApplySchemeA) {
486 win_skip("UrlApplySchemeA not found\n");
487 return;
490 for(i = 0; i < sizeof(TEST_APPLY)/sizeof(TEST_APPLY[0]); i++) {
491 len = TEST_APPLY_MAX_LENGTH;
492 lstrcpyA(newurl, untouchedA);
493 res = pUrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
494 ok( res == TEST_APPLY[i].res,
495 "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
497 ok( len == TEST_APPLY[i].newlen,
498 "#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
500 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
501 "#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
503 /* returned length is in character */
504 len = TEST_APPLY_MAX_LENGTH;
505 lstrcpyA(newurl, untouchedA);
506 MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
507 MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
509 res = pUrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
510 WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
511 ok( res == TEST_APPLY[i].res,
512 "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
514 ok( len == TEST_APPLY[i].newlen,
515 "#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
517 ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
518 "#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
522 /* buffer too small */
523 lstrcpyA(newurl, untouchedA);
524 len = lstrlenA(TEST_APPLY[0].newurl);
525 res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, &len, TEST_APPLY[0].flags);
526 ok(res == E_POINTER, "got HRESULT 0x%x (expected E_POINTER)\n", res);
527 /* The returned length include the space for the terminating 0 */
528 i = lstrlenA(TEST_APPLY[0].newurl)+1;
529 ok(len == i, "got len %d (expected %d)\n", len, i);
530 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
532 /* NULL as parameter. The length and the buffer are not modified */
533 lstrcpyA(newurl, untouchedA);
534 len = TEST_APPLY_MAX_LENGTH;
535 res = pUrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
536 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
537 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
538 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
540 len = TEST_APPLY_MAX_LENGTH;
541 res = pUrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
542 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
543 ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
545 lstrcpyA(newurl, untouchedA);
546 res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
547 ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
548 ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
552 /* ########################### */
554 static void hash_url(const char* szUrl)
556 LPCSTR szTestUrl = szUrl;
557 LPWSTR wszTestUrl = GetWideString(szTestUrl);
558 HRESULT res;
560 DWORD cbSize = sizeof(DWORD);
561 DWORD dwHash1, dwHash2;
562 res = pUrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize);
563 ok(res == S_OK, "UrlHashA returned 0x%x (expected S_OK) for %s\n", res, szUrl);
564 if (pUrlHashW) {
565 res = pUrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize);
566 ok(res == S_OK, "UrlHashW returned 0x%x (expected S_OK) for %s\n", res, szUrl);
567 ok(dwHash1 == dwHash2,
568 "Hashes didn't match (A: 0x%x, W: 0x%x) for %s\n", dwHash1, dwHash2, szUrl);
570 FreeWideString(wszTestUrl);
574 static void test_UrlHash(void)
576 if (!pUrlHashA) {
577 win_skip("UrlHashA not found\n");
578 return;
581 hash_url(TEST_URL_1);
582 hash_url(TEST_URL_2);
583 hash_url(TEST_URL_3);
586 /* ########################### */
588 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
590 CHAR szPart[INTERNET_MAX_URL_LENGTH];
591 WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
592 LPWSTR wszUrl = GetWideString(szUrl);
593 LPWSTR wszConvertedPart;
594 HRESULT res;
595 DWORD dwSize;
597 dwSize = 1;
598 res = pUrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags);
599 ok(res == E_POINTER, "UrlGetPart for \"%s\" gave: 0x%08x\n", szUrl, res);
600 ok(dwSize == strlen(szExpected)+1 ||
601 (*szExpected == '?' && dwSize == strlen(szExpected)),
602 "UrlGetPart for \"%s\" gave size: %u\n", szUrl, dwSize);
604 dwSize = INTERNET_MAX_URL_LENGTH;
605 res = pUrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags);
606 ok(res == S_OK,
607 "UrlGetPartA for \"%s\" part 0x%08x returned 0x%x and \"%s\"\n",
608 szUrl, dwPart, res, szPart);
609 if (pUrlGetPartW) {
610 dwSize = INTERNET_MAX_URL_LENGTH;
611 res = pUrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags);
612 ok(res == S_OK,
613 "UrlGetPartW for \"%s\" part 0x%08x returned 0x%x\n",
614 szUrl, dwPart, res);
616 wszConvertedPart = GetWideString(szPart);
618 ok(lstrcmpW(wszPart,wszConvertedPart)==0,
619 "Strings didn't match between ascii and unicode UrlGetPart!\n");
621 FreeWideString(wszConvertedPart);
623 FreeWideString(wszUrl);
625 /* Note that v6.0 and later don't return '?' with the query */
626 ok(strcmp(szPart,szExpected)==0 ||
627 (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
628 "Expected %s, but got %s\n", szExpected, szPart);
631 /* ########################### */
633 static void test_UrlGetPart(void)
635 const char* file_url = "file://h o s t/c:/windows/file";
636 const char* http_url = "http://user:pass 123@www.wine hq.org";
637 const char* res_url = "res://some.dll/find.dlg";
638 const char* about_url = "about:blank";
639 const char* excid_url = "x-excid://36C00000/guid:{048B4E89-2E92-496F-A837-33BA02FF6D32}/Message.htm";
640 const char* foo_url = "foo://bar-url/test";
641 const char* short_url = "ascheme:";
643 CHAR szPart[INTERNET_MAX_URL_LENGTH];
644 DWORD dwSize;
645 HRESULT res;
647 if (!pUrlGetPartA) {
648 win_skip("UrlGetPartA not found\n");
649 return;
652 res = pUrlGetPartA(NULL, NULL, NULL, URL_PART_SCHEME, 0);
653 ok(res == E_INVALIDARG, "null params gave: 0x%08x\n", res);
655 res = pUrlGetPartA(NULL, szPart, &dwSize, URL_PART_SCHEME, 0);
656 ok(res == E_INVALIDARG, "null URL gave: 0x%08x\n", res);
658 res = pUrlGetPartA(res_url, NULL, &dwSize, URL_PART_SCHEME, 0);
659 ok(res == E_INVALIDARG, "null szPart gave: 0x%08x\n", res);
661 res = pUrlGetPartA(res_url, szPart, NULL, URL_PART_SCHEME, 0);
662 ok(res == E_INVALIDARG, "null URL gave: 0x%08x\n", res);
664 dwSize = 0;
665 szPart[0]='x'; szPart[1]=0;
666 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
667 ok(res == E_INVALIDARG, "UrlGetPartA(*pcchOut = 0) returned %08X\n", res);
668 ok(szPart[0] == 'x' && szPart[1] == 0, "UrlGetPartA(*pcchOut = 0) modified szPart: \"%s\"\n", szPart);
669 ok(dwSize == 0, "dwSize = %d\n", dwSize);
671 dwSize = sizeof szPart;
672 szPart[0]='x'; szPart[1]=0;
673 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
674 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
675 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
676 ok(dwSize == 0, "dwSize = %d\n", dwSize);
678 if(pUrlGetPartW)
680 const WCHAR hiW[] = {'h','i',0};
681 WCHAR bufW[5];
683 /* UrlGetPartW returns S_OK instead of S_FALSE */
684 dwSize = sizeof szPart;
685 bufW[0]='x'; bufW[1]=0;
686 res = pUrlGetPartW(hiW, bufW, &dwSize, URL_PART_SCHEME, 0);
687 todo_wine ok(res==S_OK, "UrlGetPartW(\"hi\") returned %08X\n", res);
688 ok(bufW[0] == 0, "UrlGetPartW(\"hi\") return \"%c\"\n", bufW[0]);
689 ok(dwSize == 0, "dwSize = %d\n", dwSize);
692 dwSize = sizeof szPart;
693 szPart[0]='x'; szPart[1]=0;
694 res = pUrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0);
695 ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
696 ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
697 ok(dwSize == 0, "dwSize = %d\n", dwSize);
699 test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
700 test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
701 test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
702 test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
703 test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
704 test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
706 test_url_part(TEST_URL_4, URL_PART_HOSTNAME, 0, "google.*.com");
708 test_url_part(file_url, URL_PART_HOSTNAME, 0, "h o s t");
710 test_url_part(http_url, URL_PART_HOSTNAME, 0, "www.wine hq.org");
711 test_url_part(http_url, URL_PART_PASSWORD, 0, "pass 123");
713 test_url_part(about_url, URL_PART_SCHEME, 0, "about");
715 test_url_part(excid_url, URL_PART_SCHEME, 0, "x-excid");
716 test_url_part(foo_url, URL_PART_SCHEME, 0, "foo");
717 test_url_part(short_url, URL_PART_SCHEME, 0, "ascheme");
719 dwSize = sizeof(szPart);
720 res = pUrlGetPartA(about_url, szPart, &dwSize, URL_PART_HOSTNAME, 0);
721 ok(res==E_FAIL, "returned %08x\n", res);
723 test_url_part(res_url, URL_PART_SCHEME, 0, "res");
724 test_url_part("http://www.winehq.org", URL_PART_HOSTNAME, URL_PARTFLAG_KEEPSCHEME, "http:www.winehq.org");
726 dwSize = sizeof szPart;
727 szPart[0]='x'; szPart[1]=0;
728 res = pUrlGetPartA(res_url, szPart, &dwSize, URL_PART_QUERY, 0);
729 ok(res==S_FALSE, "UrlGetPartA returned %08X\n", res);
730 ok(szPart[0]==0, "UrlGetPartA gave \"%s\" instead of \"\"\n", szPart);
731 ok(dwSize == 0, "dwSize = %d\n", dwSize);
733 dwSize = sizeof(szPart);
734 res = pUrlGetPartA("file://c:\\index.htm", szPart, &dwSize, URL_PART_HOSTNAME, 0);
735 ok(res==S_FALSE, "returned %08x\n", res);
736 ok(dwSize == 0, "dwSize = %d\n", dwSize);
738 dwSize = sizeof(szPart);
739 szPart[0] = 'x'; szPart[1] = '\0';
740 res = pUrlGetPartA("file:some text", szPart, &dwSize, URL_PART_HOSTNAME, 0);
741 ok(res==S_FALSE, "returned %08x\n", res);
742 ok(szPart[0] == '\0', "szPart[0] = %c\n", szPart[0]);
743 ok(dwSize == 0, "dwSize = %d\n", dwSize);
745 dwSize = sizeof(szPart);
746 szPart[0] = 'x'; szPart[1] = '\0';
747 res = pUrlGetPartA("index.htm", szPart, &dwSize, URL_PART_HOSTNAME, 0);
748 ok(res==E_FAIL, "returned %08x\n", res);
750 dwSize = sizeof(szPart);
751 szPart[0] = 'x'; szPart[1] = '\0';
752 res = pUrlGetPartA(excid_url, szPart, &dwSize, URL_PART_HOSTNAME, 0);
753 ok(res==E_FAIL, "returned %08x\n", res);
754 ok(szPart[0] == 'x', "szPart[0] = %c\n", szPart[0]);
755 ok(dwSize == sizeof(szPart), "dwSize = %d\n", dwSize);
757 dwSize = sizeof(szPart);
758 szPart[0] = 'x'; szPart[1] = '\0';
759 res = pUrlGetPartA(excid_url, szPart, &dwSize, URL_PART_QUERY, 0);
760 ok(res==S_FALSE, "returned %08x\n", res);
761 ok(szPart[0] == 0, "szPart[0] = %c\n", szPart[0]);
762 ok(dwSize == 0, "dwSize = %d\n", dwSize);
764 dwSize = sizeof(szPart);
765 szPart[0] = 'x'; szPart[1] = '\0';
766 res = pUrlGetPartA(foo_url, szPart, &dwSize, URL_PART_HOSTNAME, 0);
767 ok(res==E_FAIL, "returned %08x\n", res);
768 ok(szPart[0] == 'x', "szPart[0] = %c\n", szPart[0]);
769 ok(dwSize == sizeof(szPart), "dwSize = %d\n", dwSize);
771 dwSize = sizeof(szPart);
772 szPart[0] = 'x'; szPart[1] = '\0';
773 res = pUrlGetPartA(foo_url, szPart, &dwSize, URL_PART_QUERY, 0);
774 ok(res==S_FALSE, "returned %08x\n", res);
775 ok(szPart[0] == 0, "szPart[0] = %c\n", szPart[0]);
776 ok(dwSize == 0, "dwSize = %d\n", dwSize);
779 /* ########################### */
781 static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
783 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
784 DWORD dwEscaped;
785 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
786 WCHAR *urlW, *expected_urlW;
787 dwEscaped=INTERNET_MAX_URL_LENGTH;
789 ok(pUrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn,
790 "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
791 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);
793 if (pUrlEscapeW) {
794 dwEscaped = INTERNET_MAX_URL_LENGTH;
795 urlW = GetWideString(szUrl);
796 expected_urlW = GetWideString(szExpectUrl);
797 ok(pUrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn,
798 "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
799 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
800 ok(lstrcmpW(ret_urlW, expected_urlW)==0,
801 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n",
802 szExpectUrl, szReturnUrl, szUrl, dwFlags);
803 FreeWideString(urlW);
804 FreeWideString(expected_urlW);
808 static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, HRESULT dwExpectReturnAlt, const char *szExpectUrl, BOOL todo)
810 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
811 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
812 LPWSTR wszUrl = GetWideString(szUrl);
813 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
814 LPWSTR wszConvertedUrl;
815 HRESULT ret;
817 DWORD dwSize;
819 dwSize = INTERNET_MAX_URL_LENGTH;
820 ret = pUrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags);
821 ok(ret != dwExpectReturn, "got 0s%x: Unexpected return for NULL buffer, index %d\n", ret, index);
822 ret = pUrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags);
823 ok(ret == dwExpectReturn || ret == dwExpectReturnAlt,
824 "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
825 dwExpectReturn, dwExpectReturnAlt, ret, index);
826 if (todo)
827 todo_wine
828 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
829 else
830 ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
832 if (pUrlCanonicalizeW) {
833 dwSize = INTERNET_MAX_URL_LENGTH;
834 ret = pUrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags);
835 ok(ret != dwExpectReturn, "got 0x%x: Unexpected return for NULL buffer, index %d\n", ret, index);
836 ret = pUrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags);
837 ok(ret == dwExpectReturn, "UrlCanonicalizeW failed: expected 0x%08x, got 0x%x, index %d\n",
838 dwExpectReturn, ret, index);
840 wszConvertedUrl = GetWideString(szReturnUrl);
841 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0,
842 "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
843 FreeWideString(wszConvertedUrl);
846 FreeWideString(wszUrl);
847 FreeWideString(wszExpectUrl);
851 static void test_UrlEscape(void)
853 static const WCHAR out[] = { 'f','o','o','%','2','0','b','a','r',0 };
855 DWORD size = 0;
856 HRESULT ret;
857 unsigned int i;
858 char empty_string[] = "";
859 WCHAR overwrite[] = { 'f','o','o',' ','b','a','r',0,0,0 };
861 if (!pUrlEscapeA) {
862 win_skip("UrlEscapeA noz found\n");
863 return;
866 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
867 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
868 ok(size == 0, "got %d, expected %d\n", size, 0);
870 size = 0;
871 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
872 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
873 ok(size == 0, "got %d, expected %d\n", size, 0);
875 size = 1;
876 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
877 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
878 ok(size == 1, "got %d, expected %d\n", size, 1);
880 size = 1;
881 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
882 ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
883 ok(size == 1, "got %d, expected %d\n", size, 1);
885 size = 1;
886 empty_string[0] = 127;
887 ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
888 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
889 ok(size == 34, "got %d, expected %d\n", size, 34);
890 ok(empty_string[0] == 127, "String has changed, empty_string[0] = %d\n", empty_string[0]);
892 if(pUrlEscapeW) {
893 WCHAR wc;
895 size = sizeof(overwrite)/sizeof(WCHAR);
896 ret = pUrlEscapeW(overwrite, overwrite, &size, URL_ESCAPE_SPACES_ONLY);
897 ok(ret == S_OK, "got %x, expected S_OK\n", ret);
898 ok(size == 9, "got %d, expected 9\n", size);
899 ok(!lstrcmpW(overwrite, out), "got %s, expected %s\n", wine_dbgstr_w(overwrite), wine_dbgstr_w(out));
901 size = 1;
902 wc = 127;
903 ret = pUrlEscapeW(overwrite, &wc, &size, URL_ESCAPE_SPACES_ONLY);
904 ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
905 ok(size == 10, "got %d, expected 10\n", size);
906 ok(wc == 127, "String has changed, wc = %d\n", wc);
909 for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
910 test_url_escape(TEST_ESCAPE[i].url, TEST_ESCAPE[i].flags,
911 TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].expecturl);
915 /* ########################### */
917 static void test_UrlCanonicalizeA(void)
919 unsigned int i;
920 CHAR szReturnUrl[4*INTERNET_MAX_URL_LENGTH];
921 CHAR longurl[4*INTERNET_MAX_URL_LENGTH];
922 DWORD dwSize;
923 DWORD urllen;
924 HRESULT hr;
926 if (!pUrlCanonicalizeA) {
927 win_skip("UrlCanonicalizeA not found\n");
928 return;
931 urllen = lstrlenA(winehqA);
933 /* buffer has no space for the result */
934 dwSize=urllen-1;
935 memset(szReturnUrl, '#', urllen+4);
936 szReturnUrl[urllen+4] = '\0';
937 SetLastError(0xdeadbeef);
938 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
939 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
940 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
941 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
943 /* buffer has no space for the terminating '\0' */
944 dwSize=urllen;
945 memset(szReturnUrl, '#', urllen+4);
946 szReturnUrl[urllen+4] = '\0';
947 SetLastError(0xdeadbeef);
948 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
949 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
950 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
951 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
953 /* buffer has the required size */
954 dwSize=urllen+1;
955 memset(szReturnUrl, '#', urllen+4);
956 szReturnUrl[urllen+4] = '\0';
957 SetLastError(0xdeadbeef);
958 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
959 ok( (hr == S_OK) && (dwSize == urllen),
960 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
961 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
963 /* buffer is larger as the required size */
964 dwSize=urllen+2;
965 memset(szReturnUrl, '#', urllen+4);
966 szReturnUrl[urllen+4] = '\0';
967 SetLastError(0xdeadbeef);
968 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
969 ok( (hr == S_OK) && (dwSize == urllen),
970 "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
971 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
973 /* length is set to 0 */
974 dwSize=0;
975 memset(szReturnUrl, '#', urllen+4);
976 szReturnUrl[urllen+4] = '\0';
977 SetLastError(0xdeadbeef);
978 hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
979 ok( (hr == E_INVALIDARG) && (dwSize == 0),
980 "got 0x%x with %u and size %u for '%s' and %u (expected 'E_INVALIDARG' and size %u)\n",
981 hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), 0);
983 /* url length > INTERNET_MAX_URL_SIZE */
984 dwSize=sizeof(szReturnUrl);
985 memset(longurl, 'a', sizeof(longurl));
986 memcpy(longurl, winehqA, sizeof(winehqA)-1);
987 longurl[sizeof(longurl)-1] = '\0';
988 hr = pUrlCanonicalizeA(longurl, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
989 ok(hr == S_OK, "hr = %x\n", hr);
991 test_url_canonicalize(-1, "", 0, S_OK, S_FALSE /* Vista/win2k8 */, "", FALSE);
993 /* test url-modification */
994 for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
995 test_url_canonicalize(i, TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
996 TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl,
997 TEST_CANONICALIZE[i].todo);
1001 /* ########################### */
1003 static void test_UrlCanonicalizeW(void)
1005 WCHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1006 DWORD dwSize;
1007 DWORD urllen;
1008 HRESULT hr;
1009 int i;
1012 if (!pUrlCanonicalizeW) {
1013 win_skip("UrlCanonicalizeW not found\n");
1014 return;
1016 urllen = lstrlenW(winehqW);
1018 /* buffer has no space for the result */
1019 dwSize = (urllen-1);
1020 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
1021 szReturnUrl[urllen+4] = '\0';
1022 SetLastError(0xdeadbeef);
1023 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1024 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
1025 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
1026 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
1029 /* buffer has no space for the terminating '\0' */
1030 dwSize = urllen;
1031 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
1032 szReturnUrl[urllen+4] = '\0';
1033 SetLastError(0xdeadbeef);
1034 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1035 ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
1036 "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
1037 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
1039 /* buffer has the required size */
1040 dwSize = urllen +1;
1041 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
1042 szReturnUrl[urllen+4] = '\0';
1043 SetLastError(0xdeadbeef);
1044 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1045 ok( (hr == S_OK) && (dwSize == urllen),
1046 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
1047 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
1049 /* buffer is larger as the required size */
1050 dwSize = (urllen+2);
1051 memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
1052 szReturnUrl[urllen+4] = '\0';
1053 SetLastError(0xdeadbeef);
1054 hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
1055 ok( (hr == S_OK) && (dwSize == urllen),
1056 "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
1057 hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
1059 /* check that the characters 1..32 are chopped from the end of the string */
1060 for (i = 1; i < 65536; i++)
1062 WCHAR szUrl[128];
1063 BOOL choped;
1064 int pos;
1066 MultiByteToWideChar(CP_ACP, 0, "http://www.winehq.org/X", -1, szUrl, sizeof(szUrl)/sizeof(szUrl[0]));
1067 pos = lstrlenW(szUrl) - 1;
1068 szUrl[pos] = i;
1069 urllen = INTERNET_MAX_URL_LENGTH;
1070 pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
1071 choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
1072 ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
1076 /* ########################### */
1078 static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
1080 HRESULT hr;
1081 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1082 WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
1083 LPWSTR wszUrl1 = GetWideString(szUrl1);
1084 LPWSTR wszUrl2 = GetWideString(szUrl2);
1085 LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
1086 LPWSTR wszConvertedUrl;
1088 DWORD dwSize;
1089 DWORD dwExpectLen = lstrlen(szExpectUrl);
1091 if (!pUrlCombineA) {
1092 win_skip("UrlCombineA not found\n");
1093 return;
1096 hr = pUrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
1097 ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
1099 dwSize = 0;
1100 hr = pUrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
1101 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1102 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1104 dwSize--;
1105 hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
1106 ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1107 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1109 hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
1110 ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
1111 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
1112 if(SUCCEEDED(hr)) {
1113 ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
1116 if (pUrlCombineW) {
1117 dwSize = 0;
1118 hr = pUrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
1119 ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1120 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1122 dwSize--;
1123 hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
1124 ok(hr == E_POINTER, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
1125 ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
1127 hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
1128 ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
1129 ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
1130 if(SUCCEEDED(hr)) {
1131 wszConvertedUrl = GetWideString(szReturnUrl);
1132 ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
1133 FreeWideString(wszConvertedUrl);
1137 FreeWideString(wszUrl1);
1138 FreeWideString(wszUrl2);
1139 FreeWideString(wszExpectUrl);
1142 /* ########################### */
1144 static void test_UrlCombine(void)
1146 unsigned int i;
1147 for(i=0; i<sizeof(TEST_COMBINE)/sizeof(TEST_COMBINE[0]); i++) {
1148 test_url_combine(TEST_COMBINE[i].url1, TEST_COMBINE[i].url2, TEST_COMBINE[i].flags,
1149 TEST_COMBINE[i].expectret, TEST_COMBINE[i].expecturl);
1153 /* ########################### */
1155 static void test_UrlCreateFromPath(void)
1157 size_t i;
1158 char ret_url[INTERNET_MAX_URL_LENGTH];
1159 DWORD len, ret;
1160 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
1161 WCHAR *pathW, *urlW;
1163 if (!pUrlCreateFromPathA) {
1164 win_skip("UrlCreateFromPathA not found\n");
1165 return;
1168 for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
1169 len = INTERNET_MAX_URL_LENGTH;
1170 ret = pUrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
1171 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
1172 ok(!lstrcmpi(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
1173 ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);
1175 if (pUrlCreateFromPathW) {
1176 len = INTERNET_MAX_URL_LENGTH;
1177 pathW = GetWideString(TEST_URLFROMPATH[i].path);
1178 urlW = GetWideString(TEST_URLFROMPATH[i].url);
1179 ret = pUrlCreateFromPathW(pathW, ret_urlW, &len, 0);
1180 WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
1181 ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
1182 ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
1183 ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n",
1184 ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
1185 ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
1186 FreeWideString(urlW);
1187 FreeWideString(pathW);
1192 /* ########################### */
1194 static void test_UrlIs_null(DWORD flag)
1196 BOOL ret;
1197 ret = pUrlIsA(NULL, flag);
1198 ok(ret == FALSE, "pUrlIsA(NULL, %d) failed\n", flag);
1199 ret = pUrlIsW(NULL, flag);
1200 ok(ret == FALSE, "pUrlIsW(NULL, %d) failed\n", flag);
1203 static void test_UrlIs(void)
1205 BOOL ret;
1206 size_t i;
1207 WCHAR wurl[80];
1209 if (!pUrlIsA) {
1210 win_skip("UrlIsA not found\n");
1211 return;
1214 test_UrlIs_null(URLIS_APPLIABLE);
1215 test_UrlIs_null(URLIS_DIRECTORY);
1216 test_UrlIs_null(URLIS_FILEURL);
1217 test_UrlIs_null(URLIS_HASQUERY);
1218 test_UrlIs_null(URLIS_NOHISTORY);
1219 test_UrlIs_null(URLIS_OPAQUE);
1220 test_UrlIs_null(URLIS_URL);
1222 for(i = 0; i < sizeof(TEST_PATH_IS_URL) / sizeof(TEST_PATH_IS_URL[0]); i++) {
1223 MultiByteToWideChar(CP_ACP, 0, TEST_PATH_IS_URL[i].path, -1, wurl, sizeof(wurl)/sizeof(*wurl));
1225 ret = pUrlIsA( TEST_PATH_IS_URL[i].path, URLIS_URL );
1226 ok( ret == TEST_PATH_IS_URL[i].expect,
1227 "returned %d from path %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
1228 TEST_PATH_IS_URL[i].expect );
1230 if (pUrlIsW) {
1231 ret = pUrlIsW( wurl, URLIS_URL );
1232 ok( ret == TEST_PATH_IS_URL[i].expect,
1233 "returned %d from path (UrlIsW) %s, expected %d\n", ret,
1234 TEST_PATH_IS_URL[i].path, TEST_PATH_IS_URL[i].expect );
1237 for(i = 0; i < sizeof(TEST_URLIS_ATTRIBS) / sizeof(TEST_URLIS_ATTRIBS[0]); i++) {
1238 MultiByteToWideChar(CP_ACP, 0, TEST_URLIS_ATTRIBS[i].url, -1, wurl, sizeof(wurl)/sizeof(*wurl));
1240 ret = pUrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_OPAQUE);
1241 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
1242 "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1243 TEST_URLIS_ATTRIBS[i].expectOpaque );
1244 ret = pUrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_FILEURL);
1245 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1246 "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1247 TEST_URLIS_ATTRIBS[i].expectFile );
1249 if (pUrlIsW) {
1250 ret = pUrlIsW( wurl, URLIS_OPAQUE);
1251 ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
1252 "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n",
1253 ret, TEST_URLIS_ATTRIBS[i].url, TEST_URLIS_ATTRIBS[i].expectOpaque );
1254 ret = pUrlIsW( wurl, URLIS_FILEURL);
1255 ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1256 "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n",
1257 ret, TEST_URLIS_ATTRIBS[i].url, TEST_URLIS_ATTRIBS[i].expectFile );
1262 /* ########################### */
1264 static void test_UrlUnescape(void)
1266 CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1267 WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
1268 WCHAR *urlW, *expected_urlW;
1269 DWORD dwEscaped;
1270 size_t i;
1271 static char inplace[] = "file:///C:/Program%20Files";
1272 static char another_inplace[] = "file:///C:/Program%20Files";
1273 static const char expected[] = "file:///C:/Program Files";
1274 static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
1275 static WCHAR another_inplaceW[] ={'f','i','l','e',':','/','/','/',
1276 'C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
1277 HRESULT res;
1279 if (!pUrlUnescapeA) {
1280 win_skip("UrlUnescapeA not found\n");
1281 return;
1283 for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
1284 dwEscaped=INTERNET_MAX_URL_LENGTH;
1285 res = pUrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, &dwEscaped, 0);
1286 ok(res == S_OK,
1287 "UrlUnescapeA returned 0x%x (expected S_OK) for \"%s\"\n",
1288 res, TEST_URL_UNESCAPE[i].url);
1289 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);
1291 ZeroMemory(szReturnUrl, sizeof(szReturnUrl));
1292 /* if we set the buffer pointer to NULL here, UrlUnescape fails and the string is not converted */
1293 res = pUrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, NULL, 0);
1294 ok(res == E_INVALIDARG,
1295 "UrlUnescapeA returned 0x%x (expected E_INVALIDARG) for \"%s\"\n",
1296 res, TEST_URL_UNESCAPE[i].url);
1297 ok(strcmp(szReturnUrl,"")==0, "Expected empty string\n");
1299 if (pUrlUnescapeW) {
1300 dwEscaped = INTERNET_MAX_URL_LENGTH;
1301 urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
1302 expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
1303 res = pUrlUnescapeW(urlW, ret_urlW, &dwEscaped, 0);
1304 ok(res == S_OK,
1305 "UrlUnescapeW returned 0x%x (expected S_OK) for \"%s\"\n",
1306 res, TEST_URL_UNESCAPE[i].url);
1308 WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
1309 ok(lstrcmpW(ret_urlW, expected_urlW)==0,
1310 "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n",
1311 TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url, 0L);
1312 FreeWideString(urlW);
1313 FreeWideString(expected_urlW);
1317 dwEscaped = sizeof(inplace);
1318 res = pUrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE);
1319 ok(res == S_OK, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res);
1320 ok(!strcmp(inplace, expected), "got %s expected %s\n", inplace, expected);
1321 ok(dwEscaped == 27, "got %d expected 27\n", dwEscaped);
1323 /* if we set the buffer pointer to NULL, the string apparently still gets converted (Google Lively does this) */
1324 res = pUrlUnescapeA(another_inplace, NULL, NULL, URL_UNESCAPE_INPLACE);
1325 ok(res == S_OK, "UrlUnescapeA returned 0x%x (expected S_OK)\n", res);
1326 ok(!strcmp(another_inplace, expected), "got %s expected %s\n", another_inplace, expected);
1328 if (pUrlUnescapeW) {
1329 dwEscaped = sizeof(inplaceW);
1330 res = pUrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE);
1331 ok(res == S_OK, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res);
1332 ok(dwEscaped == 50, "got %d expected 50\n", dwEscaped);
1334 /* if we set the buffer pointer to NULL, the string apparently still gets converted (Google Lively does this) */
1335 res = pUrlUnescapeW(another_inplaceW, NULL, NULL, URL_UNESCAPE_INPLACE);
1336 ok(res == S_OK, "UrlUnescapeW returned 0x%x (expected S_OK)\n", res);
1338 ok(lstrlenW(another_inplaceW) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW));
1342 static const struct parse_url_test_t {
1343 const char *url;
1344 HRESULT hres;
1345 UINT protocol_len;
1346 UINT scheme;
1347 } parse_url_tests[] = {
1348 {"http://www.winehq.org/",S_OK,4,URL_SCHEME_HTTP},
1349 {"https://www.winehq.org/",S_OK,5,URL_SCHEME_HTTPS},
1350 {"ftp://www.winehq.org/",S_OK,3,URL_SCHEME_FTP},
1351 {"test.txt?test=c:/dir",URL_E_INVALID_SYNTAX},
1352 {"test.txt",URL_E_INVALID_SYNTAX},
1353 {"xxx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1354 {"1xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1355 {"-xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1356 {"xx0://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1357 {"x://www.winehq.org/",URL_E_INVALID_SYNTAX},
1358 {"xx$://www.winehq.org/",URL_E_INVALID_SYNTAX},
1359 {"htt?p://www.winehq.org/",URL_E_INVALID_SYNTAX},
1360 {"ab-://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1361 {" http://www.winehq.org/",URL_E_INVALID_SYNTAX},
1364 static void test_ParseURL(void)
1366 const struct parse_url_test_t *test;
1367 WCHAR url[INTERNET_MAX_URL_LENGTH];
1368 PARSEDURLA parseda;
1369 PARSEDURLW parsedw;
1370 HRESULT hres;
1372 for(test = parse_url_tests; test < parse_url_tests + sizeof(parse_url_tests)/sizeof(*parse_url_tests); test++) {
1373 memset(&parseda, 0xd0, sizeof(parseda));
1374 parseda.cbSize = sizeof(parseda);
1375 hres = pParseURLA(test->url, &parseda);
1376 ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1377 if(hres == S_OK) {
1378 ok(parseda.pszProtocol == test->url, "parseda.pszProtocol = %s, expected %s\n",
1379 parseda.pszProtocol, test->url);
1380 ok(parseda.cchProtocol == test->protocol_len, "parseda.cchProtocol = %d, expected %d\n",
1381 parseda.cchProtocol, test->protocol_len);
1382 ok(parseda.pszSuffix == test->url+test->protocol_len+1, "parseda.pszSuffix = %s, expected %s\n",
1383 parseda.pszSuffix, test->url+test->protocol_len+1);
1384 ok(parseda.cchSuffix == strlen(test->url+test->protocol_len+1),
1385 "parseda.pszSuffix = %d, expected %d\n",
1386 parseda.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1387 ok(parseda.nScheme == test->scheme, "parseda.nScheme = %d, expected %d\n",
1388 parseda.nScheme, test->scheme);
1389 }else {
1390 ok(!parseda.pszProtocol, "parseda.pszProtocol = %p\n", parseda.pszProtocol);
1391 ok(parseda.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parseda.nScheme);
1394 MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, sizeof(url)/sizeof(WCHAR));
1396 memset(&parsedw, 0xd0, sizeof(parsedw));
1397 parsedw.cbSize = sizeof(parsedw);
1398 hres = pParseURLW(url, &parsedw);
1399 ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1400 if(hres == S_OK) {
1401 ok(parsedw.pszProtocol == url, "parsedw.pszProtocol = %s, expected %s\n",
1402 wine_dbgstr_w(parsedw.pszProtocol), wine_dbgstr_w(url));
1403 ok(parsedw.cchProtocol == test->protocol_len, "parsedw.cchProtocol = %d, expected %d\n",
1404 parsedw.cchProtocol, test->protocol_len);
1405 ok(parsedw.pszSuffix == url+test->protocol_len+1, "parsedw.pszSuffix = %s, expected %s\n",
1406 wine_dbgstr_w(parsedw.pszSuffix), wine_dbgstr_w(url+test->protocol_len+1));
1407 ok(parsedw.cchSuffix == strlen(test->url+test->protocol_len+1),
1408 "parsedw.pszSuffix = %d, expected %d\n",
1409 parsedw.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1410 ok(parsedw.nScheme == test->scheme, "parsedw.nScheme = %d, expected %d\n",
1411 parsedw.nScheme, test->scheme);
1412 }else {
1413 ok(!parsedw.pszProtocol, "parsedw.pszProtocol = %p\n", parseda.pszProtocol);
1414 ok(parsedw.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parsedw.nScheme);
1419 static void test_HashData(void)
1421 HRESULT res;
1422 BYTE input[16] = {0x51, 0x33, 0x4F, 0xA7, 0x45, 0x15, 0xF0, 0x52, 0x90,
1423 0x2B, 0xE7, 0xF5, 0xFD, 0xE1, 0xA6, 0xA7};
1424 BYTE output[32];
1425 static const BYTE expected[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1426 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1427 0xE3, 0x2D};
1428 static const BYTE expected2[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1429 0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1430 0xE3, 0x2D, 0x47, 0xFC, 0x80, 0xB8, 0xD0,
1431 0x49, 0xE6, 0x13, 0x2A, 0x30, 0x51, 0x8D,
1432 0xF9, 0x4B, 0x07, 0xA6};
1433 static const BYTE expected3[] = {0x2B, 0xDC, 0x9A, 0x1B, 0xF0, 0x5A, 0xF9,
1434 0xC6, 0xBE, 0x94, 0x6D, 0xF3, 0x33, 0xC1,
1435 0x36, 0x07};
1436 int i;
1438 /* Test hashing with identically sized input/output buffers. */
1439 res = pHashData(input, 16, output, 16);
1440 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1441 if(res == S_OK)
1442 ok(!memcmp(output, expected, sizeof(expected)),
1443 "Output buffer did not match expected contents\n");
1445 /* Test hashing with larger output buffer. */
1446 res = pHashData(input, 16, output, 32);
1447 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1448 if(res == S_OK)
1449 ok(!memcmp(output, expected2, sizeof(expected2)),
1450 "Output buffer did not match expected contents\n");
1452 /* Test hashing with smaller input buffer. */
1453 res = pHashData(input, 8, output, 16);
1454 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1455 if(res == S_OK)
1456 ok(!memcmp(output, expected3, sizeof(expected3)),
1457 "Output buffer did not match expected contents\n");
1459 /* Test passing NULL pointers for input/output parameters. */
1460 res = pHashData(NULL, 0, NULL, 0);
1461 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1462 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1464 res = pHashData(input, 0, NULL, 0);
1465 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1466 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1468 res = pHashData(NULL, 0, output, 0);
1469 ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1470 "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1472 /* Test passing valid pointers with sizes of zero. */
1473 for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1474 input[i] = 0x00;
1476 for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1477 output[i] = 0xFF;
1479 res = pHashData(input, 0, output, 0);
1480 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1482 /* The buffers should be unchanged. */
1483 for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1485 ok(input[i] == 0x00, "Expected the input buffer to be unchanged\n");
1486 if(input[i] != 0x00) break;
1489 for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1491 ok(output[i] == 0xFF, "Expected the output buffer to be unchanged\n");
1492 if(output[i] != 0xFF) break;
1495 /* Input/output parameters are not validated. */
1496 res = pHashData((BYTE *)0xdeadbeef, 0, (BYTE *)0xdeadbeef, 0);
1497 ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1499 if (0)
1501 res = pHashData((BYTE *)0xdeadbeef, 1, (BYTE *)0xdeadbeef, 1);
1502 trace("HashData returned 0x%08x\n", res);
1506 /* ########################### */
1508 START_TEST(url)
1510 char *pFunc;
1512 hShlwapi = GetModuleHandleA("shlwapi.dll");
1514 /* SHCreateStreamOnFileEx was introduced in shlwapi v6.0 */
1515 pFunc = (void*)GetProcAddress(hShlwapi, "SHCreateStreamOnFileEx");
1516 if(!pFunc){
1517 win_skip("Too old shlwapi version\n");
1518 return;
1521 pUrlUnescapeA = (void *) GetProcAddress(hShlwapi, "UrlUnescapeA");
1522 pUrlUnescapeW = (void *) GetProcAddress(hShlwapi, "UrlUnescapeW");
1523 pUrlIsA = (void *) GetProcAddress(hShlwapi, "UrlIsA");
1524 pUrlIsW = (void *) GetProcAddress(hShlwapi, "UrlIsW");
1525 pUrlHashA = (void *) GetProcAddress(hShlwapi, "UrlHashA");
1526 pUrlHashW = (void *) GetProcAddress(hShlwapi, "UrlHashW");
1527 pUrlGetPartA = (void *) GetProcAddress(hShlwapi, "UrlGetPartA");
1528 pUrlGetPartW = (void *) GetProcAddress(hShlwapi, "UrlGetPartW");
1529 pUrlEscapeA = (void *) GetProcAddress(hShlwapi, "UrlEscapeA");
1530 pUrlEscapeW = (void *) GetProcAddress(hShlwapi, "UrlEscapeW");
1531 pUrlCreateFromPathA = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathA");
1532 pUrlCreateFromPathW = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathW");
1533 pUrlCombineA = (void *) GetProcAddress(hShlwapi, "UrlCombineA");
1534 pUrlCombineW = (void *) GetProcAddress(hShlwapi, "UrlCombineW");
1535 pUrlCanonicalizeA = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeA");
1536 pUrlCanonicalizeW = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeW");
1537 pUrlApplySchemeA = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeA");
1538 pUrlApplySchemeW = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeW");
1539 pParseURLA = (void*)GetProcAddress(hShlwapi, (LPCSTR)1);
1540 pParseURLW = (void*)GetProcAddress(hShlwapi, (LPCSTR)2);
1541 pHashData = (void*)GetProcAddress(hShlwapi, "HashData");
1543 test_UrlApplyScheme();
1544 test_UrlHash();
1545 test_UrlGetPart();
1546 test_UrlCanonicalizeA();
1547 test_UrlCanonicalizeW();
1548 test_UrlEscape();
1549 test_UrlCombine();
1550 test_UrlCreateFromPath();
1551 test_UrlIs();
1552 test_UrlUnescape();
1553 test_ParseURL();
1554 test_HashData();