DecoderReplacementFallbackTest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // DecoderReplacementFallback.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc. http://www.novell.com
  8. //
  9. #if NET_2_0
  10. using System;
  11. using System.IO;
  12. using System.Text;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Text
  15. {
  16. [TestFixture]
  17. public class DecoderReplacementFallbackTest
  18. {
  19. [Test]
  20. public void Defaults ()
  21. {
  22. DecoderReplacementFallback f =
  23. new DecoderReplacementFallback ();
  24. Assert.AreEqual ("?", f.DefaultString, "#1");
  25. Assert.AreEqual (1, f.MaxCharCount, "#2");
  26. f = new DecoderReplacementFallback (String.Empty);
  27. Assert.AreEqual (String.Empty, f.DefaultString, "#3");
  28. Assert.AreEqual (0, f.MaxCharCount, "#4");
  29. f = Encoding.UTF8.DecoderFallback as DecoderReplacementFallback;
  30. Assert.IsNotNull (f, "#5");
  31. Assert.AreEqual (String.Empty, f.DefaultString, "#6");
  32. Assert.AreEqual (0, f.MaxCharCount, "#7");
  33. f = new MyEncoding ().DecoderFallback as DecoderReplacementFallback;
  34. Assert.IsNotNull (f, "#8");
  35. Assert.AreEqual (String.Empty, f.DefaultString, "#9");
  36. Assert.AreEqual (0, f.MaxCharCount, "#10");
  37. f = DecoderFallback.ReplacementFallback as DecoderReplacementFallback;
  38. Assert.AreEqual ("?", f.DefaultString, "#11");
  39. Assert.AreEqual (1, f.MaxCharCount, "#12");
  40. }
  41. [Test]
  42. [ExpectedException (typeof (InvalidOperationException))]
  43. public void DontChangeReadOnlyUTF8DecoderFallback ()
  44. {
  45. Encoding.UTF8.DecoderFallback =
  46. new DecoderReplacementFallback ();
  47. }
  48. [Test]
  49. [ExpectedException (typeof (InvalidOperationException))]
  50. public void DontChangeReadOnlyCodePageDecoderFallback ()
  51. {
  52. Encoding.GetEncoding (932).DecoderFallback =
  53. new DecoderReplacementFallback ();
  54. }
  55. [Test]
  56. // Don't throw an exception
  57. public void SetDecoderFallback ()
  58. {
  59. new MyEncoding ().DecoderFallback =
  60. new DecoderReplacementFallback ();
  61. new MyEncoding (1).DecoderFallback =
  62. new DecoderReplacementFallback ();
  63. }
  64. [Test]
  65. [ExpectedException (typeof (ArgumentNullException))]
  66. public void EncodingSetNullDecoderFallback ()
  67. {
  68. new MyEncoding ().DecoderFallback = null;
  69. }
  70. [Test]
  71. [ExpectedException (typeof (ArgumentNullException))]
  72. public void DecoderSetNullFallback ()
  73. {
  74. Encoding.Default.GetDecoder ().Fallback = null;
  75. }
  76. }
  77. }
  78. #endif