public void TestBoundsCheck()
{
byte[] data = { 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 };
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DummyFilterStream dfs = new DummyFilterStream(bos);
bool caughtException = false;
// -ve length
try
{
dfs.Write(data, 0, -5);
}
#pragma warning disable 168
catch (ArgumentOutOfRangeException ie)
#pragma warning restore 168
{
caughtException = true;
}
finally
{
if (!caughtException)
fail("Test failed");
}
// -ve offset
caughtException = false;
try
{
dfs.Write(data, -2, 5);
}
#pragma warning disable 168
catch (ArgumentOutOfRangeException ie)
#pragma warning restore 168
{
caughtException = true;
}
finally
{
if (!caughtException)
fail("Test failed");
}
// off + len > data.length
caughtException = false;
try
{
dfs.Write(data, 6, 5);
}
#pragma warning disable 168
catch (ArgumentException ie)
#pragma warning restore 168
{
caughtException = true;
}
finally
{
if (!caughtException)
fail("Test failed");
}
// null data
caughtException = false;
try
{
dfs.Write(null, 0, 5);
}
#pragma warning disable 168
catch (ArgumentNullException re)
#pragma warning restore 168
{
caughtException = true;
}
finally
{
if (!caughtException)
fail("Test failed");
}
}