From 8df1a9c8cb71e6667cd63a4100f2f6caf96cde4c Mon Sep 17 00:00:00 2001 From: Serge Camille Date: Mon, 4 Oct 2021 18:53:13 +0200 Subject: [PATCH] Add unit test for ReadClass uint32 bug. https://github.com/S7NetPlus/s7netplus/issues/414 --- S7.Net.UnitTest/TypeTests/ClassTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/S7.Net.UnitTest/TypeTests/ClassTests.cs b/S7.Net.UnitTest/TypeTests/ClassTests.cs index ba99c2c..03cbe44 100644 --- a/S7.Net.UnitTest/TypeTests/ClassTests.cs +++ b/S7.Net.UnitTest/TypeTests/ClassTests.cs @@ -17,6 +17,19 @@ namespace S7.Net.UnitTest.TypeTests Assert.AreEqual(Class.GetClassSize(new TestClassUnevenSize(3, 17)), 10); } + /// + /// Ensure Uint32 is correctly parsed through ReadClass functions. Adresses issue https://github.com/S7NetPlus/s7netplus/issues/414 + /// + [TestMethod] + public void TestUint32Read() + { + var result = new TestUint32(); + var data = new byte[4] { 0, 0, 0, 5 }; + var bytesRead = Class.FromBytes(result, data); + Assert.AreEqual(bytesRead, data.Length); + Assert.AreEqual(5u, result.Value1); + } + private class TestClassUnevenSize { public bool Bool { get; set; } @@ -29,5 +42,10 @@ namespace S7.Net.UnitTest.TypeTests Bools = new bool[bitCount]; } } + + private class TestUint32 + { + public uint Value1 { get; set; } + } } }