CodeVariableDeclarationStatementTest.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // CodeVariableDeclarationStatementTest.cs
  3. // - Unit tests for System.CodeDom.CodeVariableDeclarationStatement
  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 CodeVariableDeclarationStatementTest
  36. {
  37. [Test]
  38. public void Constructor0 ()
  39. {
  40. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement ();
  41. Assert.IsNull (cvds.InitExpression, "#1");
  42. Assert.IsNotNull (cvds.Name, "#2");
  43. Assert.AreEqual (string.Empty, cvds.Name, "#3");
  44. Assert.IsNotNull (cvds.Type, "#4");
  45. Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#5");
  46. string name = "mono";
  47. cvds.Name = name;
  48. Assert.AreSame (name, cvds.Name, "#6");
  49. cvds.Name = null;
  50. Assert.IsNotNull (cvds.Name, "#7");
  51. Assert.AreEqual (string.Empty, cvds.Name, "#8");
  52. CodeExpression expression = new CodeExpression ();
  53. cvds.InitExpression = expression;
  54. Assert.AreSame (expression, cvds.InitExpression, "#9");
  55. CodeTypeReference type = new CodeTypeReference ("mono");
  56. cvds.Type = type;
  57. Assert.AreSame (type, cvds.Type, "#10");
  58. cvds.Type = null;
  59. Assert.IsNotNull (cvds.Type, "#11");
  60. Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#12");
  61. #if NET_2_0
  62. Assert.IsNotNull (cvds.StartDirectives, "#13");
  63. Assert.AreEqual (0, cvds.StartDirectives.Count, "#14");
  64. Assert.IsNotNull (cvds.EndDirectives, "#15");
  65. Assert.AreEqual (0, cvds.EndDirectives.Count, "#16");
  66. #endif
  67. Assert.IsNull (cvds.LinePragma, "#17");
  68. CodeLinePragma clp = new CodeLinePragma ("mono", 10);
  69. cvds.LinePragma = clp;
  70. Assert.IsNotNull (cvds.LinePragma, "#18");
  71. Assert.AreSame (clp, cvds.LinePragma, "#19");
  72. cvds.LinePragma = null;
  73. Assert.IsNull (cvds.LinePragma, "#20");
  74. }
  75. [Test]
  76. public void Constructor1 ()
  77. {
  78. CodeTypeReference type = new CodeTypeReference ("mono");
  79. string name = "mono";
  80. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
  81. type, name);
  82. Assert.IsNull (cvds.InitExpression, "#1");
  83. Assert.IsNotNull (cvds.Name, "#2");
  84. Assert.AreSame (name, cvds.Name, "#3");
  85. Assert.IsNotNull (cvds.Type, "#4");
  86. Assert.AreSame (type, cvds.Type, "#5");
  87. cvds = new CodeVariableDeclarationStatement ((CodeTypeReference) null,
  88. (string) null);
  89. Assert.IsNotNull (cvds.Name, "#6");
  90. Assert.AreEqual (string.Empty, cvds.Name, "#7");
  91. Assert.IsNotNull (cvds.Type, "#8");
  92. Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#9");
  93. }
  94. [Test]
  95. public void Constructor2 ()
  96. {
  97. string baseType = "monotype";
  98. string name = "mono";
  99. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
  100. baseType, name);
  101. Assert.IsNull (cvds.InitExpression, "#1");
  102. Assert.IsNotNull (cvds.Name, "#2");
  103. Assert.AreSame (name, cvds.Name, "#3");
  104. Assert.IsNotNull (cvds.Type, "#4");
  105. Assert.AreSame (baseType, cvds.Type.BaseType, "#5");
  106. cvds = new CodeVariableDeclarationStatement ((string) null,
  107. (string) null);
  108. Assert.IsNotNull (cvds.Name, "#6");
  109. Assert.AreEqual (string.Empty, cvds.Name, "#7");
  110. Assert.IsNotNull (cvds.Type, "#8");
  111. Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#9");
  112. }
  113. [Test]
  114. public void Constructor3 ()
  115. {
  116. Type baseType = typeof (int);
  117. string name = "mono";
  118. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
  119. baseType, name);
  120. Assert.IsNull (cvds.InitExpression, "#1");
  121. Assert.IsNotNull (cvds.Name, "#2");
  122. Assert.AreSame (name, cvds.Name, "#3");
  123. Assert.IsNotNull (cvds.Type, "#4");
  124. Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#5");
  125. cvds = new CodeVariableDeclarationStatement (baseType,
  126. (string) null);
  127. Assert.IsNotNull (cvds.Name, "#6");
  128. Assert.AreEqual (string.Empty, cvds.Name, "#7");
  129. Assert.IsNotNull (cvds.Type, "#8");
  130. Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#9");
  131. }
  132. [Test]
  133. #if NET_2_0
  134. [ExpectedException (typeof (ArgumentNullException))]
  135. #else
  136. [ExpectedException (typeof (NullReferenceException))]
  137. #endif
  138. public void Constructor3_NullType ()
  139. {
  140. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
  141. (Type) null, "mono");
  142. }
  143. [Test]
  144. public void Constructor4 ()
  145. {
  146. CodeTypeReference type = new CodeTypeReference ("mono");
  147. string name = "mono";
  148. CodeExpression expression = new CodeExpression ();
  149. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
  150. type, name, expression);
  151. Assert.IsNotNull (cvds.InitExpression, "#1");
  152. Assert.AreSame (expression, cvds.InitExpression, "#2");
  153. Assert.IsNotNull (cvds.Name, "#3");
  154. Assert.AreSame (name, cvds.Name, "#4");
  155. Assert.IsNotNull (cvds.Type, "#5");
  156. Assert.AreSame (type, cvds.Type, "#6");
  157. cvds = new CodeVariableDeclarationStatement ((CodeTypeReference) null,
  158. (string) null, (CodeExpression) null);
  159. Assert.IsNull (cvds.InitExpression, "#7");
  160. Assert.IsNotNull (cvds.Name, "#8");
  161. Assert.AreEqual (string.Empty, cvds.Name, "#9");
  162. Assert.IsNotNull (cvds.Type, "#10");
  163. Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#11");
  164. }
  165. [Test]
  166. public void Constructor5 ()
  167. {
  168. string baseType = "monotype";
  169. string name = "mono";
  170. CodeExpression expression = new CodeExpression ();
  171. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
  172. baseType, name, expression);
  173. Assert.IsNotNull (cvds.InitExpression, "#1");
  174. Assert.AreSame (expression, cvds.InitExpression, "#2");
  175. Assert.IsNotNull (cvds.Name, "#3");
  176. Assert.AreSame (name, cvds.Name, "#4");
  177. Assert.IsNotNull (cvds.Type, "#5");
  178. Assert.AreEqual (baseType, cvds.Type.BaseType, "#6");
  179. cvds = new CodeVariableDeclarationStatement ((string) null,
  180. (string) null, (CodeExpression) null);
  181. Assert.IsNull (cvds.InitExpression, "#7");
  182. Assert.IsNotNull (cvds.Name, "#8");
  183. Assert.AreEqual (string.Empty, cvds.Name, "#9");
  184. Assert.IsNotNull (cvds.Type, "#10");
  185. Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#11");
  186. }
  187. [Test]
  188. public void Constructor6 ()
  189. {
  190. Type baseType = typeof (int);
  191. string name = "mono";
  192. CodeExpression expression = new CodeExpression ();
  193. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
  194. baseType, name, expression);
  195. Assert.IsNotNull (cvds.InitExpression, "#1");
  196. Assert.AreSame (expression, cvds.InitExpression, "#2");
  197. Assert.IsNotNull (cvds.Name, "#3");
  198. Assert.AreSame (name, cvds.Name, "#4");
  199. Assert.IsNotNull (cvds.Type, "#5");
  200. Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#6");
  201. cvds = new CodeVariableDeclarationStatement (baseType,
  202. (string) null, (CodeExpression) null);
  203. Assert.IsNull (cvds.InitExpression, "#7");
  204. Assert.IsNotNull (cvds.Name, "#8");
  205. Assert.AreEqual (string.Empty, cvds.Name, "#9");
  206. Assert.IsNotNull (cvds.Type, "#10");
  207. Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#11");
  208. }
  209. [Test]
  210. #if NET_2_0
  211. [ExpectedException (typeof (ArgumentNullException))]
  212. #else
  213. [ExpectedException (typeof (NullReferenceException))]
  214. #endif
  215. public void Constructor6_NullType ()
  216. {
  217. CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
  218. (Type) null, "mono", new CodeExpression ());
  219. }
  220. }
  221. }