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:
@@ -1,45 +1,25 @@
|
||||
using NUnit.Framework;
|
||||
using Sharp7.Rx.Interfaces;
|
||||
using Shouldly;
|
||||
|
||||
namespace Sharp7.Rx.Tests.S7ValueConverterTests;
|
||||
|
||||
[TestFixture]
|
||||
public class ConvertBothWays
|
||||
internal class ConvertBothWays : ConverterTestBase
|
||||
{
|
||||
static readonly IS7VariableNameParser parser = new S7VariableNameParser();
|
||||
|
||||
[TestCase(true, "DB0.DBx0.0")]
|
||||
[TestCase(false, "DB0.DBx0.0")]
|
||||
[TestCase(true, "DB0.DBx0.4")]
|
||||
[TestCase(false, "DB0.DBx0.4")]
|
||||
[TestCase((byte) 18, "DB0.DBB0")]
|
||||
[TestCase((short) 4660, "DB0.INT0")]
|
||||
[TestCase((short)-3532, "DB0.INT0")]
|
||||
[TestCase(-3532, "DB0.INT0")]
|
||||
[TestCase(305419879, "DB0.DINT0")]
|
||||
[TestCase(-231451033, "DB0.DINT0")]
|
||||
[TestCase(1311768394163015151L, "DB0.dul0")]
|
||||
[TestCase(-994074615050678801L, "DB0.dul0")]
|
||||
[TestCase(1311768394163015151uL, "DB0.dul0")]
|
||||
[TestCase(17452669458658872815uL, "DB0.dul0")]
|
||||
[TestCase(new byte[] { 0x12, 0x34, 0x56, 0x67 }, "DB0.DBB0.4")]
|
||||
[TestCase(0.25f, "DB0.D0")]
|
||||
[TestCase("ABCD", "DB0.string0.4")]
|
||||
[TestCase("ABCD", "DB0.string0.4")] // Clip to length in Address
|
||||
[TestCase("ABCD", "DB0.DBB0.4")]
|
||||
public void Write<T>(T input, string address)
|
||||
[TestCaseSource(nameof(GetValidTestCases))]
|
||||
public void Convert(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);
|
||||
var read = CreateReadMethod(tc);
|
||||
|
||||
//Act
|
||||
S7ValueConverter.WriteToBuffer(buffer, input, variableAddress);
|
||||
var result = S7ValueConverter.ConvertToType<T>(buffer, variableAddress);
|
||||
write.Invoke(null, [buffer, tc.Value, tc.VariableAddress]);
|
||||
var result = read.Invoke(null, [buffer, tc.VariableAddress]);
|
||||
|
||||
//Assert
|
||||
result.ShouldBe(input);
|
||||
result.ShouldBe(tc.Value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user