Clean up ComWrappers tests (#57015)
authorElinor Fung <elfung@microsoft.com>
Mon, 9 Aug 2021 23:53:46 +0000 (16:53 -0700)
committerGitHub <noreply@github.com>
Mon, 9 Aug 2021 23:53:46 +0000 (16:53 -0700)
* Remove unnecessary defines

* Clean up managed ComWrappers tests

src/tests/Interop/COM/ComWrappers/API/ComWrappersTests.csproj
src/tests/Interop/COM/ComWrappers/API/ComWrappersTestsBuiltInComDisabled.csproj
src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstanceTrackerSupportTests_TargetUnix.csproj
src/tests/Interop/COM/ComWrappers/MockReferenceTrackerRuntime/ReferenceTrackerRuntime.cpp
src/tests/Interop/COM/ComWrappers/WeakReference/WeakReferenceNative.cpp
src/tests/Interop/COM/Directory.Build.props
src/tests/Interop/common/ComHelpers.h
src/tests/Interop/common/xplatform.h

index 3e40128..ed35a36 100644 (file)
@@ -2,7 +2,6 @@
   <PropertyGroup>
     <OutputType>Exe</OutputType>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'mono'">true</DisableProjectBuild>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="Program.cs" />
index 4c1733a..a51b1eb 100644 (file)
@@ -2,7 +2,6 @@
   <PropertyGroup>
     <OutputType>Exe</OutputType>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'mono'">true</DisableProjectBuild>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="Program.cs" />
index 5663440..ecdcdf3 100644 (file)
@@ -1,13 +1,9 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <OutputType>Exe</OutputType>
-    <ApplicationManifest>App.manifest</ApplicationManifest>
-    <UseManagedCOMServer>true</UseManagedCOMServer>
-    <IsManagedCOMClient>true</IsManagedCOMClient>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <!-- There is a Windows and a non-Windows version of this test to allow it to be compiled for all targets -->
     <CLRTestTargetUnsupported Condition="'$(TargetsWindows)' == 'true'">true</CLRTestTargetUnsupported>
-    <DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'mono'">true</DisableProjectBuild>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="GlobalInstance.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="../MockReferenceTrackerRuntime/CMakeLists.txt" />
-    <ProjectReference Include="../../NETServer/NETServer.csproj">
-      <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
-      <OutputItemType>Content</OutputItemType>
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
-    </ProjectReference>
-  </ItemGroup>
-  <ItemGroup>
-    <None Include="CoreShim.X.manifest">
-      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-    </None>
   </ItemGroup>
 </Project>
index 1af8b0c..63a013b 100644 (file)
@@ -3,15 +3,16 @@
 
 #include <xplatform.h>
 #include <ComHelpers.h>
-#ifdef _WIN32
+#ifdef WINDOWS
 #include <inspectable.h>
-#else
+#endif //WINDOWS
+
 #include <atomic>
+#include <cassert>
 #include <exception>
-#endif //_WIN32
-#include <unordered_map>
 #include <list>
 #include <mutex>
+#include <unordered_map>
 
 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)
 {
index 5643f26..89a0b99 100644 (file)
@@ -3,10 +3,10 @@
 
 #include <xplatform.h>
 #include <ComHelpers.h>
-#ifdef _WIN32
+#ifdef WINDOWS
 #include <inspectable.h>
 #include <WeakReference.h>
-#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<IWeakReference*>(this));
 #else
             if (ppvObject == nullptr)
@@ -82,7 +82,7 @@ namespace
     struct WeakReferencableObject : public IWeakReferenceSource, public IInspectable, public UnknownImpl
     {
         ComSmartPtr<WeakReference> _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<IWeakReferenceSource*>(this), static_cast<IInspectable*>(this), static_cast<IWeakReferenceSource*>(this));
-#else        
             HRESULT hr;
-
+#ifdef WINDOWS
+            hr = DoQueryInterface(riid, ppvObject, static_cast<IWeakReferenceSource*>(this), static_cast<IInspectable*>(this), static_cast<IWeakReferenceSource*>(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)
             {
index 13b6b9c..06d724b 100644 (file)
@@ -4,6 +4,8 @@
   <PropertyGroup>
     <!-- COM tests are unsupported outside of Windows -->
     <CLRTestTargetUnsupported Condition="'$(TargetsWindows)' != 'true'">true</CLRTestTargetUnsupported>
+    <!-- COM is not supported on Mono -->
+    <DisableProjectBuild Condition="'$(RuntimeFlavor)' == 'mono'">true</DisableProjectBuild>
   </PropertyGroup>
 
 </Project>
index 70c316e..7678c7c 100644 (file)
@@ -2,19 +2,19 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 #pragma once
-#ifdef _WIN32
+#ifdef WINDOWS
 #include <Windows.h>
 #include <comdef.h>
-#include <cassert>
 #include <exception>
 #include <type_traits>
-#endif
+#endif // WINDOWS
 #include <atomic>
+#include <cassert>
 
 // 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<typename I>
@@ -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<typename I1, typename ...IR>
     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<typename T>
 class ClassFactoryBasic : public UnknownImpl, public IClassFactory
@@ -346,7 +346,7 @@ public: // IUnknown
 
     DEFINE_REF_COUNTING();
 };
-#endif
+#endif // WINDOWS
 
 template<typename T>
 struct ComSmartPtr
index 7422b70..cb86b15 100644 (file)
@@ -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_
 #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 <stddef.h>
 
 #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__