set {
CheckIfClosedThrowDisposed ();
- if (value == capacity)
- return; // LAMENESS: see MemoryStreamTest.ConstructorFive
if (!expandable)
throw new NotSupportedException ("Cannot expand this MemoryStream");
public override int Read ([In,Out] byte [] buffer, int offset, int count)
{
- CheckIfClosedThrowDisposed ();
-
if (buffer == null)
throw new ArgumentNullException ("buffer");
throw new ArgumentException ("offset+count",
"The size of the buffer is less than offset + count.");
+ CheckIfClosedThrowDisposed ();
+
if (position >= length || count == 0)
return 0;
public override void Write (byte [] buffer, int offset, int count)
{
- CheckIfClosedThrowDisposed ();
-
if (!canWrite)
throw new NotSupportedException ("Cannot write to this stream.");
throw new ArgumentException ("offset+count",
"The size of the buffer is less than offset + count.");
+ CheckIfClosedThrowDisposed ();
+
// reordered to avoid possible integer overflow
if (position > length - count)
Expand (position + count);
testStreamData [51] = saved;
}
ms.Position = 100;
- bool gotException = false;
+
try {
ms.WriteByte (23);
+ Assert.Fail ("#05");
} catch (NotSupportedException) {
- gotException = true;
}
- if (!gotException)
- Assert.Fail ("#05");
-
- ms.Capacity = 100; // Allowed. It's the same as the one in the ms.
- // This is lame, as the length is 50!!!
+ try {
+ ms.Capacity = 100;
+ Assert.Fail ("#06");
+ } catch (NotSupportedException) {
+ }
- gotException = false;
try {
ms.Capacity = 51;
+ Assert.Fail ("#07");
} catch (NotSupportedException) {
- gotException = true;
}
- if (!gotException)
- Assert.Fail ("#07");
-
AssertEquals ("#08", 50, ms.ToArray ().Length);
}
if (!thrown)
Assert.Fail ("#02");
- // The first exception thrown is ObjectDisposed, not ArgumentNull
- thrown = false;
try {
ms.Read (null, 0, 1);
- } catch (ObjectDisposedException) {
- thrown = true;
- }
-
- if (!thrown)
Assert.Fail ("#03");
+ } catch (ArgumentNullException) {
+ }
- thrown = false;
try {
ms.Write (null, 0, 1);
- } catch (ObjectDisposedException) {
+ Assert.Fail ("#04");
+ } catch (ArgumentNullException) {
thrown = true;
}
-
- if (!thrown)
- Assert.Fail ("#03");
}
[Test]