StackTraceTest.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // MonoTests.System.Diagnostics.StackTraceTest.cs
  3. //
  4. // Author:
  5. // Alexander Klyubin ([email protected])
  6. //
  7. // (C) 2001
  8. //
  9. using System;
  10. using System.Diagnostics;
  11. using System.Reflection;
  12. using NUnit.Framework;
  13. namespace MonoTests.System.Diagnostics {
  14. public class StackTraceTest {
  15. private StackTraceTest() {}
  16. public static ITest Suite
  17. {
  18. get
  19. {
  20. TestSuite suite = new TestSuite();
  21. suite.AddTest(StackTraceTest1.Suite);
  22. return suite;
  23. }
  24. }
  25. /// <summary>
  26. /// Tests the case where StackTrace is created for specified
  27. /// stack frame.
  28. /// </summary>
  29. private class StackTraceTest1 : TestCase {
  30. public StackTraceTest1(string name) : base(name) {}
  31. private StackTrace trace;
  32. private StackFrame frame;
  33. internal static ITest Suite
  34. {
  35. get
  36. {
  37. return new TestSuite(typeof(StackTraceTest1));
  38. }
  39. }
  40. protected override void SetUp() {
  41. frame = new StackFrame("dir/someFile",
  42. 13,
  43. 45);
  44. trace = new StackTrace(frame);
  45. }
  46. protected override void TearDown() {
  47. trace = null;
  48. }
  49. /// <summary>
  50. /// Tests whether getting number of frames works.
  51. /// </summary>
  52. public void TestFrameCount() {
  53. AssertEquals("Frame count",
  54. 1,
  55. trace.FrameCount);
  56. }
  57. /// <summary>
  58. /// Tests whether getting frames by index which is out of
  59. /// range works.
  60. /// </summary>
  61. public void TestGetFrameOutOfRange() {
  62. Assert("Frame with index -1 == null",
  63. (trace.GetFrame(-1) == null));
  64. Assert("Frame with index -129 = null",
  65. (trace.GetFrame(-129) == null));
  66. Assert("Frame with index 1 = null",
  67. (trace.GetFrame(1) == null));
  68. Assert("Frame with index 145 = null",
  69. (trace.GetFrame(145) == null));
  70. }
  71. /// <summary>
  72. /// Tests whether getting frames by index works.
  73. /// </summary>
  74. public void TestGetFrame() {
  75. AssertEquals("Frame with index 0",
  76. frame,
  77. trace.GetFrame(0));
  78. }
  79. }
  80. }
  81. }