Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeVariableDeclarationStatementTest.cs
1 //
2 // CodeVariableDeclarationStatementTest.cs
3 //      - Unit tests for System.CodeDom.CodeVariableDeclarationStatement
4 //
5 // Author:
6 //      Gert Driesen  <drieseng@users.sourceforge.net>
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
30 using NUnit.Framework;
31
32 using System;
33 using System.CodeDom;
34
35 namespace MonoTests.System.CodeDom
36 {
37         [TestFixture]
38         public class CodeVariableDeclarationStatementTest
39         {
40                 [Test]
41                 public void Constructor0 ()
42                 {
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");
49
50                         string name = "mono";
51                         cvds.Name = name;
52                         Assert.AreSame (name, cvds.Name, "#6");
53
54                         cvds.Name = null;
55                         Assert.IsNotNull (cvds.Name, "#7");
56                         Assert.AreEqual (string.Empty, cvds.Name, "#8");
57
58                         CodeExpression expression = new CodeExpression ();
59                         cvds.InitExpression = expression;
60                         Assert.AreSame (expression, cvds.InitExpression, "#9");
61
62                         CodeTypeReference type = new CodeTypeReference ("mono");
63                         cvds.Type = type;
64                         Assert.AreSame (type, cvds.Type, "#10");
65
66                         cvds.Type = null;
67                         Assert.IsNotNull (cvds.Type, "#11");
68                         Assert.AreEqual (typeof (void).FullName, cvds.Type.BaseType, "#12");
69
70                         Assert.IsNotNull (cvds.StartDirectives, "#13");
71                         Assert.AreEqual (0, cvds.StartDirectives.Count, "#14");
72
73                         Assert.IsNotNull (cvds.EndDirectives, "#15");
74                         Assert.AreEqual (0, cvds.EndDirectives.Count, "#16");
75
76                         Assert.IsNull (cvds.LinePragma, "#17");
77
78                         CodeLinePragma clp = new CodeLinePragma ("mono", 10);
79                         cvds.LinePragma = clp;
80                         Assert.IsNotNull (cvds.LinePragma, "#18");
81                         Assert.AreSame (clp, cvds.LinePragma, "#19");
82
83                         cvds.LinePragma = null;
84                         Assert.IsNull (cvds.LinePragma, "#20");
85                 }
86
87                 [Test]
88                 public void Constructor1 ()
89                 {
90                         CodeTypeReference type = new CodeTypeReference ("mono");
91                         string name = "mono";
92
93                         CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
94                                 type, name);
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");
100
101                         cvds = new CodeVariableDeclarationStatement ((CodeTypeReference) null,
102                                 (string) 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");
107                 }
108
109                 [Test]
110                 public void Constructor2 ()
111                 {
112                         string baseType = "monotype";
113                         string name = "mono";
114
115                         CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
116                                 baseType, name);
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");
122
123                         cvds = new CodeVariableDeclarationStatement ((string) null, 
124                                 (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");
129                 }
130
131                 [Test]
132                 public void Constructor3 ()
133                 {
134                         Type baseType = typeof (int);
135                         string name = "mono";
136
137                         CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
138                                 baseType, name);
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");
144
145                         cvds = new CodeVariableDeclarationStatement (baseType, 
146                                 (string) null);
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");
151                 }
152
153                 [Test]
154                 [ExpectedException (typeof (ArgumentNullException))]
155                 public void Constructor3_NullType ()
156                 {
157                         CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
158                                 (Type) null, "mono");
159                 }
160
161                 [Test]
162                 public void Constructor4 ()
163                 {
164                         CodeTypeReference type = new CodeTypeReference ("mono");
165                         string name = "mono";
166                         CodeExpression expression = new CodeExpression ();
167
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");
176
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");
184                 }
185
186                 [Test]
187                 public void Constructor5 ()
188                 {
189                         string baseType = "monotype";
190                         string name = "mono";
191                         CodeExpression expression = new CodeExpression ();
192
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");
201
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");
209                 }
210
211                 [Test]
212                 public void Constructor6 ()
213                 {
214                         Type baseType = typeof (int);
215                         string name = "mono";
216                         CodeExpression expression = new CodeExpression ();
217
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");
226
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");
234                 }
235
236                 [Test]
237                 [ExpectedException (typeof (ArgumentNullException))]
238                 public void Constructor6_NullType ()
239                 {
240                         CodeVariableDeclarationStatement cvds = new CodeVariableDeclarationStatement (
241                                 (Type) null, "mono", new CodeExpression ());
242                 }
243         }
244 }