From: Alistair Leslie-Hughes Subject: dpnet: Implement IDirectPlay8Address GetComponentByName (try 2) Message-Id: <542B7A07.9050103@hotmail.com> Date: Wed, 01 Oct 2014 13:50:31 +1000 Hi, Fixed where the size was assigned and added test. Changelog: dpnet: Implement IDirectPlay8Address GetComponentByName Best Regards Alistair Leslie-Hughes From d6284322776b7f9b844e8701fbefd0bcdc24aa0f Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Mon, 29 Sep 2014 16:11:46 +1000 Subject: [PATCH] Implement IDirectPlay8Address GetComponentByName To: wine-patches --- dlls/dpnet/address.c | 53 ++++++++++++++++++++++++++++++++++++++++++---- dlls/dpnet/tests/address.c | 23 +++++++++++++++++--- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/dlls/dpnet/address.c b/dlls/dpnet/address.c index 7df7ad6..2062bc4 100644 --- a/dlls/dpnet/address.c +++ b/dlls/dpnet/address.c @@ -316,9 +316,53 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_GetNumComponents(IDirectPlay8Addre static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByName(IDirectPlay8Address *iface, const WCHAR *const pwszName, void *pvBuffer, DWORD *pdwBufferSize, DWORD *pdwDataType) { - IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface); - TRACE("(%p): stub\n", This); - return DPN_OK; + IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface); + struct component *entry; + + TRACE("(%p)->(%p %p %p %p)\n", This, pwszName, pvBuffer, pdwBufferSize, pdwDataType); + + if(!pwszName || !pdwBufferSize || !pdwDataType || (!pvBuffer && pdwBufferSize)) + return E_POINTER; + + LIST_FOR_EACH_ENTRY(entry, &This->components, struct component, entry) + { + if (lstrcmpW(pwszName, entry->name) == 0) + { + TRACE("Found %s\n", debugstr_w(pwszName)); + + if(*pdwBufferSize < entry->size) + { + *pdwBufferSize = entry->size; + return DPNERR_BUFFERTOOSMALL; + } + + *pdwBufferSize = entry->size; + *pdwDataType = entry->type; + + switch (entry->type) + { + case DPNA_DATATYPE_DWORD: + memcpy(pvBuffer, &entry->data.value, sizeof(DWORD)); + break; + case DPNA_DATATYPE_GUID: + memcpy(pvBuffer, &entry->data.guid, sizeof(GUID)); + break; + case DPNA_DATATYPE_STRING: + memcpy(pvBuffer, &entry->data.string, entry->size); + break; + case DPNA_DATATYPE_STRING_ANSI: + memcpy(pvBuffer, &entry->data.ansi, entry->size); + break; + case DPNA_DATATYPE_BINARY: + memcpy(pvBuffer, &entry->data.binary, entry->size); + break; + } + + return S_OK; + } + } + + return DPNERR_DOESNOTEXIST; } static HRESULT WINAPI IDirectPlay8AddressImpl_GetComponentByIndex(IDirectPlay8Address *iface, @@ -364,7 +408,6 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address * list_add_tail(&This->components, &entry->entry); } - entry->size = dwDataSize; switch (dwDataType) { case DPNA_DATATYPE_DWORD: @@ -402,6 +445,8 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_AddComponent(IDirectPlay8Address * break; } + entry->size = dwDataSize; + return DPN_OK; } diff --git a/dlls/dpnet/tests/address.c b/dlls/dpnet/tests/address.c index ad35954..fc43db9 100644 --- a/dlls/dpnet/tests/address.c +++ b/dlls/dpnet/tests/address.c @@ -102,11 +102,28 @@ static void address_addcomponents(void) hr = IDirectPlay8Address_AddComponent(localaddr, DPNA_KEY_PORT, &port, sizeof(DWORD), DPNA_DATATYPE_DWORD); ok(hr == S_OK, "got 0x%08x\n", hr); + hr = IDirectPlay8Address_GetComponentByName(localaddr, NULL, &compguid, &size, &type); + ok(hr == E_POINTER, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetComponentByName(localaddr, UNKNOWN, NULL, &size, &type); + ok(hr == E_POINTER, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetComponentByName(localaddr, UNKNOWN, &compguid, NULL, &type); + ok(hr == E_POINTER, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetComponentByName(localaddr, UNKNOWN, &compguid, &size, NULL); + ok(hr == E_POINTER, "got 0x%08x\n", hr); + + size = sizeof(GUID)-1; + hr = IDirectPlay8Address_GetComponentByName(localaddr, UNKNOWN, &compguid, &size, &type); + ok(hr == DPNERR_BUFFERTOOSMALL, "got 0x%08x\n", hr); + ok(size == sizeof(GUID), "got %d expected %d\n", size, sizeof(GUID)); + 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(IsEqualGUID(&compguid, &IID_Random), "incorrect guid\n"); + ok(size == sizeof(GUID), "incorrect size got %d expected %d\n", size, sizeof(GUID)); + ok(type == DPNA_DATATYPE_GUID, "incorrect type\n"); ok(hr == S_OK, "got 0x%08x\n", hr); hr = IDirectPlay8Address_GetNumComponents(localaddr, NULL); -- 1.9.1