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 #pragma warning disable 1718 // Comparison made to same variable
70 Assert.IsTrue (pt1_1 == pt1_1, "#1");
71 #pragma warning restore 1718
72 Assert.IsTrue (pt1_1 == new Point (1, 1), "#2");
73 Assert.IsTrue (!(pt1_1 == pt1_0), "#3");
74 Assert.IsTrue (!(pt1_1 == pt0_1), "#4");
75 Assert.IsTrue (!(pt1_0 == pt0_1), "#5");
79 public void InequalityOpTest ()
81 #pragma warning disable 1718 // Comparison made to same variable
82 Assert.IsTrue (!(pt1_1 != pt1_1), "#1");
83 #pragma warning restore 1718
84 Assert.IsTrue (!(pt1_1 != new Point (1, 1)), "#2");
85 Assert.IsTrue (pt1_1 != pt1_0, "#3");
86 Assert.IsTrue (pt1_1 != pt0_1, "#4");
87 Assert.IsTrue (pt1_0 != pt0_1, "#5");
91 public void CeilingTest ()
93 PointF ptf = new PointF (0.8f, 0.3f);
94 Assert.AreEqual (pt1_1, Point.Ceiling (ptf), "#1");
98 public void RoundTest ()
100 PointF ptf = new PointF (0.8f, 1.3f);
101 Assert.AreEqual (pt1_1, Point.Round (ptf), "#1");
105 public void TruncateTest ()
107 PointF ptf = new PointF (0.8f, 1.3f);
108 Assert.AreEqual (pt0_1, Point.Truncate (ptf), "#1");
112 public void NullTest ()
114 Point pt = new Point (0, 0);
115 Assert.AreEqual (pt, Point.Empty, "#1");
119 public void AdditionTest ()
121 Assert.AreEqual (pt1_1, pt1_0 + new Size (0, 1), "#1");
122 Assert.AreEqual (pt1_1, pt0_1 + new Size (1, 0), "#2");
126 public void SubtractionTest ()
128 Assert.AreEqual (pt1_0, pt1_1 - new Size (0, 1), "#1");
129 Assert.AreEqual (pt0_1, pt1_1 - new Size (1, 0), "#2");
133 public void Point2SizeTest ()
135 Size sz1 = new Size (1, 1);
136 Size sz2 = (Size) pt1_1;
138 Assert.AreEqual (sz1, sz2, "#1");
142 public void Point2PointFTest ()
144 PointF ptf1 = new PointF (1, 1);
147 Assert.AreEqual (ptf1, ptf2, "#1");
151 public void ConstructorTest ()
153 int i = (1 << 16) + 1;
154 Size sz = new Size (1, 1);
155 Point pt_i = new Point (i);
156 Point pt_sz = new Point (sz);
158 Assert.AreEqual (pt_i, pt_sz, "#1");
159 Assert.AreEqual (pt_i, pt1_1, "#2");
160 Assert.AreEqual (pt_sz, pt1_1, "#3");
164 public void ConstructorNegativeLocationTest ()
166 var pt = new Point (unchecked ((int) 0xffe0fc00));
168 Assert.AreEqual (-32, pt.Y, "#1"); // (short) 0xffe0
169 Assert.AreEqual (-1024, pt.X, "#2"); // (short) 0xfc00
173 public void PropertyTest ()
175 Point pt = new Point (0, 0);
177 Assert.IsTrue (pt.IsEmpty, "#1");
178 Assert.IsTrue (!pt1_1.IsEmpty, "#2");
179 Assert.AreEqual (1, pt1_0.X, "#3");
180 Assert.AreEqual (1, pt0_1.Y, "#4");
184 public void OffsetTest ()
186 Point pt = new Point (0, 0);
188 Assert.AreEqual (pt, pt0_1, "#1");
190 Assert.AreEqual (pt, pt1_1, "#2");
192 Assert.AreEqual (pt, pt1_0, "#3");
196 public void GetHashCodeTest ()
198 Assert.AreEqual (0, pt1_1.GetHashCode (), "#1");
199 Assert.AreEqual (1, pt1_0.GetHashCode (), "#2");
200 Assert.AreEqual (1, pt0_1.GetHashCode (), "#3");
201 Point pt = new Point(0xFF, 0xFF00);
202 Assert.AreEqual (0xFFFF, pt.GetHashCode (), "#4");
206 public void ToStringTest ()
208 Assert.AreEqual ("{X=1,Y=1}", pt1_1.ToString (), "#1");
209 Assert.AreEqual ("{X=1,Y=0}", pt1_0.ToString (), "#2");
210 Assert.AreEqual ("{X=0,Y=1}", pt0_1.ToString (), "#3");
214 public void AddTest ()
216 Assert.AreEqual (pt1_1, Point.Add (pt1_0, new Size (0, 1)), "#1");
217 Assert.AreEqual (pt1_1, Point.Add (pt0_1, new Size (1, 0)), "#2");
221 public void OffsetTestPoint ()
223 Point pt = new Point (0, 0);
224 pt.Offset (new Point (0, 1));
225 Assert.AreEqual (pt, pt0_1, "#1");
226 pt.Offset (new Point (1, 0));
227 Assert.AreEqual (pt, pt1_1, "#2");
228 pt.Offset (new Point (0, -1));
229 Assert.AreEqual (pt, pt1_0, "#3");
233 public void SubtractTest ()
235 Assert.AreEqual (pt1_0, Point.Subtract (pt1_1, new Size (0, 1)), "#1");
236 Assert.AreEqual (pt0_1, Point.Subtract (pt1_1, new Size (1, 0)), "#2");