* PEAPI.cs: Clean up indentation. Split into ...
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / TestBitmap.cs
index c840c010a4b420b22ccc8fb27efff63011618db0..16f0b4a0056a39f63f1242ea994530f6bb74ec33 100644 (file)
@@ -7,6 +7,29 @@
 //
 // (C) 2004 Ximian, Inc.  http://www.ximian.com
 //
+
+//
+// Copyright (C) 2004 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
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 using System;
 using System.Drawing;
 using System.Drawing.Imaging;
@@ -15,11 +38,13 @@ using System.IO;
 using System.Security.Cryptography;
 using System.Text;
 using System.Runtime.InteropServices;
+using System.Security.Permissions;
 
 namespace MonoTests.System.Drawing{
 
-       [TestFixture]   
-       public class TestBitmap : Assertion {
+       [TestFixture]
+       [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+       public class TestBitmap {
                
                [TearDown]
                public void Clean() {}
@@ -38,15 +63,15 @@ namespace MonoTests.System.Drawing{
                        bmp.SetPixel(0,0,Color.FromArgb(255,128,128,128));                                      
                        Color color = bmp.GetPixel(0,0);                                
                                                
-                       AssertEquals (Color.FromArgb(255,128,128,128), color);
+                       Assert.AreEqual (Color.FromArgb(255,128,128,128), color);
                        
                        bmp.SetPixel(99,99,Color.FromArgb(255,255,0,155));                                      
                        Color color2 = bmp.GetPixel(99,99);                                                                             
-                       AssertEquals (Color.FromArgb(255,255,0,155), color2);                   
+                       Assert.AreEqual (Color.FromArgb(255,255,0,155), color2);                        
                }
                
                /* Get the output directory depending on the runtime and location*/
-               internal string getOutSubDir()
+               public static string getOutSubDir()
                {                               
                        string sSub, sRslt;                     
                        
@@ -68,7 +93,7 @@ namespace MonoTests.System.Drawing{
                }
                
                /* Get the input directory depending on the runtime*/
-               internal string getInFile(string file)
+               public static string getInFile(string file)
                {                               
                        string sRslt;                                           
                        
@@ -80,8 +105,6 @@ namespace MonoTests.System.Drawing{
                        return sRslt;
                }
                
-       
-
                //[Test]
                public void MakeTransparent() 
                {
@@ -89,15 +112,14 @@ namespace MonoTests.System.Drawing{
                        string sOutFile =  getOutSubDir() + "transparent.bmp";
                                                
                        Bitmap  bmp = new Bitmap(sInFile);
-                       Console.WriteLine("Bitmap loaded OK", bmp != null);
                                        
                        bmp.MakeTransparent();
                        bmp.Save(sOutFile);                                                     
                        
                        Color color = bmp.GetPixel(1,1);                                                        
-                       AssertEquals (Color.Black.R, color.R);                                                                                  
-                       AssertEquals (Color.Black.G, color.G);                                                                                  
-                       AssertEquals (Color.Black.B, color.B);                                                                          
+                       Assert.AreEqual (Color.Black.R, color.R);                                                                                       
+                       Assert.AreEqual (Color.Black.G, color.G);                                                                                       
+                       Assert.AreEqual (Color.Black.B, color.B);                                                                               
                }
                
                [Test]
@@ -109,16 +131,15 @@ namespace MonoTests.System.Drawing{
                        Rectangle rect = new Rectangle(0,0,50,50);                                              
                        Bitmap  bmp = new Bitmap(sInFile);                      
                        
-                       Bitmap bmpNew = bmp.Clone (rect, PixelFormat.Format32bppArgb);                  
-                       bmpNew.Save(sOutFile);                                                  
+                       Bitmap bmpNew = bmp.Clone (rect, PixelFormat.Format32bppArgb);                                                                  
                        
                        Color colororg0 = bmp.GetPixel(0,0);            
                        Color colororg50 = bmp.GetPixel(49,49);                                 
                        Color colornew0 = bmpNew.GetPixel(0,0);         
                        Color colornew50 = bmpNew.GetPixel(49,49);                              
                        
-                       AssertEquals (colororg0, colornew0);                                                                                    
-                       AssertEquals (colororg50, colornew50);                          
+                       Assert.AreEqual (colororg0, colornew0);                                                                                 
+                       Assert.AreEqual (colororg50, colornew50);                               
                }       
                
                [Test]
@@ -129,13 +150,13 @@ namespace MonoTests.System.Drawing{
                        
                        Bitmap bmpNew = (Bitmap) bmp.Clone ();                  
                        
-                       AssertEquals (bmp.Width, bmpNew.Width);
-                       AssertEquals (bmp.Height, bmpNew.Height);               
-                       AssertEquals (bmp.PixelFormat, bmpNew.PixelFormat);                     
+                       Assert.AreEqual (bmp.Width, bmpNew.Width);
+                       Assert.AreEqual (bmp.Height, bmpNew.Height);            
+                       Assert.AreEqual (bmp.PixelFormat, bmpNew.PixelFormat);
                        
                }       
 
-               //[Test]
+               [Test]
                public void Frames()
                {
                        string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");                     
@@ -143,8 +164,15 @@ namespace MonoTests.System.Drawing{
                        int cnt = bmp.GetFrameCount(FrameDimension.Page);                       
                        int active = bmp.SelectActiveFrame (FrameDimension.Page, 0);
                        
-                       AssertEquals (1, cnt);                                                          
-                       AssertEquals (0, active);                                                                                       
+                       Assert.AreEqual (1, cnt);                                                               
+                       Assert.AreEqual (0, active);                                                                                    
+               }
+               
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void FileDoesNotExists ()
+               {                       
+                       Bitmap  bmp = new Bitmap ("FileDoesNotExists.jpg");                     
                }
 
                static string ByteArrayToString(byte[] arrInput)
@@ -193,13 +221,13 @@ namespace MonoTests.System.Drawing{
                        string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");     
                        Bitmap  bmp = new Bitmap(sInFile);              
                        
-                       AssertEquals ("312958A3C67402E1299413794988A3", RotateBmp (bmp, RotateFlipType.Rotate90FlipNone));      
-                       AssertEquals ("BF70D8DA4F1545AEDD77D0296B47AE", RotateBmp (bmp, RotateFlipType.Rotate180FlipNone));
-                       AssertEquals ("15AD2ADBDC7090C0EC744D0F7ACE2F", RotateBmp (bmp, RotateFlipType.Rotate270FlipNone));
-                       AssertEquals ("2E10FEC1F4FD64ECC51D7CE68AEB18", RotateBmp (bmp, RotateFlipType.RotateNoneFlipX));
-                       AssertEquals ("E63204779B566ED01162B90B49BD9E", RotateBmp (bmp, RotateFlipType.Rotate90FlipX));
-                       AssertEquals ("B1ECB17B5093E13D04FF55CFCF7763", RotateBmp (bmp, RotateFlipType.Rotate180FlipX));
-                       AssertEquals ("71A173882C16755D86F4BC26532374", RotateBmp (bmp, RotateFlipType.Rotate270FlipX));
+                       Assert.AreEqual ("312958A3C67402E1299413794988A3", RotateBmp (bmp, RotateFlipType.Rotate90FlipNone));   
+                       Assert.AreEqual ("BF70D8DA4F1545AEDD77D0296B47AE", RotateBmp (bmp, RotateFlipType.Rotate180FlipNone));
+                       Assert.AreEqual ("15AD2ADBDC7090C0EC744D0F7ACE2F", RotateBmp (bmp, RotateFlipType.Rotate270FlipNone));
+                       Assert.AreEqual ("2E10FEC1F4FD64ECC51D7CE68AEB18", RotateBmp (bmp, RotateFlipType.RotateNoneFlipX));
+                       Assert.AreEqual ("E63204779B566ED01162B90B49BD9E", RotateBmp (bmp, RotateFlipType.Rotate90FlipX));
+                       Assert.AreEqual ("B1ECB17B5093E13D04FF55CFCF7763", RotateBmp (bmp, RotateFlipType.Rotate180FlipX));
+                       Assert.AreEqual ("71A173882C16755D86F4BC26532374", RotateBmp (bmp, RotateFlipType.Rotate270FlipX));
 
                }
                
@@ -271,7 +299,7 @@ namespace MonoTests.System.Drawing{
                        firsts, changes them, and then using GetPixel does another check of the changes.
                        The results match the .Net framework
                */
-               [Test]
+               //[Test]
                public void LockBitmap ()
                {       
                        string hash = "";               
@@ -279,37 +307,37 @@ namespace MonoTests.System.Drawing{
                                                        
                        /* Locks the whole bitmap*/                     
                        LockBmp (PixelFormat.Format32bppArgb, PixelFormat.Format32bppArgb, "output32bppArgb.bmp", 100, 100, ref hash, ref hashchg);                             
-                       AssertEquals ("AF5BFD4E98D6708FF4C9982CC9C68F", hash);                  
-                       AssertEquals ("BBEE27DC85563CB58EE11E8951230F", hashchg);                       
+                       Assert.AreEqual ("AF5BFD4E98D6708FF4C9982CC9C68F", hash);                       
+                       Assert.AreEqual ("BBEE27DC85563CB58EE11E8951230F", hashchg);                    
                        
                        LockBmp (PixelFormat.Format32bppPArgb, PixelFormat.Format32bppPArgb, "output32bppPArgb.bmp", 100, 100, ref hash, ref hashchg);                  
-                       AssertEquals ("AF5BFD4E98D6708FF4C9982CC9C68F", hash);                  
-                       AssertEquals ("BBEE27DC85563CB58EE11E8951230F", hashchg);                       
+                       Assert.AreEqual ("AF5BFD4E98D6708FF4C9982CC9C68F", hash);                       
+                       Assert.AreEqual ("BBEE27DC85563CB58EE11E8951230F", hashchg);                    
                        
                        LockBmp (PixelFormat.Format32bppRgb, PixelFormat.Format32bppRgb, "output32bppRgb.bmp", 100, 100, ref hash, ref hashchg);
-                       AssertEquals ("AF5BFD4E98D6708FF4C9982CC9C68F", hash);                  
-                       AssertEquals ("BBEE27DC85563CB58EE11E8951230F", hashchg);               
+                       Assert.AreEqual ("AF5BFD4E98D6708FF4C9982CC9C68F", hash);                       
+                       Assert.AreEqual ("BBEE27DC85563CB58EE11E8951230F", hashchg);            
                        
                        LockBmp (PixelFormat.Format24bppRgb, PixelFormat.Format24bppRgb, "output24bppRgb.bmp", 100, 100, ref hash, ref hashchg);
-                       AssertEquals ("A8A071D0B3A3743905B4E193A62769", hash);                  
-                       AssertEquals ("EEE846FA8F892339C64082DFF775CF", hashchg);                                       
+                       Assert.AreEqual ("A8A071D0B3A3743905B4E193A62769", hash);                       
+                       Assert.AreEqual ("EEE846FA8F892339C64082DFF775CF", hashchg);                                    
                        
                        /* Locks a portion of the bitmap*/              
                        LockBmp (PixelFormat.Format32bppArgb, PixelFormat.Format32bppArgb, "output32bppArgb.bmp", 50, 50, ref hash, ref hashchg);                               
-                       AssertEquals ("C361FBFD82A4F3C278605AE9EC5385", hash);                  
-                       AssertEquals ("8C2C04B361E1D5875EE8ACF5073F4E", hashchg);                       
+                       Assert.AreEqual ("C361FBFD82A4F3C278605AE9EC5385", hash);                       
+                       Assert.AreEqual ("8C2C04B361E1D5875EE8ACF5073F4E", hashchg);                    
                        
                        LockBmp (PixelFormat.Format32bppPArgb, PixelFormat.Format32bppPArgb, "output32bppPArgb.bmp", 50, 50, ref hash, ref hashchg);                    
-                       AssertEquals ("C361FBFD82A4F3C278605AE9EC5385", hash);                  
-                       AssertEquals ("8C2C04B361E1D5875EE8ACF5073F4E", hashchg);                       
+                       Assert.AreEqual ("C361FBFD82A4F3C278605AE9EC5385", hash);                       
+                       Assert.AreEqual ("8C2C04B361E1D5875EE8ACF5073F4E", hashchg);                    
                
                        LockBmp (PixelFormat.Format32bppRgb, PixelFormat.Format32bppRgb, "output32bppRgb.bmp", 50, 50, ref hash, ref hashchg);
-                       AssertEquals ("C361FBFD82A4F3C278605AE9EC5385", hash);                  
-                       AssertEquals ("8C2C04B361E1D5875EE8ACF5073F4E", hashchg);                       
+                       Assert.AreEqual ("C361FBFD82A4F3C278605AE9EC5385", hash);                       
+                       Assert.AreEqual ("8C2C04B361E1D5875EE8ACF5073F4E", hashchg);                    
                        
                        LockBmp (PixelFormat.Format24bppRgb, PixelFormat.Format24bppRgb, "output24bppRgb.bmp", 50, 50, ref hash, ref hashchg);
-                       AssertEquals ("FFE86628478591D1A1EB30E894C34F", hash);                  
-                       AssertEquals ("8C2C04B361E1D5875EE8ACF5073F4E", hashchg);                               
+                       Assert.AreEqual ("FFE86628478591D1A1EB30E894C34F", hash);                       
+                       Assert.AreEqual ("8C2C04B361E1D5875EE8ACF5073F4E", hashchg);                            
                                                
                }