From 7bf2dc49cff822492747ba7ed6c06f97f234f173 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Fri, 22 May 2026 11:25:25 -0400 Subject: [PATCH] fix(driver-twincat): align status-mapper tests with corrected ADS codes (Driver.TwinCAT-011) The Driver.TwinCAT-011 fix rewrote TwinCATStatusMapper with correct numeric values from Beckhoff.TwinCAT.Ads 7.0.172 (e.g. DeviceSymbol- VersionInvalid = 1809 / 0x0711, not 1794 / 0x0702). Pre-existing StatusMapper_covers_known_ads_error_codes InlineData cases were written against the old wrong mappings and now fail; StatusMapper_recognises_ symbol_version_changed_code asserted the legacy 0x0702 constant. Update both test files to match the corrected mapper and add a comment documenting the correction. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../TwinCATDriverTests.cs | 21 ++++++++++++------- .../TwinCATHighFindingsRegressionTests.cs | 10 ++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATDriverTests.cs b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATDriverTests.cs index 6f30bde..efd76fe 100644 --- a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATDriverTests.cs +++ b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATDriverTests.cs @@ -92,14 +92,19 @@ public sealed class TwinCATDriverTests } [Theory] - [InlineData(0u, TwinCATStatusMapper.Good)] - [InlineData(1798u, TwinCATStatusMapper.BadNodeIdUnknown)] // symbol not found - [InlineData(1808u, TwinCATStatusMapper.BadNotWritable)] // access denied - [InlineData(1861u, TwinCATStatusMapper.BadTimeout)] // sync timeout - [InlineData(1793u, TwinCATStatusMapper.BadOutOfRange)] // invalid index group - [InlineData(1794u, TwinCATStatusMapper.BadOutOfRange)] // invalid index offset - [InlineData(1792u, TwinCATStatusMapper.BadNotSupported)] // service not supported - [InlineData(7u, TwinCATStatusMapper.BadCommunicationError)] // port unreachable + [InlineData(0u, TwinCATStatusMapper.Good)] + // Device-layer codes — confirmed from Beckhoff.TwinCAT.Ads 7.0.172 AdsErrorCode enum + [InlineData(1792u, TwinCATStatusMapper.BadDeviceFailure)] // DeviceError (generic) + [InlineData(1793u, TwinCATStatusMapper.BadNotSupported)] // DeviceServiceNotSupported + [InlineData(1794u, TwinCATStatusMapper.BadOutOfRange)] // DeviceInvalidGroup (ADS index-group error) + [InlineData(1798u, TwinCATStatusMapper.BadTypeMismatch)] // DeviceInvalidData (data format mismatch) + [InlineData(1804u, TwinCATStatusMapper.BadNodeIdUnknown)] // DeviceNotFound + [InlineData(1808u, TwinCATStatusMapper.BadNodeIdUnknown)] // DeviceSymbolNotFound + [InlineData(1809u, TwinCATStatusMapper.BadInvalidState)] // DeviceSymbolVersionInvalid — rediscovery trigger + [InlineData(1827u, TwinCATStatusMapper.BadNotWritable)] // DeviceAccessDenied + [InlineData(1861u, TwinCATStatusMapper.BadTimeout)] // ClientSyncTimeOut + // AMS router errors + [InlineData(7u, TwinCATStatusMapper.BadCommunicationError)] // TargetMachineNotFound [InlineData(99999u, TwinCATStatusMapper.BadCommunicationError)] // unknown → generic comm fail public void StatusMapper_covers_known_ads_error_codes(uint adsError, uint expected) { diff --git a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATHighFindingsRegressionTests.cs b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATHighFindingsRegressionTests.cs index 723bf27..d15cb59 100644 --- a/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATHighFindingsRegressionTests.cs +++ b/tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests/TwinCATHighFindingsRegressionTests.cs @@ -181,14 +181,18 @@ public sealed class TwinCATHighFindingsRegressionTests factory.Clients[0].FireSymbolVersionChanged(); raised.ShouldNotBeNull(); - raised!.Reason.ShouldContain("0x0702"); + raised!.Reason.ShouldContain("0x0711"); } [Fact] public void StatusMapper_recognises_symbol_version_changed_code() { - TwinCATStatusMapper.AdsSymbolVersionChanged.ShouldBe(0x0702u); - TwinCATStatusMapper.IsSymbolVersionChanged(0x0702u).ShouldBeTrue(); + // DeviceSymbolVersionInvalid is 1809 (0x0711) per Beckhoff.TwinCAT.Ads 7.0.172. + // Legacy docs cited 0x0702 (= DeviceInvalidGroup, 1794) — that was a transcription error + // corrected in Driver.TwinCAT-011. + TwinCATStatusMapper.AdsSymbolVersionChanged.ShouldBe(0x0711u); // = 1809u + TwinCATStatusMapper.IsSymbolVersionChanged(0x0711u).ShouldBeTrue(); + TwinCATStatusMapper.IsSymbolVersionChanged(0x0702u).ShouldBeFalse(); // DeviceInvalidGroup is NOT the trigger TwinCATStatusMapper.IsSymbolVersionChanged(0u).ShouldBeFalse(); } }