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 [Category("LLVMNotWorking")]
46 public void TestGetFileName ()
48 Assert
.AreEqual ("dir/someFile",
49 frame1
.GetFileName (),
52 Assert
.AreEqual ("SomeFile2.cs",
53 frame2
.GetFileName (),
58 /// Tests whether getting file line number works.
61 [Category("LLVMNotWorking")]
62 public void TestGetFileLineNumber ()
65 frame1
.GetFileLineNumber (),
69 frame2
.GetFileLineNumber (),
74 /// Tests whether getting file column number works.
77 public void TestGetFileColumnNumber ()
80 frame1
.GetFileColumnNumber (),
84 frame2
.GetFileColumnNumber (),
89 /// Tests whether getting method associated with frame works.
92 public void TestGetMethod ()
94 Assert
.IsTrue ((frame1
.GetMethod () != null), "Method not null (1)");
96 Assert
.AreEqual (this.GetType (),
97 frame1
.GetMethod ().DeclaringType
,
98 "Class declaring the method (1)");
99 Assert
.AreEqual ("SetUp",
100 frame1
.GetMethod ().Name
,
103 Assert
.IsTrue ((frame2
.GetMethod () != null), "Method not null (2)");
105 Assert
.AreEqual (this.GetType (),
106 frame2
.GetMethod ().DeclaringType
,
107 "Class declaring the method (2)");
108 Assert
.AreEqual ("SetUp",
109 frame2
.GetMethod ().Name
,
115 /// Tests the case where StackFrame is created for current method.
118 /// FIXME: Must be compiled with /debug switch. Otherwise some file
119 /// information will be incorrect for the following test cases.
120 /// What's the best way to do both types of tests with and without
121 /// debug information?
124 public class StackFrameTest2
126 private StackFrame frame1
;
127 private StackFrame frame2
;
128 private StackFrame frame3
;
133 frame1
= new StackFrame ();
134 frame2
= new StackFrame (true);
135 frame3
= new StackFrame (0);
139 public void TearDown ()
147 /// Tests whether getting file name works.
150 public void TestGetFileName1 ()
152 Assert
.IsNull (frame1
.GetFileName (),
157 [Category ("LLVMNotWorking")]
158 public void TestGetFileName2 ()
161 Assert
.Ignore ("The .mdb file won't be present inside the app and no file name will be available");
163 Assert
.IsNotNull (frame2
.GetFileName (), "File name not null");
164 Assert
.IsTrue (frame2
.GetFileName ().Length
!= 0, "File name not empty");
165 Assert
.IsTrue (frame2
.GetFileName ().EndsWith ("StackFrameTest.cs"),
166 "File name (2) " + frame2
.GetFileName () + " ends with StackFrameTest.cs");
170 /// Tests whether getting file line number works.
173 [Category ("LLVMNotWorking")]
174 public void TestGetFileLineNumber ()
177 Assert
.Ignore ("The .mdb file won't be present inside the app and no line number will be available");
180 frame1
.GetFileLineNumber (),
183 Assert
.AreEqual (134,
184 frame2
.GetFileLineNumber (),
188 frame3
.GetFileLineNumber (),
193 /// Tests whether getting file column number works.
196 [Category ("NotWorking")] // bug #45730 - Column numbers always zero
197 public void TestGetFileColumnNumber ()
200 frame1
.GetFileColumnNumber (),
201 "Column number (1)");
204 frame2
.GetFileColumnNumber (),
205 "Column number (2)");
208 frame3
.GetFileColumnNumber (),
209 "Column number (3)");
213 /// Tests whether getting method associated with frame works.
216 public void TestGetMethod ()
218 Assert
.IsNotNull (frame1
.GetMethod (),
219 "Method not null (1)");
221 Assert
.AreEqual (this.GetType (),
222 frame1
.GetMethod ().DeclaringType
,
223 "Class declaring the method (1)");
224 Assert
.AreEqual ("SetUp",
225 frame1
.GetMethod ().Name
,
228 Assert
.IsNotNull (frame2
.GetMethod (),
229 "Method not null (2)");
231 Assert
.AreEqual (this.GetType (),
232 frame2
.GetMethod ().DeclaringType
,
233 "Class declaring the method (2)");
234 Assert
.AreEqual ("SetUp",
235 frame2
.GetMethod ().Name
,
238 Assert
.IsNotNull (frame3
.GetMethod (),
239 "Method not null (3)");
241 Assert
.AreEqual (this.GetType (),
242 frame3
.GetMethod ().DeclaringType
,
243 "Class declaring the method (3)");
244 Assert
.AreEqual ("SetUp",
245 frame3
.GetMethod ().Name
,
251 /// Tests the case where StackFrame is created for current method but
252 /// skipping some frames.
255 /// FIXME: Must be compiled with /debug switch. Otherwise some file
256 /// information will be incorrect for the following test cases.
257 /// What's the best way to do both types of tests with and without
258 /// debug information?
261 public class StackFrameTest3
263 protected StackFrame frame1
;
264 protected StackFrame frame2
;
269 // In order to get better test cases with stack traces
273 private void NestedSetUp ()
275 frame1
= new StackFrame (2);
276 frame2
= new StackFrame (1, true);
277 // Without this access of frame2 on the RHS, none of
278 // the properties or methods seem to return any data ???
279 string s
= frame2
.GetFileName ();
283 public void TearDown ()
290 /// Tests whether getting file name works.
293 [Category ("LLVMNotWorking")]
294 public void TestGetFileName ()
297 Assert
.Ignore ("The .mdb file won't be present inside the app and no file name will be available");
299 Assert
.IsNull (frame1
.GetFileName (),
302 Assert
.IsNotNull (frame2
.GetFileName (),
303 "File name (2) should not be null");
305 Assert
.IsTrue (frame2
.GetFileName ().EndsWith ("StackFrameTest.cs"),
306 "File name (2) " + frame2
.GetFileName () + " ends with StackFrameTest.cs");
310 /// Tests whether getting file line number works.
314 [Category ("NotDotNet")] // .NET 1.1 is off by one
316 [Category ("LLVMNotWorking")]
317 public void TestGetFileLineNumber ()
320 Assert
.Ignore ("The .mdb file won't be present inside the app and no line number will be available");
323 frame1
.GetFileLineNumber (),
326 Assert
.AreEqual (270,
327 frame2
.GetFileLineNumber (),
332 /// Tests whether getting file column number works.
336 [Category ("NotDotNet")] // .NET 1.1 is off by one
338 [Category ("NotWorking")] // bug #45730 - Column numbers always zero
339 public void TestGetFileColumnNumber ()
342 frame1
.GetFileColumnNumber (),
343 "Column number (1)");
346 frame2
.GetFileColumnNumber (),
347 "Column number (2)");
351 /// Tests whether getting method associated with frame works.
354 public void TestGetMethod ()
356 Assert
.IsTrue ((frame1
.GetMethod () != null), "Method not null (1)");
358 Assert
.IsTrue ((frame2
.GetMethod () != null), "Method not null (2)");
360 Assert
.AreEqual (this.GetType (),
361 frame2
.GetMethod ().DeclaringType
,
362 "Class declaring the method (2)");
364 Assert
.AreEqual ("SetUp",
365 frame2
.GetMethod ().Name
,