Prepares RioJoy.Core for the net40 (Windows XP) target, which has no System.Memory, ValueTask, or System.Text.Json: - IRioTransport and the whole protocol/framing layer now use byte[] + Task (RioPacket.Payload, PacketParser/Builder, RioChecksum, replies, AnalogReport, RioHidReport). At 9600 baud Span bought nothing; the SerialPortTransport bridge copies disappear entirely. - ConfigStore/OverlayTemplateStore switch to Newtonsoft 13 with the same conventions (indented, PascalCase, string enums, null-skipping); verified against the real STJ-written config.json and regions.json (load + round-trip). System.Memory and System.Text.Json packages dropped. 275 tests green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
37 lines
887 B
C#
37 lines
887 B
C#
using RioJoy.Core.Protocol;
|
|
using Xunit;
|
|
|
|
namespace RioJoy.Core.Tests.Protocol;
|
|
|
|
public class RioChecksumTests
|
|
{
|
|
[Fact]
|
|
public void Empty_IsZero()
|
|
{
|
|
Assert.Equal(0, RioChecksum.Compute(new byte[0]));
|
|
}
|
|
|
|
[Fact]
|
|
public void SumsLow7Bits()
|
|
{
|
|
// (0x84 & 0x7F) + (0x05 & 0x7F) + (0x3C & 0x7F) = 0x04 + 0x05 + 0x3C = 0x45
|
|
byte sum = RioChecksum.Compute(new byte[] { 0x84, 0x05, 0x3C });
|
|
Assert.Equal(0x45, sum);
|
|
}
|
|
|
|
[Fact]
|
|
public void MasksResultTo7Bits()
|
|
{
|
|
// Sum of low-7-bits = 0x7F + 0x7F = 0xFE; masked to 7 bits → 0x7E.
|
|
byte sum = RioChecksum.Compute(new byte[] { 0x7F, 0x7F });
|
|
Assert.Equal(0x7E, sum);
|
|
}
|
|
|
|
[Fact]
|
|
public void IgnoresHighBitOfInputs()
|
|
{
|
|
// 0x82 contributes only 0x02.
|
|
Assert.Equal(0x02, RioChecksum.Compute(new byte[] { 0x82 }));
|
|
}
|
|
}
|