System.Drawing: added email to icon and test file headers
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestRectangleF.cs
1 // Tests for System.Drawing.RectangleF.cs
2
3 // Copyright (C) 2005, 2006 Novell, Inc (http://www.novell.com)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 // Author: Jordi Mas i Hernandez <jordi@ximian.com>
25 //
26
27 using NUnit.Framework;
28 using System;
29 using System.Drawing;
30 using System.Security.Permissions;
31
32 namespace MonoTests.System.Drawing
33 {
34
35         [TestFixture]
36         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
37         public class TestRectangleF {
38
39                 RectangleF rect_0;
40                 RectangleF rect_1;
41                 RectangleF rect_2;
42                 RectangleF rect_3;
43                 RectangleF rect_4;
44                 RectangleF rect_5;
45                 RectangleF rect_6;
46
47                 [SetUp]
48                 public void GetReady ()
49                 {
50                         rect_0 = new RectangleF (new PointF (10, 10), new SizeF (40, 40));
51                         rect_1 = new RectangleF (5, 5, 5, 5);
52                         rect_2 = RectangleF.Empty;
53                         rect_3 = new RectangleF (25, 25, 0, 0);
54                         rect_4 = new RectangleF (25, 252, 10, 20);
55                         rect_5 = new RectangleF (40, 40, 50, 50);
56                         rect_6 = new RectangleF (40, 40, 0, 50);
57                 }
58
59                 [Test]
60                 public void Contains ()
61                 {
62                         Assert.IsFalse (rect_0.Contains (5, 5), "a");
63                         Assert.IsTrue (rect_0.Contains (12, 12), "b");
64                         Assert.IsTrue (rect_0.Contains (10, 10), "c");
65                         Assert.IsFalse (rect_0.Contains (10, 50), "d");
66                         Assert.IsFalse (rect_0.Contains (10, 50F - float.Epsilon), "e");
67                         Assert.IsTrue (rect_0.Contains (10, 49.9F), "f");
68                         Assert.IsFalse (rect_0.Contains (50, 10), "g");
69                 }
70
71                 [Test]
72                 public void Empty ()
73                 {
74                         Assert.AreEqual (rect_2.X, 0, "X");
75                         Assert.AreEqual (rect_2.Y, 0, "Y");
76                         Assert.AreEqual (rect_2.Width, 0, "Width");
77                         Assert.AreEqual (rect_2.Height, 0, "Height");
78                 }
79
80                 [Test]
81                 public void IsEmpty ()
82                 {
83                         Assert.IsFalse (rect_0.IsEmpty, "0");
84                         Assert.IsTrue (rect_2.IsEmpty, "2");
85                         Assert.IsTrue (rect_3.IsEmpty, "3");
86                         Assert.IsTrue (rect_6.IsEmpty, "6");
87                         Assert.IsTrue (new RectangleF (0, 0, -1, -1).IsEmpty, "negative w/h");
88                 }
89
90                 [Test]
91                 public void GetContents () 
92                 {
93                         Assert.AreEqual (rect_4.Right, rect_4.X + rect_4.Width, "Right");
94                         Assert.AreEqual (rect_4.Left, rect_4.X, "Left");
95                         Assert.AreEqual (rect_4.Bottom, rect_4.Y + rect_4.Height, "Bottom");
96                         Assert.AreEqual (rect_4.Top, rect_4.Y, "Top");
97                 }
98
99                 [Test]
100                 public void IntersectsWith () 
101                 {
102                         Assert.IsFalse (rect_0.IntersectsWith (rect_1), "0 N 1");
103                         Assert.IsFalse (rect_0.IntersectsWith (rect_2), "0 N 2");
104                         Assert.IsTrue (rect_0.IntersectsWith (rect_5), "0 N 5");
105                         Assert.IsTrue (rect_5.IntersectsWith (rect_0), "5 N 0");
106                         Assert.IsFalse (rect_0.IntersectsWith (rect_4), "0 N 4");
107                 }
108
109                 [Test]
110                 public void Location () 
111                 {
112                         Assert.AreEqual (new PointF (25, 252), rect_4.Location, "Location");
113                         PointF p = new PointF (11, 121);
114                         rect_4.Location = p;
115                         Assert.AreEqual (p, rect_4.Location, "Localtion-2");
116                         Assert.AreEqual (rect_4.X, 11, "X");
117                         Assert.AreEqual (rect_4.Y, 121, "Y");
118                         rect_4.X = 10;
119                         rect_4.Y = 15;
120                         Assert.AreEqual (new PointF (10, 15), rect_4.Location, "Localtion-3");
121                 }
122
123                 [Test]
124                 public void Size () 
125                 {
126                         Assert.AreEqual (rect_4.Width, 10, "Width-1");
127                         Assert.AreEqual (rect_4.Height, 20, "Height-1");
128                         rect_4.Width = 40;
129                         rect_4.Height = 100;
130                         Assert.AreEqual (rect_4.Size, new SizeF (40, 100), "Size");
131                         rect_4.Size = new SizeF (1, 2);
132                         Assert.AreEqual (rect_4.Width, 1, "Width-2");
133                         Assert.AreEqual (rect_4.Height, 2, "Height-2");
134                 }
135
136                 [Test]
137                 public void GetHashCodeTest () 
138                 {
139                         Assert.IsTrue (rect_0.GetHashCode () != rect_1.GetHashCode ());
140                 }
141
142                 [Test]
143                 public void Inflate () 
144                 {
145                         rect_0.Inflate (new SizeF (8, 5));
146                         Assert.AreEqual (new RectangleF (2, 5, 56, 50), rect_0, "INF#1");
147                         rect_1.Inflate (4, 4);
148                         Assert.AreEqual (new RectangleF (1, 1, 13, 13), rect_1, "INF#2");
149                         Assert.AreEqual (new RectangleF (30, 20, 70, 90),
150                                 RectangleF.Inflate (rect_5, 10, 20), "INF#3");
151                         Assert.AreEqual (new RectangleF (40, 40, 50, 50), rect_5, "INF#4");
152                 }
153
154                 [Test]
155                 public void Intersect () 
156                 {
157                         Assert.AreEqual (new RectangleF (40, 40, 10, 10),
158                                 RectangleF.Intersect (rect_0, rect_5), "INT#1");
159                         Assert.AreEqual (new RectangleF (10, 10, 40, 40), rect_0, "INT#2");
160                         rect_0.Intersect (rect_5);
161                         Assert.AreEqual (new RectangleF (40, 40, 10, 10), rect_0, "INT#3");
162                         Assert.AreEqual (RectangleF.Empty, RectangleF.Intersect (rect_1, rect_5), "INT#4");
163                 }
164
165                 [Test]
166                 public void Offset () 
167                 {
168                         rect_0.Offset (5, 5);
169                         Assert.AreEqual (new RectangleF (15, 15, 40, 40), rect_0, "OFS#1");
170                         rect_1.Offset (new Point (7, 0));
171                         Assert.AreEqual (new RectangleF (12, 5, 5, 5), rect_1, "OFS#2");
172                 }
173
174                 [Test]
175                 public void ToStringTest () 
176                 {
177                         Assert.AreEqual ("{X=10,Y=10,Width=40,Height=40}", rect_0.ToString (), "0");
178                         Assert.AreEqual ("{X=5,Y=5,Width=5,Height=5}", rect_1.ToString (), "1");
179                         Assert.AreEqual ("{X=0,Y=0,Width=0,Height=0}", rect_2.ToString (), "2");
180                         Assert.AreEqual ("{X=25,Y=25,Width=0,Height=0}", rect_3.ToString (), "3");
181                 }
182
183                 [Test]
184                 public void RectangleToRectangleF ()
185                 {
186                         Rectangle r = new Rectangle (1, 2, 3, 4);
187                         RectangleF rf = r;
188                         Assert.AreEqual (new RectangleF (1F, 2F, 3F, 4F), rf);
189                 }
190
191                 [Test]
192                 public void Union () 
193                 {
194                         Assert.AreEqual (RectangleF.FromLTRB (5, 5, 50, 50), RectangleF.Union (rect_0, rect_1));
195                 }
196
197                 [Test]
198                 public void Operator_Equal ()
199                 {
200                         RectangleF r0 = new RectangleF (1, 2, 3, 4);
201                         RectangleF r1 = r0;
202                         Assert.IsTrue (r0 == r1, "self");
203                         Assert.IsFalse (r0 == new RectangleF (0, 2, 3, 4), "X");
204                         Assert.IsFalse (r0 == new RectangleF (1, 0, 3, 4), "Y");
205                         Assert.IsFalse (r0 == new RectangleF (1, 2, 0, 4), "Width");
206                         Assert.IsFalse (r0 == new RectangleF (1, 2, 3, 0), "Height");
207                 }
208
209                 [Test]
210                 public void Operator_NotEqual ()
211                 {
212                         RectangleF r0 = new RectangleF (1, 2, 3, 4);
213                         RectangleF r1 = r0;
214                         Assert.IsFalse (r0 != r1, "self");
215                         Assert.IsTrue (r0 != new RectangleF (0, 2, 3, 4), "X");
216                         Assert.IsTrue (r0 != new RectangleF (1, 0, 3, 4), "Y");
217                         Assert.IsTrue (r0 != new RectangleF (1, 2, 0, 4), "Width");
218                         Assert.IsTrue (r0 != new RectangleF (1, 2, 3, 0), "Height");
219                 }
220
221                 [Test]
222                 public void NegativeWidth ()
223                 {
224                         RectangleF r = new RectangleF (0, 0, -1, 10);
225                         Assert.AreEqual (0, r.X, "X");
226                         Assert.AreEqual (0, r.Y, "Y");
227                         Assert.AreEqual (-1, r.Width, "Width");
228                         Assert.AreEqual (10, r.Height, "Height");
229                 }
230
231                 [Test]
232                 public void NegativeHeight ()
233                 {
234                         RectangleF r = new RectangleF (10, 10, 10, -1);
235                         Assert.AreEqual (10, r.X, "X");
236                         Assert.AreEqual (10, r.Y, "Y");
237                         Assert.AreEqual (10, r.Width, "Width");
238                         Assert.AreEqual (-1, r.Height, "Height");
239                 }
240
241                 [Test]
242                 public void EdgeIntersection ()
243                 {
244                         // https://bugzilla.novell.com/show_bug.cgi?id=431587
245                         RectangleF one = new RectangleF(10, 10, 10, 10);
246                         RectangleF two = new RectangleF(20, 10, 10, 10);
247
248                         one.Intersect(two);
249                         Assert.IsTrue (one.IsEmpty, "Empty");
250                         Assert.AreEqual (20f, one.X, "X");
251                         Assert.AreEqual (10f, one.Y, "Y");
252                         Assert.AreEqual (0f, one.Width, "Width");
253                         Assert.AreEqual (10f, one.Height, "Height");
254                 }
255         }
256 }