PageRenderTime 24ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_2_6/Src/IronPythonTest/DeTest.cs

#
C# | 252 lines | 189 code | 34 blank | 29 comment | 26 complexity | 8a066f7943cb5173a84b4e27855d9ff5 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Microsoft Public License. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Microsoft Public License, please send an email to
  8. * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Microsoft Public License.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System;
  16. namespace IronPythonTest {
  17. public enum DeTestEnum {
  18. Value_0,
  19. Value_1,
  20. Value_2,
  21. Value_3,
  22. Value_4
  23. }
  24. public enum DeTestEnumLong : long {
  25. Value_1 = 12345678901234L,
  26. Value_2 = 43210987654321L
  27. }
  28. public struct DeTestStruct {
  29. public int intVal;
  30. //public string stringVal;
  31. //public float floatVal;
  32. //public double doubleVal;
  33. //public DeTestEnum eshort;
  34. //public DeTestEnumLong elong;
  35. #pragma warning disable 169
  36. void Init() {
  37. intVal = 0;
  38. //stringVal = "Hello";
  39. //floatVal = 0;
  40. //doubleVal = 0;
  41. //eshort = DeTestEnum.Value_3;
  42. //elong = DeTestEnumLong.Value_2;
  43. }
  44. #pragma warning restore 169
  45. }
  46. public class DeTest {
  47. public delegate DeTestStruct TestStruct(DeTestStruct dts);
  48. public delegate string TestTrivial(string s1);
  49. public delegate string TestStringDelegate(string s1, string s2, string s3, string s4, string s5, string s6);
  50. public delegate int TestEnumDelegate(DeTestEnum e);
  51. public delegate long TestEnumDelegateLong(DeTestEnumLong e);
  52. public delegate string TestComplexDelegate(string s, int i, float f, double d, DeTestEnum e, string s2, DeTestEnum e2, DeTestEnumLong e3);
  53. public event TestStruct e_struct;
  54. public event TestTrivial e_tt;
  55. public event TestTrivial e_tt2;
  56. public event TestStringDelegate e_tsd;
  57. public event TestEnumDelegate e_ted;
  58. public event TestComplexDelegate e_tcd;
  59. public event TestEnumDelegateLong e_tedl;
  60. public TestStruct d_struct;
  61. public TestTrivial d_tt;
  62. public TestTrivial d_tt2;
  63. public TestStringDelegate d_tsd;
  64. public TestEnumDelegate d_ted;
  65. public TestComplexDelegate d_tcd;
  66. public TestEnumDelegateLong d_tedl;
  67. public string stringVal;
  68. public string stringVal2;
  69. public int intVal;
  70. public float floatVal;
  71. public double doubleVal;
  72. public DeTestEnum enumVal;
  73. public DeTestEnumLong longEnumVal;
  74. public DeTest() {
  75. }
  76. public void Init() {
  77. e_struct = ActualTestStruct;
  78. e_tt = VoidTestTrivial;
  79. e_tsd = VoidTestString;
  80. e_ted = VoidTestEnum;
  81. e_tedl = VoidTestEnumLong;
  82. e_tcd = VoidTestComplex;
  83. e_struct = ActualTestStruct;
  84. d_tt = VoidTestTrivial;
  85. d_tsd = VoidTestString;
  86. d_ted = VoidTestEnum;
  87. d_tedl = VoidTestEnumLong;
  88. d_tcd = VoidTestComplex;
  89. }
  90. public void RunTest() {
  91. if (e_struct != null) {
  92. DeTestStruct dts;
  93. dts.intVal = intVal;
  94. //dts.stringVal = stringVal;
  95. //dts.floatVal = floatVal;
  96. //dts.doubleVal = doubleVal;
  97. //dts.elong = longEnumVal;
  98. //dts.eshort = enumVal;
  99. e_struct(dts);
  100. }
  101. if (e_tt != null) {
  102. e_tt(stringVal);
  103. }
  104. if (e_tt2 != null) {
  105. e_tt2(stringVal2);
  106. }
  107. if (d_tt != null) {
  108. d_tt(stringVal);
  109. }
  110. if (e_tsd != null) {
  111. e_tsd(stringVal, stringVal2, stringVal, stringVal2, stringVal, stringVal2);
  112. }
  113. if (d_tsd != null) {
  114. d_tsd(stringVal, stringVal2, stringVal, stringVal2, stringVal, stringVal2);
  115. }
  116. if (e_ted != null) {
  117. e_ted(enumVal);
  118. }
  119. if (d_ted != null) {
  120. d_ted(enumVal);
  121. }
  122. if (e_tedl != null) {
  123. e_tedl(longEnumVal);
  124. }
  125. if (d_tedl != null) {
  126. d_tedl(longEnumVal);
  127. }
  128. if (e_tcd != null) {
  129. e_tcd(stringVal, intVal, floatVal, doubleVal, enumVal, stringVal2, enumVal, longEnumVal);
  130. }
  131. if (d_tcd != null) {
  132. d_tcd(stringVal, intVal, floatVal, doubleVal, enumVal, stringVal2, enumVal, longEnumVal);
  133. }
  134. }
  135. public DeTestStruct ActualTestStruct(DeTestStruct dts) {
  136. object x = dts;
  137. return (DeTestStruct)x;
  138. }
  139. public string ActualTestTrivial(string s1) {
  140. return s1;
  141. }
  142. public string VoidTestTrivial(string s1) {
  143. return String.Empty;
  144. }
  145. public string ActualTestString(string s1, string s2, string s3, string s4, string s5, string s6) {
  146. return s1 + " " + s2 + " " + s3 + " " + s4 + " " + s5 + " " + s6;
  147. }
  148. public string VoidTestString(string s1, string s2, string s3, string s4, string s5, string s6) {
  149. return String.Empty;
  150. }
  151. public int ActualTestEnum(DeTestEnum e) {
  152. return (int)e + 1000;
  153. }
  154. public int VoidTestEnum(DeTestEnum e) {
  155. return 0;
  156. }
  157. public long ActualTestEnumLong(DeTestEnumLong e) {
  158. return (long)e + 1000000000;
  159. }
  160. public long VoidTestEnumLong(DeTestEnumLong e) {
  161. return 0;
  162. }
  163. public string ActualTestComplex(string s, int i, float f, double d, DeTestEnum e, string s2, DeTestEnum e2, DeTestEnumLong e3) {
  164. return s + " " + i.ToString() + " " + f.ToString() + " " + d.ToString() + " " + s2 + " " + e2.ToString() + " " + e3.ToString();
  165. }
  166. public string VoidTestComplex(string s, int i, float f, double d, DeTestEnum e, string s2, DeTestEnum e2, DeTestEnumLong e3) {
  167. return String.Empty;
  168. }
  169. public void SetupE() {
  170. e_tt = ActualTestTrivial;
  171. e_tt2 = ActualTestTrivial;
  172. e_tsd = ActualTestString;
  173. e_ted = ActualTestEnum;
  174. e_tedl = ActualTestEnumLong;
  175. e_tcd = ActualTestComplex;
  176. }
  177. public void SetupS() {
  178. e_struct += ActualTestStruct;
  179. e_struct += ActualTestStruct;
  180. }
  181. public void SetupD() {
  182. d_tt = ActualTestTrivial;
  183. d_tt2 = ActualTestTrivial;
  184. d_tsd = ActualTestString;
  185. d_ted = ActualTestEnum;
  186. d_tedl = ActualTestEnumLong;
  187. d_tcd = ActualTestComplex;
  188. }
  189. public void Setup() {
  190. SetupE();
  191. SetupD();
  192. }
  193. public static DeTestStruct staticDeTestStruct(object o, DeTestStruct dts) {
  194. object oo = dts;
  195. return (DeTestStruct)oo;
  196. }
  197. public static void Test() {
  198. DeTest dt = new DeTest();
  199. dt.SetupS();
  200. dt.RunTest();
  201. }
  202. }
  203. public delegate float FloatDelegate(float f);
  204. public class ReturnTypes {
  205. public event FloatDelegate floatEvent;
  206. public float RunFloat(float f) {
  207. return floatEvent(f);
  208. }
  209. }
  210. public delegate void VoidDelegate();
  211. public class SimpleType {
  212. public event VoidDelegate SimpleEvent;
  213. public void RaiseEvent() {
  214. if (SimpleEvent != null)
  215. SimpleEvent();
  216. }
  217. }
  218. }