wined3d: Correctly destroy the adapter on format initialization failure in no3d mode.
[wine/zf.git] / dlls / wsdapi / tests / msgparams.c
blob9322ce1737162a6f9aafce7fac4769e9fb47a8a7
1 /*
2 * Web Services on Devices
3 * Message Parameters 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 <windows.h>
27 #include "wine/test.h"
28 #include "objbase.h"
29 #include "wsdapi.h"
31 static void CreateUdpMessageParameters_tests(void)
33 IWSDUdpMessageParameters *udpMessageParams = NULL, *udpMessageParams2 = NULL;
34 IWSDMessageParameters *messageParams = NULL;
35 IUnknown *unknown;
36 HRESULT rc;
37 ULONG ref;
39 rc = WSDCreateUdpMessageParameters(NULL);
40 ok((rc == E_POINTER) || (rc == E_INVALIDARG), "WSDCreateUdpMessageParameters(NULL) failed: %08x\n", rc);
42 rc = WSDCreateUdpMessageParameters(&udpMessageParams);
43 ok(rc == S_OK, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: %08x\n", rc);
44 ok(udpMessageParams != NULL, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: udpMessageParams == NULL\n");
46 /* Try to query for objects */
47 rc = IWSDUdpMessageParameters_QueryInterface(udpMessageParams, &IID_IWSDUdpMessageParameters, (LPVOID*)&udpMessageParams2);
48 ok(rc == S_OK, "IWSDUdpMessageParams_QueryInterface(IID_IWSDUdpMessageParameters) failed: %08x\n", rc);
50 if (rc == S_OK)
51 IWSDUdpMessageParameters_Release(udpMessageParams2);
53 rc = IWSDUdpMessageParameters_QueryInterface(udpMessageParams, &IID_IWSDMessageParameters, (LPVOID*)&messageParams);
54 ok(rc == S_OK, "IWSDUdpMessageParams_QueryInterface(IID_WSDMessageParameters) failed: %08x\n", rc);
56 if (rc == S_OK)
57 IWSDMessageParameters_Release(messageParams);
59 rc = IWSDUdpMessageParameters_QueryInterface(udpMessageParams, &IID_IUnknown, (LPVOID*)&unknown);
60 ok(rc == S_OK, "IWSDUdpMessageParams_QueryInterface(IID_IUnknown) failed: %08x\n", rc);
62 if (rc == S_OK)
63 IUnknown_Release(unknown);
65 ref = IWSDUdpMessageParameters_Release(udpMessageParams);
66 ok(ref == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ref);
69 static void LocalAddress_tests(void)
71 IWSDUdpAddress *origUdpAddress = NULL;
72 IWSDAddress *returnedAddress = NULL;
73 IWSDUdpMessageParameters *udpMessageParams = NULL;
74 WCHAR address[] = {'1','.','2','.','3','.','4',0};
75 WSADATA wsaData;
76 HRESULT rc;
77 int ret;
79 ret = WSAStartup(MAKEWORD(2, 2), &wsaData);
80 ok(ret == 0, "WSAStartup failed: %d\n", ret);
82 rc = WSDCreateUdpMessageParameters(&udpMessageParams);
83 ok(rc == S_OK, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: %08x\n", rc);
84 ok(udpMessageParams != NULL, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: udpMessageParams == NULL\n");
86 rc = IWSDUdpMessageParameters_GetLocalAddress(udpMessageParams, NULL);
87 ok(rc == E_POINTER, "GetLocalAddress failed: %08x\n", rc);
88 ok(returnedAddress == NULL, "GetLocalAddress returned %p\n", returnedAddress);
90 rc = IWSDUdpMessageParameters_GetLocalAddress(udpMessageParams, &returnedAddress);
91 ok(rc == E_ABORT, "GetLocalAddress failed: %08x\n", rc);
92 ok(returnedAddress == NULL, "GetLocalAddress returned %p\n", returnedAddress);
94 rc = WSDCreateUdpAddress(&origUdpAddress);
95 ok(rc == S_OK, "WSDCreateUdpAddress(NULL, &origUdpAddress) failed: %08x\n", rc);
96 ok(origUdpAddress != NULL, "WSDCreateUdpMessageParameters(NULL, &origUdpAddress) failed: origUdpAddress == NULL\n");
98 rc = IWSDUdpAddress_SetTransportAddress(origUdpAddress, address);
99 ok(rc == S_OK, "SetTransportAddress failed: %08x\n", rc);
101 rc = IWSDUdpMessageParameters_SetLocalAddress(udpMessageParams, (IWSDAddress *)origUdpAddress);
102 ok(rc == S_OK, "SetLocalAddress failed: %08x\n", rc);
104 rc = IWSDUdpMessageParameters_GetLocalAddress(udpMessageParams, &returnedAddress);
105 ok(rc == S_OK, "GetLocalAddress failed: %08x\n", rc);
106 ok(returnedAddress != NULL, "GetLocalAddress returned NULL\n");
108 /* Check if GetLocalAddress returns the same object */
109 ok(returnedAddress == (IWSDAddress *)origUdpAddress, "returnedAddress != origUdpAddress\n");
111 ret = IWSDUdpMessageParameters_Release(udpMessageParams);
112 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
114 if (returnedAddress != NULL)
116 ret = IWSDAddress_Release(returnedAddress);
117 ok(ret == 1, "IWSDAddress_Release() has %d references, should have 1\n", ret);
120 ret = IWSDUdpAddress_Release(origUdpAddress);
121 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
123 ret = WSACleanup();
124 ok(ret == 0, "WSACleanup failed: %d\n", ret);
127 static void RemoteAddress_tests(void)
129 IWSDUdpAddress *origUdpAddress = NULL;
130 IWSDAddress *returnedAddress = NULL;
131 IWSDUdpMessageParameters *udpMessageParams = NULL;
132 WCHAR address[] = {'1','.','2','.','3','.','4',0};
133 WSADATA wsaData;
134 HRESULT rc;
135 int ret;
137 ret = WSAStartup(MAKEWORD(2, 2), &wsaData);
138 ok(ret == 0, "WSAStartup failed: %d\n", ret);
140 rc = WSDCreateUdpMessageParameters(&udpMessageParams);
141 ok(rc == S_OK, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: %08x\n", rc);
142 ok(udpMessageParams != NULL, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: udpMessageParams == NULL\n");
144 rc = IWSDUdpMessageParameters_GetRemoteAddress(udpMessageParams, NULL);
145 ok(rc == E_POINTER, "GetRemoteAddress failed: %08x\n", rc);
146 ok(returnedAddress == NULL, "GetRemoteAddress returned %p\n", returnedAddress);
148 rc = IWSDUdpMessageParameters_GetRemoteAddress(udpMessageParams, &returnedAddress);
149 ok(rc == E_ABORT, "GetRemoteAddress failed: %08x\n", rc);
150 ok(returnedAddress == NULL, "GetRemoteAddress returned %p\n", returnedAddress);
152 rc = WSDCreateUdpAddress(&origUdpAddress);
153 ok(rc == S_OK, "WSDCreateUdpAddress(NULL, &origUdpAddress) failed: %08x\n", rc);
154 ok(origUdpAddress != NULL, "WSDCreateUdpMessageParameters(NULL, &origUdpAddress) failed: origUdpAddress == NULL\n");
156 rc = IWSDUdpAddress_SetTransportAddress(origUdpAddress, address);
157 ok(rc == S_OK, "SetTransportAddress failed: %08x\n", rc);
159 rc = IWSDUdpMessageParameters_SetRemoteAddress(udpMessageParams, (IWSDAddress *)origUdpAddress);
160 ok(rc == S_OK, "SetRemoteAddress failed: %08x\n", rc);
162 rc = IWSDUdpMessageParameters_GetRemoteAddress(udpMessageParams, &returnedAddress);
163 ok(rc == S_OK, "GetRemoteAddress failed: %08x\n", rc);
164 ok(returnedAddress != NULL, "GetLocalAddress returned NULL\n");
166 /* Check if GetRemoteAddress returns the same object */
167 ok(returnedAddress == (IWSDAddress *)origUdpAddress, "returnedAddress != origUdpAddress\n");
169 ret = IWSDUdpMessageParameters_Release(udpMessageParams);
170 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
172 if (returnedAddress != NULL)
174 ret = IWSDAddress_Release(returnedAddress);
175 ok(ret == 1, "IWSDAddress_Release() has %d references, should have 1\n", ret);
178 ret = IWSDUdpAddress_Release(origUdpAddress);
179 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
181 ret = WSACleanup();
182 ok(ret == 0, "WSACleanup failed: %d\n", ret);
185 static void RetransmitParams_tests(void)
187 WSDUdpRetransmitParams origParams, returnedParams;
188 IWSDUdpMessageParameters *udpMessageParams = NULL;
189 HRESULT rc;
190 int ret;
192 ZeroMemory(&origParams, sizeof(WSDUdpRetransmitParams));
193 ZeroMemory(&returnedParams, sizeof(WSDUdpRetransmitParams));
195 rc = WSDCreateUdpMessageParameters(&udpMessageParams);
196 ok(rc == S_OK, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: %08x\n", rc);
197 ok(udpMessageParams != NULL, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: udpMessageParams == NULL\n");
199 rc = IWSDUdpMessageParameters_GetRetransmitParams(udpMessageParams, NULL);
200 ok(rc == E_POINTER, "GetRetransmitParams returned unexpected result: %08x\n", rc);
202 /* Check if the default values are returned */
203 rc = IWSDUdpMessageParameters_GetRetransmitParams(udpMessageParams, &returnedParams);
204 ok(rc == S_OK, "GetRetransmitParams failed: %08x\n", rc);
206 ok(returnedParams.ulSendDelay == 0, "ulSendDelay = %d\n", returnedParams.ulSendDelay);
207 ok(returnedParams.ulRepeat == 1, "ulRepeat = %d\n", returnedParams.ulRepeat);
208 ok(returnedParams.ulRepeatMinDelay == 50, "ulRepeatMinDelay = %d\n", returnedParams.ulRepeatMinDelay);
209 ok(returnedParams.ulRepeatMaxDelay == 250, "ulRepeatMaxDelay = %d\n", returnedParams.ulRepeatMaxDelay);
210 ok(returnedParams.ulRepeatUpperDelay == 450, "ulRepeatUpperDelay = %d\n", returnedParams.ulRepeatUpperDelay);
212 /* Now try setting some custom parameters */
213 origParams.ulSendDelay = 100;
214 origParams.ulRepeat = 7;
215 origParams.ulRepeatMinDelay = 125;
216 origParams.ulRepeatMaxDelay = 175;
217 origParams.ulRepeatUpperDelay = 500;
219 rc = IWSDUdpMessageParameters_SetRetransmitParams(udpMessageParams, &origParams);
220 ok(rc == S_OK, "SetRetransmitParams failed: %08x\n", rc);
222 ZeroMemory(&returnedParams, sizeof(WSDUdpRetransmitParams));
224 rc = IWSDUdpMessageParameters_GetRetransmitParams(udpMessageParams, &returnedParams);
225 ok(rc == S_OK, "GetRetransmitParams failed: %08x\n", rc);
227 ok(origParams.ulSendDelay == returnedParams.ulSendDelay, "ulSendDelay = %d\n", returnedParams.ulSendDelay);
228 ok(origParams.ulRepeat == returnedParams.ulRepeat, "ulRepeat = %d\n", returnedParams.ulRepeat);
229 ok(origParams.ulRepeatMinDelay == returnedParams.ulRepeatMinDelay, "ulRepeatMinDelay = %d\n", returnedParams.ulRepeatMinDelay);
230 ok(origParams.ulRepeatMaxDelay == returnedParams.ulRepeatMaxDelay, "ulRepeatMaxDelay = %d\n", returnedParams.ulRepeatMaxDelay);
231 ok(origParams.ulRepeatUpperDelay == returnedParams.ulRepeatUpperDelay, "ulRepeatUpperDelay = %d\n", returnedParams.ulRepeatUpperDelay);
233 /* Try setting a null parameter */
234 rc = IWSDUdpMessageParameters_SetRetransmitParams(udpMessageParams, NULL);
235 ok(rc == E_INVALIDARG, "SetRetransmitParams returned unexpected result: %08x\n", rc);
237 /* Now attempt to set some invalid parameters - these appear to be accepted */
238 origParams.ulSendDelay = INFINITE;
239 origParams.ulRepeat = 500;
240 origParams.ulRepeatMinDelay = 250;
241 origParams.ulRepeatMaxDelay = 125;
242 origParams.ulRepeatUpperDelay = 100;
244 rc = IWSDUdpMessageParameters_SetRetransmitParams(udpMessageParams, &origParams);
245 ok(rc == S_OK, "SetRetransmitParams failed: %08x\n", rc);
247 ZeroMemory(&returnedParams, sizeof(WSDUdpRetransmitParams));
249 rc = IWSDUdpMessageParameters_GetRetransmitParams(udpMessageParams, &returnedParams);
250 ok(rc == S_OK, "GetRetransmitParams failed: %08x\n", rc);
252 ok(origParams.ulSendDelay == returnedParams.ulSendDelay, "ulSendDelay = %d\n", returnedParams.ulSendDelay);
253 ok(origParams.ulRepeat == returnedParams.ulRepeat, "ulRepeat = %d\n", returnedParams.ulRepeat);
254 ok(origParams.ulRepeatMinDelay == returnedParams.ulRepeatMinDelay, "ulRepeatMinDelay = %d\n", returnedParams.ulRepeatMinDelay);
255 ok(origParams.ulRepeatMaxDelay == returnedParams.ulRepeatMaxDelay, "ulRepeatMaxDelay = %d\n", returnedParams.ulRepeatMaxDelay);
256 ok(origParams.ulRepeatUpperDelay == returnedParams.ulRepeatUpperDelay, "ulRepeatUpperDelay = %d\n", returnedParams.ulRepeatUpperDelay);
258 ret = IWSDUdpMessageParameters_Release(udpMessageParams);
259 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
262 START_TEST(msgparams)
264 CoInitialize(NULL);
266 CreateUdpMessageParameters_tests();
267 LocalAddress_tests();
268 RemoteAddress_tests();
269 RetransmitParams_tests();
271 CoUninitialize();