From: Zeng Jiang Date: Thu, 1 Nov 2018 00:02:52 +0000 (+0800) Subject: Add PInvoke/NativeCallManagedComVisible tests (#19328) X-Git-Tag: accepted/tizen/unified/20190422.045933~857 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b7d2cdd29a7c1a7ec63fb39d574a817011b9ed4a;p=platform%2Fupstream%2Fcoreclr.git Add PInvoke/NativeCallManagedComVisible tests (#19328) * Add PInvoke/NativeCallManagedComVisible tests * Update to current infrastructure and disable off-Windows * Fix incorrect S_OK value and made the native side actually return an HRESULT in hr. --- diff --git a/tests/src/Interop/CMakeLists.txt b/tests/src/Interop/CMakeLists.txt index affc629..0a512c2 100644 --- a/tests/src/Interop/CMakeLists.txt +++ b/tests/src/Interop/CMakeLists.txt @@ -41,9 +41,9 @@ add_subdirectory(DllImportAttribute/Simple) add_subdirectory(ExecInDefAppDom) if(WIN32) + add_subdirectory(PInvoke/NativeCallManagedComVisible) # This test doesn't necessarily need to be Windows-only, but the implementation is very tied to Windows APIs add_subdirectory(PInvoke/DateTime) - add_subdirectory(COM/NativeServer) add_subdirectory(COM/NativeClients/Primitives) add_subdirectory(IJW/FakeMscoree) diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyTrue/AssemblyTrueTest.cs b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyTrue/AssemblyTrueTest.cs new file mode 100644 index 0000000..5d1cd11 --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyTrue/AssemblyTrueTest.cs @@ -0,0 +1,913 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using NativeCallManagedComVisible; +using TestLibrary; + +// Setting ComVisible to true makes the types in this assembly visible +// to COM components by default. If you don't need to access a type in +// this assembly from COM, set the ComVisible attribute to false on that type. +[assembly: ComVisible(true)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("41DDB0BD-1E88-4B0C-BD23-FD3B7E4037A8")] + +/// +/// Interface with ComImport. +/// +[ComImport] +[Guid("52E5F852-BD3E-4DF2-8826-E1EC39557943")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceComImport +{ + int Foo(); +} + +/// +/// Interface visible with ComVisible(true). +/// +[ComVisible(true)] +[Guid("8FDE13DC-F917-44FF-AAC8-A638FD27D647")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue +{ + int Foo(); +} + +/// +/// Interface not visible with ComVisible(false). +/// +[ComVisible(false)] +[Guid("0A2EF649-371D-4480-B0C7-07F455C836D3")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse +{ + int Foo(); +} + +/// +/// Interface not visible without ComVisible(). +/// +[Guid("FB504D72-39C4-457F-ACF4-3E5D8A31AAE4")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceWithoutVisible +{ + int Foo(); +} + +/// +/// Interface not public. +/// +[ComVisible(true)] +[Guid("11320010-13FA-4B40-8580-8CF92EE70774")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +interface IInterfaceNotPublic +{ + int Foo(); +} + +/// +/// Generic interface with ComVisible(true). +/// +[ComVisible(true)] +[Guid("BA4B32D4-1D73-4605-AD0A-900A31E75BC3")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceGenericVisibleTrue +{ + T Foo(); +} + +/// +/// Generic class for guid generator. +/// +public class GenericClassW2Pars +{ + T1 Foo(T2 a) { return default(T1); } +} + +/// +/// Derived interface visible with ComVisible(true) and GUID. +/// +[ComVisible(true)] +[Guid("FE62A5B9-34C4-4EAF-AF0A-1AD390B15BDB")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IDerivedInterfaceVisibleTrueGuid +{ + int Foo(); +} + +/// +/// Derived interface visible with ComVisible(true) wothout GUID. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IDerivedInterfaceVisibleTrueNoGuid +{ + int Foo1(UInt16 int16Val, bool boolVal); + int Foo5(Int32 int32Val); +} + +/// +/// Derived interface without visibility and without GUID. +/// +public interface IDerivedInterfaceWithoutVisibleNoGuid +{ + int Foo7(Int32 int32Val); +} + +/// +/// Interface visible with ComVisible(true) and without Custom Attribute Guid. +/// Note that in this test, change the method sequence in the interface will +/// change the GUID and could reduce the test efficiency. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrueNoGuid : IDerivedInterfaceVisibleTrueGuid, IDerivedInterfaceVisibleTrueNoGuid, IDerivedInterfaceWithoutVisibleNoGuid +{ + new int Foo1(UInt16 int16Val, bool boolVal); + new int Foo(); + int Foo2(string str, out int outIntVal, IntPtr intPtrVal, int[] arrayVal, byte inByteVal = 0, int inIntVal = 0); + int Foo3(ref short refShortVal, params byte[] paramsList); + int Foo4(ref List refShortVal, GenericClassW2Pars genericClass, params object[] paramsList); +} + +/// +/// Interface not visible and without Custom Attribute Guid. +/// +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceNotVisibleNoGuid +{ + int Foo(); +} + +/// +/// Interface visible with ComVisible(true), without Custom Attribute Guid and a generic method. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrueNoGuidGeneric +{ + int Foo(T genericVal); +} + +/// +/// Interface with ComImport derived from an interface with ComImport. +/// +[ComImport] +[Guid("943759D7-3552-43AD-9C4D-CC2F787CF36E")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceComImport_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComImport. +/// +[ComVisible(true)] +[Guid("75DE245B-0CE3-4B07-8761-328906C750B7")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(false) derived from an interface with ComImport. +/// +[ComVisible(false)] +[Guid("C73D96C3-B005-42D6-93F5-E30AEE08C66C")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComVisible(true). +/// +[ComVisible(true)] +[Guid("60B3917B-9CC2-40F2-A975-CD6898DA697F")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(false) derived from an interface with ComVisible(true). +/// +[ComVisible(false)] +[Guid("2FC59DDB-B1D0-4678-93AF-6A48E838B705")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComVisible(false). +/// +[ComVisible(true)] +[Guid("C82C25FC-FBAD-4EA9-BED1-343C887464B5")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_VisibleFalse : IInterfaceVisibleFalse +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an not public interface. +/// +[ComVisible(true)] +[Guid("8A4C1691-5615-4762-8568-481DC671F9CE")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +interface IInterfaceNotPublic_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + + +/// +/// Class visible with ComVisible(true). +/// +[ComVisible(true)] +[Guid("48FC2EFC-C7ED-4E02-8D02-F05B6A439FC9")] +public sealed class ClassVisibleTrueServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic, + IInterfaceVisibleTrueNoGuid, IInterfaceNotVisibleNoGuid, + IInterfaceComImport_ComImport, IInterfaceVisibleTrue_ComImport, IInterfaceVisibleFalse_ComImport, + IInterfaceVisibleTrue_VisibleTrue, IInterfaceVisibleFalse_VisibleTrue, IInterfaceVisibleTrue_VisibleFalse, IInterfaceNotPublic_VisibleTrue +{ + int IInterfaceComImport.Foo() { return 1; } + int IInterfaceVisibleTrue.Foo() { return 2; } + int IInterfaceVisibleFalse.Foo() { return 3; } + int IInterfaceWithoutVisible.Foo() { return 4; } + int IInterfaceNotPublic.Foo() { return 5; } + + int IInterfaceVisibleTrueNoGuid.Foo() { return 6; } + int IInterfaceVisibleTrueNoGuid.Foo1(UInt16 int16Val, bool boolVal) { return 7; } + int IInterfaceVisibleTrueNoGuid.Foo2(string str, out int outIntVal, IntPtr intPtrVal, int[] arrayVal, byte inByteVal, int inIntVal) + { + outIntVal = 10; + return 8; + } + int IInterfaceVisibleTrueNoGuid.Foo3(ref short refShortVal, params byte[] paramsList) { return 9; } + int IInterfaceVisibleTrueNoGuid.Foo4(ref List refShortVal, GenericClassW2Pars genericClass, params object[] paramsList) { return 10; } + int IDerivedInterfaceVisibleTrueGuid.Foo() { return 12; } + int IDerivedInterfaceVisibleTrueNoGuid.Foo1(UInt16 int16Val, bool boolVal) { return 13; } + int IDerivedInterfaceVisibleTrueNoGuid.Foo5(Int32 int32Val) { return 14; } + int IDerivedInterfaceWithoutVisibleNoGuid.Foo7(Int32 int32Val) { return 15; } + int IInterfaceNotVisibleNoGuid.Foo() { return 16; } + + int IInterfaceComImport_ComImport.Foo() { return 101; } + int IInterfaceVisibleTrue_ComImport.Foo() { return 102; } + int IInterfaceVisibleFalse_ComImport.Foo() { return 103; } + int IInterfaceVisibleTrue_VisibleTrue.Foo() { return 104; } + int IInterfaceVisibleFalse_VisibleTrue.Foo() { return 105; } + int IInterfaceVisibleTrue_VisibleFalse.Foo() { return 106; } + int IInterfaceNotPublic_VisibleTrue.Foo() { return 107; } + + int Foo() { return 9; } +} + +/// +/// Class not visible with ComVisible(false). +/// +[ComVisible(false)] +[Guid("6DF17EC1-A8F4-4693-B195-EDB27DF00170")] +public sealed class ClassVisibleFalseServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic +{ + int IInterfaceComImport.Foo() { return 120; } + int IInterfaceVisibleTrue.Foo() { return 121; } + int IInterfaceVisibleFalse.Foo() { return 122; } + int IInterfaceWithoutVisible.Foo() { return 123; } + int IInterfaceNotPublic.Foo() { return 124; } + int Foo() { return 129; } +} + +/// +/// Class not visible without ComVisible(). +/// +[Guid("A57430B8-E0C1-486E-AE57-A15D6A729F99")] +public sealed class ClassWithoutVisibleServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic +{ + int IInterfaceComImport.Foo() { return 130; } + int IInterfaceVisibleTrue.Foo() { return 131; } + int IInterfaceVisibleFalse.Foo() { return 132; } + int IInterfaceWithoutVisible.Foo() { return 133; } + int IInterfaceNotPublic.Foo() { return 134; } + int Foo() { return 139; } +} + +/// +/// Generic visible class with ComVisible(true). +/// +[ComVisible(true)] +[Guid("3CD290FA-1CD0-4370-B8E6-5A573F78C9F7")] +public sealed class ClassGenericServer : IInterfaceVisibleTrue, IInterfaceGenericVisibleTrue, IInterfaceComImport +{ + int IInterfaceComImport.Foo() { return 140; } + int IInterfaceVisibleTrue.Foo() { return 141; } + T IInterfaceGenericVisibleTrue.Foo() { return default(T); } + T Foo() { return default(T); } +} + + +public class ComVisibleServer +{ + /// + /// Nested interface with ComImport. + /// + [ComImport] + [Guid("1D927BC5-1530-4B8E-A183-995425CE4A0A")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceComImport + { + int Foo(); + } + + /// + /// Nested interface visible with ComVisible(true). + /// + [ComVisible(true)] + [Guid("39209692-2568-4B1E-A6C8-A5C7F141D278")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue + { + int Foo(); + } + + /// + /// Nested interface not visible with ComVisible(false). + /// + [ComVisible(false)] + [Guid("1CE4B033-4927-447A-9F91-998357B32ADF")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse + { + int Foo(); + } + + /// + /// Nested interface not visible without ComVisible(). + /// + [Guid("C770422A-C363-49F1-AAA1-3EC81A452816")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceWithoutVisible + { + int Foo(); + } + + /// + /// Nested interface not public. + /// + [ComVisible(true)] + [Guid("F776FF8A-0673-49C2-957A-33C2576062ED")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface INestedInterfaceNotPublic + { + int Foo(); + } + + /// + /// Nested visible interface with ComVisible(true). + /// + public class NestedClass + { + [ComVisible(true)] + [Guid("B31B4EC1-3B59-41C4-B3A0-CF89638CB837")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceNestedInClass + { + int Foo(); + } + } + + /// + /// Generic interface with ComVisible(true). + /// + [ComVisible(true)] + [Guid("D7A8A196-5D85-4C85-94E4-8344ED2C7277")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceGenericVisibleTrue + { + T Foo(); + } + + /// + /// Nested interface with ComImport derived from an interface with ComImport. + /// + [ComImport] + [Guid("C57D849A-A1A9-4CDC-A609-789D79F9332C")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceComImport_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComImport. + /// + [ComVisible(true)] + [Guid("81F28686-F257-4B7E-A47F-57C9775BE2CE")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(false) derived from an interface with ComImport. + /// + [ComVisible(false)] + [Guid("FAAB7E6C-8548-429F-AD34-0CEC3EBDD7B7")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComVisible(true). + /// + [ComVisible(true)] + [Guid("BEFD79A9-D8E6-42E4-8228-1892298460D7")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(false) derived from an interface with ComVisible(true). + /// + [ComVisible(false)] + [Guid("5C497454-EA83-4F79-B990-4EB28505E801")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComVisible(false). + /// + [ComVisible(true)] + [Guid("A17CF08F-EEC4-4EA5-B12C-5A603101415D")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_VisibleFalse : INestedInterfaceVisibleFalse + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an not public interface. + /// + [ComVisible(true)] + [Guid("40B723E9-E1BE-4F55-99CD-D2590D191A53")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface INestedInterfaceNotPublic_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested class visible with ComVisible(true). + /// + [ComVisible(true)] + [Guid("CF681980-CE6D-421E-8B21-AEAE3F1B7DAC")] + public sealed class NestedClassVisibleTrueServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic, + NestedClass.INestedInterfaceNestedInClass, INestedInterfaceComImport_ComImport, INestedInterfaceVisibleTrue_ComImport, INestedInterfaceVisibleFalse_ComImport, + INestedInterfaceVisibleTrue_VisibleTrue, INestedInterfaceVisibleFalse_VisibleTrue, INestedInterfaceVisibleTrue_VisibleFalse, INestedInterfaceNotPublic_VisibleTrue + { + int INestedInterfaceComImport.Foo() { return 10; } + int INestedInterfaceVisibleTrue.Foo() { return 11; } + int INestedInterfaceVisibleFalse.Foo() { return 12; } + int INestedInterfaceWithoutVisible.Foo() { return 13; } + int INestedInterfaceNotPublic.Foo() { return 14; } + + int NestedClass.INestedInterfaceNestedInClass.Foo() { return 110; } + int INestedInterfaceComImport_ComImport.Foo() { return 111; } + int INestedInterfaceVisibleTrue_ComImport.Foo() { return 112; } + int INestedInterfaceVisibleFalse_ComImport.Foo() { return 113; } + int INestedInterfaceVisibleTrue_VisibleTrue.Foo() { return 114; } + int INestedInterfaceVisibleFalse_VisibleTrue.Foo() { return 115; } + int INestedInterfaceVisibleTrue_VisibleFalse.Foo() { return 116; } + int INestedInterfaceNotPublic_VisibleTrue.Foo() { return 117; } + + int Foo() { return 19; } + } + + /// + /// Nested class not visible with ComVisible(false). + /// + [ComVisible(false)] + [Guid("6DF17EC1-A8F4-4693-B195-EDB27DF00170")] + public sealed class NestedClassVisibleFalseServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic + { + int INestedInterfaceComImport.Foo() { return 20; } + int INestedInterfaceVisibleTrue.Foo() { return 21; } + int INestedInterfaceVisibleFalse.Foo() { return 22; } + int INestedInterfaceWithoutVisible.Foo() { return 23; } + int INestedInterfaceNotPublic.Foo() { return 24; } + int Foo() { return 29; } + } + + /// + /// Nested class not visible without ComVisible(). + /// + [Guid("A57430B8-E0C1-486E-AE57-A15D6A729F99")] + public sealed class NestedClassWithoutVisibleServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic + { + int INestedInterfaceComImport.Foo() { return 30; } + int INestedInterfaceVisibleTrue.Foo() { return 31; } + int INestedInterfaceVisibleFalse.Foo() { return 32; } + int INestedInterfaceWithoutVisible.Foo() { return 33; } + int INestedInterfaceNotPublic.Foo() { return 34; } + int Foo() { return 39; } + } + + /// + /// Generic visible nested class with ComVisible(true). + /// + [ComVisible(true)] + [Guid("CAFBD2FF-710A-4E83-9229-42FA16963424")] + public sealed class NestedClassGenericServer : INestedInterfaceVisibleTrue, INestedInterfaceGenericVisibleTrue, INestedInterfaceComImport + { + int INestedInterfaceComImport.Foo() { return 40; } + int INestedInterfaceVisibleTrue.Foo() { return 41; } + T INestedInterfaceGenericVisibleTrue.Foo() { return default(T); } + T Foo() { return default(T); } + } + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceWithoutVisible([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotPublic([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrueNoGuid([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotVisibleNoGuid([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceGenericVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceComImport_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_VisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotPublic_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceWithoutVisible([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNotPublic([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNestedInClass([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceGenericVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceComImport_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_VisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNotPublic_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + /// + /// Test case set for ComVisible. The assembly is set as [assembly: ComVisible(false)] + /// + /// + private static void RunComVisibleTests() + { + int fooSuccessVal = 0; + // + // Tests for class with ComVisible(true) + // + Console.WriteLine("Class with ComVisible(true)"); + ClassVisibleTrueServer visibleBaseClass = new ClassVisibleTrueServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(1, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(2, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceWithoutVisible((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(4, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrueNoGuid"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrueNoGuid((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(6, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotVisibleNoGuid"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceNotVisibleNoGuid((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(16, fooSuccessVal, "COM method didn't return the expected value."); + + // + // Tests for nested Interface in a class with ComVisible(true) + // + Console.WriteLine("Nested Interface in a class with ComVisible(true)"); + + Console.WriteLine("CCWTest_InterfaceComImport_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport_ComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(101, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_ComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(102, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse_ComImport"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse_ComImport((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_VisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(104, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_VisibleFalse"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_VisibleFalse((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(106, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for class with ComVisible(false) + // + Console.WriteLine("Class with ComVisible(false)"); + ClassVisibleFalseServer visibleFalseBaseClass = new ClassVisibleFalseServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)visibleFalseBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(120, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)visibleFalseBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(121, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)visibleFalseBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceWithoutVisible((object)visibleFalseBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(123, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)visibleFalseBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for class without ComVisible() + // + Console.WriteLine("Class without ComVisible()"); + ClassWithoutVisibleServer withoutVisibleBaseClass = new ClassWithoutVisibleServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)withoutVisibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(130, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)withoutVisibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(131, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)withoutVisibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceWithoutVisible((object)withoutVisibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(133, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)withoutVisibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + + // + // Tests for generic class with ComVisible(true) + // + Console.WriteLine("Generic class with ComVisible(true)"); + ClassGenericServer genericServer = new ClassGenericServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)genericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(140, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)genericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(141, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceGenericVisibleTrue"); + Assert.AreEqual(Helpers.COR_E_INVALIDOPERATION, CCWTest_InterfaceGenericVisibleTrue((object)genericServer, out fooSuccessVal), "Returned diferent exception than the expected COR_E_INVALIDOPERATION."); + + // + // Tests for nested class with ComVisible(true) + // + Console.WriteLine("Nested class with ComVisible(true)"); + NestedClassVisibleTrueServer visibleNestedBaseClass = new NestedClassVisibleTrueServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(10, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(11, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceWithoutVisible((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(13, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested Interface in a nested class with ComVisible(true) + // + Console.WriteLine("Nested Interface in a nested class with ComVisible(true)"); + + Console.WriteLine("CCWTest_NestedInterfaceNestedInClass"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceNestedInClass((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(110, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceComImport_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(111, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(112, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse_ComImport"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_VisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(114, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_VisibleFalse"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_VisibleFalse((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(116, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested class with ComVisible(false) + // + Console.WriteLine("Nested class with ComVisible(false)"); + NestedClassVisibleFalseServer visibleFalseNestedBaseClass = new NestedClassVisibleFalseServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)visibleFalseNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(20, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)visibleFalseNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(21, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)visibleFalseNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceWithoutVisible((object)visibleFalseNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(23, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)visibleFalseNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested class without ComVisible() + // + Console.WriteLine("Nested class without ComVisible()"); + NestedClassWithoutVisibleServer withoutVisibleNestedBaseClass = new NestedClassWithoutVisibleServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(30, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(31, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceWithoutVisible((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(33, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for generic nested class with ComVisible(true) + // + Console.WriteLine("Nested generic class with ComVisible(true)"); + NestedClassGenericServer nestedGenericServer = new NestedClassGenericServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)nestedGenericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(40, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)nestedGenericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(41, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceGenericVisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceGenericVisibleTrue((object)nestedGenericServer, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + } + + public static int Main() + { + try + { + RunComVisibleTests(); + + return 100; + } + catch (Exception e) + { + Console.WriteLine($"Test Failure: {e}"); + return 101; + } + } +} diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyTrue/AssemblyTrueTest.csproj b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyTrue/AssemblyTrueTest.csproj new file mode 100644 index 0000000..52e7207 --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyTrue/AssemblyTrueTest.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + AssemblyTrueTest + 2.0 + {F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\..\ + $(DefineConstants);STATIC + + true + true + + + + + + + False + + + + + + + + + + + + + + + diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyWithoutComVisible/AssemblyWithoutComVisibleTest.cs b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyWithoutComVisible/AssemblyWithoutComVisibleTest.cs new file mode 100644 index 0000000..7643a04 --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyWithoutComVisible/AssemblyWithoutComVisibleTest.cs @@ -0,0 +1,912 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using NativeCallManagedComVisible; +using TestLibrary; + +// Don't set ComVisible. +// [assembly: ComVisible(true)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("41DDB0BD-1E88-4B0C-BD23-FD3B7E4037A8")] + +/// +/// Interface with ComImport. +/// +[ComImport] +[Guid("52E5F852-BD3E-4DF2-8826-E1EC39557943")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceComImport +{ + int Foo(); +} + +/// +/// Interface visible with ComVisible(true). +/// +[ComVisible(true)] +[Guid("8FDE13DC-F917-44FF-AAC8-A638FD27D647")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue +{ + int Foo(); +} + +/// +/// Interface not visible with ComVisible(false). +/// +[ComVisible(false)] +[Guid("0A2EF649-371D-4480-B0C7-07F455C836D3")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse +{ + int Foo(); +} + +/// +/// Interface not visible without ComVisible(). +/// +[Guid("FB504D72-39C4-457F-ACF4-3E5D8A31AAE4")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceWithoutVisible +{ + int Foo(); +} + +/// +/// Interface not public. +/// +[ComVisible(true)] +[Guid("11320010-13FA-4B40-8580-8CF92EE70774")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +interface IInterfaceNotPublic +{ + int Foo(); +} + +/// +/// Generic interface with ComVisible(true). +/// +[ComVisible(true)] +[Guid("BA4B32D4-1D73-4605-AD0A-900A31E75BC3")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceGenericVisibleTrue +{ + T Foo(); +} + +/// +/// Generic class for guid generator. +/// +public class GenericClassW2Pars +{ + T1 Foo(T2 a) { return default(T1); } +} + +/// +/// Derived interface visible with ComVisible(true) and GUID. +/// +[ComVisible(true)] +[Guid("FE62A5B9-34C4-4EAF-AF0A-1AD390B15BDB")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IDerivedInterfaceVisibleTrueGuid +{ + int Foo(); +} + +/// +/// Derived interface visible with ComVisible(true) wothout GUID. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IDerivedInterfaceVisibleTrueNoGuid +{ + int Foo1(UInt16 int16Val, bool boolVal); + int Foo5(Int32 int32Val); +} + +/// +/// Derived interface without visibility and without GUID. +/// +public interface IDerivedInterfaceWithoutVisibleNoGuid +{ + int Foo7(Int32 int32Val); +} + +/// +/// Interface visible with ComVisible(true) and without Custom Attribute Guid. +/// Note that in this test, change the method sequence in the interface will +/// change the GUID and could reduce the test efficiency. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrueNoGuid : IDerivedInterfaceVisibleTrueGuid, IDerivedInterfaceVisibleTrueNoGuid, IDerivedInterfaceWithoutVisibleNoGuid +{ + new int Foo1(UInt16 int16Val, bool boolVal); + new int Foo(); + int Foo2(string str, out int outIntVal, IntPtr intPtrVal, int[] arrayVal, byte inByteVal = 0, int inIntVal = 0); + int Foo3(ref short refShortVal, params byte[] paramsList); + int Foo4(ref List refShortVal, GenericClassW2Pars genericClass, params object[] paramsList); +} + +/// +/// Interface not visible and without Custom Attribute Guid. +/// +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceNotVisibleNoGuid +{ + int Foo(); +} + +/// +/// Interface visible with ComVisible(true), without Custom Attribute Guid and a generic method. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrueNoGuidGeneric +{ + int Foo(T genericVal); +} + +/// +/// Interface with ComImport derived from an interface with ComImport. +/// +[ComImport] +[Guid("943759D7-3552-43AD-9C4D-CC2F787CF36E")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceComImport_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComImport. +/// +[ComVisible(true)] +[Guid("75DE245B-0CE3-4B07-8761-328906C750B7")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(false) derived from an interface with ComImport. +/// +[ComVisible(false)] +[Guid("C73D96C3-B005-42D6-93F5-E30AEE08C66C")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComVisible(true). +/// +[ComVisible(true)] +[Guid("60B3917B-9CC2-40F2-A975-CD6898DA697F")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(false) derived from an interface with ComVisible(true). +/// +[ComVisible(false)] +[Guid("2FC59DDB-B1D0-4678-93AF-6A48E838B705")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComVisible(false). +/// +[ComVisible(true)] +[Guid("C82C25FC-FBAD-4EA9-BED1-343C887464B5")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_VisibleFalse : IInterfaceVisibleFalse +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an not public interface. +/// +[ComVisible(true)] +[Guid("8A4C1691-5615-4762-8568-481DC671F9CE")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +interface IInterfaceNotPublic_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + + +/// +/// Class visible with ComVisible(true). +/// +[ComVisible(true)] +[Guid("48FC2EFC-C7ED-4E02-8D02-F05B6A439FC9")] +public sealed class ClassVisibleTrueServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic, + IInterfaceVisibleTrueNoGuid, IInterfaceNotVisibleNoGuid, + IInterfaceComImport_ComImport, IInterfaceVisibleTrue_ComImport, IInterfaceVisibleFalse_ComImport, + IInterfaceVisibleTrue_VisibleTrue, IInterfaceVisibleFalse_VisibleTrue, IInterfaceVisibleTrue_VisibleFalse, IInterfaceNotPublic_VisibleTrue +{ + int IInterfaceComImport.Foo() { return 1; } + int IInterfaceVisibleTrue.Foo() { return 2; } + int IInterfaceVisibleFalse.Foo() { return 3; } + int IInterfaceWithoutVisible.Foo() { return 4; } + int IInterfaceNotPublic.Foo() { return 5; } + + int IInterfaceVisibleTrueNoGuid.Foo() { return 6; } + int IInterfaceVisibleTrueNoGuid.Foo1(UInt16 int16Val, bool boolVal) { return 7; } + int IInterfaceVisibleTrueNoGuid.Foo2(string str, out int outIntVal, IntPtr intPtrVal, int[] arrayVal, byte inByteVal, int inIntVal) + { + outIntVal = 10; + return 8; + } + int IInterfaceVisibleTrueNoGuid.Foo3(ref short refShortVal, params byte[] paramsList) { return 9; } + int IInterfaceVisibleTrueNoGuid.Foo4(ref List refShortVal, GenericClassW2Pars genericClass, params object[] paramsList) { return 10; } + int IDerivedInterfaceVisibleTrueGuid.Foo() { return 12; } + int IDerivedInterfaceVisibleTrueNoGuid.Foo1(UInt16 int16Val, bool boolVal) { return 13; } + int IDerivedInterfaceVisibleTrueNoGuid.Foo5(Int32 int32Val) { return 14; } + int IDerivedInterfaceWithoutVisibleNoGuid.Foo7(Int32 int32Val) { return 15; } + int IInterfaceNotVisibleNoGuid.Foo() { return 16; } + + int IInterfaceComImport_ComImport.Foo() { return 101; } + int IInterfaceVisibleTrue_ComImport.Foo() { return 102; } + int IInterfaceVisibleFalse_ComImport.Foo() { return 103; } + int IInterfaceVisibleTrue_VisibleTrue.Foo() { return 104; } + int IInterfaceVisibleFalse_VisibleTrue.Foo() { return 105; } + int IInterfaceVisibleTrue_VisibleFalse.Foo() { return 106; } + int IInterfaceNotPublic_VisibleTrue.Foo() { return 107; } + + int Foo() { return 9; } +} + +/// +/// Class not visible with ComVisible(false). +/// +[ComVisible(false)] +[Guid("6DF17EC1-A8F4-4693-B195-EDB27DF00170")] +public sealed class ClassVisibleFalseServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic +{ + int IInterfaceComImport.Foo() { return 120; } + int IInterfaceVisibleTrue.Foo() { return 121; } + int IInterfaceVisibleFalse.Foo() { return 122; } + int IInterfaceWithoutVisible.Foo() { return 123; } + int IInterfaceNotPublic.Foo() { return 124; } + int Foo() { return 129; } +} + +/// +/// Class not visible without ComVisible(). +/// +[Guid("A57430B8-E0C1-486E-AE57-A15D6A729F99")] +public sealed class ClassWithoutVisibleServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic +{ + int IInterfaceComImport.Foo() { return 130; } + int IInterfaceVisibleTrue.Foo() { return 131; } + int IInterfaceVisibleFalse.Foo() { return 132; } + int IInterfaceWithoutVisible.Foo() { return 133; } + int IInterfaceNotPublic.Foo() { return 134; } + int Foo() { return 139; } +} + +/// +/// Generic visible class with ComVisible(true). +/// +[ComVisible(true)] +[Guid("3CD290FA-1CD0-4370-B8E6-5A573F78C9F7")] +public sealed class ClassGenericServer : IInterfaceVisibleTrue, IInterfaceGenericVisibleTrue, IInterfaceComImport +{ + int IInterfaceComImport.Foo() { return 140; } + int IInterfaceVisibleTrue.Foo() { return 141; } + T IInterfaceGenericVisibleTrue.Foo() { return default(T); } + T Foo() { return default(T); } +} + + +public class ComVisibleServer +{ + /// + /// Nested interface with ComImport. + /// + [ComImport] + [Guid("1D927BC5-1530-4B8E-A183-995425CE4A0A")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceComImport + { + int Foo(); + } + + /// + /// Nested interface visible with ComVisible(true). + /// + [ComVisible(true)] + [Guid("39209692-2568-4B1E-A6C8-A5C7F141D278")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue + { + int Foo(); + } + + /// + /// Nested interface not visible with ComVisible(false). + /// + [ComVisible(false)] + [Guid("1CE4B033-4927-447A-9F91-998357B32ADF")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse + { + int Foo(); + } + + /// + /// Nested interface not visible without ComVisible(). + /// + [Guid("C770422A-C363-49F1-AAA1-3EC81A452816")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceWithoutVisible + { + int Foo(); + } + + /// + /// Nested interface not public. + /// + [ComVisible(true)] + [Guid("F776FF8A-0673-49C2-957A-33C2576062ED")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface INestedInterfaceNotPublic + { + int Foo(); + } + + /// + /// Nested visible interface with ComVisible(true). + /// + public class NestedClass + { + [ComVisible(true)] + [Guid("B31B4EC1-3B59-41C4-B3A0-CF89638CB837")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceNestedInClass + { + int Foo(); + } + } + + /// + /// Generic interface with ComVisible(true). + /// + [ComVisible(true)] + [Guid("D7A8A196-5D85-4C85-94E4-8344ED2C7277")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceGenericVisibleTrue + { + T Foo(); + } + + /// + /// Nested interface with ComImport derived from an interface with ComImport. + /// + [ComImport] + [Guid("C57D849A-A1A9-4CDC-A609-789D79F9332C")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceComImport_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComImport. + /// + [ComVisible(true)] + [Guid("81F28686-F257-4B7E-A47F-57C9775BE2CE")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(false) derived from an interface with ComImport. + /// + [ComVisible(false)] + [Guid("FAAB7E6C-8548-429F-AD34-0CEC3EBDD7B7")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComVisible(true). + /// + [ComVisible(true)] + [Guid("BEFD79A9-D8E6-42E4-8228-1892298460D7")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(false) derived from an interface with ComVisible(true). + /// + [ComVisible(false)] + [Guid("5C497454-EA83-4F79-B990-4EB28505E801")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComVisible(false). + /// + [ComVisible(true)] + [Guid("A17CF08F-EEC4-4EA5-B12C-5A603101415D")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_VisibleFalse : INestedInterfaceVisibleFalse + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an not public interface. + /// + [ComVisible(true)] + [Guid("40B723E9-E1BE-4F55-99CD-D2590D191A53")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface INestedInterfaceNotPublic_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested class visible with ComVisible(true). + /// + [ComVisible(true)] + [Guid("CF681980-CE6D-421E-8B21-AEAE3F1B7DAC")] + public sealed class NestedClassVisibleTrueServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic, + NestedClass.INestedInterfaceNestedInClass, INestedInterfaceComImport_ComImport, INestedInterfaceVisibleTrue_ComImport, INestedInterfaceVisibleFalse_ComImport, + INestedInterfaceVisibleTrue_VisibleTrue, INestedInterfaceVisibleFalse_VisibleTrue, INestedInterfaceVisibleTrue_VisibleFalse, INestedInterfaceNotPublic_VisibleTrue + { + int INestedInterfaceComImport.Foo() { return 10; } + int INestedInterfaceVisibleTrue.Foo() { return 11; } + int INestedInterfaceVisibleFalse.Foo() { return 12; } + int INestedInterfaceWithoutVisible.Foo() { return 13; } + int INestedInterfaceNotPublic.Foo() { return 14; } + + int NestedClass.INestedInterfaceNestedInClass.Foo() { return 110; } + int INestedInterfaceComImport_ComImport.Foo() { return 111; } + int INestedInterfaceVisibleTrue_ComImport.Foo() { return 112; } + int INestedInterfaceVisibleFalse_ComImport.Foo() { return 113; } + int INestedInterfaceVisibleTrue_VisibleTrue.Foo() { return 114; } + int INestedInterfaceVisibleFalse_VisibleTrue.Foo() { return 115; } + int INestedInterfaceVisibleTrue_VisibleFalse.Foo() { return 116; } + int INestedInterfaceNotPublic_VisibleTrue.Foo() { return 117; } + + int Foo() { return 19; } + } + + /// + /// Nested class not visible with ComVisible(false). + /// + [ComVisible(false)] + [Guid("6DF17EC1-A8F4-4693-B195-EDB27DF00170")] + public sealed class NestedClassVisibleFalseServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic + { + int INestedInterfaceComImport.Foo() { return 20; } + int INestedInterfaceVisibleTrue.Foo() { return 21; } + int INestedInterfaceVisibleFalse.Foo() { return 22; } + int INestedInterfaceWithoutVisible.Foo() { return 23; } + int INestedInterfaceNotPublic.Foo() { return 24; } + int Foo() { return 29; } + } + + /// + /// Nested class not visible without ComVisible(). + /// + [Guid("A57430B8-E0C1-486E-AE57-A15D6A729F99")] + public sealed class NestedClassWithoutVisibleServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic + { + int INestedInterfaceComImport.Foo() { return 30; } + int INestedInterfaceVisibleTrue.Foo() { return 31; } + int INestedInterfaceVisibleFalse.Foo() { return 32; } + int INestedInterfaceWithoutVisible.Foo() { return 33; } + int INestedInterfaceNotPublic.Foo() { return 34; } + int Foo() { return 39; } + } + + /// + /// Generic visible nested class with ComVisible(true). + /// + [ComVisible(true)] + [Guid("CAFBD2FF-710A-4E83-9229-42FA16963424")] + public sealed class NestedClassGenericServer : INestedInterfaceVisibleTrue, INestedInterfaceGenericVisibleTrue, INestedInterfaceComImport + { + int INestedInterfaceComImport.Foo() { return 40; } + int INestedInterfaceVisibleTrue.Foo() { return 41; } + T INestedInterfaceGenericVisibleTrue.Foo() { return default(T); } + T Foo() { return default(T); } + } + + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceWithoutVisible([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotPublic([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrueNoGuid([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotVisibleNoGuid([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceGenericVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceComImport_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_VisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotPublic_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceWithoutVisible([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNotPublic([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNestedInClass([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceGenericVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceComImport_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_VisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNotPublic_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + /// + /// Test case set for ComVisible. The assembly is set as [assembly: ComVisible(false)] + /// + /// + private static void RunComVisibleTests() + { + int fooSuccessVal = 0; + // + // Tests for class with ComVisible(true) + // + Console.WriteLine("Class with ComVisible(true)"); + ClassVisibleTrueServer visibleBaseClass = new ClassVisibleTrueServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(1, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(2, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceWithoutVisible((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(4, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrueNoGuid"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrueNoGuid((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(6, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotVisibleNoGuid"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceNotVisibleNoGuid((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(16, fooSuccessVal, "COM method didn't return the expected value."); + + // + // Tests for nested Interface in a class with ComVisible(true) + // + Console.WriteLine("Nested Interface in a class with ComVisible(true)"); + + Console.WriteLine("CCWTest_InterfaceComImport_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport_ComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(101, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_ComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(102, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse_ComImport"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse_ComImport((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_VisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(104, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_VisibleFalse"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_VisibleFalse((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(106, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for class with ComVisible(false) + // + Console.WriteLine("Class with ComVisible(false)"); + ClassVisibleFalseServer visibleFalseBaseClass = new ClassVisibleFalseServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)visibleFalseBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(120, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)visibleFalseBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(121, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)visibleFalseBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceWithoutVisible((object)visibleFalseBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(123, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)visibleFalseBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for class without ComVisible() + // + Console.WriteLine("Class without ComVisible()"); + ClassWithoutVisibleServer withoutVisibleBaseClass = new ClassWithoutVisibleServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)withoutVisibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(130, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)withoutVisibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(131, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)withoutVisibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceWithoutVisible((object)withoutVisibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(133, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)withoutVisibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + + // + // Tests for generic class with ComVisible(true) + // + Console.WriteLine("Generic class with ComVisible(true)"); + ClassGenericServer genericServer = new ClassGenericServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)genericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(140, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)genericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(141, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceGenericVisibleTrue"); + Assert.AreEqual(Helpers.COR_E_INVALIDOPERATION, CCWTest_InterfaceGenericVisibleTrue((object)genericServer, out fooSuccessVal), "Returned diferent exception than the expected COR_E_INVALIDOPERATION."); + + // + // Tests for nested class with ComVisible(true) + // + Console.WriteLine("Nested class with ComVisible(true)"); + NestedClassVisibleTrueServer visibleNestedBaseClass = new NestedClassVisibleTrueServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(10, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(11, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceWithoutVisible((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(13, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested Interface in a nested class with ComVisible(true) + // + Console.WriteLine("Nested Interface in a nested class with ComVisible(true)"); + + Console.WriteLine("CCWTest_NestedInterfaceNestedInClass"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceNestedInClass((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(110, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceComImport_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(111, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(112, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse_ComImport"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_VisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(114, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_VisibleFalse"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_VisibleFalse((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(116, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested class with ComVisible(false) + // + Console.WriteLine("Nested class with ComVisible(false)"); + NestedClassVisibleFalseServer visibleFalseNestedBaseClass = new NestedClassVisibleFalseServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)visibleFalseNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(20, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)visibleFalseNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(21, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)visibleFalseNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceWithoutVisible((object)visibleFalseNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(23, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)visibleFalseNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested class without ComVisible() + // + Console.WriteLine("Nested class without ComVisible()"); + NestedClassWithoutVisibleServer withoutVisibleNestedBaseClass = new NestedClassWithoutVisibleServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(30, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(31, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceWithoutVisible((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(33, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for generic nested class with ComVisible(true) + // + Console.WriteLine("Nested generic class with ComVisible(true)"); + NestedClassGenericServer nestedGenericServer = new NestedClassGenericServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)nestedGenericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(40, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)nestedGenericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(41, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceGenericVisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceGenericVisibleTrue((object)nestedGenericServer, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + } + + public static int Main() + { + try + { + RunComVisibleTests(); + + return 100; + } + catch (Exception e) + { + Console.WriteLine($"Test Failure: {e}"); + return 101; + } + } +} diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyWithoutComVisible/AssemblyWithoutComVisibleTest.csproj b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyWithoutComVisible/AssemblyWithoutComVisibleTest.csproj new file mode 100644 index 0000000..7be7e30 --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/AssemblyWithoutComVisible/AssemblyWithoutComVisibleTest.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + AssemblyWithoutComVisibleTest + 2.0 + {F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\..\ + $(DefineConstants);STATIC + + true + true + + + + + + + False + + + + + + + + + + + + + + + diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/CMakeLists.txt b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/CMakeLists.txt new file mode 100644 index 0000000..db15381 --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/CMakeLists.txt @@ -0,0 +1,13 @@ +#VCXPROJ +cmake_minimum_required (VERSION 2.6) +project (ComVisibleNative) +include ("${CLR_INTEROP_TEST_ROOT}/Interop.cmake") +include_directories(${INC_PLATFORM_DIR}) +set(SOURCES + ComVisibleNative.cpp +) +# Additional files to reference: +# add the executable +add_library (ComVisibleNative SHARED ${SOURCES}) +# add the install targets +install (TARGETS ComVisibleNative DESTINATION bin) diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/ComVisibleNative.cpp b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/ComVisibleNative.cpp new file mode 100644 index 0000000..c674f66 --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/ComVisibleNative.cpp @@ -0,0 +1,518 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +#include +#include +#include +#include +#include + +// +// Standard function to call the managed COM. +// +template class CCWTestTemplate +{ +public: + static HRESULT CallManagedCom(IUnknown* pUnk, int* fooSuccessVal) + { + T *pTargetInterface = NULL; + (*fooSuccessVal) = -1; + + HRESULT hr = pUnk->QueryInterface(_uuidof(T), reinterpret_cast(&pTargetInterface)); + if (FAILED(hr)) + return hr; + + hr = pTargetInterface->Foo(fooSuccessVal); + pTargetInterface->Release(); + + return hr; + } +}; + + +// +// Non Nested Interface: +// + +// +// IInterfaceComImport +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("52E5F852-BD3E-4DF2-8826-E1EC39557943")) IInterfaceComImport : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceComImport(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("8FDE13DC-F917-44FF-AAC8-A638FD27D647")) IInterfaceVisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleFalse +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("0A2EF649-371D-4480-B0C7-07F455C836D3")) IInterfaceVisibleFalse : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleFalse(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceWithoutVisible +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("FB504D72-39C4-457F-ACF4-3E5D8A31AAE4")) IInterfaceWithoutVisible : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceWithoutVisible(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceNotPublic +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("11320010-13FA-4B40-8580-8CF92EE70774")) IInterfaceNotPublic : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceNotPublic(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleTrueNoGuid +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("ad50a327-d23a-38a4-9d6e-b32b32acf572")) IInterfaceVisibleTrueNoGuid : IUnknown +{ + STDMETHOD(Foo1)(int* fooSuccessVal) = 0; + STDMETHOD(Foo)(int* fooSuccessVal) = 0; + STDMETHOD(Foo2)(int* fooSuccessVal) = 0; + STDMETHOD(Foo3)(int* fooSuccessVal) = 0; + STDMETHOD(Foo4)(int* fooSuccessVal) = 0; + STDMETHOD(Foo5)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleTrueNoGuid(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleTrueNoGuidGenericInterface +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("384f0b5c-28d0-368c-8c7e-5e31a84a5c84")) IInterfaceVisibleTrueNoGuidGenericInterface : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; + STDMETHOD(Foo9)(int* fooSuccessVal, int listInt[]) = 0; + STDMETHOD(Foo10)(int* fooSuccessVal, void* intCollection, void* stringCollection) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleTrueNoGuidGenericInterface(IUnknown* pUnk, int* fooSuccessVal) +{ + IInterfaceVisibleTrueNoGuidGenericInterface *pTargetInterface = NULL; + (*fooSuccessVal) = -1; + + HRESULT hr = pUnk->QueryInterface(_uuidof(IInterfaceVisibleTrueNoGuidGenericInterface), reinterpret_cast(&pTargetInterface)); + if (FAILED(hr)) + return hr; + + hr = pTargetInterface->Foo(fooSuccessVal); + if (FAILED(hr)) + { + pTargetInterface->Release(); + return hr; + } + + hr = pTargetInterface->Foo9(fooSuccessVal, NULL); + if (FAILED(hr)) + pTargetInterface->Release(); + else + hr = (HRESULT)(pTargetInterface->Release()); + + return hr; +} + +// +// IInterfaceNotVisibleNoGuid +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("b45587ec-9671-35bc-8b8e-f6bfb18a4d3a")) IInterfaceNotVisibleNoGuid : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceNotVisibleNoGuid(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + + +// +// IInterfaceGenericVisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("BA4B32D4-1D73-4605-AD0A-900A31E75BC3")) IInterfaceGenericVisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceGenericVisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceComImport_ComImport +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("943759D7-3552-43AD-9C4D-CC2F787CF36E")) IInterfaceComImport_ComImport : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceComImport_ComImport(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleTrue_ComImport +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("75DE245B-0CE3-4B07-8761-328906C750B7")) IInterfaceVisibleTrue_ComImport : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleTrue_ComImport(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleFalse_ComImport +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("C73D96C3-B005-42D6-93F5-E30AEE08C66C")) IInterfaceVisibleFalse_ComImport : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleFalse_ComImport(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleTrue_VisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("60B3917B-9CC2-40F2-A975-CD6898DA697F")) IInterfaceVisibleTrue_VisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleTrue_VisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleFalse_VisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("2FC59DDB-B1D0-4678-93AF-6A48E838B705")) IInterfaceVisibleFalse_VisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleFalse_VisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceVisibleTrue_VisibleFalse +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("C82C25FC-FBAD-4EA9-BED1-343C887464B5")) IInterfaceVisibleTrue_VisibleFalse : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceVisibleTrue_VisibleFalse(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// IInterfaceNotPublic_VisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("8A4C1691-5615-4762-8568-481DC671F9CE")) IInterfaceNotPublic_VisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_InterfaceNotPublic_VisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + + +// +// Nested Interfaces: +// + +// +// INestedInterfaceComImport +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("1D927BC5-1530-4B8E-A183-995425CE4A0A")) INestedInterfaceComImport : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceComImport(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceVisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("39209692-2568-4B1E-A6C8-A5C7F141D278")) INestedInterfaceVisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceVisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceVisibleFalse +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("1CE4B033-4927-447A-9F91-998357B32ADF")) INestedInterfaceVisibleFalse : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceVisibleFalse(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceWithoutVisible +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("C770422A-C363-49F1-AAA1-3EC81A452816")) INestedInterfaceWithoutVisible : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceWithoutVisible(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceNotPublic +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("F776FF8A-0673-49C2-957A-33C2576062ED")) INestedInterfaceNotPublic : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceNotPublic(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceNestedInClass +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("B31B4EC1-3B59-41C4-B3A0-CF89638CB837")) INestedInterfaceNestedInClass : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceNestedInClass(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceNestedInClassNoGuid +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("486bcec9-904d-3445-871c-e7084a52eb1a")) INestedInterfaceNestedInClassNoGuid : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceNestedInClassNoGuid(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceVisibleTrueNoGuid +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("0ea2cb33-db9f-3655-9240-47ef1dea0f1e")) INestedInterfaceVisibleTrueNoGuid : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceVisibleTrueNoGuid(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceGenericVisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("CAFBD2FF-710A-4E83-9229-42FA16963424")) INestedInterfaceGenericVisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceGenericVisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceComImport_ComImport +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("C57D849A-A1A9-4CDC-A609-789D79F9332C")) INestedInterfaceComImport_ComImport : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceComImport_ComImport(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceVisibleTrue_ComImport +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("81F28686-F257-4B7E-A47F-57C9775BE2CE")) INestedInterfaceVisibleTrue_ComImport : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceVisibleTrue_ComImport(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceVisibleFalse_ComImport +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("FAAB7E6C-8548-429F-AD34-0CEC3EBDD7B7")) INestedInterfaceVisibleFalse_ComImport : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceVisibleFalse_ComImport(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceVisibleTrue_VisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("BEFD79A9-D8E6-42E4-8228-1892298460D7")) INestedInterfaceVisibleTrue_VisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceVisibleTrue_VisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceVisibleFalse_VisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("5C497454-EA83-4F79-B990-4EB28505E801")) INestedInterfaceVisibleFalse_VisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceVisibleFalse_VisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceVisibleTrue_VisibleFalse +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("A17CF08F-EEC4-4EA5-B12C-5A603101415D")) INestedInterfaceVisibleTrue_VisibleFalse : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceVisibleTrue_VisibleFalse(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + +// +// INestedInterfaceNotPublic_VisibleTrue +// Interface definition and auxiliar function that will call the managed COM. +// +struct __declspec(uuid("40B723E9-E1BE-4F55-99CD-D2590D191A53")) INestedInterfaceNotPublic_VisibleTrue : IUnknown +{ + STDMETHOD(Foo)(int* fooSuccessVal) = 0; +}; + +extern "C" DLL_EXPORT HRESULT _stdcall CCWTest_NestedInterfaceNotPublic_VisibleTrue(IUnknown* pUnk, int* fooSuccessVal) +{ + return CCWTestTemplate::CallManagedCom(pUnk, fooSuccessVal); +} + diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Default/DefaultTest.cs b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Default/DefaultTest.cs new file mode 100644 index 0000000..dac3bbf --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Default/DefaultTest.cs @@ -0,0 +1,1024 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.InteropServices; +using System.Reflection; +using System.Collections.Generic; +using NativeCallManagedComVisible; +using TestLibrary; + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components by default. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("41DDB0BD-1E88-4B0C-BD23-FD3B7E4037A8")] + +/// +/// Interface with ComImport. +/// +[ComImport] +[Guid("52E5F852-BD3E-4DF2-8826-E1EC39557943")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceComImport +{ + int Foo(); +} + +/// +/// Interface visible with ComVisible(true). +/// +[ComVisible(true)] +[Guid("8FDE13DC-F917-44FF-AAC8-A638FD27D647")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue +{ + int Foo(); +} + +/// +/// Interface not visible with ComVisible(false). +/// +[ComVisible(false)] +[Guid("0A2EF649-371D-4480-B0C7-07F455C836D3")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse +{ + int Foo(); +} + +/// +/// Interface not visible without ComVisible(). +/// +[Guid("FB504D72-39C4-457F-ACF4-3E5D8A31AAE4")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceWithoutVisible +{ + int Foo(); +} + +/// +/// Interface not public. +/// +[ComVisible(true)] +[Guid("11320010-13FA-4B40-8580-8CF92EE70774")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +interface IInterfaceNotPublic +{ + int Foo(); +} + +/// +/// Generic interface with ComVisible(true). +/// +[ComVisible(true)] +[Guid("BA4B32D4-1D73-4605-AD0A-900A31E75BC3")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceGenericVisibleTrue +{ + T Foo(); +} + +/// +/// Generic class for guid generator. +/// +public class GenericClassW2Pars +{ + T1 Foo(T2 a) { return default(T1); } +} + +/// +/// Derived interface visible with ComVisible(true) and GUID. +/// +[ComVisible(true)] +[Guid("FE62A5B9-34C4-4EAF-AF0A-1AD390B15BDB")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IDerivedInterfaceVisibleTrueGuid +{ + int Foo(); +} + +/// +/// Derived interface visible with ComVisible(true) wothout GUID. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IDerivedInterfaceVisibleTrueNoGuid +{ + int Foo1(UInt16 int16Val, bool boolVal); + int Foo5(Int32 int32Val); +} + +/// +/// Derived interface without visibility and without GUID. +/// +public interface IDerivedInterfaceWithoutVisibleNoGuid +{ + int Foo7(Int32 int32Val); +} + +/// +/// Interface visible with ComVisible(true) and without Custom Attribute Guid. +/// Note that in this test, change the method sequence in the interface will +/// change the GUID and could reduce the test efficiency. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrueNoGuid : IDerivedInterfaceVisibleTrueGuid, IDerivedInterfaceVisibleTrueNoGuid, IDerivedInterfaceWithoutVisibleNoGuid +{ + new int Foo1(UInt16 int16Val, bool boolVal); + new int Foo(); + int Foo2(string str, out int outIntVal, IntPtr intPtrVal, int[] arrayVal, byte inByteVal = 0, int inIntVal = 0); + int Foo3(ref short refShortVal, params byte[] paramsList); + int Foo4(ref List refShortVal, GenericClassW2Pars genericClass, params object[] paramsList); +} + +/// +/// Interface not visible and without Custom Attribute Guid. +/// +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceNotVisibleNoGuid +{ + int Foo(); +} + +/// +/// Interface visible with ComVisible(true), without Custom Attribute Guid and a generic method. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrueNoGuidGeneric +{ + int Foo(T genericVal); +} + +/// +/// Interface visible with ComVisible(true), without Custom Attribute Guid and a method with a parameter which is a generic interface. +/// +[ComVisible(true)] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrueNoGuidGenericInterface +{ + int Foo(); + int Foo9(List listInt); + int Foo10(ICollection intCollection, ICollection stringCollection); +} + +/// +/// Interface with ComImport derived from an interface with ComImport. +/// +[ComImport] +[Guid("943759D7-3552-43AD-9C4D-CC2F787CF36E")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceComImport_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComImport. +/// +[ComVisible(true)] +[Guid("75DE245B-0CE3-4B07-8761-328906C750B7")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(false) derived from an interface with ComImport. +/// +[ComVisible(false)] +[Guid("C73D96C3-B005-42D6-93F5-E30AEE08C66C")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse_ComImport : IInterfaceComImport +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComVisible(true). +/// +[ComVisible(true)] +[Guid("60B3917B-9CC2-40F2-A975-CD6898DA697F")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(false) derived from an interface with ComVisible(true). +/// +[ComVisible(false)] +[Guid("2FC59DDB-B1D0-4678-93AF-6A48E838B705")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleFalse_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an interface with ComVisible(false). +/// +[ComVisible(true)] +[Guid("C82C25FC-FBAD-4EA9-BED1-343C887464B5")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +public interface IInterfaceVisibleTrue_VisibleFalse : IInterfaceVisibleFalse +{ + new int Foo(); +} + +/// +/// Interface with ComVisible(true) derived from an not public interface. +/// +[ComVisible(true)] +[Guid("8A4C1691-5615-4762-8568-481DC671F9CE")] +[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] +interface IInterfaceNotPublic_VisibleTrue : IInterfaceVisibleTrue +{ + new int Foo(); +} + + +/// +/// Class visible with ComVisible(true). +/// +[ComVisible(true)] +[Guid("48FC2EFC-C7ED-4E02-8D02-F05B6A439FC9")] +public sealed class ClassVisibleTrueServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic, + IInterfaceVisibleTrueNoGuid, IInterfaceNotVisibleNoGuid, IInterfaceVisibleTrueNoGuidGenericInterface, + IInterfaceComImport_ComImport, IInterfaceVisibleTrue_ComImport, IInterfaceVisibleFalse_ComImport, + IInterfaceVisibleTrue_VisibleTrue, IInterfaceVisibleFalse_VisibleTrue, IInterfaceVisibleTrue_VisibleFalse, IInterfaceNotPublic_VisibleTrue +{ + int IInterfaceComImport.Foo() { return 1; } + int IInterfaceVisibleTrue.Foo() { return 2; } + int IInterfaceVisibleFalse.Foo() { return 3; } + int IInterfaceWithoutVisible.Foo() { return 4; } + int IInterfaceNotPublic.Foo() { return 5; } + + int IInterfaceVisibleTrueNoGuid.Foo() { return 6; } + int IInterfaceVisibleTrueNoGuid.Foo1(UInt16 int16Val, bool boolVal) { return 7; } + int IInterfaceVisibleTrueNoGuid.Foo2(string str, out int outIntVal, IntPtr intPtrVal, int[] arrayVal, byte inByteVal, int inIntVal) + { + outIntVal = 10; + return 8; + } + int IInterfaceVisibleTrueNoGuid.Foo3(ref short refShortVal, params byte[] paramsList) { return 9; } + int IInterfaceVisibleTrueNoGuid.Foo4(ref List refShortVal, GenericClassW2Pars genericClass, params object[] paramsList) { return 10; } + int IDerivedInterfaceVisibleTrueGuid.Foo() { return 12; } + int IDerivedInterfaceVisibleTrueNoGuid.Foo1(UInt16 int16Val, bool boolVal) { return 13; } + int IDerivedInterfaceVisibleTrueNoGuid.Foo5(Int32 int32Val) { return 14; } + int IDerivedInterfaceWithoutVisibleNoGuid.Foo7(Int32 int32Val) { return 15; } + int IInterfaceNotVisibleNoGuid.Foo() { return 16; } + int IInterfaceVisibleTrueNoGuidGenericInterface.Foo() { return 17; } + int IInterfaceVisibleTrueNoGuidGenericInterface.Foo9(List listInt) { return 18; } + int IInterfaceVisibleTrueNoGuidGenericInterface.Foo10(ICollection intCollection, ICollection stringCollection) { return 19; } + + int IInterfaceComImport_ComImport.Foo() { return 101; } + int IInterfaceVisibleTrue_ComImport.Foo() { return 102; } + int IInterfaceVisibleFalse_ComImport.Foo() { return 103; } + int IInterfaceVisibleTrue_VisibleTrue.Foo() { return 104; } + int IInterfaceVisibleFalse_VisibleTrue.Foo() { return 105; } + int IInterfaceVisibleTrue_VisibleFalse.Foo() { return 106; } + int IInterfaceNotPublic_VisibleTrue.Foo() { return 107; } + + int Foo() { return 9; } +} + +/// +/// Class not visible with ComVisible(false). +/// +[ComVisible(false)] +[Guid("6DF17EC1-A8F4-4693-B195-EDB27DF00170")] +public sealed class ClassVisibleFalseServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic +{ + int IInterfaceComImport.Foo() { return 120; } + int IInterfaceVisibleTrue.Foo() { return 121; } + int IInterfaceVisibleFalse.Foo() { return 122; } + int IInterfaceWithoutVisible.Foo() { return 123; } + int IInterfaceNotPublic.Foo() { return 124; } + int Foo() { return 129; } +} + +/// +/// Class not visible without ComVisible(). +/// +[Guid("A57430B8-E0C1-486E-AE57-A15D6A729F99")] +public sealed class ClassWithoutVisibleServer : + IInterfaceComImport, IInterfaceVisibleTrue, IInterfaceVisibleFalse, IInterfaceWithoutVisible, IInterfaceNotPublic +{ + int IInterfaceComImport.Foo() { return 130; } + int IInterfaceVisibleTrue.Foo() { return 131; } + int IInterfaceVisibleFalse.Foo() { return 132; } + int IInterfaceWithoutVisible.Foo() { return 133; } + int IInterfaceNotPublic.Foo() { return 134; } + int Foo() { return 139; } +} + +/// +/// Generic visible class with ComVisible(true). +/// +[ComVisible(true)] +[Guid("3CD290FA-1CD0-4370-B8E6-5A573F78C9F7")] +public sealed class ClassGenericServer : IInterfaceVisibleTrue, IInterfaceGenericVisibleTrue, IInterfaceComImport +{ + int IInterfaceComImport.Foo() { return 140; } + int IInterfaceVisibleTrue.Foo() { return 141; } + T IInterfaceGenericVisibleTrue.Foo() { return default(T); } + T Foo() { return default(T); } +} + +/// +/// Class visible with ComVisible(true) and without Custom Attribute Guid. +/// Note that in this test, change the method sequence in the interface will +/// change the GUID and could broke the test or reduce the test efficiency. +/// +[ComVisible(true)] +[Guid("afb3aafc-75bc-35d3-be41-a399c2701929")] +public sealed class ClassVisibleTrueServerNoGuid : IInterfaceVisibleTrue +{ + int IInterfaceVisibleTrue.Foo() { return 150; } + + private int privateVal; +} + +public class ComVisibleServer +{ + /// + /// Nested interface with ComImport. + /// + [ComImport] + [Guid("1D927BC5-1530-4B8E-A183-995425CE4A0A")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceComImport + { + int Foo(); + } + + /// + /// Nested interface visible with ComVisible(true). + /// + [ComVisible(true)] + [Guid("39209692-2568-4B1E-A6C8-A5C7F141D278")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue + { + int Foo(); + } + + /// + /// Nested interface not visible with ComVisible(false). + /// + [ComVisible(false)] + [Guid("1CE4B033-4927-447A-9F91-998357B32ADF")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse + { + int Foo(); + } + + /// + /// Nested interface not visible without ComVisible(). + /// + [Guid("C770422A-C363-49F1-AAA1-3EC81A452816")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceWithoutVisible + { + int Foo(); + } + + /// + /// Nested interface not public. + /// + [ComVisible(true)] + [Guid("F776FF8A-0673-49C2-957A-33C2576062ED")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface INestedInterfaceNotPublic + { + int Foo(); + } + + /// + /// Nested visible interface with ComVisible(true). + /// + public class NestedClass + { + [ComVisible(true)] + [Guid("B31B4EC1-3B59-41C4-B3A0-CF89638CB837")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceNestedInClass + { + int Foo(); + } + + [ComVisible(true)] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceNestedInClassNoGuid + { + int Foo(); + } + } + + /// + /// Generic interface with ComVisible(true). + /// + [ComVisible(true)] + [Guid("D7A8A196-5D85-4C85-94E4-8344ED2C7277")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceGenericVisibleTrue + { + T Foo(); + } + + /// + /// Nested interface with ComImport derived from an interface with ComImport. + /// + [ComImport] + [Guid("C57D849A-A1A9-4CDC-A609-789D79F9332C")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceComImport_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComImport. + /// + [ComVisible(true)] + [Guid("81F28686-F257-4B7E-A47F-57C9775BE2CE")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(false) derived from an interface with ComImport. + /// + [ComVisible(false)] + [Guid("FAAB7E6C-8548-429F-AD34-0CEC3EBDD7B7")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse_ComImport : INestedInterfaceComImport + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComVisible(true). + /// + [ComVisible(true)] + [Guid("BEFD79A9-D8E6-42E4-8228-1892298460D7")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(false) derived from an interface with ComVisible(true). + /// + [ComVisible(false)] + [Guid("5C497454-EA83-4F79-B990-4EB28505E801")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleFalse_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an interface with ComVisible(false). + /// + [ComVisible(true)] + [Guid("A17CF08F-EEC4-4EA5-B12C-5A603101415D")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrue_VisibleFalse : INestedInterfaceVisibleFalse + { + new int Foo(); + } + + /// + /// Nested interface with ComVisible(true) derived from an not public interface. + /// + [ComVisible(true)] + [Guid("40B723E9-E1BE-4F55-99CD-D2590D191A53")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface INestedInterfaceNotPublic_VisibleTrue : INestedInterfaceVisibleTrue + { + new int Foo(); + } + + /// + /// Nested interface visible with ComVisible(true) without Guid. + /// + [ComVisible(true)] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface INestedInterfaceVisibleTrueNoGuid + { + int Foo(); + } + + + /// + /// Nested class visible with ComVisible(true). + /// + [ComVisible(true)] + [Guid("CF681980-CE6D-421E-8B21-AEAE3F1B7DAC")] + public sealed class NestedClassVisibleTrueServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic, + INestedInterfaceVisibleTrueNoGuid, NestedClass.INestedInterfaceNestedInClassNoGuid, + NestedClass.INestedInterfaceNestedInClass, INestedInterfaceComImport_ComImport, INestedInterfaceVisibleTrue_ComImport, INestedInterfaceVisibleFalse_ComImport, + INestedInterfaceVisibleTrue_VisibleTrue, INestedInterfaceVisibleFalse_VisibleTrue, INestedInterfaceVisibleTrue_VisibleFalse, INestedInterfaceNotPublic_VisibleTrue + { + int INestedInterfaceComImport.Foo() { return 10; } + int INestedInterfaceVisibleTrue.Foo() { return 11; } + int INestedInterfaceVisibleFalse.Foo() { return 12; } + int INestedInterfaceWithoutVisible.Foo() { return 13; } + int INestedInterfaceNotPublic.Foo() { return 14; } + + int INestedInterfaceVisibleTrueNoGuid.Foo() { return 50; } + int NestedClass.INestedInterfaceNestedInClassNoGuid.Foo() { return 51; } + + int NestedClass.INestedInterfaceNestedInClass.Foo() { return 110; } + int INestedInterfaceComImport_ComImport.Foo() { return 111; } + int INestedInterfaceVisibleTrue_ComImport.Foo() { return 112; } + int INestedInterfaceVisibleFalse_ComImport.Foo() { return 113; } + int INestedInterfaceVisibleTrue_VisibleTrue.Foo() { return 114; } + int INestedInterfaceVisibleFalse_VisibleTrue.Foo() { return 115; } + int INestedInterfaceVisibleTrue_VisibleFalse.Foo() { return 116; } + int INestedInterfaceNotPublic_VisibleTrue.Foo() { return 117; } + + int Foo() { return 19; } + } + + /// + /// Nested class not visible with ComVisible(false). + /// + [ComVisible(false)] + [Guid("6DF17EC1-A8F4-4693-B195-EDB27DF00170")] + public sealed class NestedClassVisibleFalseServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic + { + int INestedInterfaceComImport.Foo() { return 20; } + int INestedInterfaceVisibleTrue.Foo() { return 21; } + int INestedInterfaceVisibleFalse.Foo() { return 22; } + int INestedInterfaceWithoutVisible.Foo() { return 23; } + int INestedInterfaceNotPublic.Foo() { return 24; } + int Foo() { return 29; } + } + + /// + /// Nested class not visible without ComVisible(). + /// + [Guid("A57430B8-E0C1-486E-AE57-A15D6A729F99")] + public sealed class NestedClassWithoutVisibleServer : + INestedInterfaceComImport, INestedInterfaceVisibleTrue, INestedInterfaceVisibleFalse, INestedInterfaceWithoutVisible, INestedInterfaceNotPublic + { + int INestedInterfaceComImport.Foo() { return 30; } + int INestedInterfaceVisibleTrue.Foo() { return 31; } + int INestedInterfaceVisibleFalse.Foo() { return 32; } + int INestedInterfaceWithoutVisible.Foo() { return 33; } + int INestedInterfaceNotPublic.Foo() { return 34; } + int Foo() { return 39; } + } + + /// + /// Generic visible nested class with ComVisible(true). + /// + [ComVisible(true)] + [Guid("CAFBD2FF-710A-4E83-9229-42FA16963424")] + public sealed class NestedClassGenericServer : INestedInterfaceVisibleTrue, INestedInterfaceGenericVisibleTrue, INestedInterfaceComImport + { + int INestedInterfaceComImport.Foo() { return 40; } + int INestedInterfaceVisibleTrue.Foo() { return 41; } + T INestedInterfaceGenericVisibleTrue.Foo() { return default(T); } + T Foo() { return default(T); } + } + + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceWithoutVisible([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotPublic([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrueNoGuid([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrueNoGuidGenericInterface([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotVisibleNoGuid([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceGenericVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceComImport_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleFalse_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceVisibleTrue_VisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_InterfaceNotPublic_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceWithoutVisible([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNotPublic([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNestedInClass([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNestedInClassNoGuid([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrueNoGuid([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceGenericVisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceComImport_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse_ComImport([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleFalse_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceVisibleTrue_VisibleFalse([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + [DllImport("ComVisibleNative")] + public static extern int CCWTest_NestedInterfaceNotPublic_VisibleTrue([MarshalAs(UnmanagedType.IUnknown)] object unk, out int fooSuccessVal); + + /// + /// Test case set for ComVisible. The assembly is set as [assembly: ComVisible(false)] + /// + /// + private static void RunComVisibleTests() + { + int fooSuccessVal = 0; + // + // Tests for class with ComVisible(true) + // + Console.WriteLine("Class with ComVisible(true)"); + ClassVisibleTrueServer visibleBaseClass = new ClassVisibleTrueServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(1, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(2, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceWithoutVisible((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrueNoGuid"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrueNoGuid((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(6, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrueNoGuidGenericInterface"); + Assert.AreEqual(Helpers.COR_E_GENERICMETHOD, CCWTest_InterfaceVisibleTrueNoGuidGenericInterface((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceNotVisibleNoGuid"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotVisibleNoGuid((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested Interface in a class with ComVisible(true) + // + Console.WriteLine("Nested Interface in a class with ComVisible(true)"); + + Console.WriteLine("CCWTest_InterfaceComImport_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport_ComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(101, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_ComImport((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(102, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse_ComImport"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse_ComImport((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_VisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(104, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue_VisibleFalse"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue_VisibleFalse((object)visibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(106, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceNotPublic_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic_VisibleTrue((object)visibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for class with ComVisible(false) + // + Console.WriteLine("Class with ComVisible(false)"); + ClassVisibleFalseServer visibleFalseBaseClass = new ClassVisibleFalseServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)visibleFalseBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(120, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)visibleFalseBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(121, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)visibleFalseBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceWithoutVisible((object)visibleFalseBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)visibleFalseBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for class without ComVisible() + // + Console.WriteLine("Class without ComVisible()"); + ClassWithoutVisibleServer withoutVisibleBaseClass = new ClassWithoutVisibleServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)withoutVisibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(130, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)withoutVisibleBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(131, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceVisibleFalse((object)withoutVisibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceWithoutVisible"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceWithoutVisible((object)withoutVisibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_InterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_InterfaceNotPublic((object)withoutVisibleBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for generic class with ComVisible(true) + // + Console.WriteLine("Generic class with ComVisible(true)"); + ClassGenericServer genericServer = new ClassGenericServer(); + + Console.WriteLine("CCWTest_InterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceComImport((object)genericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(140, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)genericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(141, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_InterfaceGenericVisibleTrue"); + Assert.AreEqual(Helpers.COR_E_INVALIDOPERATION, CCWTest_InterfaceGenericVisibleTrue((object)genericServer, out fooSuccessVal), "Returned diferent exception than the expected COR_E_INVALIDOPERATION."); + + // + // Tests for nested class with ComVisible(true) + // + Console.WriteLine("Nested class with ComVisible(true)"); + NestedClassVisibleTrueServer visibleNestedBaseClass = new NestedClassVisibleTrueServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(10, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(11, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceWithoutVisible((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested Interface in a nested class with ComVisible(true) + // + Console.WriteLine("Nested Interface in a nested class with ComVisible(true)"); + + Console.WriteLine("CCWTest_NestedInterfaceNestedInClass"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceNestedInClass((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(110, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrueNoGuid"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrueNoGuid((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(50, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNestedInClassNoGuid"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceNestedInClassNoGuid((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(51, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceComImport_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(111, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_ComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(112, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse_ComImport"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse_ComImport((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_VisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(114, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue_VisibleFalse"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue_VisibleFalse((object)visibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(116, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic_VisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic_VisibleTrue((object)visibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested class with ComVisible(false) + // + Console.WriteLine("Nested class with ComVisible(false)"); + NestedClassVisibleFalseServer visibleFalseNestedBaseClass = new NestedClassVisibleFalseServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)visibleFalseNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(20, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)visibleFalseNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(21, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)visibleFalseNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceWithoutVisible((object)visibleFalseNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)visibleFalseNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for nested class without ComVisible() + // + Console.WriteLine("Nested class without ComVisible()"); + NestedClassWithoutVisibleServer withoutVisibleNestedBaseClass = new NestedClassWithoutVisibleServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(30, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(31, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleFalse"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceVisibleFalse((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceWithoutVisible"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceWithoutVisible((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + Console.WriteLine("CCWTest_NestedInterfaceNotPublic"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceNotPublic((object)withoutVisibleNestedBaseClass, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for generic nested class with ComVisible(true) + // + Console.WriteLine("Nested generic class with ComVisible(true)"); + NestedClassGenericServer nestedGenericServer = new NestedClassGenericServer(); + + Console.WriteLine("CCWTest_NestedInterfaceComImport"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceComImport((object)nestedGenericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(40, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_NestedInterfaceVisibleTrue((object)nestedGenericServer, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(41, fooSuccessVal, "COM method didn't return the expected value."); + + Console.WriteLine("CCWTest_NestedInterfaceGenericVisibleTrue"); + Assert.AreEqual(Helpers.E_NOINTERFACE, CCWTest_NestedInterfaceGenericVisibleTrue((object)nestedGenericServer, out fooSuccessVal), "Returned diferent exception than the expected E_NOINTERFACE."); + + // + // Tests for class with ComVisible(true) without Custom Attribute Guid. + // + Console.WriteLine("Class with ComVisible(true) without GUID"); + ClassVisibleTrueServerNoGuid visibleBaseClassNoGuid = new ClassVisibleTrueServerNoGuid(); + + Console.WriteLine("CCWTest_InterfaceVisibleTrue"); + Assert.AreEqual(Helpers.S_OK, CCWTest_InterfaceVisibleTrue((object)visibleBaseClassNoGuid, out fooSuccessVal), "COM method thrown an unexpected exception."); + Assert.AreEqual(150, fooSuccessVal, "COM method didn't return the expected value."); + + // + // Tests for get the GetTypeInfo().GUID for Interface and class without Custom Attribute Guid. + // + Console.WriteLine("GetTypeInfo().GUID for Interface and Class without GUID"); + + Console.WriteLine("IInterfaceVisibleTrueNoGuid.GUID"); + Assert.AreEqual(new Guid("ad50a327-d23a-38a4-9d6e-b32b32acf572"), typeof(IInterfaceVisibleTrueNoGuid).GetTypeInfo().GUID, + typeof(IInterfaceVisibleTrueNoGuid).GetTypeInfo() + " returns a wrong GUID {" + typeof(IInterfaceVisibleTrueNoGuid).GetTypeInfo().GUID + "}"); + + Console.WriteLine("IInterfaceNotVisibleNoGuid.GUID"); + Assert.AreEqual(new Guid("b45587ec-9671-35bc-8b8e-f6bfb18a4d3a"), typeof(IInterfaceNotVisibleNoGuid).GetTypeInfo().GUID, + typeof(IInterfaceNotVisibleNoGuid).GetTypeInfo() + " returns a wrong GUID {" + typeof(IInterfaceNotVisibleNoGuid).GetTypeInfo().GUID + "}"); + + Console.WriteLine("IDerivedInterfaceVisibleTrueNoGuid.GUID"); + Assert.AreEqual(new Guid("c3f73319-f6b3-3ef6-a095-8cb04fb8cf8b"), typeof(IDerivedInterfaceVisibleTrueNoGuid).GetTypeInfo().GUID, + typeof(IDerivedInterfaceVisibleTrueNoGuid).GetTypeInfo() + " returns a wrong GUID {" + typeof(IDerivedInterfaceVisibleTrueNoGuid).GetTypeInfo().GUID + "}"); + + Console.WriteLine("IInterfaceVisibleTrueNoGuidGeneric.GUID"); + Assert.AreEqual(new Guid("50c0a59c-b6e1-36dd-b488-a905b54910d4"), typeof(IInterfaceVisibleTrueNoGuidGeneric).GetTypeInfo().GUID, + typeof(IInterfaceVisibleTrueNoGuidGeneric).GetTypeInfo() + " returns a wrong GUID {" + typeof(IInterfaceVisibleTrueNoGuidGeneric).GetTypeInfo().GUID + "}"); + + Console.WriteLine("IInterfaceVisibleTrueNoGuidGenericInterface.GUID"); + Assert.AreEqual(new Guid("384f0b5c-28d0-368c-8c7e-5e31a84a5c84"), typeof(IInterfaceVisibleTrueNoGuidGenericInterface).GetTypeInfo().GUID, + typeof(IInterfaceVisibleTrueNoGuidGenericInterface).GetTypeInfo() + " returns a wrong GUID {" + typeof(IInterfaceVisibleTrueNoGuidGenericInterface).GetTypeInfo().GUID + "}"); + + Console.WriteLine("ClassVisibleTrueServerNoGuid.GUID"); + Assert.AreEqual(new Guid("afb3aafc-75bc-35d3-be41-a399c2701929"), typeof(ClassVisibleTrueServerNoGuid).GetTypeInfo().GUID, + typeof(ClassVisibleTrueServerNoGuid).GetTypeInfo() + " returns a wrong GUID {" + typeof(ClassVisibleTrueServerNoGuid).GetTypeInfo().GUID + "}"); + + Console.WriteLine("INestedInterfaceNestedInClassNoGuid.GUID"); + Assert.AreEqual(new Guid("486bcec9-904d-3445-871c-e7084a52eb1a"), typeof(NestedClass.INestedInterfaceNestedInClassNoGuid).GetTypeInfo().GUID, + typeof(NestedClass.INestedInterfaceNestedInClassNoGuid).GetTypeInfo() + " returns a wrong GUID {" + typeof(NestedClass.INestedInterfaceNestedInClassNoGuid).GetTypeInfo().GUID + "}"); + + Console.WriteLine("INestedInterfaceVisibleTrueNoGuid.GUID"); + Assert.AreEqual(new Guid("0ea2cb33-db9f-3655-9240-47ef1dea0f1e"), typeof(INestedInterfaceVisibleTrueNoGuid).GetTypeInfo().GUID, + typeof(INestedInterfaceVisibleTrueNoGuid).GetTypeInfo() + " returns a wrong GUID {" + typeof(INestedInterfaceVisibleTrueNoGuid).GetTypeInfo().GUID + "}"); + } + + public static int Main() + { + try + { + RunComVisibleTests(); + + return 100; + } + catch (Exception e) + { + Console.WriteLine($"Test Failure: {e}"); + return 101; + } + } +} diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Default/DefaultTest.csproj b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Default/DefaultTest.csproj new file mode 100644 index 0000000..e3cb2fa --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Default/DefaultTest.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + DefaultTest + 2.0 + {F1E66554-8C8E-4141-85CF-D0CD6A0CD0B0} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\..\ + $(DefineConstants);STATIC + + true + true + + + + + + + False + + + + + + + + + + + + + + + diff --git a/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Helpers.cs b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Helpers.cs new file mode 100644 index 0000000..47d7753 --- /dev/null +++ b/tests/src/Interop/PInvoke/NativeCallManagedComVisible/Helpers.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace NativeCallManagedComVisible +{ + public static class Helpers + { + public static int S_OK = 0; + public static int E_NOINTERFACE = unchecked((int)0x80004002); + public static int COR_E_INVALIDOPERATION = unchecked((int)0x80131509); + public static int COR_E_GENERICMETHOD = unchecked((int)0x80131535); + } +}