dpnet: Improve Error checking in Get/Set SP (try 2)
Alistair Leslie-Hughes
leslie_alistair at hotmail.com
Wed Jan 15 04:13:00 CST 2014
Hi,
Correct formatting, thanks Stedan,
Rename function to debugstr_guid, thanks Michael
Added test for guid.
Changelog:
dpnet: Improve Error checking in Get/Set SP
Best Regards
Alistair Leslie-Hughes
-------------- next part --------------
>From c377e7b596bdf724ce888a4e0a4446e85ae4bcd5 Mon Sep 17 00:00:00 2001
From: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date: Wed, 15 Jan 2014 14:11:46 +1100
Subject: [PATCH] Improve Error checking in Get/Set SP
To: wine-patches <wine-patches at winehq.org>
---
dlls/dpnet/address.c | 12 +++++++
dlls/dpnet/tests/Makefile.in | 3 +-
dlls/dpnet/tests/address.c | 85 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 99 insertions(+), 1 deletion(-)
create mode 100644 dlls/dpnet/tests/address.c
diff --git a/dlls/dpnet/address.c b/dlls/dpnet/address.c
index 78c8350..fa8d63e 100644
--- a/dlls/dpnet/address.c
+++ b/dlls/dpnet/address.c
@@ -36,6 +36,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(dpnet);
+DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
+
static inline IDirectPlay8AddressImpl *impl_from_IDirectPlay8Address(IDirectPlay8Address *iface)
{
return CONTAINING_RECORD(iface, IDirectPlay8AddressImpl, IDirectPlay8Address_iface);
@@ -170,6 +172,12 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_GetSP(IDirectPlay8Address *iface,
TRACE("(%p, %p)\n", iface, pguidSP);
+ if(!pguidSP)
+ return DPNERR_INVALIDPOINTER;
+
+ if(IsEqualGUID(&This->SP_guid, &GUID_NULL))
+ return DPNERR_DOESNOTEXIST;
+
*pguidSP = This->SP_guid;
return DPN_OK;
}
@@ -189,6 +197,9 @@ static HRESULT WINAPI IDirectPlay8AddressImpl_SetSP(IDirectPlay8Address *iface,
TRACE("(%p, %s)\n", iface, debugstr_SP(pguidSP));
+ if(!pguidSP)
+ return DPNERR_INVALIDPOINTER;
+
This->SP_guid = *pguidSP;
return DPN_OK;
}
@@ -313,6 +324,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 f7ebf3a..40bfca6 100644
--- a/dlls/dpnet/tests/Makefile.in
+++ b/dlls/dpnet/tests/Makefile.in
@@ -1,5 +1,6 @@
TESTDLL = dpnet.dll
-IMPORTS = dpnet ole32
+IMPORTS = ole32
C_SRCS = \
+ address.c \
peer.c
diff --git a/dlls/dpnet/tests/address.c b/dlls/dpnet/tests/address.c
new file mode 100644
index 0000000..0f5b410
--- /dev/null
+++ b/dlls/dpnet/tests/address.c
@@ -0,0 +1,85 @@
+/*
+ * 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"
+
+static const char *debugstr_guid(REFIID riid)
+{
+ static char buf[50];
+
+ if(!riid)
+ return "(null)";
+
+ sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
+ riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
+ riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
+ riid->Data4[5], riid->Data4[6], riid->Data4[7]);
+
+ return buf;
+}
+
+
+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 = IID_IClassFactory;
+
+ 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);
+ ok(IsEqualGUID(&guidsp, &IID_IClassFactory), "wrong guid: %s\n", debugstr_guid(&guidsp));
+
+ hr = IDirectPlay8Address_SetSP(localaddr, NULL);
+ ok(hr == DPNERR_INVALIDPOINTER, "got 0x%08x\n", hr);
+
+ 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", debugstr_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