From 1dfe32adcb30c18a617bb8870589cae225d522f0 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 9 Aug 2021 16:53:46 -0700 Subject: [PATCH] Clean up ComWrappers tests (#57015) * Remove unnecessary defines * Clean up managed ComWrappers tests --- .../COM/ComWrappers/API/ComWrappersTests.csproj | 1 - .../API/ComWrappersTestsBuiltInComDisabled.csproj | 1 - ...alInstanceTrackerSupportTests_TargetUnix.csproj | 14 --- .../ReferenceTrackerRuntime.cpp | 17 ++-- .../WeakReference/WeakReferenceNative.cpp | 29 +++--- src/tests/Interop/COM/Directory.Build.props | 2 + src/tests/Interop/common/ComHelpers.h | 22 ++--- src/tests/Interop/common/xplatform.h | 105 +++++++-------------- 8 files changed, 69 insertions(+), 122 deletions(-) diff --git a/src/tests/Interop/COM/ComWrappers/API/ComWrappersTests.csproj b/src/tests/Interop/COM/ComWrappers/API/ComWrappersTests.csproj index 3e40128..ed35a36 100644 --- a/src/tests/Interop/COM/ComWrappers/API/ComWrappersTests.csproj +++ b/src/tests/Interop/COM/ComWrappers/API/ComWrappersTests.csproj @@ -2,7 +2,6 @@ Exe true - true diff --git a/src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj b/src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj index 4c1733a..a51b1eb 100644 --- a/src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj +++ b/src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj @@ -2,7 +2,6 @@ Exe true - true diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceTrackerSupportTests_TargetUnix.csproj b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceTrackerSupportTests_TargetUnix.csproj index 5663440..ecdcdf3 100644 --- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceTrackerSupportTests_TargetUnix.csproj +++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceTrackerSupportTests_TargetUnix.csproj @@ -1,13 +1,9 @@ Exe - App.manifest - true - true true true - true @@ -18,15 +14,5 @@ - - false - Content - Always - - - - - PreserveNewest - diff --git a/src/tests/Interop/COM/ComWrappers/MockReferenceTrackerRuntime/ReferenceTrackerRuntime.cpp b/src/tests/Interop/COM/ComWrappers/MockReferenceTrackerRuntime/ReferenceTrackerRuntime.cpp index 1af8b0c..63a013b 100644 --- a/src/tests/Interop/COM/ComWrappers/MockReferenceTrackerRuntime/ReferenceTrackerRuntime.cpp +++ b/src/tests/Interop/COM/ComWrappers/MockReferenceTrackerRuntime/ReferenceTrackerRuntime.cpp @@ -3,15 +3,16 @@ #include #include -#ifdef _WIN32 +#ifdef WINDOWS #include -#else +#endif //WINDOWS + #include +#include #include -#endif //_WIN32 -#include #include #include +#include namespace API { @@ -272,7 +273,7 @@ namespace STDMETHOD(QueryInterface)( /* [in] */ REFIID riid, - /* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR* __RPC_FAR* ppvObject) + /* [iid_is][out] */ void ** ppvObject) { return _implOuter->QueryInterface(riid, ppvObject); } @@ -288,7 +289,7 @@ namespace STDMETHOD(QueryInterface)( /* [in] */ REFIID riid, - /* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR* __RPC_FAR* ppvObject) + /* [iid_is][out] */ void ** ppvObject) { if (ppvObject == nullptr) return E_POINTER; @@ -425,7 +426,7 @@ namespace STDMETHOD(QueryInterface)( /* [in] */ REFIID riid, - /* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR* __RPC_FAR* ppvObject) + /* [iid_is][out] */ void ** ppvObject) { if (ppvObject == nullptr) return E_POINTER; @@ -583,6 +584,7 @@ extern "C" DLL_EXPORT int STDMETHODCALLTYPE UpdateTestObjectAsIUnknown(IUnknown return S_OK; } +#ifdef WINDOWS extern "C" DLL_EXPORT int STDMETHODCALLTYPE UpdateTestObjectAsIDispatch(IDispatch *obj, int i, IDispatch **out) { if (obj == nullptr) @@ -590,6 +592,7 @@ extern "C" DLL_EXPORT int STDMETHODCALLTYPE UpdateTestObjectAsIDispatch(IDispatc return UpdateTestObjectAsIUnknown(obj, i, (IUnknown**)out); } +#endif // WINDOWS extern "C" DLL_EXPORT int STDMETHODCALLTYPE UpdateTestObjectAsInterface(ITest *obj, int i, ITest **out) { diff --git a/src/tests/Interop/COM/ComWrappers/WeakReference/WeakReferenceNative.cpp b/src/tests/Interop/COM/ComWrappers/WeakReference/WeakReferenceNative.cpp index 5643f26..89a0b99 100644 --- a/src/tests/Interop/COM/ComWrappers/WeakReference/WeakReferenceNative.cpp +++ b/src/tests/Interop/COM/ComWrappers/WeakReference/WeakReferenceNative.cpp @@ -3,10 +3,10 @@ #include #include -#ifdef _WIN32 +#ifdef WINDOWS #include #include -#endif //_WIN32 +#endif // WINDOWS namespace { @@ -46,9 +46,9 @@ namespace STDMETHOD(QueryInterface)( /* [in] */ REFIID riid, - /* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR* __RPC_FAR* ppvObject) + /* [iid_is][out] */ void ** ppvObject) { -#ifdef _WIN32 +#ifdef WINDOWS return DoQueryInterface(riid, ppvObject, static_cast(this)); #else if (ppvObject == nullptr) @@ -82,7 +82,7 @@ namespace struct WeakReferencableObject : public IWeakReferenceSource, public IInspectable, public UnknownImpl { ComSmartPtr _weakReference; - STDMETHOD(GetWeakReference)(_COM_Outptr_ IWeakReference** ppWeakReference) + STDMETHOD(GetWeakReference)(IWeakReference** ppWeakReference) { if (!_weakReference) { @@ -114,15 +114,14 @@ namespace STDMETHOD(QueryInterface)( /* [in] */ REFIID riid, - /* [iid_is][out] */ _COM_Outptr_ void __RPC_FAR* __RPC_FAR* ppvObject) + /* [iid_is][out] */ void ** ppvObject) { -#ifdef _WIN32 - HRESULT hr = DoQueryInterface(riid, ppvObject, static_cast(this), static_cast(this), static_cast(this)); -#else HRESULT hr; - +#ifdef WINDOWS + hr = DoQueryInterface(riid, ppvObject, static_cast(this), static_cast(this), static_cast(this)); +#else if (ppvObject == nullptr) - hr = E_POINTER; + return E_POINTER; if (riid == __uuidof(IUnknown) || riid == __uuidof(IWeakReferenceSource)) { @@ -137,12 +136,10 @@ namespace else { *ppvObject = nullptr; - hr = E_NOINTERFACE; + return E_NOINTERFACE; } - - - if (hr == S_OK) - DoAddRef(); + + DoAddRef(); #endif if (SUCCEEDED(hr) && _weakReference) { diff --git a/src/tests/Interop/COM/Directory.Build.props b/src/tests/Interop/COM/Directory.Build.props index 13b6b9c..06d724b 100644 --- a/src/tests/Interop/COM/Directory.Build.props +++ b/src/tests/Interop/COM/Directory.Build.props @@ -4,6 +4,8 @@ true + + true diff --git a/src/tests/Interop/common/ComHelpers.h b/src/tests/Interop/common/ComHelpers.h index 70c316e..7678c7c 100644 --- a/src/tests/Interop/common/ComHelpers.h +++ b/src/tests/Interop/common/ComHelpers.h @@ -2,19 +2,19 @@ // The .NET Foundation licenses this file to you under the MIT license. #pragma once -#ifdef _WIN32 +#ifdef WINDOWS #include #include -#include #include #include -#endif +#endif // WINDOWS #include +#include // Common macro for working in COM #define RETURN_IF_FAILED(exp) { hr = exp; if (FAILED(hr)) { return hr; } } -#ifdef _WIN32 +#ifdef WINDOWS namespace Internal { template @@ -52,7 +52,7 @@ namespace Internal return __QueryInterfaceImpl(riid, ppvObject, remain...); } } - #endif +#endif // WINDOWS // Implementation of IUnknown operations class UnknownImpl @@ -70,7 +70,7 @@ public: template HRESULT DoQueryInterface( /* [in] */ REFIID riid, - /* [iid_is][out] */ _COM_Outptr_ void **ppvObject, + /* [iid_is][out] */ void **ppvObject, /* [in] */ I1 i1, /* [in] */ IR... remain) { @@ -83,15 +83,15 @@ public: } else { - //Internal::__QueryInterfaceImpl available only for _WIN32 due to __uuidof(T) availability -#ifdef _WIN32 +#ifdef WINDOWS + // Internal::__QueryInterfaceImpl available only for Windows due to __uuidof(T) availability HRESULT hr = Internal::__QueryInterfaceImpl(riid, ppvObject, i1, remain...); if (hr != S_OK) return hr; #else *ppvObject = nullptr; return E_NOTIMPL; -#endif +#endif // WINDOWS } DoAddRef(); @@ -128,7 +128,7 @@ private: STDMETHOD_(ULONG, AddRef)(void) { return UnknownImpl::DoAddRef(); } \ STDMETHOD_(ULONG, Release)(void) { return UnknownImpl::DoRelease(); } -#ifdef _WIN32 +#ifdef WINDOWS // Templated class factory template class ClassFactoryBasic : public UnknownImpl, public IClassFactory @@ -346,7 +346,7 @@ public: // IUnknown DEFINE_REF_COUNTING(); }; -#endif +#endif // WINDOWS template struct ComSmartPtr diff --git a/src/tests/Interop/common/xplatform.h b/src/tests/Interop/common/xplatform.h index 7422b70..cb86b15 100644 --- a/src/tests/Interop/common/xplatform.h +++ b/src/tests/Interop/common/xplatform.h @@ -8,16 +8,14 @@ #ifndef WINDOWS -#define __RPC_FAR #define DECLSPEC_UUID(x) #define DECLSPEC_NOVTABLE #define MIDL_INTERFACE(x) struct DECLSPEC_UUID(x) DECLSPEC_NOVTABLE -//Check OBJC_TESTS presence to avoid interface definition on OSX (already defined) -#ifndef OBJC_TESTS -#define interface struct -#endif + #define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method #define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method + +// SAL #undef _In_ #define _In_ #undef _Outptr_ @@ -26,23 +24,15 @@ #define _Out_ #undef _In_opt_ #define _In_opt_ -#undef _COM_Outptr_ -#define _COM_Outptr_ #undef _Inout_ #define _Inout_ -#define __RPC__out -#define __RPC__in -#define __RPC__deref_out -#define __RPC__deref_out_opt -#define __RPC__deref_out_ecount_full_opt(x) -#define __RPC_unique_pointer - -#define E_POINTER _HRESULT_TYPEDEF_(0x80004003L) -#define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L) -#define S_FALSE _HRESULT_TYPEDEF_(0x00000001L) -#define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000EL) -#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L) +// HRESULT values +#define E_POINTER _HRESULT_TYPEDEF_(0x80004003L) +#define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L) +#define S_FALSE _HRESULT_TYPEDEF_(0x00000001L) +#define E_OUTOFMEMORY _HRESULT_TYPEDEF_(0x8007000EL) +#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L) // Declaring a handle dummy struct for HSTRING the same way DECLARE_HANDLE does. typedef struct HSTRING__{ @@ -50,32 +40,23 @@ typedef struct HSTRING__{ } HSTRING__; // Declare the HSTRING handle for C/C++ -typedef __RPC_unique_pointer HSTRING__* HSTRING; +typedef HSTRING__* HSTRING; typedef unsigned __int64 UINT64, *PUINT64; -typedef unsigned short USHORT; -typedef USHORT *PUSHORT; -typedef unsigned char UCHAR; -typedef UCHAR *PUCHAR; #ifndef GUID_DEFINED typedef struct _GUID { - ULONG Data1; // NOTE: diff from Win32, for LP64 - USHORT Data2; - USHORT Data3; - UCHAR Data4[ 8 ]; + ULONG Data1; // NOTE: diff from Win32, for LP64 + unsigned short Data2; + unsigned short Data3; + unsigned char Data4[8]; } GUID; typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED - -#ifdef __cplusplus #define REFGUID const GUID & -#endif - -#ifdef __cplusplus extern "C++" { #if !defined _SYS_GUID_OPERATOR_EQ_ && !defined _NO_SYS_GUID_OPERATOR_EQ_ #define _SYS_GUID_OPERATOR_EQ_ @@ -87,24 +68,13 @@ inline int operator!=(REFGUID guidOne, REFGUID guidOther) { return !IsEqualGUID(guidOne,guidOther); } #endif }; -#endif // __cplusplus - typedef GUID IID; -#ifdef __cplusplus #define REFIID const IID & -#endif - -#define IID_NULL { 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - #define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2) #define __uuidof(type) IID_##type -#ifndef assert -#define assert(e) ((void)0) -#endif // assert - #include #undef INT_MIN @@ -188,8 +158,7 @@ typedef struct tagDEC { #ifndef __IUnknown_INTERFACE_DEFINED__ #define __IUnknown_INTERFACE_DEFINED__ - -//00000000-0000-0000-C000-000000000046 +// 00000000-0000-0000-C000-000000000046 const IID IID_IUnknown = { 0x00000000, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} }; MIDL_INTERFACE("00000000-0000-0000-C000-000000000046") @@ -199,28 +168,22 @@ IUnknown REFIID riid, void **ppvObject) = 0; - virtual ULONG STDMETHODCALLTYPE AddRef( void) = 0; - - virtual ULONG STDMETHODCALLTYPE Release( void) = 0; + virtual ULONG STDMETHODCALLTYPE AddRef(void) = 0; + virtual ULONG STDMETHODCALLTYPE Release(void) = 0; }; #endif // __IUnknown_INTERFACE_DEFINED__ -struct IDispatch : public IUnknown -{ - -}; - typedef /* [v1_enum] */ enum TrustLevel - { - BaseTrust = 0, - PartialTrust = ( BaseTrust + 1 ) , - FullTrust = ( PartialTrust + 1 ) - } TrustLevel; +{ + BaseTrust = 0, + PartialTrust = ( BaseTrust + 1 ) , + FullTrust = ( PartialTrust + 1 ) +} TrustLevel; -//AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90 +// AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90 const IID IID_IInspectable = { 0xaf86e2e0, 0xb12d, 0x4c6a, { 0x9c, 0x5a, 0xd7, 0xaa, 0x65, 0x10, 0x1e, 0x90} }; MIDL_INTERFACE("AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90") @@ -228,18 +191,17 @@ IInspectable : public IUnknown { public: virtual HRESULT STDMETHODCALLTYPE GetIids( - /* [out] */ __RPC__out ULONG * iidCount, - /* [size_is][size_is][out] */ __RPC__deref_out_ecount_full_opt(*iidCount) IID * *iids) = 0; + /* [out] */ ULONG * iidCount, + /* [size_is][size_is][out] */ IID * *iids) = 0; virtual HRESULT STDMETHODCALLTYPE GetRuntimeClassName( - /* [out] */ __RPC__deref_out_opt HSTRING * className) = 0; + /* [out] */ HSTRING * className) = 0; virtual HRESULT STDMETHODCALLTYPE GetTrustLevel( - /* [out] */ __RPC__out TrustLevel * trustLevel) = 0; + /* [out] */ TrustLevel * trustLevel) = 0; }; - -//00000037-0000-0000-C000-000000000046 +// 00000037-0000-0000-C000-000000000046 const IID IID_IWeakReference = { 0x00000037, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} }; MIDL_INTERFACE("00000037-0000-0000-C000-000000000046") @@ -247,12 +209,11 @@ IWeakReference : public IUnknown { public: virtual HRESULT STDMETHODCALLTYPE Resolve( - /* [in] */ __RPC__in REFIID riid, - /* [iid_is][out] */ __RPC__deref_out IInspectable **objectReference) = 0; - + /* [in] */ REFIID riid, + /* [iid_is][out] */ IInspectable **objectReference) = 0; }; -//00000038-0000-0000-C000-000000000046 +// 00000038-0000-0000-C000-000000000046 const IID IID_IWeakReferenceSource = { 0x00000038, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46} }; MIDL_INTERFACE("00000038-0000-0000-C000-000000000046") @@ -260,7 +221,7 @@ IWeakReferenceSource : public IUnknown { public: virtual HRESULT STDMETHODCALLTYPE GetWeakReference( - /* [retval][out] */ __RPC__deref_out_opt IWeakReference * *weakReference) = 0; + /* [retval][out] */ IWeakReference * *weakReference) = 0; }; #define DECIMAL_NEG ((BYTE)0x80) @@ -275,6 +236,6 @@ public: #define DECIMAL_SETZERO(dec) {DECIMAL_LO32(dec) = 0; DECIMAL_MID32(dec) = 0; DECIMAL_HI32(dec) = 0; DECIMAL_SIGNSCALE(dec) = 0;} -#endif //!_Win32 +#endif // !WINDOWS #endif // __XPLAT_H__ -- 2.7.4