Merge pull request #866 from linquize/content-type-encoding
[mono.git] / mcs / class / corlib / Test / System.Diagnostics / StackFrameTest.cs
1 //
2 // MonoTests.System.Diagnostics.StackFrameTest.cs
3 //
4 // Author:
5 //      Alexander Klyubin (klyubin@aqris.com)
6 //
7 // (C) 2001
8 //
9
10 using System;
11 using System.Diagnostics;
12 using System.Reflection;
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Diagnostics
16 {
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
23         {
24                 private StackFrame frame1;
25                 private StackFrame frame2;
26
27                 [SetUp]
28                 public void SetUp ()
29                 {
30                         frame1 = new StackFrame ("dir/someFile", 13, 45);
31                         frame2 = new StackFrame ("SomeFile2.cs", 24);
32                 }
33
34                 [TearDown]
35                 public void TearDown ()
36                 {
37                         frame1 = null;
38                         frame2 = null;
39                 }
40
41                 /// <summary>
42                 ///   Tests whether getting file name works.
43                 /// </summary>
44                 [Test]
45                 [Category("LLVMNotWorking")]
46                 public void TestGetFileName ()
47                 {
48                         Assert.AreEqual ("dir/someFile",
49                                                  frame1.GetFileName (),
50                                                  "File name (1)");
51
52                         Assert.AreEqual ("SomeFile2.cs",
53                                                  frame2.GetFileName (),
54                                                  "File name (2)");
55                 }
56
57                 /// <summary>
58                 /// Tests whether getting file line number works.
59                 /// </summary>
60                 [Test]
61                 [Category("LLVMNotWorking")]
62                 public void TestGetFileLineNumber ()
63                 {
64                         Assert.AreEqual (13,
65                                                          frame1.GetFileLineNumber (),
66                                                          "Line number (1)");
67
68                         Assert.AreEqual (24,
69                                                          frame2.GetFileLineNumber (),
70                                                          "Line number (2)");
71                 }
72
73                 /// <summary>
74                 /// Tests whether getting file column number works.
75                 /// </summary>
76                 [Test]
77                 public void TestGetFileColumnNumber ()
78                 {
79                         Assert.AreEqual (45,
80                                                          frame1.GetFileColumnNumber (),
81                                                          "Column number (1)");
82
83                         Assert.AreEqual (0,
84                                                          frame2.GetFileColumnNumber (),
85                                                          "Column number (2)");
86                 }
87
88                 /// <summary>
89                 /// Tests whether getting method associated with frame works.
90                 /// </summary>
91                 [Test]
92                 public void TestGetMethod ()
93                 {
94                         Assert.IsTrue ((frame1.GetMethod () != null), "Method not null (1)");
95
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)");
102
103                         Assert.IsTrue ((frame2.GetMethod () != null), "Method not null (2)");
104
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)");
111                 }
112         }
113
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
125         {
126                 private StackFrame frame1;
127                 private StackFrame frame2;
128                 private StackFrame frame3;
129
130                 [SetUp]
131                 public void SetUp ()
132                 {
133                         frame1 = new StackFrame ();
134                         frame2 = new StackFrame (true);
135                         frame3 = new StackFrame (0);
136                 }
137
138                 [TearDown]
139                 public void TearDown ()
140                 {
141                         frame1 = null;
142                         frame2 = null;
143                         frame3 = null;
144                 }
145
146                 /// <summary>
147                 /// Tests whether getting file name works.
148                 /// </summary>
149                 [Test]
150                 public void TestGetFileName1 ()
151                 {
152                         Assert.IsNull (frame1.GetFileName (),
153                                                    "File name (1)");
154                 }
155
156                 [Test]
157                 [Category ("LLVMNotWorking")]
158                 public void TestGetFileName2 ()
159                 {
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");
167                 }
168
169                 /// <summary>
170                 /// Tests whether getting file line number works.
171                 /// </summary>
172                 [Test]
173                 [Category ("LLVMNotWorking")]
174                 public void TestGetFileLineNumber ()
175                 {
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)");
182
183                         Assert.AreEqual (134,
184                                                          frame2.GetFileLineNumber (),
185                                                          "Line number (2)");
186
187                         Assert.AreEqual (0,
188                                                          frame3.GetFileLineNumber (),
189                                                          "Line number (3)");
190                 }
191
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 ()
198                 {
199                         Assert.AreEqual (0,
200                                                          frame1.GetFileColumnNumber (),
201                                                          "Column number (1)");
202
203                         Assert.AreEqual (4,
204                                                          frame2.GetFileColumnNumber (),
205                                                          "Column number (2)");
206
207                         Assert.AreEqual (0,
208                                                          frame3.GetFileColumnNumber (),
209                                                          "Column number (3)");
210                 }
211
212                 /// <summary>
213                 /// Tests whether getting method associated with frame works.
214                 /// </summary>
215                 [Test]
216                 public void TestGetMethod ()
217                 {
218                         Assert.IsNotNull (frame1.GetMethod (),
219                                                           "Method not null (1)");
220
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)");
227
228                         Assert.IsNotNull (frame2.GetMethod (),
229                                                           "Method not null (2)");
230
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)");
237
238                         Assert.IsNotNull (frame3.GetMethod (),
239                                                           "Method not null (3)");
240
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)");
247                 }
248         }
249
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
262         {
263                 protected StackFrame frame1;
264                 protected StackFrame frame2;
265
266                 [SetUp]
267                 public void SetUp ()
268                 {
269                         // In order to get better test cases with stack traces
270                         NestedSetUp ();
271                 }
272
273                 private void NestedSetUp ()
274                 {
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 ();
280                 }
281
282                 [TearDown]
283                 public void TearDown ()
284                 {
285                         frame1 = null;
286                         frame2 = null;
287                 }
288
289                 /// <summary>
290                 /// Tests whether getting file name works.
291                 /// </summary>
292                 [Test]
293                 [Category ("LLVMNotWorking")]
294                 public void TestGetFileName ()
295                 {
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)");
301
302                         Assert.IsNotNull (frame2.GetFileName (),
303                                                           "File name (2) should not be null");
304
305                         Assert.IsTrue (frame2.GetFileName ().EndsWith ("StackFrameTest.cs"),
306                                                    "File name (2) " + frame2.GetFileName () + " ends with StackFrameTest.cs");
307                 }
308
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 ()
318                 {
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)");
325
326                         Assert.AreEqual (270,
327                                                          frame2.GetFileLineNumber (),
328                                                          "Line number (2)");
329                 }
330
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 ()
340                 {
341                         Assert.AreEqual (0,
342                                                  frame1.GetFileColumnNumber (),
343                                                          "Column number (1)");
344
345                         Assert.AreEqual (4,
346                                                          frame2.GetFileColumnNumber (),
347                                                          "Column number (2)");
348                 }
349
350                 /// <summary>
351                 /// Tests whether getting method associated with frame works.
352                 /// </summary>
353                 [Test]
354                 public void TestGetMethod ()
355                 {
356                         Assert.IsTrue ((frame1.GetMethod () != null), "Method not null (1)");
357
358                         Assert.IsTrue ((frame2.GetMethod () != null), "Method not null (2)");
359
360                         Assert.AreEqual (this.GetType (),
361                                                          frame2.GetMethod ().DeclaringType,
362                                                          "Class declaring the method (2)");
363
364                         Assert.AreEqual ("SetUp",
365                                                          frame2.GetMethod ().Name,
366                                                          "Method name (2)");
367                 }
368         }
369 }