diff --git a/internal/decoders/packet_header_chunk_test.go b/internal/decoders/packet_header_chunk_test.go new file mode 100644 index 0000000..1802a8c --- /dev/null +++ b/internal/decoders/packet_header_chunk_test.go @@ -0,0 +1,51 @@ +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) + } + } +}