Add Get/SetComObjectData tests (dotnet/corefx#31153)
authorHugh Bellamy <hughbellars@gmail.com>
Wed, 15 Aug 2018 21:04:59 +0000 (23:04 +0200)
committerAaron Robinson <arobins@microsoft.com>
Wed, 15 Aug 2018 21:04:59 +0000 (14:04 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/ca630ef6a80c49d228b8b0cc098e51e0b32a6f27

src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComAwareEventInfoTests.Windows.cs
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/ComEventsHelperTests.cs
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.cs
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.Windows.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.cs
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.Windows.cs [new file with mode: 0644]
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.cs

index e4fcb93..a4321f1 100644 (file)
@@ -56,8 +56,6 @@
     <Compile Include="System\Runtime\InteropServices\Marshal\BindToMonikerTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\ChangeWrapperHandleStrengthTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\CleanupUnusedObjectsInCurrentContextTests.cs" />
-    <Compile Include="System\Runtime\InteropServices\Marshal\Common\CommonTypes.cs" />
-    <Compile Include="System\Runtime\InteropServices\Marshal\Common\CommonTypes.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
     <Compile Include="System\Runtime\InteropServices\Marshal\DestroyStructureTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\FreeBSTRTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\FreeCoTaskMemTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GenerateGuidForTypeTests.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GenerateProgIdForTypeTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GenerateProgIdForTypeTests.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
+    <Compile Include="System\Runtime\InteropServices\Marshal\GetComObjectDataTests.cs" />
+    <Compile Include="System\Runtime\InteropServices\Marshal\GetComObjectDataTests.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
+    <Compile Include="System\Runtime\InteropServices\Marshal\GetDelegateForFunctionPointerTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GetExceptionCodeTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GetExceptionForHRTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GetExceptionPointersTests.cs" />
-    <Compile Include="System\Runtime\InteropServices\Marshal\GetComObjectDataTests.cs" />
-    <Compile Include="System\Runtime\InteropServices\Marshal\GetDelegateForFunctionPointerTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GetFunctionPointerForDelegateTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GetHINSTANCETests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\GetHRForExceptionTests.cs" />
@@ -94,6 +93,7 @@
     <Compile Include="System\Runtime\InteropServices\Marshal\SecureStringToGlobalAllocAnsiTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\SecureStringToGlobalAllocUnicodeTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\SetComObjectDataTests.cs" />
+    <Compile Include="System\Runtime\InteropServices\Marshal\SetComObjectDataTests.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
     <Compile Include="System\Runtime\InteropServices\Marshal\SizeOfTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\StringToBSTRTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\StringToCoTaskMemAnsiTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\ZeroFreeCoTaskMemUTF8Tests.cs" Condition="'$(TargetGroup)' == 'netcoreapp'" />
     <Compile Include="System\Runtime\InteropServices\Marshal\ZeroFreeGlobalAllocAnsiTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\ZeroFreeGlobalAllocUnicodeTests.cs" />
+    <Compile Include="System\Runtime\InteropServices\Marshal\Common\CommonTypes.cs" />
+    <Compile Include="System\Runtime\InteropServices\Marshal\Common\CommonTypes.Windows.cs" Condition="'$(TargetsWindows)' == 'true'" />
     <Compile Include="System\Runtime\InteropServices\Marshal\ReadWrite\ByteTests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\ReadWrite\Int16Tests.cs" />
     <Compile Include="System\Runtime\InteropServices\Marshal\ReadWrite\Int32Tests.cs" />
index 8dd9638..d950da8 100644 (file)
@@ -2,9 +2,9 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-using System;
 using System.Reflection;
 using System.Reflection.Emit;
+using System.Runtime.InteropServices.Tests.Common;
 using Xunit;
 
 namespace System.Runtime.InteropServices.Tests
@@ -13,19 +13,6 @@ namespace System.Runtime.InteropServices.Tests
     [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Not approved COM object for app")]
     public partial class ComAwareEventInfoTests
     {
-        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
-        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "ComEventsHelper.Combine throws a PNSE in .NET Core")]
-        [ActiveIssue(31214)]
-        public void AddEventHandler_DispIdAttribute_ThrowsPlatformNotSupportedException()
-        {
-            var attribute = new ComAwareEventInfo(typeof(DispAttributeInterface), nameof(DispAttributeInterface.Event));
-            var target = new ComObject();
-            Delegate handler = new EventHandler(EventHandler);
-
-            Assert.Throws<PlatformNotSupportedException>(() => attribute.AddEventHandler(target, handler));
-            Assert.Throws<PlatformNotSupportedException>(() => attribute.RemoveEventHandler(target, handler));
-        }
-
         [ComEventInterface(typeof(DispAttributeClass), typeof(int))]
         public interface DispAttributeInterface
         {
@@ -42,7 +29,7 @@ namespace System.Runtime.InteropServices.Tests
         public void AddEventHandler_ComObjectWithoutComEventInterfaceAttribute_ThrowsInvalidOperationException()
         {
             var attribute = new ComAwareEventInfo(typeof(NonComObject), nameof(NonComObject.Event));
-            var target = new ComObject();
+            var target = new ComImportObject();
             Delegate handler = new EventHandler(EventHandler);
 
             Assert.Throws<InvalidOperationException>(() => attribute.AddEventHandler(target, handler));
@@ -67,7 +54,7 @@ namespace System.Runtime.InteropServices.Tests
             eventBuilder.SetAddOnMethod(addMethod);
 
             var attribute = new ComAwareEventInfo(typeBuilder.CreateType(), "Event");
-            var target = new ComObject();
+            var target = new ComImportObject();
             Delegate handler = new EventHandler(EventHandler);
             Assert.Throws<AmbiguousMatchException>(() => attribute.AddEventHandler(target, handler));
             Assert.Throws<AmbiguousMatchException>(() => attribute.RemoveEventHandler(target, handler));
@@ -77,7 +64,7 @@ namespace System.Runtime.InteropServices.Tests
         public void AddEventHandler_NullSourceTypeEventInterface_ThrowsNullReferenceException()
         {
             var attribute = new ComAwareEventInfo(typeof(NullSourceType), nameof(NullSourceType.Event));
-            var target = new ComObject();
+            var target = new ComImportObject();
             Delegate handler = new EventHandler(EventHandler);
 
             Assert.Throws<NullReferenceException>(() => attribute.AddEventHandler(target, handler));
@@ -94,7 +81,7 @@ namespace System.Runtime.InteropServices.Tests
         public void AddEventHandler_NoSuchSourceTypeEventInterface_ThrowsArgumentNullException()
         {
             var attribute = new ComAwareEventInfo(typeof(NoSuchSourceType), nameof(NoSuchSourceType.Event));
-            var target = new ComObject();
+            var target = new ComImportObject();
             Delegate handler = new EventHandler(EventHandler);
 
             AssertExtensions.Throws<ArgumentNullException>("element", () => attribute.AddEventHandler(target, handler));
@@ -111,13 +98,24 @@ namespace System.Runtime.InteropServices.Tests
         public void AddEventHandler_NoDispIdAttribute_ThrowsInvalidOperationException()
         {
             var attribute = new ComAwareEventInfo(typeof(NoDispAttributeInterface), nameof(NoDispAttributeInterface.Event));
-            var target = new ComObject();
+            var target = new ComImportObject();
             Delegate handler = new EventHandler(EventHandler);
 
             Assert.Throws<InvalidOperationException>(() => attribute.AddEventHandler(target, handler));
             Assert.Throws<InvalidOperationException>(() => attribute.RemoveEventHandler(target, handler));
         }
 
+        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
+        public void AddEventHandler_TargetNotIConnectionIConnectionPointContainer_ThrowsInvalidCastException()
+        {
+            var attribute = new ComAwareEventInfo(typeof(DispAttributeInterface), nameof(DispAttributeInterface.Event));
+            var target = new ComImportObject();
+            Delegate handler = new EventHandler(EventHandler);
+
+            Assert.Throws<InvalidCastException>(() => attribute.AddEventHandler(target, handler));
+            attribute.RemoveEventHandler(target, handler);
+        }
+
         [ComEventInterface(typeof(NoDispAttributeClass), typeof(int))]
         public interface NoDispAttributeInterface
         {
@@ -128,10 +126,6 @@ namespace System.Runtime.InteropServices.Tests
         {
             public void Event() { }
         }
-
-        [ComImport]
-        [Guid("7b9e38b0-a97c-11d0-8534-00c04fd8d503")]
-        public class ComObject { }
     }
 #pragma warning restore 0618
 }
index 1487633..9ce363e 100644 (file)
@@ -10,62 +10,62 @@ namespace System.Runtime.InteropServices.Tests
     public class ComEventsHelperTests
     {
         [Fact]
-        [PlatformSpecific(TestPlatforms.Windows)]
-        [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Throws PlatformNotSupportedException in UapAot")]
-        public void Combine_NullRcwWindows_ThrowsArgumentNullException()
-        {
-            AssertExtensions.Throws<ArgumentNullException>(null, () => ComEventsHelper.Combine(null, Guid.Empty, 1, null));
-        }
-
-        [Fact]
         [SkipOnTargetFramework(~TargetFrameworkMonikers.UapAot, "Throws PlatformNotSupportedException in UapAot")]
-        public void Combine_NullRcwUapAot_PlatformNotSupportedException()
+        public void Combine_UapAot_PlatformNotSupportedException()
         {
             Assert.Throws<PlatformNotSupportedException>(() => ComEventsHelper.Combine(null, Guid.Empty, 1, null));
         }
         
         [Fact]
         [PlatformSpecific(TestPlatforms.AnyUnix)]
-        public void Combine_NullRcwUnix_ThrowsArgumentNullException()
+        public void Combine_Unix_ThrowsPlatformNotSupportedException()
         {
             Assert.Throws<PlatformNotSupportedException>(() => ComEventsHelper.Combine(null, Guid.Empty, 1, null));
         }
 
         [Fact]
-        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "ComEventsHelper.Combine is not supported in .NET Core.")]
-        [ActiveIssue(31214)]
-        public void Combine_NonNullRcw_ThrowsPlatformNotSupportedException()
+        [PlatformSpecific(TestPlatforms.Windows)]
+        [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Throws PlatformNotSupportedException in UapAot")]
+        public void Combine_NullRcw_ThrowsArgumentNullException()
         {
-            Assert.Throws<PlatformNotSupportedException>(() => ComEventsHelper.Combine(1, Guid.Empty, 1, null));
+            AssertExtensions.Throws<ArgumentNullException>(null, () => ComEventsHelper.Combine(null, Guid.Empty, 1, null));
         }
 
         [Fact]
         [PlatformSpecific(TestPlatforms.Windows)]
         [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Throws PlatformNotSupportedException in UapAot")]
-        public void Remove_NullRcwWindows_ThrowsArgumentNullException()
+        public void Combine_NotComObject_ThrowsArgumentException()
         {
-            AssertExtensions.Throws<ArgumentNullException>(null, () => ComEventsHelper.Remove(null, Guid.Empty, 1, null));
+            AssertExtensions.Throws<ArgumentException>("obj", () => ComEventsHelper.Combine(1, Guid.Empty, 1, null));
         }
 
         [SkipOnTargetFramework(~TargetFrameworkMonikers.UapAot, "Throws PlatformNotSupportedException in UapAot")]
-        public void Remove_NullRcwUapAot_ThrowsPlatformNotSupportedException()
+        public void Remove_UapAot_ThrowsPlatformNotSupportedException()
         {
             Assert.Throws<PlatformNotSupportedException>(() => ComEventsHelper.Remove(null, Guid.Empty, 1, null));
         }
 
         [Fact]
         [PlatformSpecific(TestPlatforms.AnyUnix)]
-        public void Remove_NullRcwUnix_ThrowPlatformNotSupportedException()
+        public void Remove_Unix_ThrowPlatformNotSupportedException()
         {
             Assert.Throws<PlatformNotSupportedException>(() => ComEventsHelper.Remove(null, Guid.Empty, 1, null));   
         }
 
         [Fact]
+        [PlatformSpecific(TestPlatforms.Windows)]
+        [SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "Throws PlatformNotSupportedException in UapAot")]
+        public void Remove_NullRcw_ThrowsArgumentNullException()
+        {
+            AssertExtensions.Throws<ArgumentNullException>(null, () => ComEventsHelper.Remove(null, Guid.Empty, 1, null));
+        }
+
+        [Fact]
+        [PlatformSpecific(TestPlatforms.Windows)]
         [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "ComEventsHelper.Combine is not supported in .NET Core.")]
-        [ActiveIssue(31214)]
-        public void Remove_NonNullRcw_ThrowsPlatformNotSupportedException()
+        public void Remove_NotComObject_ThrowsArgumentException()
         {
-            Assert.Throws<PlatformNotSupportedException>(() => ComEventsHelper.Remove(1, Guid.Empty, 1, null));
+            AssertExtensions.Throws<ArgumentException>("obj", () => ComEventsHelper.Remove(1, Guid.Empty, 1, null));
         }
     }
 #pragma warning restore 0618
index 365416e..de608be 100644 (file)
@@ -2,12 +2,34 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#pragma warning disable CS0618 // Type or member is obsolete
+
 namespace System.Runtime.InteropServices.Tests.Common
 {
     [ComImport]
     [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
     public interface IComImportObject { }
 
+    [ComImport]
+    [Guid("BF46F910-6B9B-4FBF-BC81-87CDACD2BD83")]
+    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
+    public interface DualInterface { }
+
+    [ComImport]
+    [Guid("8DCD4DCE-778A-4261-A812-F4595C2F2614")]
+    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+    public interface IUnknownInterface { }
+
+    [ComImport]
+    [Guid("9323D453-BA36-4459-92AA-ECEC2F916FED")]
+    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
+    public interface IDispatchInterface { }
+
+    [ComImport]
+    [Guid("E7AA81A5-36A2-4CEC-A629-13B6A26865D1")]
+    [InterfaceType(ComInterfaceType.InterfaceIsIInspectable)]
+    public interface IInspectableInterface { }
+
     public class InterfaceComImportObject : IComImportObject { }
 
     [ComImport]
@@ -18,5 +40,59 @@ namespace System.Runtime.InteropServices.Tests.Common
     [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
     public class ComImportObject { }
 
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.None)]
+    public class DualComObject : DualInterface { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.None)]
+    public class IUnknownComObject : IUnknownInterface { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.None)]
+    public class IDispatchComObject : IDispatchInterface { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.None)]
+    public class IInspectableComObject : IInspectableInterface { }
+
     public class SubComImportObject : ComImportObject { }
+
+    public class GenericSubComImportObject<T> : ComImportObject { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.None)]
+    public class NonDualComObject : IComImportObject { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.None)]
+    public class NonDualComObjectEmpty { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.AutoDispatch)]
+    public class AutoDispatchComObject : IComImportObject { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.AutoDispatch)]
+    public class AutoDispatchComObjectEmpty { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.AutoDual)]
+    public class AutoDualComObject : IComImportObject { }
+
+    [ComImport]
+    [Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
+    [ClassInterface(ClassInterfaceType.AutoDual)]
+    public class AutoDualComObjectEmpty { }
 }
+
+#pragma warning restore CS0618 // Type or member is obsolete
index 7472612..4b3f9d4 100644 (file)
@@ -24,4 +24,13 @@ namespace System.Runtime.InteropServices.Tests.Common
 
     [ComVisible(true)]
     public interface NonGenericInterface { }
+
+    [ComVisible(false)]
+    public interface NonComVisibleInterface { }
+
+    [ComVisible(false)]
+    public class NonComVisibleClass { }
+
+    [ComVisible(false)]
+    public struct NonComVisibleStruct { }
 }
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetComObjectDataTests.Windows.cs
new file mode 100644 (file)
index 0000000..c95fc56
--- /dev/null
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices.Tests.Common;
+using Xunit;
+
+namespace System.Runtime.InteropServices.Tests
+{
+    public partial class GetComObjectDataTests
+    {
+        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
+        [PlatformSpecific(TestPlatforms.Windows)]
+        public void GetComObjectData_ValidObject_ReturnsExpected()
+        {
+            var comObject = new ComImportObject();
+
+            Assert.Null(Marshal.GetComObjectData(comObject, "key"));
+
+            Marshal.SetComObjectData(comObject, "key", 1);
+            Assert.Equal(1, Marshal.GetComObjectData(comObject, "key"));
+            Assert.Null(Marshal.GetComObjectData(comObject, "noSuchKey"));
+        }
+    }
+}
index 64076a6..d59acc7 100644 (file)
@@ -6,46 +6,32 @@ using Xunit;
 
 namespace System.Runtime.InteropServices.Tests
 {
-    public class GetComObjectDataTests
+    public partial class GetComObjectDataTests
     {
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.GetComObjectData is not implemented in .NET Core.")]
-        public void GetComObjectData_NetFramework_ReturnsExpected()
-        {
-            Type type = Type.GetTypeFromCLSID(new Guid("927971f5-0939-11d1-8be1-00c04fd8d503"));
-            object comObject = Activator.CreateInstance(type);
-
-            Assert.Null(Marshal.GetComObjectData(comObject, "key"));
 
-            Marshal.SetComObjectData(comObject, "key", 1);
-            Assert.Equal(1, Marshal.GetComObjectData(comObject, "key"));
-            Assert.Null(Marshal.GetComObjectData(comObject, "noSuchKey"));
-        }
-
-        [Fact]
-        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Marshal.GetComObjectData is not implemented in .NET Core.")]
-        [ActiveIssue(31214)]
-        public void GetComObjectData_NetCore_ThrowsPlatformNotSupportedException()
+        [PlatformSpecific(TestPlatforms.AnyUnix)]
+        public void GetComObjectData_Unix_ThrowsPlatformNotSupportedException()
         {
             Assert.Throws<PlatformNotSupportedException>(() => Marshal.GetComObjectData(null, null));
         }
 
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.GetComObjectData is not implemented in .NET Core.")]
+        [PlatformSpecific(TestPlatforms.Windows)]
         public void GetComObjectData_NullObj_ThrowsArgumentNullException()
         {
             AssertExtensions.Throws<ArgumentNullException>("obj", () => Marshal.GetComObjectData(null, new object()));
         }
 
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.GetComObjectData is not implemented in .NET Core.")]
+        [PlatformSpecific(TestPlatforms.Windows)]
         public void GetComObjectData_NullKey_ThrowsArgumentNullException()
         {
             AssertExtensions.Throws<ArgumentNullException>("key", () => Marshal.GetComObjectData(new object(), null));
         }
 
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.GetComObjectData is not implemented in .NET Core.")]
+        [PlatformSpecific(TestPlatforms.Windows)]
         public void GetComObjectData_NonComObjectObj_ThrowsArgumentNullException()
         {
             AssertExtensions.Throws<ArgumentException>("obj", () => Marshal.GetComObjectData(1, 2));
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/SetComObjectDataTests.Windows.cs
new file mode 100644 (file)
index 0000000..e400161
--- /dev/null
@@ -0,0 +1,47 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Runtime.InteropServices.Tests.Common;
+using Xunit;
+
+namespace System.Runtime.InteropServices.Tests
+{
+    public partial class SetComObjectDataTests
+    {
+        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
+        [PlatformSpecific(TestPlatforms.Windows)]
+        public void SetComObjectData_NonNullValue_Sucesss()
+        {
+            var comObject = new ComImportObject();
+
+            Assert.True(Marshal.SetComObjectData(comObject, "key", 1));
+            Assert.Equal(1, Marshal.GetComObjectData(comObject, "key"));
+
+            Assert.False(Marshal.SetComObjectData(comObject, "key", 2));
+            Assert.Equal(1, Marshal.GetComObjectData(comObject, "key"));
+
+            Assert.True(Marshal.SetComObjectData(comObject, "otherKey", 2));
+            Assert.Equal(2, Marshal.GetComObjectData(comObject, "otherKey"));
+        }
+
+        [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
+        [PlatformSpecific(TestPlatforms.Windows)]
+        public void SetComObjectData_NullValue_Sucesss()
+        {
+            var comObject = new ComImportObject();
+
+            Assert.True(Marshal.SetComObjectData(comObject, "key", null));
+            Assert.Null(Marshal.GetComObjectData(comObject, "key"));
+
+            Assert.True(Marshal.SetComObjectData(comObject, "key", null));
+            Assert.Null(Marshal.GetComObjectData(comObject, "key"));
+
+            Assert.True(Marshal.SetComObjectData(comObject, "key", 1));
+            Assert.Equal(1, Marshal.GetComObjectData(comObject, "key"));
+
+            Assert.True(Marshal.SetComObjectData(comObject, "otherKey", null));
+            Assert.Null(Marshal.GetComObjectData(comObject, "otherKey"));
+        }
+    }
+}
index f068c26..2076c2c 100644 (file)
@@ -6,49 +6,31 @@ using Xunit;
 
 namespace System.Runtime.InteropServices.Tests
 {
-    public class SetComObjectDataTests
+    public partial class SetComObjectDataTests
     {
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.SetComObjectData is not implemented in .NET Core.")]
-        public void SetComObjectData_NetFramework_ReturnsExpected()
-        {
-            Type type = Type.GetTypeFromCLSID(new Guid("927971f5-0939-11d1-8be1-00c04fd8d503"));
-            object comObject = Activator.CreateInstance(type);
-
-            Assert.True(Marshal.SetComObjectData(comObject, "key", 1));
-            Assert.Equal(1, Marshal.GetComObjectData(comObject, "key"));
-
-            Assert.False(Marshal.SetComObjectData(comObject, "key", 2));
-            Assert.Equal(1, Marshal.GetComObjectData(comObject, "key"));
-
-            Assert.True(Marshal.SetComObjectData(comObject, "otherKey", 2));
-            Assert.Equal(2, Marshal.GetComObjectData(comObject, "otherKey"));
-        }
-
-        [Fact]
-        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Marshal.SetComObjectData is not implemented in .NET Core.")]
-        [ActiveIssue(31214)]
-        public void SetComObjectData_NetCore_ThrowsPlatformNotSupportedException()
+        [PlatformSpecific(TestPlatforms.AnyUnix)]
+        public void SetComObjectData_Unix_ThrowsPlatformNotSupportedException()
         {
             Assert.Throws<PlatformNotSupportedException>(() => Marshal.SetComObjectData(null, null, null));
         }
 
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.SetComObjectData is not implemented in .NET Core.")]
+        [PlatformSpecific(TestPlatforms.Windows)]
         public void SetComObjectData_NullObj_ThrowsArgumentNullException()
         {
             AssertExtensions.Throws<ArgumentNullException>("obj", () => Marshal.SetComObjectData(null, new object(), 3));
         }
 
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.SetComObjectData is not implemented in .NET Core.")]
+        [PlatformSpecific(TestPlatforms.Windows)]
         public void SetComObjectData_NullKey_ThrowsArgumentNullException()
         {
             AssertExtensions.Throws<ArgumentNullException>("key", () => Marshal.SetComObjectData(new object(), null, 3));
         }
 
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.SetComObjectData is not implemented in .NET Core.")]
+        [PlatformSpecific(TestPlatforms.Windows)]
         public void SetComObjectData_NonComObjectObj_ThrowsArgumentNullException()
         {
             AssertExtensions.Throws<ArgumentException>("obj", () => Marshal.SetComObjectData(1, 2, 3));