PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Runtime/Tests/ETScenariosCSLinq/CSLinq/ExpressionCompiler/lift_BackSl_lift_BackSl_test2.cs

#
C# | 529 lines | 442 code | 67 blank | 20 comment | 44 complexity | fee6f2edaf42344a4835daad0f99abc7 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. #if !CLR2
  2. using System.Linq.Expressions;
  3. #else
  4. using Microsoft.Scripting.Ast;
  5. using Microsoft.Scripting.Utils;
  6. #endif
  7. using System.Reflection;
  8. using System;
  9. namespace ExpressionCompiler {
  10. //-------- Scenario 267
  11. namespace Scenario267{
  12. public class Test
  13. {
  14. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "And__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  15. public static Expression And__() {
  16. if(Main() != 0 ) {
  17. throw new Exception();
  18. } else {
  19. return Expression.Constant(0);
  20. }
  21. }
  22. public static int Main()
  23. {
  24. Ext.StartCapture();
  25. bool success = false;
  26. try
  27. {
  28. success = check_boolq_And();
  29. }
  30. finally
  31. {
  32. Ext.StopCapture();
  33. }
  34. return success ? 0 : 1;
  35. }
  36. static bool check_boolq_And()
  37. {
  38. bool?[] svals = new bool?[] { null, true, false };
  39. for (int i = 0; i < svals.Length; i++)
  40. {
  41. for (int j = 0; j < svals.Length; j++)
  42. {
  43. if (!check_boolq_And(svals[i], svals[j]))
  44. {
  45. Console.WriteLine("boolq_And failed");
  46. return false;
  47. }
  48. }
  49. }
  50. return true;
  51. }
  52. static bool And(bool val0, bool val1)
  53. {
  54. return val0 & val1;
  55. }
  56. static bool check_boolq_And(bool? val0, bool? val1)
  57. {
  58. ParameterExpression p0 = Expression.Parameter(typeof(bool), "p0");
  59. ParameterExpression p1 = Expression.Parameter(typeof(bool), "p1");
  60. Expression<Func<bool?>> e = Expression.Lambda<Func<bool?>>(
  61. Expression.And(
  62. Expression.Constant(val0, typeof(bool?)),
  63. Expression.Constant(val1, typeof(bool?)),
  64. typeof(Test).GetMethod("And")
  65. ),
  66. new ParameterExpression[] { });
  67. Func<bool?> f = e.Compile();
  68. bool? fResult = default(bool);
  69. Exception fEx = null;
  70. try
  71. {
  72. fResult = f();
  73. }
  74. catch (Exception ex)
  75. {
  76. fEx = ex;
  77. }
  78. bool? csResult = (val0) & (val1);
  79. bool result = object.Equals(fResult, csResult);
  80. return result;
  81. }
  82. }
  83. public static class Ext {
  84. public static void StartCapture() {
  85. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  86. // m.Invoke(null, new object[] { "test.dll" });
  87. }
  88. public static void StopCapture() {
  89. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  90. // m.Invoke(null, new object[0]);
  91. }
  92. public static bool IsIntegralOrEnum(Type type) {
  93. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  94. case TypeCode.Byte:
  95. case TypeCode.SByte:
  96. case TypeCode.Int16:
  97. case TypeCode.Int32:
  98. case TypeCode.Int64:
  99. case TypeCode.UInt16:
  100. case TypeCode.UInt32:
  101. case TypeCode.UInt64:
  102. return true;
  103. default:
  104. return false;
  105. }
  106. }
  107. public static bool IsFloating(Type type) {
  108. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  109. case TypeCode.Single:
  110. case TypeCode.Double:
  111. return true;
  112. default:
  113. return false;
  114. }
  115. }
  116. public static Type GetNonNullableType(Type type) {
  117. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  118. type.GetGenericArguments()[0] :
  119. type;
  120. }
  121. }
  122. }
  123. //-------- Scenario 268
  124. namespace Scenario268{
  125. public class Test
  126. {
  127. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Or__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  128. public static Expression Or__() {
  129. if(Main() != 0 ) {
  130. throw new Exception();
  131. } else {
  132. return Expression.Constant(0);
  133. }
  134. }
  135. public static int Main()
  136. {
  137. Ext.StartCapture();
  138. bool success = false;
  139. try
  140. {
  141. success = check_boolq_Or();
  142. }
  143. finally
  144. {
  145. Ext.StopCapture();
  146. }
  147. return success ? 0 : 1;
  148. }
  149. static bool check_boolq_Or()
  150. {
  151. bool?[] svals = new bool?[] { null, true, false };
  152. for (int i = 0; i < svals.Length; i++)
  153. {
  154. for (int j = 0; j < svals.Length; j++)
  155. {
  156. if (!check_boolq_Or(svals[i], svals[j]))
  157. {
  158. Console.WriteLine("boolq_Or failed");
  159. return false;
  160. }
  161. }
  162. }
  163. return true;
  164. }
  165. static bool Or(bool val0, bool val1)
  166. {
  167. return val0 | val1;
  168. }
  169. static bool check_boolq_Or(bool? val0, bool? val1)
  170. {
  171. ParameterExpression p0 = Expression.Parameter(typeof(bool), "p0");
  172. ParameterExpression p1 = Expression.Parameter(typeof(bool), "p1");
  173. Expression<Func<bool?>> e = Expression.Lambda<Func<bool?>>(
  174. Expression.Or(
  175. Expression.Constant(val0, typeof(bool?)),
  176. Expression.Constant(val1, typeof(bool?)),
  177. typeof(Test).GetMethod("Or")
  178. ),
  179. new ParameterExpression[] { });
  180. Func<bool?> f = e.Compile();
  181. bool? fResult = default(bool);
  182. Exception fEx = null;
  183. try
  184. {
  185. fResult = f();
  186. }
  187. catch (Exception ex)
  188. {
  189. fEx = ex;
  190. }
  191. bool? csResult = (val0) | (val1);
  192. bool result = object.Equals(fResult, csResult);
  193. return result;
  194. }
  195. }
  196. public static class Ext {
  197. public static void StartCapture() {
  198. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  199. // m.Invoke(null, new object[] { "test.dll" });
  200. }
  201. public static void StopCapture() {
  202. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  203. // m.Invoke(null, new object[0]);
  204. }
  205. public static bool IsIntegralOrEnum(Type type) {
  206. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  207. case TypeCode.Byte:
  208. case TypeCode.SByte:
  209. case TypeCode.Int16:
  210. case TypeCode.Int32:
  211. case TypeCode.Int64:
  212. case TypeCode.UInt16:
  213. case TypeCode.UInt32:
  214. case TypeCode.UInt64:
  215. return true;
  216. default:
  217. return false;
  218. }
  219. }
  220. public static bool IsFloating(Type type) {
  221. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  222. case TypeCode.Single:
  223. case TypeCode.Double:
  224. return true;
  225. default:
  226. return false;
  227. }
  228. }
  229. public static Type GetNonNullableType(Type type) {
  230. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  231. type.GetGenericArguments()[0] :
  232. type;
  233. }
  234. }
  235. }
  236. //-------- Scenario 269
  237. namespace Scenario269{
  238. public class Test
  239. {
  240. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "AndAlso__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  241. public static Expression AndAlso__() {
  242. if(Main() != 0 ) {
  243. throw new Exception();
  244. } else {
  245. return Expression.Constant(0);
  246. }
  247. }
  248. public static int Main()
  249. {
  250. Ext.StartCapture();
  251. bool success = false;
  252. try
  253. {
  254. success = check_boolq_AndAlso();
  255. }
  256. finally
  257. {
  258. Ext.StopCapture();
  259. }
  260. return success ? 0 : 1;
  261. }
  262. static bool check_boolq_AndAlso()
  263. {
  264. bool?[] svals = new bool?[] { null, true, false };
  265. for (int i = 0; i < svals.Length; i++)
  266. {
  267. for (int j = 0; j < svals.Length; j++)
  268. {
  269. if (!check_boolq_AndAlso(svals[i], svals[j]))
  270. {
  271. Console.WriteLine("boolq_AndAlso failed");
  272. return false;
  273. }
  274. }
  275. }
  276. return true;
  277. }
  278. static bool AndAlso(bool val0, bool val1)
  279. {
  280. return val0 && val1;
  281. }
  282. static bool check_boolq_AndAlso(bool? val0, bool? val1)
  283. {
  284. ParameterExpression p0 = Expression.Parameter(typeof(bool), "p0");
  285. ParameterExpression p1 = Expression.Parameter(typeof(bool), "p1");
  286. Expression<Func<bool?>> e = Expression.Lambda<Func<bool?>>(
  287. Expression.AndAlso(
  288. Expression.Constant(val0, typeof(bool?)),
  289. Expression.Constant(val1, typeof(bool?)),
  290. typeof(Test).GetMethod("AndAlso")
  291. ),
  292. new ParameterExpression[] { });
  293. Func<bool?> f = e.Compile();
  294. bool? fResult = default(bool);
  295. Exception fEx = null;
  296. try
  297. {
  298. fResult = f();
  299. }
  300. catch (Exception ex)
  301. {
  302. fEx = ex;
  303. }
  304. bool? csResult = (val0) == false ? false : (val0) & (val1);
  305. bool result = object.Equals(fResult, csResult);
  306. return result;
  307. }
  308. }
  309. public static class Ext {
  310. public static void StartCapture() {
  311. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  312. // m.Invoke(null, new object[] { "test.dll" });
  313. }
  314. public static void StopCapture() {
  315. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  316. // m.Invoke(null, new object[0]);
  317. }
  318. public static bool IsIntegralOrEnum(Type type) {
  319. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  320. case TypeCode.Byte:
  321. case TypeCode.SByte:
  322. case TypeCode.Int16:
  323. case TypeCode.Int32:
  324. case TypeCode.Int64:
  325. case TypeCode.UInt16:
  326. case TypeCode.UInt32:
  327. case TypeCode.UInt64:
  328. return true;
  329. default:
  330. return false;
  331. }
  332. }
  333. public static bool IsFloating(Type type) {
  334. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  335. case TypeCode.Single:
  336. case TypeCode.Double:
  337. return true;
  338. default:
  339. return false;
  340. }
  341. }
  342. public static Type GetNonNullableType(Type type) {
  343. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  344. type.GetGenericArguments()[0] :
  345. type;
  346. }
  347. }
  348. }
  349. //-------- Scenario 270
  350. namespace Scenario270{
  351. public class Test
  352. {
  353. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "OrElse__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  354. public static Expression OrElse__() {
  355. if(Main() != 0 ) {
  356. throw new Exception();
  357. } else {
  358. return Expression.Constant(0);
  359. }
  360. }
  361. public static int Main()
  362. {
  363. Ext.StartCapture();
  364. bool success = false;
  365. try
  366. {
  367. success = check_boolq_OrElse();
  368. }
  369. finally
  370. {
  371. Ext.StopCapture();
  372. }
  373. return success ? 0 : 1;
  374. }
  375. static bool check_boolq_OrElse()
  376. {
  377. bool?[] svals = new bool?[] { null, true, false };
  378. for (int i = 0; i < svals.Length; i++)
  379. {
  380. for (int j = 0; j < svals.Length; j++)
  381. {
  382. if (!check_boolq_OrElse(svals[i], svals[j]))
  383. {
  384. Console.WriteLine("boolq_OrElse failed");
  385. return false;
  386. }
  387. }
  388. }
  389. return true;
  390. }
  391. static bool OrElse(bool val0, bool val1)
  392. {
  393. return val0 || val1;
  394. }
  395. static bool check_boolq_OrElse(bool? val0, bool? val1)
  396. {
  397. ParameterExpression p0 = Expression.Parameter(typeof(bool), "p0");
  398. ParameterExpression p1 = Expression.Parameter(typeof(bool), "p1");
  399. Expression<Func<bool?>> e = Expression.Lambda<Func<bool?>>(
  400. Expression.OrElse(
  401. Expression.Constant(val0, typeof(bool?)),
  402. Expression.Constant(val1, typeof(bool?)),
  403. typeof(Test).GetMethod("OrElse")
  404. ),
  405. new ParameterExpression[] { });
  406. Func<bool?> f = e.Compile();
  407. bool? fResult = default(bool);
  408. Exception fEx = null;
  409. try
  410. {
  411. fResult = f();
  412. }
  413. catch (Exception ex)
  414. {
  415. fEx = ex;
  416. }
  417. bool? csResult = (val0) == true ? true : (val0) | (val1);
  418. bool result = object.Equals(fResult, csResult);
  419. return result;
  420. }
  421. }
  422. public static class Ext {
  423. public static void StartCapture() {
  424. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  425. // m.Invoke(null, new object[] { "test.dll" });
  426. }
  427. public static void StopCapture() {
  428. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  429. // m.Invoke(null, new object[0]);
  430. }
  431. public static bool IsIntegralOrEnum(Type type) {
  432. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  433. case TypeCode.Byte:
  434. case TypeCode.SByte:
  435. case TypeCode.Int16:
  436. case TypeCode.Int32:
  437. case TypeCode.Int64:
  438. case TypeCode.UInt16:
  439. case TypeCode.UInt32:
  440. case TypeCode.UInt64:
  441. return true;
  442. default:
  443. return false;
  444. }
  445. }
  446. public static bool IsFloating(Type type) {
  447. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  448. case TypeCode.Single:
  449. case TypeCode.Double:
  450. return true;
  451. default:
  452. return false;
  453. }
  454. }
  455. public static Type GetNonNullableType(Type type) {
  456. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  457. type.GetGenericArguments()[0] :
  458. type;
  459. }
  460. }
  461. }
  462. }