2 // MonoTests.Remoting.ReflectionCalls.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2003 (C) Copyright, Ximian, Inc.
10 using System.Reflection;
11 using System.Collections;
12 using NUnit.Framework;
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 MethodBase m = type.GetMethod ("PrimitiveParams");
35 return (string) m.Invoke (target, parms);
38 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)
40 object[] parms = new object[] {a1,0,b1,0f,filler,c1,'\0',d1,null};
41 MethodBase m = type.GetMethod ("PrimitiveParamsInOut");
42 string res = (string) m.Invoke (target, parms);
46 d1 = (string)parms[7];
50 d2 = (string)parms[8];
54 public static Complex ComplexParams (Type type, object target, ArrayList a, Complex b, string c)
56 object[] parms = new object[] {a,b,c};
57 MethodBase m = type.GetMethod ("ComplexParams");
58 return (Complex) m.Invoke (target, parms);
61 public static Complex ComplexParamsInOut (Type type, object target, ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
63 object[] parms = new object[] {a,null,bytes,sb,c};
64 MethodBase m = type.GetMethod ("ComplexParamsInOut");
65 Complex res = (Complex) m.Invoke (target, parms);
66 a = (ArrayList) parms[0];
67 b = (Complex) parms[1];
71 public static void ProcessContextData (Type type, object target)
73 MethodBase m = type.GetMethod ("ProcessContextData");
74 m.Invoke (target, null);
78 public class ReflectionInstanceSurrogate : InstanceSurrogate
80 public override int Simple ()
82 return ReflectionCallTest.Simple (typeof (RemoteObject), RemoteObject);
85 public override string PrimitiveParams (int a, uint b, char c, string d)
87 return ReflectionCallTest.PrimitiveParams (typeof (RemoteObject), RemoteObject, a, b, c, d);
90 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)
92 return ReflectionCallTest.PrimitiveParamsInOut (typeof (RemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
95 public override Complex ComplexParams (ArrayList a, Complex b, string c)
97 return ReflectionCallTest.ComplexParams (typeof (RemoteObject), RemoteObject, a, b, c);
100 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
102 return ReflectionCallTest.ComplexParamsInOut (typeof (RemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
105 public override void ProcessContextData ()
107 ReflectionCallTest.ProcessContextData (typeof (RemoteObject), RemoteObject);
111 public class ReflectionAbstractSurrogate : AbstractSurrogate
113 public override int Simple ()
115 return ReflectionCallTest.Simple (typeof (AbstractRemoteObject), RemoteObject);
118 public override string PrimitiveParams (int a, uint b, char c, string d)
120 return ReflectionCallTest.PrimitiveParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c, d);
123 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)
125 return ReflectionCallTest.PrimitiveParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
128 public override Complex ComplexParams (ArrayList a, Complex b, string c)
130 return ReflectionCallTest.ComplexParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c);
133 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
135 return ReflectionCallTest.ComplexParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
138 public override void ProcessContextData ()
140 ReflectionCallTest.ProcessContextData (typeof (AbstractRemoteObject), RemoteObject);
144 public class ReflectionInterfaceSurrogate : InterfaceSurrogate
146 public override int Simple ()
148 return ReflectionCallTest.Simple (typeof (IRemoteObject), RemoteObject);
151 public override string PrimitiveParams (int a, uint b, char c, string d)
153 return ReflectionCallTest.PrimitiveParams (typeof (IRemoteObject), RemoteObject, a, b, c, d);
156 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)
158 return ReflectionCallTest.PrimitiveParamsInOut (typeof (IRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
161 public override Complex ComplexParams (ArrayList a, Complex b, string c)
163 return ReflectionCallTest.ComplexParams (typeof (IRemoteObject), RemoteObject, a, b, c);
166 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
168 return ReflectionCallTest.ComplexParamsInOut (typeof (IRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
171 public override void ProcessContextData ()
173 ReflectionCallTest.ProcessContextData (typeof (IRemoteObject), RemoteObject);