makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / webservices / tests / url.c
blob718f072f19c398f9ba373ea71c435f3e418bb010
1 /*
2 * Copyright 2016 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdio.h>
20 #include "windows.h"
21 #include "webservices.h"
22 #include "wine/test.h"
24 static void test_WsDecodeUrl(void)
26 static const WCHAR url1[] = L"http://host";
27 static const WCHAR url2[] = L"https://host";
28 static const WCHAR url3[] = L"http://host:80";
29 static const WCHAR url4[] = L"https://host:80";
30 static const WCHAR url5[] = L"http://host/path";
31 static const WCHAR url6[] = L"http://host/path?query";
32 static const WCHAR url7[] = L"http://host/path?query#frag";
33 static const WCHAR url8[] = L"HTTP://host";
34 static const WCHAR url9[] = L"httq://host";
35 static const WCHAR url10[] = L"http:";
36 static const WCHAR url11[] = L"http";
37 static const WCHAR url12[] = L"net.tcp://host";
38 static const WCHAR url13[] = L"soap.udp://host";
39 static const WCHAR url14[] = L"net.pipe://host";
40 static const WCHAR url15[] = L"http:/host";
41 static const WCHAR url16[] = L"http:host";
42 static const WCHAR url17[] = L"http:///host";
43 static const WCHAR url18[] = L"http://host/";
44 static const WCHAR url19[] = L"http://host:/";
45 static const WCHAR url20[] = L"http://host:65536";
46 static const WCHAR url21[] = L"http://host?query";
47 static const WCHAR url22[] = L"http://host#frag";
48 static const WCHAR url23[] = L"http://host%202";
49 static const WCHAR url24[] = L"http://host/path%202";
50 static const WCHAR url25[] = L"http://host?query%202";
51 static const WCHAR url26[] = L"http://host#frag%202";
52 static const WCHAR url27[] = L"http://host/%c3%ab/";
53 static const struct
55 const WCHAR *str;
56 HRESULT hr;
57 WS_URL_SCHEME_TYPE scheme;
58 const WCHAR *host;
59 ULONG host_len;
60 USHORT port;
61 const WCHAR *port_str;
62 ULONG port_len;
63 const WCHAR *path;
64 ULONG path_len;
65 const WCHAR *query;
66 ULONG query_len;
67 const WCHAR *fragment;
68 ULONG fragment_len;
70 tests[] =
72 { url1, S_OK, WS_URL_HTTP_SCHEME_TYPE, url1 + 7, 4, 80 },
73 { url2, S_OK, WS_URL_HTTPS_SCHEME_TYPE, url2 + 8, 4, 443 },
74 { url3, S_OK, WS_URL_HTTP_SCHEME_TYPE, url3 + 7, 4, 80, url3 + 12, 2 },
75 { url4, S_OK, WS_URL_HTTPS_SCHEME_TYPE, url4 + 8, 4, 80, url4 + 13, 2 },
76 { url5, S_OK, WS_URL_HTTP_SCHEME_TYPE, url5 + 7, 4, 80, NULL, 0, url5 + 11, 5 },
77 { url6, S_OK, WS_URL_HTTP_SCHEME_TYPE, url5 + 7, 4, 80, NULL, 0, url6 + 11, 5, url6 + 17, 5 },
78 { url7, S_OK, WS_URL_HTTP_SCHEME_TYPE, url5 + 7, 4, 80, NULL, 0, url7 + 11, 5, url7 + 17, 5, url7 + 23, 4 },
79 { url8, S_OK, WS_URL_HTTP_SCHEME_TYPE, url1 + 7, 4, 80 },
80 { url9, WS_E_INVALID_FORMAT },
81 { url10, WS_E_INVALID_FORMAT },
82 { url11, WS_E_INVALID_FORMAT },
83 { url12, S_OK, WS_URL_NETTCP_SCHEME_TYPE, url12 + 10, 4, 808 },
84 { url13, S_OK, WS_URL_SOAPUDP_SCHEME_TYPE, url13 + 11, 4, 65535 },
85 { url14, S_OK, WS_URL_NETPIPE_SCHEME_TYPE, url14 + 11, 4, 65535 },
86 { url15, WS_E_INVALID_FORMAT },
87 { url16, WS_E_INVALID_FORMAT },
88 { url17, WS_E_INVALID_FORMAT },
89 { url18, S_OK, WS_URL_HTTP_SCHEME_TYPE, url18 + 7, 4, 80, NULL, 0, url18 + 11, 1 },
90 { url19, S_OK, WS_URL_HTTP_SCHEME_TYPE, url19 + 7, 4, 80, NULL, 0, url19 + 12, 1 },
91 { url20, WS_E_INVALID_FORMAT },
92 { url21, S_OK, WS_URL_HTTP_SCHEME_TYPE, url21 + 7, 4, 80, NULL, 0, NULL, 0, url21 + 12, 5 },
93 { url22, S_OK, WS_URL_HTTP_SCHEME_TYPE, url22 + 7, 4, 80, NULL, 0, NULL, 0, NULL, 0,
94 url22 + 12, 4 },
95 { url23, S_OK, WS_URL_HTTP_SCHEME_TYPE, L"host 2", 6, 80 },
96 { url24, S_OK, WS_URL_HTTP_SCHEME_TYPE, url24 + 7, 4, 80, NULL, 0, L"/path 2", 7 },
97 { url25, S_OK, WS_URL_HTTP_SCHEME_TYPE, url25 + 7, 4, 80, NULL, 0, NULL, 0, L"query 2", 7 },
98 { url26, S_OK, WS_URL_HTTP_SCHEME_TYPE, url26 + 7, 4, 80, NULL, 0, NULL, 0, NULL, 0, L"frag 2", 6 },
99 { url27, S_OK, WS_URL_HTTP_SCHEME_TYPE, url27 + 7, 4, 80, NULL, 0, L"/\x00eb/", 3 },
101 WS_HEAP *heap;
102 WS_STRING str;
103 WS_HTTP_URL *url;
104 HRESULT hr;
105 UINT i;
107 hr = WsCreateHeap( 1 << 16, 0, NULL, 0, &heap, NULL );
108 ok( hr == S_OK, "got %08x\n", hr );
110 hr = WsDecodeUrl( NULL, 0, heap, (WS_URL **)&url, NULL );
111 ok( hr == E_INVALIDARG, "got %08x\n", hr );
113 str.chars = NULL;
114 str.length = 0;
115 hr = WsDecodeUrl( &str, 0, heap, (WS_URL **)&url, NULL );
116 ok( hr == WS_E_INVALID_FORMAT, "got %08x\n", hr );
118 str.chars = (WCHAR *)url1;
119 str.length = lstrlenW( url1 );
120 hr = WsDecodeUrl( &str, 0, NULL, (WS_URL **)&url, NULL );
121 ok( hr == E_INVALIDARG, "got %08x\n", hr );
123 for (i = 0; i < ARRAY_SIZE( tests ); i++)
125 str.length = lstrlenW( tests[i].str );
126 str.chars = (WCHAR *)tests[i].str;
127 url = NULL;
128 hr = WsDecodeUrl( &str, 0, heap, (WS_URL **)&url, NULL );
129 ok( hr == tests[i].hr ||
130 broken(hr == WS_E_INVALID_FORMAT && str.length >= 8 && !memcmp(L"net.pipe", str.chars, 8)),
131 "%u: got %08x\n", i, hr );
132 if (hr != S_OK) continue;
134 ok( url->url.scheme == tests[i].scheme, "%u: got %u\n", i, url->url.scheme );
135 ok( url->port == tests[i].port, "%u: got %u\n", i, url->port );
137 if (tests[i].host)
139 ok( url->host.length == tests[i].host_len, "%u: got %u\n", i, url->host.length );
140 ok( !memcmp( url->host.chars, tests[i].host, url->host.length * sizeof(WCHAR) ),
141 "%u: got %s\n", i, wine_dbgstr_wn(url->host.chars, url->host.length) );
143 else ok( !url->host.length, "%u: got %u\n", i, url->host.length );
145 if (tests[i].port_str)
147 ok( url->portAsString.length == tests[i].port_len, "%u: got %u\n", i, url->portAsString.length );
148 ok( !memcmp( url->portAsString.chars, tests[i].port_str, url->portAsString.length * sizeof(WCHAR) ),
149 "%u: got %s\n", i, wine_dbgstr_wn(url->portAsString.chars, url->portAsString.length) );
151 else ok( !url->portAsString.length, "%u: got %u\n", i, url->portAsString.length );
153 if (tests[i].path)
155 ok( url->path.length == tests[i].path_len, "%u: got %u\n", i, url->path.length );
156 ok( !memcmp( url->path.chars, tests[i].path, url->path.length * sizeof(WCHAR) ),
157 "%u: got %s\n", i, wine_dbgstr_wn(url->path.chars, url->path.length) );
159 else ok( !url->path.length, "%u: got %u\n", i, url->path.length );
161 if (tests[i].query)
163 ok( url->query.length == tests[i].query_len, "%u: got %u\n", i, url->query.length );
164 ok( !memcmp( url->query.chars, tests[i].query, url->query.length * sizeof(WCHAR) ),
165 "%u: got %s\n", i, wine_dbgstr_wn(url->query.chars, url->query.length) );
167 else ok( !url->query.length, "%u: got %u\n", i, url->query.length );
169 if (tests[i].fragment)
171 ok( url->fragment.length == tests[i].fragment_len, "%u: got %u\n", i, url->fragment.length );
172 ok( !memcmp( url->fragment.chars, tests[i].fragment, url->fragment.length * sizeof(WCHAR) ),
173 "%u: got %s\n", i, wine_dbgstr_wn(url->fragment.chars, url->fragment.length) );
175 else ok( !url->fragment.length, "%u: got %u\n", i, url->fragment.length );
178 WsFreeHeap( heap );
181 static void test_WsEncodeUrl(void)
183 static const WCHAR url1[] = L"http://host";
184 static const WCHAR url2[] = L"http://";
185 static const WCHAR url3[] = L"http:///path";
186 static const WCHAR url4[] = L"http://?query";
187 static const WCHAR url5[] = L"http://#frag";
188 static const WCHAR url6[] = L"http://host:8080/path?query#frag";
189 static const WCHAR url7[] = L"http://:8080";
190 static const WCHAR url8[] = L"http://";
191 static const WCHAR url9[] = L"http:///path%202";
192 static const WCHAR url10[] = L"http://?query%202";
193 static const WCHAR url11[] = L"http://#frag%202";
194 static const WCHAR url12[] = L"http://host%202";
195 static const struct
197 WS_URL_SCHEME_TYPE scheme;
198 const WCHAR *host;
199 ULONG host_len;
200 USHORT port;
201 const WCHAR *port_str;
202 ULONG port_len;
203 const WCHAR *path;
204 ULONG path_len;
205 const WCHAR *query;
206 ULONG query_len;
207 const WCHAR *fragment;
208 ULONG fragment_len;
209 HRESULT hr;
210 ULONG len;
211 const WCHAR *chars;
213 tests[] =
215 { WS_URL_HTTP_SCHEME_TYPE, L"host", 4, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, S_OK, 11, url1 },
216 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, S_OK, 7, url2 },
217 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, NULL, 0, L"/path", 5, NULL, 0, NULL, 0, S_OK, 12, url3 },
218 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, NULL, 0, NULL, 0, L"query", 5, NULL, 0, S_OK, 13, url4 },
219 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, NULL, 0, NULL, 0, NULL, 0, L"frag", 4, S_OK, 12, url5 },
220 { WS_URL_HTTP_SCHEME_TYPE, L"host", 4, 0, L"8080", 4, L"/path", 5, L"query", 5, L"frag", 4, S_OK, 32, url6 },
221 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 8080, NULL, 0, NULL, 0, NULL, 0, NULL, 0, S_OK, 12, url7 },
222 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, L"8080", 4, NULL, 0, NULL, 0, NULL, 0, S_OK, 12, url7 },
223 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 8080, L"8080", 4, NULL, 0, NULL, 0, NULL, 0, S_OK, 12, url7 },
224 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 8181, L"8080", 4, NULL, 0, NULL, 0, NULL, 0, E_INVALIDARG, 0, NULL },
225 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, L"65536", 5, NULL, 0, NULL, 0, NULL, 0, WS_E_INVALID_FORMAT, 0, NULL },
226 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 80, NULL, 0, NULL, 0, NULL, 0, NULL, 0, S_OK, 7, url8 },
227 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, NULL, 0, L"/path 2", 7, NULL, 0, NULL, 0, S_OK, 16, url9 },
228 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, NULL, 0, NULL, 0, L"query 2", 7, NULL, 0, S_OK, 17, url10 },
229 { WS_URL_HTTP_SCHEME_TYPE, NULL, 0, 0, NULL, 0, NULL, 0, NULL, 0, L"frag 2", 6, S_OK, 16, url11 },
230 { WS_URL_HTTP_SCHEME_TYPE, L"host 2", 6, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0, S_OK, 15, url12 },
232 WS_HEAP *heap;
233 WS_STRING str;
234 WS_HTTP_URL url;
235 HRESULT hr;
236 UINT i;
238 hr = WsCreateHeap( 1 << 16, 0, NULL, 0, &heap, NULL );
239 ok( hr == S_OK, "got %08x\n", hr );
241 hr = WsEncodeUrl( NULL, 0, heap, &str, NULL );
242 ok( hr == E_INVALIDARG, "got %08x\n", hr );
244 hr = WsEncodeUrl( (const WS_URL *)&url, 0, NULL, &str, NULL );
245 ok( hr == E_INVALIDARG, "got %08x\n", hr );
247 hr = WsEncodeUrl( (const WS_URL *)&url, 0, heap, NULL, NULL );
248 ok( hr == E_INVALIDARG, "got %08x\n", hr );
250 for (i = 0; i < ARRAY_SIZE( tests ); i++)
252 memset( &url, 0, sizeof(url) );
253 url.url.scheme = tests[i].scheme;
254 url.host.chars = (WCHAR *)tests[i].host;
255 url.host.length = tests[i].host_len;
256 url.port = tests[i].port;
257 url.portAsString.chars = (WCHAR *)tests[i].port_str;
258 url.portAsString.length = tests[i].port_len;
259 url.path.chars = (WCHAR *)tests[i].path;
260 url.path.length = tests[i].path_len;
261 url.query.chars = (WCHAR *)tests[i].query;
262 url.query.length = tests[i].query_len;
263 url.fragment.chars = (WCHAR *)tests[i].fragment;
264 url.fragment.length = tests[i].fragment_len;
266 memset( &str, 0, sizeof(str) );
267 hr = WsEncodeUrl( (const WS_URL *)&url, 0, heap, &str, NULL );
268 ok( hr == tests[i].hr, "%u: got %08x\n", i, hr );
269 if (hr != S_OK) continue;
271 ok( str.length == tests[i].len, "%u: got %u\n", i, str.length );
272 ok( !memcmp( str.chars, tests[i].chars, tests[i].len * sizeof(WCHAR) ),
273 "%u: wrong url %s\n", i, wine_dbgstr_wn(str.chars, str.length) );
276 WsFreeHeap( heap );
279 START_TEST(url)
281 test_WsDecodeUrl();
282 test_WsEncodeUrl();