AsyncCalls.cs 7.1 KB

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