2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Runtime.Remoting / Test / AsyncCalls.cs
1 //
2 // MonoTests.Remoting.AsyncCalls.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.Collections;
11 using System.Threading;
12 using NUnit.Framework;
13 using System.Text;
14 using System.Runtime.InteropServices;
15
16 namespace MonoTests.Remoting
17 {
18         public abstract class AsyncCallTest : BaseCallTest
19         {
20                 public override InstanceSurrogate GetInstanceSurrogate () { return new AsyncInstanceSurrogate (); }
21                 public override AbstractSurrogate GetAbstractSurrogate () { return new AsyncAbstractSurrogate (); }
22                 public override InterfaceSurrogate GetInterfaceSurrogate () { return new AsyncInterfaceSurrogate (); }
23
24                 public static void DoWork ()
25                 {
26                         for (int n=0; n<10; n++)
27                                 Thread.Sleep (1);
28                 }
29         }
30
31         public delegate int DelegateSimple ();
32         public delegate string DelegatePrimitiveParams (int a, uint b, char c, string d);
33         public delegate string DelegatePrimitiveParamsInOut (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);
34         public delegate Complex DelegateComplexParams (ArrayList a, Complex b, string c);
35         public delegate Complex DelegateComplexParamsInOut (ref ArrayList a, out Complex b, byte[] bytes, StringBuilder sb, string c);
36         public delegate void DelegateProcessContextData ();
37
38         public class AsyncInstanceSurrogate : InstanceSurrogate
39         {
40                 public override int Simple ()
41                 {
42                         DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
43                         IAsyncResult ar = de.BeginInvoke (null,null);
44                         AsyncCallTest.DoWork ();
45                         return de.EndInvoke (ar);
46                 }
47
48                 public override string PrimitiveParams (int a, uint b, char c, string d)
49                 {
50                         DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
51                         IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
52                         AsyncCallTest.DoWork ();
53                         return de.EndInvoke (ar);
54                 }
55
56                 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)
57                 {
58                         DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
59                         IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
60                         AsyncCallTest.DoWork ();
61                         return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
62                 }
63
64                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
65                 {
66                         DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
67                         IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
68                         AsyncCallTest.DoWork ();
69                         return de.EndInvoke (ar);
70                 }
71
72                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
73                 {
74                         DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
75                         IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
76                         AsyncCallTest.DoWork ();
77                         return de.EndInvoke (ref a, out b, ar);
78                 }
79
80                 public override void ProcessContextData ()
81                 {
82                         DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
83                         IAsyncResult ar = de.BeginInvoke (null,null);
84                         AsyncCallTest.DoWork ();
85                         de.EndInvoke (ar);
86                 }
87         }
88
89         public class AsyncAbstractSurrogate : AbstractSurrogate
90         {
91                 public override int Simple ()
92                 {
93                         DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
94                         IAsyncResult ar = de.BeginInvoke (null,null);
95                         AsyncCallTest.DoWork ();
96                         return de.EndInvoke (ar);
97                 }
98
99                 public override string PrimitiveParams (int a, uint b, char c, string d)
100                 {
101                         DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
102                         IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
103                         AsyncCallTest.DoWork ();
104                         return de.EndInvoke (ar);
105                 }
106
107                 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)
108                 {
109                         DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
110                         IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
111                         AsyncCallTest.DoWork ();
112                         return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
113                 }
114
115                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
116                 {
117                         DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
118                         IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
119                         AsyncCallTest.DoWork ();
120                         return de.EndInvoke (ar);
121                 }
122
123                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
124                 {
125                         DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
126                         IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
127                         AsyncCallTest.DoWork ();
128                         return de.EndInvoke (ref a, out b, ar);
129                 }
130
131                 public override void ProcessContextData ()
132                 {
133                         DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
134                         IAsyncResult ar = de.BeginInvoke (null,null);
135                         AsyncCallTest.DoWork ();
136                         de.EndInvoke (ar);
137                 }
138         }
139
140         public class AsyncInterfaceSurrogate : InterfaceSurrogate
141         {
142                 public override int Simple ()
143                 {
144                         DelegateSimple de = new DelegateSimple (RemoteObject.Simple);
145                         IAsyncResult ar = de.BeginInvoke (null,null);
146                         AsyncCallTest.DoWork ();
147                         return de.EndInvoke (ar);
148                 }
149
150                 public override string PrimitiveParams (int a, uint b, char c, string d)
151                 {
152                         DelegatePrimitiveParams de = new DelegatePrimitiveParams (RemoteObject.PrimitiveParams);
153                         IAsyncResult ar = de.BeginInvoke (a,b,c,d,null,null);
154                         AsyncCallTest.DoWork ();
155                         return de.EndInvoke (ar);
156                 }
157
158                 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)
159                 {
160                         DelegatePrimitiveParamsInOut de = new DelegatePrimitiveParamsInOut (RemoteObject.PrimitiveParamsInOut);
161                         IAsyncResult ar = de.BeginInvoke (ref a1, out a2, ref b1, out b2, filler, ref c1, out c2, ref d1, out d2, null,null);
162                         AsyncCallTest.DoWork ();
163                         return de.EndInvoke (ref a1, out a2, ref b1, out b2, ref c1, out c2, ref d1, out d2, ar);
164                 }
165
166                 public override Complex ComplexParams (ArrayList a, Complex b, string c)
167                 {
168                         DelegateComplexParams de = new DelegateComplexParams (RemoteObject.ComplexParams);
169                         IAsyncResult ar = de.BeginInvoke (a,b,c,null,null);
170                         AsyncCallTest.DoWork ();
171                         return de.EndInvoke (ar);
172                 }
173
174                 public override Complex ComplexParamsInOut (ref ArrayList a, out Complex b, [In,Out] byte[] bytes, StringBuilder sb, string c)
175                 {
176                         DelegateComplexParamsInOut de = new DelegateComplexParamsInOut (RemoteObject.ComplexParamsInOut);
177                         IAsyncResult ar = de.BeginInvoke (ref a, out b, bytes, sb, c, null,null);
178                         AsyncCallTest.DoWork ();
179                         return de.EndInvoke (ref a, out b, ar);
180                 }
181
182                 public override void ProcessContextData ()
183                 {
184                         DelegateProcessContextData de = new DelegateProcessContextData (RemoteObject.ProcessContextData);
185                         IAsyncResult ar = de.BeginInvoke (null,null);
186                         AsyncCallTest.DoWork ();
187                         de.EndInvoke (ar);
188                 }
189         }
190 }