2005-10-04 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestPoint.cs
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.
6
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.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.Drawing;
33 using System.Security.Permissions;
34
35 namespace MonoTests.System.Drawing{
36
37         [TestFixture]   
38         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
39         public class PointTest : Assertion {
40                 Point pt1_1;
41                 Point pt1_0;
42                 Point pt0_1;
43         
44                 [TearDown]
45                 public void Clean() {}
46                 
47                 [SetUp]
48                 public void GetReady()          
49                 {
50                         pt1_1 = new Point (1, 1);
51                         pt1_0 = new Point (1, 0);
52                         pt0_1 = new Point (0, 1);
53                 }
54                                 
55         
56                 [Test]
57                 public void EqualsTest () 
58                 {
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));
64                 }
65                 
66                 [Test]
67                 public void EqualityOpTest () 
68                 {
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));
74                 }
75
76                 [Test]
77                 public void InequalityOpTest () 
78                 {
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);
84                 }
85         
86                 [Test]
87                 public void CeilingTest () 
88                 {
89                         PointF ptf = new PointF (0.8f, 0.3f);
90                         AssertEquals (pt1_1, Point.Ceiling (ptf));
91                 }
92         
93                 [Test]
94                 public void RoundTest () 
95                 {
96                         PointF ptf = new PointF (0.8f, 1.3f);
97                         AssertEquals (pt1_1, Point.Round (ptf));
98                 }
99         
100                 [Test]
101                 public void TruncateTest () 
102                 {
103                         PointF ptf = new PointF (0.8f, 1.3f);
104                         AssertEquals (pt0_1, Point.Truncate (ptf));
105                 }
106         
107                 [Test]
108                 public void NullTest () 
109                 {
110                         Point pt = new Point (0, 0);
111                         AssertEquals (pt, Point.Empty);
112                 }
113         
114                 [Test]
115                 public void AdditionTest () 
116                 {
117                         AssertEquals (pt1_1, pt1_0 + new Size (0, 1));
118                         AssertEquals (pt1_1, pt0_1 + new Size (1, 0));
119                 }
120         
121                 [Test]
122                 public void SubtractionTest () 
123                 {
124                         AssertEquals (pt1_0, pt1_1 - new Size (0, 1));
125                         AssertEquals (pt0_1, pt1_1 - new Size (1, 0));
126                 }
127         
128                 [Test]
129                 public void Point2SizeTest () 
130                 {
131                         Size sz1 = new Size (1, 1);
132                         Size sz2 = (Size) pt1_1;
133         
134                         AssertEquals (sz1, sz2);
135                 }
136         
137                 [Test]
138                 public void Point2PointFTest () 
139                 {
140                         PointF ptf1 = new PointF (1, 1);
141                         PointF ptf2 = pt1_1;
142         
143                         AssertEquals (ptf1, ptf2);
144                 }
145         
146                 [Test]
147                 public void ConstructorTest () 
148                 {
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);
153         
154                         AssertEquals (pt_i, pt_sz);
155                         AssertEquals (pt_i, pt1_1);
156                         AssertEquals (pt_sz, pt1_1);
157                 }
158                 
159                 [Test]
160                 public void PropertyTest () 
161                 {
162                         Point pt = new Point (0, 0);
163         
164                         Assert (pt.IsEmpty);
165                         Assert (!pt1_1.IsEmpty);
166                         AssertEquals (1, pt1_0.X);
167                         AssertEquals (1, pt0_1.Y);
168                 }
169                 
170                 [Test]
171                 public void OffsetTest () 
172                 {
173                         Point pt = new Point (0, 0);
174                         pt.Offset (0, 1);
175                         AssertEquals (pt, pt0_1);
176                         pt.Offset (1, 0);
177                         AssertEquals (pt, pt1_1);
178                         pt.Offset (0, -1);
179                         AssertEquals (pt, pt1_0);
180                 }
181                 
182                 [Test]
183                 public void GetHashCodeTest ()
184                 {
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 ());
190                 }
191
192                 [Test]
193                 public void ToStringTest ()
194                 {
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 ());
198                 }
199         }
200 }
201