2 // DecoderReplacementFallback.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
15 using NUnit.Framework;
17 namespace MonoTests.System.Text
20 public class DecoderReplacementFallbackTest
23 public void Defaults ()
25 DecoderReplacementFallback f =
26 new DecoderReplacementFallback ();
27 Assert.AreEqual ("?", f.DefaultString, "#1");
28 Assert.AreEqual (1, f.MaxCharCount, "#2");
30 f = new DecoderReplacementFallback (String.Empty);
31 Assert.AreEqual (String.Empty, f.DefaultString, "#3");
32 Assert.AreEqual (0, f.MaxCharCount, "#4");
34 f = Encoding.UTF8.DecoderFallback as DecoderReplacementFallback;
35 Assert.IsNotNull (f, "#5");
36 Assert.AreEqual (String.Empty, f.DefaultString, "#6");
37 Assert.AreEqual (0, f.MaxCharCount, "#7");
39 // after beta2 this test became invalid.
40 //f = new MyEncoding ().DecoderFallback as DecoderReplacementFallback;
41 //Assert.IsNotNull (f, "#8");
42 //Assert.AreEqual (String.Empty, f.DefaultString, "#9");
43 //Assert.AreEqual (0, f.MaxCharCount, "#10");
45 f = DecoderFallback.ReplacementFallback as DecoderReplacementFallback;
46 Assert.AreEqual ("?", f.DefaultString, "#11");
47 Assert.AreEqual (1, f.MaxCharCount, "#12");
51 [ExpectedException (typeof (InvalidOperationException))]
52 public void DontChangeReadOnlyUTF8DecoderFallback ()
54 Encoding.UTF8.DecoderFallback =
55 new DecoderReplacementFallback ();
59 [ExpectedException (typeof (InvalidOperationException))]
60 public void DontChangeReadOnlyCodePageDecoderFallback ()
62 Encoding.GetEncoding (932).DecoderFallback =
63 new DecoderReplacementFallback ();
67 [ExpectedException (typeof (InvalidOperationException))]
68 public void CustomEncodingSetEncoderFallback ()
70 new MyEncoding ().DecoderFallback =
71 new DecoderReplacementFallback ();
75 [ExpectedException (typeof (InvalidOperationException))]
76 public void EncodingSetNullDecoderFallback ()
78 Encoding.Default.DecoderFallback = null;
82 // Don't throw an exception
83 public void SetDecoderFallback ()
85 Encoding.Default.GetDecoder ().Fallback =
86 new DecoderReplacementFallback ();
90 [ExpectedException (typeof (ArgumentNullException))]
91 public void DecoderSetNullFallback ()
93 Encoding.Default.GetDecoder ().Fallback = null;