Files
lmxopcua/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport.Tests/Wire/CipWriterTests.cs
T
Joseph Doherty 7892eb13a8 fix(abcip): harden Ab.Transport CIP codec and EncapsulationClient (#564, #565)
CIP codec (#564): PatchU16 bounds guard; CipReply content equality; CipPath
port/length/ASCII/odd/oversize validation with ArgumentException for malformed
tag names and routes; CipPath.MessageRouter/ConnectionManager are now
ReadOnlySpan<byte>; refused Forward Open surfaces ForwardOpenRefusedException
with structured general/extended status; test CaptureFile uses BinaryPrimitives.

EncapsulationClient (#565): frame write bounded by the exchange timeout, which
faults (never cancels) the connection; finite positive timeouts enforced at
every entry point; gate wait bounded by the timeout; deterministic reorder of
the 300 ms test; new dispose-during-drain, gate-wait and RegisterSession
zero-context tests.

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
2026-10-07 22:54:32 -04:00

28 lines
904 B
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport.Wire;
namespace ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport.Tests.Wire;
public sealed class CipWriterTests
{
[Fact]
public void PatchU16_overwrites_an_already_written_word()
{
var w = new CipWriter().U16(0).U8(7);
w.PatchU16(0, 0xABCD);
w.ToArray().ShouldBe(new byte[] { 0xCD, 0xAB, 0x07 });
}
[Theory]
[InlineData(-1)]
[InlineData(2)] // would straddle the end: only bytes 0..2 are written
[InlineData(3)]
[InlineData(100)] // inside spare buffer capacity (256), but never written
public void PatchU16_outside_the_written_range_throws(int offset)
{
var w = new CipWriter().U16(0).U8(7);
Should.Throw<ArgumentOutOfRangeException>(() => w.PatchU16(offset, 1));
w.ToArray().ShouldBe(new byte[] { 0, 0, 7 }); // nothing was patched
}
}