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