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