[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Imaging / TestImageCodecInfo.cs
1 //
2 // ImageCodecInfo class testing unit
3 //
4 // Authors:
5 //      Jordi Mas i Hernàndez (jordi@ximian.com)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // (C) 2004 Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2004-2007 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System;
32 using System.Drawing;
33 using System.Drawing.Imaging;
34 using NUnit.Framework;
35 using System.Collections;
36 using System.Security.Permissions;
37 using System.Text.RegularExpressions;
38
39 namespace MonoTests.System.Drawing.Imaging {
40
41         [TestFixture]
42         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
43         public class ImageCodecInfoTest {
44
45                 Hashtable decoders;
46                 Hashtable encoders;
47
48                 ImageCodecInfo GetEncoder (Guid clsid)
49                 {
50                         return (ImageCodecInfo) encoders [clsid];
51                 }
52
53                 ImageCodecInfo GetDecoder (Guid clsid) {
54                         return (ImageCodecInfo) decoders [clsid];
55                 }
56
57                 [TestFixtureSetUp]
58                 public void FixtureGetReady()           
59                 {
60                         decoders = new Hashtable ();
61                         encoders = new Hashtable ();
62
63                         foreach (ImageCodecInfo decoder in ImageCodecInfo.GetImageDecoders ())
64                                 decoders[decoder.Clsid] = decoder;
65                 
66                         foreach (ImageCodecInfo encoder in ImageCodecInfo.GetImageEncoders ())
67                                 encoders[encoder.Clsid] = encoder;
68                 }
69
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)
73                 {
74                         Regex extRegex = new Regex (@"^(\*\.\w+(;(\*\.\w+))*;)?"+
75                                 Regex.Escape (FilenameExtension)+@"(;\*\.\w+(;(\*\.\w+))*)?$",
76                                 RegexOptions.IgnoreCase | RegexOptions.Singleline);
77
78                         if (e != null) {
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);
90
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));
94                                 }
95                                 Assert.AreEqual (signatureLength, e.SignaturePatterns.Length, "Encoder.SignaturePatterns.Length");
96                                 Assert.AreEqual (pattern, BitConverter.ToString (e.SignaturePatterns[0]), "Encoder.SignaturePatterns[0]");
97                                 if (pattern2 != null)
98                                         Assert.AreEqual (pattern2, BitConverter.ToString (e.SignaturePatterns[1]), "Encoder.SignaturePatterns[1]");
99                         }
100                         if (d != null) {
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);
112
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));
116                                 }
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]");
121                         }
122                 }
123
124                 [Test]
125 #if TARGET_JVM
126                 [Category ("NotWorking")]
127 #endif
128                 public void Decoders ()
129                 {
130                         Assert.AreEqual (8, decoders.Count, "Count");
131                         foreach (DictionaryEntry de in decoders) {
132                                 string guid = de.Key.ToString ();
133                                 switch (guid) {
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
142                                         break;
143                                 default:
144                                         Assert.Ignore ("Unknown decoder " + guid);
145                                         break;
146                                 }
147                         }
148                 }
149
150                 [Test]
151 #if TARGET_JVM
152                 [Category ("NotWorking")]
153 #endif
154                 public void Encoders ()
155                 {
156                         Assert.AreEqual (5, encoders.Count, "Count");
157                         foreach (DictionaryEntry de in encoders) {
158                                 string guid = de.Key.ToString ();
159                                 switch (guid) {
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
165                                         break;
166                                 default:
167                                         Assert.Ignore ("Unknown encoder " + guid);
168                                         break;
169                                 }
170                         }
171                 }
172
173                 [Test]
174 #if TARGET_JVM
175                 [Category ("NotWorking")]
176 #endif
177                 public void BMPCodec()
178                 {
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);
184                 }
185
186                 [Test]
187 #if TARGET_JVM
188                 [Category ("NotWorking")]
189 #endif
190                 public void GifCodec()
191                 {
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");
197                 }
198                 
199                 [Test]
200 #if TARGET_JVM
201                 [Category ("NotWorking")]
202 #endif
203                 public void JpegCodec()
204                 {
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);
210                 }
211
212                 [Test]
213 #if TARGET_JVM
214                 [Category ("NotWorking")]
215 #endif
216                 public void PngCodec()
217                 {
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);
223                 }
224
225                 [Test]
226 #if TARGET_JVM
227                 [Category ("NotWorking")]
228 #endif
229                 public void TiffCodec ()
230                 {
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");
236                 }
237
238                 [Test]
239 #if TARGET_JVM
240                 [Category ("NotWorking")]
241 #endif
242                 public void IconCodec_Encoder ()
243                 {
244                         Guid g = new Guid ("557cf407-1a04-11d3-9a73-0000f81ef32e");
245                         Assert.IsNull (GetEncoder (g), "Encoder");
246                 }
247
248                 [Test]
249 #if TARGET_JVM
250                 [Category ("NotWorking")]
251 #endif
252                 public void IconCodec_Decoder ()
253                 {
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);
259                 }
260
261                 [Test]
262 #if TARGET_JVM
263                 [Category ("NotWorking")]
264 #endif
265                 public void EmfCodec_Encoder ()
266                 {
267                         Guid g = new Guid ("557cf403-1a04-11d3-9a73-0000f81ef32e");
268                         Assert.IsNull (GetEncoder (g), "Encoder");
269                 }
270
271                 [Test]
272 #if TARGET_JVM
273                 [Category ("NotWorking")]
274 #endif
275                 public void EmfCodec_Decoder ()
276                 {
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);
283                 }
284
285                 [Test]
286 #if TARGET_JVM
287                 [Category ("NotWorking")]
288 #endif
289                 public void WmfCodec_Encoder ()
290                 {
291                         Guid g = new Guid ("557cf404-1a04-11d3-9a73-0000f81ef32e");
292                         Assert.IsNull (GetEncoder (g), "Encoder");
293                 }
294
295                 [Test]
296 #if TARGET_JVM
297                 [Category ("NotWorking")]
298 #endif
299                 public void WmfCodec_Decoder ()
300                 {
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);
306                 }
307         }
308 }