2005-08-16 Marek Safar <marek.safar@seznam.cz>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestRectangleF.cs
1 // Tests for System.Drawing.RectangleF.cs
2
3 // Copyright (C) 2005 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
31 namespace MonoTests.System.Drawing
32 {
33
34         [TestFixture]
35         public class TestRectangleF : Assertion
36         {
37                 RectangleF rect_0;
38                 RectangleF rect_1;
39                 RectangleF rect_2;
40                 RectangleF rect_3;
41                 RectangleF rect_4;
42                 RectangleF rect_5;
43                 RectangleF rect_6;
44
45                 [TearDown]
46                 public void Clean () {}
47
48                 [SetUp]
49                 public void GetReady ()
50                 {
51                         rect_0 = new RectangleF (new PointF (10, 10), new SizeF (40, 40));
52                         rect_1 = new RectangleF (5, 5, 5, 5);
53                         rect_2 = RectangleF.Empty;
54                         rect_3 = new RectangleF (25, 25, 0, 0);
55                         rect_4 = new RectangleF (25, 252, 10, 20);
56                         rect_5 = new RectangleF (40, 40, 50, 50);
57                         rect_6 = new RectangleF (40, 40, 0, 50);
58                 }
59
60                 [Test]
61                 public void Contains ()
62                 {
63                         AssertEquals (false, rect_0.Contains (5, 5));
64                         AssertEquals (true, rect_0.Contains (12, 12));
65                         AssertEquals (true, rect_0.Contains (10, 10));
66                         AssertEquals (false, rect_0.Contains (10, 50));
67                         AssertEquals (false, rect_0.Contains (10, 50F-float.Epsilon));
68                         AssertEquals (true, rect_0.Contains (10, 49.9F));
69                         AssertEquals (false, rect_0.Contains (50, 10));
70                 }
71
72                 [Test]
73                 public void Empty ()
74                 {
75                         AssertEquals (rect_2.X, 0);
76                         AssertEquals (rect_2.Y, 0);
77                         AssertEquals (rect_2.Width, 0);
78                         AssertEquals (rect_2.Height, 0);
79                 }
80
81                 [Test]
82                 public void IsEmpty ()
83                 {
84                         AssertEquals (rect_0.IsEmpty, false);
85                         AssertEquals (rect_2.IsEmpty, true);
86                         AssertEquals (rect_3.IsEmpty, true);
87                         AssertEquals (rect_6.IsEmpty, true);
88                 }
89
90                 [Test]
91                 public void GetContents () {
92                         AssertEquals (rect_4.Right, rect_4.X + rect_4.Width);
93                         AssertEquals (rect_4.Left, rect_4.X);
94                         AssertEquals (rect_4.Bottom, rect_4.Y + rect_4.Height);
95                         AssertEquals (rect_4.Top, rect_4.Y);
96                 }
97
98                 [Test]
99                 public void IntersectsWith  () {                                                
100                         AssertEquals (rect_0.IntersectsWith (rect_1), false);
101                         AssertEquals (rect_0.IntersectsWith (rect_2), false);
102                         AssertEquals (rect_0.IntersectsWith (rect_5), true);
103                         AssertEquals (rect_5.IntersectsWith (rect_0), true);
104                         AssertEquals (rect_0.IntersectsWith (rect_4), false);
105                 }
106
107                 [Test]
108                 public void Location () {
109                         AssertEquals (new PointF (25, 252), rect_4.Location);
110                         PointF p = new PointF (11, 121);
111                         rect_4.Location = p;
112                         AssertEquals (p, rect_4.Location);
113                         AssertEquals (rect_4.X, 11);
114                         AssertEquals (rect_4.Y, 121);
115                         rect_4.X = 10;
116                         rect_4.Y = 15;
117                         AssertEquals (new PointF (10, 15), rect_4.Location);
118                 }
119
120                 [Test]
121                 public void Size () {
122                         AssertEquals (rect_4.Width, 10);
123                         AssertEquals (rect_4.Height, 20);
124                         rect_4.Width = 40;
125                         rect_4.Height = 100;
126                         AssertEquals (rect_4.Size, new SizeF (40, 100));
127                         rect_4.Size = new SizeF (1, 2);
128                         AssertEquals (rect_4.Width, 1);
129                         AssertEquals (rect_4.Height, 2);
130                 }
131
132                 [Test]
133                 public void GetHashCodeTest () {
134                         Assert ("GHC#1", rect_0.GetHashCode () != rect_1.GetHashCode ());
135                 }
136
137                 [Test]
138                 public void Inflate () {
139                         rect_0.Inflate (new SizeF (8, 5));
140                         AssertEquals ("INF#1", new RectangleF (2, 5, 56, 50), rect_0);
141                         rect_1.Inflate (4, 4);
142                         AssertEquals ("INF#2", new RectangleF (1, 1, 13, 13), rect_1);
143                         AssertEquals ("INF#3", new RectangleF (30, 20, 70, 90),
144                                 RectangleF.Inflate (rect_5, 10, 20));
145                         AssertEquals ("INF#4", new RectangleF (40, 40, 50, 50), rect_5);
146                 }
147
148                 [Test]
149                 public void Intersect () {
150                         AssertEquals ("INT#1", new RectangleF (40, 40, 10, 10), 
151                                 RectangleF.Intersect (rect_0, rect_5));
152                         AssertEquals ("INT#2", new RectangleF (10, 10, 40, 40), rect_0);
153                         rect_0.Intersect (rect_5);
154                         AssertEquals ("INT#3", new RectangleF (40, 40, 10, 10), rect_0);
155                         AssertEquals ("INT#4", RectangleF.Empty, RectangleF.Intersect (rect_1, rect_5));
156                 }
157
158                 [Test]
159                 public void Offset () {
160                         rect_0.Offset (5, 5);
161                         AssertEquals ("OFS#1", new RectangleF (15, 15, 40, 40), rect_0);
162                         rect_1.Offset (new Point (7, 0));
163                         AssertEquals ("OFS#2", new RectangleF (12, 5, 5, 5), rect_1);
164                 }
165
166                 [Test]
167                 public void ToStringTest () {
168                         AssertEquals ("{X=10,Y=10,Width=40,Height=40}", rect_0.ToString ());
169                         AssertEquals ("{X=5,Y=5,Width=5,Height=5}", rect_1.ToString ());
170                         AssertEquals ("{X=0,Y=0,Width=0,Height=0}", rect_2.ToString ());
171                         AssertEquals ("{X=25,Y=25,Width=0,Height=0}", rect_3.ToString ());
172                 }
173
174                 [Test]
175                 public void RectangleToRectangleF ()
176                 {
177                         Rectangle r = new Rectangle (1, 2, 3, 4);
178                         RectangleF rf = r;
179                         AssertEquals (new RectangleF (1F, 2F, 3F, 4F), rf);
180                 }
181
182                 [Test]
183                 public void Union () {
184                         AssertEquals (RectangleF.FromLTRB (5, 5, 50, 50), RectangleF.Union (rect_0, rect_1));
185                 }
186         }
187 }
188