[amd64] Save missing register
[mono.git] / mcs / class / WindowsBase / Test / System.Windows / RectTest.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 RectTest
36         {
37                 [Test]
38                 public void Ctor_Accessor ()
39                 {
40                         Rect r;
41
42                         r = new Rect (new Size (40, 50));
43                         Assert.AreEqual (0, r.X);
44                         Assert.AreEqual (0, r.Y);
45                         Assert.AreEqual (40, r.Width);
46                         Assert.AreEqual (50, r.Height);
47                         Assert.AreEqual (0, r.Left);
48                         Assert.AreEqual (0, r.Top);
49                         Assert.AreEqual (40, r.Right);
50                         Assert.AreEqual (50, r.Bottom);
51                         Assert.AreEqual (new Point (0, 0), r.TopLeft);
52                         Assert.AreEqual (new Point (40, 0), r.TopRight);
53                         Assert.AreEqual (new Point (0, 50), r.BottomLeft);
54                         Assert.AreEqual (new Point (40, 50), r.BottomRight);
55                         Assert.AreEqual (new Point (0, 0), r.Location);
56                         Assert.AreEqual (new Size (40, 50), r.Size);
57
58                         r = new Rect (new Point (4, 5), new Vector (20, 30));
59                         Assert.AreEqual (4, r.X);
60                         Assert.AreEqual (5, r.Y);
61                         Assert.AreEqual (20, r.Width);
62                         Assert.AreEqual (30, r.Height);
63                         Assert.AreEqual (4, r.Left);
64                         Assert.AreEqual (5, r.Top);
65                         Assert.AreEqual (24, r.Right);
66                         Assert.AreEqual (35, r.Bottom);
67                         Assert.AreEqual (new Point (4, 5), r.TopLeft);
68                         Assert.AreEqual (new Point (24, 5), r.TopRight);
69                         Assert.AreEqual (new Point (4, 35), r.BottomLeft);
70                         Assert.AreEqual (new Point (24, 35), r.BottomRight);
71                         Assert.AreEqual (new Point (4, 5), r.Location);
72                         Assert.AreEqual (new Size (20, 30), r.Size);
73
74                         r = new Rect (new Point (4, 5), new Point (20, 30));
75                         Assert.AreEqual (4, r.X);
76                         Assert.AreEqual (5, r.Y);
77                         Assert.AreEqual (16, r.Width);
78                         Assert.AreEqual (25, r.Height);
79                         Assert.AreEqual (4, r.Left);
80                         Assert.AreEqual (5, r.Top);
81                         Assert.AreEqual (20, r.Right);
82                         Assert.AreEqual (30, r.Bottom);
83                         Assert.AreEqual (new Point (4, 5), r.TopLeft);
84                         Assert.AreEqual (new Point (20, 5), r.TopRight);
85                         Assert.AreEqual (new Point (4, 30), r.BottomLeft);
86                         Assert.AreEqual (new Point (20, 30), r.BottomRight);
87                         Assert.AreEqual (new Point (4, 5), r.Location);
88                         Assert.AreEqual (new Size (16,25), r.Size);
89
90                         r = new Rect (new Point (20, 30), new Point (4, 5));
91                         Assert.AreEqual (4, r.X);
92                         Assert.AreEqual (5, r.Y);
93                         Assert.AreEqual (16, r.Width);
94                         Assert.AreEqual (25, r.Height);
95                         Assert.AreEqual (4, r.Left);
96                         Assert.AreEqual (5, r.Top);
97                         Assert.AreEqual (20, r.Right);
98                         Assert.AreEqual (30, r.Bottom);
99                         Assert.AreEqual (new Point (4, 5), r.TopLeft);
100                         Assert.AreEqual (new Point (20, 5), r.TopRight);
101                         Assert.AreEqual (new Point (4, 30), r.BottomLeft);
102                         Assert.AreEqual (new Point (20, 30), r.BottomRight);
103                         Assert.AreEqual (new Point (4, 5), r.Location);
104                         Assert.AreEqual (new Size (16,25), r.Size);
105
106                         r = new Rect (10, 15, 20, 30);
107                         Assert.AreEqual (10, r.X);
108                         Assert.AreEqual (15, r.Y);
109                         Assert.AreEqual (20, r.Width);
110                         Assert.AreEqual (30, r.Height);
111                         Assert.AreEqual (10, r.Left);
112                         Assert.AreEqual (15, r.Top);
113                         Assert.AreEqual (30, r.Right);
114                         Assert.AreEqual (45, r.Bottom);
115                         Assert.AreEqual (new Point (10, 15), r.TopLeft);
116                         Assert.AreEqual (new Point (30, 15), r.TopRight);
117                         Assert.AreEqual (new Point (10, 45), r.BottomLeft);
118                         Assert.AreEqual (new Point (30, 45), r.BottomRight);
119                         Assert.AreEqual (new Point (10, 15), r.Location);
120                         Assert.AreEqual (new Size (20, 30), r.Size);
121
122                         r = new Rect (new Point (10, 15), new Size (20, 30));
123                         Assert.AreEqual (10, r.X);
124                         Assert.AreEqual (15, r.Y);
125                         Assert.AreEqual (20, r.Width);
126                         Assert.AreEqual (30, r.Height);
127                         Assert.AreEqual (10, r.Left);
128                         Assert.AreEqual (15, r.Top);
129                         Assert.AreEqual (30, r.Right);
130                         Assert.AreEqual (45, r.Bottom);
131                         Assert.AreEqual (new Point (10, 15), r.TopLeft);
132                         Assert.AreEqual (new Point (30, 15), r.TopRight);
133                         Assert.AreEqual (new Point (10, 45), r.BottomLeft);
134                         Assert.AreEqual (new Point (30, 45), r.BottomRight);
135                         Assert.AreEqual (new Point (10, 15), r.Location);
136                         Assert.AreEqual (new Size (20, 30), r.Size);
137                 }
138
139                 [Test]
140                 [ExpectedException (typeof (ArgumentException))]
141                 public void Ctor_NegativeWidth ()
142                 {
143                         new Rect (10, 10, -10, 10);
144                 }
145
146                 [Test]
147                 [ExpectedException (typeof (ArgumentException))]
148                 public void Ctor_NegativeHeight ()
149                 {
150                         new Rect (10, 10, 10, -10);
151                 }
152
153                 [Test]
154                 public void Empty ()
155                 {
156                         Rect r = Rect.Empty;
157                         Assert.AreEqual (Double.PositiveInfinity, r.X);
158                         Assert.AreEqual (Double.PositiveInfinity, r.Y);
159                         Assert.AreEqual (Double.NegativeInfinity, r.Width);
160                         Assert.AreEqual (Double.NegativeInfinity, r.Height);
161                 }
162
163                 [Test]
164                 [ExpectedException (typeof (InvalidOperationException))]
165                 public void ModifyEmpty_x ()
166                 {
167                         Rect r = Rect.Empty;
168                         r.X = 5;
169                 }
170
171                 [Test]
172                 [ExpectedException (typeof (InvalidOperationException))]
173                 public void ModifyEmpty_y ()
174                 {
175                         Rect r = Rect.Empty;
176                         r.Y = 5;
177                 }
178
179                 [Test]
180                 [ExpectedException (typeof (InvalidOperationException))]
181                 public void ModifyEmpty_width ()
182                 {
183                         Rect r = Rect.Empty;
184                         r.Width = 5;
185                 }
186
187                 [Test]
188                 [ExpectedException (typeof (InvalidOperationException))]
189                 public void ModifyEmpty_height ()
190                 {
191                         Rect r = Rect.Empty;
192                         r.Height = 5;
193                 }
194
195                 [Test]
196                 [ExpectedException (typeof (InvalidOperationException))]
197                 public void ModifyEmpty_negative_width ()
198                 {
199                         Rect r = Rect.Empty;
200                         r.Width = -5;
201                 }
202
203                 [Test]
204                 [ExpectedException (typeof (InvalidOperationException))]
205                 public void ModifyEmpty_negative_height ()
206                 {
207                         Rect r = Rect.Empty;
208                         r.Height = -5;
209                 }
210
211
212                 [Test]
213                 [ExpectedException (typeof (ArgumentException))]
214                 public void Modify_negative_width ()
215                 {
216                         Rect r = new Rect (0, 0, 10, 10);
217                         r.Width = -5;
218                 }
219
220                 [Test]
221                 [ExpectedException (typeof (ArgumentException))]
222                 public void Modify_negative_height ()
223                 {
224                         Rect r = new Rect (0, 0, 10, 10);
225                         r.Height = -5;
226                 }
227
228                 [Test]
229                 public void Empty_Size ()
230                 {
231                         Assert.AreEqual (Size.Empty, Rect.Empty.Size);
232                 }
233
234                 [Test]
235                 public void IsEmpty ()
236                 {
237                         Assert.IsTrue (Rect.Empty.IsEmpty);
238                         Assert.IsFalse ((new Rect (5, 5, 5, 5)).IsEmpty);
239                 }
240
241                 [Test]
242                 public void Location ()
243                 {
244                         Rect r = new Rect (0, 0, 0, 0);
245
246                         r.Location = new Point (10, 15);
247                         Assert.AreEqual (10, r.X);
248                         Assert.AreEqual (15, r.Y);
249                 }
250
251                 [Test]
252                 public void RectSize ()
253                 {
254                         Rect r = new Rect (0, 0, 5, 5);
255
256                         r.Size = new Size (10, 15);
257                         Assert.AreEqual (10, r.Width);
258                         Assert.AreEqual (15, r.Height);
259                 }
260
261                 [Test]
262                 [SetCulture ("en-us")]
263                 public void ToStringTest ()
264                 {
265                         Rect r = new Rect (1.0, 2.5, 3, 4);
266
267                         string expectedStringOutput = "1,2.5,3,4";
268                         Assert.AreEqual (expectedStringOutput, r.ToString ());
269                         Assert.AreEqual (expectedStringOutput, r.ToString (null));
270                         Assert.AreEqual ("Empty", Rect.Empty.ToString ());
271
272                         // IFormattable.ToString
273                         IFormattable rFormattable = r;
274                         Assert.AreEqual (expectedStringOutput,
275                                 rFormattable.ToString (null, null),
276                                 "IFormattable.ToString with null format");
277                         Assert.AreEqual (expectedStringOutput,
278                                 rFormattable.ToString (string.Empty, null),
279                                 "IFormattable.ToString with empty format");
280                         Assert.AreEqual ("1.00,2.50,3.00,4.00",
281                                 rFormattable.ToString ("N2", null),
282                                 "IFormattable.ToString with N2 format");
283                         Assert.AreEqual ("blah,blah,blah,blah",
284                                 rFormattable.ToString ("blah", null),
285                                 "IFormattable.ToString with blah format");
286                         Assert.AreEqual (":,:,:,:",
287                                 rFormattable.ToString (":", null),
288                                 "IFormattable.ToString with : format");
289                         Assert.AreEqual ("Empty",
290                                 ((IFormattable) Rect.Empty).ToString ("blah", null),
291                                 "IFormattable.ToString on Rect.Empty with blah format");
292
293                         foreach (CultureInfo culture in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
294                                 if (culture.IsNeutralCulture)
295                                         continue;
296                                 string separator = ",";
297                                 if (culture.NumberFormat.NumberDecimalSeparator == separator)
298                                         separator = ";";
299                                 expectedStringOutput =
300                                         1.ToString (culture) + separator +
301                                         2.5.ToString (culture) + separator +
302                                         3.ToString (culture) + separator +
303                                         4.ToString (culture);
304                                 Assert.AreEqual (expectedStringOutput,
305                                         r.ToString (culture),
306                                         "ToString with Culture: " + culture.Name);
307                                 Assert.AreEqual ("Empty",
308                                         Rect.Empty.ToString (culture),
309                                         "ToString on Empty with Culture: " + culture.Name);
310
311                                 // IFormattable.ToString
312                                 Assert.AreEqual (expectedStringOutput,
313                                         rFormattable.ToString (null, culture),
314                                         "IFormattable.ToString with null format with Culture: " + culture.Name);
315                                 Assert.AreEqual (expectedStringOutput,
316                                         rFormattable.ToString (string.Empty, culture),
317                                         "IFormattable.ToString with empty format with Culture: " + culture.Name);
318                                 expectedStringOutput =
319                                         1.ToString ("N2", culture) + separator +
320                                         2.5.ToString ("N2", culture) + separator +
321                                         3.ToString ("N2", culture) + separator +
322                                         4.ToString ("N2", culture);
323                                 Assert.AreEqual (expectedStringOutput,
324                                         rFormattable.ToString ("N2", culture),
325                                         "IFormattable.ToString with N2 format with Culture: " + culture.Name);
326                         }
327                 }
328                 
329                 [Test]
330                 [Category ("NotWorking")]
331                 public void ToString_FormatException ()
332                 {
333                         // This test does not currently work because
334                         // String.Format does not throw all necessary exceptions
335                         IFormattable rFormattable = new Rect (1.0, 2.5, 3, 4);
336                         bool exceptionRaised = false;
337                         try {
338                                 rFormattable.ToString ("{", null);
339                         } catch (FormatException) {
340                                 exceptionRaised = true;
341                         }
342                         Assert.IsTrue (exceptionRaised, "Expected FormatException with IFormattable.ToString (\"{\", null)");
343                 }
344
345                 [Test]
346                 [Category ("NotWorking")]
347                 public void Parse ()
348                 {
349                         Rect r = Rect.Parse ("1 , 2, 3, 4");
350                         Assert.AreEqual (new Rect (1, 2, 3, 4), r);
351                 }
352
353                 [Test]
354                 [Category ("NotWorking")]
355                 public void Parse2 ()
356                 {
357                         Rect r = Rect.Parse ("1 2 3 4");
358                         Assert.AreEqual (new Rect (1, 2, 3, 4), r);
359                 }
360
361                 [Test]
362                 [Category ("NotWorking")]
363                 public void Parse3 ()
364                 {
365                         Rect r = Rect.Parse ("  1 2 3 4  ");
366                         Assert.AreEqual (new Rect (1, 2, 3, 4), r);
367                 }
368
369                 [Test]
370                 [Category ("NotWorking")]
371                 public void ParseWithBothSeparators ()
372                 {
373                         Rect.Parse ("1.0, 3 2.0, 5.0");
374                 }
375
376                 [Test]
377                 [Category ("NotWorking")]
378                 [ExpectedException (typeof (ArgumentException))]
379                 public void ParseNegative ()
380                 {
381                         Rect.Parse ("1, 2, -3, -4");
382                 }
383
384                 [Test]
385                 [Category ("NotWorking")]
386                 [ExpectedException (typeof (InvalidOperationException))] // "Premature string termination encountered."
387                 public void Parse3Doubles ()
388                 {
389                         Rect.Parse ("1.0, 3, -5");
390                 }
391
392                 [Test]
393                 [Category ("NotWorking")]
394                 [ExpectedException (typeof (FormatException))]
395                 public void ParseInvalidString1 ()
396                 {
397                         Rect.Parse ("1.0, 3, -x, 5.0");
398                 }
399
400                 [Test]
401                 [Category ("NotWorking")]
402                 [ExpectedException (typeof (InvalidOperationException))]
403                 public void ParseInvalidString3 ()
404                 {
405                         Rect.Parse ("1.0, 3, 2.0, 5.0, 2");
406                 }
407
408                 [Test]
409                 [Category ("NotWorking")]
410                 [ExpectedException (typeof (FormatException))]
411                 public void ParseInvalidString4 ()
412                 {
413                         Rect.Parse ("1.0-3, 2.0, 5.0, 2");
414                 }
415
416                 [Test]
417                 [Category ("NotWorking")]
418                 [ExpectedException (typeof (InvalidOperationException))]
419                 public void ParseInvalidString5 ()
420                 {
421                         Rect.Parse ("1.0, 2.0, 5.0, 2,");
422                 }
423
424                 [Test]
425                 [Category ("NotWorking")]
426                 public void ParseInvalidString6 ()
427                 {
428                         Rect.Parse ("\n1.0, 2.0, 5.0, 2");
429                 }
430
431                 [Test]
432                 [Category ("NotWorking")]
433                 [ExpectedException (typeof (InvalidOperationException))]
434                 public void ParseInvalidString7 ()
435                 {
436                         Rect r = Rect.Parse ("1,, 2, 3, 4");
437                         Assert.AreEqual (new Rect (1, 2, 3, 4), r);
438                 }
439
440                 [Test]
441                 public void Equals ()
442                 {
443                         Rect r1 = new Rect (1, 2, 3, 4);
444                         Rect r2 = r1;
445
446                         Assert.IsTrue (r1.Equals (r1));
447
448                         r2.X = 0;
449                         Assert.IsFalse (r1.Equals (r2));
450                         r2.X = r1.X;
451
452                         r2.Y = 0;
453                         Assert.IsFalse (r1.Equals (r2));
454                         r2.Y = r1.Y;
455
456                         r2.Width = 0;
457                         Assert.IsFalse (r1.Equals (r2));
458                         r2.Width = r1.Width;
459
460                         r2.Height = 0;
461                         Assert.IsFalse (r1.Equals (r2));
462                         r2.Height = r1.Height;
463
464                         Assert.IsFalse (r1.Equals (new object ()));
465
466                         r1 = Rect.Empty;
467                         r2 = Rect.Empty;
468
469                         Assert.AreEqual (true, r1.Equals (r2));
470                         Assert.AreEqual (true, r2.Equals (r1));
471                 }
472
473                 [Test]
474                 public void ContainsRect ()
475                 {
476                         Rect r = new Rect (0, 0, 50, 50);
477
478                         // fully contained
479                         Assert.IsTrue (r.Contains (new Rect (10, 10, 10, 10)));
480
481                         // crosses top side
482                         Assert.IsFalse (r.Contains (new Rect (5, -5, 10, 10)));
483
484                         // crosses right side
485                         Assert.IsFalse (r.Contains (new Rect (5, 5, 50, 10)));
486
487                         // crosses bottom side
488                         Assert.IsFalse (r.Contains (new Rect (5, 5, 10, 50)));
489
490                         // crosses left side
491                         Assert.IsFalse (r.Contains (new Rect (-5, 5, 10, 10)));
492
493                         // completely outside (top)
494                         Assert.IsFalse (r.Contains (new Rect (5, -5, 1, 1)));
495
496                         // completely outside (right)
497                         Assert.IsFalse (r.Contains (new Rect (75, 5, 1, 1)));
498
499                         // completely outside (bottom)
500                         Assert.IsFalse (r.Contains (new Rect (5, 75, 1, 1)));
501
502                         // completely outside (left)
503                         Assert.IsFalse (r.Contains (new Rect (-25, 5, 1, 1)));
504                 }
505
506                 [Test]
507                 public void ContainsDoubles ()
508                 {
509                         Rect r = new Rect (0, 0, 50, 50);
510
511                         Assert.IsTrue (r.Contains (10, 10));
512                         Assert.IsFalse (r.Contains (-5, -5));
513                 }
514
515                 [Test]
516                 public void ContainsPoint ()
517                 {
518                         Rect r = new Rect (0, 0, 50, 50);
519
520                         Assert.IsTrue (r.Contains (new Point (10, 10)));
521                         Assert.IsFalse (r.Contains (new Point (-5, -5)));
522                 }
523
524                 [Test]
525                 public void Inflate ()
526                 {
527                         Rect r = Rect.Inflate (new Rect (0, 0, 20, 20), 10, 15);
528                         Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
529
530                         r = Rect.Inflate (new Rect (0, 0, 20, 20), new Size (10, 15));
531                         Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
532
533                         r = new Rect (0, 0, 20, 20);
534                         r.Inflate (10, 15);
535                         Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
536
537                         r = new Rect (0, 0, 20, 20);
538                         r.Inflate (new Size (10, 15));
539                         Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
540                 }
541
542                 [Test]
543                 public void IntersectsWith ()
544                 {
545                         Rect r = new Rect (0, 0, 50, 50);
546
547                         // fully contained
548                         Assert.IsTrue (r.IntersectsWith (new Rect (10, 10, 10, 10)));
549
550                         // crosses top side
551                         Assert.IsTrue (r.IntersectsWith (new Rect (5, -5, 10, 10)));
552
553                         // crosses right side
554                         Assert.IsTrue (r.IntersectsWith (new Rect (5, 5, 50, 10)));
555
556                         // crosses bottom side
557                         Assert.IsTrue (r.IntersectsWith (new Rect (5, 5, 10, 50)));
558
559                         // crosses left side
560                         Assert.IsTrue (r.IntersectsWith (new Rect (-5, 5, 10, 10)));
561
562                         // completely outside (top)
563                         Assert.IsFalse (r.IntersectsWith (new Rect (5, -5, 1, 1)));
564
565                         // completely outside (right)
566                         Assert.IsFalse (r.IntersectsWith (new Rect (75, 5, 1, 1)));
567
568                         // completely outside (bottom)
569                         Assert.IsFalse (r.IntersectsWith (new Rect (5, 75, 1, 1)));
570
571                         // completely outside (left)
572                         Assert.IsFalse (r.IntersectsWith (new Rect (-25, 5, 1, 1)));
573                 }
574
575                 [Test]
576                 public void Intersect ()
577                 {
578                         Rect r;
579
580                         // fully contained
581                         r = new Rect (0, 0, 50, 50);
582                         r.Intersect (new Rect (10, 10, 10, 10));
583                         Assert.AreEqual (new Rect (10, 10, 10, 10), r);
584
585                         // crosses top side
586                         r = new Rect (0, 0, 50, 50);
587                         r.Intersect (new Rect (5, -5, 10, 10));
588                         Assert.AreEqual (new Rect (5, 0, 10, 5), r);
589
590                         // crosses right side
591                         r = new Rect (0, 0, 50, 50);
592                         r.Intersect (new Rect (5, 5, 50, 10));
593                         Assert.AreEqual (new Rect (5, 5, 45, 10), r);
594
595                         // crosses bottom side
596                         r = new Rect (0, 0, 50, 50);
597                         r.Intersect (new Rect (5, 5, 10, 50));
598                         Assert.AreEqual(new Rect(5, 5, 10, 45), r);
599
600                         // crosses left side
601                         r = new Rect (0, 0, 50, 50);
602                         r.Intersect (new Rect (-5, 5, 10, 10));
603                         Assert.AreEqual(new Rect(0, 5, 5, 10), r);
604
605                         // completely outside (top)
606                         r = new Rect (0, 0, 50, 50);
607                         r.Intersect (new Rect (5, -5, 1, 1));
608                         Assert.AreEqual (Rect.Empty, r);
609
610                         // completely outside (right)
611                         r = new Rect (0, 0, 50, 50);
612                         r.Intersect (new Rect (75, 5, 1, 1));
613                         Assert.AreEqual (Rect.Empty, r);
614
615                         // completely outside (bottom)
616                         r = new Rect (0, 0, 50, 50);
617                         r.Intersect (new Rect (5, 75, 1, 1));
618                         Assert.AreEqual (Rect.Empty, r);
619
620                         // completely outside (left)
621                         r = new Rect (0, 0, 50, 50);
622                         r.Intersect (new Rect (-25, 5, 1, 1));
623                         Assert.AreEqual (Rect.Empty, r);
624                 }
625
626                 [Test]
627                 public void Union()
628                 {
629                         Rect r;
630                         
631                         // fully contained
632                         r = new Rect(0, 0, 50, 50);
633                         r.Union(new Rect(10, 10, 10, 10));
634                         Assert.AreEqual(new Rect(0, 0, 50, 50), r);
635
636                         // crosses top side
637                         r = new Rect(0, 0, 50, 50);
638                         r.Union(new Rect(5, -5, 10, 10));
639                         Assert.AreEqual(new Rect(0, -5, 50, 55), r);
640
641                         // crosses right side
642                         r = new Rect(0, 0, 50, 50);
643                         r.Union(new Rect(5, 5, 50, 10));
644                         Assert.AreEqual(new Rect(0, 0, 55, 50), r);
645
646                         // crosses bottom side
647                         r = new Rect(0, 0, 50, 50);
648                         r.Union(new Rect(5, 5, 10, 50));
649                         Assert.AreEqual(new Rect(0, 0, 50, 55), r);
650
651                         // crosses left side
652                         r = new Rect(0, 0, 50, 50);
653                         r.Union(new Rect(-5, 5, 10, 10));
654                         Assert.AreEqual(new Rect(-5, 0, 55, 50), r);
655
656                         // completely outside (top)
657                         r = new Rect(0, 0, 50, 50);
658                         r.Union(new Rect(5, -5, 1, 1));
659                         Assert.AreEqual(new Rect(0, -5, 50, 55), r);
660
661                         // completely outside (right)
662                         r = new Rect(0, 0, 50, 50);
663                         r.Union(new Rect(75, 5, 1, 1));
664                         Assert.AreEqual(new Rect(0, 0, 76, 50), r);
665
666                         // completely outside (bottom)
667                         r = new Rect(0, 0, 50, 50);
668                         r.Union(new Rect(5, 75, 1, 1));
669                         Assert.AreEqual(new Rect(0,0, 50, 76), r);
670
671                         // completely outside (left)
672                         r = new Rect(0, 0, 50, 50);
673                         r.Union(new Rect(-25, 5, 1, 1));
674                         Assert.AreEqual(new Rect(-25, 0, 75, 50), r);
675                 }
676
677                 [Test]
678                 public void Equals_Operator ()
679                 {
680                         Rect r1 = new Rect (1, 2, 30, 30);
681                         Rect r2 = new Rect (1, 2, 30, 30);
682
683                         Assert.AreEqual (true,  r1 == r2);
684                         Assert.AreEqual (false, r1 != r2);
685
686                         r2 = new Rect (10, 20, 30, 30);
687
688                         Assert.AreEqual (false, r1 == r2);
689                         Assert.AreEqual (true,  r1 != r2);
690
691                         r1 = Rect.Empty;
692                         r2 = Rect.Empty;
693
694                         Assert.AreEqual (true, r1 == r2);
695                         Assert.AreEqual (false, r1 != r2);
696                 }
697
698         }
699 }
700