Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeAOT tests interopservices #73200

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly()

public static bool IsInContainer => GetIsInContainer();
public static bool SupportsComInterop => IsWindows && IsNotMonoRuntime && !IsNativeAot; // matches definitions in clr.featuredefines.props

#if NETCOREAPP
public static bool IsBuiltInComEnabled => SupportsComInterop
&& (AppContext.TryGetSwitch("System.Runtime.InteropServices.BuiltInComInterop.IsSupported", out bool isEnabled)
? isEnabled
: true);
#else
public static bool IsBuiltInComEnabled => SupportsComInterop;
#endif

public static bool SupportsSsl3 => GetSsl3Support();
public static bool SupportsSsl2 => IsWindows && !PlatformDetection.IsWindows10Version1607OrGreater;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<Compile Include="System\Runtime\InteropServices\RegistrationClassContext.cs" />
<Compile Include="System\Runtime\InteropServices\RegistrationConnectionType.cs" />
<Compile Include="System\Runtime\InteropServices\RuntimeEnvironment.cs" />
<Compile Include="System\Runtime\InteropServices\SetWin32ContextInIDispatchAttribute.cs" />
<Compile Include="System\Runtime\InteropServices\TypeLibFuncAttribute.cs" />
<Compile Include="System\Runtime\InteropServices\TypeLibFuncFlags.cs" />
<Compile Include="System\Runtime\InteropServices\TypeLibImportClassAttribute.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
<Compile Include="System\Runtime\InteropServices\ProgIdAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\RuntimeEnvironmentTests.cs" />
<Compile Include="System\Runtime\InteropServices\SafeBufferTests.cs" />
<Compile Include="System\Runtime\InteropServices\SetWin32ContextInIDispatchAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\StructLayoutAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\TypeIdentifierAttributeTests.cs" />
<Compile Include="System\Runtime\InteropServices\UnknownWrapperTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class DispAttributeClass
public void Event() { }
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
jkotas marked this conversation as resolved.
Show resolved Hide resolved
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void AddEventHandler_ComObjectWithoutComEventInterfaceAttribute_ThrowsInvalidOperationException()
{
var attribute = new ComAwareEventInfo(typeof(NonComObject), nameof(NonComObject.Event));
Expand All @@ -33,7 +33,7 @@ public void AddEventHandler_ComObjectWithoutComEventInterfaceAttribute_ThrowsInv
Assert.Throws<InvalidOperationException>(() => attribute.RemoveEventHandler(target, handler));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void AddEventHandler_ComObjectWithMultipleComEventInterfaceAttribute_ThrowsAmbiguousMatchException()
{
// C# doesn't let us apply multiple ComEventInterface values, so RefEmit is necessary.
Expand All @@ -57,7 +57,7 @@ public void AddEventHandler_ComObjectWithMultipleComEventInterfaceAttribute_Thro
Assert.Throws<AmbiguousMatchException>(() => attribute.RemoveEventHandler(target, handler));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void AddEventHandler_NullSourceTypeEventInterface_ThrowsNullReferenceException()
{
var attribute = new ComAwareEventInfo(typeof(NullSourceType), nameof(NullSourceType.Event));
Expand All @@ -74,7 +74,7 @@ public interface NullSourceType
event EventHandler Event;
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void AddEventHandler_NoSuchSourceTypeEventInterface_ThrowsArgumentNullException()
{
var attribute = new ComAwareEventInfo(typeof(NoSuchSourceType), nameof(NoSuchSourceType.Event));
Expand All @@ -91,7 +91,7 @@ public interface NoSuchSourceType
event EventHandler Event;
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void AddEventHandler_NoDispIdAttribute_ThrowsInvalidOperationException()
{
var attribute = new ComAwareEventInfo(typeof(NoDispAttributeInterface), nameof(NoDispAttributeInterface.Event));
Expand All @@ -102,7 +102,7 @@ public void AddEventHandler_NoDispIdAttribute_ThrowsInvalidOperationException()
Assert.Throws<InvalidOperationException>(() => attribute.RemoveEventHandler(target, handler));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void AddEventHandler_TargetNotIConnectionIConnectionPointContainer_ThrowsInvalidCastException()
{
var attribute = new ComAwareEventInfo(typeof(DispAttributeInterface), nameof(DispAttributeInterface.Event));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ public void Combine_Unix_ThrowsPlatformNotSupportedException()
Assert.Throws<PlatformNotSupportedException>(() => ComEventsHelper.Combine(null, Guid.Empty, 1, null));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void Combine_NullRcw_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => ComEventsHelper.Combine(null, Guid.Empty, 1, null));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void Combine_NotComObject_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("obj", () => ComEventsHelper.Combine(1, Guid.Empty, 1, null));
Expand All @@ -35,15 +33,13 @@ public void Remove_Unix_ThrowPlatformNotSupportedException()
Assert.Throws<PlatformNotSupportedException>(() => ComEventsHelper.Remove(null, Guid.Empty, 1, null));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void Remove_NullRcw_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => ComEventsHelper.Remove(null, Guid.Empty, 1, null));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void Remove_NotComObject_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("obj", () => ComEventsHelper.Remove(1, Guid.Empty, 1, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace System.Runtime.InteropServices.Tests
[ComVisible(true)]
public class ComVisibleAttributeTests
{
[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
public void Exists()
{
Type type = typeof(ComVisibleAttributeTests);
ComVisibleAttribute attribute = Assert.IsType<ComVisibleAttribute>(Assert.Single(type.GetCustomAttributes(typeof(ComVisibleAttribute), inherit: false)));
Assert.True(attribute.Value);
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
[InlineData(true)]
[InlineData(false)]
public void Ctor_Visible(bool visibility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public void Ctor_NonNull_ThrowsPlatformNotSupportedException(object value)
Assert.Throws<PlatformNotSupportedException>(() => new DispatchWrapper(value));
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
[InlineData("")]
[InlineData(0)]
[PlatformSpecific(TestPlatforms.Windows)]
public void Ctor_NonDispatchObject_ThrowsInvalidCastException(object value)
{
Assert.Throws<InvalidCastException>(() => new DispatchWrapper(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static IEnumerable<object[]> ChangeWrapperHandleStrength_ComObject_TestDa
yield return new object[] { new AutoDualComObjectEmpty() };
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
[MemberData(nameof(ChangeWrapperHandleStrength_ComObject_TestData))]
public void ChangeWrapperHandleStrength_ComObject_ReturnsExpected(object o)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ public static IEnumerable<object[]> ChangeWrapperHandleStrength_TestData()
yield return new object[] { d };
}

[Theory]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
[MemberData(nameof(ChangeWrapperHandleStrength_TestData))]
public void ChangeWrapperHandleStrength_ValidObject_Success(object otp)
{
Marshal.ChangeWrapperHandleStrength(otp, fIsWeak: true);
Marshal.ChangeWrapperHandleStrength(otp, fIsWeak: false);
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void ChangeWrapperHandleStrength_NullObject_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("otp", () => Marshal.ChangeWrapperHandleStrength(null, fIsWeak: true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ namespace System.Runtime.InteropServices.Tests
{
public partial class CreateAggregatedObjectTests
{
[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateAggregatedObject_Generic_ReturnsExpected()
{
var original = new object();
Expand Down Expand Up @@ -38,8 +37,7 @@ public void CreateAggregatedObject_Generic_ReturnsExpected()
}
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateAggregatedObject_NonGeneric_ReturnsExpected()
{
var original = new object();
Expand Down Expand Up @@ -74,22 +72,19 @@ public void CreateAggregatedObject_Unix_ThrowsPlatformNotSupportedException()
Assert.Throws<PlatformNotSupportedException>(() => Marshal.CreateAggregatedObject(IntPtr.Zero, 1));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateAggregateObject_ZeroPointer_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("pOuter", () => Marshal.CreateAggregatedObject(IntPtr.Zero, 1));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateAggregateObject_NullObject_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("o", () => Marshal.CreateAggregatedObject((IntPtr)1, null));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateAggregatedObject_AlreadyHasContainer_ThrowsArgumentException()
{
var o1 = new object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ namespace System.Runtime.InteropServices.Tests
{
public partial class CreateWrapperOfTypeTests
{
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateWrapperOfType_SameType_ReturnsSameInstance()
{
var comObject = new ComImportObject();
Assert.Same(comObject, Marshal.CreateWrapperOfType(comObject, typeof(ComImportObject)));
Assert.Same(comObject, Marshal.CreateWrapperOfType<ComImportObject, ComImportObject>(comObject));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateWrapperOfType_NullObject_ReturnsNull()
{
Assert.Null(Marshal.CreateWrapperOfType(null, typeof(ComImportObject)));
Assert.Null(Marshal.CreateWrapperOfType<ComImportObject, ComImportObject>(null));
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
[InlineData(typeof(int))]
[InlineData(typeof(GenericSubComImportObject<string>))]
[InlineData(typeof(GenericSubComImportObject<>))]
Expand All @@ -32,7 +32,7 @@ public void CreateWrapperOfType_InvalidComObjectType_ThrowsArgumentException(Typ
AssertExtensions.Throws<ArgumentException>("t", () => Marshal.CreateWrapperOfType(new ComImportObject(), t));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateWrappedOfType_ObjectNotComObject_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("o", () => Marshal.CreateWrapperOfType(10, typeof(ComImportObject)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public void CreateWrapperOfType_Unix_ThrowsPlatformNotSupportedException()
Assert.Throws<PlatformNotSupportedException>(() => Marshal.CreateWrapperOfType("object", null));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void CreateWrapperOfType_NullType_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("t", () => Marshal.CreateWrapperOfType("object", null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static IEnumerable<object[]> DestroyStructure_InvalidType_TestData()
yield return new object[] { typeBuilder };
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
[ActiveIssue("https://github.com/mono/mono/issues/15087", TestRuntimes.Mono)]
[MemberData(nameof(DestroyStructure_InvalidType_TestData))]
public void DestroyStructure_NonRuntimeType_ThrowsArgumentException(Type invalidType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace System.Runtime.InteropServices.Tests
{
public partial class FinalReleaseComObjectTests
{
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void FinalReleaseComObject_ValidComObject_Success()
{
var comObject = new ComImportObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ public void FinalReleaseComObject_Unix_ThrowsPlatformNotSupportedException()
Assert.Throws<PlatformNotSupportedException>(() => Marshal.FinalReleaseComObject(null));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void FinalReleaseComObject_NullObject_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("o", () => Marshal.FinalReleaseComObject(null));
}

[Fact]
[PlatformSpecific(TestPlatforms.Windows)]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void FinalReleaseComObject_NonComObject_ThrowsArgumentException()
{
AssertExtensions.Throws<ArgumentException>("o", () => Marshal.FinalReleaseComObject(10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IEnumerable<object[]> GenerateGuidForType_Valid_TestData()
yield return new object[] { collectibleType };
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
[MemberData(nameof(GenerateGuidForType_Valid_TestData))]
public void GenerateGuidForType_ValidType_ReturnsExpected(Type type)
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public void GenerateGuidForType_NullType_ThrowsArgumentNullException()
AssertExtensions.Throws<ArgumentNullException>("type", () => Marshal.GenerateGuidForType(null));
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public void GenerateGuidForType_NotRuntimeType_ThrowsArgumentException()
{
AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Assembly"), AssemblyBuilderAccess.Run);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static IEnumerable<object[]> GenerateProgIdForType_Valid_TestData()
yield return new object[] { typeof(ClassWithNullProgID), "" };
}

[Theory]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
[MemberData(nameof(GenerateProgIdForType_Valid_TestData))]
public void GenerateProgIdForType_ValidType_ReturnsExpected(Type type, string expected)
{
Expand All @@ -40,7 +40,7 @@ public class ClassWithNullProgID
{
}

[Fact]
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void GenerateProgIdForType_NullType_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>("type", () => Marshal.GenerateProgIdForType(null));
Expand Down
Loading