8275f1813b8611bd88151fe3406cc6502b8b4e5d
[mono.git] / mcs / class / WindowsBase / Test / System.Windows / Int32RectTest.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 Int32RectTest
35         {
36                 [Test]
37                 public void Ctor_Accessor ()
38                 {
39                         Int32Rect r;
40
41                         r = new Int32Rect (10, 15, 20, 30);
42                         Assert.AreEqual (10, r.X);
43                         Assert.AreEqual (15, r.Y);
44                         Assert.AreEqual (20, r.Width);
45                         Assert.AreEqual (30, r.Height);
46                 }
47
48                 [Test]
49                 public void Ctor_NegativeWidth ()
50                 {
51                         new Int32Rect (10, 10, -10, 10);
52                 }
53
54                 [Test]
55                 public void Ctor_NegativeHeight ()
56                 {
57                         new Int32Rect (10, 10, 10, -10);
58                 }
59
60                 [Test]
61                 public void Empty ()
62                 {
63                         Int32Rect r = Int32Rect.Empty;
64                         Assert.AreEqual (0, r.X);
65                         Assert.AreEqual (0, r.Y);
66                         Assert.AreEqual (0, r.Width);
67                         Assert.AreEqual (0, r.Height);
68                 }
69
70                 [Test]
71                 public void ModifyEmpty_x ()
72                 {
73                         Int32Rect r = Int32Rect.Empty;
74                         r.X = 5;
75                 }
76
77                 [Test]
78                 public void ModifyEmpty_y ()
79                 {
80                         Int32Rect r = Int32Rect.Empty;
81                         r.Y = 5;
82                 }
83
84                 [Test]
85                 public void ModifyEmpty_width ()
86                 {
87                         Int32Rect r = Int32Rect.Empty;
88                         r.Width = 5;
89                 }
90
91                 [Test]
92                 public void ModifyEmpty_height ()
93                 {
94                         Int32Rect r = Int32Rect.Empty;
95                         r.Height = 5;
96                 }
97
98                 [Test]
99                 public void ModifyEmpty_negative_width ()
100                 {
101                         Int32Rect r = Int32Rect.Empty;
102                         r.Width = -5;
103                 }
104
105                 [Test]
106                 public void ModifyEmpty_negative_height ()
107                 {
108                         Int32Rect r = Int32Rect.Empty;
109                         r.Height = -5;
110                 }
111
112
113                 [Test]
114                 public void Modify_negative_width ()
115                 {
116                         Int32Rect r = new Int32Rect (0, 0, 10, 10);
117                         r.Width = -5;
118                 }
119
120                 [Test]
121                 public void Modify_negative_height ()
122                 {
123                         Int32Rect r = new Int32Rect (0, 0, 10, 10);
124                         r.Height = -5;
125                 }
126
127                 [Test]
128                 public void IsEmpty ()
129                 {
130                         Assert.IsTrue (Int32Rect.Empty.IsEmpty);
131                         Assert.IsTrue ((new Int32Rect (0, 0, 0, 0)).IsEmpty);
132                         Assert.IsFalse ((new Int32Rect (5, 5, 5, 5)).IsEmpty);
133                 }
134
135                 [Test]
136                 public void ToStringTest ()
137                 {
138                         Int32Rect r = new Int32Rect (1, 2, 3, 4);
139                         Assert.AreEqual ("1,2,3,4", r.ToString());
140
141                         Assert.AreEqual ("Empty", Int32Rect.Empty.ToString());
142                 }
143
144                 [Test]
145                 [Category ("NotWorking")]
146                 public void Parse ()
147                 {
148                         Int32Rect r = Int32Rect.Parse ("1, 2, 3, 4");
149                         Assert.AreEqual (new Int32Rect (1, 2, 3, 4), r);
150                 }
151
152                 [Test]
153                 [Category ("NotWorking")]
154                 public void ParseNegative ()
155                 {
156                         Int32Rect.Parse ("1, 2, -3, -4");
157                 }
158
159                 [Test]
160                 public void Equals ()
161                 {
162                         Int32Rect r1 = new Int32Rect (1, 2, 3, 4);
163                         Int32Rect r2 = r1;
164
165                         Assert.IsTrue (r1.Equals (r1));
166
167                         r2.X = 0;
168                         Assert.IsFalse (r1.Equals (r2));
169                         r2.X = r1.X;
170
171                         r2.Y = 0;
172                         Assert.IsFalse (r1.Equals (r2));
173                         r2.Y = r1.Y;
174
175                         r2.Width = 0;
176                         Assert.IsFalse (r1.Equals (r2));
177                         r2.Width = r1.Width;
178
179                         r2.Height = 0;
180                         Assert.IsFalse (r1.Equals (r2));
181                         r2.Height = r1.Height;
182
183                         Assert.IsFalse (r1.Equals (new object()));
184                 }
185         }
186 }