2 // MonoTests.System.Diagnostics.StackTraceTest.cs
5 // Alexander Klyubin (klyubin@aqris.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Diagnostics
;
33 using System
.Reflection
;
34 using System
.Threading
;
35 using NUnit
.Framework
;
37 namespace MonoTests
.System
.Diagnostics
{
40 public class StackTraceTest
{
42 private StackTrace trace
;
43 private StackFrame frame
;
48 frame
= new StackFrame ("dir/someFile", 13, 45);
49 trace
= new StackTrace (frame
);
53 public void TearDown ()
59 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
60 public void StackTrace_Int_Negative ()
66 [ExpectedException (typeof (ArgumentNullException
))]
67 public void StackTrace_Exception_Null ()
74 [ExpectedException (typeof (ArgumentNullException
))]
75 public void StackTrace_ExceptionBool_Null ()
78 new StackTrace (e
, true);
82 [ExpectedException (typeof (ArgumentNullException
))]
83 public void StackTrace_ExceptionInt_Null ()
86 new StackTrace (e
, 1);
90 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
91 public void StackTrace_ExceptionInt_Negative ()
93 new StackTrace (new Exception (), -1);
97 [ExpectedException (typeof (ArgumentNullException
))]
98 public void StackTrace_ExceptionIntBool_Null ()
101 new StackTrace (e
, 1, true);
105 [ExpectedException (typeof (ArgumentOutOfRangeException
))]
106 public void StackTrace_ExceptionIntBool_Negative ()
108 new StackTrace (new Exception (), -1, true);
112 public void StackTrace_StackFrame_Null ()
114 StackFrame sf
= null;
115 StackTrace st
= new StackTrace (sf
);
117 Assert
.AreEqual (1, st
.FrameCount
, "FrameCount");
118 Assert
.IsNull (st
.GetFrame (0), "Empty Frame");
122 [Ignore ("Not supported in Mono")]
123 public void StackTrace_Thread_Null ()
126 StackTrace st
= new StackTrace (t
, true);
130 static void EmptyThread ()
137 // on MS .NET 1.x, ThreadState after Start() is Unstarted
138 [Category ("NotDotNet")]
140 [ExpectedException (typeof (ThreadStateException
))]
141 [Ignore ("Not supported in Mono")]
142 public void StackTrace_Thread_NotSuspended ()
144 Thread t
= new Thread (new ThreadStart (EmptyThread
));
146 new StackTrace (t
, true);
150 [Ignore ("Not supported in Mono")]
151 public void StackTrace_Thread_Suspended ()
153 Thread t
= new Thread (new ThreadStart (EmptyThread
));
156 new StackTrace (t
, true);
160 public void FrameCount ()
162 Assert
.AreEqual (1, trace
.FrameCount
, "Frame count");
166 public void GetFrame_OutOfRange ()
168 Assert
.IsNull (trace
.GetFrame (-1), "-1");
169 Assert
.IsNull (trace
.GetFrame (-129), "-129");
170 Assert
.IsNull (trace
.GetFrame (1), "1");
171 Assert
.IsNull (trace
.GetFrame (145), "145");
173 Assert
.IsNull (trace
.GetFrame (Int32
.MinValue
), "MinValue");
174 Assert
.IsNull (trace
.GetFrame (Int32
.MaxValue
), "MaxValue");
178 public void GetFrame ()
180 Assert
.AreEqual (frame
, trace
.GetFrame (0), "0");
184 public void GetFrames ()
186 StackTrace st
= new StackTrace ();
187 StackFrame
[] sf
= st
.GetFrames ();
188 Assert
.AreEqual (st
.FrameCount
, sf
.Length
, "Count");
189 for (int i
=0; i
< sf
.Length
; i
++) {
190 Assert
.AreEqual (sf
[i
], st
.GetFrame (i
), i
.ToString ());
195 public void UnthrownException ()
197 Assert
.AreEqual (0, new StackTrace (new Exception ()).FrameCount
, "Unthrown exception");