56 lines
2.4 KiB
C#
56 lines
2.4 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport.Pccc;
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Ab.Transport.Tests.Pccc;
|
|
|
|
public sealed class PcccAddressTests
|
|
{
|
|
[Theory]
|
|
[InlineData("O", 0x8B)] [InlineData("I", 0x8C)] [InlineData("S", 0x84)] [InlineData("B", 0x85)]
|
|
[InlineData("T", 0x86)] [InlineData("C", 0x87)] [InlineData("R", 0x88)] [InlineData("N", 0x89)]
|
|
[InlineData("F", 0x8A)] [InlineData("ST", 0x8D)] [InlineData("A", 0x8E)] [InlineData("L", 0x91)]
|
|
public void File_type_codes(string letter, int code) => PcccFileType.CodeFor(letter).ShouldBe((byte)code);
|
|
|
|
[Theory]
|
|
[InlineData("N7:0", "N", 7, 0, null, null)]
|
|
[InlineData("F8:12", "F", 8, 12, null, null)]
|
|
[InlineData("B3:1/4", "B", 3, 1, null, 4)]
|
|
[InlineData("ST9:2", "ST", 9, 2, null, null)]
|
|
[InlineData("T4:0.ACC", "T", 4, 0, 2, null)]
|
|
[InlineData("T4:1.PRE", "T", 4, 1, 1, null)]
|
|
[InlineData("T4:0.DN", "T", 4, 0, 0, 13)]
|
|
[InlineData("T4:0.EN", "T", 4, 0, 0, 15)]
|
|
[InlineData("C5:0.CU", "C", 5, 0, 0, 15)]
|
|
[InlineData("C5:0.OV", "C", 5, 0, 0, 12)]
|
|
[InlineData("C5:0.UA", "C", 5, 0, 0, 10)]
|
|
[InlineData("L9:0/31", "L", 9, 0, null, 31)]
|
|
[InlineData("R6:0.LEN", "R", 6, 0, 1, null)]
|
|
[InlineData("R6:0.POS", "R", 6, 0, 2, null)]
|
|
[InlineData("I:0/1", "I", null, 0, null, 1)]
|
|
[InlineData("n7:0", "N", 7, 0, null, null)]
|
|
public void Parses(string text, string letter, int? file, int element, int? sub, int? bit)
|
|
{
|
|
var a = PcccAddress.TryParse(text)!;
|
|
a.ShouldNotBeNull();
|
|
a.FileLetter.ShouldBe(letter);
|
|
a.FileNumber.ShouldBe(file);
|
|
a.Element.ShouldBe(element);
|
|
a.ResolveSubElement().ShouldBe((sub ?? 0, bit));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")] [InlineData("N7")] [InlineData("N:0")] [InlineData("X7:0")] [InlineData("I1:0")]
|
|
[InlineData("T4:0.FOO")] [InlineData("N7:0.ACC")] [InlineData("N7:-1")] [InlineData("N7:0/x")]
|
|
[InlineData("N7:0/16")] [InlineData("F8:0/1")] [InlineData("L9:0/32")] [InlineData("T4:0/3")]
|
|
public void Rejects(string text) => PcccAddress.TryParse(text).ShouldBeNull();
|
|
|
|
[Fact]
|
|
public void Effective_file_number_is_implicit_for_IOS()
|
|
{
|
|
PcccAddress.TryParse("O:0")!.EffectiveFileNumber.ShouldBe(0);
|
|
PcccAddress.TryParse("I:0")!.EffectiveFileNumber.ShouldBe(1);
|
|
PcccAddress.TryParse("S:0")!.EffectiveFileNumber.ShouldBe(2);
|
|
PcccAddress.TryParse("N9:0")!.EffectiveFileNumber.ShouldBe(9);
|
|
}
|
|
}
|