* WindowsBase/Test/System.Windows/RectTest.cs:
[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.Windows;
28 using System.Windows.Media;
29 using NUnit.Framework;
30
31 namespace MonoTests.System.Windows {
32
33         [TestFixture]
34         public class SizeTest
35         {
36                 [Test]
37                 public void Ctor_Accessors ()
38                 {
39                         Size s = new Size (10, 20);
40                         Assert.AreEqual (10, s.Width);
41                         Assert.AreEqual (20, s.Height);
42                 }
43
44                 [Test]
45                 public void Equals ()
46                 {
47                         Size s = new Size (10, 20);
48
49                         Assert.IsTrue (s.Equals (s));
50                         Assert.IsTrue (s.Equals (new Size (10, 20)));
51
52                         Assert.IsTrue (Size.Equals (s, s));
53
54                         Assert.IsFalse (s.Equals (new Size (5, 10)));
55                         Assert.IsFalse (Size.Equals (s, new Size (5, 10)));
56
57                         Assert.IsFalse (s.Equals (new object()));
58                 }
59
60                 [Test]
61                 [ExpectedException (typeof (ArgumentException))]
62                 public void Ctor_negative_width()
63                 {
64                         new Size (-10, 5);
65                 }
66
67                 [Test]
68                 [ExpectedException (typeof (ArgumentException))]
69                 public void Ctor_negative_height()
70                 {
71                         new Size (5, -10);
72                 }
73
74                 [Test]
75                 public void Modify_width ()
76                 {
77                         Size s = new Size (10, 10);
78                         s.Width = 20;
79                         Assert.AreEqual (new Size (20, 10), s);
80                 }
81
82                 [Test]
83                 [ExpectedException (typeof (InvalidOperationException))]
84                 public void ModifyEmpty_width ()
85                 {
86                         Size s = Size.Empty;
87                         s.Width = 20;
88                 }
89
90                 [Test]
91                 [ExpectedException (typeof (ArgumentException))]
92                 public void Modify_negative_width ()
93                 {
94                         Size s = new Size (10, 10);
95                         s.Width = -20;
96                 }
97
98                 [Test]
99                 public void Modify_height ()
100                 {
101                         Size s = new Size (10, 10);
102                         s.Height = 20;
103                         Assert.AreEqual (new Size (10, 20), s);
104                 }
105
106                 [Test]
107                 [ExpectedException (typeof (InvalidOperationException))]
108                 public void ModifyEmpty_height ()
109                 {
110                         Size s = Size.Empty;
111                         s.Height = 20;
112                 }
113
114                 [Test]
115                 [ExpectedException (typeof (ArgumentException))]
116                 public void Modify_negative_height ()
117                 {
118                         Size s = new Size (10, 10);
119                         s.Height = -20;
120                 }
121
122                 [Test]
123                 [Category ("NotWorking")]
124                 public void Parse ()
125                 {
126                         Assert.AreEqual (new Size (1, 2), Size.Parse ("1, 2"));
127                 }
128
129                 [Test]
130                 [ExpectedException (typeof (ArgumentException))]
131                 public void ParseNegative ()
132                 {
133                         Assert.AreEqual (new Size (-1, 2), Size.Parse ("-1, 2"));
134                 }
135
136                 [Test]
137                 public void ToStringTest ()
138                 {
139                         Assert.AreEqual ("1,2", (new Size (1, 2)).ToString());
140                 }
141
142                 [Test]
143                 public void Empty ()
144                 {
145                         Assert.AreEqual (Double.NegativeInfinity, Size.Empty.Width);
146                         Assert.AreEqual (Double.NegativeInfinity, Size.Empty.Height);
147                 }
148
149                 [Test]
150                 public void IsEmpty ()
151                 {
152                         Assert.IsTrue (Size.Empty.IsEmpty);
153                         Assert.IsFalse ((new Size (10, 10)).IsEmpty);
154                         Assert.IsFalse ((new Size (0, 0)).IsEmpty);
155                 }
156         }
157 }