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 ();
63 Assert
.IsNotNull (sf
.GetMethod (), "GetMethod");
66 string fn
= sf
.GetFileName ();
71 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
72 public void StackFrame_DefaultConstructor ()
74 StackFrame sf
= new StackFrame ();
80 [FileIOPermission (SecurityAction
.Deny
, PathDiscovery
= "C:\\")]
82 [FileIOPermission (SecurityAction
.Deny
, PathDiscovery
= "/")]
85 [ExpectedException (typeof (SecurityException
))]
87 public void StackFrame_TrueConstructor_Fail ()
91 // ask for file informations
92 sf
= new StackFrame (true);
96 Assert
.Fail ("Didn't ask for file information");
98 // now look at the file informations...
99 // note: only fails under 2.0
105 [FileIOPermission (SecurityAction
.PermitOnly
, PathDiscovery
= "C:\\")]
107 [FileIOPermission (SecurityAction
.PermitOnly
, PathDiscovery
= "/")]
109 public void StackFrame_TrueConstructor_Pass ()
112 StackFrame sf
= new StackFrame (true);
117 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
118 public void StackFrame_FalseConstructor ()
120 // DO NOT ask for file informations
121 StackFrame sf
= new StackFrame (false);
126 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
127 public void StackFrame_IntConstructor ()
129 StackFrame sf
= new StackFrame (1);
135 [FileIOPermission (SecurityAction
.Deny
, PathDiscovery
= "C:\\")]
137 [FileIOPermission (SecurityAction
.Deny
, PathDiscovery
= "/")]
140 [ExpectedException (typeof (SecurityException
))]
142 public void StackFrame_IntTrueConstructor_Fail ()
144 StackFrame sf
= null;
146 // ask for file informations
147 sf
= new StackFrame (0, true);
151 Assert
.Fail ("Didn't ask for file information");
153 // now look at the file informations...
154 // note: only fails under 2.0
160 [FileIOPermission (SecurityAction
.PermitOnly
, PathDiscovery
= "C:\\")]
162 [FileIOPermission (SecurityAction
.PermitOnly
, PathDiscovery
= "/")]
164 public void StackFrame_IntTrueConstructor_Pass ()
167 StackFrame sf
= new StackFrame (0, true);
172 [PermissionSet (SecurityAction
.Deny
, Unrestricted
= true)]
173 public void StackFrame_IntFalseConstructor ()
175 // DO NOT ask for file informations
176 StackFrame sf
= new StackFrame (1, false);
182 [FileIOPermission (SecurityAction
.Deny
, PathDiscovery
= "C:\\")]
184 [FileIOPermission (SecurityAction
.Deny
, PathDiscovery
= "/")]
187 [ExpectedException (typeof (SecurityException
))]
189 public void StackFrame_StringIntConstructor_Fail ()
191 StackFrame sf
= null;
193 // ask for file informations
194 sf
= new StackFrame ("mono.cs", 1);
198 Assert
.Fail ("Didn't ask for file information");
200 // now look at the file informations...
201 // note: only fails under 2.0
207 [FileIOPermission (SecurityAction
.PermitOnly
, PathDiscovery
= "C:\\")]
209 [FileIOPermission (SecurityAction
.PermitOnly
, PathDiscovery
= "/")]
211 public void StackFrame_StringIntConstructor_Pass ()
214 StackFrame sf
= new StackFrame ("mono.cs", 1);
220 [FileIOPermission (SecurityAction
.Deny
, PathDiscovery
= "C:\\")]
222 [FileIOPermission (SecurityAction
.Deny
, PathDiscovery
= "/")]
225 [ExpectedException (typeof (SecurityException
))]
227 public void StackFrame_StringIntIntConstructor_Fail ()
229 StackFrame sf
= null;
232 sf
= new StackFrame ("mono.cs", 1, 1);
236 Assert
.Fail ("Didn't ask for file information");
238 // now look at the file informations...
239 // note: only fails under 2.0
245 [FileIOPermission (SecurityAction
.PermitOnly
, PathDiscovery
= "C:\\")]
247 [FileIOPermission (SecurityAction
.PermitOnly
, PathDiscovery
= "/")]
249 public void StackFrame_StringIntIntConstructor_Pass ()
252 StackFrame sf
= new StackFrame ("mono.cs", 1, 1);