2 // CodeVariableDeclarationStatementTest.cs
3 // - Unit tests for System.CodeDom.CodeVariableDeclarationStatement
6 // Gert Driesen <drieseng@users.sourceforge.net>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using NUnit.Framework;
35 namespace MonoTests.System.CodeDom
38 public class CodeVariableDeclarationStatementTest
41 public void Constructor0 ()
43 CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement ();
44 Assert.IsNull (cvds.InitExpression, "#1");
45 Assert.IsNotNull (cvds.Name, "#2");
46 Assert.AreEqual (string.Empty, cvds.Name, "#3");
47 Assert.IsNotNull (cvds.Type, "#4");
48 Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#5");
52 Assert.AreSame (name, cvds.Name, "#6");
55 Assert.IsNotNull (cvds.Name, "#7");
56 Assert.AreEqual (string.Empty, cvds.Name, "#8");
58 CodeExpression expression = new CodeExpression ();
59 cvds.InitExpression = expression;
60 Assert.AreSame (expression, cvds.InitExpression, "#9");
62 CodeTypeReference type = new CodeTypeReference ("mono");
64 Assert.AreSame (type, cvds.Type, "#10");
67 Assert.IsNotNull (cvds.Type, "#11");
68 Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#12");
70 Assert.IsNotNull (cvds.StartDirectives, "#13");
71 Assert.AreEqual (0, cvds.StartDirectives.Count, "#14");
73 Assert.IsNotNull (cvds.EndDirectives, "#15");
74 Assert.AreEqual (0, cvds.EndDirectives.Count, "#16");
76 Assert.IsNull (cvds.LinePragma, "#17");
78 CodeLinePragma clp = new CodeLinePragma ("mono", 10);
79 cvds.LinePragma = clp;
80 Assert.IsNotNull (cvds.LinePragma, "#18");
81 Assert.AreSame (clp, cvds.LinePragma, "#19");
83 cvds.LinePragma = null;
84 Assert.IsNull (cvds.LinePragma, "#20");
88 public void Constructor1 ()
90 CodeTypeReference type = new CodeTypeReference ("mono");
93 CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
95 Assert.IsNull (cvds.InitExpression, "#1");
96 Assert.IsNotNull (cvds.Name, "#2");
97 Assert.AreSame (name, cvds.Name, "#3");
98 Assert.IsNotNull (cvds.Type, "#4");
99 Assert.AreSame (type, cvds.Type, "#5");
101 cvds = new CodeVariableDeclarationStatement ((CodeTypeReference) null,
103 Assert.IsNotNull (cvds.Name, "#6");
104 Assert.AreEqual (string.Empty, cvds.Name, "#7");
105 Assert.IsNotNull (cvds.Type, "#8");
106 Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#9");
110 public void Constructor2 ()
112 string baseType = "monotype";
113 string name = "mono";
115 CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
117 Assert.IsNull (cvds.InitExpression, "#1");
118 Assert.IsNotNull (cvds.Name, "#2");
119 Assert.AreSame (name, cvds.Name, "#3");
120 Assert.IsNotNull (cvds.Type, "#4");
121 Assert.AreSame (baseType, cvds.Type.BaseType, "#5");
123 cvds = new CodeVariableDeclarationStatement ((string) null,
125 Assert.IsNotNull (cvds.Name, "#6");
126 Assert.AreEqual (string.Empty, cvds.Name, "#7");
127 Assert.IsNotNull (cvds.Type, "#8");
128 Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#9");
132 public void Constructor3 ()
134 Type baseType = typeof (int);
135 string name = "mono";
137 CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
139 Assert.IsNull (cvds.InitExpression, "#1");
140 Assert.IsNotNull (cvds.Name, "#2");
141 Assert.AreSame (name, cvds.Name, "#3");
142 Assert.IsNotNull (cvds.Type, "#4");
143 Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#5");
145 cvds = new CodeVariableDeclarationStatement (baseType,
147 Assert.IsNotNull (cvds.Name, "#6");
148 Assert.AreEqual (string.Empty, cvds.Name, "#7");
149 Assert.IsNotNull (cvds.Type, "#8");
150 Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#9");
154 [ExpectedException (typeof (ArgumentNullException))]
155 public void Constructor3_NullType ()
157 CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
158 (Type) null, "mono");
162 public void Constructor4 ()
164 CodeTypeReference type = new CodeTypeReference ("mono");
165 string name = "mono";
166 CodeExpression expression = new CodeExpression ();
168 CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
169 type, name, expression);
170 Assert.IsNotNull (cvds.InitExpression, "#1");
171 Assert.AreSame (expression, cvds.InitExpression, "#2");
172 Assert.IsNotNull (cvds.Name, "#3");
173 Assert.AreSame (name, cvds.Name, "#4");
174 Assert.IsNotNull (cvds.Type, "#5");
175 Assert.AreSame (type, cvds.Type, "#6");
177 cvds = new CodeVariableDeclarationStatement ((CodeTypeReference) null,
178 (string) null, (CodeExpression) null);
179 Assert.IsNull (cvds.InitExpression, "#7");
180 Assert.IsNotNull (cvds.Name, "#8");
181 Assert.AreEqual (string.Empty, cvds.Name, "#9");
182 Assert.IsNotNull (cvds.Type, "#10");
183 Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#11");
187 public void Constructor5 ()
189 string baseType = "monotype";
190 string name = "mono";
191 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, cvds.Type.BaseType, "#6");
202 cvds = new CodeVariableDeclarationStatement ((string) null,
203 (string) null, (CodeExpression) null);
204 Assert.IsNull (cvds.InitExpression, "#7");
205 Assert.IsNotNull (cvds.Name, "#8");
206 Assert.AreEqual (string.Empty, cvds.Name, "#9");
207 Assert.IsNotNull (cvds.Type, "#10");
208 Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#11");
212 public void Constructor6 ()
214 Type baseType = typeof (int);
215 string name = "mono";
216 CodeExpression expression = new CodeExpression ();
218 CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
219 baseType, name, expression);
220 Assert.IsNotNull (cvds.InitExpression, "#1");
221 Assert.AreSame (expression, cvds.InitExpression, "#2");
222 Assert.IsNotNull (cvds.Name, "#3");
223 Assert.AreSame (name, cvds.Name, "#4");
224 Assert.IsNotNull (cvds.Type, "#5");
225 Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#6");
227 cvds = new CodeVariableDeclarationStatement (baseType,
228 (string) null, (CodeExpression) null);
229 Assert.IsNull (cvds.InitExpression, "#7");
230 Assert.IsNotNull (cvds.Name, "#8");
231 Assert.AreEqual (string.Empty, cvds.Name, "#9");
232 Assert.IsNotNull (cvds.Type, "#10");
233 Assert.AreEqual (baseType.FullName, cvds.Type.BaseType, "#11");
237 [ExpectedException (typeof (ArgumentNullException))]
238 public void Constructor6_NullType ()
240 CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
241 (Type) null, "mono", new CodeExpression ());