mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-20 22:08:59 +00:00
add osc bundle encoding with proper timetag
This commit is contained in:
+32
-14
@@ -10,13 +10,16 @@ func TestOSCBundleEncoding(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
message OSCBundle
|
||||
bundle OSCBundle
|
||||
expected []byte
|
||||
}{
|
||||
{
|
||||
"simple contents single message",
|
||||
OSCBundle{
|
||||
TimeTag: 0x0000002000000000,
|
||||
TimeTag: OSCTimeTag{
|
||||
seconds: 32,
|
||||
fractionalSeconds: 0,
|
||||
},
|
||||
Contents: []OSCPacket{&OSCMessage{Address: "/oscillator/4/frequency", Args: []OSCArg{{Type: "f", Value: float32(440)}}}},
|
||||
},
|
||||
[]byte{35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0,
|
||||
@@ -29,7 +32,7 @@ func TestOSCBundleEncoding(t *testing.T) {
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
actual := testCase.message.ToBytes()
|
||||
actual := testCase.bundle.ToBytes()
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode properly", testCase.description)
|
||||
@@ -43,29 +46,44 @@ func TestOSCBundleEncoding(t *testing.T) {
|
||||
func TestOSCBundleDecoding(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
expected OSCBundle
|
||||
bytes []byte
|
||||
expected OSCMessage
|
||||
}{}
|
||||
}{
|
||||
{
|
||||
"simple contents single message",
|
||||
OSCBundle{
|
||||
TimeTag: OSCTimeTag{
|
||||
seconds: 32,
|
||||
fractionalSeconds: 0,
|
||||
},
|
||||
Contents: []OSCPacket{&OSCMessage{Address: "/oscillator/4/frequency", Args: []OSCArg{{Type: "f", Value: float32(440)}}}},
|
||||
},
|
||||
[]byte{35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0,
|
||||
32, 0, 0, 0, 0, 0, 0, 0, 32, 47, 111,
|
||||
115, 99, 105, 108, 108, 97, 116, 111, 114, 47, 52,
|
||||
47, 102, 114, 101, 113, 117, 101, 110, 99, 121, 0,
|
||||
44, 102, 0, 0, 67, 220, 0, 0},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
actual, error := MessageFromBytes(testCase.bytes)
|
||||
actual, remainingBytes, error := BundleFromBytes(testCase.bytes)
|
||||
|
||||
if error != nil {
|
||||
fmt.Println(error)
|
||||
t.Errorf("Test '%s' failed to encode properly", testCase.description)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual.Address, testCase.expected.Address) {
|
||||
t.Errorf("Test '%s' failed to encode address properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected.Address)
|
||||
fmt.Printf("actual: %v\n", actual.Address)
|
||||
if len(remainingBytes) > 0 {
|
||||
t.Errorf("Test '%s' should not have any remaining bytes", testCase.description)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(actual.Args, testCase.expected.Args) {
|
||||
t.Errorf("Test '%s' failed to encode args properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected.Args)
|
||||
fmt.Printf("actual: %v\n", actual.Args)
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode bundle properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user