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 : Assertion
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 AssertEquals ("File name (1)",
49 frame1.GetFileName ());
51 AssertEquals ("File name (2)",
53 frame2.GetFileName ());
57 /// Tests whether getting file line number works.
60 public void TestGetFileLineNumber ()
62 AssertEquals ("Line number (1)",
64 frame1.GetFileLineNumber ());
66 AssertEquals ("Line number (2)",
68 frame2.GetFileLineNumber ());
72 /// Tests whether getting file column number works.
75 public void TestGetFileColumnNumber ()
77 AssertEquals ("Column number (1)",
79 frame1.GetFileColumnNumber ());
81 AssertEquals ("Column number (2)",
83 frame2.GetFileColumnNumber ());
87 /// Tests whether getting method associated with frame works.
90 public void TestGetMethod ()
92 Assert ("Method not null (1)", (frame1.GetMethod () != null));
94 AssertEquals ("Class declaring the method (1)",
96 frame1.GetMethod ().DeclaringType);
97 AssertEquals ("Method name (1)",
99 frame1.GetMethod ().Name);
101 Assert ("Method not null (2)", (frame2.GetMethod () != null));
103 AssertEquals ("Class declaring the method (2)",
105 frame2.GetMethod ().DeclaringType);
106 AssertEquals ("Method name (2)",
108 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 : Assertion
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 AssertNull ("File name (1)",
151 frame1.GetFileName ());
155 public void TestGetFileName2 ()
157 AssertNotNull ("File name not null", frame2.GetFileName ());
158 Assert ("File name not empty", frame2.GetFileName ().Length != 0);
159 Assert ("File name (2) " + frame2.GetFileName ()
160 + " ends with StackFrameTest.cs",
161 frame2.GetFileName ().EndsWith ("StackFrameTest.cs"));
165 /// Tests whether getting file line number works.
168 public void TestGetFileLineNumber ()
170 AssertEquals ("Line number (1)",
172 frame1.GetFileLineNumber ());
174 AssertEquals ("Line number (2)",
176 frame2.GetFileLineNumber ());
178 AssertEquals ("Line number (3)",
180 frame3.GetFileLineNumber ());
184 /// Tests whether getting file column number works.
187 [Category ("NotWorking")] // bug #45730 - Column numbers always zero
188 public void TestGetFileColumnNumber ()
190 AssertEquals ("Column number (1)",
192 frame1.GetFileColumnNumber ());
194 AssertEquals ("Column number (2)",
196 frame2.GetFileColumnNumber ());
198 AssertEquals ("Column number (3)",
200 frame3.GetFileColumnNumber ());
204 /// Tests whether getting method associated with frame works.
207 public void TestGetMethod ()
209 Assert ("Method not null (1)",
210 (frame1.GetMethod () != null));
212 AssertEquals ("Class declaring the method (1)",
214 frame1.GetMethod ().DeclaringType);
215 AssertEquals ("Method name (1)",
217 frame1.GetMethod ().Name);
219 Assert ("Method not null (2)",
220 (frame2.GetMethod () != null));
222 AssertEquals ("Class declaring the method (2)",
224 frame2.GetMethod ().DeclaringType);
225 AssertEquals ("Method name (2)",
227 frame2.GetMethod ().Name);
229 Assert ("Method not null (3)",
230 (frame3.GetMethod () != null));
232 AssertEquals ("Class declaring the method (3)",
234 frame3.GetMethod ().DeclaringType);
235 AssertEquals ("Method name (3)",
237 frame3.GetMethod ().Name);
242 /// Tests the case where StackFrame is created for current method but
243 /// skipping some frames.
246 /// FIXME: Must be compiled with /debug switch. Otherwise some file
247 /// information will be incorrect for the following test cases.
248 /// What's the best way to do both types of tests with and without
249 /// debug information?
252 public class StackFrameTest3 : Assertion
254 protected StackFrame frame1;
255 protected StackFrame frame2;
260 // In order to get better test cases with stack traces
264 private void NestedSetUp ()
266 frame1 = new StackFrame (2);
267 frame2 = new StackFrame (1, true);
268 // Without this access of frame2 on the RHS, none of
269 // the properties or methods seem to return any data ???
270 string s = frame2.GetFileName ();
274 public void TearDown ()
281 /// Tests whether getting file name works.
284 public void TestGetFileName ()
286 AssertNull ("File name (1)",
287 frame1.GetFileName ());
289 AssertNotNull ("File name (2) should not be null",
290 frame2.GetFileName ());
292 Assert ("File name (2) " + frame2.GetFileName ()
293 + " ends with StackFrameTest.cs",
294 frame2.GetFileName ().EndsWith ("StackFrameTest.cs"));
298 /// Tests whether getting file line number works.
302 [Category ("NotDotNet")] // .NET 1.1 is off by one
304 public void TestGetFileLineNumber ()
306 AssertEquals ("Line number (1)",
308 frame1.GetFileLineNumber ());
310 AssertEquals ("Line number (2)",
312 frame2.GetFileLineNumber ());
316 /// Tests whether getting file column number works.
320 [Category ("NotDotNet")] // .NET 1.1 is off by one
322 [Category ("NotWorking")] // bug #45730 - Column numbers always zero
323 public void TestGetFileColumnNumber ()
325 AssertEquals ("Column number (1)",
327 frame1.GetFileColumnNumber ());
329 AssertEquals ("Column number (2)",
331 frame2.GetFileColumnNumber ());
335 /// Tests whether getting method associated with frame works.
338 public void TestGetMethod ()
340 Assert ("Method not null (1)", (frame1.GetMethod () != null));
342 Assert ("Method not null (2)", (frame2.GetMethod () != null));
344 AssertEquals ("Class declaring the method (2)",
346 frame2.GetMethod ().DeclaringType);
348 AssertEquals ("Method name (2)",
350 frame2.GetMethod ().Name);