2 // Ximian.Mono.Tests.StackFrameTest.cs
5 // Alexander Klyubin (klyubin@aqris.com)
11 using System.Diagnostics;
12 using System.Reflection;
13 using NUnit.Framework;
15 namespace MonoTests.System.Diagnostics {
16 public class StackFrameTest {
17 private StackFrameTest() {}
18 public static ITest Suite
22 TestSuite suite = new TestSuite();
23 suite.AddTest(StackFrameTest1.Suite);
24 suite.AddTest(StackFrameTest2.Suite);
25 suite.AddTest(StackFrameTest3.Suite);
31 /// Tests the case where StackFrame is created for specified file name and
32 /// location inside it.
34 private class StackFrameTest1 : TestCase {
35 public StackFrameTest1(string name) : base(name) {}
37 private StackFrame frame1;
38 private StackFrame frame2;
40 internal static ITest Suite
44 return new TestSuite(typeof(StackFrameTest1));
48 protected override void SetUp() {
49 frame1 = new StackFrame("dir/someFile", 13, 45);
50 frame2 = new StackFrame("SomeFile2.cs", 24);
53 protected override void TearDown() {
61 /// Tests whether getting file name works.
63 public void TestGetFileName() {
64 AssertEquals("File name (1)",
66 frame1.GetFileName());
68 AssertEquals("File name (2)",
70 frame2.GetFileName());
74 /// Tests whether getting file line number works.
76 public void TestGetFileLineNumber() {
77 AssertEquals("Line number (1)",
79 frame1.GetFileLineNumber());
81 AssertEquals("Line number (2)",
83 frame2.GetFileLineNumber());
87 /// Tests whether getting file column number works.
89 public void TestGetFileColumnNumber() {
90 AssertEquals("Column number (1)",
92 frame1.GetFileColumnNumber());
94 AssertEquals("Column number (2)",
96 frame2.GetFileColumnNumber());
101 /// Tests whether getting method associated with frame works.
103 public void TestGetMethod() {
104 Assert("Method not null (1)", (frame1.GetMethod() != null));
106 AssertEquals("Class declaring the method (1)",
108 frame1.GetMethod().DeclaringType);
109 AssertEquals("Method name (1)",
111 frame1.GetMethod().Name);
113 Assert("Method not null (2)", (frame2.GetMethod() != null));
115 AssertEquals("Class declaring the method (2)",
117 frame2.GetMethod().DeclaringType);
118 AssertEquals("Method name (2)",
120 frame2.GetMethod().Name);
125 /// Tests the case where StackFrame is created for current method.
128 /// FIXME: Must be compiled with /debug switch. Otherwise some file
129 /// information will be incorrect for the following test cases.
130 /// What's the best way to do both types of tests with and without
131 /// debug information?
133 private class StackFrameTest2 : TestCase {
134 public StackFrameTest2(string name) : base(name) {}
136 private StackFrame frame1;
137 private StackFrame frame2;
138 private StackFrame frame3;
140 internal static ITest Suite
144 return new TestSuite(typeof(StackFrameTest2));
148 protected override void SetUp() {
149 frame1 = new StackFrame();
150 frame2 = new StackFrame(true);
151 frame3 = new StackFrame(0);
154 protected override void TearDown() {
163 /// Tests whether getting file name works.
165 public void TestGetFileName() {
166 AssertNull("File name (1)",
167 frame1.GetFileName());
169 Assert("File name (2) " + frame2.GetFileName()
170 + " ends with StackFrameTest.cs",
171 frame2.GetFileName().EndsWith("StackFrameTest.cs"));
175 /// Tests whether getting file line number works.
177 public void TestGetFileLineNumber() {
178 AssertEquals("Line number (1)",
180 frame1.GetFileLineNumber());
182 AssertEquals("Line number (2)",
184 frame2.GetFileLineNumber());
186 AssertEquals("Line number (3)",
188 frame3.GetFileLineNumber());
192 /// Tests whether getting file column number works.
194 public void TestGetFileColumnNumber() {
195 AssertEquals("Column number (1)",
197 frame1.GetFileColumnNumber());
199 AssertEquals("Column number (2)",
201 frame2.GetFileColumnNumber());
203 AssertEquals("Column number (3)",
205 frame3.GetFileColumnNumber());
210 /// Tests whether getting method associated with frame works.
212 public void TestGetMethod() {
213 Assert("Method not null (1)",
214 (frame1.GetMethod() != null));
216 AssertEquals("Class declaring the method (1)",
218 frame1.GetMethod().DeclaringType);
219 AssertEquals("Method name (1)",
221 frame1.GetMethod().Name);
223 Assert("Method not null (2)",
224 (frame2.GetMethod() != null));
226 AssertEquals("Class declaring the method (2)",
228 frame2.GetMethod().DeclaringType);
229 AssertEquals("Method name (2)",
231 frame2.GetMethod().Name);
233 Assert("Method not null (3)",
234 (frame3.GetMethod() != null));
236 AssertEquals("Class declaring the method (3)",
238 frame3.GetMethod().DeclaringType);
239 AssertEquals("Method name (3)",
241 frame3.GetMethod().Name);
247 /// Tests the case where StackFrame is created for current method but
248 /// skipping some frames.
251 /// FIXME: Must be compiled with /debug switch. Otherwise some file
252 /// information will be incorrect for the following test cases.
253 /// What's the best way to do both types of tests with and without
254 /// debug information?
256 private class StackFrameTest3 : TestCase {
257 public StackFrameTest3(string name) : base(name) {}
259 private StackFrame frame1;
260 private StackFrame frame2;
262 internal static ITest Suite
266 return new TestSuite(typeof(StackFrameTest3));
270 protected override void SetUp() {
271 // In order to get better test cases with stack traces
275 private void NestedSetUp() {
276 frame1 = new StackFrame(2);
277 frame2 = new StackFrame(1, true);
280 protected override void TearDown() {
288 /// Tests whether getting file name works.
290 public void TestGetFileName() {
291 AssertNull("File name (1)",
292 frame1.GetFileName());
294 Assert("File name (2) " + frame2.GetFileName()
295 + " ends with StackFrameTest.cs",
296 frame2.GetFileName().EndsWith("StackFrameTest.cs"));
300 /// Tests whether getting file line number works.
302 public void TestGetFileLineNumber() {
303 AssertEquals("Line number (1)",
305 frame1.GetFileLineNumber());
307 AssertEquals("Line number (2)",
309 frame2.GetFileLineNumber());
313 /// Tests whether getting file column number works.
315 public void TestGetFileColumnNumber() {
316 AssertEquals("Column number (1)",
318 frame1.GetFileColumnNumber());
320 AssertEquals("Column number (2)",
322 frame2.GetFileColumnNumber());
327 /// Tests whether getting method associated with frame works.
329 public void TestGetMethod() {
330 Assert("Method not null (1)", (frame1.GetMethod() != null));
332 AssertEquals("Class declaring the method (1)",
333 typeof(NUnit.Framework.TestCase),
334 frame1.GetMethod().DeclaringType);
335 AssertEquals("Method name (1)",
337 frame1.GetMethod().Name);
339 Assert("Method not null (2)", (frame2.GetMethod() != null));
341 AssertEquals("Class declaring the method (2)",
343 frame2.GetMethod().DeclaringType);
344 AssertEquals("Method name (2)",
346 frame2.GetMethod().Name);