Merge pull request #5428 from kumpera/wasm-support-p2
[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 public struct TestStruct {
64   public int F;
65 }
66         
67 class R1 : MarshalByRefObject {
68
69         public TestStruct S;
70
71         public int test_field = 5;
72         
73         public virtual int ldfield_test () {
74
75                 MyProxy real_proxy = new MyProxy (this);
76                 R1 o = (R1)real_proxy.GetTransparentProxy ();
77
78                 if (o.test_field != 1)
79                         return 1;
80
81                 if (test_field != 1)
82                         return 1;
83
84                 return 0;
85         }
86 }
87
88 class Test {
89         
90         static int Main () {
91                 R1 myobj = new R1 ();
92
93                 // Test ldflda on MarshalByRefObjects
94                 myobj.S.F = -1;
95                 if (myobj.S.F != -1)
96                         return 1;
97
98                 return myobj.ldfield_test ();
99         }
100 }