2 * Web Services on Devices
5 * Copyright 2017 Owen Rudge for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
32 static void CreateUdpAddress_tests(void)
34 IWSDUdpAddress
*udpAddress
= NULL
, *udpAddress2
= NULL
;
35 IWSDTransportAddress
*transportAddress
= NULL
;
36 IWSDAddress
*address
= NULL
;
41 rc
= WSDCreateUdpAddress(NULL
);
42 ok((rc
== E_POINTER
) || (rc
== E_INVALIDARG
), "WSDCreateUDPAddress(NULL) failed: %08x\n", rc
);
44 rc
= WSDCreateUdpAddress(&udpAddress
);
45 ok(rc
== S_OK
, "WSDCreateUDPAddress(NULL, &udpAddress) failed: %08x\n", rc
);
46 ok(udpAddress
!= NULL
, "WSDCreateUDPAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
48 /* Try to query for objects */
49 rc
= IWSDUdpAddress_QueryInterface(udpAddress
, &IID_IWSDUdpAddress
, (LPVOID
*)&udpAddress2
);
50 ok(rc
== S_OK
, "IWSDUdpAddress_QueryInterface(IWSDUdpAddress) failed: %08x\n", rc
);
53 IWSDUdpAddress_Release(udpAddress2
);
55 rc
= IWSDUdpAddress_QueryInterface(udpAddress
, &IID_IWSDTransportAddress
, (LPVOID
*)&transportAddress
);
56 ok(rc
== S_OK
, "IWSDUdpAddress_QueryInterface(IID_WSDTransportAddress) failed: %08x\n", rc
);
59 IWSDTransportAddress_Release(transportAddress
);
61 rc
= IWSDUdpAddress_QueryInterface(udpAddress
, &IID_IWSDAddress
, (LPVOID
*)&address
);
62 ok(rc
== S_OK
, "IWSDUdpAddress_QueryInterface(IWSDAddress) failed: %08x\n", rc
);
65 IWSDAddress_Release(address
);
67 rc
= IWSDUdpAddress_QueryInterface(udpAddress
, &IID_IUnknown
, (LPVOID
*)&unknown
);
68 ok(rc
== S_OK
, "IWSDUdpAddress_QueryInterface(IID_IUnknown) failed: %08x\n", rc
);
71 IUnknown_Release(unknown
);
73 ref
= IWSDUdpAddress_Release(udpAddress
);
74 ok(ref
== 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ref
);
77 static void GetSetTransportAddress_udp_tests(void)
79 IWSDUdpAddress
*udpAddress
= NULL
;
80 const WCHAR
*ipv4Address
= L
"10.20.30.40";
81 const WCHAR
*ipv6Address
= L
"aabb:cd::abc";
82 const WCHAR
*ipv6AddressWithPort
= L
"[aabb:cd::abc:567]:124";
83 LPCWSTR returnedAddress
= NULL
;
88 ret
= WSAStartup(MAKEWORD(2, 2), &wsaData
);
89 ok(ret
== 0, "WSAStartup failed: %d\n", ret
);
91 rc
= WSDCreateUdpAddress(&udpAddress
);
92 ok(rc
== S_OK
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc
);
93 ok(udpAddress
!= NULL
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
95 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, &returnedAddress
);
96 ok(rc
== S_OK
, "GetTransportAddress returned unexpected result: %08x\n", rc
);
97 ok(returnedAddress
== NULL
, "GetTransportAddress returned unexpected address: %08x\n", rc
);
99 /* Try setting a null address */
100 rc
= IWSDUdpAddress_SetTransportAddress(udpAddress
, NULL
);
101 ok(rc
== E_INVALIDARG
, "SetTransportAddress(NULL) returned unexpected result: %08x\n", rc
);
103 /* Try setting an invalid address */
104 rc
= IWSDUdpAddress_SetTransportAddress(udpAddress
, L
"not/valid");
105 ok(rc
== HRESULT_FROM_WIN32(WSAHOST_NOT_FOUND
), "SetTransportAddress(invalidAddress) returned unexpected result: %08x\n", rc
);
107 /* Try setting an IPv4 address */
108 rc
= IWSDUdpAddress_SetTransportAddress(udpAddress
, ipv4Address
);
109 ok(rc
== S_OK
, "SetTransportAddress(ipv4Address) failed: %08x\n", rc
);
111 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, NULL
);
112 ok(rc
== E_POINTER
, "GetTransportAddress(NULL) returned unexpected result: %08x\n", rc
);
114 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, &returnedAddress
);
115 ok(rc
== S_OK
, "GetTransportAddress returned unexpected result: %08x\n", rc
);
116 ok(returnedAddress
!= NULL
, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress
));
117 ok(lstrcmpW(returnedAddress
, ipv4Address
) == 0, "Returned address != ipv4Address (%s)\n", wine_dbgstr_w(returnedAddress
));
119 /* Try setting an IPv4 address with a port number */
120 rc
= IWSDUdpAddress_SetTransportAddress(udpAddress
, L
"10.20.30.40:124");
121 ok(rc
== HRESULT_FROM_WIN32(WSAHOST_NOT_FOUND
), "SetTransportAddress(ipv4Address) failed: %08x\n", rc
);
123 /* Try setting an IPv6 address */
124 rc
= IWSDUdpAddress_SetTransportAddress(udpAddress
, ipv6Address
);
125 ok(rc
== S_OK
, "SetTransportAddress(ipv6Address) failed: %08x\n", rc
);
127 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, &returnedAddress
);
128 ok(rc
== S_OK
, "GetTransportAddress returned unexpected result: %08x\n", rc
);
129 ok(returnedAddress
!= NULL
, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress
));
130 ok(lstrcmpW(returnedAddress
, ipv6Address
) == 0, "Returned address != ipv6Address (%s)\n", wine_dbgstr_w(returnedAddress
));
132 /* Try setting an IPv6 address with a port number */
133 rc
= IWSDUdpAddress_SetTransportAddress(udpAddress
, ipv6AddressWithPort
);
134 ok(rc
== S_OK
, "SetTransportAddress(ipv6AddressWithPort) failed: %08x\n", rc
);
136 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, &returnedAddress
);
137 ok(rc
== S_OK
, "GetTransportAddress returned unexpected result: %08x\n", rc
);
138 ok(returnedAddress
!= NULL
, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress
));
139 todo_wine
ok(lstrcmpW(returnedAddress
, ipv6AddressWithPort
) == 0, "Returned address != ipv6AddressWithPort (%s)\n", wine_dbgstr_w(returnedAddress
));
141 /* Release the object */
142 ret
= IWSDUdpAddress_Release(udpAddress
);
143 ok(ret
== 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret
);
146 ok(ret
== 0, "WSACleanup failed: %d\n", ret
);
149 static void GetSetPort_udp_tests(void)
151 IWSDUdpAddress
*udpAddress
= NULL
;
152 WORD expectedPort1
= 12345;
153 WORD expectedPort2
= 8080;
158 rc
= WSDCreateUdpAddress(&udpAddress
);
159 ok(rc
== S_OK
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc
);
160 ok(udpAddress
!= NULL
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
162 /* No test for GetPort(NULL) as this causes an access violation exception on Windows */
164 rc
= IWSDUdpAddress_GetPort(udpAddress
, &actualPort
);
165 ok(rc
== S_OK
, "GetPort returned unexpected result: %08x\n", rc
);
166 ok(actualPort
== 0, "GetPort returned unexpected port: %d\n", actualPort
);
168 /* Try setting a zero port */
169 rc
= IWSDUdpAddress_SetPort(udpAddress
, 0);
170 ok(rc
== S_OK
, "SetPort returned unexpected result: %08x\n", rc
);
172 rc
= IWSDUdpAddress_GetPort(udpAddress
, &actualPort
);
173 ok(rc
== S_OK
, "GetPort returned unexpected result: %08x\n", rc
);
174 ok(actualPort
== 0, "GetPort returned unexpected port: %d\n", actualPort
);
176 /* Set a real port */
177 rc
= IWSDUdpAddress_SetPort(udpAddress
, expectedPort1
);
178 ok(rc
== S_OK
, "SetPort returned unexpected result: %08x\n", rc
);
180 rc
= IWSDUdpAddress_GetPort(udpAddress
, &actualPort
);
181 ok(rc
== S_OK
, "GetPort returned unexpected result: %08x\n", rc
);
182 ok(actualPort
== expectedPort1
, "GetPort returned unexpected port: %d\n", actualPort
);
184 /* Now set a different port */
185 rc
= IWSDUdpAddress_SetPort(udpAddress
, expectedPort2
);
186 ok(rc
== S_OK
, "SetPort returned unexpected result: %08x\n", rc
);
188 rc
= IWSDUdpAddress_GetPort(udpAddress
, &actualPort
);
189 ok(rc
== S_OK
, "GetPort returned unexpected result: %08x\n", rc
);
190 ok(actualPort
== expectedPort2
, "GetPort returned unexpected port: %d\n", actualPort
);
192 /* Release the object */
193 ret
= IWSDUdpAddress_Release(udpAddress
);
194 ok(ret
== 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret
);
197 static void GetSetMessageType_udp_tests(void)
199 WSDUdpMessageType expectedMessageType1
= TWO_WAY
;
200 WSDUdpMessageType expectedMessageType2
= ONE_WAY
;
201 WSDUdpMessageType actualMessageType
= 0;
202 IWSDUdpAddress
*udpAddress
= NULL
;
206 rc
= WSDCreateUdpAddress(&udpAddress
);
207 ok(rc
== S_OK
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc
);
208 ok(udpAddress
!= NULL
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
210 rc
= IWSDUdpAddress_GetMessageType(udpAddress
, NULL
);
211 ok(rc
== E_POINTER
, "GetMessageType returned unexpected result: %08x\n", rc
);
213 rc
= IWSDUdpAddress_GetMessageType(udpAddress
, &actualMessageType
);
214 ok(rc
== S_OK
, "GetMessageType returned unexpected result: %08x\n", rc
);
215 ok(actualMessageType
== 0, "GetMessageType returned unexpected message type: %d\n", actualMessageType
);
217 /* Try setting a message type */
218 rc
= IWSDUdpAddress_SetMessageType(udpAddress
, expectedMessageType1
);
219 ok(rc
== S_OK
, "SetMessageType returned unexpected result: %08x\n", rc
);
221 rc
= IWSDUdpAddress_GetMessageType(udpAddress
, &actualMessageType
);
222 ok(rc
== S_OK
, "GetMessageType returned unexpected result: %08x\n", rc
);
223 ok(actualMessageType
== expectedMessageType1
, "GetMessageType returned unexpected message type: %d\n", actualMessageType
);
225 /* Set another one */
226 rc
= IWSDUdpAddress_SetMessageType(udpAddress
, expectedMessageType2
);
227 ok(rc
== S_OK
, "SetMessageType returned unexpected result: %08x\n", rc
);
229 rc
= IWSDUdpAddress_GetMessageType(udpAddress
, &actualMessageType
);
230 ok(rc
== S_OK
, "GetMessageType returned unexpected result: %08x\n", rc
);
231 ok(actualMessageType
== expectedMessageType2
, "GetMessageType returned unexpected message type: %d\n", actualMessageType
);
233 /* Release the object */
234 ret
= IWSDUdpAddress_Release(udpAddress
);
235 ok(ret
== 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret
);
238 static void GetSetSockaddr_udp_tests(void)
240 SOCKADDR_STORAGE storage1
, storage2
;
241 SOCKADDR_STORAGE returnedStorage
;
242 struct sockaddr_in6
*sockAddr6Ptr
;
243 struct sockaddr_in
*sockAddrPtr
;
244 IWSDUdpAddress
*udpAddress
= NULL
;
245 LPCWSTR returnedAddress
= NULL
;
246 char addressBuffer
[MAX_PATH
];
253 const char *ipv4Address
= "1.2.3.4";
254 const short ipv4Port
= 1234;
256 const char *ipv6Address
= "2a00:1234:5678:dead:beef::aaaa";
257 const short ipv6Port
= 2345;
258 const WCHAR
*expectedIpv6TransportAddr
= L
"[2a00:1234:5678:dead:beef::aaaa]:2345";
260 ZeroMemory(&storage1
, sizeof(SOCKADDR_STORAGE
));
261 ZeroMemory(&storage2
, sizeof(SOCKADDR_STORAGE
));
262 ZeroMemory(&returnedStorage
, sizeof(SOCKADDR_STORAGE
));
264 ret
= WSAStartup(MAKEWORD(2, 2), &wsaData
);
265 ok(ret
== 0, "WSAStartup failed: %d\n", ret
);
267 rc
= WSDCreateUdpAddress(&udpAddress
);
268 ok(rc
== S_OK
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc
);
269 ok(udpAddress
!= NULL
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
271 rc
= IWSDUdpAddress_GetSockaddr(udpAddress
, NULL
);
272 ok(rc
== E_POINTER
, "GetSockaddr returned unexpected result: %08x\n", rc
);
274 rc
= IWSDUdpAddress_GetSockaddr(udpAddress
, &returnedStorage
);
275 ok(rc
== E_FAIL
, "GetSockaddr returned unexpected result: %08x\n", rc
);
277 /* Try setting a transport address */
278 rc
= IWSDUdpAddress_SetTransportAddress(udpAddress
, expectedIpv6TransportAddr
);
279 ok(rc
== S_OK
, "SetTransportAddress failed: %08x\n", rc
);
281 /* A socket address should be returned */
282 rc
= IWSDUdpAddress_GetSockaddr(udpAddress
, &returnedStorage
);
283 ok(rc
== S_OK
, "GetSockaddr returned unexpected result: %08x\n", rc
);
284 ok(returnedStorage
.ss_family
== AF_INET6
, "returnedStorage.ss_family != AF_INET6 (%d)\n", returnedStorage
.ss_family
);
286 sockAddr6Ptr
= (struct sockaddr_in6
*) &returnedStorage
;
288 /* Windows however doesn't set the port number */
289 ok(sockAddr6Ptr
->sin6_port
== 0, "returnedStorage.sin6_port != 0 (%d)\n", sockAddr6Ptr
->sin6_port
);
291 cret
= inet_ntop(returnedStorage
.ss_family
, &sockAddr6Ptr
->sin6_addr
, addressBuffer
, MAX_PATH
);
292 ok(cret
!= NULL
, "inet_ntop failed (%d)\n", WSAGetLastError());
293 ok(strcmp(addressBuffer
, ipv6Address
) == 0, "returnedStorage.sin6_addr != '%s' ('%s')\n", ipv6Address
, addressBuffer
);
295 /* Release the object and create a new one */
296 ret
= IWSDUdpAddress_Release(udpAddress
);
297 ok(ret
== 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret
);
299 rc
= WSDCreateUdpAddress(&udpAddress
);
300 ok(rc
== S_OK
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc
);
301 ok(udpAddress
!= NULL
, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
303 /* Try setting an IPv4 address */
304 sockAddrPtr
= (struct sockaddr_in
*) &storage1
;
305 sockAddrPtr
->sin_family
= AF_INET
;
306 sockAddrPtr
->sin_port
= htons(ipv4Port
);
308 ret
= inet_pton(AF_INET
, ipv4Address
, &sockAddrPtr
->sin_addr
);
309 ok(ret
== 1, "inet_pton(ipv4) failed: %d\n", WSAGetLastError());
311 rc
= IWSDUdpAddress_SetSockaddr(udpAddress
, &storage1
);
312 ok(rc
== S_OK
, "SetSockaddr returned unexpected result: %08x\n", rc
);
314 rc
= IWSDUdpAddress_GetSockaddr(udpAddress
, &returnedStorage
);
315 ok(rc
== S_OK
, "GetSockaddr returned unexpected result: %08x\n", rc
);
317 ok(returnedStorage
.ss_family
== storage1
.ss_family
, "returnedStorage.ss_family != storage1.ss_family (%d)\n", returnedStorage
.ss_family
);
318 ok(memcmp(&returnedStorage
, &storage1
, sizeof(struct sockaddr_in
)) == 0, "returnedStorage != storage1\n");
320 /* Check that GetTransportAddress returns the address set via the socket */
321 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, &returnedAddress
);
322 ok(rc
== S_OK
, "GetTransportAddress failed: %08x\n", rc
);
323 ok(returnedAddress
!= NULL
, "GetTransportAddress returned unexpected address: %p\n", returnedAddress
);
324 ok(lstrcmpW(returnedAddress
, L
"1.2.3.4:1234") == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress
));
326 /* Check that GetPort doesn't return the port set via the socket */
327 rc
= IWSDUdpAddress_GetPort(udpAddress
, &port
);
328 ok(rc
== S_OK
, "GetPort returned unexpected result: %08x\n", rc
);
329 ok(port
== 0, "GetPort returned unexpected port: %d\n", port
);
331 /* Try setting an IPv4 address without a port */
332 sockAddrPtr
->sin_port
= 0;
334 rc
= IWSDUdpAddress_SetSockaddr(udpAddress
, &storage1
);
335 ok(rc
== S_OK
, "SetSockaddr returned unexpected result: %08x\n", rc
);
337 /* Check that GetTransportAddress returns the address set via the socket */
338 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, &returnedAddress
);
339 ok(rc
== S_OK
, "GetTransportAddress failed: %08x\n", rc
);
340 ok(returnedAddress
!= NULL
, "GetTransportAddress returned unexpected address: %p\n", returnedAddress
);
341 ok(lstrcmpW(returnedAddress
, L
"1.2.3.4") == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress
));
343 /* Try setting an IPv6 address */
344 sockAddr6Ptr
= (struct sockaddr_in6
*) &storage2
;
345 sockAddr6Ptr
->sin6_family
= AF_INET6
;
346 sockAddr6Ptr
->sin6_port
= htons(ipv6Port
);
348 ret
= inet_pton(AF_INET6
, ipv6Address
, &sockAddr6Ptr
->sin6_addr
);
349 ok(ret
== 1, "inet_pton(ipv6) failed: %d\n", WSAGetLastError());
351 rc
= IWSDUdpAddress_SetSockaddr(udpAddress
, &storage2
);
352 ok(rc
== S_OK
, "SetSockaddr returned unexpected result: %08x\n", rc
);
354 rc
= IWSDUdpAddress_GetSockaddr(udpAddress
, &returnedStorage
);
355 ok(rc
== S_OK
, "GetSockaddr returned unexpected result: %08x\n", rc
);
357 ok(returnedStorage
.ss_family
== storage2
.ss_family
, "returnedStorage.ss_family != storage2.ss_family (%d)\n", returnedStorage
.ss_family
);
358 ok(memcmp(&returnedStorage
, &storage2
, sizeof(struct sockaddr_in6
)) == 0, "returnedStorage != storage2\n");
360 /* Check that GetTransportAddress returns the address set via the socket */
361 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, &returnedAddress
);
362 ok(rc
== S_OK
, "GetTransportAddress failed: %08x\n", rc
);
363 ok(returnedAddress
!= NULL
, "GetTransportAddress returned unexpected address: %p\n", returnedAddress
);
364 ok(lstrcmpW(returnedAddress
, expectedIpv6TransportAddr
) == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress
));
366 /* Check that GetPort doesn't return the port set via the socket */
367 rc
= IWSDUdpAddress_GetPort(udpAddress
, &port
);
368 ok(rc
== S_OK
, "GetPort returned unexpected result: %08x\n", rc
);
369 ok(port
== 0, "GetPort returned unexpected port: %d\n", port
);
371 /* Try setting an IPv6 address without a port */
372 sockAddr6Ptr
->sin6_port
= 0;
374 rc
= IWSDUdpAddress_SetSockaddr(udpAddress
, &storage2
);
375 ok(rc
== S_OK
, "SetSockaddr returned unexpected result: %08x\n", rc
);
377 /* Check that GetTransportAddress returns the address set via the socket */
378 rc
= IWSDUdpAddress_GetTransportAddress(udpAddress
, &returnedAddress
);
379 ok(rc
== S_OK
, "GetTransportAddress failed: %08x\n", rc
);
380 ok(returnedAddress
!= NULL
, "GetTransportAddress returned unexpected address: %p\n", returnedAddress
);
381 ok(lstrcmpW(returnedAddress
, L
"2a00:1234:5678:dead:beef::aaaa") == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress
));
383 rc
= IWSDUdpAddress_SetSockaddr(udpAddress
, &storage2
);
384 ok(rc
== S_OK
, "SetSockaddr returned unexpected result: %08x\n", rc
);
386 /* Release the object */
387 ret
= IWSDUdpAddress_Release(udpAddress
);
388 ok(ret
== 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret
);
391 ok(ret
== 0, "WSACleanup failed: %d\n", ret
);
398 CreateUdpAddress_tests();
399 GetSetTransportAddress_udp_tests();
400 GetSetPort_udp_tests();
401 GetSetMessageType_udp_tests();
402 GetSetSockaddr_udp_tests();