[3/6] dpnet: Partial Implement IDirectPlay8Peer SetPeerInfo (try 4)

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Thu Jan 16 19:10:09 CST 2014


Hi,
Added tests.

Changelog:
        dpnet: Partial Implement IDirectPlay8Peer SetPeerInfo


Best Regards
    Alistair Leslie-Hughes

-------------- next part --------------
>From 1cad41a7508d9e493ff803e5524809fe36b66cc3 Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date: Fri, 10 Jan 2014 11:10:40 +1100
Subject: [PATCH] Partial Implement IDirectPlay8Peer SetPeerInfo
To: wine-patches <wine-patches at winehq.org>

---
 dlls/dpnet/dpnet_private.h | 22 ++++++++++++++++++++++
 dlls/dpnet/peer.c          | 36 +++++++++++++++++++++++++++++++++---
 dlls/dpnet/tests/peer.c    | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 3 deletions(-)

diff --git a/dlls/dpnet/dpnet_private.h b/dlls/dpnet/dpnet_private.h
index 4a42eae..e4ff219 100644
--- a/dlls/dpnet/dpnet_private.h
+++ b/dlls/dpnet/dpnet_private.h
@@ -27,6 +27,9 @@
 
 #include "dplay8.h"
 #include "dplobby8.h"
+
+#include "wine/unicode.h"
+
 /*
  *#include "dplay8sp.h"
  */
@@ -95,6 +98,25 @@ extern HRESULT DPNET_CreateDirectPlay8Address(LPCLASSFACTORY iface, LPUNKNOWN pu
 extern HRESULT DPNET_CreateDirectPlay8LobbiedApp(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN;
 extern HRESULT DPNET_CreateDirectPlay8ThreadPool(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN;
 
+static void *heap_alloc( size_t len ) __WINE_ALLOC_SIZE(1);
+static inline void *heap_alloc( size_t len )
+{
+    return HeapAlloc( GetProcessHeap(), 0, len );
+}
+
+static inline BOOL heap_free( void *mem )
+{
+    return HeapFree( GetProcessHeap(), 0, mem );
+}
+
+static inline WCHAR *heap_strdupW( const WCHAR *src )
+{
+    WCHAR *dst;
+    if (!src) return NULL;
+    if ((dst = heap_alloc( (strlenW( src ) + 1) * sizeof(WCHAR) ))) strcpyW( dst, src );
+    return dst;
+}
+
 /* used for generic dumping (copied from ddraw) */
 typedef struct {
     DWORD val;
diff --git a/dlls/dpnet/peer.c b/dlls/dpnet/peer.c
index 1b287dd..280708b 100644
--- a/dlls/dpnet/peer.c
+++ b/dlls/dpnet/peer.c
@@ -43,6 +43,10 @@ typedef struct IDirectPlay8PeerImpl
 {
     IDirectPlay8Peer IDirectPlay8Peer_iface;
     LONG ref;
+
+    PWSTR peername;
+    void* data;
+    int datasize;
 } IDirectPlay8PeerImpl;
 
 static inline IDirectPlay8PeerImpl *impl_from_IDirectPlay8Peer(IDirectPlay8Peer *iface)
@@ -86,7 +90,12 @@ static ULONG WINAPI IDirectPlay8PeerImpl_Release(IDirectPlay8Peer *iface)
     TRACE("(%p) ref=%d\n", This, RefCount);
 
     if(!RefCount)
-        HeapFree(GetProcessHeap(), 0, This);
+    {
+        heap_free(This->peername);
+        heap_free(This->data);
+
+        heap_free(This);
+    }
 
     return RefCount;
 }
@@ -292,9 +301,27 @@ static HRESULT WINAPI IDirectPlay8PeerImpl_SetPeerInfo(IDirectPlay8Peer *iface,
         const DPN_PLAYER_INFO * const pdpnPlayerInfo, void * const pvAsyncContext,
         DPNHANDLE * const phAsyncHandle, const DWORD dwFlags)
 {
-    FIXME("(%p)->(%p,%p,%p,%x): stub\n", iface, pdpnPlayerInfo, pvAsyncContext, phAsyncHandle, dwFlags);
+    IDirectPlay8PeerImpl* This = impl_from_IDirectPlay8Peer(iface);
 
-    return DPNERR_GENERIC;
+    TRACE("(%p)->(%p,%p,%p,%x)\n", This, pdpnPlayerInfo, pvAsyncContext, phAsyncHandle, dwFlags);
+
+    if(pdpnPlayerInfo->dwInfoFlags & DPNINFO_NAME)
+    {
+        heap_free(This->peername);
+
+        This->peername = heap_strdupW(pdpnPlayerInfo->pwszName);
+    }
+
+    if(pdpnPlayerInfo->dwInfoFlags & DPNINFO_DATA)
+    {
+        heap_free(This->data);
+
+        This->datasize = pdpnPlayerInfo->dwDataSize;
+        This->data = heap_alloc(pdpnPlayerInfo->dwDataSize);
+        memcpy(This->data, pdpnPlayerInfo->pvData, pdpnPlayerInfo->dwDataSize);
+    }
+
+    return S_OK;
 }
 
 static HRESULT WINAPI IDirectPlay8PeerImpl_GetPeerInfo(IDirectPlay8Peer *iface, const DPNID dpnid,
@@ -502,6 +529,9 @@ HRESULT DPNET_CreateDirectPlay8Peer(IClassFactory *iface, IUnknown *pUnkOuter, R
 
     Client->IDirectPlay8Peer_iface.lpVtbl = &DirectPlay8Peer_Vtbl;
     Client->ref = 1;
+    Client->peername = NULL;
+    Client->data = NULL;
+    Client->datasize = 0;
 
     ret = IDirectPlay8Peer_QueryInterface(&Client->IDirectPlay8Peer_iface, riid, ppobj);
     IDirectPlay8Peer_Release(&Client->IDirectPlay8Peer_iface);
diff --git a/dlls/dpnet/tests/peer.c b/dlls/dpnet/tests/peer.c
index a9ab01d..4a268c8 100644
--- a/dlls/dpnet/tests/peer.c
+++ b/dlls/dpnet/tests/peer.c
@@ -144,6 +144,46 @@ static void test_get_sp_caps(void)
        "expected 0x10000, got 0x%x\n", caps.dwSystemBufferSize);
 }
 
+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;
+
+    info.pwszName = NULL;
+    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNOP_SYNC);
+    ok(hr == S_OK, "got %x\n", hr);
+
+    info.pwszName = name;
+    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNOP_SYNC);
+    ok(hr == S_OK, "got %x\n", hr);
+
+    info.dwInfoFlags = DPNINFO_NAME;
+    info.pwszName = name2;
+    hr = IDirectPlay8Peer_SetPeerInfo(peer, &info, NULL, NULL, DPNOP_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, DPNOP_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, DPNOP_SYNC);
+    ok(hr == S_OK, "got %x\n", hr);
+}
+
 static void test_cleanup_dp(void)
 {
     HRESULT hr;
@@ -162,5 +202,6 @@ START_TEST(peer)
     test_init_dp();
     test_enum_service_providers();
     test_get_sp_caps();
+    test_player_info();
     test_cleanup_dp();
 }
-- 
1.8.3.2




More information about the wine-patches mailing list