1 // Tests for System.Drawing.RectangleF.cs
3 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
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.
24 // Author: Jordi Mas i Hernandez <jordi@ximian.com>
27 using NUnit.Framework;
30 using System.Security.Permissions;
32 namespace MonoTests.System.Drawing
36 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
37 public class TestRectangleF : Assertion
48 public void Clean () {}
51 public void GetReady ()
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);
63 public void Contains ()
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));
77 AssertEquals (rect_2.X, 0);
78 AssertEquals (rect_2.Y, 0);
79 AssertEquals (rect_2.Width, 0);
80 AssertEquals (rect_2.Height, 0);
84 public void IsEmpty ()
86 AssertEquals (rect_0.IsEmpty, false);
87 AssertEquals (rect_2.IsEmpty, true);
88 AssertEquals (rect_3.IsEmpty, true);
89 AssertEquals (rect_6.IsEmpty, true);
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);
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);
110 public void Location () {
111 AssertEquals (new PointF (25, 252), rect_4.Location);
112 PointF p = new PointF (11, 121);
114 AssertEquals (p, rect_4.Location);
115 AssertEquals (rect_4.X, 11);
116 AssertEquals (rect_4.Y, 121);
119 AssertEquals (new PointF (10, 15), rect_4.Location);
123 public void Size () {
124 AssertEquals (rect_4.Width, 10);
125 AssertEquals (rect_4.Height, 20);
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);
135 public void GetHashCodeTest () {
136 Assert ("GHC#1", rect_0.GetHashCode () != rect_1.GetHashCode ());
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);
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));
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);
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 ());
177 public void RectangleToRectangleF ()
179 Rectangle r = new Rectangle (1, 2, 3, 4);
181 AssertEquals (new RectangleF (1F, 2F, 3F, 4F), rf);
185 public void Union () {
186 AssertEquals (RectangleF.FromLTRB (5, 5, 50, 50), RectangleF.Union (rect_0, rect_1));