[PATCH] dpnet: Add Server tests

Stefan Dösinger stefandoesinger at gmail.com
Thu Oct 15 09:42:40 CDT 2015


Just fyi, I want to take a closer look at this patch but didn't get around to it yet :-( .

Stefan

> Am 13.10.2015 um 11:05 schrieb Alistair Leslie-Hughes <leslie_alistair at hotmail.com>:
> 
> Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
> ---
> dlls/dpnet/tests/server.c | 194 ++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 179 insertions(+), 15 deletions(-)
> 
> diff --git a/dlls/dpnet/tests/server.c b/dlls/dpnet/tests/server.c
> index 8279666..9ed3ef3 100644
> --- a/dlls/dpnet/tests/server.c
> +++ b/dlls/dpnet/tests/server.c
> @@ -25,22 +25,84 @@
> /* {CD0C3D4B-E15E-4CF2-9EA8-6E1D6548C5A5} */
> static const GUID appguid = { 0xcd0c3d4b, 0xe15e, 0x4cf2, { 0x9e, 0xa8, 0x6e, 0x1d, 0x65, 0x48, 0xc5, 0xa5 } };
> static WCHAR sessionname[] = {'w','i','n','e','g','a','m','e','s','s','e','r','v','e','r',0};
> +static const WCHAR localhost[] = {'1','2','7','.','0','.','0','.','1',0};
> 
> -static BOOL nCreatePlayer;
> -static BOOL nDestroyPlayer;
> +static int create_cnt = 0;
> +static int destroy_dnt = 0;
> +static int indicate_cnt = 0;
> +static IDirectPlay8Server *server = NULL;
> +static IDirectPlay8Client* client = NULL;
> +static HANDLE connect = NULL;
> +static HANDLE hostenum = NULL;
> +static HANDLE clientfinished = NULL;
> +static DPN_APPLICATION_DESC hostdesc;
> 
> -static HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
> -{
> -    trace("msgid: 0x%08x\n", dwMessageId);
> +static IDirectPlay8Address *hostAddr = NULL;
> +static IDirectPlay8Address *deviceAddr = NULL;
> +static WCHAR session[255];
> 
> +static HRESULT WINAPI DirectPlayMessageHandler(void *pvUserContext, DWORD dwMessageId, void *pMsgBuffer)
> +{
>     switch(dwMessageId)
>     {
> +        case DPN_MSGID_INDICATE_CONNECT:
> +            trace("DPN_MSGID_CREATE_PLAYER\n");
> +            indicate_cnt++;
> +            break;
>         case DPN_MSGID_CREATE_PLAYER:
> -            nCreatePlayer = TRUE;
> +            trace("DPN_MSGID_CREATE_PLAYER\n");
> +            create_cnt++;
>             break;
>         case DPN_MSGID_DESTROY_PLAYER:
> -            nDestroyPlayer = TRUE;
> +            trace("DPN_MSGID_DESTROY_PLAYER\n");
> +            destroy_dnt++;
>             break;
> +        default:
> +            trace("msgid: 0x%08x\n", dwMessageId);
> +    }
> +
> +    return S_OK;
> +}
> +
> +static HRESULT WINAPI DirectPlayClientMsHandler(void *context, DWORD dwMessageId, void *buffer)
> +{
> +    HRESULT hr;
> +
> +    switch(dwMessageId)
> +    {
> +        case DPN_MSGID_ENUM_HOSTS_RESPONSE:
> +        {
> +            DPNMSG_ENUM_HOSTS_RESPONSE *host_msg;
> +            host_msg = (PDPNMSG_ENUM_HOSTS_RESPONSE)buffer;
> +
> +            trace("DPN_MSGID_ENUM_HOSTS_RESPONSE\n");
> +
> +            hr = IDirectPlay8Address_Duplicate(host_msg->pAddressSender, &hostAddr);
> +            ok(hr == S_OK, "Failed to Duplicate Host Address\n");
> +
> +            hr = IDirectPlay8Address_Duplicate(host_msg->pAddressDevice, &deviceAddr);
> +            ok(hr == S_OK, "Failed to Duplicate Device Address\n");
> +
> +            memset(&hostdesc, 0, sizeof(DPN_APPLICATION_DESC));
> +            memcpy(&hostdesc, host_msg->pApplicationDescription, sizeof(DPN_APPLICATION_DESC) );
> +
> +            lstrcpyW(session, host_msg->pApplicationDescription->pwszSessionName);
> +
> +            trace("SessionName: %s\n", wine_dbgstr_w(session));
> +            ok(!lstrcmpW(session, sessionname), "incorrect name %s\n", wine_dbgstr_w(session));
> +
> +            SetEvent(hostenum);
> +            break;
> +        }
> +        case DPN_MSGID_ASYNC_OP_COMPLETE:
> +            trace("DPN_MSGID_ASYNC_OP_COMPLETE\n");
> +            break;
> +        case DPN_MSGID_CONNECT_COMPLETE:
> +            trace("DPN_MSGID_CONNECT_COMPLETE\n");
> +            SetEvent(connect);
> +            break;
> +        default:
> +            trace("DirectPlayClientMsHandler: 0x%08x\n", dwMessageId);
>     }
> 
>     return S_OK;
> @@ -49,7 +111,6 @@ static HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMess
> static void create_server(void)
> {
>     HRESULT hr;
> -    IDirectPlay8Server *server = NULL;
> 
>     hr = CoCreateInstance( &CLSID_DirectPlay8Server, NULL, CLSCTX_ALL, &IID_IDirectPlay8Server, (LPVOID*)&server);
>     ok(hr == S_OK, "Failed to create IDirectPlay8Server object\n");
> @@ -74,6 +135,10 @@ static void create_server(void)
>             hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP);
>             ok(hr == S_OK, "got 0x%08x\n", hr);
> 
> +            hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, localhost, sizeof(localhost),
> +                                                         DPNA_DATATYPE_STRING);
> +            ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
> +
>             memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
>             appdesc.dwSize  = sizeof( DPN_APPLICATION_DESC );
>             appdesc.dwFlags = DPNSESSION_CLIENT_SERVER;
> @@ -83,16 +148,111 @@ static void create_server(void)
>             hr = IDirectPlay8Server_Host(server, &appdesc, &localaddr, 1, NULL, NULL, NULL, 0);
>             todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
> 
> -            todo_wine ok(nCreatePlayer, "No DPN_MSGID_CREATE_PLAYER Message\n");
> -            ok(!nDestroyPlayer, "Received DPN_MSGID_DESTROY_PLAYER Message\n");
> -
> -            hr = IDirectPlay8Server_Close(server, 0);
> -            todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
> -
> -            todo_wine ok(nDestroyPlayer, "No DPN_MSGID_DESTROY_PLAYER Message\n");
> +            todo_wine ok(create_cnt == 1, "No DPN_MSGID_CREATE_PLAYER Message\n");
> +            ok(indicate_cnt == 0, "wrong indicate count (%d)\n", indicate_cnt);
> 
>             IDirectPlay8Address_Release(localaddr);
>         }
> +    }
> +}
> +
> +static void create_client(void)
> +{
> +    HRESULT hr;
> +    IDirectPlay8Address *host = NULL;
> +    IDirectPlay8Address *device = NULL;
> +    DPN_APPLICATION_DESC appdesc;
> +    DWORD ret;
> +    DPNHANDLE async = 0;
> +
> +    hr = CoCreateInstance(&CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Client, (void **)&client);
> +    ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);
> +    if(hr != S_OK)
> +        return;
> +
> +    memset( &appdesc, 0, sizeof(DPN_APPLICATION_DESC) );
> +    appdesc.dwSize  = sizeof( DPN_APPLICATION_DESC );
> +    appdesc.guidApplication  = appguid;
> +
> +    connect  = CreateEventA( NULL, TRUE, FALSE, NULL);
> +    hostenum = CreateEventA( NULL, TRUE, FALSE, NULL);
> +
> +    hr = IDirectPlay8Client_Initialize(client, NULL, DirectPlayClientMsHandler, 0);
> +    ok(hr == S_OK, "IDirectPlay8Client_Initialize failed with %x\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 = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&device);
> +    ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
> +
> +    hr = IDirectPlay8Address_SetSP(device, &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 = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&device);
> +    ok(hr == S_OK, "IDirectPlay8Address failed with 0x%08x\n", hr);
> +
> +    hr = IDirectPlay8Address_SetSP(device, &CLSID_DP8SP_TCPIP);
> +    ok(hr == S_OK, "IDirectPlay8Address_SetSP failed with 0x%08x\n", hr);
> +
> +    hr = IDirectPlay8Client_EnumHosts(client, &appdesc, host, device, NULL, 0, INFINITE, 0, INFINITE, NULL,  &async, 0);
> +    todo_wine ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Client_EnumServiceProviders failed with 0x%08x\n", hr);
> +    todo_wine ok(async, "No Handle returned\n");
> +
> +    ret = WaitForSingleObject(hostenum, 2000);
> +    todo_wine ok(ret == WAIT_OBJECT_0, "Failed to get find host\n");
> +    if(ret == WAIT_OBJECT_0)
> +    {
> +        DPNHANDLE handle = 0;
> +
> +        hr = IDirectPlay8Client_Connect(client, &hostdesc, hostAddr, deviceAddr, NULL, NULL, NULL, 0, NULL, &handle, 0 );
> +        todo_wine ok(hr == DPNSUCCESS_PENDING, "IDirectPlay8Client_EnumServiceProviders failed with 0x%08x\n", hr);
> +
> +        ret = WaitForSingleObject(connect, 2000);
> +        todo_wine ok(ret == WAIT_OBJECT_0, "Connect failed.\n");
> +
> +        todo_wine ok(create_cnt == 1, "Wrong create player count (%d)\n", create_cnt);
> +        todo_wine ok(destroy_dnt == 0, "Wrong Destroy player count (%d)\n", destroy_dnt);
> +        todo_wine ok(indicate_cnt == 1, "wrong indicate count (%d)\n", indicate_cnt);
> +    }
> +
> +    CloseHandle(connect);
> +    CloseHandle(hostenum);
> +
> +    SetEvent(clientfinished);
> +
> +    IDirectPlay8Address_Release(host);
> +    IDirectPlay8Address_Release(device);
> +}
> +
> +static void cleanup(void)
> +{
> +    HRESULT hr;
> +
> +    if(client)
> +    {
> +        IDirectPlay8Client_Close(client, 0);
> +        IDirectPlay8Client_Release(client);
> +    }
> +
> +    if(hostAddr)
> +        IDirectPlay8Address_Release(hostAddr);
> +    if(deviceAddr)
> +        IDirectPlay8Address_Release(deviceAddr);
> +
> +    if(server)
> +    {
> +        hr = IDirectPlay8Server_Close(server, 0);
> +        todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
> +
> +        todo_wine ok(destroy_dnt == 2 || broken(destroy_dnt == 1), "Wrong Destroy player count (%d)\n", destroy_dnt);
> 
>         IDirectPlay8Server_Release(server);
>     }
> @@ -109,5 +269,9 @@ START_TEST(server)
> 
>     create_server();
> 
> +    create_client();
> +
> +    cleanup();
> +
>     CoUninitialize();
> }
> --
> 2.6.1
> 
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.winehq.org/pipermail/wine-devel/attachments/20151015/dfba7d34/attachment-0001.sig>


More information about the wine-devel mailing list