2010-02-22 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 23 Feb 2010 01:01:28 +0000 (01:01 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 23 Feb 2010 01:01:28 +0000 (01:01 -0000)
* TypeTest.cs:  Test new v4 GetEnumUnderlyingType ().

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

mcs/class/corlib/Test/System/ChangeLog
mcs/class/corlib/Test/System/TypeTest.cs

index 4817d0cf1d2040e16765718b82d87800a901d417..c5e40e31e3fa0ed0e0828550695a701df6d50e03 100644 (file)
@@ -1,3 +1,7 @@
+2010-02-22 Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * TypeTest.cs:  Test new v4 GetEnumUnderlyingType ().
+
 2010-02-19 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * TypeTest.cs: Test new v4 behavior for Equals.
index fba0b2df2732e45ef0e126b40a59a3558c1f3c89..adca76253752d834683304b6a09ae581398d3728 100644 (file)
@@ -3262,6 +3262,7 @@ PublicKeyToken=b77a5c561934e089"));
                        }
                }
 
+               [Test]
                public void NewV4EqualsBehavior ()
                {
                        var ta = new MyType ();
@@ -3277,6 +3278,49 @@ PublicKeyToken=b77a5c561934e089"));
                        Assert.AreEqual (0, tb.eq, "#5");
                        Assert.AreEqual (1, tb.ust, "#6");
                }
+
+               public enum MyRealEnum : short {
+                       A,B,C
+               }
+
+               public class MyEnum : TypeDelegator {
+                       public bool is_enum { get; set; }
+                       public int fields { get; set; }
+
+                       public override bool IsSubclassOf (Type c) {
+                               return c == typeof (Enum) && is_enum;
+                       }
+
+                       public override FieldInfo[] GetFields (BindingFlags bindingAttr) {
+                               if (fields == 0)
+                                       return null;
+                               FieldInfo[] res = new FieldInfo [fields];
+                               for (int i = 0; i < fields; ++i)
+                                       res [i] = typeof (MyRealEnum).GetField ("value__");
+                               return res;
+                       }
+               }
+
+               [Test]
+               public void GetEnumUnderlyingType () {
+
+                       try {
+                               new MyEnum () { is_enum = false }.GetEnumUnderlyingType ();
+                               Assert.Fail ("#1");
+                       } catch (ArgumentException) {}
+
+                       try {
+                               new MyEnum () { is_enum = true, fields = 0 }.GetEnumUnderlyingType ();
+                               Assert.Fail ("#2");
+                       } catch (ArgumentException) {}
+
+                       try {
+                               new MyEnum () { is_enum = true, fields = 2 }.GetEnumUnderlyingType ();
+                               Assert.Fail ("#3");
+                       } catch (ArgumentException) {}
+
+                       Assert.AreSame (typeof (short), new MyEnum () { is_enum = true, fields = 1 }.GetEnumUnderlyingType ());
+               }
 #endif
 
                public abstract class Stream : IDisposable