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