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