Remove Thread.[Abort|Suspend|Resume] from TvOS/WatchOS.
[mono.git] / mcs / class / corlib / Test / System.Reflection / MethodInfoTest.cs
index ac30bc8e5c90019ffd6d17734ce20c56d85c1d5b..b8a9de2b3c59a7908974d880877fdf8d4bcd2fb3 100644 (file)
@@ -64,6 +64,11 @@ namespace MonoTests.System.Reflection
                {
                }
 
+               public interface InterfaceTest
+               {
+                       void Clone ();
+               }
+
                [Test]
                public void IsDefined_AttributeType_Null ()
                {
@@ -169,9 +174,6 @@ namespace MonoTests.System.Reflection
                }
 
                [Test]
-#if ONLY_1_1
-               [Category ("NotDotNet")] // #A2 fails on MS.NET 1.x
-#endif
                public void ByrefVtypeInvoke ()
                {
                        MethodInfo mi = typeof (MethodInfoTest).GetMethod ("ByrefVtype");
@@ -203,6 +205,7 @@ namespace MonoTests.System.Reflection
                        return (int*) 0;
                }
 
+#if MONO_FEATURE_THREAD_ABORT
                [Test] // bug #81538
                public void InvokeThreadAbort ()
                {
@@ -221,6 +224,7 @@ namespace MonoTests.System.Reflection
                {
                        Thread.CurrentThread.Abort ();
                }
+#endif
 
                [Test] // bug #76541
                public void ToStringByRef ()
@@ -307,7 +311,7 @@ namespace MonoTests.System.Reflection
                [Test]
                public void GetMethodBody_Abstract ()
                {
-                       MethodBody mb = typeof (ICloneable).GetMethod ("Clone").GetMethodBody ();
+                       MethodBody mb = typeof (InterfaceTest).GetMethod ("Clone").GetMethodBody ();
                        Assert.IsNull (mb);
                }
 
@@ -359,14 +363,20 @@ namespace MonoTests.System.Reflection
 
                        IList<LocalVariableInfo> locals = mb.LocalVariables;
 
-                       // This might break with different compilers etc.
-                       Assert.AreEqual (2, locals.Count, "#3");
-
-                       Assert.IsTrue ((locals [0].LocalType == typeof (byte[])) || (locals [1].LocalType == typeof (byte[])), "#4");
-                       if (locals [0].LocalType == typeof (byte[]))
-                               Assert.AreEqual (false, locals [0].IsPinned, "#5");
-                       else
-                               Assert.AreEqual (false, locals [1].IsPinned, "#6");
+                       bool foundPinnedBytePointer = false;
+                       unsafe {
+                               foreach (LocalVariableInfo lvi in locals) {
+                                       if (lvi.LocalType == typeof (byte[]))
+                                               // This is optimized out by CSC in .NET 4.6
+                                               Assert.IsFalse (lvi.IsPinned, "#3-1");
+
+                                       if (/* mcs */ lvi.LocalType == typeof (byte*) || /* csc */ lvi.LocalType == typeof (byte).MakeByRefType ()) {
+                                               foundPinnedBytePointer = true;
+                                               Assert.IsTrue (lvi.IsPinned, "#3-2");
+                                       }
+                               }
+                       }
+                       Assert.IsTrue (foundPinnedBytePointer, "#4");
                }
 
                public int return_parameter_test ()
@@ -398,6 +408,15 @@ namespace MonoTests.System.Reflection
                        //Assert.IsTrue (pi.IsRetval, "#3");
                }
 
+               [Test]
+               public void MethodInfoModule ()
+               {
+                       Type type = typeof (MethodInfoTest);
+                       MethodInfo me = type.GetMethod ("return_parameter_test");
+
+                       Assert.AreEqual (type.Module, me.Module);
+               }
+
                [Test]
                        public void InvokeOnRefOnlyAssembly ()
                {
@@ -727,7 +746,6 @@ namespace MonoTests.System.Reflection
                        {
                        }
                }
-#if NET_4_0
                interface IMethodInvoke<out T>
                {
                    T Test ();
@@ -751,7 +769,6 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual ("MethodInvoke", m0.Invoke (obj, new Object [0]));
                        Assert.AreEqual ("MethodInvoke", m1.Invoke (obj, new Object [0]));
                }
-#endif
 
 
                public int? Bug12856 ()
@@ -793,21 +810,44 @@ namespace MonoTests.System.Reflection
                        var type = typeof (GenericClass<>).GetMethod("Method").GetMethodBody().LocalVariables[0].LocalType;
                        Assert.AreEqual (typeofT, type);
                        Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
+               
+                       bool foundTypeOfK = false;
+                       bool foundExpectedType = false;
+           
+                       MethodBody mb = typeof (GenericClass<>).GetMethod("Method2").GetMethodBody();
+                       foreach (LocalVariableInfo lvi in mb.LocalVariables) {
+                               if (lvi.LocalType == typeofK) {
+                                       foundTypeOfK = true;
+                                       Assert.AreEqual (typeof (GenericClass<>), lvi.LocalType.DeclaringType, "#1-1");
+                               } else if (lvi.LocalType == typeofT) {
+                                       foundExpectedType = true;
+                                       Assert.AreEqual (typeof (GenericClass<>), lvi.LocalType.DeclaringType, "#1-2");
+                               }
+                       }
 
-                       type = typeof (GenericClass<>).GetMethod("Method2").GetMethodBody().LocalVariables[0].LocalType;
-                       Assert.AreEqual (typeofT, type);
-                       Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
-
-                       type = typeof (GenericClass<>).GetMethod("Method2").GetMethodBody().LocalVariables[1].LocalType;
-                       Assert.AreEqual (typeofK, type);
-                       Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
-
-                       type = typeof (GenericClass<int>).GetMethod("Method2").GetMethodBody().LocalVariables[0].LocalType;
-                       Assert.AreEqual (typeof (int), type);
-
-                       type = typeof (GenericClass<int>).GetMethod("Method2").GetMethodBody().LocalVariables[1].LocalType;
-                       Assert.AreEqual (typeofK, type);
-                       Assert.AreEqual (typeof (GenericClass<>), type.DeclaringType);
+                       Assert.IsTrue (foundTypeOfK, "#1-3");
+                       if (mb.LocalVariables.Count < 2)
+                               Assert.Ignore ("Code built in release mode - 'T var0' optmized out");
+                       else
+                               Assert.IsTrue (foundExpectedType, "#1-4");
+           
+                       foundTypeOfK = false;
+                       foundExpectedType = false;
+                       mb = typeof (GenericClass<int>).GetMethod("Method2").GetMethodBody();
+                       foreach (LocalVariableInfo lvi in mb.LocalVariables) {
+                               if (lvi.LocalType == typeofK) {
+                                       foundTypeOfK = true;
+                                       Assert.AreEqual (typeof (GenericClass<>), lvi.LocalType.DeclaringType, "#2-1");
+                               } else if (lvi.LocalType == typeof (int)) {
+                                       foundExpectedType = true;
+                               }
+                       }
+           
+                       Assert.IsTrue (foundTypeOfK, "#2-3");
+                       if (mb.LocalVariables.Count < 2)
+                               Assert.Ignore ("Code built in release mode - 'int var0' optmized out");
+                       else
+                               Assert.IsTrue (foundExpectedType, "#2-4");
                }
 #endif
        }