Merge pull request #3528 from BrzVlad/fix-sgen-check-before-collections
[mono.git] / mcs / class / corlib / Test / System.Reflection / ParameterInfoTest.cs
index b22f46f36507cf03144467ebacdb9adedc85f3be..fb2706d575b9753db0bc5597138d7baa07c910fb 100644 (file)
@@ -14,6 +14,7 @@ using System.Reflection;
 using System.Runtime.InteropServices;
 using System.Runtime.CompilerServices;
 using System.Collections.Generic;
+using System.Linq;
 
 using NUnit.Framework;
 
@@ -72,7 +73,7 @@ namespace MonoTests.System.Reflection
                        }
                }
 
-#if NET_2_0 && !NET_2_1
+#if !MOBILE
                public enum ParamEnum {
                        None = 0,
                        Foo = 1,
@@ -83,13 +84,11 @@ namespace MonoTests.System.Reflection
                {
                }
 
-#if !TARGET_JVM // No support for extern methods in TARGET_JVM
                [DllImport ("foo")]
                public extern static void marshalAsMethod (
                        [MarshalAs(UnmanagedType.Bool)]int p0, 
                        [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] string [] p1,
                        [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")] object p2);
-#endif
                [Test]
                public void DefaultValueEnum () {
                        ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
@@ -98,14 +97,12 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (ParamEnum.Foo, info [5].DefaultValue, "#2");
                }
 
-#if NET_4_5
                [Test]
                public void HasDefaultValueEnum () {
                        ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
 
                        Assert.IsTrue (info [5].HasDefaultValue);
                }
-#endif
 
                public static void Sample2 ([DecimalConstantAttribute(2,2,2,2,2)] decimal a, [DateTimeConstantAttribute(123456)] DateTime b) {}
 
@@ -126,7 +123,6 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (pi [1].DefaultValue.GetType (), typeof (Missing), "#2");
                }
 
-#if NET_4_5
                [Test]
                public void TestHasDefaultValues ()
                {
@@ -136,7 +132,6 @@ namespace MonoTests.System.Reflection
                        Assert.IsFalse (pi [1].HasDefaultValue, "#2");
                        Assert.IsTrue (pi [2].HasDefaultValue, "#3");
                }
-#endif
 
                public void Sample (int a, [Optional] int b, object c = null)
                {
@@ -151,7 +146,6 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (1, info[3].GetCustomAttributes (typeof (OptionalAttribute), true).Length, "#A4");
                        Assert.AreEqual (2, info[4].GetCustomAttributes (true).Length, "#A5");
 
-#if !TARGET_JVM // No support for extern methods in TARGET_JVM
                        ParameterInfo[] pi = typeof (ParameterInfoTest).GetMethod ("marshalAsMethod").GetParameters ();
                        MarshalAsAttribute attr;
 
@@ -166,7 +160,6 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#D1");
                        Assert.AreEqual ("5", attr.MarshalCookie, "#D2");
                        Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#D3");
-#endif
                }
 
                [Test] // bug #342536
@@ -246,7 +239,6 @@ namespace MonoTests.System.Reflection
                {
                }
 
-#if NET_4_0
                public static void TestC (decimal u = decimal.MaxValue) {
                }
 
@@ -256,13 +248,31 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (decimal.MaxValue, info [0].DefaultValue);
                }
 
-#if NET_4_5
                [Test]
                public void HasDefaultValueDecimal () {
                        var info = typeof (ParameterInfoTest).GetMethod ("TestC").GetParameters ();
                        Assert.IsTrue (info [0].HasDefaultValue);
                }
-#endif
+
+               class TestParamAttribute : Attribute
+               {
+               }
+
+               public static int TestCustomAttribute_Method ([TestParamAttribute] string arg)
+               {
+                       return arg.Length;
+               }
+
+               [Test]
+               public void TestCustomAttribute ()
+               {
+                       var metInfo = GetType ().GetMethod ("TestCustomAttribute_Method", new Type[] { typeof(string) });
+                       var paramInfos = metInfo.GetParameters ();
+                       var argParamInfo = paramInfos[0];
+
+                       var custAttrs = argParamInfo.GetCustomAttributes ();
+                       Assert.AreEqual (1, custAttrs.Count ());
+               }
 
                class MyParameterInfo2 : ParameterInfo
                {
@@ -328,25 +338,23 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (0, p.GetCustomAttributes (typeof (FlagsAttribute), false).Length, "#3");
                        Assert.AreEqual (0, p.GetOptionalCustomModifiers ().Length, "#4");
                        Assert.AreEqual (0, p.GetRequiredCustomModifiers ().Length, "#5");
-#if NET_4_5
                        try {
                                var ign = p.HasDefaultValue;
                                Assert.Fail ("#6");
                        } catch (NotImplementedException) {
                        }
-#endif
                        Assert.IsFalse (p.IsIn, "#7");
+#if FEATURE_USE_LCID
                        Assert.IsFalse (p.IsLcid, "#8");
+#endif
                        Assert.IsFalse (p.IsOptional, "#9");
                        Assert.IsFalse (p.IsOut, "#10");
                        Assert.IsFalse (p.IsRetval, "#10");
-#if NET_4_5
                        try {
                                var ign = p.CustomAttributes;
                                Assert.Fail ("#11");
                        } catch (NotImplementedException) {
                        }
-#endif
                        try {
                                p.GetCustomAttributesData ();
                                Assert.Fail ("#12");
@@ -428,10 +436,7 @@ namespace MonoTests.System.Reflection
                        Assert.IsFalse (p2.IsIn, "#1");
                        p2.MyAttrsImpl = ParameterAttributes.In;
                        Assert.IsTrue (p2.IsIn, "#2");
-#if NET_4_5
                        Assert.AreEqual (p2.myList, p2.CustomAttributes, "#3");
-#endif
                }
-#endif
        }
 }