2 // StackFrameCas.cs - CAS unit tests for System.Diagnostics.StackFrame
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.Diagnostics;
33 using System.Security;
34 using System.Security.Permissions;
35 using System.Threading;
37 namespace MonoCasTests.System.Diagnostics {
41 public class StackFrameCas {
46 if (!SecurityManager.SecurityEnabled)
47 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
50 // avoid replication of tests on all constructors (this is no
51 // problem because the stack is already set correctly). The
52 // goal is to call every property and methods to see if they
53 // have any* security requirements (*except for LinkDemand and
54 // InheritanceDemand).
55 private void Check (StackFrame sf, bool checkFile)
57 int cn = sf.GetFileColumnNumber ();
58 int ln = sf.GetFileLineNumber ();
59 int il = sf.GetILOffset ();
60 int no = sf.GetNativeOffset ();
62 Assert.IsNotNull (sf.GetMethod (), "GetMethod");
65 string fn = sf.GetFileName ();
70 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
71 public void StackFrame_DefaultConstructor ()
73 StackFrame sf = new StackFrame ();
77 #if !RUN_ONDOTNET || NET_4_0 // Disabled because .net 2 fails to load dll with "Failure decoding embedded permission set object" due to "/" path
79 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
80 [ExpectedException (typeof (SecurityException))]
81 public void StackFrame_TrueConstructor_Fail ()
85 // ask for file informations
86 sf = new StackFrame (true);
90 Assert.Fail ("Didn't ask for file information");
92 // now look at the file informations...
93 // note: only fails under 2.0
98 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
99 public void StackFrame_TrueConstructor_Pass ()
102 StackFrame sf = new StackFrame (true);
107 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
108 [ExpectedException (typeof (SecurityException))]
109 public void StackFrame_IntTrueConstructor_Fail ()
111 StackFrame sf = null;
113 // ask for file informations
114 sf = new StackFrame (0, true);
118 Assert.Fail ("Didn't ask for file information");
120 // now look at the file informations...
121 // note: only fails under 2.0
126 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
127 public void StackFrame_IntTrueConstructor_Pass ()
130 StackFrame sf = new StackFrame (0, true);
135 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
136 [ExpectedException (typeof (SecurityException))]
137 public void StackFrame_StringIntConstructor_Fail ()
139 StackFrame sf = null;
141 // ask for file informations
142 sf = new StackFrame ("mono.cs", 1);
146 Assert.Fail ("Didn't ask for file information");
148 // now look at the file informations...
149 // note: only fails under 2.0
154 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
155 public void StackFrame_StringIntConstructor_Pass ()
158 StackFrame sf = new StackFrame ("mono.cs", 1);
163 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
164 [ExpectedException (typeof (SecurityException))]
165 public void StackFrame_StringIntIntConstructor_Fail ()
167 StackFrame sf = null;
170 sf = new StackFrame ("mono.cs", 1, 1);
174 Assert.Fail ("Didn't ask for file information");
176 // now look at the file informations...
177 // note: only fails under 2.0
182 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
183 public void StackFrame_StringIntIntConstructor_Pass ()
186 StackFrame sf = new StackFrame ("mono.cs", 1, 1);
192 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
193 public void StackFrame_FalseConstructor ()
195 // DO NOT ask for file informations
196 StackFrame sf = new StackFrame (false);
201 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
202 public void StackFrame_IntConstructor ()
204 StackFrame sf = new StackFrame (1);
209 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
210 public void StackFrame_IntFalseConstructor ()
212 // DO NOT ask for file informations
213 StackFrame sf = new StackFrame (1, false);