diff --git a/diskSubHeader_whitebox_test.go b/diskSubHeader_whitebox_test.go new file mode 100644 index 0000000..a024331 --- /dev/null +++ b/diskSubHeader_whitebox_test.go @@ -0,0 +1,38 @@ +package main + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +// TestParseTelemetrySubHeader_WithGoodBuffer +// Given a well structured buffer it will output the expected +// DiskSubHeader struct +func TestParseTelemetrySubHeader_WithGoodBuffer(t *testing.T) { + // Arrange + header := [32]byte{ + 0x54, 0x1e, 0x14, 0x67, 0x00, 0x00, 0x00, 0x00, 0x54, 0x09, 0x00, 0xf0, + 0xee, 0x7e, 0x6b, 0x40, 0x53, 0x74, 0x88, 0x44, 0x44, 0x86, 0x8f, 0x40, + 0x08, 0x00, 0x00, 0x00, 0xe1, 0xb8, 0x00, 0x00, + } + + expectedHeader := DiskSubHeader{ + StartDate: 1729371732, + StartTime: 219.96666717536084, + EndTime: 1008.7833338413715, + LapCount: 8, + RecordCount: 47329, + } + + // Act + headers, err := parseTelemetrySubHeader(header) + + // Assert + if err != nil { + t.Fatalf("Error parsing buffer: %v", err) + } + if !cmp.Equal(&expectedHeader, headers) { + t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers) + } +} diff --git a/headers_whitebox_test.go b/headers_whitebox_test.go index 0cdef96..a767268 100644 --- a/headers_whitebox_test.go +++ b/headers_whitebox_test.go @@ -10,42 +10,43 @@ import ( // Given a well structured buffer it will output the expected // TelemetryHeaders struct func TestParseTelemetryHeader_WithGoodBuffer(t *testing.T) { - // Arrange - header := [112]byte{ - 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x05, 0x3f, 0x00, 0x00, 0x90, 0x99, 0x00, 0x00, - 0x10, 0x01, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x1d, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x60, 0x2b, 0x00, 0x00, 0x95, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - } + // Arrange + header := [112]byte{ + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x05, 0x3f, 0x00, 0x00, 0x90, 0x99, 0x00, 0x00, + 0x10, 0x01, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x1d, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x60, 0x2b, 0x00, 0x00, 0x95, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + } - expectedHeader := TelemetryHeaders{ - Version: 2, - Status: 1, - TickRate: 60, - SessionInfoUpdate: 0, - SessionInfoLength: 16133, - SessionInfoOffset: 39312, - NumVars: 272, - VarHeaderOffset: 144, - NumBuf: 1, - BufLen: 1053, - BufOffset: 55445, - } + expectedHeader := TelemetryHeaders{ + Version: 2, + Status: 1, + TickRate: 60, + SessionInfoUpdate: 0, + SessionInfoLength: 16133, + SessionInfoOffset: 39312, + NumVars: 272, + VarHeaderOffset: 144, + NumBuf: 1, + BufLen: 1053, + Padding: [12]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0x2b, 0x0, 0x0}, + BufOffset: 55445, + } - // Act - headers, err := parseTelemetryHeader(header) + // Act + headers, err := parseTelemetryHeader(header) - // Assert - if err != nil { - t.Fatalf("Error parsing buffer: %v", err) - } - if cmp.Equal(expectedHeader, headers) { - t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers) - } + // Assert + if err != nil { + t.Fatalf("Error parsing buffer: %v", err) + } + if !cmp.Equal(&expectedHeader, headers) { + t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers) + } }