Added the test for the disksubheaders and fixed the headers one
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
+36
-35
@@ -10,42 +10,43 @@ import (
|
|||||||
// Given a well structured buffer it will output the expected
|
// Given a well structured buffer it will output the expected
|
||||||
// TelemetryHeaders struct
|
// TelemetryHeaders struct
|
||||||
func TestParseTelemetryHeader_WithGoodBuffer(t *testing.T) {
|
func TestParseTelemetryHeader_WithGoodBuffer(t *testing.T) {
|
||||||
// Arrange
|
// Arrange
|
||||||
header := [112]byte{
|
header := [112]byte{
|
||||||
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x05, 0x3f, 0x00, 0x00, 0x90, 0x99, 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,
|
0x10, 0x01, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
0x1d, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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,
|
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, 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{
|
expectedHeader := TelemetryHeaders{
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Status: 1,
|
Status: 1,
|
||||||
TickRate: 60,
|
TickRate: 60,
|
||||||
SessionInfoUpdate: 0,
|
SessionInfoUpdate: 0,
|
||||||
SessionInfoLength: 16133,
|
SessionInfoLength: 16133,
|
||||||
SessionInfoOffset: 39312,
|
SessionInfoOffset: 39312,
|
||||||
NumVars: 272,
|
NumVars: 272,
|
||||||
VarHeaderOffset: 144,
|
VarHeaderOffset: 144,
|
||||||
NumBuf: 1,
|
NumBuf: 1,
|
||||||
BufLen: 1053,
|
BufLen: 1053,
|
||||||
BufOffset: 55445,
|
Padding: [12]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0x2b, 0x0, 0x0},
|
||||||
}
|
BufOffset: 55445,
|
||||||
|
}
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
headers, err := parseTelemetryHeader(header)
|
headers, err := parseTelemetryHeader(header)
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error parsing buffer: %v", err)
|
t.Fatalf("Error parsing buffer: %v", err)
|
||||||
}
|
}
|
||||||
if cmp.Equal(expectedHeader, headers) {
|
if !cmp.Equal(&expectedHeader, headers) {
|
||||||
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
|
t.Fatalf("Expected:\n%#v\nGot:\n%#v\n", expectedHeader, headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user