* MethodInfoTest.cs: Numbered tests. Improved existing tests.
authorGert Driesen <drieseng@users.sourceforge.net>
Sat, 2 Feb 2008 18:31:00 +0000 (18:31 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Sat, 2 Feb 2008 18:31:00 +0000 (18:31 -0000)
* ParameterInfoTest.cs: Added test for bug #342536.
* MonoMethod.cs (MakeGenericMethod): Modified argument name to match
MS. When one of the types is null, throw ArgumentNullException instead
of ArgumentException.
* MethodInfo.cs (MakeGenericMethod): Modified argument name to match
MS.

svn path=/trunk/mcs/; revision=94641

mcs/class/corlib/System.Reflection/ChangeLog
mcs/class/corlib/System.Reflection/MethodInfo.cs
mcs/class/corlib/System.Reflection/MonoMethod.cs
mcs/class/corlib/Test/System.Reflection/ChangeLog
mcs/class/corlib/Test/System.Reflection/MethodInfoTest.cs
mcs/class/corlib/Test/System.Reflection/ParameterInfoTest.cs

index 806529b0e18dc2405198240ad773046048be797c..9d70412cb6ec1e57d14540f63569e6f84205ca29 100644 (file)
@@ -1,3 +1,11 @@
+2008-02-02  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * MonoMethod.cs (MakeGenericMethod): Modified argument name to match
+       MS. When one of the types is null, throw ArgumentNullException instead
+       of ArgumentException.
+       * MethodInfo.cs (MakeGenericMethod): Modified argument name to match
+       MS.
+
 2008-01-29  Zoltan Varga  <vargaz@gmail.com>
 
        * Assembly.cs: Make GetTypes () virtual so it can be overriden by AssemblyBuilder.
index 5dc8b911d34c0e8e293f45a814cdc3aac7d9ca0e..ab1f3ce281d2865b23b67d9aee420e8111314ee4 100644 (file)
@@ -103,7 +103,7 @@ namespace System.Reflection {
                        throw new NotSupportedException ();
                }
 
-               public virtual MethodInfo MakeGenericMethod (params Type [] typeArguments)
+               public virtual MethodInfo MakeGenericMethod (params Type [] methodInstantiation)
                {
                        throw new NotSupportedException (this.GetType().ToString ());
                }
index f88240fbc1ecf5d22b90508cad8309043169d064..bbae031f8d9c33f6d50c1142b04223b164b86b5f 100644 (file)
@@ -301,17 +301,17 @@ namespace System.Reflection {
                }
 
 #if NET_2_0 || BOOTSTRAP_NET_2_0
-               public override MethodInfo MakeGenericMethod (Type [] types)
+               public override MethodInfo MakeGenericMethod (Type [] methodInstantiation)
                {
-                       if (types == null)
-                               throw new ArgumentNullException ("types");
-                       foreach (Type type in types)
+                       if (methodInstantiation == null)
+                               throw new ArgumentNullException ("methodInstantiation");
+                       foreach (Type type in methodInstantiation)
                                if (type == null)
-                                       throw new ArgumentException ("Types cannot contain a null value");
+                                       throw new ArgumentNullException ();
 
-                       MethodInfo ret = MakeGenericMethod_impl (types);
+                       MethodInfo ret = MakeGenericMethod_impl (methodInstantiation);
                        if (ret == null)
-                               throw new ArgumentException (String.Format ("The method has {0} generic parameter(s) but {1} generic argument(s) were provided.", GetGenericArguments ().Length, types.Length));
+                               throw new ArgumentException (String.Format ("The method has {0} generic parameter(s) but {1} generic argument(s) were provided.", GetGenericArguments ().Length, methodInstantiation.Length));
                        return ret;
                }
 
index 77f4be9d4b68bfa7ce7e7ebe73e217079119872e..81d59a561df6a83dbe14503858663d01e3a46372 100644 (file)
@@ -1,3 +1,8 @@
+2008-02-02  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * MethodInfoTest.cs: Numbered tests. Improved existing tests.
+       * ParameterInfoTest.cs: Added test for bug #342536.
+
 2008-01-30  Zoltan Varga  <vargaz@gmail.com>
 
        * AssemblyTest.cs (GetModules_MissingFile): Rename the generated assembly to
index 08a67696faee409d8992711255b08f612466919d..6888ce5fca0d1cda45b901208e23ed296873bacb 100644 (file)
@@ -321,23 +321,29 @@ namespace MonoTests.System.Reflection
                public void ReturnParameter ()
                {
                        ParameterInfo pi = typeof (MethodInfoTest).GetMethod ("return_parameter_test").ReturnParameter;
-
-                       Assert.AreEqual (typeof (int), pi.ParameterType);
-                       Assert.AreEqual (-1, pi.Position);
-                       // This fails on MS
-                       //Assert.AreEqual (True, pi.IsRetval);
+                       Assert.AreEqual (typeof (int), pi.ParameterType, "#1");
+                       Assert.AreEqual (-1, pi.Position, "#2");
+                       // MS always return false here
+                       //Assert.IsTrue (pi.IsRetval, "#3");
                }
 
 #if !TARGET_JVM // ReflectionOnly is not supported yet on TARGET_JVM
                [Test]
-               [ExpectedException (typeof (InvalidOperationException))]
-               public void InvokeOnRefOnlyAssembly ()
+                       public void InvokeOnRefOnlyAssembly ()
                {
                        Assembly a = Assembly.ReflectionOnlyLoad (typeof (MethodInfoTest).Assembly.FullName);
                        Type t = a.GetType (typeof (RefOnlyMethodClass).FullName);
                        MethodInfo m = t.GetMethod ("RefOnlyMethod", BindingFlags.Static | BindingFlags.NonPublic);
-                       
-                       m.Invoke (null, new object [0]);
+                       try {
+                               m.Invoke (null, new object [0]);
+                               Assert.Fail ("#1");
+                       } catch (InvalidOperationException ex) {
+                               // The requested operation is invalid in the
+                               // ReflectionOnly context
+                               Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                       }
                }
 #endif // TARGET_JVM
 
@@ -351,8 +357,8 @@ namespace MonoTests.System.Reflection
                        MethodInfo generic_method = method.MakeGenericMethod (arguments);
                        kvp = (KeyValuePair<string, uint>)generic_method.Invoke (null, new object [] { kvp });
 
-                       Assert.AreEqual ("a", kvp.Key);
-                       Assert.AreEqual (21, kvp.Value);
+                       Assert.AreEqual ("a", kvp.Key, "#1");
+                       Assert.AreEqual (21, kvp.Value, "#2");
                }
 
                public static KeyValuePair<T1, T2> Go <T1, T2> (KeyValuePair <T1, T2> kvp)
@@ -384,35 +390,60 @@ namespace MonoTests.System.Reflection
                        strArg.Add ("test");
                }
 
-               public void MakeGenericMethodArgsMismatchFoo<T> () {}
+               public void MakeGenericMethodArgsMismatchFoo<T> ()
+               {
+               }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void MakeGenericMethodArgsMismatch ()
                {
                        MethodInfo gmi = this.GetType ().GetMethod (
-                               "MakeGenericMethodArgsMismatchFoo")
-                               .MakeGenericMethod ();
+                               "MakeGenericMethodArgsMismatchFoo");
+                       try {
+                               gmi.MakeGenericMethod ();
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException ex) {
+                               // The type or method has 1 generic parameter(s),
+                               // but 0 generic argument(s) were provided. A
+                               // generic argument must be provided for each
+                               // generic parameter
+                               Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNull (ex.ParamName, "#5");
+                       }
                }
 
                public void SimpleGenericMethod<TFoo, TBar> () {}
 
                [Test]
-               [ExpectedException (typeof (ArgumentNullException))]
                public void MakeGenericMethodWithNullArray ()
                {
                        MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
-
-                       gmi.MakeGenericMethod ((Type []) null);
+                       try {
+                               gmi.MakeGenericMethod ((Type []) null);
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.AreEqual ("methodInstantiation", ex.ParamName, "#5");
+                       }
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void MakeGenericMethodWithNullValueInTypesArray ()
                {
                        MethodInfo gmi = this.GetType ().GetMethod ("SimpleGenericMethod");
-
-                       gmi.MakeGenericMethod (new Type [] { typeof (int), null });
+                       try {
+                               gmi.MakeGenericMethod (new Type [] { typeof (int), null });
+                               Assert.Fail ("#1");
+                       } catch (ArgumentNullException ex) {
+                               Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+                               Assert.IsNull (ex.InnerException, "#3");
+                               Assert.IsNotNull (ex.Message, "#4");
+                               Assert.IsNull (ex.ParamName, "#5");
+                       }
                }
 
                public static int? pass_nullable (int? i)
@@ -429,9 +460,9 @@ namespace MonoTests.System.Reflection
 
                        // Test conversion of vtype to a nullable type for the this argument
                        PropertyInfo pi = typeof (Nullable <int>).GetProperty ("HasValue");
-                   Assert.AreEqual (true, pi.GetGetMethod ().Invoke (10, null));
+                       Assert.AreEqual (true, pi.GetGetMethod ().Invoke (10, null));
                        PropertyInfo pi2 = typeof (Nullable <int>).GetProperty ("Value");
-                   Assert.AreEqual (10, pi2.GetGetMethod ().Invoke (10, null));
+                       Assert.AreEqual (10, pi2.GetGetMethod ().Invoke (10, null));
                }
 
                public static void foo_generic<T> ()
@@ -445,7 +476,6 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (true, mi.IsGenericMethod, "#1");
                        MethodInfo mi2 = mi.MakeGenericMethod (new Type[] { typeof (int) });
                        Assert.AreEqual (true, mi2.IsGenericMethod, "#2");
-
                        MethodInfo mi3 = typeof (GenericHelper<int>).GetMethod ("Test");
                        Assert.AreEqual (false, mi3.IsGenericMethod, "#3");
                }
@@ -489,16 +519,16 @@ namespace MonoTests.System.Reflection
                public void IsGenericMethodDefinition ()
                {
                        MethodInfo m1 = typeof (A<>).GetMethod ("Foo");
-                       Assert.IsTrue (m1.IsGenericMethod);
-                       Assert.IsTrue (m1.IsGenericMethodDefinition);
+                       Assert.IsTrue (m1.IsGenericMethod, "#A1");
+                       Assert.IsTrue (m1.IsGenericMethodDefinition, "#A2");
 
                        MethodInfo m2 = typeof (A<int>).GetMethod ("Foo");
-                       Assert.IsTrue (m2.IsGenericMethod);
-                       Assert.IsTrue (m2.IsGenericMethodDefinition);
+                       Assert.IsTrue (m2.IsGenericMethod, "#B1");
+                       Assert.IsTrue (m2.IsGenericMethodDefinition, "#B2");
 
                        MethodInfo m3 = m2.MakeGenericMethod (typeof (int));
-                       Assert.IsTrue (m3.IsGenericMethod);
-                       Assert.IsFalse (m3.IsGenericMethodDefinition);
+                       Assert.IsTrue (m3.IsGenericMethod, "#C1");
+                       Assert.IsFalse (m3.IsGenericMethodDefinition, "#C2");
                }
 
                [Test]
@@ -508,21 +538,19 @@ namespace MonoTests.System.Reflection
                        MethodInfo mi2 = typeof (MyList<int>).GetMethod ("ConvertAll");
 
                        Assert.AreEqual ("MonoTests.System.Reflection.MethodInfoTest+Foo`2[T,TOutput]",
-                                        mi1.GetParameters () [0].ParameterType.ToString ());
+                                        mi1.GetParameters () [0].ParameterType.ToString (), "#A1");
                        Assert.AreEqual ("MonoTests.System.Reflection.MethodInfoTest+Foo`2[System.Int32,TOutput]",
-                                        mi2.GetParameters () [0].ParameterType.ToString ());
-                       Assert.IsTrue (mi1.IsGenericMethod);
-                       Assert.IsTrue (mi1.IsGenericMethodDefinition);
-                       Assert.IsTrue (mi2.IsGenericMethod);
-                       Assert.IsTrue (mi2.IsGenericMethodDefinition);
+                                        mi2.GetParameters () [0].ParameterType.ToString (), "#A2");
+                       Assert.IsTrue (mi1.IsGenericMethod, "#A3");
+                       Assert.IsTrue (mi1.IsGenericMethodDefinition, "#A4");
+                       Assert.IsTrue (mi2.IsGenericMethod, "#A5");
+                       Assert.IsTrue (mi2.IsGenericMethodDefinition, "#A6");
 
                        MethodInfo mi3 = mi2.GetGenericMethodDefinition ();
 
-                       Assert.IsTrue (mi3.IsGenericMethod);
-                       Assert.IsTrue (mi3.IsGenericMethodDefinition);
-
-                       // ensure it's the same object, not just equal
-                       Assert.IsTrue (mi2 == mi3);
+                       Assert.IsTrue (mi3.IsGenericMethod, "#B1");
+                       Assert.IsTrue (mi3.IsGenericMethodDefinition, "#B2");
+                       Assert.AreSame (mi2, mi3, "#B3");
                }
 
                public class MyList<T>
@@ -544,7 +572,8 @@ namespace MonoTests.System.Reflection
                class GenericHelper<T>
                {
                        public void Test (T t)
-                       { }
+                       {
+                       }
                }
 #endif
        }
index bf7a40b582a219fffb621b5708d64bea41f14737..0a1710e0621046ec500211fc0ebf5a358e656849 100644 (file)
@@ -72,7 +72,6 @@ namespace MonoTests.System.Reflection
                        }
                }
 
-
 #if NET_2_0
                public enum ParamEnum {
                        None = 0,
@@ -80,8 +79,10 @@ namespace MonoTests.System.Reflection
                        Bar = 2
                };
 
-               public static void paramMethod (int i, [In] int j, [Out] int k, [Optional] int l, [In,Out] int m, [DefaultParameterValue (ParamEnum.Foo)] ParamEnum n) {
+               public static void paramMethod (int i, [In] int j, [Out] int k, [Optional] int l, [In,Out] int m, [DefaultParameterValue (ParamEnum.Foo)] ParamEnum n)
+               {
                }
+
 #if !TARGET_JVM // No support for extern methods in TARGET_JVM
                [DllImport ("foo")]
                public extern static void marshalAsMethod (
@@ -97,8 +98,7 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (ParamEnum.Foo, info [5].DefaultValue, "#2");
                }
 
-               // See bug: 339013
-               [Test]
+               [Test] // bug #339013
                public void TestDefaultValues ()
                {
                        ParameterInfo [] pi = typeof (ParameterInfoTest).GetMethod ("Sample").GetParameters ();
@@ -110,7 +110,7 @@ namespace MonoTests.System.Reflection
                public void Sample (int a, [Optional] int b)
                {
                }
-                       
+
                [Test]
                public void PseudoCustomAttributes () {
                        ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
@@ -137,6 +137,52 @@ namespace MonoTests.System.Reflection
                        Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#D3");
 #endif
                }
+
+               [Test] // bug #342536
+               public void Generics_Name ()
+               {
+                       MethodInfo mi;
+                       Type type;
+                       ParameterInfo [] info;
+               
+                       type = typeof (BaseType<string>);
+
+                       mi = type.GetMethod ("GetItems");
+                       Assert.IsNotNull (mi, "#A1");
+                       info = mi.GetParameters ();
+                       Assert.AreEqual (1, info.Length, "#A2");
+                       Assert.AreEqual ("count", info [0].Name, "#A3");
+
+                       mi = type.GetMethod ("Add");
+                       Assert.IsNotNull (mi, "#B1");
+                       info = mi.GetParameters ();
+                       Assert.AreEqual (2, info.Length, "#B2");
+                       Assert.AreEqual ("item", info [0].Name, "#B3");
+                       Assert.AreEqual ("index", info [1].Name, "#B4");
+
+                       mi = type.GetMethod ("Create");
+                       Assert.IsNotNull (mi, "#C1");
+                       info = mi.GetParameters ();
+                       Assert.AreEqual (2, info.Length, "#C2");
+                       Assert.AreEqual ("x", info [0].Name, "#C3");
+                       Assert.AreEqual ("item", info [1].Name, "#C4");
+               }
+
+               public class BaseType <T>
+               {
+                       public void GetItems (int count)
+                       {
+                       }
+
+                       public void Add (T item, int index)
+                       {
+                       }
+
+                       public V Create <V> (int x, T item)
+                       {
+                               return default (V);
+                       }
+               }
 #endif
        }
 }