Module: wine Branch: master Commit: c41d275079cfa247e93c7e53e7e3b03a6e2a1152 URL: http://source.winehq.org/git/wine.git/?a=commit;h=c41d275079cfa247e93c7e53e7...
Author: Alistair Leslie-Hughes leslie_alistair@hotmail.com Date: Fri Apr 11 09:52:20 2014 +1000
dpnet: Improve error checking in Get/Set SP.
---
dlls/dpnet/address.c | 26 +++++++++----- dlls/dpnet/dpnet_private.h | 2 +- dlls/dpnet/tests/Makefile.in | 3 +- dlls/dpnet/tests/address.c | 82 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 10 deletions(-)
diff --git a/dlls/dpnet/address.c b/dlls/dpnet/address.c index 78c8350..796e8a4 100644 --- a/dlls/dpnet/address.c +++ b/dlls/dpnet/address.c @@ -166,12 +166,18 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_GetURLA(IDirectPlay8Address *iface
static HRESULT WINAPI IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address *iface, GUID *pguidSP) { - IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface); + IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
- TRACE("(%p, %p)\n", iface, pguidSP); + TRACE("(%p, %p)\n", iface, pguidSP);
- *pguidSP = This->SP_guid; - return DPN_OK; + if(!pguidSP) + return DPNERR_INVALIDPOINTER; + + if(!This->init) + return DPNERR_DOESNOTEXIST; + + *pguidSP = This->SP_guid; + return DPN_OK; }
static HRESULT WINAPI IDirectPlay8AddressImpl_GetUserData(IDirectPlay8Address *iface, @@ -185,12 +191,16 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_GetUserData(IDirectPlay8Address *i static HRESULT WINAPI IDirectPlay8AddressImpl_SetSP(IDirectPlay8Address *iface, const GUID *const pguidSP) { - IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface); + IDirectPlay8AddressImpl *This = impl_from_IDirectPlay8Address(iface);
- TRACE("(%p, %s)\n", iface, debugstr_SP(pguidSP)); + TRACE("(%p, %s)\n", iface, debugstr_SP(pguidSP));
- This->SP_guid = *pguidSP; - return DPN_OK; + if(!pguidSP) + return DPNERR_INVALIDPOINTER; + + This->init = TRUE; + This->SP_guid = *pguidSP; + return DPN_OK; }
static HRESULT WINAPI IDirectPlay8AddressImpl_SetUserData(IDirectPlay8Address *iface, diff --git a/dlls/dpnet/dpnet_private.h b/dlls/dpnet/dpnet_private.h index 4a42eae..00ea94b 100644 --- a/dlls/dpnet/dpnet_private.h +++ b/dlls/dpnet/dpnet_private.h @@ -64,7 +64,7 @@ struct IDirectPlay8AddressImpl LONG ref; /* IDirectPlay8Address fields */ GUID SP_guid; - const WCHAR *url; + BOOL init; };
/***************************************************************************** diff --git a/dlls/dpnet/tests/Makefile.in b/dlls/dpnet/tests/Makefile.in index 890ef3b..69339dc 100644 --- a/dlls/dpnet/tests/Makefile.in +++ b/dlls/dpnet/tests/Makefile.in @@ -1,6 +1,7 @@ TESTDLL = dpnet.dll -IMPORTS = dpnet ole32 dxguid +IMPORTS = dxguid uuid dpnet ole32
C_SRCS = \ + address.c \ peer.c \ server.c diff --git a/dlls/dpnet/tests/address.c b/dlls/dpnet/tests/address.c new file mode 100644 index 0000000..dad5a8e --- /dev/null +++ b/dlls/dpnet/tests/address.c @@ -0,0 +1,82 @@ +/* + * 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> +#include "wine/test.h" + +/* {6733C6E8-A0D6-450E-8C18-CEACF331DC27} */ +static const GUID IID_Random = {0x6733c6e8, 0xa0d6, 0x450e, { 0x8c, 0x18, 0xce, 0xac, 0xf3, 0x31, 0xdc, 0x27 } }; + +static void create_directplay_address(void) +{ + 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"); + if(SUCCEEDED(hr)) + { + GUID guidsp; + + hr = IDirectPlay8Address_GetSP(localaddr, NULL); + ok(hr == DPNERR_INVALIDPOINTER, "GetSP failed 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetSP(localaddr, &guidsp); + ok(hr == DPNERR_DOESNOTEXIST, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_SetSP(localaddr, &GUID_NULL); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetSP(localaddr, &guidsp); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(IsEqualGUID(&guidsp, &GUID_NULL), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp)); + + hr = IDirectPlay8Address_SetSP(localaddr, &IID_Random); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetSP(localaddr, &guidsp); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(IsEqualGUID(&guidsp, &IID_Random), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp)); + + hr = IDirectPlay8Address_SetSP(localaddr, &CLSID_DP8SP_TCPIP); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = IDirectPlay8Address_GetSP(localaddr, &guidsp); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(IsEqualGUID(&guidsp, &CLSID_DP8SP_TCPIP), "wrong guid: %s\n", wine_dbgstr_guid(&guidsp)); + + IDirectPlay8Address_Release(localaddr); + } +} + +START_TEST(address) +{ + HRESULT hr; + + hr = CoInitialize(0); + ok(hr == S_OK, "failed to init com\n"); + if(hr != S_OK) + return; + + create_directplay_address(); + + CoUninitialize(); +}