5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2006 Novell, Inc.
12 using NUnit.Framework;
14 using System.Collections.Generic;
16 using System.Reflection;
19 namespace MonoTests.System.Text
22 public class EncodingInfoTest
25 // The purpose of this test is to make sure that
26 // new encodings added to I18N are also listed in the
27 // returned array from Encoding.GetEncodings() so that
28 // we can make sure to put additional encodings into
29 // Encoding.GetEncodings() code.
30 public void EncodingGetEncodingsReturnsAll ()
32 // Make sure that those I18N assemblies are loaded.
33 string basePath = Assembly.GetAssembly (typeof (int)).CodeBase;
34 basePath = basePath.Substring (0, basePath.LastIndexOf ('/'));
35 Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.West.dll"), "West");
36 Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.CJK.dll"), "CJK");
37 Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.MidEast.dll"), "MidEast");
38 Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.Rare.dll"), "Rare");
39 Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.Other.dll"), "Other");
41 List<int> list = new List<int> ();
42 for (int i = 1; i < 0x10000; i++) {
43 // Do this in a method to work around #5432
44 GetEncoding (i, list);
46 int [] reference = list.ToArray ();
48 EncodingInfo [] infos = Encoding.GetEncodings ();
49 int [] actual = new int [infos.Length];
51 for (int i = 0; i < infos.Length; i++)
52 actual [i] = infos [i].CodePage;
54 Assert.AreEqual (reference, actual);
58 public void GetEncodingForAllInfo ()
60 foreach (EncodingInfo i in Encoding.GetEncodings ())
61 Assert.IsNotNull (i.GetEncoding (), "codepage " + i);
64 void GetEncoding (int id, List<int> list) {
66 Encoding.GetEncoding (id);