Merge pull request #225 from mistoll/master
[mono.git] / mcs / class / System.Runtime.Remoting / Test / ReflectionCalls.cs
1 //
2 // MonoTests.Remoting.ReflectionCalls.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
5 //
6 // 2003 (C) Copyright, Ximian, Inc.
7 //
8
9 using System;
10 using System.Reflection;
11 using System.Collections;
12 using NUnit.Framework;
13 using System.Text;
14 using System.Runtime.InteropServices;
15
16 namespace MonoTests.Remoting
17 {
18         public abstract class ReflectionCallTest : BaseCallTest
19         {
20                 public override InstanceSurrogate GetInstanceSurrogate () { return new ReflectionInstanceSurrogate (); }
21                 public override AbstractSurrogate GetAbstractSurrogate () { return new ReflectionAbstractSurrogate (); }
22                 public override InterfaceSurrogate GetInterfaceSurrogate () { return new ReflectionInterfaceSurrogate (); }
23
24                 public static int Simple (Type type, object target)
25                 {
26                         object[] parms = new object[0];
27                         MethodBase m = type.GetMethod ("Simple");
28                         return (int) m.Invoke (target, parms);
29                 }
30
31                 public static string PrimitiveParams (Type type, object target, int a, uint b, char c, string d)
32                 {
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);
37                 }
38
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)
40                 {
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;
53                 }
54
55                 public static Complex ComplexParams (Type type, object target, ArrayList a, Complex b, string c)
56                 {
57                         object[] parms = new object[] {a,b,c};
58                         MethodBase m = type.GetMethod ("ComplexParams");
59                         return (Complex) m.Invoke (target, parms);
60                 }
61
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)
63                 {
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;
70                 }
71
72                 public static void ProcessContextData (Type type, object target)
73                 {
74                         MethodBase m = type.GetMethod ("ProcessContextData");
75                         m.Invoke (target, null);
76                 }
77         }
78
79         public class ReflectionInstanceSurrogate : InstanceSurrogate
80         {
81                 public override int Simple ()
82                 {
83                         return ReflectionCallTest.Simple (typeof (RemoteObject), RemoteObject);
84                 }
85
86                 public override string PrimitiveParams (int a, uint b, char c, string d)
87                 {
88                         return ReflectionCallTest.PrimitiveParams (typeof (RemoteObject), RemoteObject, a, b, c, d);
89                 }
90
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)
92                 {
93                         return ReflectionCallTest.PrimitiveParamsInOut (typeof (RemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
94                 }
95
96                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
97                 {
98                         return ReflectionCallTest.ComplexParams (typeof (RemoteObject), RemoteObject, a, b, c);
99                 }
100
101                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
102                 {
103                         return ReflectionCallTest.ComplexParamsInOut (typeof (RemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
104                 }
105
106                 public override void ProcessContextData ()
107                 {
108                         ReflectionCallTest.ProcessContextData (typeof (RemoteObject), RemoteObject);
109                 }
110         }
111
112         public class ReflectionAbstractSurrogate : AbstractSurrogate
113         {
114                 public override int Simple ()
115                 {
116                         return ReflectionCallTest.Simple (typeof (AbstractRemoteObject), RemoteObject);
117                 }
118
119                 public override string PrimitiveParams (int a, uint b, char c, string d)
120                 {
121                         return ReflectionCallTest.PrimitiveParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c, d);
122                 }
123
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)
125                 {
126                         return ReflectionCallTest.PrimitiveParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
127                 }
128
129                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
130                 {
131                         return ReflectionCallTest.ComplexParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c);
132                 }
133
134                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
135                 {
136                         return ReflectionCallTest.ComplexParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
137                 }
138
139                 public override void ProcessContextData ()
140                 {
141                         ReflectionCallTest.ProcessContextData (typeof (AbstractRemoteObject), RemoteObject);
142                 }
143         }
144
145         public class ReflectionInterfaceSurrogate : InterfaceSurrogate
146         {
147                 public override int Simple ()
148                 {
149                         return ReflectionCallTest.Simple (typeof (IRemoteObject), RemoteObject);
150                 }
151
152                 public override string PrimitiveParams (int a, uint b, char c, string d)
153                 {
154                         return ReflectionCallTest.PrimitiveParams (typeof (IRemoteObject), RemoteObject, a, b, c, d);
155                 }
156
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)
158                 {
159                         return ReflectionCallTest.PrimitiveParamsInOut (typeof (IRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
160                 }
161
162                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
163                 {
164                         return ReflectionCallTest.ComplexParams (typeof (IRemoteObject), RemoteObject, a, b, c);
165                 }
166
167                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
168                 {
169                         return ReflectionCallTest.ComplexParamsInOut (typeof (IRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
170                 }
171
172                 public override void ProcessContextData ()
173                 {
174                         ReflectionCallTest.ProcessContextData (typeof (IRemoteObject), RemoteObject);
175                 }
176         }
177 }