ObjectTest.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // ObjectTest.cs - NUnit Test Cases for the System.Object struct
  2. //
  3. // David Brandt ([email protected])
  4. //
  5. // (C) Ximian, Inc. http://www.ximian.com
  6. //
  7. using NUnit.Framework;
  8. using System;
  9. using System.Globalization;
  10. namespace MonoTests.System
  11. {
  12. public class ObjectTest : TestCase
  13. {
  14. public ObjectTest() {}
  15. protected override void SetUp()
  16. {
  17. }
  18. protected override void TearDown()
  19. {
  20. }
  21. public void TestCtor() {
  22. Object o = new Object();
  23. AssertNotNull("Can I at least get an _Object_, please?", o);
  24. }
  25. public void TestEquals1() {
  26. {
  27. Object x = new Object();
  28. Object y = new Object();
  29. Assert("Object should equal itself",
  30. x.Equals(x));
  31. Assert("object should not equal null",
  32. !x.Equals(null));
  33. Assert("Different objects should not equal 1",
  34. !x.Equals(y));
  35. Assert("Different objects should not equal 2",
  36. !y.Equals(x));
  37. }
  38. {
  39. double x = Double.NaN;
  40. double y = Double.NaN;
  41. Assert("NaNs should always equal each other",
  42. ((Object)x).Equals(y));
  43. }
  44. }
  45. public void TestEquals2() {
  46. {
  47. Object x = new Object();
  48. Object y = new Object();
  49. Assert("Object should equal itself",
  50. Object.Equals(x,x));
  51. Assert("object should not equal null",
  52. !Object.Equals(x,null));
  53. Assert("null should not equal object",
  54. !Object.Equals(null,x));
  55. Assert("Different objects should not equal 1",
  56. !Object.Equals(x,y));
  57. Assert("Different objects should not equal 2",
  58. !Object.Equals(y,x));
  59. Assert("null should not equal null",
  60. Object.Equals(null,null));
  61. }
  62. {
  63. double x = Double.NaN;
  64. double y = Double.NaN;
  65. Assert("NaNs should always equal each other",
  66. Object.Equals(x,y));
  67. }
  68. }
  69. public void TestGetHashCode() {
  70. Object x = new Object();
  71. AssertEquals("Object's hash code should not change",
  72. x.GetHashCode(), x.GetHashCode());
  73. }
  74. public void TestGetType() {
  75. Object x = new Object();
  76. AssertNotNull("Should get a type for Object", x.GetType());
  77. AssertEquals("Bad name for Object type", "System.Object",
  78. x.GetType().ToString());
  79. }
  80. public void TestReferenceEquals() {
  81. Object x = new Object();
  82. Object y = new Object();
  83. Assert("Object should equal itself",
  84. Object.ReferenceEquals(x,x));
  85. Assert("object should not equal null",
  86. !Object.ReferenceEquals(x,null));
  87. Assert("null should not equal object",
  88. !Object.ReferenceEquals(null,x));
  89. Assert("Different objects should not equal 1",
  90. !Object.ReferenceEquals(x,y));
  91. Assert("Different objects should not equal 2",
  92. !Object.ReferenceEquals(y,x));
  93. Assert("null should not equal null",
  94. Object.ReferenceEquals(null,null));
  95. }
  96. public void TestToString() {
  97. Object x = new Object();
  98. Object y = new Object();
  99. AssertEquals("All Objects should have same string rep",
  100. x.ToString(), y.ToString());
  101. }
  102. }
  103. }