From d04c37304e49da83fce620adc761e482cf3df6bb Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Wed, 30 May 2012 17:58:26 +0200 Subject: [PATCH] Add unit test for Xamarin-5278 Change-Id: Ic2d9070148b6582933a4116c288d08c176c80738 --- mono/tests/Makefile.am | 1 + mono/tests/bug-Xamarin-5278.cs | 171 +++++++++++++++++++++++++++++++++ mono/tests/libtest.c | 3 + 3 files changed, 175 insertions(+) create mode 100644 mono/tests/bug-Xamarin-5278.cs diff --git a/mono/tests/Makefile.am b/mono/tests/Makefile.am index f1776e8458c..7cb7c36293b 100644 --- a/mono/tests/Makefile.am +++ b/mono/tests/Makefile.am @@ -229,6 +229,7 @@ BASE_TEST_CS_SRC= \ bug-78656.cs \ bug-77127.cs \ bug-323114.cs \ + bug-Xamarin-5278.cs \ interlocked.cs \ cross-domain.cs \ appdomain-exit.cs \ diff --git a/mono/tests/bug-Xamarin-5278.cs b/mono/tests/bug-Xamarin-5278.cs new file mode 100644 index 00000000000..d7c4c265f37 --- /dev/null +++ b/mono/tests/bug-Xamarin-5278.cs @@ -0,0 +1,171 @@ +// +// bug-Xamarin-5278.cs +// +// Tests for System.Reflection.Binder class that require an unmanaged COM object +// (Xamarin bug 5278) +// +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +public class Tests +{ + [DllImport ("libtest")] + public static extern int mono_test_marshal_com_object_create (out IntPtr pUnk); + + [DllImport("libtest")] + public static extern bool mono_cominterop_is_supported (); + + #region Definition of COM object + [ComImport ()] + [Guid ("00000000-0000-0000-0000-000000000001")] + [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)] + public interface ITest + { + // properties need to go first since mcs puts them there + ITest Test { + [return: MarshalAs (UnmanagedType.Interface)] + [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)] + get; + } + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void SByteIn (sbyte val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void ByteIn (byte val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void ShortIn (short val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void UShortIn (ushort val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void IntIn (int val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void UIntIn (uint val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void LongIn (long val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void ULongIn (ulong val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void FloatIn (float val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void DoubleIn (double val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val); + } + + [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")] + [System.Runtime.InteropServices.ComImportAttribute ()] + [System.Runtime.InteropServices.ClassInterfaceAttribute (ClassInterfaceType.None)] + public class _TestClass : ITest + { + // properties need to go first since mcs puts them there + public virtual extern ITest Test { + [return: MarshalAs (UnmanagedType.Interface)] + [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)] + get; + } + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void SByteIn (sbyte val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void ByteIn (byte val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void ShortIn (short val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void UShortIn (ushort val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void IntIn (int val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void UIntIn (uint val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void LongIn (long val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void ULongIn (ulong val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void FloatIn (float val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void DoubleIn (double val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val); + + [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)] + public virtual extern void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val); + } + + [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")] + public class TestClass : _TestClass + { + static TestClass () + { + ExtensibleClassFactory.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject)); + ; + } + + private static System.IntPtr CreateObject (System.IntPtr aggr) + { + IntPtr pUnk3; + mono_test_marshal_com_object_create (out pUnk3); + return pUnk3; + } + } + #endregion + + public class Foo + { + public Foo (ITest test) + { + } + } + + public static bool CreateInstanceWithComObjectParameter () + { + try { + var testObj = new TestClass (); + var comObject = testObj.Test; + var assembly = Assembly.GetExecutingAssembly (); + var foo = assembly.CreateInstance (typeof(Foo).FullName, false, BindingFlags.Instance | BindingFlags.Public, + null, new object[] { comObject }, null, null); + return foo != null; + } catch (MissingMethodException) { + return false; + } + } + + public static int Main () + { + bool isWindows = !(((int)Environment.OSVersion.Platform == 4) || + ((int)Environment.OSVersion.Platform == 128)); + + if (!mono_cominterop_is_supported () && !isWindows) + return 0; + + if (!CreateInstanceWithComObjectParameter ()) + return 1; + + return 0; + } +} diff --git a/mono/tests/libtest.c b/mono/tests/libtest.c index 21c30f3ea52..7884664568d 100644 --- a/mono/tests/libtest.c +++ b/mono/tests/libtest.c @@ -3164,9 +3164,12 @@ ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk) return S_OK; } +static void create_com_object (MonoComObject** pOut); + LIBTEST_API int STDCALL get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk) { + create_com_object (ppUnk); return S_OK; } -- 2.25.1