[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / corlib / Test / System.Text / DecoderTest.cs
index fb8c774d74b850d3d70283112e902d69c7a98696..63112d995be6c961d89cb6b8931b0cc7303bfdda 100644 (file)
@@ -15,7 +15,6 @@ namespace MonoTests.System.Text
        [TestFixture]
        public class DecoderTest
        {
-#if NET_2_0
                [Test]
                [ExpectedException (typeof (ArgumentNullException))]
                public void ConvertNullChars ()
@@ -44,7 +43,7 @@ namespace MonoTests.System.Text
                        char [] chars = new char [10000];
                        byte [] bytes = new byte [10000];
 
-                       Decoder conv = Encoding.UTF8.GetDecoder ();
+                       Decoder conv = new ExposedDecoder ();
                        int charsUsed, bytesUsed;
                        bool done;
 
@@ -55,6 +54,94 @@ namespace MonoTests.System.Text
                        Assert.AreEqual (625, charsUsed, "#2");
                        Assert.AreEqual (625, bytesUsed, "#3");
                }
-#endif
+
+               [Test]
+               public void ConvertLimitedDestinationUTF8 ()
+               {
+                       char [] chars = new char [10000];
+                       byte [] bytes = new byte [10000];
+
+                       Decoder conv = Encoding.UTF8.GetDecoder ();
+                       int charsUsed, bytesUsed;
+                       bool done;
+
+                       conv.Convert (bytes, 0, 10000, chars, 0, 1000, true,
+                                     out charsUsed, out bytesUsed, out done);
+
+                       Assert.IsFalse (done, "#1");
+                       Assert.AreEqual (1000, charsUsed, "#2");
+                       Assert.AreEqual (1000, bytesUsed, "#3");
+               }
+
+
+               [Test]
+               public void CustomEncodingGetDecoder ()
+               {
+                       var encoding = new CustomEncoding ();
+                       var decoder = encoding.GetDecoder ();
+                       Assert.IsNotNull (decoder);
+               }
+
+               class ExposedDecoder : Decoder {
+                       public override int GetCharCount (byte [] bytes, int index, int count)
+                       {
+                               return Encoding.UTF8.GetDecoder ().GetCharCount (bytes, index, count);
+                       }
+
+                       public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex)
+                       {
+                               return Encoding.UTF8.GetDecoder ().GetChars (bytes, byteIndex, byteCount, chars, charIndex);
+                       }
+               }
+
+               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 ();
+                       }
+               }
+
+               [Test]
+               public void Bug10789 ()
+               {
+                       byte[] bytes = new byte[100];
+                       char[] chars = new char[100];  
+
+                       Decoder conv = Encoding.UTF8.GetDecoder ();
+                       int charsUsed, bytesUsed;
+                       bool completed;
+                       
+                       conv.Convert (bytes, 0, 0, chars, 100, 0, false, out bytesUsed, out charsUsed, out completed);
+
+                       Assert.IsTrue (completed, "#1");
+                       Assert.AreEqual (0, charsUsed, "#2");
+                       Assert.AreEqual (0, bytesUsed, "#3");
+               }
        }
 }