winedbg: Don't dereference possibly NULL thread pointer.
[wine/zf.git] / dlls / dpnet / tests / client.c
blobda42e6d695101654de2de4651aca10d066541eb1
1 /*
2 * Copyright 2011 Louis Lenders
3 * Copyright 2014 Alistair Leslie-Hughes
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define WIN32_LEAN_AND_MEAN
21 #include <stdio.h>
23 #include <dplay8.h>
24 #include <dplobby8.h>
25 #include <winver.h>
26 #define COBJMACROS
27 #include "wine/test.h"
29 #include "dpnet_test.h"
31 static IDirectPlay8Server* server = NULL;
32 static IDirectPlay8Peer* peer = NULL;
33 static IDirectPlay8Client* client = NULL;
34 static IDirectPlay8LobbiedApplication* lobbied = NULL;
35 static const GUID appguid = { 0xcd0c3d4b, 0xe15e, 0x4cf2, { 0x9e, 0xa8, 0x6e, 0x1d, 0x65, 0x48, 0xc5, 0xa5 } };
36 static const WCHAR localhost[] = L"127.0.0.1";
38 static HRESULT lastAsyncCode = E_FAIL;
39 static DPNHANDLE lastAsyncHandle = 0xdeadbeef;
40 static HANDLE enumevent = NULL;
41 static int handlecnt = 0;
43 static HRESULT WINAPI DirectPlayServerHandler(void *context, DWORD message_id, void *buffer)
45 switch(message_id)
47 case DPN_MSGID_CREATE_PLAYER:
48 case DPN_MSGID_DESTROY_PLAYER:
49 /* These are tested in the server test */
50 break;
51 default:
52 trace("DirectPlayServerHandler: 0x%08x\n", message_id);
54 return S_OK;
57 static HRESULT WINAPI DirectPlayMessageHandler(PVOID context, DWORD message_id, PVOID buffer)
59 switch(message_id)
61 case DPN_MSGID_ENUM_HOSTS_RESPONSE:
62 handlecnt++;
63 if(handlecnt >= 2)
64 SetEvent(enumevent);
65 break;
66 case DPN_MSGID_ASYNC_OP_COMPLETE:
68 DPNMSG_ASYNC_OP_COMPLETE *async_msg = (DPNMSG_ASYNC_OP_COMPLETE*)buffer;
69 lastAsyncCode = async_msg->hResultCode;
70 lastAsyncHandle = async_msg->hAsyncOp;
71 break;
73 default:
74 trace("DirectPlayMessageHandler: 0x%08x\n", message_id);
77 return S_OK;
80 static HRESULT WINAPI DirectPlayLobbyMessageHandler(PVOID context, DWORD message_id, PVOID buffer)
82 trace("DirectPlayLobbyMessageHandler: 0x%08x\n", message_id);
83 return S_OK;
86 static HRESULT WINAPI DirectPlayLobbyClientMessageHandler(void *context, DWORD message_id, void* buffer)
88 trace("DirectPlayLobbyClientMessageHandler: 0x%08x\n", message_id);
89 return S_OK;
92 static void create_server(void)
94 static WCHAR sessionname[] = L"winegamesserver";
95 HRESULT hr;
96 IDirectPlay8Address *localaddr = NULL;
97 DPN_APPLICATION_DESC appdesc;
99 hr = CoCreateInstance( &CLSID_DirectPlay8Server, NULL, CLSCTX_ALL, &IID_IDirectPlay8Server, (void **)&server);
100 ok(hr == S_OK, "Failed to create IDirectPlay8Server object\n");
102 hr = IDirectPlay8Server_Initialize(server, NULL, DirectPlayServerHandler, 0);
103 ok(hr == S_OK, "got 0x%08x\n", hr);
105 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void **)&localaddr);
106 ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
108 hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
109 ok(hr == S_OK, "got 0x%08x\n", hr);
111 memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
112 appdesc.dwSize = sizeof( DPN_APPLICATION_DESC );
113 appdesc.dwFlags = DPNSESSION_CLIENT_SERVER;
114 appdesc.guidApplication = appguid;
115 appdesc.pwszSessionName = sessionname;
117 hr = IDirectPlay8Server_Host(server, &appdesc, &localaddr, 1, NULL, NULL, NULL, 0);
118 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
120 IDirectPlay8Address_Release(localaddr);
123 static BOOL test_init_dp(void)
125 HRESULT hr;
126 DPN_SP_CAPS caps;
127 DPNHANDLE lobbyConnection;
129 enumevent = CreateEventA( NULL, TRUE, FALSE, NULL);
131 hr = CoCreateInstance(&CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Client, (void **)&client);
132 ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);
134 memset(&caps, 0, sizeof(DPN_SP_CAPS));
135 caps.dwSize = sizeof(DPN_SP_CAPS);
137 hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
138 ok(hr == DPNERR_UNINITIALIZED, "GetSPCaps failed with %x\n", hr);
140 hr = IDirectPlay8Client_Initialize(client, NULL, NULL, 0);
141 ok(hr == DPNERR_INVALIDPARAM, "got %x\n", hr);
143 hr = IDirectPlay8Client_SetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
144 ok(hr == DPNERR_INVALIDPARAM, "SetSPCaps failed with %x\n", hr);
146 hr = IDirectPlay8Client_Initialize(client, NULL, DirectPlayMessageHandler, 0);
147 ok(hr == S_OK, "IDirectPlay8Client_Initialize failed with %x\n", hr);
149 hr = CoCreateInstance(&CLSID_DirectPlay8LobbiedApplication, NULL, CLSCTX_INPROC_SERVER,
150 &IID_IDirectPlay8LobbiedApplication, (void **)&lobbied);
151 ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);
153 hr = IDirectPlay8LobbiedApplication_Initialize(lobbied, NULL, DirectPlayLobbyMessageHandler,
154 &lobbyConnection, 0);
155 ok(hr == S_OK, "IDirectPlay8LobbiedApplication_Initialize failed with %x\n", hr);
157 return client != NULL;
160 static void test_enum_service_providers(void)
162 DPN_SERVICE_PROVIDER_INFO *serv_prov_info;
163 DWORD items, size;
164 DWORD i;
165 HRESULT hr;
167 size = 0;
168 items = 0;
170 hr = IDirectPlay8Client_EnumServiceProviders(client, NULL, NULL, NULL, &size, NULL, 0);
171 ok(hr == E_POINTER, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
173 hr = IDirectPlay8Client_EnumServiceProviders(client, NULL, NULL, NULL, NULL, &items, 0);
174 ok(hr == E_POINTER, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
176 hr = IDirectPlay8Client_EnumServiceProviders(client, NULL, NULL, NULL, &size, &items, 0);
177 ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
178 ok(size != 0, "size is unexpectedly 0\n");
180 serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);
182 hr = IDirectPlay8Client_EnumServiceProviders(client, NULL, NULL, serv_prov_info, &size, &items, 0);
183 ok(hr == S_OK, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
184 ok(items != 0, "Found unexpectedly no service providers\n");
186 trace("number of items found: %d\n", items);
188 for (i=0;i<items;i++)
190 trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info[i].pwszName));
191 trace("Found guid: %s\n", wine_dbgstr_guid(&serv_prov_info[i].guid));
194 ok(HeapFree(GetProcessHeap(), 0, serv_prov_info), "Failed freeing server provider info\n");
196 size = 0;
197 items = 0;
199 hr = IDirectPlay8Client_EnumServiceProviders(client, &CLSID_DP8SP_TCPIP, NULL, NULL, &size, &items, 0);
200 ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
201 ok(size != 0, "size is unexpectedly 0\n");
203 serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);
205 hr = IDirectPlay8Client_EnumServiceProviders(client, &CLSID_DP8SP_TCPIP, NULL, serv_prov_info, &size, &items, 0);
206 ok(hr == S_OK, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
207 ok(items != 0, "Found unexpectedly no adapter\n");
210 for (i=0;i<items;i++)
212 trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info[i].pwszName));
213 trace("Found adapter guid: %s\n", wine_dbgstr_guid(&serv_prov_info[i].guid));
216 /* Invalid GUID */
217 items = 88;
218 hr = IDirectPlay8Client_EnumServiceProviders(client, &appguid, NULL, serv_prov_info, &size, &items, 0);
219 ok(hr == DPNERR_DOESNOTEXIST, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
220 ok(items == 88, "Found adapter %d\n", items);
222 HeapFree(GetProcessHeap(), 0, serv_prov_info);
225 static void test_enum_hosts(void)
227 HRESULT hr;
228 IDirectPlay8Client *client2;
229 IDirectPlay8Address *host = NULL;
230 IDirectPlay8Address *local = NULL;
231 DPN_APPLICATION_DESC appdesc;
232 DPNHANDLE async = 0, async2 = 0;
233 DPN_SP_CAPS caps;
234 char *data;
236 memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
237 appdesc.dwSize = sizeof( DPN_APPLICATION_DESC );
238 appdesc.guidApplication = appguid;
240 hr = CoCreateInstance(&CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Client, (void **)&client2);
241 ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);
243 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&local);
244 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
246 hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
247 ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);
249 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&host);
250 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
252 hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
253 ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);
255 hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
256 DPNA_DATATYPE_STRING);
257 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
259 caps.dwSize = sizeof(DPN_SP_CAPS);
261 hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
262 ok(hr == DPN_OK, "got %x\n", hr);
263 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, caps.dwMaxEnumPayloadSize + 1);
265 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, 2, 1000, 1000, NULL, &async, DPNENUMHOSTS_SYNC);
266 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
268 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, data, caps.dwMaxEnumPayloadSize + 1,
269 INFINITE, 0, INFINITE, NULL, &async, DPNENUMHOSTS_SYNC);
270 ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
272 async = 0;
273 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, data, caps.dwMaxEnumPayloadSize + 1, INFINITE, 0,
274 INFINITE, NULL, &async, 0);
275 ok(hr == DPNERR_ENUMQUERYTOOLARGE, "got 0x%08x\n", hr);
276 ok(!async, "Handle returned\n");
278 async = 0;
279 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, data, caps.dwMaxEnumPayloadSize, INFINITE, 0, INFINITE,
280 NULL, &async, 0);
281 ok(hr == DPNSUCCESS_PENDING, "got 0x%08x\n", hr);
282 todo_wine ok(async, "No Handle returned\n");
284 /* This CancelAsyncOperation doesn't generate a DPN_MSGID_ASYNC_OP_COMPLETE */
285 hr = IDirectPlay8Client_CancelAsyncOperation(client, async, 0);
286 ok(hr == S_OK, "got 0x%08x\n", hr);
287 HeapFree(GetProcessHeap(), 0, data);
289 /* No Initialize has been called on client2. */
290 hr = IDirectPlay8Client_EnumHosts(client2, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async, 0);
291 ok(hr == DPNERR_UNINITIALIZED, "IDirectPlay8Client_EnumHosts failed with 0x%08x\n", hr);
293 /* Since we are running asynchronously, EnumHosts returns DPNSUCCESS_PENDING. */
294 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async, 0);
295 ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Client_EnumHosts failed with 0x%08x\n", hr);
296 todo_wine ok(async, "No Handle returned\n");
298 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async2, 0);
299 ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Client_EnumHosts failed with 0x%08x\n", hr);
300 todo_wine ok(async2, "No Handle returned\n");
301 todo_wine ok(async2 != async, "Same handle returned.\n");
303 WaitForSingleObject(enumevent, 1000);
305 lastAsyncCode = E_FAIL;
306 lastAsyncHandle = 0xdeadbeef;
307 hr = IDirectPlay8Client_CancelAsyncOperation(client, async, 0);
308 ok(hr == S_OK, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr);
309 todo_wine ok(lastAsyncCode == DPNERR_USERCANCEL, "got 0x%08x\n", lastAsyncCode);
310 todo_wine ok(lastAsyncHandle == async, "got 0x%08x\n", async);
312 hr = IDirectPlay8Client_Initialize(client2, NULL, DirectPlayMessageHandler, 0);
313 ok(hr == S_OK, "got %x\n", hr);
315 /* Show that handlers are per object. */
316 hr = IDirectPlay8Client_CancelAsyncOperation(client2, async2, 0);
317 todo_wine ok(hr == DPNERR_INVALIDHANDLE, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr);
319 lastAsyncCode = E_FAIL;
320 lastAsyncHandle = 0xdeadbeef;
321 hr = IDirectPlay8Client_CancelAsyncOperation(client, async2, 0);
322 ok(hr == S_OK, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr);
323 todo_wine ok(lastAsyncCode == DPNERR_USERCANCEL, "got 0x%08x\n", lastAsyncCode);
324 todo_wine ok(lastAsyncHandle == async2, "got 0x%08x\n", async2);
326 IDirectPlay8Address_Release(local);
327 IDirectPlay8Address_Release(host);
328 IDirectPlay8Client_Release(client2);
331 static void test_enum_hosts_sync(void)
333 HRESULT hr;
334 IDirectPlay8Address *host = NULL;
335 IDirectPlay8Address *local = NULL;
336 DPN_APPLICATION_DESC appdesc;
337 DWORD port = 5445, type = 0, size;
339 memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
340 appdesc.dwSize = sizeof( DPN_APPLICATION_DESC );
341 appdesc.guidApplication = appguid;
343 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void**)&local);
344 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
346 hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
347 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
349 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void**)&host);
350 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
352 hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
353 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
355 hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
356 DPNA_DATATYPE_STRING);
357 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
359 handlecnt = 0;
360 lastAsyncCode = 0xdeadbeef;
361 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, 3, 1500, 1000,
362 NULL, NULL, DPNENUMHOSTS_SYNC);
363 ok(hr == DPN_OK, "got 0x%08x\n", hr);
364 ok(lastAsyncCode == 0xdeadbeef, "got 0x%08x\n", lastAsyncCode);
365 todo_wine ok(handlecnt == 2, "message handler not called\n");
367 size = sizeof(port);
368 hr = IDirectPlay8Address_GetComponentByName(host, DPNA_KEY_PORT, &port, &size, &type);
369 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
371 size = sizeof(port);
372 hr = IDirectPlay8Address_GetComponentByName(local, DPNA_KEY_PORT, &port, &size, &type);
373 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
375 /* Try with specific port */
376 port = 5445;
377 hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_PORT, &port, sizeof(port),
378 DPNA_DATATYPE_DWORD);
380 handlecnt = 0;
381 lastAsyncCode = 0xbeefdead;
382 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
383 hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, 1, 1500, 1000,
384 NULL, NULL, DPNENUMHOSTS_SYNC);
385 ok(hr == DPN_OK, "got 0x%08x\n", hr);
386 ok(lastAsyncCode == 0xbeefdead, "got 0x%08x\n", lastAsyncCode);
387 ok(handlecnt == 0, "message handler called\n");
389 IDirectPlay8Address_Release(local);
390 IDirectPlay8Address_Release(host);
393 static void test_get_sp_caps(void)
395 DPN_SP_CAPS caps;
396 HRESULT hr;
398 memset(&caps, 0, sizeof(DPN_SP_CAPS));
400 hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
401 ok(hr == DPNERR_INVALIDPARAM, "GetSPCaps unexpectedly returned %x\n", hr);
403 caps.dwSize = sizeof(DPN_SP_CAPS);
405 hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
406 ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);
408 ok(caps.dwSize == sizeof(DPN_SP_CAPS), "got %d\n", caps.dwSize);
409 ok((caps.dwFlags &
410 (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS)) ==
411 (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS),
412 "unexpected flags %x\n", caps.dwFlags);
413 ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
414 ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
415 ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
416 ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
417 ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
418 ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
419 ok(caps.dwSystemBufferSize == 0x10000 || broken(caps.dwSystemBufferSize == 0x2000 /* before Win8 */),
420 "expected 0x10000, got 0x%x\n", caps.dwSystemBufferSize);
422 caps.dwNumThreads = 2;
423 caps.dwDefaultEnumCount = 3;
424 caps.dwDefaultEnumRetryInterval = 1400;
425 caps.dwDefaultEnumTimeout = 1400;
426 caps.dwMaxEnumPayloadSize = 900;
427 caps.dwBuffersPerThread = 2;
428 caps.dwSystemBufferSize = 0x0ffff;
429 hr = IDirectPlay8Client_SetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
430 ok(hr == DPN_OK, "SetSPCaps failed with %x\n", hr);
432 hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
433 ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);
435 ok(caps.dwSize == sizeof(DPN_SP_CAPS), "got %d\n", caps.dwSize);
436 ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
437 ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
438 ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
439 ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
440 ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
441 ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
442 ok(caps.dwSystemBufferSize == 0x0ffff, "expected 0x0ffff, got 0x%x\n", caps.dwSystemBufferSize);
444 /* Reset the System setting back to its default. */
445 caps.dwSystemBufferSize = 0x10000;
446 hr = IDirectPlay8Client_SetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
447 ok(hr == DPN_OK, "SetSPCaps failed with %x\n", hr);
450 static void test_lobbyclient(void)
452 HRESULT hr;
453 IDirectPlay8LobbyClient *client = NULL;
455 hr = CoCreateInstance( &CLSID_DirectPlay8LobbyClient, NULL, CLSCTX_ALL, &IID_IDirectPlay8LobbyClient, (void**)&client);
456 ok(hr == S_OK, "Failed to create object\n");
457 if(SUCCEEDED(hr))
459 hr = IDirectPlay8LobbyClient_Initialize(client, NULL, NULL, 0);
460 ok(hr == E_POINTER, "got 0x%08x\n", hr);
462 hr = IDirectPlay8LobbyClient_Initialize(client, NULL, DirectPlayLobbyClientMessageHandler, 0);
463 ok(hr == S_OK, "got 0x%08x\n", hr);
465 hr = IDirectPlay8LobbyClient_Close(client, 0);
466 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
468 IDirectPlay8LobbyClient_Release(client);
472 static void test_player_info(void)
474 HRESULT hr;
475 DPN_PLAYER_INFO info;
476 WCHAR name[] = L"wine";
477 WCHAR name2[] = L"wine2";
478 WCHAR data[] = L"XXXX";
480 ZeroMemory( &info, sizeof(DPN_PLAYER_INFO) );
481 info.dwSize = sizeof(DPN_PLAYER_INFO);
482 info.dwInfoFlags = DPNINFO_NAME;
484 hr = IDirectPlay8Client_SetClientInfo(client, NULL, NULL, NULL, DPNSETCLIENTINFO_SYNC);
485 ok(hr == E_POINTER, "got %x\n", hr);
487 info.pwszName = NULL;
488 hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
489 ok(hr == S_OK, "got %x\n", hr);
491 info.pwszName = name;
492 hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
493 ok(hr == S_OK, "got %x\n", hr);
495 info.dwInfoFlags = DPNINFO_NAME;
496 info.pwszName = name2;
497 hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
498 ok(hr == S_OK, "got %x\n", hr);
500 info.dwInfoFlags = DPNINFO_DATA;
501 info.pwszName = NULL;
502 info.pvData = NULL;
503 info.dwDataSize = sizeof(data);
504 hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
505 ok(hr == E_POINTER, "got %x\n", hr);
507 info.dwInfoFlags = DPNINFO_DATA;
508 info.pwszName = NULL;
509 info.pvData = data;
510 info.dwDataSize = 0;
511 hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
512 ok(hr == S_OK, "got %x\n", hr);
514 info.dwInfoFlags = DPNINFO_DATA;
515 info.pwszName = NULL;
516 info.pvData = data;
517 info.dwDataSize = sizeof(data);
518 hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
519 ok(hr == S_OK, "got %x\n", hr);
521 info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME;
522 info.pwszName = name;
523 info.pvData = data;
524 info.dwDataSize = sizeof(data);
525 hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
526 ok(hr == S_OK, "got %x\n", hr);
528 /* Leave ClientInfo with only the name set. */
529 info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME;
530 info.pwszName = name;
531 info.pvData = NULL;
532 info.dwDataSize = 0;
533 hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
534 ok(hr == S_OK, "got %x\n", hr);
537 static void test_cleanup_dp(void)
539 HRESULT hr;
541 hr = IDirectPlay8Client_Close(client, 0);
542 ok(hr == S_OK, "IDirectPlay8Client_Close failed with %x\n", hr);
544 if(lobbied)
546 hr = IDirectPlay8LobbiedApplication_Close(lobbied, 0);
547 ok(hr == S_OK, "IDirectPlay8LobbiedApplication_Close failed with %x\n", hr);
549 IDirectPlay8LobbiedApplication_Release(lobbied);
552 IDirectPlay8Client_Release(client);
555 static void test_close(void)
557 HRESULT hr;
558 static IDirectPlay8Client* client2;
559 DPN_SP_CAPS caps;
561 hr = CoCreateInstance(&CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Client, (void **)&client2);
562 ok(hr == S_OK, "got 0x%x\n", hr);
564 memset(&caps, 0, sizeof(DPN_SP_CAPS));
565 caps.dwSize = sizeof(DPN_SP_CAPS);
567 hr = IDirectPlay8Client_Initialize(client2, NULL, DirectPlayMessageHandler, 0);
568 ok(hr == S_OK, "got %x\n", hr);
570 hr = IDirectPlay8Client_GetSPCaps(client2, &CLSID_DP8SP_TCPIP, &caps, 0);
571 ok(hr == DPN_OK, "got %x\n", hr);
573 hr = IDirectPlay8Client_Close(client2, 0);
574 ok(hr == DPN_OK, "got %x\n", hr);
576 hr = IDirectPlay8Client_GetSPCaps(client2, &CLSID_DP8SP_TCPIP, &caps, 0);
577 ok(hr == DPNERR_UNINITIALIZED, "got %x\n", hr);
579 IDirectPlay8Client_Release(client2);
582 static void test_init_dp_peer(void)
584 HRESULT hr;
585 DPN_SP_CAPS caps;
586 DPNHANDLE lobbyConnection;
588 hr = CoCreateInstance(&CLSID_DirectPlay8Peer, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Peer, (void **)&peer);
589 ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);
591 memset(&caps, 0, sizeof(DPN_SP_CAPS));
592 caps.dwSize = sizeof(DPN_SP_CAPS);
594 hr = IDirectPlay8Peer_SetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
595 ok(hr == DPNERR_INVALIDPARAM, "SetSPCaps failed with %x\n", hr);
597 hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
598 ok(hr == DPNERR_UNINITIALIZED, "GetSPCaps failed with %x\n", hr);
600 hr = IDirectPlay8Peer_Initialize(peer, NULL, NULL, 0);
601 ok(hr == DPNERR_INVALIDPARAM, "got %x\n", hr);
603 hr = IDirectPlay8Peer_Initialize(peer, NULL, DirectPlayMessageHandler, 0);
604 ok(hr == S_OK, "IDirectPlay8Peer_Initialize failed with %x\n", hr);
606 hr = CoCreateInstance(&CLSID_DirectPlay8LobbiedApplication, NULL, CLSCTX_INPROC_SERVER,
607 &IID_IDirectPlay8LobbiedApplication, (void **)&lobbied);
608 ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);
610 hr = IDirectPlay8LobbiedApplication_Initialize(lobbied, NULL, NULL,
611 &lobbyConnection, 0);
612 ok(hr == DPNERR_INVALIDPOINTER, "Failed with %x\n", hr);
614 hr = IDirectPlay8LobbiedApplication_Initialize(lobbied, NULL, DirectPlayLobbyMessageHandler,
615 &lobbyConnection, 0);
616 ok(hr == S_OK, "IDirectPlay8LobbiedApplication_Initialize failed with %x\n", hr);
619 static void test_enum_service_providers_peer(void)
621 DPN_SERVICE_PROVIDER_INFO *serv_prov_info;
622 DWORD items, size;
623 DWORD i;
624 HRESULT hr;
626 size = 0;
627 items = 0;
629 hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, NULL, &size, NULL, 0);
630 ok(hr == E_POINTER, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
632 hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, NULL, NULL, &items, 0);
633 ok(hr == E_POINTER, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
635 hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, NULL, &size, &items, 0);
636 ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
637 ok(size != 0, "size is unexpectedly 0\n");
639 serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);
641 hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, serv_prov_info, &size, &items, 0);
642 ok(hr == S_OK, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
643 ok(items != 0, "Found unexpectedly no service providers\n");
645 trace("number of items found: %d\n", items);
647 for (i=0;i<items;i++)
649 trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info[i].pwszName));
650 trace("Found guid: %s\n", wine_dbgstr_guid(&serv_prov_info[i].guid));
653 HeapFree(GetProcessHeap(), 0, serv_prov_info);
655 size = 0;
656 items = 0;
658 hr = IDirectPlay8Peer_EnumServiceProviders(peer, &CLSID_DP8SP_TCPIP, NULL, NULL, &size, &items, 0);
659 ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
660 ok(size != 0, "size is unexpectedly 0\n");
662 serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);
664 hr = IDirectPlay8Peer_EnumServiceProviders(peer, &CLSID_DP8SP_TCPIP, NULL, serv_prov_info, &size, &items, 0);
665 ok(hr == S_OK, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
666 ok(items != 0, "Found unexpectedly no adapter\n");
669 for (i=0;i<items;i++)
671 trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info[i].pwszName));
672 trace("Found adapter guid: %s\n", wine_dbgstr_guid(&serv_prov_info[i].guid));
675 /* Invalid GUID */
676 items = 88;
677 hr = IDirectPlay8Peer_EnumServiceProviders(peer, &appguid, NULL, serv_prov_info, &size, &items, 0);
678 ok(hr == DPNERR_DOESNOTEXIST, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
679 ok(items == 88, "Found adapter %d\n", items);
681 HeapFree(GetProcessHeap(), 0, serv_prov_info);
684 static void test_enum_hosts_peer(void)
686 HRESULT hr;
687 IDirectPlay8Peer *peer2;
688 IDirectPlay8Address *host = NULL;
689 IDirectPlay8Address *local = NULL;
690 DPN_APPLICATION_DESC appdesc;
691 DPNHANDLE async = 0, async2 = 0;
693 ResetEvent(enumevent);
694 handlecnt = 0;
696 memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
697 appdesc.dwSize = sizeof( DPN_APPLICATION_DESC );
698 appdesc.guidApplication = appguid;
700 hr = CoCreateInstance(&CLSID_DirectPlay8Peer, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Peer, (void **)&peer2);
701 ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);
703 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&local);
704 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
706 hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
707 ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);
709 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&host);
710 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
712 hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
713 ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);
715 hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
716 DPNA_DATATYPE_STRING);
717 ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
719 hr = IDirectPlay8Peer_EnumHosts(peer, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async, 0);
720 ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Peer_EnumServiceProviders failed with 0x%08x\n", hr);
721 todo_wine ok(async, "No Handle returned\n");
723 hr = IDirectPlay8Peer_CancelAsyncOperation(peer, async, 0);
724 todo_wine ok(hr == S_OK, "IDirectPlay8Peer_CancelAsyncOperation failed with 0x%08x\n", hr);
726 /* No Initialize has been called on peer2. */
727 hr = IDirectPlay8Peer_EnumHosts(peer2, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async, 0);
728 ok(hr == DPNERR_UNINITIALIZED, "IDirectPlay8Peer_EnumHosts failed with 0x%08x\n", hr);
730 /* Since we are running asynchronously, EnumHosts returns DPNSUCCESS_PENDING. */
731 hr = IDirectPlay8Peer_EnumHosts(peer, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async, 0);
732 ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Peer_EnumHosts failed with 0x%08x\n", hr);
733 todo_wine ok(async, "No Handle returned\n");
735 hr = IDirectPlay8Peer_EnumHosts(peer, &appdesc, host, local, NULL, 0, INFINITE, 0, INFINITE, NULL, &async2, 0);
736 ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Peer_EnumHosts failed with 0x%08x\n", hr);
737 todo_wine ok(async2, "No Handle returned\n");
738 todo_wine ok(async2 != async, "Same handle returned.\n");
740 WaitForSingleObject(enumevent, 1000);
742 lastAsyncCode = E_FAIL;
743 lastAsyncHandle = 0xdeadbeef;
744 hr = IDirectPlay8Peer_CancelAsyncOperation(peer, async, 0);
745 todo_wine ok(hr == S_OK, "IDirectPlay8Peer_CancelAsyncOperation failed with 0x%08x\n", hr);
746 todo_wine ok(lastAsyncCode == DPNERR_USERCANCEL, "got 0x%08x\n", lastAsyncCode);
747 todo_wine ok(lastAsyncHandle == async, "got 0x%08x\n", async);
749 lastAsyncCode = E_FAIL;
750 lastAsyncHandle = 0xdeadbeef;
751 hr = IDirectPlay8Peer_CancelAsyncOperation(peer, async2, 0);
752 todo_wine ok(hr == S_OK, "IDirectPlay8Peer_CancelAsyncOperation failed with 0x%08x\n", hr);
753 todo_wine ok(lastAsyncCode == DPNERR_USERCANCEL, "got 0x%08x\n", lastAsyncCode);
754 todo_wine ok(lastAsyncHandle == async2, "got 0x%08x\n", async2);
756 IDirectPlay8Peer_Release(peer2);
757 IDirectPlay8Address_Release(local);
758 IDirectPlay8Address_Release(host);
761 static void test_enum_hosts_sync_peer(void)
763 HRESULT hr;
764 IDirectPlay8Address *host = NULL;
765 IDirectPlay8Address *local = NULL;
766 DPN_APPLICATION_DESC appdesc;
767 DWORD port = 5445, type = 0, size;
769 memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
770 appdesc.dwSize = sizeof( DPN_APPLICATION_DESC );
771 appdesc.guidApplication = appguid;
773 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void**)&local);
774 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
776 hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
777 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
779 hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void**)&host);
780 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
782 hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
783 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
785 hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
786 DPNA_DATATYPE_STRING);
787 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
789 handlecnt = 0;
790 lastAsyncCode = 0xdeadbeef;
791 hr = IDirectPlay8Peer_EnumHosts(peer, &appdesc, host, local, NULL, 0, 3, 1500, 1000,
792 NULL, NULL, DPNENUMHOSTS_SYNC);
793 ok(hr == DPN_OK, "got 0x%08x\n", hr);
794 ok(lastAsyncCode == 0xdeadbeef, "got 0x%08x\n", lastAsyncCode);
795 todo_wine ok(handlecnt == 2, "wrong handle cnt\n");
797 size = sizeof(port);
798 hr = IDirectPlay8Address_GetComponentByName(host, DPNA_KEY_PORT, &port, &size, &type);
799 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
801 size = sizeof(port);
802 hr = IDirectPlay8Address_GetComponentByName(local, DPNA_KEY_PORT, &port, &size, &type);
803 ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
805 /* Try with specific port */
806 port = 5445;
807 hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_PORT, &port, sizeof(port),
808 DPNA_DATATYPE_DWORD);
810 handlecnt = 0;
811 lastAsyncCode = 0xbeefdead;
812 ok(hr == S_OK, "Failed with 0x%08x\n", hr);
813 hr = IDirectPlay8Peer_EnumHosts(peer, &appdesc, host, local, NULL, 0, 1, 1500, 1000,
814 NULL, NULL, DPNENUMHOSTS_SYNC);
815 ok(hr == DPN_OK, "got 0x%08x\n", hr);
816 ok(lastAsyncCode == 0xbeefdead, "got 0x%08x\n", lastAsyncCode);
817 ok(handlecnt == 0, "message handler called\n");
819 IDirectPlay8Address_Release(local);
820 IDirectPlay8Address_Release(host);
823 static void test_get_sp_caps_peer(void)
825 DPN_SP_CAPS caps;
826 HRESULT hr;
828 memset(&caps, 0, sizeof(DPN_SP_CAPS));
830 hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
831 ok(hr == DPNERR_INVALIDPARAM, "GetSPCaps unexpectedly returned %x\n", hr);
833 caps.dwSize = sizeof(DPN_SP_CAPS);
835 hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
836 ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);
838 ok(caps.dwSize == sizeof(DPN_SP_CAPS), "got %d\n", caps.dwSize);
839 ok((caps.dwFlags &
840 (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS)) ==
841 (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS),
842 "unexpected flags %x\n", caps.dwFlags);
843 ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
844 ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
845 ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
846 ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
847 ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
848 ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
849 ok(caps.dwSystemBufferSize == 0x10000 || broken(caps.dwSystemBufferSize == 0x2000 /* before Win8 */),
850 "expected 0x10000, got 0x%x\n", caps.dwSystemBufferSize);
852 caps.dwNumThreads = 2;
853 caps.dwDefaultEnumCount = 3;
854 caps.dwDefaultEnumRetryInterval = 1400;
855 caps.dwDefaultEnumTimeout = 1400;
856 caps.dwMaxEnumPayloadSize = 900;
857 caps.dwBuffersPerThread = 2;
858 caps.dwSystemBufferSize = 0x0ffff;
859 hr = IDirectPlay8Peer_SetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
860 ok(hr == DPN_OK, "SetSPCaps failed with %x\n", hr);
862 hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
863 ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);
865 ok(caps.dwSize == sizeof(DPN_SP_CAPS), "got %d\n", caps.dwSize);
866 ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
867 ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
868 ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
869 ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
870 ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
871 ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
872 ok(caps.dwSystemBufferSize == 0x0ffff, "expected 0x0ffff, got 0x%x\n", caps.dwSystemBufferSize);
875 static void test_player_info_peer(void)
877 HRESULT hr;
878 DPN_PLAYER_INFO info;
879 WCHAR name[] = L"wine";
880 WCHAR name2[] = L"wine2";
881 WCHAR data[] = L"XXXX";
883 ZeroMemory( &info, sizeof(DPN_PLAYER_INFO) );
884 info.dwSize = sizeof(DPN_PLAYER_INFO);
885 info.dwInfoFlags = DPNINFO_NAME;
887 hr = IDirectPlay8Peer_SetPeerInfo(peer, NULL, NULL, NULL, DPNSETPEERINFO_SYNC);
888 ok(hr == E_POINTER, "got %x\n", hr);
890 info.pwszName = NULL;
891 hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
892 ok(hr == S_OK, "got %x\n", hr);
894 info.pwszName = name;
895 hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
896 ok(hr == S_OK, "got %x\n", hr);
898 info.dwInfoFlags = DPNINFO_NAME;
899 info.pwszName = name2;
900 hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
901 ok(hr == S_OK, "got %x\n", hr);
903 if(0) /* Crashes on windows */
905 info.dwInfoFlags = DPNINFO_DATA;
906 info.pwszName = NULL;
907 info.pvData = NULL;
908 info.dwDataSize = sizeof(data);
909 hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
910 ok(hr == S_OK, "got %x\n", hr);
913 info.dwInfoFlags = DPNINFO_DATA;
914 info.pwszName = NULL;
915 info.pvData = data;
916 info.dwDataSize = 0;
917 hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
918 ok(hr == S_OK, "got %x\n", hr);
920 info.dwInfoFlags = DPNINFO_DATA;
921 info.pwszName = NULL;
922 info.pvData = data;
923 info.dwDataSize = sizeof(data);
924 hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
925 ok(hr == S_OK, "got %x\n", hr);
927 info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME;
928 info.pwszName = name;
929 info.pvData = data;
930 info.dwDataSize = sizeof(data);
931 hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
932 ok(hr == S_OK, "got %x\n", hr);
934 /* Leave PeerInfo with only the name set. */
935 info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME;
936 info.pwszName = name;
937 info.pvData = NULL;
938 info.dwDataSize = 0;
939 hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
940 ok(hr == S_OK, "got %x\n", hr);
943 static void test_cleanup_dp_peer(void)
945 HRESULT hr;
947 hr = IDirectPlay8Peer_Close(peer, 0);
948 ok(hr == S_OK, "IDirectPlay8Peer_Close failed with %x\n", hr);
950 if(lobbied)
952 hr = IDirectPlay8LobbiedApplication_Close(lobbied, 0);
953 ok(hr == S_OK, "IDirectPlay8LobbiedApplication_Close failed with %x\n", hr);
955 IDirectPlay8LobbiedApplication_Release(lobbied);
958 IDirectPlay8Peer_Release(peer);
961 START_TEST(client)
963 BOOL firewall_enabled;
964 HRESULT hr;
965 char path[MAX_PATH];
967 if(!GetSystemDirectoryA(path, MAX_PATH))
969 skip("Failed to get systems directory\n");
970 return;
972 strcat(path, "\\dpnet.dll");
974 if (!winetest_interactive && is_stub_dll(path))
976 win_skip("dpnet is a stub dll, skipping tests\n");
977 return;
980 if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated())
982 skip("no privileges, skipping tests to avoid firewall dialog\n");
983 return;
986 if (firewall_enabled)
988 hr = set_firewall(APP_ADD);
989 if (hr != S_OK)
991 skip("can't authorize app in firewall %08x\n", hr);
992 return;
996 hr = CoInitialize(0);
997 ok(hr == S_OK, "CoInitialize failed with %x\n", hr);
999 if (!test_init_dp())
1000 goto done;
1002 create_server();
1004 test_enum_service_providers();
1005 test_enum_hosts();
1006 test_enum_hosts_sync();
1007 test_get_sp_caps();
1008 test_player_info();
1009 test_lobbyclient();
1010 test_close();
1011 test_cleanup_dp();
1013 test_init_dp_peer();
1014 test_enum_service_providers_peer();
1015 test_enum_hosts_peer();
1016 test_enum_hosts_sync_peer();
1017 test_get_sp_caps_peer();
1018 test_player_info_peer();
1019 test_cleanup_dp_peer();
1021 hr = IDirectPlay8Server_Close(server, 0);
1022 todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
1023 IDirectPlay8Server_Release(server);
1025 CloseHandle(enumevent);
1027 done:
1028 if (firewall_enabled) set_firewall(APP_REMOVE);
1030 CoUninitialize();