2006-04-25 Peter Dennis Bartok <pbartok@novell.com>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Imaging / TestBmpCodec.cs
1 //
2 // BMPCodec class testing unit
3 //
4 // Author:
5 //
6 //       Jordi Mas i Hernàndez (jordi@ximian.com)
7 //
8 // (C) 2004 Ximian, Inc.  http://www.ximian.com
9 //
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
21 // 
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
24 // 
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 //
33 using System;
34 using System.Drawing;
35 using System.Drawing.Imaging;
36 using NUnit.Framework;
37 using System.IO;
38 using System.Security.Cryptography;
39 using System.Security.Permissions;
40 using System.Text;
41
42 namespace MonoTests.System.Drawing
43 {
44
45         [TestFixture]
46         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
47         public class TestBmpCodec
48         {
49                 
50                 [TearDown]
51                 public void Clean() {}
52                 
53                 [SetUp]
54                 public void GetReady()          
55                 {
56                 
57                 }
58                 
59                 /* Get suffix to add to the filename */
60                 internal string getOutSufix()
61                 {                       
62                         if (Environment.GetEnvironmentVariable("MSNet")==null)
63                                 return "-mono";
64                                         
65                         return "";
66                 }
67
68                 /* Get the input directory depending on the runtime*/
69                 internal string getInFile(string file)
70                 {                               
71                         string sRslt, local;                                            
72
73                         local = "../System.Drawing/" + file;
74                         
75                         sRslt = Path.GetFullPath (local);
76                                 
77                         if (File.Exists(sRslt)==false) 
78                                 sRslt = "Test/System.Drawing/" + file;                                                  
79                         
80                         return sRslt;
81                 }
82                 
83                 /* Checks bitmap features on a know 24-bits bitmap */
84                 [Test]
85 #if TARGET_JVM
86                 [NUnit.Framework.Category ("NotWorking")]
87 #endif
88                 [Category("NotWorking")]
89                 public void Bitmap24bitFeatures()
90                 {
91                         string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");                     
92                         Bitmap  bmp = new Bitmap(sInFile);                                              
93                         RectangleF rect;
94                         GraphicsUnit unit = GraphicsUnit.World;
95                         
96                         rect = bmp.GetBounds(ref unit);
97                         
98                         Assert.AreEqual (PixelFormat.Format24bppRgb, bmp.PixelFormat);
99                         Assert.AreEqual (173, bmp.Width);
100                         Assert.AreEqual (183, bmp.Height);              
101                         
102                         Assert.AreEqual (0, rect.X);
103                         Assert.AreEqual (0, rect.Y);            
104                         Assert.AreEqual (173, rect.Width);
105                         Assert.AreEqual (183, rect.Height);                                     
106                         
107                         Assert.AreEqual (173, bmp.Size.Width);
108                         Assert.AreEqual (183, bmp.Size.Height);                                 
109                 }
110
111                 
112
113                 /* Checks bitmap features on a know 32-bits bitmap (codec)*/
114                 [Test]
115                 public void Bitmap32bitFeatures()
116                 {
117                         string sInFile = getInFile ("bitmaps/almogaver32bits.bmp");
118                         Bitmap  bmp = new Bitmap(sInFile);                                              
119                         RectangleF rect;
120                         GraphicsUnit unit = GraphicsUnit.World;
121                         
122                         rect = bmp.GetBounds(ref unit); 
123
124                         Assert.AreEqual (173, bmp.Width);
125                         Assert.AreEqual (183, bmp.Height);              
126                         
127                         Assert.AreEqual (0, rect.X);
128                         Assert.AreEqual (0, rect.Y);            
129                         Assert.AreEqual (173, rect.Width);
130                         Assert.AreEqual (183, rect.Height);                                     
131                         
132                         Assert.AreEqual (173, bmp.Size.Width);
133                         Assert.AreEqual (183, bmp.Size.Height);                                 
134                 }
135
136                 [Test]
137                 public void Save() 
138                 {                               
139                         string sOutFile =  "linerect" + getOutSufix() + ".bmp";
140                                                 
141                         // Save         
142                         Bitmap  bmp = new Bitmap(100,100, PixelFormat.Format32bppRgb);                                          
143                         Graphics gr = Graphics.FromImage(bmp);          
144                         
145                         Pen p = new Pen(Color.Red, 2);
146                         gr.DrawLine(p, 10.0F, 10.0F, 90.0F, 90.0F);
147                         gr.DrawRectangle(p, 10.0F, 10.0F, 80.0F, 80.0F);
148                         p.Dispose();                                    
149                         bmp.Save(sOutFile, ImageFormat.Bmp);
150                         gr.Dispose();
151                         bmp.Dispose();                                                  
152                         
153                         // Load                 
154                         Bitmap  bmpLoad = new Bitmap(sOutFile);                                 
155                         
156                         Color color = bmpLoad.GetPixel(10,10);                                  
157                         
158                         //Assert.AreEqual (Color.FromArgb(255,255,0,0), color);                                                                                 
159                 }
160
161                 
162         }
163 }