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
18 /// Tests the case where StackFrame is created for specified file name and
19 /// location inside it.
22 public class StackFrameTest1
24 private StackFrame frame1;
25 private StackFrame frame2;
30 frame1 = new StackFrame ("dir/someFile", 13, 45);
31 frame2 = new StackFrame ("SomeFile2.cs", 24);
35 public void TearDown ()
42 /// Tests whether getting file name works.
45 public void TestGetFileName ()
47 Assert.AreEqual ("dir/someFile",
48 frame1.GetFileName (),
51 Assert.AreEqual ("SomeFile2.cs",
52 frame2.GetFileName (),
57 /// Tests whether getting file line number works.
60 public void TestGetFileLineNumber ()
63 frame1.GetFileLineNumber (),
67 frame2.GetFileLineNumber (),
72 /// Tests whether getting file column number works.
75 public void TestGetFileColumnNumber ()
78 frame1.GetFileColumnNumber (),
82 frame2.GetFileColumnNumber (),
87 /// Tests whether getting method associated with frame works.
90 public void TestGetMethod ()
92 Assert.IsTrue ((frame1.GetMethod () != null), "Method not null (1)");
94 Assert.AreEqual (this.GetType (),
95 frame1.GetMethod ().DeclaringType,
96 "Class declaring the method (1)");
97 Assert.AreEqual ("SetUp",
98 frame1.GetMethod ().Name,
101 Assert.IsTrue ((frame2.GetMethod () != null), "Method not null (2)");
103 Assert.AreEqual (this.GetType (),
104 frame2.GetMethod ().DeclaringType,
105 "Class declaring the method (2)");
106 Assert.AreEqual ("SetUp",
107 frame2.GetMethod ().Name,
113 /// Tests the case where StackFrame is created for current method.
116 /// FIXME: Must be compiled with /debug switch. Otherwise some file
117 /// information will be incorrect for the following test cases.
118 /// What's the best way to do both types of tests with and without
119 /// debug information?
122 public class StackFrameTest2
124 private StackFrame frame1;
125 private StackFrame frame2;
126 private StackFrame frame3;
131 frame1 = new StackFrame ();
132 frame2 = new StackFrame (true);
133 frame3 = new StackFrame (0);
137 public void TearDown ()
145 /// Tests whether getting file name works.
148 public void TestGetFileName1 ()
150 Assert.IsNull (frame1.GetFileName (),
155 public void TestGetFileName2 ()
157 Assert.IsNotNull (frame2.GetFileName (), "File name not null");
158 Assert.IsTrue (frame2.GetFileName ().Length != 0, "File name not empty");
159 Assert.IsTrue (frame2.GetFileName ().EndsWith ("StackFrameTest.cs"),
160 "File name (2) " + frame2.GetFileName () + " ends with StackFrameTest.cs");
164 /// Tests whether getting file line number works.
167 public void TestGetFileLineNumber ()
170 frame1.GetFileLineNumber (),
173 Assert.AreEqual (132,
174 frame2.GetFileLineNumber (),
178 frame3.GetFileLineNumber (),
183 /// Tests whether getting file column number works.
186 [Category ("NotWorking")] // bug #45730 - Column numbers always zero
187 public void TestGetFileColumnNumber ()
190 frame1.GetFileColumnNumber (),
191 "Column number (1)");
194 frame2.GetFileColumnNumber (),
195 "Column number (2)");
198 frame3.GetFileColumnNumber (),
199 "Column number (3)");
203 /// Tests whether getting method associated with frame works.
206 public void TestGetMethod ()
208 Assert.IsNotNull (frame1.GetMethod (),
209 "Method not null (1)");
211 Assert.AreEqual (this.GetType (),
212 frame1.GetMethod ().DeclaringType,
213 "Class declaring the method (1)");
214 Assert.AreEqual ("SetUp",
215 frame1.GetMethod ().Name,
218 Assert.IsNotNull (frame2.GetMethod (),
219 "Method not null (2)");
221 Assert.AreEqual (this.GetType (),
222 frame2.GetMethod ().DeclaringType,
223 "Class declaring the method (2)");
224 Assert.AreEqual ("SetUp",
225 frame2.GetMethod ().Name,
228 Assert.IsNotNull (frame3.GetMethod (),
229 "Method not null (3)");
231 Assert.AreEqual (this.GetType (),
232 frame3.GetMethod ().DeclaringType,
233 "Class declaring the method (3)");
234 Assert.AreEqual ("SetUp",
235 frame3.GetMethod ().Name,
241 /// Tests the case where StackFrame is created for current method but
242 /// skipping some frames.
245 /// FIXME: Must be compiled with /debug switch. Otherwise some file
246 /// information will be incorrect for the following test cases.
247 /// What's the best way to do both types of tests with and without
248 /// debug information?
251 public class StackFrameTest3
253 protected StackFrame frame1;
254 protected StackFrame frame2;
259 // In order to get better test cases with stack traces
263 private void NestedSetUp ()
265 frame1 = new StackFrame (2);
266 frame2 = new StackFrame (1, true);
267 // Without this access of frame2 on the RHS, none of
268 // the properties or methods seem to return any data ???
269 string s = frame2.GetFileName ();
273 public void TearDown ()
280 /// Tests whether getting file name works.
283 public void TestGetFileName ()
285 Assert.IsNull (frame1.GetFileName (),
288 Assert.IsNotNull (frame2.GetFileName (),
289 "File name (2) should not be null");
291 Assert.IsTrue (frame2.GetFileName ().EndsWith ("StackFrameTest.cs"),
292 "File name (2) " + frame2.GetFileName () + " ends with StackFrameTest.cs");
296 /// Tests whether getting file line number works.
300 [Category ("NotDotNet")] // .NET 1.1 is off by one
302 public void TestGetFileLineNumber ()
305 frame1.GetFileLineNumber (),
308 Assert.AreEqual (260,
309 frame2.GetFileLineNumber (),
314 /// Tests whether getting file column number works.
318 [Category ("NotDotNet")] // .NET 1.1 is off by one
320 [Category ("NotWorking")] // bug #45730 - Column numbers always zero
321 public void TestGetFileColumnNumber ()
324 frame1.GetFileColumnNumber (),
325 "Column number (1)");
328 frame2.GetFileColumnNumber (),
329 "Column number (2)");
333 /// Tests whether getting method associated with frame works.
336 public void TestGetMethod ()
338 Assert.IsTrue ((frame1.GetMethod () != null), "Method not null (1)");
340 Assert.IsTrue ((frame2.GetMethod () != null), "Method not null (2)");
342 Assert.AreEqual (this.GetType (),
343 frame2.GetMethod ().DeclaringType,
344 "Class declaring the method (2)");
346 Assert.AreEqual ("SetUp",
347 frame2.GetMethod ().Name,