2 // ExceptionCas.cs - CAS unit tests for System.Exception
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit.Framework;
32 using System.Security;
33 using System.Security.Permissions;
35 namespace MonoCasTests.System {
39 public class ExceptionCas {
44 if (!SecurityManager.SecurityEnabled)
45 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
50 public void NoRestriction ()
52 Exception e = new Exception ("message", new Exception ("inner message"));
54 Assert.AreEqual ("message", e.Message, "Message");
55 Assert.IsNotNull (e.InnerException, "InnerException");
56 Assert.IsNotNull (e.ToString (), "ToString");
58 Assert.IsNotNull (e.Data, "Data");
60 Assert.IsNull (e.HelpLink, "HelpLink");
61 Assert.IsNull (e.Source, "Source");
62 Assert.IsNull (e.StackTrace, "StackTrace");
63 Assert.IsNull (e.TargetSite, "TargetSite");
67 public void Throw_NoRestriction ()
70 throw new Exception ("message", new Exception ("inner message"));
73 Assert.AreEqual ("message", e.Message, "Message");
74 Assert.IsNotNull (e.InnerException, "InnerException");
75 Assert.IsNotNull (e.ToString (), "ToString");
77 Assert.IsNotNull (e.Data, "Data");
79 Assert.IsNull (e.HelpLink, "HelpLink");
80 Assert.IsNotNull (e.Source, "Source");
81 Assert.IsNotNull (e.StackTrace, "StackTrace");
82 Assert.IsNotNull (e.TargetSite, "TargetSite");
87 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
88 public void FullRestriction ()
90 Exception e = new Exception ("message", new Exception ("inner message"));
92 Assert.AreEqual ("message", e.Message, "Message");
93 Assert.IsNotNull (e.InnerException, "InnerException");
94 Assert.IsNotNull (e.ToString (), "ToString");
95 Assert.IsNull (e.HelpLink, "HelpLink");
96 Assert.IsNull (e.Source, "Source");
97 Assert.IsNull (e.StackTrace, "StackTrace");
99 Assert.IsNotNull (e.Data, "Data");
101 Assert.IsNull (e.TargetSite, "TargetSite");
107 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
108 [ExpectedException (typeof (SecurityException))]
109 public void FullRestriction_TargetSite ()
111 Exception e = new Exception ("message", new Exception ("inner message"));
112 Assert.IsNull (e.TargetSite, "TargetSite");
117 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
118 public void Throw_FullRestriction_Pass ()
121 throw new Exception ("message", new Exception ("inner message"));
123 catch (Exception e) {
124 Assert.AreEqual ("message", e.Message, "Message");
125 Assert.IsNotNull (e.InnerException, "InnerException");
126 Assert.IsNull (e.HelpLink, "HelpLink");
127 Assert.IsNotNull (e.Source, "Source");
129 Assert.IsNotNull (e.Data, "Data");
131 Assert.IsNotNull (e.TargetSite, "TargetSite");
138 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "C:\\")]
140 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
143 [ExpectedException (typeof (Exception))]
145 public void Throw_FullRestriction_Fail_StackTrace ()
148 throw new Exception ("message");
150 catch (Exception e) {
151 // throws only under 2.x
152 string s = e.StackTrace;
158 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "C:\\")]
160 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
163 [ExpectedException (typeof (Exception))]
165 public void Throw_FullRestriction_Fail_ToString ()
168 throw new Exception ("message");
170 catch (Exception e) {
171 // throws only under 2.x
172 string s = e.ToString ();