mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / wsdapi / tests / msgparams.c
blob6e40094f17164316cbb3ab9ac31b64d6b9bbc5e6
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 WSADATA wsaData;
75 HRESULT rc;
76 int ret;
78 ret = WSAStartup(MAKEWORD(2, 2), &wsaData);
79 ok(ret == 0, "WSAStartup failed: %d\n", ret);
81 rc = WSDCreateUdpMessageParameters(&udpMessageParams);
82 ok(rc == S_OK, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: %08x\n", rc);
83 ok(udpMessageParams != NULL, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: udpMessageParams == NULL\n");
85 rc = IWSDUdpMessageParameters_GetLocalAddress(udpMessageParams, NULL);
86 ok(rc == E_POINTER, "GetLocalAddress failed: %08x\n", rc);
87 ok(returnedAddress == NULL, "GetLocalAddress returned %p\n", returnedAddress);
89 rc = IWSDUdpMessageParameters_GetLocalAddress(udpMessageParams, &returnedAddress);
90 ok(rc == E_ABORT, "GetLocalAddress failed: %08x\n", rc);
91 ok(returnedAddress == NULL, "GetLocalAddress returned %p\n", returnedAddress);
93 rc = WSDCreateUdpAddress(&origUdpAddress);
94 ok(rc == S_OK, "WSDCreateUdpAddress(NULL, &origUdpAddress) failed: %08x\n", rc);
95 ok(origUdpAddress != NULL, "WSDCreateUdpMessageParameters(NULL, &origUdpAddress) failed: origUdpAddress == NULL\n");
97 rc = IWSDUdpAddress_SetTransportAddress(origUdpAddress, L"1.2.3.4");
98 ok(rc == S_OK, "SetTransportAddress failed: %08x\n", rc);
100 rc = IWSDUdpMessageParameters_SetLocalAddress(udpMessageParams, (IWSDAddress *)origUdpAddress);
101 ok(rc == S_OK, "SetLocalAddress failed: %08x\n", rc);
103 rc = IWSDUdpMessageParameters_GetLocalAddress(udpMessageParams, &returnedAddress);
104 ok(rc == S_OK, "GetLocalAddress failed: %08x\n", rc);
105 ok(returnedAddress != NULL, "GetLocalAddress returned NULL\n");
107 /* Check if GetLocalAddress returns the same object */
108 ok(returnedAddress == (IWSDAddress *)origUdpAddress, "returnedAddress != origUdpAddress\n");
110 ret = IWSDUdpMessageParameters_Release(udpMessageParams);
111 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
113 if (returnedAddress != NULL)
115 ret = IWSDAddress_Release(returnedAddress);
116 ok(ret == 1, "IWSDAddress_Release() has %d references, should have 1\n", ret);
119 ret = IWSDUdpAddress_Release(origUdpAddress);
120 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
122 ret = WSACleanup();
123 ok(ret == 0, "WSACleanup failed: %d\n", ret);
126 static void RemoteAddress_tests(void)
128 IWSDUdpAddress *origUdpAddress = NULL;
129 IWSDAddress *returnedAddress = NULL;
130 IWSDUdpMessageParameters *udpMessageParams = NULL;
131 WSADATA wsaData;
132 HRESULT rc;
133 int ret;
135 ret = WSAStartup(MAKEWORD(2, 2), &wsaData);
136 ok(ret == 0, "WSAStartup failed: %d\n", ret);
138 rc = WSDCreateUdpMessageParameters(&udpMessageParams);
139 ok(rc == S_OK, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: %08x\n", rc);
140 ok(udpMessageParams != NULL, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: udpMessageParams == NULL\n");
142 rc = IWSDUdpMessageParameters_GetRemoteAddress(udpMessageParams, NULL);
143 ok(rc == E_POINTER, "GetRemoteAddress failed: %08x\n", rc);
144 ok(returnedAddress == NULL, "GetRemoteAddress returned %p\n", returnedAddress);
146 rc = IWSDUdpMessageParameters_GetRemoteAddress(udpMessageParams, &returnedAddress);
147 ok(rc == E_ABORT, "GetRemoteAddress failed: %08x\n", rc);
148 ok(returnedAddress == NULL, "GetRemoteAddress returned %p\n", returnedAddress);
150 rc = WSDCreateUdpAddress(&origUdpAddress);
151 ok(rc == S_OK, "WSDCreateUdpAddress(NULL, &origUdpAddress) failed: %08x\n", rc);
152 ok(origUdpAddress != NULL, "WSDCreateUdpMessageParameters(NULL, &origUdpAddress) failed: origUdpAddress == NULL\n");
154 rc = IWSDUdpAddress_SetTransportAddress(origUdpAddress, L"1.2.3.4");
155 ok(rc == S_OK, "SetTransportAddress failed: %08x\n", rc);
157 rc = IWSDUdpMessageParameters_SetRemoteAddress(udpMessageParams, (IWSDAddress *)origUdpAddress);
158 ok(rc == S_OK, "SetRemoteAddress failed: %08x\n", rc);
160 rc = IWSDUdpMessageParameters_GetRemoteAddress(udpMessageParams, &returnedAddress);
161 ok(rc == S_OK, "GetRemoteAddress failed: %08x\n", rc);
162 ok(returnedAddress != NULL, "GetLocalAddress returned NULL\n");
164 /* Check if GetRemoteAddress returns the same object */
165 ok(returnedAddress == (IWSDAddress *)origUdpAddress, "returnedAddress != origUdpAddress\n");
167 ret = IWSDUdpMessageParameters_Release(udpMessageParams);
168 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
170 if (returnedAddress != NULL)
172 ret = IWSDAddress_Release(returnedAddress);
173 ok(ret == 1, "IWSDAddress_Release() has %d references, should have 1\n", ret);
176 ret = IWSDUdpAddress_Release(origUdpAddress);
177 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
179 ret = WSACleanup();
180 ok(ret == 0, "WSACleanup failed: %d\n", ret);
183 static void RetransmitParams_tests(void)
185 WSDUdpRetransmitParams origParams, returnedParams;
186 IWSDUdpMessageParameters *udpMessageParams = NULL;
187 HRESULT rc;
188 int ret;
190 ZeroMemory(&origParams, sizeof(WSDUdpRetransmitParams));
191 ZeroMemory(&returnedParams, sizeof(WSDUdpRetransmitParams));
193 rc = WSDCreateUdpMessageParameters(&udpMessageParams);
194 ok(rc == S_OK, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: %08x\n", rc);
195 ok(udpMessageParams != NULL, "WSDCreateUdpMessageParameters(NULL, &udpMessageParams) failed: udpMessageParams == NULL\n");
197 rc = IWSDUdpMessageParameters_GetRetransmitParams(udpMessageParams, NULL);
198 ok(rc == E_POINTER, "GetRetransmitParams returned unexpected result: %08x\n", rc);
200 /* Check if the default values are returned */
201 rc = IWSDUdpMessageParameters_GetRetransmitParams(udpMessageParams, &returnedParams);
202 ok(rc == S_OK, "GetRetransmitParams failed: %08x\n", rc);
204 ok(returnedParams.ulSendDelay == 0, "ulSendDelay = %d\n", returnedParams.ulSendDelay);
205 ok(returnedParams.ulRepeat == 1, "ulRepeat = %d\n", returnedParams.ulRepeat);
206 ok(returnedParams.ulRepeatMinDelay == 50, "ulRepeatMinDelay = %d\n", returnedParams.ulRepeatMinDelay);
207 ok(returnedParams.ulRepeatMaxDelay == 250, "ulRepeatMaxDelay = %d\n", returnedParams.ulRepeatMaxDelay);
208 ok(returnedParams.ulRepeatUpperDelay == 450, "ulRepeatUpperDelay = %d\n", returnedParams.ulRepeatUpperDelay);
210 /* Now try setting some custom parameters */
211 origParams.ulSendDelay = 100;
212 origParams.ulRepeat = 7;
213 origParams.ulRepeatMinDelay = 125;
214 origParams.ulRepeatMaxDelay = 175;
215 origParams.ulRepeatUpperDelay = 500;
217 rc = IWSDUdpMessageParameters_SetRetransmitParams(udpMessageParams, &origParams);
218 ok(rc == S_OK, "SetRetransmitParams failed: %08x\n", rc);
220 ZeroMemory(&returnedParams, sizeof(WSDUdpRetransmitParams));
222 rc = IWSDUdpMessageParameters_GetRetransmitParams(udpMessageParams, &returnedParams);
223 ok(rc == S_OK, "GetRetransmitParams failed: %08x\n", rc);
225 ok(origParams.ulSendDelay == returnedParams.ulSendDelay, "ulSendDelay = %d\n", returnedParams.ulSendDelay);
226 ok(origParams.ulRepeat == returnedParams.ulRepeat, "ulRepeat = %d\n", returnedParams.ulRepeat);
227 ok(origParams.ulRepeatMinDelay == returnedParams.ulRepeatMinDelay, "ulRepeatMinDelay = %d\n", returnedParams.ulRepeatMinDelay);
228 ok(origParams.ulRepeatMaxDelay == returnedParams.ulRepeatMaxDelay, "ulRepeatMaxDelay = %d\n", returnedParams.ulRepeatMaxDelay);
229 ok(origParams.ulRepeatUpperDelay == returnedParams.ulRepeatUpperDelay, "ulRepeatUpperDelay = %d\n", returnedParams.ulRepeatUpperDelay);
231 /* Try setting a null parameter */
232 rc = IWSDUdpMessageParameters_SetRetransmitParams(udpMessageParams, NULL);
233 ok(rc == E_INVALIDARG, "SetRetransmitParams returned unexpected result: %08x\n", rc);
235 /* Now attempt to set some invalid parameters - these appear to be accepted */
236 origParams.ulSendDelay = INFINITE;
237 origParams.ulRepeat = 500;
238 origParams.ulRepeatMinDelay = 250;
239 origParams.ulRepeatMaxDelay = 125;
240 origParams.ulRepeatUpperDelay = 100;
242 rc = IWSDUdpMessageParameters_SetRetransmitParams(udpMessageParams, &origParams);
243 ok(rc == S_OK, "SetRetransmitParams failed: %08x\n", rc);
245 ZeroMemory(&returnedParams, sizeof(WSDUdpRetransmitParams));
247 rc = IWSDUdpMessageParameters_GetRetransmitParams(udpMessageParams, &returnedParams);
248 ok(rc == S_OK, "GetRetransmitParams failed: %08x\n", rc);
250 ok(origParams.ulSendDelay == returnedParams.ulSendDelay, "ulSendDelay = %d\n", returnedParams.ulSendDelay);
251 ok(origParams.ulRepeat == returnedParams.ulRepeat, "ulRepeat = %d\n", returnedParams.ulRepeat);
252 ok(origParams.ulRepeatMinDelay == returnedParams.ulRepeatMinDelay, "ulRepeatMinDelay = %d\n", returnedParams.ulRepeatMinDelay);
253 ok(origParams.ulRepeatMaxDelay == returnedParams.ulRepeatMaxDelay, "ulRepeatMaxDelay = %d\n", returnedParams.ulRepeatMaxDelay);
254 ok(origParams.ulRepeatUpperDelay == returnedParams.ulRepeatUpperDelay, "ulRepeatUpperDelay = %d\n", returnedParams.ulRepeatUpperDelay);
256 ret = IWSDUdpMessageParameters_Release(udpMessageParams);
257 ok(ret == 0, "IWSDUdpMessageParameters_Release() has %d references, should have 0\n", ret);
260 START_TEST(msgparams)
262 CoInitialize(NULL);
264 CreateUdpMessageParameters_tests();
265 LocalAddress_tests();
266 RemoteAddress_tests();
267 RetransmitParams_tests();
269 CoUninitialize();