In corlib/System.Runtime.InteropServices:
[mono.git] / mcs / class / corlib / Test / System.IO / BinaryReaderTest.cs
index 93bbec1ecb40d78bfc33bfd84111e5e88e02f627..211c07d520de94967b3d9004b942aff8dad056d1 100644 (file)
@@ -4,7 +4,9 @@
 //
 // (C) Eduardo Garcia Cebollero.
 // (C) Ximian, Inc.  http://www.ximian.com
+// Copyright (C) 2004 Novell (http://www.novell.com)
 // 
+
 using NUnit.Framework;
 using System;
 using System.IO;
@@ -30,7 +32,6 @@ namespace MonoTests.System.IO
                 [TearDown]
                public void TearDown ()
                {
-
                                if (Directory.Exists (TempFolder))
                                        Directory.Delete (TempFolder, true);
                }               
@@ -550,7 +551,87 @@ namespace MonoTests.System.IO
                        stream.Close ();
                }
        }
-       
+
+       [Test]
+       [ExpectedException (typeof (ArgumentNullException))]
+       public void Read_Bytes_BufferNull () 
+       {
+               byte[] b = null;
+               new BinaryReader (new MemoryStream ()).Read (b, 0, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void Read_Bytes_IndexNegative () 
+       {
+               byte[] array = new byte [8];
+               new BinaryReader (new MemoryStream ()).Read (array, -1, array.Length);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void Read_Bytes_IndexOverflow () 
+       {
+               byte[] array = new byte [8];
+               new BinaryReader (new MemoryStream ()).Read (array, Int32.MaxValue, array.Length);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void Read_Bytes_CountNegative () 
+       {
+               byte[] array = new byte [8];
+               new BinaryReader (new MemoryStream ()).Read (array, 0, -1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void Read_Bytes_CountOverflow () 
+       {
+               byte[] array = new byte [8];
+               new BinaryReader (new MemoryStream ()).Read (array, 0, Int32.MaxValue);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentNullException))]
+       public void Read_Chars_BufferNull () 
+       {
+               char[] c = null;
+               new BinaryReader (new MemoryStream ()).Read (c, 0, 1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void Read_Chars_IndexNegative () 
+       {
+               char[] array = new char [8];
+               new BinaryReader (new MemoryStream ()).Read (array, -1, array.Length);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void Read_Chars_IndexOverflow () 
+       {
+               char[] array = new char [8];
+               new BinaryReader (new MemoryStream ()).Read (array, Int32.MaxValue, array.Length);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentOutOfRangeException))]
+       public void Read_Chars_CountNegative () 
+       {
+               char[] array = new char [8];
+               new BinaryReader (new MemoryStream ()).Read (array, 0, -1);
+       }
+
+       [Test]
+       [ExpectedException (typeof (ArgumentException))]
+       public void Read_Chars_CountOverflow () 
+       {
+               char[] array = new char [8];
+               new BinaryReader (new MemoryStream ()).Read (array, 0, Int32.MaxValue);
+       }
+
        [Test]
        public void PeakChar ()
        {
@@ -971,7 +1052,7 @@ namespace MonoTests.System.IO
                MemoryStream stream = null;
                BinaryReader reader = null;             
                try {
-                       stream = new MemoryStream (new byte [] {0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0 ,87, 98, 0, 0, 0, 0});
+                       stream = new MemoryStream (new byte [] {0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0 ,128, 0, 0, 0, 0, 0});
                        reader = new BinaryReader (stream);             
                        AssertEquals ("test#01", -18295873486192640, reader.ReadDecimal ());
                } finally {
@@ -982,6 +1063,9 @@ namespace MonoTests.System.IO
        
        [Test]
        [ExpectedException(typeof(EndOfStreamException))]
+#if TARGET_JVM
+    [Category("NotWorking")]
+#endif
        public void ReadDecimalException ()
        {
                MemoryStream stream = new MemoryStream (new byte [] {0, 0, 0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0 ,87, 98, 0, 0, 0, 0, 0});
@@ -1150,6 +1234,9 @@ namespace MonoTests.System.IO
        }
        
        [Test]
+#if TARGET_JVM
+    [Category("NotWorking")]
+#endif
        public void ReadSingle ()
        {
                MemoryStream stream = new MemoryStream (new byte [] {65, 200, 0, 0, 0, 1, 2, 3, 4});
@@ -1198,6 +1285,20 @@ namespace MonoTests.System.IO
                        stream.Close ();                        
                }
        }
+
+       [Test]
+       public void ReadLongUTF8String ()
+       {
+               // \u00A9 == (C)
+               string s = new String ('\u00A9', 100);
+               MemoryStream ms = new MemoryStream ();
+               BinaryWriter w = new BinaryWriter (ms);         
+               w.Write (s);
+               w.Flush ();
+               ms.Position = 0;
+               BinaryReader r = new BinaryReader (ms);
+               AssertEquals (s, r.ReadString ());
+       }               
        
        [Test]
        [ExpectedException(typeof(EndOfStreamException))]               
@@ -1292,7 +1393,17 @@ namespace MonoTests.System.IO
                        stream.Close ();                        
                }
        }
-       
+
+       [Test]
+       public void Test_ReadZeroBytes ()
+       {
+               MemoryStream stream = new MemoryStream (new byte [] {65, 1, 32, 43, 5, 3, 54, 0, 34, 5, 7, 4, 23, 4, 76, 34, 76, 2, 6,45});
+               BinaryReader reader = new BinaryReader (stream);
+
+               char [] result = reader.ReadChars (0);
+               AssertEquals ("ZERO_1", result.Length, 0);
+       }
+               
        [Test]
        [ExpectedException(typeof(EndOfStreamException))]       
        public void ReadUInt64Exception ()
@@ -1314,6 +1425,6 @@ namespace MonoTests.System.IO
        {
                if (File.Exists (path))
                        File.Delete (path);
-       }       
+       }
 }
 }