**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Drawing / Test / System.Drawing / TestPoint.cs
blob126a08461a1e3040759223b825f2fe98d64b5beb
1 // Tests for System.Drawing.Point.cs
2 //
3 // Author: Mike Kestner (mkestner@speakeasy.net)
4 // Improvements by Jordi Mas i Hernàndez <jmas@softcatala.org>
5 // Copyright (c) 2001 Ximian, Inc.
7 //
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 //
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:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
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;
31 using System;
32 using System.Drawing;
34 namespace MonoTests.System.Drawing{
36 [TestFixture]
37 public class PointTest : Assertion {
38 Point pt1_1;
39 Point pt1_0;
40 Point pt0_1;
42 [TearDown]
43 public void Clean() {}
45 [SetUp]
46 public void GetReady()
48 pt1_1 = new Point (1, 1);
49 pt1_0 = new Point (1, 0);
50 pt0_1 = new Point (0, 1);
54 [Test]
55 public void EqualsTest ()
57 AssertEquals (pt1_1, pt1_1);
58 AssertEquals (pt1_1, new Point (1, 1));
59 Assert (!pt1_1.Equals (pt1_0));
60 Assert (!pt1_1.Equals (pt0_1));
61 Assert (!pt1_0.Equals (pt0_1));
64 [Test]
65 public void EqualityOpTest ()
67 Assert (pt1_1 == pt1_1);
68 Assert (pt1_1 == new Point (1, 1));
69 Assert (!(pt1_1 == pt1_0));
70 Assert (!(pt1_1 == pt0_1));
71 Assert (!(pt1_0 == pt0_1));
74 [Test]
75 public void InequalityOpTest ()
77 Assert (!(pt1_1 != pt1_1));
78 Assert (!(pt1_1 != new Point (1, 1)));
79 Assert (pt1_1 != pt1_0);
80 Assert (pt1_1 != pt0_1);
81 Assert (pt1_0 != pt0_1);
84 [Test]
85 public void CeilingTest ()
87 PointF ptf = new PointF (0.8f, 0.3f);
88 AssertEquals (pt1_1, Point.Ceiling (ptf));
91 [Test]
92 public void RoundTest ()
94 PointF ptf = new PointF (0.8f, 1.3f);
95 AssertEquals (pt1_1, Point.Round (ptf));
98 [Test]
99 public void TruncateTest ()
101 PointF ptf = new PointF (0.8f, 1.3f);
102 AssertEquals (pt0_1, Point.Truncate (ptf));
105 [Test]
106 public void NullTest ()
108 Point pt = new Point (0, 0);
109 AssertEquals (pt, Point.Empty);
112 [Test]
113 public void AdditionTest ()
115 AssertEquals (pt1_1, pt1_0 + new Size (0, 1));
116 AssertEquals (pt1_1, pt0_1 + new Size (1, 0));
119 [Test]
120 public void SubtractionTest ()
122 AssertEquals (pt1_0, pt1_1 - new Size (0, 1));
123 AssertEquals (pt0_1, pt1_1 - new Size (1, 0));
126 [Test]
127 public void Point2SizeTest ()
129 Size sz1 = new Size (1, 1);
130 Size sz2 = (Size) pt1_1;
132 AssertEquals (sz1, sz2);
135 [Test]
136 public void Point2PointFTest ()
138 PointF ptf1 = new PointF (1, 1);
139 PointF ptf2 = pt1_1;
141 AssertEquals (ptf1, ptf2);
144 [Test]
145 public void ConstructorTest ()
147 int i = (1 << 16) + 1;
148 Size sz = new Size (1, 1);
149 Point pt_i = new Point (i);
150 Point pt_sz = new Point (sz);
152 AssertEquals (pt_i, pt_sz);
153 AssertEquals (pt_i, pt1_1);
154 AssertEquals (pt_sz, pt1_1);
157 [Test]
158 public void PropertyTest ()
160 Point pt = new Point (0, 0);
162 Assert (pt.IsEmpty);
163 Assert (!pt1_1.IsEmpty);
164 AssertEquals (1, pt1_0.X);
165 AssertEquals (1, pt0_1.Y);
168 [Test]
169 public void OffsetTest ()
171 Point pt = new Point (0, 0);
172 pt.Offset (0, 1);
173 AssertEquals (pt, pt0_1);
174 pt.Offset (1, 0);
175 AssertEquals (pt, pt1_1);
176 pt.Offset (0, -1);
177 AssertEquals (pt, pt1_0);