EncodingInfoTest.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // EncodingInfoTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // (C) 2006 Novell, Inc.
  8. //
  9. #if NET_2_0
  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. namespace MonoTests.System.Text
  17. {
  18. [TestFixture]
  19. public class EncodingInfoTest
  20. {
  21. [Test]
  22. // The purpose of this test is to make sure that
  23. // new encodings added to I18N are also listed in the
  24. // returned array from Encoding.GetEncodings() so that
  25. // we can make sure to put additional encodings into
  26. // Encoding.GetEncodings() code.
  27. public void EncodingGetEncodingsReturnsAll ()
  28. {
  29. // Make sure that those I18N assemblies are loaded.
  30. string basePath = Assembly.GetAssembly (typeof (int)).CodeBase;
  31. basePath = basePath.Substring (0, basePath.LastIndexOf ('/'));
  32. Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.West.dll"), "West");
  33. Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.CJK.dll"), "CJK");
  34. Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.MidEast.dll"), "MidEast");
  35. Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.Rare.dll"), "Rare");
  36. Assert.IsNotNull (Assembly.LoadFrom (basePath + "/I18N.Other.dll"), "Other");
  37. List<int> list = new List<int> ();
  38. for (int i = 1; i < 0x10000; i++) {
  39. try {
  40. Encoding.GetEncoding (i);
  41. list.Add (i);
  42. } catch {
  43. }
  44. }
  45. int [] reference = list.ToArray ();
  46. EncodingInfo [] infos = Encoding.GetEncodings ();
  47. int [] actual = new int [infos.Length];
  48. for (int i = 0; i < infos.Length; i++)
  49. actual [i] = infos [i].CodePage;
  50. Assert.AreEqual (reference, actual);
  51. }
  52. [Test]
  53. public void GetEncodingForAllInfo ()
  54. {
  55. foreach (EncodingInfo i in Encoding.GetEncodings ())
  56. Assert.IsNotNull (i.GetEncoding (), "codepage " + i);
  57. }
  58. }
  59. }
  60. #endif