6f8e3a61406915c6979749fd17fd232663f9df4f
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestGraphics.cs
1 //
2 // Graphics class testing unit
3 //
4 // Authors:
5 //   Jordi Mas, jordi@ximian.com
6 //   Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2005-2008 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 NUnit.Framework;
31 using System;
32 using System.Drawing;
33 using System.Drawing.Drawing2D;
34 using System.Drawing.Imaging;
35 using System.Drawing.Text;
36 using System.IO;
37 using System.Reflection;
38 using System.Security.Permissions;
39
40 namespace MonoTests.System.Drawing {
41
42         [TestFixture]
43         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
44         public class GraphicsTest {
45
46                 private RectangleF[] rects;
47                 private Font font;
48
49                 [TestFixtureSetUp]
50                 public void FixtureSetUp ()
51                 {
52                         try {
53                                 font = new Font ("Arial", 12);
54                         }
55                         catch {
56                         }
57                 }
58
59                 [TestFixtureTearDown]
60                 public void FixtureTearDown ()
61                 {
62                         if (font != null)
63                                 font.Dispose ();
64                 }
65
66
67                 private bool IsEmptyBitmap (Bitmap bitmap, out int x, out int y)
68                 {
69                         bool result = true;
70                         int empty = Color.Empty.ToArgb ();
71 #if false
72                         for (y = 0; y < bitmap.Height; y++) {
73                                 for (x = 0; x < bitmap.Width; x++) {
74                                         if (bitmap.GetPixel (x, y).ToArgb () != empty) {
75                                                 Console.Write ("X");
76                                                 result = false;
77                                         } else
78                                                 Console.Write (" ");
79                                 }
80                                 Console.WriteLine ();
81                         }
82 #else
83                         for (y = 0; y < bitmap.Height; y++) {
84                                 for (x = 0; x < bitmap.Width; x++) {
85                                         if (bitmap.GetPixel (x, y).ToArgb () != empty)
86                                                 return false;
87                                 }
88                         }
89 #endif
90                         x = -1;
91                         y = -1;
92                         return result;
93                 }
94
95                 private void CheckForEmptyBitmap (Bitmap bitmap)
96                 {
97                         int x, y;
98                         if (!IsEmptyBitmap (bitmap, out x, out y))
99                                 Assert.Fail (String.Format ("Position {0},{1}", x, y));
100                 }
101
102                 private void CheckForNonEmptyBitmap (Bitmap bitmap)
103                 {
104                         int x, y;
105                         if (IsEmptyBitmap (bitmap, out x, out y))
106                                 Assert.Fail ("Bitmap was empty");
107                 }
108
109                 private void AssertEquals (string msg, object expected, object actual)
110                 {
111                         Assert.AreEqual (expected, actual, msg);
112                 }
113
114                 private void AssertEquals (string msg, double expected, double actual, double delta)
115                 {
116                         Assert.AreEqual (expected, actual, delta, msg);
117                 }
118
119                 [Test]
120                 public void DefaultProperties ()
121                 {
122                         Bitmap bmp = new Bitmap (200, 200);
123                         Graphics g = Graphics.FromImage (bmp);
124                         Region r = new Region ();
125
126                         Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "DefaultProperties1");
127                         Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "DefaultProperties2");
128                         Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "DefaultProperties3");
129                         Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "DefaultProperties4");
130                         Assert.AreEqual (1, g.PageScale, "DefaultProperties5");
131                         Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "DefaultProperties6");
132                         Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "DefaultProperties7");
133                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "DefaultProperties8");
134                         Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "DefaultProperties9");
135                         Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "DefaultProperties10");
136
137                         r.Dispose ();
138                 }
139
140                 [Test]
141                 public void SetGetProperties ()
142                 {
143                         Bitmap bmp = new Bitmap (200, 200);
144                         Graphics g = Graphics.FromImage (bmp);
145
146                         g.CompositingMode = CompositingMode.SourceCopy;
147                         g.CompositingQuality = CompositingQuality.GammaCorrected;
148                         g.InterpolationMode = InterpolationMode.HighQualityBilinear;
149                         g.PageScale = 2;
150                         g.PageUnit = GraphicsUnit.Inch;
151                         g.PixelOffsetMode = PixelOffsetMode.Half;
152                         g.RenderingOrigin = new Point (10, 20);
153                         g.SmoothingMode = SmoothingMode.AntiAlias;
154                         g.TextRenderingHint = TextRenderingHint.SystemDefault;
155
156                         //Clipping set/get tested in clipping functions                 
157                         Assert.AreEqual (CompositingMode.SourceCopy, g.CompositingMode, "SetGetProperties2");
158                         Assert.AreEqual (CompositingQuality.GammaCorrected, g.CompositingQuality, "SetGetProperties3");
159                         Assert.AreEqual (InterpolationMode.HighQualityBilinear, g.InterpolationMode, "SetGetProperties4");
160                         Assert.AreEqual (2, g.PageScale, "SetGetProperties5");
161                         Assert.AreEqual (GraphicsUnit.Inch, g.PageUnit, "SetGetProperties6");
162                         Assert.AreEqual (PixelOffsetMode.Half, g.PixelOffsetMode, "SetGetProperties7");
163                         Assert.AreEqual (new Point (10, 20), g.RenderingOrigin, "SetGetProperties8");
164                         Assert.AreEqual (SmoothingMode.AntiAlias, g.SmoothingMode, "SetGetProperties9");
165                         Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "SetGetProperties10");
166                 }
167
168                 // Properties
169                 [Test]
170                 public void Clip ()
171                 {
172                         RectangleF[] rects;
173                         Bitmap bmp = new Bitmap (200, 200);
174                         Graphics g = Graphics.FromImage (bmp);
175                         g.Clip = new Region (new Rectangle (50, 40, 210, 220));
176                         rects = g.Clip.GetRegionScans (new Matrix ());
177
178                         Assert.AreEqual (1, rects.Length, "Clip1");
179                         Assert.AreEqual (50, rects[0].X, "Clip2");
180                         Assert.AreEqual (40, rects[0].Y, "Clip3");
181                         Assert.AreEqual (210, rects[0].Width, "Clip4");
182                         Assert.AreEqual (220, rects[0].Height, "Clip5");
183                 }
184
185                 [Test]
186                 public void Clip_NotAReference ()
187                 {
188                         Bitmap bmp = new Bitmap (200, 200);
189                         Graphics g = Graphics.FromImage (bmp);
190                         Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite");
191                         g.Clip.IsEmpty (g);
192                         Assert.IsFalse (g.Clip.IsEmpty (g), "!IsEmpty");
193                         Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite-2");
194                 }
195
196                 [Test]
197                 public void ExcludeClip ()
198                 {
199                         Bitmap bmp = new Bitmap (200, 200);
200                         Graphics g = Graphics.FromImage (bmp);
201
202                         g.Clip = new Region (new RectangleF (10, 10, 100, 100));
203                         g.ExcludeClip (new Rectangle (40, 60, 100, 20));
204                         rects = g.Clip.GetRegionScans (new Matrix ());
205
206                         Assert.AreEqual (3, rects.Length, "ExcludeClip1");
207
208                         Assert.AreEqual (10, rects[0].X, "ExcludeClip2");
209                         Assert.AreEqual (10, rects[0].Y, "ExcludeClip3");
210                         Assert.AreEqual (100, rects[0].Width, "ExcludeClip4");
211                         Assert.AreEqual (50, rects[0].Height, "ExcludeClip5");
212
213                         Assert.AreEqual (10, rects[1].X, "ExcludeClip6");
214                         Assert.AreEqual (60, rects[1].Y, "ExcludeClip7");
215                         Assert.AreEqual (30, rects[1].Width, "ExcludeClip8");
216                         Assert.AreEqual (20, rects[1].Height, "ExcludeClip9");
217
218                         Assert.AreEqual (10, rects[2].X, "ExcludeClip10");
219                         Assert.AreEqual (80, rects[2].Y, "ExcludeClip11");
220                         Assert.AreEqual (100, rects[2].Width, "ExcludeClip12");
221                         Assert.AreEqual (30, rects[2].Height, "ExcludeClip13");
222                 }
223
224                 [Test]
225                 public void IntersectClip ()
226                 {
227                         Bitmap bmp = new Bitmap (200, 200);
228                         Graphics g = Graphics.FromImage (bmp);
229
230                         g.Clip = new Region (new RectangleF (260, 30, 60, 80));
231                         g.IntersectClip (new Rectangle (290, 40, 60, 80));
232                         rects = g.Clip.GetRegionScans (new Matrix ());
233
234                         Assert.AreEqual (1, rects.Length, "IntersectClip");
235
236                         Assert.AreEqual (290, rects[0].X, "IntersectClip");
237                         Assert.AreEqual (40, rects[0].Y, "IntersectClip");
238                         Assert.AreEqual (30, rects[0].Width, "IntersectClip");
239                         Assert.AreEqual (70, rects[0].Height, "IntersectClip");
240                 }
241
242                 [Test]
243                 public void ResetClip ()
244                 {
245                         Bitmap bmp = new Bitmap (200, 200);
246                         Graphics g = Graphics.FromImage (bmp);
247
248                         g.Clip = new Region (new RectangleF (260, 30, 60, 80));
249                         g.IntersectClip (new Rectangle (290, 40, 60, 80));
250                         g.ResetClip ();
251                         rects = g.Clip.GetRegionScans (new Matrix ());
252
253                         Assert.AreEqual (1, rects.Length, "ResetClip");
254
255                         Assert.AreEqual (-4194304, rects[0].X, "ResetClip");
256                         Assert.AreEqual (-4194304, rects[0].Y, "ResetClip");
257                         Assert.AreEqual (8388608, rects[0].Width, "ResetClip");
258                         Assert.AreEqual (8388608, rects[0].Height, "ResetClip");
259                 }
260
261                 [Test]
262                 public void SetClip ()
263                 {
264                         RectangleF[] rects;
265                         Bitmap bmp = new Bitmap (200, 200);
266                         Graphics g = Graphics.FromImage (bmp);
267
268                         // Region
269                         g.SetClip (new Region (new Rectangle (50, 40, 210, 220)), CombineMode.Replace);
270                         rects = g.Clip.GetRegionScans (new Matrix ());
271                         Assert.AreEqual (1, rects.Length, "SetClip1");
272                         Assert.AreEqual (50, rects[0].X, "SetClip2");
273                         Assert.AreEqual (40, rects[0].Y, "SetClip3");
274                         Assert.AreEqual (210, rects[0].Width, "SetClip4");
275                         Assert.AreEqual (220, rects[0].Height, "SetClip5");
276
277                         // RectangleF
278                         g = Graphics.FromImage (bmp);
279                         g.SetClip (new RectangleF (50, 40, 210, 220));
280                         rects = g.Clip.GetRegionScans (new Matrix ());
281                         Assert.AreEqual (1, rects.Length, "SetClip6");
282                         Assert.AreEqual (50, rects[0].X, "SetClip7");
283                         Assert.AreEqual (40, rects[0].Y, "SetClip8");
284                         Assert.AreEqual (210, rects[0].Width, "SetClip9");
285                         Assert.AreEqual (220, rects[0].Height, "SetClip10");
286
287                         // Rectangle
288                         g = Graphics.FromImage (bmp);
289                         g.SetClip (new Rectangle (50, 40, 210, 220));
290                         rects = g.Clip.GetRegionScans (new Matrix ());
291                         Assert.AreEqual (1, rects.Length, "SetClip10");
292                         Assert.AreEqual (50, rects[0].X, "SetClip11");
293                         Assert.AreEqual (40, rects[0].Y, "SetClip12");
294                         Assert.AreEqual (210, rects[0].Width, "SetClip13");
295                         Assert.AreEqual (220, rects[0].Height, "SetClip14");
296                 }
297
298                 [Test]
299                 public void SetSaveReset ()
300                 {
301                         Bitmap bmp = new Bitmap (200, 200);
302                         Graphics g = Graphics.FromImage (bmp);
303                         GraphicsState state_default, state_modified;
304
305                         state_default = g.Save (); // Default
306
307                         g.CompositingMode = CompositingMode.SourceCopy;
308                         g.CompositingQuality = CompositingQuality.GammaCorrected;
309                         g.InterpolationMode = InterpolationMode.HighQualityBilinear;
310                         g.PageScale = 2;
311                         g.PageUnit = GraphicsUnit.Inch;
312                         g.PixelOffsetMode = PixelOffsetMode.Half;
313                         g.Clip = new Region (new Rectangle (0, 0, 100, 100));
314                         g.RenderingOrigin = new Point (10, 20);
315                         g.SmoothingMode = SmoothingMode.AntiAlias;
316                         g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
317
318
319                         state_modified = g.Save (); // Modified
320
321                         g.CompositingMode = CompositingMode.SourceOver;
322                         g.CompositingQuality = CompositingQuality.Default;
323                         g.InterpolationMode = InterpolationMode.Bilinear;
324                         g.PageScale = 5;
325                         g.PageUnit = GraphicsUnit.Display;
326                         g.PixelOffsetMode = PixelOffsetMode.Default;
327                         g.Clip = new Region (new Rectangle (1, 2, 20, 25));
328                         g.RenderingOrigin = new Point (5, 6);
329                         g.SmoothingMode = SmoothingMode.None;
330                         g.TextRenderingHint = TextRenderingHint.SystemDefault;
331
332                         g.Restore (state_modified);
333
334                         Assert.AreEqual (CompositingMode.SourceCopy, g.CompositingMode, "SetSaveReset1");
335                         Assert.AreEqual (CompositingQuality.GammaCorrected, g.CompositingQuality, "SetSaveReset2");
336                         Assert.AreEqual (InterpolationMode.HighQualityBilinear, g.InterpolationMode, "SetSaveReset3");
337                         Assert.AreEqual (2, g.PageScale, "SetSaveReset4");
338                         Assert.AreEqual (GraphicsUnit.Inch, g.PageUnit, "SetSaveReset5");
339                         Assert.AreEqual (PixelOffsetMode.Half, g.PixelOffsetMode, "SetSaveReset6");
340                         Assert.AreEqual (new Point (10, 20), g.RenderingOrigin, "SetSaveReset7");
341                         Assert.AreEqual (SmoothingMode.AntiAlias, g.SmoothingMode, "SetSaveReset8");
342                         Assert.AreEqual (TextRenderingHint.ClearTypeGridFit, g.TextRenderingHint, "SetSaveReset9");
343                         Assert.AreEqual (0, (int) g.ClipBounds.X, "SetSaveReset10");
344                         Assert.AreEqual (0, (int) g.ClipBounds.Y, "SetSaveReset10");
345
346                         g.Restore (state_default);
347
348                         Assert.AreEqual (CompositingMode.SourceOver, g.CompositingMode, "SetSaveReset11");
349                         Assert.AreEqual (CompositingQuality.Default, g.CompositingQuality, "SetSaveReset12");
350                         Assert.AreEqual (InterpolationMode.Bilinear, g.InterpolationMode, "SetSaveReset13");
351                         Assert.AreEqual (1, g.PageScale, "SetSaveReset14");
352                         Assert.AreEqual (GraphicsUnit.Display, g.PageUnit, "SetSaveReset15");
353                         Assert.AreEqual (PixelOffsetMode.Default, g.PixelOffsetMode, "SetSaveReset16");
354                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "SetSaveReset17");
355                         Assert.AreEqual (SmoothingMode.None, g.SmoothingMode, "SetSaveReset18");
356                         Assert.AreEqual (TextRenderingHint.SystemDefault, g.TextRenderingHint, "SetSaveReset19");
357
358                         Region r = new Region ();
359                         Assert.AreEqual (r.GetBounds (g), g.ClipBounds, "SetSaveReset20");
360
361                         g.Dispose ();
362                 }
363
364                 [Test]
365                 [Category ("NotWorking")] // looks like MS PNG codec promote indexed format to 32bpp ARGB
366                 public void LoadIndexed_PngStream ()
367                 {
368                         // Tests that we can load an indexed file
369                         using (Stream s = Assembly.GetExecutingAssembly ().GetManifestResourceStream ("indexed.png")) {
370                                 using (Image img = Image.FromStream (s)) {
371                                         // however it's no more indexed once loaded
372                                         Assert.AreEqual (PixelFormat.Format32bppArgb, img.PixelFormat, "PixelFormat");
373                                         using (Graphics g = Graphics.FromImage (img)) {
374                                                 Assert.AreEqual (img.Height, g.VisibleClipBounds.Height, "Height");
375                                                 Assert.AreEqual (img.Width, g.VisibleClipBounds.Width, "Width");
376                                         }
377                                 }
378                         }
379                 }
380
381                 [Test]
382                 [ExpectedException (typeof (Exception))]
383                 public void LoadIndexed_BmpFile ()
384                 {
385                         // Tests that we can load an indexed file, but...
386                         string sInFile = TestBitmap.getInFile ("bitmaps/almogaver1bit.bmp");
387                         // note: file is misnamed (it's a 4bpp bitmap)
388                         using (Image img = Image.FromFile (sInFile)) {
389                                 Assert.AreEqual (PixelFormat.Format4bppIndexed, img.PixelFormat, "PixelFormat");
390                                 Graphics.FromImage (img);
391                         }
392                 }
393
394                 [Test]
395                 [ExpectedException (typeof (ArgumentNullException))]
396                 public void FromImage ()
397                 {
398                         Graphics g = Graphics.FromImage (null);
399                 }
400
401                 private Graphics Get (int w, int h)
402                 {
403                         Bitmap bitmap = new Bitmap (w, h);
404                         Graphics g = Graphics.FromImage (bitmap);
405                         g.Clip = new Region (new Rectangle (0, 0, w, h));
406                         return g;
407                 }
408
409                 private void Compare (string msg, RectangleF b1, RectangleF b2)
410                 {
411                         AssertEquals (msg + ".compare.X", b1.X, b2.X);
412                         AssertEquals (msg + ".compare.Y", b1.Y, b2.Y);
413                         AssertEquals (msg + ".compare.Width", b1.Width, b2.Width);
414                         AssertEquals (msg + ".compare.Height", b1.Height, b2.Height);
415                 }
416
417                 [Test]
418                 public void Clip_GetBounds ()
419                 {
420                         Graphics g = Get (16, 16);
421                         RectangleF bounds = g.Clip.GetBounds (g);
422                         Assert.AreEqual (0, bounds.X, "X");
423                         Assert.AreEqual (0, bounds.Y, "Y");
424                         Assert.AreEqual (16, bounds.Width, "Width");
425                         Assert.AreEqual (16, bounds.Height, "Height");
426                         Assert.IsTrue (g.Transform.IsIdentity, "Identity");
427                         g.Dispose ();
428                 }
429
430                 [Test]
431                 public void Clip_TranslateTransform ()
432                 {
433                         Graphics g = Get (16, 16);
434                         g.TranslateTransform (12.22f, 10.10f);
435                         RectangleF bounds = g.Clip.GetBounds (g);
436                         Compare ("translate", bounds, g.ClipBounds);
437                         Assert.AreEqual (-12.2200003f, bounds.X, "translate.X");
438                         Assert.AreEqual (-10.1000004f, bounds.Y, "translate.Y");
439                         Assert.AreEqual (16, bounds.Width, "translate.Width");
440                         Assert.AreEqual (16, bounds.Height, "translate.Height");
441                         float[] elements = g.Transform.Elements;
442                         Assert.AreEqual (1, elements[0], "translate.0");
443                         Assert.AreEqual (0, elements[1], "translate.1");
444                         Assert.AreEqual (0, elements[2], "translate.2");
445                         Assert.AreEqual (1, elements[3], "translate.3");
446                         Assert.AreEqual (12.2200003f, elements[4], "translate.4");
447                         Assert.AreEqual (10.1000004f, elements[5], "translate.5");
448
449                         g.ResetTransform ();
450                         bounds = g.Clip.GetBounds (g);
451                         Compare ("reset", bounds, g.ClipBounds);
452                         Assert.AreEqual (0, bounds.X, "reset.X");
453                         Assert.AreEqual (0, bounds.Y, "reset.Y");
454                         Assert.AreEqual (16, bounds.Width, "reset.Width");
455                         Assert.AreEqual (16, bounds.Height, "reset.Height");
456                         Assert.IsTrue (g.Transform.IsIdentity, "Identity");
457                         g.Dispose ();
458                 }
459
460                 [Test]
461                 [ExpectedException (typeof (ArgumentException))]
462                 public void Transform_NonInvertibleMatrix ()
463                 {
464                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
465                         Assert.IsFalse (matrix.IsInvertible, "IsInvertible");
466                         Graphics g = Get (16, 16);
467                         g.Transform = matrix;
468                 }
469
470
471                 [Test]
472                 [ExpectedException (typeof (ArgumentException))]
473                 public void Multiply_NonInvertibleMatrix ()
474                 {
475                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
476                         Assert.IsFalse (matrix.IsInvertible, "IsInvertible");
477                         Graphics g = Get (16, 16);
478                         g.MultiplyTransform (matrix);
479                 }
480
481                 [Test]
482                 [ExpectedException (typeof (ArgumentNullException))]
483                 public void Multiply_Null ()
484                 {
485                         Graphics g = Get (16, 16);
486                         g.MultiplyTransform (null);
487                 }
488
489                 private void CheckBounds (string msg, RectangleF bounds, float x, float y, float w, float h)
490                 {
491                         AssertEquals (msg + ".X", x, bounds.X, 0.1);
492                         AssertEquals (msg + ".Y", y, bounds.Y, 0.1);
493                         AssertEquals (msg + ".Width", w, bounds.Width, 0.1);
494                         AssertEquals (msg + ".Height", h, bounds.Height, 0.1);
495                 }
496
497                 [Test]
498                 public void ClipBounds ()
499                 {
500                         Graphics g = Get (16, 16);
501                         CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
502                         CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
503
504                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
505                         CheckBounds ("clip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
506                         CheckBounds ("clip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
507                 }
508
509                 [Test]
510                 public void ClipBounds_Rotate ()
511                 {
512                         Graphics g = Get (16, 16);
513                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
514                         g.RotateTransform (90);
515                         CheckBounds ("rotate.ClipBounds", g.ClipBounds, 0, -8, 8, 8);
516                         CheckBounds ("rotate.Clip.GetBounds", g.Clip.GetBounds (g), 0, -8, 8, 8);
517
518                         g.Transform = new Matrix ();
519                         CheckBounds ("identity.ClipBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
520                         CheckBounds ("identity.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
521                 }
522
523                 [Test]
524                 public void ClipBounds_Scale ()
525                 {
526                         RectangleF clip = new Rectangle (0, 0, 8, 8);
527                         Graphics g = Get (16, 16);
528                         g.Clip = new Region (clip);
529                         g.ScaleTransform (0.25f, 0.5f);
530                         CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 32, 16);
531                         CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 32, 16);
532
533                         g.SetClip (clip);
534                         CheckBounds ("setclip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
535                         CheckBounds ("setclip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
536                 }
537
538                 [Test]
539                 public void ClipBounds_Translate ()
540                 {
541                         Graphics g = Get (16, 16);
542                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
543                         Region clone = g.Clip.Clone ();
544                         g.TranslateTransform (8, 8);
545                         CheckBounds ("translate.ClipBounds", g.ClipBounds, -8, -8, 8, 8);
546                         CheckBounds ("translate.Clip.GetBounds", g.Clip.GetBounds (g), -8, -8, 8, 8);
547
548                         g.SetClip (clone, CombineMode.Replace);
549                         CheckBounds ("setclip.ClipBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
550                         CheckBounds ("setclip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
551                 }
552
553                 [Test]
554                 public void ClipBounds_Transform_Translation ()
555                 {
556                         Graphics g = Get (16, 16);
557                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
558                         g.Transform = new Matrix (1, 0, 0, 1, 8, 8);
559                         CheckBounds ("transform.ClipBounds", g.ClipBounds, -8, -8, 8, 8);
560                         CheckBounds ("transform.Clip.GetBounds", g.Clip.GetBounds (g), -8, -8, 8, 8);
561
562                         g.ResetTransform ();
563                         CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
564                         CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
565                 }
566
567                 [Test]
568                 public void ClipBounds_Transform_Scale ()
569                 {
570                         Graphics g = Get (16, 16);
571                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
572                         g.Transform = new Matrix (0.5f, 0, 0, 0.25f, 0, 0);
573                         CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 16, 32);
574                         CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 32);
575
576                         g.ResetClip ();
577                         // see next test for ClipBounds
578                         CheckBounds ("resetclip.Clip.GetBounds", g.Clip.GetBounds (g), -4194304, -4194304, 8388608, 8388608);
579                         Assert.IsTrue (g.Clip.IsInfinite (g), "IsInfinite");
580                 }
581
582                 [Test]
583                 [Category ("NotWorking")]
584                 public void ClipBounds_Transform_Scale_Strange ()
585                 {
586                         Graphics g = Get (16, 16);
587                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
588                         g.Transform = new Matrix (0.5f, 0, 0, 0.25f, 0, 0);
589                         CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, 0, 16, 32);
590                         CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 32);
591
592                         g.ResetClip ();
593                         // note: strange case where g.ClipBounds and g.Clip.GetBounds are different
594                         CheckBounds ("resetclip.ClipBounds", g.ClipBounds, -8388608, -16777216, 16777216, 33554432);
595                 }
596
597                 [Test]
598                 public void ClipBounds_Multiply ()
599                 {
600                         Graphics g = Get (16, 16);
601                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
602                         g.Transform = new Matrix (1, 0, 0, 1, 8, 8);
603                         g.MultiplyTransform (g.Transform);
604                         CheckBounds ("multiply.ClipBounds", g.ClipBounds, -16, -16, 8, 8);
605                         CheckBounds ("multiply.Clip.GetBounds", g.Clip.GetBounds (g), -16, -16, 8, 8);
606
607                         g.ResetTransform ();
608                         CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
609                         CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
610                 }
611
612                 [Test]
613                 public void ClipBounds_Cumulative_Effects ()
614                 {
615                         Graphics g = Get (16, 16);
616                         CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
617                         CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
618
619                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
620                         CheckBounds ("clip.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
621                         CheckBounds ("clip.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
622
623                         g.RotateTransform (90);
624                         CheckBounds ("rotate.ClipBounds", g.ClipBounds, 0, -8, 8, 8);
625                         CheckBounds ("rotate.Clip.GetBounds", g.Clip.GetBounds (g), 0, -8, 8, 8);
626
627                         g.ScaleTransform (0.25f, 0.5f);
628                         CheckBounds ("scale.ClipBounds", g.ClipBounds, 0, -16, 32, 16);
629                         CheckBounds ("scale.Clip.GetBounds", g.Clip.GetBounds (g), 0, -16, 32, 16);
630
631                         g.TranslateTransform (8, 8);
632                         CheckBounds ("translate.ClipBounds", g.ClipBounds, -8, -24, 32, 16);
633                         CheckBounds ("translate.Clip.GetBounds", g.Clip.GetBounds (g), -8, -24, 32, 16);
634
635                         g.MultiplyTransform (g.Transform);
636                         CheckBounds ("multiply.ClipBounds", g.ClipBounds, -104, -56, 64, 64);
637                         CheckBounds ("multiply.Clip.GetBounds", g.Clip.GetBounds (g), -104, -56, 64, 64);
638
639                         g.ResetTransform ();
640                         CheckBounds ("reset.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
641                         CheckBounds ("reset.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
642                 }
643
644                 [Test]
645                 public void Clip_TranslateTransform_BoundsChange ()
646                 {
647                         Graphics g = Get (16, 16);
648                         CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
649                         CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
650                         g.TranslateTransform (-16, -16);
651                         CheckBounds ("translated.ClipBounds", g.ClipBounds, 16, 16, 16, 16);
652                         CheckBounds ("translated.Clip.GetBounds", g.Clip.GetBounds (g), 16, 16, 16, 16);
653
654                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
655                         // ClipBounds isn't affected by a previous translation
656                         CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
657                         // Clip.GetBounds isn't affected by a previous translation
658                         CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
659
660                         g.ResetTransform ();
661                         CheckBounds ("reseted.ClipBounds", g.ClipBounds, -16, -16, 8, 8);
662                         CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -16, -16, 8, 8);
663                 }
664
665                 [Test]
666                 public void Clip_RotateTransform_BoundsChange ()
667                 {
668                         Graphics g = Get (16, 16);
669                         CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
670                         CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
671                         // we select a "simple" angle because the region will be converted into
672                         // a bitmap (well for libgdiplus) and we would lose precision after that
673                         g.RotateTransform (90);
674                         CheckBounds ("rotated.ClipBounds", g.ClipBounds, 0, -16, 16, 16);
675                         CheckBounds ("rotated.Clip.GetBounds", g.Clip.GetBounds (g), 0, -16, 16, 16);
676                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
677                         // ClipBounds isn't affected by a previous rotation (90)
678                         CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
679                         // Clip.GetBounds isn't affected by a previous rotation
680                         CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
681
682                         g.ResetTransform ();
683                         CheckBounds ("reseted.ClipBounds", g.ClipBounds, -8, 0, 8, 8);
684                         CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -8, 0, 8, 8);
685                 }
686
687                 private void CheckBoundsInt (string msg, RectangleF bounds, int x, int y, int w, int h)
688                 {
689                         // currently bounds are rounded at 8 pixels (FIXME - we can go down to 1 pixel)
690                         AssertEquals (msg + ".X", x, bounds.X, 4f);
691                         AssertEquals (msg + ".Y", y, bounds.Y, 4f);
692                         AssertEquals (msg + ".Width", w, bounds.Width, 4f);
693                         AssertEquals (msg + ".Height", h, bounds.Height, 4f);
694                 }
695
696                 [Test]
697                 [Category ("NotWorking")]
698                 public void Clip_RotateTransform_BoundsChange_45 ()
699                 {
700                         Graphics g = Get (16, 16);
701                         CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
702                         CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
703                         g.RotateTransform (45);
704                         // we can't use the "normal" CheckBound here because of libgdiplus crude rounding
705                         CheckBoundsInt ("rotated.ClipBounds", g.ClipBounds, 0, -11, 24, 24);
706                         CheckBoundsInt ("rotated.Clip.GetBounds", g.Clip.GetBounds (g), 0, -11, 24, 24);
707                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
708                         // ClipBounds IS affected by a previous rotation (45)
709                         CheckBoundsInt ("rectangle.ClipBounds", g.ClipBounds, -3, -4, 16, 16);
710                         // Clip.GetBounds isn't affected by a previous rotation
711                         CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
712
713                         g.ResetTransform ();
714                         CheckBounds ("reseted.ClipBounds", g.ClipBounds, -5, 1, 11, 11);
715                         CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -5.6f, 0, 11.3f, 11.3f);
716                 }
717
718                 [Test]
719                 public void Clip_ScaleTransform_NoBoundsChange ()
720                 {
721                         Graphics g = Get (16, 16);
722                         CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
723                         CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
724                         g.ScaleTransform (2, 0.5f);
725                         CheckBounds ("scaled.ClipBounds", g.ClipBounds, 0, 0, 8, 32);
726                         CheckBounds ("scaled.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 32);
727                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
728                         // ClipBounds isn't affected by a previous scaling
729                         CheckBounds ("rectangle.ClipBounds", g.ClipBounds, 0, 0, 8, 8);
730                         // Clip.GetBounds isn't affected by a previous scaling
731                         CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
732
733                         g.ResetTransform ();
734                         CheckBounds ("reseted.ClipBounds", g.ClipBounds, 0, 0, 16, 4);
735                         CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 4);
736                 }
737
738                 [Test]
739                 [Category ("NotWorking")]
740                 public void Clip_MultiplyTransform_NoBoundsChange ()
741                 {
742                         Graphics g = Get (16, 16);
743                         CheckBounds ("graphics.ClipBounds", g.ClipBounds, 0, 0, 16, 16);
744                         CheckBounds ("graphics.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 16, 16);
745                         g.MultiplyTransform (new Matrix (2.5f, 0.5f, -2.5f, 0.5f, 4, -4));
746                         CheckBounds ("multiplied.ClipBounds", g.ClipBounds, 3.2f, 1.6f, 19.2f, 19.2f);
747                         CheckBounds ("multiplied.Clip.GetBounds", g.Clip.GetBounds (g), 3.2f, 1.6f, 19.2f, 19.2f);
748                         g.Clip = new Region (new Rectangle (0, 0, 8, 8));
749                         // ClipBounds IS affected by the previous multiplication
750                         CheckBounds ("rectangle.ClipBounds", g.ClipBounds, -3, -3, 15, 15);
751                         // Clip.GetBounds isn't affected by the previous multiplication
752                         CheckBounds ("rectangle.Clip.GetBounds", g.Clip.GetBounds (g), 0, 0, 8, 8);
753
754                         g.ResetTransform ();
755                         CheckBounds ("reseted.ClipBounds", g.ClipBounds, -16, -3, 40, 7);
756                         CheckBounds ("reseted.Clip.GetBounds", g.Clip.GetBounds (g), -16, -4, 40, 8);
757                 }
758
759                 [Test]
760                 [ExpectedException (typeof (ArgumentException))]
761                 public void ScaleTransform_X0 ()
762                 {
763                         Graphics g = Get (16, 16);
764                         g.ScaleTransform (0, 1);
765                 }
766
767                 [Test]
768                 [ExpectedException (typeof (ArgumentException))]
769                 public void ScaleTransform_Y0 ()
770                 {
771                         Graphics g = Get (16, 16);
772                         g.ScaleTransform (1, 0);
773                 }
774
775                 [Test]
776                 public void TranslateTransform_Order ()
777                 {
778                         Graphics g = Get (16, 16);
779                         g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
780                         g.TranslateTransform (3, -3);
781                         float[] elements = g.Transform.Elements;
782                         Assert.AreEqual (1, elements[0], "default.0");
783                         Assert.AreEqual (2, elements[1], "default.1");
784                         Assert.AreEqual (3, elements[2], "default.2");
785                         Assert.AreEqual (4, elements[3], "default.3");
786                         Assert.AreEqual (-1, elements[4], "default.4");
787                         Assert.AreEqual (0, elements[5], "default.5");
788
789                         g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
790                         g.TranslateTransform (3, -3, MatrixOrder.Prepend);
791                         elements = g.Transform.Elements;
792                         Assert.AreEqual (1, elements[0], "prepend.0");
793                         Assert.AreEqual (2, elements[1], "prepend.1");
794                         Assert.AreEqual (3, elements[2], "prepend.2");
795                         Assert.AreEqual (4, elements[3], "prepend.3");
796                         Assert.AreEqual (-1, elements[4], "prepend.4");
797                         Assert.AreEqual (0, elements[5], "prepend.5");
798
799                         g.Transform = new Matrix (1, 2, 3, 4, 5, 6);
800                         g.TranslateTransform (3, -3, MatrixOrder.Append);
801                         elements = g.Transform.Elements;
802                         Assert.AreEqual (1, elements[0], "append.0");
803                         Assert.AreEqual (2, elements[1], "append.1");
804                         Assert.AreEqual (3, elements[2], "append.2");
805                         Assert.AreEqual (4, elements[3], "append.3");
806                         Assert.AreEqual (8, elements[4], "append.4");
807                         Assert.AreEqual (3, elements[5], "append.5");
808                 }
809
810                 static Point[] SmallCurve = new Point[3] { new Point (0, 0), new Point (15, 5), new Point (5, 15) };
811                 static PointF[] SmallCurveF = new PointF[3] { new PointF (0, 0), new PointF (15, 5), new PointF (5, 15) };
812
813                 static Point[] TooSmallCurve = new Point[2] { new Point (0, 0), new Point (15, 5) };
814                 static PointF[] LargeCurveF = new PointF[4] { new PointF (0, 0), new PointF (15, 5), new PointF (5, 15), new PointF (0, 20) };
815
816                 [Test]
817                 [ExpectedException (typeof (ArgumentNullException))]
818                 public void DrawCurve_PenNull ()
819                 {
820                         Bitmap bitmap = new Bitmap (20, 20);
821                         Graphics g = Graphics.FromImage (bitmap);
822                         g.DrawCurve (null, SmallCurveF);
823                 }
824
825                 [Test]
826                 [ExpectedException (typeof (ArgumentNullException))]
827                 public void DrawCurve_PointFNull ()
828                 {
829                         Bitmap bitmap = new Bitmap (20, 20);
830                         Graphics g = Graphics.FromImage (bitmap);
831                         g.DrawCurve (Pens.Black, (PointF[]) null);
832                 }
833
834                 [Test]
835                 [ExpectedException (typeof (ArgumentNullException))]
836                 public void DrawCurve_PointNull ()
837                 {
838                         Bitmap bitmap = new Bitmap (20, 20);
839                         Graphics g = Graphics.FromImage (bitmap);
840                         g.DrawCurve (Pens.Black, (Point[]) null);
841                 }
842
843                 [Test]
844                 public void DrawCurve_NotEnoughPoints ()
845                 {
846                         Bitmap bitmap = new Bitmap (20, 20);
847                         Graphics g = Graphics.FromImage (bitmap);
848                         CheckForEmptyBitmap (bitmap);
849                         g.DrawCurve (Pens.Black, TooSmallCurve, 0.5f);
850                         CheckForNonEmptyBitmap (bitmap);
851                         // so a "curve" can be drawn with less than 3 points!
852                         // actually I used to call that a line... (and it's not related to tension)
853                         g.Dispose ();
854                         bitmap.Dispose ();
855                 }
856
857                 [Test]
858                 [ExpectedException (typeof (ArgumentException))]
859                 public void DrawCurve_SinglePoint ()
860                 {
861                         Bitmap bitmap = new Bitmap (20, 20);
862                         Graphics g = Graphics.FromImage (bitmap);
863                         g.DrawCurve (Pens.Black, new Point[1] { new Point (10, 10) }, 0.5f);
864                         // a single point isn't enough
865                 }
866
867                 [Test]
868                 [ExpectedException (typeof (ArgumentException))]
869                 public void DrawCurve3_NotEnoughPoints ()
870                 {
871                         Bitmap bitmap = new Bitmap (20, 20);
872                         Graphics g = Graphics.FromImage (bitmap);
873                         g.DrawCurve (Pens.Black, TooSmallCurve, 0, 2, 0.5f);
874                         // aha, this is API dependent
875                 }
876
877                 [Test]
878                 public void DrawCurve_NegativeTension ()
879                 {
880                         Bitmap bitmap = new Bitmap (20, 20);
881                         Graphics g = Graphics.FromImage (bitmap);
882                         // documented as bigger (or equals) to 0
883                         g.DrawCurve (Pens.Black, SmallCurveF, -0.9f);
884                         CheckForNonEmptyBitmap (bitmap);
885                         g.Dispose ();
886                         bitmap.Dispose ();
887                 }
888
889                 [Test]
890                 public void DrawCurve_PositiveTension ()
891                 {
892                         Bitmap bitmap = new Bitmap (20, 20);
893                         Graphics g = Graphics.FromImage (bitmap);
894                         g.DrawCurve (Pens.Black, SmallCurveF, 0.9f);
895                         // this is not the same as -1
896                         CheckForNonEmptyBitmap (bitmap);
897                         g.Dispose ();
898                         bitmap.Dispose ();
899                 }
900
901                 [Test]
902                 [Category ("NotWorking")] // libgdiplus is drawing something
903                 public void DrawCurve_LargeTension ()
904                 {
905                         Bitmap bitmap = new Bitmap (20, 20);
906                         Graphics g = Graphics.FromImage (bitmap);
907                         g.DrawCurve (Pens.Black, SmallCurve, Single.MaxValue);
908                         CheckForEmptyBitmap (bitmap);
909                         // too much tension ;)
910                         g.Dispose ();
911                         bitmap.Dispose ();
912                 }
913
914                 [Test]
915                 [ExpectedException (typeof (ArgumentException))]
916                 public void DrawCurve_ZeroSegments ()
917                 {
918                         Bitmap bitmap = new Bitmap (20, 20);
919                         Graphics g = Graphics.FromImage (bitmap);
920                         g.DrawCurve (Pens.Black, SmallCurveF, 0, 0);
921                 }
922
923                 [Test]
924                 [ExpectedException (typeof (ArgumentException))]
925                 public void DrawCurve_NegativeSegments ()
926                 {
927                         Bitmap bitmap = new Bitmap (20, 20);
928                         Graphics g = Graphics.FromImage (bitmap);
929                         g.DrawCurve (Pens.Black, SmallCurveF, 0, -1);
930                 }
931
932                 [Test]
933                 [ExpectedException (typeof (ArgumentException))]
934                 public void DrawCurve_OffsetTooLarge ()
935                 {
936                         Bitmap bitmap = new Bitmap (20, 20);
937                         Graphics g = Graphics.FromImage (bitmap);
938                         // starting offset 1 doesn't give 3 points to make a curve
939                         g.DrawCurve (Pens.Black, SmallCurveF, 1, 2);
940                         // and in this case 2 points aren't enough to draw something
941                 }
942
943                 [Test]
944                 public void DrawCurve_Offset_0 ()
945                 {
946                         Bitmap bitmap = new Bitmap (20, 20);
947                         Graphics g = Graphics.FromImage (bitmap);
948                         g.DrawCurve (Pens.Black, LargeCurveF, 0, 2, 0.5f);
949                         CheckForNonEmptyBitmap (bitmap);
950                         g.Dispose ();
951                         bitmap.Dispose ();
952                 }
953
954                 [Test]
955                 public void DrawCurve_Offset_1 ()
956                 {
957                         Bitmap bitmap = new Bitmap (20, 20);
958                         Graphics g = Graphics.FromImage (bitmap);
959                         g.DrawCurve (Pens.Black, LargeCurveF, 1, 2, 0.5f);
960                         CheckForNonEmptyBitmap (bitmap);
961                         g.Dispose ();
962                         bitmap.Dispose ();
963                 }
964
965                 [Test]
966                 public void DrawCurve_Offset_2 ()
967                 {
968                         Bitmap bitmap = new Bitmap (20, 20);
969                         Graphics g = Graphics.FromImage (bitmap);
970                         // it works even with two points because we know the previous ones
971                         g.DrawCurve (Pens.Black, LargeCurveF, 2, 1, 0.5f);
972                         CheckForNonEmptyBitmap (bitmap);
973                         g.Dispose ();
974                         bitmap.Dispose ();
975                 }
976
977                 [Test]
978                 public void DrawRectangle_Negative ()
979                 {
980                         Bitmap bitmap = new Bitmap (20, 20);
981                         Graphics g = Graphics.FromImage (bitmap);
982                         Pen pen = new Pen (Color.Red);
983                         g.DrawRectangle (pen, 5, 5, -10, -10);
984                         g.DrawRectangle (pen, 0.0f, 0.0f, 5.0f, -10.0f);
985                         g.DrawRectangle (pen, new Rectangle (15, 0, -10, 5));
986                         CheckForEmptyBitmap (bitmap);
987                         pen.Dispose ();
988                         g.Dispose ();
989                         bitmap.Dispose ();
990                 }
991
992                 [Test]
993                 public void DrawRectangles_Negative ()
994                 {
995                         Bitmap bitmap = new Bitmap (20, 20);
996                         Graphics g = Graphics.FromImage (bitmap);
997                         Pen pen = new Pen (Color.Red);
998                         Rectangle[] rects = new Rectangle[2] {
999                                 new Rectangle (5, 5, -10, -10), new Rectangle (0, 0, 5, -10)
1000                         };
1001                         RectangleF[] rectf = new RectangleF[2] {
1002                                 new RectangleF (0.0f, 5.0f, -10.0f, -10.0f), new RectangleF (15.0f, 0.0f, -10.0f, 5.0f)
1003                         };
1004                         g.DrawRectangles (pen, rects);
1005                         g.DrawRectangles (pen, rectf);
1006                         CheckForEmptyBitmap (bitmap);
1007                         pen.Dispose ();
1008                         g.Dispose ();
1009                         bitmap.Dispose ();
1010                 }
1011
1012                 [Test]
1013                 public void FillRectangle_Negative ()
1014                 {
1015                         Bitmap bitmap = new Bitmap (20, 20);
1016                         Graphics g = Graphics.FromImage (bitmap);
1017                         SolidBrush brush = new SolidBrush (Color.Red);
1018                         g.FillRectangle (brush, 5, 5, -10, -10);
1019                         g.FillRectangle (brush, 0.0f, 0.0f, 5.0f, -10.0f);
1020                         g.FillRectangle (brush, new Rectangle (15, 0, -10, 5));
1021                         CheckForEmptyBitmap (bitmap);
1022                         brush.Dispose ();
1023                         g.Dispose ();
1024                         bitmap.Dispose ();
1025                 }
1026
1027                 [Test]
1028                 public void FillRectangles_Negative ()
1029                 {
1030                         Bitmap bitmap = new Bitmap (20, 20);
1031                         Graphics g = Graphics.FromImage (bitmap);
1032                         SolidBrush brush = new SolidBrush (Color.Red);
1033                         Rectangle[] rects = new Rectangle[2] {
1034                                 new Rectangle (5, 5, -10, -10), new Rectangle (0, 0, 5, -10)
1035                         };
1036                         RectangleF[] rectf = new RectangleF[2] {
1037                                 new RectangleF (0.0f, 5.0f, -10.0f, -10.0f), new RectangleF (15.0f, 0.0f, -10.0f, 5.0f)
1038                         };
1039                         g.FillRectangles (brush, rects);
1040                         g.FillRectangles (brush, rectf);
1041                         CheckForEmptyBitmap (bitmap);
1042                         brush.Dispose ();
1043                         g.Dispose ();
1044                         bitmap.Dispose ();
1045                 }
1046
1047                 [Test] // bug #355141
1048                 [Category ("CAS")]
1049                 public void FromHwnd_Zero ()
1050                 {
1051                         Graphics g = Graphics.FromHwnd (IntPtr.Zero);
1052                         Assert.IsNotNull (g);
1053                 }
1054
1055                 private void CheckDefaultProperties (string message, Graphics g)
1056                 {
1057                         Assert.IsTrue (g.Clip.IsInfinite (g), message + ".Clip.IsInfinite");
1058                         AssertEquals (message + ".CompositingMode", CompositingMode.SourceOver, g.CompositingMode);
1059                         AssertEquals (message + ".CompositingQuality", CompositingQuality.Default, g.CompositingQuality);
1060                         AssertEquals (message + ".InterpolationMode", InterpolationMode.Bilinear, g.InterpolationMode);
1061                         AssertEquals (message + ".PageScale", 1.0f, g.PageScale);
1062                         AssertEquals (message + ".PageUnit", GraphicsUnit.Display, g.PageUnit);
1063                         AssertEquals (message + ".PixelOffsetMode", PixelOffsetMode.Default, g.PixelOffsetMode);
1064                         AssertEquals (message + ".SmoothingMode", SmoothingMode.None, g.SmoothingMode);
1065                         AssertEquals (message + ".TextContrast", 4, g.TextContrast);
1066                         AssertEquals (message + ".TextRenderingHint", TextRenderingHint.SystemDefault, g.TextRenderingHint);
1067                         Assert.IsTrue (g.Transform.IsIdentity, message + ".Transform.IsIdentity");
1068                 }
1069
1070                 private void CheckCustomProperties (string message, Graphics g)
1071                 {
1072                         Assert.IsFalse (g.Clip.IsInfinite (g), message + ".Clip.IsInfinite");
1073                         AssertEquals (message + ".CompositingMode", CompositingMode.SourceCopy, g.CompositingMode);
1074                         AssertEquals (message + ".CompositingQuality", CompositingQuality.HighQuality, g.CompositingQuality);
1075                         AssertEquals (message + ".InterpolationMode", InterpolationMode.HighQualityBicubic, g.InterpolationMode);
1076                         AssertEquals (message + ".PageScale", 0.5f, g.PageScale);
1077                         AssertEquals (message + ".PageUnit", GraphicsUnit.Inch, g.PageUnit);
1078                         AssertEquals (message + ".PixelOffsetMode", PixelOffsetMode.Half, g.PixelOffsetMode);
1079                         AssertEquals (message + ".RenderingOrigin", new Point (-1, -1), g.RenderingOrigin);
1080                         AssertEquals (message + ".SmoothingMode", SmoothingMode.AntiAlias, g.SmoothingMode);
1081                         AssertEquals (message + ".TextContrast", 0, g.TextContrast);
1082                         AssertEquals (message + ".TextRenderingHint", TextRenderingHint.AntiAlias, g.TextRenderingHint);
1083                         Assert.IsFalse (g.Transform.IsIdentity, message + ".Transform.IsIdentity");
1084                 }
1085
1086                 private void CheckMatrix (string message, Matrix m, float xx, float yx, float xy, float yy, float x0, float y0)
1087                 {
1088                         float[] elements = m.Elements;
1089                         AssertEquals (message + ".Matrix.xx", xx, elements[0], 0.01);
1090                         AssertEquals (message + ".Matrix.yx", yx, elements[1], 0.01);
1091                         AssertEquals (message + ".Matrix.xy", xy, elements[2], 0.01);
1092                         AssertEquals (message + ".Matrix.yy", yy, elements[3], 0.01);
1093                         AssertEquals (message + ".Matrix.x0", x0, elements[4], 0.01);
1094                         AssertEquals (message + ".Matrix.y0", y0, elements[5], 0.01);
1095                 }
1096
1097                 [Test]
1098                 public void BeginContainer ()
1099                 {
1100                         Bitmap bitmap = new Bitmap (20, 20);
1101                         Graphics g = Graphics.FromImage (bitmap);
1102
1103                         CheckDefaultProperties ("default", g);
1104                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1105
1106                         g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1107                         g.CompositingMode = CompositingMode.SourceCopy;
1108                         g.CompositingQuality = CompositingQuality.HighQuality;
1109                         g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1110                         g.PageScale = 0.5f;
1111                         g.PageUnit = GraphicsUnit.Inch;
1112                         g.PixelOffsetMode = PixelOffsetMode.Half;
1113                         g.RenderingOrigin = new Point (-1, -1);
1114                         g.RotateTransform (45);
1115                         g.SmoothingMode = SmoothingMode.AntiAlias;
1116                         g.TextContrast = 0;
1117                         g.TextRenderingHint = TextRenderingHint.AntiAlias;
1118                         CheckCustomProperties ("modified", g);
1119                         CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1120
1121                         GraphicsContainer gc = g.BeginContainer ();
1122                         // things gets reseted after calling BeginContainer
1123                         CheckDefaultProperties ("BeginContainer", g);
1124                         // but not everything 
1125                         Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
1126
1127                         g.EndContainer (gc);
1128                         CheckCustomProperties ("EndContainer", g);
1129                 }
1130
1131                 [Test]
1132                 public void BeginContainer_Rect ()
1133                 {
1134                         Bitmap bitmap = new Bitmap (20, 20);
1135                         Graphics g = Graphics.FromImage (bitmap);
1136
1137                         CheckDefaultProperties ("default", g);
1138                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1139
1140                         g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1141                         g.CompositingMode = CompositingMode.SourceCopy;
1142                         g.CompositingQuality = CompositingQuality.HighQuality;
1143                         g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1144                         g.PageScale = 0.5f;
1145                         g.PageUnit = GraphicsUnit.Inch;
1146                         g.PixelOffsetMode = PixelOffsetMode.Half;
1147                         g.RenderingOrigin = new Point (-1, -1);
1148                         g.RotateTransform (45);
1149                         g.SmoothingMode = SmoothingMode.AntiAlias;
1150                         g.TextContrast = 0;
1151                         g.TextRenderingHint = TextRenderingHint.AntiAlias;
1152                         CheckCustomProperties ("modified", g);
1153                         CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1154
1155                         GraphicsContainer gc = g.BeginContainer (new Rectangle (10, 20, 30, 40), new Rectangle (10, 20, 300, 400), GraphicsUnit.Millimeter);
1156                         // things gets reseted after calling BeginContainer
1157                         CheckDefaultProperties ("BeginContainer", g);
1158                         // but not everything 
1159                         Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
1160
1161                         g.EndContainer (gc);
1162                         CheckCustomProperties ("EndContainer", g);
1163                         CheckMatrix ("EndContainer.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1164                 }
1165
1166                 [Test]
1167                 public void BeginContainer_RectF ()
1168                 {
1169                         Bitmap bitmap = new Bitmap (20, 20);
1170                         Graphics g = Graphics.FromImage (bitmap);
1171
1172                         CheckDefaultProperties ("default", g);
1173                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1174
1175                         g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1176                         g.CompositingMode = CompositingMode.SourceCopy;
1177                         g.CompositingQuality = CompositingQuality.HighQuality;
1178                         g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1179                         g.PageScale = 0.5f;
1180                         g.PageUnit = GraphicsUnit.Inch;
1181                         g.PixelOffsetMode = PixelOffsetMode.Half;
1182                         g.RenderingOrigin = new Point (-1, -1);
1183                         g.RotateTransform (45);
1184                         g.SmoothingMode = SmoothingMode.AntiAlias;
1185                         g.TextContrast = 0;
1186                         g.TextRenderingHint = TextRenderingHint.AntiAlias;
1187                         CheckCustomProperties ("modified", g);
1188                         CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1189
1190                         GraphicsContainer gc = g.BeginContainer (new RectangleF (40, 30, 20, 10), new RectangleF (10, 20, 30, 40), GraphicsUnit.Inch);
1191                         // things gets reseted after calling BeginContainer
1192                         CheckDefaultProperties ("BeginContainer", g);
1193                         // but not everything 
1194                         Assert.AreEqual (new Point (-1, -1), g.RenderingOrigin, "BeginContainer.RenderingOrigin");
1195
1196                         g.EndContainer (gc);
1197                         CheckCustomProperties ("EndContainer", g);
1198                 }
1199
1200                 private void BeginContainer_GraphicsUnit (GraphicsUnit unit)
1201                 {
1202                         Bitmap bitmap = new Bitmap (20, 20);
1203                         Graphics g = Graphics.FromImage (bitmap);
1204                         g.BeginContainer (new RectangleF (40, 30, 20, 10), new RectangleF (10, 20, 30, 40), unit);
1205                 }
1206
1207                 [Test]
1208                 [ExpectedException (typeof (ArgumentException))]
1209                 public void BeginContainer_GraphicsUnit_Display ()
1210                 {
1211                         BeginContainer_GraphicsUnit (GraphicsUnit.Display);
1212                 }
1213
1214                 [Test]
1215                 public void BeginContainer_GraphicsUnit_Valid ()
1216                 {
1217                         BeginContainer_GraphicsUnit (GraphicsUnit.Document);
1218                         BeginContainer_GraphicsUnit (GraphicsUnit.Inch);
1219                         BeginContainer_GraphicsUnit (GraphicsUnit.Millimeter);
1220                         BeginContainer_GraphicsUnit (GraphicsUnit.Pixel);
1221                         BeginContainer_GraphicsUnit (GraphicsUnit.Point);
1222                 }
1223
1224                 [Test]
1225                 [ExpectedException (typeof (ArgumentException))]
1226                 public void BeginContainer_GraphicsUnit_World ()
1227                 {
1228                         BeginContainer_GraphicsUnit (GraphicsUnit.World);
1229                 }
1230
1231                 [Test]
1232                 [ExpectedException (typeof (ArgumentException))]
1233                 public void BeginContainer_GraphicsUnit_Bad ()
1234                 {
1235                         BeginContainer_GraphicsUnit ((GraphicsUnit) Int32.MinValue);
1236                 }
1237
1238                 [Test]
1239                 [ExpectedException (typeof (ArgumentNullException))]
1240                 public void EndContainer_Null ()
1241                 {
1242                         Bitmap bitmap = new Bitmap (20, 20);
1243                         Graphics g = Graphics.FromImage (bitmap);
1244                         g.EndContainer (null);
1245                 }
1246
1247                 [Test]
1248                 public void Save ()
1249                 {
1250                         Bitmap bitmap = new Bitmap (20, 20);
1251                         Graphics g = Graphics.FromImage (bitmap);
1252
1253                         CheckDefaultProperties ("default", g);
1254                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1255
1256                         GraphicsState gs1 = g.Save ();
1257                         // nothing is changed after a save
1258                         CheckDefaultProperties ("save1", g);
1259                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "save1.RenderingOrigin");
1260
1261                         g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1262                         g.CompositingMode = CompositingMode.SourceCopy;
1263                         g.CompositingQuality = CompositingQuality.HighQuality;
1264                         g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1265                         g.PageScale = 0.5f;
1266                         g.PageUnit = GraphicsUnit.Inch;
1267                         g.PixelOffsetMode = PixelOffsetMode.Half;
1268                         g.RenderingOrigin = new Point (-1, -1);
1269                         g.RotateTransform (45);
1270                         g.SmoothingMode = SmoothingMode.AntiAlias;
1271                         g.TextContrast = 0;
1272                         g.TextRenderingHint = TextRenderingHint.AntiAlias;
1273                         CheckCustomProperties ("modified", g);
1274                         CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1275
1276                         GraphicsState gs2 = g.Save ();
1277                         CheckCustomProperties ("save2", g);
1278
1279                         g.Restore (gs2);
1280                         CheckCustomProperties ("restored1", g);
1281                         CheckMatrix ("restored1.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1282
1283                         g.Restore (gs1);
1284                         CheckDefaultProperties ("restored2", g);
1285                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "restored2.RenderingOrigin");
1286                 }
1287
1288                 [Test]
1289                 [ExpectedException (typeof (NullReferenceException))]
1290                 public void Restore_Null ()
1291                 {
1292                         Bitmap bitmap = new Bitmap (20, 20);
1293                         Graphics g = Graphics.FromImage (bitmap);
1294                         g.Restore (null);
1295                 }
1296
1297                 [Test]
1298                 [ExpectedException (typeof (ArgumentNullException))]
1299                 public void FillRectangles_BrushNull_Rectangle ()
1300                 {
1301                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1302                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1303                                         g.FillRectangles (null, new Rectangle[1]);
1304                                 }
1305                         }
1306                 }
1307
1308                 [Test]
1309                 [ExpectedException (typeof (ArgumentNullException))]
1310                 public void FillRectangles_Rectangle_Null ()
1311                 {
1312                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1313                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1314                                         g.FillRectangles (Brushes.Red, (Rectangle[]) null);
1315                                 }
1316                         }
1317                 }
1318
1319                 [Test] // see bug #78408
1320                 [ExpectedException (typeof (ArgumentException))]
1321                 public void FillRectanglesZeroRectangle ()
1322                 {
1323                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1324                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1325                                         g.FillRectangles (Brushes.Red, new Rectangle[0]);
1326                                 }
1327                         }
1328                 }
1329
1330                 [Test]
1331                 [ExpectedException (typeof (ArgumentNullException))]
1332                 public void FillRectangles_BrushNull_RectangleF ()
1333                 {
1334                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1335                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1336                                         g.FillRectangles (null, new RectangleF[1]);
1337                                 }
1338                         }
1339                 }
1340
1341                 [Test]
1342                 [ExpectedException (typeof (ArgumentNullException))]
1343                 public void FillRectangles_RectangleF_Null ()
1344                 {
1345                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1346                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1347                                         g.FillRectangles (Brushes.Red, (RectangleF[]) null);
1348                                 }
1349                         }
1350                 }
1351
1352                 [Test] // see bug #78408
1353                 [ExpectedException (typeof (ArgumentException))]
1354                 public void FillRectanglesZeroRectangleF ()
1355                 {
1356                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1357                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1358                                         g.FillRectangles (Brushes.Red, new RectangleF[0]);
1359                                 }
1360                         }
1361                 }
1362
1363                 [Test]
1364                 public void FillRectangles_NormalBehavior ()
1365                 {
1366                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1367                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1368                                         g.Clear (Color.Fuchsia);
1369                                         Rectangle rect = new Rectangle (5, 5, 10, 10);
1370                                         g.Clip = new Region (rect);
1371                                         g.FillRectangle (Brushes.Red, rect);
1372                                 }
1373                                 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1374                                 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1375                                 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 14).ToArgb (), "5,14");
1376                                 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1377
1378                                 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1379                                 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1380                                 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1381                         }
1382                 }
1383
1384                 // see bug #81737 for details
1385                 private Bitmap FillDrawRectangle (float width)
1386                 {
1387                         Bitmap bitmap = new Bitmap (20, 20);
1388                         using (Graphics g = Graphics.FromImage (bitmap)) {
1389                                 g.Clear (Color.Red);
1390                                 Rectangle rect = new Rectangle (5, 5, 10, 10);
1391                                 g.FillRectangle (Brushes.Green, rect);
1392                                 if (width >= 0) {
1393                                         using (Pen pen = new Pen (Color.Blue, width)) {
1394                                                 g.DrawRectangle (pen, rect);
1395                                         }
1396                                 } else {
1397                                         g.DrawRectangle (Pens.Blue, rect);
1398                                 }
1399                         }
1400                         return bitmap;
1401                 }
1402
1403                 [Test]
1404                 public void FillDrawRectangle_Width_Default ()
1405                 {
1406                         // default pen size
1407                         using (Bitmap bitmap = FillDrawRectangle (Single.MinValue)) {
1408                                 // NW
1409                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1410                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1411                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1412                                 // N
1413                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1414                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1415                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1416                                 // NE
1417                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1418                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1419                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1420                                 // E
1421                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1422                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1423                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1424                                 // SE
1425                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1426                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1427                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1428                                 // S
1429                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1430                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1431                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1432                                 // SW
1433                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1434                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1435                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1436                                 // W
1437                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1438                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1439                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1440                         }
1441                 }
1442
1443                 [Test]
1444                 [Category ("NotOnMac")]
1445                 public void FillDrawRectangle_Width_2 ()
1446                 {
1447                         // even pen size
1448                         using (Bitmap bitmap = FillDrawRectangle (2.0f)) {
1449                                 // NW
1450                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1451                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1452                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1453                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1454                                 // N
1455                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1456                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1457                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1458                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1459                                 // NE
1460                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1461                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1462                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1463                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1464                                 // E
1465                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1466                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1467                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1468                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
1469                                 // SE
1470                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1471                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1472                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1473                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
1474                                 // S
1475                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1476                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1477                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1478                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
1479                                 // SW
1480                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "3,16");
1481                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "4,15");
1482                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 14).ToArgb (), "5,14");
1483                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 13).ToArgb (), "6,13");
1484                                 // W
1485                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1486                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1487                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1488                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1489                         }
1490                 }
1491
1492                 [Test]
1493                 public void FillDrawRectangle_Width_3 ()
1494                 {
1495                         // odd pen size
1496                         using (Bitmap bitmap = FillDrawRectangle (3.0f)) {
1497                                 // NW
1498                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1499                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1500                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1501                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1502                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 7).ToArgb (), "7,7");
1503                                 // N
1504                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1505                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1506                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1507                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1508                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 7).ToArgb (), "9,7");
1509                                 // NE
1510                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1511                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1512                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1513                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1514                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
1515                                 // E
1516                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
1517                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1518                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1519                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1520                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
1521                                 // SE
1522                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
1523                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1524                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1525                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1526                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
1527                                 // S
1528                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
1529                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1530                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1531                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1532                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
1533                                 // SW
1534                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
1535                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1536                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1537                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1538                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 13).ToArgb (), "7,13");
1539                                 // W
1540                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1541                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1542                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1543                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1544                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 9).ToArgb (), "7,9");
1545                         }
1546                 }
1547
1548                 // reverse, draw the fill over
1549                 private Bitmap DrawFillRectangle (float width)
1550                 {
1551                         Bitmap bitmap = new Bitmap (20, 20);
1552                         using (Graphics g = Graphics.FromImage (bitmap)) {
1553                                 g.Clear (Color.Red);
1554                                 Rectangle rect = new Rectangle (5, 5, 10, 10);
1555                                 if (width >= 0) {
1556                                         using (Pen pen = new Pen (Color.Blue, width)) {
1557                                                 g.DrawRectangle (pen, rect);
1558                                         }
1559                                 } else {
1560                                         g.DrawRectangle (Pens.Blue, rect);
1561                                 }
1562                                 g.FillRectangle (Brushes.Green, rect);
1563                         }
1564                         return bitmap;
1565                 }
1566
1567                 [Test]
1568                 public void DrawFillRectangle_Width_Default ()
1569                 {
1570                         // default pen size
1571                         using (Bitmap bitmap = DrawFillRectangle (Single.MinValue)) {
1572                                 // NW - no blue border
1573                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1574                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1575                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1576                                 // N - no blue border
1577                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1578                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1579                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1580                                 // NE
1581                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1582                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1583                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1584                                 // E
1585                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1586                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1587                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1588                                 // SE
1589                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1590                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1591                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1592                                 // S
1593                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1594                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1595                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1596                                 // SW
1597                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1598                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1599                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1600                                 // W - no blue border
1601                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1602                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1603                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1604                         }
1605                 }
1606
1607                 [Test]
1608                 [Category ("NotOnMac")]
1609                 public void DrawFillRectangle_Width_2 ()
1610                 {
1611                         // even pen size
1612                         using (Bitmap bitmap = DrawFillRectangle (2.0f)) {
1613                                 // looks like a one pixel border - but enlarged
1614                                 // NW
1615                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1616                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1617                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1618                                 // N
1619                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1620                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1621                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1622                                 // NE
1623                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1624                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1625                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1626                                 // E
1627                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1628                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1629                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1630                                 // SE
1631                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1632                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1633                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1634                                 // S
1635                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1636                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1637                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1638                                 // SW
1639                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "4,16");
1640                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "5,15");
1641                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 14).ToArgb (), "6,14");
1642                                 // W
1643                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1644                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1645                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1646                         }
1647                 }
1648
1649                 [Test]
1650                 public void DrawFillRectangle_Width_3 ()
1651                 {
1652                         // odd pen size
1653                         using (Bitmap bitmap = DrawFillRectangle (3.0f)) {
1654                                 // NW
1655                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1656                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1657                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1658                                 // N
1659                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1660                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1661                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1662                                 // NE
1663                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1664                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1665                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1666                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1667                                 // E
1668                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
1669                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1670                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1671                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1672                                 // SE
1673                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
1674                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1675                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1676                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1677                                 // S
1678                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
1679                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1680                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1681                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1682                                 // SW
1683                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
1684                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1685                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1686                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1687                                 // W
1688                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1689                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1690                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1691                         }
1692                 }
1693
1694                 private Bitmap DrawLines (float width)
1695                 {
1696                         Bitmap bitmap = new Bitmap (20, 20);
1697                         using (Graphics g = Graphics.FromImage (bitmap)) {
1698                                 g.Clear (Color.Red);
1699                                 Point[] pts = new Point[3] { new Point (5, 5), new Point (15, 5), new Point (15, 15) };
1700                                 if (width >= 0) {
1701                                         using (Pen pen = new Pen (Color.Blue, width)) {
1702                                                 g.DrawLines (pen, pts);
1703                                         }
1704                                 } else {
1705                                         g.DrawLines (Pens.Blue, pts);
1706                                 }
1707                         }
1708                         return bitmap;
1709                 }
1710
1711                 [Test]
1712                 public void DrawLines_Width_Default ()
1713                 {
1714                         // default pen size
1715                         using (Bitmap bitmap = DrawLines (Single.MinValue)) {
1716                                 // start
1717                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1718                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1719                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1720                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1721                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1722                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1723                                 // middle
1724                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1725                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1726                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1727                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1728                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1729                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1730                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1731                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1732                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1733                                 //end
1734                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1735                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1736                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1737                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 16).ToArgb (), "14,16");
1738                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 16).ToArgb (), "15,16");
1739                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1740                         }
1741                 }
1742
1743                 [Test]
1744                 [Category ("NotWorking")]
1745                 public void DrawLines_Width_2 ()
1746                 {
1747                         // default pen size
1748                         using (Bitmap bitmap = DrawLines (2.0f)) {
1749                                 // start
1750                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
1751                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1752                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1753                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1754                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
1755                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1756                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1757                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1758                                 // middle
1759                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
1760                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
1761                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
1762                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1763                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
1764                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1765                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1766                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1767                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
1768                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1769                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1770                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1771                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1772                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1773                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1774                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1775                                 //end
1776                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
1777                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1778                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
1779                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
1780                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
1781                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1782                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1783                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1784                         }
1785                 }
1786
1787                 [Test]
1788                 [Category ("NotWorking")]
1789                 public void DrawLines_Width_3 ()
1790                 {
1791                         // default pen size
1792                         using (Bitmap bitmap = DrawLines (3.0f)) {
1793                                 // start
1794                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
1795                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1796                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1797                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1798                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 7).ToArgb (), "4,7");
1799                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
1800                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1801                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1802                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1803                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 7).ToArgb (), "5,7");
1804                                 // middle
1805                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
1806                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
1807                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
1808                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1809                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
1810                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
1811                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1812                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1813                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1814                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 7).ToArgb (), "14,7");
1815                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
1816                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1817                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1818                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1819                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 7).ToArgb (), "15,7");
1820                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1821                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1822                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1823                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1824                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 7).ToArgb (), "16,7");
1825                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1826                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 4).ToArgb (), "17,4");
1827                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 5).ToArgb (), "17,5");
1828                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 6).ToArgb (), "17,6");
1829                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 7).ToArgb (), "17,7");
1830                                 //end
1831                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
1832                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1833                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
1834                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
1835                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 14).ToArgb (), "17,14");
1836                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
1837                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1838                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1839                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1840                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 15).ToArgb (), "17,15");
1841                         }
1842                 }
1843
1844                 [Test]
1845                 public void MeasureString_StringFont ()
1846                 {
1847                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1848                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1849                                         SizeF size = g.MeasureString (null, font);
1850                                         Assert.IsTrue (size.IsEmpty, "MeasureString(null,font)");
1851                                         size = g.MeasureString (String.Empty, font);
1852                                         Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font)");
1853                                         // null font
1854                                         size = g.MeasureString (null, null);
1855                                         Assert.IsTrue (size.IsEmpty, "MeasureString(null,null)");
1856                                         size = g.MeasureString (String.Empty, null);
1857                                         Assert.IsTrue (size.IsEmpty, "MeasureString(empty,null)");
1858                                 }
1859                         }
1860                 }
1861
1862                 [Test]
1863                 [ExpectedException (typeof (ArgumentNullException))]
1864                 public void MeasureString_StringFont_Null ()
1865                 {
1866                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1867                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1868                                         g.MeasureString ("a", null);
1869                                 }
1870                         }
1871                 }
1872
1873                 [Test]
1874                 public void MeasureString_StringFontSizeF ()
1875                 {
1876                         if (font == null)
1877                                 Assert.Ignore ("Couldn't create required font");
1878
1879                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1880                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1881                                         SizeF size = g.MeasureString ("a", font, SizeF.Empty);
1882                                         Assert.IsFalse (size.IsEmpty, "MeasureString(a,font,empty)");
1883
1884                                         size = g.MeasureString (String.Empty, font, SizeF.Empty);
1885                                         Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font,empty)");
1886                                 }
1887                         }
1888                 }
1889
1890                 private void MeasureString_StringFontInt (string s)
1891                 {
1892                         if (font == null)
1893                                 Assert.Ignore ("Couldn't create required font");
1894
1895                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1896                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1897                                         SizeF size0 = g.MeasureString (s, font, 0);
1898                                         SizeF sizeN = g.MeasureString (s, font, Int32.MinValue);
1899                                         SizeF sizeP = g.MeasureString (s, font, Int32.MaxValue);
1900                                         Assert.AreEqual (size0, sizeN, "0-Min");
1901                                         Assert.AreEqual (size0, sizeP, "0-Max");
1902                                 }
1903                         }
1904                 }
1905
1906                 [Test]
1907                 public void MeasureString_StringFontInt_ShortString ()
1908                 {
1909                         MeasureString_StringFontInt ("a");
1910                 }
1911
1912                 [Test]
1913                 public void MeasureString_StringFontInt_LongString ()
1914                 {
1915                         HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_StringFontInt_LongString");
1916                         MeasureString_StringFontInt ("A very long string..."); // see bug #79643
1917                 }
1918
1919                 [Test]
1920                 public void MeasureString_StringFormat_Alignment ()
1921                 {
1922                         if (font == null)
1923                                 Assert.Ignore ("Couldn't create required font");
1924
1925                         string text = "Hello Mono::";
1926                         StringFormat string_format = new StringFormat ();
1927
1928                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1929                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1930                                         string_format.Alignment = StringAlignment.Near;
1931                                         SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1932
1933                                         string_format.Alignment = StringAlignment.Center;
1934                                         SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1935
1936                                         string_format.Alignment = StringAlignment.Far;
1937                                         SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1938
1939                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1940                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
1941
1942                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
1943                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
1944                                 }
1945                         }
1946                 }
1947
1948                 [Test]
1949                 public void MeasureString_StringFormat_Alignment_DirectionVertical ()
1950                 {
1951                         if (font == null)
1952                                 Assert.Ignore ("Couldn't create required font");
1953
1954                         string text = "Hello Mono::";
1955                         StringFormat string_format = new StringFormat ();
1956                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1957
1958                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1959                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1960                                         string_format.Alignment = StringAlignment.Near;
1961                                         SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1962
1963                                         string_format.Alignment = StringAlignment.Center;
1964                                         SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1965
1966                                         string_format.Alignment = StringAlignment.Far;
1967                                         SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1968
1969                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1970                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
1971
1972                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
1973                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
1974                                 }
1975                         }
1976                 }
1977
1978                 [Test]
1979                 public void MeasureString_StringFormat_LineAlignment ()
1980                 {
1981                         if (font == null)
1982                                 Assert.Ignore ("Couldn't create required font");
1983
1984                         string text = "Hello Mono::";
1985                         StringFormat string_format = new StringFormat ();
1986
1987                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1988                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1989                                         string_format.LineAlignment = StringAlignment.Near;
1990                                         SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1991
1992                                         string_format.LineAlignment = StringAlignment.Center;
1993                                         SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1994
1995                                         string_format.LineAlignment = StringAlignment.Far;
1996                                         SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1997
1998                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1999                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2000
2001                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2002                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2003                                 }
2004                         }
2005                 }
2006
2007                 [Test]
2008                 public void MeasureString_StringFormat_LineAlignment_DirectionVertical ()
2009                 {
2010                         if (font == null)
2011                                 Assert.Ignore ("Couldn't create required font");
2012
2013                         string text = "Hello Mono::";
2014                         StringFormat string_format = new StringFormat ();
2015                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2016
2017                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2018                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2019                                         string_format.LineAlignment = StringAlignment.Near;
2020                                         SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
2021
2022                                         string_format.LineAlignment = StringAlignment.Center;
2023                                         SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
2024
2025                                         string_format.LineAlignment = StringAlignment.Far;
2026                                         SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
2027
2028                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2029                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2030
2031                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2032                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2033                                 }
2034                         }
2035                 }
2036
2037                 [Test]
2038                 public void MeasureString_MultlineString_Width ()
2039                 {
2040                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2041                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2042                                         StringFormat string_format = new StringFormat ();
2043
2044                                         string text1 = "Test\nTest123\nTest 456\nTest 1,2,3,4,5...";
2045                                         string text2 = "Test 1,2,3,4,5...";
2046
2047                                         SizeF size1 = g.MeasureString (text1, font, SizeF.Empty, string_format);
2048                                         SizeF size2 = g.MeasureString (text2, font, SizeF.Empty, string_format);
2049
2050                                         Assert.AreEqual ((int) size1.Width, (int) size2.Width, "Multiline Text Width");
2051                                 }
2052                         }
2053                 }
2054
2055                 [Test]
2056                 public void MeasureString_Bug76664 ()
2057                 {
2058                         if (font == null)
2059                                 Assert.Ignore ("Couldn't create required font");
2060
2061                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2062                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2063                                         string s = "aaa aa aaaa a aaa";
2064                                         SizeF size = g.MeasureString (s, font);
2065
2066                                         int chars, lines;
2067                                         SizeF size2 = g.MeasureString (s, font, new SizeF (80, size.Height), null, out chars, out lines);
2068
2069                                         // in pixels
2070                                         Assert.IsTrue (size2.Width < size.Width, "Width/pixel");
2071                                         Assert.AreEqual (size2.Height, size.Height, "Height/pixel");
2072
2073                                         Assert.AreEqual (1, lines, "lines fitted");
2074                                         // LAMESPEC: documentation seems to suggest chars is total length
2075                                         Assert.IsTrue (chars < s.Length, "characters fitted");
2076                                 }
2077                         }
2078                 }
2079
2080                 [Test]
2081                 public void MeasureString_Bug80680 ()
2082                 {
2083                         if (font == null)
2084                                 Assert.Ignore ("Couldn't create required font");
2085
2086                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2087                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2088                                         string s = String.Empty;
2089                                         SizeF size = g.MeasureString (s, font);
2090                                         Assert.AreEqual (0, size.Height, "Empty.Height");
2091                                         Assert.AreEqual (0, size.Width, "Empty.Width");
2092
2093                                         s += " ";
2094                                         SizeF expected = g.MeasureString (s, font);
2095                                         for (int i = 1; i < 10; i++) {
2096                                                 s += " ";
2097                                                 size = g.MeasureString (s, font);
2098                                                 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2099                                                 Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
2100                                         }
2101
2102                                         s = "a";
2103                                         expected = g.MeasureString (s, font);
2104                                         s = " " + s;
2105                                         size = g.MeasureString (s, font);
2106                                         float space_width = size.Width - expected.Width;
2107                                         for (int i = 1; i < 10; i++) {
2108                                                 size = g.MeasureString (s, font);
2109                                                 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2110                                                 Assert.AreEqual (expected.Width + i * space_width, size.Width, 0.1, ">" + s + "< Width");
2111                                                 s = " " + s;
2112                                         }
2113
2114                                         s = "a";
2115                                         expected = g.MeasureString (s, font);
2116                                         for (int i = 1; i < 10; i++) {
2117                                                 s = s + " ";
2118                                                 size = g.MeasureString (s, font);
2119                                                 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2120                                                 Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
2121                                         }
2122                                 }
2123                         }
2124                 }
2125
2126                 [Test]
2127                 public void MeasureCharacterRanges_NullOrEmptyText ()
2128                 {
2129                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2130                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2131                                         Region[] regions = g.MeasureCharacterRanges (null, font, new RectangleF (), null);
2132                                         Assert.AreEqual (0, regions.Length, "text null");
2133                                         regions = g.MeasureCharacterRanges (String.Empty, font, new RectangleF (), null);
2134                                         Assert.AreEqual (0, regions.Length, "text empty");
2135                                         // null font is ok with null or empty string
2136                                         regions = g.MeasureCharacterRanges (null, null, new RectangleF (), null);
2137                                         Assert.AreEqual (0, regions.Length, "text null/null font");
2138                                         regions = g.MeasureCharacterRanges (String.Empty, null, new RectangleF (), null);
2139                                         Assert.AreEqual (0, regions.Length, "text empty/null font");
2140                                 }
2141                         }
2142                 }
2143
2144                 [Test]
2145                 public void MeasureCharacterRanges_EmptyStringFormat ()
2146                 {
2147                         if (font == null)
2148                                 Assert.Ignore ("Couldn't create required font");
2149
2150                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2151                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2152                                         // string format without character ranges
2153                                         Region[] regions = g.MeasureCharacterRanges ("Mono", font, new RectangleF (), new StringFormat ());
2154                                         Assert.AreEqual (0, regions.Length, "empty stringformat");
2155                                 }
2156                         }
2157                 }
2158
2159                 [Test]
2160                 [ExpectedException (typeof (ArgumentNullException))]
2161                 public void MeasureCharacterRanges_FontNull ()
2162                 {
2163                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2164                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2165                                         g.MeasureCharacterRanges ("a", null, new RectangleF (), null);
2166                                 }
2167                         }
2168                 }
2169
2170                 [Test] // adapted from bug #78777
2171                 public void MeasureCharacterRanges_TwoLines ()
2172                 {
2173                         if (font == null)
2174                                 Assert.Ignore ("Couldn't create required font");
2175
2176                         string text = "this\nis a test";
2177                         CharacterRange[] ranges = new CharacterRange[2];
2178                         ranges[0] = new CharacterRange (0, 5);
2179                         ranges[1] = new CharacterRange (5, 9);
2180
2181                         StringFormat string_format = new StringFormat ();
2182                         string_format.FormatFlags = StringFormatFlags.NoClip;
2183                         string_format.SetMeasurableCharacterRanges (ranges);
2184
2185                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2186                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2187                                         SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2188                                         RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2189                                         Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2190
2191                                         Assert.AreEqual (2, regions.Length, "Length");
2192                                         Assert.AreEqual (regions[0].GetBounds (g).Height, regions[1].GetBounds (g).Height, "Height");
2193                                 }
2194                         }
2195                 }
2196
2197                 private void MeasureCharacterRanges (string text, int first, int length)
2198                 {
2199                         if (font == null)
2200                                 Assert.Ignore ("Couldn't create required font");
2201
2202                         CharacterRange[] ranges = new CharacterRange[1];
2203                         ranges[0] = new CharacterRange (first, length);
2204
2205                         StringFormat string_format = new StringFormat ();
2206                         string_format.FormatFlags = StringFormatFlags.NoClip;
2207                         string_format.SetMeasurableCharacterRanges (ranges);
2208
2209                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2210                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2211                                         SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2212                                         RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2213                                         g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2214                                 }
2215                         }
2216                 }
2217
2218                 [Test]
2219                 [ExpectedException (typeof (ArgumentException))]
2220                 public void MeasureCharacterRanges_FirstTooFar ()
2221                 {
2222                         string text = "this\nis a test";
2223                         MeasureCharacterRanges (text, text.Length, 1);
2224                 }
2225
2226                 [Test]
2227                 [ExpectedException (typeof (ArgumentException))]
2228                 public void MeasureCharacterRanges_LengthTooLong ()
2229                 {
2230                         string text = "this\nis a test";
2231                         MeasureCharacterRanges (text, 0, text.Length + 1);
2232                 }
2233
2234                 [Test]
2235                 public void MeasureCharacterRanges_Prefix ()
2236                 {
2237                         if (font == null)
2238                                 Assert.Ignore ("Couldn't create required font");
2239
2240                         string text = "Hello &Mono::";
2241                         CharacterRange[] ranges = new CharacterRange[1];
2242                         ranges[0] = new CharacterRange (5, 4);
2243
2244                         StringFormat string_format = new StringFormat ();
2245                         string_format.SetMeasurableCharacterRanges (ranges);
2246
2247                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2248                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2249                                         SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2250                                         RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2251
2252                                         // here & is part of the measure and visible
2253                                         string_format.HotkeyPrefix = HotkeyPrefix.None;
2254                                         Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2255                                         RectangleF bounds_none = regions[0].GetBounds (g);
2256
2257                                         // here & is part of the measure (range) but visible as an underline
2258                                         string_format.HotkeyPrefix = HotkeyPrefix.Show;
2259                                         regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2260                                         RectangleF bounds_show = regions[0].GetBounds (g);
2261                                         Assert.IsTrue (bounds_show.Width < bounds_none.Width, "Show<None");
2262
2263                                         // here & is part of the measure (range) but invisible
2264                                         string_format.HotkeyPrefix = HotkeyPrefix.Hide;
2265                                         regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2266                                         RectangleF bounds_hide = regions[0].GetBounds (g);
2267                                         Assert.AreEqual (bounds_hide.Width, bounds_show.Width, "Hide==None");
2268                                 }
2269                         }
2270                 }
2271
2272                 [Test]
2273                 [ExpectedException (typeof (ArgumentException))]
2274                 public void MeasureCharacterRanges_NullStringFormat ()
2275                 {
2276                         if (font == null)
2277                                 Assert.Ignore ("Couldn't create required font");
2278
2279                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2280                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2281                                         g.MeasureCharacterRanges ("Mono", font, new RectangleF (), null);
2282                                 }
2283                         }
2284                 }
2285
2286                 [Test]
2287                 [Category ("NotWorking")]
2288                 public void MeasureCharacterRanges_StringFormat_Alignment ()
2289                 {
2290                         if (font == null)
2291                                 Assert.Ignore ("Couldn't create required font");
2292
2293                         string text = "Hello Mono::";
2294                         CharacterRange[] ranges = new CharacterRange[1];
2295                         ranges[0] = new CharacterRange (5, 4);
2296                         StringFormat string_format = new StringFormat ();
2297                         string_format.SetMeasurableCharacterRanges (ranges);
2298
2299                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2300                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2301                                         string_format.Alignment = StringAlignment.Near;
2302                                         Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2303                                         Assert.AreEqual (1, regions.Length, "Near.Region");
2304                                         RectangleF near = regions[0].GetBounds (g);
2305
2306                                         string_format.Alignment = StringAlignment.Center;
2307                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2308                                         Assert.AreEqual (1, regions.Length, "Center.Region");
2309                                         RectangleF center = regions[0].GetBounds (g);
2310
2311                                         string_format.Alignment = StringAlignment.Far;
2312                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2313                                         Assert.AreEqual (1, regions.Length, "Far.Region");
2314                                         RectangleF far = regions[0].GetBounds (g);
2315
2316                                         Assert.IsTrue (near.X < center.X, "near-center/X");
2317                                         Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
2318                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2319                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2320
2321                                         Assert.IsTrue (center.X < far.X, "center-far/X");
2322                                         Assert.AreEqual (center.Y, far.Y, "center-far/Y");
2323                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2324                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2325                                 }
2326                         }
2327                 }
2328
2329                 [Test]
2330                 [Category ("NotWorking")]
2331                 public void MeasureCharacterRanges_StringFormat_LineAlignment ()
2332                 {
2333                         if (font == null)
2334                                 Assert.Ignore ("Couldn't create required font");
2335
2336                         string text = "Hello Mono::";
2337                         CharacterRange[] ranges = new CharacterRange[1];
2338                         ranges[0] = new CharacterRange (5, 4);
2339                         StringFormat string_format = new StringFormat ();
2340                         string_format.SetMeasurableCharacterRanges (ranges);
2341
2342                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2343                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2344                                         string_format.LineAlignment = StringAlignment.Near;
2345                                         Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2346                                         Assert.AreEqual (1, regions.Length, "Near.Region");
2347                                         RectangleF near = regions[0].GetBounds (g);
2348
2349                                         string_format.LineAlignment = StringAlignment.Center;
2350                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2351                                         Assert.AreEqual (1, regions.Length, "Center.Region");
2352                                         RectangleF center = regions[0].GetBounds (g);
2353
2354                                         string_format.LineAlignment = StringAlignment.Far;
2355                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2356                                         Assert.AreEqual (1, regions.Length, "Far.Region");
2357                                         RectangleF far = regions[0].GetBounds (g);
2358
2359                                         Assert.AreEqual (near.X, center.X, 0.1, "near-center/X");
2360                                         Assert.IsTrue (near.Y < center.Y, "near-center/Y");
2361                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2362                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2363
2364                                         Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
2365                                         Assert.IsTrue (center.Y < far.Y, "center-far/Y");
2366                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2367                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2368                                 }
2369                         }
2370                 }
2371
2372                 [Test]
2373                 [Category ("NotWorking")]
2374                 public void MeasureCharacterRanges_StringFormat_Alignment_DirectionVertical ()
2375                 {
2376                         if (font == null)
2377                                 Assert.Ignore ("Couldn't create required font");
2378
2379                         string text = "Hello Mono::";
2380                         CharacterRange[] ranges = new CharacterRange[1];
2381                         ranges[0] = new CharacterRange (5, 4);
2382                         StringFormat string_format = new StringFormat ();
2383                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2384                         string_format.SetMeasurableCharacterRanges (ranges);
2385
2386                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2387                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2388                                         string_format.Alignment = StringAlignment.Near;
2389                                         Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2390                                         Assert.AreEqual (1, regions.Length, "Near.Region");
2391                                         RectangleF near = regions[0].GetBounds (g);
2392
2393                                         string_format.Alignment = StringAlignment.Center;
2394                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2395                                         Assert.AreEqual (1, regions.Length, "Center.Region");
2396                                         RectangleF center = regions[0].GetBounds (g);
2397
2398                                         string_format.Alignment = StringAlignment.Far;
2399                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2400                                         Assert.AreEqual (1, regions.Length, "Far.Region");
2401                                         RectangleF far = regions[0].GetBounds (g);
2402
2403                                         Assert.IsTrue (near.X == center.X, "near-center/X"); // ???
2404                                         Assert.IsTrue (near.Y < center.Y, "near-center/Y");
2405                                         Assert.IsTrue (near.Width == center.Width, "near-center/Width"); // ???
2406                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2407
2408                                         Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
2409                                         Assert.IsTrue (center.Y < far.Y, "center-far/Y");
2410                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2411                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2412                                 }
2413                         }
2414                 }
2415
2416                 [Test]
2417                 [Category ("NotWorking")]
2418                 public void MeasureCharacterRanges_StringFormat_LineAlignment_DirectionVertical ()
2419                 {
2420                         if (font == null)
2421                                 Assert.Ignore ("Couldn't create required font");
2422
2423                         string text = "Hello Mono::";
2424                         CharacterRange[] ranges = new CharacterRange[1];
2425                         ranges[0] = new CharacterRange (5, 4);
2426                         StringFormat string_format = new StringFormat ();
2427                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2428                         string_format.SetMeasurableCharacterRanges (ranges);
2429
2430                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2431                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2432                                         string_format.LineAlignment = StringAlignment.Near;
2433                                         Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2434                                         Assert.AreEqual (1, regions.Length, "Near.Region");
2435                                         RectangleF near = regions[0].GetBounds (g);
2436
2437                                         string_format.LineAlignment = StringAlignment.Center;
2438                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2439                                         Assert.AreEqual (1, regions.Length, "Center.Region");
2440                                         RectangleF center = regions[0].GetBounds (g);
2441
2442                                         string_format.LineAlignment = StringAlignment.Far;
2443                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2444                                         Assert.AreEqual (1, regions.Length, "Far.Region");
2445                                         RectangleF far = regions[0].GetBounds (g);
2446
2447                                         Assert.IsTrue (near.X < center.X, "near-center/X");
2448                                         Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
2449                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2450                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2451
2452                                         Assert.IsTrue (center.X < far.X, "center-far/X");
2453                                         Assert.AreEqual (center.Y, far.Y, 0.1, "center-far/Y");
2454                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2455                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2456                                 }
2457                         }
2458                 }
2459
2460                 static CharacterRange [] ranges = new CharacterRange [] {
2461                     new CharacterRange (0, 1),
2462                     new CharacterRange (1, 1),
2463                     new CharacterRange (2, 1)
2464                 };
2465
2466                 Region [] Measure (Graphics gfx, RectangleF rect)
2467                 {
2468                         using (StringFormat format = StringFormat.GenericTypographic) {
2469                                 format.SetMeasurableCharacterRanges (ranges);
2470
2471                                 using (Font font = new Font (FontFamily.GenericSerif, 11.0f)) {
2472                                         return gfx.MeasureCharacterRanges ("abc", font, rect, format);
2473                                 }
2474                         }
2475                 }
2476
2477                 [Test]
2478                 public void Measure ()
2479                 {
2480                         using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
2481                                 Region [] zero = Measure (gfx, new RectangleF (0, 0, 0, 0));
2482                                 Assert.AreEqual (3, zero.Length, "zero.Length");
2483
2484                                 Region [] small = Measure (gfx, new RectangleF (0, 0, 100, 100));
2485                                 Assert.AreEqual (3, small.Length, "small.Length");
2486                                 for (int i = 0; i < 3; i++ ) {
2487                                         RectangleF zb = zero [i].GetBounds (gfx);
2488                                         RectangleF sb = small [i].GetBounds (gfx);
2489                                         Assert.AreEqual (sb.X, zb.X, "sx" + i.ToString ());
2490                                         Assert.AreEqual (sb.Y, zb.Y, "sy" + i.ToString ());
2491                                         Assert.AreEqual (sb.Width, zb.Width, "sw" + i.ToString ());
2492                                         Assert.AreEqual (sb.Height, zb.Height, "sh" + i.ToString ());
2493                                 }
2494
2495                                 Region [] max = Measure (gfx, new RectangleF (0, 0, Single.MaxValue, Single.MaxValue));
2496                                 Assert.AreEqual (3, max.Length, "empty.Length");
2497                                 for (int i = 0; i < 3; i++) {
2498                                         RectangleF zb = zero [i].GetBounds (gfx);
2499                                         RectangleF mb = max [i].GetBounds (gfx);
2500                                         Assert.AreEqual (mb.X, zb.X, "mx" + i.ToString ());
2501                                         Assert.AreEqual (mb.Y, zb.Y, "my" + i.ToString ());
2502                                         Assert.AreEqual (mb.Width, zb.Width, "mw" + i.ToString ());
2503                                         Assert.AreEqual (mb.Height, zb.Height, "mh" + i.ToString ());
2504                                 }
2505                         }
2506                 }
2507
2508                 [Test]
2509                 public void MeasureLimits ()
2510                 {
2511                         using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
2512                                 Region [] min = Measure (gfx, new RectangleF (0, 0, Single.MinValue, Single.MinValue));
2513                                 Assert.AreEqual (3, min.Length, "origin.Length");
2514                                 for (int i = 0; i < 3; i++) {
2515                                         RectangleF mb = min [i].GetBounds (gfx);
2516                                         Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
2517                                         Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
2518                                         Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
2519                                         Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
2520                                 }
2521
2522                                 Region [] neg = Measure (gfx, new RectangleF (0, 0, -20, -20));
2523                                 Assert.AreEqual (3, neg.Length, "neg.Length");
2524                                 for (int i = 0; i < 3; i++) {
2525                                         RectangleF mb = neg [i].GetBounds (gfx);
2526                                         Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
2527                                         Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
2528                                         Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
2529                                         Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
2530                                 }
2531                         }
2532                 }
2533
2534                 [Test]
2535                 public void DrawString_EndlessLoop_Bug77699 ()
2536                 {
2537                         if (font == null)
2538                                 Assert.Ignore ("Couldn't create required font");
2539
2540                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2541                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2542                                         Rectangle rect = Rectangle.Empty;
2543                                         rect.Location = new Point (10, 10);
2544                                         rect.Size = new Size (1, 20);
2545                                         StringFormat fmt = new StringFormat ();
2546                                         fmt.Alignment = StringAlignment.Center;
2547                                         fmt.LineAlignment = StringAlignment.Center;
2548                                         fmt.FormatFlags = StringFormatFlags.NoWrap;
2549                                         fmt.Trimming = StringTrimming.EllipsisWord;
2550                                         g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
2551                                 }
2552                         }
2553                 }
2554
2555                 [Test]
2556                 public void DrawString_EndlessLoop_Wrapping ()
2557                 {
2558                         if (font == null)
2559                                 Assert.Ignore ("Couldn't create required font");
2560
2561                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2562                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2563                                         Rectangle rect = Rectangle.Empty;
2564                                         rect.Location = new Point (10, 10);
2565                                         rect.Size = new Size (1, 20);
2566                                         StringFormat fmt = new StringFormat ();
2567                                         fmt.Alignment = StringAlignment.Center;
2568                                         fmt.LineAlignment = StringAlignment.Center;
2569                                         fmt.Trimming = StringTrimming.EllipsisWord;
2570                                         g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
2571                                 }
2572                         }
2573                 }
2574
2575                 [Test]
2576                 public void MeasureString_Wrapping_Dots ()
2577                 {
2578                         HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_Wrapping_Dots");
2579
2580                         if (font == null)
2581                                 Assert.Ignore ("Couldn't create required font");
2582
2583                         string text = "this is really long text........................................... with a lot o periods.";
2584                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2585                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2586                                         using (StringFormat format = new StringFormat ()) {
2587                                                 format.Alignment = StringAlignment.Center;
2588                                                 SizeF sz = g.MeasureString (text, font, 80, format);
2589                                                 Assert.IsTrue (sz.Width < 80, "Width");
2590                                                 Assert.IsTrue (sz.Height > font.Height * 2, "Height");
2591                                         }
2592                                 }
2593                         }
2594                 }
2595
2596                 [Test]
2597                 public void GetReleaseHdcInternal ()
2598                 {
2599                         using (Bitmap b = new Bitmap (10, 10)) {
2600                                 using (Graphics g = Graphics.FromImage (b)) {
2601                                         IntPtr hdc1 = g.GetHdc ();
2602                                         g.ReleaseHdcInternal (hdc1);
2603                                         IntPtr hdc2 = g.GetHdc ();
2604                                         g.ReleaseHdcInternal (hdc2);
2605                                         Assert.AreEqual (hdc1, hdc2, "hdc");
2606                                 }
2607                         }
2608                 }
2609
2610                 [Test]
2611                 [ExpectedException (typeof (ArgumentException))]
2612                 public void ReleaseHdcInternal_IntPtrZero ()
2613                 {
2614                         using (Bitmap b = new Bitmap (10, 10)) {
2615                                 using (Graphics g = Graphics.FromImage (b)) {
2616                                         g.ReleaseHdcInternal (IntPtr.Zero);
2617                                 }
2618                         }
2619                 }
2620
2621                 [Test]
2622                 [ExpectedException (typeof (ArgumentException))]
2623                 public void ReleaseHdcInternal_TwoTimes ()
2624                 {
2625                         using (Bitmap b = new Bitmap (10, 10)) {
2626                                 using (Graphics g = Graphics.FromImage (b)) {
2627                                         IntPtr hdc = g.GetHdc ();
2628                                         g.ReleaseHdcInternal (hdc);
2629                                         g.ReleaseHdcInternal (hdc);
2630                                 }
2631                         }
2632                 }
2633                 [Test]
2634                 public void TestReleaseHdc ()
2635                 {
2636                         using (Bitmap b = new Bitmap (10, 10)) {
2637                                 using (Graphics g = Graphics.FromImage (b)) {
2638                                         IntPtr hdc1 = g.GetHdc ();
2639                                         g.ReleaseHdc ();
2640                                         IntPtr hdc2 = g.GetHdc ();
2641                                         g.ReleaseHdc ();
2642                                         Assert.AreEqual (hdc1, hdc2, "hdc");
2643                                 }
2644                         }
2645                 }
2646
2647                 [Test]
2648                 [ExpectedException (typeof (ArgumentException))]
2649                 public void TestReleaseHdcException ()
2650                 {
2651                         using (Bitmap b = new Bitmap (10, 10)) {
2652                                 using (Graphics g = Graphics.FromImage (b)) {
2653                                         g.ReleaseHdc ();
2654                                 }
2655                         }
2656                 }
2657
2658                 [Test]
2659                 [ExpectedException (typeof (ArgumentException))]
2660                 public void TestReleaseHdcException2 ()
2661                 {
2662                         using (Bitmap b = new Bitmap (10, 10)) {
2663                                 using (Graphics g = Graphics.FromImage (b)) {
2664                                         g.GetHdc ();
2665                                         g.ReleaseHdc ();
2666                                         g.ReleaseHdc ();
2667                                 }
2668                         }
2669                 }
2670                 [Test]
2671                 public void VisibleClipBound ()
2672                 {
2673                         // see #78958
2674                         using (Bitmap bmp = new Bitmap (100, 100)) {
2675                                 using (Graphics g = Graphics.FromImage (bmp)) {
2676                                         RectangleF noclip = g.VisibleClipBounds;
2677                                         Assert.AreEqual (0, noclip.X, "noclip.X");
2678                                         Assert.AreEqual (0, noclip.Y, "noclip.Y");
2679                                         Assert.AreEqual (100, noclip.Width, "noclip.Width");
2680                                         Assert.AreEqual (100, noclip.Height, "noclip.Height");
2681
2682                                         // note: libgdiplus regions are precise to multiple of multiple of 8
2683                                         g.Clip = new Region (new RectangleF (0, 0, 32, 32));
2684                                         RectangleF clip = g.VisibleClipBounds;
2685                                         Assert.AreEqual (0, clip.X, "clip.X");
2686                                         Assert.AreEqual (0, clip.Y, "clip.Y");
2687                                         Assert.AreEqual (32, clip.Width, "clip.Width");
2688                                         Assert.AreEqual (32, clip.Height, "clip.Height");
2689
2690                                         g.RotateTransform (90);
2691                                         RectangleF rotclip = g.VisibleClipBounds;
2692                                         Assert.AreEqual (0, rotclip.X, "rotclip.X");
2693                                         Assert.AreEqual (-32, rotclip.Y, "rotclip.Y");
2694                                         Assert.AreEqual (32, rotclip.Width, "rotclip.Width");
2695                                         Assert.AreEqual (32, rotclip.Height, "rotclip.Height");
2696                                 }
2697                         }
2698                 }
2699
2700                 [Test]
2701                 public void VisibleClipBound_BigClip ()
2702                 {
2703                         using (Bitmap bmp = new Bitmap (100, 100)) {
2704                                 using (Graphics g = Graphics.FromImage (bmp)) {
2705                                         RectangleF noclip = g.VisibleClipBounds;
2706                                         Assert.AreEqual (0, noclip.X, "noclip.X");
2707                                         Assert.AreEqual (0, noclip.Y, "noclip.Y");
2708                                         Assert.AreEqual (100, noclip.Width, "noclip.Width");
2709                                         Assert.AreEqual (100, noclip.Height, "noclip.Height");
2710
2711                                         // clip is larger than bitmap
2712                                         g.Clip = new Region (new RectangleF (0, 0, 200, 200));
2713                                         RectangleF clipbound = g.ClipBounds;
2714                                         Assert.AreEqual (0, clipbound.X, "clipbound.X");
2715                                         Assert.AreEqual (0, clipbound.Y, "clipbound.Y");
2716                                         Assert.AreEqual (200, clipbound.Width, "clipbound.Width");
2717                                         Assert.AreEqual (200, clipbound.Height, "clipbound.Height");
2718
2719                                         RectangleF clip = g.VisibleClipBounds;
2720                                         Assert.AreEqual (0, clip.X, "clip.X");
2721                                         Assert.AreEqual (0, clip.Y, "clip.Y");
2722                                         Assert.AreEqual (100, clip.Width, "clip.Width");
2723                                         Assert.AreEqual (100, clip.Height, "clip.Height");
2724
2725                                         g.RotateTransform (90);
2726                                         RectangleF rotclipbound = g.ClipBounds;
2727                                         Assert.AreEqual (0, rotclipbound.X, "rotclipbound.X");
2728                                         Assert.AreEqual (-200, rotclipbound.Y, "rotclipbound.Y");
2729                                         Assert.AreEqual (200, rotclipbound.Width, "rotclipbound.Width");
2730                                         Assert.AreEqual (200, rotclipbound.Height, "rotclipbound.Height");
2731
2732                                         RectangleF rotclip = g.VisibleClipBounds;
2733                                         Assert.AreEqual (0, rotclip.X, "rotclip.X");
2734                                         Assert.AreEqual (-100, rotclip.Y, "rotclip.Y");
2735                                         Assert.AreEqual (100, rotclip.Width, "rotclip.Width");
2736                                         Assert.AreEqual (100, rotclip.Height, "rotclip.Height");
2737                                 }
2738                         }
2739                 }
2740
2741                 [Test]
2742                 public void Rotate ()
2743                 {
2744                         using (Bitmap bmp = new Bitmap (100, 50)) {
2745                                 using (Graphics g = Graphics.FromImage (bmp)) {
2746                                         RectangleF vcb = g.VisibleClipBounds;
2747                                         Assert.AreEqual (0, vcb.X, "vcb.X");
2748                                         Assert.AreEqual (0, vcb.Y, "vcb.Y");
2749                                         Assert.AreEqual (100, vcb.Width, "vcb.Width");
2750                                         Assert.AreEqual (50, vcb.Height, "vcb.Height");
2751
2752                                         g.RotateTransform (90);
2753                                         RectangleF rvcb = g.VisibleClipBounds;
2754                                         Assert.AreEqual (0, rvcb.X, "rvcb.X");
2755                                         Assert.AreEqual (-100, rvcb.Y, "rvcb.Y");
2756                                         Assert.AreEqual (50.0f, rvcb.Width, 0.0001, "rvcb.Width");
2757                                         Assert.AreEqual (100, rvcb.Height, "rvcb.Height");
2758                                 }
2759                         }
2760                 }
2761
2762                 [Test]
2763                 public void Scale ()
2764                 {
2765                         using (Bitmap bmp = new Bitmap (100, 50)) {
2766                                 using (Graphics g = Graphics.FromImage (bmp)) {
2767                                         RectangleF vcb = g.VisibleClipBounds;
2768                                         Assert.AreEqual (0, vcb.X, "vcb.X");
2769                                         Assert.AreEqual (0, vcb.Y, "vcb.Y");
2770                                         Assert.AreEqual (100, vcb.Width, "vcb.Width");
2771                                         Assert.AreEqual (50, vcb.Height, "vcb.Height");
2772
2773                                         g.ScaleTransform (2, 0.5f);
2774                                         RectangleF svcb = g.VisibleClipBounds;
2775                                         Assert.AreEqual (0, svcb.X, "svcb.X");
2776                                         Assert.AreEqual (0, svcb.Y, "svcb.Y");
2777                                         Assert.AreEqual (50, svcb.Width, "svcb.Width");
2778                                         Assert.AreEqual (100, svcb.Height, "svcb.Height");
2779                                 }
2780                         }
2781                 }
2782
2783                 [Test]
2784                 public void Translate ()
2785                 {
2786                         using (Bitmap bmp = new Bitmap (100, 50)) {
2787                                 using (Graphics g = Graphics.FromImage (bmp)) {
2788                                         RectangleF vcb = g.VisibleClipBounds;
2789                                         Assert.AreEqual (0, vcb.X, "vcb.X");
2790                                         Assert.AreEqual (0, vcb.Y, "vcb.Y");
2791                                         Assert.AreEqual (100, vcb.Width, "vcb.Width");
2792                                         Assert.AreEqual (50, vcb.Height, "vcb.Height");
2793
2794                                         g.TranslateTransform (-25, 25);
2795                                         RectangleF tvcb = g.VisibleClipBounds;
2796                                         Assert.AreEqual (25, tvcb.X, "tvcb.X");
2797                                         Assert.AreEqual (-25, tvcb.Y, "tvcb.Y");
2798                                         Assert.AreEqual (100, tvcb.Width, "tvcb.Width");
2799                                         Assert.AreEqual (50, tvcb.Height, "tvcb.Height");
2800                                 }
2801                         }
2802                 }
2803
2804                 [Test]
2805                 [ExpectedException (typeof (ArgumentNullException))]
2806                 public void DrawIcon_NullRectangle ()
2807                 {
2808                         using (Bitmap bmp = new Bitmap (40, 40)) {
2809                                 using (Graphics g = Graphics.FromImage (bmp)) {
2810                                         g.DrawIcon (null, new Rectangle (0, 0, 32, 32));
2811                                 }
2812                         }
2813                 }
2814
2815                 [Test]
2816                 public void DrawIcon_IconRectangle ()
2817                 {
2818                         using (Bitmap bmp = new Bitmap (40, 40)) {
2819                                 using (Graphics g = Graphics.FromImage (bmp)) {
2820                                         g.DrawIcon (SystemIcons.Application, new Rectangle (0, 0, 40, 20));
2821                                         // Rectangle is empty when X, Y, Width and Height == 0 
2822                                         // (yep X and Y too, RectangleF only checks for Width and Height)
2823                                         g.DrawIcon (SystemIcons.Asterisk, new Rectangle (0, 0, 0, 0));
2824                                         // so this one is half-empty ;-)
2825                                         g.DrawIcon (SystemIcons.Error, new Rectangle (20, 40, 0, 0));
2826                                         // negative width or height isn't empty (for Rectangle)
2827                                         g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
2828                                         g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
2829                                 }
2830                         }
2831                 }
2832
2833                 [Test]
2834                 [ExpectedException (typeof (ArgumentNullException))]
2835                 public void DrawIcon_NullIntInt ()
2836                 {
2837                         using (Bitmap bmp = new Bitmap (40, 40)) {
2838                                 using (Graphics g = Graphics.FromImage (bmp)) {
2839                                         g.DrawIcon (null, 4, 2);
2840                                 }
2841                         }
2842                 }
2843
2844                 [Test]
2845                 public void DrawIcon_IconIntInt ()
2846                 {
2847                         using (Bitmap bmp = new Bitmap (40, 40)) {
2848                                 using (Graphics g = Graphics.FromImage (bmp)) {
2849                                         g.DrawIcon (SystemIcons.Exclamation, 4, 2);
2850                                         g.DrawIcon (SystemIcons.Hand, 0, 0);
2851                                 }
2852                         }
2853                 }
2854
2855                 [Test]
2856                 [ExpectedException (typeof (ArgumentNullException))]
2857                 public void DrawIconUnstretched_NullRectangle ()
2858                 {
2859                         using (Bitmap bmp = new Bitmap (40, 40)) {
2860                                 using (Graphics g = Graphics.FromImage (bmp)) {
2861                                         g.DrawIconUnstretched (null, new Rectangle (0, 0, 40, 20));
2862                                 }
2863                         }
2864                 }
2865
2866                 [Test]
2867                 public void DrawIconUnstretched_IconRectangle ()
2868                 {
2869                         using (Bitmap bmp = new Bitmap (40, 40)) {
2870                                 using (Graphics g = Graphics.FromImage (bmp)) {
2871                                         g.DrawIconUnstretched (SystemIcons.Information, new Rectangle (0, 0, 40, 20));
2872                                         // Rectangle is empty when X, Y, Width and Height == 0 
2873                                         // (yep X and Y too, RectangleF only checks for Width and Height)
2874                                         g.DrawIconUnstretched (SystemIcons.Question, new Rectangle (0, 0, 0, 0));
2875                                         // so this one is half-empty ;-)
2876                                         g.DrawIconUnstretched (SystemIcons.Warning, new Rectangle (20, 40, 0, 0));
2877                                         // negative width or height isn't empty (for Rectangle)
2878                                         g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
2879                                         g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
2880                                 }
2881                         }
2882                 }
2883
2884                 [Test]
2885                 [ExpectedException (typeof (ArgumentNullException))]
2886                 public void DrawImage_NullRectangleF ()
2887                 {
2888                         using (Bitmap bmp = new Bitmap (40, 40)) {
2889                                 using (Graphics g = Graphics.FromImage (bmp)) {
2890                                         g.DrawImage (null, new RectangleF (0, 0, 0, 0));
2891                                 }
2892                         }
2893                 }
2894
2895                 [Test]
2896                 public void DrawImage_ImageRectangleF ()
2897                 {
2898                         using (Bitmap bmp = new Bitmap (40, 40)) {
2899                                 using (Graphics g = Graphics.FromImage (bmp)) {
2900                                         g.DrawImage (bmp, new RectangleF (0, 0, 0, 0));
2901                                         g.DrawImage (bmp, new RectangleF (20, 40, 0, 0));
2902                                         g.DrawImage (bmp, new RectangleF (10, 20, -1, 0));
2903                                         g.DrawImage (bmp, new RectangleF (20, 10, 0, -1));
2904                                 }
2905                         }
2906                 }
2907
2908                 [Test]
2909                 [ExpectedException (typeof (ArgumentNullException))]
2910                 public void DrawImage_NullPointF ()
2911                 {
2912                         using (Bitmap bmp = new Bitmap (40, 40)) {
2913                                 using (Graphics g = Graphics.FromImage (bmp)) {
2914                                         g.DrawImage (null, new PointF (0, 0));
2915                                 }
2916                         }
2917                 }
2918
2919                 [Test]
2920                 public void DrawImage_ImagePointF ()
2921                 {
2922                         using (Bitmap bmp = new Bitmap (40, 40)) {
2923                                 using (Graphics g = Graphics.FromImage (bmp)) {
2924                                         g.DrawImage (bmp, new PointF (0, 0));
2925                                 }
2926                         }
2927                 }
2928
2929                 [Test]
2930                 [ExpectedException (typeof (ArgumentNullException))]
2931                 public void DrawImage_NullPointFArray ()
2932                 {
2933                         using (Bitmap bmp = new Bitmap (40, 40)) {
2934                                 using (Graphics g = Graphics.FromImage (bmp)) {
2935                                         g.DrawImage (null, new PointF[0]);
2936                                 }
2937                         }
2938                 }
2939
2940                 [Test]
2941                 [ExpectedException (typeof (ArgumentNullException))]
2942                 public void DrawImage_ImagePointFArrayNull ()
2943                 {
2944                         using (Bitmap bmp = new Bitmap (40, 40)) {
2945                                 using (Graphics g = Graphics.FromImage (bmp)) {
2946                                         g.DrawImage (bmp, (PointF[]) null);
2947                                 }
2948                         }
2949                 }
2950
2951                 [Test]
2952                 [ExpectedException (typeof (ArgumentException))]
2953                 public void DrawImage_ImagePointFArrayEmpty ()
2954                 {
2955                         using (Bitmap bmp = new Bitmap (40, 40)) {
2956                                 using (Graphics g = Graphics.FromImage (bmp)) {
2957                                         g.DrawImage (bmp, new PointF[0]);
2958                                 }
2959                         }
2960                 }
2961
2962                 [Test]
2963                 public void DrawImage_ImagePointFArray ()
2964                 {
2965                         using (Bitmap bmp = new Bitmap (40, 40)) {
2966                                 using (Graphics g = Graphics.FromImage (bmp)) {
2967                                         g.DrawImage (bmp, new PointF[] { 
2968                                                 new PointF (0, 0), new PointF (1, 1), new PointF (2, 2) });
2969                                 }
2970                         }
2971                 }
2972
2973                 [Test]
2974                 [ExpectedException (typeof (ArgumentNullException))]
2975                 public void DrawImage_NullRectangle ()
2976                 {
2977                         using (Bitmap bmp = new Bitmap (40, 40)) {
2978                                 using (Graphics g = Graphics.FromImage (bmp)) {
2979                                         g.DrawImage (null, new Rectangle (0, 0, 0, 0));
2980                                 }
2981                         }
2982                 }
2983
2984                 [Test]
2985                 public void DrawImage_ImageRectangle ()
2986                 {
2987                         using (Bitmap bmp = new Bitmap (40, 40)) {
2988                                 using (Graphics g = Graphics.FromImage (bmp)) {
2989                                         // Rectangle is empty when X, Y, Width and Height == 0 
2990                                         // (yep X and Y too, RectangleF only checks for Width and Height)
2991                                         g.DrawImage (bmp, new Rectangle (0, 0, 0, 0));
2992                                         // so this one is half-empty ;-)
2993                                         g.DrawImage (bmp, new Rectangle (20, 40, 0, 0));
2994                                         // negative width or height isn't empty (for Rectangle)
2995                                         g.DrawImage (bmp, new Rectangle (10, 20, -1, 0));
2996                                         g.DrawImage (bmp, new Rectangle (20, 10, 0, -1));
2997                                 }
2998                         }
2999                 }
3000
3001                 [Test]
3002                 [ExpectedException (typeof (ArgumentNullException))]
3003                 public void DrawImage_NullPoint ()
3004                 {
3005                         using (Bitmap bmp = new Bitmap (40, 40)) {
3006                                 using (Graphics g = Graphics.FromImage (bmp)) {
3007                                         g.DrawImage (null, new Point (0, 0));
3008                                 }
3009                         }
3010                 }
3011
3012                 [Test]
3013                 public void DrawImage_ImagePoint ()
3014                 {
3015                         using (Bitmap bmp = new Bitmap (40, 40)) {
3016                                 using (Graphics g = Graphics.FromImage (bmp)) {
3017                                         g.DrawImage (bmp, new Point (0, 0));
3018                                 }
3019                         }
3020                 }
3021
3022                 [Test]
3023                 [ExpectedException (typeof (ArgumentNullException))]
3024                 public void DrawImage_NullPointArray ()
3025                 {
3026                         using (Bitmap bmp = new Bitmap (40, 40)) {
3027                                 using (Graphics g = Graphics.FromImage (bmp)) {
3028                                         g.DrawImage (null, new Point[0]);
3029                                 }
3030                         }
3031                 }
3032
3033                 [Test]
3034                 [ExpectedException (typeof (ArgumentNullException))]
3035                 public void DrawImage_ImagePointArrayNull ()
3036                 {
3037                         using (Bitmap bmp = new Bitmap (40, 40)) {
3038                                 using (Graphics g = Graphics.FromImage (bmp)) {
3039                                         g.DrawImage (bmp, (Point[]) null);
3040                                 }
3041                         }
3042                 }
3043
3044                 [Test]
3045                 [ExpectedException (typeof (ArgumentException))]
3046                 public void DrawImage_ImagePointArrayEmpty ()
3047                 {
3048                         using (Bitmap bmp = new Bitmap (40, 40)) {
3049                                 using (Graphics g = Graphics.FromImage (bmp)) {
3050                                         g.DrawImage (bmp, new Point[0]);
3051                                 }
3052                         }
3053                 }
3054
3055                 [Test]
3056                 public void DrawImage_ImagePointArray ()
3057                 {
3058                         using (Bitmap bmp = new Bitmap (40, 40)) {
3059                                 using (Graphics g = Graphics.FromImage (bmp)) {
3060                                         g.DrawImage (bmp, new Point[] { 
3061                                                 new Point (0, 0), new Point (1, 1), new Point (2, 2) });
3062                                 }
3063                         }
3064                 }
3065
3066                 [Test]
3067                 [ExpectedException (typeof (ArgumentNullException))]
3068                 public void DrawImage_NullIntInt ()
3069                 {
3070                         using (Bitmap bmp = new Bitmap (40, 40)) {
3071                                 using (Graphics g = Graphics.FromImage (bmp)) {
3072                                         g.DrawImage (null, Int32.MaxValue, Int32.MinValue);
3073                                 }
3074                         }
3075                 }
3076
3077                 [Test]
3078                 [ExpectedException (typeof (OverflowException))]
3079                 public void DrawImage_ImageIntInt_Overflow ()
3080                 {
3081                         using (Bitmap bmp = new Bitmap (40, 40)) {
3082                                 using (Graphics g = Graphics.FromImage (bmp)) {
3083                                         g.DrawImage (bmp, Int32.MaxValue, Int32.MinValue);
3084                                 }
3085                         }
3086                 }
3087
3088                 [Test]
3089                 public void DrawImage_ImageIntInt ()
3090                 {
3091                         using (Bitmap bmp = new Bitmap (40, 40)) {
3092                                 using (Graphics g = Graphics.FromImage (bmp)) {
3093                                         g.DrawImage (bmp, -40, -40);
3094                                 }
3095                         }
3096                 }
3097
3098                 [Test]
3099                 [ExpectedException (typeof (ArgumentNullException))]
3100                 public void DrawImage_NullFloat ()
3101                 {
3102                         using (Bitmap bmp = new Bitmap (40, 40)) {
3103                                 using (Graphics g = Graphics.FromImage (bmp)) {
3104                                         g.DrawImage (null, Single.MaxValue, Single.MinValue);
3105                                 }
3106                         }
3107                 }
3108
3109                 [Test]
3110                 [ExpectedException (typeof (OverflowException))]
3111                 public void DrawImage_ImageFloatFloat_Overflow ()
3112                 {
3113                         using (Bitmap bmp = new Bitmap (40, 40)) {
3114                                 using (Graphics g = Graphics.FromImage (bmp)) {
3115                                         g.DrawImage (bmp, Single.MaxValue, Single.MinValue);
3116                                 }
3117                         }
3118                 }
3119
3120                 [Test]
3121                 public void DrawImage_ImageFloatFloat ()
3122                 {
3123                         using (Bitmap bmp = new Bitmap (40, 40)) {
3124                                 using (Graphics g = Graphics.FromImage (bmp)) {
3125                                         g.DrawImage (bmp, -40.0f, -40.0f);
3126                                 }
3127                         }
3128                 }
3129
3130                 [Test]
3131                 [ExpectedException (typeof (ArgumentNullException))]
3132                 public void DrawImage_NullRectangleRectangleGraphicsUnit ()
3133                 {
3134                         using (Bitmap bmp = new Bitmap (40, 40)) {
3135                                 using (Graphics g = Graphics.FromImage (bmp)) {
3136                                         g.DrawImage (null, new Rectangle (), new Rectangle (), GraphicsUnit.Display);
3137                                 }
3138                         }
3139                 }
3140
3141                 private void DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit unit)
3142                 {
3143                         using (Bitmap bmp = new Bitmap (40, 40)) {
3144                                 using (Graphics g = Graphics.FromImage (bmp)) {
3145                                         Rectangle r = new Rectangle (0, 0, 40, 40);
3146                                         g.DrawImage (bmp, r, r, unit);
3147                                 }
3148                         }
3149                 }
3150
3151                 [Test]
3152                 [ExpectedException (typeof (ArgumentException))]
3153                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Display ()
3154                 {
3155                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Display);
3156                 }
3157
3158                 [Test]
3159                 [ExpectedException (typeof (NotImplementedException))]
3160                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Document ()
3161                 {
3162                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Document);
3163                 }
3164
3165                 [Test]
3166                 [ExpectedException (typeof (NotImplementedException))]
3167                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Inch ()
3168                 {
3169                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Inch);
3170                 }
3171
3172                 [Test]
3173                 [ExpectedException (typeof (NotImplementedException))]
3174                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Millimeter ()
3175                 {
3176                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Millimeter);
3177                 }
3178
3179                 [Test]
3180                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Pixel ()
3181                 {
3182                         // this unit works
3183                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Pixel);
3184                 }
3185
3186                 [Test]
3187                 [ExpectedException (typeof (NotImplementedException))]
3188                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Point ()
3189                 {
3190                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Point);
3191                 }
3192
3193                 [Test]
3194                 [ExpectedException (typeof (ArgumentException))]
3195                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_World ()
3196                 {
3197                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.World);
3198                 }
3199
3200                 [Test]
3201                 [ExpectedException (typeof (ArgumentNullException))]
3202                 public void DrawImage_NullPointRectangleGraphicsUnit ()
3203                 {
3204                         Rectangle r = new Rectangle (1, 2, 3, 4);
3205                         Point[] pts = new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) };
3206                         using (Bitmap bmp = new Bitmap (40, 40)) {
3207                                 using (Graphics g = Graphics.FromImage (bmp)) {
3208                                         g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
3209                                 }
3210                         }
3211                 }
3212
3213                 private void DrawImage_ImagePointRectangleGraphicsUnit (Point[] pts)
3214                 {
3215                         Rectangle r = new Rectangle (1, 2, 3, 4);
3216                         using (Bitmap bmp = new Bitmap (40, 40)) {
3217                                 using (Graphics g = Graphics.FromImage (bmp)) {
3218                                         g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
3219                                 }
3220                         }
3221                 }
3222
3223                 [Test]
3224                 [ExpectedException (typeof (ArgumentNullException))]
3225                 public void DrawImage_ImageNullRectangleGraphicsUnit ()
3226                 {
3227                         DrawImage_ImagePointRectangleGraphicsUnit (null);
3228                 }
3229
3230                 [Test]
3231                 [ExpectedException (typeof (ArgumentException))]
3232                 public void DrawImage_ImagePoint0RectangleGraphicsUnit ()
3233                 {
3234                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[0]);
3235                 }
3236
3237                 [Test]
3238                 [ExpectedException (typeof (ArgumentException))]
3239                 public void DrawImage_ImagePoint1RectangleGraphicsUnit ()
3240                 {
3241                         Point p = new Point (1, 1);
3242                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[1] { p });
3243                 }
3244
3245                 [Test]
3246                 [ExpectedException (typeof (ArgumentException))]
3247                 public void DrawImage_ImagePoint2RectangleGraphicsUnit ()
3248                 {
3249                         Point p = new Point (1, 1);
3250                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[2] { p, p });
3251                 }
3252
3253                 [Test]
3254                 public void DrawImage_ImagePoint3RectangleGraphicsUnit ()
3255                 {
3256                         Point p = new Point (1, 1);
3257                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[3] { p, p, p });
3258                 }
3259
3260                 [Test]
3261                 [ExpectedException (typeof (NotImplementedException))]
3262                 public void DrawImage_ImagePoint4RectangleGraphicsUnit ()
3263                 {
3264                         Point p = new Point (1, 1);
3265                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[4] { p, p, p, p });
3266                 }
3267
3268                 [Test]
3269                 [ExpectedException (typeof (ArgumentNullException))]
3270                 public void DrawImage_NullPointFRectangleGraphicsUnit ()
3271                 {
3272                         Rectangle r = new Rectangle (1, 2, 3, 4);
3273                         PointF[] pts = new PointF[3] { new PointF (1, 1), new PointF (2, 2), new PointF (3, 3) };
3274                         using (Bitmap bmp = new Bitmap (40, 40)) {
3275                                 using (Graphics g = Graphics.FromImage (bmp)) {
3276                                         g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
3277                                 }
3278                         }
3279                 }
3280
3281                 private void DrawImage_ImagePointFRectangleGraphicsUnit (PointF[] pts)
3282                 {
3283                         Rectangle r = new Rectangle (1, 2, 3, 4);
3284                         using (Bitmap bmp = new Bitmap (40, 40)) {
3285                                 using (Graphics g = Graphics.FromImage (bmp)) {
3286                                         g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
3287                                 }
3288                         }
3289                 }
3290
3291                 [Test]
3292                 [ExpectedException (typeof (ArgumentNullException))]
3293                 public void DrawImage_ImageNullFRectangleGraphicsUnit ()
3294                 {
3295                         DrawImage_ImagePointFRectangleGraphicsUnit (null);
3296                 }
3297
3298                 [Test]
3299                 [ExpectedException (typeof (ArgumentException))]
3300                 public void DrawImage_ImagePointF0RectangleGraphicsUnit ()
3301                 {
3302                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[0]);
3303                 }
3304
3305                 [Test]
3306                 [ExpectedException (typeof (ArgumentException))]
3307                 public void DrawImage_ImagePointF1RectangleGraphicsUnit ()
3308                 {
3309                         PointF p = new PointF (1, 1);
3310                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[1] { p });
3311                 }
3312
3313                 [Test]
3314                 [ExpectedException (typeof (ArgumentException))]
3315                 public void DrawImage_ImagePointF2RectangleGraphicsUnit ()
3316                 {
3317                         PointF p = new PointF (1, 1);
3318                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[2] { p, p });
3319                 }
3320
3321                 [Test]
3322                 public void DrawImage_ImagePointF3RectangleGraphicsUnit ()
3323                 {
3324                         PointF p = new PointF (1, 1);
3325                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[3] { p, p, p });
3326                 }
3327
3328                 [Test]
3329                 [ExpectedException (typeof (NotImplementedException))]
3330                 public void DrawImage_ImagePointF4RectangleGraphicsUnit ()
3331                 {
3332                         PointF p = new PointF (1, 1);
3333                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[4] { p, p, p, p });
3334                 }
3335
3336                 [Test]
3337                 public void DrawImage_ImagePointRectangleGraphicsUnitNull ()
3338                 {
3339                         Point p = new Point (1, 1);
3340                         Point[] pts = new Point[3] { p, p, p };
3341                         Rectangle r = new Rectangle (1, 2, 3, 4);
3342                         using (Bitmap bmp = new Bitmap (40, 40)) {
3343                                 using (Graphics g = Graphics.FromImage (bmp)) {
3344                                         g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, null);
3345                                 }
3346                         }
3347                 }
3348
3349                 [Test]
3350                 public void DrawImage_ImagePointRectangleGraphicsUnitAttributes ()
3351                 {
3352                         Point p = new Point (1, 1);
3353                         Point[] pts = new Point[3] { p, p, p };
3354                         Rectangle r = new Rectangle (1, 2, 3, 4);
3355                         using (Bitmap bmp = new Bitmap (40, 40)) {
3356                                 using (Graphics g = Graphics.FromImage (bmp)) {
3357                                         ImageAttributes ia = new ImageAttributes ();
3358                                         g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, ia);
3359                                 }
3360                         }
3361                 }
3362
3363                 [Test]
3364                 [ExpectedException (typeof (ArgumentNullException))]
3365                 public void DrawImageUnscaled_NullPoint ()
3366                 {
3367                         using (Bitmap bmp = new Bitmap (40, 40)) {
3368                                 using (Graphics g = Graphics.FromImage (bmp)) {
3369                                         g.DrawImageUnscaled (null, new Point (0, 0));
3370                                 }
3371                         }
3372                 }
3373
3374                 [Test]
3375                 public void DrawImageUnscaled_ImagePoint ()
3376                 {
3377                         using (Bitmap bmp = new Bitmap (40, 40)) {
3378                                 using (Graphics g = Graphics.FromImage (bmp)) {
3379                                         g.DrawImageUnscaled (bmp, new Point (0, 0));
3380                                 }
3381                         }
3382                 }
3383
3384                 [Test]
3385                 [ExpectedException (typeof (ArgumentNullException))]
3386                 public void DrawImageUnscaled_NullRectangle ()
3387                 {
3388                         using (Bitmap bmp = new Bitmap (40, 40)) {
3389                                 using (Graphics g = Graphics.FromImage (bmp)) {
3390                                         g.DrawImageUnscaled (null, new Rectangle (0, 0, -1, -1));
3391                                 }
3392                         }
3393                 }
3394
3395                 [Test]
3396                 public void DrawImageUnscaled_ImageRectangle ()
3397                 {
3398                         using (Bitmap bmp = new Bitmap (40, 40)) {
3399                                 using (Graphics g = Graphics.FromImage (bmp)) {
3400                                         g.DrawImageUnscaled (bmp, new Rectangle (0, 0, -1, -1));
3401                                 }
3402                         }
3403                 }
3404
3405                 [Test]
3406                 [ExpectedException (typeof (ArgumentNullException))]
3407                 public void DrawImageUnscaled_NullIntInt ()
3408                 {
3409                         using (Bitmap bmp = new Bitmap (40, 40)) {
3410                                 using (Graphics g = Graphics.FromImage (bmp)) {
3411                                         g.DrawImageUnscaled (null, 0, 0);
3412                                 }
3413                         }
3414                 }
3415
3416                 [Test]
3417                 public void DrawImageUnscaled_ImageIntInt ()
3418                 {
3419                         using (Bitmap bmp = new Bitmap (40, 40)) {
3420                                 using (Graphics g = Graphics.FromImage (bmp)) {
3421                                         g.DrawImageUnscaled (bmp, 0, 0);
3422                                 }
3423                         }
3424                 }
3425
3426                 [Test]
3427                 [ExpectedException (typeof (ArgumentNullException))]
3428                 public void DrawImageUnscaled_NullIntIntIntInt ()
3429                 {
3430                         using (Bitmap bmp = new Bitmap (40, 40)) {
3431                                 using (Graphics g = Graphics.FromImage (bmp)) {
3432                                         g.DrawImageUnscaled (null, 0, 0, -1, -1);
3433                                 }
3434                         }
3435                 }
3436
3437                 [Test]
3438                 public void DrawImageUnscaled_ImageIntIntIntInt ()
3439                 {
3440                         using (Bitmap bmp = new Bitmap (40, 40)) {
3441                                 using (Graphics g = Graphics.FromImage (bmp)) {
3442                                         g.DrawImageUnscaled (bmp, 0, 0, -1, -1);
3443                                 }
3444                         }
3445                 }
3446                 [Test]
3447                 [ExpectedException (typeof (ArgumentNullException))]
3448                 public void DrawImageUnscaledAndClipped_Null ()
3449                 {
3450                         using (Bitmap bmp = new Bitmap (40, 40)) {
3451                                 using (Graphics g = Graphics.FromImage (bmp)) {
3452                                         g.DrawImageUnscaledAndClipped (null, new Rectangle (0, 0, 0, 0));
3453                                 }
3454                         }
3455                 }
3456
3457                 [Test]
3458                 public void DrawImageUnscaledAndClipped ()
3459                 {
3460                         using (Bitmap bmp = new Bitmap (40, 40)) {
3461                                 using (Graphics g = Graphics.FromImage (bmp)) {
3462                                         // Rectangle is empty when X, Y, Width and Height == 0 
3463                                         // (yep X and Y too, RectangleF only checks for Width and Height)
3464                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 0, 0));
3465                                         // so this one is half-empty ;-)
3466                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 40, 0, 0));
3467                                         // negative width or height isn't empty (for Rectangle)
3468                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (10, 20, -1, 0));
3469                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 10, 0, -1));
3470                                         // smaller
3471                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 10, 20));
3472                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 40, 10));
3473                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 80, 20));
3474                                 }
3475                         }
3476                 }
3477
3478                 [Test]
3479                 [ExpectedException (typeof (ArgumentNullException))]
3480                 public void DrawPath_Pen_Null ()
3481                 {
3482                         using (Bitmap bmp = new Bitmap (20, 20)) {
3483                                 using (Graphics g = Graphics.FromImage (bmp)) {
3484                                         using (GraphicsPath path = new GraphicsPath ()) {
3485                                                 g.DrawPath (null, path);
3486                                         }
3487                                 }
3488                         }
3489                 }
3490
3491                 [Test]
3492                 [ExpectedException (typeof (ArgumentNullException))]
3493                 public void DrawPath_Path_Null ()
3494                 {
3495                         using (Bitmap bmp = new Bitmap (20, 20)) {
3496                                 using (Graphics g = Graphics.FromImage (bmp)) {
3497                                         g.DrawPath (Pens.Black, null);
3498                                 }
3499                         }
3500                 }
3501
3502                 [Test]
3503                 public void DrawPath_82202 ()
3504                 {
3505                         // based on test case from bug #82202
3506                         using (Bitmap bmp = new Bitmap (20, 20)) {
3507                                 using (Graphics g = Graphics.FromImage (bmp)) {
3508                                         using (GraphicsPath path = new GraphicsPath ()) {
3509                                                 int d = 5;
3510                                                 Rectangle baserect = new Rectangle (0, 0, 19, 19);
3511                                                 Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
3512
3513                                                 path.AddArc (arcrect, 180, 90);
3514                                                 arcrect.X = baserect.Right - d;
3515                                                 path.AddArc (arcrect, 270, 90);
3516                                                 arcrect.Y = baserect.Bottom - d;
3517                                                 path.AddArc (arcrect, 0, 90);
3518                                                 arcrect.X = baserect.Left;
3519                                                 path.AddArc (arcrect, 90, 90);
3520                                                 path.CloseFigure ();
3521                                                 g.Clear (Color.White);
3522                                                 g.DrawPath (Pens.SteelBlue, path);
3523
3524                                                 Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
3525                                                 Assert.AreEqual (-1, bmp.GetPixel (1, 9).ToArgb (), "1,9");
3526                                         }
3527                                 }
3528                         }
3529                 }
3530
3531                 [Test]
3532                 [ExpectedException (typeof (ArgumentNullException))]
3533                 public void FillPath_Brush_Null ()
3534                 {
3535                         using (Bitmap bmp = new Bitmap (20, 20)) {
3536                                 using (Graphics g = Graphics.FromImage (bmp)) {
3537                                         using (GraphicsPath path = new GraphicsPath ()) {
3538                                                 g.FillPath (null, path);
3539                                         }
3540                                 }
3541                         }
3542                 }
3543
3544                 [Test]
3545                 [ExpectedException (typeof (ArgumentNullException))]
3546                 public void FillPath_Path_Null ()
3547                 {
3548                         using (Bitmap bmp = new Bitmap (20, 20)) {
3549                                 using (Graphics g = Graphics.FromImage (bmp)) {
3550                                         g.FillPath (Brushes.Black, null);
3551                                 }
3552                         }
3553                 }
3554
3555                 [Test]
3556                 public void FillPath_82202 ()
3557                 {
3558                         // based on test case from bug #82202
3559                         using (Bitmap bmp = new Bitmap (20, 20)) {
3560                                 using (Graphics g = Graphics.FromImage (bmp)) {
3561                                         using (GraphicsPath path = new GraphicsPath ()) {
3562                                                 int d = 5;
3563                                                 Rectangle baserect = new Rectangle (0, 0, 19, 19);
3564                                                 Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
3565
3566                                                 path.AddArc (arcrect, 180, 90);
3567                                                 arcrect.X = baserect.Right - d;
3568                                                 path.AddArc (arcrect, 270, 90);
3569                                                 arcrect.Y = baserect.Bottom - d;
3570                                                 path.AddArc (arcrect, 0, 90);
3571                                                 arcrect.X = baserect.Left;
3572                                                 path.AddArc (arcrect, 90, 90);
3573                                                 path.CloseFigure ();
3574                                                 g.Clear (Color.White);
3575                                                 g.FillPath (Brushes.SteelBlue, path);
3576
3577                                                 Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
3578                                                 Assert.AreEqual (-12156236, bmp.GetPixel (1, 9).ToArgb (), "1,9");
3579                                         }
3580                                 }
3581                         }
3582                 }
3583
3584                 [Test]
3585                 public void TransformPoints_349800 ()
3586                 {
3587                         using (Bitmap bmp = new Bitmap (10, 10)) {
3588                                 using (Graphics g = Graphics.FromImage (bmp)) {
3589                                         Point [] pts = new Point [5];
3590                                         PointF [] ptf = new PointF [5];
3591                                         for (int i = 0; i < 5; i++) {
3592                                                 pts [i] = new Point (i, i);
3593                                                 ptf [i] = new PointF (i, i);
3594                                         }
3595
3596                                         g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, pts);
3597                                         g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, ptf);
3598
3599                                         for (int i = 0; i < 5; i++) {
3600                                                 Assert.AreEqual (i, pts [i].X, "Point.X " + i.ToString ());
3601                                                 Assert.AreEqual (i, pts [i].Y, "Point.Y " + i.ToString ());
3602                                                 Assert.AreEqual (i, ptf [i].X, "PointF.X " + i.ToString ());
3603                                                 Assert.AreEqual (i, ptf [i].Y, "PointF.Y " + i.ToString ());
3604                                         }
3605                                 }
3606                         }
3607                 }
3608
3609                 [Test]
3610                 public void Dpi_556181 ()
3611                 {
3612                         float x, y;
3613                         using (Bitmap bmp = new Bitmap (10, 10)) {
3614                                 using (Graphics g = Graphics.FromImage (bmp)) {
3615                                         x = g.DpiX - 10;
3616                                         y = g.DpiY + 10;
3617                                 }
3618                                 bmp.SetResolution (x, y);
3619                                 using (Graphics g = Graphics.FromImage (bmp)) {
3620                                         Assert.AreEqual (x, g.DpiX, "DpiX");
3621                                         Assert.AreEqual (y, g.DpiY, "DpiY");
3622                                 }
3623                         }
3624                 }
3625         }
3626
3627         [TestFixture]
3628         public class GraphicsFullTrustTest {
3629
3630                 // note: this test would fail, on ReleaseHdc, without fulltrust
3631                 // i.e. it's a demand and not a linkdemand
3632                 [Test]
3633                 public void GetReleaseHdc ()
3634                 {
3635                         using (Bitmap b = new Bitmap (100, 100)) {
3636                                 using (Graphics g = Graphics.FromImage (b)) {
3637                                         IntPtr hdc1 = g.GetHdc ();
3638                                         g.ReleaseHdc (hdc1);
3639                                         IntPtr hdc2 = g.GetHdc ();
3640                                         g.ReleaseHdc (hdc2);
3641                                         Assert.AreEqual (hdc1, hdc2, "hdc");
3642                                 }
3643                         }
3644                 }
3645
3646         }
3647 }