New test.
[mono.git] / mcs / class / corlib / Test / System.Text / DecoderReplacementFallbackTest.cs
1 //
2 // DecoderReplacementFallback.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
8 //
9
10 #if NET_2_0
11
12 using System;
13 using System.IO;
14 using System.Text;
15 using NUnit.Framework;
16
17 namespace MonoTests.System.Text
18 {
19         [TestFixture]
20         public class DecoderReplacementFallbackTest
21         {
22                 [Test]
23                 public void Defaults ()
24                 {
25                         DecoderReplacementFallback f =
26                                 new DecoderReplacementFallback ();
27                         Assert.AreEqual ("?", f.DefaultString, "#1");
28                         Assert.AreEqual (1, f.MaxCharCount, "#2");
29
30                         f = new DecoderReplacementFallback (String.Empty);
31                         Assert.AreEqual (String.Empty, f.DefaultString, "#3");
32                         Assert.AreEqual (0, f.MaxCharCount, "#4");
33
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");
38
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");
44
45                         f = DecoderFallback.ReplacementFallback as DecoderReplacementFallback;
46                         Assert.AreEqual ("?", f.DefaultString, "#11");
47                         Assert.AreEqual (1, f.MaxCharCount, "#12");
48                 }
49
50                 [Test]
51                 [ExpectedException (typeof (InvalidOperationException))]
52                 public void DontChangeReadOnlyUTF8DecoderFallback ()
53                 {
54                         Encoding.UTF8.DecoderFallback =
55                                 new DecoderReplacementFallback ();
56                 }
57
58                 [Test]
59                 [ExpectedException (typeof (InvalidOperationException))]
60                 public void DontChangeReadOnlyCodePageDecoderFallback ()
61                 {
62                         Encoding.GetEncoding (932).DecoderFallback =
63                                 new DecoderReplacementFallback ();
64                 }
65
66                 [Test]
67                 [ExpectedException (typeof (InvalidOperationException))]
68                 public void CustomEncodingSetEncoderFallback ()
69                 {
70                         new MyEncoding ().DecoderFallback =
71                                 new DecoderReplacementFallback ();
72                 }
73
74                 [Test]
75                 [ExpectedException (typeof (InvalidOperationException))]
76                 public void EncodingSetNullDecoderFallback ()
77                 {
78                         Encoding.Default.DecoderFallback = null;
79                 }
80
81                 [Test]
82                 // Don't throw an exception
83                 public void SetDecoderFallback ()
84                 {
85                         Encoding.Default.GetDecoder ().Fallback =
86                                 new DecoderReplacementFallback ();
87                 }
88
89                 [Test]
90                 [ExpectedException (typeof (ArgumentNullException))]
91                 public void DecoderSetNullFallback ()
92                 {
93                         Encoding.Default.GetDecoder ().Fallback = null;
94                 }
95         }
96 }
97
98 #endif
99