mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 15:43:49 +01:00
Add unit tests across multiple packages: - byteframe: SetBE/SetLE byte order switching - config: Mode.String() for all safe version ranges - mhfpacket: 28 Parse methods, 5 Build methods, empty packet builds, variable-length packets, NOT IMPLEMENTED error paths, UpdateWarehouse - network: PacketID.String() for known IDs, out-of-range, and all valid - channelserver: handleMsgMhfGetPaperData (6 switch cases), grpToGR (11 input values), gacha handlers, TimeGameAbsolute, equipSkinHistSize (4 config branches), guild mission handlers, dumpSaveData disabled path - entranceserver: makeHeader with various inputs
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)
|
|
}
|
|
}
|