windowscodecs: Implement IWICMetadataQueryReader::GetContainerFormat.
[wine.git] / dlls / wsdapi / tests / address.c
blobfefc25384d1109558e243a98ff34f7b667dbc361
1 /*
2 * Web Services on Devices
3 * Address tests
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
22 #define COBJMACROS
24 #include <winsock2.h>
25 #include <ws2tcpip.h>
26 #include <windows.h>
28 #include "wine/test.h"
29 #include "objbase.h"
30 #include "wsdapi.h"
32 static void CreateUdpAddress_tests(void)
34 IWSDUdpAddress *udpAddress = NULL, *udpAddress2 = NULL;
35 IWSDTransportAddress *transportAddress = NULL;
36 IWSDAddress *address = NULL;
37 IUnknown *unknown;
38 HRESULT rc;
39 ULONG ref;
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);
52 if (rc == S_OK)
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);
58 if (rc == S_OK)
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);
64 if (rc == S_OK)
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);
70 if (rc == S_OK)
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[] = {'1','0','.','2','0','.','3','0','.','4','0',0};
81 const WCHAR ipv6Address[] = {'a','a','b','b',':','c','d',':',':','a','b','c',0};
82 const WCHAR invalidAddress[] = {'n','o','t','/','v','a','l','i','d',0};
83 LPCWSTR returnedAddress = NULL;
84 WSADATA wsaData;
85 HRESULT rc;
86 int ret;
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 todo_wine 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 todo_wine ok(rc == E_INVALIDARG, "SetTransportAddress(NULL) returned unexpected result: %08x\n", rc);
103 /* Try setting an invalid address */
104 rc = IWSDUdpAddress_SetTransportAddress(udpAddress, invalidAddress);
105 todo_wine 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 todo_wine ok(rc == S_OK, "SetTransportAddress(ipv4Address) failed: %08x\n", rc);
111 rc = IWSDUdpAddress_GetTransportAddress(udpAddress, NULL);
112 todo_wine ok(rc == E_POINTER, "GetTransportAddress(NULL) returned unexpected result: %08x\n", rc);
114 rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress);
115 todo_wine ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc);
116 todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress));
117 todo_wine ok(lstrcmpW(returnedAddress, ipv4Address) == 0, "Returned address != ipv4Address (%s)\n", wine_dbgstr_w(returnedAddress));
119 /* Try setting an IPv6 address */
120 rc = IWSDUdpAddress_SetTransportAddress(udpAddress, ipv6Address);
121 todo_wine ok(rc == S_OK, "SetTransportAddress(ipv6Address) failed: %08x\n", rc);
123 rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress);
124 todo_wine ok(rc == S_OK, "GetTransportAddress returned unexpected result: %08x\n", rc);
125 todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: '%s'\n", wine_dbgstr_w(returnedAddress));
126 todo_wine ok(lstrcmpW(returnedAddress, ipv6Address) == 0, "Returned address != ipv6Address (%s)\n", wine_dbgstr_w(returnedAddress));
128 /* Release the object */
129 ret = IWSDUdpAddress_Release(udpAddress);
130 ok(ret == 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret);
132 ret = WSACleanup();
133 ok(ret == 0, "WSACleanup failed: %d\n", ret);
136 static void GetSetPort_udp_tests(void)
138 IWSDUdpAddress *udpAddress = NULL;
139 WORD expectedPort1 = 12345;
140 WORD expectedPort2 = 8080;
141 WORD actualPort = 0;
142 HRESULT rc;
143 int ret;
145 rc = WSDCreateUdpAddress(&udpAddress);
146 ok(rc == S_OK, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc);
147 ok(udpAddress != NULL, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
149 /* No test for GetPort(NULL) as this causes an access violation exception on Windows */
151 rc = IWSDUdpAddress_GetPort(udpAddress, &actualPort);
152 todo_wine ok(rc == S_OK, "GetPort returned unexpected result: %08x\n", rc);
153 ok(actualPort == 0, "GetPort returned unexpected port: %d\n", actualPort);
155 /* Try setting a zero port */
156 rc = IWSDUdpAddress_SetPort(udpAddress, 0);
157 todo_wine ok(rc == S_OK, "SetPort returned unexpected result: %08x\n", rc);
159 rc = IWSDUdpAddress_GetPort(udpAddress, &actualPort);
160 todo_wine ok(rc == S_OK, "GetPort returned unexpected result: %08x\n", rc);
161 ok(actualPort == 0, "GetPort returned unexpected port: %d\n", actualPort);
163 /* Set a real port */
164 rc = IWSDUdpAddress_SetPort(udpAddress, expectedPort1);
165 todo_wine ok(rc == S_OK, "SetPort returned unexpected result: %08x\n", rc);
167 rc = IWSDUdpAddress_GetPort(udpAddress, &actualPort);
168 todo_wine ok(rc == S_OK, "GetPort returned unexpected result: %08x\n", rc);
169 todo_wine ok(actualPort == expectedPort1, "GetPort returned unexpected port: %d\n", actualPort);
171 /* Now set a different port */
172 rc = IWSDUdpAddress_SetPort(udpAddress, expectedPort2);
173 todo_wine ok(rc == S_OK, "SetPort returned unexpected result: %08x\n", rc);
175 rc = IWSDUdpAddress_GetPort(udpAddress, &actualPort);
176 todo_wine ok(rc == S_OK, "GetPort returned unexpected result: %08x\n", rc);
177 todo_wine ok(actualPort == expectedPort2, "GetPort returned unexpected port: %d\n", actualPort);
179 /* Release the object */
180 ret = IWSDUdpAddress_Release(udpAddress);
181 ok(ret == 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret);
184 static void GetSetMessageType_udp_tests(void)
186 WSDUdpMessageType expectedMessageType1 = TWO_WAY;
187 WSDUdpMessageType expectedMessageType2 = ONE_WAY;
188 WSDUdpMessageType actualMessageType = 0;
189 IWSDUdpAddress *udpAddress = NULL;
190 HRESULT rc;
191 int ret;
193 rc = WSDCreateUdpAddress(&udpAddress);
194 ok(rc == S_OK, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc);
195 ok(udpAddress != NULL, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
197 rc = IWSDUdpAddress_GetMessageType(udpAddress, NULL);
198 todo_wine ok(rc == E_POINTER, "GetMessageType returned unexpected result: %08x\n", rc);
200 rc = IWSDUdpAddress_GetMessageType(udpAddress, &actualMessageType);
201 todo_wine ok(rc == S_OK, "GetMessageType returned unexpected result: %08x\n", rc);
202 ok(actualMessageType == 0, "GetMessageType returned unexpected message type: %d\n", actualMessageType);
204 /* Try setting a message type */
205 rc = IWSDUdpAddress_SetMessageType(udpAddress, expectedMessageType1);
206 todo_wine ok(rc == S_OK, "SetMessageType returned unexpected result: %08x\n", rc);
208 rc = IWSDUdpAddress_GetMessageType(udpAddress, &actualMessageType);
209 todo_wine ok(rc == S_OK, "GetMessageType returned unexpected result: %08x\n", rc);
210 todo_wine ok(actualMessageType == expectedMessageType1, "GetMessageType returned unexpected message type: %d\n", actualMessageType);
212 /* Set another one */
213 rc = IWSDUdpAddress_SetMessageType(udpAddress, expectedMessageType2);
214 todo_wine ok(rc == S_OK, "SetMessageType returned unexpected result: %08x\n", rc);
216 rc = IWSDUdpAddress_GetMessageType(udpAddress, &actualMessageType);
217 todo_wine ok(rc == S_OK, "GetMessageType returned unexpected result: %08x\n", rc);
218 ok(actualMessageType == expectedMessageType2, "GetMessageType returned unexpected message type: %d\n", actualMessageType);
220 /* Release the object */
221 ret = IWSDUdpAddress_Release(udpAddress);
222 ok(ret == 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret);
225 static void GetSetSockaddr_udp_tests(void)
227 SOCKADDR_STORAGE storage1, storage2;
228 SOCKADDR_STORAGE returnedStorage;
229 struct sockaddr_in6 *sockAddr6Ptr;
230 struct sockaddr_in *sockAddrPtr;
231 IWSDUdpAddress *udpAddress = NULL;
232 LPCWSTR returnedAddress = NULL;
233 char addressBuffer[MAX_PATH];
234 WSADATA wsaData;
235 WORD port = 0;
236 HRESULT rc;
237 int ret;
239 const char *ipv4Address = "1.2.3.4";
240 const short ipv4Port = 1234;
241 const WCHAR expectedIpv4TransportAddr[] = {'1','.','2','.','3','.','4',':','1','2','3','4',0};
243 const char *ipv6Address = "2a00:1234:5678:dead:beef::aaaa";
244 const short ipv6Port = 2345;
245 const WCHAR expectedIpv6TransportAddr[] = {'[','2','a','0','0',':','1','2','3','4',':','5','6','7','8',':','d','e','a','d',':',
246 'b','e','e','f',':',':','a','a','a','a',']',':','2','3','4','5',0};
248 ZeroMemory(&storage1, sizeof(SOCKADDR_STORAGE));
249 ZeroMemory(&storage2, sizeof(SOCKADDR_STORAGE));
250 ZeroMemory(&returnedStorage, sizeof(SOCKADDR_STORAGE));
252 ret = WSAStartup(MAKEWORD(2, 2), &wsaData);
253 ok(ret == 0, "WSAStartup failed: %d\n", ret);
255 rc = WSDCreateUdpAddress(&udpAddress);
256 ok(rc == S_OK, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc);
257 ok(udpAddress != NULL, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
259 rc = IWSDUdpAddress_GetSockaddr(udpAddress, NULL);
260 todo_wine ok(rc == E_POINTER, "GetSockaddr returned unexpected result: %08x\n", rc);
262 rc = IWSDUdpAddress_GetSockaddr(udpAddress, &returnedStorage);
263 todo_wine ok(rc == E_FAIL, "GetSockaddr returned unexpected result: %08x\n", rc);
265 /* Try setting a transport address */
266 rc = IWSDUdpAddress_SetTransportAddress(udpAddress, expectedIpv6TransportAddr);
267 todo_wine ok(rc == S_OK, "SetTransportAddress failed: %08x\n", rc);
269 /* A socket address should be returned */
270 rc = IWSDUdpAddress_GetSockaddr(udpAddress, &returnedStorage);
271 todo_wine ok(rc == S_OK, "GetSockaddr returned unexpected result: %08x\n", rc);
272 todo_wine ok(returnedStorage.ss_family == AF_INET6, "returnedStorage.ss_family != AF_INET6 (%d)\n", returnedStorage.ss_family);
274 sockAddr6Ptr = (struct sockaddr_in6 *) &returnedStorage;
276 /* Windows however doesn't set the port number */
277 ok(sockAddr6Ptr->sin6_port == 0, "returnedStorage.sin6_port != 0 (%d)\n", sockAddr6Ptr->sin6_port);
279 todo_wine ok(inet_ntop(returnedStorage.ss_family, &sockAddr6Ptr->sin6_addr, addressBuffer, MAX_PATH) != NULL, "inet_ntop failed (%d)\n", WSAGetLastError());
280 todo_wine ok(strcmp(addressBuffer, ipv6Address) == 0, "returnedStorage.sin6_addr != '%s' ('%s')\n", ipv6Address, addressBuffer);
282 /* Release the object and create a new one */
283 ret = IWSDUdpAddress_Release(udpAddress);
284 ok(ret == 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret);
286 rc = WSDCreateUdpAddress(&udpAddress);
287 ok(rc == S_OK, "WSDCreateUdpAddress(NULL, &udpAddress) failed: %08x\n", rc);
288 ok(udpAddress != NULL, "WSDCreateUdpAddress(NULL, &udpAddress) failed: udpAddress == NULL\n");
290 /* Try setting an IPv4 address */
291 sockAddrPtr = (struct sockaddr_in *) &storage1;
292 sockAddrPtr->sin_family = AF_INET;
293 sockAddrPtr->sin_port = htons(ipv4Port);
295 ret = inet_pton(AF_INET, ipv4Address, &sockAddrPtr->sin_addr);
296 ok(ret == 1, "inet_pton(ipv4) failed: %d\n", WSAGetLastError());
298 rc = IWSDUdpAddress_SetSockaddr(udpAddress, &storage1);
299 todo_wine ok(rc == S_OK, "SetSockaddr returned unexpected result: %08x\n", rc);
301 rc = IWSDUdpAddress_GetSockaddr(udpAddress, &returnedStorage);
302 todo_wine ok(rc == S_OK, "GetSockaddr returned unexpected result: %08x\n", rc);
304 todo_wine ok(returnedStorage.ss_family == storage1.ss_family, "returnedStorage.ss_family != storage1.ss_family (%d)\n", returnedStorage.ss_family);
305 todo_wine ok(memcmp(&returnedStorage, &storage1, sizeof(struct sockaddr_in)) == 0, "returnedStorage != storage1\n");
307 /* Check that GetTransportAddress returns the address set via the socket */
308 rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress);
309 todo_wine ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc);
310 todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: %p\n", returnedAddress);
311 todo_wine ok(lstrcmpW(returnedAddress, expectedIpv4TransportAddr) == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress));
313 /* Check that GetPort doesn't return the port set via the socket */
314 rc = IWSDUdpAddress_GetPort(udpAddress, &port);
315 todo_wine ok(rc == S_OK, "GetPort returned unexpected result: %08x\n", rc);
316 ok(port == 0, "GetPort returned unexpected port: %d\n", port);
318 /* Try setting an IPv6 address */
319 sockAddr6Ptr = (struct sockaddr_in6 *) &storage2;
320 sockAddr6Ptr->sin6_family = AF_INET6;
321 sockAddr6Ptr->sin6_port = htons(ipv6Port);
323 ret = inet_pton(AF_INET6, ipv6Address, &sockAddr6Ptr->sin6_addr);
324 ok(ret == 1, "inet_pton(ipv6) failed: %d\n", WSAGetLastError());
326 rc = IWSDUdpAddress_SetSockaddr(udpAddress, &storage2);
327 todo_wine ok(rc == S_OK, "SetSockaddr returned unexpected result: %08x\n", rc);
329 rc = IWSDUdpAddress_GetSockaddr(udpAddress, &returnedStorage);
330 todo_wine ok(rc == S_OK, "GetSockaddr returned unexpected result: %08x\n", rc);
332 todo_wine ok(returnedStorage.ss_family == storage2.ss_family, "returnedStorage.ss_family != storage2.ss_family (%d)\n", returnedStorage.ss_family);
333 todo_wine ok(memcmp(&returnedStorage, &storage2, sizeof(struct sockaddr_in6)) == 0, "returnedStorage != storage2\n");
335 /* Check that GetTransportAddress returns the address set via the socket */
336 rc = IWSDUdpAddress_GetTransportAddress(udpAddress, &returnedAddress);
337 todo_wine ok(rc == S_OK, "GetTransportAddress failed: %08x\n", rc);
338 todo_wine ok(returnedAddress != NULL, "GetTransportAddress returned unexpected address: %p\n", returnedAddress);
339 todo_wine ok(lstrcmpW(returnedAddress, expectedIpv6TransportAddr) == 0, "GetTransportAddress returned unexpected address: %s\n", wine_dbgstr_w(returnedAddress));
341 /* Check that GetPort doesn't return the port set via the socket */
342 rc = IWSDUdpAddress_GetPort(udpAddress, &port);
343 todo_wine ok(rc == S_OK, "GetPort returned unexpected result: %08x\n", rc);
344 ok(port == 0, "GetPort returned unexpected port: %d\n", port);
346 /* Release the object */
347 ret = IWSDUdpAddress_Release(udpAddress);
348 ok(ret == 0, "IWSDUdpAddress_Release() has %d references, should have 0\n", ret);
350 ret = WSACleanup();
351 ok(ret == 0, "WSACleanup failed: %d\n", ret);
354 START_TEST(address)
356 CoInitialize(NULL);
358 CreateUdpAddress_tests();
359 GetSetTransportAddress_udp_tests();
360 GetSetPort_udp_tests();
361 GetSetMessageType_udp_tests();
362 GetSetSockaddr_udp_tests();
364 CoUninitialize();