Files
artnet-go/timecode_test.go
2026-05-30 09:20:20 -05:00

86 lines
1.8 KiB
Go

package artnet_test
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/jwetzell/artnet-go"
)
func TestGoodArtTimeCodeUnmarshal(t *testing.T) {
tests := []struct {
Name string
Data []byte
Expected *artnet.ArtTimeCode
}{
{
Name: "Basic timecode",
Data: []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 151, 0, 14, 0, 0, 11, 17, 3, 0, 0},
Expected: &artnet.ArtTimeCode{
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
},
},
}
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
got := &artnet.ArtTimeCode{}
err := got.UnmarshalBinary(test.Data)
if err != nil {
t.Fatalf("failed to decode ArtTimeCode: %s", err)
}
diff := cmp.Diff(test.Expected, got, cmpopts.IgnoreUnexported(artnet.ArtTimeCode{}))
if diff != "" {
t.Fatalf("ArtTimeCode does not match\n%s", diff)
}
})
}
}
func BenchmarkArtTimeCodeUnmarshalBinary(b *testing.B) {
data := []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 151, 0, 14, 0, 0, 11, 17, 3, 0, 0}
for b.Loop() {
got := artnet.ArtTimeCode{}
err := got.UnmarshalBinary(data)
if err != nil {
b.Fatalf("failed to decode ArtTimeCode: %s", err)
}
}
}
func BenchmarkArtTimeCodeMarshalBinary(b *testing.B) {
data := artnet.ArtTimeCode{
StreamId: 0,
Frames: 11,
Seconds: 17,
Minutes: 3,
Hours: 0,
Type: 0,
}
for b.Loop() {
_, err := data.MarshalBinary()
if err != nil {
b.Fatalf("failed to encode ArtTimeCode: %s", err)
}
}
}
func FuzzArtTimeCodeUnmarshalBinary(f *testing.F) {
f.Add([]byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 151, 0, 14, 0, 0, 11, 17, 3, 0, 0})
f.Fuzz(func(t *testing.T, data []byte) {
artTimeCode := artnet.ArtTimeCode{}
artTimeCode.UnmarshalBinary(data)
})
}