PageRenderTime 52ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 3ms

/IronPython_Main/Runtime/Tests/ETScenariosCSLinq/CSLinq/ExpressionTreeNodes/Not.cs

#
C# | 13447 lines | 11483 code | 1922 blank | 42 comment | 4914 complexity | 666008fde201bf2127369f0fca935e49 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.Collections;
  9. using System.Text;
  10. using System.Collections.Generic;
  11. using System;
  12. namespace ExpressionTreeNodes
  13. {
  14. //-------- Scenario 782
  15. namespace Scenario782
  16. {
  17. namespace Not
  18. {
  19. public class Test
  20. {
  21. // expression = null
  22. public static int Test1()
  23. {
  24. ConstantExpression ce = Expression.Constant(10);
  25. try
  26. {
  27. ce = null;
  28. UnaryExpression result = Expression.Not(ce);
  29. return 1;
  30. }
  31. catch (ArgumentNullException ane)
  32. {
  33. if (ane.CompareParamName("expression")) return 0;
  34. return 1;
  35. }
  36. }
  37. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not1__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  38. public static Expression Not1__()
  39. {
  40. if (Main() != 0)
  41. {
  42. throw new Exception();
  43. }
  44. else
  45. {
  46. return Expression.Constant(0);
  47. }
  48. }
  49. public static int Main()
  50. {
  51. return Test1();
  52. }
  53. }
  54. }
  55. public static class Extension
  56. {
  57. public static bool CompareParamName(this ArgumentException ex, string expected)
  58. {
  59. #if SILVERLIGHT
  60. #if SLRESOURCES
  61. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  62. #else
  63. return true;
  64. #endif
  65. #else
  66. return ex.ParamName == expected;
  67. #endif
  68. }
  69. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  70. {
  71. #if SILVERLIGHT
  72. #if SLRESOURCES
  73. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  74. #else
  75. return true;
  76. #endif
  77. #else
  78. return ex.ParamName == expected;
  79. #endif
  80. }
  81. }
  82. public static class Verification
  83. {
  84. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  85. {
  86. if (!(result.NodeType == et))
  87. {
  88. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  89. return 1;
  90. }
  91. if (!(result.Type == type))
  92. {
  93. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  94. return 1;
  95. }
  96. if (val == null)
  97. {
  98. if (result.Value != null) return 1;
  99. }
  100. else
  101. {
  102. if (!(result.Value.Equals(val))) return 1;
  103. }
  104. if (!(result.ToString() == str)) return 1;
  105. return 0;
  106. }
  107. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  108. {
  109. if (!(result.NodeType == et))
  110. {
  111. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  112. return 1;
  113. }
  114. if (!(result.Type == type))
  115. {
  116. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  117. return 1;
  118. }
  119. if (operand == null)
  120. {
  121. if (result.Operand != null) return 1;
  122. }
  123. else
  124. {
  125. if (!(result.Operand.Equals(operand))) return 1;
  126. }
  127. if (!(result.ToString() == str))
  128. {
  129. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  130. return 1;
  131. }
  132. if (result.Method != mi) return 1;
  133. if (result.IsLifted != islifted) return 1;
  134. if (result.IsLiftedToNull != isliftedtonull) return 1;
  135. return 0;
  136. }
  137. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  138. {
  139. if (!(result.NodeType == et))
  140. {
  141. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  142. return 1;
  143. }
  144. if (!(result.Type == type))
  145. {
  146. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  147. return 1;
  148. }
  149. if (left == null)
  150. {
  151. if (result.Left != null)
  152. {
  153. Console.WriteLine("left was null");
  154. return 1;
  155. }
  156. }
  157. else
  158. {
  159. if (!(result.Left.Equals(left)))
  160. {
  161. Console.WriteLine("left was different");
  162. return 1;
  163. }
  164. }
  165. if (right == null)
  166. {
  167. if (result.Right != null) return 1;
  168. }
  169. else
  170. {
  171. if (!(result.Right.Equals(right))) return 1;
  172. }
  173. if (!(result.ToString() == str))
  174. {
  175. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  176. return 1;
  177. }
  178. if (result.Method != mi) return 1;
  179. if (result.IsLifted != islifted) return 1;
  180. if (result.IsLiftedToNull != isliftedtonull) return 1;
  181. if (result.Conversion != null) return 1;
  182. return 0;
  183. }
  184. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  185. {
  186. if (!(result.NodeType == et))
  187. {
  188. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  189. return 1;
  190. }
  191. if (!(result.Type == type))
  192. {
  193. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  194. return 1;
  195. }
  196. if (left == null)
  197. {
  198. if (result.Left != null) return 1;
  199. }
  200. else
  201. {
  202. if (!(result.Left.Equals(left))) return 1;
  203. }
  204. if (right == null)
  205. {
  206. if (result.Right != null) return 1;
  207. }
  208. else
  209. {
  210. if (!(result.Right.Equals(right))) return 1;
  211. }
  212. if (!(result.ToString() == str)) return 1;
  213. if (result.Method != mi) return 1;
  214. if (result.IsLifted != islifted) return 1;
  215. if (result.IsLiftedToNull != isliftedtonull) return 1;
  216. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  217. return 0;
  218. }
  219. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  220. {
  221. if (!(result.NodeType == et))
  222. {
  223. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  224. return 1;
  225. }
  226. if (!(result.Type == type))
  227. {
  228. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  229. return 1;
  230. }
  231. if (!(result.Method == method)) return 1;
  232. if (obj == null)
  233. {
  234. if (result.Object != null)
  235. {
  236. Console.WriteLine("Expected object to be null.");
  237. return 1;
  238. }
  239. }
  240. else
  241. {
  242. if (!(result.Object.Equals(obj)))
  243. {
  244. Console.WriteLine("Object on which call is made is different from the result.");
  245. return 1;
  246. }
  247. }
  248. if (!(result.ToString() == str))
  249. {
  250. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  251. return 1;
  252. }
  253. if (result.Arguments.Count != arguments.Length) return 1;
  254. for (int i = 0; i < arguments.Length; i++)
  255. {
  256. if (result.Arguments[i] != arguments[i]) return 1;
  257. }
  258. return 0;
  259. }
  260. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  261. {
  262. if (!(result.NodeType == et))
  263. {
  264. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  265. return 1;
  266. }
  267. if (!(result.Type == type))
  268. {
  269. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  270. return 1;
  271. }
  272. if (expr == null)
  273. {
  274. Console.WriteLine("expr was null.");
  275. if (result.Expression != null) return 1;
  276. }
  277. else
  278. {
  279. if (!(result.Expression.Equals(expr)))
  280. {
  281. return 1;
  282. }
  283. }
  284. if (!(result.TypeOperand == typeop)) return 1;
  285. if (!(result.ToString() == str))
  286. {
  287. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  288. return 1;
  289. }
  290. return 0;
  291. }
  292. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  293. {
  294. if (!(result.NodeType == et))
  295. {
  296. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  297. return 1;
  298. }
  299. if (!(result.Type == type))
  300. {
  301. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  302. return 1;
  303. }
  304. if (test == null)
  305. {
  306. if (result.Test != null) return 1;
  307. }
  308. else
  309. {
  310. if (!(result.Test.Equals(test))) return 1;
  311. }
  312. if (ifTrue == null)
  313. {
  314. if (result.IfTrue != null) return 1;
  315. }
  316. else
  317. {
  318. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  319. }
  320. if (ifFalse == null)
  321. {
  322. if (result.IfFalse != null) return 1;
  323. }
  324. else
  325. {
  326. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  327. }
  328. if (!(result.ToString() == str)) return 1;
  329. return 0;
  330. }
  331. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  332. {
  333. if (!(result.NodeType == et))
  334. {
  335. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  336. return 1;
  337. }
  338. if (!(result.Type == type))
  339. {
  340. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  341. return 1;
  342. }
  343. if (exp_expr == null)
  344. {
  345. if (result.Expression != null)
  346. {
  347. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  348. return 1;
  349. }
  350. }
  351. else
  352. {
  353. if (!(result.Expression.Equals(exp_expr)))
  354. {
  355. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  356. return 1;
  357. }
  358. }
  359. if (!(result.Member == exp_member))
  360. {
  361. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  362. return 1;
  363. }
  364. if (!(result.ToString() == str))
  365. {
  366. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  367. return 1;
  368. }
  369. return 0;
  370. }
  371. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  372. {
  373. if (!(result.NodeType == et))
  374. {
  375. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  376. return 1;
  377. }
  378. if (!(result.Type == type))
  379. {
  380. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  381. return 1;
  382. }
  383. if (!(result.Constructor == constructor))
  384. {
  385. Console.WriteLine("Unexpected constructor");
  386. return 1;
  387. }
  388. if (!(result.ToString() == str))
  389. {
  390. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  391. return 1;
  392. }
  393. if (arguments == null)
  394. {
  395. if (result.Arguments.Count != 0)
  396. {
  397. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  398. return 1;
  399. }
  400. }
  401. else
  402. {
  403. if (result.Arguments.Count != arguments.Length)
  404. {
  405. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  406. return 1;
  407. }
  408. for (int i = 0; i < arguments.Length; i++)
  409. {
  410. if (result.Arguments[i] != arguments[i])
  411. {
  412. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  413. return 1;
  414. }
  415. }
  416. }
  417. if (result.Members == null)
  418. {
  419. Console.WriteLine("result.Members was null");
  420. return 1;
  421. }
  422. if (members == null)
  423. {
  424. if (result.Members.Count != 0)
  425. {
  426. Console.WriteLine("Got more than zero members");
  427. return 1;
  428. }
  429. }
  430. else
  431. {
  432. if (result.Members.Count != members.Length)
  433. {
  434. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  435. return 1;
  436. }
  437. for (int i = 0; i < members.Length; i++)
  438. {
  439. if (result.Members[i] != members[i])
  440. {
  441. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  442. return 1;
  443. }
  444. }
  445. }
  446. return 0;
  447. }
  448. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  449. {
  450. if (!(result.NodeType == et))
  451. {
  452. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  453. return 1;
  454. }
  455. if (!(result.Type == type))
  456. {
  457. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  458. return 1;
  459. }
  460. if (!(result.Constructor == constructor))
  461. {
  462. Console.WriteLine("Constructor is different from expected.");
  463. return 1;
  464. }
  465. if (!(result.ToString() == str))
  466. {
  467. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  468. return 1;
  469. }
  470. if (result.Arguments.Count != arguments.Length)
  471. {
  472. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  473. return 1;
  474. }
  475. for (int i = 0; i < arguments.Length; i++)
  476. {
  477. if (result.Arguments[i] != arguments[i])
  478. {
  479. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  480. return 1;
  481. }
  482. }
  483. if (result.Members != null)
  484. {
  485. Console.WriteLine("result.Members isn't null");
  486. return 1;
  487. }
  488. return 0;
  489. }
  490. public static int VerifyListInitParms(ListInitExpression result, ExpressionType et, Type type, NewExpression newExpression, string str, params ElementInit[] initializers)
  491. {
  492. if (!(result.NodeType == et))
  493. {
  494. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  495. return 1;
  496. }
  497. if (!(result.Type == type))
  498. {
  499. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  500. return 1;
  501. }
  502. if (!(result.NewExpression == newExpression)) return 1;
  503. if (!(result.ToString() == str))
  504. {
  505. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  506. return 1;
  507. }
  508. if (result.Initializers.Count != initializers.Length) return 1;
  509. for (int i = 0; i < initializers.Length; i++)
  510. {
  511. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  512. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  513. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  514. {
  515. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  516. }
  517. }
  518. return 0;
  519. }
  520. public static int VerifyElementInitParms(ElementInit result, MethodInfo exp_mi, string str, params Expression[] args)
  521. {
  522. if (result.AddMethod != exp_mi) return 1;
  523. if (!(result.ToString() == str))
  524. {
  525. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  526. return 1;
  527. }
  528. if (result.Arguments.Count != args.Length) return 1;
  529. for (int i = 0; i < args.Length; i++)
  530. {
  531. if (result.Arguments[i] != args[i]) return 1;
  532. }
  533. return 0;
  534. }
  535. public static int VerifyMemberAssignmentParms(MemberAssignment result, MemberBindingType bt, Expression expr, MemberInfo member, string str)
  536. {
  537. if (!(result.BindingType == bt)) return 1;
  538. if (!(result.Expression == expr)) return 1;
  539. if (!(result.Member.Equals(member))) return 1;
  540. if (!(result.ToString() == str))
  541. {
  542. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  543. return 1;
  544. }
  545. return 0;
  546. }
  547. public static int VerifyMemberListBindParms(MemberListBinding result, MemberBindingType bt, ElementInit[] initializers, MemberInfo member, string str)
  548. {
  549. if (!(result.BindingType == bt)) return 1;
  550. if (!(result.Member.Equals(member))) return 1;
  551. if (!(result.ToString() == str))
  552. {
  553. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  554. return 1;
  555. }
  556. if (result.Initializers.Count != initializers.Length) return 1;
  557. for (int i = 0; i < initializers.Length; i++)
  558. {
  559. if (result.Initializers[i].AddMethod != initializers[i].AddMethod) return 1;
  560. if (result.Initializers[i].Arguments.Count != initializers[i].Arguments.Count) return 1;
  561. for (int j = 0; j < result.Initializers[i].Arguments.Count; j++)
  562. {
  563. if (result.Initializers[i].Arguments[j] != initializers[i].Arguments[j]) return 1;
  564. }
  565. }
  566. return 0;
  567. }
  568. public static int VerifyMemberMemberBindParms(MemberMemberBinding result, MemberBindingType bt, MemberBinding[] bindings, MemberInfo member, string str)
  569. {
  570. if (!(result.BindingType == bt)) return 1;
  571. if (!(result.Member.Equals(member))) return 1;
  572. if (!(result.ToString() == str))
  573. {
  574. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  575. return 1;
  576. }
  577. if (result.Bindings.Count != bindings.Length) return 1;
  578. for (int i = 0; i < bindings.Length; i++)
  579. {
  580. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  581. }
  582. return 0;
  583. }
  584. public static int VerifyMemberInitParms(MemberInitExpression result, ExpressionType et, Type type, NewExpression newExpr, MemberBinding[] bindings, string str)
  585. {
  586. if (!(result.NodeType == et))
  587. {
  588. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  589. return 1;
  590. }
  591. if (!(result.Type == type))
  592. {
  593. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  594. return 1;
  595. }
  596. if (!(result.NewExpression.Equals(newExpr))) return 1;
  597. if (!(result.ToString() == str)) return 1;
  598. if (result.Bindings.Count != bindings.Length) return 1;
  599. for (int i = 0; i < bindings.Length; i++)
  600. {
  601. if (!(result.Bindings[i].Equals(bindings[i]))) return 1;
  602. }
  603. return 0;
  604. }
  605. public static int VerifyNewArrayParms(NewArrayExpression result, ExpressionType et, Type type, Expression[] expr, string str)
  606. {
  607. if (!(result.NodeType == et))
  608. {
  609. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  610. return 1;
  611. }
  612. if (!(result.Type == type))
  613. {
  614. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  615. return 1;
  616. }
  617. if (result.Expressions.Count != expr.Length) return 1;
  618. for (int i = 0; i < expr.Length; i++)
  619. {
  620. if (!(result.Expressions[i].Equals(expr[i]))) return 1;
  621. }
  622. if (!(result.ToString() == str))
  623. {
  624. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  625. return 1;
  626. }
  627. return 0;
  628. }
  629. public static int VerifyParameterParms(ParameterExpression result, ExpressionType et, Type type, string name, string str)
  630. {
  631. if (!(result.NodeType == et))
  632. {
  633. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  634. return 1;
  635. }
  636. if (!(result.Type == type))
  637. {
  638. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  639. return 1;
  640. }
  641. if (!(result.Name == name)) return 1;
  642. if (!(result.ToString() == str))
  643. {
  644. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  645. return 1;
  646. }
  647. return 0;
  648. }
  649. public static int VerifyLambdaParms(LambdaExpression result, ExpressionType et, Type type, Expression expr, ParameterExpression[] parms, string str)
  650. {
  651. if (!(result.NodeType == et))
  652. {
  653. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  654. return 1;
  655. }
  656. if (!(result.Type == type))
  657. {
  658. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  659. return 1;
  660. }
  661. if (expr == null)
  662. {
  663. if (result.Body != null) return 1;
  664. }
  665. else
  666. {
  667. if (!(result.Body.Equals(expr))) return 1;
  668. }
  669. if (result.Parameters.Count != parms.Length) return 1;
  670. for (int i = 0; i < parms.Length; i++)
  671. {
  672. if (!(result.Parameters[i].Equals(parms[i]))) return 1;
  673. }
  674. if (!(result.ToString() == str))
  675. {
  676. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  677. return 1;
  678. }
  679. return 0;
  680. }
  681. public static int VerifyInvokeParms(InvocationExpression result, ExpressionType et, Type type, Expression expr, Expression[] args, string str)
  682. {
  683. if (!(result.NodeType == et))
  684. {
  685. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  686. return 1;
  687. }
  688. if (!(result.Type == type))
  689. {
  690. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  691. return 1;
  692. }
  693. if (expr == null)
  694. {
  695. if (result.Expression != null) return 1;
  696. }
  697. else
  698. {
  699. if (!(result.Expression.Equals(expr))) return 1;
  700. }
  701. if (result.Arguments.Count != args.Length) return 1;
  702. for (int i = 0; i < args.Length; i++)
  703. {
  704. if (!(result.Arguments[i].Equals(args[i])))
  705. {
  706. return 1;
  707. }
  708. }
  709. if (result.ToString() != str)
  710. {
  711. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. }
  717. }
  718. //-------- Scenario 783
  719. namespace Scenario783
  720. {
  721. namespace Not
  722. {
  723. public class Test
  724. {
  725. // Test for functionality: Argument is of type integer
  726. public static int Test2()
  727. {
  728. ConstantExpression ce = Expression.Constant(10);
  729. Type exp_type = ce.Type;
  730. ExpressionType exp_et = ExpressionType.Not;
  731. string exp_str = "Not(" + ce.ToString() + ")";
  732. Expression exp_operand = ce;
  733. UnaryExpression result = Expression.Not(ce);
  734. return Verification.VerifyUnaryParms(result, exp_et, exp_type, exp_operand, exp_str, null, false, false);
  735. }
  736. [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "Not2__", new string[] { "positive", "cslinq", "FullTrustOnly", "Pri1" })]
  737. public static Expression Not2__()
  738. {
  739. if (Main() != 0)
  740. {
  741. throw new Exception();
  742. }
  743. else
  744. {
  745. return Expression.Constant(0);
  746. }
  747. }
  748. public static int Main()
  749. {
  750. return Test2();
  751. }
  752. }
  753. }
  754. public static class Extension
  755. {
  756. public static bool CompareParamName(this ArgumentException ex, string expected)
  757. {
  758. #if SILVERLIGHT
  759. #if SLRESOURCES
  760. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  761. #else
  762. return true;
  763. #endif
  764. #else
  765. return ex.ParamName == expected;
  766. #endif
  767. }
  768. public static bool CompareParamName(this ArgumentNullException ex, string expected)
  769. {
  770. #if SILVERLIGHT
  771. #if SLRESOURCES
  772. return ex.Message.Substring(ex.Message.LastIndexOf(": ") + 2) == expected;
  773. #else
  774. return true;
  775. #endif
  776. #else
  777. return ex.ParamName == expected;
  778. #endif
  779. }
  780. }
  781. public static class Verification
  782. {
  783. public static int VerifyConstParms(ConstantExpression result, ExpressionType et, Type type, object val, string str)
  784. {
  785. if (!(result.NodeType == et))
  786. {
  787. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  788. return 1;
  789. }
  790. if (!(result.Type == type))
  791. {
  792. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  793. return 1;
  794. }
  795. if (val == null)
  796. {
  797. if (result.Value != null) return 1;
  798. }
  799. else
  800. {
  801. if (!(result.Value.Equals(val))) return 1;
  802. }
  803. if (!(result.ToString() == str)) return 1;
  804. return 0;
  805. }
  806. public static int VerifyUnaryParms(UnaryExpression result, ExpressionType et, Type type, Expression operand, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  807. {
  808. if (!(result.NodeType == et))
  809. {
  810. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  811. return 1;
  812. }
  813. if (!(result.Type == type))
  814. {
  815. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  816. return 1;
  817. }
  818. if (operand == null)
  819. {
  820. if (result.Operand != null) return 1;
  821. }
  822. else
  823. {
  824. if (!(result.Operand.Equals(operand))) return 1;
  825. }
  826. if (!(result.ToString() == str))
  827. {
  828. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  829. return 1;
  830. }
  831. if (result.Method != mi) return 1;
  832. if (result.IsLifted != islifted) return 1;
  833. if (result.IsLiftedToNull != isliftedtonull) return 1;
  834. return 0;
  835. }
  836. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, bool islifted, bool isliftedtonull)
  837. {
  838. if (!(result.NodeType == et))
  839. {
  840. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  841. return 1;
  842. }
  843. if (!(result.Type == type))
  844. {
  845. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  846. return 1;
  847. }
  848. if (left == null)
  849. {
  850. if (result.Left != null)
  851. {
  852. Console.WriteLine("left was null");
  853. return 1;
  854. }
  855. }
  856. else
  857. {
  858. if (!(result.Left.Equals(left)))
  859. {
  860. Console.WriteLine("left was different");
  861. return 1;
  862. }
  863. }
  864. if (right == null)
  865. {
  866. if (result.Right != null) return 1;
  867. }
  868. else
  869. {
  870. if (!(result.Right.Equals(right))) return 1;
  871. }
  872. if (!(result.ToString() == str))
  873. {
  874. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  875. return 1;
  876. }
  877. if (result.Method != mi) return 1;
  878. if (result.IsLifted != islifted) return 1;
  879. if (result.IsLiftedToNull != isliftedtonull) return 1;
  880. if (result.Conversion != null) return 1;
  881. return 0;
  882. }
  883. public static int VerifyBinaryParms(BinaryExpression result, ExpressionType et, Type type, Expression left, Expression right, string str, MethodInfo mi, LambdaExpression conv_expr, bool islifted, bool isliftedtonull)
  884. {
  885. if (!(result.NodeType == et))
  886. {
  887. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  888. return 1;
  889. }
  890. if (!(result.Type == type))
  891. {
  892. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  893. return 1;
  894. }
  895. if (left == null)
  896. {
  897. if (result.Left != null) return 1;
  898. }
  899. else
  900. {
  901. if (!(result.Left.Equals(left))) return 1;
  902. }
  903. if (right == null)
  904. {
  905. if (result.Right != null) return 1;
  906. }
  907. else
  908. {
  909. if (!(result.Right.Equals(right))) return 1;
  910. }
  911. if (!(result.ToString() == str)) return 1;
  912. if (result.Method != mi) return 1;
  913. if (result.IsLifted != islifted) return 1;
  914. if (result.IsLiftedToNull != isliftedtonull) return 1;
  915. if (result.Conversion.ToString() != conv_expr.ToString()) return 1;
  916. return 0;
  917. }
  918. public static int VerifyMethodCallParms(MethodCallExpression result, ExpressionType et, Type type, MethodInfo method, Expression obj, string str, params Expression[] arguments)
  919. {
  920. if (!(result.NodeType == et))
  921. {
  922. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  923. return 1;
  924. }
  925. if (!(result.Type == type))
  926. {
  927. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  928. return 1;
  929. }
  930. if (!(result.Method == method)) return 1;
  931. if (obj == null)
  932. {
  933. if (result.Object != null)
  934. {
  935. Console.WriteLine("Expected object to be null.");
  936. return 1;
  937. }
  938. }
  939. else
  940. {
  941. if (!(result.Object.Equals(obj)))
  942. {
  943. Console.WriteLine("Object on which call is made is different from the result.");
  944. return 1;
  945. }
  946. }
  947. if (!(result.ToString() == str))
  948. {
  949. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  950. return 1;
  951. }
  952. if (result.Arguments.Count != arguments.Length) return 1;
  953. for (int i = 0; i < arguments.Length; i++)
  954. {
  955. if (result.Arguments[i] != arguments[i]) return 1;
  956. }
  957. return 0;
  958. }
  959. public static int VerifyTypeBinaryParms(TypeBinaryExpression result, ExpressionType et, Type type, Expression expr, Type typeop, string str)
  960. {
  961. if (!(result.NodeType == et))
  962. {
  963. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  964. return 1;
  965. }
  966. if (!(result.Type == type))
  967. {
  968. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  969. return 1;
  970. }
  971. if (expr == null)
  972. {
  973. Console.WriteLine("expr was null.");
  974. if (result.Expression != null) return 1;
  975. }
  976. else
  977. {
  978. if (!(result.Expression.Equals(expr)))
  979. {
  980. return 1;
  981. }
  982. }
  983. if (!(result.TypeOperand == typeop)) return 1;
  984. if (!(result.ToString() == str))
  985. {
  986. Console.WriteLine("Expected: " + str + " Actual: " + result.ToString());
  987. return 1;
  988. }
  989. return 0;
  990. }
  991. public static int VerifyConditionalParms(ConditionalExpression result, ExpressionType et, Type type, Expression test, Expression ifTrue, Expression ifFalse, string str)
  992. {
  993. if (!(result.NodeType == et))
  994. {
  995. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  996. return 1;
  997. }
  998. if (!(result.Type == type))
  999. {
  1000. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1001. return 1;
  1002. }
  1003. if (test == null)
  1004. {
  1005. if (result.Test != null) return 1;
  1006. }
  1007. else
  1008. {
  1009. if (!(result.Test.Equals(test))) return 1;
  1010. }
  1011. if (ifTrue == null)
  1012. {
  1013. if (result.IfTrue != null) return 1;
  1014. }
  1015. else
  1016. {
  1017. if (!(result.IfTrue.Equals(ifTrue))) return 1;
  1018. }
  1019. if (ifFalse == null)
  1020. {
  1021. if (result.IfFalse != null) return 1;
  1022. }
  1023. else
  1024. {
  1025. if (!(result.IfFalse.Equals(ifFalse))) return 1;
  1026. }
  1027. if (!(result.ToString() == str)) return 1;
  1028. return 0;
  1029. }
  1030. public static int VerifyMemberParms(MemberExpression result, ExpressionType et, Type type, Expression exp_expr, MemberInfo exp_member, string str)
  1031. {
  1032. if (!(result.NodeType == et))
  1033. {
  1034. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1035. return 1;
  1036. }
  1037. if (!(result.Type == type))
  1038. {
  1039. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1040. return 1;
  1041. }
  1042. if (exp_expr == null)
  1043. {
  1044. if (result.Expression != null)
  1045. {
  1046. Console.WriteLine("Expression is not null: " + result.Expression.ToString());
  1047. return 1;
  1048. }
  1049. }
  1050. else
  1051. {
  1052. if (!(result.Expression.Equals(exp_expr)))
  1053. {
  1054. Console.WriteLine("Unexpected Expression: " + result.Expression.ToString());
  1055. return 1;
  1056. }
  1057. }
  1058. if (!(result.Member == exp_member))
  1059. {
  1060. Console.WriteLine("Unexpected result member: " + result.Member.ToString());
  1061. return 1;
  1062. }
  1063. if (!(result.ToString() == str))
  1064. {
  1065. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1066. return 1;
  1067. }
  1068. return 0;
  1069. }
  1070. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments, params MemberInfo[] members)
  1071. {
  1072. if (!(result.NodeType == et))
  1073. {
  1074. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1075. return 1;
  1076. }
  1077. if (!(result.Type == type))
  1078. {
  1079. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1080. return 1;
  1081. }
  1082. if (!(result.Constructor == constructor))
  1083. {
  1084. Console.WriteLine("Unexpected constructor");
  1085. return 1;
  1086. }
  1087. if (!(result.ToString() == str))
  1088. {
  1089. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1090. return 1;
  1091. }
  1092. if (arguments == null)
  1093. {
  1094. if (result.Arguments.Count != 0)
  1095. {
  1096. Console.WriteLine("More than one argument supplied: " + result.Arguments.Count);
  1097. return 1;
  1098. }
  1099. }
  1100. else
  1101. {
  1102. if (result.Arguments.Count != arguments.Length)
  1103. {
  1104. Console.WriteLine("Different number of arguments obtained: " + result.Arguments.Count);
  1105. return 1;
  1106. }
  1107. for (int i = 0; i < arguments.Length; i++)
  1108. {
  1109. if (result.Arguments[i] != arguments[i])
  1110. {
  1111. Console.WriteLine("Argument " + i.ToString() + " is different than expected: Expected " + arguments[i].ToString() + " and got " + result.Arguments[i].ToString());
  1112. return 1;
  1113. }
  1114. }
  1115. }
  1116. if (result.Members == null)
  1117. {
  1118. Console.WriteLine("result.Members was null");
  1119. return 1;
  1120. }
  1121. if (members == null)
  1122. {
  1123. if (result.Members.Count != 0)
  1124. {
  1125. Console.WriteLine("Got more than zero members");
  1126. return 1;
  1127. }
  1128. }
  1129. else
  1130. {
  1131. if (result.Members.Count != members.Length)
  1132. {
  1133. Console.WriteLine("Got an unexpected number of members: " + result.Members.Count);
  1134. return 1;
  1135. }
  1136. for (int i = 0; i < members.Length; i++)
  1137. {
  1138. if (result.Members[i] != members[i])
  1139. {
  1140. Console.WriteLine("Member " + i.ToString() + " is different than expected: Expected " + members[i].ToString() + " and got " + result.Members[i].ToString());
  1141. return 1;
  1142. }
  1143. }
  1144. }
  1145. return 0;
  1146. }
  1147. public static int VerifyNewParms(NewExpression result, ExpressionType et, Type type, ConstructorInfo constructor, string str, Expression[] arguments)
  1148. {
  1149. if (!(result.NodeType == et))
  1150. {
  1151. Console.WriteLine("Unexpected result node type: " + result.NodeType.ToString());
  1152. return 1;
  1153. }
  1154. if (!(result.Type == type))
  1155. {
  1156. Console.WriteLine("Unexpected result type: " + result.Type.ToString());
  1157. return 1;
  1158. }
  1159. if (!(result.Constructor == constructor))
  1160. {
  1161. Console.WriteLine("Constructor is different from expected.");
  1162. return 1;
  1163. }
  1164. if (!(result.ToString() == str))
  1165. {
  1166. Console.WriteLine("Unexpected result: " + result.ToString() + " - Expected: " + str);
  1167. return 1;
  1168. }
  1169. if (result.Arguments.Count != arguments.Length)
  1170. {
  1171. Console.WriteLine("Different number of arguments: " + result.Arguments.Count);
  1172. return 1;
  1173. }
  1174. for (int i = 0; i < arguments.Length; i++)
  1175. {

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