mirror of
https://github.com/jwetzell/artnet-go.git
synced 2026-07-26 10:28:41 +00:00
258 lines
8.9 KiB
Go
258 lines
8.9 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 TestGoodArtPollUnmarshal(t *testing.T) {
|
|
tests := []struct {
|
|
Name string
|
|
Data []byte
|
|
Expected *artnet.ArtPoll
|
|
}{
|
|
{
|
|
Name: "ACT Packet 1",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
},
|
|
},
|
|
{
|
|
Name: "ACT Packet 2",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
},
|
|
},
|
|
{
|
|
Name: "ACT Packet 3",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
},
|
|
},
|
|
{
|
|
Name: "ACT Packet 4",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
},
|
|
},
|
|
{
|
|
Name: "ACT Packet 5",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
TargetPortAddressBottom: 0x0000,
|
|
},
|
|
},
|
|
{
|
|
Name: "ACT Packet 6",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
TargetPortAddressBottom: 0x0000,
|
|
},
|
|
},
|
|
{
|
|
Name: "ACT Packet 7",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
TargetPortAddressBottom: 0x0000,
|
|
EstaMan: 0x5379,
|
|
},
|
|
},
|
|
{
|
|
Name: "ACT Packet 8",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
TargetPortAddressBottom: 0x0000,
|
|
EstaMan: 0x5379,
|
|
},
|
|
},
|
|
{
|
|
Name: "ACT Packet 9",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
TargetPortAddressBottom: 0x0000,
|
|
EstaMan: 0x5379,
|
|
Oem: 0x2269,
|
|
},
|
|
},
|
|
// TODO(jwetzell): uncomment when extend field parsing is done
|
|
// {
|
|
// Name: "ACT Packet 10",
|
|
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00},
|
|
// Expected: &artnet.ArtPoll{
|
|
// Flags: 0x00,
|
|
// DiagPriority: 0x00,
|
|
// TargetPortAddressTop: 0x7fff,
|
|
// TargetPortAddressBottom: 0x0000,
|
|
// EstaMan: 0x5379,
|
|
// Oem: 0x2269,
|
|
// },
|
|
// },
|
|
// {
|
|
// Name: "ACT Packet 11",
|
|
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00},
|
|
// Expected: &artnet.ArtPoll{
|
|
// Flags: 0x00,
|
|
// DiagPriority: 0x00,
|
|
// TargetPortAddressTop: 0x7fff,
|
|
// TargetPortAddressBottom: 0x0000,
|
|
// EstaMan: 0x5379,
|
|
// Oem: 0x2269,
|
|
// },
|
|
// },
|
|
// {
|
|
// Name: "ACT Packet 12",
|
|
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00},
|
|
// Expected: &artnet.ArtPoll{
|
|
// Flags: 0x00,
|
|
// DiagPriority: 0x00,
|
|
// TargetPortAddressTop: 0x7fff,
|
|
// TargetPortAddressBottom: 0x0000,
|
|
// EstaMan: 0x5379,
|
|
// Oem: 0x2269,
|
|
// },
|
|
// },
|
|
// {
|
|
// Name: "ACT Packet 13",
|
|
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00},
|
|
// Expected: &artnet.ArtPoll{
|
|
// Flags: 0x00,
|
|
// DiagPriority: 0x00,
|
|
// TargetPortAddressTop: 0x7fff,
|
|
// TargetPortAddressBottom: 0x0000,
|
|
// EstaMan: 0x5379,
|
|
// Oem: 0x2269,
|
|
// },
|
|
// },
|
|
// {
|
|
// Name: "ACT Packet 14",
|
|
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
// Expected: &artnet.ArtPoll{
|
|
// Flags: 0x00,
|
|
// DiagPriority: 0x00,
|
|
// TargetPortAddressTop: 0x7fff,
|
|
// TargetPortAddressBottom: 0x0000,
|
|
// EstaMan: 0x5379,
|
|
// Oem: 0x2269,
|
|
// },
|
|
// },
|
|
// {
|
|
// Name: "ACT Packet 15",
|
|
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
// Expected: &artnet.ArtPoll{
|
|
// Flags: 0x00,
|
|
// DiagPriority: 0x00,
|
|
// TargetPortAddressTop: 0x7fff,
|
|
// TargetPortAddressBottom: 0x0000,
|
|
// EstaMan: 0x5379,
|
|
// Oem: 0x2269,
|
|
// },
|
|
// },
|
|
// {
|
|
// Name: "ACT Packet 16",
|
|
// Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x21, 0x0a, 0x00, 0x00, 0x3e, 0x36, 0x19, 0x07, 0x33, 0x00, 0x06, 0x22, 0x69, 0x00, 0x00, 0x79, 0x53, 0x41, 0x43, 0x54, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x43, 0x54, 0x2e, 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},
|
|
// Expected: &artnet.ArtPoll{
|
|
// Flags: 0x00,
|
|
// DiagPriority: 0x00,
|
|
// TargetPortAddressTop: 0x7fff,
|
|
// TargetPortAddressBottom: 0x0000,
|
|
// EstaMan: 0x5379,
|
|
// Oem: 0x2269,
|
|
// },
|
|
// },
|
|
{
|
|
Name: "ACT Packet 17",
|
|
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x06, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69},
|
|
Expected: &artnet.ArtPoll{
|
|
Flags: 0x06,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
TargetPortAddressBottom: 0x0000,
|
|
EstaMan: 0x5379,
|
|
Oem: 0x2269,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.Name, func(t *testing.T) {
|
|
got := &artnet.ArtPoll{}
|
|
|
|
err := got.UnmarshalBinary(test.Data)
|
|
if err != nil {
|
|
t.Fatalf("failed to Unmarshal ArtPoll: %s", err)
|
|
}
|
|
diff := cmp.Diff(test.Expected, got, cmpopts.IgnoreUnexported(artnet.ArtPoll{}))
|
|
if diff != "" {
|
|
t.Fatalf("ArtPoll does not match\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkArtPollUnmarshalBinary(b *testing.B) {
|
|
data := []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69}
|
|
|
|
for b.Loop() {
|
|
got := artnet.ArtPoll{}
|
|
|
|
err := got.UnmarshalBinary(data)
|
|
if err != nil {
|
|
b.Fatalf("failed to decode ArtPoll: %s", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func BenchmarkArtPollMarshalBinary(b *testing.B) {
|
|
data := artnet.ArtPoll{
|
|
Flags: 0x00,
|
|
DiagPriority: 0x00,
|
|
TargetPortAddressTop: 0x7fff,
|
|
TargetPortAddressBottom: 0x0000,
|
|
EstaMan: 0x5379,
|
|
Oem: 0x2269,
|
|
}
|
|
|
|
for b.Loop() {
|
|
_, err := data.MarshalBinary()
|
|
if err != nil {
|
|
b.Fatalf("failed to encode ArtPoll: %s", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func FuzzArtPollUnmarshalBinary(f *testing.F) {
|
|
f.Add([]byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f, 0xff, 0x00, 0x00, 0x53, 0x79, 0x22, 0x69})
|
|
f.Fuzz(func(t *testing.T, data []byte) {
|
|
artPoll := artnet.ArtPoll{}
|
|
artPoll.UnmarshalBinary(data)
|
|
})
|
|
}
|