Merge pull request #5560 from kumpera/wasm-work-p3
[mono.git] / mcs / class / WindowsBase / Test / System.Windows / SizeTest.cs
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:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
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.
19 //
20 // Copyright (c) 2007 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Chris Toshok (toshok@ximian.com)
24 //
25
26 using System;
27 using System.Globalization;
28 using System.Windows;
29 using System.Windows.Media;
30 using NUnit.Framework;
31
32 namespace MonoTests.System.Windows {
33
34         [TestFixture]
35         public class SizeTest
36         {
37                 [Test]
38                 public void Ctor_Accessors ()
39                 {
40                         Size s = new Size (10, 20);
41                         Assert.AreEqual (10, s.Width);
42                         Assert.AreEqual (20, s.Height);
43                 }
44
45                 [Test]
46                 public void Equals ()
47                 {
48                         Size s = new Size (10, 20);
49
50                         Assert.IsTrue (s.Equals (s));
51                         Assert.IsTrue (s.Equals (new Size (10, 20)));
52
53                         Assert.IsTrue (Size.Equals (s, s));
54
55                         Assert.IsFalse (s.Equals (new Size (5, 10)));
56                         Assert.IsFalse (Size.Equals (s, new Size (5, 10)));
57
58                         Assert.IsFalse (s.Equals (new object()));
59                 }
60
61                 [Test]
62                 [ExpectedException (typeof (ArgumentException))]
63                 public void Ctor_negative_width()
64                 {
65                         new Size (-10, 5);
66                 }
67
68                 [Test]
69                 [ExpectedException (typeof (ArgumentException))]
70                 public void Ctor_negative_height()
71                 {
72                         new Size (5, -10);
73                 }
74
75                 [Test]
76                 public void Modify_width ()
77                 {
78                         Size s = new Size (10, 10);
79                         s.Width = 20;
80                         Assert.AreEqual (new Size (20, 10), s);
81                 }
82
83                 [Test]
84                 [ExpectedException (typeof (InvalidOperationException))]
85                 public void ModifyEmpty_width ()
86                 {
87                         Size s = Size.Empty;
88                         s.Width = 20;
89                 }
90
91                 [Test]
92                 [ExpectedException (typeof (ArgumentException))]
93                 public void Modify_negative_width ()
94                 {
95                         Size s = new Size (10, 10);
96                         s.Width = -20;
97                 }
98
99                 [Test]
100                 public void Modify_height ()
101                 {
102                         Size s = new Size (10, 10);
103                         s.Height = 20;
104                         Assert.AreEqual (new Size (10, 20), s);
105                 }
106
107                 [Test]
108                 [ExpectedException (typeof (InvalidOperationException))]
109                 public void ModifyEmpty_height ()
110                 {
111                         Size s = Size.Empty;
112                         s.Height = 20;
113                 }
114
115                 [Test]
116                 [ExpectedException (typeof (ArgumentException))]
117                 public void Modify_negative_height ()
118                 {
119                         Size s = new Size (10, 10);
120                         s.Height = -20;
121                 }
122
123                 [Test]
124                 public void ParseWithoutWhiteSpaces ()
125                 {
126                         Assert.AreEqual (new Size (1, 2), Size.Parse ("1,2"));
127                 }
128
129                 [Test]
130                 public void ParseWithWhiteSpaces ()
131                 {
132                         Assert.AreEqual (new Size (1, 2), Size.Parse (" 1, 2 "));
133                 }
134
135                 [Test]
136                 public void ParseValueWithFloatingPoint ()
137                 {
138                         Assert.AreEqual (new Size (1.234, 5.678), Size.Parse ("1.234,5.678"));
139                 }
140                 [Test]
141                 public void ParseEmpty ()
142                 {
143                         Assert.AreEqual (Size.Empty, Size.Parse ("Empty"));
144                 }
145
146                 [Test]
147                 public void ParseEmptyWithWhiteSpaces ()
148                 {
149                         Assert.AreEqual (Size.Empty, Size.Parse (" Empty "));
150                 }
151
152                 [Test]
153                 [ExpectedException (typeof (ArgumentException))]
154                 public void ParseNegative ()
155                 {
156                         Assert.AreEqual (new Size (-1, 2), Size.Parse ("-1, 2"));
157                 }
158
159                 [Test]
160                 public void ToStringTest ()
161                 {
162                         Assert.AreEqual ("1,2", (new Size (1, 2)).ToString (CultureInfo.InvariantCulture));
163                 }
164
165                 [Test]
166                 public void Empty ()
167                 {
168                         Assert.AreEqual (Double.NegativeInfinity, Size.Empty.Width);
169                         Assert.AreEqual (Double.NegativeInfinity, Size.Empty.Height);
170                 }
171
172                 [Test]
173                 public void IsEmpty ()
174                 {
175                         Assert.IsTrue (Size.Empty.IsEmpty);
176                         Assert.IsFalse ((new Size (10, 10)).IsEmpty);
177                         Assert.IsFalse ((new Size (0, 0)).IsEmpty);
178                 }
179         }
180 }