[System.Runtime.InteropServices.RuntimeInformation] Updated to reference copied files...
[mono-project.git] / mono / tests / remoting1.cs
blobce9589469e1dfa59b76da3c07504fc79d74551fc
1 using System;
2 using System.Threading;
3 using System.Runtime.InteropServices;
4 using System.Runtime.Remoting;
5 using System.Runtime.Remoting.Messaging;
6 using System.Runtime.Remoting.Proxies;
8 class MyProxy : RealProxy {
9 readonly MarshalByRefObject target;
11 public MyProxy (MarshalByRefObject target) : base (target.GetType())
13 this.target = target;
16 public override IMessage Invoke (IMessage request) {
17 IMethodCallMessage call = (IMethodCallMessage)request;
18 Console.WriteLine ("Invoke " + call.MethodName);
20 Console.Write ("ARGS(");
21 for (int i = 0; i < call.ArgCount; i++) {
22 if (i != 0)
23 Console.Write (", ");
24 Console.Write (call.GetArgName (i) + " " +
25 call.GetArg (i));
27 Console.WriteLine (")");
28 Console.Write ("INARGS(");
29 for (int i = 0; i < call.InArgCount; i++) {
30 if (i != 0)
31 Console.Write (", ");
32 Console.Write (call.GetInArgName (i) + " " +
33 call.GetInArg (i));
35 Console.WriteLine (")");
37 IMethodReturnMessage res = RemotingServices.ExecuteMessage (target, call);
39 Console.Write ("RESARGS(");
40 for (int i = 0; i < res.ArgCount; i++) {
41 if (i != 0)
42 Console.Write (", ");
43 Console.Write (res.GetArgName (i) + " " +
44 res.GetArg (i));
46 Console.WriteLine (")");
48 Console.Write ("RESOUTARGS(");
49 for (int i = 0; i < res.OutArgCount; i++) {
50 if (i != 0)
51 Console.Write (", ");
52 Console.Write (res.GetOutArgName (i) + " " +
53 res.GetOutArg (i));
55 Console.WriteLine (")");
57 return res;
61 public class EmptyProxy : RealProxy
63 public EmptyProxy ( Type type ) : base( type )
67 public override IMessage Invoke( IMessage msg )
69 IMethodCallMessage call = (IMethodCallMessage)msg;
71 return new ReturnMessage( null, null, 0, null, call );
75 public struct MyStruct {
76 public int a;
77 public int b;
78 public int c;
81 interface R2 {
84 class R1 : MarshalByRefObject, R2 {
86 public int test_field = 5;
87 public object null_test_field;
89 public virtual MyStruct Add (int a, out int c, int b) {
90 Console.WriteLine ("ADD");
91 c = a + b;
93 MyStruct res = new MyStruct ();
95 res.a = a;
96 res.b = b;
97 res.c = c;
99 return res;
102 public long nonvirtual_Add (int a, int b) {
103 Console.WriteLine ("nonvirtual_Add " + a + " + " + b);
104 return a + b;
108 class R3 : MarshalByRefObject {
109 public object anObject;
112 class Test {
114 delegate MyStruct RemoteDelegate1 (int a, out int c, int b);
115 delegate long RemoteDelegate2 (int a, int b);
117 static long test_call (R1 o)
119 return o.nonvirtual_Add (2, 3);
122 static int Main () {
123 R1 myobj = new R1 ();
124 int res = 0;
125 long lres;
127 MyProxy real_proxy = new MyProxy (myobj);
129 R1 o = (R1)real_proxy.GetTransparentProxy ();
131 if (RemotingServices.IsTransparentProxy (null))
132 return 1;
134 if (!RemotingServices.IsTransparentProxy (o))
135 return 2;
137 Console.WriteLine ("XXXXXXXXXXXX: " + RemotingServices.GetRealProxy (o));
139 if (o.GetType () != myobj.GetType ())
140 return 3;
142 MyStruct myres = o.Add (2, out res, 3);
144 Console.WriteLine ("Result: " + myres.a + " " +
145 myres.b + " " + myres.c + " " + res);
147 if (myres.a != 2)
148 return 4;
150 if (myres.b != 3)
151 return 5;
153 if (myres.c != 5)
154 return 6;
156 if (res != 5)
157 return 7;
159 R1 o2 = new R1 ();
161 lres = test_call (o2);
163 lres = test_call (o);
165 Console.WriteLine ("Result: " + lres);
166 if (lres != 5)
167 return 8;
169 lres = test_call (o);
171 o.test_field = 2;
173 Console.WriteLine ("test_field: " + o.test_field);
174 if (o.test_field != 2)
175 return 9;
177 RemoteDelegate1 d1 = new RemoteDelegate1 (o.Add);
178 MyStruct myres2 = d1 (2, out res, 3);
180 Console.WriteLine ("Result: " + myres2.a + " " +
181 myres2.b + " " + myres2.c + " " + res);
183 if (myres2.a != 2)
184 return 10;
186 if (myres2.b != 3)
187 return 11;
189 if (myres2.c != 5)
190 return 12;
192 if (res != 5)
193 return 13;
195 RemoteDelegate2 d2 = new RemoteDelegate2 (o.nonvirtual_Add);
196 d2 (6, 7);
198 if (!(real_proxy.GetTransparentProxy () is R2))
199 return 14;
201 /* Test what happens if the proxy doesn't return the required information */
202 EmptyProxy handler = new EmptyProxy ( typeof (R3) );
203 R3 o3 = (R3)handler.GetTransparentProxy();
205 if (o3.anObject != null)
206 return 15;
208 if (o.null_test_field != null)
209 return 16;
211 return 0;