new test
[mono.git] / mono / tests / remoting5.cs
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;
7
8 class MyProxy : RealProxy {
9         readonly MarshalByRefObject target;
10
11         public MyProxy (MarshalByRefObject target) : base (target.GetType())
12         {
13                 this.target = target;
14         }
15
16         public override IMessage Invoke (IMessage request) {
17                 IMethodCallMessage call = (IMethodCallMessage)request;
18                 Console.WriteLine ("Invoke " + call.MethodName);
19
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));
26                 }
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));
34                 }
35                 Console.WriteLine (")");
36
37                 ((R1)target).test_field = 1;
38                 
39                 IMethodReturnMessage res = RemotingServices.ExecuteMessage (target, call);
40
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));
47                 }
48                 Console.WriteLine (")");                
49         
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));
56                 }
57                 Console.WriteLine (")");                
58          
59                 return res;
60         }
61 }
62
63         
64 class R1 : MarshalByRefObject {
65
66         public int test_field = 5;
67         
68         public virtual int ldfield_test () {
69
70                 MyProxy real_proxy = new MyProxy (this);
71                 R1 o = (R1)real_proxy.GetTransparentProxy ();
72
73                 if (o.test_field != 1)
74                         return 1;
75
76                 return 0;
77         }
78 }
79
80 class Test {
81         
82         static int Main () {
83                 R1 myobj = new R1 ();
84
85                 return myobj.ldfield_test ();
86         }
87 }