2 // ImageCodecInfo class testing unit
5 // Jordi Mas i Hernàndez (jordi@ximian.com)
7 // (C) 2004 Ximian, Inc. http://www.ximian.com
8 // Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 using System.Drawing.Imaging;
33 using NUnit.Framework;
34 using System.Collections;
35 using System.Security.Permissions;
36 using System.Text.RegularExpressions;
38 namespace MonoTests.System.Drawing.Imaging {
41 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
42 public class ImageCodecInfoTest {
47 ImageCodecInfo GetEncoder (Guid clsid)
49 return (ImageCodecInfo) encoders [clsid];
52 ImageCodecInfo GetDecoder (Guid clsid) {
53 return (ImageCodecInfo) decoders [clsid];
57 public void FixtureGetReady()
59 ImageCodecInfo [] arrEnc = ImageCodecInfo.GetImageDecoders ();
60 ImageCodecInfo [] arrDec = ImageCodecInfo.GetImageEncoders ();
61 decoders = new Hashtable ();
62 encoders = new Hashtable ();
64 foreach (ImageCodecInfo decoder in arrDec)
65 decoders[decoder.Clsid] = decoder;
67 foreach (ImageCodecInfo encoder in arrEnc)
68 encoders[encoder.Clsid] = encoder;
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)
75 Regex extRegex = new Regex (@"^(\*\.\w+(;(\*\.\w+))*;)?"+
76 Regex.Escape (FilenameExtension)+@"(;\*\.\w+(;(\*\.\w+))*)?$",
77 RegexOptions.IgnoreCase | RegexOptions.Singleline);
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);
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);
106 if (SignatureMasks == null) {
107 Assert.AreEqual (null, e.SignatureMasks, "Encoder.SignatureMasks");
108 Assert.AreEqual (null, d.SignatureMasks, "Decoder.SignatureMasks");
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 ()+"]");
132 [Category ("NotWorking")]
134 public void BMPCodec()
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);
145 [Category ("NotWorking")]
147 public void GifCodec()
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);
158 [Category ("NotWorking")]
160 public void JpegCodec()
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);
171 [Category ("NotWorking")]
173 public void PngCodec()
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);
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);