2007-01-15 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestImage.cs
index 302f22d0f6e75642e21bd977dbb676b431f7f62f..6349648ed558e4b11e4be0e1df87b2d37f12f2c7 100644 (file)
@@ -6,7 +6,7 @@
 //     Sebastien Pouliot  <sebastien@ximian.com>
 //
 // (C) 2005 Ximian, Inc.  http://www.ximian.com
-// Copyright (C) 2005, 2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-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
@@ -164,5 +164,44 @@ namespace MonoTests.System.Drawing{
                                tn.Save (fname, ImageFormat.Png);
                        }
                }
+
+               [Test]
+               public void Stream_Unlocked ()
+               {
+                       try {
+                               Image img = null;
+                               using (MemoryStream ms = new MemoryStream ()) {
+                                       using (Bitmap bmp = new Bitmap (10, 10)) {
+                                               bmp.Save (ms, ImageFormat.Png);
+                                       }
+                                       ms.Position = 0;
+                                       img = Image.FromStream (ms);
+                               }
+                               // stream isn't available anymore
+                               ((Bitmap) img).MakeTransparent (Color.Transparent);
+                       }
+                       catch (OutOfMemoryException) {
+                               int p = (int) Environment.OSVersion.Platform;
+                               // libgdiplus (UNIX) doesn't lazy load the image so the
+                               // stream may be freed (and this exception will never occur)
+                               if ((p == 4) || (p == 128))
+                                       throw;
+                       }
+               }
+
+               [Test]
+               public void Stream_Locked ()
+               {
+                       Image img = null;
+                       using (MemoryStream ms = new MemoryStream ()) {
+                               using (Bitmap bmp = new Bitmap (10, 10)) {
+                                       bmp.Save (ms, ImageFormat.Png);
+                               }
+                               ms.Position = 0;
+                               img = Image.FromStream (ms);
+                               // stream is available
+                               ((Bitmap) img).MakeTransparent (Color.Transparent);
+                       }
+               }
        }
 }