dpnet: Implement IDirectPlay8Address AddComponent.

This commit is contained in:
Alistair Leslie-Hughes 2014-04-11 09:02:56 +10:00 committed by Alexandre Julliard
parent a192e7f11b
commit 9a5a5a365e
3 changed files with 269 additions and 31 deletions

View File

@ -29,6 +29,8 @@
#include "wingdi.h"
#include "winuser.h"
#include "objbase.h"
#include "wine/unicode.h"
#include "wine/debug.h"
#include "dplay8.h"
@ -36,6 +38,42 @@
WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
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 LPWSTR heap_strdupW(LPCWSTR str)
{
LPWSTR ret = NULL;
if(str) {
DWORD size;
size = (strlenW(str)+1)*sizeof(WCHAR);
ret = heap_alloc(size);
if(ret)
memcpy(ret, str, size);
}
return ret;
}
static char *heap_strdupA( const char *str )
{
char *ret;
if (!str) return NULL;
if ((ret = HeapAlloc( GetProcessHeap(), 0, strlen(str) + 1 ))) strcpy( ret, str );
return ret;
}
static inline IDirectPlay8AddressImpl *impl_from_IDirectPlay8Address(IDirectPlay8Address *iface)
{
return CONTAINING_RECORD(iface, IDirectPlay8AddressImpl, IDirectPlay8Address_iface);
@ -72,7 +110,28 @@ static ULONG WINAPI IDirectPlay8AddressImpl_Release(IDirectPlay8Address *iface)
TRACE("(%p) ref=%u\n", This, ref);
if (!ref) {
if (!ref)
{
struct component *entry, *entry2;
LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->components, struct component, entry)
{
switch(entry->type)
{
case DPNA_DATATYPE_STRING:
heap_free(entry->data.string);
break;
case DPNA_DATATYPE_STRING_ANSI:
heap_free(entry->data.ansi);
break;
case DPNA_DATATYPE_BINARY:
heap_free(entry->data.binary);
break;
}
HeapFree(GetProcessHeap(), 0, entry);
}
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
@ -214,9 +273,15 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_SetUserData(IDirectPlay8Address *i
static HRESULT WINAPI IDirectPlay8AddressImpl_GetNumComponents(IDirectPlay8Address *iface,
DWORD *pdwNumComponents)
{
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
TRACE("(%p): stub\n", This);
return DPN_OK;
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
TRACE("(%p): stub\n", This);
if(!pdwNumComponents)
return DPNERR_INVALIDPOINTER;
*pdwNumComponents = list_count(&This->components);
return DPN_OK;
}
static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByName(IDirectPlay8Address *iface,
@ -240,28 +305,74 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address *
const WCHAR *const pwszName, const void* const lpvData, const DWORD dwDataSize,
const DWORD dwDataType)
{
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
TRACE("(%p, %s, %p, %u, %x): stub\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
if (NULL == lpvData) return DPNERR_INVALIDPOINTER;
switch (dwDataType) {
case DPNA_DATATYPE_DWORD:
if (sizeof(DWORD) != dwDataSize) return DPNERR_INVALIDPARAM;
TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
break;
case DPNA_DATATYPE_GUID:
if (sizeof(GUID) != dwDataSize) return DPNERR_INVALIDPARAM;
TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid(lpvData));
break;
case DPNA_DATATYPE_STRING:
TRACE("(%p, %u): STRING Type -> %s\n", lpvData, dwDataSize, (const CHAR*) lpvData);
break;
case DPNA_DATATYPE_BINARY:
TRACE("(%p, %u): BINARY Type\n", lpvData, dwDataSize);
break;
}
return DPN_OK;
IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
struct component *entry;
BOOL found = FALSE;
TRACE("(%p, %s, %p, %u, %x): stub\n", This, debugstr_w(pwszName), lpvData, dwDataSize, dwDataType);
if (NULL == lpvData)
return DPNERR_INVALIDPOINTER;
LIST_FOR_EACH_ENTRY(entry, &This->components, struct component, entry)
{
if (lstrcmpW(pwszName, entry->name) == 0)
{
TRACE("Found %s\n", debugstr_w(pwszName));
found = TRUE;
break;
}
}
if(!found)
{
/* Create a new one */
entry = heap_alloc(sizeof(struct component));
entry->name = heap_strdupW(pwszName);
entry->type = dwDataType;
list_add_tail(&This->components, &entry->entry);
}
switch (dwDataType)
{
case DPNA_DATATYPE_DWORD:
if (sizeof(DWORD) != dwDataSize)
return DPNERR_INVALIDPARAM;
entry->data.value = *(DWORD*)lpvData;
TRACE("(%p, %u): DWORD Type -> %u\n", lpvData, dwDataSize, *(const DWORD*) lpvData);
break;
case DPNA_DATATYPE_GUID:
if (sizeof(GUID) != dwDataSize)
return DPNERR_INVALIDPARAM;
entry->data.guid = *(GUID*)lpvData;
TRACE("(%p, %u): GUID Type -> %s\n", lpvData, dwDataSize, debugstr_guid(lpvData));
break;
case DPNA_DATATYPE_STRING:
heap_free(entry->data.string);
entry->data.string = heap_strdupW((WCHAR*)lpvData);
TRACE("(%p, %u): STRING Type -> %s\n", lpvData, dwDataSize, debugstr_w((WCHAR*)lpvData));
break;
case DPNA_DATATYPE_STRING_ANSI:
heap_free(entry->data.ansi);
entry->data.ansi = heap_strdupA((CHAR*)lpvData);
TRACE("(%p, %u): ANSI STRING Type -> %s\n", lpvData, dwDataSize, (const CHAR*) lpvData);
break;
case DPNA_DATATYPE_BINARY:
heap_free(entry->data.binary);
entry->data.binary = heap_alloc(dwDataSize);
memcpy(entry->data.binary, lpvData, dwDataSize);
TRACE("(%p, %u): BINARY Type\n", lpvData, dwDataSize);
break;
}
return DPN_OK;
}
static HRESULT WINAPI IDirectPlay8AddressImpl_GetDevice(IDirectPlay8Address *iface, GUID *pDevGuid) {
@ -328,6 +439,8 @@ HRESULT DPNET_CreateDirectPlay8Address(IClassFactory *iface, IUnknown *pUnkOuter
client->IDirectPlay8Address_iface.lpVtbl = &DirectPlay8Address_Vtbl;
client->ref = 1;
list_init(&client->components);
ret = IDirectPlay8AddressImpl_QueryInterface(&client->IDirectPlay8Address_iface, riid, ppobj);
IDirectPlay8AddressImpl_Release(&client->IDirectPlay8Address_iface);

View File

@ -25,6 +25,8 @@
# error You must include config.h to use this header
#endif
#include <wine/list.h>
#include "dplay8.h"
#include "dplobby8.h"
/*
@ -60,17 +62,35 @@ struct IDirectPlay8ClientImpl
/* ------------------- */
/* IDirectPlay8Address */
/* ------------------- */
struct component
{
struct list entry;
WCHAR *name;
DWORD type;
union
{
DWORD value; /* DPNA_DATATYPE_DWORD */
GUID guid; /* DPNA_DATATYPE_GUID */
WCHAR *string; /* DPNA_DATATYPE_STRING */
char *ansi; /* DPNA_DATATYPE_STRING_ANSI */
void *binary; /* DPNA_DATATYPE_BINARY */
} data;
};
/*****************************************************************************
* IDirectPlay8Address implementation structure
*/
struct IDirectPlay8AddressImpl
{
IDirectPlay8Address IDirectPlay8Address_iface;
LONG ref;
/* IDirectPlay8Address fields */
GUID SP_guid;
BOOL init;
IDirectPlay8Address IDirectPlay8Address_iface;
LONG ref;
/* IDirectPlay8Address fields */
GUID SP_guid;
BOOL init;
struct list components;
};
/*****************************************************************************

View File

@ -67,6 +67,110 @@ static void create_directplay_address(void)
}
}
static void address_addcomponents(void)
{
static const WCHAR UNKNOWN[] = { 'u','n','k','n','o','w','n',0 };
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
HRESULT hr;
IDirectPlay8Address *localaddr = NULL;
hr = CoCreateInstance( &CLSID_DirectPlay8Address, NULL, CLSCTX_ALL, &IID_IDirectPlay8Address, (LPVOID*)&localaddr);
ok(hr == S_OK, "Failed to create IDirectPlay8Address object\n");
if(SUCCEEDED(hr))
{
GUID compguid;
DWORD size, type;
DWORD components;
DWORD i;
DWORD namelen = 0;
DWORD bufflen = 0;
DWORD port = 8888;
/* We can add any Component to the Address interface not just the predefined ones. */
hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID), DPNA_DATATYPE_GUID);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_AddComponent(localaddr, UNKNOWN, &IID_Random, sizeof(GUID)+1, DPNA_DATATYPE_GUID);
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_HOSTNAME, &localhost, sizeof(localhost), DPNA_DATATYPE_STRING);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD)+2, DPNA_DATATYPE_DWORD);
ok(hr == DPNERR_INVALIDPARAM, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD);
ok(hr == S_OK, "got 0x%08x\n", hr);
size = sizeof(GUID);
hr = IDirectPlay8Address_GetComponentByName(localaddr, UNKNOWN, &compguid, &size, &type);
todo_wine ok(IsEqualGUID(&compguid, &IID_Random), "incorrect guid\n");
ok(size == sizeof(GUID), "incorrect size\n");
todo_wine ok(type == DPNA_DATATYPE_GUID, "incorrect type\n");
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetNumComponents(localaddr, NULL);
ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetNumComponents(localaddr, &components);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, &bufflen, &type);
todo_wine ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, NULL, NULL, &bufflen, &type);
todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr);
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, 100, NULL, &namelen, NULL, NULL, &type);
todo_wine ok(hr == E_POINTER, "got 0x%08x\n", hr);
trace("GetNumComponents=%d\n", components);
for(i=0; i < components; i++)
{
WCHAR *name;
void *buffer;
bufflen = 0;
namelen = 0;
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, NULL, &namelen, NULL, &bufflen, &type);
todo_wine ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr);
name = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, namelen * sizeof(WCHAR));
buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bufflen);
hr = IDirectPlay8Address_GetComponentByIndex(localaddr, i, name, &namelen, buffer, &bufflen, &type);
ok(hr == S_OK, "got 0x%08x\n", hr);
if(hr == S_OK)
{
switch(type)
{
case DPNA_DATATYPE_STRING:
trace("%d: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_w(buffer));
break;
case DPNA_DATATYPE_DWORD:
trace("%d: %s: %d\n", i, wine_dbgstr_w(name), *(DWORD*)buffer);
break;
case DPNA_DATATYPE_GUID:
trace("%d: %s: %s\n", i, wine_dbgstr_w(name), wine_dbgstr_guid( (GUID*)buffer));
break;
case DPNA_DATATYPE_BINARY:
trace("%d: %s: Binary Data %d\n", i, wine_dbgstr_w(name), bufflen);
break;
default:
trace(" Unknown\n");
break;
}
}
HeapFree(GetProcessHeap(), 0, name);
HeapFree(GetProcessHeap(), 0, buffer);
}
IDirectPlay8Address_Release(localaddr);
}
}
START_TEST(address)
{
HRESULT hr;
@ -77,6 +181,7 @@ START_TEST(address)
return;
create_directplay_address();
address_addcomponents();
CoUninitialize();
}