using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Driver.AbCip;
namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Tests;
///
/// Array element stride. Seen live on a production CompactLogix: reading
/// Program:UN01_Press._ModeNames (STR0016[32], 4 elements requested) returned an
/// 80-byte buffer with libplctag's ElementSize unset; the driver strode 88 bytes (built-in
/// STRING) and the read failed ErrorOutOfBounds. The real values were
/// "undefined" / "Production" / "Maintenance" / "Manual" at a 20-byte stride.
///
[Trait("Category", "Unit")]
public sealed class AbCipArrayStrideTests
{
/// A user string type's stride comes from the buffer, not the built-in STRING size.
[Fact]
public void User_string_array_strides_by_buffer_size_over_count()
{
LibplctagTagRuntime.ResolveArrayStride(null, bufferSize: 80, count: 4, AbCipDataType.String).ShouldBe(20);
}
/// The built-in STRING still strides 88.
[Fact]
public void Builtin_STRING_array_strides_88()
{
LibplctagTagRuntime.ResolveArrayStride(null, bufferSize: 3 * 88, count: 3, AbCipDataType.String).ShouldBe(88);
}
/// libplctag's own element size wins when it is populated.
[Fact]
public void Reported_element_size_wins()
{
LibplctagTagRuntime.ResolveArrayStride(4, bufferSize: 80, count: 4, AbCipDataType.DInt).ShouldBe(4);
}
/// An empty or uneven buffer falls back to the static per-type size.
[Fact]
public void Empty_or_uneven_buffer_falls_back_to_the_type_size()
{
LibplctagTagRuntime.ResolveArrayStride(null, bufferSize: 0, count: 4, AbCipDataType.Real).ShouldBe(4);
LibplctagTagRuntime.ResolveArrayStride(null, bufferSize: 81, count: 4, AbCipDataType.String).ShouldBe(88);
}
}