Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ObjectTest.cs « System « Test « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5a9545f390a1b114068f7e98ec3f25d396fe52b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// ObjectTest.cs - NUnit Test Cases for the System.Object struct
//
// David Brandt (bucky@keystreams.com)
//
// (C) Ximian, Inc.  http://www.ximian.com
// 

using NUnit.Framework;
using System;
using System.Globalization;

namespace MonoTests.System
{

public class ObjectTest : TestCase
{
	public ObjectTest() : base ("MonoTests.System.ObjectTest testsuite") {}
	public ObjectTest(string name) : base(name) {}

	protected override void SetUp() 
	{
	}

	protected override void TearDown() 
	{
	}

	public static ITest Suite {
		get { 
			return new TestSuite(typeof(ObjectTest)); 
		}
	}

	public void TestCtor() {
		Object o = new Object();
		AssertNotNull("Can I at least get an _Object_, please?", o);
	}

	public void TestEquals1() {
		{
			Object x = new Object();
			Object y = new Object();
			Assert("Object should equal itself",
			       x.Equals(x));
			Assert("object should not equal null",
			       !x.Equals(null));
			Assert("Different objects should not equal 1",
			       !x.Equals(y));
			Assert("Different objects should not equal 2",
			       !y.Equals(x));
		}
		{
			double x = Double.NaN;
			double y = Double.NaN;
			Assert("NaNs should always equal each other",
			       ((Object)x).Equals(y));
		}
	}
	public void TestEquals2() {
		{
			Object x = new Object();
			Object y = new Object();
			Assert("Object should equal itself",
			       Object.Equals(x,x));
			Assert("object should not equal null",
			       !Object.Equals(x,null));
			Assert("null should not equal object",
			       !Object.Equals(null,x));
			Assert("Different objects should not equal 1",
			       !Object.Equals(x,y));
			Assert("Different objects should not equal 2",
			       !Object.Equals(y,x));
			Assert("null should not equal null",
			       Object.Equals(null,null));
		}
		{
			double x = Double.NaN;
			double y = Double.NaN;
			Assert("NaNs should always equal each other",
			       Object.Equals(x,y));
		}
	}

	public void TestGetHashCode() {
		Object x = new Object();
		AssertEquals("Object's hash code should not change",
			     x.GetHashCode(), x.GetHashCode());
	}

	public void TestGetType() {
		Object x = new Object();
		AssertNotNull("Should get a type for Object", x.GetType());
		AssertEquals("Bad name for Object type", "System.Object",
			     x.GetType().ToString());
	}

	public void TestReferenceEquals() {
		Object x = new Object();
		Object y = new Object();
		Assert("Object should equal itself",
		       Object.ReferenceEquals(x,x));
		Assert("object should not equal null",
		       !Object.ReferenceEquals(x,null));
		Assert("null should not equal object",
		       !Object.ReferenceEquals(null,x));
		Assert("Different objects should not equal 1",
		       !Object.ReferenceEquals(x,y));
		Assert("Different objects should not equal 2",
		       !Object.ReferenceEquals(y,x));
		Assert("null should not equal null",
		       Object.ReferenceEquals(null,null));
	}

	public void TestToString() {
		Object x = new Object();
		Object y = new Object();
		AssertEquals("All Objects should have same string rep",
			     x.ToString(), y.ToString());
	}
}
}