1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
23 // Chris Toshok (toshok@ximian.com)
27 using System.Globalization;
29 using System.Windows.Media;
30 using NUnit.Framework;
32 namespace MonoTests.System.Windows {
38 public void Ctor_Accessors ()
40 Size s = new Size (10, 20);
41 Assert.AreEqual (10, s.Width);
42 Assert.AreEqual (20, s.Height);
48 Size s = new Size (10, 20);
50 Assert.IsTrue (s.Equals (s));
51 Assert.IsTrue (s.Equals (new Size (10, 20)));
53 Assert.IsTrue (Size.Equals (s, s));
55 Assert.IsFalse (s.Equals (new Size (5, 10)));
56 Assert.IsFalse (Size.Equals (s, new Size (5, 10)));
58 Assert.IsFalse (s.Equals (new object()));
62 [ExpectedException (typeof (ArgumentException))]
63 public void Ctor_negative_width()
69 [ExpectedException (typeof (ArgumentException))]
70 public void Ctor_negative_height()
76 public void Modify_width ()
78 Size s = new Size (10, 10);
80 Assert.AreEqual (new Size (20, 10), s);
84 [ExpectedException (typeof (InvalidOperationException))]
85 public void ModifyEmpty_width ()
92 [ExpectedException (typeof (ArgumentException))]
93 public void Modify_negative_width ()
95 Size s = new Size (10, 10);
100 public void Modify_height ()
102 Size s = new Size (10, 10);
104 Assert.AreEqual (new Size (10, 20), s);
108 [ExpectedException (typeof (InvalidOperationException))]
109 public void ModifyEmpty_height ()
116 [ExpectedException (typeof (ArgumentException))]
117 public void Modify_negative_height ()
119 Size s = new Size (10, 10);
124 public void ParseWithoutWhiteSpaces ()
126 Assert.AreEqual (new Size (1, 2), Size.Parse ("1,2"));
130 public void ParseWithWhiteSpaces ()
132 Assert.AreEqual (new Size (1, 2), Size.Parse (" 1, 2 "));
136 public void ParseValueWithFloatingPoint ()
138 Assert.AreEqual (new Size (1.234, 5.678), Size.Parse ("1.234,5.678"));
141 public void ParseEmpty ()
143 Assert.AreEqual (Size.Empty, Size.Parse ("Empty"));
147 public void ParseEmptyWithWhiteSpaces ()
149 Assert.AreEqual (Size.Empty, Size.Parse (" Empty "));
153 [ExpectedException (typeof (ArgumentException))]
154 public void ParseNegative ()
156 Assert.AreEqual (new Size (-1, 2), Size.Parse ("-1, 2"));
160 public void ToStringTest ()
162 Assert.AreEqual ("1,2", (new Size (1, 2)).ToString (CultureInfo.InvariantCulture));
168 Assert.AreEqual (Double.NegativeInfinity, Size.Empty.Width);
169 Assert.AreEqual (Double.NegativeInfinity, Size.Empty.Height);
173 public void IsEmpty ()
175 Assert.IsTrue (Size.Empty.IsEmpty);
176 Assert.IsFalse ((new Size (10, 10)).IsEmpty);
177 Assert.IsFalse ((new Size (0, 0)).IsEmpty);