2007-12-03 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Mon, 3 Dec 2007 14:10:08 +0000 (14:10 -0000)
committerZoltan Varga <vargaz@gmail.com>
Mon, 3 Dec 2007 14:10:08 +0000 (14:10 -0000)
* FieldInfoTest.cs: Add GetRawDefaultValue () tests.

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

mcs/class/corlib/Test/System.Reflection/ChangeLog
mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs

index 9a2280c71b14165d9bdeb534e9e9c39eb4f092b9..b6efcb4438fef2c4ceb1395ee47934ff6ca8c18c 100644 (file)
@@ -1,3 +1,7 @@
+2007-12-03  Zoltan Varga  <vargaz@gmail.com>
+
+       * FieldInfoTest.cs: Add GetRawDefaultValue () tests.
+
 2007-11-05  Mark Probst  <mark.probst@gmail.com>
 
        * BinderTests.cs: Add test for bug #324998.
index 85bc10641968d3dcbe7426e7dd800c6d2e9a8dfc..208fbb8aa5b834c984db9c7cf828c808bf3eca31 100644 (file)
@@ -316,6 +316,46 @@ namespace MonoTests.System.Reflection
                        Assert.IsNotNull (f);
                }
 #endif // TARGET_JVM
+
+               [Test]
+               public void GetRawDefaultValue ()
+               {
+                       Assert.AreEqual (5, typeof (FieldInfoTest).GetField ("int_field").GetRawConstantValue ());
+                       Assert.AreEqual (Int64.MaxValue, typeof (FieldInfoTest).GetField ("long_field").GetRawConstantValue ());
+                       Assert.AreEqual (2, typeof (FieldInfoTest).GetField ("int_enum_field").GetRawConstantValue ());
+                       Assert.AreEqual (typeof (int), typeof (FieldInfoTest).GetField ("int_enum_field").GetRawConstantValue ().GetType ());
+                       Assert.AreEqual (2, typeof (FieldInfoTest).GetField ("long_enum_field").GetRawConstantValue ());
+                       Assert.AreEqual (typeof (long), typeof (FieldInfoTest).GetField ("long_enum_field").GetRawConstantValue ().GetType ());
+                       Assert.AreEqual ("Hello", typeof (FieldInfoTest).GetField ("string_field").GetRawConstantValue ());
+                       Assert.AreEqual (null, typeof (FieldInfoTest).GetField ("object_field").GetRawConstantValue ());
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void GetRawDefaultValueNoDefault ()
+               {
+                       typeof (FieldInfoTest).GetField ("non_const_field").GetRawConstantValue ();
+               }
+
+               public enum IntEnum {
+                       First = 1,
+                       Second = 2,
+                       Third = 3
+               }
+
+               public enum LongEnum : long {
+                       First = 1,
+                   Second = 2,
+                       Third = 3
+               }
+
+               public const int int_field = 5;
+               public const long long_field = Int64.MaxValue;
+               public const IntEnum int_enum_field = IntEnum.Second;
+               public const LongEnum long_enum_field = LongEnum.Second;
+               public const string string_field = "Hello";
+               public const FieldInfoTest object_field = null;
+               public int non_const_field;
        
 #endif
        }