//
// (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;
[TearDown]
public void TearDown ()
{
-
if (Directory.Exists (TempFolder))
Directory.Delete (TempFolder, true);
}
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 ()
{
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 {
[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});
}
[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});
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))]
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 ()
{
if (File.Exists (path))
File.Delete (path);
- }
+ }
}
}