2 // ImageCodecInfo class testing unit
5 // Jordi Mas i Hernàndez (jordi@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) 2004 Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2004-2007 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Drawing.Imaging;
34 using NUnit.Framework;
35 using System.Collections;
36 using System.Security.Permissions;
37 using System.Text.RegularExpressions;
39 namespace MonoTests.System.Drawing.Imaging {
42 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
43 public class ImageCodecInfoTest {
48 ImageCodecInfo GetEncoder (Guid clsid)
50 return (ImageCodecInfo) encoders [clsid];
53 ImageCodecInfo GetDecoder (Guid clsid) {
54 return (ImageCodecInfo) decoders [clsid];
58 public void FixtureGetReady()
60 decoders = new Hashtable ();
61 encoders = new Hashtable ();
63 foreach (ImageCodecInfo decoder in ImageCodecInfo.GetImageDecoders ())
64 decoders[decoder.Clsid] = decoder;
66 foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders ())
67 encoders[encoder.Clsid] = encoder;
70 static void Check (ImageCodecInfo e, ImageCodecInfo d, Guid FormatID, string CodecName, string DllName,
71 string FilenameExtension, ImageCodecFlags Flags, string FormatDescription,
72 string MimeType, int Version, int signatureLength, string mask, string pattern, string pattern2)
74 Regex extRegex = new Regex (@"^(\*\.\w+(;(\*\.\w+))*;)?"+
75 Regex.Escape (FilenameExtension)+@"(;\*\.\w+(;(\*\.\w+))*)?$",
76 RegexOptions.IgnoreCase | RegexOptions.Singleline);
79 Assert.AreEqual (FormatID, e.FormatID, "Encoder.FormatID");
80 Assert.IsTrue (e.CodecName.IndexOf (CodecName)>=0,
81 "Encoder.CodecName contains "+CodecName);
82 Assert.AreEqual (DllName, e.DllName, "Encoder.DllName");
83 Assert.IsTrue (extRegex.IsMatch (e.FilenameExtension),
84 "Encoder.FilenameExtension is a right list with "+FilenameExtension);
85 Assert.AreEqual (Flags, e.Flags, "Encoder.Flags");
86 Assert.IsTrue (e.FormatDescription.IndexOf (FormatDescription)>=0,
87 "Encoder.FormatDescription contains "+FormatDescription);
88 Assert.IsTrue (e.MimeType.IndexOf (MimeType)>=0,
89 "Encoder.MimeType contains "+MimeType);
91 Assert.AreEqual (signatureLength, e.SignatureMasks.Length, "Encoder.SignatureMasks.Length");
92 for (int i = 0; i < signatureLength; i++) {
93 Assert.AreEqual (mask, BitConverter.ToString (e.SignatureMasks[i]), String.Format ("Encoder.SignatureMasks[{0}]", i));
95 Assert.AreEqual (signatureLength, e.SignaturePatterns.Length, "Encoder.SignaturePatterns.Length");
96 Assert.AreEqual (pattern, BitConverter.ToString (e.SignaturePatterns[0]), "Encoder.SignaturePatterns[0]");
98 Assert.AreEqual (pattern2, BitConverter.ToString (e.SignaturePatterns[1]), "Encoder.SignaturePatterns[1]");
101 Assert.AreEqual (FormatID, d.FormatID, "Decoder.FormatID");
102 Assert.IsTrue (d.CodecName.IndexOf (CodecName)>=0,
103 "Decoder.CodecName contains "+CodecName);
104 Assert.AreEqual (DllName, d.DllName, "Decoder.DllName");
105 Assert.IsTrue (extRegex.IsMatch (d.FilenameExtension),
106 "Decoder.FilenameExtension is a right list with "+FilenameExtension);
107 Assert.AreEqual (Flags, d.Flags, "Decoder.Flags");
108 Assert.IsTrue (d.FormatDescription.IndexOf (FormatDescription)>=0,
109 "Decoder.FormatDescription contains "+FormatDescription);
110 Assert.IsTrue (d.MimeType.IndexOf (MimeType)>=0,
111 "Decoder.MimeType contains "+MimeType);
113 Assert.AreEqual (signatureLength, d.SignatureMasks.Length, "Decoder.SignatureMasks.Length");
114 for (int i = 0; i < signatureLength; i++) {
115 Assert.AreEqual (mask, BitConverter.ToString (d.SignatureMasks[i]), String.Format ("Decoder.SignatureMasks[{0}]", i));
117 Assert.AreEqual (signatureLength, d.SignaturePatterns.Length, "Decoder.SignaturePatterns.Length");
118 Assert.AreEqual (pattern, BitConverter.ToString (d.SignaturePatterns[0]), "Decoder.SignaturePatterns[0]");
119 if (pattern2 != null)
120 Assert.AreEqual (pattern2, BitConverter.ToString (d.SignaturePatterns[1]), "Decoder.SignaturePatterns[1]");
126 [Category ("NotWorking")]
128 public void Decoders ()
130 Assert.AreEqual (8, decoders.Count, "Count");
131 foreach (DictionaryEntry de in decoders) {
132 string guid = de.Key.ToString ();
134 case "557cf402-1a04-11d3-9a73-0000f81ef32e": // GIF
135 case "557cf403-1a04-11d3-9a73-0000f81ef32e": // EMF
136 case "557cf400-1a04-11d3-9a73-0000f81ef32e": // BMP/DIB/RLE
137 case "557cf401-1a04-11d3-9a73-0000f81ef32e": // JPG,JPEG,JPE,JFIF
138 case "557cf406-1a04-11d3-9a73-0000f81ef32e": // PNG
139 case "557cf407-1a04-11d3-9a73-0000f81ef32e": // ICO
140 case "557cf404-1a04-11d3-9a73-0000f81ef32e": // WMF
141 case "557cf405-1a04-11d3-9a73-0000f81ef32e": // TIF,TIFF
144 Assert.Ignore ("Unknown decoder " + guid);
152 [Category ("NotWorking")]
154 public void Encoders ()
156 Assert.AreEqual (5, encoders.Count, "Count");
157 foreach (DictionaryEntry de in encoders) {
158 string guid = de.Key.ToString ();
160 case "557cf402-1a04-11d3-9a73-0000f81ef32e": // GIF
161 case "557cf400-1a04-11d3-9a73-0000f81ef32e": // BMP/DIB/RLE
162 case "557cf401-1a04-11d3-9a73-0000f81ef32e": // JPG,JPEG,JPE,JFIF
163 case "557cf406-1a04-11d3-9a73-0000f81ef32e": // PNG
164 case "557cf405-1a04-11d3-9a73-0000f81ef32e": // TIF,TIFF
167 Assert.Ignore ("Unknown encoder " + guid);
175 [Category ("NotWorking")]
177 public void BMPCodec()
179 Guid g = new Guid ("557cf400-1a04-11d3-9a73-0000f81ef32e");
180 Check (GetEncoder (g), GetDecoder (g), ImageFormat.Bmp.Guid,
181 "BMP", null, "*.BMP",
182 ImageCodecFlags.Builtin | ImageCodecFlags.Encoder | ImageCodecFlags.Decoder | ImageCodecFlags.SupportBitmap,
183 "BMP", "image/bmp", 1, 1, "FF-FF", "42-4D", null);
188 [Category ("NotWorking")]
190 public void GifCodec()
192 Guid g = new Guid ("557cf402-1a04-11d3-9a73-0000f81ef32e");
193 Check (GetEncoder (g), GetDecoder (g), ImageFormat.Gif.Guid,
194 "GIF", null, "*.GIF",
195 ImageCodecFlags.Builtin|ImageCodecFlags.Encoder|ImageCodecFlags.Decoder|ImageCodecFlags.SupportBitmap,
196 "GIF", "image/gif", 1, 2, "FF-FF-FF-FF-FF-FF", "47-49-46-38-39-61", "47-49-46-38-37-61");
201 [Category ("NotWorking")]
203 public void JpegCodec()
205 Guid g = new Guid ("557cf401-1a04-11d3-9a73-0000f81ef32e");
206 Check (GetEncoder (g), GetDecoder (g), ImageFormat.Jpeg.Guid,
207 "JPEG", null, "*.JPG",
208 ImageCodecFlags.Builtin|ImageCodecFlags.Encoder|ImageCodecFlags.Decoder|ImageCodecFlags.SupportBitmap,
209 "JPEG", "image/jpeg", 1, 1, "FF-FF", "FF-D8", null);
214 [Category ("NotWorking")]
216 public void PngCodec()
218 Guid g = new Guid ("557cf406-1a04-11d3-9a73-0000f81ef32e");
219 Check (GetEncoder (g), GetDecoder (g), ImageFormat.Png.Guid,
220 "PNG", null, "*.PNG",
221 ImageCodecFlags.Builtin|ImageCodecFlags.Encoder|ImageCodecFlags.Decoder|ImageCodecFlags.SupportBitmap,
222 "PNG", "image/png", 1, 1, "FF-FF-FF-FF-FF-FF-FF-FF", "89-50-4E-47-0D-0A-1A-0A", null);
227 [Category ("NotWorking")]
229 public void TiffCodec ()
231 Guid g = new Guid ("557cf405-1a04-11d3-9a73-0000f81ef32e");
232 Check (GetEncoder (g), GetDecoder (g), ImageFormat.Tiff.Guid,
233 "TIFF", null, "*.TIF;*.TIFF",
234 ImageCodecFlags.Builtin | ImageCodecFlags.Encoder | ImageCodecFlags.Decoder | ImageCodecFlags.SupportBitmap,
235 "TIFF", "image/tiff", 1, 2, "FF-FF", "49-49", "4D-4D");
240 [Category ("NotWorking")]
242 public void IconCodec_Encoder ()
244 Guid g = new Guid ("557cf407-1a04-11d3-9a73-0000f81ef32e");
245 Assert.IsNull (GetEncoder (g), "Encoder");
250 [Category ("NotWorking")]
252 public void IconCodec_Decoder ()
254 Guid g = new Guid ("557cf407-1a04-11d3-9a73-0000f81ef32e");
255 Check (null, GetDecoder (g), ImageFormat.Icon.Guid,
256 "ICO", null, "*.ICO",
257 ImageCodecFlags.Builtin | ImageCodecFlags.Decoder | ImageCodecFlags.SupportBitmap,
258 "ICO", "image/x-icon", 1, 1, "FF-FF-FF-FF", "00-00-01-00", null);
263 [Category ("NotWorking")]
265 public void EmfCodec_Encoder ()
267 Guid g = new Guid ("557cf403-1a04-11d3-9a73-0000f81ef32e");
268 Assert.IsNull (GetEncoder (g), "Encoder");
273 [Category ("NotWorking")]
275 public void EmfCodec_Decoder ()
277 Guid g = new Guid ("557cf403-1a04-11d3-9a73-0000f81ef32e");
278 Check (null, GetDecoder (g), ImageFormat.Emf.Guid,
279 "EMF", null, "*.EMF",
280 ImageCodecFlags.Builtin | ImageCodecFlags.Decoder | ImageCodecFlags.SupportBitmap,
281 "EMF", "image/x-emf", 1, 1, "00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-FF-FF-FF-FF",
282 "00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-20-45-4D-46", null);
287 [Category ("NotWorking")]
289 public void WmfCodec_Encoder ()
291 Guid g = new Guid ("557cf404-1a04-11d3-9a73-0000f81ef32e");
292 Assert.IsNull (GetEncoder (g), "Encoder");
297 [Category ("NotWorking")]
299 public void WmfCodec_Decoder ()
301 Guid g = new Guid ("557cf404-1a04-11d3-9a73-0000f81ef32e");
302 Check (null, GetDecoder (g), ImageFormat.Wmf.Guid,
303 "WMF", null, "*.WMF",
304 ImageCodecFlags.Builtin | ImageCodecFlags.Decoder | ImageCodecFlags.SupportBitmap,
305 "WMF", "image/x-wmf", 1, 1, "FF-FF-FF-FF", "D7-CD-C6-9A", null);