New test.
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Imaging / TestImageCodecInfo.cs
1 //
2 // ImageCodecInfo class testing unit
3 //
4 // Author:
5 //       Jordi Mas i Hernàndez (jordi@ximian.com)
6 //
7 // (C) 2004 Ximian, Inc.  http://www.ximian.com
8 // Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Drawing;
32 using System.Drawing.Imaging;
33 using NUnit.Framework;
34 using System.Collections;
35 using System.Security.Permissions;
36 using System.Text.RegularExpressions;
37
38 namespace MonoTests.System.Drawing.Imaging {
39
40         [TestFixture]
41         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
42         public class ImageCodecInfoTest {
43
44                 Hashtable decoders;
45                 Hashtable encoders;
46
47                 ImageCodecInfo GetEncoder (Guid clsid)
48                 {
49                         return (ImageCodecInfo) encoders [clsid];
50                 }
51
52                 ImageCodecInfo GetDecoder (Guid clsid) {
53                         return (ImageCodecInfo) decoders [clsid];
54                 }
55
56                 [TestFixtureSetUp]
57                 public void FixtureGetReady()           
58                 {
59                         ImageCodecInfo [] arrEnc  = ImageCodecInfo.GetImageDecoders ();
60                         ImageCodecInfo [] arrDec = ImageCodecInfo.GetImageEncoders ();
61                         decoders = new Hashtable ();
62                         encoders = new Hashtable ();
63
64                         foreach (ImageCodecInfo decoder in arrDec)
65                                 decoders[decoder.Clsid] = decoder;
66                 
67                         foreach (ImageCodecInfo encoder in arrEnc)
68                                 encoders[encoder.Clsid] = encoder;
69                 }
70
71                 static void Check (ImageCodecInfo e, ImageCodecInfo d, Guid FormatID, string CodecName, string DllName,
72                         string FilenameExtension, ImageCodecFlags Flags, string FormatDescription,
73                         string MimeType, int Version)
74                 {
75                         Regex extRegex = new Regex (@"^(\*\.\w+(;(\*\.\w+))*;)?"+
76                                 Regex.Escape (FilenameExtension)+@"(;\*\.\w+(;(\*\.\w+))*)?$",
77                                 RegexOptions.IgnoreCase | RegexOptions.Singleline);
78
79                         if (e != null) {
80                                 Assert.AreEqual (FormatID, e.FormatID, "Encoder.FormatID");
81                                 Assert.IsTrue (e.CodecName.IndexOf (CodecName)>=0,
82                                         "Encoder.CodecName contains "+CodecName);
83                                 Assert.AreEqual (DllName, e.DllName, "Encoder.DllName");
84                                 Assert.IsTrue (extRegex.IsMatch (e.FilenameExtension),
85                                         "Encoder.FilenameExtension is a right list with "+FilenameExtension);
86                                 Assert.AreEqual (Flags, e.Flags, "Encoder.Flags");
87                                 Assert.IsTrue (e.FormatDescription.IndexOf (FormatDescription)>=0,
88                                         "Encoder.FormatDescription contains "+FormatDescription);
89                                 Assert.IsTrue (e.MimeType.IndexOf (MimeType)>=0,
90                                         "Encoder.MimeType contains "+MimeType);
91                         }
92                         if (d != null) {
93                                 Assert.AreEqual (FormatID, d.FormatID, "Decoder.FormatID");
94                                 Assert.IsTrue (d.CodecName.IndexOf (CodecName)>=0,
95                                         "Decoder.CodecName contains "+CodecName);
96                                 Assert.AreEqual (DllName, d.DllName, "Decoder.DllName");
97                                 Assert.IsTrue (extRegex.IsMatch (d.FilenameExtension),
98                                         "Decoder.FilenameExtension is a right list with "+FilenameExtension);
99                                 Assert.AreEqual (Flags, d.Flags, "Decoder.Flags");
100                                 Assert.IsTrue (d.FormatDescription.IndexOf (FormatDescription)>=0,
101                                         "Decoder.FormatDescription contains "+FormatDescription);
102                                 Assert.IsTrue (d.MimeType.IndexOf (MimeType)>=0,
103                                         "Decoder.MimeType contains "+MimeType);
104                         }
105                         /*
106                         if (SignatureMasks == null) {
107                                 Assert.AreEqual (null, e.SignatureMasks, "Encoder.SignatureMasks");
108                                 Assert.AreEqual (null, d.SignatureMasks, "Decoder.SignatureMasks");
109                         }
110                         else {
111                                 Assert.AreEqual (SignatureMasks.Length, e.SignatureMasks.Length, "Encoder.SignatureMasks.Length");
112                                 Assert.AreEqual (SignatureMasks.Length, d.SignatureMasks.Length, "Decoder.SignatureMasks.Length");
113                                 for (int i = 0; i < SignatureMasks.Length; i++) {
114                                         Assert.AreEqual (SignatureMasks[i].Length, e.SignatureMasks[i].Length,
115                                                 "Encoder.SignatureMasks["+i.ToString ()+"].Length");
116                                         Assert.AreEqual (SignatureMasks[i].Length, d.SignatureMasks[i].Length,
117                                                 "Decoder.SignatureMasks["+i.ToString ()+"].Length");
118                                         for (int j = 0; j < SignatureMasks[i].Length; j++) {
119                                                 Assert.AreEqual (SignatureMasks[i][j], e.SignatureMasks[i][j],
120                                                         "Encoder.SignatureMasks["+i.ToString ()+"]["+j.ToString ()+"]");
121                                                 Assert.AreEqual (SignatureMasks[i][j], d.SignatureMasks[i][j],
122                                                         "Decoder.SignatureMasks["+i.ToString ()+"]["+j.ToString ()+"]");
123                                         }
124                                 }
125                         }
126                         */
127                         
128                 }
129
130                 [Test]
131 #if TARGET_JVM
132                 [Category ("NotWorking")]
133 #endif
134                 public void BMPCodec()
135                 {
136                         Guid g = new Guid ("557cf400-1a04-11d3-9a73-0000f81ef32e");
137                         Check (GetEncoder (g), GetDecoder (g), ImageFormat.Bmp.Guid,
138                                 "BMP", null, "*.BMP",
139                                 ImageCodecFlags.Builtin|ImageCodecFlags.Encoder|ImageCodecFlags.Decoder|ImageCodecFlags.SupportBitmap,
140                                 "BMP", "image/bmp", 1);
141                 }
142
143                 [Test]
144 #if TARGET_JVM
145                 [Category ("NotWorking")]
146 #endif
147                 public void GifCodec()
148                 {
149                         Guid g = new Guid ("557cf402-1a04-11d3-9a73-0000f81ef32e");
150                         Check (GetEncoder (g), GetDecoder (g), ImageFormat.Gif.Guid,
151                                 "GIF", null, "*.GIF",
152                                 ImageCodecFlags.Builtin|ImageCodecFlags.Encoder|ImageCodecFlags.Decoder|ImageCodecFlags.SupportBitmap,
153                                 "GIF", "image/gif", 1);
154                 }
155                 
156                 [Test]
157 #if TARGET_JVM
158                 [Category ("NotWorking")]
159 #endif
160                 public void JpegCodec()
161                 {
162                         Guid g = new Guid ("557cf401-1a04-11d3-9a73-0000f81ef32e");
163                         Check (GetEncoder (g), GetDecoder (g), ImageFormat.Jpeg.Guid,
164                                 "JPEG", null, "*.JPG",
165                                 ImageCodecFlags.Builtin|ImageCodecFlags.Encoder|ImageCodecFlags.Decoder|ImageCodecFlags.SupportBitmap,
166                                 "JPEG", "image/jpeg", 1);
167                 }
168
169                 [Test]
170 #if TARGET_JVM
171                 [Category ("NotWorking")]
172 #endif
173                 public void PngCodec()
174                 {
175                         Guid g = new Guid ("557cf406-1a04-11d3-9a73-0000f81ef32e");
176                         Check (GetEncoder (g), GetDecoder (g), ImageFormat.Png.Guid,
177                                 "PNG", null, "*.PNG",
178                                 ImageCodecFlags.Builtin|ImageCodecFlags.Encoder|ImageCodecFlags.Decoder|ImageCodecFlags.SupportBitmap,
179                                 "PNG", "image/png", 1);
180                 }
181                 [Test]
182                 public void IconCodec() {
183                         Guid g = new Guid ("557cf407-1a04-11d3-9a73-0000f81ef32e");
184                         Check (null, GetDecoder (g), ImageFormat.Bmp.Guid,
185                                 "ICO", null, "*.ICO",
186                                 ImageCodecFlags.Builtin|ImageCodecFlags.Encoder|ImageCodecFlags.SupportBitmap,
187                                 "ICO", "image/x-icon", 1);
188                 }
189
190         }
191 }