Second + third of the four driver test clients. Both follow the same shape as otopcua-modbus-cli (#249) and consume Driver.Cli.Common for DriverCommandBase + SnapshotFormatter. New projects: - src/ZB.MOM.WW.OtOpcUa.Driver.AbCip.Cli/ — otopcua-abcip-cli. AbCipCommandBase carries gateway (ab://host[:port]/cip-path) + family (ControlLogix/CompactLogix/Micro800/GuardLogix) + timeout. Commands: probe, read, write, subscribe. Value parser covers every AbCipDataType atomic type (Bool, SInt..LInt, USInt..ULInt, Real, LReal, String, Dt); Structure writes refused as out-of-scope for the CLI. - src/ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli/ — otopcua-ablegacy-cli. AbLegacyCommandBase carries gateway + plc-type (Slc500/MicroLogix/Plc5/ LogixPccc) + timeout. Commands: probe (default address N7:0), read, write, subscribe. Value parser covers Bit, Int, Long, Float, AnalogInt, String, and the three sub-element types (TimerElement / CounterElement / ControlElement all land on int32 at the wire). Tests (35 new, 73 cumulative across the driver CLI family): - AB CIP: 17 tests — ParseValue happy-paths for every Logix atomic type, failure cases (non-numeric / bool garbage), tag-name synthesis. - AB Legacy: 18 tests — ParseValue coverage (Bit / Int / AnalogInt / Long / Float / String / sub-elements), PCCC address round-trip in tag names including bit-within-word + sub-element syntax. Docs: - docs/Driver.AbCip.Cli.md — family ↔ CIP-path cheat sheet + examples per command + typical workflows. - docs/Driver.AbLegacy.Cli.md — PCCC address primer (file letters → CLI --type) + known ab_server upstream gap cross-ref to #224 close-out. Wiring: - ZB.MOM.WW.OtOpcUa.slnx grew 4 entries (2 src + 2 tests). Full-solution build clean. `otopcua-abcip-cli --help` + `otopcua-ablegacy-cli --help` verified end-to-end. Next up (#251): S7 + TwinCAT CLIs, same pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
92 lines
3.1 KiB
C#
92 lines
3.1 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli.Commands;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Cli.Tests;
|
|
|
|
/// <summary>
|
|
/// Covers <see cref="WriteCommand.ParseValue"/>. PCCC types are narrower than AB CIP
|
|
/// (no 64-bit, no unsigned variants, no Structure / Dt) so the matrix is smaller.
|
|
/// </summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class WriteCommandParseValueTests
|
|
{
|
|
[Theory]
|
|
[InlineData("true", true)]
|
|
[InlineData("0", false)]
|
|
[InlineData("yes", true)]
|
|
[InlineData("OFF", false)]
|
|
public void ParseValue_Bit_accepts_common_aliases(string raw, bool expected)
|
|
{
|
|
WriteCommand.ParseValue(raw, AbLegacyDataType.Bit).ShouldBe(expected);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseValue_Int_signed_16bit()
|
|
{
|
|
WriteCommand.ParseValue("-32768", AbLegacyDataType.Int).ShouldBe((short)-32768);
|
|
WriteCommand.ParseValue("32767", AbLegacyDataType.Int).ShouldBe((short)32767);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseValue_AnalogInt_parses_same_as_Int()
|
|
{
|
|
// A-file uses N-file semantics — 16-bit signed with the same wire format.
|
|
WriteCommand.ParseValue("100", AbLegacyDataType.AnalogInt).ShouldBeOfType<short>();
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseValue_Long_32bit()
|
|
{
|
|
WriteCommand.ParseValue("-2147483648", AbLegacyDataType.Long).ShouldBe(int.MinValue);
|
|
WriteCommand.ParseValue("2147483647", AbLegacyDataType.Long).ShouldBe(int.MaxValue);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseValue_Float_invariant_culture()
|
|
{
|
|
WriteCommand.ParseValue("3.14", AbLegacyDataType.Float).ShouldBe(3.14f);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseValue_String_passthrough()
|
|
{
|
|
WriteCommand.ParseValue("hello slc", AbLegacyDataType.String).ShouldBe("hello slc");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(AbLegacyDataType.TimerElement)]
|
|
[InlineData(AbLegacyDataType.CounterElement)]
|
|
[InlineData(AbLegacyDataType.ControlElement)]
|
|
public void ParseValue_Element_types_land_on_int32(AbLegacyDataType type)
|
|
{
|
|
// T/C/R sub-elements are 32-bit at the wire level regardless of semantic meaning.
|
|
WriteCommand.ParseValue("42", type).ShouldBeOfType<int>();
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseValue_Bit_rejects_unknown_strings()
|
|
{
|
|
Should.Throw<CliFx.Exceptions.CommandException>(
|
|
() => WriteCommand.ParseValue("perhaps", AbLegacyDataType.Bit));
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseValue_non_numeric_for_numeric_types_throws()
|
|
{
|
|
Should.Throw<FormatException>(
|
|
() => WriteCommand.ParseValue("xyz", AbLegacyDataType.Int));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("N7:0", AbLegacyDataType.Int, "N7:0:Int")]
|
|
[InlineData("B3:0/3", AbLegacyDataType.Bit, "B3:0/3:Bit")]
|
|
[InlineData("F8:10", AbLegacyDataType.Float, "F8:10:Float")]
|
|
[InlineData("T4:0.ACC", AbLegacyDataType.TimerElement, "T4:0.ACC:TimerElement")]
|
|
public void SynthesiseTagName_preserves_PCCC_address_verbatim(
|
|
string address, AbLegacyDataType type, string expected)
|
|
{
|
|
ReadCommand.SynthesiseTagName(address, type).ShouldBe(expected);
|
|
}
|
|
}
|