More mobile tests update
[mono.git] / mcs / class / corlib / Test / System.Text / EncodingInfoTest.cs
1 //
2 // EncodingInfoTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // (C) 2006 Novell, Inc.
8 // 
9
10 using NUnit.Framework;
11 using System;
12 using System.Collections.Generic;
13 using System.IO;
14 using System.Reflection;
15 using System.Text;
16
17 namespace MonoTests.System.Text
18 {
19         [TestFixture]
20         [Category ("MobileNotWorking")]
21         public class EncodingInfoTest
22         {
23                 [Test]
24                 // The purpose of this test is to make sure that
25                 // new encodings added to I18N are also listed in the
26                 // returned array from Encoding.GetEncodings() so that
27                 // we can make sure to put additional encodings into
28                 // Encoding.GetEncodings() code.
29                 public void EncodingGetEncodingsReturnsAll ()
30                 {
31                         // Make sure that those I18N assemblies are loaded.
32                         string basePath = Assembly.GetAssembly (typeof (int)).CodeBase;
33                         basePath = basePath.Substring (0, basePath.LastIndexOf ('/'));
34                         Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.West.dll"), "West");
35                         Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.CJK.dll"), "CJK");
36                         Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.MidEast.dll"), "MidEast");
37                         Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.Rare.dll"), "Rare");
38                         Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.Other.dll"), "Other");
39
40                         List<int> list = new List<int> ();
41                         for (int i = 1; i < 0x10000; i++) {
42                                 // Do this in a method to work around #5432
43                                 GetEncoding (i, list);
44                         }
45                         int [] reference = list.ToArray ();
46
47                         EncodingInfo [] infos = Encoding.GetEncodings ();
48                         int [] actual = new int [infos.Length];
49
50                         for (int i = 0; i < infos.Length; i++)
51                                 actual [i] = infos [i].CodePage;
52
53                         Assert.AreEqual (reference, actual);
54                 }
55
56                 [Test]
57                 public void GetEncodingForAllInfo ()
58                 {
59                         foreach (EncodingInfo i in Encoding.GetEncodings ())
60                                 Assert.IsNotNull (i.GetEncoding (), "codepage " + i);
61                 }
62
63                 void GetEncoding (int id, List<int> list) {
64                         try {
65                                 Encoding.GetEncoding (id);
66                                 list.Add (id);
67                         } catch {
68                         }
69                 }
70         }
71 }