New test.
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestRegion.cs
1 //
2 // Region class testing unit
3 //
4 // Authors:
5 //   Jordi Mas, jordi@ximian.com
6 //   Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Drawing.Imaging;
32 using System.Drawing;
33 using System.Drawing.Drawing2D;
34 using System.Security.Permissions;
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Drawing
38 {
39
40         [TestFixture]
41         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
42         public class TestRegion
43         {
44                 /* For debugging */
45                 public static void DumpRegion (Region rgn)
46                 {
47                         Matrix matrix = new Matrix ();
48                         RectangleF [] rects = rgn.GetRegionScans (matrix);
49
50                         for (int i = 0; i < rects.Length; i++)
51                                 Console.WriteLine ( rects[i]);
52                 }
53
54                 private Bitmap bitmap;
55                 private Graphics graphic;
56
57                 [TestFixtureSetUp]
58                 public void FixtureSetUp ()
59                 {
60                         bitmap = new Bitmap (10, 10);
61                         graphic = Graphics.FromImage (bitmap);
62                 }
63
64                 [Test]
65                 public void TestBounds()
66                 {
67                         Bitmap bmp = new Bitmap (600, 800);
68                         Graphics dc = Graphics.FromImage (bmp);
69                         Rectangle rect1, rect2;
70                         Region rgn1, rgn2;
71                         RectangleF bounds;
72
73                         rect1 = new Rectangle (500, 30, 60, 80);
74                         rect2 = new Rectangle (520, 40, 60, 80);
75                         rgn1 = new Region(rect1);
76                         rgn2 = new Region(rect2);
77                         rgn1.Union(rgn2);
78
79                         bounds = rgn1.GetBounds (dc);
80
81                         Assert.AreEqual (500, bounds.X);
82                         Assert.AreEqual (30, bounds.Y);
83                         Assert.AreEqual (80, bounds.Width);
84                         Assert.AreEqual (90, bounds.Height);
85                 }
86
87                 [Test]
88 #if TARGET_JVM
89                 [Category ("NotWorking")]
90 #endif
91                 public void TestCloneAndEquals()
92                 {
93                         Bitmap bmp = new Bitmap (600, 800);
94                         Graphics dc = Graphics.FromImage (bmp);
95                         Rectangle rect1, rect2;
96                         Region rgn1, rgn2;
97                         RectangleF [] rects;
98                         RectangleF [] rects2;
99                         Matrix matrix = new Matrix ();
100
101                         rect1 = new Rectangle (500, 30, 60, 80);
102                         rect2 = new Rectangle (520, 40, 60, 80);
103                         rgn1 = new Region (rect1);
104                         rgn1.Union (rect2);
105                         rgn2 = rgn1.Clone ();
106
107                         rects = rgn1.GetRegionScans (matrix);
108                         rects2 = rgn2.GetRegionScans (matrix);
109
110                         Assert.AreEqual (rects.Length, rects2.Length);
111
112                         for (int i = 0; i < rects.Length; i++) {
113
114                                 Assert.AreEqual (rects[i].X, rects[i].X);
115                                 Assert.AreEqual (rects[i].Y, rects[i].Y);
116                                 Assert.AreEqual (rects[i].Width, rects[i].Width);
117                                 Assert.AreEqual (rects[i].Height, rects[i].Height);
118                         }
119
120                         Assert.AreEqual (true, rgn1.Equals (rgn2, dc));
121                 }
122
123                  /*Tests infinite, empty, etc*/
124                 [Test]
125 #if TARGET_JVM
126                 [Category ("NotWorking")]
127 #endif
128                 public void TestInfiniteAndEmpty()
129                 {
130                         Bitmap bmp = new Bitmap (600, 800);
131                         Graphics dc = Graphics.FromImage (bmp);
132                         Rectangle rect1, rect2;
133                         Region rgn1;
134                         RectangleF [] rects;
135                         Matrix matrix = new Matrix ();
136
137                         rect1 = new Rectangle (500, 30, 60, 80);
138                         rect2 = new Rectangle (520, 40, 60, 80);
139                         rgn1 = new Region (rect1);
140                         rgn1.Union (rect2);
141
142                         Assert.AreEqual (false, rgn1.IsEmpty (dc));
143                         Assert.AreEqual (false, rgn1.IsInfinite (dc));
144
145                         rgn1.MakeEmpty();
146                         Assert.AreEqual (true, rgn1.IsEmpty (dc));
147
148                         rgn1 = new Region (rect1);
149                         rgn1.Union (rect2);
150                         rgn1.MakeInfinite ();
151                         rects = rgn1.GetRegionScans (matrix);
152
153                         Assert.AreEqual (1, rects.Length);
154                         Assert.AreEqual (-4194304, rects[0].X);
155                         Assert.AreEqual (-4194304, rects[0].Y);
156                         Assert.AreEqual (8388608, rects[0].Width);
157                         Assert.AreEqual (8388608, rects[0].Height);
158                         Assert.AreEqual (true, rgn1.IsInfinite (dc));
159                 }
160
161
162                 [Test]
163 #if TARGET_JVM
164                 [Category ("NotWorking")]
165 #endif
166                 public void TestUnionGroup1 ()
167                 {
168                         Bitmap bmp = new Bitmap (600, 800);
169                         Graphics dc = Graphics.FromImage (bmp);
170                         Matrix matrix = new Matrix ();
171                         Rectangle rect1, rect2, rect3, rect4;
172                         Region rgn1, rgn2, rgn3, rgn4;
173                         RectangleF [] rects;
174
175                         rect1 = new Rectangle (500, 30, 60, 80);
176                         rect2 = new Rectangle (520, 40, 60, 80);
177                         rgn1 = new Region(rect1);
178                         rgn2 = new Region(rect2);
179                         rgn1.Union(rgn2);
180                         rects = rgn1.GetRegionScans (matrix);
181
182                         Assert.AreEqual (3, rects.Length);
183                         Assert.AreEqual (500, rects[0].X);
184                         Assert.AreEqual (30, rects[0].Y);
185                         Assert.AreEqual (60, rects[0].Width);
186                         Assert.AreEqual (10, rects[0].Height);
187
188                         Assert.AreEqual (500, rects[1].X);
189                         Assert.AreEqual (40, rects[1].Y);
190                         Assert.AreEqual (80, rects[1].Width);
191                         Assert.AreEqual (70, rects[1].Height);
192
193                         Assert.AreEqual (520, rects[2].X);
194                         Assert.AreEqual (110, rects[2].Y);
195                         Assert.AreEqual (60, rects[2].Width);
196                         Assert.AreEqual (10, rects[2].Height);
197
198                         rect1 = new Rectangle (20, 180, 40, 50);
199                         rect2 = new Rectangle (50, 190, 40, 50);
200                         rect3 = new Rectangle (70, 210, 30, 50);
201                         rgn1 = new Region (rect1);
202                         rgn2 = new Region (rect2);
203                         rgn3 = new Region (rect3);
204
205                         rgn1.Union (rgn2);
206                         rgn1.Union (rgn3);
207                         rects = rgn1.GetRegionScans (matrix);
208                         Assert.AreEqual (5, rects.Length);
209
210                         Assert.AreEqual (20, rects[0].X);
211                         Assert.AreEqual (180, rects[0].Y);
212                         Assert.AreEqual (40, rects[0].Width);
213                         Assert.AreEqual (10, rects[0].Height);
214
215                         Assert.AreEqual (20, rects[1].X);
216                         Assert.AreEqual (190, rects[1].Y);
217                         Assert.AreEqual (70, rects[1].Width);
218                         Assert.AreEqual (20, rects[1].Height);
219
220                         Assert.AreEqual (20, rects[2].X);
221                         Assert.AreEqual (210, rects[2].Y);
222                         Assert.AreEqual (80, rects[2].Width);
223                         Assert.AreEqual (20, rects[2].Height);
224
225                         Assert.AreEqual (50, rects[3].X);
226                         Assert.AreEqual (230, rects[3].Y);
227                         Assert.AreEqual (50, rects[3].Width);
228                         Assert.AreEqual (10, rects[3].Height);
229
230                         Assert.AreEqual (70, rects[4].X);
231                         Assert.AreEqual (240, rects[4].Y);
232                         Assert.AreEqual (30, rects[4].Width);
233                         Assert.AreEqual (20, rects[4].Height);
234
235                         rect1 = new Rectangle (20, 330, 40, 50);
236                         rect2 = new Rectangle (50, 340, 40, 50);
237                         rect3 = new Rectangle (70, 360, 30, 50);
238                         rect4 = new Rectangle (80, 400, 30, 10);
239                         rgn1 = new Region (rect1);
240                         rgn2 = new Region (rect2);
241                         rgn3 = new Region (rect3);
242                         rgn4 = new Region (rect4);
243
244                         rgn1.Union (rgn2);
245                         rgn1.Union (rgn3);
246                         rgn1.Union (rgn4);
247
248                         rects = rgn1.GetRegionScans (matrix);
249
250                         Assert.AreEqual (6, rects.Length);
251
252                         Assert.AreEqual (20, rects[0].X);
253                         Assert.AreEqual (330, rects[0].Y);
254                         Assert.AreEqual (40, rects[0].Width);
255                         Assert.AreEqual (10, rects[0].Height);
256
257                         Assert.AreEqual (20, rects[1].X);
258                         Assert.AreEqual (340, rects[1].Y);
259                         Assert.AreEqual (70, rects[1].Width);
260                         Assert.AreEqual (20, rects[1].Height);
261
262                         Assert.AreEqual (20, rects[2].X);
263                         Assert.AreEqual (360, rects[2].Y);
264                         Assert.AreEqual (80, rects[2].Width);
265                         Assert.AreEqual (20, rects[2].Height);
266
267                         Assert.AreEqual (50, rects[3].X);
268                         Assert.AreEqual (380, rects[3].Y);
269                         Assert.AreEqual (50, rects[3].Width);
270                         Assert.AreEqual (10, rects[3].Height);
271
272                         Assert.AreEqual (70, rects[4].X);
273                         Assert.AreEqual (390, rects[4].Y);
274                         Assert.AreEqual (30, rects[4].Width);
275                         Assert.AreEqual (10, rects[4].Height);
276
277                         Assert.AreEqual (70, rects[5].X);
278                         Assert.AreEqual (400, rects[5].Y);
279                         Assert.AreEqual (40, rects[5].Width);
280                         Assert.AreEqual (10, rects[5].Height);
281
282                         rect1 = new Rectangle (10, 20, 50, 50);
283                         rect2 = new Rectangle (100, 100, 60, 60);
284                         rect3 = new Rectangle (200, 200, 80, 80);
285
286                         rgn1 = new Region (rect1);
287                         rgn1.Union (rect2);
288                         rgn1.Union (rect3);
289
290                         rects = rgn1.GetRegionScans (matrix);
291
292                         Assert.AreEqual (3, rects.Length);
293
294                         Assert.AreEqual (10, rects[0].X);
295                         Assert.AreEqual (20, rects[0].Y);
296                         Assert.AreEqual (50, rects[0].Width);
297                         Assert.AreEqual (50, rects[0].Height);
298
299                         Assert.AreEqual (100, rects[1].X);
300                         Assert.AreEqual (100, rects[1].Y);
301                         Assert.AreEqual (60, rects[1].Width);
302                         Assert.AreEqual (60, rects[1].Height);
303
304                         Assert.AreEqual (200, rects[2].X);
305                         Assert.AreEqual (200, rects[2].Y);
306                         Assert.AreEqual (80, rects[2].Width);
307                         Assert.AreEqual (80, rects[2].Height);
308                 }
309
310                 void AssertEqualRectangles (RectangleF rect1, RectangleF rect2, string text)
311                 {
312                         Assert.AreEqual (rect1.X, rect2.X, text + ".X");
313                         Assert.AreEqual (rect1.Y, rect2.Y, text + ".Y");
314                         Assert.AreEqual (rect1.Width, rect2.Width, text + ".Width");
315                         Assert.AreEqual (rect1.Height, rect2.Height, text + ".Height");
316                 }
317
318                 [Test]
319 #if TARGET_JVM
320                 [Category ("NotWorking")]
321 #endif
322                 public void TestUnionGroup2 ()
323                 {
324                         RectangleF[] rects;
325                         Region r1  = new Region ();
326                         Rectangle rect2 = Rectangle.Empty;
327                         Rectangle rect1 = Rectangle.Empty;
328                         Rectangle rect3 = Rectangle.Empty;
329                         Rectangle rect4 = Rectangle.Empty;
330
331                         { // TEST1: Not intersecting rects. Union just adds them
332
333                                 rect1 = new Rectangle (20, 20, 20, 20);
334                                 rect2 = new Rectangle (20, 80, 20, 10);
335                                 rect3 = new Rectangle (60, 60, 30, 10);
336
337                                 r1 = new Region (rect1);
338                                 r1.Union (rect2);
339                                 r1.Union (rect3);
340
341                                 rects = r1.GetRegionScans (new Matrix ());
342                                 Assert.AreEqual (3, rects.Length, "TUG1Test1");
343                                 AssertEqualRectangles (new RectangleF (20, 20, 20, 20), rects[0], "TUG1Test2");
344                                 AssertEqualRectangles (new RectangleF (60, 60, 30, 10), rects[1], "TUG1Test3");
345                                 AssertEqualRectangles (new RectangleF (20, 80, 20, 10), rects[2], "TUG1Test4");
346                         }
347
348                         { // TEST2: Intersecting from the right
349                                  /*
350                                  *  -----------
351                                  *  |         |
352                                  *  |     |-------- |
353                                  *  |     |         |
354                                  *  |     |-------- |
355                                  *  |         |
356                                  *  ----------|
357                                  *
358                                  */
359
360                                 rect1 = new Rectangle (10, 10, 100, 100);
361                                 rect2 = new Rectangle (40, 60, 100, 20);
362                                 r1 = new Region (rect1);
363                                 r1.Union (rect2);
364
365                                 rects = r1.GetRegionScans (new Matrix ());
366                                 Assert.AreEqual  (3, rects.Length, "TUG2Test1");
367                                 AssertEqualRectangles (new RectangleF (10, 10, 100, 50), rects[0], "TUG2Test2");
368                                 AssertEqualRectangles (new RectangleF (10, 60, 130, 20), rects[1], "TUG2Test3");
369                                 AssertEqualRectangles (new RectangleF (10, 80, 100, 30), rects[2], "TUG2Test4");
370                         }
371
372                         { // TEST3: Intersecting from the right
373                                  /*
374                                  *      -----------
375                                  *      |         |
376                                  * |-------- |    |
377                                  * |         |    |
378                                  * |-------- |    |
379                                  *      |         |
380                                  *      ----------|
381                                  *
382                                  */
383
384                                 rect1 = new Rectangle (70, 10, 100, 100);
385                                 rect2 = new Rectangle (40, 60, 100, 20);
386
387                                 r1 = new Region (rect1);
388                                 r1.Union (rect2);
389
390                                 rects = r1.GetRegionScans (new Matrix ());
391                                 Assert.AreEqual  (3, rects.Length, "TUG3Test1");
392                                 AssertEqualRectangles (new RectangleF (70, 10, 100, 50), rects[0], "TUG3Test2");
393                                 AssertEqualRectangles (new RectangleF (40, 60, 130, 20), rects[1], "TUG3Test3");
394                                 AssertEqualRectangles (new RectangleF (70, 80, 100, 30), rects[2], "TUG3Test4");
395                         }
396
397                         { // TEST4: Intersecting from the top
398                                  /*
399                                  *         -----
400                                  *         |   |
401                                  *      -----------
402                                  *      |  |   |  |
403                                  *      |  -----  |
404                                  *      |         |
405                                  *      |         |
406                                  *      ----------|
407                                  *
408                                  */
409
410                                 rect1 = new Rectangle (40, 100, 100, 100);
411                                 rect2 = new Rectangle (70, 80, 50, 40);
412                                 r1 = new Region (rect1);
413                                 r1.Union (rect2);
414
415                                 rects = r1.GetRegionScans (new Matrix ());
416                                 Assert.AreEqual  (2, rects.Length, "TUG4Test1");
417                                 AssertEqualRectangles (new RectangleF (70, 80, 50, 20), rects[0], "TUG4Test2");
418                                 AssertEqualRectangles (new RectangleF (40, 100, 100, 100), rects[1], "TUG4Test3");
419                         }
420
421                         { // TEST5: Intersecting from the bottom
422                                  /*
423
424                                  *      -----------
425                                  *      |         |
426                                  *      |         |
427                                  *      |         |
428                                  *      |  |   |  |
429                                  *      |--|   |--|
430                                  *         |   |
431                                  *         -----
432                                  */
433
434                                 rect1 = new Rectangle (40, 10, 100, 100);
435                                 rect2 = new Rectangle (70, 80, 50, 40);
436
437                                 r1 = new Region (rect1);
438                                 r1.Union (rect2);
439
440                                 rects = r1.GetRegionScans (new Matrix ());
441                                 Assert.AreEqual  (2, rects.Length, "TUG5Test1");
442                                 AssertEqualRectangles (new RectangleF (40, 10, 100, 100), rects[0], "TUG5Test2");
443                                 AssertEqualRectangles (new RectangleF (70, 110, 50, 10), rects[1], "TUG5Test3");
444                         }
445
446                         { // TEST6: Multiple regions, two separted by zero pixels
447
448                                 rect1 = new Rectangle (30, 30, 80, 80);
449                                 rect2 = new Rectangle (45, 45, 200, 200);
450                                 rect3 = new Rectangle (160, 260, 10, 10);
451                                 rect4 = new Rectangle (170, 260, 10, 10);
452
453                                 r1 = new Region (rect1);
454                                 r1.Union (rect2);
455                                 r1.Union (rect3);
456                                 r1.Union (rect4);
457
458                                 rects = r1.GetRegionScans (new Matrix ());
459                                 Assert.AreEqual  (4, rects.Length, "TUG6Test1");
460                                 AssertEqualRectangles (new RectangleF (30, 30, 80, 15), rects[0], "TUG6Test2");
461                                 AssertEqualRectangles (new RectangleF (30, 45, 215, 65), rects[1], "TUG6Test3");
462                                 AssertEqualRectangles (new RectangleF (45, 110, 200, 135), rects[2], "TUG6Test4");
463                                 AssertEqualRectangles (new RectangleF (160, 260, 20, 10), rects[3], "TUG6Test5");
464                         }
465                 }
466
467
468                 [Test]
469 #if TARGET_JVM
470                 [Category ("NotWorking")]
471 #endif
472                 public void TestComplementGroup1 ()
473                 {
474                         RectangleF[] rects;
475                         Region r1  = new Region ();
476                         Region r2 = new Region ();
477                         Rectangle rect1 = Rectangle.Empty;
478                         Rectangle rect2 = Rectangle.Empty;
479                         Rectangle rect3 = Rectangle.Empty;
480                         Rectangle rect4 = Rectangle.Empty;
481                         Rectangle rect5 = Rectangle.Empty;
482                         Rectangle rect6 = Rectangle.Empty;
483                         Rectangle rect7 = Rectangle.Empty;
484
485
486                         { // TEST1
487
488                                 rect1 = new Rectangle (20, 20, 20, 20);
489                                 rect2 = new Rectangle (20, 80, 20, 10);
490                                 rect3 = new Rectangle (60, 60, 30, 10);
491
492                                 r1 = new Region (rect1);
493                                 r2 = new Region (rect2);
494                                 r2.Union (rect3);
495                                 r1.Complement (r2);
496
497                                 rects = r1.GetRegionScans (new Matrix ());
498                                 Assert.AreEqual  (2, rects.Length, "TCG1Test1");
499                                 AssertEqualRectangles (new RectangleF (60, 60, 30, 10), rects[0], "TCG1Test2");
500                                 AssertEqualRectangles (new RectangleF (20, 80, 20, 10), rects[1], "TCG1Test3");
501                         }
502
503
504                         { // TEST2
505
506                                 rect1 = new Rectangle (10, 10, 100, 100);
507                                 rect2 = new Rectangle (40, 60, 100, 20);
508
509                                 r1 = new Region (rect1);
510                                 r1.Complement (rect2);
511
512                                 rects = r1.GetRegionScans (new Matrix ());
513                                 Assert.AreEqual  (1, rects.Length, "TCG2Test1");
514                                 AssertEqualRectangles (new RectangleF (110, 60, 30, 20), rects[0], "TCG2Test2");
515                         }
516
517                         { // TEST3
518
519                                 rect1 = new Rectangle (70, 10, 100, 100);
520                                 rect2 = new Rectangle (40, 60, 100, 20);
521
522                                 r1 = new Region (rect1);
523                                 r1.Complement (rect2);
524
525                                 rects = r1.GetRegionScans (new Matrix ());
526                                 Assert.AreEqual  (1, rects.Length, "TCG3Test1");
527                                 AssertEqualRectangles (new RectangleF (40, 60, 30, 20), rects[0], "TCG3Test2");
528                         }
529
530                         { // TEST4
531
532                                 rect1 = new Rectangle (40, 100, 100, 100);
533                                 rect2 = new Rectangle (70, 80, 50, 40);
534
535                                 r1 = new Region (rect1);
536                                 r1.Complement (rect2);
537
538                                 rects = r1.GetRegionScans (new Matrix ());
539                                 Assert.AreEqual  (1, rects.Length, "TCG4Test1");
540                                 AssertEqualRectangles (new RectangleF (70, 80, 50, 20), rects[0], "TCG4Test2");
541                         }
542
543                         { // TEST5
544
545                                 rect1 = new Rectangle (40, 10, 100, 100);
546                                 rect2 = new Rectangle (70, 80, 50, 40);
547
548                                 r1 = new Region (rect1);
549                                 r1.Complement (rect2);
550
551                                 rects = r1.GetRegionScans (new Matrix ());
552                                 Assert.AreEqual  (1, rects.Length, "TCG5Test1");
553                                 AssertEqualRectangles (new RectangleF (70, 110, 50, 10), rects[0], "TCG5Test2");
554                         }
555
556                         { // TEST6: Multiple regions
557
558                                 rect1 = new Rectangle (30, 30, 80, 80);
559                                 rect2 = new Rectangle (45, 45, 200, 200);
560                                 rect3 = new Rectangle (160, 260, 10, 10);
561                                 rect4 = new Rectangle (170, 260, 10, 10);
562
563                                 r1 = new Region (rect1);
564                                 r1.Complement (rect2);
565                                 r1.Complement (rect3);
566                                 r1.Complement (rect4);
567
568                                 rects = r1.GetRegionScans (new Matrix ());
569                                 Assert.AreEqual  (1, rects.Length, "TCG6Test1");
570                                 AssertEqualRectangles (new RectangleF (170, 260, 10, 10), rects[0], "TCG6Test2");
571                         }
572
573                 }
574
575                 [Test]
576 #if TARGET_JVM
577                 [Category ("NotWorking")]
578 #endif
579                 public void TestComplementGroup2 ()
580                 {
581
582                         Bitmap bmp = new Bitmap (600, 800);
583                         Graphics dc = Graphics.FromImage (bmp);
584                         Matrix matrix = new Matrix ();
585                         Rectangle rect1, rect2;
586                         Region rgn1, rgn2;
587                         RectangleF [] rects;
588
589                         rect1 = new Rectangle (20, 30, 60, 80);
590                         rect2 = new Rectangle (50, 40, 60, 80);
591                         rgn1 = new Region (rect1);
592                         rgn2 = new Region (rect2);
593                         dc.DrawRectangle (Pens.Green, rect1);
594                         dc.DrawRectangle (Pens.Red, rect2);
595                         rgn1.Complement (rgn2);
596                         dc.FillRegion (Brushes.Blue, rgn1);
597                         dc.DrawRectangles (Pens.Yellow, rgn1.GetRegionScans (matrix));
598
599                         rects = rgn1.GetRegionScans (matrix);
600
601                         Assert.AreEqual (2, rects.Length);
602
603                         Assert.AreEqual (80, rects[0].X);
604                         Assert.AreEqual (40, rects[0].Y);
605                         Assert.AreEqual (30, rects[0].Width);
606                         Assert.AreEqual (70, rects[0].Height);
607
608                         Assert.AreEqual (50, rects[1].X);
609                         Assert.AreEqual (110, rects[1].Y);
610                         Assert.AreEqual (60, rects[1].Width);
611                         Assert.AreEqual (10, rects[1].Height);
612
613                 }
614
615
616                 [Test]
617 #if TARGET_JVM
618                 [Category ("NotWorking")]
619 #endif
620                 public void TestExcludeGroup1 ()
621                 {
622                         RectangleF[] rects;
623                         Region r1  = new Region ();
624                         Region r2 = new Region ();
625                         Rectangle rect1 = Rectangle.Empty;
626                         Rectangle rect2 = Rectangle.Empty;
627                         Rectangle rect3 = Rectangle.Empty;
628                         Rectangle rect4 = Rectangle.Empty;
629                         Rectangle rect5 = Rectangle.Empty;
630                         Rectangle rect6 = Rectangle.Empty;
631                         Rectangle rect7 = Rectangle.Empty;
632
633
634                         { // TEST1: Not intersecting rects. Exclude just adds them
635
636                                 rect1 = new Rectangle (20, 20, 20, 20);
637                                 rect2 = new Rectangle (20, 80, 20, 10);
638                                 rect3 = new Rectangle (60, 60, 30, 10);
639
640                                 r1 = new Region (rect1);
641                                 r2 = new Region (rect2);
642                                 r2.Union (rect3);
643                                 r1.Exclude (r2);
644
645                                 rects = r1.GetRegionScans (new Matrix ());
646                                 Assert.AreEqual  (1, rects.Length, "TEG1Test1");
647                                 AssertEqualRectangles (new RectangleF (20, 20, 20, 20), rects[0], "TEG1Test2");
648                         }
649
650                         { // TEST2: Excluding from the right
651                                  /*
652                                  *  -----------
653                                  *  |         |
654                                  *  |     |-------- |
655                                  *  |     |         |
656                                  *  |     |-------- |
657                                  *  |         |
658                                  *  ----------|
659                                  *
660                                  */
661
662                                 rect1 = new Rectangle (10, 10, 100, 100);
663                                 rect2 = new Rectangle (40, 60, 100, 20);
664                                 r1 = new Region (rect1);
665                                 r1.Exclude (rect2);
666
667                                 rects = r1.GetRegionScans (new Matrix ());
668                                 Assert.AreEqual  (3, rects.Length, "TEG2Test1");
669                                 AssertEqualRectangles (new RectangleF (10, 10, 100, 50), rects[0], "TEG2Test2");
670                                 AssertEqualRectangles (new RectangleF (10, 60, 30, 20), rects[1], "TEG2Test3");
671                                 AssertEqualRectangles (new RectangleF (10, 80, 100, 30), rects[2], "TEG2Test4");
672                         }
673
674
675                         { // TEST3: Intersecting from the right
676                                  /*
677                                  *      -----------
678                                  *      |         |
679                                  * |-------- |    |
680                                  * |         |    |
681                                  * |-------- |    |
682                                  *      |         |
683                                  *      ----------|
684                                  *
685                                  */
686
687                                 rect1 = new Rectangle (70, 10, 100, 100);
688                                 rect2 = new Rectangle (40, 60, 100, 20);
689
690                                 r1 = new Region (rect1);
691                                 r1.Exclude (rect2);
692
693                                 rects = r1.GetRegionScans (new Matrix ());
694                                 Assert.AreEqual  (3, rects.Length, "TEG3Test1");
695                                 AssertEqualRectangles (new RectangleF (70, 10, 100, 50), rects[0], "TEG3Test2");
696                                 AssertEqualRectangles (new RectangleF (140, 60, 30, 20), rects[1], "TEG3Test3");
697                                 AssertEqualRectangles (new RectangleF (70, 80, 100, 30), rects[2], "TEG3Test4");
698                         }
699
700
701                         { // TEST4: Intersecting from the top
702                                  /*
703                                  *         -----
704                                  *         |   |
705                                  *      -----------
706                                  *      |  |   |  |
707                                  *      |  -----  |
708                                  *      |         |
709                                  *      |         |
710                                  *      ----------|
711                                  *
712                                  */
713
714                                 rect1 = new Rectangle (40, 100, 100, 100);
715                                 rect2 = new Rectangle (70, 80, 50, 40);
716
717                                 r1 = new Region (rect1);
718                                 r1.Exclude (rect2);
719
720                                 rects = r1.GetRegionScans (new Matrix ());
721                                 Assert.AreEqual  (3, rects.Length, "TEG4Test1");
722                                 AssertEqualRectangles (new RectangleF (40, 100, 30, 20), rects[0], "TEG4Test2");
723                                 AssertEqualRectangles (new RectangleF (120, 100, 20, 20), rects[1], "TEG4Test3");
724                                 AssertEqualRectangles (new RectangleF (40, 120, 100, 80), rects[2], "TEG4Test4");
725                         }
726
727
728                         { // TEST5: Intersecting from the bottom
729                                  /*
730                                  *      -----------
731                                  *      |         |
732                                  *      |         |
733                                  *      |         |
734                                  *      |  |   |  |
735                                  *      |--|   |--|
736                                  *         |   |
737                                  *         -----
738                                  *
739                                  */
740
741                                 rect1 = new Rectangle (40, 10, 100, 100);
742                                 rect2 = new Rectangle (70, 80, 50, 40);
743
744                                 r1 = new Region (rect1);
745                                 r1.Exclude (rect2);
746
747                                 rects = r1.GetRegionScans (new Matrix ());
748                                 Assert.AreEqual (3, rects.Length, "TEG5Test1");
749                                 AssertEqualRectangles (new RectangleF (40, 10, 100, 70), rects[0], "TEG5Test2");
750                                 AssertEqualRectangles (new RectangleF (40, 80, 30, 30), rects[1], "TEG5Test3");
751                                 AssertEqualRectangles (new RectangleF (120, 80, 20, 30), rects[2], "TEG5Test4");
752                         }
753
754
755                         { // TEST6: Multiple regions
756
757                                 rect1 = new Rectangle (30, 30, 80, 80);
758                                 rect2 = new Rectangle (45, 45, 200, 200);
759                                 rect3 = new Rectangle (160, 260, 10, 10);
760                                 rect4 = new Rectangle (170, 260, 10, 10);
761
762                                 r1 = new Region (rect1);
763                                 r1.Exclude (rect2);
764                                 r1.Exclude (rect3);
765                                 r1.Exclude (rect4);
766
767                                 rects = r1.GetRegionScans (new Matrix ());
768                                 Assert.AreEqual (2, rects.Length, "TEG6Test1");
769                                 AssertEqualRectangles (new RectangleF (30, 30, 80, 15), rects[0], "TEG6Test2");
770                                 AssertEqualRectangles (new RectangleF (30, 45, 15, 65), rects[1], "TEG6Test3");
771                         }
772
773
774                         { // TEST7: Intersecting from the top with a larger rect
775                                  /*
776                                  *    -----------------
777                                  *    |               |
778                                  *    | -----------   |
779                                  *      |  |   |  |
780                                  *      |  -----  |
781                                  *      |         |
782                                  *      |         |
783                                  *      ----------|
784                                  *
785                                  */
786
787                                 rect1 = new Rectangle (50, 100, 100, 100);
788                                 rect2 = new Rectangle (30, 70, 150, 40);
789
790                                 r1 = new Region (rect1);
791                                 r1.Exclude (rect2);
792
793                                 rects = r1.GetRegionScans (new Matrix ());
794                                 Assert.AreEqual (1, rects.Length, "TEG7Test1");
795                                 AssertEqualRectangles (new RectangleF (50, 110, 100, 90), rects[0], "TEG7Test2");
796                         }
797
798                         { // TEST8: Intersecting from the right with a larger rect
799                                  /*
800                                  *
801                                  * |--------|
802                                  * |        |
803                                  * |    -----------
804                                  * |    |         |
805                                  * |    |         |
806                                  * |    |         |
807                                  * |    |         |
808                                  * |    |         |
809                                  * |    ----------|
810                                  * |-------|
811                                  */
812
813                                 rect1 = new Rectangle (70, 60, 100, 70);
814                                 rect2 = new Rectangle (40, 10, 100, 150);
815
816                                 r1 = new Region (rect1);
817                                 r1.Exclude (rect2);
818
819                                 rects = r1.GetRegionScans (new Matrix ());
820                                 Assert.AreEqual (1, rects.Length, "TEG8Test1");
821                                 AssertEqualRectangles (new RectangleF (140, 60, 30, 70), rects[0], "TEG8Test2");
822
823                         }
824
825                         { // TEST9: Intersecting from the left with a larger rect
826                                  /*
827                                  *
828                                  *              |--------|
829                                  *              |        |
830                                  *      -----------      |
831                                  *      |         |      |
832                                  *      |         |      |
833                                  *      |         |      |
834                                  *      |         |      |
835                                  *      |         |      |
836                                  *      ----------|      |
837                                  *              |--------|
838                                  *
839                                  */
840
841
842                                 rect1 = new Rectangle (70, 60, 100, 70);
843                                 rect2 = new Rectangle (100, 10, 100, 150);
844
845                                 r1 = new Region (rect1);
846                                 r1.Exclude (rect2);
847
848                                 rects = r1.GetRegionScans (new Matrix ());
849                                 Assert.AreEqual (1, rects.Length, "TEG9Test1");
850                                 AssertEqualRectangles (new RectangleF (70, 60, 30, 70), rects[0], "TEG9Test2");
851                         }
852
853
854                         { // TEST10: Intersecting from the bottom with a larger rect
855                                  /*
856                                  * *
857                                  *              |--------|
858                                  *              |        |
859                                  *              |        |
860                                  *              |        |
861                                  *        --------------------
862                                  *        |                  |
863                                  *        |                  |
864                                  *        |------------------|
865                                  */
866
867
868                                 rect1 = new Rectangle (20, 20, 100, 100);
869                                 rect2 = new Rectangle (10, 80, 140, 150);
870
871                                 r1 = new Region (rect1);
872                                 r1.Exclude (rect2);
873
874                                 rects = r1.GetRegionScans (new Matrix ());
875                                 Assert.AreEqual (1, rects.Length, "TEG10Test1");
876                                 AssertEqualRectangles (new RectangleF (20, 20, 100, 60), rects[0], "TEG10Test2");
877                         }
878
879
880                 }
881
882                 [Test]
883 #if TARGET_JVM
884                 [Category ("NotWorking")]
885 #endif
886                 public void TestExcludeGroup2 ()
887                 {
888                         Bitmap bmp = new Bitmap (600, 800);
889                         Graphics dc = Graphics.FromImage (bmp);
890                         Matrix matrix = new Matrix ();
891                         Rectangle rect1, rect2;
892                         Region rgn1;
893                         RectangleF [] rects;
894
895                         rect1 = new Rectangle (130, 30, 60, 80);
896                         rect2 = new Rectangle (170, 40, 60, 80);
897                         rgn1 = new Region (rect1);
898                         rgn1.Exclude (rect2);
899                         rects = rgn1.GetRegionScans (matrix);
900
901                         Assert.AreEqual (2, rects.Length);
902
903                         Assert.AreEqual (130, rects[0].X);
904                         Assert.AreEqual (30, rects[0].Y);
905                         Assert.AreEqual (60, rects[0].Width);
906                         Assert.AreEqual (10, rects[0].Height);
907
908                         Assert.AreEqual (130, rects[1].X);
909                         Assert.AreEqual (40, rects[1].Y);
910                         Assert.AreEqual (40, rects[1].Width);
911                         Assert.AreEqual (70, rects[1].Height);
912                 }
913
914                 [Test]
915 #if TARGET_JVM
916                 [Category ("NotWorking")]
917 #endif
918                 public void TestIntersect()
919                 {
920
921
922                         Bitmap bmp = new Bitmap (600, 800);
923                         Graphics dc = Graphics.FromImage (bmp);
924                         Matrix matrix = new Matrix ();
925                         RectangleF [] rects;
926                         RectangleF rect3, rect4;
927                         Region rgn3, rgn4;
928
929                         /* Two simple areas */
930                         Rectangle rect1 = new Rectangle (260, 30, 60, 80);
931                         Rectangle rect2 = new Rectangle (290, 40, 60, 80);
932                         Region rgn1 = new Region (rect1);
933                         Region rgn2 = new Region (rect2);
934                         rgn1.Intersect (rgn2);
935
936                         rects = rgn1.GetRegionScans (matrix);
937                         Assert.AreEqual (1, rects.Length);
938
939                         Assert.AreEqual (290, rects[0].X);
940                         Assert.AreEqual (40, rects[0].Y);
941                         Assert.AreEqual (30, rects[0].Width);
942                         Assert.AreEqual (70, rects[0].Height);                                                  
943
944                         /* No intersect */
945                         rect1 = new Rectangle (20, 330, 40, 50);
946                         rect2 = new Rectangle (50, 340, 40, 50);
947                         rect3 = new Rectangle (70, 360, 30, 50);
948                         rect4 = new Rectangle (80, 400, 30, 10);
949                         rgn1 = new Region (rect1);
950                         rgn2 = new Region (rect2);
951                         rgn3 = new Region (rect3);
952                         rgn4 = new Region (rect4);
953
954                         rgn1.Intersect (rgn2);
955                         rgn1.Intersect (rgn3);
956                         rgn1.Intersect (rgn4);
957                         rects = rgn1.GetRegionScans (matrix);
958                         Assert.AreEqual (0, rects.Length);
959                 }
960
961                 [Test]
962 #if TARGET_JVM
963                 [Category ("NotWorking")]
964 #endif
965                 public void TestXor()
966                 {
967                         Bitmap bmp = new Bitmap (600, 800);
968                         Graphics dc = Graphics.FromImage (bmp);
969                         Matrix matrix = new Matrix ();
970                         RectangleF [] rects;
971
972                         Rectangle rect1 = new Rectangle (380, 30, 60, 80);
973                         Rectangle rect2 = new Rectangle (410, 40, 60, 80);
974                         Region rgn1 = new Region (rect1);
975                         Region rgn2 = new Region (rect2);
976                         rgn1.Xor (rgn2);
977
978
979                         rects = rgn1.GetRegionScans (matrix);
980
981                         Assert.AreEqual (4, rects.Length);
982
983                         Assert.AreEqual (380, rects[0].X);
984                         Assert.AreEqual (30, rects[0].Y);
985                         Assert.AreEqual (60, rects[0].Width);
986                         Assert.AreEqual (10, rects[0].Height);
987
988                         Assert.AreEqual (380, rects[1].X);
989                         Assert.AreEqual (40, rects[1].Y);
990                         Assert.AreEqual (30, rects[1].Width);
991                         Assert.AreEqual (70, rects[1].Height);
992
993                         Assert.AreEqual (440, rects[2].X);
994                         Assert.AreEqual (40, rects[2].Y);
995                         Assert.AreEqual (30, rects[2].Width);
996                         Assert.AreEqual (70, rects[2].Height);
997
998                         Assert.AreEqual (410, rects[3].X);
999                         Assert.AreEqual (110, rects[3].Y);
1000                         Assert.AreEqual (60, rects[3].Width);
1001                         Assert.AreEqual (10, rects[3].Height);
1002                 }
1003
1004
1005                 [Test]
1006                 public void TestIsVisible()
1007                 {
1008                         Bitmap bmp = new Bitmap (600, 800);
1009                         Graphics dc = Graphics.FromImage (bmp);
1010                         Rectangle rect1, rect2;
1011                         Region rgn1, rgn2;
1012                         Matrix matrix = new Matrix ();
1013
1014                         rect1 = new Rectangle (500, 30, 60, 80);
1015                         rect2 = new Rectangle (520, 40, 60, 80);
1016
1017                         rgn1 = new Region (new RectangleF (0, 0, 10,10));
1018                         Assert.AreEqual (false, rgn1.IsVisible (0,0,0,1));
1019
1020                         rgn1 = new Region (rect1);
1021                         Assert.AreEqual (false, rgn1.IsVisible (500,29));
1022                         Assert.AreEqual (true, rgn1.IsVisible (500,30));
1023                         Assert.AreEqual (true, rgn1.IsVisible (rect1));
1024                         Assert.AreEqual (true, rgn1.IsVisible (rect2));
1025                         Assert.AreEqual (false, rgn1.IsVisible (new Rectangle (50,50,2,5)));
1026
1027                         Rectangle r = new Rectangle (1,1, 2,1);
1028                         rgn2 = new Region (r);
1029                         Assert.AreEqual (true, rgn2.IsVisible (r));
1030                         Assert.AreEqual (true, rgn2.IsVisible (new Rectangle (1,1, 2,2)));
1031                         Assert.AreEqual (true, rgn2.IsVisible (new Rectangle (1,1, 10,10)));
1032                         Assert.AreEqual (true, rgn2.IsVisible (new Rectangle (1,1, 1,1)));
1033                         Assert.AreEqual (false, rgn2.IsVisible (new Rectangle (2,2, 1,1)));
1034                         Assert.AreEqual (false, rgn2.IsVisible (new Rectangle (0,0, 1,1)));
1035                         Assert.AreEqual (false, rgn2.IsVisible (new Rectangle (3,3, 1,1)));
1036
1037                         Assert.AreEqual (false, rgn2.IsVisible (0,0));
1038                         Assert.AreEqual (false, rgn2.IsVisible (1,0));
1039                         Assert.AreEqual (false, rgn2.IsVisible (2,0));
1040                         Assert.AreEqual (false, rgn2.IsVisible (3,0));
1041                         Assert.AreEqual (false, rgn2.IsVisible (0,1));
1042                         Assert.AreEqual (true, rgn2.IsVisible (1,1));
1043                         Assert.AreEqual (true, rgn2.IsVisible (2,1));
1044                         Assert.AreEqual (false, rgn2.IsVisible (3,1));
1045                         Assert.AreEqual (false, rgn2.IsVisible (0,2));
1046                         Assert.AreEqual (false, rgn2.IsVisible (1,2));
1047                         Assert.AreEqual (false, rgn2.IsVisible (2,2));
1048                         Assert.AreEqual (false, rgn2.IsVisible (3,2));
1049
1050
1051                 }
1052
1053                 [Test]
1054 #if TARGET_JVM
1055                 [Category ("NotWorking")]
1056 #endif
1057                 public void TestTranslate()
1058                 {
1059                         Region rgn1 = new Region (new RectangleF (10, 10, 120,120));
1060                         rgn1.Translate (30,20);
1061                         Matrix matrix = new Matrix ();
1062
1063                         RectangleF [] rects = rgn1.GetRegionScans (matrix);
1064
1065                         Assert.AreEqual (1, rects.Length);
1066
1067                         Assert.AreEqual (40, rects[0].X);
1068                         Assert.AreEqual (30, rects[0].Y);
1069                         Assert.AreEqual (120, rects[0].Width);
1070                         Assert.AreEqual (120, rects[0].Height);
1071                 }
1072
1073                 [Test]
1074                 [ExpectedException (typeof (ArgumentNullException))]
1075 #if TARGET_JVM
1076                 [Category ("NotWorking")]
1077 #endif
1078                 public void Constructor_GraphicsPath_Null ()
1079                 {
1080                         GraphicsPath gp = null;
1081                         Region r = new Region (gp);
1082                 }
1083
1084                 [Test]
1085                 [ExpectedException (typeof (ArgumentNullException))]
1086 #if TARGET_JVM
1087                 [Category ("NotWorking")]
1088 #endif
1089                 public void Constructor_RegionData_Null ()
1090                 {
1091                         RegionData rd = null;
1092                         Region r = new Region (rd);
1093                 }
1094
1095                 [Test]
1096                 [ExpectedException (typeof (ArgumentNullException))]
1097                 public void Union_GraphicsPath_Null ()
1098                 {
1099                         GraphicsPath gp = null;
1100                         new Region ().Union (gp);
1101                 }
1102
1103                 [Test]
1104                 [ExpectedException (typeof (ArgumentNullException))]
1105                 public void Union_Region_Null ()
1106                 {
1107                         Region r = null;
1108                         new Region ().Union (r);
1109                 }
1110
1111                 [Test]
1112                 public void Union_Region_Infinite ()
1113                 {
1114                         // default ctor creates an infinite region
1115                         Region r = new Region ();
1116                         CheckEmpty ("default .ctor", r);
1117                         // union-ing to infinity doesn't change the results
1118                         r.Union (new Rectangle (10, 10, 100, 100));
1119                         CheckEmpty ("U infinity", r);
1120                 }
1121
1122                 [Test]
1123                 [ExpectedException (typeof (ArgumentNullException))]
1124                 public void Intersect_GraphicsPath_Null ()
1125                 {
1126                         GraphicsPath gp = null;
1127                         new Region ().Intersect (gp);
1128                 }
1129
1130                 [Test]
1131                 [ExpectedException (typeof (ArgumentNullException))]
1132                 public void Intersect_Region_Null ()
1133                 {
1134                         Region r = null;
1135                         new Region ().Intersect (r);
1136                 }
1137
1138                 [Test]
1139                 [ExpectedException (typeof (ArgumentNullException))]
1140                 public void Complement_GraphicsPath_Null ()
1141                 {
1142                         GraphicsPath gp = null;
1143                         new Region ().Complement (gp);
1144                 }
1145
1146                 [Test]
1147                 [ExpectedException (typeof (ArgumentNullException))]
1148                 public void Complement_Region_Null ()
1149                 {
1150                         Region r = null;
1151                         new Region ().Complement (r);
1152                 }
1153
1154                 [Test]
1155                 [ExpectedException (typeof (ArgumentNullException))]
1156                 public void Exclude_GraphicsPath_Null ()
1157                 {
1158                         GraphicsPath gp = null;
1159                         new Region ().Exclude (gp);
1160                 }
1161
1162                 [Test]
1163                 [ExpectedException (typeof (ArgumentNullException))]
1164                 public void Exclude_Region_Null ()
1165                 {
1166                         Region r = null;
1167                         new Region ().Exclude (r);
1168                 }
1169
1170                 [Test]
1171                 [ExpectedException (typeof (ArgumentNullException))]
1172                 public void Xor_GraphicsPath_Null ()
1173                 {
1174                         GraphicsPath gp = null;
1175                         new Region ().Xor (gp);
1176                 }
1177
1178                 [Test]
1179                 [ExpectedException (typeof (ArgumentNullException))]
1180                 public void Xor_Region_Null ()
1181                 {
1182                         Region r = null;
1183                         new Region ().Xor (r);
1184                 }
1185
1186                 [Test]
1187                 [ExpectedException (typeof (ArgumentNullException))]
1188                 public void GetBounds_Null ()
1189                 {
1190                         new Region ().GetBounds (null);
1191                 }
1192
1193                 [Test]
1194 #if TARGET_JVM
1195                 [Category ("NotWorking")]
1196 #endif
1197                 public void IsVisible_IntIntNull ()
1198                 {
1199                         Assert.IsTrue (new Region ().IsVisible (0, 0, null));
1200                 }
1201
1202                 [Test]
1203 #if TARGET_JVM
1204                 [Category ("NotWorking")]
1205 #endif
1206                 public void IsVisible_IntIntIntIntNull ()
1207                 {
1208                         Assert.IsFalse (new Region ().IsVisible (0, 0, 0, 0, null));
1209                 }
1210
1211                 [Test]
1212 #if TARGET_JVM
1213                 [Category ("NotWorking")]
1214 #endif
1215                 public void IsVisible_PointNull ()
1216                 {
1217                         Point p = new Point ();
1218                         Assert.IsTrue (new Region ().IsVisible (p, null));
1219                 }
1220
1221                 [Test]
1222 #if TARGET_JVM
1223                 [Category ("NotWorking")]
1224 #endif
1225                 public void IsVisible_PointFNull ()
1226                 {
1227                         PointF p = new PointF ();
1228                         Assert.IsTrue (new Region ().IsVisible (p, null));
1229                 }
1230
1231                 [Test]
1232 #if TARGET_JVM
1233                 [Category ("NotWorking")]
1234 #endif
1235                 public void IsVisible_RectangleNull ()
1236                 {
1237                         Rectangle r = new Rectangle ();
1238                         Assert.IsFalse (new Region ().IsVisible (r, null));
1239                 }
1240
1241                 [Test]
1242 #if TARGET_JVM
1243                 [Category ("NotWorking")]
1244 #endif
1245                 public void IsVisible_RectangleFNull ()
1246                 {
1247                         RectangleF r = new RectangleF ();
1248                         Assert.IsFalse (new Region ().IsVisible (r, null));
1249                 }
1250
1251                 [Test]
1252 #if TARGET_JVM
1253                 [Category ("NotWorking")]
1254 #endif
1255                 public void IsVisible_SingleSingleNull ()
1256                 {
1257                         Assert.IsTrue (new Region ().IsVisible (0f, 0f, null));
1258                 }
1259
1260                 [Test]
1261 #if TARGET_JVM
1262                 [Category ("NotWorking")]
1263 #endif
1264                 public void IsVisible_SingleSingleSingleSingleNull ()
1265                 {
1266                         Assert.IsFalse (new Region ().IsVisible (0f, 0f, 0f, 0f, null));
1267                 }
1268
1269                 [Test]
1270                 [ExpectedException (typeof (ArgumentNullException))]
1271                 public void IsEmpty_Null ()
1272                 {
1273                         new Region ().IsEmpty (null);
1274                 }
1275
1276                 [Test]
1277                 [ExpectedException (typeof (ArgumentNullException))]
1278                 public void IsInfinite_Null ()
1279                 {
1280                         new Region ().IsInfinite (null);
1281                 }
1282
1283                 [Test]
1284 #if TARGET_JVM
1285                 [Category ("NotWorking")]
1286 #endif
1287                 [ExpectedException (typeof (ArgumentNullException))]
1288                 public void Equals_NullGraphics ()
1289                 {
1290                         new Region ().Equals (null, Graphics.FromImage (new Bitmap (10, 10)));
1291                 }
1292
1293                 [Test]
1294                 [ExpectedException (typeof (ArgumentNullException))]
1295                 public void Equals_RegionNull ()
1296                 {
1297                         new Region ().Equals (new Region (), null);
1298                 }
1299
1300                 [Test]
1301                 [ExpectedException (typeof (ArgumentNullException))]
1302                 [Category ("NotWorking")] // caused regression in SWF
1303                 public void GetHrgn_Null ()
1304                 {
1305                         new Region ().GetHrgn (null);
1306                 }
1307
1308                 [Test]
1309 #if TARGET_JVM
1310                 [Category ("NotWorking")]
1311 #endif
1312                 [ExpectedException (typeof (ArgumentNullException))]
1313                 public void GetRegionScans_Null ()
1314                 {
1315                         new Region ().GetRegionScans (null);
1316                 }
1317
1318                 [Test]
1319                 [ExpectedException (typeof (ArgumentNullException))]
1320                 public void Transform_Null ()
1321                 {
1322                         new Region ().Transform (null);
1323                 }
1324
1325                 // an "empty ctor" Region is infinite
1326                 private void CheckEmpty (string prefix, Region region)
1327                 {
1328                         Assert.IsFalse (region.IsEmpty (graphic), prefix + "IsEmpty");
1329                         Assert.IsTrue (region.IsInfinite (graphic), prefix + "graphic");
1330
1331                         RectangleF rect = region.GetBounds (graphic);
1332                         Assert.AreEqual (-4194304f, rect.X, prefix + "GetBounds.X");
1333                         Assert.AreEqual (-4194304f, rect.Y, prefix + "GetBounds.Y");
1334                         Assert.AreEqual (8388608f, rect.Width, prefix + "GetBounds.Width");
1335                         Assert.AreEqual (8388608f, rect.Height, prefix + "GetBounds.Height");
1336                 }
1337
1338                 [Test]
1339 #if TARGET_JVM
1340                 [Category ("NotWorking")]
1341 #endif
1342                 public void Region_Empty ()
1343                 {
1344                         Region region = new Region ();
1345                         CheckEmpty ("Empty.", region);
1346
1347                         Region clone = region.Clone ();
1348                         CheckEmpty ("Clone.", region);
1349
1350                         RegionData data = region.GetRegionData ();
1351                         Region r2 = new Region (data);
1352                         CheckEmpty ("RegionData.", region);
1353                 }
1354
1355                 [Test]
1356                 [Category ("NotWorking")]
1357                 public void Region_Infinite_MultipleRectangles ()
1358                 {
1359                         Region region = new Region ();
1360                         Assert.IsTrue (region.IsInfinite (graphic), "Empty.IsInfinite");
1361
1362                         GraphicsPath gp = new GraphicsPath ();
1363                         gp.AddRectangle (new Rectangle (-4194304, -4194304, 8388608, 8388608));
1364                         region = new Region (gp);
1365                         Assert.IsTrue (region.IsInfinite (graphic), "OneRectangle.IsInfinite");
1366
1367                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1368                         region = new Region (gp);
1369                         Assert.IsFalse (region.IsInfinite (graphic), "TwoOverlappingRectangle.IsInfinite");
1370
1371                         gp = new GraphicsPath ();
1372                         gp.AddRectangle (new Rectangle (-4194304, -4194304, 4194304, 8388608));
1373                         gp.AddRectangle (new Rectangle (0, -4194304, 4194304, 8388608));
1374                         Assert.IsFalse (region.IsInfinite (graphic), "TwoSideBySideRectangle.IsInfinite");
1375                 }
1376
1377                 [Test]
1378 #if TARGET_JVM
1379                 [Category ("NotWorking")]
1380 #endif
1381                 public void Rectangle_GetRegionScans ()
1382                 {
1383                         Matrix matrix = new Matrix ();
1384                         GraphicsPath gp = new GraphicsPath ();
1385                         gp.AddRectangle (new Rectangle (10, 10, 10, 10));
1386                         Region region = new Region (gp);
1387                         Assert.AreEqual (1, region.GetRegionScans (matrix).Length, "1");
1388
1389                         gp.AddRectangle (new Rectangle (20, 20, 20, 20));
1390                         region = new Region (gp);
1391                         Assert.AreEqual (2, region.GetRegionScans (matrix).Length, "2");
1392                 }
1393
1394                 [Test]
1395                 public void ExcludeFromInfinity ()
1396                 {
1397                         Region r = new Region ();
1398                         Assert.IsTrue (r.IsInfinite (graphic), "before");
1399                         r.Exclude (new Rectangle (5, 5, 10, 10));
1400                         Assert.IsFalse (r.IsInfinite (graphic), "after");
1401                         RectangleF bounds = r.GetBounds (graphic);
1402                         Assert.AreEqual (-4194304, bounds.X, "X");
1403                         Assert.AreEqual (-4194304, bounds.Y, "Y");
1404                         Assert.AreEqual (8388608, bounds.Width, "Width");
1405                         Assert.AreEqual (8388608, bounds.Height, "Height");
1406                 }
1407         }
1408
1409         [TestFixture]
1410 #if TARGET_JVM
1411         [Category ("NotWorking")]
1412 #endif
1413         // the test cases in this fixture aren't restricted wrt running unmanaged code
1414         public class RegionTestUnmanaged {
1415
1416                 private Bitmap bitmap;
1417                 private Graphics graphic;
1418
1419                 [TestFixtureSetUp]
1420                 public void FixtureSetUp ()
1421                 {
1422                         bitmap = new Bitmap (10, 10);
1423                         graphic = Graphics.FromImage (bitmap);
1424                 }
1425
1426                 [Test]
1427                 public void GetHrgn_Infinite_MakeEmpty ()
1428                 {
1429                         Region r = new Region ();
1430                         Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
1431                         Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
1432                         Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
1433
1434                         r.MakeEmpty ();
1435                         Assert.IsTrue (r.IsEmpty (graphic), "Empty");
1436                         Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
1437                         Assert.IsFalse (r.GetHrgn (graphic) == IntPtr.Zero, "Handle!=0");
1438                 }
1439
1440                 [Test]
1441                 public void GetHrgn_Empty_MakeInfinite ()
1442                 {
1443                         Region r = new Region (new GraphicsPath ());
1444                         Assert.IsTrue (r.IsEmpty (graphic), "Empty");
1445                         Assert.IsFalse (r.IsInfinite (graphic), "!Infinite");
1446                         Assert.IsFalse (r.GetHrgn (graphic) == IntPtr.Zero, "Handle!=0");
1447
1448                         r.MakeInfinite ();
1449                         Assert.IsFalse (r.IsEmpty (graphic), "!Empty");
1450                         Assert.IsTrue (r.IsInfinite (graphic), "Infinite");
1451                         Assert.AreEqual (IntPtr.Zero, r.GetHrgn (graphic), "Handle==0");
1452                 }
1453
1454                 [Test]
1455                 public void GetHrgn_FromHrgn ()
1456                 {
1457                         Region r1 = new Region (new GraphicsPath ());
1458                         IntPtr h1 = r1.GetHrgn (graphic);
1459                         Assert.IsFalse (h1 == IntPtr.Zero, "Handle_1!=0");
1460
1461                         Region r2 = Region.FromHrgn (h1);
1462                         IntPtr h2 = r2.GetHrgn (graphic);
1463                         Assert.IsFalse (h2 == IntPtr.Zero, "Handle_2!=0");
1464                         Assert.IsFalse (h1 == h2, "Handle_1!=Handle_2");
1465                 }
1466
1467                 [Test]
1468                 [ExpectedException (typeof (ArgumentException))]
1469                 public void FromHrgn_Zero ()
1470                 {
1471                         Region.FromHrgn (IntPtr.Zero);
1472                 }
1473         }
1474 }