[Microsoft.Build] Ignore ThreadAbortException in BuildNodeManager
[mono-project.git] / mono / tests / bug-Xamarin-5278.cs
blobd7c4c265f37b8b3eeea9bf43bbe3aa5b3b7704e6
1 //
2 // bug-Xamarin-5278.cs
3 //
4 // Tests for System.Reflection.Binder class that require an unmanaged COM object
5 // (Xamarin bug 5278)
6 //
7 using System;
8 using System.Reflection;
9 using System.Runtime.CompilerServices;
10 using System.Runtime.InteropServices;
12 public class Tests
14 [DllImport ("libtest")]
15 public static extern int mono_test_marshal_com_object_create (out IntPtr pUnk);
17 [DllImport("libtest")]
18 public static extern bool mono_cominterop_is_supported ();
20 #region Definition of COM object
21 [ComImport ()]
22 [Guid ("00000000-0000-0000-0000-000000000001")]
23 [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
24 public interface ITest
26 // properties need to go first since mcs puts them there
27 ITest Test {
28 [return: MarshalAs (UnmanagedType.Interface)]
29 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
30 get;
33 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
34 void SByteIn (sbyte val);
36 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
37 void ByteIn (byte val);
39 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
40 void ShortIn (short val);
42 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
43 void UShortIn (ushort val);
45 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
46 void IntIn (int val);
48 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
49 void UIntIn (uint val);
51 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
52 void LongIn (long val);
54 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
55 void ULongIn (ulong val);
57 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
58 void FloatIn (float val);
60 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
61 void DoubleIn (double val);
63 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
64 void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
66 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
67 void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
70 [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
71 [System.Runtime.InteropServices.ComImportAttribute ()]
72 [System.Runtime.InteropServices.ClassInterfaceAttribute (ClassInterfaceType.None)]
73 public class _TestClass : ITest
75 // properties need to go first since mcs puts them there
76 public virtual extern ITest Test {
77 [return: MarshalAs (UnmanagedType.Interface)]
78 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
79 get;
82 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
83 public virtual extern void SByteIn (sbyte val);
85 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
86 public virtual extern void ByteIn (byte val);
88 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
89 public virtual extern void ShortIn (short val);
91 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
92 public virtual extern void UShortIn (ushort val);
94 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
95 public virtual extern void IntIn (int val);
97 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
98 public virtual extern void UIntIn (uint val);
100 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
101 public virtual extern void LongIn (long val);
103 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
104 public virtual extern void ULongIn (ulong val);
106 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
107 public virtual extern void FloatIn (float val);
109 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
110 public virtual extern void DoubleIn (double val);
112 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
113 public virtual extern void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
115 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
116 public virtual extern void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
119 [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
120 public class TestClass : _TestClass
122 static TestClass ()
124 ExtensibleClassFactory.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject));
128 private static System.IntPtr CreateObject (System.IntPtr aggr)
130 IntPtr pUnk3;
131 mono_test_marshal_com_object_create (out pUnk3);
132 return pUnk3;
135 #endregion
137 public class Foo
139 public Foo (ITest test)
144 public static bool CreateInstanceWithComObjectParameter ()
146 try {
147 var testObj = new TestClass ();
148 var comObject = testObj.Test;
149 var assembly = Assembly.GetExecutingAssembly ();
150 var foo = assembly.CreateInstance (typeof(Foo).FullName, false, BindingFlags.Instance | BindingFlags.Public,
151 null, new object[] { comObject }, null, null);
152 return foo != null;
153 } catch (MissingMethodException) {
154 return false;
158 public static int Main ()
160 bool isWindows = !(((int)Environment.OSVersion.Platform == 4) ||
161 ((int)Environment.OSVersion.Platform == 128));
163 if (!mono_cominterop_is_supported () && !isWindows)
164 return 0;
166 if (!CreateInstanceWithComObjectParameter ())
167 return 1;
169 return 0;