Merge pull request #1057 from lextm/master
[mono.git] / mcs / class / corlib / Test / System.IO / BinaryReaderTest.cs
index 5d8be432ca403593d1455cc4379fe3da4e63a601..852d69089b3dcbf72739707831f01b8c46903a91 100644 (file)
@@ -1459,6 +1459,88 @@ namespace MonoTests.System.IO
                }
        }
 
+       class ReadStringMockStream : Stream
+       {
+               int noc;
+
+               #region implemented abstract members of Stream
+
+               public override void Flush ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override int Read (byte[] buffer, int offset, int count)
+               {
+                       switch (noc++) {
+                       case 0:
+                               buffer [0] = 42; // Length
+                               return 2; 
+                       default:
+                               buffer [0] = 0x65;
+                               return 1;
+                       }
+               }
+
+               public override long Seek (long offset, SeekOrigin origin)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override void SetLength (long value)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override void Write (byte[] buffer, int offset, int count)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override bool CanRead {
+                       get {
+                               return true;
+                       }
+               }
+
+               public override bool CanSeek {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+
+               public override bool CanWrite {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+
+               public override long Length {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+               }
+
+               public override long Position {
+                       get {
+                               throw new NotImplementedException ();
+                       }
+                       set {
+                               throw new NotImplementedException ();
+                       }
+               }
+
+               #endregion
+       }
+
+       [Test]
+       public void ReadSting_CustomStream ()
+       {
+               var sr = new BinaryReader (new ReadStringMockStream ());
+               var s = sr.ReadString ();
+               Assert.AreEqual ("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", s);
+       }
+
        [Test]
        public void ReadOverrides ()
        {