mirror of
https://github.com/jwetzell/artnet-go.git
synced 2026-08-14 19:43:39 +00:00
217 lines
7.8 KiB
Go
217 lines
7.8 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{
|
|
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)
|
|
}
|
|
if !reflect.DeepEqual(got, test.Expected) {
|
|
t.Fatalf("ArtPoll does not match got: %+v expected: %+v", got, test.Expected)
|
|
}
|
|
})
|
|
}
|
|
}
|