2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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                         MethodBase m = type.GetMethod ("PrimitiveParams");
35                         return (string) m.Invoke (target, parms);
36                 }
37
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)
39                 {
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);
43                         a1 = (int)parms[0];
44                         b1 = (float)parms[2];
45                         c1 = (char)parms[5];
46                         d1 = (string)parms[7];
47                         a2 = (int)parms[1];
48                         b2 = (float)parms[3];
49                         c2 = (char)parms[6];
50                         d2 = (string)parms[8];
51                         return res;
52                 }
53
54                 public static Complex ComplexParams (Type type, object target, ArrayList a, Complex b, string c)
55                 {
56                         object[] parms = new object[] {a,b,c};
57                         MethodBase m = type.GetMethod ("ComplexParams");
58                         return (Complex) m.Invoke (target, parms);
59                 }
60
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)
62                 {
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];
68                         return res;
69                 }
70
71                 public static void ProcessContextData (Type type, object target)
72                 {
73                         MethodBase m = type.GetMethod ("ProcessContextData");
74                         m.Invoke (target, null);
75                 }
76         }
77
78         public class ReflectionInstanceSurrogate : InstanceSurrogate
79         {
80                 public override int Simple ()
81                 {
82                         return ReflectionCallTest.Simple (typeof (RemoteObject), RemoteObject);
83                 }
84
85                 public override string PrimitiveParams (int a, uint b, char c, string d)
86                 {
87                         return ReflectionCallTest.PrimitiveParams (typeof (RemoteObject), RemoteObject, a, b, c, d);
88                 }
89
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)
91                 {
92                         return ReflectionCallTest.PrimitiveParamsInOut (typeof (RemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
93                 }
94
95                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
96                 {
97                         return ReflectionCallTest.ComplexParams (typeof (RemoteObject), RemoteObject, a, b, c);
98                 }
99
100                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
101                 {
102                         return ReflectionCallTest.ComplexParamsInOut (typeof (RemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
103                 }
104
105                 public override void ProcessContextData ()
106                 {
107                         ReflectionCallTest.ProcessContextData (typeof (RemoteObject), RemoteObject);
108                 }
109         }
110
111         public class ReflectionAbstractSurrogate : AbstractSurrogate
112         {
113                 public override int Simple ()
114                 {
115                         return ReflectionCallTest.Simple (typeof (AbstractRemoteObject), RemoteObject);
116                 }
117
118                 public override string PrimitiveParams (int a, uint b, char c, string d)
119                 {
120                         return ReflectionCallTest.PrimitiveParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c, d);
121                 }
122
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)
124                 {
125                         return ReflectionCallTest.PrimitiveParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
126                 }
127
128                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
129                 {
130                         return ReflectionCallTest.ComplexParams (typeof (AbstractRemoteObject), RemoteObject, a, b, c);
131                 }
132
133                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
134                 {
135                         return ReflectionCallTest.ComplexParamsInOut (typeof (AbstractRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
136                 }
137
138                 public override void ProcessContextData ()
139                 {
140                         ReflectionCallTest.ProcessContextData (typeof (AbstractRemoteObject), RemoteObject);
141                 }
142         }
143
144         public class ReflectionInterfaceSurrogate : InterfaceSurrogate
145         {
146                 public override int Simple ()
147                 {
148                         return ReflectionCallTest.Simple (typeof (IRemoteObject), RemoteObject);
149                 }
150
151                 public override string PrimitiveParams (int a, uint b, char c, string d)
152                 {
153                         return ReflectionCallTest.PrimitiveParams (typeof (IRemoteObject), RemoteObject, a, b, c, d);
154                 }
155
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)
157                 {
158                         return ReflectionCallTest.PrimitiveParamsInOut (typeof (IRemoteObject), RemoteObject, ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2);
159                 }
160
161                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
162                 {
163                         return ReflectionCallTest.ComplexParams (typeof (IRemoteObject), RemoteObject, a, b, c);
164                 }
165
166                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, [In,Out] StringBuilder sb, string c)
167                 {
168                         return ReflectionCallTest.ComplexParamsInOut (typeof (IRemoteObject), RemoteObject, ref a, out b, bytes, sb, c);
169                 }
170
171                 public override void ProcessContextData ()
172                 {
173                         ReflectionCallTest.ProcessContextData (typeof (IRemoteObject), RemoteObject);
174                 }
175         }
176 }