client.c 40.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright 2011 Louis Lenders
 * Copyright 2014 Alistair Leslie-Hughes
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#define WIN32_LEAN_AND_MEAN
#include <stdio.h>

#include <dplay8.h>
24
#include <dplobby8.h>
25 26
#include <winver.h>
#define COBJMACROS
27 28
#include "wine/test.h"

29 30
#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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
static const WCHAR localhost[] = {'1','2','7','.','0','.','0','.','1',0};

static HRESULT   lastAsyncCode   = E_FAIL;
static DPNHANDLE lastAsyncHandle = 0xdeadbeef;
static HANDLE    enumevent       = NULL;
static int       handlecnt       = 0;

static HRESULT WINAPI DirectPlayServerHandler(void *context, DWORD message_id, void *buffer)
{
    switch(message_id)
    {
        case DPN_MSGID_CREATE_PLAYER:
        case DPN_MSGID_DESTROY_PLAYER:
            /* These are tested in the server test */
            break;
        default:
            trace("DirectPlayServerHandler: 0x%08x\n", message_id);
    }
    return S_OK;
}
56 57 58

static HRESULT WINAPI DirectPlayMessageHandler(PVOID context, DWORD message_id, PVOID buffer)
{
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    switch(message_id)
    {
        case DPN_MSGID_ENUM_HOSTS_RESPONSE:
            handlecnt++;
            if(handlecnt >= 2)
                SetEvent(enumevent);
            break;
        case DPN_MSGID_ASYNC_OP_COMPLETE:
        {
            DPNMSG_ASYNC_OP_COMPLETE *async_msg = (DPNMSG_ASYNC_OP_COMPLETE*)buffer;
            lastAsyncCode   = async_msg->hResultCode;
            lastAsyncHandle = async_msg->hAsyncOp;
            break;
        }
        default:
            trace("DirectPlayMessageHandler: 0x%08x\n", message_id);
    }

77 78 79
    return S_OK;
}

80 81 82 83 84 85
static HRESULT WINAPI DirectPlayLobbyMessageHandler(PVOID context, DWORD message_id, PVOID buffer)
{
    trace("DirectPlayLobbyMessageHandler: 0x%08x\n", message_id);
    return S_OK;
}

86 87 88 89 90 91
static HRESULT WINAPI DirectPlayLobbyClientMessageHandler(void *context, DWORD message_id, void* buffer)
{
    trace("DirectPlayLobbyClientMessageHandler: 0x%08x\n", message_id);
    return S_OK;
}

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
static void create_server(void)
{
    static WCHAR sessionname[] = {'w','i','n','e','g','a','m','e','s','s','e','r','v','e','r',0};
    HRESULT hr;
    IDirectPlay8Address *localaddr = NULL;
    DPN_APPLICATION_DESC appdesc;

    hr = CoCreateInstance( &CLSID_DirectPlay8Server, NULL, CLSCTX_ALL, &IID_IDirectPlay8Server, (void **)&server);
    ok(hr == S_OK, "Failed to create IDirectPlay8Server object\n");

    hr = IDirectPlay8Server_Initialize(server, NULL, DirectPlayServerHandler, 0);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL,  CLSCTX_ALL, &IID_IDirectPlay8Address, (void **)&localaddr);
    ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");

    hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
    appdesc.dwSize  = sizeof( DPN_APPLICATION_DESC );
    appdesc.dwFlags = DPNSESSION_CLIENT_SERVER;
    appdesc.guidApplication  = appguid;
    appdesc.pwszSessionName  = sessionname;

    hr = IDirectPlay8Server_Host(server, &appdesc, &localaddr, 1, NULL, NULL, NULL, 0);
    todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);

    IDirectPlay8Address_Release(localaddr);
}

123 124 125
static BOOL test_init_dp(void)
{
    HRESULT hr;
126
    DPN_SP_CAPS caps;
127
    DPNHANDLE lobbyConnection;
128

129
    enumevent = CreateEventA( NULL, TRUE, FALSE, NULL);
130 131 132 133

    hr = CoCreateInstance(&CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Client, (void **)&client);
    ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);

134 135 136 137 138 139
    memset(&caps, 0, sizeof(DPN_SP_CAPS));
    caps.dwSize = sizeof(DPN_SP_CAPS);

    hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
    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);
142

143 144 145
    hr = IDirectPlay8Client_SetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPNERR_INVALIDPARAM, "SetSPCaps failed with %x\n", hr);

146 147 148
    hr = IDirectPlay8Client_Initialize(client, NULL, DirectPlayMessageHandler, 0);
    ok(hr == S_OK, "IDirectPlay8Client_Initialize failed with %x\n", hr);

149 150 151 152 153 154 155 156
    hr = CoCreateInstance(&CLSID_DirectPlay8LobbiedApplication, NULL, CLSCTX_INPROC_SERVER,
                          &IID_IDirectPlay8LobbiedApplication, (void **)&lobbied);
    ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);

    hr = IDirectPlay8LobbiedApplication_Initialize(lobbied, NULL, DirectPlayLobbyMessageHandler,
                                                &lobbyConnection, 0);
    ok(hr == S_OK, "IDirectPlay8LobbiedApplication_Initialize failed with %x\n", hr);

157 158 159 160 161 162 163 164 165 166 167 168 169 170
    return client != NULL;
}

static void test_enum_service_providers(void)
{
    DPN_SERVICE_PROVIDER_INFO *serv_prov_info;
    DWORD items, size;
    DWORD i;
    HRESULT hr;

    size = 0;
    items = 0;

    hr = IDirectPlay8Client_EnumServiceProviders(client, NULL, NULL, NULL, &size, NULL, 0);
171
    ok(hr == E_POINTER, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
172 173

    hr = IDirectPlay8Client_EnumServiceProviders(client, NULL, NULL, NULL, NULL, &items, 0);
174
    ok(hr == E_POINTER, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
175 176

    hr = IDirectPlay8Client_EnumServiceProviders(client, NULL, NULL, NULL, &size, &items, 0);
177 178
    ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
    ok(size != 0, "size is unexpectedly 0\n");
179 180 181 182 183

    serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);

    hr = IDirectPlay8Client_EnumServiceProviders(client, NULL, NULL, serv_prov_info, &size, &items, 0);
    ok(hr == S_OK, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
184
    ok(items != 0, "Found unexpectedly no service providers\n");
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

    trace("number of items found: %d\n", items);

    for (i=0;i<items;i++)
    {
        trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info[i].pwszName));
        trace("Found guid: %s\n", wine_dbgstr_guid(&serv_prov_info[i].guid));
    }

    ok(HeapFree(GetProcessHeap(), 0, serv_prov_info), "Failed freeing server provider info\n");

    size = 0;
    items = 0;

    hr = IDirectPlay8Client_EnumServiceProviders(client, &CLSID_DP8SP_TCPIP, NULL, NULL, &size, &items, 0);
200 201
    ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
    ok(size != 0, "size is unexpectedly 0\n");
202 203 204 205 206

    serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);

    hr = IDirectPlay8Client_EnumServiceProviders(client, &CLSID_DP8SP_TCPIP, NULL, serv_prov_info, &size, &items, 0);
    ok(hr == S_OK, "IDirectPlay8Client_EnumServiceProviders failed with %x\n", hr);
207
    ok(items != 0, "Found unexpectedly no adapter\n");
208 209 210 211 212 213 214 215


    for (i=0;i<items;i++)
    {
        trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info[i].pwszName));
        trace("Found adapter guid: %s\n", wine_dbgstr_guid(&serv_prov_info[i].guid));
    }

216 217 218 219 220
    /* Invalid GUID */
    items = 88;
    hr = IDirectPlay8Client_EnumServiceProviders(client, &appguid, NULL, serv_prov_info, &size, &items, 0);
    ok(hr == DPNERR_DOESNOTEXIST, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
    ok(items == 88, "Found adapter %d\n", items);
221 222

    HeapFree(GetProcessHeap(), 0, serv_prov_info);
223 224 225 226 227
}

static void test_enum_hosts(void)
{
    HRESULT hr;
228
    IDirectPlay8Client *client2;
229 230 231
    IDirectPlay8Address *host = NULL;
    IDirectPlay8Address *local = NULL;
    DPN_APPLICATION_DESC appdesc;
232 233 234
    DPNHANDLE async = 0, async2 = 0;
    DPN_SP_CAPS caps;
    char *data;
235 236 237 238 239

    memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
    appdesc.dwSize  = sizeof( DPN_APPLICATION_DESC );
    appdesc.guidApplication  = appguid;

240 241 242
    hr = CoCreateInstance(&CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Client, (void **)&client2);
    ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&local);
    ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);

    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&host);
    ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
                                                         DPNA_DATATYPE_STRING);
    ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);

259 260 261 262 263 264 265
    caps.dwSize = sizeof(DPN_SP_CAPS);

    hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPN_OK, "got %x\n", hr);
    data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, caps.dwMaxEnumPayloadSize + 1);

    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);
267 268 269

    hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, data, caps.dwMaxEnumPayloadSize + 1,
                                        INFINITE, 0, INFINITE, NULL,  &async, DPNENUMHOSTS_SYNC);
270
    ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
271 272 273 274

    async = 0;
    hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, data, caps.dwMaxEnumPayloadSize + 1, INFINITE, 0,
                                        INFINITE, NULL,  &async, 0);
275
    ok(hr == DPNERR_ENUMQUERYTOOLARGE, "got 0x%08x\n", hr);
276 277 278 279 280
    ok(!async, "Handle returned\n");

    async = 0;
    hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, data, caps.dwMaxEnumPayloadSize, INFINITE, 0, INFINITE,
                                        NULL,  &async, 0);
281
    ok(hr == DPNSUCCESS_PENDING, "got 0x%08x\n", hr);
282 283 284 285 286 287 288 289 290
    todo_wine ok(async, "No Handle returned\n");

    /* This CancelAsyncOperation doesn't generate a DPN_MSGID_ASYNC_OP_COMPLETE */
    hr = IDirectPlay8Client_CancelAsyncOperation(client, async, 0);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    HeapFree(GetProcessHeap(), 0, data);

    /* No Initialize has been called on client2. */
    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);
292

293 294
    /* Since we are running asynchronously, EnumHosts returns DPNSUCCESS_PENDING. */
    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 297
    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 301 302 303 304 305 306
    todo_wine ok(async2, "No Handle returned\n");
    todo_wine ok(async2 != async, "Same handle returned.\n");

    WaitForSingleObject(enumevent, 1000);

    lastAsyncCode = E_FAIL;
    lastAsyncHandle = 0xdeadbeef;
307 308
    hr = IDirectPlay8Client_CancelAsyncOperation(client, async, 0);
    ok(hr == S_OK, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr);
309 310 311
    todo_wine ok(lastAsyncCode == DPNERR_USERCANCEL, "got 0x%08x\n", lastAsyncCode);
    todo_wine ok(lastAsyncHandle == async, "got 0x%08x\n", async);

312 313 314 315 316 317 318
    hr = IDirectPlay8Client_Initialize(client2, NULL, DirectPlayMessageHandler, 0);
    ok(hr == S_OK, "got %x\n", hr);

    /* Show that handlers are per object. */
    hr = IDirectPlay8Client_CancelAsyncOperation(client2, async2, 0);
    todo_wine ok(hr == DPNERR_INVALIDHANDLE, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr);

319 320 321 322 323 324
    lastAsyncCode = E_FAIL;
    lastAsyncHandle = 0xdeadbeef;
    hr = IDirectPlay8Client_CancelAsyncOperation(client, async2, 0);
    ok(hr == S_OK, "IDirectPlay8Client_CancelAsyncOperation failed with 0x%08x\n", hr);
    todo_wine ok(lastAsyncCode == DPNERR_USERCANCEL, "got 0x%08x\n", lastAsyncCode);
    todo_wine ok(lastAsyncHandle == async2, "got 0x%08x\n", async2);
325 326 327

    IDirectPlay8Address_Release(local);
    IDirectPlay8Address_Release(host);
328
    IDirectPlay8Client_Release(client2);
329 330
}

331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
static void test_enum_hosts_sync(void)
{
    HRESULT hr;
    IDirectPlay8Address *host = NULL;
    IDirectPlay8Address *local = NULL;
    DPN_APPLICATION_DESC appdesc;
    DWORD port = 5445, type = 0, size;

    memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
    appdesc.dwSize  = sizeof( DPN_APPLICATION_DESC );
    appdesc.guidApplication  = appguid;

    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void**)&local);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void**)&host);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
                                                         DPNA_DATATYPE_STRING);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    handlecnt = 0;
    lastAsyncCode = 0xdeadbeef;
    hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, 3, 1500, 1000,
                                        NULL,  NULL, DPNENUMHOSTS_SYNC);
    ok(hr == DPN_OK, "got 0x%08x\n", hr);
    ok(lastAsyncCode == 0xdeadbeef, "got 0x%08x\n", lastAsyncCode);
    todo_wine ok(handlecnt == 2, "message handler not called\n");

    size = sizeof(port);
    hr = IDirectPlay8Address_GetComponentByName(host, DPNA_KEY_PORT, &port, &size, &type);
    ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);

    size = sizeof(port);
    hr = IDirectPlay8Address_GetComponentByName(local, DPNA_KEY_PORT, &port, &size, &type);
    ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);

    /* Try with specific port */
    port = 5445;
    hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_PORT, &port, sizeof(port),
                                                         DPNA_DATATYPE_DWORD);

    handlecnt = 0;
    lastAsyncCode = 0xbeefdead;
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);
    hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, local, NULL, 0, 1, 1500, 1000,
                                        NULL,  NULL, DPNENUMHOSTS_SYNC);
    ok(hr == DPN_OK, "got 0x%08x\n", hr);
    ok(lastAsyncCode == 0xbeefdead, "got 0x%08x\n", lastAsyncCode);
    ok(handlecnt == 0, "message handler called\n");

    IDirectPlay8Address_Release(local);
    IDirectPlay8Address_Release(host);
}

393 394 395 396 397 398 399 400
static void test_get_sp_caps(void)
{
    DPN_SP_CAPS caps;
    HRESULT hr;

    memset(&caps, 0, sizeof(DPN_SP_CAPS));

    hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
401
    ok(hr == DPNERR_INVALIDPARAM, "GetSPCaps unexpectedly returned %x\n", hr);
402 403 404 405 406 407

    caps.dwSize = sizeof(DPN_SP_CAPS);

    hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
    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 411 412
        (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS)) ==
       (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS),
       "unexpected flags %x\n", caps.dwFlags);
413 414 415 416 417 418 419
    ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
    ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
    ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
    ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
    ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
    ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
    ok(caps.dwSystemBufferSize == 0x10000 || broken(caps.dwSystemBufferSize == 0x2000 /* before Win8 */),
420
       "expected 0x10000, got 0x%x\n", caps.dwSystemBufferSize);
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447

    caps.dwNumThreads = 2;
    caps.dwDefaultEnumCount = 3;
    caps.dwDefaultEnumRetryInterval = 1400;
    caps.dwDefaultEnumTimeout = 1400;
    caps.dwMaxEnumPayloadSize = 900;
    caps.dwBuffersPerThread = 2;
    caps.dwSystemBufferSize = 0x0ffff;
    hr = IDirectPlay8Client_SetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPN_OK, "SetSPCaps failed with %x\n", hr);

    hr = IDirectPlay8Client_GetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);

    ok(caps.dwSize == sizeof(DPN_SP_CAPS), "got %d\n", caps.dwSize);
    ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
    ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
    ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
    ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
    ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
    ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
    ok(caps.dwSystemBufferSize == 0x0ffff, "expected 0x0ffff, got 0x%x\n", caps.dwSystemBufferSize);

    /* Reset the System setting back to its default. */
    caps.dwSystemBufferSize = 0x10000;
    hr = IDirectPlay8Client_SetSPCaps(client, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPN_OK, "SetSPCaps failed with %x\n", hr);
448 449
}

450
static void test_lobbyclient(void)
451 452 453 454 455 456 457 458
{
    HRESULT hr;
    IDirectPlay8LobbyClient *client = NULL;

    hr = CoCreateInstance( &CLSID_DirectPlay8LobbyClient, NULL, CLSCTX_ALL, &IID_IDirectPlay8LobbyClient, (void**)&client);
    ok(hr == S_OK, "Failed to create object\n");
    if(SUCCEEDED(hr))
    {
459 460 461
        hr = IDirectPlay8LobbyClient_Initialize(client, NULL, NULL, 0);
        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);
464 465 466 467 468 469 470 471

        hr = IDirectPlay8LobbyClient_Close(client, 0);
        todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);

        IDirectPlay8LobbyClient_Release(client);
    }
}

472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
static void test_player_info(void)
{
    HRESULT hr;
    DPN_PLAYER_INFO info;
    WCHAR name[] = {'w','i','n','e',0};
    WCHAR name2[] = {'w','i','n','e','2',0};
    WCHAR data[] = {'X','X','X','X',0};

    ZeroMemory( &info, sizeof(DPN_PLAYER_INFO) );
    info.dwSize = sizeof(DPN_PLAYER_INFO);
    info.dwInfoFlags = DPNINFO_NAME;

    hr = IDirectPlay8Client_SetClientInfo(client, NULL, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == E_POINTER, "got %x\n", hr);

    info.pwszName = NULL;
    hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.pwszName = name;
    hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.dwInfoFlags = DPNINFO_NAME;
    info.pwszName = name2;
    hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.dwInfoFlags = DPNINFO_DATA;
    info.pwszName = NULL;
    info.pvData = NULL;
    info.dwDataSize = sizeof(data);
    hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == E_POINTER, "got %x\n", hr);

    info.dwInfoFlags = DPNINFO_DATA;
    info.pwszName = NULL;
    info.pvData = data;
    info.dwDataSize = 0;
    hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.dwInfoFlags = DPNINFO_DATA;
    info.pwszName = NULL;
    info.pvData = data;
    info.dwDataSize = sizeof(data);
    hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME;
    info.pwszName = name;
    info.pvData = data;
    info.dwDataSize = sizeof(data);
    hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    /* Leave ClientInfo with only the name set. */
    info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME;
    info.pwszName = name;
    info.pvData = NULL;
    info.dwDataSize = 0;
    hr = IDirectPlay8Client_SetClientInfo(client, &info, NULL, NULL, DPNSETCLIENTINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);
}

537 538 539 540 541 542 543
static void test_cleanup_dp(void)
{
    HRESULT hr;

    hr = IDirectPlay8Client_Close(client, 0);
    ok(hr == S_OK, "IDirectPlay8Client_Close failed with %x\n", hr);

544 545 546 547 548 549 550 551 552
    if(lobbied)
    {
        hr = IDirectPlay8LobbiedApplication_Close(lobbied, 0);
        ok(hr == S_OK, "IDirectPlay8LobbiedApplication_Close failed with %x\n", hr);

        IDirectPlay8LobbiedApplication_Release(lobbied);
    }

    IDirectPlay8Client_Release(client);
553 554
}

555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
static void test_close(void)
{
    HRESULT hr;
    static IDirectPlay8Client* client2;
    DPN_SP_CAPS caps;

    hr = CoCreateInstance(&CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Client, (void **)&client2);
    ok(hr == S_OK, "got 0x%x\n", hr);

    memset(&caps, 0, sizeof(DPN_SP_CAPS));
    caps.dwSize = sizeof(DPN_SP_CAPS);

    hr = IDirectPlay8Client_Initialize(client2, NULL, DirectPlayMessageHandler, 0);
    ok(hr == S_OK, "got %x\n", hr);

    hr = IDirectPlay8Client_GetSPCaps(client2, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPN_OK, "got %x\n", hr);

    hr = IDirectPlay8Client_Close(client2, 0);
    ok(hr == DPN_OK, "got %x\n", hr);

    hr = IDirectPlay8Client_GetSPCaps(client2, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPNERR_UNINITIALIZED, "got %x\n", hr);

    IDirectPlay8Client_Release(client2);
}

582 583 584 585 586 587 588 589 590 591 592 593
static void test_init_dp_peer(void)
{
    HRESULT hr;
    DPN_SP_CAPS caps;
    DPNHANDLE lobbyConnection;

    hr = CoCreateInstance(&CLSID_DirectPlay8Peer, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Peer, (void **)&peer);
    ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);

    memset(&caps, 0, sizeof(DPN_SP_CAPS));
    caps.dwSize = sizeof(DPN_SP_CAPS);

594 595 596
    hr = IDirectPlay8Peer_SetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPNERR_INVALIDPARAM, "SetSPCaps failed with %x\n", hr);

597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
    hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPNERR_UNINITIALIZED, "GetSPCaps failed with %x\n", hr);

    hr = IDirectPlay8Peer_Initialize(peer, NULL, NULL, 0);
    ok(hr == DPNERR_INVALIDPARAM, "got %x\n", hr);

    hr = IDirectPlay8Peer_Initialize(peer, NULL, DirectPlayMessageHandler, 0);
    ok(hr == S_OK, "IDirectPlay8Peer_Initialize failed with %x\n", hr);

    hr = CoCreateInstance(&CLSID_DirectPlay8LobbiedApplication, NULL, CLSCTX_INPROC_SERVER,
                          &IID_IDirectPlay8LobbiedApplication, (void **)&lobbied);
    ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);

    hr = IDirectPlay8LobbiedApplication_Initialize(lobbied, NULL, NULL,
                                                &lobbyConnection, 0);
    ok(hr == DPNERR_INVALIDPOINTER, "Failed with %x\n", hr);

    hr = IDirectPlay8LobbiedApplication_Initialize(lobbied, NULL, DirectPlayLobbyMessageHandler,
                                                &lobbyConnection, 0);
    ok(hr == S_OK, "IDirectPlay8LobbiedApplication_Initialize failed with %x\n", hr);
}

static void test_enum_service_providers_peer(void)
{
    DPN_SERVICE_PROVIDER_INFO *serv_prov_info;
    DWORD items, size;
    DWORD i;
    HRESULT hr;

    size = 0;
    items = 0;

    hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, NULL, &size, NULL, 0);
    ok(hr == E_POINTER, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);

    hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, NULL, NULL, &items, 0);
    ok(hr == E_POINTER, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);

    hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, NULL, &size, &items, 0);
    ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
    ok(size != 0, "size is unexpectedly 0\n");

    serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);

    hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, serv_prov_info, &size, &items, 0);
    ok(hr == S_OK, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
    ok(items != 0, "Found unexpectedly no service providers\n");

    trace("number of items found: %d\n", items);

    for (i=0;i<items;i++)
    {
649 650
        trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info[i].pwszName));
        trace("Found guid: %s\n", wine_dbgstr_guid(&serv_prov_info[i].guid));
651 652
    }

653
    HeapFree(GetProcessHeap(), 0, serv_prov_info);
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670

    size = 0;
    items = 0;

    hr = IDirectPlay8Peer_EnumServiceProviders(peer, &CLSID_DP8SP_TCPIP, NULL, NULL, &size, &items, 0);
    ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
    ok(size != 0, "size is unexpectedly 0\n");

    serv_prov_info = HeapAlloc(GetProcessHeap(), 0, size);

    hr = IDirectPlay8Peer_EnumServiceProviders(peer, &CLSID_DP8SP_TCPIP, NULL, serv_prov_info, &size, &items, 0);
    ok(hr == S_OK, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
    ok(items != 0, "Found unexpectedly no adapter\n");


    for (i=0;i<items;i++)
    {
671 672
        trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info[i].pwszName));
        trace("Found adapter guid: %s\n", wine_dbgstr_guid(&serv_prov_info[i].guid));
673 674
    }

675 676 677 678 679
    /* Invalid GUID */
    items = 88;
    hr = IDirectPlay8Peer_EnumServiceProviders(peer, &appguid, NULL, serv_prov_info, &size, &items, 0);
    ok(hr == DPNERR_DOESNOTEXIST, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
    ok(items == 88, "Found adapter %d\n", items);
680 681

    HeapFree(GetProcessHeap(), 0, serv_prov_info);
682 683 684 685 686
}

static void test_enum_hosts_peer(void)
{
    HRESULT hr;
687
    IDirectPlay8Peer *peer2;
688 689 690
    IDirectPlay8Address *host = NULL;
    IDirectPlay8Address *local = NULL;
    DPN_APPLICATION_DESC appdesc;
691 692 693 694
    DPNHANDLE async = 0, async2 = 0;

    ResetEvent(enumevent);
    handlecnt = 0;
695 696 697 698 699

    memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
    appdesc.dwSize  = sizeof( DPN_APPLICATION_DESC );
    appdesc.guidApplication  = appguid;

700 701 702
    hr = CoCreateInstance(&CLSID_DirectPlay8Peer, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Peer, (void **)&peer2);
    ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);

703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&local);
    ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);

    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&host);
    ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
                                                         DPNA_DATATYPE_STRING);
    ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);

    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 722 723 724 725
    todo_wine ok(async, "No Handle returned\n");

    hr = IDirectPlay8Peer_CancelAsyncOperation(peer, async, 0);
    todo_wine ok(hr == S_OK, "IDirectPlay8Peer_CancelAsyncOperation failed with 0x%08x\n", hr);

726 727
    /* No Initialize has been called on peer2. */
    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);
729 730 731

    /* Since we are running asynchronously, EnumHosts returns DPNSUCCESS_PENDING. */
    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 734 735
    todo_wine ok(async, "No Handle returned\n");

    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 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
    todo_wine ok(async2, "No Handle returned\n");
    todo_wine ok(async2 != async, "Same handle returned.\n");

    WaitForSingleObject(enumevent, 1000);

    lastAsyncCode = E_FAIL;
    lastAsyncHandle = 0xdeadbeef;
    hr = IDirectPlay8Peer_CancelAsyncOperation(peer, async, 0);
    todo_wine ok(hr == S_OK, "IDirectPlay8Peer_CancelAsyncOperation failed with 0x%08x\n", hr);
    todo_wine ok(lastAsyncCode == DPNERR_USERCANCEL, "got 0x%08x\n", lastAsyncCode);
    todo_wine ok(lastAsyncHandle == async, "got 0x%08x\n", async);

    lastAsyncCode = E_FAIL;
    lastAsyncHandle = 0xdeadbeef;
    hr = IDirectPlay8Peer_CancelAsyncOperation(peer, async2, 0);
    todo_wine ok(hr == S_OK, "IDirectPlay8Peer_CancelAsyncOperation failed with 0x%08x\n", hr);
    todo_wine ok(lastAsyncCode == DPNERR_USERCANCEL, "got 0x%08x\n", lastAsyncCode);
    todo_wine ok(lastAsyncHandle == async2, "got 0x%08x\n", async2);

    IDirectPlay8Peer_Release(peer2);
757 758 759 760
    IDirectPlay8Address_Release(local);
    IDirectPlay8Address_Release(host);
}

761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
static void test_enum_hosts_sync_peer(void)
{
    HRESULT hr;
    IDirectPlay8Address *host = NULL;
    IDirectPlay8Address *local = NULL;
    DPN_APPLICATION_DESC appdesc;
    DWORD port = 5445, type = 0, size;

    memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
    appdesc.dwSize  = sizeof( DPN_APPLICATION_DESC );
    appdesc.guidApplication  = appguid;

    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void**)&local);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_SetSP(local, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (void**)&host);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_SetSP(host, &CLSID_DP8SP_TCPIP);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
                                                         DPNA_DATATYPE_STRING);
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);

    handlecnt = 0;
    lastAsyncCode = 0xdeadbeef;
    hr = IDirectPlay8Peer_EnumHosts(peer, &appdesc, host, local, NULL, 0, 3, 1500, 1000,
                                        NULL,  NULL, DPNENUMHOSTS_SYNC);
    ok(hr == DPN_OK, "got 0x%08x\n", hr);
    ok(lastAsyncCode == 0xdeadbeef, "got 0x%08x\n", lastAsyncCode);
    todo_wine ok(handlecnt == 2, "wrong handle cnt\n");

    size = sizeof(port);
    hr = IDirectPlay8Address_GetComponentByName(host, DPNA_KEY_PORT, &port, &size, &type);
    ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);

    size = sizeof(port);
    hr = IDirectPlay8Address_GetComponentByName(local, DPNA_KEY_PORT, &port, &size, &type);
    ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);

    /* Try with specific port */
    port = 5445;
    hr = IDirectPlay8Address_AddComponent(host, DPNA_KEY_PORT, &port, sizeof(port),
                                                         DPNA_DATATYPE_DWORD);

    handlecnt = 0;
    lastAsyncCode = 0xbeefdead;
    ok(hr == S_OK, "Failed with 0x%08x\n", hr);
    hr = IDirectPlay8Peer_EnumHosts(peer, &appdesc, host, local, NULL, 0, 1, 1500, 1000,
                                        NULL,  NULL, DPNENUMHOSTS_SYNC);
    ok(hr == DPN_OK, "got 0x%08x\n", hr);
    ok(lastAsyncCode == 0xbeefdead, "got 0x%08x\n", lastAsyncCode);
    ok(handlecnt == 0, "message handler called\n");

    IDirectPlay8Address_Release(local);
    IDirectPlay8Address_Release(host);
}

823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
static void test_get_sp_caps_peer(void)
{
    DPN_SP_CAPS caps;
    HRESULT hr;

    memset(&caps, 0, sizeof(DPN_SP_CAPS));

    hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPNERR_INVALIDPARAM, "GetSPCaps unexpectedly returned %x\n", hr);

    caps.dwSize = sizeof(DPN_SP_CAPS);

    hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);

    ok(caps.dwSize == sizeof(DPN_SP_CAPS), "got %d\n", caps.dwSize);
    ok((caps.dwFlags &
        (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS)) ==
       (DPNSPCAPS_SUPPORTSDPNSRV | DPNSPCAPS_SUPPORTSBROADCAST | DPNSPCAPS_SUPPORTSALLADAPTERS),
       "unexpected flags %x\n", caps.dwFlags);
    ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
    ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
    ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
    ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
    ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
    ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
    ok(caps.dwSystemBufferSize == 0x10000 || broken(caps.dwSystemBufferSize == 0x2000 /* before Win8 */),
       "expected 0x10000, got 0x%x\n", caps.dwSystemBufferSize);
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872

    caps.dwNumThreads = 2;
    caps.dwDefaultEnumCount = 3;
    caps.dwDefaultEnumRetryInterval = 1400;
    caps.dwDefaultEnumTimeout = 1400;
    caps.dwMaxEnumPayloadSize = 900;
    caps.dwBuffersPerThread = 2;
    caps.dwSystemBufferSize = 0x0ffff;
    hr = IDirectPlay8Peer_SetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPN_OK, "SetSPCaps failed with %x\n", hr);

    hr = IDirectPlay8Peer_GetSPCaps(peer, &CLSID_DP8SP_TCPIP, &caps, 0);
    ok(hr == DPN_OK, "GetSPCaps failed with %x\n", hr);

    ok(caps.dwSize == sizeof(DPN_SP_CAPS), "got %d\n", caps.dwSize);
    ok(caps.dwNumThreads >= 3, "got %d\n", caps.dwNumThreads);
    ok(caps.dwDefaultEnumCount == 5, "expected 5, got %d\n", caps.dwDefaultEnumCount);
    ok(caps.dwDefaultEnumRetryInterval == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumRetryInterval);
    ok(caps.dwDefaultEnumTimeout == 1500, "expected 1500, got %d\n", caps.dwDefaultEnumTimeout);
    ok(caps.dwMaxEnumPayloadSize == 983, "expected 983, got %d\n", caps.dwMaxEnumPayloadSize);
    ok(caps.dwBuffersPerThread == 1, "expected 1, got %d\n", caps.dwBuffersPerThread);
    ok(caps.dwSystemBufferSize == 0x0ffff, "expected 0x0ffff, got 0x%x\n", caps.dwSystemBufferSize);
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
}

static void test_player_info_peer(void)
{
    HRESULT hr;
    DPN_PLAYER_INFO info;
    WCHAR name[] = {'w','i','n','e',0};
    WCHAR name2[] = {'w','i','n','e','2',0};
    WCHAR data[] = {'X','X','X','X',0};

    ZeroMemory( &info, sizeof(DPN_PLAYER_INFO) );
    info.dwSize = sizeof(DPN_PLAYER_INFO);
    info.dwInfoFlags = DPNINFO_NAME;

    hr = IDirectPlay8Peer_SetPeerInfo(peer, NULL, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == E_POINTER, "got %x\n", hr);

    info.pwszName = NULL;
    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.pwszName = name;
    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.dwInfoFlags = DPNINFO_NAME;
    info.pwszName = name2;
    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

if(0) /* Crashes on windows */
{
    info.dwInfoFlags = DPNINFO_DATA;
    info.pwszName = NULL;
    info.pvData = NULL;
    info.dwDataSize = sizeof(data);
    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);
}

    info.dwInfoFlags = DPNINFO_DATA;
    info.pwszName = NULL;
    info.pvData = data;
    info.dwDataSize = 0;
    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.dwInfoFlags = DPNINFO_DATA;
    info.pwszName = NULL;
    info.pvData = data;
    info.dwDataSize = sizeof(data);
    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME;
    info.pwszName = name;
    info.pvData = data;
    info.dwDataSize = sizeof(data);
    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);

    /* Leave PeerInfo with only the name set. */
    info.dwInfoFlags = DPNINFO_DATA | DPNINFO_NAME;
    info.pwszName = name;
    info.pvData = NULL;
    info.dwDataSize = 0;
    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNSETPEERINFO_SYNC);
    ok(hr == S_OK, "got %x\n", hr);
}

static void test_cleanup_dp_peer(void)
{
    HRESULT hr;

    hr = IDirectPlay8Peer_Close(peer, 0);
    ok(hr == S_OK, "IDirectPlay8Peer_Close failed with %x\n", hr);

    if(lobbied)
    {
        hr = IDirectPlay8LobbiedApplication_Close(lobbied, 0);
        ok(hr == S_OK, "IDirectPlay8LobbiedApplication_Close failed with %x\n", hr);

        IDirectPlay8LobbiedApplication_Release(lobbied);
    }

    IDirectPlay8Peer_Release(peer);
}

961 962
START_TEST(client)
{
963
    BOOL firewall_enabled;
964
    HRESULT hr;
965
    char path[MAX_PATH];
966

967 968 969 970 971 972 973 974
    if(!GetSystemDirectoryA(path, MAX_PATH))
    {
        skip("Failed to get systems directory\n");
        return;
    }
    strcat(path, "\\dpnet.dll");

    if (!winetest_interactive && is_stub_dll(path))
975 976 977 978 979
    {
        win_skip("dpnet is a stub dll, skipping tests\n");
        return;
    }

980 981 982
    if ((firewall_enabled = is_firewall_enabled()) && !is_process_elevated())
    {
        skip("no privileges, skipping tests to avoid firewall dialog\n");
983
        return;
984 985 986 987
    }

    if (firewall_enabled)
    {
988
        hr = set_firewall(APP_ADD);
989 990 991 992 993 994 995
        if (hr != S_OK)
        {
            skip("can't authorize app in firewall %08x\n", hr);
            return;
        }
    }

996 997 998 999 1000 1001 1002
    hr = CoInitialize(0);
    ok(hr == S_OK, "CoInitialize failed with %x\n", hr);

    if (!test_init_dp())
        goto done;

    create_server();
1003 1004 1005

    test_enum_service_providers();
    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();
1012 1013 1014 1015

    test_init_dp_peer();
    test_enum_service_providers_peer();
    test_enum_hosts_peer();
1016
    test_enum_hosts_sync_peer();
1017 1018 1019
    test_get_sp_caps_peer();
    test_player_info_peer();
    test_cleanup_dp_peer();
1020

1021 1022 1023 1024 1025 1026
    hr = IDirectPlay8Server_Close(server, 0);
    todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
    IDirectPlay8Server_Release(server);

    CloseHandle(enumevent);

1027 1028
done:
    if (firewall_enabled) set_firewall(APP_REMOVE);
1029 1030

    CoUninitialize();
1031
}