mirror of
https://github.com/evopro-ag/Sharp7Reactive.git
synced 2025-12-17 04:02:52 +00:00
Restructure and extens tests for converter
This commit is contained in:
@@ -5,41 +5,20 @@ using Shouldly;
|
||||
namespace Sharp7.Rx.Tests.S7ValueConverterTests;
|
||||
|
||||
[TestFixture]
|
||||
public class WriteToBuffer
|
||||
internal class WriteToBuffer:ConverterTestBase
|
||||
{
|
||||
static readonly IS7VariableNameParser parser = new S7VariableNameParser();
|
||||
|
||||
[TestCase(true, "DB0.DBx0.0", new byte[] {0x01})]
|
||||
[TestCase(false, "DB0.DBx0.0", new byte[] {0x00})]
|
||||
[TestCase(true, "DB0.DBx0.4", new byte[] {0x10})]
|
||||
[TestCase(false, "DB0.DBx0.4", new byte[] {0})]
|
||||
[TestCase((byte) 18, "DB0.DBB0", new byte[] {0x12})]
|
||||
[TestCase((short) 4660, "DB0.INT0", new byte[] {0x12, 0x34})]
|
||||
[TestCase((short) -3532, "DB0.INT0", new byte[] {0xF2, 0x34})]
|
||||
[TestCase(-3532, "DB0.INT0", new byte[] {0xF2, 0x34})]
|
||||
[TestCase(305419879, "DB0.DINT0", new byte[] {0x12, 0x34, 0x56, 0x67})]
|
||||
[TestCase(-231451033, "DB0.DINT0", new byte[] {0xF2, 0x34, 0x56, 0x67})]
|
||||
[TestCase(1311768394163015151L, "DB0.dul0", new byte[] {0x12, 0x34, 0x56, 0x67, 0x89, 0xAB, 0xCD, 0xEF})]
|
||||
[TestCase(-994074615050678801L, "DB0.dul0", new byte[] {0xF2, 0x34, 0x56, 0x67, 0x89, 0xAB, 0xCD, 0xEF})]
|
||||
[TestCase(1311768394163015151uL, "DB0.dul0", new byte[] {0x12, 0x34, 0x56, 0x67, 0x89, 0xAB, 0xCD, 0xEF})]
|
||||
[TestCase(17452669458658872815uL, "DB0.dul0", new byte[] {0xF2, 0x34, 0x56, 0x67, 0x89, 0xAB, 0xCD, 0xEF})]
|
||||
[TestCase(new byte[] {0x12, 0x34, 0x56, 0x67}, "DB0.DBB0.4", new byte[] {0x12, 0x34, 0x56, 0x67})]
|
||||
[TestCase(0.25f, "DB0.D0", new byte[] {0x3E, 0x80, 0x00, 0x00})]
|
||||
[TestCase("ABCD", "DB0.string0.4", new byte[] {0x04, 0x04, 0x41, 0x42, 0x43, 0x44})]
|
||||
[TestCase("ABCD", "DB0.string0.8", new byte[] {0x08, 0x04, 0x41, 0x42, 0x43, 0x44, 0x00, 0x00, 0x00, 0x00})]
|
||||
[TestCase("ABCD", "DB0.string0.2", new byte[] {0x02, 0x02, 0x41, 0x42})]
|
||||
[TestCase("ABCD", "DB0.DBB0.4", new byte[] {0x41, 0x42, 0x43, 0x44})]
|
||||
public void Write<T>(T input, string address, byte[] expected)
|
||||
[TestCaseSource(nameof(GetValidTestCases))]
|
||||
public void Write(ConverterTestCase tc)
|
||||
{
|
||||
//Arrange
|
||||
var variableAddress = parser.Parse(address);
|
||||
var buffer = new byte[variableAddress.BufferLength];
|
||||
var buffer = new byte[tc.VariableAddress.BufferLength];
|
||||
var write = CreateWriteMethod(tc);
|
||||
|
||||
//Act
|
||||
S7ValueConverter.WriteToBuffer(buffer, input, variableAddress);
|
||||
write.Invoke(null, [buffer, tc.Value, tc.VariableAddress]);
|
||||
|
||||
//Assert
|
||||
buffer.ShouldBe(expected);
|
||||
buffer.ShouldBe(tc.Data);
|
||||
}
|
||||
|
||||
[TestCase((char) 18, "DB0.DBB0")]
|
||||
@@ -47,7 +26,7 @@ public class WriteToBuffer
|
||||
public void Invalid<T>(T input, string address)
|
||||
{
|
||||
//Arrange
|
||||
var variableAddress = parser.Parse(address);
|
||||
var variableAddress = Parser.Parse(address);
|
||||
var buffer = new byte[variableAddress.BufferLength];
|
||||
|
||||
//Act
|
||||
|
||||
Reference in New Issue
Block a user