JpegCodec Testcase
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Imaging / TestJpegCodec.cs
1 //
2 // JpegCodec 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 using System;
11 using System.Drawing;
12 using System.Drawing.Imaging;
13 using NUnit.Framework;
14 using System.IO;
15
16 namespace MonoTests.System.Drawing
17 {
18
19         [TestFixture]   
20         public class TestJpegCodec : Assertion 
21         {
22                 
23                 [TearDown]
24                 public void Clean() {}
25                 
26                 [SetUp]
27                 public void GetReady()          
28                 {
29                 
30                 }
31                 
32                 /* Get the output directory depending on the runtime and location*/
33                 internal string getOutSubDir()
34                 {                               
35                         string sSub, sRslt;                     
36                         
37                         if (Environment.GetEnvironmentVariable("MSNet")==null)
38                                 sSub = "mono/";
39                         else
40                                 sSub = "MSNet/";                        
41                         
42                         sRslt = Path.GetFullPath ("../System.Drawing/" +  sSub);
43                                 
44                         if (Directory.Exists(sRslt) ==  false) 
45                                 sRslt = "Test/System.Drawing/" + sSub;                                                  
46                         
47                         if (sRslt.Length > 0)
48                                 if (sRslt[sRslt.Length-1] != '\\' && sRslt[sRslt.Length-1] != '/')
49                                         sRslt += "/";                                   
50                         return sRslt;
51                 }
52
53                 /* Get the input directory depending on the runtime*/
54                 internal string getInFile(string file)
55                 {                               
56                         string sRslt, local;                                            
57
58                         local = "../System.Drawing/" + file;
59                         
60                         sRslt = Path.GetFullPath (local);
61                                 
62                         if (File.Exists(sRslt)==false) 
63                                 sRslt = "Test/System.Drawing/" + file;                                                  
64                         
65                         return sRslt;
66                 }
67                 
68                 /* Checks bitmap features on a know 24-bits bitmap */
69                 [Test]
70                 public void Bitmap24bitFeatures()
71                 {
72                         string sInFile = getInFile ("bitmaps/nature24bits.jpg");
73                         Bitmap  bmp = new Bitmap(sInFile);                                              
74                         RectangleF rect;
75                         GraphicsUnit unit = GraphicsUnit.World;
76                         
77                         rect = bmp.GetBounds(ref unit);
78
79                         AssertEquals (PixelFormat.Format24bppRgb, bmp.PixelFormat);
80                         AssertEquals (110, bmp.Width);
81                         AssertEquals (100, bmp.Height);         
82                         
83                         AssertEquals (0, rect.X);
84                         AssertEquals (0, rect.Y);               
85                         AssertEquals (110, rect.Width);
86                         AssertEquals (100, rect.Height);                                        
87                         
88                         AssertEquals (110, bmp.Size.Width);
89                         AssertEquals (100, bmp.Size.Height);
90                         
91                 }
92
93                 [Test]
94                 public void Save() 
95                 {                               
96                         string sOutFile =  getOutSubDir() + "linerect.jpeg";
97                                                 
98                         // Save         
99                         Bitmap  bmp = new Bitmap(100,100, PixelFormat.Format32bppRgb);                                          
100                         Graphics gr = Graphics.FromImage(bmp);          
101                         
102                         Pen p = new Pen(Color.Red, 2);
103                         gr.DrawLine(p, 10.0F, 10.0F, 90.0F, 90.0F);
104                         gr.DrawRectangle(p, 10.0F, 10.0F, 80.0F, 80.0F);
105                         p.Dispose();                                    
106                         bmp.Save(sOutFile, ImageFormat.Bmp);
107                         gr.Dispose();
108                         bmp.Dispose();                                                  
109                         
110                         // Load                 
111                         Bitmap  bmpLoad = new Bitmap(sOutFile);                                 
112                         
113                         Color color = bmpLoad.GetPixel(10,10);                                  
114                         
115                         AssertEquals (Color.FromArgb(255,255,0,0), color);                                                                                      
116                 }
117
118                 
119         }
120 }