dpnet: Improve Error checking in Get/Set SP (try 3 Resend )
Alistair Leslie-Hughes
leslie_alistair at hotmail.com
Tue Apr 8 05:12:28 CDT 2014
Hi,
Any feedback would be good.
Changelog:
dpnet: Improve Error checking in Get/Set SP
Best Regards
Alistair Leslie-Hughes
-------------- next part --------------
>From 17e5c3329acecb13d047ef3537bfbec5a37d4366 Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date: Fri, 17 Jan 2014 09:38:13 +1100
Subject: [PATCH] Improve Error checking in Get/Set SP
To: wine-patches <wine-patches at winehq.org>
---
dlls/dpnet/address.c | 26 ++++++++++-----
dlls/dpnet/tests/Makefile.in | 1 +
dlls/dpnet/tests/address.c | 78 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+), 8 deletions(-)
create mode 100644 dlls/dpnet/tests/address.c
diff --git a/dlls/dpnet/address.c b/dlls/dpnet/address.c
index 78c8350..f87aa3f 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(IsEqualGUID(&This->SP_guid, &GUID_NULL))
+ return DPNERR_DOESNOTEXIST;
+
+ *pguidSP = This->SP_guid;
+ return DPN_OK;
}
static HRESULT WINAPI IDirectPlay8AddressImpl_GetUserData(IDirectPlay8Address *iface,
@@ -185,12 +191,15 @@ 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->SP_guid = *pguidSP;
+ return DPN_OK;
}
static HRESULT WINAPI IDirectPlay8AddressImpl_SetUserData(IDirectPlay8Address *iface,
@@ -313,6 +322,7 @@ HRESULT DPNET_CreateDirectPlay8Address(LPCLASSFACTORY iface, LPUNKNOWN punkOuter
return E_OUTOFMEMORY;
}
client->IDirectPlay8Address_iface.lpVtbl = &DirectPlay8Address_Vtbl;
+ client->SP_guid = GUID_NULL;
client->ref = 0; /* will be inited with QueryInterface */
return IDirectPlay8AddressImpl_QueryInterface (&client->IDirectPlay8Address_iface, riid, ppobj);
}
diff --git a/dlls/dpnet/tests/Makefile.in b/dlls/dpnet/tests/Makefile.in
index 9220121..f97f01d 100644
--- a/dlls/dpnet/tests/Makefile.in
+++ b/dlls/dpnet/tests/Makefile.in
@@ -2,5 +2,6 @@ TESTDLL = dpnet.dll
IMPORTS = 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..9229e13
--- /dev/null
+++ b/dlls/dpnet/tests/address.c
@@ -0,0 +1,78 @@
+/*
+ * 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, NULL);
+ ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
+
+ 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();
+}
--
1.8.3.2
More information about the wine-patches
mailing list