[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestSize.cs
1 // Tests for System.Drawing.Size.cs
2 //
3 // Author: Ravindra (rkumar@novell.com)
4 //
5
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29
30 using NUnit.Framework;
31 using System;
32 using System.Drawing;
33 using System.Security.Permissions;
34
35 namespace MonoTests.System.Drawing 
36 {
37         [TestFixture]
38         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
39         public class SizeTest 
40         {
41                 Size sz1_1;
42                 Size sz1_0;
43                 Size sz0_1;
44
45                 [TearDown]
46                 public void TearDown () {}
47
48                 [SetUp]
49                 public void SetUp ()            
50                 {
51                         sz1_1 = new Size (1, 1);
52                         sz1_0 = new Size (1, 0);
53                         sz0_1 = new Size (0, 1);
54                 }
55
56                 [Test]
57                 public void TestConstructors ()
58                 {
59                         Size sz_wh = new Size (1, 5);
60                         Assert.AreEqual (1, sz_wh.Width, "C#1");
61                         Assert.AreEqual (5, sz_wh.Height, "C#2");
62
63                         Size sz_pt = new Size (new Point (1, 5));
64                         Assert.AreEqual (1, sz_pt.Width, "C#3");
65                         Assert.AreEqual (5, sz_pt.Height, "C#4");
66
67                         Assert.AreEqual (sz_wh, sz_pt, "C#5");
68                 }
69
70                 [Test]
71                 public void TestEmptyField () 
72                 {
73                         Size sz = new Size (0, 0);
74                         Assert.AreEqual (sz, Size.Empty, "EMP#1");
75                 }
76
77                 [Test]
78                 public void TestProperties () 
79                 {
80                         Size sz = new Size (0, 0);
81         
82                         Assert.IsTrue (sz.IsEmpty, "P#1");
83                         Assert.IsTrue (! sz1_1.IsEmpty, "P#2");
84                         Assert.AreEqual (1, sz1_0.Width, "P#3");
85                         Assert.AreEqual (1, sz0_1.Height, "P#4");
86                 }
87
88                 [Test]
89                 public void TestCeiling ()
90                 {
91                         SizeF sf = new SizeF (0.5F, 0.6F);
92                         Assert.AreEqual (sz1_1, Size.Ceiling (sf), "CL#1");
93
94                         sf = new SizeF (1.0F, 1.0F);
95                         Assert.AreEqual (sz1_1, Size.Ceiling (sf), "CL#2");
96                 }
97
98                 [Test]
99                 public void TestEquals () 
100                 {
101                         Assert.AreEqual (sz1_1, sz1_1, "EQ#1");
102                         Assert.AreEqual (sz1_1, new Size (1, 1), "EQ#2");
103                         Assert.IsTrue (! sz1_1.Equals (sz1_0), "EQ#3");
104                         Assert.IsTrue (! sz1_1.Equals (sz0_1), "EQ#4");
105                         Assert.IsTrue (! sz1_0.Equals (sz0_1), "EQ#5");
106                 }
107
108                 [Test]
109                 public void TestRound ()
110                 {
111                         SizeF sf = new SizeF (0.3F, 0.7F);
112                         Assert.AreEqual (sz0_1, Size.Round (sf), "CL#1");
113
114                         sf = new SizeF (0.6F, 0.6F);
115                         Assert.AreEqual (sz1_1, Size.Round (sf), "CL#2");
116
117                         sf = new SizeF (1.0F, 1.0F);
118                         Assert.AreEqual (sz1_1, Size.Round (sf), "CL#3");
119                 }
120
121                 
122                 [Test]
123                 public void TestTruncate ()
124                 {
125                         SizeF sf = new SizeF (0.8f, 1.3f);
126                         Assert.AreEqual (sz0_1, Size.Truncate (sf), "TR#1");
127
128                         sf = new SizeF (1.9f, 1.9f);
129                         Assert.AreEqual (sz1_1, Size.Truncate (sf), "TR#2");
130
131                         sf = new SizeF (1.0f, 1.0f);
132                         Assert.AreEqual (sz1_1, Size.Truncate (sf), "TR#3");
133                 }
134
135                 [Test]
136                 public void TestAddition ()
137                 {
138                         Assert.AreEqual (sz1_1, sz1_0 + sz0_1, "ADD#1");
139                         Assert.AreEqual (sz1_1, sz1_1 + new Size (0, 0), "ADD#2");
140                 }
141
142                 [Test]
143                 public void TestEqualityOp () 
144                 {
145                         Assert.IsTrue (sz1_1 == sz1_1, "EOP#1");
146                         Assert.IsTrue (sz1_1 == new Size (1, 1), "EOP#2");
147                         Assert.IsTrue (! (sz1_1 == sz1_0), "EOP#3");
148                         Assert.IsTrue (! (sz1_1 == sz0_1), "EOP#4");
149                         Assert.IsTrue (! (sz1_0 == sz0_1), "EOP#5");
150                 }
151
152                 [Test]
153                 public void TestInequalityOp () 
154                 {
155                         Assert.IsTrue (! (sz1_1 != sz1_1), "IOP#1");
156                         Assert.IsTrue (! (sz1_1 != new Size (1, 1)), "IOP#2");
157                         Assert.IsTrue (sz1_1 != sz1_0, "IOP#3");
158                         Assert.IsTrue (sz1_1 != sz0_1, "IOP#4");
159                         Assert.IsTrue (sz1_0 != sz0_1, "IOP#5");
160                 }
161         
162                 [Test]
163                 public void TestSubtraction () 
164                 {
165                         Assert.AreEqual (sz1_0, sz1_1 - sz0_1, "SUB#1");
166                         Assert.AreEqual (sz0_1, sz1_1 - sz1_0, "SUB#2");
167                 }
168
169                 [Test]
170                 public void TestSize2Point ()
171                 {
172                         Point pt1 = new Point (1, 1);
173                         Point pt2 = (Point) sz1_1;
174         
175                         Assert.AreEqual (pt1, pt2, "SZ2PT#1");
176                 }
177         
178                 [Test]
179                 public void TestSize2SizeF ()
180                 {
181                         SizeF sf1 = new SizeF (1.0F, 1.0F);
182                         SizeF sf2 = (SizeF) sz1_1;
183
184                         Assert.AreEqual (sf1, sf2, "SZ2SF#1");
185                 }
186
187                 [Test]
188                 public void ToStringTest ()
189                 {
190                         Assert.AreEqual (sz1_0.ToString (), "{Width=1, Height=0}");
191                         Assert.AreEqual (Size.Empty.ToString (), "{Width=0, Height=0}");
192                 }
193
194                 [Test]
195                 public void GetHashCodeTest ()
196                 {
197                         Assert.AreEqual (new Size (1, 0).GetHashCode (), sz1_0.GetHashCode (), "#1");
198                 }
199
200                 [Test]
201                 public void AddTest ()
202                 {
203                         Assert.AreEqual (sz1_1, Size.Add (sz1_0, sz0_1), "ADD#1");
204                         Assert.AreEqual (sz1_1, Size.Add (sz1_1, new Size (0, 0)), "ADD#2");
205                 }
206
207                 [Test]
208                 public void SubtractTest ()
209                 {
210                         Assert.AreEqual (sz1_0, Size.Subtract (sz1_1, sz0_1), "SUB#1");
211                         Assert.AreEqual (sz0_1, Size.Subtract (sz1_1, sz1_0), "SUB#2");
212                 }
213
214         }
215 }
216