Make System.Drawing unit tests use Assert.Throws instead of [ExpectedException] ...
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / SolidBrushTest.cs
index 1caf9ff6419308918fcd5321e2469e6b2aec1144..b854d6f5401a5cdc1f025129541b28c11fd07e2c 100644 (file)
@@ -4,7 +4,7 @@
 // Authors:
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
-// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -58,12 +58,11 @@ namespace MonoTests.System.Drawing {
                }
 
                [Test]
-               [ExpectedException (typeof (ArgumentException))]
                public void Dispose_Clone ()
                {
                        SolidBrush sb = new SolidBrush (Color.Transparent);
                        sb.Dispose ();
-                       sb.Clone ();
+                       Assert.Throws<ArgumentException> (() => sb.Clone ());
                }
 
                [Test]
@@ -105,6 +104,28 @@ namespace MonoTests.System.Drawing {
                                Assert.AreEqual (Color.Red.ToArgb (), bmp.GetPixel (8, 8).ToArgb (), "8,8");
                                Assert.AreEqual (Color.Red.ToArgb (), bmp.GetPixel (9, 9).ToArgb (), "9,9"); // include end point
                        }
+                       using (Bitmap bmp = new Bitmap (10, 10)) {
+                               using (Graphics g = Graphics.FromImage (bmp)) {
+                                       SolidBrush sb = new SolidBrush (Color.Red);
+                                       Pen p = new Pen (sb);
+                                       g.DrawLine (p, float.NaN, float.NaN, 9, 9);
+                               }
+                               Assert.AreNotEqual (Color.Red.ToArgb (), bmp.GetPixel (0, 0).ToArgb (), "#DrawLine: Drew Line with NaN value when shouldn't have");
+                       }
+               }
+
+               [Test]
+               public void Clone ()
+               {
+                       using (SolidBrush sb = new SolidBrush (Color.Transparent)) {
+                               // we still get a "named" color
+                               Assert.AreEqual (Color.Transparent, sb.Color, "Color");
+                               using (SolidBrush clone = (SolidBrush) sb.Clone ()) {
+                                       // but not after cloning the brush
+                                       Assert.IsFalse (Color.Transparent.Equals (clone.Color), "Color-Clone-Unnamed");
+                                       Assert.AreEqual (Color.Transparent.ToArgb (), clone.Color.ToArgb (), "Color-Clone-Argb");
+                               }
+                       }
                }
        }
 }