CodeCastExpressionTest.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // CodeCastExpressionTest.cs
  3. // - Unit tests for System.CodeDom.CodeCastExpression
  4. //
  5. // Author:
  6. // Gert Driesen <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.CodeDom;
  32. namespace MonoTests.System.CodeDom
  33. {
  34. [TestFixture]
  35. public class CodeCastExpressionTest
  36. {
  37. [Test]
  38. public void Constructor0 ()
  39. {
  40. CodeCastExpression cce = new CodeCastExpression ();
  41. Assert.IsNull (cce.Expression, "#1");
  42. Assert.IsNotNull (cce.TargetType, "#2");
  43. Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#3");
  44. CodeExpression expression = new CodeExpression ();
  45. cce.Expression = expression;
  46. Assert.IsNotNull (cce.Expression, "#4");
  47. Assert.AreSame (expression, cce.Expression, "#5");
  48. cce.Expression = null;
  49. Assert.IsNull (cce.Expression, "#6");
  50. CodeTypeReference type = new CodeTypeReference ("mono");
  51. cce.TargetType = type;
  52. Assert.IsNotNull (cce.TargetType, "#7");
  53. Assert.AreSame (type, cce.TargetType, "#8");
  54. cce.TargetType = null;
  55. Assert.IsNotNull (cce.TargetType, "#9");
  56. Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#10");
  57. }
  58. [Test]
  59. public void Constructor1 ()
  60. {
  61. CodeTypeReference type1 = new CodeTypeReference ("mono1");
  62. CodeExpression expression1 = new CodeExpression ();
  63. CodeCastExpression cce = new CodeCastExpression (type1, expression1);
  64. Assert.IsNotNull (cce.Expression, "#1");
  65. Assert.AreSame (expression1, cce.Expression, "#2");
  66. Assert.IsNotNull (cce.TargetType, "#3");
  67. Assert.AreSame (type1, cce.TargetType, "#4");
  68. cce.Expression = null;
  69. Assert.IsNull (cce.Expression, "#5");
  70. CodeExpression expression2 = new CodeExpression ();
  71. cce.Expression = expression2;
  72. Assert.IsNotNull (cce.Expression, "#6");
  73. Assert.AreSame (expression2, cce.Expression, "#7");
  74. cce.TargetType = null;
  75. Assert.IsNotNull (cce.TargetType, "#8");
  76. Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#9");
  77. CodeTypeReference type2 = new CodeTypeReference ("mono2");
  78. cce.TargetType = type2;
  79. Assert.IsNotNull (cce.TargetType, "#10");
  80. Assert.AreSame (type2, cce.TargetType, "#11");
  81. cce = new CodeCastExpression ((CodeTypeReference) null, (CodeExpression) null);
  82. Assert.IsNull (cce.Expression, "#12");
  83. Assert.IsNotNull (cce.TargetType, "#13");
  84. Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#14");
  85. }
  86. [Test]
  87. public void Constructor2 ()
  88. {
  89. string baseType = "mono";
  90. CodeExpression expression = new CodeExpression ();
  91. CodeCastExpression cce = new CodeCastExpression (baseType, expression);
  92. Assert.IsNotNull (cce.Expression, "#1");
  93. Assert.AreSame (expression, cce.Expression, "#2");
  94. Assert.IsNotNull (cce.TargetType, "#3");
  95. Assert.AreEqual (baseType, cce.TargetType.BaseType, "#4");
  96. cce = new CodeCastExpression ((string) null, expression);
  97. Assert.IsNotNull (cce.Expression, "#5");
  98. Assert.AreSame (expression, cce.Expression, "#6");
  99. Assert.IsNotNull (cce.TargetType, "#7");
  100. Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#8");
  101. }
  102. [Test]
  103. public void Constructor3 ()
  104. {
  105. Type type = typeof (int);
  106. CodeExpression expression = new CodeExpression ();
  107. CodeCastExpression cce = new CodeCastExpression (type, expression);
  108. Assert.IsNotNull (cce.Expression, "#1");
  109. Assert.AreSame (expression, cce.Expression, "#2");
  110. Assert.IsNotNull (cce.TargetType, "#3");
  111. Assert.AreEqual (type.FullName, cce.TargetType.BaseType, "#4");
  112. cce = new CodeCastExpression (type, (CodeExpression) null);
  113. Assert.IsNull (cce.Expression, "#5");
  114. Assert.IsNotNull (cce.TargetType, "#6");
  115. Assert.AreEqual (type.FullName, cce.TargetType.BaseType, "#7");
  116. }
  117. [Test]
  118. #if NET_2_0
  119. [ExpectedException (typeof (ArgumentNullException))]
  120. #else
  121. [ExpectedException (typeof (NullReferenceException))]
  122. #endif
  123. public void Constructor3_NullType ()
  124. {
  125. CodeCastExpression cce = new CodeCastExpression ((Type) null,
  126. new CodeExpression ());
  127. }
  128. }
  129. }