From e5760c0ace6dea3972ed15ad21352f0c8c5f3874 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 5 Dec 2018 19:44:57 +0100 Subject: [PATCH] Remove test for disabled collectible COM interop There were some old tests that I have missed that were testing that COM interop cannot be used for collectible objects. This is now supported, so I am removing the tests as obsolete. --- .../ChangeWrapperHandleStrengthTests.cs | 15 ----------- .../Marshal/GetComInterfaceForObjectTests.cs | 17 ------------- .../Marshal/GetIDispatchForObjectTests.cs | 16 ------------ .../Marshal/GetIUnknownForObjectTests.cs | 15 ----------- .../Marshal/GetNativeVariantForObjectTests.cs | 25 ------------------- 5 files changed, 88 deletions(-) diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.cs index d129aa524949..b691ea2a1055 100644 --- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.cs +++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.cs @@ -51,21 +51,6 @@ public void ChangeWrapperHandleStrength_NullObject_ThrowsArgumentNullException() AssertExtensions.Throws("otp", () => Marshal.ChangeWrapperHandleStrength(null, fIsWeak: false)); } -#if !netstandard // TODO: Enable for netstandard2.1 - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetNative))] - [PlatformSpecific(TestPlatforms.Windows)] - public void ChangeWrapperHandleStrength_ObjectNotCollectible_ThrowsNotSupportedException() - { - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - Type type = typeBuilder.CreateType(); - - object o = Activator.CreateInstance(type); - Assert.Throws(() => Marshal.ChangeWrapperHandleStrength(o, fIsWeak: true)); - } -#endif - [Fact] [PlatformSpecific(TestPlatforms.AnyUnix)] public void ChangeWrapperHandleStrength_Unix_ThrowsPlatformNotSupportedException() diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetComInterfaceForObjectTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetComInterfaceForObjectTests.cs index 3a9a0d8b5eb1..2d999315bf23 100644 --- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetComInterfaceForObjectTests.cs +++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetComInterfaceForObjectTests.cs @@ -206,23 +206,6 @@ public void GetComInterfaceForObject_InvalidObject_ThrowsArgumentException(objec AssertExtensions.Throws("o", () => Marshal.GetComInterfaceForObject(o)); } -#if !netstandard // TODO: Enable for netstandard2.1 - [Fact] - [PlatformSpecific(TestPlatforms.Windows)] - public void GetComInterfaceForObject_ObjectNotCollectible_ThrowsNotSupportedException() - { - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - Type type = typeBuilder.CreateType(); - - object o = Activator.CreateInstance(type); - Assert.Throws(() => Marshal.GetComInterfaceForObject(o, typeof(NonGenericInterface))); - Assert.Throws(() => Marshal.GetComInterfaceForObject(o, typeof(NonGenericInterface), CustomQueryInterfaceMode.Allow)); - Assert.Throws(() => Marshal.GetComInterfaceForObject(o)); - } -#endif - [Fact] [PlatformSpecific(TestPlatforms.Windows)] public void GetTypedObjectForIUnknown_UncastableType_ThrowsInvalidCastException() diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.cs index 45d974d7df5a..cc0b04e8eb4b 100644 --- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.cs +++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.cs @@ -54,22 +54,6 @@ public void GetIDispatchForObject_NullObject_ThrowsArgumentNullException() AssertExtensions.Throws("o", () => Marshal.GetIDispatchForObject(null)); } -#if !netstandard // TODO: Enable for netstandard2.1 - [ConditionalFact] - [PlatformSpecific(TestPlatforms.Windows)] - [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.GetIDispatchForObject is not implemented in .NET Core.")] - public void GetIDispatchForObject_ObjectNotCollectible_ThrowsNotSupportedException() - { - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - Type type = typeBuilder.CreateType(); - - object o = Activator.CreateInstance(type); - Assert.Throws(() => Marshal.GetIDispatchForObject(o)); - } -#endif - [Theory] [MemberData(nameof(GetIDispatchForObject_Invalid_TestData))] [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "Marshal.GetIDispatchForObject is not implemented in .NET Core.")] diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetIUnknownForObjectTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetIUnknownForObjectTests.cs index 6ebb94669cd3..be962e50ae09 100644 --- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetIUnknownForObjectTests.cs +++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetIUnknownForObjectTests.cs @@ -23,20 +23,5 @@ public void GetIUnknownForObject_NullObject_ThrowsArgumentNullException() { AssertExtensions.Throws("o", () => Marshal.GetIUnknownForObject(null)); } - -#if !netstandard // TODO: Enable for netstandard2.1 - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetNative))] - [PlatformSpecific(TestPlatforms.Windows)] - public void GetIUnknownForObject_ObjectNotCollectible_ThrowsNotSupportedException() - { - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - Type type = typeBuilder.CreateType(); - - object o = Activator.CreateInstance(type); - Assert.Throws(() => Marshal.GetIUnknownForObject(o)); - } -#endif } } diff --git a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.cs b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.cs index cf65155b5041..330397f6d092 100644 --- a/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.cs +++ b/src/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.cs @@ -449,31 +449,6 @@ public static void GetNativeVariantForObject_CantCastToObject_ThrowsInvalidCastE } } -#if !netstandard // TODO: Enable for netstandard2.1 - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNetNative))] - [PlatformSpecific(TestPlatforms.Windows)] - public void GetNativeVariantForObject_ObjectNotCollectible_ThrowsNotSupportedException() - { - AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.RunAndCollect); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("Module"); - TypeBuilder typeBuilder = moduleBuilder.DefineType("Type"); - Type type = typeBuilder.CreateType(); - - object o = Activator.CreateInstance(type); - - var v = new Variant(); - IntPtr pNative = Marshal.AllocHGlobal(Marshal.SizeOf(v)); - try - { - Assert.Throws(() => Marshal.GetNativeVariantForObject(o, pNative)); - } - finally - { - Marshal.FreeHGlobal(pNative); - } - } -#endif - public struct StructWithValue { public int Value;