Author: atsushi
Date: 2005-11-15 12:34:20 -0500 (Tue, 15 Nov 2005)
New Revision: 53077

Added:
   
trunk/mcs/class/corlib/Test/System.Text/DecoderReplacementFallbackBufferTest.cs
Modified:
   trunk/mcs/class/corlib/ChangeLog
   trunk/mcs/class/corlib/System.Text/ChangeLog
   trunk/mcs/class/corlib/System.Text/DecoderFallbackBuffer.cs
   trunk/mcs/class/corlib/System.Text/DecoderReplacementFallbackBuffer.cs
   trunk/mcs/class/corlib/Test/System.Text/ChangeLog
   trunk/mcs/class/corlib/corlib_test.dll.sources
Log:
2005-11-15  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * corlib_test.dll.sources:
          Added DecoderReplacementFallbackBudderTest.cs.

        * DecoderFallbackBuffer.cs : Reset() does nothing here.
        * DecoderReplacementFallbackBuffer.cs : implemented, but no idea how
          bytesUnknown is used.

        * DecoderReplacementFallbackBufferTest.cs : new test.



Modified: trunk/mcs/class/corlib/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/ChangeLog    2005-11-15 16:59:26 UTC (rev 53076)
+++ trunk/mcs/class/corlib/ChangeLog    2005-11-15 17:34:20 UTC (rev 53077)
@@ -1,3 +1,8 @@
+2005-11-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * corlib_test.dll.sources:
+         Added DecoderReplacementFallbackBudderTest.cs.
+
 2005-11-15  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * corlib.dll.sources: Readd NewConstraintAttribute.cs as gmcs depends 
on it.

Modified: trunk/mcs/class/corlib/System.Text/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Text/ChangeLog        2005-11-15 16:59:26 UTC 
(rev 53076)
+++ trunk/mcs/class/corlib/System.Text/ChangeLog        2005-11-15 17:34:20 UTC 
(rev 53077)
@@ -1,5 +1,11 @@
 2005-11-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * DecoderFallbackBuffer.cs : Reset() does nothing here.
+       * DecoderReplacementFallbackBuffer.cs : implemented, but no idea how
+         bytesUnknown is used.
+
+2005-11-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * Encoding.cs : added ICloneable, Clone() and new GetEncoding().
 
 2005-11-15  Atsushi Enomoto  <[EMAIL PROTECTED]>

Modified: trunk/mcs/class/corlib/System.Text/DecoderFallbackBuffer.cs
===================================================================
--- trunk/mcs/class/corlib/System.Text/DecoderFallbackBuffer.cs 2005-11-15 
16:59:26 UTC (rev 53076)
+++ trunk/mcs/class/corlib/System.Text/DecoderFallbackBuffer.cs 2005-11-15 
17:34:20 UTC (rev 53077)
@@ -46,10 +46,8 @@
 
                public abstract bool MovePrevious ();
 
-               [MonoTODO]
                public virtual void Reset ()
                {
-                       throw new NotImplementedException ();
                }
        }
 }

Modified: trunk/mcs/class/corlib/System.Text/DecoderReplacementFallbackBuffer.cs
===================================================================
--- trunk/mcs/class/corlib/System.Text/DecoderReplacementFallbackBuffer.cs      
2005-11-15 16:59:26 UTC (rev 53076)
+++ trunk/mcs/class/corlib/System.Text/DecoderReplacementFallbackBuffer.cs      
2005-11-15 17:34:20 UTC (rev 53077)
@@ -32,44 +32,63 @@
 
 namespace System.Text
 {
+       [MonoTODO ("Find out how bytesUnknown is used")]
        public sealed class DecoderReplacementFallbackBuffer
                : DecoderFallbackBuffer
        {
                DecoderReplacementFallback fallback;
+               byte [] bytes;
+               int index, current;
+               string replacement;
 
                public DecoderReplacementFallbackBuffer (
                        DecoderReplacementFallback fallback)
                {
+                       if (fallback == null)
+                               throw new ArgumentNullException ("fallback");
                        this.fallback = fallback;
+                       replacement = fallback.DefaultString;
+                       current = 0;
                }
 
-               [MonoTODO]
                public override int Remaining {
-                       get { throw new NotImplementedException (); }
+                       get { return replacement.Length - current; }
                }
 
-               [MonoTODO]
                public override bool Fallback (byte [] bytesUnknown, int index)
                {
-                       throw new NotImplementedException ();
+                       if (bytesUnknown == null)
+                               throw new ArgumentNullException 
("bytesUnknown");
+                       if (bytes != null && Remaining != 0)
+                               throw new ArgumentException ("Reentrant 
Fallback method invocation occured. It might be because either this 
FallbackBuffer is incorrectly shared by multiple threads, invoked inside 
Encoding recursively, or Reset invocation is forgotten.");
+                       if (index < 0 || bytesUnknown.Length < index)
+                               throw new ArgumentOutOfRangeException ("index");
+                       bytes = bytesUnknown;
+                       this.index = index;
+                       current = 0;
+
+                       return replacement.Length > 0;
                }
 
-               [MonoTODO]
                public override char GetNextChar ()
                {
-                       throw new NotImplementedException ();
+                       if (current >= replacement.Length)
+                               return char.MinValue;
+                       return replacement [current++];
                }
 
-               [MonoTODO]
                public override bool MovePrevious ()
                {
-                       throw new NotImplementedException ();
+                       if (current == 0)
+                               return false;
+                       current--;
+                       return true;
                }
 
-               [MonoTODO]
                public override void Reset ()
                {
-                       throw new NotImplementedException ();
+                       bytes = null;
+                       current = 0;
                }
        }
 }

Modified: trunk/mcs/class/corlib/Test/System.Text/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Text/ChangeLog   2005-11-15 16:59:26 UTC 
(rev 53076)
+++ trunk/mcs/class/corlib/Test/System.Text/ChangeLog   2005-11-15 17:34:20 UTC 
(rev 53077)
@@ -1,5 +1,9 @@
 2005-11-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * DecoderReplacementFallbackBufferTest.cs : new test.
+
+2005-11-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * TestEncoding.cs,
          DecoderReplacementFallbackTest.cs,
          EncoderReplacementFallbackTest.cs : new 2.0 tests.

Added: 
trunk/mcs/class/corlib/Test/System.Text/DecoderReplacementFallbackBufferTest.cs
===================================================================
--- 
trunk/mcs/class/corlib/Test/System.Text/DecoderReplacementFallbackBufferTest.cs 
    2005-11-15 16:59:26 UTC (rev 53076)
+++ 
trunk/mcs/class/corlib/Test/System.Text/DecoderReplacementFallbackBufferTest.cs 
    2005-11-15 17:34:20 UTC (rev 53077)
@@ -0,0 +1,91 @@
+//
+// DecoderReplacementFallbackBuffer.cs
+//
+// Author:
+//     Atsushi Enomoto  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2005 Novell, Inc.  http://www.novell.com
+//
+
+#if NET_2_0
+
+using System;
+using System.IO;
+using System.Text;
+using NUnit.Framework;
+
+using Buffer = System.Text.DecoderReplacementFallbackBuffer;
+
+namespace MonoTests.System.Text
+{
+       [TestFixture]
+       public class DecoderReplacementFallbackBufferTest
+       {
+               private Buffer NewInstance ()
+               {
+                       return new Buffer (new DecoderReplacementFallback ());
+               }
+
+               [Test]
+               public void FallbackEmptyDefault ()
+               {
+                       Buffer b = NewInstance ();
+                       Assert.IsTrue (b.Fallback (new byte [] {}, 0), "#0");
+                       Assert.IsFalse (b.MovePrevious (), "#1");
+                       Assert.AreEqual (1, b.Remaining, "#2");
+                       Assert.AreEqual ('?', b.GetNextChar (), "#3");
+                       Assert.AreEqual (0, b.Remaining, "#4");
+                       // the string is already consumed.
+                       Assert.AreEqual (char.MinValue, b.GetNextChar (), "#5");
+               }
+
+               [Test]
+               public void FallbackEmptyForEncodingUTF8 ()
+               {
+                       Buffer b = 
Encoding.UTF8.DecoderFallback.CreateFallbackBuffer () as Buffer;
+                       Assert.IsFalse (b.Fallback (new byte [] {}, 0), "#1");
+                       Assert.IsFalse (b.MovePrevious (), "#2");
+                       Assert.AreEqual (0, b.Remaining, "#3");
+                       // the string does not exist.
+                       Assert.AreEqual (char.MinValue, b.GetNextChar (), "#4");
+               }
+
+               [Test]
+               public void FallbackSequential ()
+               {
+                       Buffer b = NewInstance ();
+                       b.Fallback (new byte [] {}, 0);
+                       b.GetNextChar ();
+                       b.Fallback (new byte [] {}, 0);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void FallbackRecursiveError ()
+               {
+                       Buffer b = NewInstance ();
+                       b.Fallback (new byte [] {}, 0);
+                       b.Fallback (new byte [] {}, 0);
+               }
+
+               [Test]
+               public void Iterate ()
+               {
+                       Assert.AreEqual ('\0', Encoding.UTF8.DecoderFallback
+                               .CreateFallbackBuffer ().GetNextChar (), "#1");
+
+                       Buffer b = NewInstance ();
+                       Assert.AreEqual (1, b.Remaining, "#2");
+                       Assert.AreEqual ('?', b.GetNextChar (), "#3");
+                       Assert.AreEqual (0, b.Remaining, "#4");
+                       Assert.AreEqual ('\0', b.GetNextChar (), "#5");
+                       Assert.IsTrue (b.MovePrevious (), "#6");
+                       Assert.AreEqual (1, b.Remaining, "#7");
+                       Assert.IsFalse (b.MovePrevious (), "#8");
+                       Assert.AreEqual ('?', b.GetNextChar (), "#9");
+               }
+       }
+}
+
+#endif
+


Property changes on: 
trunk/mcs/class/corlib/Test/System.Text/DecoderReplacementFallbackBufferTest.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/mcs/class/corlib/corlib_test.dll.sources
===================================================================
--- trunk/mcs/class/corlib/corlib_test.dll.sources      2005-11-15 16:59:26 UTC 
(rev 53076)
+++ trunk/mcs/class/corlib/corlib_test.dll.sources      2005-11-15 17:34:20 UTC 
(rev 53077)
@@ -275,6 +275,7 @@
 System/StringTest.cs
 System.Text/ASCIIEncodingTest.cs
 System.Text/DecoderReplacementFallbackTest.cs
+System.Text/DecoderReplacementFallbackBufferTest.cs
 System.Text/EncoderReplacementFallbackTest.cs
 System.Text/StringBuilderTest.cs
 System.Text/TestEncoding.cs

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to