Merge pull request #484 from roji/transactions_pspe
[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 #if NET_2_0
1240                 [ExpectedException (typeof (ArgumentNullException))]
1241 #else
1242                 [ExpectedException (typeof (NullReferenceException))]
1243 #endif
1244                 public void EndContainer_Null ()
1245                 {
1246                         Bitmap bitmap = new Bitmap (20, 20);
1247                         Graphics g = Graphics.FromImage (bitmap);
1248                         g.EndContainer (null);
1249                 }
1250
1251                 [Test]
1252                 public void Save ()
1253                 {
1254                         Bitmap bitmap = new Bitmap (20, 20);
1255                         Graphics g = Graphics.FromImage (bitmap);
1256
1257                         CheckDefaultProperties ("default", g);
1258                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "default.RenderingOrigin");
1259
1260                         GraphicsState gs1 = g.Save ();
1261                         // nothing is changed after a save
1262                         CheckDefaultProperties ("save1", g);
1263                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "save1.RenderingOrigin");
1264
1265                         g.Clip = new Region (new Rectangle (10, 10, 10, 10));
1266                         g.CompositingMode = CompositingMode.SourceCopy;
1267                         g.CompositingQuality = CompositingQuality.HighQuality;
1268                         g.InterpolationMode = InterpolationMode.HighQualityBicubic;
1269                         g.PageScale = 0.5f;
1270                         g.PageUnit = GraphicsUnit.Inch;
1271                         g.PixelOffsetMode = PixelOffsetMode.Half;
1272                         g.RenderingOrigin = new Point (-1, -1);
1273                         g.RotateTransform (45);
1274                         g.SmoothingMode = SmoothingMode.AntiAlias;
1275                         g.TextContrast = 0;
1276                         g.TextRenderingHint = TextRenderingHint.AntiAlias;
1277                         CheckCustomProperties ("modified", g);
1278                         CheckMatrix ("modified.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1279
1280                         GraphicsState gs2 = g.Save ();
1281                         CheckCustomProperties ("save2", g);
1282
1283                         g.Restore (gs2);
1284                         CheckCustomProperties ("restored1", g);
1285                         CheckMatrix ("restored1.Transform", g.Transform, 0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
1286
1287                         g.Restore (gs1);
1288                         CheckDefaultProperties ("restored2", g);
1289                         Assert.AreEqual (new Point (0, 0), g.RenderingOrigin, "restored2.RenderingOrigin");
1290                 }
1291
1292                 [Test]
1293                 [ExpectedException (typeof (NullReferenceException))]
1294                 public void Restore_Null ()
1295                 {
1296                         Bitmap bitmap = new Bitmap (20, 20);
1297                         Graphics g = Graphics.FromImage (bitmap);
1298                         g.Restore (null);
1299                 }
1300
1301                 [Test]
1302                 [ExpectedException (typeof (ArgumentNullException))]
1303                 public void FillRectangles_BrushNull_Rectangle ()
1304                 {
1305                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1306                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1307                                         g.FillRectangles (null, new Rectangle[1]);
1308                                 }
1309                         }
1310                 }
1311
1312                 [Test]
1313                 [ExpectedException (typeof (ArgumentNullException))]
1314                 public void FillRectangles_Rectangle_Null ()
1315                 {
1316                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1317                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1318                                         g.FillRectangles (Brushes.Red, (Rectangle[]) null);
1319                                 }
1320                         }
1321                 }
1322
1323                 [Test] // see bug #78408
1324                 [ExpectedException (typeof (ArgumentException))]
1325                 public void FillRectanglesZeroRectangle ()
1326                 {
1327                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1328                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1329                                         g.FillRectangles (Brushes.Red, new Rectangle[0]);
1330                                 }
1331                         }
1332                 }
1333
1334                 [Test]
1335                 [ExpectedException (typeof (ArgumentNullException))]
1336                 public void FillRectangles_BrushNull_RectangleF ()
1337                 {
1338                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1339                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1340                                         g.FillRectangles (null, new RectangleF[1]);
1341                                 }
1342                         }
1343                 }
1344
1345                 [Test]
1346                 [ExpectedException (typeof (ArgumentNullException))]
1347                 public void FillRectangles_RectangleF_Null ()
1348                 {
1349                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1350                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1351                                         g.FillRectangles (Brushes.Red, (RectangleF[]) null);
1352                                 }
1353                         }
1354                 }
1355
1356                 [Test] // see bug #78408
1357                 [ExpectedException (typeof (ArgumentException))]
1358                 public void FillRectanglesZeroRectangleF ()
1359                 {
1360                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1361                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1362                                         g.FillRectangles (Brushes.Red, new RectangleF[0]);
1363                                 }
1364                         }
1365                 }
1366
1367                 [Test]
1368                 public void FillRectangles_NormalBehavior ()
1369                 {
1370                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1371                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1372                                         g.Clear (Color.Fuchsia);
1373                                         Rectangle rect = new Rectangle (5, 5, 10, 10);
1374                                         g.Clip = new Region (rect);
1375                                         g.FillRectangle (Brushes.Red, rect);
1376                                 }
1377                                 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1378                                 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1379                                 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (5, 14).ToArgb (), "5,14");
1380                                 Assert.AreEqual (Color.Red.ToArgb (), bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1381
1382                                 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1383                                 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1384                                 Assert.AreEqual (Color.Fuchsia.ToArgb (), bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1385                         }
1386                 }
1387
1388                 // see bug #81737 for details
1389                 private Bitmap FillDrawRectangle (float width)
1390                 {
1391                         Bitmap bitmap = new Bitmap (20, 20);
1392                         using (Graphics g = Graphics.FromImage (bitmap)) {
1393                                 g.Clear (Color.Red);
1394                                 Rectangle rect = new Rectangle (5, 5, 10, 10);
1395                                 g.FillRectangle (Brushes.Green, rect);
1396                                 if (width >= 0) {
1397                                         using (Pen pen = new Pen (Color.Blue, width)) {
1398                                                 g.DrawRectangle (pen, rect);
1399                                         }
1400                                 } else {
1401                                         g.DrawRectangle (Pens.Blue, rect);
1402                                 }
1403                         }
1404                         return bitmap;
1405                 }
1406
1407                 [Test]
1408                 public void FillDrawRectangle_Width_Default ()
1409                 {
1410                         // default pen size
1411                         using (Bitmap bitmap = FillDrawRectangle (Single.MinValue)) {
1412                                 // NW
1413                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1414                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1415                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1416                                 // N
1417                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1418                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1419                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1420                                 // NE
1421                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1422                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1423                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1424                                 // E
1425                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1426                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1427                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1428                                 // SE
1429                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1430                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1431                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1432                                 // S
1433                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1434                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1435                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1436                                 // SW
1437                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1438                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1439                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1440                                 // W
1441                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1442                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1443                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1444                         }
1445                 }
1446
1447                 [Test]
1448                 [Category ("NotOnMac")]
1449                 public void FillDrawRectangle_Width_2 ()
1450                 {
1451                         // even pen size
1452                         using (Bitmap bitmap = FillDrawRectangle (2.0f)) {
1453                                 // NW
1454                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1455                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1456                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1457                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1458                                 // N
1459                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1460                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1461                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1462                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1463                                 // NE
1464                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1465                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1466                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1467                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1468                                 // E
1469                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1470                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1471                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1472                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
1473                                 // SE
1474                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1475                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1476                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1477                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
1478                                 // S
1479                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1480                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1481                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1482                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
1483                                 // SW
1484                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "3,16");
1485                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "4,15");
1486                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 14).ToArgb (), "5,14");
1487                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 13).ToArgb (), "6,13");
1488                                 // W
1489                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1490                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1491                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1492                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1493                         }
1494                 }
1495
1496                 [Test]
1497                 public void FillDrawRectangle_Width_3 ()
1498                 {
1499                         // odd pen size
1500                         using (Bitmap bitmap = FillDrawRectangle (3.0f)) {
1501                                 // NW
1502                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1503                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1504                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1505                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1506                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 7).ToArgb (), "7,7");
1507                                 // N
1508                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1509                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1510                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1511                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1512                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 7).ToArgb (), "9,7");
1513                                 // NE
1514                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1515                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1516                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1517                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1518                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
1519                                 // E
1520                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
1521                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1522                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1523                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1524                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 9).ToArgb (), "13,9");
1525                                 // SE
1526                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
1527                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1528                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1529                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1530                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (13, 13).ToArgb (), "13,13");
1531                                 // S
1532                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
1533                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1534                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1535                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1536                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 13).ToArgb (), "9,13");
1537                                 // SW
1538                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
1539                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1540                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1541                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1542                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 13).ToArgb (), "7,13");
1543                                 // W
1544                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1545                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1546                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1547                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1548                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (7, 9).ToArgb (), "7,9");
1549                         }
1550                 }
1551
1552                 // reverse, draw the fill over
1553                 private Bitmap DrawFillRectangle (float width)
1554                 {
1555                         Bitmap bitmap = new Bitmap (20, 20);
1556                         using (Graphics g = Graphics.FromImage (bitmap)) {
1557                                 g.Clear (Color.Red);
1558                                 Rectangle rect = new Rectangle (5, 5, 10, 10);
1559                                 if (width >= 0) {
1560                                         using (Pen pen = new Pen (Color.Blue, width)) {
1561                                                 g.DrawRectangle (pen, rect);
1562                                         }
1563                                 } else {
1564                                         g.DrawRectangle (Pens.Blue, rect);
1565                                 }
1566                                 g.FillRectangle (Brushes.Green, rect);
1567                         }
1568                         return bitmap;
1569                 }
1570
1571                 [Test]
1572                 public void DrawFillRectangle_Width_Default ()
1573                 {
1574                         // default pen size
1575                         using (Bitmap bitmap = DrawFillRectangle (Single.MinValue)) {
1576                                 // NW - no blue border
1577                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1578                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1579                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 6).ToArgb (), "6,6");
1580                                 // N - no blue border
1581                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1582                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1583                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 6).ToArgb (), "9,6");
1584                                 // NE
1585                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1586                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1587                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1588                                 // E
1589                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1590                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1591                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1592                                 // SE
1593                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1594                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1595                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1596                                 // S
1597                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1598                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1599                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1600                                 // SW
1601                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1602                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1603                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1604                                 // W - no blue border
1605                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1606                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1607                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 9).ToArgb (), "6,9");
1608                         }
1609                 }
1610
1611                 [Test]
1612                 [Category ("NotOnMac")]
1613                 public void DrawFillRectangle_Width_2 ()
1614                 {
1615                         // even pen size
1616                         using (Bitmap bitmap = DrawFillRectangle (2.0f)) {
1617                                 // looks like a one pixel border - but enlarged
1618                                 // NW
1619                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1620                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1621                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1622                                 // N
1623                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1624                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1625                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1626                                 // NE
1627                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1628                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1629                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1630                                 // E
1631                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1632                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1633                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1634                                 // SE
1635                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1636                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1637                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1638                                 // S
1639                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1640                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1641                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1642                                 // SW
1643                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 16).ToArgb (), "4,16");
1644                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 15).ToArgb (), "5,15");
1645                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 14).ToArgb (), "6,14");
1646                                 // W
1647                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1648                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1649                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1650                         }
1651                 }
1652
1653                 [Test]
1654                 public void DrawFillRectangle_Width_3 ()
1655                 {
1656                         // odd pen size
1657                         using (Bitmap bitmap = DrawFillRectangle (3.0f)) {
1658                                 // NW
1659                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 3).ToArgb (), "3,3");
1660                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1661                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1662                                 // N
1663                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 3).ToArgb (), "9,3");
1664                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 4).ToArgb (), "9,4");
1665                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 5).ToArgb (), "9,5");
1666                                 // NE
1667                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1668                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1669                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1670                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1671                                 // E
1672                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 9).ToArgb (), "17,9");
1673                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 9).ToArgb (), "16,9");
1674                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 9).ToArgb (), "15,9");
1675                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 9).ToArgb (), "14,9");
1676                                 // SE
1677                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 17).ToArgb (), "17,17");
1678                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1679                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1680                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1681                                 // S
1682                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (9, 17).ToArgb (), "9,17");
1683                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 16).ToArgb (), "9,16");
1684                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (9, 15).ToArgb (), "9,15");
1685                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (9, 14).ToArgb (), "9,14");
1686                                 // SW
1687                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 17).ToArgb (), "3,17");
1688                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 16).ToArgb (), "4,16");
1689                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 15).ToArgb (), "5,15");
1690                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (6, 14).ToArgb (), "6,14");
1691                                 // W
1692                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (3, 9).ToArgb (), "3,9");
1693                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (4, 9).ToArgb (), "4,9");
1694                                 Assert.AreEqual (0xFF008000, (uint) bitmap.GetPixel (5, 9).ToArgb (), "5,9");
1695                         }
1696                 }
1697
1698                 private Bitmap DrawLines (float width)
1699                 {
1700                         Bitmap bitmap = new Bitmap (20, 20);
1701                         using (Graphics g = Graphics.FromImage (bitmap)) {
1702                                 g.Clear (Color.Red);
1703                                 Point[] pts = new Point[3] { new Point (5, 5), new Point (15, 5), new Point (15, 15) };
1704                                 if (width >= 0) {
1705                                         using (Pen pen = new Pen (Color.Blue, width)) {
1706                                                 g.DrawLines (pen, pts);
1707                                         }
1708                                 } else {
1709                                         g.DrawLines (Pens.Blue, pts);
1710                                 }
1711                         }
1712                         return bitmap;
1713                 }
1714
1715                 [Test]
1716                 public void DrawLines_Width_Default ()
1717                 {
1718                         // default pen size
1719                         using (Bitmap bitmap = DrawLines (Single.MinValue)) {
1720                                 // start
1721                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1722                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1723                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1724                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1725                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1726                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1727                                 // middle
1728                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1729                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1730                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1731                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1732                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1733                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1734                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1735                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1736                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1737                                 //end
1738                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1739                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1740                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1741                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 16).ToArgb (), "14,16");
1742                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 16).ToArgb (), "15,16");
1743                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 16).ToArgb (), "16,16");
1744                         }
1745                 }
1746
1747                 [Test]
1748                 [Category ("NotWorking")]
1749                 public void DrawLines_Width_2 ()
1750                 {
1751                         // default pen size
1752                         using (Bitmap bitmap = DrawLines (2.0f)) {
1753                                 // start
1754                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
1755                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1756                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1757                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1758                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
1759                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1760                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1761                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1762                                 // middle
1763                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
1764                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
1765                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
1766                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1767                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
1768                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1769                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1770                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1771                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
1772                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1773                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1774                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1775                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1776                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1777                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1778                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1779                                 //end
1780                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
1781                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1782                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
1783                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
1784                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
1785                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1786                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1787                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1788                         }
1789                 }
1790
1791                 [Test]
1792                 [Category ("NotWorking")]
1793                 public void DrawLines_Width_3 ()
1794                 {
1795                         // default pen size
1796                         using (Bitmap bitmap = DrawLines (3.0f)) {
1797                                 // start
1798                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 3).ToArgb (), "4,3");
1799                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 4).ToArgb (), "4,4");
1800                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 5).ToArgb (), "4,5");
1801                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 6).ToArgb (), "4,6");
1802                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (4, 7).ToArgb (), "4,7");
1803                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 3).ToArgb (), "5,3");
1804                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 4).ToArgb (), "5,4");
1805                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 5).ToArgb (), "5,5");
1806                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (5, 6).ToArgb (), "5,6");
1807                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (5, 7).ToArgb (), "5,7");
1808                                 // middle
1809                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 3).ToArgb (), "13,3");
1810                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 4).ToArgb (), "13,4");
1811                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 5).ToArgb (), "13,5");
1812                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (13, 6).ToArgb (), "13,6");
1813                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 7).ToArgb (), "13,7");
1814                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 3).ToArgb (), "14,3");
1815                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 4).ToArgb (), "14,4");
1816                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 5).ToArgb (), "14,5");
1817                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 6).ToArgb (), "14,6");
1818                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 7).ToArgb (), "14,7");
1819                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 3).ToArgb (), "15,3");
1820                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 4).ToArgb (), "15,4");
1821                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 5).ToArgb (), "15,5");
1822                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 6).ToArgb (), "15,6");
1823                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 7).ToArgb (), "15,7");
1824                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 3).ToArgb (), "16,3");
1825                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 4).ToArgb (), "16,4");
1826                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 5).ToArgb (), "16,5");
1827                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 6).ToArgb (), "16,6");
1828                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 7).ToArgb (), "16,7");
1829                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 3).ToArgb (), "17,3");
1830                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 4).ToArgb (), "17,4");
1831                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 5).ToArgb (), "17,5");
1832                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 6).ToArgb (), "17,6");
1833                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 7).ToArgb (), "17,7");
1834                                 //end
1835                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 14).ToArgb (), "13,14");
1836                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (14, 14).ToArgb (), "14,14");
1837                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (15, 14).ToArgb (), "15,14");
1838                                 Assert.AreEqual (0xFF0000FF, (uint) bitmap.GetPixel (16, 14).ToArgb (), "16,14");
1839                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 14).ToArgb (), "17,14");
1840                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (13, 15).ToArgb (), "13,15");
1841                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (14, 15).ToArgb (), "14,15");
1842                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (15, 15).ToArgb (), "15,15");
1843                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (16, 15).ToArgb (), "16,15");
1844                                 Assert.AreEqual (0xFFFF0000, (uint) bitmap.GetPixel (17, 15).ToArgb (), "17,15");
1845                         }
1846                 }
1847
1848                 [Test]
1849                 public void MeasureString_StringFont ()
1850                 {
1851                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1852                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1853                                         SizeF size = g.MeasureString (null, font);
1854                                         Assert.IsTrue (size.IsEmpty, "MeasureString(null,font)");
1855                                         size = g.MeasureString (String.Empty, font);
1856                                         Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font)");
1857                                         // null font
1858                                         size = g.MeasureString (null, null);
1859                                         Assert.IsTrue (size.IsEmpty, "MeasureString(null,null)");
1860                                         size = g.MeasureString (String.Empty, null);
1861                                         Assert.IsTrue (size.IsEmpty, "MeasureString(empty,null)");
1862                                 }
1863                         }
1864                 }
1865
1866                 [Test]
1867                 [ExpectedException (typeof (ArgumentNullException))]
1868                 public void MeasureString_StringFont_Null ()
1869                 {
1870                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1871                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1872                                         g.MeasureString ("a", null);
1873                                 }
1874                         }
1875                 }
1876
1877                 [Test]
1878                 public void MeasureString_StringFontSizeF ()
1879                 {
1880                         if (font == null)
1881                                 Assert.Ignore ("Couldn't create required font");
1882
1883                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1884                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1885                                         SizeF size = g.MeasureString ("a", font, SizeF.Empty);
1886                                         Assert.IsFalse (size.IsEmpty, "MeasureString(a,font,empty)");
1887
1888                                         size = g.MeasureString (String.Empty, font, SizeF.Empty);
1889                                         Assert.IsTrue (size.IsEmpty, "MeasureString(empty,font,empty)");
1890                                 }
1891                         }
1892                 }
1893
1894                 private void MeasureString_StringFontInt (string s)
1895                 {
1896                         if (font == null)
1897                                 Assert.Ignore ("Couldn't create required font");
1898
1899                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1900                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1901                                         SizeF size0 = g.MeasureString (s, font, 0);
1902                                         SizeF sizeN = g.MeasureString (s, font, Int32.MinValue);
1903                                         SizeF sizeP = g.MeasureString (s, font, Int32.MaxValue);
1904                                         Assert.AreEqual (size0, sizeN, "0-Min");
1905                                         Assert.AreEqual (size0, sizeP, "0-Max");
1906                                 }
1907                         }
1908                 }
1909
1910                 [Test]
1911                 public void MeasureString_StringFontInt_ShortString ()
1912                 {
1913                         MeasureString_StringFontInt ("a");
1914                 }
1915
1916                 [Test]
1917                 public void MeasureString_StringFontInt_LongString ()
1918                 {
1919                         HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_StringFontInt_LongString");
1920                         MeasureString_StringFontInt ("A very long string..."); // see bug #79643
1921                 }
1922
1923                 [Test]
1924                 public void MeasureString_StringFormat_Alignment ()
1925                 {
1926                         if (font == null)
1927                                 Assert.Ignore ("Couldn't create required font");
1928
1929                         string text = "Hello Mono::";
1930                         StringFormat string_format = new StringFormat ();
1931
1932                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1933                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1934                                         string_format.Alignment = StringAlignment.Near;
1935                                         SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1936
1937                                         string_format.Alignment = StringAlignment.Center;
1938                                         SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1939
1940                                         string_format.Alignment = StringAlignment.Far;
1941                                         SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1942
1943                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1944                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
1945
1946                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
1947                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
1948                                 }
1949                         }
1950                 }
1951
1952                 [Test]
1953                 public void MeasureString_StringFormat_Alignment_DirectionVertical ()
1954                 {
1955                         if (font == null)
1956                                 Assert.Ignore ("Couldn't create required font");
1957
1958                         string text = "Hello Mono::";
1959                         StringFormat string_format = new StringFormat ();
1960                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1961
1962                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1963                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1964                                         string_format.Alignment = StringAlignment.Near;
1965                                         SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1966
1967                                         string_format.Alignment = StringAlignment.Center;
1968                                         SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1969
1970                                         string_format.Alignment = StringAlignment.Far;
1971                                         SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
1972
1973                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
1974                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
1975
1976                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
1977                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
1978                                 }
1979                         }
1980                 }
1981
1982                 [Test]
1983                 public void MeasureString_StringFormat_LineAlignment ()
1984                 {
1985                         if (font == null)
1986                                 Assert.Ignore ("Couldn't create required font");
1987
1988                         string text = "Hello Mono::";
1989                         StringFormat string_format = new StringFormat ();
1990
1991                         using (Bitmap bitmap = new Bitmap (20, 20)) {
1992                                 using (Graphics g = Graphics.FromImage (bitmap)) {
1993                                         string_format.LineAlignment = StringAlignment.Near;
1994                                         SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
1995
1996                                         string_format.LineAlignment = StringAlignment.Center;
1997                                         SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
1998
1999                                         string_format.LineAlignment = StringAlignment.Far;
2000                                         SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
2001
2002                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2003                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2004
2005                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2006                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2007                                 }
2008                         }
2009                 }
2010
2011                 [Test]
2012                 public void MeasureString_StringFormat_LineAlignment_DirectionVertical ()
2013                 {
2014                         if (font == null)
2015                                 Assert.Ignore ("Couldn't create required font");
2016
2017                         string text = "Hello Mono::";
2018                         StringFormat string_format = new StringFormat ();
2019                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2020
2021                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2022                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2023                                         string_format.LineAlignment = StringAlignment.Near;
2024                                         SizeF near = g.MeasureString (text, font, Int32.MaxValue, string_format);
2025
2026                                         string_format.LineAlignment = StringAlignment.Center;
2027                                         SizeF center = g.MeasureString (text, font, Int32.MaxValue, string_format);
2028
2029                                         string_format.LineAlignment = StringAlignment.Far;
2030                                         SizeF far = g.MeasureString (text, font, Int32.MaxValue, string_format);
2031
2032                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2033                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2034
2035                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2036                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2037                                 }
2038                         }
2039                 }
2040
2041                 [Test]
2042                 public void MeasureString_MultlineString_Width ()
2043                 {
2044                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2045                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2046                                         StringFormat string_format = new StringFormat ();
2047
2048                                         string text1 = "Test\nTest123\nTest 456\nTest 1,2,3,4,5...";
2049                                         string text2 = "Test 1,2,3,4,5...";
2050
2051                                         SizeF size1 = g.MeasureString (text1, font, SizeF.Empty, string_format);
2052                                         SizeF size2 = g.MeasureString (text2, font, SizeF.Empty, string_format);
2053
2054                                         Assert.AreEqual ((int) size1.Width, (int) size2.Width, "Multiline Text Width");
2055                                 }
2056                         }
2057                 }
2058
2059                 [Test]
2060                 public void MeasureString_Bug76664 ()
2061                 {
2062                         if (font == null)
2063                                 Assert.Ignore ("Couldn't create required font");
2064
2065                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2066                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2067                                         string s = "aaa aa aaaa a aaa";
2068                                         SizeF size = g.MeasureString (s, font);
2069
2070                                         int chars, lines;
2071                                         SizeF size2 = g.MeasureString (s, font, new SizeF (80, size.Height), null, out chars, out lines);
2072
2073                                         // in pixels
2074                                         Assert.IsTrue (size2.Width < size.Width, "Width/pixel");
2075                                         Assert.AreEqual (size2.Height, size.Height, "Height/pixel");
2076
2077                                         Assert.AreEqual (1, lines, "lines fitted");
2078                                         // LAMESPEC: documentation seems to suggest chars is total length
2079                                         Assert.IsTrue (chars < s.Length, "characters fitted");
2080                                 }
2081                         }
2082                 }
2083
2084                 [Test]
2085                 public void MeasureString_Bug80680 ()
2086                 {
2087                         if (font == null)
2088                                 Assert.Ignore ("Couldn't create required font");
2089
2090                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2091                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2092                                         string s = String.Empty;
2093                                         SizeF size = g.MeasureString (s, font);
2094                                         Assert.AreEqual (0, size.Height, "Empty.Height");
2095                                         Assert.AreEqual (0, size.Width, "Empty.Width");
2096
2097                                         s += " ";
2098                                         SizeF expected = g.MeasureString (s, font);
2099                                         for (int i = 1; i < 10; i++) {
2100                                                 s += " ";
2101                                                 size = g.MeasureString (s, font);
2102                                                 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2103                                                 Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
2104                                         }
2105
2106                                         s = "a";
2107                                         expected = g.MeasureString (s, font);
2108                                         s = " " + s;
2109                                         size = g.MeasureString (s, font);
2110                                         float space_width = size.Width - expected.Width;
2111                                         for (int i = 1; i < 10; i++) {
2112                                                 size = g.MeasureString (s, font);
2113                                                 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2114                                                 Assert.AreEqual (expected.Width + i * space_width, size.Width, 0.1, ">" + s + "< Width");
2115                                                 s = " " + s;
2116                                         }
2117
2118                                         s = "a";
2119                                         expected = g.MeasureString (s, font);
2120                                         for (int i = 1; i < 10; i++) {
2121                                                 s = s + " ";
2122                                                 size = g.MeasureString (s, font);
2123                                                 Assert.AreEqual (expected.Height, size.Height, 0.1, ">" + s + "< Height");
2124                                                 Assert.AreEqual (expected.Width, size.Width, 0.1, ">" + s + "< Width");
2125                                         }
2126                                 }
2127                         }
2128                 }
2129
2130                 [Test]
2131                 public void MeasureCharacterRanges_NullOrEmptyText ()
2132                 {
2133                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2134                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2135                                         Region[] regions = g.MeasureCharacterRanges (null, font, new RectangleF (), null);
2136                                         Assert.AreEqual (0, regions.Length, "text null");
2137                                         regions = g.MeasureCharacterRanges (String.Empty, font, new RectangleF (), null);
2138                                         Assert.AreEqual (0, regions.Length, "text empty");
2139                                         // null font is ok with null or empty string
2140                                         regions = g.MeasureCharacterRanges (null, null, new RectangleF (), null);
2141                                         Assert.AreEqual (0, regions.Length, "text null/null font");
2142                                         regions = g.MeasureCharacterRanges (String.Empty, null, new RectangleF (), null);
2143                                         Assert.AreEqual (0, regions.Length, "text empty/null font");
2144                                 }
2145                         }
2146                 }
2147
2148                 [Test]
2149                 public void MeasureCharacterRanges_EmptyStringFormat ()
2150                 {
2151                         if (font == null)
2152                                 Assert.Ignore ("Couldn't create required font");
2153
2154                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2155                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2156                                         // string format without character ranges
2157                                         Region[] regions = g.MeasureCharacterRanges ("Mono", font, new RectangleF (), new StringFormat ());
2158                                         Assert.AreEqual (0, regions.Length, "empty stringformat");
2159                                 }
2160                         }
2161                 }
2162
2163                 [Test]
2164                 [ExpectedException (typeof (ArgumentNullException))]
2165                 public void MeasureCharacterRanges_FontNull ()
2166                 {
2167                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2168                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2169                                         g.MeasureCharacterRanges ("a", null, new RectangleF (), null);
2170                                 }
2171                         }
2172                 }
2173
2174                 [Test] // adapted from bug #78777
2175                 public void MeasureCharacterRanges_TwoLines ()
2176                 {
2177                         if (font == null)
2178                                 Assert.Ignore ("Couldn't create required font");
2179
2180                         string text = "this\nis a test";
2181                         CharacterRange[] ranges = new CharacterRange[2];
2182                         ranges[0] = new CharacterRange (0, 5);
2183                         ranges[1] = new CharacterRange (5, 9);
2184
2185                         StringFormat string_format = new StringFormat ();
2186                         string_format.FormatFlags = StringFormatFlags.NoClip;
2187                         string_format.SetMeasurableCharacterRanges (ranges);
2188
2189                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2190                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2191                                         SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2192                                         RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2193                                         Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2194
2195                                         Assert.AreEqual (2, regions.Length, "Length");
2196                                         Assert.AreEqual (regions[0].GetBounds (g).Height, regions[1].GetBounds (g).Height, "Height");
2197                                 }
2198                         }
2199                 }
2200
2201                 private void MeasureCharacterRanges (string text, int first, int length)
2202                 {
2203                         if (font == null)
2204                                 Assert.Ignore ("Couldn't create required font");
2205
2206                         CharacterRange[] ranges = new CharacterRange[1];
2207                         ranges[0] = new CharacterRange (first, length);
2208
2209                         StringFormat string_format = new StringFormat ();
2210                         string_format.FormatFlags = StringFormatFlags.NoClip;
2211                         string_format.SetMeasurableCharacterRanges (ranges);
2212
2213                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2214                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2215                                         SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2216                                         RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2217                                         g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2218                                 }
2219                         }
2220                 }
2221
2222                 [Test]
2223                 [ExpectedException (typeof (ArgumentException))]
2224                 public void MeasureCharacterRanges_FirstTooFar ()
2225                 {
2226                         string text = "this\nis a test";
2227                         MeasureCharacterRanges (text, text.Length, 1);
2228                 }
2229
2230                 [Test]
2231                 [ExpectedException (typeof (ArgumentException))]
2232                 public void MeasureCharacterRanges_LengthTooLong ()
2233                 {
2234                         string text = "this\nis a test";
2235                         MeasureCharacterRanges (text, 0, text.Length + 1);
2236                 }
2237
2238                 [Test]
2239                 public void MeasureCharacterRanges_Prefix ()
2240                 {
2241                         if (font == null)
2242                                 Assert.Ignore ("Couldn't create required font");
2243
2244                         string text = "Hello &Mono::";
2245                         CharacterRange[] ranges = new CharacterRange[1];
2246                         ranges[0] = new CharacterRange (5, 4);
2247
2248                         StringFormat string_format = new StringFormat ();
2249                         string_format.SetMeasurableCharacterRanges (ranges);
2250
2251                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2252                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2253                                         SizeF size = g.MeasureString (text, font, new Point (0, 0), string_format);
2254                                         RectangleF layout_rect = new RectangleF (0.0f, 0.0f, size.Width, size.Height);
2255
2256                                         // here & is part of the measure and visible
2257                                         string_format.HotkeyPrefix = HotkeyPrefix.None;
2258                                         Region[] regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2259                                         RectangleF bounds_none = regions[0].GetBounds (g);
2260
2261                                         // here & is part of the measure (range) but visible as an underline
2262                                         string_format.HotkeyPrefix = HotkeyPrefix.Show;
2263                                         regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2264                                         RectangleF bounds_show = regions[0].GetBounds (g);
2265                                         Assert.IsTrue (bounds_show.Width < bounds_none.Width, "Show<None");
2266
2267                                         // here & is part of the measure (range) but invisible
2268                                         string_format.HotkeyPrefix = HotkeyPrefix.Hide;
2269                                         regions = g.MeasureCharacterRanges (text, font, layout_rect, string_format);
2270                                         RectangleF bounds_hide = regions[0].GetBounds (g);
2271                                         Assert.AreEqual (bounds_hide.Width, bounds_show.Width, "Hide==None");
2272                                 }
2273                         }
2274                 }
2275
2276                 [Test]
2277                 [ExpectedException (typeof (ArgumentException))]
2278                 public void MeasureCharacterRanges_NullStringFormat ()
2279                 {
2280                         if (font == null)
2281                                 Assert.Ignore ("Couldn't create required font");
2282
2283                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2284                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2285                                         g.MeasureCharacterRanges ("Mono", font, new RectangleF (), null);
2286                                 }
2287                         }
2288                 }
2289
2290                 [Test]
2291                 [Category ("NotWorking")]
2292                 public void MeasureCharacterRanges_StringFormat_Alignment ()
2293                 {
2294                         if (font == null)
2295                                 Assert.Ignore ("Couldn't create required font");
2296
2297                         string text = "Hello Mono::";
2298                         CharacterRange[] ranges = new CharacterRange[1];
2299                         ranges[0] = new CharacterRange (5, 4);
2300                         StringFormat string_format = new StringFormat ();
2301                         string_format.SetMeasurableCharacterRanges (ranges);
2302
2303                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2304                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2305                                         string_format.Alignment = StringAlignment.Near;
2306                                         Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2307                                         Assert.AreEqual (1, regions.Length, "Near.Region");
2308                                         RectangleF near = regions[0].GetBounds (g);
2309
2310                                         string_format.Alignment = StringAlignment.Center;
2311                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2312                                         Assert.AreEqual (1, regions.Length, "Center.Region");
2313                                         RectangleF center = regions[0].GetBounds (g);
2314
2315                                         string_format.Alignment = StringAlignment.Far;
2316                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2317                                         Assert.AreEqual (1, regions.Length, "Far.Region");
2318                                         RectangleF far = regions[0].GetBounds (g);
2319
2320                                         Assert.IsTrue (near.X < center.X, "near-center/X");
2321                                         Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
2322                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2323                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2324
2325                                         Assert.IsTrue (center.X < far.X, "center-far/X");
2326                                         Assert.AreEqual (center.Y, far.Y, "center-far/Y");
2327                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2328                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2329                                 }
2330                         }
2331                 }
2332
2333                 [Test]
2334                 [Category ("NotWorking")]
2335                 public void MeasureCharacterRanges_StringFormat_LineAlignment ()
2336                 {
2337                         if (font == null)
2338                                 Assert.Ignore ("Couldn't create required font");
2339
2340                         string text = "Hello Mono::";
2341                         CharacterRange[] ranges = new CharacterRange[1];
2342                         ranges[0] = new CharacterRange (5, 4);
2343                         StringFormat string_format = new StringFormat ();
2344                         string_format.SetMeasurableCharacterRanges (ranges);
2345
2346                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2347                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2348                                         string_format.LineAlignment = StringAlignment.Near;
2349                                         Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2350                                         Assert.AreEqual (1, regions.Length, "Near.Region");
2351                                         RectangleF near = regions[0].GetBounds (g);
2352
2353                                         string_format.LineAlignment = StringAlignment.Center;
2354                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2355                                         Assert.AreEqual (1, regions.Length, "Center.Region");
2356                                         RectangleF center = regions[0].GetBounds (g);
2357
2358                                         string_format.LineAlignment = StringAlignment.Far;
2359                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2360                                         Assert.AreEqual (1, regions.Length, "Far.Region");
2361                                         RectangleF far = regions[0].GetBounds (g);
2362
2363                                         Assert.AreEqual (near.X, center.X, 0.1, "near-center/X");
2364                                         Assert.IsTrue (near.Y < center.Y, "near-center/Y");
2365                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2366                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2367
2368                                         Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
2369                                         Assert.IsTrue (center.Y < far.Y, "center-far/Y");
2370                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2371                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2372                                 }
2373                         }
2374                 }
2375
2376                 [Test]
2377                 [Category ("NotWorking")]
2378                 public void MeasureCharacterRanges_StringFormat_Alignment_DirectionVertical ()
2379                 {
2380                         if (font == null)
2381                                 Assert.Ignore ("Couldn't create required font");
2382
2383                         string text = "Hello Mono::";
2384                         CharacterRange[] ranges = new CharacterRange[1];
2385                         ranges[0] = new CharacterRange (5, 4);
2386                         StringFormat string_format = new StringFormat ();
2387                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2388                         string_format.SetMeasurableCharacterRanges (ranges);
2389
2390                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2391                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2392                                         string_format.Alignment = StringAlignment.Near;
2393                                         Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2394                                         Assert.AreEqual (1, regions.Length, "Near.Region");
2395                                         RectangleF near = regions[0].GetBounds (g);
2396
2397                                         string_format.Alignment = StringAlignment.Center;
2398                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2399                                         Assert.AreEqual (1, regions.Length, "Center.Region");
2400                                         RectangleF center = regions[0].GetBounds (g);
2401
2402                                         string_format.Alignment = StringAlignment.Far;
2403                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2404                                         Assert.AreEqual (1, regions.Length, "Far.Region");
2405                                         RectangleF far = regions[0].GetBounds (g);
2406
2407                                         Assert.IsTrue (near.X == center.X, "near-center/X"); // ???
2408                                         Assert.IsTrue (near.Y < center.Y, "near-center/Y");
2409                                         Assert.IsTrue (near.Width == center.Width, "near-center/Width"); // ???
2410                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2411
2412                                         Assert.AreEqual (center.X, far.X, 0.1, "center-far/X");
2413                                         Assert.IsTrue (center.Y < far.Y, "center-far/Y");
2414                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2415                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2416                                 }
2417                         }
2418                 }
2419
2420                 [Test]
2421                 [Category ("NotWorking")]
2422                 public void MeasureCharacterRanges_StringFormat_LineAlignment_DirectionVertical ()
2423                 {
2424                         if (font == null)
2425                                 Assert.Ignore ("Couldn't create required font");
2426
2427                         string text = "Hello Mono::";
2428                         CharacterRange[] ranges = new CharacterRange[1];
2429                         ranges[0] = new CharacterRange (5, 4);
2430                         StringFormat string_format = new StringFormat ();
2431                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2432                         string_format.SetMeasurableCharacterRanges (ranges);
2433
2434                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2435                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2436                                         string_format.LineAlignment = StringAlignment.Near;
2437                                         Region[] regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2438                                         Assert.AreEqual (1, regions.Length, "Near.Region");
2439                                         RectangleF near = regions[0].GetBounds (g);
2440
2441                                         string_format.LineAlignment = StringAlignment.Center;
2442                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2443                                         Assert.AreEqual (1, regions.Length, "Center.Region");
2444                                         RectangleF center = regions[0].GetBounds (g);
2445
2446                                         string_format.LineAlignment = StringAlignment.Far;
2447                                         regions = g.MeasureCharacterRanges (text, font, new RectangleF (0, 0, 320, 32), string_format);
2448                                         Assert.AreEqual (1, regions.Length, "Far.Region");
2449                                         RectangleF far = regions[0].GetBounds (g);
2450
2451                                         Assert.IsTrue (near.X < center.X, "near-center/X");
2452                                         Assert.AreEqual (near.Y, center.Y, 0.1, "near-center/Y");
2453                                         Assert.AreEqual (near.Width, center.Width, 0.1, "near-center/Width");
2454                                         Assert.AreEqual (near.Height, center.Height, 0.1, "near-center/Height");
2455
2456                                         Assert.IsTrue (center.X < far.X, "center-far/X");
2457                                         Assert.AreEqual (center.Y, far.Y, 0.1, "center-far/Y");
2458                                         Assert.AreEqual (center.Width, far.Width, 0.1, "center-far/Width");
2459                                         Assert.AreEqual (center.Height, far.Height, 0.1, "center-far/Height");
2460                                 }
2461                         }
2462                 }
2463
2464                 static CharacterRange [] ranges = new CharacterRange [] {
2465                     new CharacterRange (0, 1),
2466                     new CharacterRange (1, 1),
2467                     new CharacterRange (2, 1)
2468                 };
2469
2470                 Region [] Measure (Graphics gfx, RectangleF rect)
2471                 {
2472                         using (StringFormat format = StringFormat.GenericTypographic) {
2473                                 format.SetMeasurableCharacterRanges (ranges);
2474
2475                                 using (Font font = new Font (FontFamily.GenericSerif, 11.0f)) {
2476                                         return gfx.MeasureCharacterRanges ("abc", font, rect, format);
2477                                 }
2478                         }
2479                 }
2480
2481                 [Test]
2482                 public void Measure ()
2483                 {
2484                         using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
2485                                 Region [] zero = Measure (gfx, new RectangleF (0, 0, 0, 0));
2486                                 Assert.AreEqual (3, zero.Length, "zero.Length");
2487
2488                                 Region [] small = Measure (gfx, new RectangleF (0, 0, 100, 100));
2489                                 Assert.AreEqual (3, small.Length, "small.Length");
2490                                 for (int i = 0; i < 3; i++ ) {
2491                                         RectangleF zb = zero [i].GetBounds (gfx);
2492                                         RectangleF sb = small [i].GetBounds (gfx);
2493                                         Assert.AreEqual (sb.X, zb.X, "sx" + i.ToString ());
2494                                         Assert.AreEqual (sb.Y, zb.Y, "sy" + i.ToString ());
2495                                         Assert.AreEqual (sb.Width, zb.Width, "sw" + i.ToString ());
2496                                         Assert.AreEqual (sb.Height, zb.Height, "sh" + i.ToString ());
2497                                 }
2498
2499                                 Region [] max = Measure (gfx, new RectangleF (0, 0, Single.MaxValue, Single.MaxValue));
2500                                 Assert.AreEqual (3, max.Length, "empty.Length");
2501                                 for (int i = 0; i < 3; i++) {
2502                                         RectangleF zb = zero [i].GetBounds (gfx);
2503                                         RectangleF mb = max [i].GetBounds (gfx);
2504                                         Assert.AreEqual (mb.X, zb.X, "mx" + i.ToString ());
2505                                         Assert.AreEqual (mb.Y, zb.Y, "my" + i.ToString ());
2506                                         Assert.AreEqual (mb.Width, zb.Width, "mw" + i.ToString ());
2507                                         Assert.AreEqual (mb.Height, zb.Height, "mh" + i.ToString ());
2508                                 }
2509                         }
2510                 }
2511
2512                 [Test]
2513                 public void MeasureLimits ()
2514                 {
2515                         using (Graphics gfx = Graphics.FromImage (new Bitmap (1, 1))) {
2516                                 Region [] min = Measure (gfx, new RectangleF (0, 0, Single.MinValue, Single.MinValue));
2517                                 Assert.AreEqual (3, min.Length, "origin.Length");
2518                                 for (int i = 0; i < 3; i++) {
2519                                         RectangleF mb = min [i].GetBounds (gfx);
2520                                         Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
2521                                         Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
2522                                         Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
2523                                         Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
2524                                 }
2525
2526                                 Region [] neg = Measure (gfx, new RectangleF (0, 0, -20, -20));
2527                                 Assert.AreEqual (3, neg.Length, "neg.Length");
2528                                 for (int i = 0; i < 3; i++) {
2529                                         RectangleF mb = neg [i].GetBounds (gfx);
2530                                         Assert.AreEqual (-4194304.0f, mb.X, "minx" + i.ToString ());
2531                                         Assert.AreEqual (-4194304.0f, mb.Y, "miny" + i.ToString ());
2532                                         Assert.AreEqual (8388608.0f, mb.Width, "minw" + i.ToString ());
2533                                         Assert.AreEqual (8388608.0f, mb.Height, "minh" + i.ToString ());
2534                                 }
2535                         }
2536                 }
2537
2538                 [Test]
2539                 public void DrawString_EndlessLoop_Bug77699 ()
2540                 {
2541                         if (font == null)
2542                                 Assert.Ignore ("Couldn't create required font");
2543
2544                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2545                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2546                                         Rectangle rect = Rectangle.Empty;
2547                                         rect.Location = new Point (10, 10);
2548                                         rect.Size = new Size (1, 20);
2549                                         StringFormat fmt = new StringFormat ();
2550                                         fmt.Alignment = StringAlignment.Center;
2551                                         fmt.LineAlignment = StringAlignment.Center;
2552                                         fmt.FormatFlags = StringFormatFlags.NoWrap;
2553                                         fmt.Trimming = StringTrimming.EllipsisWord;
2554                                         g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
2555                                 }
2556                         }
2557                 }
2558
2559                 [Test]
2560                 public void DrawString_EndlessLoop_Wrapping ()
2561                 {
2562                         if (font == null)
2563                                 Assert.Ignore ("Couldn't create required font");
2564
2565                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2566                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2567                                         Rectangle rect = Rectangle.Empty;
2568                                         rect.Location = new Point (10, 10);
2569                                         rect.Size = new Size (1, 20);
2570                                         StringFormat fmt = new StringFormat ();
2571                                         fmt.Alignment = StringAlignment.Center;
2572                                         fmt.LineAlignment = StringAlignment.Center;
2573                                         fmt.Trimming = StringTrimming.EllipsisWord;
2574                                         g.DrawString ("Test String", font, Brushes.Black, rect, fmt);
2575                                 }
2576                         }
2577                 }
2578
2579                 [Test]
2580                 public void MeasureString_Wrapping_Dots ()
2581                 {
2582                         HostIgnoreList.CheckTest ("MonoTests.System.Drawing.GraphicsTest.MeasureString_Wrapping_Dots");
2583
2584                         if (font == null)
2585                                 Assert.Ignore ("Couldn't create required font");
2586
2587                         string text = "this is really long text........................................... with a lot o periods.";
2588                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2589                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2590                                         using (StringFormat format = new StringFormat ()) {
2591                                                 format.Alignment = StringAlignment.Center;
2592                                                 SizeF sz = g.MeasureString (text, font, 80, format);
2593                                                 Assert.IsTrue (sz.Width < 80, "Width");
2594                                                 Assert.IsTrue (sz.Height > font.Height * 2, "Height");
2595                                         }
2596                                 }
2597                         }
2598                 }
2599
2600                 [Test]
2601                 public void GetReleaseHdcInternal ()
2602                 {
2603                         using (Bitmap b = new Bitmap (10, 10)) {
2604                                 using (Graphics g = Graphics.FromImage (b)) {
2605                                         IntPtr hdc1 = g.GetHdc ();
2606                                         g.ReleaseHdcInternal (hdc1);
2607                                         IntPtr hdc2 = g.GetHdc ();
2608                                         g.ReleaseHdcInternal (hdc2);
2609                                         Assert.AreEqual (hdc1, hdc2, "hdc");
2610                                 }
2611                         }
2612                 }
2613
2614                 [Test]
2615                 [ExpectedException (typeof (ArgumentException))]
2616                 public void ReleaseHdcInternal_IntPtrZero ()
2617                 {
2618                         using (Bitmap b = new Bitmap (10, 10)) {
2619                                 using (Graphics g = Graphics.FromImage (b)) {
2620                                         g.ReleaseHdcInternal (IntPtr.Zero);
2621                                 }
2622                         }
2623                 }
2624
2625                 [Test]
2626                 [ExpectedException (typeof (ArgumentException))]
2627                 public void ReleaseHdcInternal_TwoTimes ()
2628                 {
2629                         using (Bitmap b = new Bitmap (10, 10)) {
2630                                 using (Graphics g = Graphics.FromImage (b)) {
2631                                         IntPtr hdc = g.GetHdc ();
2632                                         g.ReleaseHdcInternal (hdc);
2633                                         g.ReleaseHdcInternal (hdc);
2634                                 }
2635                         }
2636                 }
2637 #if NET_2_0
2638                 [Test]
2639                 public void TestReleaseHdc ()
2640                 {
2641                         using (Bitmap b = new Bitmap (10, 10)) {
2642                                 using (Graphics g = Graphics.FromImage (b)) {
2643                                         IntPtr hdc1 = g.GetHdc ();
2644                                         g.ReleaseHdc ();
2645                                         IntPtr hdc2 = g.GetHdc ();
2646                                         g.ReleaseHdc ();
2647                                         Assert.AreEqual (hdc1, hdc2, "hdc");
2648                                 }
2649                         }
2650                 }
2651
2652                 [Test]
2653                 [ExpectedException (typeof (ArgumentException))]
2654                 public void TestReleaseHdcException ()
2655                 {
2656                         using (Bitmap b = new Bitmap (10, 10)) {
2657                                 using (Graphics g = Graphics.FromImage (b)) {
2658                                         g.ReleaseHdc ();
2659                                 }
2660                         }
2661                 }
2662
2663                 [Test]
2664                 [ExpectedException (typeof (ArgumentException))]
2665                 public void TestReleaseHdcException2 ()
2666                 {
2667                         using (Bitmap b = new Bitmap (10, 10)) {
2668                                 using (Graphics g = Graphics.FromImage (b)) {
2669                                         g.GetHdc ();
2670                                         g.ReleaseHdc ();
2671                                         g.ReleaseHdc ();
2672                                 }
2673                         }
2674                 }
2675 #endif
2676                 [Test]
2677                 public void VisibleClipBound ()
2678                 {
2679                         // see #78958
2680                         using (Bitmap bmp = new Bitmap (100, 100)) {
2681                                 using (Graphics g = Graphics.FromImage (bmp)) {
2682                                         RectangleF noclip = g.VisibleClipBounds;
2683                                         Assert.AreEqual (0, noclip.X, "noclip.X");
2684                                         Assert.AreEqual (0, noclip.Y, "noclip.Y");
2685                                         Assert.AreEqual (100, noclip.Width, "noclip.Width");
2686                                         Assert.AreEqual (100, noclip.Height, "noclip.Height");
2687
2688                                         // note: libgdiplus regions are precise to multiple of multiple of 8
2689                                         g.Clip = new Region (new RectangleF (0, 0, 32, 32));
2690                                         RectangleF clip = g.VisibleClipBounds;
2691                                         Assert.AreEqual (0, clip.X, "clip.X");
2692                                         Assert.AreEqual (0, clip.Y, "clip.Y");
2693                                         Assert.AreEqual (32, clip.Width, "clip.Width");
2694                                         Assert.AreEqual (32, clip.Height, "clip.Height");
2695
2696                                         g.RotateTransform (90);
2697                                         RectangleF rotclip = g.VisibleClipBounds;
2698                                         Assert.AreEqual (0, rotclip.X, "rotclip.X");
2699                                         Assert.AreEqual (-32, rotclip.Y, "rotclip.Y");
2700                                         Assert.AreEqual (32, rotclip.Width, "rotclip.Width");
2701                                         Assert.AreEqual (32, rotclip.Height, "rotclip.Height");
2702                                 }
2703                         }
2704                 }
2705
2706                 [Test]
2707                 public void VisibleClipBound_BigClip ()
2708                 {
2709                         using (Bitmap bmp = new Bitmap (100, 100)) {
2710                                 using (Graphics g = Graphics.FromImage (bmp)) {
2711                                         RectangleF noclip = g.VisibleClipBounds;
2712                                         Assert.AreEqual (0, noclip.X, "noclip.X");
2713                                         Assert.AreEqual (0, noclip.Y, "noclip.Y");
2714                                         Assert.AreEqual (100, noclip.Width, "noclip.Width");
2715                                         Assert.AreEqual (100, noclip.Height, "noclip.Height");
2716
2717                                         // clip is larger than bitmap
2718                                         g.Clip = new Region (new RectangleF (0, 0, 200, 200));
2719                                         RectangleF clipbound = g.ClipBounds;
2720                                         Assert.AreEqual (0, clipbound.X, "clipbound.X");
2721                                         Assert.AreEqual (0, clipbound.Y, "clipbound.Y");
2722                                         Assert.AreEqual (200, clipbound.Width, "clipbound.Width");
2723                                         Assert.AreEqual (200, clipbound.Height, "clipbound.Height");
2724
2725                                         RectangleF clip = g.VisibleClipBounds;
2726                                         Assert.AreEqual (0, clip.X, "clip.X");
2727                                         Assert.AreEqual (0, clip.Y, "clip.Y");
2728                                         Assert.AreEqual (100, clip.Width, "clip.Width");
2729                                         Assert.AreEqual (100, clip.Height, "clip.Height");
2730
2731                                         g.RotateTransform (90);
2732                                         RectangleF rotclipbound = g.ClipBounds;
2733                                         Assert.AreEqual (0, rotclipbound.X, "rotclipbound.X");
2734                                         Assert.AreEqual (-200, rotclipbound.Y, "rotclipbound.Y");
2735                                         Assert.AreEqual (200, rotclipbound.Width, "rotclipbound.Width");
2736                                         Assert.AreEqual (200, rotclipbound.Height, "rotclipbound.Height");
2737
2738                                         RectangleF rotclip = g.VisibleClipBounds;
2739                                         Assert.AreEqual (0, rotclip.X, "rotclip.X");
2740                                         Assert.AreEqual (-100, rotclip.Y, "rotclip.Y");
2741                                         Assert.AreEqual (100, rotclip.Width, "rotclip.Width");
2742                                         Assert.AreEqual (100, rotclip.Height, "rotclip.Height");
2743                                 }
2744                         }
2745                 }
2746
2747                 [Test]
2748                 public void Rotate ()
2749                 {
2750                         using (Bitmap bmp = new Bitmap (100, 50)) {
2751                                 using (Graphics g = Graphics.FromImage (bmp)) {
2752                                         RectangleF vcb = g.VisibleClipBounds;
2753                                         Assert.AreEqual (0, vcb.X, "vcb.X");
2754                                         Assert.AreEqual (0, vcb.Y, "vcb.Y");
2755                                         Assert.AreEqual (100, vcb.Width, "vcb.Width");
2756                                         Assert.AreEqual (50, vcb.Height, "vcb.Height");
2757
2758                                         g.RotateTransform (90);
2759                                         RectangleF rvcb = g.VisibleClipBounds;
2760                                         Assert.AreEqual (0, rvcb.X, "rvcb.X");
2761                                         Assert.AreEqual (-100, rvcb.Y, "rvcb.Y");
2762                                         Assert.AreEqual (50.0f, rvcb.Width, 0.0001, "rvcb.Width");
2763                                         Assert.AreEqual (100, rvcb.Height, "rvcb.Height");
2764                                 }
2765                         }
2766                 }
2767
2768                 [Test]
2769                 public void Scale ()
2770                 {
2771                         using (Bitmap bmp = new Bitmap (100, 50)) {
2772                                 using (Graphics g = Graphics.FromImage (bmp)) {
2773                                         RectangleF vcb = g.VisibleClipBounds;
2774                                         Assert.AreEqual (0, vcb.X, "vcb.X");
2775                                         Assert.AreEqual (0, vcb.Y, "vcb.Y");
2776                                         Assert.AreEqual (100, vcb.Width, "vcb.Width");
2777                                         Assert.AreEqual (50, vcb.Height, "vcb.Height");
2778
2779                                         g.ScaleTransform (2, 0.5f);
2780                                         RectangleF svcb = g.VisibleClipBounds;
2781                                         Assert.AreEqual (0, svcb.X, "svcb.X");
2782                                         Assert.AreEqual (0, svcb.Y, "svcb.Y");
2783                                         Assert.AreEqual (50, svcb.Width, "svcb.Width");
2784                                         Assert.AreEqual (100, svcb.Height, "svcb.Height");
2785                                 }
2786                         }
2787                 }
2788
2789                 [Test]
2790                 public void Translate ()
2791                 {
2792                         using (Bitmap bmp = new Bitmap (100, 50)) {
2793                                 using (Graphics g = Graphics.FromImage (bmp)) {
2794                                         RectangleF vcb = g.VisibleClipBounds;
2795                                         Assert.AreEqual (0, vcb.X, "vcb.X");
2796                                         Assert.AreEqual (0, vcb.Y, "vcb.Y");
2797                                         Assert.AreEqual (100, vcb.Width, "vcb.Width");
2798                                         Assert.AreEqual (50, vcb.Height, "vcb.Height");
2799
2800                                         g.TranslateTransform (-25, 25);
2801                                         RectangleF tvcb = g.VisibleClipBounds;
2802                                         Assert.AreEqual (25, tvcb.X, "tvcb.X");
2803                                         Assert.AreEqual (-25, tvcb.Y, "tvcb.Y");
2804                                         Assert.AreEqual (100, tvcb.Width, "tvcb.Width");
2805                                         Assert.AreEqual (50, tvcb.Height, "tvcb.Height");
2806                                 }
2807                         }
2808                 }
2809
2810                 [Test]
2811                 [ExpectedException (typeof (ArgumentNullException))]
2812                 public void DrawIcon_NullRectangle ()
2813                 {
2814                         using (Bitmap bmp = new Bitmap (40, 40)) {
2815                                 using (Graphics g = Graphics.FromImage (bmp)) {
2816                                         g.DrawIcon (null, new Rectangle (0, 0, 32, 32));
2817                                 }
2818                         }
2819                 }
2820
2821                 [Test]
2822                 public void DrawIcon_IconRectangle ()
2823                 {
2824                         using (Bitmap bmp = new Bitmap (40, 40)) {
2825                                 using (Graphics g = Graphics.FromImage (bmp)) {
2826                                         g.DrawIcon (SystemIcons.Application, new Rectangle (0, 0, 40, 20));
2827                                         // Rectangle is empty when X, Y, Width and Height == 0 
2828                                         // (yep X and Y too, RectangleF only checks for Width and Height)
2829                                         g.DrawIcon (SystemIcons.Asterisk, new Rectangle (0, 0, 0, 0));
2830                                         // so this one is half-empty ;-)
2831                                         g.DrawIcon (SystemIcons.Error, new Rectangle (20, 40, 0, 0));
2832                                         // negative width or height isn't empty (for Rectangle)
2833                                         g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
2834                                         g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
2835                                 }
2836                         }
2837                 }
2838
2839                 [Test]
2840                 [ExpectedException (typeof (ArgumentNullException))]
2841                 public void DrawIcon_NullIntInt ()
2842                 {
2843                         using (Bitmap bmp = new Bitmap (40, 40)) {
2844                                 using (Graphics g = Graphics.FromImage (bmp)) {
2845                                         g.DrawIcon (null, 4, 2);
2846                                 }
2847                         }
2848                 }
2849
2850                 [Test]
2851                 public void DrawIcon_IconIntInt ()
2852                 {
2853                         using (Bitmap bmp = new Bitmap (40, 40)) {
2854                                 using (Graphics g = Graphics.FromImage (bmp)) {
2855                                         g.DrawIcon (SystemIcons.Exclamation, 4, 2);
2856                                         g.DrawIcon (SystemIcons.Hand, 0, 0);
2857                                 }
2858                         }
2859                 }
2860
2861                 [Test]
2862                 [ExpectedException (typeof (ArgumentNullException))]
2863                 public void DrawIconUnstretched_NullRectangle ()
2864                 {
2865                         using (Bitmap bmp = new Bitmap (40, 40)) {
2866                                 using (Graphics g = Graphics.FromImage (bmp)) {
2867                                         g.DrawIconUnstretched (null, new Rectangle (0, 0, 40, 20));
2868                                 }
2869                         }
2870                 }
2871
2872                 [Test]
2873                 public void DrawIconUnstretched_IconRectangle ()
2874                 {
2875                         using (Bitmap bmp = new Bitmap (40, 40)) {
2876                                 using (Graphics g = Graphics.FromImage (bmp)) {
2877                                         g.DrawIconUnstretched (SystemIcons.Information, new Rectangle (0, 0, 40, 20));
2878                                         // Rectangle is empty when X, Y, Width and Height == 0 
2879                                         // (yep X and Y too, RectangleF only checks for Width and Height)
2880                                         g.DrawIconUnstretched (SystemIcons.Question, new Rectangle (0, 0, 0, 0));
2881                                         // so this one is half-empty ;-)
2882                                         g.DrawIconUnstretched (SystemIcons.Warning, new Rectangle (20, 40, 0, 0));
2883                                         // negative width or height isn't empty (for Rectangle)
2884                                         g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (10, 20, -1, 0));
2885                                         g.DrawIconUnstretched (SystemIcons.WinLogo, new Rectangle (20, 10, 0, -1));
2886                                 }
2887                         }
2888                 }
2889
2890                 [Test]
2891                 [ExpectedException (typeof (ArgumentNullException))]
2892                 public void DrawImage_NullRectangleF ()
2893                 {
2894                         using (Bitmap bmp = new Bitmap (40, 40)) {
2895                                 using (Graphics g = Graphics.FromImage (bmp)) {
2896                                         g.DrawImage (null, new RectangleF (0, 0, 0, 0));
2897                                 }
2898                         }
2899                 }
2900
2901                 [Test]
2902                 public void DrawImage_ImageRectangleF ()
2903                 {
2904                         using (Bitmap bmp = new Bitmap (40, 40)) {
2905                                 using (Graphics g = Graphics.FromImage (bmp)) {
2906                                         g.DrawImage (bmp, new RectangleF (0, 0, 0, 0));
2907                                         g.DrawImage (bmp, new RectangleF (20, 40, 0, 0));
2908                                         g.DrawImage (bmp, new RectangleF (10, 20, -1, 0));
2909                                         g.DrawImage (bmp, new RectangleF (20, 10, 0, -1));
2910                                 }
2911                         }
2912                 }
2913
2914                 [Test]
2915                 [ExpectedException (typeof (ArgumentNullException))]
2916                 public void DrawImage_NullPointF ()
2917                 {
2918                         using (Bitmap bmp = new Bitmap (40, 40)) {
2919                                 using (Graphics g = Graphics.FromImage (bmp)) {
2920                                         g.DrawImage (null, new PointF (0, 0));
2921                                 }
2922                         }
2923                 }
2924
2925                 [Test]
2926                 public void DrawImage_ImagePointF ()
2927                 {
2928                         using (Bitmap bmp = new Bitmap (40, 40)) {
2929                                 using (Graphics g = Graphics.FromImage (bmp)) {
2930                                         g.DrawImage (bmp, new PointF (0, 0));
2931                                 }
2932                         }
2933                 }
2934
2935                 [Test]
2936                 [ExpectedException (typeof (ArgumentNullException))]
2937                 public void DrawImage_NullPointFArray ()
2938                 {
2939                         using (Bitmap bmp = new Bitmap (40, 40)) {
2940                                 using (Graphics g = Graphics.FromImage (bmp)) {
2941                                         g.DrawImage (null, new PointF[0]);
2942                                 }
2943                         }
2944                 }
2945
2946                 [Test]
2947                 [ExpectedException (typeof (ArgumentNullException))]
2948                 public void DrawImage_ImagePointFArrayNull ()
2949                 {
2950                         using (Bitmap bmp = new Bitmap (40, 40)) {
2951                                 using (Graphics g = Graphics.FromImage (bmp)) {
2952                                         g.DrawImage (bmp, (PointF[]) null);
2953                                 }
2954                         }
2955                 }
2956
2957                 [Test]
2958                 [ExpectedException (typeof (ArgumentException))]
2959                 public void DrawImage_ImagePointFArrayEmpty ()
2960                 {
2961                         using (Bitmap bmp = new Bitmap (40, 40)) {
2962                                 using (Graphics g = Graphics.FromImage (bmp)) {
2963                                         g.DrawImage (bmp, new PointF[0]);
2964                                 }
2965                         }
2966                 }
2967
2968                 [Test]
2969                 public void DrawImage_ImagePointFArray ()
2970                 {
2971                         using (Bitmap bmp = new Bitmap (40, 40)) {
2972                                 using (Graphics g = Graphics.FromImage (bmp)) {
2973                                         g.DrawImage (bmp, new PointF[] { 
2974                                                 new PointF (0, 0), new PointF (1, 1), new PointF (2, 2) });
2975                                 }
2976                         }
2977                 }
2978
2979                 [Test]
2980                 [ExpectedException (typeof (ArgumentNullException))]
2981                 public void DrawImage_NullRectangle ()
2982                 {
2983                         using (Bitmap bmp = new Bitmap (40, 40)) {
2984                                 using (Graphics g = Graphics.FromImage (bmp)) {
2985                                         g.DrawImage (null, new Rectangle (0, 0, 0, 0));
2986                                 }
2987                         }
2988                 }
2989
2990                 [Test]
2991                 public void DrawImage_ImageRectangle ()
2992                 {
2993                         using (Bitmap bmp = new Bitmap (40, 40)) {
2994                                 using (Graphics g = Graphics.FromImage (bmp)) {
2995                                         // Rectangle is empty when X, Y, Width and Height == 0 
2996                                         // (yep X and Y too, RectangleF only checks for Width and Height)
2997                                         g.DrawImage (bmp, new Rectangle (0, 0, 0, 0));
2998                                         // so this one is half-empty ;-)
2999                                         g.DrawImage (bmp, new Rectangle (20, 40, 0, 0));
3000                                         // negative width or height isn't empty (for Rectangle)
3001                                         g.DrawImage (bmp, new Rectangle (10, 20, -1, 0));
3002                                         g.DrawImage (bmp, new Rectangle (20, 10, 0, -1));
3003                                 }
3004                         }
3005                 }
3006
3007                 [Test]
3008                 [ExpectedException (typeof (ArgumentNullException))]
3009                 public void DrawImage_NullPoint ()
3010                 {
3011                         using (Bitmap bmp = new Bitmap (40, 40)) {
3012                                 using (Graphics g = Graphics.FromImage (bmp)) {
3013                                         g.DrawImage (null, new Point (0, 0));
3014                                 }
3015                         }
3016                 }
3017
3018                 [Test]
3019                 public void DrawImage_ImagePoint ()
3020                 {
3021                         using (Bitmap bmp = new Bitmap (40, 40)) {
3022                                 using (Graphics g = Graphics.FromImage (bmp)) {
3023                                         g.DrawImage (bmp, new Point (0, 0));
3024                                 }
3025                         }
3026                 }
3027
3028                 [Test]
3029                 [ExpectedException (typeof (ArgumentNullException))]
3030                 public void DrawImage_NullPointArray ()
3031                 {
3032                         using (Bitmap bmp = new Bitmap (40, 40)) {
3033                                 using (Graphics g = Graphics.FromImage (bmp)) {
3034                                         g.DrawImage (null, new Point[0]);
3035                                 }
3036                         }
3037                 }
3038
3039                 [Test]
3040                 [ExpectedException (typeof (ArgumentNullException))]
3041                 public void DrawImage_ImagePointArrayNull ()
3042                 {
3043                         using (Bitmap bmp = new Bitmap (40, 40)) {
3044                                 using (Graphics g = Graphics.FromImage (bmp)) {
3045                                         g.DrawImage (bmp, (Point[]) null);
3046                                 }
3047                         }
3048                 }
3049
3050                 [Test]
3051                 [ExpectedException (typeof (ArgumentException))]
3052                 public void DrawImage_ImagePointArrayEmpty ()
3053                 {
3054                         using (Bitmap bmp = new Bitmap (40, 40)) {
3055                                 using (Graphics g = Graphics.FromImage (bmp)) {
3056                                         g.DrawImage (bmp, new Point[0]);
3057                                 }
3058                         }
3059                 }
3060
3061                 [Test]
3062                 public void DrawImage_ImagePointArray ()
3063                 {
3064                         using (Bitmap bmp = new Bitmap (40, 40)) {
3065                                 using (Graphics g = Graphics.FromImage (bmp)) {
3066                                         g.DrawImage (bmp, new Point[] { 
3067                                                 new Point (0, 0), new Point (1, 1), new Point (2, 2) });
3068                                 }
3069                         }
3070                 }
3071
3072                 [Test]
3073                 [ExpectedException (typeof (ArgumentNullException))]
3074                 public void DrawImage_NullIntInt ()
3075                 {
3076                         using (Bitmap bmp = new Bitmap (40, 40)) {
3077                                 using (Graphics g = Graphics.FromImage (bmp)) {
3078                                         g.DrawImage (null, Int32.MaxValue, Int32.MinValue);
3079                                 }
3080                         }
3081                 }
3082
3083                 [Test]
3084                 [ExpectedException (typeof (OverflowException))]
3085                 public void DrawImage_ImageIntInt_Overflow ()
3086                 {
3087                         using (Bitmap bmp = new Bitmap (40, 40)) {
3088                                 using (Graphics g = Graphics.FromImage (bmp)) {
3089                                         g.DrawImage (bmp, Int32.MaxValue, Int32.MinValue);
3090                                 }
3091                         }
3092                 }
3093
3094                 [Test]
3095                 public void DrawImage_ImageIntInt ()
3096                 {
3097                         using (Bitmap bmp = new Bitmap (40, 40)) {
3098                                 using (Graphics g = Graphics.FromImage (bmp)) {
3099                                         g.DrawImage (bmp, -40, -40);
3100                                 }
3101                         }
3102                 }
3103
3104                 [Test]
3105                 [ExpectedException (typeof (ArgumentNullException))]
3106                 public void DrawImage_NullFloat ()
3107                 {
3108                         using (Bitmap bmp = new Bitmap (40, 40)) {
3109                                 using (Graphics g = Graphics.FromImage (bmp)) {
3110                                         g.DrawImage (null, Single.MaxValue, Single.MinValue);
3111                                 }
3112                         }
3113                 }
3114
3115                 [Test]
3116                 [ExpectedException (typeof (OverflowException))]
3117                 public void DrawImage_ImageFloatFloat_Overflow ()
3118                 {
3119                         using (Bitmap bmp = new Bitmap (40, 40)) {
3120                                 using (Graphics g = Graphics.FromImage (bmp)) {
3121                                         g.DrawImage (bmp, Single.MaxValue, Single.MinValue);
3122                                 }
3123                         }
3124                 }
3125
3126                 [Test]
3127                 public void DrawImage_ImageFloatFloat ()
3128                 {
3129                         using (Bitmap bmp = new Bitmap (40, 40)) {
3130                                 using (Graphics g = Graphics.FromImage (bmp)) {
3131                                         g.DrawImage (bmp, -40.0f, -40.0f);
3132                                 }
3133                         }
3134                 }
3135
3136                 [Test]
3137                 [ExpectedException (typeof (ArgumentNullException))]
3138                 public void DrawImage_NullRectangleRectangleGraphicsUnit ()
3139                 {
3140                         using (Bitmap bmp = new Bitmap (40, 40)) {
3141                                 using (Graphics g = Graphics.FromImage (bmp)) {
3142                                         g.DrawImage (null, new Rectangle (), new Rectangle (), GraphicsUnit.Display);
3143                                 }
3144                         }
3145                 }
3146
3147                 private void DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit unit)
3148                 {
3149                         using (Bitmap bmp = new Bitmap (40, 40)) {
3150                                 using (Graphics g = Graphics.FromImage (bmp)) {
3151                                         Rectangle r = new Rectangle (0, 0, 40, 40);
3152                                         g.DrawImage (bmp, r, r, unit);
3153                                 }
3154                         }
3155                 }
3156
3157                 [Test]
3158                 [ExpectedException (typeof (ArgumentException))]
3159                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Display ()
3160                 {
3161                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Display);
3162                 }
3163
3164                 [Test]
3165                 [ExpectedException (typeof (NotImplementedException))]
3166                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Document ()
3167                 {
3168                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Document);
3169                 }
3170
3171                 [Test]
3172                 [ExpectedException (typeof (NotImplementedException))]
3173                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Inch ()
3174                 {
3175                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Inch);
3176                 }
3177
3178                 [Test]
3179                 [ExpectedException (typeof (NotImplementedException))]
3180                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Millimeter ()
3181                 {
3182                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Millimeter);
3183                 }
3184
3185                 [Test]
3186                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Pixel ()
3187                 {
3188                         // this unit works
3189                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Pixel);
3190                 }
3191
3192                 [Test]
3193                 [ExpectedException (typeof (NotImplementedException))]
3194                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_Point ()
3195                 {
3196                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.Point);
3197                 }
3198
3199                 [Test]
3200                 [ExpectedException (typeof (ArgumentException))]
3201                 public void DrawImage_ImageRectangleRectangleGraphicsUnit_World ()
3202                 {
3203                         DrawImage_ImageRectangleRectangleGraphicsUnit (GraphicsUnit.World);
3204                 }
3205
3206                 [Test]
3207                 [ExpectedException (typeof (ArgumentNullException))]
3208                 public void DrawImage_NullPointRectangleGraphicsUnit ()
3209                 {
3210                         Rectangle r = new Rectangle (1, 2, 3, 4);
3211                         Point[] pts = new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) };
3212                         using (Bitmap bmp = new Bitmap (40, 40)) {
3213                                 using (Graphics g = Graphics.FromImage (bmp)) {
3214                                         g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
3215                                 }
3216                         }
3217                 }
3218
3219                 private void DrawImage_ImagePointRectangleGraphicsUnit (Point[] pts)
3220                 {
3221                         Rectangle r = new Rectangle (1, 2, 3, 4);
3222                         using (Bitmap bmp = new Bitmap (40, 40)) {
3223                                 using (Graphics g = Graphics.FromImage (bmp)) {
3224                                         g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
3225                                 }
3226                         }
3227                 }
3228
3229                 [Test]
3230                 [ExpectedException (typeof (ArgumentNullException))]
3231                 public void DrawImage_ImageNullRectangleGraphicsUnit ()
3232                 {
3233                         DrawImage_ImagePointRectangleGraphicsUnit (null);
3234                 }
3235
3236                 [Test]
3237                 [ExpectedException (typeof (ArgumentException))]
3238                 public void DrawImage_ImagePoint0RectangleGraphicsUnit ()
3239                 {
3240                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[0]);
3241                 }
3242
3243                 [Test]
3244                 [ExpectedException (typeof (ArgumentException))]
3245                 public void DrawImage_ImagePoint1RectangleGraphicsUnit ()
3246                 {
3247                         Point p = new Point (1, 1);
3248                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[1] { p });
3249                 }
3250
3251                 [Test]
3252                 [ExpectedException (typeof (ArgumentException))]
3253                 public void DrawImage_ImagePoint2RectangleGraphicsUnit ()
3254                 {
3255                         Point p = new Point (1, 1);
3256                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[2] { p, p });
3257                 }
3258
3259                 [Test]
3260                 public void DrawImage_ImagePoint3RectangleGraphicsUnit ()
3261                 {
3262                         Point p = new Point (1, 1);
3263                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[3] { p, p, p });
3264                 }
3265
3266                 [Test]
3267                 [ExpectedException (typeof (NotImplementedException))]
3268                 public void DrawImage_ImagePoint4RectangleGraphicsUnit ()
3269                 {
3270                         Point p = new Point (1, 1);
3271                         DrawImage_ImagePointRectangleGraphicsUnit (new Point[4] { p, p, p, p });
3272                 }
3273
3274                 [Test]
3275                 [ExpectedException (typeof (ArgumentNullException))]
3276                 public void DrawImage_NullPointFRectangleGraphicsUnit ()
3277                 {
3278                         Rectangle r = new Rectangle (1, 2, 3, 4);
3279                         PointF[] pts = new PointF[3] { new PointF (1, 1), new PointF (2, 2), new PointF (3, 3) };
3280                         using (Bitmap bmp = new Bitmap (40, 40)) {
3281                                 using (Graphics g = Graphics.FromImage (bmp)) {
3282                                         g.DrawImage (null, pts, r, GraphicsUnit.Pixel);
3283                                 }
3284                         }
3285                 }
3286
3287                 private void DrawImage_ImagePointFRectangleGraphicsUnit (PointF[] pts)
3288                 {
3289                         Rectangle r = new Rectangle (1, 2, 3, 4);
3290                         using (Bitmap bmp = new Bitmap (40, 40)) {
3291                                 using (Graphics g = Graphics.FromImage (bmp)) {
3292                                         g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel);
3293                                 }
3294                         }
3295                 }
3296
3297                 [Test]
3298                 [ExpectedException (typeof (ArgumentNullException))]
3299                 public void DrawImage_ImageNullFRectangleGraphicsUnit ()
3300                 {
3301                         DrawImage_ImagePointFRectangleGraphicsUnit (null);
3302                 }
3303
3304                 [Test]
3305                 [ExpectedException (typeof (ArgumentException))]
3306                 public void DrawImage_ImagePointF0RectangleGraphicsUnit ()
3307                 {
3308                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[0]);
3309                 }
3310
3311                 [Test]
3312                 [ExpectedException (typeof (ArgumentException))]
3313                 public void DrawImage_ImagePointF1RectangleGraphicsUnit ()
3314                 {
3315                         PointF p = new PointF (1, 1);
3316                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[1] { p });
3317                 }
3318
3319                 [Test]
3320                 [ExpectedException (typeof (ArgumentException))]
3321                 public void DrawImage_ImagePointF2RectangleGraphicsUnit ()
3322                 {
3323                         PointF p = new PointF (1, 1);
3324                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[2] { p, p });
3325                 }
3326
3327                 [Test]
3328                 public void DrawImage_ImagePointF3RectangleGraphicsUnit ()
3329                 {
3330                         PointF p = new PointF (1, 1);
3331                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[3] { p, p, p });
3332                 }
3333
3334                 [Test]
3335                 [ExpectedException (typeof (NotImplementedException))]
3336                 public void DrawImage_ImagePointF4RectangleGraphicsUnit ()
3337                 {
3338                         PointF p = new PointF (1, 1);
3339                         DrawImage_ImagePointFRectangleGraphicsUnit (new PointF[4] { p, p, p, p });
3340                 }
3341
3342                 [Test]
3343                 public void DrawImage_ImagePointRectangleGraphicsUnitNull ()
3344                 {
3345                         Point p = new Point (1, 1);
3346                         Point[] pts = new Point[3] { p, p, p };
3347                         Rectangle r = new Rectangle (1, 2, 3, 4);
3348                         using (Bitmap bmp = new Bitmap (40, 40)) {
3349                                 using (Graphics g = Graphics.FromImage (bmp)) {
3350                                         g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, null);
3351                                 }
3352                         }
3353                 }
3354
3355                 [Test]
3356                 public void DrawImage_ImagePointRectangleGraphicsUnitAttributes ()
3357                 {
3358                         Point p = new Point (1, 1);
3359                         Point[] pts = new Point[3] { p, p, p };
3360                         Rectangle r = new Rectangle (1, 2, 3, 4);
3361                         using (Bitmap bmp = new Bitmap (40, 40)) {
3362                                 using (Graphics g = Graphics.FromImage (bmp)) {
3363                                         ImageAttributes ia = new ImageAttributes ();
3364                                         g.DrawImage (bmp, pts, r, GraphicsUnit.Pixel, ia);
3365                                 }
3366                         }
3367                 }
3368
3369                 [Test]
3370                 [ExpectedException (typeof (ArgumentNullException))]
3371                 public void DrawImageUnscaled_NullPoint ()
3372                 {
3373                         using (Bitmap bmp = new Bitmap (40, 40)) {
3374                                 using (Graphics g = Graphics.FromImage (bmp)) {
3375                                         g.DrawImageUnscaled (null, new Point (0, 0));
3376                                 }
3377                         }
3378                 }
3379
3380                 [Test]
3381                 public void DrawImageUnscaled_ImagePoint ()
3382                 {
3383                         using (Bitmap bmp = new Bitmap (40, 40)) {
3384                                 using (Graphics g = Graphics.FromImage (bmp)) {
3385                                         g.DrawImageUnscaled (bmp, new Point (0, 0));
3386                                 }
3387                         }
3388                 }
3389
3390                 [Test]
3391                 [ExpectedException (typeof (ArgumentNullException))]
3392                 public void DrawImageUnscaled_NullRectangle ()
3393                 {
3394                         using (Bitmap bmp = new Bitmap (40, 40)) {
3395                                 using (Graphics g = Graphics.FromImage (bmp)) {
3396                                         g.DrawImageUnscaled (null, new Rectangle (0, 0, -1, -1));
3397                                 }
3398                         }
3399                 }
3400
3401                 [Test]
3402                 public void DrawImageUnscaled_ImageRectangle ()
3403                 {
3404                         using (Bitmap bmp = new Bitmap (40, 40)) {
3405                                 using (Graphics g = Graphics.FromImage (bmp)) {
3406                                         g.DrawImageUnscaled (bmp, new Rectangle (0, 0, -1, -1));
3407                                 }
3408                         }
3409                 }
3410
3411                 [Test]
3412                 [ExpectedException (typeof (ArgumentNullException))]
3413                 public void DrawImageUnscaled_NullIntInt ()
3414                 {
3415                         using (Bitmap bmp = new Bitmap (40, 40)) {
3416                                 using (Graphics g = Graphics.FromImage (bmp)) {
3417                                         g.DrawImageUnscaled (null, 0, 0);
3418                                 }
3419                         }
3420                 }
3421
3422                 [Test]
3423                 public void DrawImageUnscaled_ImageIntInt ()
3424                 {
3425                         using (Bitmap bmp = new Bitmap (40, 40)) {
3426                                 using (Graphics g = Graphics.FromImage (bmp)) {
3427                                         g.DrawImageUnscaled (bmp, 0, 0);
3428                                 }
3429                         }
3430                 }
3431
3432                 [Test]
3433                 [ExpectedException (typeof (ArgumentNullException))]
3434                 public void DrawImageUnscaled_NullIntIntIntInt ()
3435                 {
3436                         using (Bitmap bmp = new Bitmap (40, 40)) {
3437                                 using (Graphics g = Graphics.FromImage (bmp)) {
3438                                         g.DrawImageUnscaled (null, 0, 0, -1, -1);
3439                                 }
3440                         }
3441                 }
3442
3443                 [Test]
3444                 public void DrawImageUnscaled_ImageIntIntIntInt ()
3445                 {
3446                         using (Bitmap bmp = new Bitmap (40, 40)) {
3447                                 using (Graphics g = Graphics.FromImage (bmp)) {
3448                                         g.DrawImageUnscaled (bmp, 0, 0, -1, -1);
3449                                 }
3450                         }
3451                 }
3452 #if NET_2_0
3453                 [Test]
3454                 [ExpectedException (typeof (ArgumentNullException))]
3455                 public void DrawImageUnscaledAndClipped_Null ()
3456                 {
3457                         using (Bitmap bmp = new Bitmap (40, 40)) {
3458                                 using (Graphics g = Graphics.FromImage (bmp)) {
3459                                         g.DrawImageUnscaledAndClipped (null, new Rectangle (0, 0, 0, 0));
3460                                 }
3461                         }
3462                 }
3463
3464                 [Test]
3465                 public void DrawImageUnscaledAndClipped ()
3466                 {
3467                         using (Bitmap bmp = new Bitmap (40, 40)) {
3468                                 using (Graphics g = Graphics.FromImage (bmp)) {
3469                                         // Rectangle is empty when X, Y, Width and Height == 0 
3470                                         // (yep X and Y too, RectangleF only checks for Width and Height)
3471                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 0, 0));
3472                                         // so this one is half-empty ;-)
3473                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 40, 0, 0));
3474                                         // negative width or height isn't empty (for Rectangle)
3475                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (10, 20, -1, 0));
3476                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (20, 10, 0, -1));
3477                                         // smaller
3478                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 10, 20));
3479                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 40, 10));
3480                                         g.DrawImageUnscaledAndClipped (bmp, new Rectangle (0, 0, 80, 20));
3481                                 }
3482                         }
3483                 }
3484 #endif
3485
3486                 [Test]
3487                 [ExpectedException (typeof (ArgumentNullException))]
3488                 public void DrawPath_Pen_Null ()
3489                 {
3490                         using (Bitmap bmp = new Bitmap (20, 20)) {
3491                                 using (Graphics g = Graphics.FromImage (bmp)) {
3492                                         using (GraphicsPath path = new GraphicsPath ()) {
3493                                                 g.DrawPath (null, path);
3494                                         }
3495                                 }
3496                         }
3497                 }
3498
3499                 [Test]
3500                 [ExpectedException (typeof (ArgumentNullException))]
3501                 public void DrawPath_Path_Null ()
3502                 {
3503                         using (Bitmap bmp = new Bitmap (20, 20)) {
3504                                 using (Graphics g = Graphics.FromImage (bmp)) {
3505                                         g.DrawPath (Pens.Black, null);
3506                                 }
3507                         }
3508                 }
3509
3510                 [Test]
3511                 public void DrawPath_82202 ()
3512                 {
3513                         // based on test case from bug #82202
3514                         using (Bitmap bmp = new Bitmap (20, 20)) {
3515                                 using (Graphics g = Graphics.FromImage (bmp)) {
3516                                         using (GraphicsPath path = new GraphicsPath ()) {
3517                                                 int d = 5;
3518                                                 Rectangle baserect = new Rectangle (0, 0, 19, 19);
3519                                                 Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
3520
3521                                                 path.AddArc (arcrect, 180, 90);
3522                                                 arcrect.X = baserect.Right - d;
3523                                                 path.AddArc (arcrect, 270, 90);
3524                                                 arcrect.Y = baserect.Bottom - d;
3525                                                 path.AddArc (arcrect, 0, 90);
3526                                                 arcrect.X = baserect.Left;
3527                                                 path.AddArc (arcrect, 90, 90);
3528                                                 path.CloseFigure ();
3529                                                 g.Clear (Color.White);
3530                                                 g.DrawPath (Pens.SteelBlue, path);
3531
3532                                                 Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
3533                                                 Assert.AreEqual (-1, bmp.GetPixel (1, 9).ToArgb (), "1,9");
3534                                         }
3535                                 }
3536                         }
3537                 }
3538
3539                 [Test]
3540                 [ExpectedException (typeof (ArgumentNullException))]
3541                 public void FillPath_Brush_Null ()
3542                 {
3543                         using (Bitmap bmp = new Bitmap (20, 20)) {
3544                                 using (Graphics g = Graphics.FromImage (bmp)) {
3545                                         using (GraphicsPath path = new GraphicsPath ()) {
3546                                                 g.FillPath (null, path);
3547                                         }
3548                                 }
3549                         }
3550                 }
3551
3552                 [Test]
3553                 [ExpectedException (typeof (ArgumentNullException))]
3554                 public void FillPath_Path_Null ()
3555                 {
3556                         using (Bitmap bmp = new Bitmap (20, 20)) {
3557                                 using (Graphics g = Graphics.FromImage (bmp)) {
3558                                         g.FillPath (Brushes.Black, null);
3559                                 }
3560                         }
3561                 }
3562
3563                 [Test]
3564                 public void FillPath_82202 ()
3565                 {
3566                         // based on test case from bug #82202
3567                         using (Bitmap bmp = new Bitmap (20, 20)) {
3568                                 using (Graphics g = Graphics.FromImage (bmp)) {
3569                                         using (GraphicsPath path = new GraphicsPath ()) {
3570                                                 int d = 5;
3571                                                 Rectangle baserect = new Rectangle (0, 0, 19, 19);
3572                                                 Rectangle arcrect = new Rectangle (baserect.Location, new Size (d, d));
3573
3574                                                 path.AddArc (arcrect, 180, 90);
3575                                                 arcrect.X = baserect.Right - d;
3576                                                 path.AddArc (arcrect, 270, 90);
3577                                                 arcrect.Y = baserect.Bottom - d;
3578                                                 path.AddArc (arcrect, 0, 90);
3579                                                 arcrect.X = baserect.Left;
3580                                                 path.AddArc (arcrect, 90, 90);
3581                                                 path.CloseFigure ();
3582                                                 g.Clear (Color.White);
3583                                                 g.FillPath (Brushes.SteelBlue, path);
3584
3585                                                 Assert.AreEqual (-12156236, bmp.GetPixel (0, 9).ToArgb (), "0,9");
3586                                                 Assert.AreEqual (-12156236, bmp.GetPixel (1, 9).ToArgb (), "1,9");
3587                                         }
3588                                 }
3589                         }
3590                 }
3591
3592                 [Test]
3593                 public void TransformPoints_349800 ()
3594                 {
3595                         using (Bitmap bmp = new Bitmap (10, 10)) {
3596                                 using (Graphics g = Graphics.FromImage (bmp)) {
3597                                         Point [] pts = new Point [5];
3598                                         PointF [] ptf = new PointF [5];
3599                                         for (int i = 0; i < 5; i++) {
3600                                                 pts [i] = new Point (i, i);
3601                                                 ptf [i] = new PointF (i, i);
3602                                         }
3603
3604                                         g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, pts);
3605                                         g.TransformPoints (CoordinateSpace.Page, CoordinateSpace.Device, ptf);
3606
3607                                         for (int i = 0; i < 5; i++) {
3608                                                 Assert.AreEqual (i, pts [i].X, "Point.X " + i.ToString ());
3609                                                 Assert.AreEqual (i, pts [i].Y, "Point.Y " + i.ToString ());
3610                                                 Assert.AreEqual (i, ptf [i].X, "PointF.X " + i.ToString ());
3611                                                 Assert.AreEqual (i, ptf [i].Y, "PointF.Y " + i.ToString ());
3612                                         }
3613                                 }
3614                         }
3615                 }
3616
3617                 [Test]
3618                 public void Dpi_556181 ()
3619                 {
3620                         float x, y;
3621                         using (Bitmap bmp = new Bitmap (10, 10)) {
3622                                 using (Graphics g = Graphics.FromImage (bmp)) {
3623                                         x = g.DpiX - 10;
3624                                         y = g.DpiY + 10;
3625                                 }
3626                                 bmp.SetResolution (x, y);
3627                                 using (Graphics g = Graphics.FromImage (bmp)) {
3628                                         Assert.AreEqual (x, g.DpiX, "DpiX");
3629                                         Assert.AreEqual (y, g.DpiY, "DpiY");
3630                                 }
3631                         }
3632                 }
3633         }
3634
3635         [TestFixture]
3636         public class GraphicsFullTrustTest {
3637
3638                 // note: this test would fail, on ReleaseHdc, without fulltrust
3639                 // i.e. it's a demand and not a linkdemand
3640                 [Test]
3641                 public void GetReleaseHdc ()
3642                 {
3643                         using (Bitmap b = new Bitmap (100, 100)) {
3644                                 using (Graphics g = Graphics.FromImage (b)) {
3645                                         IntPtr hdc1 = g.GetHdc ();
3646                                         g.ReleaseHdc (hdc1);
3647                                         IntPtr hdc2 = g.GetHdc ();
3648                                         g.ReleaseHdc (hdc2);
3649                                         Assert.AreEqual (hdc1, hdc2, "hdc");
3650                                 }
3651                         }
3652                 }
3653
3654         }
3655 }