New tests.
[mono.git] / mcs / class / corlib / Test / System.Reflection / FieldInfoTest.cs
index 0fb77ffbba6720cf3dbdd641c6c86ebbc2e50738..5bc090f9565418bd23fa58d8944f5a7d04dbfad2 100644 (file)
@@ -229,6 +229,19 @@ namespace MonoTests.System.Reflection
                                Assert.IsNull (ex.ParamName, "#5");
                        }
                }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void GetFieldFromHandle2_Incompatible ()
+               {
+                       RuntimeFieldHandle fh = typeof (FieldInfoTest<int>).GetField ("TestField").FieldHandle;
+
+                       FieldInfoTest<string> instance = new FieldInfoTest<string> ();
+                       Type t2 = instance.GetType ();
+                       RuntimeTypeHandle th = t2.TypeHandle;
+
+                       FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
+               }
 #endif
 
                [Test]
@@ -421,9 +434,6 @@ namespace MonoTests.System.Reflection
                        // get it for real
                        fi = t.GetField ("protectedField", BindingFlags.NonPublic | BindingFlags.Instance);
                        Assert.IsNotNull (fi);
-                       // get via typebuilder
-                       FieldInfo f = TypeBuilder.GetField (t, fi);
-                       Assert.IsNotNull (f);
                }
 #endif // TARGET_JVM
 
@@ -447,7 +457,6 @@ namespace MonoTests.System.Reflection
                        typeof (FieldInfoTest).GetField ("non_const_field").GetRawConstantValue ();
                }
 
-#if NET_2_0
                [Test]
                [ExpectedException (typeof (InvalidOperationException))]
                public void GetValueOpenGeneric ()
@@ -466,14 +475,23 @@ namespace MonoTests.System.Reflection
                public void GetValueOnConstantOfOpenGeneric ()
                {
                        Assert.AreEqual (10, typeof(Foo<>).GetField ("constant").GetValue (null), "#1");
+                       Assert.AreEqual ("waa", typeof(Foo<>).GetField ("sconstant").GetValue (null), "#2");
+                       Assert.AreEqual (IntEnum.Third, typeof(Foo<>).GetField ("econstant").GetValue (null), "#3");
                }
 
                public class Foo<T>
                {
+                        /*
+                       The whole point of this field is to make sure we don't create the vtable layout
+                       when loading the value of constants for Foo<>. See bug #594942.
+
+                       */
+                       public T dummy;
                        public static int field;
                        public const int constant = 10;
+                       public const string sconstant = "waa";
+                       public const IntEnum econstant = IntEnum.Third;
                }
-#endif
 
                public enum IntEnum {
                        First = 1,