mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 23:54:33 +01:00
Re-enable the golangci-lint job in CI (disabled Oct 2025), update to Go 1.25 and golangci-lint-action v7. Fix errcheck, gosimple S1009, staticcheck SA4031 and SA2001 errors across 54 files. Remaining ~39 lint errors will be addressed in follow-up commits.
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package byteframe
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"io"
|
|
"testing"
|
|
)
|
|
|
|
func TestByteFrame_SetBE(t *testing.T) {
|
|
bf := NewByteFrame()
|
|
// Default is already BigEndian, switch to LE first
|
|
bf.SetLE()
|
|
if bf.byteOrder != binary.LittleEndian {
|
|
t.Error("SetLE() should set LittleEndian")
|
|
}
|
|
|
|
// Now test SetBE
|
|
bf.SetBE()
|
|
if bf.byteOrder != binary.BigEndian {
|
|
t.Error("SetBE() should set BigEndian")
|
|
}
|
|
|
|
// Verify write/read works correctly in BE mode after switching
|
|
bf.WriteUint16(0x1234)
|
|
_, _ = bf.Seek(0, io.SeekStart)
|
|
got := bf.ReadUint16()
|
|
if got != 0x1234 {
|
|
t.Errorf("ReadUint16() = 0x%04X, want 0x1234", got)
|
|
}
|
|
|
|
// Verify raw bytes are in big endian order
|
|
bf2 := NewByteFrame()
|
|
bf2.SetLE()
|
|
bf2.SetBE()
|
|
bf2.WriteUint32(0xDEADBEEF)
|
|
data := bf2.Data()
|
|
if data[0] != 0xDE || data[1] != 0xAD || data[2] != 0xBE || data[3] != 0xEF {
|
|
t.Errorf("SetBE bytes: got %X, want DEADBEEF", data)
|
|
}
|
|
}
|
|
|
|
func TestByteFrame_LEReadWrite(t *testing.T) {
|
|
bf := NewByteFrame()
|
|
bf.SetLE()
|
|
|
|
bf.WriteUint32(0x12345678)
|
|
data := bf.Data()
|
|
// In LE, LSB first
|
|
if data[0] != 0x78 || data[1] != 0x56 || data[2] != 0x34 || data[3] != 0x12 {
|
|
t.Errorf("LE WriteUint32 bytes: got %X, want 78563412", data)
|
|
}
|
|
|
|
_, _ = bf.Seek(0, io.SeekStart)
|
|
got := bf.ReadUint32()
|
|
if got != 0x12345678 {
|
|
t.Errorf("LE ReadUint32() = 0x%08X, want 0x12345678", got)
|
|
}
|
|
}
|