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");
48 // Partial Trust Tests - i.e. call "normal" unit with reduced privileges
51 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
52 public void PartialTrust_DenyUnrestricted_Success ()
54 MonoTests.System.ExceptionTest et = new MonoTests.System.ExceptionTest ();
55 // call most (all but arguments checking) unit tests from ExceptionTest
56 et.TestThrowOnBlockBoundaries ();
57 et.Source_InnerException ();
63 public void NoRestriction ()
65 Exception e = new Exception ("message", new Exception ("inner message"));
67 Assert.AreEqual ("message", e.Message, "Message");
68 Assert.IsNotNull (e.InnerException, "InnerException");
69 Assert.IsNotNull (e.ToString (), "ToString");
70 Assert.IsNotNull (e.Data, "Data");
71 Assert.IsNull (e.HelpLink, "HelpLink");
72 Assert.IsNull (e.Source, "Source");
73 Assert.IsNull (e.StackTrace, "StackTrace");
74 Assert.IsNull (e.TargetSite, "TargetSite");
78 public void Throw_NoRestriction ()
81 throw new Exception ("message", new Exception ("inner message"));
84 Assert.AreEqual ("message", e.Message, "Message");
85 Assert.IsNotNull (e.InnerException, "InnerException");
86 Assert.IsNotNull (e.ToString (), "ToString");
87 Assert.IsNotNull (e.Data, "Data");
88 Assert.IsNull (e.HelpLink, "HelpLink");
89 Assert.IsNotNull (e.Source, "Source");
90 Assert.IsNotNull (e.StackTrace, "StackTrace");
91 Assert.IsNotNull (e.TargetSite, "TargetSite");
96 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
97 public void FullRestriction ()
99 Exception e = new Exception ("message", new Exception ("inner message"));
101 Assert.AreEqual ("message", e.Message, "Message");
102 Assert.IsNotNull (e.InnerException, "InnerException");
103 Assert.IsNotNull (e.ToString (), "ToString");
104 Assert.IsNull (e.HelpLink, "HelpLink");
105 Assert.IsNull (e.Source, "Source");
106 Assert.IsNull (e.StackTrace, "StackTrace");
107 Assert.IsNotNull (e.Data, "Data");
109 Assert.IsNull (e.TargetSite, "TargetSite");
113 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
114 public void Throw_FullRestriction_Pass ()
117 throw new Exception ("message", new Exception ("inner message"));
119 catch (Exception e) {
120 Assert.AreEqual ("message", e.Message, "Message");
121 Assert.IsNotNull (e.InnerException, "InnerException");
122 Assert.IsNull (e.HelpLink, "HelpLink");
123 Assert.IsNotNull (e.Source, "Source");
124 Assert.IsNotNull (e.Data, "Data");
126 Assert.IsNotNull (e.TargetSite, "TargetSite");
132 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
133 [ExpectedException (typeof (Exception))]
134 public void Throw_FullRestriction_Fail_StackTrace ()
137 throw new Exception ("message");
139 catch (Exception e) {
140 // throws only under 2.x
141 string s = e.StackTrace;
146 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
147 [ExpectedException (typeof (Exception))]
148 public void Throw_FullRestriction_Fail_ToString ()
151 throw new Exception ("message");
153 catch (Exception e) {
154 // throws only under 2.x
155 string s = e.ToString ();