EncodingInfoTest.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // Do this in a method to work around #5432
  40. GetEncoding (i, list);
  41. }
  42. int [] reference = list.ToArray ();
  43. EncodingInfo [] infos = Encoding.GetEncodings ();
  44. int [] actual = new int [infos.Length];
  45. for (int i = 0; i < infos.Length; i++)
  46. actual [i] = infos [i].CodePage;
  47. Assert.AreEqual (reference, actual);
  48. }
  49. [Test]
  50. public void GetEncodingForAllInfo ()
  51. {
  52. foreach (EncodingInfo i in Encoding.GetEncodings ())
  53. Assert.IsNotNull (i.GetEncoding (), "codepage " + i);
  54. }
  55. void GetEncoding (int id, List<int> list) {
  56. try {
  57. Encoding.GetEncoding (id);
  58. list.Add (id);
  59. } catch {
  60. }
  61. }
  62. }
  63. }
  64. #endif