Files
artnet-go/poll_test.go
T
2026-05-30 07:21:06 -05:00

202 lines
6.2 KiB
Go

package artnet_test
import (
"reflect"
"testing"
"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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
Name: "ACT Packet 2",
Data: []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x20, 0x00, 0x0e, 0x00, 0x00, 0x7f},
Expected: &artnet.ArtPoll{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
{
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{
ID: artnet.ArtNetID,
OpCode: 0x2000,
ProtVerHi: 0x00,
ProtVerLo: 0x0e,
},
},
}
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)
}
if !reflect.DeepEqual(got, test.Expected) {
t.Fatalf("ArtPoll does not match got: %+v expected: %+v", got, test.Expected)
}
})
}
}