2 // MonoTests.Remoting.AsyncCalls.cs
4 // Author: Lluis Sanchez Gual (lluis@ximian.com)
6 // 2003 (C) Copyright, Ximian, Inc.
10 using System
.Collections
;
11 using System
.Threading
;
12 using NUnit
.Framework
;
14 using System
.Runtime
.InteropServices
;
16 namespace MonoTests
.Remoting
18 public abstract class AsyncCallTest
: BaseCallTest
20 public override InstanceSurrogate
GetInstanceSurrogate () { return new AsyncInstanceSurrogate (); }
21 public override AbstractSurrogate
GetAbstractSurrogate () { return new AsyncAbstractSurrogate (); }
22 public override InterfaceSurrogate
GetInterfaceSurrogate () { return new AsyncInterfaceSurrogate (); }
24 public static void DoWork ()
26 for (int n
=0; n
<10; n
++)
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 ();
38 public class AsyncInstanceSurrogate
: InstanceSurrogate
40 public override int Simple ()
42 DelegateSimple de
= new DelegateSimple (RemoteObject
.Simple
);
43 IAsyncResult ar
= de
.BeginInvoke (null,null);
44 AsyncCallTest
.DoWork ();
45 return de
.EndInvoke (ar
);
48 public override string PrimitiveParams (int a
, uint b
, char c
, string d
)
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
);
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
)
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
);
64 public override Complex
ComplexParams (ArrayList a
, Complex b
, string c
)
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
);
72 public override Complex
ComplexParamsInOut (ref ArrayList a
, out Complex b
, [In
,Out
] byte[] bytes
, StringBuilder sb
, string c
)
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
);
80 public override void ProcessContextData ()
82 DelegateProcessContextData de
= new DelegateProcessContextData (RemoteObject
.ProcessContextData
);
83 IAsyncResult ar
= de
.BeginInvoke (null,null);
84 AsyncCallTest
.DoWork ();
89 public class AsyncAbstractSurrogate
: AbstractSurrogate
91 public override int Simple ()
93 DelegateSimple de
= new DelegateSimple (RemoteObject
.Simple
);
94 IAsyncResult ar
= de
.BeginInvoke (null,null);
95 AsyncCallTest
.DoWork ();
96 return de
.EndInvoke (ar
);
99 public override string PrimitiveParams (int a
, uint b
, char c
, string d
)
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
);
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
)
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
);
115 public override Complex
ComplexParams (ArrayList a
, Complex b
, string c
)
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
);
123 public override Complex
ComplexParamsInOut (ref ArrayList a
, out Complex b
, [In
,Out
] byte[] bytes
, StringBuilder sb
, string c
)
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
);
131 public override void ProcessContextData ()
133 DelegateProcessContextData de
= new DelegateProcessContextData (RemoteObject
.ProcessContextData
);
134 IAsyncResult ar
= de
.BeginInvoke (null,null);
135 AsyncCallTest
.DoWork ();
140 public class AsyncInterfaceSurrogate
: InterfaceSurrogate
142 public override int Simple ()
144 DelegateSimple de
= new DelegateSimple (RemoteObject
.Simple
);
145 IAsyncResult ar
= de
.BeginInvoke (null,null);
146 AsyncCallTest
.DoWork ();
147 return de
.EndInvoke (ar
);
150 public override string PrimitiveParams (int a
, uint b
, char c
, string d
)
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
);
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
)
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
);
166 public override Complex
ComplexParams (ArrayList a
, Complex b
, string c
)
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
);
174 public override Complex
ComplexParamsInOut (ref ArrayList a
, out Complex b
, [In
,Out
] byte[] bytes
, StringBuilder sb
, string c
)
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
);
182 public override void ProcessContextData ()
184 DelegateProcessContextData de
= new DelegateProcessContextData (RemoteObject
.ProcessContextData
);
185 IAsyncResult ar
= de
.BeginInvoke (null,null);
186 AsyncCallTest
.DoWork ();