shlwapi/tests: UrlEscape* is not present on Win95B (winetestbot).
[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 *pUrlEscapeA)(LPCSTR,LPSTR,LPDWORD,DWORD);
35 static HRESULT (WINAPI *pUrlEscapeW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
36 static HRESULT (WINAPI *pUrlCreateFromPathA)(LPCSTR,LPSTR,LPDWORD,DWORD);
37 static HRESULT (WINAPI *pUrlCreateFromPathW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
38 static HRESULT (WINAPI *pUrlCombineA)(LPCSTR,LPCSTR,LPSTR,LPDWORD,DWORD);
39 static HRESULT (WINAPI *pUrlCombineW)(LPCWSTR,LPCWSTR,LPWSTR,LPDWORD,DWORD);
40 static HRESULT (WINAPI *pUrlCanonicalizeA)(LPCSTR, LPSTR, LPDWORD, DWORD);
41 static HRESULT (WINAPI *pUrlCanonicalizeW)(LPCWSTR, LPWSTR, LPDWORD, DWORD);
42 static HRESULT (WINAPI *pUrlApplySchemeA)(LPCSTR,LPSTR,LPDWORD,DWORD);
43 static HRESULT (WINAPI *pUrlApplySchemeW)(LPCWSTR,LPWSTR,LPDWORD,DWORD);
44 static HRESULT (WINAPI *pParseURLA)(LPCSTR,PARSEDURLA*);
45 static HRESULT (WINAPI *pParseURLW)(LPCWSTR,PARSEDURLW*);
46 static HRESULT (WINAPI *pHashData)(LPBYTE, DWORD, LPBYTE, DWORD);
47
48 static const char* TEST_URL_1 = "http://www.winehq.org/tests?date=10/10/1923";
49 static const char* TEST_URL_2 = "http://localhost:8080/tests%2e.html?date=Mon%2010/10/1923";
50 static const char* TEST_URL_3 = "http://foo:bar@localhost:21/internal.php?query=x&return=y";
51 static const WCHAR winehqW[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
52 static const  CHAR winehqA[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/',0};
53
54 /* ################ */
55
56 static const CHAR untouchedA[] = "untouched";
57
58 #define TEST_APPLY_MAX_LENGTH INTERNET_MAX_URL_LENGTH
59
60 typedef struct _TEST_URL_APPLY {
61     const char * url;
62     DWORD flags;
63     HRESULT res;
64     DWORD newlen;
65     const char * newurl;
66 } TEST_URL_APPLY;
67
68 static const TEST_URL_APPLY TEST_APPLY[] = {
69     {"www.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
70     {"www.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 21, "http://www.winehq.org"},
71     {"www.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://www.winehq.org"},
72     {"ftp.winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 20, "ftp://ftp.winehq.org"},
73     {"ftp.winehq.org", URL_APPLY_GUESSSCHEME, S_OK, 20, "ftp://ftp.winehq.org"},
74     {"ftp.winehq.org", URL_APPLY_DEFAULT, S_OK, 21, "http://ftp.winehq.org"},
75     {"winehq.org", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
76     {"winehq.org", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
77     {"winehq.org", URL_APPLY_DEFAULT, S_OK, 17, "http://winehq.org"},
78     {"", URL_APPLY_GUESSSCHEME | URL_APPLY_DEFAULT, S_OK, 7, "http://"},
79     {"", URL_APPLY_GUESSSCHEME, S_FALSE, TEST_APPLY_MAX_LENGTH, untouchedA},
80     {"", URL_APPLY_DEFAULT, S_OK, 7, "http://"}
81 };
82
83 /* ################ */
84
85 typedef struct _TEST_URL_CANONICALIZE {
86     const char *url;
87     DWORD flags;
88     HRESULT expectret;
89     const char *expecturl;
90     BOOL todo;
91 } TEST_URL_CANONICALIZE;
92
93 static const TEST_URL_CANONICALIZE TEST_CANONICALIZE[] = {
94     {"http://www.winehq.org/tests/../tests/../..", 0, S_OK, "http://www.winehq.org/", TRUE},
95     {"http://www.winehq.org/tests/../tests", 0, S_OK, "http://www.winehq.org/tests", FALSE},
96     {"http://www.winehq.org/tests\n", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
97     {"http://www.winehq.org/tests\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, S_OK, "http://www.winehq.org/tests", FALSE},
98     {"http://www.winehq.org/tests\r", 0, S_OK, "http://www.winehq.org/tests", FALSE},
99     {"http://www.winehq.org/tests\r", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests", FALSE},
100     {"http://www.winehq.org/tests/../tests/", 0, S_OK, "http://www.winehq.org/tests/", FALSE},
101     {"http://www.winehq.org/tests/../tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
102     {"http://www.winehq.org/tests/../tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
103     {"http://www.winehq.org/tests/..", 0, S_OK, "http://www.winehq.org/", FALSE},
104     {"http://www.winehq.org/tests/../", 0, S_OK, "http://www.winehq.org/", FALSE},
105     {"http://www.winehq.org/tests/..?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
106     {"http://www.winehq.org/tests/../?query=x&return=y", 0, S_OK, "http://www.winehq.org/?query=x&return=y", FALSE},
107     {"http://www.winehq.org/tests/..#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
108     {"http://www.winehq.org/tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
109     {"http://www.winehq.org/tests\\../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
110     {"http://www.winehq.org/tests/..\\#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
111     {"http://www.winehq.org\\tests/../#example", 0, S_OK, "http://www.winehq.org/#example", FALSE},
112     {"http://www.winehq.org/tests/../#example", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../#example", FALSE},
113     {"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},
114     {"http://www.winehq.org/tests/foo%20bar", URL_UNESCAPE , S_OK, "http://www.winehq.org/tests/foo bar", FALSE},
115     {"file:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
116     {"file:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "file:///c:/tests/foo bar", FALSE},
117     {"file:///c:/tests/foo%20bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
118     {"file:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
119     {"file://localhost/c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
120     {"file://localhost\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
121     {"file://localhost\\\\c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
122     {"file://localhost\\c:\\tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
123     {"file://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
124     {"file://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
125     {"file://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
126     {"file:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\\\tests\\foo bar", FALSE},
127     {"file:///c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo bar", FALSE},
128     {"file:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "file:///c:/tests/foo bar", FALSE},
129     {"http://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/site/about", FALSE},
130     {"file_://www.winehq.org/site/about", URL_FILE_USE_PATHURL, S_OK, "file_://www.winehq.org/site/about", FALSE},
131     {"c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
132     {"file:///c:\\dir\\file", 0, S_OK, "file:///c:/dir/file", FALSE},
133     {"c:dir\\file", 0, S_OK, "file:///c:dir/file", FALSE},
134     {"c:\\tests\\foo bar", URL_FILE_USE_PATHURL, S_OK, "file://c:\\tests\\foo bar", FALSE},
135     {"c:\\tests\\foo bar", 0, S_OK, "file:///c:/tests/foo%20bar", FALSE},
136     {"res://file", 0, S_OK, "res://file/", FALSE},
137     {"res://file", URL_FILE_USE_PATHURL, S_OK, "res://file/", FALSE},
138     {"res:///c:/tests/foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests/foo bar", FALSE},
139     {"res:///c:/tests\\foo%20bar", URL_UNESCAPE , S_OK, "res:///c:/tests\\foo bar", FALSE},
140     {"res:///c:/tests/foo%20bar", 0, S_OK, "res:///c:/tests/foo%20bar", FALSE},
141     {"res:///c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c:/tests/foo%20bar", FALSE},
142     {"res://c:/tests/../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
143     {"res://c:/tests\\../tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
144     {"res://c:/tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res://c:/tests/foo%20bar", FALSE},
145     {"res:///c://tests/foo%20bar", URL_FILE_USE_PATHURL, S_OK, "res:///c://tests/foo%20bar", FALSE},
146     {"res:///c:\\tests\\foo bar", 0, S_OK, "res:///c:\\tests\\foo bar", FALSE},
147     {"res:///c:\\tests\\foo bar", URL_DONT_SIMPLIFY, S_OK, "res:///c:\\tests\\foo bar", FALSE},
148     {"res://c:\\tests\\foo bar/res", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests\\foo bar/res", FALSE},
149     {"res://c:\\tests/res\\foo%20bar/strange\\sth", 0, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
150     {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_FILE_USE_PATHURL, S_OK, "res://c:\\tests/res\\foo%20bar/strange\\sth", FALSE},
151     {"res://c:\\tests/res\\foo%20bar/strange\\sth", URL_UNESCAPE, S_OK, "res://c:\\tests/res\\foo bar/strange\\sth", FALSE},
152     {"A", 0, S_OK, "A", FALSE},
153     {"/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*/,
154     {"http:www.winehq.org/dir/../index.html", 0, S_OK, "http:www.winehq.org/index.html"},
155 };
156
157 /* ################ */
158
159 typedef struct _TEST_URL_ESCAPE {
160     const char *url;
161     DWORD flags;
162     DWORD expectescaped;
163     HRESULT expectret;
164     const char *expecturl;
165 } TEST_URL_ESCAPE;
166
167 static const TEST_URL_ESCAPE TEST_ESCAPE[] = {
168     {"http://www.winehq.org/tests0", 0, 0, S_OK, "http://www.winehq.org/tests0"},
169     {"http://www.winehq.org/tests1\n", 0, 0, S_OK, "http://www.winehq.org/tests1%0A"},
170     {"http://www.winehq.org/tests2\r", 0, 0, S_OK, "http://www.winehq.org/tests2%0D"},
171     {"http://www.winehq.org/tests3\r", URL_ESCAPE_SPACES_ONLY|URL_ESCAPE_UNSAFE, 0, S_OK, "http://www.winehq.org/tests3\r"},
172     {"http://www.winehq.org/tests4\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests4\r"},
173     {"http://www.winehq.org/tests5\r", URL_WININET_COMPATIBILITY|URL_ESCAPE_SPACES_ONLY, 0, S_OK, "http://www.winehq.org/tests5\r"},
174     {"/direct/swhelp/series6/6.2i_latestservicepack.dat\r", URL_ESCAPE_SPACES_ONLY, 0, S_OK, "/direct/swhelp/series6/6.2i_latestservicepack.dat\r"},
175
176     {"file://////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
177     {"file://///foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
178     {"file:////foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
179     {"file:///localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
180     {"file:///foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
181     {"file://loCalHost/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
182     {"file://foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
183     {"file:/localhost/foo/bar\\baz", 0, 0, S_OK, "file:///localhost/foo/bar/baz"},
184     {"file:/foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
185     {"file:foo/bar\\baz", 0, 0, S_OK, "file:foo/bar/baz"},
186     {"file:\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
187     {"file:\\\\foo/bar\\baz", 0, 0, S_OK, "file://foo/bar/baz"},
188     {"file:\\\\\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
189     {"file:\\\\localhost\\foo/bar\\baz", 0, 0, S_OK, "file:///foo/bar/baz"},
190     {"file:///f oo/b?a r\\baz", 0, 0, S_OK, "file:///f%20oo/b?a r\\baz"},
191     {"file:///foo/b#a r\\baz", 0, 0, S_OK, "file:///foo/b%23a%20r/baz"},
192     {"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"},
193     {"file:///f o%o/b?a r\\b%az", URL_ESCAPE_PERCENT, 0, S_OK, "file:///f%20o%25o/b?a r\\b%az"},
194     {"file:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "file:%2Ffoo%2Fbar%5Cbaz"},
195
196     {"foo/b%ar\\ba?z\\", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%ar%5Cba%3Fz%5C"},
197     {"foo/b%ar\\ba?z\\", URL_ESCAPE_PERCENT | URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "foo%2Fb%25ar%5Cba%3Fz%5C"},
198     {"foo/bar\\ba?z\\", 0, 0, S_OK, "foo/bar%5Cba?z\\"},
199     {"/foo/bar\\ba?z\\", 0, 0, S_OK, "/foo/bar%5Cba?z\\"},
200     {"/foo/bar\\ba#z\\", 0, 0, S_OK, "/foo/bar%5Cba#z\\"},
201     {"/foo/%5C", 0, 0, S_OK, "/foo/%5C"},
202     {"/foo/%5C", URL_ESCAPE_PERCENT, 0, S_OK, "/foo/%255C"},
203
204     {"http://////foo/bar\\baz", 0, 0, S_OK, "http://////foo/bar/baz"},
205     {"http://///foo/bar\\baz", 0, 0, S_OK, "http://///foo/bar/baz"},
206     {"http:////foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
207     {"http:///foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
208     {"http://localhost/foo/bar\\baz", 0, 0, S_OK, "http://localhost/foo/bar/baz"},
209     {"http://foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
210     {"http:/foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
211     {"http:foo/bar\\ba?z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba?z\\"},
212     {"http:foo/bar\\ba#z\\", 0, 0, S_OK, "http:foo%2Fbar%2Fba#z\\"},
213     {"http:\\foo/bar\\baz", 0, 0, S_OK, "http:/foo/bar/baz"},
214     {"http:\\\\foo/bar\\baz", 0, 0, S_OK, "http://foo/bar/baz"},
215     {"http:\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:///foo/bar/baz"},
216     {"http:\\\\\\\\foo/bar\\baz", 0, 0, S_OK, "http:////foo/bar/baz"},
217     {"http:/fo ?o/b ar\\baz", 0, 0, S_OK, "http:/fo%20?o/b ar\\baz"},
218     {"http:fo ?o/b ar\\baz", 0, 0, S_OK, "http:fo%20?o/b ar\\baz"},
219     {"http:/foo/bar\\baz", URL_ESCAPE_SEGMENT_ONLY, 0, S_OK, "http:%2Ffoo%2Fbar%5Cbaz"},
220
221     {"https://foo/bar\\baz", 0, 0, S_OK, "https://foo/bar/baz"},
222     {"https:/foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
223     {"https:\\foo/bar\\baz", 0, 0, S_OK, "https:/foo/bar/baz"},
224
225     {"foo:////foo/bar\\baz", 0, 0, S_OK, "foo:////foo/bar%5Cbaz"},
226     {"foo:///foo/bar\\baz", 0, 0, S_OK, "foo:///foo/bar%5Cbaz"},
227     {"foo://localhost/foo/bar\\baz", 0, 0, S_OK, "foo://localhost/foo/bar%5Cbaz"},
228     {"foo://foo/bar\\baz", 0, 0, S_OK, "foo://foo/bar%5Cbaz"},
229     {"foo:/foo/bar\\baz", 0, 0, S_OK, "foo:/foo/bar%5Cbaz"},
230     {"foo:foo/bar\\baz", 0, 0, S_OK, "foo:foo%2Fbar%5Cbaz"},
231     {"foo:\\foo/bar\\baz", 0, 0, S_OK, "foo:%5Cfoo%2Fbar%5Cbaz"},
232     {"foo:/foo/bar\\ba?\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba?\\z"},
233     {"foo:/foo/bar\\ba#\\z", 0, 0, S_OK, "foo:/foo/bar%5Cba#\\z"},
234
235     {"mailto:/fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:%2Ffo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
236     {"mailto:fo/o@b\\%a?\\r.b#\\az", 0, 0, S_OK, "mailto:fo%2Fo@b%5C%a%3F%5Cr.b%23%5Caz"},
237     {"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"},
238
239     {"ftp:fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:fo%2Fo@bar.baz%2Ffoo%2Fbar"},
240     {"ftp:/fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:/fo/o@bar.baz/foo/bar"},
241     {"ftp://fo/o@bar.baz/fo?o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo?o\\bar"},
242     {"ftp://fo/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://fo/o@bar.baz/fo#o\\bar"},
243     {"ftp://localhost/o@bar.baz/fo#o\\bar", 0, 0, S_OK, "ftp://localhost/o@bar.baz/fo#o\\bar"},
244     {"ftp:///fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:///fo/o@bar.baz/foo/bar"},
245     {"ftp:////fo/o@bar.baz/foo/bar", 0, 0, S_OK, "ftp:////fo/o@bar.baz/foo/bar"}
246 };
247
248 /* ################ */
249
250 typedef struct _TEST_URL_COMBINE {
251     const char *url1;
252     const char *url2;
253     DWORD flags;
254     HRESULT expectret;
255     const char *expecturl;
256 } TEST_URL_COMBINE;
257
258 static const TEST_URL_COMBINE TEST_COMBINE[] = {
259     {"http://www.winehq.org/tests", "tests1", 0, S_OK, "http://www.winehq.org/tests1"},
260     {"http://www.%77inehq.org/tests", "tests1", 0, S_OK, "http://www.%77inehq.org/tests1"},
261     /*FIXME {"http://www.winehq.org/tests", "../tests2", 0, S_OK, "http://www.winehq.org/tests2"},*/
262     {"http://www.winehq.org/tests/", "../tests3", 0, S_OK, "http://www.winehq.org/tests3"},
263     {"http://www.winehq.org/tests/test1", "test2", 0, S_OK, "http://www.winehq.org/tests/test2"},
264     {"http://www.winehq.org/tests/../tests", "tests4", 0, S_OK, "http://www.winehq.org/tests4"},
265     {"http://www.winehq.org/tests/../tests/", "tests5", 0, S_OK, "http://www.winehq.org/tests/tests5"},
266     {"http://www.winehq.org/tests/../tests/", "/tests6/..", 0, S_OK, "http://www.winehq.org/"},
267     {"http://www.winehq.org/tests/../tests/..", "tests7/..", 0, S_OK, "http://www.winehq.org/"},
268     {"http://www.winehq.org/tests/?query=x&return=y", "tests8", 0, S_OK, "http://www.winehq.org/tests/tests8"},
269     {"http://www.winehq.org/tests/#example", "tests9", 0, S_OK, "http://www.winehq.org/tests/tests9"},
270     {"http://www.winehq.org/tests/../tests/", "/tests10/..", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests10/.."},
271     {"http://www.winehq.org/tests/../", "tests11", URL_DONT_SIMPLIFY, S_OK, "http://www.winehq.org/tests/../tests11"},
272     {"file:///C:\\dir\\file.txt", "test.txt", 0, S_OK, "file:///C:/dir/test.txt"},
273     {"C:\\winehq\\winehq.txt", "C:\\Test\\test.txt", 0, S_OK, "file:///C:/Test/test.txt"},
274     {"http://www.winehq.org/test/", "test%20file.txt", 0, S_OK, "http://www.winehq.org/test/test%20file.txt"},
275     {"http://www.winehq.org/test/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org/test/test%20file.txt"},
276     {"http://www.winehq.org%2ftest/", "test%20file.txt", URL_FILE_USE_PATHURL, S_OK, "http://www.winehq.org%2ftest/test%20file.txt"},
277     {"xxx:@MSITStore:file.chm/file.html", "dir/file", 0, S_OK, "xxx:dir/file"},
278     {"mk:@MSITStore:file.chm::/file.html", "/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
279     {"mk:@MSITStore:file.chm::/file.html", "mk:@MSITStore:file.chm::/dir/file", 0, S_OK, "mk:@MSITStore:file.chm::/dir/file"},
280     {"foo:today", "foo:calendar", 0, S_OK, "foo:calendar"},
281     {"foo:today", "bar:calendar", 0, S_OK, "bar:calendar"},
282     {"foo:/today", "foo:calendar", 0, S_OK, "foo:/calendar"},
283     {"foo:/today/", "foo:calendar", 0, S_OK, "foo:/today/calendar"},
284     {"mk:@MSITStore:dir/test.chm::dir/index.html", "image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
285     {"mk:@MSITStore:dir/test.chm::dir/dir2/index.html", "../image.jpg", 0, S_OK, "mk:@MSITStore:dir/test.chm::dir/image.jpg"},
286     /* UrlCombine case 2 tests.  Schemes do not match */
287     {"outbind://xxxxxxxxx","http://wine1/dir",0, S_OK,"http://wine1/dir"},
288     {"xxxx://xxxxxxxxx","http://wine2/dir",0, S_OK,"http://wine2/dir"},
289     {"ftp://xxxxxxxxx/","http://wine3/dir",0, S_OK,"http://wine3/dir"},
290     {"outbind://xxxxxxxxx","http://wine4/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine4/dir"},
291     {"xxx://xxxxxxxxx","http://wine5/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine5/dir"},
292     {"ftp://xxxxxxxxx/","http://wine6/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http://wine6/dir"},
293     {"http://xxxxxxxxx","outbind://wine7/dir",0, S_OK,"outbind://wine7/dir"},
294     {"xxx://xxxxxxxxx","ftp://wine8/dir",0, S_OK,"ftp://wine8/dir"},
295     {"ftp://xxxxxxxxx/","xxx://wine9/dir",0, S_OK,"xxx://wine9/dir"},
296     {"http://xxxxxxxxx","outbind://wine10/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind://wine10/dir"},
297     {"xxx://xxxxxxxxx","ftp://wine11/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp://wine11/dir"},
298     {"ftp://xxxxxxxxx/","xxx://wine12/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx://wine12/dir"},
299     {"http://xxxxxxxxx","outbind:wine13/dir",0, S_OK,"outbind:wine13/dir"},
300     {"xxx://xxxxxxxxx","ftp:wine14/dir",0, S_OK,"ftp:wine14/dir"},
301     {"ftp://xxxxxxxxx/","xxx:wine15/dir",0, S_OK,"xxx:wine15/dir"},
302     {"outbind://xxxxxxxxx/","http:wine16/dir",0, S_OK,"http:wine16/dir"},
303     {"http://xxxxxxxxx","outbind:wine17/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"outbind:wine17/dir"},
304     {"xxx://xxxxxxxxx","ftp:wine18/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"ftp:wine18/dir"},
305     {"ftp://xxxxxxxxx/","xxx:wine19/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"xxx:wine19/dir"},
306     {"outbind://xxxxxxxxx/","http:wine20/dir",URL_PLUGGABLE_PROTOCOL, S_OK,"http:wine20/dir"},
307     {"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"}
308 };
309
310 /* ################ */
311
312 static const struct {
313     const char *path;
314     const char *url;
315     DWORD ret;
316 } TEST_URLFROMPATH [] = {
317     {"foo", "file:foo", S_OK},
318     {"foo\\bar", "file:foo/bar", S_OK},
319     {"\\foo\\bar", "file:///foo/bar", S_OK},
320     {"c:\\foo\\bar", "file:///c:/foo/bar", S_OK},
321     {"c:foo\\bar", "file:///c:foo/bar", S_OK},
322     {"c:\\foo/b a%r", "file:///c:/foo/b%20a%25r", S_OK},
323     {"c:\\foo\\foo bar", "file:///c:/foo/foo%20bar", S_OK},
324 #if 0
325     /* The following test fails on native shlwapi as distributed with Win95/98.
326      * Wine matches the behaviour of later versions.
327      */
328     {"xx:c:\\foo\\bar", "xx:c:\\foo\\bar", S_FALSE}
329 #endif
330 };
331
332 /* ################ */
333
334 static struct {
335     char url[30];
336     const char *expect;
337 } TEST_URL_UNESCAPE[] = {
338     {"file://foo/bar", "file://foo/bar"},
339     {"file://fo%20o%5Ca/bar", "file://fo o\\a/bar"},
340     {"file://%24%25foobar", "file://$%foobar"}
341 };
342
343 /* ################ */
344
345 static const  struct {
346     const char *path;
347     BOOL expect;
348 } TEST_PATH_IS_URL[] = {
349     {"http://foo/bar", TRUE},
350     {"c:\\foo\\bar", FALSE},
351     {"foo://foo/bar", TRUE},
352     {"foo\\bar", FALSE},
353     {"foo.bar", FALSE},
354     {"bogusscheme:", TRUE},
355     {"http:partial", TRUE}
356 };
357
358 /* ################ */
359
360 static const struct {
361     const char *url;
362     BOOL expectOpaque;
363     BOOL expectFile;
364 } TEST_URLIS_ATTRIBS[] = {
365     {   "ftp:",                                         FALSE,  FALSE   },
366     {   "http:",                                        FALSE,  FALSE   },
367     {   "gopher:",                                      FALSE,  FALSE   },
368     {   "mailto:",                                      TRUE,   FALSE   },
369     {   "news:",                                        FALSE,  FALSE   },
370     {   "nntp:",                                        FALSE,  FALSE   },
371     {   "telnet:",                                      FALSE,  FALSE   },
372     {   "wais:",                                        FALSE,  FALSE   },
373     {   "file:",                                        FALSE,  TRUE    },
374     {   "mk:",                                          FALSE,  FALSE   },
375     {   "https:",                                       FALSE,  FALSE   },
376     {   "shell:",                                       TRUE,   FALSE   },
377     {   "https:",                                       FALSE,  FALSE   },
378     {   "snews:",                                       FALSE,  FALSE   },
379     {   "local:",                                       FALSE,  FALSE   },
380     {   "javascript:",                                  TRUE,   FALSE   },
381     {   "vbscript:",                                    TRUE,   FALSE   },
382     {   "about:",                                       TRUE,   FALSE   },
383     {   "res:",                                         FALSE,  FALSE   },
384     {   "bogusscheme:",                                 FALSE,  FALSE   },
385     {   "file:\\\\e:\\b\\c",                            FALSE,  TRUE    },
386     {   "file://e:/b/c",                                FALSE,  TRUE    },
387     {   "http:partial",                                 FALSE,  FALSE   },
388     {   "mailto://www.winehq.org/test.html",            TRUE,   FALSE   },
389     {   "file:partial",                                 FALSE,  TRUE    }
390 };
391
392 /* ########################### */
393
394 static LPWSTR GetWideString(const char* szString)
395 {
396   LPWSTR wszString = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR));
397
398   MultiByteToWideChar(0, 0, szString, -1, wszString, INTERNET_MAX_URL_LENGTH);
399
400   return wszString;
401 }
402
403
404 static void FreeWideString(LPWSTR wszString)
405 {
406    HeapFree(GetProcessHeap(), 0, wszString);
407 }
408
409 /* ########################### */
410
411 static void test_UrlApplyScheme(void)
412 {
413     CHAR newurl[TEST_APPLY_MAX_LENGTH];
414     WCHAR urlW[TEST_APPLY_MAX_LENGTH];
415     WCHAR newurlW[TEST_APPLY_MAX_LENGTH];
416     HRESULT res;
417     DWORD len;
418     DWORD i;
419
420     if (!pUrlApplySchemeA) {
421         win_skip("UrlApplySchemeA not found\n");
422         return;
423     }
424
425     for(i = 0; i < sizeof(TEST_APPLY)/sizeof(TEST_APPLY[0]); i++) {
426         len = TEST_APPLY_MAX_LENGTH;
427         lstrcpyA(newurl, untouchedA);
428         res = pUrlApplySchemeA(TEST_APPLY[i].url, newurl, &len, TEST_APPLY[i].flags);
429         ok( res == TEST_APPLY[i].res,
430             "#%dA: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
431
432         ok( len == TEST_APPLY[i].newlen,
433             "#%dA: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
434
435         ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
436             "#%dA: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
437
438         /* returned length is in character */
439         len = TEST_APPLY_MAX_LENGTH;
440         lstrcpyA(newurl, untouchedA);
441         MultiByteToWideChar(CP_ACP, 0, newurl, -1, newurlW, len);
442         MultiByteToWideChar(CP_ACP, 0, TEST_APPLY[i].url, -1, urlW, len);
443
444         res = pUrlApplySchemeW(urlW, newurlW, &len, TEST_APPLY[i].flags);
445         WideCharToMultiByte(CP_ACP, 0, newurlW, -1, newurl, TEST_APPLY_MAX_LENGTH, NULL, NULL);
446         ok( res == TEST_APPLY[i].res,
447             "#%dW: got HRESULT 0x%x (expected 0x%x)\n", i, res, TEST_APPLY[i].res);
448
449         ok( len == TEST_APPLY[i].newlen,
450             "#%dW: got len %d (expected %d)\n", i, len, TEST_APPLY[i].newlen);
451
452         ok( !lstrcmpA(newurl, TEST_APPLY[i].newurl),
453             "#%dW: got '%s' (expected '%s')\n", i, newurl, TEST_APPLY[i].newurl);
454
455     }
456
457     /* buffer too small */
458     lstrcpyA(newurl, untouchedA);
459     len = lstrlenA(TEST_APPLY[0].newurl);
460     res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, &len, TEST_APPLY[0].flags);
461     ok(res == E_POINTER, "got HRESULT 0x%x (expected E_POINTER)\n", res);
462     /* The returned length include the space for the terminating 0 */
463     i = lstrlenA(TEST_APPLY[0].newurl)+1;
464     ok(len == i, "got len %d (expected %d)\n", len, i);
465     ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
466
467     /* NULL as parameter. The length and the buffer are not modified */
468     lstrcpyA(newurl, untouchedA);
469     len = TEST_APPLY_MAX_LENGTH;
470     res = pUrlApplySchemeA(NULL, newurl, &len, TEST_APPLY[0].flags);
471     ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
472     ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
473     ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
474
475     len = TEST_APPLY_MAX_LENGTH;
476     res = pUrlApplySchemeA(TEST_APPLY[0].url, NULL, &len, TEST_APPLY[0].flags);
477     ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
478     ok(len == TEST_APPLY_MAX_LENGTH, "got len %d\n", len);
479
480     lstrcpyA(newurl, untouchedA);
481     res = pUrlApplySchemeA(TEST_APPLY[0].url, newurl, NULL, TEST_APPLY[0].flags);
482     ok(res == E_INVALIDARG, "got HRESULT 0x%x (expected E_INVALIDARG)\n", res);
483     ok(!lstrcmpA(newurl, untouchedA), "got '%s' (expected '%s')\n", newurl, untouchedA);
484
485 }
486
487 /* ########################### */
488
489 static void hash_url(const char* szUrl)
490 {
491   LPCSTR szTestUrl = szUrl;
492   LPWSTR wszTestUrl = GetWideString(szTestUrl);
493
494   DWORD cbSize = sizeof(DWORD);
495   DWORD dwHash1, dwHash2;
496   ok(UrlHashA(szTestUrl, (LPBYTE)&dwHash1, cbSize) == S_OK, "UrlHashA didn't return S_OK\n");
497   ok(UrlHashW(wszTestUrl, (LPBYTE)&dwHash2, cbSize) == S_OK, "UrlHashW didn't return S_OK\n");
498
499   FreeWideString(wszTestUrl);
500
501   ok(dwHash1 == dwHash2, "Hashes didn't compare\n");
502 }
503
504 static void test_UrlHash(void)
505 {
506   hash_url(TEST_URL_1);
507   hash_url(TEST_URL_2);
508   hash_url(TEST_URL_3);
509 }
510
511 /* ########################### */
512
513 static void test_url_part(const char* szUrl, DWORD dwPart, DWORD dwFlags, const char* szExpected)
514 {
515   CHAR szPart[INTERNET_MAX_URL_LENGTH];
516   WCHAR wszPart[INTERNET_MAX_URL_LENGTH];
517   LPWSTR wszUrl = GetWideString(szUrl);
518   LPWSTR wszConvertedPart;
519
520   DWORD dwSize;
521
522   dwSize = INTERNET_MAX_URL_LENGTH;
523   ok( UrlGetPartA(szUrl, szPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartA for \"%s\" part 0x%08x didn't return S_OK but \"%s\"\n", szUrl, dwPart, szPart);
524   dwSize = INTERNET_MAX_URL_LENGTH;
525   ok( UrlGetPartW(wszUrl, wszPart, &dwSize, dwPart, dwFlags) == S_OK, "UrlGetPartW didn't return S_OK\n" );
526
527   wszConvertedPart = GetWideString(szPart);
528
529   ok(lstrcmpW(wszPart,wszConvertedPart)==0, "Strings didn't match between ascii and unicode UrlGetPart!\n");
530
531   FreeWideString(wszUrl);
532   FreeWideString(wszConvertedPart);
533
534   /* Note that v6.0 and later don't return '?' with the query */
535   ok(strcmp(szPart,szExpected)==0 ||
536      (*szExpected=='?' && !strcmp(szPart,szExpected+1)),
537          "Expected %s, but got %s\n", szExpected, szPart);
538 }
539
540 /* ########################### */
541
542 static void test_UrlGetPart(void)
543 {
544   const char* file_url = "file://h o s t/c:/windows/file";
545   const char* http_url = "http://user:pass 123@www.wine hq.org";
546
547   CHAR szPart[INTERNET_MAX_URL_LENGTH];
548   DWORD dwSize;
549   HRESULT res;
550
551   dwSize = sizeof szPart;
552   szPart[0]='x'; szPart[1]=0;
553   res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_SCHEME, 0);
554   todo_wine {
555   ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
556   ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
557   }
558   dwSize = sizeof szPart;
559   szPart[0]='x'; szPart[1]=0;
560   res = UrlGetPartA("hi", szPart, &dwSize, URL_PART_QUERY, 0);
561   todo_wine {
562   ok (res==S_FALSE, "UrlGetPartA(\"hi\") returned %08X\n", res);
563   ok(szPart[0]==0, "UrlGetPartA(\"hi\") return \"%s\" instead of \"\"\n", szPart);
564   }
565
566   test_url_part(TEST_URL_3, URL_PART_HOSTNAME, 0, "localhost");
567   test_url_part(TEST_URL_3, URL_PART_PORT, 0, "21");
568   test_url_part(TEST_URL_3, URL_PART_USERNAME, 0, "foo");
569   test_url_part(TEST_URL_3, URL_PART_PASSWORD, 0, "bar");
570   test_url_part(TEST_URL_3, URL_PART_SCHEME, 0, "http");
571   test_url_part(TEST_URL_3, URL_PART_QUERY, 0, "?query=x&return=y");
572
573   test_url_part(file_url, URL_PART_HOSTNAME, 0, "h o s t");
574
575   test_url_part(http_url, URL_PART_HOSTNAME, 0, "www.wine hq.org");
576   test_url_part(http_url, URL_PART_PASSWORD, 0, "pass 123");
577
578   dwSize = sizeof(szPart);
579   res = UrlGetPartA("file://c:\\index.htm", szPart, &dwSize, URL_PART_HOSTNAME, 0);
580   ok(res==S_FALSE, "returned %08x\n", res);
581
582   dwSize = sizeof(szPart);
583   szPart[0] = 'x'; szPart[1] = '\0';
584   res = UrlGetPartA("file:some text", szPart, &dwSize, URL_PART_HOSTNAME, 0);
585   ok(res==S_FALSE, "returned %08x\n", res);
586   ok(szPart[0] == '\0', "szPart[0] = %c\n", szPart[0]);
587   ok(dwSize == 0, "dwSize = %d\n", dwSize);
588 }
589
590 /* ########################### */
591
592 static void test_url_escape(const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
593 {
594     CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
595     DWORD dwEscaped;
596     WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
597     WCHAR *urlW, *expected_urlW;
598     dwEscaped=INTERNET_MAX_URL_LENGTH;
599
600     ok(pUrlEscapeA(szUrl, szReturnUrl, &dwEscaped, dwFlags) == dwExpectReturn,
601         "UrlEscapeA didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
602     ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected \"%s\", but got \"%s\" from \"%s\"\n", szExpectUrl, szReturnUrl, szUrl);
603
604     if (pUrlEscapeW) {
605         dwEscaped = INTERNET_MAX_URL_LENGTH;
606         urlW = GetWideString(szUrl);
607         expected_urlW = GetWideString(szExpectUrl);
608         ok(pUrlEscapeW(urlW, ret_urlW, &dwEscaped, dwFlags) == dwExpectReturn,
609             "UrlEscapeW didn't return 0x%08x from \"%s\"\n", dwExpectReturn, szUrl);
610         WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
611         ok(lstrcmpW(ret_urlW, expected_urlW)==0,
612             "Expected \"%s\", but got \"%s\" from \"%s\" flags %08x\n",
613             szExpectUrl, szReturnUrl, szUrl, dwFlags);
614         FreeWideString(urlW);
615         FreeWideString(expected_urlW);
616     }
617 }
618
619 static void test_url_canonicalize(int index, const char *szUrl, DWORD dwFlags, HRESULT dwExpectReturn, HRESULT dwExpectReturnAlt, const char *szExpectUrl, BOOL todo)
620 {
621     CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
622     WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
623     LPWSTR wszUrl = GetWideString(szUrl);
624     LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
625     LPWSTR wszConvertedUrl;
626     HRESULT ret;
627
628     DWORD dwSize;
629
630     dwSize = INTERNET_MAX_URL_LENGTH;
631     ret = pUrlCanonicalizeA(szUrl, NULL, &dwSize, dwFlags);
632     ok(ret != dwExpectReturn, "got 0s%x: Unexpected return for NULL buffer, index %d\n", ret, index);
633     ret = pUrlCanonicalizeA(szUrl, szReturnUrl, &dwSize, dwFlags);
634     ok(ret == dwExpectReturn || ret == dwExpectReturnAlt,
635        "UrlCanonicalizeA failed: expected=0x%08x or 0x%08x, got=0x%08x, index %d\n",
636        dwExpectReturn, dwExpectReturnAlt, ret, index);
637     if (todo)
638         todo_wine
639         ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
640     else
641         ok(strcmp(szReturnUrl,szExpectUrl)==0, "UrlCanonicalizeA dwFlags 0x%08x url '%s' Expected \"%s\", but got \"%s\", index %d\n", dwFlags, szUrl, szExpectUrl, szReturnUrl, index);
642
643     if (pUrlCanonicalizeW) {
644         dwSize = INTERNET_MAX_URL_LENGTH;
645         ret = pUrlCanonicalizeW(wszUrl, NULL, &dwSize, dwFlags);
646         ok(ret != dwExpectReturn, "got 0x%x: Unexpected return for NULL buffer, index %d\n", ret, index);
647         ret = pUrlCanonicalizeW(wszUrl, wszReturnUrl, &dwSize, dwFlags);
648         ok(ret == dwExpectReturn, "UrlCanonicalizeW failed: expected 0x%08x, got 0x%x, index %d\n",
649             dwExpectReturn, ret, index);
650
651         wszConvertedUrl = GetWideString(szReturnUrl);
652         ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0,
653             "Strings didn't match between ascii and unicode UrlCanonicalize, index %d!\n", index);
654         FreeWideString(wszConvertedUrl);
655     }
656
657     FreeWideString(wszUrl);
658     FreeWideString(wszExpectUrl);
659 }
660
661
662 static void test_UrlEscape(void)
663 {
664     DWORD size = 0;
665     HRESULT ret;
666     unsigned int i;
667     char empty_string[] = "";
668
669     if (!pUrlEscapeA) {
670         win_skip("UrlEscapeA noz found\n");
671         return;
672     }
673
674     ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
675     ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
676     ok(size == 0, "got %d, expected %d\n", size, 0);
677
678     size = 0;
679     ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
680     ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
681     ok(size == 0, "got %d, expected %d\n", size, 0);
682
683     size = 1;
684     ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", NULL, &size, URL_ESCAPE_SPACES_ONLY);
685     ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
686     ok(size == 1, "got %d, expected %d\n", size, 1);
687
688     size = 1;
689     ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, NULL, URL_ESCAPE_SPACES_ONLY);
690     ok(ret == E_INVALIDARG, "got %x, expected %x\n", ret, E_INVALIDARG);
691     ok(size == 1, "got %d, expected %d\n", size, 1);
692
693     size = 1;
694     ret = pUrlEscapeA("/woningplan/woonkamer basis.swf", empty_string, &size, URL_ESCAPE_SPACES_ONLY);
695     ok(ret == E_POINTER, "got %x, expected %x\n", ret, E_POINTER);
696     ok(size == 34, "got %d, expected %d\n", size, 34);
697
698     for(i=0; i<sizeof(TEST_ESCAPE)/sizeof(TEST_ESCAPE[0]); i++) {
699         test_url_escape(TEST_ESCAPE[i].url, TEST_ESCAPE[i].flags,
700                               TEST_ESCAPE[i].expectret, TEST_ESCAPE[i].expecturl);
701     }
702 }
703
704 /* ########################### */
705
706 static void test_UrlCanonicalizeA(void)
707 {
708     unsigned int i;
709     CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
710     DWORD dwSize;
711     DWORD urllen;
712     HRESULT hr;
713
714     if (!pUrlCanonicalizeA) {
715         win_skip("UrlCanonicalizeA not found\n");
716         return;
717     }
718
719     urllen = lstrlenA(winehqA);
720
721     /* buffer has no space for the result */
722     dwSize=urllen-1;
723     memset(szReturnUrl, '#', urllen+4);
724     szReturnUrl[urllen+4] = '\0';
725     SetLastError(0xdeadbeef);
726     hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY  | URL_ESCAPE_UNSAFE);
727     ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
728         "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
729         hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
730
731     /* buffer has no space for the terminating '\0' */
732     dwSize=urllen;
733     memset(szReturnUrl, '#', urllen+4);
734     szReturnUrl[urllen+4] = '\0';
735     SetLastError(0xdeadbeef);
736     hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
737     ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
738         "got 0x%x with %u and size %u for '%s' and %u (expected 'E_POINTER' and size %u)\n",
739         hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen+1);
740
741     /* buffer has the required size */
742     dwSize=urllen+1;
743     memset(szReturnUrl, '#', urllen+4);
744     szReturnUrl[urllen+4] = '\0';
745     SetLastError(0xdeadbeef);
746     hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
747     ok( (hr == S_OK) && (dwSize == urllen),
748         "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
749         hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
750
751     /* buffer is larger as the required size */
752     dwSize=urllen+2;
753     memset(szReturnUrl, '#', urllen+4);
754     szReturnUrl[urllen+4] = '\0';
755     SetLastError(0xdeadbeef);
756     hr = pUrlCanonicalizeA(winehqA, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
757     ok( (hr == S_OK) && (dwSize == urllen),
758         "got 0x%x with %u and size %u for '%s' and %u (expected 'S_OK' and size %u)\n",
759         hr, GetLastError(), dwSize, szReturnUrl, lstrlenA(szReturnUrl), urllen);
760
761     test_url_canonicalize(-1, "", 0, S_OK, S_FALSE /* Vista/win2k8 */, "", FALSE);
762
763     /* test url-modification */
764     for(i=0; i<sizeof(TEST_CANONICALIZE)/sizeof(TEST_CANONICALIZE[0]); i++) {
765         test_url_canonicalize(i, TEST_CANONICALIZE[i].url, TEST_CANONICALIZE[i].flags,
766                               TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expectret, TEST_CANONICALIZE[i].expecturl,
767                               TEST_CANONICALIZE[i].todo);
768     }
769 }
770
771 /* ########################### */
772
773 static void test_UrlCanonicalizeW(void)
774 {
775     WCHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
776     DWORD dwSize;
777     DWORD urllen;
778     HRESULT hr;
779     int i;
780
781
782     if (!pUrlCanonicalizeW) {
783         win_skip("UrlCanonicalizeW not found\n");
784         return;
785     }
786     urllen = lstrlenW(winehqW);
787
788     /* buffer has no space for the result */
789     dwSize = (urllen-1);
790     memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
791     szReturnUrl[urllen+4] = '\0';
792     SetLastError(0xdeadbeef);
793     hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
794     ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
795         "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
796         hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
797
798
799     /* buffer has no space for the terminating '\0' */
800     dwSize = urllen;
801     memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
802     szReturnUrl[urllen+4] = '\0';
803     SetLastError(0xdeadbeef);
804     hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
805     ok( (hr == E_POINTER) && (dwSize == (urllen + 1)),
806         "got 0x%x with %u and size %u for %u (expected 'E_POINTER' and size %u)\n",
807         hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen+1);
808
809     /* buffer has the required size */
810     dwSize = urllen +1;
811     memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
812     szReturnUrl[urllen+4] = '\0';
813     SetLastError(0xdeadbeef);
814     hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
815     ok( (hr == S_OK) && (dwSize == urllen),
816         "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
817         hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
818
819     /* buffer is larger as the required size */
820     dwSize = (urllen+2);
821     memset(szReturnUrl, '#', (urllen+4) * sizeof(WCHAR));
822     szReturnUrl[urllen+4] = '\0';
823     SetLastError(0xdeadbeef);
824     hr = pUrlCanonicalizeW(winehqW, szReturnUrl, &dwSize, URL_WININET_COMPATIBILITY | URL_ESCAPE_UNSAFE);
825     ok( (hr == S_OK) && (dwSize == urllen),
826         "got 0x%x with %u and size %u for %u (expected 'S_OK' and size %u)\n",
827         hr, GetLastError(), dwSize, lstrlenW(szReturnUrl), urllen);
828
829     /* check that the characters 1..32 are chopped from the end of the string */
830     for (i = 1; i < 65536; i++)
831     {
832         WCHAR szUrl[128];
833         BOOL choped;
834         int pos;
835
836         MultiByteToWideChar(CP_ACP, 0, "http://www.winehq.org/X", -1, szUrl, 128);
837         pos = lstrlenW(szUrl) - 1;
838         szUrl[pos] = i;
839         urllen = INTERNET_MAX_URL_LENGTH;
840         pUrlCanonicalizeW(szUrl, szReturnUrl, &urllen, 0);
841         choped = lstrlenW(szReturnUrl) < lstrlenW(szUrl);
842         ok(choped == (i <= 32), "Incorrect char chopping for char %d\n", i);
843     }
844 }
845
846 /* ########################### */
847
848 static void test_url_combine(const char *szUrl1, const char *szUrl2, DWORD dwFlags, HRESULT dwExpectReturn, const char *szExpectUrl)
849 {
850     HRESULT hr;
851     CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
852     WCHAR wszReturnUrl[INTERNET_MAX_URL_LENGTH];
853     LPWSTR wszUrl1 = GetWideString(szUrl1);
854     LPWSTR wszUrl2 = GetWideString(szUrl2);
855     LPWSTR wszExpectUrl = GetWideString(szExpectUrl);
856     LPWSTR wszConvertedUrl;
857
858     DWORD dwSize;
859     DWORD dwExpectLen = lstrlen(szExpectUrl);
860
861     if (!pUrlCombineA) {
862         win_skip("UrlCombineA not found\n");
863         return;
864     }
865
866     hr = pUrlCombineA(szUrl1, szUrl2, NULL, NULL, dwFlags);
867     ok(hr == E_INVALIDARG, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_INVALIDARG);
868
869     dwSize = 0;
870     hr = pUrlCombineA(szUrl1, szUrl2, NULL, &dwSize, dwFlags);
871     ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
872     ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
873
874     dwSize--;
875     hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
876     ok(hr == E_POINTER, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
877     ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
878
879     hr = pUrlCombineA(szUrl1, szUrl2, szReturnUrl, &dwSize, dwFlags);
880     ok(hr == dwExpectReturn, "UrlCombineA returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
881     ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
882     if(SUCCEEDED(hr)) {
883         ok(strcmp(szReturnUrl,szExpectUrl)==0, "Expected %s, but got %s\n", szExpectUrl, szReturnUrl);
884     }
885
886     if (pUrlCombineW) {
887         dwSize = 0;
888         hr = pUrlCombineW(wszUrl1, wszUrl2, NULL, &dwSize, dwFlags);
889         ok(hr == E_POINTER, "Checking length of string, return was 0x%08x, expected 0x%08x\n", hr, E_POINTER);
890         ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
891
892         dwSize--;
893         hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
894         ok(hr == E_POINTER, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, E_POINTER);
895         ok(dwSize == dwExpectLen+1, "Got length %d, expected %d\n", dwSize, dwExpectLen+1);
896
897         hr = pUrlCombineW(wszUrl1, wszUrl2, wszReturnUrl, &dwSize, dwFlags);
898         ok(hr == dwExpectReturn, "UrlCombineW returned 0x%08x, expected 0x%08x\n", hr, dwExpectReturn);
899         ok(dwSize == dwExpectLen, "Got length %d, expected %d\n", dwSize, dwExpectLen);
900         if(SUCCEEDED(hr)) {
901             wszConvertedUrl = GetWideString(szReturnUrl);
902             ok(lstrcmpW(wszReturnUrl, wszConvertedUrl)==0, "Strings didn't match between ascii and unicode UrlCombine!\n");
903             FreeWideString(wszConvertedUrl);
904         }
905     }
906
907     FreeWideString(wszUrl1);
908     FreeWideString(wszUrl2);
909     FreeWideString(wszExpectUrl);
910 }
911
912 /* ########################### */
913
914 static void test_UrlCombine(void)
915 {
916     unsigned int i;
917     for(i=0; i<sizeof(TEST_COMBINE)/sizeof(TEST_COMBINE[0]); i++) {
918         test_url_combine(TEST_COMBINE[i].url1, TEST_COMBINE[i].url2, TEST_COMBINE[i].flags,
919                          TEST_COMBINE[i].expectret, TEST_COMBINE[i].expecturl);
920     }
921 }
922
923 /* ########################### */
924
925 static void test_UrlCreateFromPath(void)
926 {
927     size_t i;
928     char ret_url[INTERNET_MAX_URL_LENGTH];
929     DWORD len, ret;
930     WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
931     WCHAR *pathW, *urlW;
932
933     if (!pUrlCreateFromPathA) {
934         win_skip("UrlCreateFromPathA not found\n");
935         return;
936     }
937
938     for(i = 0; i < sizeof(TEST_URLFROMPATH) / sizeof(TEST_URLFROMPATH[0]); i++) {
939         len = INTERNET_MAX_URL_LENGTH;
940         ret = pUrlCreateFromPathA(TEST_URLFROMPATH[i].path, ret_url, &len, 0);
941         ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path %s\n", ret, TEST_URLFROMPATH[i].path);
942         ok(!lstrcmpi(ret_url, TEST_URLFROMPATH[i].url), "url %s from path %s\n", ret_url, TEST_URLFROMPATH[i].path);
943         ok(len == strlen(ret_url), "ret len %d from path %s\n", len, TEST_URLFROMPATH[i].path);
944
945         if (pUrlCreateFromPathW) {
946             len = INTERNET_MAX_URL_LENGTH;
947             pathW = GetWideString(TEST_URLFROMPATH[i].path);
948             urlW = GetWideString(TEST_URLFROMPATH[i].url);
949             ret = pUrlCreateFromPathW(pathW, ret_urlW, &len, 0);
950             WideCharToMultiByte(CP_ACP, 0, ret_urlW, -1, ret_url, sizeof(ret_url),0,0);
951             ok(ret == TEST_URLFROMPATH[i].ret, "ret %08x from path L\"%s\", expected %08x\n",
952                 ret, TEST_URLFROMPATH[i].path, TEST_URLFROMPATH[i].ret);
953             ok(!lstrcmpiW(ret_urlW, urlW), "got %s expected %s from path L\"%s\"\n",
954                 ret_url, TEST_URLFROMPATH[i].url, TEST_URLFROMPATH[i].path);
955             ok(len == lstrlenW(ret_urlW), "ret len %d from path L\"%s\"\n", len, TEST_URLFROMPATH[i].path);
956             FreeWideString(urlW);
957             FreeWideString(pathW);
958         }
959     }
960 }
961
962 /* ########################### */
963
964 static void test_UrlIs(void)
965 {
966     BOOL ret;
967     size_t i;
968     WCHAR wurl[80];
969
970     for(i = 0; i < sizeof(TEST_PATH_IS_URL) / sizeof(TEST_PATH_IS_URL[0]); i++) {
971         MultiByteToWideChar(CP_ACP, 0, TEST_PATH_IS_URL[i].path, -1, wurl, 80);
972
973         ret = UrlIsA( TEST_PATH_IS_URL[i].path, URLIS_URL );
974         ok( ret == TEST_PATH_IS_URL[i].expect,
975             "returned %d from path %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
976             TEST_PATH_IS_URL[i].expect );
977
978         ret = UrlIsW( wurl, URLIS_URL );
979         ok( ret == TEST_PATH_IS_URL[i].expect,
980             "returned %d from path (UrlIsW) %s, expected %d\n", ret, TEST_PATH_IS_URL[i].path,
981             TEST_PATH_IS_URL[i].expect );
982     }
983     for(i = 0; i < sizeof(TEST_URLIS_ATTRIBS) / sizeof(TEST_URLIS_ATTRIBS[0]); i++) {
984         MultiByteToWideChar(CP_ACP, 0, TEST_URLIS_ATTRIBS[i].url, -1, wurl, 80);
985
986         ret = UrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_OPAQUE);
987         ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
988             "returned %d for URLIS_OPAQUE, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
989             TEST_URLIS_ATTRIBS[i].expectOpaque );
990         ret = UrlIsA( TEST_URLIS_ATTRIBS[i].url, URLIS_FILEURL);
991         ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
992             "returned %d for URLIS_FILEURL, url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
993             TEST_URLIS_ATTRIBS[i].expectFile );
994
995         ret = UrlIsW( wurl, URLIS_OPAQUE);
996         ok( ret == TEST_URLIS_ATTRIBS[i].expectOpaque,
997             "returned %d for URLIS_OPAQUE (UrlIsW), url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
998             TEST_URLIS_ATTRIBS[i].expectOpaque );
999         ret = UrlIsW( wurl, URLIS_FILEURL);
1000         ok( ret == TEST_URLIS_ATTRIBS[i].expectFile,
1001             "returned %d for URLIS_FILEURL (UrlIsW), url \"%s\", expected %d\n", ret, TEST_URLIS_ATTRIBS[i].url,
1002             TEST_URLIS_ATTRIBS[i].expectFile );
1003     }
1004 }
1005
1006 /* ########################### */
1007
1008 static void test_UrlUnescape(void)
1009 {
1010     CHAR szReturnUrl[INTERNET_MAX_URL_LENGTH];
1011     WCHAR ret_urlW[INTERNET_MAX_URL_LENGTH];
1012     WCHAR *urlW, *expected_urlW;
1013     DWORD dwEscaped;
1014     size_t i;
1015     static char inplace[] = "file:///C:/Program%20Files";
1016     static char another_inplace[] = "file:///C:/Program%20Files";
1017     static const char expected[] = "file:///C:/Program Files";
1018     static WCHAR inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m',' ','F','i','l','e','s',0};
1019     static WCHAR another_inplaceW[] = {'f','i','l','e',':','/','/','/','C',':','/','P','r','o','g','r','a','m','%','2','0','F','i','l','e','s',0};
1020
1021     for(i=0; i<sizeof(TEST_URL_UNESCAPE)/sizeof(TEST_URL_UNESCAPE[0]); i++) {
1022         dwEscaped=INTERNET_MAX_URL_LENGTH;
1023         ok(UrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, &dwEscaped, 0) == S_OK, "UrlUnescapeA didn't return 0x%08x from \"%s\"\n", S_OK, TEST_URL_UNESCAPE[i].url);
1024         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);
1025
1026         ZeroMemory(szReturnUrl, sizeof(szReturnUrl));
1027         /* if we set the bufferpointer to NULL here UrlUnescape  fails and string gets not converted */
1028         ok(UrlUnescapeA(TEST_URL_UNESCAPE[i].url, szReturnUrl, NULL, 0) == E_INVALIDARG, "UrlUnescapeA didn't return 0x%08x from \"%s\"\n", E_INVALIDARG ,TEST_URL_UNESCAPE[i].url);
1029         ok(strcmp(szReturnUrl,"")==0, "Expected empty string\n");
1030
1031         dwEscaped = INTERNET_MAX_URL_LENGTH;
1032         urlW = GetWideString(TEST_URL_UNESCAPE[i].url);
1033         expected_urlW = GetWideString(TEST_URL_UNESCAPE[i].expect);
1034         ok(UrlUnescapeW(urlW, ret_urlW, &dwEscaped, 0) == S_OK, "UrlUnescapeW didn't return 0x%08x from \"%s\"\n", S_OK, TEST_URL_UNESCAPE[i].url);
1035         WideCharToMultiByte(CP_ACP,0,ret_urlW,-1,szReturnUrl,INTERNET_MAX_URL_LENGTH,0,0);
1036         ok(lstrcmpW(ret_urlW, expected_urlW)==0, "Expected \"%s\", but got \"%s\" from \"%s\" flags %08lx\n", TEST_URL_UNESCAPE[i].expect, szReturnUrl, TEST_URL_UNESCAPE[i].url, 0L);
1037         FreeWideString(urlW);
1038         FreeWideString(expected_urlW);
1039     }
1040
1041     dwEscaped = sizeof(inplace);
1042     ok(UrlUnescapeA(inplace, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");
1043     ok(!strcmp(inplace, expected), "got %s expected %s\n", inplace, expected);
1044     ok(dwEscaped == 27, "got %d expected 27\n", dwEscaped);
1045
1046     /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1047     ok(UrlUnescapeA(another_inplace, NULL, NULL, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeA failed unexpectedly\n");
1048     ok(!strcmp(another_inplace, expected), "got %s expected %s\n", another_inplace, expected);
1049
1050     dwEscaped = sizeof(inplaceW);
1051     ok(UrlUnescapeW(inplaceW, NULL, &dwEscaped, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
1052     ok(dwEscaped == 50, "got %d expected 50\n", dwEscaped);
1053
1054     /* if we set the bufferpointer to NULL, the string apparently still gets converted (Google Lively does this)) */
1055     ok(UrlUnescapeW(another_inplaceW, NULL, NULL, URL_UNESCAPE_INPLACE) == S_OK, "UrlUnescapeW failed unexpectedly\n");
1056     ok(lstrlenW(another_inplaceW) == 24, "got %d expected 24\n", lstrlenW(another_inplaceW));
1057
1058 }
1059
1060 static const struct parse_url_test_t {
1061     const char *url;
1062     HRESULT hres;
1063     UINT protocol_len;
1064     UINT scheme;
1065 } parse_url_tests[] = {
1066     {"http://www.winehq.org/",S_OK,4,URL_SCHEME_HTTP},
1067     {"https://www.winehq.org/",S_OK,5,URL_SCHEME_HTTPS},
1068     {"ftp://www.winehq.org/",S_OK,3,URL_SCHEME_FTP},
1069     {"test.txt?test=c:/dir",URL_E_INVALID_SYNTAX},
1070     {"test.txt",URL_E_INVALID_SYNTAX},
1071     {"xxx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1072     {"1xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1073     {"-xx://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1074     {"xx0://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1075     {"x://www.winehq.org/",URL_E_INVALID_SYNTAX},
1076     {"xx$://www.winehq.org/",URL_E_INVALID_SYNTAX},
1077     {"htt?p://www.winehq.org/",URL_E_INVALID_SYNTAX},
1078     {"ab-://www.winehq.org/",S_OK,3,URL_SCHEME_UNKNOWN},
1079     {" http://www.winehq.org/",URL_E_INVALID_SYNTAX},
1080 };
1081
1082 static void test_ParseURL(void)
1083 {
1084     const struct parse_url_test_t *test;
1085     WCHAR url[INTERNET_MAX_URL_LENGTH];
1086     PARSEDURLA parseda;
1087     PARSEDURLW parsedw;
1088     HRESULT hres;
1089
1090     for(test = parse_url_tests; test < parse_url_tests + sizeof(parse_url_tests)/sizeof(*parse_url_tests); test++) {
1091         memset(&parseda, 0xd0, sizeof(parseda));
1092         parseda.cbSize = sizeof(parseda);
1093         hres = pParseURLA(test->url, &parseda);
1094         ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1095         if(hres == S_OK) {
1096             ok(parseda.pszProtocol == test->url, "parseda.pszProtocol = %s, expected %s\n",
1097                parseda.pszProtocol, test->url);
1098             ok(parseda.cchProtocol == test->protocol_len, "parseda.cchProtocol = %d, expected %d\n",
1099                parseda.cchProtocol, test->protocol_len);
1100             ok(parseda.pszSuffix == test->url+test->protocol_len+1, "parseda.pszSuffix = %s, expected %s\n",
1101                parseda.pszSuffix, test->url+test->protocol_len+1);
1102             ok(parseda.cchSuffix == strlen(test->url+test->protocol_len+1),
1103                "parseda.pszSuffix = %d, expected %d\n",
1104                parseda.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1105             ok(parseda.nScheme == test->scheme, "parseda.nScheme = %d, expected %d\n",
1106                parseda.nScheme, test->scheme);
1107         }else {
1108             ok(!parseda.pszProtocol, "parseda.pszProtocol = %p\n", parseda.pszProtocol);
1109             ok(parseda.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parseda.nScheme);
1110         }
1111
1112         MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, sizeof(url)/sizeof(WCHAR));
1113
1114         memset(&parsedw, 0xd0, sizeof(parsedw));
1115         parsedw.cbSize = sizeof(parsedw);
1116         hres = pParseURLW(url, &parsedw);
1117         ok(hres == test->hres, "ParseURL failed: %08x, expected %08x\n", hres, test->hres);
1118         if(hres == S_OK) {
1119             ok(parsedw.pszProtocol == url, "parsedw.pszProtocol = %s, expected %s\n",
1120                wine_dbgstr_w(parsedw.pszProtocol), wine_dbgstr_w(url));
1121             ok(parsedw.cchProtocol == test->protocol_len, "parsedw.cchProtocol = %d, expected %d\n",
1122                parsedw.cchProtocol, test->protocol_len);
1123             ok(parsedw.pszSuffix == url+test->protocol_len+1, "parsedw.pszSuffix = %s, expected %s\n",
1124                wine_dbgstr_w(parsedw.pszSuffix), wine_dbgstr_w(url+test->protocol_len+1));
1125             ok(parsedw.cchSuffix == strlen(test->url+test->protocol_len+1),
1126                "parsedw.pszSuffix = %d, expected %d\n",
1127                parsedw.cchSuffix, lstrlenA(test->url+test->protocol_len+1));
1128             ok(parsedw.nScheme == test->scheme, "parsedw.nScheme = %d, expected %d\n",
1129                parsedw.nScheme, test->scheme);
1130         }else {
1131             ok(!parsedw.pszProtocol, "parsedw.pszProtocol = %p\n", parseda.pszProtocol);
1132             ok(parsedw.nScheme == 0xd0d0d0d0, "nScheme = %d\n", parsedw.nScheme);
1133         }
1134     }
1135 }
1136
1137 static void test_HashData(void)
1138 {
1139     HRESULT res;
1140     BYTE input[16] = {0x51, 0x33, 0x4F, 0xA7, 0x45, 0x15, 0xF0, 0x52, 0x90,
1141                       0x2B, 0xE7, 0xF5, 0xFD, 0xE1, 0xA6, 0xA7};
1142     BYTE output[32];
1143     static const BYTE expected[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1144                                     0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1145                                     0xE3, 0x2D};
1146     static const BYTE expected2[] = {0x54, 0x9C, 0x92, 0x55, 0xCD, 0x82, 0xFF,
1147                                      0xA1, 0x8E, 0x0F, 0xCF, 0x93, 0x14, 0xAA,
1148                                      0xE3, 0x2D, 0x47, 0xFC, 0x80, 0xB8, 0xD0,
1149                                      0x49, 0xE6, 0x13, 0x2A, 0x30, 0x51, 0x8D,
1150                                      0xF9, 0x4B, 0x07, 0xA6};
1151     static const BYTE expected3[] = {0x2B, 0xDC, 0x9A, 0x1B, 0xF0, 0x5A, 0xF9,
1152                                      0xC6, 0xBE, 0x94, 0x6D, 0xF3, 0x33, 0xC1,
1153                                      0x36, 0x07};
1154     int i;
1155
1156     /* Test hashing with identically sized input/output buffers. */
1157     res = pHashData(input, 16, output, 16);
1158     ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1159     if(res == S_OK)
1160        ok(!memcmp(output, expected, sizeof(expected)),
1161           "Output buffer did not match expected contents\n");
1162
1163     /* Test hashing with larger output buffer. */
1164     res = pHashData(input, 16, output, 32);
1165     ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1166     if(res == S_OK)
1167        ok(!memcmp(output, expected2, sizeof(expected2)),
1168           "Output buffer did not match expected contents\n");
1169
1170     /* Test hashing with smaller input buffer. */
1171     res = pHashData(input, 8, output, 16);
1172     ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1173     if(res == S_OK)
1174        ok(!memcmp(output, expected3, sizeof(expected3)),
1175           "Output buffer did not match expected contents\n");
1176
1177     /* Test passing NULL pointers for input/output parameters. */
1178     res = pHashData(NULL, 0, NULL, 0);
1179     ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1180        "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1181
1182     res = pHashData(input, 0, NULL, 0);
1183     ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1184        "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1185
1186     res = pHashData(NULL, 0, output, 0);
1187     ok(res == E_INVALIDARG || broken(res == S_OK), /* Windows 2000 */
1188        "Expected HashData to return E_INVALIDARG, got 0x%08x\n", res);
1189
1190     /* Test passing valid pointers with sizes of zero. */
1191     for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1192         input[i] = 0x00;
1193
1194     for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1195         output[i] = 0xFF;
1196
1197     res = pHashData(input, 0, output, 0);
1198     ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1199
1200     /* The buffers should be unchanged. */
1201     for (i = 0; i < sizeof(input)/sizeof(BYTE); i++)
1202     {
1203         ok(input[i] == 0x00, "Expected the input buffer to be unchanged\n");
1204         if(input[i] != 0x00) break;
1205     }
1206
1207     for (i = 0; i < sizeof(output)/sizeof(BYTE); i++)
1208     {
1209         ok(output[i] == 0xFF, "Expected the output buffer to be unchanged\n");
1210         if(output[i] != 0xFF) break;
1211     }
1212
1213     /* Input/output parameters are not validated. */
1214     res = pHashData((BYTE *)0xdeadbeef, 0, (BYTE *)0xdeadbeef, 0);
1215     ok(res == S_OK, "Expected HashData to return S_OK, got 0x%08x\n", res);
1216
1217     if (0)
1218     {
1219         res = pHashData((BYTE *)0xdeadbeef, 1, (BYTE *)0xdeadbeef, 1);
1220         trace("HashData returned 0x%08x\n", res);
1221     }
1222 }
1223
1224 /* ########################### */
1225
1226 START_TEST(url)
1227 {
1228
1229   hShlwapi = GetModuleHandleA("shlwapi.dll");
1230   pUrlEscapeA = (void *) GetProcAddress(hShlwapi, "UrlEscapeA");
1231   pUrlEscapeW = (void *) GetProcAddress(hShlwapi, "UrlEscapeW");
1232   pUrlCreateFromPathA = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathA");
1233   pUrlCreateFromPathW = (void *) GetProcAddress(hShlwapi, "UrlCreateFromPathW");
1234   pUrlCombineA = (void *) GetProcAddress(hShlwapi, "UrlCombineA");
1235   pUrlCombineW = (void *) GetProcAddress(hShlwapi, "UrlCombineW");
1236   pUrlCanonicalizeA = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeA");
1237   pUrlCanonicalizeW = (void *) GetProcAddress(hShlwapi, "UrlCanonicalizeW");
1238   pUrlApplySchemeA = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeA");
1239   pUrlApplySchemeW = (void *) GetProcAddress(hShlwapi, "UrlApplySchemeW");
1240   pParseURLA = (void*)GetProcAddress(hShlwapi, (LPCSTR)1);
1241   pParseURLW = (void*)GetProcAddress(hShlwapi, (LPCSTR)2);
1242   pHashData = (void*)GetProcAddress(hShlwapi, "HashData");
1243
1244   test_UrlApplyScheme();
1245   test_UrlHash();
1246   test_UrlGetPart();
1247   test_UrlCanonicalizeA();
1248   test_UrlCanonicalizeW();
1249   test_UrlEscape();
1250   test_UrlCombine();
1251   test_UrlCreateFromPath();
1252   test_UrlIs();
1253   test_UrlUnescape();
1254   test_ParseURL();
1255   test_HashData();
1256 }