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