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,21 @@ 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

// Automation refers to COM Automation support. Automation support here means the OS
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
// and runtime provide support for the following: IDispatch, STA apartments, etc. This
// is typically available whenever COM support is enabled, but Windows nano-server is an exception.
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
public static bool IsBuiltInComEnabledWithOSAutomationSupport => IsBuiltInComEnabled && IsNotWindowsNanoServer;

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 @@ -37,7 +37,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
Loading