Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeCatchClauseTest.cs
1 //
2 // CodeCatchClauseTest.cs
3 //      - Unit tests for System.CodeDom.CodeCatchClause
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 CodeCatchClauseTest
39         {
40                 [Test]
41                 public void Constructor0 ()
42                 {
43                         CodeCatchClause ccc = new CodeCatchClause ();
44
45                         Assert.IsNotNull (ccc.CatchExceptionType, "#1");
46                         Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#2");
47
48                         Assert.IsNotNull (ccc.LocalName, "#3");
49                         Assert.AreEqual (string.Empty, ccc.LocalName, "#4");
50
51                         Assert.IsNotNull (ccc.Statements, "#5");
52                         Assert.AreEqual (0, ccc.Statements.Count, "#6");
53
54                         ccc.LocalName = null;
55                         Assert.IsNotNull (ccc.LocalName, "#7");
56                         Assert.AreEqual (string.Empty, ccc.LocalName, "#8");
57
58                         string localName = "mono";
59                         ccc.LocalName = localName;
60                         Assert.AreSame (localName, ccc.LocalName, "#9");
61
62                         ccc.CatchExceptionType = null;
63                         Assert.IsNotNull (ccc.CatchExceptionType, "#10");
64                         Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
65
66                         CodeTypeReference cet = new CodeTypeReference("SomeException");
67                         ccc.CatchExceptionType = cet;
68                         Assert.AreSame (cet, ccc.CatchExceptionType, "#12");
69                 }
70
71                 [Test]
72                 public void Constructor1 () {
73                         string localName = "mono";
74
75                         CodeCatchClause ccc = new CodeCatchClause (localName);
76
77                         Assert.IsNotNull (ccc.CatchExceptionType, "#1");
78                         Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#2");
79
80                         Assert.IsNotNull (ccc.LocalName, "#3");
81                         Assert.AreEqual (localName, ccc.LocalName, "#4");
82                         Assert.AreSame (localName, ccc.LocalName, "#5");
83
84                         Assert.IsNotNull (ccc.Statements, "#6");
85                         Assert.AreEqual (0, ccc.Statements.Count, "#7");
86
87                         ccc.LocalName = null;
88                         Assert.IsNotNull (ccc.LocalName, "#8");
89                         Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
90
91                         ccc = new CodeCatchClause ((string) null);
92                         Assert.IsNotNull (ccc.LocalName, "#10");
93                         Assert.AreEqual (string.Empty, ccc.LocalName, "#22");
94                 }
95
96                 [Test]
97                 public void Constructor2 () {
98                         string localName = "mono";
99                         CodeTypeReference cet = new CodeTypeReference("SomeException");
100
101                         CodeCatchClause ccc = new CodeCatchClause (localName, cet);
102
103                         Assert.IsNotNull (ccc.CatchExceptionType, "#1");
104                         Assert.AreSame (cet, ccc.CatchExceptionType, "#2");
105
106                         Assert.IsNotNull (ccc.LocalName, "#3");
107                         Assert.AreEqual (localName, ccc.LocalName, "#4");
108                         Assert.AreSame (localName, ccc.LocalName, "#5");
109
110                         Assert.IsNotNull (ccc.Statements, "#6");
111                         Assert.AreEqual (0, ccc.Statements.Count, "#7");
112
113                         ccc.LocalName = null;
114                         Assert.IsNotNull (ccc.LocalName, "#8");
115                         Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
116
117                         ccc.CatchExceptionType = null;
118                         Assert.IsNotNull (ccc.CatchExceptionType, "#10");
119                         Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
120
121                         ccc = new CodeCatchClause ((string) null, (CodeTypeReference) null);
122                         Assert.IsNotNull (ccc.LocalName, "#12");
123                         Assert.AreEqual (string.Empty, ccc.LocalName, "#13");
124                         Assert.IsNotNull (ccc.CatchExceptionType, "#14");
125                         Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#15");
126                 }
127
128                 [Test]
129                 public void Constructor3 () {
130                         string localName = "mono";
131                         CodeTypeReference cet = new CodeTypeReference("SomeException");
132                         CodeStatement cs1 = new CodeStatement ();
133                         CodeStatement cs2 = new CodeStatement ();
134
135                         CodeCatchClause ccc = new CodeCatchClause (localName, cet, cs1, cs2);
136
137                         Assert.IsNotNull (ccc.CatchExceptionType, "#1");
138                         Assert.AreSame (cet, ccc.CatchExceptionType, "#2");
139
140                         Assert.IsNotNull (ccc.LocalName, "#3");
141                         Assert.AreEqual (localName, ccc.LocalName, "#4");
142                         Assert.AreSame (localName, ccc.LocalName, "#5");
143
144                         Assert.IsNotNull (ccc.Statements, "#6");
145                         Assert.AreEqual (2, ccc.Statements.Count, "#7");
146                         Assert.AreSame (cs1, ccc.Statements[0], "#8");
147                         Assert.AreSame (cs2, ccc.Statements[1], "#9");
148
149                         ccc.LocalName = null;
150                         Assert.IsNotNull (ccc.LocalName, "#8");
151                         Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
152
153                         ccc.CatchExceptionType = null;
154                         Assert.IsNotNull (ccc.CatchExceptionType, "#10");
155                         Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
156
157                         ccc = new CodeCatchClause ((string) null, (CodeTypeReference) null, cs1);
158                         Assert.IsNotNull (ccc.LocalName, "#12");
159                         Assert.AreEqual (string.Empty, ccc.LocalName, "#13");
160                         Assert.IsNotNull (ccc.CatchExceptionType, "#14");
161                         Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#15");
162                         Assert.AreEqual (1, ccc.Statements.Count, "#16");
163                         Assert.AreSame (cs1, ccc.Statements[0], "#17");
164                 }
165         }
166 }