Add unit test for Xamarin-5278
authorEberhard Beilharz <eb1@sil.org>
Wed, 30 May 2012 15:58:26 +0000 (17:58 +0200)
committerEberhard Beilharz <eb1@sil.org>
Wed, 30 May 2012 15:58:26 +0000 (17:58 +0200)
Change-Id: Ic2d9070148b6582933a4116c288d08c176c80738

mono/tests/Makefile.am
mono/tests/bug-Xamarin-5278.cs [new file with mode: 0644]
mono/tests/libtest.c

index f1776e8458c0f16028557363972ba97fcd6aefec..7cb7c36293bed92532df0ccd241af965d62c2246 100644 (file)
@@ -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 (file)
index 0000000..d7c4c26
--- /dev/null
@@ -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;
+       }
+}
index 21c30f3ea52ad8cc5b06275e8e796c36ae0afe20..7884664568d65f9b08759dd9c9687605607a98c0 100644 (file)
@@ -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;
 }