Skip to content

Commit

Permalink
Fix up COM related tests running on Windows nanoserver.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronRobinsonMSFT committed Aug 2, 2022
1 parent 3e98baf commit 366429d
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly()
public static bool IsBuiltInComEnabled => SupportsComInterop;
#endif

// Automation refers to COM Automation support. Automation support here means the OS
// 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.
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 @@ -11,19 +11,23 @@ public partial class ChangeWrapperHandleStrengthTests
{
public static IEnumerable<object[]> ChangeWrapperHandleStrength_ComObject_TestData()
{
yield return new object[] { new ComImportObject() };

yield return new object[] { new DualComObject() };
yield return new object[] { new IUnknownComObject() };
yield return new object[] { new IDispatchComObject() };

yield return new object[] { new NonDualComObject() };
yield return new object[] { new AutoDispatchComObject() };
yield return new object[] { new AutoDualComObject() };
if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport)
{
yield return new object[] { new ComImportObject() };

yield return new object[] { new DualComObject() };
yield return new object[] { new IDispatchComObject() };

yield return new object[] { new NonDualComObject() };
yield return new object[] { new AutoDispatchComObject() };
yield return new object[] { new AutoDualComObject() };

yield return new object[] { new NonDualComObjectEmpty() };
yield return new object[] { new AutoDispatchComObjectEmpty() };
yield return new object[] { new AutoDualComObjectEmpty() };
yield return new object[] { new NonDualComObjectEmpty() };
yield return new object[] { new AutoDispatchComObjectEmpty() };
yield return new object[] { new AutoDualComObjectEmpty() };
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace System.Runtime.InteropServices.Tests.Common
{
[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid("293E13A4-2791-4121-9714-14D37CF5DCD4")]
public interface IComImportObject { }

[ComImport]
Expand All @@ -31,31 +31,42 @@ public interface IInspectableInterface { }

public class InterfaceComImportObject : IComImportObject { }

public static class ComServers
{
// Represents an IUnknown only server that exists on all Windows SKUs.
public const string IUnknownOnlyComServer = "0340F119-A598-4ed9-B0AC-6F6A12D3E755";

// Represents a COM server that exists on all Windows skus that support IDispatch.
// See System.DirectoryServices.AccountManagement.ADsLargeInteger.
public const string IDispatchSupportedComServer = "927971f5-0939-11d1-8be1-00c04fd8d503";
public const string IDispatchSupportedComServerProgId = "LargeInteger";
}

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
public class InterfaceAndComImportObject : IComImportObject { }
[Guid(ComServers.IUnknownOnlyComServer)]
public class InterfaceOnComImportObject : IComImportObject { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
public class ComImportObject { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.None)]
public class DualComObject : DualInterface { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IUnknownOnlyComServer)]
[ClassInterface(ClassInterfaceType.None)]
public class IUnknownComObject : IUnknownInterface { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.None)]
public class IDispatchComObject : IDispatchInterface { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.None)]
public class IInspectableComObject : IInspectableInterface { }

Expand All @@ -66,32 +77,32 @@ public class SubComImportObject : ComImportObject { }
public class GenericSubComImportObject<T> : ComImportObject { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.None)]
public class NonDualComObject : IComImportObject { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.None)]
public class NonDualComObjectEmpty { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class AutoDispatchComObject : IComImportObject { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class AutoDispatchComObjectEmpty { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class AutoDualComObject : IComImportObject { }

[ComImport]
[Guid("927971f5-0939-11d1-8be1-00c04fd8d503")]
[Guid(ComServers.IDispatchSupportedComServer)]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class AutoDualComObjectEmpty { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ namespace System.Runtime.InteropServices.Tests
{
public partial class GenerateGuidForTypeTests
{
private const string GuidStr = "708DDB5E-09B1-4550-A5D9-9D7DE2771C10";

[ComImport]
[Guid(GuidStr)]
private class DummyObject { }

[Fact]
public void GenerateGuidForType_ComObject_ReturnsComGuid()
{
Assert.Equal(new Guid("927971f5-0939-11d1-8be1-00c04fd8d503"), Marshal.GenerateGuidForType(typeof(ComImportObject)));
Assert.Equal(new Guid(GuidStr), Marshal.GenerateGuidForType(typeof(DummyObject)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public static IEnumerable<object[]> GetIDispatchForObject_ComObject_TestData()
yield return new object[] { new ComImportObject() };

yield return new object[] { new DualComObject() };
yield return new object[] { new IUnknownComObject() };
yield return new object[] { new IDispatchComObject() };
yield return new object[] { new IInspectableComObject() };

Expand All @@ -27,7 +26,7 @@ public static IEnumerable<object[]> GetIDispatchForObject_ComObject_TestData()
yield return new object[] { new AutoDualComObjectEmpty() };
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport))]
[MemberData(nameof(GetIDispatchForObject_ComObject_TestData))]
public void GetIDispatchForObject_DispatchObject_Success(object obj)
{
Expand All @@ -43,8 +42,9 @@ public void GetIDispatchForObject_DispatchObject_Success(object obj)
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
public void GetIDispatchForObject_ManagedIInspectableObject_Fail()
public void GetIDispatchForObject_NonIDispatchObject_Fail()
{
Assert.Throws<InvalidCastException>(() => Marshal.GetIDispatchForObject(new IUnknownComObject()));
Assert.Throws<PlatformNotSupportedException>(() => Marshal.GetIDispatchForObject(new IInspectableManagedObject()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ public partial class GetNativeVariantForObjectTests
public static IEnumerable<object[]> GetNativeVariantForObject_ComObject_TestData()
{
// Objects.
yield return new object[] { new ComImportObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new IUnknownComObject(), VarEnum.VT_UNKNOWN };

yield return new object[] { new DualComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new IUnknownComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new IDispatchComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new IInspectableComObject(), VarEnum.VT_DISPATCH };
if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport)
{
yield return new object[] { new ComImportObject(), VarEnum.VT_DISPATCH };

yield return new object[] { new DualComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new IDispatchComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new IInspectableComObject(), VarEnum.VT_DISPATCH };

yield return new object[] { new NonDualComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new AutoDispatchComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new AutoDualComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new NonDualComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new AutoDispatchComObject(), VarEnum.VT_DISPATCH };
yield return new object[] { new AutoDualComObject(), VarEnum.VT_DISPATCH };

yield return new object[] { new NonDualComObjectEmpty(), VarEnum.VT_DISPATCH };
yield return new object[] { new AutoDispatchComObjectEmpty(), VarEnum.VT_DISPATCH };
yield return new object[] { new AutoDualComObjectEmpty(), VarEnum.VT_DISPATCH };
yield return new object[] { new NonDualComObjectEmpty(), VarEnum.VT_DISPATCH };
yield return new object[] { new AutoDispatchComObjectEmpty(), VarEnum.VT_DISPATCH };
yield return new object[] { new AutoDualComObjectEmpty(), VarEnum.VT_DISPATCH };
}
}

public static IEnumerable<object[]> GetNativeVariantForObject_ComObjectArray_TestData()
Expand Down Expand Up @@ -59,32 +63,35 @@ public void GetNativeVariantForObject_ComObject_Success(object obj, VarEnum expe

public static IEnumerable<object[]> GetNativeVariantForObject_WrappedComObject_TestData()
{
var empty = new ComImportObject();
var dual = new DualComObject();
var iUnknown = new IUnknownComObject();
var iDispatch = new IDispatchComObject();
var iInspectable = new IInspectableComObject();
var nonDual = new NonDualComObject();
var autoDispatch = new AutoDispatchComObject();
var autoDual = new AutoDualComObject();

yield return new object[] { new UnknownWrapper(empty), empty, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(dual), dual, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(iUnknown), iUnknown, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(iDispatch), iDispatch, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(iInspectable), iInspectable, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(nonDual), nonDual, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(autoDispatch), autoDispatch, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(autoDual), autoDual, VarEnum.VT_UNKNOWN };

yield return new object[] { new DispatchWrapper(empty), empty, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(dual), dual, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(iUnknown), iUnknown, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(iDispatch), iDispatch, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(iInspectable), iInspectable, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(nonDual), nonDual, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(autoDispatch), autoDispatch, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(autoDual), autoDual, VarEnum.VT_DISPATCH };

if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport)
{
var empty = new ComImportObject();
var dual = new DualComObject();
var iDispatch = new IDispatchComObject();
var iInspectable = new IInspectableComObject();
var nonDual = new NonDualComObject();
var autoDispatch = new AutoDispatchComObject();
var autoDual = new AutoDualComObject();

yield return new object[] { new UnknownWrapper(empty), empty, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(dual), dual, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(iDispatch), iDispatch, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(iInspectable), iInspectable, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(nonDual), nonDual, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(autoDispatch), autoDispatch, VarEnum.VT_UNKNOWN };
yield return new object[] { new UnknownWrapper(autoDual), autoDual, VarEnum.VT_UNKNOWN };

yield return new object[] { new DispatchWrapper(empty), empty, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(dual), dual, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(iDispatch), iDispatch, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(iInspectable), iInspectable, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(nonDual), nonDual, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(autoDispatch), autoDispatch, VarEnum.VT_DISPATCH };
yield return new object[] { new DispatchWrapper(autoDual), autoDual, VarEnum.VT_DISPATCH };
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
Expand All @@ -96,12 +103,16 @@ public void GetNativeVariantForObject_WrappedComObject_Success(object obj, objec

public static IEnumerable<object[]> GetNativeVariantForObject_InvalidArrayType_TestData()
{
yield return new object[] { new DualComObject[] { new DualComObject() } };
yield return new object[] { new IUnknownComObject[] { new IUnknownComObject(), null } };
yield return new object[] { new IDispatchComObject[] { new IDispatchComObject(), null } };
yield return new object[] { new NonDualComObject[] { new NonDualComObject(), null } };
yield return new object[] { new AutoDispatchComObject[] { new AutoDispatchComObject(), null } };
yield return new object[] { new AutoDualComObject[] { new AutoDualComObject(), null } };

if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport)
{
yield return new object[] { new DualComObject[] { new DualComObject() } };
yield return new object[] { new IDispatchComObject[] { new IDispatchComObject(), null } };
yield return new object[] { new NonDualComObject[] { new NonDualComObject(), null } };
yield return new object[] { new AutoDispatchComObject[] { new AutoDispatchComObject(), null } };
yield return new object[] { new AutoDualComObject[] { new AutoDualComObject(), null } };
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ public partial class GetObjectForIUnknownTests
{
public static IEnumerable<object[]> GetObjectForIUnknown_ComObject_TestData()
{
yield return new object[] { new ComImportObject() };

yield return new object[] { new DualComObject() };
yield return new object[] { new IUnknownComObject() };
yield return new object[] { new IDispatchComObject() };
yield return new object[] { new IInspectableComObject() };

yield return new object[] { new NonDualComObject() };
yield return new object[] { new AutoDispatchComObject() };
yield return new object[] { new AutoDualComObject() };
if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport)
{
yield return new object[] { new ComImportObject() };

yield return new object[] { new DualComObject() };
yield return new object[] { new IDispatchComObject() };
yield return new object[] { new IInspectableComObject() };

yield return new object[] { new NonDualComObject() };
yield return new object[] { new AutoDispatchComObject() };
yield return new object[] { new AutoDualComObject() };

yield return new object[] { new NonDualComObjectEmpty() };
yield return new object[] { new AutoDispatchComObjectEmpty() };
yield return new object[] { new AutoDualComObjectEmpty() };
yield return new object[] { new NonDualComObjectEmpty() };
yield return new object[] { new AutoDispatchComObjectEmpty() };
yield return new object[] { new AutoDualComObjectEmpty() };
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))]
Expand Down
Loading

0 comments on commit 366429d

Please sign in to comment.