remove TARGET_JVM
[mono.git] / mcs / class / corlib / Test / System.Reflection / ParameterInfoTest.cs
1 //
2 // ParameterInfoTest - NUnit Test Cases for the ParameterInfo class
3 //
4 // Zoltan Varga (vargaz@freemail.hu)
5 //
6 // (C) Ximian, Inc.  http://www.ximian.com
7 //
8 //
9
10 using System;
11 using System.Threading;
12 using System.Reflection;
13 #if !TARGET_JVM
14 using System.Reflection.Emit;
15 #endif // TARGET_JVM
16 using System.Runtime.InteropServices;
17
18 using NUnit.Framework;
19
20 namespace MonoTests.System.Reflection
21 {
22
23
24 public class Marshal1 : ICustomMarshaler
25 {
26         public static ICustomMarshaler GetInstance (string s) {
27                 return new Marshal1 ();
28         }
29
30         public void CleanUpManagedData (object managedObj)
31         {
32         }
33
34         public void CleanUpNativeData (IntPtr pNativeData)
35         {
36         }
37
38         public int GetNativeDataSize ()
39         {
40                 return 4;
41         }
42
43         public IntPtr MarshalManagedToNative (object managedObj)
44         {
45                 return IntPtr.Zero;
46         }
47
48         public object MarshalNativeToManaged (IntPtr pNativeData)
49         {
50                 return null;
51         }
52 }
53
54 [TestFixture]
55 public class ParameterInfoTest : Assertion
56 {
57 #if NET_2_0
58         public enum ParamEnum {
59                 None = 0,
60                 Foo = 1,
61                 Bar = 2
62         };
63
64         public static void paramMethod (int i, [In] int j, [Out] int k, [Optional] int l, [In,Out] int m, [DefaultParameterValue (ParamEnum.Foo)] ParamEnum n) {
65         }
66 #if !TARGET_JVM
67         [DllImport ("foo")]
68         public extern static void marshalAsMethod (
69                 [MarshalAs(UnmanagedType.Bool)]int p0, 
70                 [MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.LPStr)] string [] p1,
71                 [MarshalAs( UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")] object p2);
72 #endif
73         [Test]
74         public void DefaultValueEnum () {
75                 ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
76
77                 AssertEquals (typeof (ParamEnum), info [5].DefaultValue.GetType ());
78                 AssertEquals (ParamEnum.Foo, info [5].DefaultValue);
79         }
80
81         [Test]
82         public void PseudoCustomAttributes () {
83                 ParameterInfo[] info = typeof (ParameterInfoTest).GetMethod ("paramMethod").GetParameters ();
84                 AssertEquals (0, info[0].GetCustomAttributes (true).Length);
85                 AssertEquals (1, info[1].GetCustomAttributes (typeof (InAttribute), true).Length);
86                 AssertEquals (1, info[2].GetCustomAttributes (typeof (OutAttribute), true).Length);
87                 AssertEquals (1, info[3].GetCustomAttributes (typeof (OptionalAttribute), true).Length);
88                 AssertEquals (2, info[4].GetCustomAttributes (true).Length);
89
90                 ParameterInfo[] pi = typeof (ParameterInfoTest).GetMethod ("marshalAsMethod").GetParameters ();
91                 MarshalAsAttribute attr;
92
93                 attr = (MarshalAsAttribute)(pi [0].GetCustomAttributes (true) [0]);
94                 AssertEquals (UnmanagedType.Bool, attr.Value);
95
96                 attr = (MarshalAsAttribute)(pi [1].GetCustomAttributes (true) [0]);
97                 AssertEquals (UnmanagedType.LPArray, attr.Value);
98                 AssertEquals (UnmanagedType.LPStr, attr.ArraySubType);
99
100                 attr = (MarshalAsAttribute)(pi [2].GetCustomAttributes (true) [0]);
101                 AssertEquals (UnmanagedType.CustomMarshaler, attr.Value);
102                 AssertEquals ("5", attr.MarshalCookie);
103                 AssertEquals (typeof (Marshal1), Type.GetType (attr.MarshalType));
104         }
105 #endif
106 }               
107 }