[jit] Use MONO_INS_IS_PCONST_NULL () macro in more places.
[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                 public void ToStringTest ()
263                 {
264                         Rect r = new Rect (1.0, 2.5, 3, 4);
265
266                         string expectedStringOutput = "1,2.5,3,4";
267                         Assert.AreEqual (expectedStringOutput, r.ToString ());
268                         Assert.AreEqual (expectedStringOutput, r.ToString (null));
269                         Assert.AreEqual ("Empty", Rect.Empty.ToString ());
270
271                         // IFormattable.ToString
272                         IFormattable rFormattable = r;
273                         Assert.AreEqual (expectedStringOutput,
274                                 rFormattable.ToString (null, null),
275                                 "IFormattable.ToString with null format");
276                         Assert.AreEqual (expectedStringOutput,
277                                 rFormattable.ToString (string.Empty, null),
278                                 "IFormattable.ToString with empty format");
279                         Assert.AreEqual ("1.00,2.50,3.00,4.00",
280                                 rFormattable.ToString ("N2", null),
281                                 "IFormattable.ToString with N2 format");
282                         Assert.AreEqual ("blah,blah,blah,blah",
283                                 rFormattable.ToString ("blah", null),
284                                 "IFormattable.ToString with blah format");
285                         Assert.AreEqual (":,:,:,:",
286                                 rFormattable.ToString (":", null),
287                                 "IFormattable.ToString with : format");
288                         Assert.AreEqual ("Empty",
289                                 ((IFormattable) Rect.Empty).ToString ("blah", null),
290                                 "IFormattable.ToString on Rect.Empty with blah format");
291
292                         foreach (CultureInfo culture in CultureInfo.GetCultures (CultureTypes.AllCultures)) {
293                                 if (culture.IsNeutralCulture)
294                                         continue;
295                                 string separator = ",";
296                                 if (culture.NumberFormat.NumberDecimalSeparator == separator)
297                                         separator = ";";
298                                 expectedStringOutput =
299                                         1.ToString (culture) + separator +
300                                         2.5.ToString (culture) + separator +
301                                         3.ToString (culture) + separator +
302                                         4.ToString (culture);
303                                 Assert.AreEqual (expectedStringOutput,
304                                         r.ToString (culture),
305                                         "ToString with Culture: " + culture.Name);
306                                 Assert.AreEqual ("Empty",
307                                         Rect.Empty.ToString (culture),
308                                         "ToString on Empty with Culture: " + culture.Name);
309
310                                 // IFormattable.ToString
311                                 Assert.AreEqual (expectedStringOutput,
312                                         rFormattable.ToString (null, culture),
313                                         "IFormattable.ToString with null format with Culture: " + culture.Name);
314                                 Assert.AreEqual (expectedStringOutput,
315                                         rFormattable.ToString (string.Empty, culture),
316                                         "IFormattable.ToString with empty format with Culture: " + culture.Name);
317                                 expectedStringOutput =
318                                         1.ToString ("N2", culture) + separator +
319                                         2.5.ToString ("N2", culture) + separator +
320                                         3.ToString ("N2", culture) + separator +
321                                         4.ToString ("N2", culture);
322                                 Assert.AreEqual (expectedStringOutput,
323                                         rFormattable.ToString ("N2", culture),
324                                         "IFormattable.ToString with N2 format with Culture: " + culture.Name);
325                         }
326                 }
327                 
328                 [Test]
329                 [Category ("NotWorking")]
330                 public void ToString_FormatException ()
331                 {
332                         // This test does not currently work because
333                         // String.Format does not throw all necessary exceptions
334                         IFormattable rFormattable = new Rect (1.0, 2.5, 3, 4);
335                         bool exceptionRaised = false;
336                         try {
337                                 rFormattable.ToString ("{", null);
338                         } catch (FormatException) {
339                                 exceptionRaised = true;
340                         }
341                         Assert.IsTrue (exceptionRaised, "Expected FormatException with IFormattable.ToString (\"{\", null)");
342                 }
343
344                 [Test]
345                 [Category ("NotWorking")]
346                 public void Parse ()
347                 {
348                         Rect r = Rect.Parse ("1 , 2, 3, 4");
349                         Assert.AreEqual (new Rect (1, 2, 3, 4), r);
350                 }
351
352                 [Test]
353                 [Category ("NotWorking")]
354                 public void Parse2 ()
355                 {
356                         Rect r = Rect.Parse ("1 2 3 4");
357                         Assert.AreEqual (new Rect (1, 2, 3, 4), r);
358                 }
359
360                 [Test]
361                 [Category ("NotWorking")]
362                 public void Parse3 ()
363                 {
364                         Rect r = Rect.Parse ("  1 2 3 4  ");
365                         Assert.AreEqual (new Rect (1, 2, 3, 4), r);
366                 }
367
368                 [Test]
369                 [Category ("NotWorking")]
370                 public void ParseWithBothSeparators ()
371                 {
372                         Rect.Parse ("1.0, 3 2.0, 5.0");
373                 }
374
375                 [Test]
376                 [Category ("NotWorking")]
377                 [ExpectedException (typeof (ArgumentException))]
378                 public void ParseNegative ()
379                 {
380                         Rect.Parse ("1, 2, -3, -4");
381                 }
382
383                 [Test]
384                 [Category ("NotWorking")]
385                 [ExpectedException (typeof (InvalidOperationException))] // "Premature string termination encountered."
386                 public void Parse3Doubles ()
387                 {
388                         Rect.Parse ("1.0, 3, -5");
389                 }
390
391                 [Test]
392                 [Category ("NotWorking")]
393                 [ExpectedException (typeof (FormatException))]
394                 public void ParseInvalidString1 ()
395                 {
396                         Rect.Parse ("1.0, 3, -x, 5.0");
397                 }
398
399                 [Test]
400                 [Category ("NotWorking")]
401                 [ExpectedException (typeof (InvalidOperationException))]
402                 public void ParseInvalidString3 ()
403                 {
404                         Rect.Parse ("1.0, 3, 2.0, 5.0, 2");
405                 }
406
407                 [Test]
408                 [Category ("NotWorking")]
409                 [ExpectedException (typeof (FormatException))]
410                 public void ParseInvalidString4 ()
411                 {
412                         Rect.Parse ("1.0-3, 2.0, 5.0, 2");
413                 }
414
415                 [Test]
416                 [Category ("NotWorking")]
417                 [ExpectedException (typeof (InvalidOperationException))]
418                 public void ParseInvalidString5 ()
419                 {
420                         Rect.Parse ("1.0, 2.0, 5.0, 2,");
421                 }
422
423                 [Test]
424                 [Category ("NotWorking")]
425                 public void ParseInvalidString6 ()
426                 {
427                         Rect.Parse ("\n1.0, 2.0, 5.0, 2");
428                 }
429
430                 [Test]
431                 [Category ("NotWorking")]
432                 [ExpectedException (typeof (InvalidOperationException))]
433                 public void ParseInvalidString7 ()
434                 {
435                         Rect r = Rect.Parse ("1,, 2, 3, 4");
436                         Assert.AreEqual (new Rect (1, 2, 3, 4), r);
437                 }
438
439                 [Test]
440                 public void Equals ()
441                 {
442                         Rect r1 = new Rect (1, 2, 3, 4);
443                         Rect r2 = r1;
444
445                         Assert.IsTrue (r1.Equals (r1));
446
447                         r2.X = 0;
448                         Assert.IsFalse (r1.Equals (r2));
449                         r2.X = r1.X;
450
451                         r2.Y = 0;
452                         Assert.IsFalse (r1.Equals (r2));
453                         r2.Y = r1.Y;
454
455                         r2.Width = 0;
456                         Assert.IsFalse (r1.Equals (r2));
457                         r2.Width = r1.Width;
458
459                         r2.Height = 0;
460                         Assert.IsFalse (r1.Equals (r2));
461                         r2.Height = r1.Height;
462
463                         Assert.IsFalse (r1.Equals (new object ()));
464
465                         r1 = Rect.Empty;
466                         r2 = Rect.Empty;
467
468                         Assert.AreEqual (true, r1.Equals (r2));
469                         Assert.AreEqual (true, r2.Equals (r1));
470                 }
471
472                 [Test]
473                 public void ContainsRect ()
474                 {
475                         Rect r = new Rect (0, 0, 50, 50);
476
477                         // fully contained
478                         Assert.IsTrue (r.Contains (new Rect (10, 10, 10, 10)));
479
480                         // crosses top side
481                         Assert.IsFalse (r.Contains (new Rect (5, -5, 10, 10)));
482
483                         // crosses right side
484                         Assert.IsFalse (r.Contains (new Rect (5, 5, 50, 10)));
485
486                         // crosses bottom side
487                         Assert.IsFalse (r.Contains (new Rect (5, 5, 10, 50)));
488
489                         // crosses left side
490                         Assert.IsFalse (r.Contains (new Rect (-5, 5, 10, 10)));
491
492                         // completely outside (top)
493                         Assert.IsFalse (r.Contains (new Rect (5, -5, 1, 1)));
494
495                         // completely outside (right)
496                         Assert.IsFalse (r.Contains (new Rect (75, 5, 1, 1)));
497
498                         // completely outside (bottom)
499                         Assert.IsFalse (r.Contains (new Rect (5, 75, 1, 1)));
500
501                         // completely outside (left)
502                         Assert.IsFalse (r.Contains (new Rect (-25, 5, 1, 1)));
503                 }
504
505                 [Test]
506                 public void ContainsDoubles ()
507                 {
508                         Rect r = new Rect (0, 0, 50, 50);
509
510                         Assert.IsTrue (r.Contains (10, 10));
511                         Assert.IsFalse (r.Contains (-5, -5));
512                 }
513
514                 [Test]
515                 public void ContainsPoint ()
516                 {
517                         Rect r = new Rect (0, 0, 50, 50);
518
519                         Assert.IsTrue (r.Contains (new Point (10, 10)));
520                         Assert.IsFalse (r.Contains (new Point (-5, -5)));
521                 }
522
523                 [Test]
524                 public void Inflate ()
525                 {
526                         Rect r = Rect.Inflate (new Rect (0, 0, 20, 20), 10, 15);
527                         Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
528
529                         r = Rect.Inflate (new Rect (0, 0, 20, 20), new Size (10, 15));
530                         Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
531
532                         r = new Rect (0, 0, 20, 20);
533                         r.Inflate (10, 15);
534                         Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
535
536                         r = new Rect (0, 0, 20, 20);
537                         r.Inflate (new Size (10, 15));
538                         Assert.AreEqual (new Rect (-10, -15, 40, 50), r);
539                 }
540
541                 [Test]
542                 public void IntersectsWith ()
543                 {
544                         Rect r = new Rect (0, 0, 50, 50);
545
546                         // fully contained
547                         Assert.IsTrue (r.IntersectsWith (new Rect (10, 10, 10, 10)));
548
549                         // crosses top side
550                         Assert.IsTrue (r.IntersectsWith (new Rect (5, -5, 10, 10)));
551
552                         // crosses right side
553                         Assert.IsTrue (r.IntersectsWith (new Rect (5, 5, 50, 10)));
554
555                         // crosses bottom side
556                         Assert.IsTrue (r.IntersectsWith (new Rect (5, 5, 10, 50)));
557
558                         // crosses left side
559                         Assert.IsTrue (r.IntersectsWith (new Rect (-5, 5, 10, 10)));
560
561                         // completely outside (top)
562                         Assert.IsFalse (r.IntersectsWith (new Rect (5, -5, 1, 1)));
563
564                         // completely outside (right)
565                         Assert.IsFalse (r.IntersectsWith (new Rect (75, 5, 1, 1)));
566
567                         // completely outside (bottom)
568                         Assert.IsFalse (r.IntersectsWith (new Rect (5, 75, 1, 1)));
569
570                         // completely outside (left)
571                         Assert.IsFalse (r.IntersectsWith (new Rect (-25, 5, 1, 1)));
572                 }
573
574                 [Test]
575                 public void Intersect ()
576                 {
577                         Rect r;
578
579                         // fully contained
580                         r = new Rect (0, 0, 50, 50);
581                         r.Intersect (new Rect (10, 10, 10, 10));
582                         Assert.AreEqual (new Rect (10, 10, 10, 10), r);
583
584                         // crosses top side
585                         r = new Rect (0, 0, 50, 50);
586                         r.Intersect (new Rect (5, -5, 10, 10));
587                         Assert.AreEqual (new Rect (5, 0, 10, 5), r);
588
589                         // crosses right side
590                         r = new Rect (0, 0, 50, 50);
591                         r.Intersect (new Rect (5, 5, 50, 10));
592                         Assert.AreEqual (new Rect (5, 5, 45, 10), r);
593
594                         // crosses bottom side
595                         r = new Rect (0, 0, 50, 50);
596                         r.Intersect (new Rect (5, 5, 10, 50));
597                         Assert.AreEqual(new Rect(5, 5, 10, 45), r);
598
599                         // crosses left side
600                         r = new Rect (0, 0, 50, 50);
601                         r.Intersect (new Rect (-5, 5, 10, 10));
602                         Assert.AreEqual(new Rect(0, 5, 5, 10), r);
603
604                         // completely outside (top)
605                         r = new Rect (0, 0, 50, 50);
606                         r.Intersect (new Rect (5, -5, 1, 1));
607                         Assert.AreEqual (Rect.Empty, r);
608
609                         // completely outside (right)
610                         r = new Rect (0, 0, 50, 50);
611                         r.Intersect (new Rect (75, 5, 1, 1));
612                         Assert.AreEqual (Rect.Empty, r);
613
614                         // completely outside (bottom)
615                         r = new Rect (0, 0, 50, 50);
616                         r.Intersect (new Rect (5, 75, 1, 1));
617                         Assert.AreEqual (Rect.Empty, r);
618
619                         // completely outside (left)
620                         r = new Rect (0, 0, 50, 50);
621                         r.Intersect (new Rect (-25, 5, 1, 1));
622                         Assert.AreEqual (Rect.Empty, r);
623                 }
624
625                 [Test]
626                 public void Union()
627                 {
628                         Rect r;
629                         
630                         // fully contained
631                         r = new Rect(0, 0, 50, 50);
632                         r.Union(new Rect(10, 10, 10, 10));
633                         Assert.AreEqual(new Rect(0, 0, 50, 50), r);
634
635                         // crosses top side
636                         r = new Rect(0, 0, 50, 50);
637                         r.Union(new Rect(5, -5, 10, 10));
638                         Assert.AreEqual(new Rect(0, -5, 50, 55), r);
639
640                         // crosses right side
641                         r = new Rect(0, 0, 50, 50);
642                         r.Union(new Rect(5, 5, 50, 10));
643                         Assert.AreEqual(new Rect(0, 0, 55, 50), r);
644
645                         // crosses bottom side
646                         r = new Rect(0, 0, 50, 50);
647                         r.Union(new Rect(5, 5, 10, 50));
648                         Assert.AreEqual(new Rect(0, 0, 50, 55), r);
649
650                         // crosses left side
651                         r = new Rect(0, 0, 50, 50);
652                         r.Union(new Rect(-5, 5, 10, 10));
653                         Assert.AreEqual(new Rect(-5, 0, 55, 50), r);
654
655                         // completely outside (top)
656                         r = new Rect(0, 0, 50, 50);
657                         r.Union(new Rect(5, -5, 1, 1));
658                         Assert.AreEqual(new Rect(0, -5, 50, 55), r);
659
660                         // completely outside (right)
661                         r = new Rect(0, 0, 50, 50);
662                         r.Union(new Rect(75, 5, 1, 1));
663                         Assert.AreEqual(new Rect(0, 0, 76, 50), r);
664
665                         // completely outside (bottom)
666                         r = new Rect(0, 0, 50, 50);
667                         r.Union(new Rect(5, 75, 1, 1));
668                         Assert.AreEqual(new Rect(0,0, 50, 76), r);
669
670                         // completely outside (left)
671                         r = new Rect(0, 0, 50, 50);
672                         r.Union(new Rect(-25, 5, 1, 1));
673                         Assert.AreEqual(new Rect(-25, 0, 75, 50), r);
674                 }
675
676                 [Test]
677                 public void Equals_Operator ()
678                 {
679                         Rect r1 = new Rect (1, 2, 30, 30);
680                         Rect r2 = new Rect (1, 2, 30, 30);
681
682                         Assert.AreEqual (true,  r1 == r2);
683                         Assert.AreEqual (false, r1 != r2);
684
685                         r2 = new Rect (10, 20, 30, 30);
686
687                         Assert.AreEqual (false, r1 == r2);
688                         Assert.AreEqual (true,  r1 != r2);
689
690                         r1 = Rect.Empty;
691                         r2 = Rect.Empty;
692
693                         Assert.AreEqual (true, r1 == r2);
694                         Assert.AreEqual (false, r1 != r2);
695                 }
696
697         }
698 }
699