initial commit
This commit is contained in:
52
ENIGProtocol.Tests/EEProtocolTests.cs
Normal file
52
ENIGProtocol.Tests/EEProtocolTests.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Xunit;
|
||||
using ENIG;
|
||||
|
||||
namespace ENIGProtocol.Tests
|
||||
{
|
||||
public class EEProtocolTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestCRC16Calculation()
|
||||
{
|
||||
// 테스트 데이터
|
||||
byte[] testData = new byte[] { 0x02,0x00,0xFF };
|
||||
|
||||
// CRC16 계산
|
||||
var protocol = new EEProtocol();
|
||||
ushort crc = protocol.CalculateCRC16(testData);
|
||||
|
||||
// 예상 결과와 비교
|
||||
Assert.Equal(0x1789, crc); // 실제 예상값으로 수정 필요
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPacketCreation()
|
||||
{
|
||||
// 패킷 생성 테스트
|
||||
var protocol = new EEProtocol();
|
||||
byte[] packet = protocol.CreatePacket(0x01, 0x02, new byte[] { 0x03, 0x04 });
|
||||
|
||||
// 패킷 구조 검증
|
||||
Assert.Equal(0x02, packet[0]); // STX
|
||||
Assert.Equal(0x04, packet[1]); // Length
|
||||
Assert.Equal(0x01, packet[2]); // ID
|
||||
Assert.Equal(0x02, packet[3]); // Command
|
||||
Assert.Equal(0x03, packet[4]); // Data[0]
|
||||
Assert.Equal(0x04, packet[5]); // Data[1]
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPacketParsing()
|
||||
{
|
||||
// 패킷 파싱 테스트
|
||||
var protocol = new EEProtocol();
|
||||
//byte[] testPacket = new byte[] { 0x02, 0x04, 0x01, 0x02, 0x03, 0x04, 0x12, 0x34, 0x03 };
|
||||
byte[] testPacket = new byte[] { 0x02, 0x02, 0x00, 0xFF, 0x89, 0x17, 0x03 };
|
||||
|
||||
|
||||
bool result = protocol.ParsePacket(testPacket);
|
||||
|
||||
Assert.True(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user