2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Runtime.Remoting / Test / ReflectionCalls.cs
blobe13152096bb3a178232b12098556607244cab449
1 //
2 // MonoTests.Remoting.ReflectionCalls.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // 2003 (C) Copyright, Ximian, Inc.
7 //
9 using System;
10 using System.Reflection;
11 using System.Collections;
12 using NUnit.Framework;
13 using System.Text;
14 using System.Runtime.InteropServices;
16 namespace MonoTests.Remoting
18 public abstract class ReflectionCallTest : BaseCallTest
20 public override InstanceSurrogate GetInstanceSurrogate () { return new ReflectionInstanceSurrogate (); }
21 public override AbstractSurrogate GetAbstractSurrogate () { return new ReflectionAbstractSurrogate (); }
22 public override InterfaceSurrogate GetInterfaceSurrogate () { return new ReflectionInterfaceSurrogate (); }
24 public static int Simple (Type type, object target)
26 object[] parms = new object[0];
27 MethodBase m = type.GetMethod ("Simple");
28 return (int) m.Invoke (target, parms);
31 public static string PrimitiveParams (Type type, object target, int a, uint b, char c, string d)
33 object[] parms = new object[] {a,b,c,d};
34 Type[] sig = new Type[] {typeof (int), typeof (uint), typeof (char), typeof (string)};
35 MethodBase m = type.GetMethod ("PrimitiveParams", sig);
36 return (string) m.Invoke (target, parms);
39 public static string PrimitiveParamsInOut (Type type, object target, ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
41 object[] parms = new object[] {a1,0,b1,0f,filler,c1,'\0',d1,null};
42 MethodBase m = type.GetMethod ("PrimitiveParamsInOut");
43 string res = (string) m.Invoke (target, parms);
44 a1 = (int)parms[0];
45 b1 = (float)parms[2];
46 c1 = (char)parms[5];
47 d1 = (string)parms[7];
48 a2 = (int)parms[1];
49 b2 = (float)parms[3];
50 c2 = (char)parms[6];
51 d2 = (string)parms[8];
52 return res;
55 public static Complex ComplexParams (Type type, object target, ArrayList a, Complex b, string c)
57 object[] parms = new object[] {a,b,c};
58 MethodBase m = type.GetMethod ("ComplexParams");
59 return (Complex) m.Invoke (target, parms);
62 public static Complex ComplexParamsInOut (Type type, object target, ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
64 object[] parms = new object[] {a,null,bytes,sb,c};
65 MethodBase m = type.GetMethod ("ComplexParamsInOut");
66 Complex res = (Complex) m.Invoke (target, parms);
67 a = (ArrayList) parms[0];
68 b = (Complex) parms[1];
69 return res;
72 public static void ProcessContextData (Type type, object target)
74 MethodBase m = type.GetMethod ("ProcessContextData");
75 m.Invoke (target, null);
79 public class ReflectionInstanceSurrogate : InstanceSurrogate
81 public override int Simple ()
83 return ReflectionCallTest.Simple (typeof (RemoteObject), RemoteObject);
86 public override string PrimitiveParams (int a, uint b, char c, string d)
88 return ReflectionCallTest.PrimitiveParams (typeof (RemoteObject), RemoteObject, a, b, c, d);
91 public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
93 return ReflectionCallTest.PrimitiveParamsInOut (typeof (RemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
96 public override Complex ComplexParams (ArrayList a, Complex b, string c)
98 return ReflectionCallTest.ComplexParams (typeof (RemoteObject), RemoteObject, a, b, c);
101 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
103 return ReflectionCallTest.ComplexParamsInOut (typeof (RemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
106 public override void ProcessContextData ()
108 ReflectionCallTest.ProcessContextData (typeof (RemoteObject), RemoteObject);
112 public class ReflectionAbstractSurrogate : AbstractSurrogate
114 public override int Simple ()
116 return ReflectionCallTest.Simple (typeof (AbstractRemoteObject), RemoteObject);
119 public override string PrimitiveParams (int a, uint b, char c, string d)
121 return ReflectionCallTest.PrimitiveParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c, d);
124 public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
126 return ReflectionCallTest.PrimitiveParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
129 public override Complex ComplexParams (ArrayList a, Complex b, string c)
131 return ReflectionCallTest.ComplexParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c);
134 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
136 return ReflectionCallTest.ComplexParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
139 public override void ProcessContextData ()
141 ReflectionCallTest.ProcessContextData (typeof (AbstractRemoteObject), RemoteObject);
145 public class ReflectionInterfaceSurrogate : InterfaceSurrogate
147 public override int Simple ()
149 return ReflectionCallTest.Simple (typeof (IRemoteObject), RemoteObject);
152 public override string PrimitiveParams (int a, uint b, char c, string d)
154 return ReflectionCallTest.PrimitiveParams (typeof (IRemoteObject), RemoteObject, a, b, c, d);
157 public override string PrimitiveParamsInOut (ref int a1, out int a2, ref float b1, out float b2, int filler, ref char c1, out char c2, ref string d1, out string d2)
159 return ReflectionCallTest.PrimitiveParamsInOut (typeof (IRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
162 public override Complex ComplexParams (ArrayList a, Complex b, string c)
164 return ReflectionCallTest.ComplexParams (typeof (IRemoteObject), RemoteObject, a, b, c);
167 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
169 return ReflectionCallTest.ComplexParamsInOut (typeof (IRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
172 public override void ProcessContextData ()
174 ReflectionCallTest.ProcessContextData (typeof (IRemoteObject), RemoteObject);