Simplify TPKT Read buffer length arguments and improve exception message.

This commit is contained in:
Serge Camille
2020-09-02 16:34:18 +02:00
parent d11f46eedb
commit edfa208c3e
2 changed files with 14 additions and 2 deletions

View File

@@ -34,6 +34,10 @@ namespace S7.Net.UnitTest
int _position = 0;
public override int Read(byte[] buffer, int offset, int count)
{
if (_position >= Data.Length)
{
return 0;
}
buffer[offset] = Data[_position];
++_position;
return 1;
@@ -81,5 +85,13 @@ namespace S7.Net.UnitTest
Assert.AreEqual(fullMessage.Length, t.Length);
Assert.AreEqual(fullMessage.Last(), t.Data.Last());
}
[TestMethod]
public void TPKT_ReadStreamTooShort()
{
var fullMessage = ProtocolUnitTest.StringToByteArray("0300002902f0803203000000010002001400");
var m = new TestStream1BytePerRead(fullMessage);
Assert.ThrowsException<TPKTInvalidException>(() => TPKT.Read(m));
}
}
}