1 // Tests for System.Drawing.Size.cs
3 // Author: Ravindra (rkumar@novell.com)
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // 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 SizeTest : Assertion
46 public void TearDown () {}
51 sz1_1 = new Size (1, 1);
52 sz1_0 = new Size (1, 0);
53 sz0_1 = new Size (0, 1);
57 public void TestConstructors ()
59 Size sz_wh = new Size (1, 5);
60 AssertEquals ("C#1", 1, sz_wh.Width);
61 AssertEquals ("C#2", 5, sz_wh.Height);
63 Size sz_pt = new Size (new Point (1, 5));
64 AssertEquals ("C#3", 1, sz_pt.Width);
65 AssertEquals ("C#4", 5, sz_pt.Height);
67 AssertEquals ("C#5", sz_wh, sz_pt);
71 public void TestEmptyField ()
73 Size sz = new Size (0, 0);
74 AssertEquals ("EMP#1", sz, Size.Empty);
78 public void TestProperties ()
80 Size sz = new Size (0, 0);
82 Assert ("P#1", sz.IsEmpty);
83 Assert ("P#2", ! sz1_1.IsEmpty);
84 AssertEquals ("P#3", 1, sz1_0.Width);
85 AssertEquals ("P#4", 1, sz0_1.Height);
89 public void TestCeiling ()
91 SizeF sf = new SizeF (0.5F, 0.6F);
92 AssertEquals ("CL#1", sz1_1, Size.Ceiling (sf));
94 sf = new SizeF (1.0F, 1.0F);
95 AssertEquals ("CL#2", sz1_1, Size.Ceiling (sf));
99 public void TestEquals ()
101 AssertEquals ("EQ#1", sz1_1, sz1_1);
102 AssertEquals ("EQ#2", sz1_1, new Size (1, 1));
103 Assert ("EQ#3", ! sz1_1.Equals (sz1_0));
104 Assert ("EQ#4", ! sz1_1.Equals (sz0_1));
105 Assert ("EQ#5", ! sz1_0.Equals (sz0_1));
109 public void TestRound ()
111 SizeF sf = new SizeF (0.3F, 0.7F);
112 AssertEquals ("CL#1", sz0_1, Size.Round (sf));
114 sf = new SizeF (0.6F, 0.6F);
115 AssertEquals ("CL#2", sz1_1, Size.Round (sf));
117 sf = new SizeF (1.0F, 1.0F);
118 AssertEquals ("CL#3", sz1_1, Size.Round (sf));
123 public void TestTruncate ()
125 SizeF sf = new SizeF (0.8f, 1.3f);
126 AssertEquals ("TR#1", sz0_1, Size.Truncate (sf));
128 sf = new SizeF (1.9f, 1.9f);
129 AssertEquals ("TR#2", sz1_1, Size.Truncate (sf));
131 sf = new SizeF (1.0f, 1.0f);
132 AssertEquals ("TR#3", sz1_1, Size.Truncate (sf));
136 public void TestAddition ()
138 AssertEquals ("ADD#1", sz1_1, sz1_0 + sz0_1);
139 AssertEquals ("ADD#2", sz1_1, sz1_1 + new Size (0, 0));
143 public void TestEqualityOp ()
145 Assert ("EOP#1", sz1_1 == sz1_1);
146 Assert ("EOP#2", sz1_1 == new Size (1, 1));
147 Assert ("EOP#3", ! (sz1_1 == sz1_0));
148 Assert ("EOP#4", ! (sz1_1 == sz0_1));
149 Assert ("EOP#5", ! (sz1_0 == sz0_1));
153 public void TestInequalityOp ()
155 Assert ("IOP#1", ! (sz1_1 != sz1_1));
156 Assert ("IOP#2", ! (sz1_1 != new Size (1, 1)));
157 Assert ("IOP#3", sz1_1 != sz1_0);
158 Assert ("IOP#4", sz1_1 != sz0_1);
159 Assert ("IOP#5", sz1_0 != sz0_1);
163 public void TestSubtraction ()
165 AssertEquals ("SUB#1", sz1_0, sz1_1 - sz0_1);
166 AssertEquals ("SUB#2", sz0_1, sz1_1 - sz1_0);
170 public void TestSize2Point ()
172 Point pt1 = new Point (1, 1);
173 Point pt2 = (Point) sz1_1;
175 AssertEquals ("SZ2PT#1", pt1, pt2);
179 public void TestSize2SizeF ()
181 SizeF sf1 = new SizeF (1.0F, 1.0F);
182 SizeF sf2 = (SizeF) sz1_1;
184 AssertEquals ("SZ2SF#1", sf1, sf2);
188 public void ToStringTest ()
190 AssertEquals ("{Width=1, Height=0}", sz1_0.ToString ());
191 AssertEquals ("{Width=0, Height=0}", Size.Empty.ToString ());
195 public void GetHashCodeTest ()
197 AssertEquals (new Size (1, 0).GetHashCode (), sz1_0.GetHashCode ());