PageRenderTime 53ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 1045 lines | 866 code | 139 blank | 40 comment | 64 complexity | 6450423675f1aae5cd9539264c550c5b 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 302
  11. namespace Scenario302{
  12. public class Test
  13. {
  14. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "byteq_Not__1", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  15. public static Expression byteq_Not__1() {
  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_byteq_Not();
  29. }
  30. finally
  31. {
  32. Ext.StopCapture();
  33. }
  34. return success ? 0 : 1;
  35. }
  36. static bool check_byteq_Not() {
  37. foreach (byte? val in new byte?[] { 0, 1, byte.MaxValue }) {
  38. if (!check_byteq_Not(val)) {
  39. Console.WriteLine("byteq_Not failed");
  40. return false;
  41. }
  42. }
  43. return true;
  44. }
  45. static bool check_byteq_Not(byte? val) {
  46. ParameterExpression p = Expression.Parameter(typeof(byte?), "p");
  47. Expression<Func<byte?>> e1 = Expression.Lambda<Func<byte?>>(
  48. Expression.Invoke(
  49. Expression.Lambda<Func<byte?, byte?>>(
  50. Expression.Not(p),
  51. new ParameterExpression[] { p }),
  52. new Expression[] { Expression.Constant(val, typeof(byte?)) }),
  53. new System.Collections.Generic.List<ParameterExpression>());
  54. Func<byte?> f1 = e1.Compile();
  55. Expression<Func<byte?, Func<byte?>>> e2 = Expression.Lambda<Func<byte?, Func<byte?>>>(
  56. Expression.Lambda<Func<byte?>>(Expression.Not(p), new System.Collections.Generic.List<ParameterExpression>()),
  57. new ParameterExpression[] { p });
  58. Func<byte?, Func<byte?>> f2 = e2.Compile();
  59. Expression<Func<Func<byte?, byte?>>> e3 = Expression.Lambda<Func<Func<byte?, byte?>>>(
  60. Expression.Invoke(
  61. Expression.Lambda<Func<Func<byte?, byte?>>>(
  62. Expression.Lambda<Func<byte?, byte?>>(
  63. Expression.Not(p),
  64. new ParameterExpression[] { p }),
  65. new System.Collections.Generic.List<ParameterExpression>()),
  66. new System.Collections.Generic.List<Expression>()),
  67. new System.Collections.Generic.List<ParameterExpression>());
  68. Func<byte?, byte?> f3 = e3.Compile()();
  69. Expression<Func<Func<byte?, byte?>>> e4 = Expression.Lambda<Func<Func<byte?, byte?>>>(
  70. Expression.Lambda<Func<byte?, byte?>>(
  71. Expression.Not(p),
  72. new ParameterExpression[] { p }),
  73. new System.Collections.Generic.List<ParameterExpression>());
  74. Func<Func<byte?, byte?>> f4 = e4.Compile();
  75. byte? expected = (byte?) ~val;
  76. return object.Equals(f1(), expected) &&
  77. object.Equals(f2(val)(), expected) &&
  78. object.Equals(f3(val), expected) &&
  79. object.Equals(f4()(val), expected);
  80. }
  81. }
  82. public static class Ext {
  83. public static void StartCapture() {
  84. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  85. // m.Invoke(null, new object[] { "test.dll" });
  86. }
  87. public static void StopCapture() {
  88. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  89. // m.Invoke(null, new object[0]);
  90. }
  91. public static bool IsIntegralOrEnum(Type type) {
  92. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  93. case TypeCode.Byte:
  94. case TypeCode.SByte:
  95. case TypeCode.Int16:
  96. case TypeCode.Int32:
  97. case TypeCode.Int64:
  98. case TypeCode.UInt16:
  99. case TypeCode.UInt32:
  100. case TypeCode.UInt64:
  101. return true;
  102. default:
  103. return false;
  104. }
  105. }
  106. public static bool IsFloating(Type type) {
  107. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  108. case TypeCode.Single:
  109. case TypeCode.Double:
  110. return true;
  111. default:
  112. return false;
  113. }
  114. }
  115. public static Type GetNonNullableType(Type type) {
  116. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  117. type.GetGenericArguments()[0] :
  118. type;
  119. }
  120. }
  121. }
  122. //-------- Scenario 303
  123. namespace Scenario303{
  124. public class Test
  125. {
  126. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "sbyteq_Not__1", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  127. public static Expression sbyteq_Not__1() {
  128. if(Main() != 0 ) {
  129. throw new Exception();
  130. } else {
  131. return Expression.Constant(0);
  132. }
  133. }
  134. public static int Main()
  135. {
  136. Ext.StartCapture();
  137. bool success = false;
  138. try
  139. {
  140. success = check_sbyteq_Not();
  141. }
  142. finally
  143. {
  144. Ext.StopCapture();
  145. }
  146. return success ? 0 : 1;
  147. }
  148. static bool check_sbyteq_Not() {
  149. foreach (sbyte? val in new sbyte?[] { 0, 1, -1, sbyte.MinValue, sbyte.MaxValue }) {
  150. if (!check_sbyteq_Not(val)) {
  151. Console.WriteLine("sbyteq_Not failed");
  152. return false;
  153. }
  154. }
  155. return true;
  156. }
  157. static bool check_sbyteq_Not(sbyte? val) {
  158. ParameterExpression p = Expression.Parameter(typeof(sbyte?), "p");
  159. Expression<Func<sbyte?>> e1 = Expression.Lambda<Func<sbyte?>>(
  160. Expression.Invoke(
  161. Expression.Lambda<Func<sbyte?, sbyte?>>(
  162. Expression.Not(p),
  163. new ParameterExpression[] { p }),
  164. new Expression[] { Expression.Constant(val, typeof(sbyte?)) }),
  165. new System.Collections.Generic.List<ParameterExpression>());
  166. Func<sbyte?> f1 = e1.Compile();
  167. Expression<Func<sbyte?, Func<sbyte?>>> e2 = Expression.Lambda<Func<sbyte?, Func<sbyte?>>>(
  168. Expression.Lambda<Func<sbyte?>>(Expression.Not(p), new System.Collections.Generic.List<ParameterExpression>()),
  169. new ParameterExpression[] { p });
  170. Func<sbyte?, Func<sbyte?>> f2 = e2.Compile();
  171. Expression<Func<Func<sbyte?, sbyte?>>> e3 = Expression.Lambda<Func<Func<sbyte?, sbyte?>>>(
  172. Expression.Invoke(
  173. Expression.Lambda<Func<Func<sbyte?, sbyte?>>>(
  174. Expression.Lambda<Func<sbyte?, sbyte?>>(
  175. Expression.Not(p),
  176. new ParameterExpression[] { p }),
  177. new System.Collections.Generic.List<ParameterExpression>()),
  178. new System.Collections.Generic.List<Expression>()),
  179. new System.Collections.Generic.List<ParameterExpression>());
  180. Func<sbyte?, sbyte?> f3 = e3.Compile()();
  181. Expression<Func<Func<sbyte?, sbyte?>>> e4 = Expression.Lambda<Func<Func<sbyte?, sbyte?>>>(
  182. Expression.Lambda<Func<sbyte?, sbyte?>>(
  183. Expression.Not(p),
  184. new ParameterExpression[] { p }),
  185. new System.Collections.Generic.List<ParameterExpression>());
  186. Func<Func<sbyte?, sbyte?>> f4 = e4.Compile();
  187. sbyte? expected = (sbyte?) ~val;
  188. return object.Equals(f1(), expected) &&
  189. object.Equals(f2(val)(), expected) &&
  190. object.Equals(f3(val), expected) &&
  191. object.Equals(f4()(val), expected);
  192. }
  193. }
  194. public static class Ext {
  195. public static void StartCapture() {
  196. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  197. // m.Invoke(null, new object[] { "test.dll" });
  198. }
  199. public static void StopCapture() {
  200. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  201. // m.Invoke(null, new object[0]);
  202. }
  203. public static bool IsIntegralOrEnum(Type type) {
  204. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  205. case TypeCode.Byte:
  206. case TypeCode.SByte:
  207. case TypeCode.Int16:
  208. case TypeCode.Int32:
  209. case TypeCode.Int64:
  210. case TypeCode.UInt16:
  211. case TypeCode.UInt32:
  212. case TypeCode.UInt64:
  213. return true;
  214. default:
  215. return false;
  216. }
  217. }
  218. public static bool IsFloating(Type type) {
  219. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  220. case TypeCode.Single:
  221. case TypeCode.Double:
  222. return true;
  223. default:
  224. return false;
  225. }
  226. }
  227. public static Type GetNonNullableType(Type type) {
  228. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  229. type.GetGenericArguments()[0] :
  230. type;
  231. }
  232. }
  233. }
  234. //-------- Scenario 304
  235. namespace Scenario304{
  236. public class Test
  237. {
  238. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "ushortq_Not__1", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  239. public static Expression ushortq_Not__1() {
  240. if(Main() != 0 ) {
  241. throw new Exception();
  242. } else {
  243. return Expression.Constant(0);
  244. }
  245. }
  246. public static int Main()
  247. {
  248. Ext.StartCapture();
  249. bool success = false;
  250. try
  251. {
  252. success = check_ushortq_Not();
  253. }
  254. finally
  255. {
  256. Ext.StopCapture();
  257. }
  258. return success ? 0 : 1;
  259. }
  260. static bool check_ushortq_Not() {
  261. foreach (ushort? val in new ushort?[] { 0, 1, ushort.MaxValue }) {
  262. if (!check_ushortq_Not(val)) {
  263. Console.WriteLine("ushortq_Not failed");
  264. return false;
  265. }
  266. }
  267. return true;
  268. }
  269. static bool check_ushortq_Not(ushort? val) {
  270. ParameterExpression p = Expression.Parameter(typeof(ushort?), "p");
  271. Expression<Func<ushort?>> e1 = Expression.Lambda<Func<ushort?>>(
  272. Expression.Invoke(
  273. Expression.Lambda<Func<ushort?, ushort?>>(
  274. Expression.Not(p),
  275. new ParameterExpression[] { p }),
  276. new Expression[] { Expression.Constant(val, typeof(ushort?)) }),
  277. new System.Collections.Generic.List<ParameterExpression>());
  278. Func<ushort?> f1 = e1.Compile();
  279. Expression<Func<ushort?, Func<ushort?>>> e2 = Expression.Lambda<Func<ushort?, Func<ushort?>>>(
  280. Expression.Lambda<Func<ushort?>>(Expression.Not(p), new System.Collections.Generic.List<ParameterExpression>()),
  281. new ParameterExpression[] { p });
  282. Func<ushort?, Func<ushort?>> f2 = e2.Compile();
  283. Expression<Func<Func<ushort?, ushort?>>> e3 = Expression.Lambda<Func<Func<ushort?, ushort?>>>(
  284. Expression.Invoke(
  285. Expression.Lambda<Func<Func<ushort?, ushort?>>>(
  286. Expression.Lambda<Func<ushort?, ushort?>>(
  287. Expression.Not(p),
  288. new ParameterExpression[] { p }),
  289. new System.Collections.Generic.List<ParameterExpression>()),
  290. new System.Collections.Generic.List<Expression>()),
  291. new System.Collections.Generic.List<ParameterExpression>());
  292. Func<ushort?, ushort?> f3 = e3.Compile()();
  293. Expression<Func<Func<ushort?, ushort?>>> e4 = Expression.Lambda<Func<Func<ushort?, ushort?>>>(
  294. Expression.Lambda<Func<ushort?, ushort?>>(
  295. Expression.Not(p),
  296. new ParameterExpression[] { p }),
  297. new System.Collections.Generic.List<ParameterExpression>());
  298. Func<Func<ushort?, ushort?>> f4 = e4.Compile();
  299. ushort? expected = (ushort?) ~val;
  300. return object.Equals(f1(), expected) &&
  301. object.Equals(f2(val)(), expected) &&
  302. object.Equals(f3(val), expected) &&
  303. object.Equals(f4()(val), expected);
  304. }
  305. }
  306. public static class Ext {
  307. public static void StartCapture() {
  308. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  309. // m.Invoke(null, new object[] { "test.dll" });
  310. }
  311. public static void StopCapture() {
  312. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  313. // m.Invoke(null, new object[0]);
  314. }
  315. public static bool IsIntegralOrEnum(Type type) {
  316. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  317. case TypeCode.Byte:
  318. case TypeCode.SByte:
  319. case TypeCode.Int16:
  320. case TypeCode.Int32:
  321. case TypeCode.Int64:
  322. case TypeCode.UInt16:
  323. case TypeCode.UInt32:
  324. case TypeCode.UInt64:
  325. return true;
  326. default:
  327. return false;
  328. }
  329. }
  330. public static bool IsFloating(Type type) {
  331. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  332. case TypeCode.Single:
  333. case TypeCode.Double:
  334. return true;
  335. default:
  336. return false;
  337. }
  338. }
  339. public static Type GetNonNullableType(Type type) {
  340. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  341. type.GetGenericArguments()[0] :
  342. type;
  343. }
  344. }
  345. }
  346. //-------- Scenario 305
  347. namespace Scenario305{
  348. public class Test
  349. {
  350. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "shortq_Not__1", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  351. public static Expression shortq_Not__1() {
  352. if(Main() != 0 ) {
  353. throw new Exception();
  354. } else {
  355. return Expression.Constant(0);
  356. }
  357. }
  358. public static int Main()
  359. {
  360. Ext.StartCapture();
  361. bool success = false;
  362. try
  363. {
  364. success = check_shortq_Not();
  365. }
  366. finally
  367. {
  368. Ext.StopCapture();
  369. }
  370. return success ? 0 : 1;
  371. }
  372. static bool check_shortq_Not() {
  373. foreach (short? val in new short?[] { 0, 1, -1, short.MinValue, short.MaxValue }) {
  374. if (!check_shortq_Not(val)) {
  375. Console.WriteLine("shortq_Not failed");
  376. return false;
  377. }
  378. }
  379. return true;
  380. }
  381. static bool check_shortq_Not(short? val) {
  382. ParameterExpression p = Expression.Parameter(typeof(short?), "p");
  383. Expression<Func<short?>> e1 = Expression.Lambda<Func<short?>>(
  384. Expression.Invoke(
  385. Expression.Lambda<Func<short?, short?>>(
  386. Expression.Not(p),
  387. new ParameterExpression[] { p }),
  388. new Expression[] { Expression.Constant(val, typeof(short?)) }),
  389. new System.Collections.Generic.List<ParameterExpression>());
  390. Func<short?> f1 = e1.Compile();
  391. Expression<Func<short?, Func<short?>>> e2 = Expression.Lambda<Func<short?, Func<short?>>>(
  392. Expression.Lambda<Func<short?>>(Expression.Not(p), new System.Collections.Generic.List<ParameterExpression>()),
  393. new ParameterExpression[] { p });
  394. Func<short?, Func<short?>> f2 = e2.Compile();
  395. Expression<Func<Func<short?, short?>>> e3 = Expression.Lambda<Func<Func<short?, short?>>>(
  396. Expression.Invoke(
  397. Expression.Lambda<Func<Func<short?, short?>>>(
  398. Expression.Lambda<Func<short?, short?>>(
  399. Expression.Not(p),
  400. new ParameterExpression[] { p }),
  401. new System.Collections.Generic.List<ParameterExpression>()),
  402. new System.Collections.Generic.List<Expression>()),
  403. new System.Collections.Generic.List<ParameterExpression>());
  404. Func<short?, short?> f3 = e3.Compile()();
  405. Expression<Func<Func<short?, short?>>> e4 = Expression.Lambda<Func<Func<short?, short?>>>(
  406. Expression.Lambda<Func<short?, short?>>(
  407. Expression.Not(p),
  408. new ParameterExpression[] { p }),
  409. new System.Collections.Generic.List<ParameterExpression>());
  410. Func<Func<short?, short?>> f4 = e4.Compile();
  411. short? expected = (short?) ~val;
  412. return object.Equals(f1(), expected) &&
  413. object.Equals(f2(val)(), expected) &&
  414. object.Equals(f3(val), expected) &&
  415. object.Equals(f4()(val), expected);
  416. }
  417. }
  418. public static class Ext {
  419. public static void StartCapture() {
  420. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  421. // m.Invoke(null, new object[] { "test.dll" });
  422. }
  423. public static void StopCapture() {
  424. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  425. // m.Invoke(null, new object[0]);
  426. }
  427. public static bool IsIntegralOrEnum(Type type) {
  428. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  429. case TypeCode.Byte:
  430. case TypeCode.SByte:
  431. case TypeCode.Int16:
  432. case TypeCode.Int32:
  433. case TypeCode.Int64:
  434. case TypeCode.UInt16:
  435. case TypeCode.UInt32:
  436. case TypeCode.UInt64:
  437. return true;
  438. default:
  439. return false;
  440. }
  441. }
  442. public static bool IsFloating(Type type) {
  443. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  444. case TypeCode.Single:
  445. case TypeCode.Double:
  446. return true;
  447. default:
  448. return false;
  449. }
  450. }
  451. public static Type GetNonNullableType(Type type) {
  452. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  453. type.GetGenericArguments()[0] :
  454. type;
  455. }
  456. }
  457. }
  458. //-------- Scenario 306
  459. namespace Scenario306{
  460. public class Test
  461. {
  462. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "uintq_Not__1", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  463. public static Expression uintq_Not__1() {
  464. if(Main() != 0 ) {
  465. throw new Exception();
  466. } else {
  467. return Expression.Constant(0);
  468. }
  469. }
  470. public static int Main()
  471. {
  472. Ext.StartCapture();
  473. bool success = false;
  474. try
  475. {
  476. success = check_uintq_Not();
  477. }
  478. finally
  479. {
  480. Ext.StopCapture();
  481. }
  482. return success ? 0 : 1;
  483. }
  484. static bool check_uintq_Not() {
  485. foreach (uint? val in new uint?[] { 0, 1, uint.MaxValue }) {
  486. if (!check_uintq_Not(val)) {
  487. Console.WriteLine("uintq_Not failed");
  488. return false;
  489. }
  490. }
  491. return true;
  492. }
  493. static bool check_uintq_Not(uint? val) {
  494. ParameterExpression p = Expression.Parameter(typeof(uint?), "p");
  495. Expression<Func<uint?>> e1 = Expression.Lambda<Func<uint?>>(
  496. Expression.Invoke(
  497. Expression.Lambda<Func<uint?, uint?>>(
  498. Expression.Not(p),
  499. new ParameterExpression[] { p }),
  500. new Expression[] { Expression.Constant(val, typeof(uint?)) }),
  501. new System.Collections.Generic.List<ParameterExpression>());
  502. Func<uint?> f1 = e1.Compile();
  503. Expression<Func<uint?, Func<uint?>>> e2 = Expression.Lambda<Func<uint?, Func<uint?>>>(
  504. Expression.Lambda<Func<uint?>>(Expression.Not(p), new System.Collections.Generic.List<ParameterExpression>()),
  505. new ParameterExpression[] { p });
  506. Func<uint?, Func<uint?>> f2 = e2.Compile();
  507. Expression<Func<Func<uint?, uint?>>> e3 = Expression.Lambda<Func<Func<uint?, uint?>>>(
  508. Expression.Invoke(
  509. Expression.Lambda<Func<Func<uint?, uint?>>>(
  510. Expression.Lambda<Func<uint?, uint?>>(
  511. Expression.Not(p),
  512. new ParameterExpression[] { p }),
  513. new System.Collections.Generic.List<ParameterExpression>()),
  514. new System.Collections.Generic.List<Expression>()),
  515. new System.Collections.Generic.List<ParameterExpression>());
  516. Func<uint?, uint?> f3 = e3.Compile()();
  517. Expression<Func<Func<uint?, uint?>>> e4 = Expression.Lambda<Func<Func<uint?, uint?>>>(
  518. Expression.Lambda<Func<uint?, uint?>>(
  519. Expression.Not(p),
  520. new ParameterExpression[] { p }),
  521. new System.Collections.Generic.List<ParameterExpression>());
  522. Func<Func<uint?, uint?>> f4 = e4.Compile();
  523. uint? expected = (uint?) ~val;
  524. return object.Equals(f1(), expected) &&
  525. object.Equals(f2(val)(), expected) &&
  526. object.Equals(f3(val), expected) &&
  527. object.Equals(f4()(val), expected);
  528. }
  529. }
  530. public static class Ext {
  531. public static void StartCapture() {
  532. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  533. // m.Invoke(null, new object[] { "test.dll" });
  534. }
  535. public static void StopCapture() {
  536. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  537. // m.Invoke(null, new object[0]);
  538. }
  539. public static bool IsIntegralOrEnum(Type type) {
  540. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  541. case TypeCode.Byte:
  542. case TypeCode.SByte:
  543. case TypeCode.Int16:
  544. case TypeCode.Int32:
  545. case TypeCode.Int64:
  546. case TypeCode.UInt16:
  547. case TypeCode.UInt32:
  548. case TypeCode.UInt64:
  549. return true;
  550. default:
  551. return false;
  552. }
  553. }
  554. public static bool IsFloating(Type type) {
  555. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  556. case TypeCode.Single:
  557. case TypeCode.Double:
  558. return true;
  559. default:
  560. return false;
  561. }
  562. }
  563. public static Type GetNonNullableType(Type type) {
  564. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  565. type.GetGenericArguments()[0] :
  566. type;
  567. }
  568. }
  569. }
  570. //-------- Scenario 307
  571. namespace Scenario307{
  572. public class Test
  573. {
  574. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "intq_Not__1", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  575. public static Expression intq_Not__1() {
  576. if(Main() != 0 ) {
  577. throw new Exception();
  578. } else {
  579. return Expression.Constant(0);
  580. }
  581. }
  582. public static int Main()
  583. {
  584. Ext.StartCapture();
  585. bool success = false;
  586. try
  587. {
  588. success = check_intq_Not();
  589. }
  590. finally
  591. {
  592. Ext.StopCapture();
  593. }
  594. return success ? 0 : 1;
  595. }
  596. static bool check_intq_Not() {
  597. foreach (int? val in new int?[] { 0, 1, -1, int.MinValue, int.MaxValue }) {
  598. if (!check_intq_Not(val)) {
  599. Console.WriteLine("intq_Not failed");
  600. return false;
  601. }
  602. }
  603. return true;
  604. }
  605. static bool check_intq_Not(int? val) {
  606. ParameterExpression p = Expression.Parameter(typeof(int?), "p");
  607. Expression<Func<int?>> e1 = Expression.Lambda<Func<int?>>(
  608. Expression.Invoke(
  609. Expression.Lambda<Func<int?, int?>>(
  610. Expression.Not(p),
  611. new ParameterExpression[] { p }),
  612. new Expression[] { Expression.Constant(val, typeof(int?)) }),
  613. new System.Collections.Generic.List<ParameterExpression>());
  614. Func<int?> f1 = e1.Compile();
  615. Expression<Func<int?, Func<int?>>> e2 = Expression.Lambda<Func<int?, Func<int?>>>(
  616. Expression.Lambda<Func<int?>>(Expression.Not(p), new System.Collections.Generic.List<ParameterExpression>()),
  617. new ParameterExpression[] { p });
  618. Func<int?, Func<int?>> f2 = e2.Compile();
  619. Expression<Func<Func<int?, int?>>> e3 = Expression.Lambda<Func<Func<int?, int?>>>(
  620. Expression.Invoke(
  621. Expression.Lambda<Func<Func<int?, int?>>>(
  622. Expression.Lambda<Func<int?, int?>>(
  623. Expression.Not(p),
  624. new ParameterExpression[] { p }),
  625. new System.Collections.Generic.List<ParameterExpression>()),
  626. new System.Collections.Generic.List<Expression>()),
  627. new System.Collections.Generic.List<ParameterExpression>());
  628. Func<int?, int?> f3 = e3.Compile()();
  629. Expression<Func<Func<int?, int?>>> e4 = Expression.Lambda<Func<Func<int?, int?>>>(
  630. Expression.Lambda<Func<int?, int?>>(
  631. Expression.Not(p),
  632. new ParameterExpression[] { p }),
  633. new System.Collections.Generic.List<ParameterExpression>());
  634. Func<Func<int?, int?>> f4 = e4.Compile();
  635. int? expected = (int?) ~val;
  636. return object.Equals(f1(), expected) &&
  637. object.Equals(f2(val)(), expected) &&
  638. object.Equals(f3(val), expected) &&
  639. object.Equals(f4()(val), expected);
  640. }
  641. }
  642. public static class Ext {
  643. public static void StartCapture() {
  644. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  645. // m.Invoke(null, new object[] { "test.dll" });
  646. }
  647. public static void StopCapture() {
  648. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  649. // m.Invoke(null, new object[0]);
  650. }
  651. public static bool IsIntegralOrEnum(Type type) {
  652. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  653. case TypeCode.Byte:
  654. case TypeCode.SByte:
  655. case TypeCode.Int16:
  656. case TypeCode.Int32:
  657. case TypeCode.Int64:
  658. case TypeCode.UInt16:
  659. case TypeCode.UInt32:
  660. case TypeCode.UInt64:
  661. return true;
  662. default:
  663. return false;
  664. }
  665. }
  666. public static bool IsFloating(Type type) {
  667. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  668. case TypeCode.Single:
  669. case TypeCode.Double:
  670. return true;
  671. default:
  672. return false;
  673. }
  674. }
  675. public static Type GetNonNullableType(Type type) {
  676. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  677. type.GetGenericArguments()[0] :
  678. type;
  679. }
  680. }
  681. }
  682. //-------- Scenario 308
  683. namespace Scenario308{
  684. public class Test
  685. {
  686. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "ulongq_Not__1", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  687. public static Expression ulongq_Not__1() {
  688. if(Main() != 0 ) {
  689. throw new Exception();
  690. } else {
  691. return Expression.Constant(0);
  692. }
  693. }
  694. public static int Main()
  695. {
  696. Ext.StartCapture();
  697. bool success = false;
  698. try
  699. {
  700. success = check_ulongq_Not();
  701. }
  702. finally
  703. {
  704. Ext.StopCapture();
  705. }
  706. return success ? 0 : 1;
  707. }
  708. static bool check_ulongq_Not() {
  709. foreach (ulong? val in new ulong?[] { 0, 1, ulong.MaxValue }) {
  710. if (!check_ulongq_Not(val)) {
  711. Console.WriteLine("ulongq_Not failed");
  712. return false;
  713. }
  714. }
  715. return true;
  716. }
  717. static bool check_ulongq_Not(ulong? val) {
  718. ParameterExpression p = Expression.Parameter(typeof(ulong?), "p");
  719. Expression<Func<ulong?>> e1 = Expression.Lambda<Func<ulong?>>(
  720. Expression.Invoke(
  721. Expression.Lambda<Func<ulong?, ulong?>>(
  722. Expression.Not(p),
  723. new ParameterExpression[] { p }),
  724. new Expression[] { Expression.Constant(val, typeof(ulong?)) }),
  725. new System.Collections.Generic.List<ParameterExpression>());
  726. Func<ulong?> f1 = e1.Compile();
  727. Expression<Func<ulong?, Func<ulong?>>> e2 = Expression.Lambda<Func<ulong?, Func<ulong?>>>(
  728. Expression.Lambda<Func<ulong?>>(Expression.Not(p), new System.Collections.Generic.List<ParameterExpression>()),
  729. new ParameterExpression[] { p });
  730. Func<ulong?, Func<ulong?>> f2 = e2.Compile();
  731. Expression<Func<Func<ulong?, ulong?>>> e3 = Expression.Lambda<Func<Func<ulong?, ulong?>>>(
  732. Expression.Invoke(
  733. Expression.Lambda<Func<Func<ulong?, ulong?>>>(
  734. Expression.Lambda<Func<ulong?, ulong?>>(
  735. Expression.Not(p),
  736. new ParameterExpression[] { p }),
  737. new System.Collections.Generic.List<ParameterExpression>()),
  738. new System.Collections.Generic.List<Expression>()),
  739. new System.Collections.Generic.List<ParameterExpression>());
  740. Func<ulong?, ulong?> f3 = e3.Compile()();
  741. Expression<Func<Func<ulong?, ulong?>>> e4 = Expression.Lambda<Func<Func<ulong?, ulong?>>>(
  742. Expression.Lambda<Func<ulong?, ulong?>>(
  743. Expression.Not(p),
  744. new ParameterExpression[] { p }),
  745. new System.Collections.Generic.List<ParameterExpression>());
  746. Func<Func<ulong?, ulong?>> f4 = e4.Compile();
  747. ulong? expected = (ulong?) ~val;
  748. return object.Equals(f1(), expected) &&
  749. object.Equals(f2(val)(), expected) &&
  750. object.Equals(f3(val), expected) &&
  751. object.Equals(f4()(val), expected);
  752. }
  753. }
  754. public static class Ext {
  755. public static void StartCapture() {
  756. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  757. // m.Invoke(null, new object[] { "test.dll" });
  758. }
  759. public static void StopCapture() {
  760. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  761. // m.Invoke(null, new object[0]);
  762. }
  763. public static bool IsIntegralOrEnum(Type type) {
  764. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  765. case TypeCode.Byte:
  766. case TypeCode.SByte:
  767. case TypeCode.Int16:
  768. case TypeCode.Int32:
  769. case TypeCode.Int64:
  770. case TypeCode.UInt16:
  771. case TypeCode.UInt32:
  772. case TypeCode.UInt64:
  773. return true;
  774. default:
  775. return false;
  776. }
  777. }
  778. public static bool IsFloating(Type type) {
  779. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  780. case TypeCode.Single:
  781. case TypeCode.Double:
  782. return true;
  783. default:
  784. return false;
  785. }
  786. }
  787. public static Type GetNonNullableType(Type type) {
  788. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  789. type.GetGenericArguments()[0] :
  790. type;
  791. }
  792. }
  793. }
  794. //-------- Scenario 309
  795. namespace Scenario309{
  796. public class Test
  797. {
  798. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "longq_Not__1", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  799. public static Expression longq_Not__1() {
  800. if(Main() != 0 ) {
  801. throw new Exception();
  802. } else {
  803. return Expression.Constant(0);
  804. }
  805. }
  806. public static int Main()
  807. {
  808. Ext.StartCapture();
  809. bool success = false;
  810. try
  811. {
  812. success = check_longq_Not();
  813. }
  814. finally
  815. {
  816. Ext.StopCapture();
  817. }
  818. return success ? 0 : 1;
  819. }
  820. static bool check_longq_Not() {
  821. foreach (long? val in new long?[] { 0, 1, -1, long.MinValue, long.MaxValue }) {
  822. if (!check_longq_Not(val)) {
  823. Console.WriteLine("longq_Not failed");
  824. return false;
  825. }
  826. }
  827. return true;
  828. }
  829. static bool check_longq_Not(long? val) {
  830. ParameterExpression p = Expression.Parameter(typeof(long?), "p");
  831. Expression<Func<long?>> e1 = Expression.Lambda<Func<long?>>(
  832. Expression.Invoke(
  833. Expression.Lambda<Func<long?, long?>>(
  834. Expression.Not(p),
  835. new ParameterExpression[] { p }),
  836. new Expression[] { Expression.Constant(val, typeof(long?)) }),
  837. new System.Collections.Generic.List<ParameterExpression>());
  838. Func<long?> f1 = e1.Compile();
  839. Expression<Func<long?, Func<long?>>> e2 = Expression.Lambda<Func<long?, Func<long?>>>(
  840. Expression.Lambda<Func<long?>>(Expression.Not(p), new System.Collections.Generic.List<ParameterExpression>()),
  841. new ParameterExpression[] { p });
  842. Func<long?, Func<long?>> f2 = e2.Compile();
  843. Expression<Func<Func<long?, long?>>> e3 = Expression.Lambda<Func<Func<long?, long?>>>(
  844. Expression.Invoke(
  845. Expression.Lambda<Func<Func<long?, long?>>>(
  846. Expression.Lambda<Func<long?, long?>>(
  847. Expression.Not(p),
  848. new ParameterExpression[] { p }),
  849. new System.Collections.Generic.List<ParameterExpression>()),
  850. new System.Collections.Generic.List<Expression>()),
  851. new System.Collections.Generic.List<ParameterExpression>());
  852. Func<long?, long?> f3 = e3.Compile()();
  853. Expression<Func<Func<long?, long?>>> e4 = Expression.Lambda<Func<Func<long?, long?>>>(
  854. Expression.Lambda<Func<long?, long?>>(
  855. Expression.Not(p),
  856. new ParameterExpression[] { p }),
  857. new System.Collections.Generic.List<ParameterExpression>());
  858. Func<Func<long?, long?>> f4 = e4.Compile();
  859. long? expected = (long?) ~val;
  860. return object.Equals(f1(), expected) &&
  861. object.Equals(f2(val)(), expected) &&
  862. object.Equals(f3(val), expected) &&
  863. object.Equals(f4()(val), expected);
  864. }
  865. }
  866. public static class Ext {
  867. public static void StartCapture() {
  868. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  869. // m.Invoke(null, new object[] { "test.dll" });
  870. }
  871. public static void StopCapture() {
  872. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  873. // m.Invoke(null, new object[0]);
  874. }
  875. public static bool IsIntegralOrEnum(Type type) {
  876. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  877. case TypeCode.Byte:
  878. case TypeCode.SByte:
  879. case TypeCode.Int16:
  880. case TypeCode.Int32:
  881. case TypeCode.Int64:
  882. case TypeCode.UInt16:
  883. case TypeCode.UInt32:
  884. case TypeCode.UInt64:
  885. return true;
  886. default:
  887. return false;
  888. }
  889. }
  890. public static bool IsFloating(Type type) {
  891. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  892. case TypeCode.Single:
  893. case TypeCode.Double:
  894. return true;
  895. default:
  896. return false;
  897. }
  898. }
  899. public static Type GetNonNullableType(Type type) {
  900. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  901. type.GetGenericArguments()[0] :
  902. type;
  903. }
  904. }
  905. }
  906. }