2 // MonoTests.System.Diagnostics.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 {
17 /// Tests the case where StackFrame is created for specified file name and
18 /// location inside it.
21 public class StackFrameTest1 : Assertion {
22 private StackFrame frame1;
23 private StackFrame frame2;
26 public void SetUp () {
27 frame1 = new StackFrame("dir/someFile", 13, 45);
28 frame2 = new StackFrame("SomeFile2.cs", 24);
32 public void TearDown () {
38 /// Tests whether getting file name works.
40 public void TestGetFileName() {
41 AssertEquals("File name (1)",
43 frame1.GetFileName());
45 AssertEquals("File name (2)",
47 frame2.GetFileName());
51 /// Tests whether getting file line number works.
53 public void TestGetFileLineNumber() {
54 AssertEquals("Line number (1)",
56 frame1.GetFileLineNumber());
58 AssertEquals("Line number (2)",
60 frame2.GetFileLineNumber());
64 /// Tests whether getting file column number works.
66 public void TestGetFileColumnNumber() {
67 AssertEquals("Column number (1)",
69 frame1.GetFileColumnNumber());
71 AssertEquals("Column number (2)",
73 frame2.GetFileColumnNumber());
78 /// Tests whether getting method associated with frame works.
80 public void TestGetMethod() {
81 Assert("Method not null (1)", (frame1.GetMethod() != null));
83 AssertEquals("Class declaring the method (1)",
85 frame1.GetMethod().DeclaringType);
86 AssertEquals("Method name (1)",
88 frame1.GetMethod().Name);
90 Assert("Method not null (2)", (frame2.GetMethod() != null));
92 AssertEquals("Class declaring the method (2)",
94 frame2.GetMethod().DeclaringType);
95 AssertEquals("Method name (2)",
97 frame2.GetMethod().Name);
102 /// Tests the case where StackFrame is created for current method.
105 /// FIXME: Must be compiled with /debug switch. Otherwise some file
106 /// information will be incorrect for the following test cases.
107 /// What's the best way to do both types of tests with and without
108 /// debug information?
111 public class StackFrameTest2 : Assertion {
112 private StackFrame frame1;
113 private StackFrame frame2;
114 private StackFrame frame3;
117 public void SetUp() {
118 frame1 = new StackFrame();
119 frame2 = new StackFrame(true);
120 frame3 = new StackFrame(0);
124 public void TearDown () {
131 /// Tests whether getting file name works.
133 public void TestGetFileName1() {
134 AssertNull("File name (1)",
135 frame1.GetFileName());
139 public void TestGetFileName2() {
140 Assert("File name (2) " + frame2.GetFileName()
141 + " ends with StackFrameTest.cs",
142 frame2.GetFileName().EndsWith("StackFrameTest.cs"));
146 /// Tests whether getting file line number works.
148 public void TestGetFileLineNumber() {
149 AssertEquals("Line number (1)",
151 frame1.GetFileLineNumber());
153 AssertEquals("Line number (2)",
155 frame2.GetFileLineNumber());
157 AssertEquals("Line number (3)",
159 frame3.GetFileLineNumber());
163 /// Tests whether getting file column number works.
165 public void TestGetFileColumnNumber() {
166 AssertEquals("Column number (1)",
168 frame1.GetFileColumnNumber());
170 AssertEquals("Column number (2)",
172 frame2.GetFileColumnNumber());
174 AssertEquals("Column number (3)",
176 frame3.GetFileColumnNumber());
181 /// Tests whether getting method associated with frame works.
183 public void TestGetMethod() {
184 Assert("Method not null (1)",
185 (frame1.GetMethod() != null));
187 AssertEquals("Class declaring the method (1)",
189 frame1.GetMethod().DeclaringType);
190 AssertEquals("Method name (1)",
192 frame1.GetMethod().Name);
194 Assert("Method not null (2)",
195 (frame2.GetMethod() != null));
197 AssertEquals("Class declaring the method (2)",
199 frame2.GetMethod().DeclaringType);
200 AssertEquals("Method name (2)",
202 frame2.GetMethod().Name);
204 Assert("Method not null (3)",
205 (frame3.GetMethod() != null));
207 AssertEquals("Class declaring the method (3)",
209 frame3.GetMethod().DeclaringType);
210 AssertEquals("Method name (3)",
212 frame3.GetMethod().Name);
218 /// Tests the case where StackFrame is created for current method but
219 /// skipping some frames.
222 /// FIXME: Must be compiled with /debug switch. Otherwise some file
223 /// information will be incorrect for the following test cases.
224 /// What's the best way to do both types of tests with and without
225 /// debug information?
228 public class StackFrameTest3 : Assertion {
229 protected StackFrame frame1;
230 protected StackFrame frame2;
233 public void SetUp() {
234 // In order to get better test cases with stack traces
238 private void NestedSetUp() {
239 frame1 = new StackFrame(2);
240 frame2 = new StackFrame(1, true);
241 // Without this access of frame2 on the RHS, none of
242 // the properties or methods seem to return any data ???
243 string s = frame2.GetFileName();
247 public void TearDown() {
253 /// Tests whether getting file name works.
255 public void TestGetFileName() {
256 AssertNull("File name (1)",
257 frame1.GetFileName());
259 AssertNotNull("File name (2) should not be null",
260 frame2.GetFileName());
262 Assert("File name (2) " + frame2.GetFileName()
263 + " ends with StackFrameTest.cs",
264 frame2.GetFileName().EndsWith("StackFrameTest.cs"));
268 /// Tests whether getting file line number works.
270 public void TestGetFileLineNumber() {
271 AssertEquals("Line number (1)",
273 frame1.GetFileLineNumber());
275 AssertEquals("Line number (2)",
277 frame2.GetFileLineNumber());
281 /// Tests whether getting file column number works.
283 public void TestGetFileColumnNumber() {
284 AssertEquals("Column number (1)",
286 frame1.GetFileColumnNumber());
288 AssertEquals("Column number (2)",
290 frame2.GetFileColumnNumber());
295 /// Tests whether getting method associated with frame works.
297 public void TestGetMethod() {
298 Assert("Method not null (1)", (frame1.GetMethod() != null));
300 Assert("Method not null (2)", (frame2.GetMethod() != null));
302 AssertEquals("Class declaring the method (2)",
304 frame2.GetMethod().DeclaringType);
306 AssertEquals("Method name (2)",
308 frame2.GetMethod().Name);