2010-04-15 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / Test / System.Diagnostics / StackFrameCas.cs
blob594f221246262068458194477bcb83a88c132d39
1 //
2 // StackFrameCas.cs - CAS unit tests for System.Diagnostics.StackFrame
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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;
31 using System;
32 using System.Diagnostics;
33 using System.Security;
34 using System.Security.Permissions;
35 using System.Threading;
37 namespace MonoCasTests.System.Diagnostics {
39 [TestFixture]
40 [Category ("CAS")]
41 public class StackFrameCas {
43 [SetUp]
44 public void SetUp ()
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 ();
61 #if NET_2_0
62 // this throws in 1.x
63 Assert.IsNotNull (sf.GetMethod (), "GetMethod");
64 #endif
65 if (checkFile) {
66 string fn = sf.GetFileName ();
70 [Test]
71 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
72 public void StackFrame_DefaultConstructor ()
74 StackFrame sf = new StackFrame ();
75 Check (sf, true);
78 [Test]
79 #if WINDOWS
80 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "C:\\")]
81 #else
82 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
83 #endif
84 #if NET_2_0
85 [ExpectedException (typeof (SecurityException))]
86 #endif
87 public void StackFrame_TrueConstructor_Fail ()
89 StackFrame sf = null;
90 try {
91 // ask for file informations
92 sf = new StackFrame (true);
93 Check (sf, false);
95 catch {
96 Assert.Fail ("Didn't ask for file information");
98 // now look at the file informations...
99 // note: only fails under 2.0
100 Check (sf, true);
103 [Test]
104 #if WINDOWS
105 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "C:\\")]
106 #else
107 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
108 #endif
109 public void StackFrame_TrueConstructor_Pass ()
111 // ask file info
112 StackFrame sf = new StackFrame (true);
113 Check (sf, true);
116 [Test]
117 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
118 public void StackFrame_FalseConstructor ()
120 // DO NOT ask for file informations
121 StackFrame sf = new StackFrame (false);
122 Check (sf, true);
125 [Test]
126 [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
127 public void StackFrame_IntConstructor ()
129 StackFrame sf = new StackFrame (1);
130 Check (sf, true);
133 [Test]
134 #if WINDOWS
135 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "C:\\")]
136 #else
137 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
138 #endif
139 #if NET_2_0
140 [ExpectedException (typeof (SecurityException))]
141 #endif
142 public void StackFrame_IntTrueConstructor_Fail ()
144 StackFrame sf = null;
145 try {
146 // ask for file informations
147 sf = new StackFrame (0, true);
148 Check (sf, false);
150 catch {
151 Assert.Fail ("Didn't ask for file information");
153 // now look at the file informations...
154 // note: only fails under 2.0
155 Check (sf, true);
158 [Test]
159 #if WINDOWS
160 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "C:\\")]
161 #else
162 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
163 #endif
164 public void StackFrame_IntTrueConstructor_Pass ()
166 // ask file info
167 StackFrame sf = new StackFrame (0, true);
168 Check (sf, true);
171 [Test]
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);
177 Check (sf, true);
180 [Test]
181 #if WINDOWS
182 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "C:\\")]
183 #else
184 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
185 #endif
186 #if NET_2_0
187 [ExpectedException (typeof (SecurityException))]
188 #endif
189 public void StackFrame_StringIntConstructor_Fail ()
191 StackFrame sf = null;
192 try {
193 // ask for file informations
194 sf = new StackFrame ("mono.cs", 1);
195 Check (sf, false);
197 catch {
198 Assert.Fail ("Didn't ask for file information");
200 // now look at the file informations...
201 // note: only fails under 2.0
202 Check (sf, true);
205 [Test]
206 #if WINDOWS
207 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "C:\\")]
208 #else
209 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
210 #endif
211 public void StackFrame_StringIntConstructor_Pass ()
213 // supply file info
214 StackFrame sf = new StackFrame ("mono.cs", 1);
215 Check (sf, true);
218 [Test]
219 #if WINDOWS
220 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "C:\\")]
221 #else
222 [FileIOPermission (SecurityAction.Deny, PathDiscovery = "/")]
223 #endif
224 #if NET_2_0
225 [ExpectedException (typeof (SecurityException))]
226 #endif
227 public void StackFrame_StringIntIntConstructor_Fail ()
229 StackFrame sf = null;
230 try {
231 // supply file info
232 sf = new StackFrame ("mono.cs", 1, 1);
233 Check (sf, false);
235 catch {
236 Assert.Fail ("Didn't ask for file information");
238 // now look at the file informations...
239 // note: only fails under 2.0
240 Check (sf, true);
243 [Test]
244 #if WINDOWS
245 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "C:\\")]
246 #else
247 [FileIOPermission (SecurityAction.PermitOnly, PathDiscovery = "/")]
248 #endif
249 public void StackFrame_StringIntIntConstructor_Pass ()
251 // supply file info
252 StackFrame sf = new StackFrame ("mono.cs", 1, 1);
253 Check (sf, true);