Files
psn-go/internal/decoders/packet_header_chunk_test.go
T

52 lines
1.2 KiB
Go

package decoders
import (
"fmt"
"reflect"
"testing"
)
func TestGoodPacketHeaderChunkDecoding(t *testing.T) {
testCases := []struct {
description string
bytes []byte
expected PacketHeaderChunk
}{
{
description: "PacketHeaderChunk",
bytes: []byte{
0, 0, 12, 0, 210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123,
},
expected: PacketHeaderChunk{
Chunk: Chunk{
ChunkData: []byte{210, 2, 150, 73, 0, 0, 0, 0, 2, 3, 1, 123},
Header: ChunkHeader{DataLen: 12, Id: 0, HasSubchunks: false},
},
Data: PacketHeaderChunkData{
PacketTimestamp: 1234567890,
VersionHigh: 2,
VersionLow: 3,
FrameId: 1,
FramePacketCount: 123,
},
},
},
}
for _, testCase := range testCases {
actual, err := DecodePacketHeaderChunk(testCase.bytes)
if err != nil {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Println(err)
}
if !reflect.DeepEqual(actual, testCase.expected) {
t.Errorf("Test '%s' failed to decode chunk properly", testCase.description)
fmt.Printf("expected: %+v\n", testCase.expected)
fmt.Printf("actual: %+v\n", actual)
}
}
}