Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add unit test for Xamarin-5278

Change-Id: Ic2d9070148b6582933a4116c288d08c176c80738
  • Loading branch information...
commit d04c37304e49da83fce620adc761e482cf3df6bb 1 parent 0ee43a1
@ermshiperete ermshiperete authored
View
1  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 \
View
171 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;
+ }
+}
View
3  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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.