[Test] Fix previous test change as the test is dependent on line numbers
[mono-project.git] / mcs / class / corlib / Test / System.Diagnostics / StackFrameTest.cs
blobadec97c3ead35728d07f9120fe70c2ecbc1923c4
1 //
2 // MonoTests.System.Diagnostics.StackFrameTest.cs
3 //
4 // Author:
5 // Alexander Klyubin (klyubin@aqris.com)
6 //
7 // (C) 2001
8 //
10 using System;
11 using System.Diagnostics;
12 using System.Reflection;
13 using NUnit.Framework;
15 namespace MonoTests.System.Diagnostics
17 /// <summary>
18 /// Tests the case where StackFrame is created for specified file name and
19 /// location inside it.
20 /// </summary>
21 [TestFixture]
22 public class StackFrameTest1
24 private StackFrame frame1;
25 private StackFrame frame2;
27 [SetUp]
28 public void SetUp ()
30 frame1 = new StackFrame ("dir/someFile", 13, 45);
31 frame2 = new StackFrame ("SomeFile2.cs", 24);
34 [TearDown]
35 public void TearDown ()
37 frame1 = null;
38 frame2 = null;
41 /// <summary>
42 /// Tests whether getting file name works.
43 /// </summary>
44 [Test]
45 [Category("LLVMNotWorking")]
46 public void TestGetFileName ()
48 Assert.AreEqual ("dir/someFile",
49 frame1.GetFileName (),
50 "File name (1)");
52 Assert.AreEqual ("SomeFile2.cs",
53 frame2.GetFileName (),
54 "File name (2)");
57 /// <summary>
58 /// Tests whether getting file line number works.
59 /// </summary>
60 [Test]
61 [Category("LLVMNotWorking")]
62 public void TestGetFileLineNumber ()
64 Assert.AreEqual (13,
65 frame1.GetFileLineNumber (),
66 "Line number (1)");
68 Assert.AreEqual (24,
69 frame2.GetFileLineNumber (),
70 "Line number (2)");
73 /// <summary>
74 /// Tests whether getting file column number works.
75 /// </summary>
76 [Test]
77 public void TestGetFileColumnNumber ()
79 Assert.AreEqual (45,
80 frame1.GetFileColumnNumber (),
81 "Column number (1)");
83 Assert.AreEqual (0,
84 frame2.GetFileColumnNumber (),
85 "Column number (2)");
88 /// <summary>
89 /// Tests whether getting method associated with frame works.
90 /// </summary>
91 [Test]
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,
101 "Method name (1)");
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,
110 "Method name (2)");
114 /// <summary>
115 /// Tests the case where StackFrame is created for current method.
116 /// </summary>
117 /// <remarks>
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?
122 /// </remarks>
123 [TestFixture]
124 public class StackFrameTest2
126 private StackFrame frame1;
127 private StackFrame frame2;
128 private StackFrame frame3;
130 [SetUp]
131 public void SetUp ()
133 frame1 = new StackFrame ();
134 frame2 = new StackFrame (true);
135 frame3 = new StackFrame (0);
138 [TearDown]
139 public void TearDown ()
141 frame1 = null;
142 frame2 = null;
143 frame3 = null;
146 /// <summary>
147 /// Tests whether getting file name works.
148 /// </summary>
149 [Test]
150 public void TestGetFileName1 ()
152 Assert.IsNull (frame1.GetFileName (),
153 "File name (1)");
156 [Test]
157 [Category ("LLVMNotWorking")]
158 public void TestGetFileName2 ()
160 #if MOBILE && !DEBUG
161 Assert.Ignore ("The .mdb file won't be present inside the app and no file name will be available");
162 #endif
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");
169 /// <summary>
170 /// Tests whether getting file line number works.
171 /// </summary>
172 [Test]
173 [Category ("LLVMNotWorking")]
174 public void TestGetFileLineNumber ()
176 #if MOBILE && !DEBUG
177 Assert.Ignore ("The .mdb file won't be present inside the app and no line number will be available");
178 #endif
179 Assert.AreEqual (0,
180 frame1.GetFileLineNumber (),
181 "Line number (1)");
183 Assert.AreEqual (134,
184 frame2.GetFileLineNumber (),
185 "Line number (2)");
187 Assert.AreEqual (0,
188 frame3.GetFileLineNumber (),
189 "Line number (3)");
192 /// <summary>
193 /// Tests whether getting file column number works.
194 /// </summary>
195 [Test]
196 [Category ("NotWorking")] // bug #45730 - Column numbers always zero
197 public void TestGetFileColumnNumber ()
199 Assert.AreEqual (0,
200 frame1.GetFileColumnNumber (),
201 "Column number (1)");
203 Assert.AreEqual (4,
204 frame2.GetFileColumnNumber (),
205 "Column number (2)");
207 Assert.AreEqual (0,
208 frame3.GetFileColumnNumber (),
209 "Column number (3)");
212 /// <summary>
213 /// Tests whether getting method associated with frame works.
214 /// </summary>
215 [Test]
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,
226 "Method name (1)");
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,
236 "Method name (2)");
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,
246 "Method name (3)");
250 /// <summary>
251 /// Tests the case where StackFrame is created for current method but
252 /// skipping some frames.
253 /// </summary>
254 /// <remarks>
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?
259 /// </remarks>
260 [TestFixture]
261 public class StackFrameTest3
263 protected StackFrame frame1;
264 protected StackFrame frame2;
266 [SetUp]
267 public void SetUp ()
269 // In order to get better test cases with stack traces
270 NestedSetUp ();
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 ();
282 [TearDown]
283 public void TearDown ()
285 frame1 = null;
286 frame2 = null;
289 /// <summary>
290 /// Tests whether getting file name works.
291 /// </summary>
292 [Test]
293 [Category ("LLVMNotWorking")]
294 public void TestGetFileName ()
296 #if MOBILE && !DEBUG
297 Assert.Ignore ("The .mdb file won't be present inside the app and no file name will be available");
298 #endif
299 Assert.IsNull (frame1.GetFileName (),
300 "File name (1)");
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");
309 /// <summary>
310 /// Tests whether getting file line number works.
311 /// </summary>
312 [Test]
313 #if ONLY_1_1
314 [Category ("NotDotNet")] // .NET 1.1 is off by one
315 #endif
316 [Category ("LLVMNotWorking")]
317 public void TestGetFileLineNumber ()
319 #if MOBILE && !DEBUG
320 Assert.Ignore ("The .mdb file won't be present inside the app and no line number will be available");
321 #endif
322 Assert.AreEqual (0,
323 frame1.GetFileLineNumber (),
324 "Line number (1)");
326 Assert.AreEqual (270,
327 frame2.GetFileLineNumber (),
328 "Line number (2)");
331 /// <summary>
332 /// Tests whether getting file column number works.
333 /// </summary>
334 [Test]
335 #if ONLY_1_1
336 [Category ("NotDotNet")] // .NET 1.1 is off by one
337 #endif
338 [Category ("NotWorking")] // bug #45730 - Column numbers always zero
339 public void TestGetFileColumnNumber ()
341 Assert.AreEqual (0,
342 frame1.GetFileColumnNumber (),
343 "Column number (1)");
345 Assert.AreEqual (4,
346 frame2.GetFileColumnNumber (),
347 "Column number (2)");
350 /// <summary>
351 /// Tests whether getting method associated with frame works.
352 /// </summary>
353 [Test]
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,
366 "Method name (2)");