New test.
[mono.git] / mcs / class / corlib / Test / System.Reflection / FieldInfoTest.cs
index 49a257ef3a78521bb6101bf7b435a634dde511a8..4ad97602f8f7b3d9a75fbdf52ba637501d70e3c7 100644 (file)
@@ -98,7 +98,6 @@ public class FieldInfoTest : Assertion
 
        [Test]
        [ExpectedException (typeof (InvalidOperationException))]
-       [Category ("NotWorking")]
        public void GetValueOnRefOnlyAssembly ()
        {
                Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
@@ -110,7 +109,6 @@ public class FieldInfoTest : Assertion
        
        [Test]
        [ExpectedException (typeof (InvalidOperationException))]
-       [Category ("NotWorking")]
        public void SetValueOnRefOnlyAssembly ()
        {
                Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (FieldInfoTest).Assembly.FullName);
@@ -119,7 +117,40 @@ public class FieldInfoTest : Assertion
 
                f.SetValue (null, 8);
        }
-       
+
+       const int literal = 42;
+
+       [Test]
+       [ExpectedException (typeof (FieldAccessException))]
+       public void SetValueOnLiteralField ()
+       {
+               FieldInfo f = typeof (FieldInfoTest).GetField ("literal", BindingFlags.Static | BindingFlags.NonPublic);
+               f.SetValue (null, 0);
+       }
+
+       public int? nullable_field;
+
+       public static int? static_nullable_field;
+
+       [Test]
+       public void NullableTests ()
+       {
+               FieldInfoTest t = new FieldInfoTest ();
+
+               FieldInfo fi = typeof (FieldInfoTest).GetField ("nullable_field");
+
+               fi.SetValue (t, 101);
+               AssertEquals (101, fi.GetValue (t));
+               fi.SetValue (t, null);
+               AssertEquals (null, fi.GetValue (t));
+
+               FieldInfo fi2 = typeof (FieldInfoTest).GetField ("static_nullable_field");
+
+               fi2.SetValue (t, 101);
+               AssertEquals (101, fi2.GetValue (t));
+               fi2.SetValue (t, null);
+               AssertEquals (null, fi2.GetValue (t));
+       }
 #endif
 }              
 #if NET_2_0