2 // BMPCodec class testing unit
6 // Jordi Mas i Hernàndez (jordi@ximian.com)
8 // (C) 2004 Ximian, Inc. http://www.ximian.com
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
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.
35 using System.Drawing.Imaging;
36 using NUnit.Framework;
38 using System.Security.Cryptography;
41 namespace MonoTests.System.Drawing
45 public class TestBmpCodec
49 public void Clean() {}
52 public void GetReady()
57 /* Get suffix to add to the filename */
58 internal string getOutSufix()
60 if (Environment.GetEnvironmentVariable("MSNet")==null)
66 /* Get the input directory depending on the runtime*/
67 internal string getInFile(string file)
71 local = "../System.Drawing/" + file;
73 sRslt = Path.GetFullPath (local);
75 if (File.Exists(sRslt)==false)
76 sRslt = "Test/System.Drawing/" + file;
81 /* Checks bitmap features on a know 24-bits bitmap */
83 public void Bitmap24bitFeatures()
85 string sInFile = getInFile ("bitmaps/almogaver24bits.bmp");
86 Console.WriteLine ("openning " + sInFile);
87 Bitmap bmp = new Bitmap(sInFile);
89 GraphicsUnit unit = GraphicsUnit.World;
91 rect = bmp.GetBounds(ref unit);
93 Assert.AreEqual (PixelFormat.Format24bppRgb, bmp.PixelFormat);
94 Assert.AreEqual (173, bmp.Width);
95 Assert.AreEqual (183, bmp.Height);
97 Assert.AreEqual (0, rect.X);
98 Assert.AreEqual (0, rect.Y);
99 Assert.AreEqual (173, rect.Width);
100 Assert.AreEqual (183, rect.Height);
102 Assert.AreEqual (173, bmp.Size.Width);
103 Assert.AreEqual (183, bmp.Size.Height);
108 /* Checks bitmap features on a know 32-bits bitmap (codec)*/
110 public void Bitmap32bitFeatures()
112 string sInFile = getInFile ("bitmaps/almogaver32bits.bmp");
113 Bitmap bmp = new Bitmap(sInFile);
115 GraphicsUnit unit = GraphicsUnit.World;
117 rect = bmp.GetBounds(ref unit);
119 Assert.AreEqual (PixelFormat.Format32bppArgb, bmp.PixelFormat);
120 Assert.AreEqual (173, bmp.Width);
121 Assert.AreEqual (183, bmp.Height);
123 Assert.AreEqual (0, rect.X);
124 Assert.AreEqual (0, rect.Y);
125 Assert.AreEqual (173, rect.Width);
126 Assert.AreEqual (183, rect.Height);
128 Assert.AreEqual (173, bmp.Size.Width);
129 Assert.AreEqual (183, bmp.Size.Height);
135 string sOutFile = "linerect" + getOutSufix() + ".bmp";
138 Bitmap bmp = new Bitmap(100,100, PixelFormat.Format32bppRgb);
139 Graphics gr = Graphics.FromImage(bmp);
141 Pen p = new Pen(Color.Red, 2);
142 gr.DrawLine(p, 10.0F, 10.0F, 90.0F, 90.0F);
143 gr.DrawRectangle(p, 10.0F, 10.0F, 80.0F, 80.0F);
145 bmp.Save(sOutFile, ImageFormat.Bmp);
150 Bitmap bmpLoad = new Bitmap(sOutFile);
152 Color color = bmpLoad.GetPixel(10,10);
154 //Assert.AreEqual (Color.FromArgb(255,255,0,0), color);