Author: spouliot
Date: 2007-01-16 11:08:58 -0500 (Tue, 16 Jan 2007)
New Revision: 71147
Modified:
trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
trunk/mcs/class/System.Drawing/Test/System.Drawing/TestBitmap.cs
trunk/mcs/class/System.Drawing/Test/System.Drawing/TestIcon.cs
Log:
2007-01-16 Sebastien Pouliot <[EMAIL PROTECTED]>
* TestBitmap.cs: Added test case to create multiple bitmaps from a
single HBITMAP.
* TestIcon.cs: Added test cases to create multiple icons from a
single Handle or HICON. Enabled SaveAndCompare on roundtrip tests.
Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
2007-01-16 16:08:44 UTC (rev 71146)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/ChangeLog
2007-01-16 16:08:58 UTC (rev 71147)
@@ -1,3 +1,10 @@
+2007-01-16 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * TestBitmap.cs: Added test case to create multiple bitmaps from a
+ single HBITMAP.
+ * TestIcon.cs: Added test cases to create multiple icons from a
+ single Handle or HICON. Enabled SaveAndCompare on roundtrip tests.
+
2007-01-15 Sebastien Pouliot <[EMAIL PROTECTED]>
* TestIcon.cs: Add test cases for ToBitmap when multiple icon sizes
Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/TestBitmap.cs
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/TestBitmap.cs
2007-01-16 16:08:44 UTC (rev 71146)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/TestBitmap.cs
2007-01-16 16:08:58 UTC (rev 71147)
@@ -908,6 +908,39 @@
Assert.IsTrue (image.RawFormat.Equals
(ImageFormat.MemoryBmp), "FromHbitmap.RawFormat");
}
}
+
+ [Test]
+ public void CreateMultipleBitmapFromSameHBITMAP ()
+ {
+ IntPtr hbitmap;
+ string sInFile = TestBitmap.getInFile
("bitmaps/almogaver24bits.bmp");
+ using (Bitmap bitmap = new Bitmap (sInFile)) {
+ Assert.AreEqual (PixelFormat.Format24bppRgb,
bitmap.PixelFormat, "Original.PixelFormat");
+ Assert.AreEqual (0,
bitmap.Palette.Entries.Length, "Original.Palette");
+ Assert.AreEqual (183, bitmap.Height,
"Original.Height");
+ Assert.AreEqual (173, bitmap.Width,
"Original.Width");
+ Assert.AreEqual (73744, bitmap.Flags,
"Original.Flags");
+ Assert.IsTrue (bitmap.RawFormat.Equals
(ImageFormat.Bmp), "Original.RawFormat");
+ hbitmap = bitmap.GetHbitmap ();
+ }
+ // hbitmap survives original bitmap disposal
+ using (Image image = Image.FromHbitmap (hbitmap)) {
+ //Assert.AreEqual (PixelFormat.Format32bppRgb,
image.PixelFormat, "1.PixelFormat");
+ Assert.AreEqual (0,
image.Palette.Entries.Length, "1.Palette");
+ Assert.AreEqual (183, image.Height, "1.Height");
+ Assert.AreEqual (173, image.Width, "1.Width");
+ Assert.AreEqual (335888, image.Flags,
"1.Flags");
+ Assert.IsTrue (image.RawFormat.Equals
(ImageFormat.MemoryBmp), "1.RawFormat");
+ }
+ using (Image image2 = Image.FromHbitmap (hbitmap)) {
+ //Assert.AreEqual (PixelFormat.Format32bppRgb,
image2.PixelFormat, "2.PixelFormat");
+ Assert.AreEqual (0,
image2.Palette.Entries.Length, "2.Palette");
+ Assert.AreEqual (183, image2.Height,
"2.Height");
+ Assert.AreEqual (173, image2.Width, "2.Width");
+ Assert.AreEqual (335888, image2.Flags,
"2.Flags");
+ Assert.IsTrue (image2.RawFormat.Equals
(ImageFormat.MemoryBmp), "2.RawFormat");
+ }
+ }
}
}
Modified: trunk/mcs/class/System.Drawing/Test/System.Drawing/TestIcon.cs
===================================================================
--- trunk/mcs/class/System.Drawing/Test/System.Drawing/TestIcon.cs
2007-01-16 16:08:44 UTC (rev 71146)
+++ trunk/mcs/class/System.Drawing/Test/System.Drawing/TestIcon.cs
2007-01-16 16:08:58 UTC (rev 71147)
@@ -277,7 +277,7 @@
}
}
- internal static void SaveAndCompare (string msg, Icon icon)
+ internal static void SaveAndCompare (string msg, Icon icon,
bool alpha)
{
using (MemoryStream ms = new MemoryStream ()) {
icon.Save (ms);
@@ -286,6 +286,25 @@
using (Icon loaded = new Icon (ms)) {
Assert.AreEqual (icon.Height,
loaded.Height, msg + ".Loaded.Height");
Assert.AreEqual (icon.Width,
loaded.Width, msg + ".Loaded.Width");
+
+ using (Bitmap expected = icon.ToBitmap
()) {
+ using (Bitmap actual =
loaded.ToBitmap ()) {
+ Assert.AreEqual
(expected.Height, actual.Height, msg + ".Bitmap.Height");
+ Assert.AreEqual
(expected.Width, actual.Width, msg + ".Bitmap.Width");
+
+ for (int y = 0; y <
expected.Height; y++) {
+ for (int x = 0;
x < expected.Width; x++) {
+ Color e
= expected.GetPixel (x, y);
+ Color a
= actual.GetPixel (x, y);
+ if
(alpha)
+
Assert.AreEqual (e.A, a.A, String.Format ("{0}:{1}x{2}:A", msg, x, y));
+
Assert.AreEqual (e.R, a.R, String.Format ("{0}:{1}x{2}:R", msg, x, y));
+
Assert.AreEqual (e.G, a.G, String.Format ("{0}:{1}x{2}:G", msg, x, y));
+
Assert.AreEqual (e.B, a.B, String.Format ("{0}:{1}x{2}:B", msg, x, y));
+ }
+ }
+ }
+ }
}
}
}
@@ -296,11 +315,11 @@
#endif
public void Save ()
{
- SaveAndCompare ("16", icon16);
- SaveAndCompare ("32", icon32);
- SaveAndCompare ("48", icon48);
- SaveAndCompare ("64", icon64);
- SaveAndCompare ("96", icon96);
+ SaveAndCompare ("16", icon16, true);
+ SaveAndCompare ("32", icon32, true);
+ SaveAndCompare ("48", icon48, true);
+ SaveAndCompare ("64", icon64, true);
+ SaveAndCompare ("96", icon96, true);
}
[Test]
@@ -427,8 +446,7 @@
Assert.AreEqual (16, icon2.Height,
"FromHandle.Height");
Assert.AreEqual (16, icon2.Width,
"FromHandle.Width");
Assert.AreEqual (handle, icon2.Handle,
"FromHandle.Handle");
-// enable when Save is enabled for re-constructed icons
-// IconTest.SaveAndCompare ("Handle",
icon2);
+ IconTest.SaveAndCompare ("Handle",
icon2, false);
}
}
// unlike other cases (HICON, HBITMAP) handle DOESN'T
survives original icon disposal
@@ -441,6 +459,31 @@
}
[Test]
+ public void CreateMultipleIconFromSameHandle ()
+ {
+ IntPtr handle;
+ using (Icon icon = new Icon (TestBitmap.getInFile
("bitmaps/16x16x16.ico"))) {
+ Assert.AreEqual (16, icon.Height,
"Original.Height");
+ Assert.AreEqual (16, icon.Width,
"Original.Width");
+ handle = icon.Handle;
+ using (Icon icon2 = Icon.FromHandle (handle)) {
+ Assert.AreEqual (16, icon2.Height,
"2.Height");
+ Assert.AreEqual (16, icon2.Width,
"2.Width");
+ Assert.AreEqual (handle, icon2.Handle,
"2.Handle");
+ IconTest.SaveAndCompare ("Handle2",
icon2, false);
+ }
+ using (Icon icon3 = Icon.FromHandle (handle)) {
+ Assert.AreEqual (16, icon3.Height,
"3.Height");
+ Assert.AreEqual (16, icon3.Width,
"3.Width");
+ Assert.AreEqual (handle, icon3.Handle,
"3.Handle");
+ IconTest.SaveAndCompare ("Handle3",
icon3, false);
+ }
+ }
+ // unlike other cases (HICON, HBITMAP) handle DOESN'T
survives original icon disposal
+ // commented / using freed memory is risky ;-)
+ }
+
+ [Test]
public void HiconRoundtrip ()
{
IntPtr handle;
@@ -454,9 +497,32 @@
Assert.AreEqual (16, icon2.Height,
"Survivor.Height");
Assert.AreEqual (16, icon2.Width,
"Survivor.Width");
Assert.AreEqual (handle, icon2.Handle,
"Survivor.Handle");
-// enable when Save is enabled for re-constructed icons
-// IconTest.SaveAndCompare ("HICON", icon2);
+ IconTest.SaveAndCompare ("HICON", icon2, false);
}
}
+
+ [Test]
+ public void CreateMultipleIconFromSameHICON ()
+ {
+ IntPtr handle;
+ using (Icon icon = new Icon (TestBitmap.getInFile
("bitmaps/16x16x16.ico"))) {
+ Assert.AreEqual (16, icon.Height,
"Original.Height");
+ Assert.AreEqual (16, icon.Width,
"Original.Width");
+ handle = icon.ToBitmap ().GetHicon ();
+ }
+ // HICON survives
+ using (Icon icon2 = Icon.FromHandle (handle)) {
+ Assert.AreEqual (16, icon2.Height, "2.Height");
+ Assert.AreEqual (16, icon2.Width, "2.Width");
+ Assert.AreEqual (handle, icon2.Handle,
"2.Handle");
+ IconTest.SaveAndCompare ("HICON2", icon2,
false);
+ }
+ using (Icon icon3 = Icon.FromHandle (handle)) {
+ Assert.AreEqual (16, icon3.Height, "3.Height");
+ Assert.AreEqual (16, icon3.Width, "3.Width");
+ Assert.AreEqual (handle, icon3.Handle,
"3.Handle");
+ IconTest.SaveAndCompare ("HICON", icon3, false);
+ }
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches