PageRenderTime 67ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 2ms

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

#
C# | 17067 lines | 13916 code | 2661 blank | 490 comment | 1717 complexity | 22396c4bece7d3cee26efab926f9d6e0 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

Large files files are truncated, but you can click here to view the full file

  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 1706
  11. namespace Scenario1706{
  12. public class Test
  13. {
  14. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check0__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  15. public static Expression check0__() {
  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 = check0();
  29. }
  30. finally
  31. {
  32. Ext.StopCapture();
  33. }
  34. return success ? 0 : 1;
  35. }
  36. static bool check0() {
  37. foreach (byte val in new byte[] { 0, 1, byte.MaxValue }) {
  38. if (!check0(val)) {
  39. return false;
  40. }
  41. }
  42. return true;
  43. }
  44. static bool check0(byte val) {
  45. Expression<Func<byte>> e =
  46. Expression.Lambda<Func<byte>>(
  47. Expression.Constant(val, typeof(byte)),
  48. new System.Collections.Generic.List<ParameterExpression>());
  49. Func<byte> f = e.Compile();
  50. return object.Equals(f(), val);
  51. }
  52. }
  53. public static class Ext {
  54. public static void StartCapture() {
  55. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  56. // m.Invoke(null, new object[] { "test.dll" });
  57. }
  58. public static void StopCapture() {
  59. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  60. // m.Invoke(null, new object[0]);
  61. }
  62. public static bool IsIntegralOrEnum(Type type) {
  63. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  64. case TypeCode.Byte:
  65. case TypeCode.SByte:
  66. case TypeCode.Int16:
  67. case TypeCode.Int32:
  68. case TypeCode.Int64:
  69. case TypeCode.UInt16:
  70. case TypeCode.UInt32:
  71. case TypeCode.UInt64:
  72. return true;
  73. default:
  74. return false;
  75. }
  76. }
  77. public static bool IsFloating(Type type) {
  78. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  79. case TypeCode.Single:
  80. case TypeCode.Double:
  81. return true;
  82. default:
  83. return false;
  84. }
  85. }
  86. public static Type GetNonNullableType(Type type) {
  87. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  88. type.GetGenericArguments()[0] :
  89. type;
  90. }
  91. }
  92. }
  93. //-------- Scenario 1707
  94. namespace Scenario1707{
  95. public class Test
  96. {
  97. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check1__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  98. public static Expression check1__() {
  99. if(Main() != 0 ) {
  100. throw new Exception();
  101. } else {
  102. return Expression.Constant(0);
  103. }
  104. }
  105. public static int Main()
  106. {
  107. Ext.StartCapture();
  108. bool success = false;
  109. try
  110. {
  111. success = check1();
  112. }
  113. finally
  114. {
  115. Ext.StopCapture();
  116. }
  117. return success ? 0 : 1;
  118. }
  119. static bool check1() {
  120. foreach (ushort val in new ushort[] { 0, 1, ushort.MaxValue }) {
  121. if (!check1(val)) {
  122. return false;
  123. }
  124. }
  125. return true;
  126. }
  127. static bool check1(ushort val) {
  128. Expression<Func<ushort>> e =
  129. Expression.Lambda<Func<ushort>>(
  130. Expression.Constant(val, typeof(ushort)),
  131. new System.Collections.Generic.List<ParameterExpression>());
  132. Func<ushort> f = e.Compile();
  133. return object.Equals(f(), val);
  134. }
  135. }
  136. public static class Ext {
  137. public static void StartCapture() {
  138. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  139. // m.Invoke(null, new object[] { "test.dll" });
  140. }
  141. public static void StopCapture() {
  142. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  143. // m.Invoke(null, new object[0]);
  144. }
  145. public static bool IsIntegralOrEnum(Type type) {
  146. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  147. case TypeCode.Byte:
  148. case TypeCode.SByte:
  149. case TypeCode.Int16:
  150. case TypeCode.Int32:
  151. case TypeCode.Int64:
  152. case TypeCode.UInt16:
  153. case TypeCode.UInt32:
  154. case TypeCode.UInt64:
  155. return true;
  156. default:
  157. return false;
  158. }
  159. }
  160. public static bool IsFloating(Type type) {
  161. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  162. case TypeCode.Single:
  163. case TypeCode.Double:
  164. return true;
  165. default:
  166. return false;
  167. }
  168. }
  169. public static Type GetNonNullableType(Type type) {
  170. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  171. type.GetGenericArguments()[0] :
  172. type;
  173. }
  174. }
  175. }
  176. //-------- Scenario 1708
  177. namespace Scenario1708{
  178. public class Test
  179. {
  180. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check2__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  181. public static Expression check2__() {
  182. if(Main() != 0 ) {
  183. throw new Exception();
  184. } else {
  185. return Expression.Constant(0);
  186. }
  187. }
  188. public static int Main()
  189. {
  190. Ext.StartCapture();
  191. bool success = false;
  192. try
  193. {
  194. success = check2();
  195. }
  196. finally
  197. {
  198. Ext.StopCapture();
  199. }
  200. return success ? 0 : 1;
  201. }
  202. static bool check2() {
  203. foreach (uint val in new uint[] { 0, 1, uint.MaxValue }) {
  204. if (!check2(val)) {
  205. return false;
  206. }
  207. }
  208. return true;
  209. }
  210. static bool check2(uint val) {
  211. Expression<Func<uint>> e =
  212. Expression.Lambda<Func<uint>>(
  213. Expression.Constant(val, typeof(uint)),
  214. new System.Collections.Generic.List<ParameterExpression>());
  215. Func<uint> f = e.Compile();
  216. return object.Equals(f(), val);
  217. }
  218. }
  219. public static class Ext {
  220. public static void StartCapture() {
  221. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  222. // m.Invoke(null, new object[] { "test.dll" });
  223. }
  224. public static void StopCapture() {
  225. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  226. // m.Invoke(null, new object[0]);
  227. }
  228. public static bool IsIntegralOrEnum(Type type) {
  229. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  230. case TypeCode.Byte:
  231. case TypeCode.SByte:
  232. case TypeCode.Int16:
  233. case TypeCode.Int32:
  234. case TypeCode.Int64:
  235. case TypeCode.UInt16:
  236. case TypeCode.UInt32:
  237. case TypeCode.UInt64:
  238. return true;
  239. default:
  240. return false;
  241. }
  242. }
  243. public static bool IsFloating(Type type) {
  244. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  245. case TypeCode.Single:
  246. case TypeCode.Double:
  247. return true;
  248. default:
  249. return false;
  250. }
  251. }
  252. public static Type GetNonNullableType(Type type) {
  253. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  254. type.GetGenericArguments()[0] :
  255. type;
  256. }
  257. }
  258. }
  259. //-------- Scenario 1709
  260. namespace Scenario1709{
  261. public class Test
  262. {
  263. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check3__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  264. public static Expression check3__() {
  265. if(Main() != 0 ) {
  266. throw new Exception();
  267. } else {
  268. return Expression.Constant(0);
  269. }
  270. }
  271. public static int Main()
  272. {
  273. Ext.StartCapture();
  274. bool success = false;
  275. try
  276. {
  277. success = check3();
  278. }
  279. finally
  280. {
  281. Ext.StopCapture();
  282. }
  283. return success ? 0 : 1;
  284. }
  285. static bool check3() {
  286. foreach (ulong val in new ulong[] { 0, 1, ulong.MaxValue }) {
  287. if (!check3(val)) {
  288. return false;
  289. }
  290. }
  291. return true;
  292. }
  293. static bool check3(ulong val) {
  294. Expression<Func<ulong>> e =
  295. Expression.Lambda<Func<ulong>>(
  296. Expression.Constant(val, typeof(ulong)),
  297. new System.Collections.Generic.List<ParameterExpression>());
  298. Func<ulong> f = e.Compile();
  299. return object.Equals(f(), val);
  300. }
  301. }
  302. public static class Ext {
  303. public static void StartCapture() {
  304. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  305. // m.Invoke(null, new object[] { "test.dll" });
  306. }
  307. public static void StopCapture() {
  308. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  309. // m.Invoke(null, new object[0]);
  310. }
  311. public static bool IsIntegralOrEnum(Type type) {
  312. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  313. case TypeCode.Byte:
  314. case TypeCode.SByte:
  315. case TypeCode.Int16:
  316. case TypeCode.Int32:
  317. case TypeCode.Int64:
  318. case TypeCode.UInt16:
  319. case TypeCode.UInt32:
  320. case TypeCode.UInt64:
  321. return true;
  322. default:
  323. return false;
  324. }
  325. }
  326. public static bool IsFloating(Type type) {
  327. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  328. case TypeCode.Single:
  329. case TypeCode.Double:
  330. return true;
  331. default:
  332. return false;
  333. }
  334. }
  335. public static Type GetNonNullableType(Type type) {
  336. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  337. type.GetGenericArguments()[0] :
  338. type;
  339. }
  340. }
  341. }
  342. //-------- Scenario 1710
  343. namespace Scenario1710{
  344. public class Test
  345. {
  346. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check4__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  347. public static Expression check4__() {
  348. if(Main() != 0 ) {
  349. throw new Exception();
  350. } else {
  351. return Expression.Constant(0);
  352. }
  353. }
  354. public static int Main()
  355. {
  356. Ext.StartCapture();
  357. bool success = false;
  358. try
  359. {
  360. success = check4();
  361. }
  362. finally
  363. {
  364. Ext.StopCapture();
  365. }
  366. return success ? 0 : 1;
  367. }
  368. static bool check4() {
  369. foreach (sbyte val in new sbyte[] { 0, 1, -1, sbyte.MinValue, sbyte.MaxValue }) {
  370. if (!check4(val)) {
  371. return false;
  372. }
  373. }
  374. return true;
  375. }
  376. static bool check4(sbyte val) {
  377. Expression<Func<sbyte>> e =
  378. Expression.Lambda<Func<sbyte>>(
  379. Expression.Constant(val, typeof(sbyte)),
  380. new System.Collections.Generic.List<ParameterExpression>());
  381. Func<sbyte> f = e.Compile();
  382. return object.Equals(f(), val);
  383. }
  384. }
  385. public static class Ext {
  386. public static void StartCapture() {
  387. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  388. // m.Invoke(null, new object[] { "test.dll" });
  389. }
  390. public static void StopCapture() {
  391. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  392. // m.Invoke(null, new object[0]);
  393. }
  394. public static bool IsIntegralOrEnum(Type type) {
  395. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  396. case TypeCode.Byte:
  397. case TypeCode.SByte:
  398. case TypeCode.Int16:
  399. case TypeCode.Int32:
  400. case TypeCode.Int64:
  401. case TypeCode.UInt16:
  402. case TypeCode.UInt32:
  403. case TypeCode.UInt64:
  404. return true;
  405. default:
  406. return false;
  407. }
  408. }
  409. public static bool IsFloating(Type type) {
  410. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  411. case TypeCode.Single:
  412. case TypeCode.Double:
  413. return true;
  414. default:
  415. return false;
  416. }
  417. }
  418. public static Type GetNonNullableType(Type type) {
  419. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  420. type.GetGenericArguments()[0] :
  421. type;
  422. }
  423. }
  424. }
  425. //-------- Scenario 1711
  426. namespace Scenario1711{
  427. public class Test
  428. {
  429. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check5__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  430. public static Expression check5__() {
  431. if(Main() != 0 ) {
  432. throw new Exception();
  433. } else {
  434. return Expression.Constant(0);
  435. }
  436. }
  437. public static int Main()
  438. {
  439. Ext.StartCapture();
  440. bool success = false;
  441. try
  442. {
  443. success = check5();
  444. }
  445. finally
  446. {
  447. Ext.StopCapture();
  448. }
  449. return success ? 0 : 1;
  450. }
  451. static bool check5() {
  452. foreach (short val in new short[] { 0, 1, -1, short.MinValue, short.MaxValue }) {
  453. if (!check5(val)) {
  454. return false;
  455. }
  456. }
  457. return true;
  458. }
  459. static bool check5(short val) {
  460. Expression<Func<short>> e =
  461. Expression.Lambda<Func<short>>(
  462. Expression.Constant(val, typeof(short)),
  463. new System.Collections.Generic.List<ParameterExpression>());
  464. Func<short> f = e.Compile();
  465. return object.Equals(f(), val);
  466. }
  467. }
  468. public static class Ext {
  469. public static void StartCapture() {
  470. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  471. // m.Invoke(null, new object[] { "test.dll" });
  472. }
  473. public static void StopCapture() {
  474. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  475. // m.Invoke(null, new object[0]);
  476. }
  477. public static bool IsIntegralOrEnum(Type type) {
  478. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  479. case TypeCode.Byte:
  480. case TypeCode.SByte:
  481. case TypeCode.Int16:
  482. case TypeCode.Int32:
  483. case TypeCode.Int64:
  484. case TypeCode.UInt16:
  485. case TypeCode.UInt32:
  486. case TypeCode.UInt64:
  487. return true;
  488. default:
  489. return false;
  490. }
  491. }
  492. public static bool IsFloating(Type type) {
  493. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  494. case TypeCode.Single:
  495. case TypeCode.Double:
  496. return true;
  497. default:
  498. return false;
  499. }
  500. }
  501. public static Type GetNonNullableType(Type type) {
  502. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  503. type.GetGenericArguments()[0] :
  504. type;
  505. }
  506. }
  507. }
  508. //-------- Scenario 1712
  509. namespace Scenario1712{
  510. public class Test
  511. {
  512. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check6__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  513. public static Expression check6__() {
  514. if(Main() != 0 ) {
  515. throw new Exception();
  516. } else {
  517. return Expression.Constant(0);
  518. }
  519. }
  520. public static int Main()
  521. {
  522. Ext.StartCapture();
  523. bool success = false;
  524. try
  525. {
  526. success = check6();
  527. }
  528. finally
  529. {
  530. Ext.StopCapture();
  531. }
  532. return success ? 0 : 1;
  533. }
  534. static bool check6() {
  535. foreach (int val in new int[] { 0, 1, -1, int.MinValue, int.MaxValue }) {
  536. if (!check6(val)) {
  537. return false;
  538. }
  539. }
  540. return true;
  541. }
  542. static bool check6(int val) {
  543. Expression<Func<int>> e =
  544. Expression.Lambda<Func<int>>(
  545. Expression.Constant(val, typeof(int)),
  546. new System.Collections.Generic.List<ParameterExpression>());
  547. Func<int> f = e.Compile();
  548. return object.Equals(f(), val);
  549. }
  550. }
  551. public static class Ext {
  552. public static void StartCapture() {
  553. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  554. // m.Invoke(null, new object[] { "test.dll" });
  555. }
  556. public static void StopCapture() {
  557. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  558. // m.Invoke(null, new object[0]);
  559. }
  560. public static bool IsIntegralOrEnum(Type type) {
  561. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  562. case TypeCode.Byte:
  563. case TypeCode.SByte:
  564. case TypeCode.Int16:
  565. case TypeCode.Int32:
  566. case TypeCode.Int64:
  567. case TypeCode.UInt16:
  568. case TypeCode.UInt32:
  569. case TypeCode.UInt64:
  570. return true;
  571. default:
  572. return false;
  573. }
  574. }
  575. public static bool IsFloating(Type type) {
  576. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  577. case TypeCode.Single:
  578. case TypeCode.Double:
  579. return true;
  580. default:
  581. return false;
  582. }
  583. }
  584. public static Type GetNonNullableType(Type type) {
  585. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  586. type.GetGenericArguments()[0] :
  587. type;
  588. }
  589. }
  590. }
  591. //-------- Scenario 1713
  592. namespace Scenario1713{
  593. public class Test
  594. {
  595. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check7__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  596. public static Expression check7__() {
  597. if(Main() != 0 ) {
  598. throw new Exception();
  599. } else {
  600. return Expression.Constant(0);
  601. }
  602. }
  603. public static int Main()
  604. {
  605. Ext.StartCapture();
  606. bool success = false;
  607. try
  608. {
  609. success = check7();
  610. }
  611. finally
  612. {
  613. Ext.StopCapture();
  614. }
  615. return success ? 0 : 1;
  616. }
  617. static bool check7() {
  618. foreach (long val in new long[] { 0, 1, -1, long.MinValue, long.MaxValue }) {
  619. if (!check7(val)) {
  620. return false;
  621. }
  622. }
  623. return true;
  624. }
  625. static bool check7(long val) {
  626. Expression<Func<long>> e =
  627. Expression.Lambda<Func<long>>(
  628. Expression.Constant(val, typeof(long)),
  629. new System.Collections.Generic.List<ParameterExpression>());
  630. Func<long> f = e.Compile();
  631. return object.Equals(f(), val);
  632. }
  633. }
  634. public static class Ext {
  635. public static void StartCapture() {
  636. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  637. // m.Invoke(null, new object[] { "test.dll" });
  638. }
  639. public static void StopCapture() {
  640. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  641. // m.Invoke(null, new object[0]);
  642. }
  643. public static bool IsIntegralOrEnum(Type type) {
  644. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  645. case TypeCode.Byte:
  646. case TypeCode.SByte:
  647. case TypeCode.Int16:
  648. case TypeCode.Int32:
  649. case TypeCode.Int64:
  650. case TypeCode.UInt16:
  651. case TypeCode.UInt32:
  652. case TypeCode.UInt64:
  653. return true;
  654. default:
  655. return false;
  656. }
  657. }
  658. public static bool IsFloating(Type type) {
  659. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  660. case TypeCode.Single:
  661. case TypeCode.Double:
  662. return true;
  663. default:
  664. return false;
  665. }
  666. }
  667. public static Type GetNonNullableType(Type type) {
  668. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  669. type.GetGenericArguments()[0] :
  670. type;
  671. }
  672. }
  673. }
  674. //-------- Scenario 1714
  675. namespace Scenario1714{
  676. public class Test
  677. {
  678. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check8__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  679. public static Expression check8__() {
  680. if(Main() != 0 ) {
  681. throw new Exception();
  682. } else {
  683. return Expression.Constant(0);
  684. }
  685. }
  686. public static int Main()
  687. {
  688. Ext.StartCapture();
  689. bool success = false;
  690. try
  691. {
  692. success = check8();
  693. }
  694. finally
  695. {
  696. Ext.StopCapture();
  697. }
  698. return success ? 0 : 1;
  699. }
  700. static bool check8() {
  701. foreach (float val in new float[] { 0, 1, -1, float.MinValue, float.MaxValue, float.Epsilon, float.NegativeInfinity, float.PositiveInfinity, float.NaN }) {
  702. if (!check8(val)) {
  703. return false;
  704. }
  705. }
  706. return true;
  707. }
  708. static bool check8(float val) {
  709. Expression<Func<float>> e =
  710. Expression.Lambda<Func<float>>(
  711. Expression.Constant(val, typeof(float)),
  712. new System.Collections.Generic.List<ParameterExpression>());
  713. Func<float> f = e.Compile();
  714. return object.Equals(f(), val);
  715. }
  716. }
  717. public static class Ext {
  718. public static void StartCapture() {
  719. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  720. // m.Invoke(null, new object[] { "test.dll" });
  721. }
  722. public static void StopCapture() {
  723. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  724. // m.Invoke(null, new object[0]);
  725. }
  726. public static bool IsIntegralOrEnum(Type type) {
  727. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  728. case TypeCode.Byte:
  729. case TypeCode.SByte:
  730. case TypeCode.Int16:
  731. case TypeCode.Int32:
  732. case TypeCode.Int64:
  733. case TypeCode.UInt16:
  734. case TypeCode.UInt32:
  735. case TypeCode.UInt64:
  736. return true;
  737. default:
  738. return false;
  739. }
  740. }
  741. public static bool IsFloating(Type type) {
  742. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  743. case TypeCode.Single:
  744. case TypeCode.Double:
  745. return true;
  746. default:
  747. return false;
  748. }
  749. }
  750. public static Type GetNonNullableType(Type type) {
  751. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  752. type.GetGenericArguments()[0] :
  753. type;
  754. }
  755. }
  756. }
  757. //-------- Scenario 1715
  758. namespace Scenario1715{
  759. public class Test
  760. {
  761. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check9__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  762. public static Expression check9__() {
  763. if(Main() != 0 ) {
  764. throw new Exception();
  765. } else {
  766. return Expression.Constant(0);
  767. }
  768. }
  769. public static int Main()
  770. {
  771. Ext.StartCapture();
  772. bool success = false;
  773. try
  774. {
  775. success = check9();
  776. }
  777. finally
  778. {
  779. Ext.StopCapture();
  780. }
  781. return success ? 0 : 1;
  782. }
  783. static bool check9() {
  784. foreach (double val in new double[] { 0, 1, -1, double.MinValue, double.MaxValue, double.Epsilon, double.NegativeInfinity, double.PositiveInfinity, double.NaN }) {
  785. if (!check9(val)) {
  786. return false;
  787. }
  788. }
  789. return true;
  790. }
  791. static bool check9(double val) {
  792. Expression<Func<double>> e =
  793. Expression.Lambda<Func<double>>(
  794. Expression.Constant(val, typeof(double)),
  795. new System.Collections.Generic.List<ParameterExpression>());
  796. Func<double> f = e.Compile();
  797. return object.Equals(f(), val);
  798. }
  799. }
  800. public static class Ext {
  801. public static void StartCapture() {
  802. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  803. // m.Invoke(null, new object[] { "test.dll" });
  804. }
  805. public static void StopCapture() {
  806. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  807. // m.Invoke(null, new object[0]);
  808. }
  809. public static bool IsIntegralOrEnum(Type type) {
  810. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  811. case TypeCode.Byte:
  812. case TypeCode.SByte:
  813. case TypeCode.Int16:
  814. case TypeCode.Int32:
  815. case TypeCode.Int64:
  816. case TypeCode.UInt16:
  817. case TypeCode.UInt32:
  818. case TypeCode.UInt64:
  819. return true;
  820. default:
  821. return false;
  822. }
  823. }
  824. public static bool IsFloating(Type type) {
  825. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  826. case TypeCode.Single:
  827. case TypeCode.Double:
  828. return true;
  829. default:
  830. return false;
  831. }
  832. }
  833. public static Type GetNonNullableType(Type type) {
  834. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  835. type.GetGenericArguments()[0] :
  836. type;
  837. }
  838. }
  839. }
  840. //-------- Scenario 1716
  841. namespace Scenario1716{
  842. public class Test
  843. {
  844. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check10__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  845. public static Expression check10__() {
  846. if(Main() != 0 ) {
  847. throw new Exception();
  848. } else {
  849. return Expression.Constant(0);
  850. }
  851. }
  852. public static int Main()
  853. {
  854. Ext.StartCapture();
  855. bool success = false;
  856. try
  857. {
  858. success = check10();
  859. }
  860. finally
  861. {
  862. Ext.StopCapture();
  863. }
  864. return success ? 0 : 1;
  865. }
  866. static bool check10() {
  867. foreach (decimal val in new decimal[] { decimal.Zero, decimal.One, decimal.MinusOne, decimal.MinValue, decimal.MaxValue }) {
  868. if (!check10(val)) {
  869. return false;
  870. }
  871. }
  872. return true;
  873. }
  874. static bool check10(decimal val) {
  875. Expression<Func<decimal>> e =
  876. Expression.Lambda<Func<decimal>>(
  877. Expression.Constant(val, typeof(decimal)),
  878. new System.Collections.Generic.List<ParameterExpression>());
  879. Func<decimal> f = e.Compile();
  880. return object.Equals(f(), val);
  881. }
  882. }
  883. public static class Ext {
  884. public static void StartCapture() {
  885. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  886. // m.Invoke(null, new object[] { "test.dll" });
  887. }
  888. public static void StopCapture() {
  889. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  890. // m.Invoke(null, new object[0]);
  891. }
  892. public static bool IsIntegralOrEnum(Type type) {
  893. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  894. case TypeCode.Byte:
  895. case TypeCode.SByte:
  896. case TypeCode.Int16:
  897. case TypeCode.Int32:
  898. case TypeCode.Int64:
  899. case TypeCode.UInt16:
  900. case TypeCode.UInt32:
  901. case TypeCode.UInt64:
  902. return true;
  903. default:
  904. return false;
  905. }
  906. }
  907. public static bool IsFloating(Type type) {
  908. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  909. case TypeCode.Single:
  910. case TypeCode.Double:
  911. return true;
  912. default:
  913. return false;
  914. }
  915. }
  916. public static Type GetNonNullableType(Type type) {
  917. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  918. type.GetGenericArguments()[0] :
  919. type;
  920. }
  921. }
  922. }
  923. //-------- Scenario 1717
  924. namespace Scenario1717{
  925. public class Test
  926. {
  927. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check11__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  928. public static Expression check11__() {
  929. if(Main() != 0 ) {
  930. throw new Exception();
  931. } else {
  932. return Expression.Constant(0);
  933. }
  934. }
  935. public static int Main()
  936. {
  937. Ext.StartCapture();
  938. bool success = false;
  939. try
  940. {
  941. success = check11();
  942. }
  943. finally
  944. {
  945. Ext.StopCapture();
  946. }
  947. return success ? 0 : 1;
  948. }
  949. static bool check11() {
  950. foreach (char val in new char[] { '\0', '\b', 'A', '\uffff' }) {
  951. if (!check11(val)) {
  952. return false;
  953. }
  954. }
  955. return true;
  956. }
  957. static bool check11(char val) {
  958. Expression<Func<char>> e =
  959. Expression.Lambda<Func<char>>(
  960. Expression.Constant(val, typeof(char)),
  961. new System.Collections.Generic.List<ParameterExpression>());
  962. Func<char> f = e.Compile();
  963. return object.Equals(f(), val);
  964. }
  965. }
  966. public static class Ext {
  967. public static void StartCapture() {
  968. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  969. // m.Invoke(null, new object[] { "test.dll" });
  970. }
  971. public static void StopCapture() {
  972. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  973. // m.Invoke(null, new object[0]);
  974. }
  975. public static bool IsIntegralOrEnum(Type type) {
  976. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  977. case TypeCode.Byte:
  978. case TypeCode.SByte:
  979. case TypeCode.Int16:
  980. case TypeCode.Int32:
  981. case TypeCode.Int64:
  982. case TypeCode.UInt16:
  983. case TypeCode.UInt32:
  984. case TypeCode.UInt64:
  985. return true;
  986. default:
  987. return false;
  988. }
  989. }
  990. public static bool IsFloating(Type type) {
  991. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  992. case TypeCode.Single:
  993. case TypeCode.Double:
  994. return true;
  995. default:
  996. return false;
  997. }
  998. }
  999. public static Type GetNonNullableType(Type type) {
  1000. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1001. type.GetGenericArguments()[0] :
  1002. type;
  1003. }
  1004. }
  1005. }
  1006. //-------- Scenario 1718
  1007. namespace Scenario1718{
  1008. public class Test
  1009. {
  1010. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check12__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1011. public static Expression check12__() {
  1012. if(Main() != 0 ) {
  1013. throw new Exception();
  1014. } else {
  1015. return Expression.Constant(0);
  1016. }
  1017. }
  1018. public static int Main()
  1019. {
  1020. Ext.StartCapture();
  1021. bool success = false;
  1022. try
  1023. {
  1024. success = check12();
  1025. }
  1026. finally
  1027. {
  1028. Ext.StopCapture();
  1029. }
  1030. return success ? 0 : 1;
  1031. }
  1032. static bool check12() {
  1033. foreach (bool val in new bool[] { true, false }) {
  1034. if (!check12(val)) {
  1035. return false;
  1036. }
  1037. }
  1038. return true;
  1039. }
  1040. static bool check12(bool val) {
  1041. Expression<Func<bool>> e =
  1042. Expression.Lambda<Func<bool>>(
  1043. Expression.Constant(val, typeof(bool)),
  1044. new System.Collections.Generic.List<ParameterExpression>());
  1045. Func<bool> f = e.Compile();
  1046. return object.Equals(f(), val);
  1047. }
  1048. }
  1049. public static class Ext {
  1050. public static void StartCapture() {
  1051. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1052. // m.Invoke(null, new object[] { "test.dll" });
  1053. }
  1054. public static void StopCapture() {
  1055. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1056. // m.Invoke(null, new object[0]);
  1057. }
  1058. public static bool IsIntegralOrEnum(Type type) {
  1059. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1060. case TypeCode.Byte:
  1061. case TypeCode.SByte:
  1062. case TypeCode.Int16:
  1063. case TypeCode.Int32:
  1064. case TypeCode.Int64:
  1065. case TypeCode.UInt16:
  1066. case TypeCode.UInt32:
  1067. case TypeCode.UInt64:
  1068. return true;
  1069. default:
  1070. return false;
  1071. }
  1072. }
  1073. public static bool IsFloating(Type type) {
  1074. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1075. case TypeCode.Single:
  1076. case TypeCode.Double:
  1077. return true;
  1078. default:
  1079. return false;
  1080. }
  1081. }
  1082. public static Type GetNonNullableType(Type type) {
  1083. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1084. type.GetGenericArguments()[0] :
  1085. type;
  1086. }
  1087. }
  1088. }
  1089. //-------- Scenario 1719
  1090. namespace Scenario1719{
  1091. public class Test
  1092. {
  1093. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check13__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1094. public static Expression check13__() {
  1095. if(Main() != 0 ) {
  1096. throw new Exception();
  1097. } else {
  1098. return Expression.Constant(0);
  1099. }
  1100. }
  1101. public static int Main()
  1102. {
  1103. Ext.StartCapture();
  1104. bool success = false;
  1105. try
  1106. {
  1107. success = check13();
  1108. }
  1109. finally
  1110. {
  1111. Ext.StopCapture();
  1112. }
  1113. return success ? 0 : 1;
  1114. }
  1115. static bool check13() {
  1116. foreach (S val in new S[] { default(S), new S() }) {
  1117. if (!check13(val)) {
  1118. return false;
  1119. }
  1120. }
  1121. return true;
  1122. }
  1123. static bool check13(S val) {
  1124. Expression<Func<S>> e =
  1125. Expression.Lambda<Func<S>>(
  1126. Expression.Constant(val, typeof(S)),
  1127. new System.Collections.Generic.List<ParameterExpression>());
  1128. Func<S> f = e.Compile();
  1129. return object.Equals(f(), val);
  1130. }
  1131. }
  1132. public static class Ext {
  1133. public static void StartCapture() {
  1134. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1135. // m.Invoke(null, new object[] { "test.dll" });
  1136. }
  1137. public static void StopCapture() {
  1138. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  1139. // m.Invoke(null, new object[0]);
  1140. }
  1141. public static bool IsIntegralOrEnum(Type type) {
  1142. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1143. case TypeCode.Byte:
  1144. case TypeCode.SByte:
  1145. case TypeCode.Int16:
  1146. case TypeCode.Int32:
  1147. case TypeCode.Int64:
  1148. case TypeCode.UInt16:
  1149. case TypeCode.UInt32:
  1150. case TypeCode.UInt64:
  1151. return true;
  1152. default:
  1153. return false;
  1154. }
  1155. }
  1156. public static bool IsFloating(Type type) {
  1157. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  1158. case TypeCode.Single:
  1159. case TypeCode.Double:
  1160. return true;
  1161. default:
  1162. return false;
  1163. }
  1164. }
  1165. public static Type GetNonNullableType(Type type) {
  1166. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  1167. type.GetGenericArguments()[0] :
  1168. type;
  1169. }
  1170. }
  1171. public interface I {
  1172. void M();
  1173. }
  1174. public class C : IEquatable<C>, I {
  1175. void I.M() {
  1176. }
  1177. public override bool Equals(object o) {
  1178. return o is C && Equals((C) o);
  1179. }
  1180. public bool Equals(C c) {
  1181. return c != null;
  1182. }
  1183. public override int GetHashCode() {
  1184. return 0;
  1185. }
  1186. }
  1187. public class D : C, IEquatable<D> {
  1188. public int Val;
  1189. public D() {
  1190. }
  1191. public D(int val) {
  1192. Val = val;
  1193. }
  1194. public override bool Equals(object o) {
  1195. return o is D && Equals((D) o);
  1196. }
  1197. public bool Equals(D d) {
  1198. return d != null && d.Val == Val;
  1199. }
  1200. public override int GetHashCode() {
  1201. return Val;
  1202. }
  1203. }
  1204. public enum E {
  1205. A=1, B=2
  1206. }
  1207. public enum El : long {
  1208. A, B, C
  1209. }
  1210. public struct S : IEquatable<S> {
  1211. public override bool Equals(object o) {
  1212. return (o is S) && Equals((S) o);
  1213. }
  1214. public bool Equals(S other) {
  1215. return true;
  1216. }
  1217. public override int GetHashCode() {
  1218. return 0;
  1219. }
  1220. }
  1221. public struct Sp : IEquatable<Sp> {
  1222. public Sp(int i, double d) {
  1223. I = i;
  1224. D = d;
  1225. }
  1226. public int I;
  1227. public double D;
  1228. public override bool Equals(object o) {
  1229. return (o is Sp) && Equals((Sp) o);
  1230. }
  1231. public bool Equals(Sp other) {
  1232. return other.I == I && other.D == D;
  1233. }
  1234. public override int GetHashCode() {
  1235. return I.GetHashCode() ^ D.GetHashCode();
  1236. }
  1237. }
  1238. public struct Ss : IEquatable<Ss> {
  1239. public Ss(S s) {
  1240. Val = s;
  1241. }
  1242. public S Val;
  1243. public override bool Equals(object o) {
  1244. return (o is Ss) && Equals((Ss) o);
  1245. }
  1246. public bool Equals(Ss other) {
  1247. return other.Val.Equals(Val);
  1248. }
  1249. public override int GetHashCode() {
  1250. return Val.GetHashCode();
  1251. }
  1252. }
  1253. public struct Sc : IEquatable<Sc> {
  1254. public Sc(string s) {
  1255. S = s;
  1256. }
  1257. public string S;
  1258. public override bool Equals(object o) {
  1259. return (o is Sc) && Equals((Sc) o);
  1260. }
  1261. public bool Equals(Sc other) {
  1262. return other.S == S;
  1263. }
  1264. public override int GetHashCode() {
  1265. return S.GetHashCode();
  1266. }
  1267. }
  1268. public struct Scs : IEquatable<Scs> {
  1269. public Scs(string s, S val) {
  1270. S = s;
  1271. Val = val;
  1272. }
  1273. public string S;
  1274. public S Val;
  1275. public override bool Equals(object o) {
  1276. return (o is Scs) && Equals((Scs) o);
  1277. }
  1278. public bool Equals(Scs other) {
  1279. return other.S == S && other.Val.Equals(Val);
  1280. }
  1281. public override int GetHashCode() {
  1282. return S.GetHashCode() ^ Val.GetHashCode();
  1283. }
  1284. }
  1285. }
  1286. //-------- Scenario 1720
  1287. namespace Scenario1720{
  1288. public class Test
  1289. {
  1290. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "check14__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  1291. public static Expression check14__() {
  1292. if(Main() != 0 ) {
  1293. throw new Exception();
  1294. } else {
  1295. return Expression.Constant(0);
  1296. }
  1297. }
  1298. public static int Main()
  1299. {
  1300. Ext.StartCapture();
  1301. bool success = false;
  1302. try
  1303. {
  1304. success = check14();
  1305. }
  1306. finally
  1307. {
  1308. Ext.StopCapture();
  1309. }
  1310. return success ? 0 : 1;
  1311. }
  1312. static bool check14() {
  1313. foreach (Sp val in new Sp[] { default(Sp), new Sp(), new Sp(5,5.0) }) {
  1314. if (!check14(val)) {

Large files files are truncated, but you can click here to view the full file