diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index 252cb293ae400..3a879b71ff847 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -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; diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.Windows.cs index 184308df8950c..327f6f3832b60 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/ChangeWrapperHandleStrengthTests.Windows.cs @@ -11,19 +11,23 @@ public partial class ChangeWrapperHandleStrengthTests { public static IEnumerable 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))] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs index 1cf889d5a158f..faf67042f87c0 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/Common/CommonTypes.Windows.cs @@ -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] @@ -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 { } @@ -66,32 +77,32 @@ public class SubComImportObject : ComImportObject { } public class GenericSubComImportObject : 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 { } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.Windows.cs index 747ea33bac65d..c960cbb4d544d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GenerateGuidForTypeTests.Windows.cs @@ -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))); } } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.Windows.cs index 8ad00b8e31081..c53cc7d55a32e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetIDispatchForObjectTests.Windows.cs @@ -14,7 +14,6 @@ public static IEnumerable 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() }; @@ -27,7 +26,7 @@ public static IEnumerable 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) { @@ -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(() => Marshal.GetIDispatchForObject(new IUnknownComObject())); Assert.Throws(() => Marshal.GetIDispatchForObject(new IInspectableManagedObject())); } } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.Windows.cs index ea466ac7d3176..25a6178366270 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetNativeVariantForObjectTests.Windows.cs @@ -12,20 +12,24 @@ public partial class GetNativeVariantForObjectTests public static IEnumerable 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 GetNativeVariantForObject_ComObjectArray_TestData() @@ -59,32 +63,35 @@ public void GetNativeVariantForObject_ComObject_Success(object obj, VarEnum expe public static IEnumerable 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))] @@ -96,12 +103,16 @@ public void GetNativeVariantForObject_WrappedComObject_Success(object obj, objec public static IEnumerable 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))] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.Windows.cs index 1c35391fb2e7f..3c7fcb92d7550 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetObjectForIUnknownTests.Windows.cs @@ -11,20 +11,24 @@ public partial class GetObjectForIUnknownTests { public static IEnumerable 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))] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.Windows.cs index d74843abb0ec9..0967fb5b38984 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetStartComSlotTests.Windows.cs @@ -11,24 +11,28 @@ public partial class GetStartComSlotTests { public static IEnumerable GetStartComSlot_TestData() { - yield return new object[] { typeof(ComImportObject), -1 }; - yield return new object[] { typeof(SubComImportObject), -1 }; + yield return new object[] { typeof(IUnknownComObject), 3}; + yield return new object[] { typeof(IUnknownInterface), 3}; + yield return new object[] { typeof(InterfaceOnComImportObject), 7 }; yield return new object[] { typeof(InterfaceComImportObject), -1 }; - yield return new object[] { typeof(InterfaceAndComImportObject), 7 }; - yield return new object[] { typeof(IComImportObject), 7 }; - yield return new object[] { typeof(DualInterface), 7}; - yield return new object[] { typeof(IUnknownInterface), 3}; - yield return new object[] { typeof(IDispatchInterface), 7}; - yield return new object[] { typeof(DualComObject), 7}; - yield return new object[] { typeof(IUnknownComObject), 3}; - yield return new object[] { typeof(IDispatchComObject), 7}; - yield return new object[] { typeof(NonDualComObject), 7}; - yield return new object[] { typeof(AutoDispatchComObject), 7}; - yield return new object[] { typeof(AutoDualComObject), 7}; - yield return new object[] { typeof(NonDualComObjectEmpty), -1}; - yield return new object[] { typeof(AutoDispatchComObjectEmpty), -1}; - yield return new object[] { typeof(AutoDualComObjectEmpty), -1}; + if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport) + { + yield return new object[] { typeof(ComImportObject), -1 }; + yield return new object[] { typeof(SubComImportObject), -1 }; + yield return new object[] { typeof(IComImportObject), 7 }; + + yield return new object[] { typeof(DualInterface), 7}; + yield return new object[] { typeof(IDispatchInterface), 7}; + yield return new object[] { typeof(DualComObject), 7}; + yield return new object[] { typeof(IDispatchComObject), 7}; + yield return new object[] { typeof(NonDualComObject), 7}; + yield return new object[] { typeof(AutoDispatchComObject), 7}; + yield return new object[] { typeof(AutoDualComObject), 7}; + yield return new object[] { typeof(NonDualComObjectEmpty), -1}; + yield return new object[] { typeof(AutoDispatchComObjectEmpty), -1}; + yield return new object[] { typeof(AutoDualComObjectEmpty), -1}; + } yield return new object[] { typeof(ManagedInterfaceSupportIUnknown), 3 }; yield return new object[] { typeof(ManagedInterfaceSupportIUnknownWithMethods), 3 }; diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeFromCLSIDTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeFromCLSIDTests.cs index 85d980f18e9b3..34916cde8d981 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeFromCLSIDTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/GetTypeFromCLSIDTests.cs @@ -8,9 +8,10 @@ namespace System.Runtime.InteropServices.Tests { public class GetTypeFromCLSIDTests { - private static readonly Guid TestCLSID = new Guid("927971f5-0939-11d1-8be1-00c04fd8d503"); - private const string TestProgID = "LargeInteger"; + private static readonly Guid TestCLSID = new Guid(Common.ComServers.IDispatchSupportedComServer); + + private const string TestProgID = Common.ComServers.IDispatchSupportedComServerProgId; private const string TestServerName = "____NonExistingServer____"; [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] @@ -26,7 +27,7 @@ public void GetTypeFromCLSID_NoSuchCLSIDExists_ReturnsExpected() Assert.Throws(() => Activator.CreateInstance(type)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport))] public void GetTypeFromCLSID_CLSIDExists_ReturnsExpected() { Type type = Marshal.GetTypeFromCLSID(TestCLSID); @@ -44,7 +45,7 @@ public void GetTypeFromCLSID_CLSIDExists_ReturnsExpected() Assert.NotNull(Activator.CreateInstance(type)); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport))] public void GetTypeFromCLSID_CLSIDExists_Server_ReturnsExpected() { Type type = Type.GetTypeFromCLSID(TestCLSID, server: TestServerName, throwOnError: true); @@ -71,7 +72,7 @@ public void GetTypeFromProgID_Unix() Assert.Throws(() => Type.GetTypeFromProgID(TestProgID, throwOnError: true)); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] public void GetTypeFromProgID_ReturnsExpected() { AssertExtensions.Throws("progID", () => Type.GetTypeFromProgID(null)); diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.Windows.cs index 1724ceaf4a2d2..0eb7ccce90012 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsComObjectTests.Windows.cs @@ -11,12 +11,16 @@ public partial class IsComObjectTests { public static IEnumerable IsComObject_Windows_TestData() { - yield return new object[] { new ComImportObject(), true }; - yield return new object[] { new ComImportObject[0], false }; - yield return new object[] { new SubComImportObject(), true }; - yield return new object[] { new GenericSubComImportObject(), true }; - yield return new object[] { new InterfaceAndComImportObject(), true }; + yield return new object[] { new InterfaceOnComImportObject(), true }; yield return new object[] { new InterfaceComImportObject(), false }; + + if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport) + { + yield return new object[] { new ComImportObject(), true }; + yield return new object[] { new ComImportObject[0], false }; + yield return new object[] { new SubComImportObject(), true }; + yield return new object[] { new GenericSubComImportObject(), true }; + } } [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsTypeVisibleFromComTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsTypeVisibleFromComTests.Windows.cs index c161192dc0265..8b0145b89a8c5 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsTypeVisibleFromComTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/IsTypeVisibleFromComTests.Windows.cs @@ -11,19 +11,23 @@ public partial class IsTypeVisibleFromComTests { public static IEnumerable IsTypeVisibleFromCom_Windows_TestData() { - yield return new object[] { typeof(ComImportObject), true }; - yield return new object[] { typeof(InterfaceAndComImportObject), true }; + yield return new object[] { typeof(InterfaceOnComImportObject), true }; yield return new object[] { typeof(InterfaceComImportObject), true }; - yield return new object[] { typeof(IsTypeVisibleFromComTests), true }; - yield return new object[] { typeof(PrivateType), false }; - yield return new object[] { typeof(ProtectedType), false }; - yield return new object[] { typeof(InternalType), false }; - yield return new object[] { typeof(InnerManagedInterface), false}; - yield return new object[] { typeof(INonGenericInterface), true }; - yield return new object[] { typeof(NonGenericStruct), true }; - yield return new object[] { typeof(ManagedClassWithComVisibleFalse), false }; - yield return new object[] { typeof(ManagedClassWithComVisibleTrue), true }; + if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport) + { + yield return new object[] { typeof(ComImportObject), true }; + + yield return new object[] { typeof(IsTypeVisibleFromComTests), true }; + yield return new object[] { typeof(PrivateType), false }; + yield return new object[] { typeof(ProtectedType), false }; + yield return new object[] { typeof(InternalType), false }; + yield return new object[] { typeof(InnerManagedInterface), false}; + yield return new object[] { typeof(INonGenericInterface), true }; + yield return new object[] { typeof(NonGenericStruct), true }; + yield return new object[] { typeof(ManagedClassWithComVisibleFalse), false }; + yield return new object[] { typeof(ManagedClassWithComVisibleTrue), true }; + } } [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs index ec54567bee972..f9dd294cd838f 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.Windows.cs @@ -14,32 +14,32 @@ public partial class QueryInterfaceTests public static IEnumerable QueryInterface_ValidComObjectInterface_TestData() { - yield return new object[] { new ComImportObject(), IID_IUNKNOWN }; - yield return new object[] { new ComImportObject(), IID_IDISPATCH }; - - yield return new object[] { new DualComObject(), IID_IUNKNOWN }; - yield return new object[] { new DualComObject(), IID_IDISPATCH }; yield return new object[] { new IUnknownComObject(), IID_IUNKNOWN }; - yield return new object[] { new IUnknownComObject(), IID_IDISPATCH }; - yield return new object[] { new IDispatchComObject(), IID_IUNKNOWN }; - yield return new object[] { new IDispatchComObject(), IID_IDISPATCH }; - yield return new object[] { new NonDualComObject(), IID_IUNKNOWN }; - yield return new object[] { new NonDualComObject(), IID_IDISPATCH }; - yield return new object[] { new AutoDispatchComObject(), IID_IUNKNOWN }; - yield return new object[] { new AutoDispatchComObject(), IID_IDISPATCH }; - yield return new object[] { new AutoDualComObject(), IID_IUNKNOWN }; - yield return new object[] { new AutoDualComObject(), IID_IDISPATCH }; + if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport) + { + yield return new object[] { new ComImportObject(), IID_IUNKNOWN }; + yield return new object[] { new ComImportObject(), IID_IDISPATCH }; - yield return new object[] { new NonDualComObjectEmpty(), IID_IUNKNOWN }; - yield return new object[] { new NonDualComObjectEmpty(), IID_IDISPATCH }; - yield return new object[] { new AutoDispatchComObjectEmpty(), IID_IUNKNOWN }; - yield return new object[] { new AutoDispatchComObjectEmpty(), IID_IDISPATCH }; - yield return new object[] { new AutoDualComObjectEmpty(), IID_IUNKNOWN }; - yield return new object[] { new AutoDualComObjectEmpty(), IID_IDISPATCH }; + yield return new object[] { new DualComObject(), IID_IUNKNOWN }; + yield return new object[] { new DualComObject(), IID_IDISPATCH }; + yield return new object[] { new IDispatchComObject(), IID_IUNKNOWN }; + yield return new object[] { new IDispatchComObject(), IID_IDISPATCH }; - yield return new object[] { new IUnknownComObject(), IID_IUNKNOWN }; - yield return new object[] { new IUnknownComObject(), IID_IDISPATCH }; + yield return new object[] { new NonDualComObject(), IID_IUNKNOWN }; + yield return new object[] { new NonDualComObject(), IID_IDISPATCH }; + yield return new object[] { new AutoDispatchComObject(), IID_IUNKNOWN }; + yield return new object[] { new AutoDispatchComObject(), IID_IDISPATCH }; + yield return new object[] { new AutoDualComObject(), IID_IUNKNOWN }; + yield return new object[] { new AutoDualComObject(), IID_IDISPATCH }; + + yield return new object[] { new NonDualComObjectEmpty(), IID_IUNKNOWN }; + yield return new object[] { new NonDualComObjectEmpty(), IID_IDISPATCH }; + yield return new object[] { new AutoDispatchComObjectEmpty(), IID_IUNKNOWN }; + yield return new object[] { new AutoDispatchComObjectEmpty(), IID_IDISPATCH }; + yield return new object[] { new AutoDualComObjectEmpty(), IID_IUNKNOWN }; + yield return new object[] { new AutoDualComObjectEmpty(), IID_IDISPATCH }; + } } [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] @@ -69,33 +69,37 @@ public void QueryInterface_ValidComObjectInterface_Success(object o, string iidS public static IEnumerable QueryInterface_NoSuchComObjectInterface_TestData() { - const string IID_CUSTOMINTERFACE = "927971f5-0939-11d1-8be1-00c04fd8d503"; + const string IID_CUSTOMINTERFACE = "ED53244F-0514-49D1-9A85-E14B33E71CDF"; - yield return new object[] { new ComImportObject(), IID_IINSPECTABLE }; - yield return new object[] { new ComImportObject(), IID_CUSTOMINTERFACE }; - - yield return new object[] { new DualComObject(), IID_IINSPECTABLE }; - yield return new object[] { new DualComObject(), IID_CUSTOMINTERFACE }; yield return new object[] { new IUnknownComObject(), IID_IINSPECTABLE }; yield return new object[] { new IUnknownComObject(), IID_CUSTOMINTERFACE }; - yield return new object[] { new IDispatchComObject(), IID_IINSPECTABLE }; - yield return new object[] { new IDispatchComObject(), IID_CUSTOMINTERFACE }; - yield return new object[] { new IInspectableComObject(), IID_IINSPECTABLE }; - yield return new object[] { new IInspectableComObject(), IID_CUSTOMINTERFACE }; - yield return new object[] { new NonDualComObject(), IID_IINSPECTABLE }; - yield return new object[] { new NonDualComObject(), IID_CUSTOMINTERFACE }; - yield return new object[] { new AutoDispatchComObject(), IID_IINSPECTABLE }; - yield return new object[] { new AutoDispatchComObject(), IID_CUSTOMINTERFACE }; - yield return new object[] { new AutoDualComObject(), IID_IINSPECTABLE }; - yield return new object[] { new AutoDualComObject(), IID_CUSTOMINTERFACE }; + if (PlatformDetection.IsBuiltInComEnabledWithOSAutomationSupport) + { + yield return new object[] { new ComImportObject(), IID_IINSPECTABLE }; + yield return new object[] { new ComImportObject(), IID_CUSTOMINTERFACE }; + + yield return new object[] { new DualComObject(), IID_IINSPECTABLE }; + yield return new object[] { new DualComObject(), IID_CUSTOMINTERFACE }; + yield return new object[] { new IDispatchComObject(), IID_IINSPECTABLE }; + yield return new object[] { new IDispatchComObject(), IID_CUSTOMINTERFACE }; + yield return new object[] { new IInspectableComObject(), IID_IINSPECTABLE }; + yield return new object[] { new IInspectableComObject(), IID_CUSTOMINTERFACE }; - yield return new object[] { new NonDualComObjectEmpty(), IID_IINSPECTABLE }; - yield return new object[] { new NonDualComObjectEmpty(), IID_CUSTOMINTERFACE }; - yield return new object[] { new AutoDispatchComObjectEmpty(), IID_IINSPECTABLE }; - yield return new object[] { new AutoDispatchComObjectEmpty(), IID_CUSTOMINTERFACE }; - yield return new object[] { new AutoDualComObjectEmpty(), IID_IINSPECTABLE }; - yield return new object[] { new AutoDualComObjectEmpty(), IID_CUSTOMINTERFACE }; + yield return new object[] { new NonDualComObject(), IID_IINSPECTABLE }; + yield return new object[] { new NonDualComObject(), IID_CUSTOMINTERFACE }; + yield return new object[] { new AutoDispatchComObject(), IID_IINSPECTABLE }; + yield return new object[] { new AutoDispatchComObject(), IID_CUSTOMINTERFACE }; + yield return new object[] { new AutoDualComObject(), IID_IINSPECTABLE }; + yield return new object[] { new AutoDualComObject(), IID_CUSTOMINTERFACE }; + + yield return new object[] { new NonDualComObjectEmpty(), IID_IINSPECTABLE }; + yield return new object[] { new NonDualComObjectEmpty(), IID_CUSTOMINTERFACE }; + yield return new object[] { new AutoDispatchComObjectEmpty(), IID_IINSPECTABLE }; + yield return new object[] { new AutoDispatchComObjectEmpty(), IID_CUSTOMINTERFACE }; + yield return new object[] { new AutoDualComObjectEmpty(), IID_IINSPECTABLE }; + yield return new object[] { new AutoDualComObjectEmpty(), IID_CUSTOMINTERFACE }; + } } [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltInComEnabled))] diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.cs index a52f710abf576..7d1db477dd974 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/Marshal/QueryInterfaceTests.cs @@ -49,7 +49,7 @@ public void QueryInterface_ValidInterface_Success(object o, string iidString) public static IEnumerable QueryInterface_NoSuchInterface_TestData() { yield return new object[] { new object(), Guid.Empty.ToString() }; - yield return new object[] { new object(), "927971f5-0939-11d1-8be1-00c04fd8d503" }; + yield return new object[] { new object(), "639610C8-26EA-48BB-BD74-4BC18EECC6EA" }; } [Theory]