in System.Text:
authorJb Evain <jbevain@gmail.com>
Tue, 13 Jan 2009 15:25:45 +0000 (15:25 -0000)
committerJb Evain <jbevain@gmail.com>
Tue, 13 Jan 2009 15:25:45 +0000 (15:25 -0000)
2009-01-13  Jb Evain  <jbevain@novell.com>

* Encoding.cs: when creating a ForwardingEncoder or a
ForwardingDecoder, don't crash if the Encoding doesn't
provide an EncoderFallback or a DecoderFallback.

in Test/System.Text:
2009-01-13  Jb Evain  <jbevain@novell.com>

* EncoderTest.cs: Make sure we can get an encoder for a custom
encoding.
* DecoderTest.cs: ditto.

svn path=/trunk/mcs/; revision=123196

mcs/class/corlib/System.Text/ChangeLog
mcs/class/corlib/System.Text/Encoding.cs
mcs/class/corlib/Test/System.Text/ChangeLog
mcs/class/corlib/Test/System.Text/DecoderTest.cs
mcs/class/corlib/Test/System.Text/EncoderTest.cs

index 8719cd8655491e2ae606cf656c3f8b628aff1959..1e01d446316b772b5b067c0cdef12634298d3b68 100644 (file)
@@ -1,3 +1,8 @@
+2009-01-13  Jb Evain  <jbevain@novell.com>
+
+       * Encoding.cs: when creating a ForwardingEncoder or a
+       ForwardingDecoder, don't crash if the Encoding doesn't
+       provide an EncoderFallback or a DecoderFallback.
 
 Mon Oct 6 09:46:09 CEST 2008 Paolo Molaro <lupus@ximian.com>
 
index 19ddf206351cb99e2a10673f1a680f32b225a015..d1f1ac898ed7c576a610e47dba8696eb4ab5891e 100644 (file)
@@ -1099,7 +1099,9 @@ public abstract class Encoding
                {
                        encoding = enc;
 #if NET_2_0
-                       Fallback = encoding.DecoderFallback;
+                       DecoderFallback fallback = encoding.DecoderFallback;
+                       if (fallback != null)
+                               Fallback = fallback;
 #endif
                }
 
@@ -1127,7 +1129,9 @@ public abstract class Encoding
                {
                        encoding = enc;
 #if NET_2_0
-                       Fallback = encoding.EncoderFallback;
+                       EncoderFallback fallback = encoding.EncoderFallback;
+                       if (fallback != null)
+                               Fallback = fallback;
 #endif
                }
 
index 6286ff5b902a0ac8a42a5d222764e56716e42e13..cca04e879aefdf9ee832c89979faab65d8d439e6 100644 (file)
@@ -1,3 +1,9 @@
+2009-01-13  Jb Evain  <jbevain@novell.com>
+
+       * EncoderTest.cs: Make sure we can get an encoder for a custom
+       encoding.
+       * DecoderTest.cs: ditto.
+
 2008-04-09  Atsushi Enomoto  <atsushi@ximian.com>
 
        * UTF7EncodingTest.cs : added test for broken GetCharCount() case.
index fb8c774d74b850d3d70283112e902d69c7a98696..3da0846360b0866e32f3a8fdb3512cd1212be50e 100644 (file)
@@ -55,6 +55,48 @@ namespace MonoTests.System.Text
                        Assert.AreEqual (625, charsUsed, "#2");
                        Assert.AreEqual (625, bytesUsed, "#3");
                }
+
+
+               [Test]
+               public void CustomEncodingGetDecoder ()
+               {
+                       var encoding = new CustomEncoding ();
+                       var decoder = encoding.GetDecoder ();
+                       Assert.IsNotNull (decoder);
+               }
+
+               class CustomEncoding : Encoding {
+
+                       public override int GetByteCount (char [] chars, int index, int count)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetBytes (char [] chars, int charIndex, int charCount, byte [] bytes, int byteIndex)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetCharCount (byte [] bytes, int index, int count)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetMaxByteCount (int charCount)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetMaxCharCount (int byteCount)
+                       {
+                               throw new NotSupportedException ();
+                       }
+               }
 #endif
        }
 }
index 5dc13e1a813db820f9aa4c4718ad16eeb9b4b166..3102e3838a00383ac936b3bb2a0a80ae76226f92 100644 (file)
@@ -55,6 +55,47 @@ namespace MonoTests.System.Text
                        Assert.AreEqual (625, bytesUsed, "#2");
                        Assert.AreEqual (625, charsUsed, "#3");
                }
+
+               [Test]
+               public void CustomEncodingGetEncoder ()
+               {
+                       var encoding = new CustomEncoding ();
+                       var encoder = encoding.GetEncoder ();
+                       Assert.IsNotNull (encoder);
+               }
+
+               class CustomEncoding : Encoding {
+
+                       public override int GetByteCount (char [] chars, int index, int count)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetBytes (char [] chars, int charIndex, int charCount, byte [] bytes, int byteIndex)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetCharCount (byte [] bytes, int index, int count)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetMaxByteCount (int charCount)
+                       {
+                               throw new NotSupportedException ();
+                       }
+
+                       public override int GetMaxCharCount (int byteCount)
+                       {
+                               throw new NotSupportedException ();
+                       }
+               }
 #endif
        }
 }