[mkbundle] Fixes the embedding of dependency assemblies + test
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestSizeF.cs
1 // Tests for System.Drawing.SizeF.cs
2 //
3 // Author: Ravindra (rkumar@novell.com)
4 //
5 //      Modified TestPoint.cs for testing SizeF.cs.
6 //
7
8 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.Drawing;
33 using System.Security.Permissions;
34 using System.Globalization;
35 using System.Threading;
36
37 using NUnit.Framework;
38
39 namespace MonoTests.System.Drawing 
40 {
41         [TestFixture]   
42         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
43         public class SizeFTest
44         {
45                 SizeF sz11_99;
46                 SizeF sz11_0;
47                 SizeF sz0_11;
48
49                 [SetUp]
50                 public void SetUp ()
51                 {
52                         sz11_99 = new SizeF (1.1F, 9.9F);
53                         sz11_0 = new SizeF (1.1F, 0F);
54                         sz0_11 = new SizeF (0F, 1.1F);
55                 }
56
57                 [Test]
58                 public void TestConstructors ()
59                 {
60                         SizeF sz_wh = new SizeF (1.5F, 5.8F);
61                         Assert.AreEqual (1.5F, sz_wh.Width, "C#1");
62                         Assert.AreEqual (5.8F, sz_wh.Height, "C#2");
63
64                         SizeF sz_pf = new SizeF (new PointF (1.5F, 5.8F));
65                         Assert.AreEqual (1.5F, sz_pf.Width, "C#3");
66                         Assert.AreEqual (5.8F, sz_pf.Height, "C#4");
67
68                         SizeF sz_sz = new SizeF (sz_wh);
69                         Assert.AreEqual (1.5F, sz_sz.Width, "C#5");
70                         Assert.AreEqual (5.8F, sz_sz.Height, "C#6");
71
72                         Assert.AreEqual (sz_wh, sz_pf, "C#7");
73                         Assert.AreEqual (sz_pf, sz_sz, "C#8");
74                         Assert.AreEqual (sz_wh, sz_sz, "C#9");
75                 }
76
77                 [Test]
78                 public void TestEmptyField () 
79                 {
80                         SizeF sz = new SizeF (0.0F, 0.0F);
81                         Assert.AreEqual (sz, SizeF.Empty, "EMP#1");
82                 }
83
84                 [Test]
85                 public void TestProperties () 
86                 {
87                         SizeF sz = new SizeF (0.0F, 0.0F);
88
89                         Assert.IsTrue (sz.IsEmpty, "P#1");
90                         Assert.IsFalse (sz11_99.IsEmpty, "P#2");
91                         Assert.AreEqual (1.1F, sz11_0.Width, "P#3");
92                         Assert.AreEqual (1.1F, sz0_11.Height, "P#4");
93                 }
94
95                 [Test]
96                 public void TestEquals () 
97                 {
98                         Assert.AreEqual (sz11_99, sz11_99, "EQ#1");
99                         Assert.AreEqual (sz11_99, new SizeF (1.1F, 9.9F), "EQ#2");
100                         Assert.IsFalse (sz11_99.Equals (sz11_0), "EQ#3");
101                         Assert.IsFalse (sz11_99.Equals (sz0_11), "EQ#4");
102                         Assert.IsFalse (sz11_0.Equals (sz0_11), "EQ#5");
103                 }
104
105                 [Test]
106                 public void Test2PointF ()
107                 {
108                         PointF p1 = new PointF (1.1F, 9.9F);
109                         PointF p2 = sz11_99.ToPointF ();
110
111                         Assert.AreEqual (p1, p2, "2PF#1");
112                 }
113                 
114                 [Test]
115                 public void Test2Size ()
116                 {
117                         // note: using Size (not SizeF) is normal for this test
118                         Size sz1 = new Size (1, 9);
119                         Size sz2 = sz11_99.ToSize ();
120
121                         Assert.AreEqual (sz1, sz2, "2SZ#1");
122                 }
123
124                 
125                 [Test]
126                 public void TestAddition ()
127                 {
128                         Assert.AreEqual (sz11_99, sz11_0 + new SizeF (0.0F, 9.9F), "ADD#1");
129                         Assert.AreEqual (sz11_99, new SizeF (0.0F, 0.0F) + new SizeF (1.1F, 9.9F), "ADD#2");
130                 }
131
132                 [Test]
133                 public void TestEqualityOp () 
134                 {
135                         Assert.IsTrue (sz11_99 == sz11_99, "EOP#1");
136                         Assert.IsTrue (sz11_99 == new SizeF (1.1F, 9.9F), "EOP#2");
137                         Assert.IsFalse (sz11_99 == sz11_0, "EOP#3");
138                         Assert.IsFalse (sz11_99 == sz0_11, "EOP#4");
139                         Assert.IsFalse (sz11_0 == sz0_11, "EOP#5");
140                 }
141
142                 [Test]
143                 public void TestInequalityOp () 
144                 {
145                         Assert.IsFalse (sz11_99 != sz11_99, "IOP#1");
146                         Assert.IsFalse (sz11_99 != new SizeF (1.1F, 9.9F), "IOP#2");
147                         Assert.IsTrue (sz11_99 != sz11_0, "IOP#3");
148                         Assert.IsTrue (sz11_99 != sz0_11, "IOP#4");
149                         Assert.IsTrue (sz11_0 != sz0_11, "IOP#5");
150                 }
151         
152                 [Test]
153                 public void TestSubtraction () 
154                 {
155                         Assert.AreEqual (sz11_0, sz11_99 - new SizeF (0.0F, 9.9F), "SUB#1");
156                         Assert.AreEqual (sz0_11, new SizeF (1.1F, 1.1F) - new SizeF (1.1F, 0.0F), "SUB#2");
157                 }
158         
159                 [Test]
160                 public void TestSizeF2PointF ()
161                 {
162                         PointF pf1 = new PointF (1.1F, 9.9F);
163                         PointF pf2 = (PointF) sz11_99;
164
165                         Assert.AreEqual (pf1, pf2, "SF2PF#1");
166                 }
167
168                 [Test]
169                 public void GetHashCodeTest ()
170                 {
171                         Assert.AreEqual (sz11_0.GetHashCode (), new SizeF (1.1f, 0).GetHashCode (), "GHC#1");
172                         Assert.AreEqual (SizeF.Empty.GetHashCode (), new SizeF (0, 0).GetHashCode (), "GHC#2");
173                 }
174
175                 [Test]
176                 public void ToStringTest () {
177                         // save current culture
178                         CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
179
180                         try {
181                                 PerformToStringTest (new CultureInfo ("en-US"));
182                                 PerformToStringTest (new CultureInfo ("nl-BE"));
183                         } finally {
184                                 // restore original culture
185                                 Thread.CurrentThread.CurrentCulture = currentCulture;
186                         }
187                 }
188
189                 private void PerformToStringTest (CultureInfo culture)
190                 {
191                         // set current culture
192                         Thread.CurrentThread.CurrentCulture = culture;
193
194                         // perform tests
195                         Assert.AreEqual (GetExpectedToString (culture, sz11_0), sz11_0.ToString (),
196                                 "TS#1-" + culture.Name);
197                         Assert.AreEqual (GetExpectedToString (culture, sz0_11), sz0_11.ToString (),
198                                 "TS#2-" + culture.Name);
199                         Assert.AreEqual (GetExpectedToString (culture, SizeF.Empty), SizeF.Empty.ToString (),
200                                 "TS#3-" + culture.Name);
201                         SizeF size = new SizeF (float.NaN, float.NegativeInfinity);
202                         Assert.AreEqual (GetExpectedToString (culture, size), size.ToString (),
203                                 "TS#4-" + culture.Name);
204                 }
205
206                 private static string GetExpectedToString (CultureInfo culture, SizeF size)
207                 {
208                         return string.Format ("{{Width={0}, Height={1}}}", size.Width.ToString (culture),
209                                 size.Height.ToString (culture));
210                 }
211
212                 [Test]
213                 public void AddTest ()
214                 {
215                         Assert.AreEqual (sz11_99, SizeF.Add (sz11_0, new SizeF (0.0F, 9.9F)), "ADD#1");
216                         Assert.AreEqual (sz11_99, SizeF.Add (new SizeF (0.0F, 0.0F), new SizeF (1.1F, 9.9F)), "ADD#2");
217                 }
218
219                 [Test]
220                 public void SubtractTest ()
221                 {
222                         Assert.AreEqual (sz11_0, SizeF.Subtract (sz11_99, new SizeF (0.0F, 9.9F)), "SUB#1");
223                         Assert.AreEqual (sz0_11, SizeF.Subtract (new SizeF (1.1F, 1.1F), new SizeF (1.1F, 0.0F)), "SUB#2");
224                 }
225
226         }
227 }
228