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

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

#
C# | 760 lines | 616 code | 129 blank | 15 comment | 84 complexity | fb79c283ae2934e4a80e62d7da6b11eb 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 256
  11. namespace Scenario256{
  12. public class Test
  13. {
  14. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "int_double_Sp_New__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  15. public static Expression int_double_Sp_New__() {
  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_int_double_Sp_New();
  29. }
  30. finally
  31. {
  32. Ext.StopCapture();
  33. }
  34. return success ? 0 : 1;
  35. }
  36. static bool check_int_double_Sp_New() {
  37. int[] svals0 = new int[] { 0, 1, -1, int.MinValue, int.MaxValue };
  38. double[] svals1 = new double[] { 0, 1, -1, double.MinValue, double.MaxValue, double.Epsilon, double.NegativeInfinity, double.PositiveInfinity, double.NaN };
  39. for (int i = 0; i < svals0.Length; i++) {
  40. for (int j = 0; j < svals1.Length; j++) {
  41. if (!check_int_double_Sp_New(svals0[i], svals1[j])) {
  42. Console.WriteLine("int_double_Sp_New failed");
  43. return false;
  44. }
  45. }
  46. }
  47. return true;
  48. }
  49. static bool check_int_double_Sp_New(int val0, double val1) {
  50. ConstructorInfo constructor = typeof(Sp).GetConstructor(new Type[] { typeof(int), typeof(double) });
  51. Expression[] exprArgs = new Expression[] { Expression.Constant(val0, typeof(int)), Expression.Constant(val1, typeof(double)) };
  52. Expression<Func<Sp>> e = Expression.Lambda<Func<Sp>>(
  53. Expression.New(constructor, exprArgs),
  54. new System.Collections.Generic.List<ParameterExpression>());
  55. Func<Sp> f = e.Compile();
  56. return object.Equals(f(), new Sp(val0, val1));
  57. }
  58. }
  59. public static class Ext {
  60. public static void StartCapture() {
  61. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  62. // m.Invoke(null, new object[] { "test.dll" });
  63. }
  64. public static void StopCapture() {
  65. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  66. // m.Invoke(null, new object[0]);
  67. }
  68. public static bool IsIntegralOrEnum(Type type) {
  69. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  70. case TypeCode.Byte:
  71. case TypeCode.SByte:
  72. case TypeCode.Int16:
  73. case TypeCode.Int32:
  74. case TypeCode.Int64:
  75. case TypeCode.UInt16:
  76. case TypeCode.UInt32:
  77. case TypeCode.UInt64:
  78. return true;
  79. default:
  80. return false;
  81. }
  82. }
  83. public static bool IsFloating(Type type) {
  84. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  85. case TypeCode.Single:
  86. case TypeCode.Double:
  87. return true;
  88. default:
  89. return false;
  90. }
  91. }
  92. public static Type GetNonNullableType(Type type) {
  93. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  94. type.GetGenericArguments()[0] :
  95. type;
  96. }
  97. }
  98. public interface I {
  99. void M();
  100. }
  101. public class C : IEquatable<C>, I {
  102. void I.M() {
  103. }
  104. public override bool Equals(object o) {
  105. return o is C && Equals((C) o);
  106. }
  107. public bool Equals(C c) {
  108. return c != null;
  109. }
  110. public override int GetHashCode() {
  111. return 0;
  112. }
  113. }
  114. public class D : C, IEquatable<D> {
  115. public int Val;
  116. public string S;
  117. public D() {
  118. }
  119. public D(int val) : this(val, "") {
  120. }
  121. public D(int val, string s) {
  122. Val = val;
  123. S = s;
  124. }
  125. public override bool Equals(object o) {
  126. return o is D && Equals((D) o);
  127. }
  128. public bool Equals(D d) {
  129. return d != null && d.Val == Val && d.S == S;
  130. }
  131. public override int GetHashCode() {
  132. return Val ^ (S == null ? 0 : S.GetHashCode());
  133. }
  134. }
  135. public enum E {
  136. A=1, B=2
  137. }
  138. public enum El : long {
  139. A, B, C
  140. }
  141. public struct S : IEquatable<S> {
  142. public override bool Equals(object o) {
  143. return (o is S) && Equals((S) o);
  144. }
  145. public bool Equals(S other) {
  146. return true;
  147. }
  148. public override int GetHashCode() {
  149. return 0;
  150. }
  151. }
  152. public struct Sp : IEquatable<Sp> {
  153. public Sp(int i, double d) {
  154. I = i;
  155. D = d;
  156. }
  157. public int I;
  158. public double D;
  159. public override bool Equals(object o) {
  160. return (o is Sp) && Equals((Sp) o);
  161. }
  162. public bool Equals(Sp other) {
  163. return other.I.Equals(I) && other.D.Equals(D);
  164. }
  165. public override int GetHashCode() {
  166. return I.GetHashCode() ^ D.GetHashCode();
  167. }
  168. }
  169. public struct Ss : IEquatable<Ss> {
  170. public Ss(S s) {
  171. Val = s;
  172. }
  173. public S Val;
  174. public override bool Equals(object o) {
  175. return (o is Ss) && Equals((Ss) o);
  176. }
  177. public bool Equals(Ss other) {
  178. return other.Val.Equals(Val);
  179. }
  180. public override int GetHashCode() {
  181. return Val.GetHashCode();
  182. }
  183. }
  184. public struct Sc : IEquatable<Sc> {
  185. public Sc(string s) {
  186. S = s;
  187. }
  188. public string S;
  189. public override bool Equals(object o) {
  190. return (o is Sc) && Equals((Sc) o);
  191. }
  192. public bool Equals(Sc other) {
  193. return other.S == S;
  194. }
  195. public override int GetHashCode() {
  196. return S.GetHashCode();
  197. }
  198. }
  199. public struct Scs : IEquatable<Scs> {
  200. public Scs(string s, S val) {
  201. S = s;
  202. Val = val;
  203. }
  204. public string S;
  205. public S Val;
  206. public override bool Equals(object o) {
  207. return (o is Scs) && Equals((Scs) o);
  208. }
  209. public bool Equals(Scs other) {
  210. return other.S == S && other.Val.Equals(Val);
  211. }
  212. public override int GetHashCode() {
  213. return S.GetHashCode() ^ Val.GetHashCode();
  214. }
  215. }
  216. }
  217. //-------- Scenario 257
  218. namespace Scenario257{
  219. public class Test
  220. {
  221. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "string_S_Scs_New__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  222. public static Expression string_S_Scs_New__() {
  223. if(Main() != 0 ) {
  224. throw new Exception();
  225. } else {
  226. return Expression.Constant(0);
  227. }
  228. }
  229. public static int Main()
  230. {
  231. Ext.StartCapture();
  232. bool success = false;
  233. try
  234. {
  235. success = check_string_S_Scs_New();
  236. }
  237. finally
  238. {
  239. Ext.StopCapture();
  240. }
  241. return success ? 0 : 1;
  242. }
  243. static bool check_string_S_Scs_New() {
  244. string[] svals0 = new string[] { null, "", "a", "foo" };
  245. S[] svals1 = new S[] { default(S), new S() };
  246. for (int i = 0; i < svals0.Length; i++) {
  247. for (int j = 0; j < svals1.Length; j++) {
  248. if (!check_string_S_Scs_New(svals0[i], svals1[j])) {
  249. Console.WriteLine("string_S_Scs_New failed");
  250. return false;
  251. }
  252. }
  253. }
  254. return true;
  255. }
  256. static bool check_string_S_Scs_New(string val0, S val1) {
  257. ConstructorInfo constructor = typeof(Scs).GetConstructor(new Type[] { typeof(string), typeof(S) });
  258. Expression[] exprArgs = new Expression[] { Expression.Constant(val0, typeof(string)), Expression.Constant(val1, typeof(S)) };
  259. Expression<Func<Scs>> e = Expression.Lambda<Func<Scs>>(
  260. Expression.New(constructor, exprArgs),
  261. new System.Collections.Generic.List<ParameterExpression>());
  262. Func<Scs> f = e.Compile();
  263. return object.Equals(f(), new Scs(val0, val1));
  264. }
  265. }
  266. public static class Ext {
  267. public static void StartCapture() {
  268. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  269. // m.Invoke(null, new object[] { "test.dll" });
  270. }
  271. public static void StopCapture() {
  272. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  273. // m.Invoke(null, new object[0]);
  274. }
  275. public static bool IsIntegralOrEnum(Type type) {
  276. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  277. case TypeCode.Byte:
  278. case TypeCode.SByte:
  279. case TypeCode.Int16:
  280. case TypeCode.Int32:
  281. case TypeCode.Int64:
  282. case TypeCode.UInt16:
  283. case TypeCode.UInt32:
  284. case TypeCode.UInt64:
  285. return true;
  286. default:
  287. return false;
  288. }
  289. }
  290. public static bool IsFloating(Type type) {
  291. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  292. case TypeCode.Single:
  293. case TypeCode.Double:
  294. return true;
  295. default:
  296. return false;
  297. }
  298. }
  299. public static Type GetNonNullableType(Type type) {
  300. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  301. type.GetGenericArguments()[0] :
  302. type;
  303. }
  304. }
  305. public interface I {
  306. void M();
  307. }
  308. public class C : IEquatable<C>, I {
  309. void I.M() {
  310. }
  311. public override bool Equals(object o) {
  312. return o is C && Equals((C) o);
  313. }
  314. public bool Equals(C c) {
  315. return c != null;
  316. }
  317. public override int GetHashCode() {
  318. return 0;
  319. }
  320. }
  321. public class D : C, IEquatable<D> {
  322. public int Val;
  323. public string S;
  324. public D() {
  325. }
  326. public D(int val) : this(val, "") {
  327. }
  328. public D(int val, string s) {
  329. Val = val;
  330. S = s;
  331. }
  332. public override bool Equals(object o) {
  333. return o is D && Equals((D) o);
  334. }
  335. public bool Equals(D d) {
  336. return d != null && d.Val == Val && d.S == S;
  337. }
  338. public override int GetHashCode() {
  339. return Val ^ (S == null ? 0 : S.GetHashCode());
  340. }
  341. }
  342. public enum E {
  343. A=1, B=2
  344. }
  345. public enum El : long {
  346. A, B, C
  347. }
  348. public struct S : IEquatable<S> {
  349. public override bool Equals(object o) {
  350. return (o is S) && Equals((S) o);
  351. }
  352. public bool Equals(S other) {
  353. return true;
  354. }
  355. public override int GetHashCode() {
  356. return 0;
  357. }
  358. }
  359. public struct Sp : IEquatable<Sp> {
  360. public Sp(int i, double d) {
  361. I = i;
  362. D = d;
  363. }
  364. public int I;
  365. public double D;
  366. public override bool Equals(object o) {
  367. return (o is Sp) && Equals((Sp) o);
  368. }
  369. public bool Equals(Sp other) {
  370. return other.I.Equals(I) && other.D.Equals(D);
  371. }
  372. public override int GetHashCode() {
  373. return I.GetHashCode() ^ D.GetHashCode();
  374. }
  375. }
  376. public struct Ss : IEquatable<Ss> {
  377. public Ss(S s) {
  378. Val = s;
  379. }
  380. public S Val;
  381. public override bool Equals(object o) {
  382. return (o is Ss) && Equals((Ss) o);
  383. }
  384. public bool Equals(Ss other) {
  385. return other.Val.Equals(Val);
  386. }
  387. public override int GetHashCode() {
  388. return Val.GetHashCode();
  389. }
  390. }
  391. public struct Sc : IEquatable<Sc> {
  392. public Sc(string s) {
  393. S = s;
  394. }
  395. public string S;
  396. public override bool Equals(object o) {
  397. return (o is Sc) && Equals((Sc) o);
  398. }
  399. public bool Equals(Sc other) {
  400. return other.S == S;
  401. }
  402. public override int GetHashCode() {
  403. return S.GetHashCode();
  404. }
  405. }
  406. public struct Scs : IEquatable<Scs> {
  407. public Scs(string s, S val) {
  408. S = s;
  409. Val = val;
  410. }
  411. public string S;
  412. public S Val;
  413. public override bool Equals(object o) {
  414. return (o is Scs) && Equals((Scs) o);
  415. }
  416. public bool Equals(Scs other) {
  417. return other.S == S && other.Val.Equals(Val);
  418. }
  419. public override int GetHashCode() {
  420. return S.GetHashCode() ^ Val.GetHashCode();
  421. }
  422. }
  423. }
  424. //-------- Scenario 258
  425. namespace Scenario258{
  426. public class Test
  427. {
  428. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "int_string_D_New__", new string[] { "positive", "cslinq", "FullTrustOnly","Pri1" })]
  429. public static Expression int_string_D_New__() {
  430. if(Main() != 0 ) {
  431. throw new Exception();
  432. } else {
  433. return Expression.Constant(0);
  434. }
  435. }
  436. public static int Main()
  437. {
  438. Ext.StartCapture();
  439. bool success = false;
  440. try
  441. {
  442. success = check_int_string_D_New();
  443. }
  444. finally
  445. {
  446. Ext.StopCapture();
  447. }
  448. return success ? 0 : 1;
  449. }
  450. static bool check_int_string_D_New() {
  451. int[] svals0 = new int[] { 0, 1, -1, int.MinValue, int.MaxValue };
  452. string[] svals1 = new string[] { null, "", "a", "foo" };
  453. for (int i = 0; i < svals0.Length; i++) {
  454. for (int j = 0; j < svals1.Length; j++) {
  455. if (!check_int_string_D_New(svals0[i], svals1[j])) {
  456. Console.WriteLine("int_string_D_New failed");
  457. return false;
  458. }
  459. }
  460. }
  461. return true;
  462. }
  463. static bool check_int_string_D_New(int val0, string val1) {
  464. ConstructorInfo constructor = typeof(D).GetConstructor(new Type[] { typeof(int), typeof(string) });
  465. Expression[] exprArgs = new Expression[] { Expression.Constant(val0, typeof(int)), Expression.Constant(val1, typeof(string)) };
  466. Expression<Func<D>> e = Expression.Lambda<Func<D>>(
  467. Expression.New(constructor, exprArgs),
  468. new System.Collections.Generic.List<ParameterExpression>());
  469. Func<D> f = e.Compile();
  470. return object.Equals(f(), new D(val0, val1));
  471. }
  472. }
  473. public static class Ext {
  474. public static void StartCapture() {
  475. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StartCaptureToFile", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  476. // m.Invoke(null, new object[] { "test.dll" });
  477. }
  478. public static void StopCapture() {
  479. // MethodInfo m = Assembly.GetAssembly(typeof(Expression)).GetType("System.Linq.Expressions.ExpressionCompiler").GetMethod("StopCapture", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
  480. // m.Invoke(null, new object[0]);
  481. }
  482. public static bool IsIntegralOrEnum(Type type) {
  483. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  484. case TypeCode.Byte:
  485. case TypeCode.SByte:
  486. case TypeCode.Int16:
  487. case TypeCode.Int32:
  488. case TypeCode.Int64:
  489. case TypeCode.UInt16:
  490. case TypeCode.UInt32:
  491. case TypeCode.UInt64:
  492. return true;
  493. default:
  494. return false;
  495. }
  496. }
  497. public static bool IsFloating(Type type) {
  498. switch (Type.GetTypeCode(GetNonNullableType(type))) {
  499. case TypeCode.Single:
  500. case TypeCode.Double:
  501. return true;
  502. default:
  503. return false;
  504. }
  505. }
  506. public static Type GetNonNullableType(Type type) {
  507. return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>) ?
  508. type.GetGenericArguments()[0] :
  509. type;
  510. }
  511. }
  512. public interface I {
  513. void M();
  514. }
  515. public class C : IEquatable<C>, I {
  516. void I.M() {
  517. }
  518. public override bool Equals(object o) {
  519. return o is C && Equals((C) o);
  520. }
  521. public bool Equals(C c) {
  522. return c != null;
  523. }
  524. public override int GetHashCode() {
  525. return 0;
  526. }
  527. }
  528. public class D : C, IEquatable<D> {
  529. public int Val;
  530. public string S;
  531. public D() {
  532. }
  533. public D(int val) : this(val, "") {
  534. }
  535. public D(int val, string s) {
  536. Val = val;
  537. S = s;
  538. }
  539. public override bool Equals(object o) {
  540. return o is D && Equals((D) o);
  541. }
  542. public bool Equals(D d) {
  543. return d != null && d.Val == Val && d.S == S;
  544. }
  545. public override int GetHashCode() {
  546. return Val ^ (S == null ? 0 : S.GetHashCode());
  547. }
  548. }
  549. public enum E {
  550. A=1, B=2
  551. }
  552. public enum El : long {
  553. A, B, C
  554. }
  555. public struct S : IEquatable<S> {
  556. public override bool Equals(object o) {
  557. return (o is S) && Equals((S) o);
  558. }
  559. public bool Equals(S other) {
  560. return true;
  561. }
  562. public override int GetHashCode() {
  563. return 0;
  564. }
  565. }
  566. public struct Sp : IEquatable<Sp> {
  567. public Sp(int i, double d) {
  568. I = i;
  569. D = d;
  570. }
  571. public int I;
  572. public double D;
  573. public override bool Equals(object o) {
  574. return (o is Sp) && Equals((Sp) o);
  575. }
  576. public bool Equals(Sp other) {
  577. return other.I.Equals(I) && other.D.Equals(D);
  578. }
  579. public override int GetHashCode() {
  580. return I.GetHashCode() ^ D.GetHashCode();
  581. }
  582. }
  583. public struct Ss : IEquatable<Ss> {
  584. public Ss(S s) {
  585. Val = s;
  586. }
  587. public S Val;
  588. public override bool Equals(object o) {
  589. return (o is Ss) && Equals((Ss) o);
  590. }
  591. public bool Equals(Ss other) {
  592. return other.Val.Equals(Val);
  593. }
  594. public override int GetHashCode() {
  595. return Val.GetHashCode();
  596. }
  597. }
  598. public struct Sc : IEquatable<Sc> {
  599. public Sc(string s) {
  600. S = s;
  601. }
  602. public string S;
  603. public override bool Equals(object o) {
  604. return (o is Sc) && Equals((Sc) o);
  605. }
  606. public bool Equals(Sc other) {
  607. return other.S == S;
  608. }
  609. public override int GetHashCode() {
  610. return S.GetHashCode();
  611. }
  612. }
  613. public struct Scs : IEquatable<Scs> {
  614. public Scs(string s, S val) {
  615. S = s;
  616. Val = val;
  617. }
  618. public string S;
  619. public S Val;
  620. public override bool Equals(object o) {
  621. return (o is Scs) && Equals((Scs) o);
  622. }
  623. public bool Equals(Scs other) {
  624. return other.S == S && other.Val.Equals(Val);
  625. }
  626. public override int GetHashCode() {
  627. return S.GetHashCode() ^ Val.GetHashCode();
  628. }
  629. }
  630. }
  631. }