1 // Tests for System.Drawing.Point.cs
3 // Author: Mike Kestner (mkestner@speakeasy.net)
4 // Improvements by Jordi Mas i Hernandez <jmas@softcatala.org>
5 // Copyright (c) 2001 Ximian, Inc.
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
33 using System.Security.Permissions;
35 namespace MonoTests.System.Drawing{
38 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
39 public class PointTest {
45 public void Clean() {}
48 public void GetReady()
50 pt1_1 = new Point (1, 1);
51 pt1_0 = new Point (1, 0);
52 pt0_1 = new Point (0, 1);
57 public void EqualsTest ()
59 Assert.AreEqual (pt1_1, pt1_1, "#1");
60 Assert.AreEqual (pt1_1, new Point (1, 1), "#2");
61 Assert.IsTrue (!pt1_1.Equals (pt1_0), "#3");
62 Assert.IsTrue (!pt1_1.Equals (pt0_1), "#4");
63 Assert.IsTrue (!pt1_0.Equals (pt0_1), "#5");
67 public void EqualityOpTest ()
69 Assert.IsTrue (pt1_1 == pt1_1, "#1");
70 Assert.IsTrue (pt1_1 == new Point (1, 1), "#2");
71 Assert.IsTrue (!(pt1_1 == pt1_0), "#3");
72 Assert.IsTrue (!(pt1_1 == pt0_1), "#4");
73 Assert.IsTrue (!(pt1_0 == pt0_1), "#5");
77 public void InequalityOpTest ()
79 Assert.IsTrue (!(pt1_1 != pt1_1), "#1");
80 Assert.IsTrue (!(pt1_1 != new Point (1, 1)), "#2");
81 Assert.IsTrue (pt1_1 != pt1_0, "#3");
82 Assert.IsTrue (pt1_1 != pt0_1, "#4");
83 Assert.IsTrue (pt1_0 != pt0_1, "#5");
87 public void CeilingTest ()
89 PointF ptf = new PointF (0.8f, 0.3f);
90 Assert.AreEqual (pt1_1, Point.Ceiling (ptf), "#1");
94 public void RoundTest ()
96 PointF ptf = new PointF (0.8f, 1.3f);
97 Assert.AreEqual (pt1_1, Point.Round (ptf), "#1");
101 public void TruncateTest ()
103 PointF ptf = new PointF (0.8f, 1.3f);
104 Assert.AreEqual (pt0_1, Point.Truncate (ptf), "#1");
108 public void NullTest ()
110 Point pt = new Point (0, 0);
111 Assert.AreEqual (pt, Point.Empty, "#1");
115 public void AdditionTest ()
117 Assert.AreEqual (pt1_1, pt1_0 + new Size (0, 1), "#1");
118 Assert.AreEqual (pt1_1, pt0_1 + new Size (1, 0), "#2");
122 public void SubtractionTest ()
124 Assert.AreEqual (pt1_0, pt1_1 - new Size (0, 1), "#1");
125 Assert.AreEqual (pt0_1, pt1_1 - new Size (1, 0), "#2");
129 public void Point2SizeTest ()
131 Size sz1 = new Size (1, 1);
132 Size sz2 = (Size) pt1_1;
134 Assert.AreEqual (sz1, sz2, "#1");
138 public void Point2PointFTest ()
140 PointF ptf1 = new PointF (1, 1);
143 Assert.AreEqual (ptf1, ptf2, "#1");
147 public void ConstructorTest ()
149 int i = (1 << 16) + 1;
150 Size sz = new Size (1, 1);
151 Point pt_i = new Point (i);
152 Point pt_sz = new Point (sz);
154 Assert.AreEqual (pt_i, pt_sz, "#1");
155 Assert.AreEqual (pt_i, pt1_1, "#2");
156 Assert.AreEqual (pt_sz, pt1_1, "#3");
160 public void PropertyTest ()
162 Point pt = new Point (0, 0);
164 Assert.IsTrue (pt.IsEmpty, "#1");
165 Assert.IsTrue (!pt1_1.IsEmpty, "#2");
166 Assert.AreEqual (1, pt1_0.X, "#3");
167 Assert.AreEqual (1, pt0_1.Y, "#4");
171 public void OffsetTest ()
173 Point pt = new Point (0, 0);
175 Assert.AreEqual (pt, pt0_1, "#1");
177 Assert.AreEqual (pt, pt1_1, "#2");
179 Assert.AreEqual (pt, pt1_0, "#3");
183 public void GetHashCodeTest ()
185 Assert.AreEqual (0, pt1_1.GetHashCode (), "#1");
186 Assert.AreEqual (1, pt1_0.GetHashCode (), "#2");
187 Assert.AreEqual (1, pt0_1.GetHashCode (), "#3");
188 Point pt = new Point(0xFF, 0xFF00);
189 Assert.AreEqual (0xFFFF, pt.GetHashCode (), "#4");
193 public void ToStringTest ()
195 Assert.AreEqual ("{X=1,Y=1}", pt1_1.ToString (), "#1");
196 Assert.AreEqual ("{X=1,Y=0}", pt1_0.ToString (), "#2");
197 Assert.AreEqual ("{X=0,Y=1}", pt0_1.ToString (), "#3");
201 public void AddTest ()
203 Assert.AreEqual (pt1_1, Point.Add (pt1_0, new Size (0, 1)), "#1");
204 Assert.AreEqual (pt1_1, Point.Add (pt0_1, new Size (1, 0)), "#2");
208 public void OffsetTestPoint ()
210 Point pt = new Point (0, 0);
211 pt.Offset (new Point (0, 1));
212 Assert.AreEqual (pt, pt0_1, "#1");
213 pt.Offset (new Point (1, 0));
214 Assert.AreEqual (pt, pt1_1, "#2");
215 pt.Offset (new Point (0, -1));
216 Assert.AreEqual (pt, pt1_0, "#3");
220 public void SubtractTest ()
222 Assert.AreEqual (pt1_0, Point.Subtract (pt1_1, new Size (0, 1)), "#1");
223 Assert.AreEqual (pt0_1, Point.Subtract (pt1_1, new Size (1, 0)), "#2");