1 // Tests for System.Drawing.Point.cs
3 // Author: Mike Kestner (mkestner@speakeasy.net)
4 // Improvements by Jordi Mas i Hernàndez <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 : Assertion {
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 AssertEquals (pt1_1, pt1_1);
60 AssertEquals (pt1_1, new Point (1, 1));
61 Assert (!pt1_1.Equals (pt1_0));
62 Assert (!pt1_1.Equals (pt0_1));
63 Assert (!pt1_0.Equals (pt0_1));
67 public void EqualityOpTest ()
69 Assert (pt1_1 == pt1_1);
70 Assert (pt1_1 == new Point (1, 1));
71 Assert (!(pt1_1 == pt1_0));
72 Assert (!(pt1_1 == pt0_1));
73 Assert (!(pt1_0 == pt0_1));
77 public void InequalityOpTest ()
79 Assert (!(pt1_1 != pt1_1));
80 Assert (!(pt1_1 != new Point (1, 1)));
81 Assert (pt1_1 != pt1_0);
82 Assert (pt1_1 != pt0_1);
83 Assert (pt1_0 != pt0_1);
87 public void CeilingTest ()
89 PointF ptf = new PointF (0.8f, 0.3f);
90 AssertEquals (pt1_1, Point.Ceiling (ptf));
94 public void RoundTest ()
96 PointF ptf = new PointF (0.8f, 1.3f);
97 AssertEquals (pt1_1, Point.Round (ptf));
101 public void TruncateTest ()
103 PointF ptf = new PointF (0.8f, 1.3f);
104 AssertEquals (pt0_1, Point.Truncate (ptf));
108 public void NullTest ()
110 Point pt = new Point (0, 0);
111 AssertEquals (pt, Point.Empty);
115 public void AdditionTest ()
117 AssertEquals (pt1_1, pt1_0 + new Size (0, 1));
118 AssertEquals (pt1_1, pt0_1 + new Size (1, 0));
122 public void SubtractionTest ()
124 AssertEquals (pt1_0, pt1_1 - new Size (0, 1));
125 AssertEquals (pt0_1, pt1_1 - new Size (1, 0));
129 public void Point2SizeTest ()
131 Size sz1 = new Size (1, 1);
132 Size sz2 = (Size) pt1_1;
134 AssertEquals (sz1, sz2);
138 public void Point2PointFTest ()
140 PointF ptf1 = new PointF (1, 1);
143 AssertEquals (ptf1, ptf2);
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 AssertEquals (pt_i, pt_sz);
155 AssertEquals (pt_i, pt1_1);
156 AssertEquals (pt_sz, pt1_1);
160 public void PropertyTest ()
162 Point pt = new Point (0, 0);
165 Assert (!pt1_1.IsEmpty);
166 AssertEquals (1, pt1_0.X);
167 AssertEquals (1, pt0_1.Y);
171 public void OffsetTest ()
173 Point pt = new Point (0, 0);
175 AssertEquals (pt, pt0_1);
177 AssertEquals (pt, pt1_1);
179 AssertEquals (pt, pt1_0);
183 public void GetHashCodeTest ()
185 AssertEquals (0, pt1_1.GetHashCode ());
186 AssertEquals (1, pt1_0.GetHashCode ());
187 AssertEquals (1, pt0_1.GetHashCode ());
188 Point pt = new Point(0xFF, 0xFF00);
189 AssertEquals (0xFFFF, pt.GetHashCode ());
193 public void ToStringTest ()
195 AssertEquals ("{X=1,Y=1}", pt1_1.ToString ());
196 AssertEquals ("{X=1,Y=0}", pt1_0.ToString ());
197 AssertEquals ("{X=0,Y=1}", pt0_1.ToString ());