2004-09-26 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Sun, 26 Sep 2004 17:14:13 +0000 (17:14 -0000)
committerZoltan Varga <vargaz@gmail.com>
Sun, 26 Sep 2004 17:14:13 +0000 (17:14 -0000)
* FieldInfoTest.cs: Add tests for MarshalAsAttribute.

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

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

index fff4c6b3cdab03b41c73014e83c4c3e2927c34b2..51feacebb3af46c67deeec9ced168df82ed70c00 100644 (file)
@@ -1,5 +1,7 @@
 2004-09-26  Zoltan Varga  <vargaz@freemail.hu>
 
+       * FieldInfoTest.cs: Add tests for MarshalAsAttribute.
+
        * ParameterInfoTest.cs: Add tests for MarshalAsAttribute.
 
        * FieldInfoTest.cs: Add tests for FieldOffsetAttribute.
index c421a227f1b7527e704c24aebb1cee81448efa05..9ecb7f21afcd8e31051f451376845d9eff5882ff 100644 (file)
@@ -43,6 +43,22 @@ public class Class1 {
        public int i;
 }
 
+[StructLayout(LayoutKind.Sequential)]
+public class Class2 {
+       [MarshalAsAttribute(UnmanagedType.Bool)]
+       public int f0;
+
+       [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)]
+       public string[] f1;
+
+       [MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
+       public string f2;
+
+       // This doesn't work under mono
+       //[MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")]
+       //public object f3;
+}
+
 [TestFixture]
 public class FieldInfoTest : Assertion
 {
@@ -56,8 +72,28 @@ public class FieldInfoTest : Assertion
 
                AssertEquals (1, t.GetField ("i").GetCustomAttributes (typeof (NonSerializedAttribute), true).Length);
 
-               FieldOffsetAttribute attr = (FieldOffsetAttribute)(typeof (Class1).GetField ("i").GetCustomAttributes (true) [0]);
-               AssertEquals (32, attr.Value);
+               FieldOffsetAttribute field_attr = (FieldOffsetAttribute)(typeof (Class1).GetField ("i").GetCustomAttributes (true) [0]);
+               AssertEquals (32, field_attr.Value);
+
+               MarshalAsAttribute attr;
+
+               attr = (MarshalAsAttribute)typeof (Class2).GetField ("f0").GetCustomAttributes (true) [0];
+               AssertEquals (UnmanagedType.Bool, attr.Value);
+
+               attr = (MarshalAsAttribute)typeof (Class2).GetField ("f1").GetCustomAttributes (true) [0];
+               AssertEquals (UnmanagedType.LPArray, attr.Value);
+               AssertEquals (UnmanagedType.LPStr, attr.ArraySubType);
+
+               attr = (MarshalAsAttribute)typeof (Class2).GetField ("f2").GetCustomAttributes (true) [0];
+               AssertEquals (UnmanagedType.ByValTStr, attr.Value);
+               AssertEquals (100, attr.SizeConst);
+
+               /*
+               attr = (MarshalAsAttribute)typeof (Class2).GetField ("f3").GetCustomAttributes (true) [0];
+               AssertEquals (UnmanagedType.CustomMarshaler, attr.Value);
+               AssertEquals ("5", attr.MarshalCookie);
+               AssertEquals (typeof (Marshal1), Type.GetType (attr.MarshalType));
+               */
        }
 #endif
 }