2 // CodeCatchClauseTest.cs
3 // - Unit tests for System.CodeDom.CodeCatchClause
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 CodeCatchClauseTest
41 public void Constructor0 ()
43 CodeCatchClause ccc = new CodeCatchClause ();
45 Assert.IsNotNull (ccc.CatchExceptionType, "#1");
46 Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#2");
48 Assert.IsNotNull (ccc.LocalName, "#3");
49 Assert.AreEqual (string.Empty, ccc.LocalName, "#4");
51 Assert.IsNotNull (ccc.Statements, "#5");
52 Assert.AreEqual (0, ccc.Statements.Count, "#6");
55 Assert.IsNotNull (ccc.LocalName, "#7");
56 Assert.AreEqual (string.Empty, ccc.LocalName, "#8");
58 string localName = "mono";
59 ccc.LocalName = localName;
60 Assert.AreSame (localName, ccc.LocalName, "#9");
62 ccc.CatchExceptionType = null;
63 Assert.IsNotNull (ccc.CatchExceptionType, "#10");
64 Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
66 CodeTypeReference cet = new CodeTypeReference("SomeException");
67 ccc.CatchExceptionType = cet;
68 Assert.AreSame (cet, ccc.CatchExceptionType, "#12");
72 public void Constructor1 () {
73 string localName = "mono";
75 CodeCatchClause ccc = new CodeCatchClause (localName);
77 Assert.IsNotNull (ccc.CatchExceptionType, "#1");
78 Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#2");
80 Assert.IsNotNull (ccc.LocalName, "#3");
81 Assert.AreEqual (localName, ccc.LocalName, "#4");
82 Assert.AreSame (localName, ccc.LocalName, "#5");
84 Assert.IsNotNull (ccc.Statements, "#6");
85 Assert.AreEqual (0, ccc.Statements.Count, "#7");
88 Assert.IsNotNull (ccc.LocalName, "#8");
89 Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
91 ccc = new CodeCatchClause ((string) null);
92 Assert.IsNotNull (ccc.LocalName, "#10");
93 Assert.AreEqual (string.Empty, ccc.LocalName, "#22");
97 public void Constructor2 () {
98 string localName = "mono";
99 CodeTypeReference cet = new CodeTypeReference("SomeException");
101 CodeCatchClause ccc = new CodeCatchClause (localName, cet);
103 Assert.IsNotNull (ccc.CatchExceptionType, "#1");
104 Assert.AreSame (cet, ccc.CatchExceptionType, "#2");
106 Assert.IsNotNull (ccc.LocalName, "#3");
107 Assert.AreEqual (localName, ccc.LocalName, "#4");
108 Assert.AreSame (localName, ccc.LocalName, "#5");
110 Assert.IsNotNull (ccc.Statements, "#6");
111 Assert.AreEqual (0, ccc.Statements.Count, "#7");
113 ccc.LocalName = null;
114 Assert.IsNotNull (ccc.LocalName, "#8");
115 Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
117 ccc.CatchExceptionType = null;
118 Assert.IsNotNull (ccc.CatchExceptionType, "#10");
119 Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
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");
129 public void Constructor3 () {
130 string localName = "mono";
131 CodeTypeReference cet = new CodeTypeReference("SomeException");
132 CodeStatement cs1 = new CodeStatement ();
133 CodeStatement cs2 = new CodeStatement ();
135 CodeCatchClause ccc = new CodeCatchClause (localName, cet, cs1, cs2);
137 Assert.IsNotNull (ccc.CatchExceptionType, "#1");
138 Assert.AreSame (cet, ccc.CatchExceptionType, "#2");
140 Assert.IsNotNull (ccc.LocalName, "#3");
141 Assert.AreEqual (localName, ccc.LocalName, "#4");
142 Assert.AreSame (localName, ccc.LocalName, "#5");
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");
149 ccc.LocalName = null;
150 Assert.IsNotNull (ccc.LocalName, "#8");
151 Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
153 ccc.CatchExceptionType = null;
154 Assert.IsNotNull (ccc.CatchExceptionType, "#10");
155 Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
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");