2010-01-04 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / remoting5.cs
blob223fd112f01e2a2ae69ae3c7e8ab575203c74d2d
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 ((R1)target).test_field = 1;
39 IMethodReturnMessage res = RemotingServices.ExecuteMessage (target, call);
41 Console.Write ("RESARGS(");
42 for (int i = 0; i < res.ArgCount; i++) {
43 if (i != 0)
44 Console.Write (", ");
45 Console.Write (res.GetArgName (i) + " " +
46 res.GetArg (i));
48 Console.WriteLine (")");
50 Console.Write ("RESOUTARGS(");
51 for (int i = 0; i < res.OutArgCount; i++) {
52 if (i != 0)
53 Console.Write (", ");
54 Console.Write (res.GetOutArgName (i) + " " +
55 res.GetOutArg (i));
57 Console.WriteLine (")");
59 return res;
63 public struct TestStruct {
64 public int F;
67 class R1 : MarshalByRefObject {
69 public TestStruct S;
71 public int test_field = 5;
73 public virtual int ldfield_test () {
75 MyProxy real_proxy = new MyProxy (this);
76 R1 o = (R1)real_proxy.GetTransparentProxy ();
78 if (o.test_field != 1)
79 return 1;
81 if (test_field != 1)
82 return 1;
84 return 0;
88 class Test {
90 static int Main () {
91 R1 myobj = new R1 ();
93 // Test ldflda on MarshalByRefObjects
94 myobj.S.F = -1;
95 if (myobj.S.F != -1)
96 return 1;
98 return myobj.ldfield_test ();